Skip to content

Commit c28487e

Browse files
committed
Revert "[RISCV] Support memcmp expansion for vectors"
This reverts commit 4903c11.
1 parent df1194a commit c28487e

File tree

4 files changed

+552
-2474
lines changed

4 files changed

+552
-2474
lines changed

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

Lines changed: 6 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -16172,80 +16172,17 @@ static bool narrowIndex(SDValue &N, ISD::MemIndexType IndexType, SelectionDAG &D
1617216172
return true;
1617316173
}
1617416174

16175-
/// Try to map an integer comparison with size > XLEN to vector instructions
16176-
/// before type legalization splits it up into chunks.
16177-
static SDValue
16178-
combineVectorSizedSetCCEquality(EVT VT, SDValue X, SDValue Y, ISD::CondCode CC,
16179-
const SDLoc &DL, SelectionDAG &DAG,
16180-
const RISCVSubtarget &Subtarget) {
16181-
assert(ISD::isIntEqualitySetCC(CC) && "Bad comparison predicate");
16182-
16183-
if (!Subtarget.hasVInstructions())
16184-
return SDValue();
16185-
16186-
MVT XLenVT = Subtarget.getXLenVT();
16187-
EVT OpVT = X.getValueType();
16188-
// We're looking for an oversized integer equality comparison.
16189-
if (!OpVT.isScalarInteger())
16190-
return SDValue();
16191-
16192-
unsigned OpSize = OpVT.getSizeInBits();
16193-
// TODO: Support non-power-of-2 types.
16194-
if (!isPowerOf2_32(OpSize))
16195-
return SDValue();
16196-
16197-
// The size should be larger than XLen and smaller than the maximum vector
16198-
// size.
16199-
if (OpSize <= Subtarget.getXLen() ||
16200-
OpSize > Subtarget.getRealMinVLen() *
16201-
Subtarget.getMaxLMULForFixedLengthVectors())
16202-
return SDValue();
16203-
16204-
// Don't perform this combine if constructing the vector will be expensive.
16205-
auto IsVectorBitCastCheap = [](SDValue X) {
16206-
X = peekThroughBitcasts(X);
16207-
return isa<ConstantSDNode>(X) || X.getValueType().isVector() ||
16208-
X.getOpcode() == ISD::LOAD;
16209-
};
16210-
if (!IsVectorBitCastCheap(X) || !IsVectorBitCastCheap(Y))
16211-
return SDValue();
16212-
16213-
if (DAG.getMachineFunction().getFunction().hasFnAttribute(
16214-
Attribute::NoImplicitFloat))
16215-
return SDValue();
16216-
16217-
unsigned VecSize = OpSize / 8;
16218-
EVT VecVT = MVT::getVectorVT(MVT::i8, VecSize);
16219-
EVT CmpVT = MVT::getVectorVT(MVT::i1, VecSize);
16220-
16221-
SDValue VecX = DAG.getBitcast(VecVT, X);
16222-
SDValue VecY = DAG.getBitcast(VecVT, Y);
16223-
SDValue Cmp = DAG.getSetCC(DL, CmpVT, VecX, VecY, ISD::SETNE);
16224-
return DAG.getSetCC(DL, VT, DAG.getNode(ISD::VECREDUCE_OR, DL, XLenVT, Cmp),
16225-
DAG.getConstant(0, DL, XLenVT), CC);
16226-
}
16227-
1622816175
// Replace (seteq (i64 (and X, 0xffffffff)), C1) with
1622916176
// (seteq (i64 (sext_inreg (X, i32)), C1')) where C1' is C1 sign extended from
1623016177
// bit 31. Same for setne. C1' may be cheaper to materialize and the sext_inreg
1623116178
// can become a sext.w instead of a shift pair.
1623216179
static SDValue performSETCCCombine(SDNode *N, SelectionDAG &DAG,
1623316180
const RISCVSubtarget &Subtarget) {
16234-
SDLoc dl(N);
1623516181
SDValue N0 = N->getOperand(0);
1623616182
SDValue N1 = N->getOperand(1);
1623716183
EVT VT = N->getValueType(0);
1623816184
EVT OpVT = N0.getValueType();
1623916185

16240-
ISD::CondCode Cond = cast<CondCodeSDNode>(N->getOperand(2))->get();
16241-
// Looking for an equality compare.
16242-
if (!isIntEqualitySetCC(Cond))
16243-
return SDValue();
16244-
16245-
if (SDValue V =
16246-
combineVectorSizedSetCCEquality(VT, N0, N1, Cond, dl, DAG, Subtarget))
16247-
return V;
16248-
1624916186
if (OpVT != MVT::i64 || !Subtarget.is64Bit())
1625016187
return SDValue();
1625116188

@@ -16260,6 +16197,11 @@ static SDValue performSETCCCombine(SDNode *N, SelectionDAG &DAG,
1626016197
N0.getConstantOperandVal(1) != UINT64_C(0xffffffff))
1626116198
return SDValue();
1626216199

16200+
// Looking for an equality compare.
16201+
ISD::CondCode Cond = cast<CondCodeSDNode>(N->getOperand(2))->get();
16202+
if (!isIntEqualitySetCC(Cond))
16203+
return SDValue();
16204+
1626316205
// Don't do this if the sign bit is provably zero, it will be turned back into
1626416206
// an AND.
1626516207
APInt SignMask = APInt::getOneBitSet(64, 31);
@@ -16268,6 +16210,7 @@ static SDValue performSETCCCombine(SDNode *N, SelectionDAG &DAG,
1626816210

1626916211
const APInt &C1 = N1C->getAPIntValue();
1627016212

16213+
SDLoc dl(N);
1627116214
// If the constant is larger than 2^32 - 1 it is impossible for both sides
1627216215
// to be equal.
1627316216
if (C1.getActiveBits() > 32)

llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2983,22 +2983,5 @@ RISCVTTIImpl::enableMemCmpExpansion(bool OptSize, bool IsZeroCmp) const {
29832983
Options.LoadSizes = {4, 2, 1};
29842984
Options.AllowedTailExpansions = {3};
29852985
}
2986-
2987-
if (IsZeroCmp && ST->hasVInstructions()) {
2988-
unsigned RealMinVLen = ST->getRealMinVLen();
2989-
// Support Fractional LMULs if the lengths are larger than XLen.
2990-
// TODO: Support non-power-of-2 types.
2991-
for (unsigned FLMUL = 8; FLMUL >= 2; FLMUL /= 2) {
2992-
unsigned Len = RealMinVLen / FLMUL;
2993-
if (Len > ST->getXLen())
2994-
Options.LoadSizes.insert(Options.LoadSizes.begin(), Len / 8);
2995-
}
2996-
for (unsigned LMUL = 1; LMUL <= ST->getMaxLMULForFixedLengthVectors();
2997-
LMUL *= 2) {
2998-
unsigned Len = RealMinVLen * LMUL;
2999-
if (Len > ST->getXLen())
3000-
Options.LoadSizes.insert(Options.LoadSizes.begin(), Len / 8);
3001-
}
3002-
}
30032986
return Options;
30042987
}

0 commit comments

Comments
 (0)