]> granicus.if.org Git - llvm/commit
[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)
commit6d4c970c3440a7d3418b3222b663438bc343c0db
tree7cfa196a858b9e1c6d13b5329e8c5e4b5da03830
parent3a084a509839771bdb080f5551678c75ec1c3b44
[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.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@373801 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Transforms/InstCombine/InstCombineShifts.cpp
test/Transforms/InstCombine/shift-amount-reassociation-with-truncation-ashr.ll
test/Transforms/InstCombine/shift-amount-reassociation-with-truncation-lshr.ll
test/Transforms/InstCombine/sign-bit-test-via-right-shifting-all-other-bits.ll