[llvm] [BOLT][AArch64] Expand cmpbr when reversing would overflow (PR #202998)

Rafael Auler via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 4 18:33:33 PDT 2026


================
@@ -553,12 +557,26 @@ bool ReorderBasicBlocks::modifyFunctionLayout(BinaryFunction &BF,
 }
 
 Error FixupBranches::runOnFunctions(BinaryContext &BC) {
+  const bool ShouldRunRegisterAnalysis =
+      opts::FixBranchesWithLiveness &&
+      llvm::any_of(BC.getBinaryFunctions(), [&](auto &It) {
+        BinaryFunction &BF = It.second;
+        return BC.shouldEmit(BF) && BF.isSimple() && needsBranchLiveness(BF);
+      });
+
+  std::optional<RegAnalysis> RA;
+  if (ShouldRunRegisterAnalysis)
+    RA.emplace(BC, nullptr, nullptr);
+
   for (auto &It : BC.getBinaryFunctions()) {
-    BinaryFunction &Function = It.second;
-    if (!BC.shouldEmit(Function) || !Function.isSimple())
+    BinaryFunction &BF = It.second;
+    if (!BC.shouldEmit(BF) || !BF.isSimple())
       continue;
 
-    Function.fixBranches();
+    BranchLivenessInfo BLI;
+    if (RA)
+      BLI = computeBranchLiveness(BF, *RA);
+    BF.fixBranches(&BLI);
----------------
rafaelauler wrote:

You already added the logic to make fixBranches check for null BLI, so we can just use it here to make it clear we're following the path where no BLI is available:
```
  if (!RA)
    BF.fixBranches();  // Common case
  else 
    BF.fixBranches(computeBranchLiveness(BF, *RA));
```

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


More information about the llvm-commits mailing list