[llvm] [RISCV][VPlan] Cost vp.merges that are likely to be folded away as free (PR #209387)

Luke Lau via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 14 22:56:30 PDT 2026


================
@@ -2319,11 +2319,19 @@ InstructionCost VPWidenIntrinsicRecipe::computeCallCost(
         return toVectorTy(Op->getScalarType(), VF);
       });
 
+  VectorInstrContext VIC = VectorInstrContext::None;
+  for (const VPValue *Op : Operands)
+    if (isa<VPWidenRecipe>(Op) &&
+        Instruction::isBinaryOp(cast<VPWidenRecipe>(Op)->getOpcode())) {
+      VIC = VectorInstrContext::BinaryOp;
+      break;
+    }
+
   // TODO: Rework TTI interface to avoid reliance on underlying IntrinsicInst.
   IntrinsicCostAttributes CostAttrs(
       ID, RetTy, Arguments, ParamTys, R.getFastMathFlagsOrNone(),
----------------
lukel97 wrote:

`Arguments` only gets passed to the TTI when all arguments have an underlying value from the scalar IR, and for vp.merge the mask and EVL argument don't have an underlying value. So it will be empty, even though the true and false operands to the vp.merge have underlying values. 

In general value-based cost modelling is pretty fragile, there's a comment above to move away from it: `// TODO: Rework TTI interface to be independent of concrete IR values.`

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


More information about the llvm-commits mailing list