[llvm] [VPlan] Don't apply predication discount to non-originally-predicated blocks (PR #160449)

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 2 00:43:03 PDT 2025


================
@@ -1228,6 +1228,27 @@ class LoopVectorizationCostModel {
   /// Superset of instructions that return true for isScalarWithPredication.
   bool isPredicatedInst(Instruction *I) const;
 
+  /// A helper function that returns how much we should divide the cost of a
+  /// predicated block by. Typically this is the reciprocal of the block
+  /// probability, i.e. if we return X we are assuming the predicated block will
+  /// execute once for every X iterations of the loop header so the block should
+  /// only contribute 1/X of its cost to the total cost calculation, but when
+  /// optimizing for code size it will just be 1 as code size costs don't depend
+  /// on execution probabilities.
+  ///
+  /// TODO: We should use actual block probability here, if available.
+  /// Currently, we always assume predicated blocks have a 50% chance of
+  /// executing, apart from blocks that are only predicated due to tail folding.
+  inline unsigned
+  getPredBlockCostDivisor(TargetTransformInfo::TargetCostKind CostKind,
+                          BasicBlock *BB) const {
+    // If a block wasn't originally predicated but was predicated due to
+    // e.g. tail folding, don't divide the cost.
----------------
fhahn wrote:

Can you add a note about the cases where this may not be 100% acurate?

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


More information about the llvm-commits mailing list