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

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


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-transforms

@llvm/pr-subscribers-llvm-analysis

Author: Aiden Grossman (boomanaiden154)

<details>
<summary>Changes</summary>

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.


---
Full diff: https://github.com/llvm/llvm-project/pull/202517.diff


2 Files Affected:

- (modified) llvm/lib/Analysis/BlockFrequencyInfoImpl.cpp (-1) 
- (modified) llvm/lib/Transforms/Utils/CodeExtractor.cpp (+1-4) 


``````````diff
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.

``````````

</details>


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


More information about the llvm-commits mailing list