-
Notifications
You must be signed in to change notification settings - Fork 11.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[InstCombine] Improve folds for and/or cmp, cmp
#72965
Open
goldsteinn
wants to merge
10
commits into
llvm:main
Choose a base branch
from
goldsteinn:goldsteinn/and-canonicalization-cont
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
[InstCombine] Improve folds for and/or cmp, cmp
#72965
goldsteinn
wants to merge
10
commits into
llvm:main
from
goldsteinn:goldsteinn/and-canonicalization-cont
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Make recursive matcher that is able to detect a lot more patterns. Proofs for all supported patterns: https://alive2.llvm.org/ce/z/fSQ3nZ Differential Revision: https://reviews.llvm.org/D159058
…foldICmpWithLowBitMaskedVal` `(icmp eq/ne (and X, ~Mask), 0)` is equivilent to `(icmp eq/ne (and X, Mask), X` and we sometimes generate the former pattern intentionally to reduce number of uses of `X`. Proof: https://alive2.llvm.org/ce/z/3u-usC Differential Revision: https://reviews.llvm.org/D159329
…work for non-const operands We currently do: `(icmp eq/ne (and X, Y), Y)` -> `(icmp eq/ne (and ~X, Y), 0)` if `X` is constant. We can make this more general and do it if `X` is freely invertable (i.e say `X = ~Z`). As well, we can also do: `(icmp eq/ne (and X, Y), Y)` -> `(icmp eq/ne (or X, ~Y), -1)` If `Y` is freely invertible. Proofs: https://alive2.llvm.org/ce/z/yeWH3E Differential Revision: https://reviews.llvm.org/D159059
This is prep for using `getKnownSign` outside of just InstCombineCalls. Differential Revision: https://reviews.llvm.org/D159060
…Y` are known signed/unsigned Several transforms: 1) If known `Y < 0`: - slt -> ult: https://alive2.llvm.org/ce/z/unpsxu - sle -> ule: https://alive2.llvm.org/ce/z/a5cpmr - sgt -> ugt: https://alive2.llvm.org/ce/z/qgsgya - sge -> uge: https://alive2.llvm.org/ce/z/ek_3ls 2) If known `Y > 0`: - `(X & PosY) s> X --> X s< 0` - https://alive2.llvm.org/ce/z/drewij - `(X & PosY) s> X --> X s< 0` - https://alive2.llvm.org/ce/z/9arL3D 3) If known `X < 0`: - `(NegX & Y) s> NegX --> Y s>= 0` - https://alive2.llvm.org/ce/z/ApkaEh - `(NegX & Y) s<= NegX --> Y s< 0` - https://alive2.llvm.org/ce/z/oRnfHp Differential Revision: https://reviews.llvm.org/D145426
…Y)`; NFC Differential Revision: https://reviews.llvm.org/D159061
… of `Y` The fold will replace 2 uses of `Y` we should also do fold if `Y` has 2 uses (not only oneuse). Reviewed By: nikic Differential Revision: https://reviews.llvm.org/D159062
…cmp eq/ne X,Pow2OrZero))`; NFC Differential Revision: https://reviews.llvm.org/D157311
…e X,Pow2OrZero))` `(or (icmp eq X, 0), (icmp eq X, Pow2OrZero))` --> `(icmp eq (and X, Pow2OrZero), X)` `(and (icmp ne X, 0), (icmp ne X, Pow2OrZero))` --> `(icmp ne (and X, Pow2OrZero), X)` Proofs: https://alive2.llvm.org/ce/z/nPo2BN Reviewed By: nikic Differential Revision: https://reviews.llvm.org/D157312
and/or cmp, cmp
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
foldICmpWithLowBitMaskedVal
; NFCfoldICmpWithLowBitMaskedVal
(icmp eq/ne (and X, ~Mask), 0)
pattern infoldICmpWithLowBitMaskedVal
(icmp eq/ne (and X, Y), X)
canonicalization work for non-const operandsgetKnownSign
a member function of InstCombiner; NFC(icmp spred (and X, Y), X)
ifX
orY
are known signed/unsigned(icmp eq/ne (or X, Y), Y)
; NFC(icmp eq/ne (or X, Y), Y)
for 2 uses ofY
(or/and (icmp eq/ne X,0),(icmp eq/ne X,Pow2OrZero))
; NFC(or/and (icmp eq/ne X,0),(icmp eq/ne X,Pow2OrZero))