1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc < %s -x86-use-vzeroupper -mtriple=x86_64-unknown-unknown -mattr=+avx | FileCheck %s --check-prefix=ALL --check-prefix=VZ --check-prefix=AVX
3 ; RUN: llc < %s -x86-use-vzeroupper -mtriple=x86_64-unknown-unknown -mattr=+avx512f | FileCheck %s --check-prefix=ALL --check-prefix=VZ --check-prefix=AVX512
4 ; RUN: llc < %s -x86-use-vzeroupper -mtriple=x86_64-unknown-unknown -mattr=+avx,+fast-partial-ymm-or-zmm-write | FileCheck %s --check-prefix=ALL --check-prefix=NO-VZ --check-prefix=FAST-ymm-zmm
5 ; RUN: llc < %s -x86-use-vzeroupper -mtriple=x86_64-unknown-unknown -mcpu=bdver2 | FileCheck %s --check-prefix=ALL --check-prefix=NO-VZ --check-prefix=BDVER2
6 ; RUN: llc < %s -x86-use-vzeroupper -mtriple=x86_64-unknown-unknown -mcpu=btver2 | FileCheck %s --check-prefix=ALL --check-prefix=NO-VZ --check-prefix=BTVER2
9 declare <4 x float> @do_sse(<4 x float>)
10 declare <8 x float> @do_avx(<8 x float>)
11 declare <4 x float> @llvm.x86.avx.vextractf128.ps.256(<8 x float>, i8) nounwind readnone
12 @x = common global <4 x float> zeroinitializer, align 16
13 @g = common global <8 x float> zeroinitializer, align 32
15 ;; Basic checking - don't emit any vzeroupper instruction
17 define <4 x float> @test00(<4 x float> %a, <4 x float> %b) nounwind {
20 ; ALL-NEXT: pushq %rax
21 ; ALL-NEXT: vaddps %xmm1, %xmm0, %xmm0
22 ; ALL-NEXT: callq do_sse
25 %add.i = fadd <4 x float> %a, %b
26 %call3 = call <4 x float> @do_sse(<4 x float> %add.i) nounwind
27 ret <4 x float> %call3
30 ;; Check parameter 256-bit parameter passing
32 define <8 x float> @test01(<4 x float> %a, <4 x float> %b, <8 x float> %c) nounwind {
35 ; VZ-NEXT: subq $56, %rsp
36 ; VZ-NEXT: vmovups %ymm2, (%rsp) # 32-byte Spill
37 ; VZ-NEXT: vmovaps {{.*}}(%rip), %xmm0
39 ; VZ-NEXT: callq do_sse
40 ; VZ-NEXT: vmovaps %xmm0, {{.*}}(%rip)
41 ; VZ-NEXT: callq do_sse
42 ; VZ-NEXT: vmovaps %xmm0, {{.*}}(%rip)
43 ; VZ-NEXT: vmovups (%rsp), %ymm0 # 32-byte Reload
44 ; VZ-NEXT: addq $56, %rsp
47 ; FAST-ymm-zmm-LABEL: test01:
48 ; FAST-ymm-zmm: # %bb.0:
49 ; FAST-ymm-zmm-NEXT: subq $56, %rsp
50 ; FAST-ymm-zmm-NEXT: vmovups %ymm2, (%rsp) # 32-byte Spill
51 ; FAST-ymm-zmm-NEXT: vmovaps {{.*}}(%rip), %xmm0
52 ; FAST-ymm-zmm-NEXT: callq do_sse
53 ; FAST-ymm-zmm-NEXT: vmovaps %xmm0, {{.*}}(%rip)
54 ; FAST-ymm-zmm-NEXT: callq do_sse
55 ; FAST-ymm-zmm-NEXT: vmovaps %xmm0, {{.*}}(%rip)
56 ; FAST-ymm-zmm-NEXT: vmovups (%rsp), %ymm0 # 32-byte Reload
57 ; FAST-ymm-zmm-NEXT: addq $56, %rsp
58 ; FAST-ymm-zmm-NEXT: retq
60 ; BDVER2-LABEL: test01:
62 ; BDVER2-NEXT: subq $56, %rsp
63 ; BDVER2-NEXT: vmovaps {{.*}}(%rip), %xmm0
64 ; BDVER2-NEXT: vmovups %ymm2, (%rsp) # 32-byte Spill
65 ; BDVER2-NEXT: vzeroupper
66 ; BDVER2-NEXT: callq do_sse
67 ; BDVER2-NEXT: vmovaps %xmm0, {{.*}}(%rip)
68 ; BDVER2-NEXT: callq do_sse
69 ; BDVER2-NEXT: vmovaps %xmm0, {{.*}}(%rip)
70 ; BDVER2-NEXT: vmovups (%rsp), %ymm0 # 32-byte Reload
71 ; BDVER2-NEXT: addq $56, %rsp
74 ; BTVER2-LABEL: test01:
76 ; BTVER2-NEXT: subq $56, %rsp
77 ; BTVER2-NEXT: vmovaps {{.*}}(%rip), %xmm0
78 ; BTVER2-NEXT: vmovups %ymm2, (%rsp) # 32-byte Spill
79 ; BTVER2-NEXT: callq do_sse
80 ; BTVER2-NEXT: vmovaps %xmm0, {{.*}}(%rip)
81 ; BTVER2-NEXT: callq do_sse
82 ; BTVER2-NEXT: vmovaps %xmm0, {{.*}}(%rip)
83 ; BTVER2-NEXT: vmovups (%rsp), %ymm0 # 32-byte Reload
84 ; BTVER2-NEXT: addq $56, %rsp
86 %tmp = load <4 x float>, <4 x float>* @x, align 16
87 %call = tail call <4 x float> @do_sse(<4 x float> %tmp) nounwind
88 store <4 x float> %call, <4 x float>* @x, align 16
89 %call2 = tail call <4 x float> @do_sse(<4 x float> %call) nounwind
90 store <4 x float> %call2, <4 x float>* @x, align 16
94 ;; Check that vzeroupper is emitted for tail calls.
96 define <4 x float> @test02(<8 x float> %a, <8 x float> %b) nounwind {
99 ; VZ-NEXT: vaddps %xmm1, %xmm0, %xmm0
100 ; VZ-NEXT: vzeroupper
101 ; VZ-NEXT: jmp do_sse # TAILCALL
103 ; FAST-ymm-zmm-LABEL: test02:
104 ; FAST-ymm-zmm: # %bb.0:
105 ; FAST-ymm-zmm-NEXT: vaddps %xmm1, %xmm0, %xmm0
106 ; FAST-ymm-zmm-NEXT: jmp do_sse # TAILCALL
108 ; BDVER2-LABEL: test02:
110 ; BDVER2-NEXT: vaddps %xmm1, %xmm0, %xmm0
111 ; BDVER2-NEXT: vzeroupper
112 ; BDVER2-NEXT: jmp do_sse # TAILCALL
114 ; BTVER2-LABEL: test02:
116 ; BTVER2-NEXT: vaddps %xmm1, %xmm0, %xmm0
117 ; BTVER2-NEXT: jmp do_sse # TAILCALL
118 %add.i = fadd <8 x float> %a, %b
119 %add.low = call <4 x float> @llvm.x86.avx.vextractf128.ps.256(<8 x float> %add.i, i8 0)
120 %call3 = tail call <4 x float> @do_sse(<4 x float> %add.low) nounwind
121 ret <4 x float> %call3
124 ;; Test the pass convergence and also that vzeroupper is only issued when necessary,
125 ;; for this function it should be only once
127 define <4 x float> @test03(<4 x float> %a, <4 x float> %b) nounwind {
129 ; VZ: # %bb.0: # %entry
130 ; VZ-NEXT: pushq %rbx
131 ; VZ-NEXT: subq $16, %rsp
132 ; VZ-NEXT: vaddps %xmm1, %xmm0, %xmm0
133 ; VZ-NEXT: vmovaps %xmm0, (%rsp) # 16-byte Spill
134 ; VZ-NEXT: .p2align 4, 0x90
135 ; VZ-NEXT: .LBB3_1: # %while.cond
136 ; VZ-NEXT: # =>This Inner Loop Header: Depth=1
138 ; VZ-NEXT: testl %eax, %eax
139 ; VZ-NEXT: jne .LBB3_1
140 ; VZ-NEXT: # %bb.2: # %for.body.preheader
141 ; VZ-NEXT: movl $4, %ebx
142 ; VZ-NEXT: vmovaps (%rsp), %xmm0 # 16-byte Reload
143 ; VZ-NEXT: .p2align 4, 0x90
144 ; VZ-NEXT: .LBB3_3: # %for.body
145 ; VZ-NEXT: # =>This Inner Loop Header: Depth=1
146 ; VZ-NEXT: callq do_sse
147 ; VZ-NEXT: callq do_sse
148 ; VZ-NEXT: vmovaps g+{{.*}}(%rip), %xmm0
149 ; VZ-NEXT: callq do_sse
151 ; VZ-NEXT: jne .LBB3_3
152 ; VZ-NEXT: # %bb.4: # %for.end
153 ; VZ-NEXT: addq $16, %rsp
157 ; FAST-ymm-zmm-LABEL: test03:
158 ; FAST-ymm-zmm: # %bb.0: # %entry
159 ; FAST-ymm-zmm-NEXT: pushq %rbx
160 ; FAST-ymm-zmm-NEXT: subq $16, %rsp
161 ; FAST-ymm-zmm-NEXT: vaddps %xmm1, %xmm0, %xmm0
162 ; FAST-ymm-zmm-NEXT: vmovaps %xmm0, (%rsp) # 16-byte Spill
163 ; FAST-ymm-zmm-NEXT: .p2align 4, 0x90
164 ; FAST-ymm-zmm-NEXT: .LBB3_1: # %while.cond
165 ; FAST-ymm-zmm-NEXT: # =>This Inner Loop Header: Depth=1
166 ; FAST-ymm-zmm-NEXT: callq foo
167 ; FAST-ymm-zmm-NEXT: testl %eax, %eax
168 ; FAST-ymm-zmm-NEXT: jne .LBB3_1
169 ; FAST-ymm-zmm-NEXT: # %bb.2: # %for.body.preheader
170 ; FAST-ymm-zmm-NEXT: movl $4, %ebx
171 ; FAST-ymm-zmm-NEXT: vmovaps (%rsp), %xmm0 # 16-byte Reload
172 ; FAST-ymm-zmm-NEXT: .p2align 4, 0x90
173 ; FAST-ymm-zmm-NEXT: .LBB3_3: # %for.body
174 ; FAST-ymm-zmm-NEXT: # =>This Inner Loop Header: Depth=1
175 ; FAST-ymm-zmm-NEXT: callq do_sse
176 ; FAST-ymm-zmm-NEXT: callq do_sse
177 ; FAST-ymm-zmm-NEXT: vmovaps g+{{.*}}(%rip), %xmm0
178 ; FAST-ymm-zmm-NEXT: callq do_sse
179 ; FAST-ymm-zmm-NEXT: decl %ebx
180 ; FAST-ymm-zmm-NEXT: jne .LBB3_3
181 ; FAST-ymm-zmm-NEXT: # %bb.4: # %for.end
182 ; FAST-ymm-zmm-NEXT: addq $16, %rsp
183 ; FAST-ymm-zmm-NEXT: popq %rbx
184 ; FAST-ymm-zmm-NEXT: retq
186 ; BDVER2-LABEL: test03:
187 ; BDVER2: # %bb.0: # %entry
188 ; BDVER2-NEXT: pushq %rbx
189 ; BDVER2-NEXT: subq $16, %rsp
190 ; BDVER2-NEXT: vaddps %xmm1, %xmm0, %xmm0
191 ; BDVER2-NEXT: vmovaps %xmm0, (%rsp) # 16-byte Spill
192 ; BDVER2-NEXT: .p2align 4, 0x90
193 ; BDVER2-NEXT: .LBB3_1: # %while.cond
194 ; BDVER2-NEXT: # =>This Inner Loop Header: Depth=1
195 ; BDVER2-NEXT: callq foo
196 ; BDVER2-NEXT: testl %eax, %eax
197 ; BDVER2-NEXT: jne .LBB3_1
198 ; BDVER2-NEXT: # %bb.2: # %for.body.preheader
199 ; BDVER2-NEXT: vmovaps (%rsp), %xmm0 # 16-byte Reload
200 ; BDVER2-NEXT: movl $4, %ebx
201 ; BDVER2-NEXT: .p2align 4, 0x90
202 ; BDVER2-NEXT: .LBB3_3: # %for.body
203 ; BDVER2-NEXT: # =>This Inner Loop Header: Depth=1
204 ; BDVER2-NEXT: callq do_sse
205 ; BDVER2-NEXT: callq do_sse
206 ; BDVER2-NEXT: vmovaps g+{{.*}}(%rip), %xmm0
207 ; BDVER2-NEXT: callq do_sse
208 ; BDVER2-NEXT: decl %ebx
209 ; BDVER2-NEXT: jne .LBB3_3
210 ; BDVER2-NEXT: # %bb.4: # %for.end
211 ; BDVER2-NEXT: addq $16, %rsp
212 ; BDVER2-NEXT: popq %rbx
215 ; BTVER2-LABEL: test03:
216 ; BTVER2: # %bb.0: # %entry
217 ; BTVER2-NEXT: pushq %rbx
218 ; BTVER2-NEXT: subq $16, %rsp
219 ; BTVER2-NEXT: vaddps %xmm1, %xmm0, %xmm0
220 ; BTVER2-NEXT: vmovaps %xmm0, (%rsp) # 16-byte Spill
221 ; BTVER2-NEXT: .p2align 4, 0x90
222 ; BTVER2-NEXT: .LBB3_1: # %while.cond
223 ; BTVER2-NEXT: # =>This Inner Loop Header: Depth=1
224 ; BTVER2-NEXT: callq foo
225 ; BTVER2-NEXT: testl %eax, %eax
226 ; BTVER2-NEXT: jne .LBB3_1
227 ; BTVER2-NEXT: # %bb.2: # %for.body.preheader
228 ; BTVER2-NEXT: vmovaps (%rsp), %xmm0 # 16-byte Reload
229 ; BTVER2-NEXT: movl $4, %ebx
230 ; BTVER2-NEXT: .p2align 4, 0x90
231 ; BTVER2-NEXT: .LBB3_3: # %for.body
232 ; BTVER2-NEXT: # =>This Inner Loop Header: Depth=1
233 ; BTVER2-NEXT: callq do_sse
234 ; BTVER2-NEXT: callq do_sse
235 ; BTVER2-NEXT: vmovaps g+{{.*}}(%rip), %xmm0
236 ; BTVER2-NEXT: callq do_sse
237 ; BTVER2-NEXT: decl %ebx
238 ; BTVER2-NEXT: jne .LBB3_3
239 ; BTVER2-NEXT: # %bb.4: # %for.end
240 ; BTVER2-NEXT: addq $16, %rsp
241 ; BTVER2-NEXT: popq %rbx
244 %add.i = fadd <4 x float> %a, %b
248 %call = tail call i32 @foo()
249 %tobool = icmp eq i32 %call, 0
250 br i1 %tobool, label %for.body, label %while.cond
253 %i.018 = phi i32 [ 0, %while.cond ], [ %1, %for.body ]
254 %c.017 = phi <4 x float> [ %add.i, %while.cond ], [ %call14, %for.body ]
255 %call5 = tail call <4 x float> @do_sse(<4 x float> %c.017) nounwind
256 %call7 = tail call <4 x float> @do_sse(<4 x float> %call5) nounwind
257 %tmp11 = load <8 x float>, <8 x float>* @g, align 32
258 %0 = tail call <4 x float> @llvm.x86.avx.vextractf128.ps.256(<8 x float> %tmp11, i8 1) nounwind
259 %call14 = tail call <4 x float> @do_sse(<4 x float> %0) nounwind
260 %1 = add nsw i32 %i.018, 1
261 %exitcond = icmp eq i32 %1, 4
262 br i1 %exitcond, label %for.end, label %for.body
265 ret <4 x float> %call14
268 ;; Check that we also perform vzeroupper when we return from a function.
270 define <4 x float> @test04(<4 x float> %a, <4 x float> %b) nounwind {
273 ; VZ-NEXT: pushq %rax
274 ; VZ-NEXT: # kill: def $xmm0 killed $xmm0 def $ymm0
275 ; VZ-NEXT: vinsertf128 $1, %xmm1, %ymm0, %ymm0
276 ; VZ-NEXT: callq do_avx
277 ; VZ-NEXT: # kill: def $xmm0 killed $xmm0 killed $ymm0
279 ; VZ-NEXT: vzeroupper
282 ; FAST-ymm-zmm-LABEL: test04:
283 ; FAST-ymm-zmm: # %bb.0:
284 ; FAST-ymm-zmm-NEXT: pushq %rax
285 ; FAST-ymm-zmm-NEXT: # kill: def $xmm0 killed $xmm0 def $ymm0
286 ; FAST-ymm-zmm-NEXT: vinsertf128 $1, %xmm1, %ymm0, %ymm0
287 ; FAST-ymm-zmm-NEXT: callq do_avx
288 ; FAST-ymm-zmm-NEXT: # kill: def $xmm0 killed $xmm0 killed $ymm0
289 ; FAST-ymm-zmm-NEXT: popq %rax
290 ; FAST-ymm-zmm-NEXT: retq
292 ; BDVER2-LABEL: test04:
294 ; BDVER2-NEXT: pushq %rax
295 ; BDVER2-NEXT: # kill: def $xmm0 killed $xmm0 def $ymm0
296 ; BDVER2-NEXT: vinsertf128 $1, %xmm1, %ymm0, %ymm0
297 ; BDVER2-NEXT: callq do_avx
298 ; BDVER2-NEXT: # kill: def $xmm0 killed $xmm0 killed $ymm0
299 ; BDVER2-NEXT: popq %rax
300 ; BDVER2-NEXT: vzeroupper
303 ; BTVER2-LABEL: test04:
305 ; BTVER2-NEXT: pushq %rax
306 ; BTVER2-NEXT: # kill: def $xmm0 killed $xmm0 def $ymm0
307 ; BTVER2-NEXT: vinsertf128 $1, %xmm1, %ymm0, %ymm0
308 ; BTVER2-NEXT: callq do_avx
309 ; BTVER2-NEXT: # kill: def $xmm0 killed $xmm0 killed $ymm0
310 ; BTVER2-NEXT: popq %rax
312 %shuf = shufflevector <4 x float> %a, <4 x float> %b, <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7>
313 %call = call <8 x float> @do_avx(<8 x float> %shuf) nounwind
314 %shuf2 = shufflevector <8 x float> %call, <8 x float> undef, <4 x i32> <i32 0, i32 1, i32 2, i32 3>
315 ret <4 x float> %shuf2