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

David Sherwood via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 26 07:59:44 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,
----------------
david-arm wrote:

Do we have a test for the fcmp case with blend? It would be good to have one I think, since `m_Cmp` includes floating point. I guess you can't write a switch with floating point values, but perhaps there's another way of producing a blend?

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


More information about the llvm-commits mailing list