[llvm] [ARM][AArch64] Bail out if CandidatesWithoutStackFixups is empty (PR #95410)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 13 07:01:47 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-aarch64
Author: Nikita Popov (nikic)
<details>
<summary>Changes</summary>
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: https://github.com/llvm/llvm-project/pull/93965#issuecomment-2151989716
---
Full diff: https://github.com/llvm/llvm-project/pull/95410.diff
3 Files Affected:
- (modified) llvm/lib/Target/AArch64/AArch64InstrInfo.cpp (+2)
- (modified) llvm/lib/Target/ARM/ARMBaseInstrInfo.cpp (+2)
- (added) llvm/test/CodeGen/ARM/machine-outliner-no-candidates-without-stack-fixup.ll (+30)
``````````diff
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
+}
``````````
</details>
https://github.com/llvm/llvm-project/pull/95410
More information about the llvm-commits
mailing list