-
Notifications
You must be signed in to change notification settings - Fork 12.2k
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
[X86] Suboptimal lowering of short vectors equality check: could use scalar types instead #53419
Comments
Here is something in between: if we bitcast vector values to i32 after load, codegen can produce good code. |
@llvm/issue-subscribers-backend-x86 |
3271f43 tests. |
You can't do that transformation at IR level; it's not sound because of poison values. It has to be delayed until the backend. |
Ah, nervermind, you are doing an and of all the comparisons. That's fine, yes. |
https://reviews.llvm.org/D118317 should address this pattern on IR level, but I still believe there should also be a codegen solution. |
Several things need to be addressed: MatchVectorAllZeroTest needs to be extended to handle the (icmp bitcast(iN (icmp vNiX V, 0) ), 0) style reduction pattern that we canonicalize to - this will catch the (legal) integer size patterns. Extend MatchVectorAllZeroTest and LowerVectorAllZero so that they handle 'VectorAllEqual' patterns - PTEST lowering will need to perform a SUB(X,Y), but the MOVMSK can still use PCMPEQB. The ExpandReductions pass should fold the allof(icmp(vector)) -> (icmp bitcast(iN (icmp (vector)) ), 0) canonicalization, we currently only perform this inside InstCombine so if anything else has generated this we might miss it. |
…kortestw patterns Another step toward #53419 - this is also another step towards expanding MatchVectorAllZeroTest to match any pair of vectors and merge EmitAVX512Test into it.
…kortestw patterns (REAPPLIED) Another step toward #53419 - this is also another step towards expanding MatchVectorAllZeroTest to match any pair of vectors and merge EmitAVX512Test into it.
Candidate Patch: https://reviews.llvm.org/D147243 |
…,Y)),0) vector reduction patterns Many allof/anyof/noneof reduction patterns are canonicalized by bitcasting a vXi1 vector comparison result to iN and compared against 0/-1. This patch adds support for recognizing a icmp_ne vector comparison against 0, which matches an 'whole vectors are equal' comparison pattern. There are a few more steps to follow in future patches - we need to add support to MatchVectorAllZeroTest for comparing against -1 (in some cases), and this initial refactoring of LowerVectorAllZero to LowerVectorAllEqual needs to be extended so we can fully merge with the similar combineVectorSizedSetCCEquality code (which deals with scalar integer memcmp patterns). Another step towards Issue #53419 Differential Revision: https://reviews.llvm.org/D147243
Final Candidate Patch: https://reviews.llvm.org/D147452 |
… bitcast(<X x i1> V)) canonicalization This already exists in InstCombine but was missing from the late stage ExpandReductions pass Fixes llvm#53419 Fixes llvm#61923 Differential Revision: https://reviews.llvm.org/D147452
… bitcast(<X x i1> V)) canonicalization This already exists in InstCombine but was missing from the late stage ExpandReductions pass Fixes llvm#53419 Fixes llvm#61923 Differential Revision: https://reviews.llvm.org/D147452
Motivating case: https://godbolt.org/z/rbE3TzqdP
The original test
reads two short vector values and effectively checks that they are equal. Codegen generates vector code from it:
This code is semantically equivalent to its scalar counterpart
which produces neater asm:
Unfortunately we cannot use RM vector sub here as stated in #53416, but it looks like we could give up using vector registers at all.
Not sure what is the proper place for this - codegen or instcombine.
The text was updated successfully, but these errors were encountered: