Skip to content

[RISCV] Support non-power-of-2 types when expanding memcmp #114971

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions llvm/lib/Target/RISCV/RISCVISelLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16165,10 +16165,6 @@ combineVectorSizedSetCCEquality(EVT VT, SDValue X, SDValue Y, ISD::CondCode CC,
return SDValue();

unsigned OpSize = OpVT.getSizeInBits();
// TODO: Support non-power-of-2 types.
if (!isPowerOf2_32(OpSize))
return SDValue();

// The size should be larger than XLen and smaller than the maximum vector
// size.
if (OpSize <= Subtarget.getXLen() ||
Expand All @@ -16190,13 +16186,20 @@ combineVectorSizedSetCCEquality(EVT VT, SDValue X, SDValue Y, ISD::CondCode CC,
return SDValue();

unsigned VecSize = OpSize / 8;
EVT VecVT = MVT::getVectorVT(MVT::i8, VecSize);
EVT CmpVT = MVT::getVectorVT(MVT::i1, VecSize);
EVT VecVT = EVT::getVectorVT(*DAG.getContext(), MVT::i8, VecSize);
EVT CmpVT = EVT::getVectorVT(*DAG.getContext(), MVT::i1, VecSize);

SDValue VecX = DAG.getBitcast(VecVT, X);
SDValue VecY = DAG.getBitcast(VecVT, Y);
SDValue Cmp = DAG.getSetCC(DL, CmpVT, VecX, VecY, ISD::SETNE);
return DAG.getSetCC(DL, VT, DAG.getNode(ISD::VECREDUCE_OR, DL, XLenVT, Cmp),
SDValue Mask = DAG.getAllOnesConstant(DL, CmpVT);
SDValue VL = DAG.getConstant(VecSize, DL, XLenVT);

SDValue Cmp = DAG.getNode(ISD::VP_SETCC, DL, CmpVT, VecX, VecY,
DAG.getCondCode(ISD::SETNE), Mask, VL);
return DAG.getSetCC(DL, VT,
DAG.getNode(ISD::VP_REDUCE_OR, DL, XLenVT,
DAG.getConstant(0, DL, XLenVT), Cmp, Mask,
VL),
DAG.getConstant(0, DL, XLenVT), CC);
}

Expand Down
21 changes: 7 additions & 14 deletions llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2954,20 +2954,13 @@ RISCVTTIImpl::enableMemCmpExpansion(bool OptSize, bool IsZeroCmp) const {
}

if (IsZeroCmp && ST->hasVInstructions()) {
unsigned RealMinVLen = ST->getRealMinVLen();
// Support Fractional LMULs if the lengths are larger than XLen.
// TODO: Support non-power-of-2 types.
for (unsigned FLMUL = 8; FLMUL >= 2; FLMUL /= 2) {
unsigned Len = RealMinVLen / FLMUL;
if (Len > ST->getXLen())
Options.LoadSizes.insert(Options.LoadSizes.begin(), Len / 8);
}
for (unsigned LMUL = 1; LMUL <= ST->getMaxLMULForFixedLengthVectors();
LMUL *= 2) {
unsigned Len = RealMinVLen * LMUL;
if (Len > ST->getXLen())
Options.LoadSizes.insert(Options.LoadSizes.begin(), Len / 8);
}
unsigned VLenB = ST->getRealMinVLen() / 8;
// The minimum size should be the maximum bytes between `VLen * LMUL_MF8`
// and `XLen * 2`.
unsigned MinSize = std::max(VLenB / 8, ST->getXLen() * 2 / 8);
for (unsigned Size = MinSize;
Size <= VLenB * ST->getMaxLMULForFixedLengthVectors(); Size++)
Options.LoadSizes.insert(Options.LoadSizes.begin(), Size);
}
return Options;
}
Loading
Loading