[InstCombine] fold mul with incremented "shl 1" factor
authorSanjay Patel <spatel@rotateright.com>
Sat, 29 Oct 2022 14:53:23 +0000 (10:53 -0400)
committerSanjay Patel <spatel@rotateright.com>
Sat, 29 Oct 2022 16:50:19 +0000 (12:50 -0400)
commit6064e92b0a84b6d52b25ab1e6da90e74c76c6eb0
treeb4560028c37b42dd82f3ce570105369b596c4742
parent50000ec2cb16a2f7c157164858ae10074064c1ee
[InstCombine] fold mul with incremented "shl 1" factor

X * ((1 << Z) + 1) --> (X << Z) + X

https://alive2.llvm.org/ce/z/P-7WK9

It's possible that we could do better with propagating
no-wrap, but this carries over the existing logic and
appears to be correct.

The naming differences on the existing folds are a result
of using getName() to set the final value via Builder.
That makes it easier to transfer no-wrap rather than the
gymnastics required from the raw create instruction APIs.
llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
llvm/test/Transforms/InstCombine/mul.ll