[PATCH] D133667: [InstCombine] convert mul by negative-pow2 to negate and shift

Sanjay Patel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Sep 11 05:26:25 PDT 2022


spatel created this revision.
spatel added reviewers: craig.topper, RKSimon, chfast, nikic.
Herald added subscribers: StephenFan, hiraditya, mcrosier.
Herald added a project: All.
spatel requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

This is an unusual canonicalization because we create an extra instruction, but it's very likely better for analysis and codegen (similar reasoning as D133399 <https://reviews.llvm.org/D133399>).

InstCombine::Negator aggressively creates this kind of multiply from subtract and shift, so this is partly reversing a transform in the motivating case from issue #57576 <https://github.com/llvm/llvm-project/issues/57576>.

We may want to limit Negator more to prevent creating multiplies like this. We've seen regressions from that, but no wins AFAIK.

I don't know how to create a fully general proof for this kind of transform in Alive2, but here's an example with bitwidths similar to one of the regression tests:
https://alive2.llvm.org/ce/z/J3jTjR


https://reviews.llvm.org/D133667

Files:
  llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
  llvm/test/Transforms/InstCombine/add.ll
  llvm/test/Transforms/InstCombine/mul.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D133667.459357.patch
Type: text/x-patch
Size: 6070 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220911/488dda84/attachment.bin>


More information about the llvm-commits mailing list