This is an archive of the discontinued LLVM Phabricator instance.

[InstCombine] Dropping redundant masking before left-shift [3/5] (PR42563)
ClosedPublic

Authored by lebedev.ri on Jul 10 2019, 11:04 AM.

Details

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:
d. (x & ((-1 << MaskShAmt) >> MaskShAmt)) << ShiftShAmt
All these patterns can be simplified to just:
x << ShiftShAmt
iff:
d. (ShiftShAmt-MaskShAmt) s>= 0 (i.e. ShiftShAmt u>= MaskShAmt)

alive proofs:
d: https://rise4fun.com/Alive/I5Y

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

Diff Detail

Repository
rL LLVM

Event Timeline

lebedev.ri created this revision.Jul 10 2019, 11:04 AM
lebedev.ri marked an inline comment as done.
lebedev.ri added inline comments.
llvm/test/Transforms/InstCombine/redundant-left-shift-input-masking-variant-d.ll
333 ↗(On Diff #209022)

Yes, i will re-pre-commit and rebase after posting two last patches.

Rebased over re-combed tests, NFC.

lebedev.ri edited the summary of this revision. (Show Details)Jul 10 2019, 1:18 PM

Rebased, NFC.

This revision was not accepted when it landed; it landed in state Needs Review.Jul 19 2019, 1:28 AM
This revision was automatically updated to reflect the committed changes.