[llvm] [NFC][Analysis] Drop assertion on zero weights in Distribution (PR #202517)

Aiden Grossman via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 9 00:08:07 PDT 2026


https://github.com/boomanaiden154 created https://github.com/llvm/llvm-project/pull/202517

Distribution can handle zero weights just fine (the shift that is used
for normalization is computed entirely on the total and applied equally
to all weights). This makes the only external use of this
(CodeExtractor.cpp) slightly simpler and will also make upcoming fixes
to TailCallElim slightly simpler as well.


>From ddad8348d68364f2e6eccb8333cc26382362046f Mon Sep 17 00:00:00 2001
From: Aiden Grossman <aidengrossman at google.com>
Date: Tue, 9 Jun 2026 07:07:56 +0000
Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20initia?=
 =?UTF-8?q?l=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.7
---
 llvm/lib/Analysis/BlockFrequencyInfoImpl.cpp | 1 -
 llvm/lib/Transforms/Utils/CodeExtractor.cpp  | 5 +----
 2 files changed, 1 insertion(+), 5 deletions(-)

diff --git a/llvm/lib/Analysis/BlockFrequencyInfoImpl.cpp b/llvm/lib/Analysis/BlockFrequencyInfoImpl.cpp
index 9f6e53ba15b6a..ba8afc8740f88 100644
--- a/llvm/lib/Analysis/BlockFrequencyInfoImpl.cpp
+++ b/llvm/lib/Analysis/BlockFrequencyInfoImpl.cpp
@@ -144,7 +144,6 @@ BlockMass DitheringDistributer::takeMass(uint32_t Weight) {
 
 void Distribution::add(const BlockNode &Node, uint64_t Amount,
                        Weight::DistType Type) {
-  assert(Amount && "invalid weight of 0");
   uint64_t NewTotal = Total + Amount;
 
   // Check for overflow.  It should be impossible to overflow twice.
diff --git a/llvm/lib/Transforms/Utils/CodeExtractor.cpp b/llvm/lib/Transforms/Utils/CodeExtractor.cpp
index 7ffa99878cf74..6a282b7923b4a 100644
--- a/llvm/lib/Transforms/Utils/CodeExtractor.cpp
+++ b/llvm/lib/Transforms/Utils/CodeExtractor.cpp
@@ -1220,10 +1220,7 @@ void CodeExtractor::calculateNewCallTerminatorWeights(
   for (unsigned i = 0, e = TI->getNumSuccessors(); i < e; ++i) {
     BlockNode ExitNode(i);
     uint64_t ExitFreq = ExitWeights.lookup(TI->getSuccessor(i)).getFrequency();
-    if (ExitFreq != 0)
-      BranchDist.addExit(ExitNode, ExitFreq);
-    else
-      EdgeProbabilities[i] = BranchProbability::getZero();
+    BranchDist.addExit(ExitNode, ExitFreq);
   }
 
   // Check for no total weight.



More information about the llvm-commits mailing list