This is an archive of the discontinued LLVM Phabricator instance.

Demonstrate behaviour of add mul instruction sequence
Needs ReviewPublic

Authored by davidb on Feb 17 2020, 9:01 AM.
This revision needs review, but there are no reviewers specified.

Details

Reviewers
None
Summary

Noticed a couple of issues with the sequence and folding of mul (add x, c1), c2 -> (add (mul x, c2), c1*c2).

  1. In some cases, the result of c1*c2 cannot be represented as an immediate without materialising into a register. In this case, it would be better not to perform this reordering of the add instruction.
  1. In the bitcast case the constant c1 and c2 are marked as opaque and cannot be folded, resulting in a second mul instruction.

I have a fix that is a WIP that prevents this transformation in the case that 1. The value of c1*c2 cannot be represented as an immediate without a register, or 2. if either of the constants are opaque. Sadly this generates regressions on other targets that I am still investigating...

NOTE: not tagged as [RISCV] as I can demonstrate this on other targets, and might be worth adding here.

Event Timeline

davidb created this revision.Feb 17 2020, 9:01 AM
davidb edited the summary of this revision. (Show Details)Feb 17 2020, 9:10 AM
davidb added a subscriber: JonChesterfield.
davidb edited the summary of this revision. (Show Details)Feb 17 2020, 9:13 AM