Skip to content

Commit db08b09

Browse files
authored
[ARM][AArch64] Bail out if CandidatesWithoutStackFixups is empty (#95410)
The following code assumes that RepeatedSequenceLocs is non-empty. Bail out if there are less than 2 candidates left, as no outlining is possible in that case. The same check is already present in all the other places where elements from RepeatedSequenceLocs may be dropped. This fixes the issue reported at: #93965 (comment)
1 parent c4a1440 commit db08b09

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

llvm/lib/Target/AArch64/AArch64InstrInfo.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8556,6 +8556,8 @@ AArch64InstrInfo::getOutliningCandidateInfo(
85568556
NumBytesNoStackCalls <= RepeatedSequenceLocs.size() * 12) {
85578557
RepeatedSequenceLocs = CandidatesWithoutStackFixups;
85588558
FrameID = MachineOutlinerNoLRSave;
8559+
if (RepeatedSequenceLocs.size() < 2)
8560+
return std::nullopt;
85598561
} else {
85608562
SetCandidateCallInfo(MachineOutlinerDefault, 12);
85618563

llvm/lib/Target/ARM/ARMBaseInstrInfo.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6060,6 +6060,8 @@ ARMBaseInstrInfo::getOutliningCandidateInfo(
60606060
RepeatedSequenceLocs.size() * Costs.CallDefault) {
60616061
RepeatedSequenceLocs = CandidatesWithoutStackFixups;
60626062
FrameID = MachineOutlinerNoLRSave;
6063+
if (RepeatedSequenceLocs.size() < 2)
6064+
return std::nullopt;
60636065
} else
60646066
SetCandidateCallInfo(MachineOutlinerDefault, Costs.CallDefault);
60656067
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
2+
; RUN: llc -mtriple=thumbv8.1m.main-unknown-unknown < %s | FileCheck %s
3+
4+
; Make sure this does not assert during machine outlining.
5+
6+
declare void @a(...)
7+
8+
define void @b(i32 %a, i32 %b, i32 %c, ptr %d, ptr %e) minsize {
9+
; CHECK-LABEL: b:
10+
; CHECK: @ %bb.0:
11+
; CHECK-NEXT: ldr r3, [sp]
12+
; CHECK-NEXT: mov r2, r1
13+
; CHECK-NEXT: mov r1, r0
14+
; CHECK-NEXT: movs r0, #2
15+
; CHECK-NEXT: b a
16+
tail call void @a(i32 2, i32 %a, i32 %b, ptr %e)
17+
ret void
18+
}
19+
20+
define void @c(i32 %a, i32 %b, i32 %c, ptr %d, ptr %e) minsize {
21+
; CHECK-LABEL: c:
22+
; CHECK: @ %bb.0:
23+
; CHECK-NEXT: ldr r3, [sp]
24+
; CHECK-NEXT: mov r2, r1
25+
; CHECK-NEXT: mov r1, r0
26+
; CHECK-NEXT: movs r0, #4
27+
; CHECK-NEXT: b a
28+
tail call void @a(i32 4, i32 %a, i32 %b, ptr %e)
29+
ret void
30+
}

0 commit comments

Comments
 (0)