[llvm] r335604 - [X86, ARM] Retain split-stack prolog check for sibling calls
Than McIntosh via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 26 07:11:30 PDT 2018
Author: thanm
Date: Tue Jun 26 07:11:30 2018
New Revision: 335604
URL: http://llvm.org/viewvc/llvm-project?rev=335604&view=rev
Log:
[X86,ARM] Retain split-stack prolog check for sibling calls
Summary:
If a routine with no stack frame makes a sibling call, we need to
preserve the stack space check even if the local stack frame is empty,
since the call target could be a "no-split" function (in which case
the linker needs to be able to fix up the prolog sequence in order to
switch to a larger stack).
This fixes PR37807.
Reviewers: cherry, javed.absar
Subscribers: srhines, llvm-commits
Differential Revision: https://reviews.llvm.org/D48444
Modified:
llvm/trunk/lib/Target/ARM/ARMFrameLowering.cpp
llvm/trunk/lib/Target/X86/X86FrameLowering.cpp
llvm/trunk/test/CodeGen/ARM/segmented-stacks.ll
llvm/trunk/test/CodeGen/X86/segmented-stacks.ll
Modified: llvm/trunk/lib/Target/ARM/ARMFrameLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/ARMFrameLowering.cpp?rev=335604&r1=335603&r2=335604&view=diff
==============================================================================
--- llvm/trunk/lib/Target/ARM/ARMFrameLowering.cpp (original)
+++ llvm/trunk/lib/Target/ARM/ARMFrameLowering.cpp Tue Jun 26 07:11:30 2018
@@ -2148,8 +2148,10 @@ void ARMFrameLowering::adjustForSegmente
uint64_t StackSize = MFI.getStackSize();
- // Do not generate a prologue for functions with a stack of size zero
- if (StackSize == 0)
+ // Do not generate a prologue for leaf functions with a stack of size zero.
+ // For non-leaf functions we have to allow for the possibility that the
+ // call is to a non-split function, as in PR37807.
+ if (StackSize == 0 && !MFI.hasTailCall())
return;
// Use R4 and R5 as scratch registers.
Modified: llvm/trunk/lib/Target/X86/X86FrameLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86FrameLowering.cpp?rev=335604&r1=335603&r2=335604&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86FrameLowering.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86FrameLowering.cpp Tue Jun 26 07:11:30 2018
@@ -2241,8 +2241,10 @@ void X86FrameLowering::adjustForSegmente
// prologue.
StackSize = MFI.getStackSize();
- // Do not generate a prologue for functions with a stack of size zero
- if (StackSize == 0)
+ // Do not generate a prologue for leaf functions with a stack of size zero.
+ // For non-leaf functions we have to allow for the possibility that the
+ // call is to a non-split function, as in PR37807.
+ if (StackSize == 0 && !MFI.hasTailCall())
return;
MachineBasicBlock *allocMBB = MF.CreateMachineBasicBlock();
Modified: llvm/trunk/test/CodeGen/ARM/segmented-stacks.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/ARM/segmented-stacks.ll?rev=335604&r1=335603&r2=335604&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/ARM/segmented-stacks.ll (original)
+++ llvm/trunk/test/CodeGen/ARM/segmented-stacks.ll Tue Jun 26 07:11:30 2018
@@ -246,4 +246,22 @@ define void @test_nostack() #0 {
; ARM-android-NOT: bl __morestack
}
+; Test to make sure that a morestack call is generated if there is a
+; sibling call, even if the function in question has no stack frame
+; (PR37807).
+
+declare i32 @callee(i32)
+
+define i32 @test_sibling_call_empty_frame(i32 %x) #0 {
+ %call = tail call i32 @callee(i32 %x) #0
+ ret i32 %call
+
+; ARM-linux: test_sibling_call_empty_frame:
+; ARM-linux: bl __morestack
+
+; ARM-android: test_sibling_call_empty_frame:
+; ARM-android: bl __morestack
+
+}
+
attributes #0 = { "split-stack" }
Modified: llvm/trunk/test/CodeGen/X86/segmented-stacks.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/segmented-stacks.ll?rev=335604&r1=335603&r2=335604&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/segmented-stacks.ll (original)
+++ llvm/trunk/test/CodeGen/X86/segmented-stacks.ll Tue Jun 26 07:11:30 2018
@@ -640,6 +640,52 @@ define void @test_nosplitstck() {
ret void
}
+; Test to make sure that a morestack call is generated if there is a
+; sibling call, even if the function in question has no stack frame
+; (PR37807).
+
+declare i32 @callee(i32)
+
+define i32 @test_sibling_call_empty_frame(i32 %x) #0 {
+ %call = tail call i32 @callee(i32 %x) #0
+ ret i32 %call
+
+; X32-Linux-LABEL: test_sibling_call_empty_frame:
+; X32-Linux: calll __morestack
+
+; X64-Linux-LABEL: test_sibling_call_empty_frame:
+; X64-Linux: callq __morestack
+
+; X64-Linux-Large-LABEL: test_sibling_call_empty_frame:
+; X64-Linux-Large: callq *__morestack_addr(%rip)
+
+; X32ABI-LABEL: test_sibling_call_empty_frame:
+; X32ABI: callq __morestack
+
+; X32-Darwin-LABEL: test_sibling_call_empty_frame:
+; X32-Darwin: calll ___morestack
+
+; X64-Darwin-LABEL: test_sibling_call_empty_frame:
+; X64-Darwin: callq ___morestack
+
+; X32-MinGW-LABEL: test_sibling_call_empty_frame:
+; X32-MinGW: calll ___morestack
+
+; X64-MinGW-LABEL: test_sibling_call_empty_frame:
+; X64-MinGW: callq __morestack
+
+; X64-FreeBSD-LABEL: test_sibling_call_empty_frame:
+; X64-FreeBSD: callq __morestack
+
+; X32-DFlyBSD-LABEL: test_sibling_call_empty_frame:
+; X32-DFlyBSD: calll __morestack
+; X32-DFlyBSD-NEXT: ret
+
+; X64-DFlyBSD-LABEL: test_sibling_call_empty_frame:
+; X64-DFlyBSD: callq __morestack
+
+}
+
attributes #0 = { "split-stack" }
; X64-Linux-Large: .rodata
More information about the llvm-commits
mailing list