[PATCH] D136237: [BasicBlockSections] avoid insertting redundant branch to fall through blocks

Sinan Lin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 20 06:03:04 PDT 2022


sinan added inline comments.


================
Comment at: llvm/lib/CodeGen/BasicBlockSections.cpp:134-141
+  auto I = MBB.terminators().begin(), E = MBB.end();
+
+  while (I != E) {
+    if (I->isUnconditionalBranch())
+      return false;
+    I++;
+  }
----------------
rahmanl wrote:
> Can we simply write:
> ` return !MBB.terminators.empty() && MBB.terminators.back().isUncoditionalBranch()`
I implemented it in this way since I have encountered code pieces like

```
0000000000400c98 <main.eh>:
  400c98:	d503201f 	nop
  400c9c:	aa0003f3 	mov	x19, x0
  400ca0:	7100043f 	cmp	w1, #0x1
  400ca4:	54ffff61 	b.ne	400c90 <main.__part.9>  // b.any
  400ca8:	17ffffef 	b	400c64 <main.__part.6>
  400cac:	aa0003f3 	mov	x19, x0
  400cb0:	97ffff50 	bl	4009f0 <__cxa_end_catch at plt>
  400cb4:	17fffff7 	b	400c90 <main.__part.9>
  400cb8:	94000001 	bl	400cbc <__clang_call_terminate>
```

But I just checked it and they seem to come from two eh-related basic blocks.


I will update it according to your suggestion.


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

https://reviews.llvm.org/D136237



More information about the llvm-commits mailing list