[llvm] [LV][VPlan] Implement VPlan-based cost for exit condition. (PR #125640)
    Florian Hahn via llvm-commits 
    llvm-commits at lists.llvm.org
       
    Tue Feb  4 13:15:11 PST 2025
    
    
  
================
@@ -823,6 +823,29 @@ bool VPInstruction::onlyFirstPartUsed(const VPValue *Op) const {
   llvm_unreachable("switch should return");
 }
 
+InstructionCost VPInstruction::computeCost(ElementCount VF,
+                                           VPCostContext &Ctx) const {
+  Type *ValTy = Ctx.Types.inferScalarType(getOperand(0));
+
+  switch (getOpcode()) {
+  case VPInstruction::BranchOnCount: {
+    // BranchOnCount will genearte icmp_eq + br instructions and the
+    // cost of branch will be calculated in VPRegionBlock.
+    // If the vector loop only executed once, ignore the cost of the cmp.
+    auto TC = dyn_cast_if_present<ConstantInt>(
+        getParent()->getPlan()->getTripCount()->getUnderlyingValue());
+    if (TC && VF.isFixed() && TC->getSExtValue() == VF.getFixedValue())
+      return 0;
----------------
fhahn wrote:
Why is this needed here?
https://github.com/llvm/llvm-project/pull/125640
    
    
More information about the llvm-commits
mailing list