[llvm] [VPlan] Give zero-weight edges minimum probability. (PR #226150)

Luke Lau via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 28 02:06:30 PDT 2026


================
@@ -1222,6 +1222,10 @@ getSuccessorProbabilities(const VPBasicBlock *VPBB) {
     auto [Succ, Weight] = SuccWeight;
     if (Total == 0)
       return std::make_pair(Succ, BranchProbability::getUnknown());
+    // Like BlockFrequencyInfo, treat zero branch weights cold, not as never
+    // taken.
+    if (Weight == 0)
+      return std::make_pair(Succ, BranchProbability::getRaw(1));
----------------
lukel97 wrote:

> I don't follow, why not return [Succ, 0]?

Returning a 0 execution frequency prevents the scalar cost model from being able to divide the cost, since 0 is treated as "no frequency recorded", see https://github.com/llvm/llvm-project/pull/196845#pullrequestreview-5294734685. In the previous legacy cost model which used BFI directly it rounded up 0 frequencies to 1

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


More information about the llvm-commits mailing list