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

Luke Lau via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 24 07:23:09 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 think this will still leave the other non-zero siblings as having 100% probabilities, so setExecutionFrequency won't record anything for it.

I think BFI normalizes all the branch weights beforehand, e.g. compute probabilities first, then `prob(x) <= umax(1, prob(x))`, then divides the probabilities by the new sum. That should also prevent the new probabilities from not summing to 1.

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


More information about the llvm-commits mailing list