[llvm] r361052 - [X86][SSE] Match all-of bool scalar reductions into a bitcast/movmsk + cmp.
Simon Pilgrim via llvm-commits
llvm-commits at lists.llvm.org
Fri May 17 10:25:55 PDT 2019
Author: rksimon
Date: Fri May 17 10:25:55 2019
New Revision: 361052
URL: http://llvm.org/viewvc/llvm-project?rev=361052&view=rev
Log:
[X86][SSE] Match all-of bool scalar reductions into a bitcast/movmsk + cmp.
Same as what we do for vector reductions in combineHorizontalPredicateResult, use movmsk+cmp for scalar (and(extract(x,0),extract(x,1)) reduction patterns.
Modified:
llvm/trunk/lib/Target/X86/X86ISelLowering.cpp
llvm/trunk/test/CodeGen/X86/movmsk-cmp.ll
Modified: llvm/trunk/lib/Target/X86/X86ISelLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86ISelLowering.cpp?rev=361052&r1=361051&r2=361052&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86ISelLowering.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86ISelLowering.cpp Fri May 17 10:25:55 2019
@@ -37841,6 +37841,24 @@ static SDValue combineAnd(SDNode *N, Sel
if (SDValue V = combineParity(N, DAG, Subtarget))
return V;
+ // Match all-of bool scalar reductions into a bitcast/movmsk + cmp.
+ // TODO: Support multiple SrcOps.
+ if (VT == MVT::i1) {
+ SmallVector<SDValue, 2> SrcOps;
+ if (matchBitOpReduction(SDValue(N, 0), ISD::AND, SrcOps) &&
+ SrcOps.size() == 1) {
+ SDLoc dl(N);
+ unsigned NumElts = SrcOps[0].getValueType().getVectorNumElements();
+ EVT MaskVT = EVT::getIntegerVT(*DAG.getContext(), NumElts);
+ SDValue Mask = combineBitcastvxi1(DAG, MaskVT, SrcOps[0], dl, Subtarget);
+ if (Mask) {
+ APInt AllBits = APInt::getAllOnesValue(NumElts);
+ return DAG.getSetCC(dl, MVT::i1, Mask,
+ DAG.getConstant(AllBits, dl, MaskVT), ISD::SETEQ);
+ }
+ }
+ }
+
if (DCI.isBeforeLegalizeOps())
return SDValue();
Modified: llvm/trunk/test/CodeGen/X86/movmsk-cmp.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/movmsk-cmp.ll?rev=361052&r1=361051&r2=361052&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/movmsk-cmp.ll (original)
+++ llvm/trunk/test/CodeGen/X86/movmsk-cmp.ll Fri May 17 10:25:55 2019
@@ -4487,10 +4487,9 @@ define i1 @movmsk_v2i64(<2 x i64> %x, <2
; SSE2-NEXT: pand %xmm0, %xmm1
; SSE2-NEXT: pcmpeqd %xmm0, %xmm0
; SSE2-NEXT: pxor %xmm1, %xmm0
-; SSE2-NEXT: movmskpd %xmm0, %ecx
-; SSE2-NEXT: movl %ecx, %eax
-; SSE2-NEXT: shrb %al
-; SSE2-NEXT: andb %cl, %al
+; SSE2-NEXT: movmskpd %xmm0, %eax
+; SSE2-NEXT: cmpb $3, %al
+; SSE2-NEXT: sete %al
; SSE2-NEXT: retq
;
; AVX-LABEL: movmsk_v2i64:
@@ -4498,10 +4497,9 @@ define i1 @movmsk_v2i64(<2 x i64> %x, <2
; AVX-NEXT: vpcmpeqq %xmm1, %xmm0, %xmm0
; AVX-NEXT: vpcmpeqd %xmm1, %xmm1, %xmm1
; AVX-NEXT: vpxor %xmm1, %xmm0, %xmm0
-; AVX-NEXT: vmovmskpd %xmm0, %ecx
-; AVX-NEXT: movl %ecx, %eax
-; AVX-NEXT: shrb %al
-; AVX-NEXT: andb %cl, %al
+; AVX-NEXT: vmovmskpd %xmm0, %eax
+; AVX-NEXT: cmpb $3, %al
+; AVX-NEXT: sete %al
; AVX-NEXT: retq
;
; KNL-LABEL: movmsk_v2i64:
@@ -4596,19 +4594,17 @@ define i1 @movmsk_v2f64(<2 x double> %x,
; SSE2-LABEL: movmsk_v2f64:
; SSE2: # %bb.0:
; SSE2-NEXT: cmplepd %xmm0, %xmm1
-; SSE2-NEXT: movmskpd %xmm1, %ecx
-; SSE2-NEXT: movl %ecx, %eax
-; SSE2-NEXT: shrb %al
-; SSE2-NEXT: andb %cl, %al
+; SSE2-NEXT: movmskpd %xmm1, %eax
+; SSE2-NEXT: cmpb $3, %al
+; SSE2-NEXT: sete %al
; SSE2-NEXT: retq
;
; AVX-LABEL: movmsk_v2f64:
; AVX: # %bb.0:
; AVX-NEXT: vcmplepd %xmm0, %xmm1, %xmm0
-; AVX-NEXT: vmovmskpd %xmm0, %ecx
-; AVX-NEXT: movl %ecx, %eax
-; AVX-NEXT: shrb %al
-; AVX-NEXT: andb %cl, %al
+; AVX-NEXT: vmovmskpd %xmm0, %eax
+; AVX-NEXT: cmpb $3, %al
+; AVX-NEXT: sete %al
; AVX-NEXT: retq
;
; KNL-LABEL: movmsk_v2f64:
More information about the llvm-commits
mailing list