Skip to content

Commit

Permalink
[RISCV] Minor style fixes in lowerVectorMaskVecReduction [nfc]
Browse files Browse the repository at this point in the history
Reuse existing routine to avoid duplication, and reduce variable scopes.
  • Loading branch information
preames authored and cjdb committed Aug 23, 2024
1 parent 80c3460 commit 13be345
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions llvm/lib/Target/RISCV/RISCVISelLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9409,10 +9409,7 @@ SDValue RISCVTargetLowering::lowerVectorMaskVecReduction(SDValue Op,
getDefaultVLOps(VecVT, ContainerVT, DL, DAG, Subtarget);
}

unsigned BaseOpc;
ISD::CondCode CC;
SDValue Zero = DAG.getConstant(0, DL, XLenVT);

switch (Op.getOpcode()) {
default:
llvm_unreachable("Unhandled reduction");
Expand All @@ -9423,15 +9420,13 @@ SDValue RISCVTargetLowering::lowerVectorMaskVecReduction(SDValue Op,
Vec = DAG.getNode(RISCVISD::VMXOR_VL, DL, ContainerVT, Vec, TrueMask, VL);
Vec = DAG.getNode(RISCVISD::VCPOP_VL, DL, XLenVT, Vec, Mask, VL);
CC = ISD::SETEQ;
BaseOpc = ISD::AND;
break;
}
case ISD::VECREDUCE_OR:
case ISD::VP_REDUCE_OR:
// vcpop x != 0
Vec = DAG.getNode(RISCVISD::VCPOP_VL, DL, XLenVT, Vec, Mask, VL);
CC = ISD::SETNE;
BaseOpc = ISD::OR;
break;
case ISD::VECREDUCE_XOR:
case ISD::VP_REDUCE_XOR: {
Expand All @@ -9440,11 +9435,11 @@ SDValue RISCVTargetLowering::lowerVectorMaskVecReduction(SDValue Op,
Vec = DAG.getNode(RISCVISD::VCPOP_VL, DL, XLenVT, Vec, Mask, VL);
Vec = DAG.getNode(ISD::AND, DL, XLenVT, Vec, One);
CC = ISD::SETNE;
BaseOpc = ISD::XOR;
break;
}
}

SDValue Zero = DAG.getConstant(0, DL, XLenVT);
SDValue SetCC = DAG.getSetCC(DL, XLenVT, Vec, Zero, CC);
SetCC = DAG.getNode(ISD::TRUNCATE, DL, Op.getValueType(), SetCC);

Expand All @@ -9457,6 +9452,7 @@ SDValue RISCVTargetLowering::lowerVectorMaskVecReduction(SDValue Op,
// 0 for an inactive vector, and so we've already received the neutral value:
// AND gives us (0 == 0) -> 1 and OR/XOR give us (0 != 0) -> 0. Therefore we
// can simply include the start value.
unsigned BaseOpc = ISD::getVecReduceBaseOpcode(Op.getOpcode());
return DAG.getNode(BaseOpc, DL, Op.getValueType(), SetCC, Op.getOperand(0));
}

Expand Down

0 comments on commit 13be345

Please sign in to comment.