[InstCombine] Dropping redundant masking before left-shift [4/5] (PR42563)
authorRoman Lebedev <lebedev.ri@gmail.com>
Fri, 19 Jul 2019 08:26:47 +0000 (08:26 +0000)
committerRoman Lebedev <lebedev.ri@gmail.com>
Fri, 19 Jul 2019 08:26:47 +0000 (08:26 +0000)
commit441c9d6ca897663408446af956630399e988cd6d
tree2617a1a02d3318c90768a1c60960f02fbbcf7238
parent3c212ce3054a94d8f501a8d0184c4e298964e8ec
[InstCombine] Dropping redundant masking before left-shift [4/5] (PR42563)

Summary:
If we have some pattern that leaves only some low bits set, and then performs
left-shift of those bits, if none of the bits that are left after the final
shift are modified by the mask, we can omit the mask.

There are many variants to this pattern:
e. `((x << MaskShAmt) l>> MaskShAmt) << ShiftShAmt`
All these patterns can be simplified to just:
`x << ShiftShAmt`
iff:
e. `(ShiftShAmt-MaskShAmt) s>= 0` (i.e. `ShiftShAmt u>= MaskShAmt`)

alive proofs:
e: https://rise4fun.com/Alive/0FT

For now let's start with patterns where both shift amounts are variable,
with trivial constant "offset" between them, since i believe this is
both simplest to handle and i think this is most common.
But again, there are likely other variants where we could use
ValueTracking/ConstantRange to handle more cases.

https://bugs.llvm.org/show_bug.cgi?id=42563

Differential Revision: https://reviews.llvm.org/D64521

llvm-svn: 366539
llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp
llvm/test/Transforms/InstCombine/redundant-left-shift-input-masking-variant-e.ll