[llvm] 9734b22 - [X86] combineCMP - use widenMaskVector to allow us to handle sub-i8 mask cases when just comparing a bool element against zero
Simon Pilgrim via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 31 08:57:35 PDT 2023
Author: Simon Pilgrim
Date: 2023-08-31T16:57:22+01:00
New Revision: 9734b2256d89cb4c61a4dbf4a3c3f3f942fe9b8c
URL: https://github.com/llvm/llvm-project/commit/9734b2256d89cb4c61a4dbf4a3c3f3f942fe9b8c
DIFF: https://github.com/llvm/llvm-project/commit/9734b2256d89cb4c61a4dbf4a3c3f3f942fe9b8c.diff
LOG: [X86] combineCMP - use widenMaskVector to allow us to handle sub-i8 mask cases when just comparing a bool element against zero
Added:
Modified:
llvm/lib/Target/X86/X86ISelLowering.cpp
llvm/test/CodeGen/X86/movmsk-cmp.ll
llvm/test/CodeGen/X86/pr33349.ll
llvm/test/CodeGen/X86/pr34177.ll
Removed:
################################################################################
diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp b/llvm/lib/Target/X86/X86ISelLowering.cpp
index 3828dcf5cbc56f..17af88b03f2282 100644
--- a/llvm/lib/Target/X86/X86ISelLowering.cpp
+++ b/llvm/lib/Target/X86/X86ISelLowering.cpp
@@ -53455,7 +53455,8 @@ static bool onlyZeroFlagUsed(SDValue Flags) {
return true;
}
-static SDValue combineCMP(SDNode *N, SelectionDAG &DAG) {
+static SDValue combineCMP(SDNode *N, SelectionDAG &DAG,
+ const X86Subtarget &Subtarget) {
// Only handle test patterns.
if (!isNullConstant(N->getOperand(1)))
return SDValue();
@@ -53493,7 +53494,6 @@ static SDValue combineCMP(SDNode *N, SelectionDAG &DAG) {
// If we're extracting from a avx512 bool vector and comparing against zero,
// then try to just bitcast the vector to an integer to use TEST/BT directly.
- // TODO: Handle v2i1/v4i1 bool vector cases.
// (and (extract_elt (kshiftr vXi1, C), 0), 1) -> (and (bc vXi1), 1<<C)
if (Op.getOpcode() == ISD::AND && isOneConstant(Op.getOperand(1)) &&
Op.hasOneUse() && onlyZeroFlagUsed(SDValue(N, 0))) {
@@ -53502,16 +53502,16 @@ static SDValue combineCMP(SDNode *N, SelectionDAG &DAG) {
isNullConstant(Src.getOperand(1)) &&
Src.getOperand(0).getValueType().getScalarType() == MVT::i1) {
SDValue BoolVec = Src.getOperand(0);
+ unsigned ShAmt = 0;
+ if (BoolVec.getOpcode() == X86ISD::KSHIFTR) {
+ ShAmt = BoolVec.getConstantOperandVal(1);
+ BoolVec = BoolVec.getOperand(0);
+ }
+ BoolVec = widenMaskVector(BoolVec, false, Subtarget, DAG, dl);
EVT VecVT = BoolVec.getValueType();
unsigned BitWidth = VecVT.getVectorNumElements();
EVT BCVT = EVT::getIntegerVT(*DAG.getContext(), BitWidth);
if (TLI.isTypeLegal(VecVT) && TLI.isTypeLegal(BCVT)) {
- unsigned ShAmt = 0;
- if (BoolVec.getOpcode() == X86ISD::KSHIFTR &&
- BoolVec.getConstantOperandAPInt(1).ult(BitWidth)) {
- ShAmt = BoolVec.getConstantOperandVal(1);
- BoolVec = BoolVec.getOperand(0);
- }
APInt Mask = APInt::getOneBitSet(BitWidth, ShAmt);
Op = DAG.getBitcast(BCVT, BoolVec);
Op = DAG.getNode(ISD::AND, dl, BCVT, Op,
@@ -55800,7 +55800,7 @@ SDValue X86TargetLowering::PerformDAGCombine(SDNode *N,
case X86ISD::BLENDV: return combineSelect(N, DAG, DCI, Subtarget);
case ISD::BITCAST: return combineBitcast(N, DAG, DCI, Subtarget);
case X86ISD::CMOV: return combineCMov(N, DAG, DCI, Subtarget);
- case X86ISD::CMP: return combineCMP(N, DAG);
+ case X86ISD::CMP: return combineCMP(N, DAG, Subtarget);
case ISD::ADD: return combineAdd(N, DAG, DCI, Subtarget);
case ISD::SUB: return combineSub(N, DAG, DCI, Subtarget);
case X86ISD::ADD:
diff --git a/llvm/test/CodeGen/X86/movmsk-cmp.ll b/llvm/test/CodeGen/X86/movmsk-cmp.ll
index a66a7e0b605d77..a0901e265f5ae9 100644
--- a/llvm/test/CodeGen/X86/movmsk-cmp.ll
+++ b/llvm/test/CodeGen/X86/movmsk-cmp.ll
@@ -4351,8 +4351,7 @@ define i32 @PR39665_c_ray(<2 x double> %x, <2 x double> %y) {
; KNL-NEXT: # kill: def $xmm0 killed $xmm0 def $zmm0
; KNL-NEXT: vcmpltpd %zmm0, %zmm1, %k0
; KNL-NEXT: kmovw %k0, %ecx
-; KNL-NEXT: kmovw %k0, %eax
-; KNL-NEXT: testb $2, %al
+; KNL-NEXT: testb $2, %cl
; KNL-NEXT: movl $42, %eax
; KNL-NEXT: movl $99, %edx
; KNL-NEXT: cmovel %edx, %eax
@@ -4365,8 +4364,7 @@ define i32 @PR39665_c_ray(<2 x double> %x, <2 x double> %y) {
; SKX: # %bb.0:
; SKX-NEXT: vcmpltpd %xmm0, %xmm1, %k0
; SKX-NEXT: kmovd %k0, %ecx
-; SKX-NEXT: kmovd %k0, %eax
-; SKX-NEXT: testb $2, %al
+; SKX-NEXT: testb $2, %cl
; SKX-NEXT: movl $42, %eax
; SKX-NEXT: movl $99, %edx
; SKX-NEXT: cmovel %edx, %eax
diff --git a/llvm/test/CodeGen/X86/pr33349.ll b/llvm/test/CodeGen/X86/pr33349.ll
index 5e84028aa738d7..83d3a33572266f 100644
--- a/llvm/test/CodeGen/X86/pr33349.ll
+++ b/llvm/test/CodeGen/X86/pr33349.ll
@@ -12,8 +12,7 @@ target triple = "x86_64-unknown-linux-gnu"
; KNL-NEXT: vptestmd %zmm0, %zmm0, %k0
; KNL-NEXT: kshiftrw $2, %k0, %k1
; KNL-NEXT: kmovw %k1, %eax
-; KNL-NEXT: kmovw %k1, %ecx
-; KNL-NEXT: testb $1, %cl
+; KNL-NEXT: testb $1, %al
; KNL-NEXT: fld1
; KNL-NEXT: fldz
; KNL-NEXT: fld %st(0)
@@ -22,8 +21,7 @@ target triple = "x86_64-unknown-linux-gnu"
; KNL-NEXT: fld %st(1)
; KNL-NEXT: fcmovne %st(3), %st
; KNL-NEXT: kmovw %k0, %eax
-; KNL-NEXT: kmovw %k0, %ecx
-; KNL-NEXT: testb $1, %cl
+; KNL-NEXT: testb $1, %al
; KNL-NEXT: fld %st(2)
; KNL-NEXT: fcmovne %st(4), %st
; KNL-NEXT: testb $2, %al
@@ -46,8 +44,7 @@ target triple = "x86_64-unknown-linux-gnu"
; SKX-NEXT: vpmovd2m %xmm0, %k0
; SKX-NEXT: kshiftrb $2, %k0, %k1
; SKX-NEXT: kmovd %k1, %eax
-; SKX-NEXT: kmovd %k1, %ecx
-; SKX-NEXT: testb $1, %cl
+; SKX-NEXT: testb $1, %al
; SKX-NEXT: fld1
; SKX-NEXT: fldz
; SKX-NEXT: fld %st(0)
@@ -56,8 +53,7 @@ target triple = "x86_64-unknown-linux-gnu"
; SKX-NEXT: fld %st(1)
; SKX-NEXT: fcmovne %st(3), %st
; SKX-NEXT: kmovd %k0, %eax
-; SKX-NEXT: kmovd %k0, %ecx
-; SKX-NEXT: testb $1, %cl
+; SKX-NEXT: testb $1, %al
; SKX-NEXT: fld %st(2)
; SKX-NEXT: fcmovne %st(4), %st
; SKX-NEXT: testb $2, %al
diff --git a/llvm/test/CodeGen/X86/pr34177.ll b/llvm/test/CodeGen/X86/pr34177.ll
index c5cd436109b3a4..29922c2ac1a716 100644
--- a/llvm/test/CodeGen/X86/pr34177.ll
+++ b/llvm/test/CodeGen/X86/pr34177.ll
@@ -49,10 +49,9 @@ define void @test(<4 x i64> %a, <4 x x86_fp80> %b, ptr %c) local_unnamed_addr {
; AVX512VL-LABEL: test:
; AVX512VL: # %bb.0:
; AVX512VL-NEXT: vpcmpeqq {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %ymm0, %k0
-; AVX512VL-NEXT: kmovd %k0, %eax
; AVX512VL-NEXT: kshiftrb $2, %k0, %k1
-; AVX512VL-NEXT: kmovd %k0, %ecx
-; AVX512VL-NEXT: testb $2, %cl
+; AVX512VL-NEXT: kmovd %k0, %eax
+; AVX512VL-NEXT: testb $2, %al
; AVX512VL-NEXT: fld1
; AVX512VL-NEXT: fldz
; AVX512VL-NEXT: fld %st(0)
@@ -61,8 +60,7 @@ define void @test(<4 x i64> %a, <4 x x86_fp80> %b, ptr %c) local_unnamed_addr {
; AVX512VL-NEXT: fld %st(1)
; AVX512VL-NEXT: fcmovne %st(3), %st
; AVX512VL-NEXT: kmovd %k1, %eax
-; AVX512VL-NEXT: kmovd %k1, %ecx
-; AVX512VL-NEXT: testb $2, %cl
+; AVX512VL-NEXT: testb $2, %al
; AVX512VL-NEXT: fld %st(2)
; AVX512VL-NEXT: fcmovne %st(4), %st
; AVX512VL-NEXT: testb $1, %al
More information about the llvm-commits
mailing list