Skip to content

Commit bee9440

Browse files
committed
[RISCV] Avoid VMNOT by swapping VMERGE operands
1 parent 67b7a25 commit bee9440

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8875,13 +8875,25 @@ SDValue RISCVTargetLowering::lowerVectorMaskExt(SDValue Op, SelectionDAG &DAG,
88758875
MVT I1ContainerVT =
88768876
MVT::getVectorVT(MVT::i1, ContainerVT.getVectorElementCount());
88778877

8878+
bool negated = false;
8879+
if (Src.getOpcode() == ISD::EXTRACT_SUBVECTOR &&
8880+
Src.getOperand(0).getOpcode() ==
8881+
RISCVISD::VMXOR_VL) { // TODO: check xor 1
8882+
negated = true;
8883+
Src = DAG.getNode(ISD::EXTRACT_SUBVECTOR, DL, Src.getValueType(),
8884+
Src.getOperand(0).getOperand(0),
8885+
DAG.getVectorIdxConstant(0, DL));
8886+
}
8887+
88788888
SDValue CC = convertToScalableVector(I1ContainerVT, Src, DAG, Subtarget);
88798889

88808890
SDValue VL = getDefaultVLOps(VecVT, ContainerVT, DL, DAG, Subtarget).second;
88818891

88828892
MVT XLenVT = Subtarget.getXLenVT();
88838893
SDValue SplatZero = DAG.getConstant(0, DL, XLenVT);
88848894
SDValue SplatTrueVal = DAG.getSignedConstant(ExtTrueVal, DL, XLenVT);
8895+
if (negated)
8896+
std::swap(SplatZero, SplatTrueVal);
88858897

88868898
SplatZero = DAG.getNode(RISCVISD::VMV_V_X_VL, DL, ContainerVT,
88878899
DAG.getUNDEF(ContainerVT), SplatZero, VL);

0 commit comments

Comments
 (0)