Move all inline-asm-fpstack tests to a single file.
[oota-llvm.git] / test / CodeGen / X86 / inline-asm-fpstack.ll
1 ; RUN: llc < %s -mtriple=i386-apple-darwin | FileCheck %s
2
3 ; There should be no stack manipulations between the inline asm and ret.
4 ; CHECK: test1
5 ; CHECK: InlineAsm End
6 ; CHECK-NEXT: ret
7 define x86_fp80 @test1() {
8         %tmp85 = call x86_fp80 asm sideeffect "fld0", "={st(0)}"()
9         ret x86_fp80 %tmp85
10 }
11
12 ; CHECK: test2
13 ; CHECK: InlineAsm End
14 ; CHECK-NEXT: ret
15 define double @test2() {
16         %tmp85 = call double asm sideeffect "fld0", "={st(0)}"()
17         ret double %tmp85
18 }
19
20 ; Setting up argument in st(0) should be a single fld.
21 ; CHECK: test3
22 ; CHECK: fld
23 ; CHECK-NEXT: InlineAsm Start
24 ; Asm consumes stack, nothing should be popped.
25 ; CHECK: InlineAsm End
26 ; CHECK-NOT: fstp
27 ; CHECK: ret
28 define void @test3(x86_fp80 %X) {
29         call void asm sideeffect "frob ", "{st(0)},~{st},~{dirflag},~{fpsr},~{flags}"( x86_fp80 %X)
30         ret void
31 }
32
33 ; CHECK: test4
34 ; CHECK: fld
35 ; CHECK-NEXT: InlineAsm Start
36 ; CHECK: InlineAsm End
37 ; CHECK-NOT: fstp
38 ; CHECK: ret
39 define void @test4(double %X) {
40         call void asm sideeffect "frob ", "{st(0)},~{st},~{dirflag},~{fpsr},~{flags}"( double %X)
41         ret void
42 }
43
44 ; Same as test3/4, but using value from fadd.
45 ; The fadd can be done in xmm or x87 regs - we don't test that.
46 ; CHECK: test5
47 ; CHECK: InlineAsm End
48 ; CHECK-NOT: fstp
49 ; CHECK: ret
50 define void @test5(double %X) {
51         %Y = fadd double %X, 123.0
52         call void asm sideeffect "frob ", "{st(0)},~{st},~{dirflag},~{fpsr},~{flags}"( double %Y)
53         ret void
54 }
55
56 ; CHECK: test6
57 define void @test6(double %A, double %B, double %C, 
58                    double %D, double %E) nounwind  {
59 entry:
60 ; Uses the same value twice, should have one fstp after the asm.
61 ; CHECK: foo
62 ; CHECK: InlineAsm End
63 ; CHECK-NEXT: fstp
64 ; CHECK-NOT: fstp
65         tail call void asm sideeffect "foo $0 $1", "f,f,~{dirflag},~{fpsr},~{flags}"( double %A, double %A ) nounwind 
66 ; Uses two different values, should be in st(0)/st(1) and both be popped.
67 ; CHECK: bar
68 ; CHECK: InlineAsm End
69 ; CHECK-NEXT: fstp
70 ; CHECK-NEXT: fstp
71         tail call void asm sideeffect "bar $0 $1", "f,f,~{dirflag},~{fpsr},~{flags}"( double %B, double %C ) nounwind 
72 ; Uses two different values, one of which isn't killed in this asm, it
73 ; should not be popped after the asm.
74 ; CHECK: baz
75 ; CHECK: InlineAsm End
76 ; CHECK-NEXT: fstp
77 ; CHECK-NOT: fstp
78         tail call void asm sideeffect "baz $0 $1", "f,f,~{dirflag},~{fpsr},~{flags}"( double %D, double %E ) nounwind 
79 ; This is the last use of %D, so it should be popped after.
80 ; CHECK: baz
81 ; CHECK: InlineAsm End
82 ; CHECK-NEXT: fstp
83 ; CHECK-NOT: fstp
84 ; CHECK: ret
85         tail call void asm sideeffect "baz $0", "f,~{dirflag},~{fpsr},~{flags}"( double %D ) nounwind 
86         ret void
87 }
88
89 ; PR4185
90 ; Passing a non-killed value to asm in {st}.
91 ; Make sure it is duped before.
92 ; asm kills st(0), so we shouldn't pop anything
93 ; CHECK: testPR4185
94 ; CHECK: fld %st(0)
95 ; CHECK: fistpl
96 ; CHECK-NOT: fstp
97 ; CHECK: fistpl
98 ; CHECK-NOT: fstp
99 ; CHECK: ret
100 ; A valid alternative would be to remat the constant pool load before each
101 ; inline asm.
102 define void @testPR4185() {
103 return:
104         call void asm sideeffect "fistpl $0", "{st},~{st}"(double 1.000000e+06)
105         call void asm sideeffect "fistpl $0", "{st},~{st}"(double 1.000000e+06)
106         ret void
107 }
108
109 ; PR4459
110 ; The return value from ceil must be duped before being consumed by asm.
111 ; CHECK: testPR4459
112 ; CHECK: ceil
113 ; CHECK: fld %st(0)
114 ; CHECK-NOT: fxch
115 ; CHECK: fistpl
116 ; CHECK-NOT: fxch
117 ; CHECK: fstpt
118 ; CHECK: test
119 define void @testPR4459(x86_fp80 %a) {
120 entry:
121         %0 = call x86_fp80 @ceil(x86_fp80 %a)
122         call void asm sideeffect "fistpl $0", "{st},~{st}"( x86_fp80 %0)
123         call void @test3(x86_fp80 %0 )
124         ret void
125 }
126 declare x86_fp80 @ceil(x86_fp80)
127
128 ; PR4484
129 ; test1 leaves a value on the stack that is needed after the asm.
130 ; CHECK: testPR4484
131 ; CHECK: test1
132 ; CHECK-NOT: fstp
133 ; Load %a from stack after ceil
134 ; CHECK: fldt
135 ; CHECK-NOT: fxch
136 ; CHECK: fistpl
137 ; CHECK-NOT: fstp
138 ; Set up call to test.
139 ; CHECK: fstpt
140 ; CHECK: test
141 define void @testPR4484(x86_fp80 %a) {
142 entry:
143         %0 = call x86_fp80 @test1()
144         call void asm sideeffect "fistpl $0", "{st},~{st}"(x86_fp80 %a)
145         call void @test3(x86_fp80 %0)
146         ret void
147 }
148
149 ; PR4485
150 ; CHECK: testPR4485
151 define void @testPR4485(x86_fp80* %a) {
152 entry:
153         %0 = load x86_fp80* %a, align 16
154         %1 = fmul x86_fp80 %0, 0xK4006B400000000000000
155         %2 = fmul x86_fp80 %1, 0xK4012F424000000000000
156         tail call void asm sideeffect "fistpl $0", "{st},~{st}"(x86_fp80 %2)
157         %3 = load x86_fp80* %a, align 16
158         %4 = fmul x86_fp80 %3, 0xK4006B400000000000000
159         %5 = fmul x86_fp80 %4, 0xK4012F424000000000000
160         tail call void asm sideeffect "fistpl $0", "{st},~{st}"(x86_fp80 %5)
161         ret void
162 }