[InstCombine] Right-shift shift amount reassociation with truncation (PR43564, PR42391)
authorRoman Lebedev <lebedev.ri@gmail.com>
Fri, 4 Oct 2019 22:16:11 +0000 (22:16 +0000)
committerRoman Lebedev <lebedev.ri@gmail.com>
Fri, 4 Oct 2019 22:16:11 +0000 (22:16 +0000)
commitf304d4d185d24eec9f0ca84d566da0d51b2344ef
tree515be38bbf0d6a835b9600b54647ebd0bfd63912
parentae738641d53e06b30b1189aedaa1c3dddd8d371d
[InstCombine] Right-shift shift amount reassociation with truncation (PR43564, PR42391)

Initially (D65380) i believed that if we have rightshift-trunc-rightshift,
we can't do any folding. But as it usually happens, i was wrong.

https://rise4fun.com/Alive/GEw
https://rise4fun.com/Alive/gN2O

In https://bugs.llvm.org/show_bug.cgi?id=43564 we happen to have
this very sequence, of two right shifts separated by trunc.
And "just" so that happens, we apparently can fold the pattern
if the total shift amount is either 0, or it's equal to the bitwidth
of the innermost widest shift - i.e. if we are left with only the
original sign bit. Which is exactly what is wanted there.

llvm-svn: 373801
llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp
llvm/test/Transforms/InstCombine/shift-amount-reassociation-with-truncation-ashr.ll
llvm/test/Transforms/InstCombine/shift-amount-reassociation-with-truncation-lshr.ll
llvm/test/Transforms/InstCombine/sign-bit-test-via-right-shifting-all-other-bits.ll