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

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 13 07:01:17 PDT 2024


https://github.com/nikic created https://github.com/llvm/llvm-project/pull/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

>From f4d8f0834d7f8b2b65f29fecb456854a2dcf6c15 Mon Sep 17 00:00:00 2001
From: Nikita Popov <npopov at redhat.com>
Date: Thu, 13 Jun 2024 15:58:05 +0200
Subject: [PATCH] [ARM][AArch64] Bail out if CandidatesWithoutStackFixups is
 empty

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
---
 llvm/lib/Target/AArch64/AArch64InstrInfo.cpp  |  2 ++
 llvm/lib/Target/ARM/ARMBaseInstrInfo.cpp      |  2 ++
 ...liner-no-candidates-without-stack-fixup.ll | 30 +++++++++++++++++++
 3 files changed, 34 insertions(+)
 create mode 100644 llvm/test/CodeGen/ARM/machine-outliner-no-candidates-without-stack-fixup.ll

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