[PATCH] D134557: [BranchRelaxation] Fall through only if block has no unconditional branches

Ruiling, Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 12 23:13:09 PDT 2022


ruiling added inline comments.


================
Comment at: llvm/lib/CodeGen/BranchRelaxation.cpp:500
     MachineBasicBlock *PrevBB = &*std::prev(DestBB->getIterator());
-    if (auto *FT = PrevBB->getFallThrough()) {
-      assert(FT == DestBB);
-      TII->insertUnconditionalBranch(*PrevBB, FT, DebugLoc());
-      // Recalculate the block size.
-      BlockInfo[PrevBB->getNumber()].Size = computeBlockSize(*PrevBB);
+    bool FailToAnalyze = TII->analyzeBranch(*PrevBB, TBB, FBB, Cond);
+    // Fall through only if PrevBB has no unconditional branch as one of its
----------------
I am not quite sure whether a simplified approach would work here: Check whether there is explicit branch to `FT` in `PrevBB`? if no, insert unconditional branch at the end of `PrevBB` to `FT`, otherwise do nothing. Does this solve the problem here? The remaining question is how to detect whether there is pre-existing branch to `FT` in `PrevBB`? I think we can do an iteration over the terminators of `PrevBB` to find if there is any branch instruction that has a MBB operand referencing `DestBB`.
The overall idea would look like:
```
if ((auto *FT = PrevBB->getFallThrough()) {
  iterating over the terminators of PrevBB, see if there is any branch instruction which has a MachineOperand that references FT
  if (explicit branch to FT NOT found)
    insert unconditional branch and recalculate block size
}
```
Does this sounds good to you? @efriedma @arsenm 


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D134557/new/

https://reviews.llvm.org/D134557



More information about the llvm-commits mailing list