[llvm] b20c1ff - [X86] combinePTESTCC - remove unnecessary legal vector type assertion
Simon Pilgrim via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 12 03:04:01 PDT 2023
Author: Simon Pilgrim
Date: 2023-04-12T11:03:50+01:00
New Revision: b20c1ffe8f3e18367b6b460c32a6d78518198a1f
URL: https://github.com/llvm/llvm-project/commit/b20c1ffe8f3e18367b6b460c32a6d78518198a1f
DIFF: https://github.com/llvm/llvm-project/commit/b20c1ffe8f3e18367b6b460c32a6d78518198a1f.diff
LOG: [X86] combinePTESTCC - remove unnecessary legal vector type assertion
Most of these folds bitcast to the PTEST operand type anyway, and its only relevant for the PTEST->MOVMSK fold, which I'm looking at expanding to attempt to fold to PTEST->TESTP as well.
Noticed while beginning triage of Issue #60007
Added:
Modified:
llvm/lib/Target/X86/X86ISelLowering.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp b/llvm/lib/Target/X86/X86ISelLowering.cpp
index 21e968934cd1a..dcd9d6900427d 100644
--- a/llvm/lib/Target/X86/X86ISelLowering.cpp
+++ b/llvm/lib/Target/X86/X86ISelLowering.cpp
@@ -47321,8 +47321,6 @@ static SDValue combinePTESTCC(SDValue EFLAGS, X86::CondCode &CC,
if (Op0 == Op1) {
SDValue BC = peekThroughBitcasts(Op0);
EVT BCVT = BC.getValueType();
- assert(BCVT.isVector() && DAG.getTargetLoweringInfo().isTypeLegal(BCVT) &&
- "Unexpected vector type");
// TESTZ(AND(X,Y),AND(X,Y)) == TESTZ(X,Y)
if (BC.getOpcode() == ISD::AND || BC.getOpcode() == X86ISD::FAND) {
@@ -47342,29 +47340,32 @@ static SDValue combinePTESTCC(SDValue EFLAGS, X86::CondCode &CC,
// If every element is an all-sign value, see if we can use MOVMSK to
// more efficiently extract the sign bits and compare that.
// TODO: Handle TESTC with comparison inversion.
+ // TODO: When can we use TESTPS/TESTPD instead?
// TODO: Can we remove SimplifyMultipleUseDemandedBits and rely on
// MOVMSK combines to make sure its never worse than PTEST?
- unsigned EltBits = BCVT.getScalarSizeInBits();
- if (DAG.ComputeNumSignBits(BC) == EltBits) {
- assert(VT == MVT::i32 && "Expected i32 EFLAGS comparison result");
- APInt SignMask = APInt::getSignMask(EltBits);
- const TargetLowering &TLI = DAG.getTargetLoweringInfo();
- if (SDValue Res =
- TLI.SimplifyMultipleUseDemandedBits(BC, SignMask, DAG)) {
- // For vXi16 cases we need to use pmovmksb and extract every other
- // sign bit.
- SDLoc DL(EFLAGS);
- if (EltBits == 16) {
- MVT MovmskVT = BCVT.is128BitVector() ? MVT::v16i8 : MVT::v32i8;
- Res = DAG.getBitcast(MovmskVT, Res);
- Res = getPMOVMSKB(DL, Res, DAG, Subtarget);
- Res = DAG.getNode(ISD::AND, DL, MVT::i32, Res,
- DAG.getConstant(0xAAAAAAAA, DL, MVT::i32));
- } else {
- Res = getPMOVMSKB(DL, Res, DAG, Subtarget);
+ if (BCVT.isVector() && DAG.getTargetLoweringInfo().isTypeLegal(BCVT)) {
+ unsigned EltBits = BCVT.getScalarSizeInBits();
+ if (DAG.ComputeNumSignBits(BC) == EltBits) {
+ assert(VT == MVT::i32 && "Expected i32 EFLAGS comparison result");
+ APInt SignMask = APInt::getSignMask(EltBits);
+ const TargetLowering &TLI = DAG.getTargetLoweringInfo();
+ if (SDValue Res =
+ TLI.SimplifyMultipleUseDemandedBits(BC, SignMask, DAG)) {
+ // For vXi16 cases we need to use pmovmksb and extract every other
+ // sign bit.
+ SDLoc DL(EFLAGS);
+ if (EltBits == 16) {
+ MVT MovmskVT = BCVT.is128BitVector() ? MVT::v16i8 : MVT::v32i8;
+ Res = DAG.getBitcast(MovmskVT, Res);
+ Res = getPMOVMSKB(DL, Res, DAG, Subtarget);
+ Res = DAG.getNode(ISD::AND, DL, MVT::i32, Res,
+ DAG.getConstant(0xAAAAAAAA, DL, MVT::i32));
+ } else {
+ Res = getPMOVMSKB(DL, Res, DAG, Subtarget);
+ }
+ return DAG.getNode(X86ISD::CMP, DL, MVT::i32, Res,
+ DAG.getConstant(0, DL, MVT::i32));
}
- return DAG.getNode(X86ISD::CMP, DL, MVT::i32, Res,
- DAG.getConstant(0, DL, MVT::i32));
}
}
}
More information about the llvm-commits
mailing list