[llvm] 1e155ce - [X86] SimplifyDemandedBitsForTargetNode - add TESTPS/TESTPD support
Simon Pilgrim via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 12 03:54:39 PDT 2023
Author: Simon Pilgrim
Date: 2023-04-12T11:54:23+01:00
New Revision: 1e155ce9cd204621949347bb73630873efacda47
URL: https://github.com/llvm/llvm-project/commit/1e155ce9cd204621949347bb73630873efacda47
DIFF: https://github.com/llvm/llvm-project/commit/1e155ce9cd204621949347bb73630873efacda47.diff
LOG: [X86] SimplifyDemandedBitsForTargetNode - add TESTPS/TESTPD support
We only need the sign bits from these nodes
Another step towards Issue #60007
Added:
Modified:
llvm/lib/Target/X86/X86ISelLowering.cpp
llvm/test/CodeGen/X86/combine-testpd.ll
llvm/test/CodeGen/X86/combine-testps.ll
Removed:
################################################################################
diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp b/llvm/lib/Target/X86/X86ISelLowering.cpp
index dcd9d6900427..0a0918139b3d 100644
--- a/llvm/lib/Target/X86/X86ISelLowering.cpp
+++ b/llvm/lib/Target/X86/X86ISelLowering.cpp
@@ -43742,6 +43742,20 @@ bool X86TargetLowering::SimplifyDemandedBitsForTargetNode(
return TLO.CombineTo(Op, TLO.DAG.getNode(Opc, SDLoc(Op), VT, NewSrc));
return false;
}
+ case X86ISD::TESTP: {
+ SDValue Op0 = Op.getOperand(0);
+ SDValue Op1 = Op.getOperand(1);
+ MVT OpVT = Op0.getSimpleValueType();
+ assert((OpVT.getVectorElementType() == MVT::f32 ||
+ OpVT.getVectorElementType() == MVT::f64) &&
+ "Illegal vector type for X86ISD::TESTP");
+
+ // TESTPS/TESTPD only demands the sign bits of ALL the elements.
+ KnownBits KnownSrc;
+ APInt SignMask = APInt::getSignMask(OpVT.getScalarSizeInBits());
+ return SimplifyDemandedBits(Op0, SignMask, KnownSrc, TLO, Depth + 1) ||
+ SimplifyDemandedBits(Op1, SignMask, KnownSrc, TLO, Depth + 1);
+ }
case X86ISD::BEXTR:
case X86ISD::BEXTRI: {
SDValue Op0 = Op.getOperand(0);
@@ -54658,6 +54672,21 @@ static SDValue combineMOVMSK(SDNode *N, SelectionDAG &DAG,
return SDValue();
}
+static SDValue combineTESTP(SDNode *N, SelectionDAG &DAG,
+ TargetLowering::DAGCombinerInfo &DCI,
+ const X86Subtarget &Subtarget) {
+ MVT VT = N->getSimpleValueType(0);
+ unsigned NumBits = VT.getScalarSizeInBits();
+
+ // Simplify the inputs.
+ const TargetLowering &TLI = DAG.getTargetLoweringInfo();
+ APInt DemandedMask(APInt::getAllOnes(NumBits));
+ if (TLI.SimplifyDemandedBits(SDValue(N, 0), DemandedMask, DCI))
+ return SDValue(N, 0);
+
+ return SDValue();
+}
+
static SDValue combineX86GatherScatter(SDNode *N, SelectionDAG &DAG,
TargetLowering::DAGCombinerInfo &DCI,
const X86Subtarget &Subtarget) {
@@ -57545,6 +57574,7 @@ SDValue X86TargetLowering::PerformDAGCombine(SDNode *N,
case X86ISD::FMADDSUB:
case X86ISD::FMSUBADD: return combineFMADDSUB(N, DAG, DCI);
case X86ISD::MOVMSK: return combineMOVMSK(N, DAG, DCI, Subtarget);
+ case X86ISD::TESTP: return combineTESTP(N, DAG, DCI, Subtarget);
case X86ISD::MGATHER:
case X86ISD::MSCATTER:
return combineX86GatherScatter(N, DAG, DCI, Subtarget);
diff --git a/llvm/test/CodeGen/X86/combine-testpd.ll b/llvm/test/CodeGen/X86/combine-testpd.ll
index 2ca0ece3c8a0..3a7fbd5f368b 100644
--- a/llvm/test/CodeGen/X86/combine-testpd.ll
+++ b/llvm/test/CodeGen/X86/combine-testpd.ll
@@ -157,8 +157,6 @@ define i32 @testpdc_128_signbit(<2 x double> %c, <2 x double> %d, i32 %a, i32 %b
; CHECK-LABEL: testpdc_128_signbit:
; CHECK: # %bb.0:
; CHECK-NEXT: movl %edi, %eax
-; CHECK-NEXT: vpxor %xmm2, %xmm2, %xmm2
-; CHECK-NEXT: vpcmpgtq %xmm0, %xmm2, %xmm0
; CHECK-NEXT: vtestpd %xmm1, %xmm0
; CHECK-NEXT: cmovael %esi, %eax
; CHECK-NEXT: retq
@@ -175,11 +173,6 @@ define i32 @testpdz_256_signbit(<4 x double> %c, <4 x double> %d, i32 %a, i32 %b
; CHECK-LABEL: testpdz_256_signbit:
; CHECK: # %bb.0:
; CHECK-NEXT: movl %edi, %eax
-; CHECK-NEXT: vextractf128 $1, %ymm0, %xmm2
-; CHECK-NEXT: vpxor %xmm3, %xmm3, %xmm3
-; CHECK-NEXT: vpcmpgtq %xmm2, %xmm3, %xmm2
-; CHECK-NEXT: vpcmpgtq %xmm0, %xmm3, %xmm0
-; CHECK-NEXT: vinsertf128 $1, %xmm2, %ymm0, %ymm0
; CHECK-NEXT: vtestpd %ymm1, %ymm0
; CHECK-NEXT: cmovnel %esi, %eax
; CHECK-NEXT: vzeroupper
diff --git a/llvm/test/CodeGen/X86/combine-testps.ll b/llvm/test/CodeGen/X86/combine-testps.ll
index 66e5fe12876d..6f508f05ac14 100644
--- a/llvm/test/CodeGen/X86/combine-testps.ll
+++ b/llvm/test/CodeGen/X86/combine-testps.ll
@@ -157,7 +157,6 @@ define i32 @testpsz_128_signbit(<4 x float> %c, <4 x float> %d, i32 %a, i32 %b)
; CHECK-LABEL: testpsz_128_signbit:
; CHECK: # %bb.0:
; CHECK-NEXT: movl %edi, %eax
-; CHECK-NEXT: vpsrad $31, %xmm0, %xmm0
; CHECK-NEXT: vtestps %xmm1, %xmm0
; CHECK-NEXT: cmovnel %esi, %eax
; CHECK-NEXT: retq
@@ -174,11 +173,6 @@ define i32 @testpsnzc_256_signbit(<8 x float> %c, <8 x float> %d, i32 %a, i32 %b
; CHECK-LABEL: testpsnzc_256_signbit:
; CHECK: # %bb.0:
; CHECK-NEXT: movl %edi, %eax
-; CHECK-NEXT: vextractf128 $1, %ymm0, %xmm2
-; CHECK-NEXT: vpxor %xmm3, %xmm3, %xmm3
-; CHECK-NEXT: vpcmpgtd %xmm2, %xmm3, %xmm2
-; CHECK-NEXT: vpcmpgtd %xmm0, %xmm3, %xmm0
-; CHECK-NEXT: vinsertf128 $1, %xmm2, %ymm0, %ymm0
; CHECK-NEXT: vtestps %ymm1, %ymm0
; CHECK-NEXT: cmovnel %esi, %eax
; CHECK-NEXT: vzeroupper
More information about the llvm-commits
mailing list