[llvm] [VPlan] Pass the mask's compare predicate when costing a blend. (PR #218422)

Elvis Wang via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 24 21:45:57 PDT 2026


================
@@ -3334,9 +3334,16 @@ InstructionCost VPBlendRecipe::computeCost(ElementCount VF,
 
   Type *ResultTy = toVectorTy(this->getScalarType(), VF);
   Type *CmpTy = toVectorTy(Type::getInt1Ty(Ctx.LLVMCtx), VF);
-  return (getNumIncomingValues() - 1) *
-         Ctx.TTI.getCmpSelInstrCost(Instruction::Select, ResultTy, CmpTy,
-                                    CmpInst::BAD_ICMP_PREDICATE, Ctx.CostKind);
+
+  InstructionCost Cost = 0;
+  for (unsigned I = 1, E = getNumIncomingValues(); I != E; ++I) {
+    CmpPredicate Pred;
+    if (!match(getMask(I), m_Cmp(Pred, m_VPValue(), m_VPValue())))
+      Pred = CmpInst::BAD_ICMP_PREDICATE;
+    Cost += Ctx.TTI.getCmpSelInstrCost(Instruction::Select, ResultTy, CmpTy,
----------------
ElvisWang123 wrote:

I think it might be better to initialize `Pred` based on the type. This should help us get more accurate cost calculations on RISC-V.

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


More information about the llvm-commits mailing list