[llvm] [AArch64] Allow SME peephole opts without +sme in streaming compat functions (PR #222728)

via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 10 10:56:29 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-backend-aarch64

Author: Benjamin Maxwell (MacDue)

<details>
<summary>Changes</summary>



---
Full diff: https://github.com/llvm/llvm-project/pull/222728.diff


2 Files Affected:

- (modified) llvm/lib/Target/AArch64/SMEPeepholeOpt.cpp (+5-2) 
- (added) llvm/test/CodeGen/AArch64/sme-peephole-opt-sm-compat.ll (+36) 


``````````diff
diff --git a/llvm/lib/Target/AArch64/SMEPeepholeOpt.cpp b/llvm/lib/Target/AArch64/SMEPeepholeOpt.cpp
index 720e7c8b05d90..8e617e64ff230 100644
--- a/llvm/lib/Target/AArch64/SMEPeepholeOpt.cpp
+++ b/llvm/lib/Target/AArch64/SMEPeepholeOpt.cpp
@@ -293,7 +293,11 @@ bool SMEPeepholeOpt::runOnMachineFunction(MachineFunction &MF) {
   if (skipFunction(MF.getFunction()))
     return false;
 
-  if (!MF.getSubtarget<AArch64Subtarget>().hasSME())
+  AArch64FunctionInfo *AFI = MF.getInfo<AArch64FunctionInfo>();
+  SMEAttrs SMEFnAttrs = AFI->getSMEFnAttrs();
+
+  if (!MF.getSubtarget<AArch64Subtarget>().hasSME() &&
+      !SMEFnAttrs.hasStreamingCompatibleInterface())
     return false;
 
   assert(MF.getRegInfo().isSSA() && "Expected to be run on SSA form!");
@@ -316,7 +320,6 @@ bool SMEPeepholeOpt::runOnMachineFunction(MachineFunction &MF) {
     }
   }
 
-  AArch64FunctionInfo *AFI = MF.getInfo<AArch64FunctionInfo>();
   if (FunctionHasAllSMChangesRemoved)
     AFI->setHasStreamingModeChanges(false);
 
diff --git a/llvm/test/CodeGen/AArch64/sme-peephole-opt-sm-compat.ll b/llvm/test/CodeGen/AArch64/sme-peephole-opt-sm-compat.ll
new file mode 100644
index 0000000000000..5dfc232448a5e
--- /dev/null
+++ b/llvm/test/CodeGen/AArch64/sme-peephole-opt-sm-compat.ll
@@ -0,0 +1,36 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 6
+; RUN: llc -mtriple=aarch64-linux-gnu -aarch64-streaming-hazard-size=0 -mattr=+sve < %s | FileCheck %s
+
+declare void @callee()
+
+; streaming-compatible caller -> normal callees
+define void @test0() nounwind "aarch64_pstate_sm_compatible" {
+; CHECK-LABEL: test0:
+; 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:    stp x30, x19, [sp, #64] // 16-byte Folded Spill
+; CHECK-NEXT:    bl __arm_sme_state
+; CHECK-NEXT:    mov x19, x0
+; CHECK-NEXT:    tbz w19, #0, .LBB0_2
+; CHECK-NEXT:  // %bb.1:
+; CHECK-NEXT:    smstop sm
+; CHECK-NEXT:  .LBB0_2:
+; CHECK-NEXT:    bl callee
+; CHECK-NEXT:    bl callee
+; CHECK-NEXT:    tbz w19, #0, .LBB0_4
+; CHECK-NEXT:  // %bb.3:
+; CHECK-NEXT:    smstart sm
+; CHECK-NEXT:  .LBB0_4:
+; CHECK-NEXT:    ldp x30, x19, [sp, #64] // 16-byte Folded Reload
+; CHECK-NEXT:    ldp d9, d8, [sp, #48] // 16-byte Folded Reload
+; 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
+  call void @callee()
+  call void @callee()
+  ret void
+}

``````````

</details>


https://github.com/llvm/llvm-project/pull/222728


More information about the llvm-commits mailing list