Skip to content

Commit 33b74f5

Browse files
committed
[BranchRelaxation] Fix invalid branch generation in branch-relaxation
1 parent a9ca220 commit 33b74f5

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

llvm/lib/CodeGen/BranchRelaxation.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,20 @@ bool BranchRelaxation::fixupConditionalBranch(MachineInstr &MI) {
491491
return true;
492492
}
493493
if (FBB) {
494+
// If we get here with a MBB which ends like this:
495+
//
496+
// bb.1:
497+
// successors: %bb.2;
498+
// ...
499+
// BNE $x1, $x0, %bb.2
500+
// PseudoBR %bb.2
501+
//
502+
// Just remove conditional branch.
503+
if (TBB == FBB) {
504+
BlockInfo[MBB->getNumber()].Size -= TII->getInstSizeInBytes(MI);
505+
MI.eraseFromParent();
506+
return true;
507+
}
494508
// We need to split the basic block here to obtain two long-range
495509
// unconditional branches.
496510
NewBB = createNewBlockAfter(*MBB);
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
2+
# RUN: llc %s -mtriple=riscv64 -run-pass=branch-relaxation -o - -verify-machineinstrs | FileCheck %s
3+
4+
--- |
5+
define void @foo() {
6+
ret void
7+
}
8+
...
9+
---
10+
name: foo
11+
tracksRegLiveness: true
12+
body: |
13+
bb.0:
14+
liveins: $x1
15+
BNE $x1, $x0, %bb.3
16+
PseudoBR %bb.3
17+
bb.1:
18+
liveins: $x1
19+
INLINEASM &".space 4096", 1
20+
BGE $x1, $x0, %bb.3
21+
bb.3:
22+
PseudoRET
23+
## NOTE: These prefixes are unused and the list is autogenerated. Do not add tests below this line:
24+
# CHECK: {{.*}}

0 commit comments

Comments
 (0)