[llvm] [RISCV] custom scmp(x, 0) and scmp(0, x) lowering for RVV (PR #151753)
Luke Lau via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 4 01:05:56 PDT 2025
================
@@ -8223,6 +8225,40 @@ SDValue RISCVTargetLowering::LowerOperation(SDValue Op,
case ISD::SADDSAT:
case ISD::SSUBSAT:
return lowerToScalableOp(Op, DAG);
+ case ISD::SCMP: {
+ SDLoc DL(Op);
+ EVT VT = Op->getValueType(0);
+ EVT CCVT = getSetCCResultType(DAG.getDataLayout(), *DAG.getContext(), VT);
+
+ SDValue LHS = DAG.getFreeze(Op->getOperand(0));
+ SDValue RHS = DAG.getFreeze(Op->getOperand(1));
+ unsigned SEW = VT.getScalarSizeInBits();
+
+ SDValue Shift = DAG.getConstant(SEW-1, DL, VT);
+ SDValue Zero = DAG.getConstant(0, DL, VT);
+ SDValue One = DAG.getConstant(1, DL, VT);
+ SDValue MinusOne = DAG.getAllOnesConstant(DL, VT);
+
+ if (ISD::isConstantSplatVectorAllZeros(RHS.getNode())) {
+ SDValue Sra = DAG.getNode(ISD::SRA, DL, VT, LHS, Shift);
+ if (SEW <= 32) {
+ // scmp(lhs, 0) -> vor.vv(vsra.vi(lhs,SEW-1), vmin.vx(lhs,1))
----------------
lukel97 wrote:
Using an extra GPR to avoid clobbering V0 for SEW=64 sounds reasonable to me. If this happens in a loop the li is likely going to be hoisted out anyway.
https://github.com/llvm/llvm-project/pull/151753
More information about the llvm-commits
mailing list