[llvm] [RISCV] Fixed redundant add instructions generated during the fold of vscale add in rvv. (PR #225266)

via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 30 06:48:16 PDT 2026


================
@@ -2153,6 +2153,22 @@ MVT RISCVTargetLowering::getVPExplicitVectorLengthTy() const {
   return Subtarget.getXLenVT();
 }
 
+// Return false to lower the fold of vscale add to RISCV.
+bool RISCVTargetLowering::isDesirableToFoldVScaleAdd(const SDNode *N) const {
+  // Fold (add (add A, (vscale C1)), (vscale C2))
+  //   -> (add A, (vscale (C1 + C2)))
+  // Optimize only when (add A, (vscale C1)) is not reused.
+  SDValue N0 = N->getOperand(0);
+  SDValue N1 = N->getOperand(1);
+
+  if (N0.getOpcode() == ISD::ADD &&
----------------
FoolgryGamer wrote:

I move the check to `DAGCombine.cpp` to avoid redundant code. Thanks for advice.

https://github.com/llvm/llvm-project/pull/225266


More information about the llvm-commits mailing list