Skip to content

[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

Merged

Conversation

nikic
Copy link
Contributor

@nikic nikic commented Jun 13, 2024

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)

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)
@llvmbot
Copy link
Member

llvmbot commented Jun 13, 2024

@llvm/pr-subscribers-backend-aarch64

Author: Nikita Popov (nikic)

Changes

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)


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

@llvmbot
Copy link
Member

llvmbot commented Jun 13, 2024

@llvm/pr-subscribers-backend-arm

Author: Nikita Popov (nikic)

Changes

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)


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

Copy link
Contributor

@rgwott rgwott left a 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.

@nikic nikic merged commit db08b09 into llvm:main Jun 14, 2024
10 checks passed
@nikic nikic deleted the machine-outline-no-candidates-without-stack-fixup branch June 14, 2024 07:29
EthanLuisMcDonough pushed a commit to EthanLuisMcDonough/llvm-project that referenced this pull request Aug 13, 2024
…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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants