[PATCH] Don't force the use of a base pointer with MS inline asm
Reid Kleckner
rnk at google.com
Wed Aug 7 17:33:37 PDT 2013
This way we only use a base pointer if we need to realign the stack.
Otherwise we use the frame pointer. We still have a bug in that case if
the inline asm clobbers esi.
Partial fix for PR16830.
http://llvm-reviews.chandlerc.com/D1317
Files:
lib/Target/X86/X86RegisterInfo.cpp
test/CodeGen/X86/ms-inline-asm.ll
Index: lib/Target/X86/X86RegisterInfo.cpp
===================================================================
--- lib/Target/X86/X86RegisterInfo.cpp
+++ lib/Target/X86/X86RegisterInfo.cpp
@@ -396,18 +396,14 @@
if (!EnableBasePointer)
return false;
- // When we need stack realignment and there are dynamic allocas, we can't
- // reference off of the stack pointer, so we reserve a base pointer.
- //
- // This is also true if the function contain MS-style inline assembly. We
- // do this because if any stack changes occur in the inline assembly, e.g.,
- // "pusha", then any C local variable or C argument references in the
- // inline assembly will be wrong because the SP is not properly tracked.
- if ((needsStackRealignment(MF) && MFI->hasVarSizedObjects()) ||
- MF.hasMSInlineAsm())
- return true;
-
- return false;
+ // When we need stack realignment, we can't address the stack from the frame
+ // pointer. When we have dynamic allocas or MS inline asm, we can't address
+ // variables from the stack pointer. MS inline asm can reference locals
+ // while also adjusting the stack pointer. When we can't use both the SP and
+ // the FP, we need a separate base pointer register.
+ bool CantUseFP = needsStackRealignment(MF);
+ bool CantUseSP = MFI->hasVarSizedObjects() || MF.hasMSInlineAsm();
+ return CantUseFP && CantUseSP;
}
bool X86RegisterInfo::canRealignStack(const MachineFunction &MF) const {
Index: test/CodeGen/X86/ms-inline-asm.ll
===================================================================
--- test/CodeGen/X86/ms-inline-asm.ll
+++ test/CodeGen/X86/ms-inline-asm.ll
@@ -103,8 +103,8 @@
; CHECK: {{## InlineAsm End|#NO_APP}}
; CHECK: {{## InlineAsm Start|#APP}}
; CHECK: .intel_syntax
-; CHECK: mov dword ptr [esi], edi
+; CHECK: mov dword ptr [ebp - 8], edi
; CHECK: .att_syntax
; CHECK: {{## InlineAsm End|#NO_APP}}
-; CHECK: movl (%esi), %eax
+; CHECK: movl -8(%ebp), %eax
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D1317.1.patch
Type: text/x-patch
Size: 1977 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130807/930bf9c2/attachment.bin>
More information about the llvm-commits
mailing list