Fix a bug in the x86-32 code generated for segmented stacks.
authorSanjoy Das <sanjoy@playingwithpointers.com>
Sat, 3 Dec 2011 09:21:07 +0000 (09:21 +0000)
committerSanjoy Das <sanjoy@playingwithpointers.com>
Sat, 3 Dec 2011 09:21:07 +0000 (09:21 +0000)
Currently LLVM pads the call to __morestack with a add and sub of 8
bytes to esp.  This isn't correct since __morestack expects the call
to be followed directly by a ret.

This commit also adjusts the relevant test-case.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@145765 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/X86/X86FrameLowering.cpp
test/CodeGen/X86/segmented-stacks.ll

index ed3118af0583153d2953ae8702f3fbd99c33247f..182af84f7cac9cb89ecbf0682b10bd2443a3bdaa 100644 (file)
@@ -1394,9 +1394,6 @@ X86FrameLowering::adjustForSegmentedStacks(MachineFunction &MF) const {
     MF.getRegInfo().setPhysRegUsed(X86::R10);
     MF.getRegInfo().setPhysRegUsed(X86::R11);
   } else {
-    // Since we'll call __morestack, stack alignment needs to be preserved.
-    BuildMI(allocMBB, DL, TII.get(X86::SUB32ri), X86::ESP).addReg(X86::ESP)
-      .addImm(8);
     BuildMI(allocMBB, DL, TII.get(X86::PUSHi32))
       .addImm(X86FI->getArgumentStackSize());
     BuildMI(allocMBB, DL, TII.get(X86::PUSHi32))
@@ -1411,11 +1408,6 @@ X86FrameLowering::adjustForSegmentedStacks(MachineFunction &MF) const {
     BuildMI(allocMBB, DL, TII.get(X86::CALLpcrel32))
       .addExternalSymbol("__morestack");
 
-  // __morestack only seems to remove 8 bytes off the stack. Add back the
-  // additional 8 bytes we added before pushing the arguments.
-  if (!Is64Bit)
-    BuildMI(allocMBB, DL, TII.get(X86::ADD32ri), X86::ESP).addReg(X86::ESP)
-      .addImm(8);
   if (IsNested)
     BuildMI(allocMBB, DL, TII.get(X86::MORESTACK_RET_RESTORE_R10));
   else
index a92aca5abb2b7696da7c92bc22a91429c60a8ff1..c28c31911d24aa83a41fd6fcf4455a31c6059a7b 100644 (file)
@@ -23,11 +23,9 @@ false:
 ; X32:      leal -12(%esp), %ecx
 ; X32-NEXT: cmpl %gs:48, %ecx
 
-; X32:      subl $8, %esp
-; X32-NEXT: pushl $4
+; X32:      pushl $4
 ; X32-NEXT: pushl $12
 ; X32-NEXT: calll __morestack
-; X32-NEXT: addl $8, %esp
 ; X32-NEXT: ret 
 
 ; X32:      movl %esp, %eax
@@ -72,11 +70,9 @@ define i32 @test_nested(i32 * nest %closure, i32 %other) {
 ; X32-NEXT: cmpl %gs:48, %edx
 
 
-; X32:      subl $8, %esp
-; X32-NEXT: pushl $4
+; X32:      pushl $4
 ; X32-NEXT: pushl $0
 ; X32-NEXT: calll __morestack
-; X32-NEXT: addl $8, %esp
 ; X32-NEXT: ret
 
 ; X64:      leaq (%rsp), %r11