-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[ARM][AArch64] Bail out if CandidatesWithoutStackFixups is empty #95410
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ARM][AArch64] Bail out if CandidatesWithoutStackFixups is empty #95410
Conversation
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: llvm#93965 (comment)
@llvm/pr-subscribers-backend-aarch64 Author: Nikita Popov (nikic) ChangesThe 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) Full diff: https://github.com/llvm/llvm-project/pull/95410.diff 3 Files Affected:
diff --git a/llvm/lib/Target/AArch64/AArch64InstrInfo.cpp b/llvm/lib/Target/AArch64/AArch64InstrInfo.cpp
index 1a795b58319c9..f4b5fd7a003c2 100644
--- a/llvm/lib/Target/AArch64/AArch64InstrInfo.cpp
+++ b/llvm/lib/Target/AArch64/AArch64InstrInfo.cpp
@@ -8556,6 +8556,8 @@ AArch64InstrInfo::getOutliningCandidateInfo(
NumBytesNoStackCalls <= RepeatedSequenceLocs.size() * 12) {
RepeatedSequenceLocs = CandidatesWithoutStackFixups;
FrameID = MachineOutlinerNoLRSave;
+ if (RepeatedSequenceLocs.size() < 2)
+ return std::nullopt;
} else {
SetCandidateCallInfo(MachineOutlinerDefault, 12);
diff --git a/llvm/lib/Target/ARM/ARMBaseInstrInfo.cpp b/llvm/lib/Target/ARM/ARMBaseInstrInfo.cpp
index 627148b73c4f5..e81e6bb697588 100644
--- a/llvm/lib/Target/ARM/ARMBaseInstrInfo.cpp
+++ b/llvm/lib/Target/ARM/ARMBaseInstrInfo.cpp
@@ -6060,6 +6060,8 @@ ARMBaseInstrInfo::getOutliningCandidateInfo(
RepeatedSequenceLocs.size() * Costs.CallDefault) {
RepeatedSequenceLocs = CandidatesWithoutStackFixups;
FrameID = MachineOutlinerNoLRSave;
+ if (RepeatedSequenceLocs.size() < 2)
+ return std::nullopt;
} else
SetCandidateCallInfo(MachineOutlinerDefault, Costs.CallDefault);
}
diff --git a/llvm/test/CodeGen/ARM/machine-outliner-no-candidates-without-stack-fixup.ll b/llvm/test/CodeGen/ARM/machine-outliner-no-candidates-without-stack-fixup.ll
new file mode 100644
index 0000000000000..f50d92b8160d5
--- /dev/null
+++ b/llvm/test/CodeGen/ARM/machine-outliner-no-candidates-without-stack-fixup.ll
@@ -0,0 +1,30 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
+; RUN: llc -mtriple=thumbv8.1m.main-unknown-unknown < %s | FileCheck %s
+
+; Make sure this does not assert during machine outlining.
+
+declare void @a(...)
+
+define void @b(i32 %a, i32 %b, i32 %c, ptr %d, ptr %e) minsize {
+; CHECK-LABEL: b:
+; CHECK: @ %bb.0:
+; CHECK-NEXT: ldr r3, [sp]
+; CHECK-NEXT: mov r2, r1
+; CHECK-NEXT: mov r1, r0
+; CHECK-NEXT: movs r0, #2
+; CHECK-NEXT: b a
+ tail call void @a(i32 2, i32 %a, i32 %b, ptr %e)
+ ret void
+}
+
+define void @c(i32 %a, i32 %b, i32 %c, ptr %d, ptr %e) minsize {
+; CHECK-LABEL: c:
+; CHECK: @ %bb.0:
+; CHECK-NEXT: ldr r3, [sp]
+; CHECK-NEXT: mov r2, r1
+; CHECK-NEXT: mov r1, r0
+; CHECK-NEXT: movs r0, #4
+; CHECK-NEXT: b a
+ tail call void @a(i32 4, i32 %a, i32 %b, ptr %e)
+ ret void
+}
|
@llvm/pr-subscribers-backend-arm Author: Nikita Popov (nikic) ChangesThe 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) Full diff: https://github.com/llvm/llvm-project/pull/95410.diff 3 Files Affected:
diff --git a/llvm/lib/Target/AArch64/AArch64InstrInfo.cpp b/llvm/lib/Target/AArch64/AArch64InstrInfo.cpp
index 1a795b58319c9..f4b5fd7a003c2 100644
--- a/llvm/lib/Target/AArch64/AArch64InstrInfo.cpp
+++ b/llvm/lib/Target/AArch64/AArch64InstrInfo.cpp
@@ -8556,6 +8556,8 @@ AArch64InstrInfo::getOutliningCandidateInfo(
NumBytesNoStackCalls <= RepeatedSequenceLocs.size() * 12) {
RepeatedSequenceLocs = CandidatesWithoutStackFixups;
FrameID = MachineOutlinerNoLRSave;
+ if (RepeatedSequenceLocs.size() < 2)
+ return std::nullopt;
} else {
SetCandidateCallInfo(MachineOutlinerDefault, 12);
diff --git a/llvm/lib/Target/ARM/ARMBaseInstrInfo.cpp b/llvm/lib/Target/ARM/ARMBaseInstrInfo.cpp
index 627148b73c4f5..e81e6bb697588 100644
--- a/llvm/lib/Target/ARM/ARMBaseInstrInfo.cpp
+++ b/llvm/lib/Target/ARM/ARMBaseInstrInfo.cpp
@@ -6060,6 +6060,8 @@ ARMBaseInstrInfo::getOutliningCandidateInfo(
RepeatedSequenceLocs.size() * Costs.CallDefault) {
RepeatedSequenceLocs = CandidatesWithoutStackFixups;
FrameID = MachineOutlinerNoLRSave;
+ if (RepeatedSequenceLocs.size() < 2)
+ return std::nullopt;
} else
SetCandidateCallInfo(MachineOutlinerDefault, Costs.CallDefault);
}
diff --git a/llvm/test/CodeGen/ARM/machine-outliner-no-candidates-without-stack-fixup.ll b/llvm/test/CodeGen/ARM/machine-outliner-no-candidates-without-stack-fixup.ll
new file mode 100644
index 0000000000000..f50d92b8160d5
--- /dev/null
+++ b/llvm/test/CodeGen/ARM/machine-outliner-no-candidates-without-stack-fixup.ll
@@ -0,0 +1,30 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
+; RUN: llc -mtriple=thumbv8.1m.main-unknown-unknown < %s | FileCheck %s
+
+; Make sure this does not assert during machine outlining.
+
+declare void @a(...)
+
+define void @b(i32 %a, i32 %b, i32 %c, ptr %d, ptr %e) minsize {
+; CHECK-LABEL: b:
+; CHECK: @ %bb.0:
+; CHECK-NEXT: ldr r3, [sp]
+; CHECK-NEXT: mov r2, r1
+; CHECK-NEXT: mov r1, r0
+; CHECK-NEXT: movs r0, #2
+; CHECK-NEXT: b a
+ tail call void @a(i32 2, i32 %a, i32 %b, ptr %e)
+ ret void
+}
+
+define void @c(i32 %a, i32 %b, i32 %c, ptr %d, ptr %e) minsize {
+; CHECK-LABEL: c:
+; CHECK: @ %bb.0:
+; CHECK-NEXT: ldr r3, [sp]
+; CHECK-NEXT: mov r2, r1
+; CHECK-NEXT: mov r1, r0
+; CHECK-NEXT: movs r0, #4
+; CHECK-NEXT: b a
+ tail call void @a(i32 4, i32 %a, i32 %b, ptr %e)
+ ret void
+}
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks for looking into this.
…m#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: llvm#93965 (comment)
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)