[InstCombine] fold cast of right-shift if high bits are not demanded (2nd try)
authorSanjay Patel <spatel@rotateright.com>
Thu, 23 Sep 2021 13:40:01 +0000 (09:40 -0400)
committerSanjay Patel <spatel@rotateright.com>
Thu, 23 Sep 2021 13:41:37 +0000 (09:41 -0400)
commitbb9333c3504a4a02b982526ad8264d14c6ec1ad4
tree14986432e295a1c461d9a51e34818207a4824e42
parentac889a5262f230eaccfbe60ad2c1d1ae60280623
[InstCombine] fold cast of right-shift if high bits are not demanded (2nd try)

The 1st try at this was reverted because it caused an infinite loop in instcombine.
That should be fixed after:
1cd6b44f267b

(masked) trunc (lshr X, C) --> (masked) lshr (trunc X), C

Narrowing the shift should be better for analysis and can lead
to follow-on transforms as shown.

Attempt at a general proof in Alive2:
https://alive2.llvm.org/ce/z/tRnnSF

Here are a couple of the specific tests:
https://alive2.llvm.org/ce/z/bCnTp-
https://alive2.llvm.org/ce/z/TfaHnb

Differential Revision: https://reviews.llvm.org/D110170
llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
llvm/test/Transforms/InstCombine/trunc-demand.ll