[llvm] [BFI] Preserve zero-mass exits in solveIrreducibleMass (PR #218140)
via llvm-commits
llvm-commits at lists.llvm.org
Sat Aug 22 09:09:04 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-analysis
Author: ʟᴜɴᴇx (im-lunex)
<details>
<summary>Changes</summary>
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.
Adds a regression test.
---
Full diff: https://github.com/llvm/llvm-project/pull/218140.diff
2 Files Affected:
- (modified) llvm/include/llvm/Analysis/BlockFrequencyInfoImpl.h (-2)
- (added) llvm/test/Analysis/BlockFrequencyInfo/nested-irreducible-zero-mass-exit.ll (+60)
``````````diff
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/nested-irreducible-zero-mass-exit.ll b/llvm/test/Analysis/BlockFrequencyInfo/nested-irreducible-zero-mass-exit.ll
new file mode 100644
index 0000000000000..c3f70b2c84c24
--- /dev/null
+++ b/llvm/test/Analysis/BlockFrequencyInfo/nested-irreducible-zero-mass-exit.ll
@@ -0,0 +1,60 @@
+; test for https://github.com/llvm/llvm-project/issues/217740
+
+; REQUIRES: asserts
+
+; RUN: llc -O3 -o /dev/null %s
+
+target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+define void @f20() {
+entry:
+ br i1 false, label %entry.lbl_br28_crit_edge, label %lbl_bf2
+
+entry.lbl_br28_crit_edge: ; preds = %entry
+ br label %lbl_br28
+
+lbl_bf2: ; preds = %lbl_br52.us.lbl_bf2_crit_edge, %entry
+ br label %lbl_br28
+
+lbl_bf27: ; preds = %if.end19.us.lbl_bf27_crit_edge, %lbl_b51.preheader, %lbl_br28
+ br label %lbl_b51.preheader
+
+lbl_br28: ; preds = %lbl_b51.us.peel.lbl_br28_crit_edge, %entry.lbl_br28_crit_edge, %lbl_bf2
+ br i1 false, label %lbl_br28.lbl_b51.preheader_crit_edge, label %lbl_bf27
+
+lbl_br28.lbl_b51.preheader_crit_edge: ; preds = %lbl_br28
+ br label %lbl_b51.preheader
+
+lbl_b51.preheader: ; preds = %lbl_br28.lbl_b51.preheader_crit_edge, %lbl_bf27
+ br i1 false, label %lbl_b51.us.peel, label %lbl_bf27
+
+lbl_b51.us.peel: ; preds = %lbl_b51.preheader
+ br i1 false, label %if.end19.us, label %lbl_b51.us.peel.lbl_br28_crit_edge, !prof !0
+
+lbl_b51.us.peel.lbl_br28_crit_edge: ; preds = %lbl_b51.us.peel
+ br label %lbl_br28
+
+lbl_br52.us: ; preds = %lbl_b51.us
+ br i1 false, label %lbl_br52.us.lbl_bf2_crit_edge, label %if.end19.us
+
+lbl_br52.us.lbl_bf2_crit_edge: ; preds = %lbl_br52.us
+ br label %lbl_bf2
+
+lbl_b51.us: ; preds = %if.end19.us
+ br i1 false, label %lbl_br52.us, label %lbl_b51.us.lbl_br28_crit_edge, !prof !0
+
+lbl_b51.us.lbl_br28_crit_edge: ; preds = %lbl_b51.us
+ ret void
+
+if.end19.us: ; preds = %lbl_br52.us, %lbl_b51.us.peel
+ br i1 false, label %lbl_b51.us, label %if.end19.us.lbl_bf27_crit_edge
+
+if.end19.us.lbl_bf27_crit_edge: ; preds = %if.end19.us
+ br label %lbl_bf27
+
+; uselistorder directives
+ uselistorder label %lbl_br28, { 0, 2, 1 }
+}
+
+!0 = !{!"branch_weights", i32 0, i32 128849020}
``````````
</details>
https://github.com/llvm/llvm-project/pull/218140
More information about the llvm-commits
mailing list