[llvm] 2e0940c - [X86] Fix for offsets of CFA directives
Phoebe Wang via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 27 19:04:34 PST 2023
Author: Theodoros Kasampalis
Date: 2023-02-28T10:30:06+08:00
New Revision: 2e0940c6a0857e3cc6aecfe7dd0c4cde94e1ae9a
URL: https://github.com/llvm/llvm-project/commit/2e0940c6a0857e3cc6aecfe7dd0c4cde94e1ae9a
DIFF: https://github.com/llvm/llvm-project/commit/2e0940c6a0857e3cc6aecfe7dd0c4cde94e1ae9a.diff
LOG: [X86] Fix for offsets of CFA directives
`emitPrologue` may insert stack pointer adjustment in tail call optimized functions where the callee argument stack size is bigger than the caller's. In such a case, the adjustment must be taken into account when generating CFA directives.
Reviewed By: pengfei
Differential Revision: https://reviews.llvm.org/D143618
Added:
llvm/test/CodeGen/X86/tailcc-dwarf.ll
Modified:
llvm/lib/Target/X86/X86FrameLowering.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Target/X86/X86FrameLowering.cpp b/llvm/lib/Target/X86/X86FrameLowering.cpp
index 1f827587d115..cb42a1025ea2 100644
--- a/llvm/lib/Target/X86/X86FrameLowering.cpp
+++ b/llvm/lib/Target/X86/X86FrameLowering.cpp
@@ -1645,14 +1645,16 @@ void X86FrameLowering::emitPrologue(MachineFunction &MF,
// Define the current CFA rule to use the provided offset.
assert(StackSize);
BuildCFI(MBB, MBBI, DL,
- MCCFIInstruction::cfiDefCfaOffset(nullptr, -2 * stackGrowth),
+ MCCFIInstruction::cfiDefCfaOffset(
+ nullptr, -2 * stackGrowth + (int)TailCallArgReserveSize),
MachineInstr::FrameSetup);
// Change the rule for the FramePtr to be an "offset" rule.
unsigned DwarfFramePtr = TRI->getDwarfRegNum(MachineFramePtr, true);
BuildCFI(MBB, MBBI, DL,
MCCFIInstruction::createOffset(nullptr, DwarfFramePtr,
- 2 * stackGrowth),
+ 2 * stackGrowth -
+ (int)TailCallArgReserveSize),
MachineInstr::FrameSetup);
}
diff --git a/llvm/test/CodeGen/X86/tailcc-dwarf.ll b/llvm/test/CodeGen/X86/tailcc-dwarf.ll
new file mode 100644
index 000000000000..2676a091081e
--- /dev/null
+++ b/llvm/test/CodeGen/X86/tailcc-dwarf.ll
@@ -0,0 +1,47 @@
+; RUN: llc -mtriple=x86_64-unknown-linux-gnu -O0 --frame-pointer=non-leaf %s -o - | FileCheck %s
+
+%block = type { %blockheader, [0 x i64*] }
+%blockheader = type { i64 }
+
+define void @scanStackRoots(i32) {
+ ret void
+}
+
+define i32 @main(i32 %argc, i8** %argv) {
+entry:
+ %0 = call tailcc %block* @apply_rule_6870(%block* null, %block* null)
+ ret i32 0
+}
+
+define internal tailcc %block* @apply_rule_6870(%block* %0, %block* %1) {
+entry:
+ %2 = tail call tailcc %block* @sender12(%block* %0, %block* %1)
+ ret %block* null
+}
+
+define internal tailcc %block* @sender12(%block* %0, %block* %1) {
+; CHECK-LABEL: sender12:
+; CHECK: .cfi_startproc
+; CHECK: subq $8160, %rsp
+; CHECK: pushq %rbp
+; CHECK: .cfi_def_cfa_offset 8176
+; CHECK: .cfi_offset %rbp, -8176
+entry:
+ %a = alloca [1024 x i32]
+ %b = load [1024 x i32], [1024 x i32]* %a
+ call void @scanStackRoots(i32 1)
+ %2 = tail call tailcc %block* @apply_rule_6300(%block* %0, %block* %1, [1024 x i32] %b)
+ ret %block* %2
+}
+
+define internal tailcc %block* @apply_rule_6300(%block* %0, %block* %1, [1024 x i32] %2) {
+entry:
+ %3 = tail call tailcc %block* @sender4(%block* %0, %block* %1)
+ ret %block* %3
+}
+
+define internal tailcc %block* @sender4(%block* %0, %block* %1) {
+entry:
+ call void @scanStackRoots(i32 2)
+ ret %block* null
+}
More information about the llvm-commits
mailing list