[llvm-commits] [llvm] r40018 - /llvm/trunk/lib/Target/X86/X86RegisterInfo.cpp

Evan Cheng evan.cheng at apple.com
Wed Jul 18 14:26:07 PDT 2007


Author: evancheng
Date: Wed Jul 18 16:26:06 2007
New Revision: 40018

URL: http://llvm.org/viewvc/llvm-project?rev=40018&view=rev
Log:
Use MOV instead of LEA to restore ESP if callee-saved frame size is 0; if previous instruction updates esp, fold it in.

Modified:
    llvm/trunk/lib/Target/X86/X86RegisterInfo.cpp

Modified: llvm/trunk/lib/Target/X86/X86RegisterInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86RegisterInfo.cpp?rev=40018&r1=40017&r2=40018&view=diff

==============================================================================
--- llvm/trunk/lib/Target/X86/X86RegisterInfo.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86RegisterInfo.cpp Wed Jul 18 16:26:06 2007
@@ -1361,17 +1361,7 @@
     --MBBI;
   }
 
-  // If dynamic alloca is used, then reset esp to point to the last
-  // callee-saved slot before popping them off!
-  if (MFI->hasVarSizedObjects()) {
-    unsigned Opc = Is64Bit ? X86::LEA64r : X86::LEA32r;
-    MachineInstr *MI = addRegOffset(BuildMI(TII.get(Opc), StackPtr),
-                                    FramePtr, -CSSize);
-    MBB.insert(MBBI, MI);
-    NumBytes = 0;
-  }
-
-  if (NumBytes) {    // adjust stack pointer back: ESP += numbytes
+  if (NumBytes || MFI->hasVarSizedObjects()) {
     // If there is an ADD32ri or SUB32ri of ESP immediately before this
     // instruction, merge the two instructions.
     if (MBBI != MBB.begin()) {
@@ -1389,11 +1379,27 @@
         MBB.erase(PI);
       }
     }
+  }
 
-    if (NumBytes)
-      emitSPUpdate(MBB, MBBI, StackPtr, NumBytes, Is64Bit, TII);
+  // If dynamic alloca is used, then reset esp to point to the last
+  // callee-saved slot before popping them off!
+  if (MFI->hasVarSizedObjects()) {
+    unsigned Opc = Is64Bit ? X86::LEA64r : X86::LEA32r;
+    if (CSSize) {
+      MachineInstr *MI = addRegOffset(BuildMI(TII.get(Opc), StackPtr),
+                                      FramePtr, -CSSize);
+      MBB.insert(MBBI, MI);
+    } else
+      BuildMI(MBB, MBBI, TII.get(Is64Bit ? X86::MOV64rr : X86::MOV32rr),StackPtr).
+        addReg(FramePtr);
+
+    NumBytes = 0;
   }
 
+  // adjust stack pointer back: ESP += numbytes
+  if (NumBytes)
+    emitSPUpdate(MBB, MBBI, StackPtr, NumBytes, Is64Bit, TII);
+
   // We're returning from function via eh_return.
   if (RetOpcode == X86::EH_RETURN) {
     MBBI = prior(MBB.end());





More information about the llvm-commits mailing list