[InstCombine] convert mul by negative-pow2 to negate and shift
authorSanjay Patel <spatel@rotateright.com>
Sun, 2 Oct 2022 16:22:25 +0000 (12:22 -0400)
committerSanjay Patel <spatel@rotateright.com>
Sun, 2 Oct 2022 16:22:25 +0000 (12:22 -0400)
commit2e87333bfe7e226533fb66c84015c4523e352d3f
treed33c9203ee43de9cdbc2d5546894ebebf9a750ea
parent4490cfbaf4591febc784592fa11a9d418e6c8d5a
[InstCombine] convert mul by negative-pow2 to negate and shift

This is an unusual canonicalization because we create an extra instruction,
but it's likely better for analysis and codegen (similar reasoning as D133399).

InstCombine::Negator may create this kind of multiply from negate and shift,
but this should not conflict because of the narrow negation.

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

Differential Revision: https://reviews.llvm.org/D133667
llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
llvm/test/Transforms/InstCombine/add.ll
llvm/test/Transforms/InstCombine/mul.ll