[llvm] [X86] Accept the canonical form of a sign bit test in MatchVectorAllEqualTest. (PR #154421)

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 20 01:43:27 PDT 2025


================
@@ -903,6 +903,95 @@ define i1 @mask_v8i32(<8 x i32> %a0) {
   ret i1 %3
 }
 
+define i1 @mask_v8i32_2(<8 x i32> %a0) {
+; SSE2-LABEL: mask_v8i32_2:
+; SSE2:       # %bb.0:
+; SSE2-NEXT:    por %xmm1, %xmm0
+; SSE2-NEXT:    pslld $1, %xmm0
+; SSE2-NEXT:    movmskps %xmm0, %eax
+; SSE2-NEXT:    testl %eax, %eax
+; SSE2-NEXT:    sete %al
+; SSE2-NEXT:    retq
+;
+; SSE41-LABEL: mask_v8i32_2:
+; SSE41:       # %bb.0:
+; SSE41-NEXT:    por %xmm1, %xmm0
+; SSE41-NEXT:    ptest {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm0
+; SSE41-NEXT:    sete %al
+; SSE41-NEXT:    retq
+;
+; AVX1-LABEL: mask_v8i32_2:
+; AVX1:       # %bb.0:
+; AVX1-NEXT:    vptest {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %ymm0
----------------
RKSimon wrote:

If we're just using the sign bits, we might be missing a fold that would allow us to use VTESTPS/PD and avoid the constant load. IIRC we do have some PTEST->TESTP folds.

https://github.com/llvm/llvm-project/pull/154421


More information about the llvm-commits mailing list