Skip to content

Commit bd6c16c

Browse files
authored
[MachineOutliner] Avoid ranges that cross bundle boundary (#148977)
We found some code that was hitting this assert because `getOutlinableRanges()` was trying to create a range that crossed a bundle boundary. https://github.com/llvm/llvm-project/blob/ae3bba4d15a10646ea91c6c0795633b82939857b/llvm/include/llvm/CodeGen/MachineInstrBundleIterator.h#L133-L135 Avoid creating those ranges and add a test that hit the assert.
1 parent 9f364fe commit bd6c16c

File tree

2 files changed

+43
-12
lines changed

2 files changed

+43
-12
lines changed

llvm/lib/Target/AArch64/AArch64InstrInfo.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9585,10 +9585,15 @@ AArch64InstrInfo::getOutlinableRanges(MachineBasicBlock &MBB,
95859585
};
95869586
auto SaveRangeIfNonEmpty = [&RangeLen, &Ranges, &RangeBegin, &RangeEnd]() {
95879587
// At least one unsafe register is not dead. We do not want to outline at
9588-
// this point. If it is long enough to outline from, save the range
9589-
// [RangeBegin, RangeEnd).
9590-
if (RangeLen > 1)
9591-
Ranges.push_back(std::make_pair(RangeBegin, RangeEnd));
9588+
// this point. If it is long enough to outline from and does not cross a
9589+
// bundle boundary, save the range [RangeBegin, RangeEnd).
9590+
if (RangeLen <= 1)
9591+
return;
9592+
if (!RangeBegin.isEnd() && RangeBegin->isBundledWithPred())
9593+
return;
9594+
if (!RangeEnd.isEnd() && RangeEnd->isBundledWithPred())
9595+
return;
9596+
Ranges.emplace_back(RangeBegin, RangeEnd);
95929597
};
95939598
// Find the first point where all unsafe registers are dead.
95949599
// FIND: <safe instr> <-- end of first potential range

llvm/test/CodeGen/AArch64/machine-outliner-safe-range-in-middle.mir

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,53 @@ body: |
1616
; CHECK-NEXT: {{ $}}
1717
; CHECK-NEXT: BL @OUTLINED_FUNCTION_0, implicit-def $lr, implicit $sp, implicit-def $lr, implicit-def $x0, implicit-def $x1, implicit-def $x2, implicit-def $x3, implicit-def $x16, implicit $x0, implicit $sp
1818
; CHECK-NEXT: $x9 = ADDXri $x16, 16, 0
19-
; CHECK-NEXT: $x16 = ADDXri killed $x16, 16, 0
19+
; CHECK-NEXT: $x16 = ADDXri killed $x16, 16, 1
2020
; CHECK-NEXT: BL @OUTLINED_FUNCTION_0, implicit-def $lr, implicit $sp, implicit-def $lr, implicit-def $x0, implicit-def $x1, implicit-def $x2, implicit-def $x3, implicit-def $x16, implicit $x0, implicit $sp
2121
; CHECK-NEXT: $x9 = ADDXri $x9, 16, 0
22-
; CHECK-NEXT: $x16 = ADDXri killed $x16, 16, 0
22+
; CHECK-NEXT: $x16 = ADDXri killed $x16, 16, 2
2323
; CHECK-NEXT: RET undef $x9
2424
$x0 = ADDXri $x0, 0, 0
2525
$x1 = ADDXri $x0, 1, 0
2626
$x2 = ADDXri $x0, 2, 0
2727
$x3 = ADDXri $x0, 3, 0
28-
29-
; End safe range
3028
$x16 = ADDXri $x0, 16, 0
3129
$x9 = ADDXri $x16, 16, 0
32-
$x16 = ADDXri killed $x16, 16, 0
33-
30+
$x16 = ADDXri killed $x16, 16, 1
31+
; End safe range
3432
$x0 = ADDXri $x0, 0, 0
3533
$x1 = ADDXri $x0, 1, 0
3634
$x2 = ADDXri $x0, 2, 0
3735
$x3 = ADDXri $x0, 3, 0
38-
; End safe range
3936
$x16 = ADDXri $x0, 16, 0
4037
$x9 = ADDXri $x9, 16, 0
41-
$x16 = ADDXri killed $x16, 16, 0
38+
$x16 = ADDXri killed $x16, 16, 2
39+
; End safe range
4240
RET undef $x9
41+
...
42+
---
43+
name: unsafe_range_bundle
44+
tracksRegLiveness: true
45+
machineFunctionInfo:
46+
hasRedZone: false
47+
body: |
48+
bb.0:
49+
liveins: $x0
50+
; CHECK-LABEL: name: unsafe_range_bundle
51+
; CHECK: liveins: $x0
52+
; CHECK-NEXT: {{ $}}
53+
; CHECK-NEXT: $x0 = ADDXri $x0, 0, 0
54+
; CHECK-NEXT: $x16 = ADDXri $x0, 16, 0
55+
; CHECK-NEXT: BUNDLE {
56+
; CHECK-NEXT: $x16 = ADDXri killed $x16, 16, 3
57+
; CHECK-NEXT: $x1 = ADDXri $x0, 0, 0
58+
; CHECK-NEXT: }
59+
; CHECK-NEXT: RET undef $x9
60+
$x0 = ADDXri $x0, 0, 0
61+
$x16 = ADDXri $x0, 16, 0
62+
BUNDLE { ; Bundle crosses a safe range
63+
$x16 = ADDXri killed $x16, 16, 3
64+
; End safe range
65+
$x1 = ADDXri $x0, 0, 0
66+
}
67+
RET undef $x9
68+
...

0 commit comments

Comments
 (0)