[llvm] [RISCV][CostModel] Updates reduction and shuffle cost (PR #77342)

Philip Reames via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 22 07:49:21 PST 2024


================
@@ -1358,19 +1358,51 @@ RISCVTTIImpl::getMinMaxReductionCost(Intrinsic::ID IID, VectorType *Ty,
     return BaseT::getMinMaxReductionCost(IID, Ty, FMF, CostKind);
 
   std::pair<InstructionCost, MVT> LT = getTypeLegalizationCost(Ty);
-  if (Ty->getElementType()->isIntegerTy(1))
-    // vcpop sequences, see vreduction-mask.ll.  umax, smin actually only
-    // cost 2, but we don't have enough info here so we slightly over cost.
-    return (LT.first - 1) + 3;
+  if (Ty->getElementType()->isIntegerTy(1)) {
+    // vcpop sequences, see vreduction-mask.ll.
+    if ((IID == Intrinsic::umax) || (IID == Intrinsic::smin))
+      return getArithmeticReductionCost(Instruction::Or, Ty, FMF, CostKind);
+    else
+      return getArithmeticReductionCost(Instruction::And, Ty, FMF, CostKind);
+  }
 
   // IR Reduction is composed by two vmv and one rvv reduction instruction.
-  InstructionCost BaseCost = 2;
-
-  if (CostKind == TTI::TCK_CodeSize)
-    return (LT.first - 1) + BaseCost;
-
-  unsigned VL = getEstimatedVLFor(Ty);
----------------
preames wrote:

The net effect of this change appears to be to increase BaseCost by 1, make the reduction linear in lmul, and remove the log2(VL) term.  

This bit (maybe with the other reduction change) needs to be it's own review so we can clearly see the effect.  This one (in particular), you should also try running through some reasonable large codebase (llvm test-suite, spec, whatever) and checking for unexpected interactions.

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


More information about the llvm-commits mailing list