[llvm] db08b09 - [ARM][AArch64] Bail out if CandidatesWithoutStackFixups is empty (#95410)

via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 14 00:29:26 PDT 2024


Author: Nikita Popov
Date: 2024-06-14T09:29:21+02:00
New Revision: db08b0999d1b42391e34ac0c469b92de98e9f550

URL: https://github.com/llvm/llvm-project/commit/db08b0999d1b42391e34ac0c469b92de98e9f550
DIFF: https://github.com/llvm/llvm-project/commit/db08b0999d1b42391e34ac0c469b92de98e9f550.diff

LOG: [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:
https://github.com/llvm/llvm-project/pull/93965#issuecomment-2151989716

Added: 
    llvm/test/CodeGen/ARM/machine-outliner-no-candidates-without-stack-fixup.ll

Modified: 
    llvm/lib/Target/AArch64/AArch64InstrInfo.cpp
    llvm/lib/Target/ARM/ARMBaseInstrInfo.cpp

Removed: 
    


################################################################################
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
+}


        


More information about the llvm-commits mailing list