1263320SdimPull in r196986 from upstream llvm trunk (by Reid Kleckner):
2263320Sdim
3263320Sdim  Revert the backend fatal error from r196939
4263320Sdim
5263320Sdim  The combination of inline asm, stack realignment, and dynamic allocas
6263320Sdim  turns out to be too common to reject out of hand.
7263320Sdim
8263320Sdim  ASan inserts empy inline asm fragments and uses aligned allocas.
9263320Sdim  Compiling any trivial function containing a dynamic alloca with ASan is
10263320Sdim  enough to trigger the check.
11263320Sdim
12263320Sdim  XFAIL the test cases that would be miscompiled and add one that uses the
13263320Sdim  relevant functionality.
14263320Sdim
15269012SemasteIntroduced here: http://svnweb.freebsd.org/changeset/base/263312
16263320Sdim
17263320SdimIndex: lib/Target/X86/X86RegisterInfo.cpp
18263320Sdim===================================================================
19263320Sdim--- lib/Target/X86/X86RegisterInfo.cpp
20263320Sdim+++ lib/Target/X86/X86RegisterInfo.cpp
21263320Sdim@@ -347,12 +347,6 @@ BitVector X86RegisterInfo::getReservedRegs(const M
22263320Sdim         "Stack realignment in presence of dynamic allocas is not supported with"
23263320Sdim         "this calling convention.");
24263320Sdim 
25263320Sdim-    // FIXME: Do a proper analysis of the inline asm to see if it actually
26263320Sdim-    // conflicts with the base register we chose.
27263320Sdim-    if (MF.hasInlineAsm())
28263320Sdim-      report_fatal_error("Stack realignment in presence of dynamic stack "
29263320Sdim-                         "adjustments is not supported with inline assembly.");
30263320Sdim-
31263320Sdim     for (MCSubRegIterator I(getBaseRegister(), this, /*IncludeSelf=*/true);
32263320Sdim          I.isValid(); ++I)
33263320Sdim       Reserved.set(*I);
34263320SdimIndex: test/CodeGen/X86/inline-asm-stack-realign3.ll
35263320Sdim===================================================================
36263320Sdim--- test/CodeGen/X86/inline-asm-stack-realign3.ll
37263320Sdim+++ test/CodeGen/X86/inline-asm-stack-realign3.ll
38263320Sdim@@ -0,0 +1,29 @@
39263320Sdim+; RUN: llc -march=x86 < %s | FileCheck %s
40263320Sdim+
41263320Sdim+declare void @bar(i32* %junk)
42263320Sdim+
43263320Sdim+define i32 @foo(i1 %cond) {
44263320Sdim+entry:
45263320Sdim+  %r = alloca i32, align 128
46263320Sdim+  store i32 -1, i32* %r, align 128
47263320Sdim+  br i1 %cond, label %doit, label %skip
48263320Sdim+
49263320Sdim+doit:
50263320Sdim+  call void asm sideeffect "xor %ecx, %ecx\0A\09mov %ecx, $0", "=*m,~{ecx},~{flags}"(i32* %r)
51263320Sdim+  %junk = alloca i32
52263320Sdim+  call void @bar(i32* %junk)
53263320Sdim+  br label %skip
54263320Sdim+
55263320Sdim+skip:
56263320Sdim+  %0 = load i32* %r, align 128
57263320Sdim+  ret i32 %0
58263320Sdim+}
59263320Sdim+
60263320Sdim+; CHECK-LABEL: foo:
61263320Sdim+; CHECK: pushl %ebp
62263320Sdim+; CHECK: andl $-128, %esp
63263320Sdim+; CHECK: xor %ecx, %ecx
64263320Sdim+; CHECK-NEXT: mov %ecx, (%esi)
65263320Sdim+; CHECK: movl (%esi), %eax
66263320Sdim+; CHECK: popl %ebp
67263320Sdim+; CHECK: ret
68263320SdimIndex: test/CodeGen/X86/inline-asm-stack-realign.ll
69263320Sdim===================================================================
70263320Sdim--- test/CodeGen/X86/inline-asm-stack-realign.ll
71263320Sdim+++ test/CodeGen/X86/inline-asm-stack-realign.ll
72263320Sdim@@ -1,8 +1,8 @@
73263320Sdim ; RUN: not llc -mtriple=i686-pc-win32 < %s 2>&1 | FileCheck %s
74263320Sdim 
75263320Sdim-; We don't currently support realigning the stack and adjusting the stack
76263320Sdim-; pointer in inline asm.  This commonly happens in MS inline assembly using
77263320Sdim-; push and pop.
78263320Sdim+; FIXME: This is miscompiled due to our unconditional use of ESI as the base
79263320Sdim+; pointer.
80263320Sdim+; XFAIL:
81263320Sdim 
82263320Sdim ; CHECK: Stack realignment in presence of dynamic stack adjustments is not supported with inline assembly
83263320Sdim 
84263320SdimIndex: test/CodeGen/X86/inline-asm-stack-realign2.ll
85263320Sdim===================================================================
86263320Sdim--- test/CodeGen/X86/inline-asm-stack-realign2.ll
87263320Sdim+++ test/CodeGen/X86/inline-asm-stack-realign2.ll
88263320Sdim@@ -1,7 +1,8 @@
89263320Sdim ; RUN: not llc -mtriple=i686-pc-win32 < %s 2>&1 | FileCheck %s
90263320Sdim 
91263320Sdim-; We don't currently support realigning the stack and adjusting the stack
92263320Sdim-; pointer in inline asm.  This can even happen in GNU asm.
93263320Sdim+; FIXME: This is miscompiled due to our unconditional use of ESI as the base
94263320Sdim+; pointer.
95263320Sdim+; XFAIL:
96263320Sdim 
97263320Sdim ; CHECK: Stack realignment in presence of dynamic stack adjustments is not supported with inline assembly
98263320Sdim 
99