[llvm] 33b5894 - [BFI] Preserve zero-mass exits in solveIrreducibleMass (#218140)
via llvm-commits
llvm-commits at lists.llvm.org
Sat Aug 22 16:21:32 PDT 2026
Author: ʟᴜɴᴇx
Date: 2026-08-22T23:21:26Z
New Revision: 33b589426c06be42839b3284d04d3b2caf4a5fc1
URL: https://github.com/llvm/llvm-project/commit/33b589426c06be42839b3284d04d3b2caf4a5fc1
DIFF: https://github.com/llvm/llvm-project/commit/33b589426c06be42839b3284d04d3b2caf4a5fc1.diff
LOG: [BFI] Preserve zero-mass exits in solveIrreducibleMass (#218140)
Fixes #217740.
Keep zero-mass exits in `solveIrreducibleMass`.
Although their mass is zero, these exits are later reused when building
enclosing irreducible SCCs... dropping them can change SCC membership
and eventually trigger the "**unhandled irreducible control flow**"
assertion.
---------
Co-authored-by: Fangrui Song <i at maskray.me>
Added:
Modified:
llvm/include/llvm/Analysis/BlockFrequencyInfoImpl.h
llvm/test/Analysis/BlockFrequencyInfo/irreducible.ll
Removed:
################################################################################
diff --git a/llvm/include/llvm/Analysis/BlockFrequencyInfoImpl.h b/llvm/include/llvm/Analysis/BlockFrequencyInfoImpl.h
index 2df013fbd6375..29be24ce0c32a 100644
--- a/llvm/include/llvm/Analysis/BlockFrequencyInfoImpl.h
+++ b/llvm/include/llvm/Analysis/BlockFrequencyInfoImpl.h
@@ -1250,8 +1250,6 @@ void BlockFrequencyInfoImpl<BT>::solveIrreducibleMass(LoopData &Loop) {
BlockMass TotalExit;
for (auto [I, Succ, Pr] : Ex) {
uint64_t M = (F[I] * Pr).scale(UINT64_MAX);
- if (!M)
- continue;
Loop.Exits.emplace_back(Succ, BlockMass(M));
TotalExit += BlockMass(M);
}
diff --git a/llvm/test/Analysis/BlockFrequencyInfo/irreducible.ll b/llvm/test/Analysis/BlockFrequencyInfo/irreducible.ll
index da52da4bb1213..e7e15d48c3cea 100644
--- a/llvm/test/Analysis/BlockFrequencyInfo/irreducible.ll
+++ b/llvm/test/Analysis/BlockFrequencyInfo/irreducible.ll
@@ -522,3 +522,42 @@ exit:
; CHECK-NEXT: exit: float = 1.0, int = [[ENTRY]]
ret void
}
+
+;; The irreducible SCC {h1, h2, c1, c2} inside the natural loop lh exits to e2
+;; with a mass that rounds to zero. Dropping that exit leaves the lh package
+;; with no successors, hiding the function-level SCC {e1, e2, lh}.
+define void @zero_mass_exit(i1 %x) {
+; CHECK-LABEL: block-frequency-info: zero_mass_exit
+entry:
+; CHECK-NEXT: entry: float = 1.0, int = [[ENTRY:[0-9]+]]
+ br i1 %x, label %e1, label %e2
+
+e1:
+; CHECK-NEXT: e1: float = 1365.3,
+ br label %lh
+
+e2:
+; CHECK-NEXT: e2: float = 1365.3,
+ br label %e1
+
+lh:
+; CHECK-NEXT: lh: float = 1466015503616.0,
+ br i1 %x, label %h1, label %h2
+
+h1:
+; CHECK-NEXT: h1: float = 46912496115712.0,
+ br i1 %x, label %h2, label %lh
+
+h2:
+; CHECK-NEXT: h2: float = 140737486944101.9,
+ br i1 %x, label %h1, label %c1, !prof !36
+
+c1:
+; CHECK-NEXT: c1: float = 21845.3,
+ br i1 %x, label %h1, label %c2, !prof !36
+
+c2:
+; CHECK-NEXT: c2: float = 0.00004069,
+ br i1 %x, label %h1, label %e2, !prof !36
+}
+!36 = !{!"branch_weights", i32 1, i32 0}
More information about the llvm-commits
mailing list