1 ; RUN: llc < %s -mcpu=generic -mtriple=i386-apple-darwin -no-integrated-as | FileCheck %s
3 ; There should be no stack manipulations between the inline asm and ret.
7 define x86_fp80 @test1() {
8 %tmp85 = call x86_fp80 asm sideeffect "fld0", "={st(0)}"()
13 ; CHECK: InlineAsm End
15 define double @test2() {
16 %tmp85 = call double asm sideeffect "fld0", "={st(0)}"()
20 ; Setting up argument in st(0) should be a single fld.
23 ; CHECK-NEXT: InlineAsm Start
24 ; Asm consumes stack, nothing should be popped.
25 ; CHECK: InlineAsm End
28 define void @test3(x86_fp80 %X) {
29 call void asm sideeffect "frob ", "{st(0)},~{st},~{dirflag},~{fpsr},~{flags}"( x86_fp80 %X)
35 ; CHECK-NEXT: InlineAsm Start
36 ; CHECK: InlineAsm End
39 define void @test4(double %X) {
40 call void asm sideeffect "frob ", "{st(0)},~{st},~{dirflag},~{fpsr},~{flags}"( double %X)
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.
47 ; CHECK: InlineAsm End
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)
57 define void @test6(double %A, double %B, double %C,
58 double %D, double %E) nounwind {
60 ; Uses the same value twice, should have one fstp after the asm.
62 ; CHECK: InlineAsm End
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.
68 ; CHECK: InlineAsm End
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.
75 ; CHECK: InlineAsm End
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.
81 ; CHECK: InlineAsm End
85 tail call void asm sideeffect "baz $0", "f,~{dirflag},~{fpsr},~{flags}"( double %D ) nounwind
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
100 ; A valid alternative would be to remat the constant pool load before each
102 define void @testPR4185() {
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)
109 ; Passing a non-killed value through asm in {st}.
110 ; Make sure it is not duped before.
111 ; Second asm kills st(0), so we shouldn't pop anything
113 ; CHECK-NOT: fld %st(0)
119 ; A valid alternative would be to remat the constant pool load before each
121 define void @testPR4185b() {
123 call void asm sideeffect "fistl $0", "{st}"(double 1.000000e+06)
124 call void asm sideeffect "fistpl $0", "{st},~{st}"(double 1.000000e+06)
129 ; The return value from ceil must be duped before being consumed by asm.
138 define void @testPR4459(x86_fp80 %a) {
140 %0 = call x86_fp80 @ceil(x86_fp80 %a)
141 call void asm sideeffect "fistpl $0", "{st},~{st}"( x86_fp80 %0)
142 call void @test3(x86_fp80 %0 )
145 declare x86_fp80 @ceil(x86_fp80)
148 ; test1 leaves a value on the stack that is needed after the asm.
150 ; CHECK: calll _test1
152 ; Load %a from stack after ceil
157 ; Set up call to test.
160 define void @testPR4484(x86_fp80 %a) {
162 %0 = call x86_fp80 @test1()
163 call void asm sideeffect "fistpl $0", "{st},~{st}"(x86_fp80 %a)
164 call void @test3(x86_fp80 %0)
170 define void @testPR4485(x86_fp80* %a) {
172 %0 = load x86_fp80, x86_fp80* %a, align 16
173 %1 = fmul x86_fp80 %0, 0xK4006B400000000000000
174 %2 = fmul x86_fp80 %1, 0xK4012F424000000000000
175 tail call void asm sideeffect "fistpl $0", "{st},~{st}"(x86_fp80 %2)
176 %3 = load x86_fp80, x86_fp80* %a, align 16
177 %4 = fmul x86_fp80 %3, 0xK4006B400000000000000
178 %5 = fmul x86_fp80 %4, 0xK4012F424000000000000
179 tail call void asm sideeffect "fistpl $0", "{st},~{st}"(x86_fp80 %5)
183 ; An input argument in a fixed position is implicitly popped by the asm only if
184 ; the input argument is tied to an output register, or it is in the clobber list.
185 ; The clobber list case is tested above.
187 ; This doesn't implicitly pop the stack:
189 ; void fist1(long double x, int *p) {
190 ; asm volatile ("fistl %1" : : "t"(x), "m"(*p));
198 define void @fist1(x86_fp80 %x, i32* %p) nounwind ssp {
200 tail call void asm sideeffect "fistl $1", "{st},*m,~{memory},~{dirflag},~{fpsr},~{flags}"(x86_fp80 %x, i32* %p) nounwind
204 ; Here, the input operand is tied to an output which means that is is
205 ; implicitly popped (and then the output is implicitly pushed).
207 ; long double fist2(long double x, int *p) {
209 ; asm ("fistl %1" : "=&t"(y) : "0"(x), "m"(*p) : "memory");
218 define x86_fp80 @fist2(x86_fp80 %x, i32* %p) nounwind ssp {
220 %0 = tail call x86_fp80 asm "fistl $2", "=&{st},0,*m,~{memory},~{dirflag},~{fpsr},~{flags}"(x86_fp80 %x, i32* %p) nounwind
224 ; An 'f' constraint is never implicitly popped:
226 ; void fucomp1(long double x, long double y) {
227 ; asm volatile ("fucomp %1" : : "t"(x), "f"(y) : "st");
236 define void @fucomp1(x86_fp80 %x, x86_fp80 %y) nounwind ssp {
238 tail call void asm sideeffect "fucomp $1", "{st},f,~{st},~{dirflag},~{fpsr},~{flags}"(x86_fp80 %x, x86_fp80 %y) nounwind
242 ; The 'u' constraint is only popped implicitly when clobbered:
244 ; void fucomp2(long double x, long double y) {
245 ; asm volatile ("fucomp %1" : : "t"(x), "u"(y) : "st");
248 ; void fucomp3(long double x, long double y) {
249 ; asm volatile ("fucompp %1" : : "t"(x), "u"(y) : "st", "st(1)");
255 ; CHECK: fucomp %st(1)
263 ; CHECK: fucompp %st(1)
266 define void @fucomp2(x86_fp80 %x, x86_fp80 %y) nounwind ssp {
268 tail call void asm sideeffect "fucomp $1", "{st},{st(1)},~{st},~{dirflag},~{fpsr},~{flags}"(x86_fp80 %x, x86_fp80 %y) nounwind
271 define void @fucomp3(x86_fp80 %x, x86_fp80 %y) nounwind ssp {
273 tail call void asm sideeffect "fucompp $1", "{st},{st(1)},~{st},~{st(1)},~{dirflag},~{fpsr},~{flags}"(x86_fp80 %x, x86_fp80 %y) nounwind
277 ; One input, two outputs, one dead output.
278 %complex = type { float, float }
287 define float @sincos1(float %x) nounwind ssp {
289 %0 = tail call %complex asm "sincos", "={st},={st(1)},0,~{dirflag},~{fpsr},~{flags}"(float %x) nounwind
290 %asmresult = extractvalue %complex %0, 0
294 ; Same thing, swapped output operands.
303 define float @sincos2(float %x) nounwind ssp {
305 %0 = tail call %complex asm "sincos", "={st(1)},={st},1,~{dirflag},~{fpsr},~{flags}"(float %x) nounwind
306 %asmresult = extractvalue %complex %0, 1
310 ; Clobber st(0) after it was live-out/dead from the previous asm.
312 ; Load x, make a copy for the second asm.
316 ; Discard dead result in st(0), bring x to the top.
319 ; x is now in st(0) for the second asm
321 ; Discard both results.
325 define float @sincos3(float %x) nounwind ssp {
327 %0 = tail call %complex asm sideeffect "sincos", "={st(1)},={st},1,~{dirflag},~{fpsr},~{flags}"(float %x) nounwind
328 %1 = tail call %complex asm sideeffect "sincos", "={st(1)},={st},1,~{dirflag},~{fpsr},~{flags}"(float %x) nounwind
329 %asmresult = extractvalue %complex %0, 0
333 ; Pass the same value in two fixed stack slots.
337 ; CHECK: fcomi %st(1), %st(0)
338 define i32 @PR10602() nounwind ssp {
340 %0 = tail call i32 asm "fcomi $2, $1; pushf; pop $0", "=r,{st},{st(1)},~{dirflag},~{fpsr},~{flags}"(double 2.000000e+00, double 2.000000e+00) nounwind
344 ; <rdar://problem/16952634>
345 ; X87 stackifier asserted when there was an ST register defined by an
346 ; inline-asm instruction and the ST register was live across another
347 ; inline-asm instruction.
349 ; INLINEASM <es:frndint> [sideeffect] [attdialect], $0:[regdef], %ST0<imp-def,tied5>, $1:[reguse tiedto:$0], %ST0<tied3>, $2:[clobber], %EFLAGS<earlyclobber,imp-def,dead>
350 ; INLINEASM <es:fldcw $0> [sideeffect] [mayload] [attdialect], $0:[mem], %EAX<undef>, 1, %noreg, 0, %noreg, $1:[clobber], %EFLAGS<earlyclobber,imp-def,dead>
351 ; %FP0<def> = COPY %ST0
353 ; CHECK-LABEL: _test_live_st
354 ; CHECK: ## InlineAsm Start
356 ; CHECK: ## InlineAsm End
357 ; CHECK: ## InlineAsm Start
359 ; CHECK: ## InlineAsm End
361 %struct.fpu_t = type { [8 x x86_fp80], x86_fp80, %struct.anon1, %struct.anon2, i32, i8, [15 x i8] }
362 %struct.anon1 = type { i32, i32, i32 }
363 %struct.anon2 = type { i32, i32, i32, i32 }
365 @fpu = external global %struct.fpu_t, align 16
367 ; Function Attrs: ssp
368 define void @test_live_st(i32 %a1) {
370 %0 = load x86_fp80, x86_fp80* undef, align 16
371 %cond = icmp eq i32 %a1, 1
372 br i1 %cond, label %sw.bb4.i, label %_Z5tointRKe.exit
375 %1 = call x86_fp80 asm sideeffect "frndint", "={st},0,~{dirflag},~{fpsr},~{flags}"(x86_fp80 %0)
376 call void asm sideeffect "fldcw $0", "*m,~{dirflag},~{fpsr},~{flags}"(i32* undef)
377 br label %_Z5tointRKe.exit
380 %result.0.i = phi x86_fp80 [ %1, %sw.bb4.i ], [ %0, %entry ]
381 %conv.i1814 = fptosi x86_fp80 %result.0.i to i32
382 %conv626 = sitofp i32 %conv.i1814 to x86_fp80
383 store x86_fp80 %conv626, x86_fp80* getelementptr inbounds (%struct.fpu_t* @fpu, i32 0, i32 1)
390 ; Check that x87 stackifier is correctly rewriting FP registers to ST registers.
392 ; CHECK-LABEL: _test_operand_rewrite
393 ; CHECK: ## InlineAsm Start
394 ; CHECK: foo %st(0), %st(1)
395 ; CHECK: ## InlineAsm End
397 define double @test_operand_rewrite() {
399 %0 = tail call { double, double } asm sideeffect "foo $0, $1", "={st},={st(1)},~{dirflag},~{fpsr},~{flags}"()
400 %asmresult = extractvalue { double, double } %0, 0
401 %asmresult1 = extractvalue { double, double } %0, 1
402 %sub = fsub double %asmresult, %asmresult1