Skip to content

Commit e9de2d8

Browse files
committed
[BranchFolding] Fix assertion failure in HoistCommonCodeInSuccs
Assertion failure introduced in #140063, which didn't account for TBB and FBB being the same block.
1 parent 94142d9 commit e9de2d8

File tree

2 files changed

+86
-4
lines changed

2 files changed

+86
-4
lines changed

llvm/lib/CodeGen/BranchFolding.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2072,9 +2072,11 @@ bool BranchFolder::HoistCommonCodeInSuccs(MachineBasicBlock *MBB) {
20722072
return false;
20732073

20742074
// Hoist the instructions from [T.begin, TIB) and then delete [F.begin, FIB).
2075-
// Merge the debug locations. FIXME: We should do something with the
2076-
// debug instructions too (from BOTH branches).
2077-
{
2075+
// If we're hoisting from a single block then just splice. Else step through
2076+
// and merge the debug locations.
2077+
if (TBB == FBB) {
2078+
MBB->splice(Loc, TBB, TBB->begin(), TIB);
2079+
} else {
20782080
// TIB and FIB point to the end of the regions to hoist/merge in TBB and
20792081
// FBB.
20802082
MachineBasicBlock::iterator FE = FIB;
@@ -2083,7 +2085,7 @@ bool BranchFolder::HoistCommonCodeInSuccs(MachineBasicBlock *MBB) {
20832085
make_early_inc_range(make_range(TBB->begin(), TIB))) {
20842086
// Move debug instructions and pseudo probes without modifying them.
20852087
// FIXME: This is the wrong thing to do for debug locations, which
2086-
// should at least be killed.
2088+
// should at least be killed (and hoisted from BOTH blocks).
20872089
if (TI->isDebugOrPseudoInstr()) {
20882090
TI->moveBefore(&*Loc);
20892091
continue;
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py UTC_ARGS: --version 5
2+
# RUN: llc -mtriple=armv7-apple-ios --run-pass=branch-folder %s -o - | FileCheck %s
3+
4+
## Don't crash in branch-folder's HoistCommonCodeInSuccs when TBB and FBB are
5+
## the same block.
6+
7+
...
8+
---
9+
name: f_1418_2054
10+
tracksRegLiveness: true
11+
noPhis: true
12+
isSSA: false
13+
noVRegs: true
14+
body: |
15+
; CHECK-LABEL: name: f_1418_2054
16+
; CHECK: bb.0:
17+
; CHECK-NEXT: successors: %bb.1(0x80000000)
18+
; CHECK-NEXT: {{ $}}
19+
; CHECK-NEXT: bb.1:
20+
; CHECK-NEXT: successors: %bb.1(0x40000000), %bb.2(0x40000000)
21+
; CHECK-NEXT: {{ $}}
22+
; CHECK-NEXT: $r0 = MOVr undef $r0, 14 /* CC::al */, $noreg, $noreg
23+
; CHECK-NEXT: Bcc %bb.1, 1 /* CC::ne */, undef $cpsr
24+
; CHECK-NEXT: {{ $}}
25+
; CHECK-NEXT: bb.2:
26+
; CHECK-NEXT: successors: %bb.3(0x40000000), %bb.4(0x40000000)
27+
; CHECK-NEXT: {{ $}}
28+
; CHECK-NEXT: $r0 = MOVr undef $r0, 14 /* CC::al */, $noreg, $noreg
29+
; CHECK-NEXT: Bcc %bb.4, 1 /* CC::ne */, undef $cpsr
30+
; CHECK-NEXT: {{ $}}
31+
; CHECK-NEXT: bb.3:
32+
; CHECK-NEXT: BX_RET 14 /* CC::al */, $noreg
33+
; CHECK-NEXT: {{ $}}
34+
; CHECK-NEXT: bb.4:
35+
; CHECK-NEXT: TRAP
36+
bb.0:
37+
successors: %bb.1
38+
39+
bb.1:
40+
successors: %bb.3, %bb.2
41+
42+
Bcc %bb.3, 1, undef $cpsr
43+
B %bb.2
44+
45+
bb.2:
46+
successors: %bb.5, %bb.6
47+
48+
Bcc %bb.5, 1, undef $cpsr
49+
B %bb.6
50+
51+
bb.3:
52+
successors: %bb.4
53+
54+
$r0 = MOVr undef $r0, 14, $noreg, $noreg
55+
56+
bb.4:
57+
successors: %bb.1
58+
59+
B %bb.1
60+
61+
bb.5:
62+
successors: %bb.6
63+
64+
bb.6:
65+
successors: %bb.8, %bb.7
66+
67+
$r0 = MOVr undef $r0, 14, $noreg, $noreg
68+
$r0 = MOVr undef $r0, 14, $noreg, $noreg
69+
70+
Bcc %bb.7, 1, undef $cpsr
71+
B %bb.8
72+
73+
bb.7:
74+
successors:
75+
76+
TRAP
77+
78+
bb.8:
79+
BX_RET 14, _
80+
...

0 commit comments

Comments
 (0)