[llvm] [AArch64][SME] Disable outlining for functions with streaming-mode changes (PR #95132)

Kerry McLaughlin via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 11 08:18:19 PDT 2024


https://github.com/kmclaughlin-arm created https://github.com/llvm/llvm-project/pull/95132

None

>From 2e158b83d91feb9a37244c16baeecabd7405b112 Mon Sep 17 00:00:00 2001
From: Kerry McLaughlin <kerry.mclaughlin at arm.com>
Date: Tue, 11 Jun 2024 15:00:47 +0000
Subject: [PATCH 1/2] Add tests with streaming-mode changes using
 -enable-machine-outliner

---
 .../outlining-with-streaming-mode-changes.ll  | 68 +++++++++++++++++++
 1 file changed, 68 insertions(+)
 create mode 100644 llvm/test/CodeGen/AArch64/outlining-with-streaming-mode-changes.ll

diff --git a/llvm/test/CodeGen/AArch64/outlining-with-streaming-mode-changes.ll b/llvm/test/CodeGen/AArch64/outlining-with-streaming-mode-changes.ll
new file mode 100644
index 0000000000000..2bd0eb0b75315
--- /dev/null
+++ b/llvm/test/CodeGen/AArch64/outlining-with-streaming-mode-changes.ll
@@ -0,0 +1,68 @@
+; RUN: llc -mtriple=aarch64-linux-gnu -mattr=+sve -mattr=+sme2 -enable-machine-outliner -verify-machineinstrs < %s | FileCheck %s
+
+declare void @callee();
+
+define void @streaming_mode_change1() #0 {
+; CHECK-LABEL: streaming_mode_change1:
+; CHECK:       // %bb.0:
+; CHECK-NEXT:    stp d15, d14, [sp, #-80]! // 16-byte Folded Spill
+; CHECK-NEXT:    stp d13, d12, [sp, #16] // 16-byte Folded Spill
+; CHECK-NEXT:    stp d11, d10, [sp, #32] // 16-byte Folded Spill
+; CHECK-NEXT:    stp d9, d8, [sp, #48] // 16-byte Folded Spill
+; CHECK-NEXT:    str x30, [sp, #64] // 8-byte Folded Spill
+; CHECK-NEXT:    bl OUTLINED_FUNCTION_1
+; CHECK-NEXT:    smstart sm
+; CHECK-NEXT:    ldp d9, d8, [sp, #48] // 16-byte Folded Reload
+; CHECK-NEXT:    ldr x30, [sp, #64] // 8-byte Folded Reload
+; CHECK-NEXT:    b OUTLINED_FUNCTION_0
+  call void @callee();
+  ret void;
+}
+
+define void @streaming_mode_change2() #0 {
+; CHECK-LABEL: streaming_mode_change2:
+; CHECK:       // %bb.0:
+; CHECK-NEXT:    stp d15, d14, [sp, #-80]! // 16-byte Folded Spill
+; CHECK-NEXT:    stp d13, d12, [sp, #16] // 16-byte Folded Spill
+; CHECK-NEXT:    stp d11, d10, [sp, #32] // 16-byte Folded Spill
+; CHECK-NEXT:    stp d9, d8, [sp, #48] // 16-byte Folded Spill
+; CHECK-NEXT:    str x30, [sp, #64] // 8-byte Folded Spill
+; CHECK-NEXT:    bl OUTLINED_FUNCTION_1
+; CHECK-NEXT:    smstart sm
+; CHECK-NEXT:    ldp d9, d8, [sp, #48] // 16-byte Folded Reload
+; CHECK-NEXT:    ldr x30, [sp, #64] // 8-byte Folded Reload
+; CHECK-NEXT:    b OUTLINED_FUNCTION_0
+  call void @callee();
+  ret void;
+}
+
+define void @streaming_mode_change3() #0 {
+; CHECK-LABEL: streaming_mode_change3:
+; CHECK:       // %bb.0:
+; CHECK-NEXT:    stp d15, d14, [sp, #-80]! // 16-byte Folded Spill
+; CHECK-NEXT:    stp d13, d12, [sp, #16] // 16-byte Folded Spill
+; CHECK-NEXT:    stp d11, d10, [sp, #32] // 16-byte Folded Spill
+; CHECK-NEXT:    stp d9, d8, [sp, #48] // 16-byte Folded Spill
+; CHECK-NEXT:    str x30, [sp, #64] // 8-byte Folded Spill
+; CHECK-NEXT:    bl OUTLINED_FUNCTION_1
+; CHECK-NEXT:    smstart sm
+; CHECK-NEXT:    ldp d9, d8, [sp, #48] // 16-byte Folded Reload
+; CHECK-NEXT:    ldr x30, [sp, #64] // 8-byte Folded Reload
+; CHECK-NEXT:    b OUTLINED_FUNCTION_0
+  call void @callee();
+  ret void;
+}
+
+; CHECK-LABEL: OUTLINED_FUNCTION_0:
+; CHECK:       // %bb.0:
+; CHECK-NEXT:    ldp d11, d10, [sp, #32]
+; CHECK-NEXT:    ldp d13, d12, [sp, #16]
+; CHECK-NEXT:    ldp d15, d14, [sp], #80
+; CHECK-NEXT:    ret
+
+; CHECK-LABEL: OUTLINED_FUNCTION_1:
+; CHECK:       // %bb.0:
+; CHECK-NEXT:    smstop	sm
+; CHECK-NEXT:    b callee
+
+attributes #0 = { "aarch64_pstate_sm_enabled" nounwind }

>From a57cf815b9bd7aac0b44ef58ce3e6ccfda73e9a9 Mon Sep 17 00:00:00 2001
From: Kerry McLaughlin <kerry.mclaughlin at arm.com>
Date: Tue, 11 Jun 2024 15:02:28 +0000
Subject: [PATCH 2/2] [AArch64][SME] Disable outlining for functions with
 streaming-mode changes

---
 llvm/lib/Target/AArch64/AArch64InstrInfo.cpp  |  7 +++
 .../outlining-with-streaming-mode-changes.ll  | 46 +++++++++++--------
 2 files changed, 35 insertions(+), 18 deletions(-)

diff --git a/llvm/lib/Target/AArch64/AArch64InstrInfo.cpp b/llvm/lib/Target/AArch64/AArch64InstrInfo.cpp
index 7d540efe2b41e..e79d4422e255e 100644
--- a/llvm/lib/Target/AArch64/AArch64InstrInfo.cpp
+++ b/llvm/lib/Target/AArch64/AArch64InstrInfo.cpp
@@ -8700,6 +8700,13 @@ bool AArch64InstrInfo::isFunctionSafeToOutlineFrom(
   if (!AFI || AFI->hasRedZone().value_or(true))
     return false;
 
+  // FIXME: Determine whether it is safe to outline from functions which contain
+  // streaming-mode changes. We may need to ensure any smstart/smstop pairs are
+  // outlined together and ensure it is safe to outline with async unwind info,
+  // required for saving & restoring VG around calls.
+  if (AFI->hasStreamingModeChanges())
+    return false;
+
   // FIXME: Teach the outliner to generate/handle Windows unwind info.
   if (MF.getTarget().getMCAsmInfo()->usesWindowsCFI())
     return false;
diff --git a/llvm/test/CodeGen/AArch64/outlining-with-streaming-mode-changes.ll b/llvm/test/CodeGen/AArch64/outlining-with-streaming-mode-changes.ll
index 2bd0eb0b75315..44d47a01dbe2b 100644
--- a/llvm/test/CodeGen/AArch64/outlining-with-streaming-mode-changes.ll
+++ b/llvm/test/CodeGen/AArch64/outlining-with-streaming-mode-changes.ll
@@ -1,4 +1,5 @@
 ; RUN: llc -mtriple=aarch64-linux-gnu -mattr=+sve -mattr=+sme2 -enable-machine-outliner -verify-machineinstrs < %s | FileCheck %s
+; RUN: llc -mtriple=aarch64-linux-gnu -mattr=+sve -mattr=+sme2 -enable-machine-outliner -verify-machineinstrs < %s | FileCheck %s -check-prefix=OUTLINER
 
 declare void @callee();
 
@@ -10,11 +11,18 @@ define void @streaming_mode_change1() #0 {
 ; CHECK-NEXT:    stp d11, d10, [sp, #32] // 16-byte Folded Spill
 ; CHECK-NEXT:    stp d9, d8, [sp, #48] // 16-byte Folded Spill
 ; CHECK-NEXT:    str x30, [sp, #64] // 8-byte Folded Spill
-; CHECK-NEXT:    bl OUTLINED_FUNCTION_1
+; CHECK-NEXT:    smstop sm
+; CHECK-NEXT:    bl callee
 ; CHECK-NEXT:    smstart sm
 ; CHECK-NEXT:    ldp d9, d8, [sp, #48] // 16-byte Folded Reload
 ; CHECK-NEXT:    ldr x30, [sp, #64] // 8-byte Folded Reload
-; CHECK-NEXT:    b OUTLINED_FUNCTION_0
+; CHECK-NEXT:    ldp d11, d10, [sp, #32] // 16-byte Folded Reload
+; CHECK-NEXT:    ldp d13, d12, [sp, #16] // 16-byte Folded Reload
+; CHECK-NEXT:    ldp d15, d14, [sp], #80 // 16-byte Folded Reload
+; CHECK-NEXT:    ret
+;
+; OUTLINER-LABEL: streaming_mode_change1:
+; OUTLINER-NOT: OUTLINED_FUNCTION_
   call void @callee();
   ret void;
 }
@@ -27,11 +35,18 @@ define void @streaming_mode_change2() #0 {
 ; CHECK-NEXT:    stp d11, d10, [sp, #32] // 16-byte Folded Spill
 ; CHECK-NEXT:    stp d9, d8, [sp, #48] // 16-byte Folded Spill
 ; CHECK-NEXT:    str x30, [sp, #64] // 8-byte Folded Spill
-; CHECK-NEXT:    bl OUTLINED_FUNCTION_1
+; CHECK-NEXT:    smstop sm
+; CHECK-NEXT:    bl callee
 ; CHECK-NEXT:    smstart sm
 ; CHECK-NEXT:    ldp d9, d8, [sp, #48] // 16-byte Folded Reload
 ; CHECK-NEXT:    ldr x30, [sp, #64] // 8-byte Folded Reload
-; CHECK-NEXT:    b OUTLINED_FUNCTION_0
+; CHECK-NEXT:    ldp d11, d10, [sp, #32] // 16-byte Folded Reload
+; CHECK-NEXT:    ldp d13, d12, [sp, #16] // 16-byte Folded Reload
+; CHECK-NEXT:    ldp d15, d14, [sp], #80 // 16-byte Folded Reload
+; CHECK-NEXT:    ret
+;
+; OUTLINER-LABEL: streaming_mode_change2:
+; OUTLINER-NOT: OUTLINED_FUNCTION_
   call void @callee();
   ret void;
 }
@@ -44,25 +59,20 @@ define void @streaming_mode_change3() #0 {
 ; CHECK-NEXT:    stp d11, d10, [sp, #32] // 16-byte Folded Spill
 ; CHECK-NEXT:    stp d9, d8, [sp, #48] // 16-byte Folded Spill
 ; CHECK-NEXT:    str x30, [sp, #64] // 8-byte Folded Spill
-; CHECK-NEXT:    bl OUTLINED_FUNCTION_1
+; CHECK-NEXT:    smstop sm
+; CHECK-NEXT:    bl callee
 ; CHECK-NEXT:    smstart sm
 ; CHECK-NEXT:    ldp d9, d8, [sp, #48] // 16-byte Folded Reload
 ; CHECK-NEXT:    ldr x30, [sp, #64] // 8-byte Folded Reload
-; CHECK-NEXT:    b OUTLINED_FUNCTION_0
+; CHECK-NEXT:    ldp d11, d10, [sp, #32] // 16-byte Folded Reload
+; CHECK-NEXT:    ldp d13, d12, [sp, #16] // 16-byte Folded Reload
+; CHECK-NEXT:    ldp d15, d14, [sp], #80 // 16-byte Folded Reload
+; CHECK-NEXT:    ret
+;
+; OUTLINER-LABEL: streaming_mode_change3:
+; OUTLINER-NOT: OUTLINED_FUNCTION_
   call void @callee();
   ret void;
 }
 
-; CHECK-LABEL: OUTLINED_FUNCTION_0:
-; CHECK:       // %bb.0:
-; CHECK-NEXT:    ldp d11, d10, [sp, #32]
-; CHECK-NEXT:    ldp d13, d12, [sp, #16]
-; CHECK-NEXT:    ldp d15, d14, [sp], #80
-; CHECK-NEXT:    ret
-
-; CHECK-LABEL: OUTLINED_FUNCTION_1:
-; CHECK:       // %bb.0:
-; CHECK-NEXT:    smstop	sm
-; CHECK-NEXT:    b callee
-
 attributes #0 = { "aarch64_pstate_sm_enabled" nounwind }



More information about the llvm-commits mailing list