[llvm-commits] [llvm] r145765 - in /llvm/trunk: lib/Target/X86/X86FrameLowering.cpp test/CodeGen/X86/segmented-stacks.ll

Sanjoy Das sanjoy at playingwithpointers.com
Sat Dec 3 01:21:07 PST 2011


Author: sanjoy
Date: Sat Dec  3 03:21:07 2011
New Revision: 145765

URL: http://llvm.org/viewvc/llvm-project?rev=145765&view=rev
Log:
Fix a bug in the x86-32 code generated for segmented stacks.

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.

Modified:
    llvm/trunk/lib/Target/X86/X86FrameLowering.cpp
    llvm/trunk/test/CodeGen/X86/segmented-stacks.ll

Modified: llvm/trunk/lib/Target/X86/X86FrameLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86FrameLowering.cpp?rev=145765&r1=145764&r2=145765&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86FrameLowering.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86FrameLowering.cpp Sat Dec  3 03:21:07 2011
@@ -1394,9 +1394,6 @@
     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 @@
     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

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=145765&r1=145764&r2=145765&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/segmented-stacks.ll (original)
+++ llvm/trunk/test/CodeGen/X86/segmented-stacks.ll Sat Dec  3 03:21:07 2011
@@ -23,11 +23,9 @@
 ; 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 @@
 ; 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





More information about the llvm-commits mailing list