[llvm] [AArch64][SME] Disable tail-call optimization for __arm_locally_streaming functions. (PR #65258)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 4 05:33:53 PDT 2023
https://github.com/sdesmalen-arm created https://github.com/llvm/llvm-project/pull/65258:
When calling e.g. a streaming-compatible function (which requires no streaming-mode change), LLVM would otherwise emit:
// function prologue
smstart
b streaming_compatible_function // tail call
// never an smstop
>From 3a45f9cdd76e14c8f9a3977328a9a5a179daeae8 Mon Sep 17 00:00:00 2001
From: Sander de Smalen <sander.desmalen at arm.com>
Date: Mon, 4 Sep 2023 11:45:39 +0100
Subject: [PATCH] [AArch64][SME] Disable tail-call optimization for
__arm_locally_streaming functions.
When calling e.g. a streaming-compatible function (which requires no streaming-mode change),
LLVM would otherwise emit:
// function prologue
smstart
b streaming_compatible_function // tail call
// never an smstop
---
.../Target/AArch64/AArch64ISelLowering.cpp | 3 ++-
.../CodeGen/AArch64/sme-streaming-body.ll | 21 +++++++++++++++++++
2 files changed, 23 insertions(+), 1 deletion(-)
diff --git a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
index 0c8432daeb8c56c..d82575dd978088c 100644
--- a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
+++ b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
@@ -6977,7 +6977,8 @@ bool AArch64TargetLowering::isEligibleForTailCallOptimization(
SMEAttrs CallerAttrs(MF.getFunction());
auto CalleeAttrs = CLI.CB ? SMEAttrs(*CLI.CB) : SMEAttrs(SMEAttrs::Normal);
if (CallerAttrs.requiresSMChange(CalleeAttrs) ||
- CallerAttrs.requiresLazySave(CalleeAttrs))
+ CallerAttrs.requiresLazySave(CalleeAttrs) ||
+ CallerAttrs.hasStreamingBody())
return false;
// Functions using the C or Fast calling convention that have an SVE signature
diff --git a/llvm/test/CodeGen/AArch64/sme-streaming-body.ll b/llvm/test/CodeGen/AArch64/sme-streaming-body.ll
index ff23ed9dfe5a2d5..1aaef90e9eed867 100644
--- a/llvm/test/CodeGen/AArch64/sme-streaming-body.ll
+++ b/llvm/test/CodeGen/AArch64/sme-streaming-body.ll
@@ -306,3 +306,24 @@ for.cond.cleanup:
ret float %add
}
+
+define void @disable_tailcallopt() "aarch64_pstate_sm_body" nounwind {
+; CHECK-LABEL: disable_tailcallopt:
+; 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: smstart sm
+; CHECK-NEXT: bl streaming_compatible_callee
+; CHECK-NEXT: smstop sm
+; CHECK-NEXT: ldp d9, d8, [sp, #48] // 16-byte Folded Reload
+; CHECK-NEXT: ldr x30, [sp, #64] // 8-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
+ tail call void @streaming_compatible_callee();
+ ret void;
+}
More information about the llvm-commits
mailing list