[llvm] [AArch64] Fix the size passed to __trampoline_setup (PR #118234)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 8 14:04:10 PST 2025
https://github.com/ssijaric-nv updated https://github.com/llvm/llvm-project/pull/118234
>From 557cd59f0a2fdb02cd256ff8139bbe03c0d5341a Mon Sep 17 00:00:00 2001
From: Sanjin Sijaric <ssijaric at nvidia.com>
Date: Sun, 1 Dec 2024 14:25:13 -0800
Subject: [PATCH 1/2] [AArch64] Fix the size passed to __trampoline_setup
The trampoline size is 36 bytes on AArch64. The runtime function __trampoline_setup
aborts as it expects the trampoline size of at least 36 bytes, and the size passed
is 20 bytes. Fix the inconsistency in AArch64TargetLowering::LowerINIT_TRAMPOLINE.
---
llvm/lib/Target/AArch64/AArch64ISelLowering.cpp | 11 +++++++++--
llvm/test/CodeGen/AArch64/trampoline.ll | 1 +
2 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
index e1be825fcf7bf3..418cef075ba65f 100644
--- a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
+++ b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
@@ -7148,9 +7148,16 @@ SDValue AArch64TargetLowering::LowerINIT_TRAMPOLINE(SDValue Op,
Entry.Ty = IntPtrTy;
Entry.Node = Trmp;
Args.push_back(Entry);
- Entry.Node = DAG.getConstant(20, dl, MVT::i64);
- Args.push_back(Entry);
+ if (auto *FI = dyn_cast<FrameIndexSDNode>(Trmp.getNode())) {
+ MachineFunction &MF = DAG.getMachineFunction();
+ MachineFrameInfo &MFI = MF.getFrameInfo();
+ Entry.Node =
+ DAG.getConstant(MFI.getObjectSize(FI->getIndex()), dl, MVT::i64);
+ } else
+ Entry.Node = DAG.getConstant(36, dl, MVT::i64);
+
+ Args.push_back(Entry);
Entry.Node = FPtr;
Args.push_back(Entry);
Entry.Node = Nest;
diff --git a/llvm/test/CodeGen/AArch64/trampoline.ll b/llvm/test/CodeGen/AArch64/trampoline.ll
index 293e538a7459d4..217cda1a4ce1ca 100644
--- a/llvm/test/CodeGen/AArch64/trampoline.ll
+++ b/llvm/test/CodeGen/AArch64/trampoline.ll
@@ -12,6 +12,7 @@ define i64 @main() {
%val = alloca i64
%nval = bitcast ptr %val to ptr
%tramp = alloca [36 x i8], align 8
+ ; CHECK: mov w1, #36
; CHECK: bl __trampoline_setup
call void @llvm.init.trampoline(ptr %tramp, ptr @f, ptr %nval)
%fp = call ptr @llvm.adjust.trampoline(ptr %tramp)
>From 1225320abd650c17ce2d12cfb7755bbc90933870 Mon Sep 17 00:00:00 2001
From: Sanjin Sijaric <ssijaric at nvidia.com>
Date: Mon, 30 Dec 2024 16:11:31 -0800
Subject: [PATCH 2/2] Add a test for the non frame-index path
---
llvm/test/CodeGen/AArch64/trampoline.ll | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)
diff --git a/llvm/test/CodeGen/AArch64/trampoline.ll b/llvm/test/CodeGen/AArch64/trampoline.ll
index 217cda1a4ce1ca..30ac2aa283b3ee 100644
--- a/llvm/test/CodeGen/AArch64/trampoline.ll
+++ b/llvm/test/CodeGen/AArch64/trampoline.ll
@@ -1,5 +1,7 @@
; RUN: llc -mtriple=aarch64-- < %s | FileCheck %s
+ at trampg = internal global [36 x i8] zeroinitializer, align 8
+
declare void @llvm.init.trampoline(ptr, ptr, ptr);
declare ptr @llvm.adjust.trampoline(ptr);
@@ -8,7 +10,7 @@ define i64 @f(ptr nest %c, i64 %x, i64 %y) {
ret i64 %sum
}
-define i64 @main() {
+define i64 @func1() {
%val = alloca i64
%nval = bitcast ptr %val to ptr
%tramp = alloca [36 x i8], align 8
@@ -18,3 +20,13 @@ define i64 @main() {
%fp = call ptr @llvm.adjust.trampoline(ptr %tramp)
ret i64 0
}
+
+define i64 @func2() {
+ %val = alloca i64
+ %nval = bitcast ptr %val to ptr
+ ; CHECK: mov w1, #36
+ ; CHECK: bl __trampoline_setup
+ call void @llvm.init.trampoline(ptr @trampg, ptr @f, ptr %nval)
+ %fp = call ptr @llvm.adjust.trampoline(ptr @trampg)
+ ret i64 0
+}
More information about the llvm-commits
mailing list