xref: /aosp_15_r20/external/llvm/test/CodeGen/X86/avx-vzeroupper.ll (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Worker; RUN: llc < %s -x86-use-vzeroupper -mtriple=x86_64-apple-darwin -mattr=+avx | FileCheck %s
2*9880d681SAndroid Build Coastguard Worker; RUN: llc < %s -x86-use-vzeroupper -mtriple=x86_64-apple-darwin -mattr=+avx,+fast-partial-ymm-write | FileCheck --check-prefix=FASTYMM %s
3*9880d681SAndroid Build Coastguard Worker; RUN: llc < %s -x86-use-vzeroupper -mtriple=x86_64-apple-darwin -mcpu=btver2 | FileCheck --check-prefix=BTVER2 %s
4*9880d681SAndroid Build Coastguard Worker
5*9880d681SAndroid Build Coastguard Worker; FASTYMM-NOT: vzeroupper
6*9880d681SAndroid Build Coastguard Worker; BTVER2-NOT: vzeroupper
7*9880d681SAndroid Build Coastguard Worker
8*9880d681SAndroid Build Coastguard Workerdeclare i32 @foo()
9*9880d681SAndroid Build Coastguard Workerdeclare <4 x float> @do_sse(<4 x float>)
10*9880d681SAndroid Build Coastguard Workerdeclare <8 x float> @do_avx(<8 x float>)
11*9880d681SAndroid Build Coastguard Workerdeclare <4 x float> @llvm.x86.avx.vextractf128.ps.256(<8 x float>, i8) nounwind readnone
12*9880d681SAndroid Build Coastguard Worker@x = common global <4 x float> zeroinitializer, align 16
13*9880d681SAndroid Build Coastguard Worker@g = common global <8 x float> zeroinitializer, align 32
14*9880d681SAndroid Build Coastguard Worker
15*9880d681SAndroid Build Coastguard Worker;; Basic checking - don't emit any vzeroupper instruction
16*9880d681SAndroid Build Coastguard Worker
17*9880d681SAndroid Build Coastguard Worker; CHECK: _test00
18*9880d681SAndroid Build Coastguard Workerdefine <4 x float> @test00(<4 x float> %a, <4 x float> %b) nounwind uwtable ssp {
19*9880d681SAndroid Build Coastguard Workerentry:
20*9880d681SAndroid Build Coastguard Worker  ; CHECK-NOT: vzeroupper
21*9880d681SAndroid Build Coastguard Worker  %add.i = fadd <4 x float> %a, %b
22*9880d681SAndroid Build Coastguard Worker  %call3 = call <4 x float> @do_sse(<4 x float> %add.i) nounwind
23*9880d681SAndroid Build Coastguard Worker  ; CHECK: ret
24*9880d681SAndroid Build Coastguard Worker  ret <4 x float> %call3
25*9880d681SAndroid Build Coastguard Worker}
26*9880d681SAndroid Build Coastguard Worker
27*9880d681SAndroid Build Coastguard Worker;; Check parameter 256-bit parameter passing
28*9880d681SAndroid Build Coastguard Worker
29*9880d681SAndroid Build Coastguard Worker; CHECK: _test01
30*9880d681SAndroid Build Coastguard Workerdefine <8 x float> @test01(<4 x float> %a, <4 x float> %b, <8 x float> %c) nounwind uwtable ssp {
31*9880d681SAndroid Build Coastguard Workerentry:
32*9880d681SAndroid Build Coastguard Worker  %tmp = load <4 x float>, <4 x float>* @x, align 16
33*9880d681SAndroid Build Coastguard Worker  ; CHECK: vzeroupper
34*9880d681SAndroid Build Coastguard Worker  ; CHECK-NEXT: callq _do_sse
35*9880d681SAndroid Build Coastguard Worker  %call = tail call <4 x float> @do_sse(<4 x float> %tmp) nounwind
36*9880d681SAndroid Build Coastguard Worker  store <4 x float> %call, <4 x float>* @x, align 16
37*9880d681SAndroid Build Coastguard Worker  ; CHECK-NOT: vzeroupper
38*9880d681SAndroid Build Coastguard Worker  ; CHECK: callq _do_sse
39*9880d681SAndroid Build Coastguard Worker  %call2 = tail call <4 x float> @do_sse(<4 x float> %call) nounwind
40*9880d681SAndroid Build Coastguard Worker  store <4 x float> %call2, <4 x float>* @x, align 16
41*9880d681SAndroid Build Coastguard Worker  ; CHECK: ret
42*9880d681SAndroid Build Coastguard Worker  ret <8 x float> %c
43*9880d681SAndroid Build Coastguard Worker}
44*9880d681SAndroid Build Coastguard Worker
45*9880d681SAndroid Build Coastguard Worker;; Check that vzeroupper is emitted for tail calls.
46*9880d681SAndroid Build Coastguard Worker
47*9880d681SAndroid Build Coastguard Worker; CHECK: _test02
48*9880d681SAndroid Build Coastguard Workerdefine <4 x float> @test02(<8 x float> %a, <8 x float> %b) nounwind uwtable ssp {
49*9880d681SAndroid Build Coastguard Workerentry:
50*9880d681SAndroid Build Coastguard Worker  %add.i = fadd <8 x float> %a, %b
51*9880d681SAndroid Build Coastguard Worker  %add.low = call <4 x float> @llvm.x86.avx.vextractf128.ps.256(<8 x float> %add.i, i8 0)
52*9880d681SAndroid Build Coastguard Worker  ; CHECK: vzeroupper
53*9880d681SAndroid Build Coastguard Worker  ; CHECK: jmp _do_sse
54*9880d681SAndroid Build Coastguard Worker  %call3 = tail call <4 x float> @do_sse(<4 x float> %add.low) nounwind
55*9880d681SAndroid Build Coastguard Worker  ret <4 x float> %call3
56*9880d681SAndroid Build Coastguard Worker}
57*9880d681SAndroid Build Coastguard Worker
58*9880d681SAndroid Build Coastguard Worker;; Test the pass convergence and also that vzeroupper is only issued when necessary,
59*9880d681SAndroid Build Coastguard Worker;; for this function it should be only once
60*9880d681SAndroid Build Coastguard Worker
61*9880d681SAndroid Build Coastguard Worker; CHECK: _test03
62*9880d681SAndroid Build Coastguard Workerdefine <4 x float> @test03(<4 x float> %a, <4 x float> %b) nounwind uwtable ssp {
63*9880d681SAndroid Build Coastguard Workerentry:
64*9880d681SAndroid Build Coastguard Worker  %add.i = fadd <4 x float> %a, %b
65*9880d681SAndroid Build Coastguard Worker  br label %while.cond
66*9880d681SAndroid Build Coastguard Worker
67*9880d681SAndroid Build Coastguard Workerwhile.cond:
68*9880d681SAndroid Build Coastguard Worker  %call = tail call i32 @foo()
69*9880d681SAndroid Build Coastguard Worker  %tobool = icmp eq i32 %call, 0
70*9880d681SAndroid Build Coastguard Worker  br i1 %tobool, label %for.body, label %while.cond
71*9880d681SAndroid Build Coastguard Worker
72*9880d681SAndroid Build Coastguard Workerfor.body:
73*9880d681SAndroid Build Coastguard Worker  ; CHECK: LBB
74*9880d681SAndroid Build Coastguard Worker  ; CHECK-NOT: vzeroupper
75*9880d681SAndroid Build Coastguard Worker  %i.018 = phi i32 [ 0, %while.cond ], [ %1, %for.body ]
76*9880d681SAndroid Build Coastguard Worker  %c.017 = phi <4 x float> [ %add.i, %while.cond ], [ %call14, %for.body ]
77*9880d681SAndroid Build Coastguard Worker  ; CHECK: callq _do_sse
78*9880d681SAndroid Build Coastguard Worker  %call5 = tail call <4 x float> @do_sse(<4 x float> %c.017) nounwind
79*9880d681SAndroid Build Coastguard Worker  ; CHECK-NEXT: callq _do_sse
80*9880d681SAndroid Build Coastguard Worker  %call7 = tail call <4 x float> @do_sse(<4 x float> %call5) nounwind
81*9880d681SAndroid Build Coastguard Worker  %tmp11 = load <8 x float>, <8 x float>* @g, align 32
82*9880d681SAndroid Build Coastguard Worker  %0 = tail call <4 x float> @llvm.x86.avx.vextractf128.ps.256(<8 x float> %tmp11, i8 1) nounwind
83*9880d681SAndroid Build Coastguard Worker  ; CHECK: vzeroupper
84*9880d681SAndroid Build Coastguard Worker  ; CHECK-NEXT: callq _do_sse
85*9880d681SAndroid Build Coastguard Worker  %call14 = tail call <4 x float> @do_sse(<4 x float> %0) nounwind
86*9880d681SAndroid Build Coastguard Worker  %1 = add nsw i32 %i.018, 1
87*9880d681SAndroid Build Coastguard Worker  %exitcond = icmp eq i32 %1, 4
88*9880d681SAndroid Build Coastguard Worker  br i1 %exitcond, label %for.end, label %for.body
89*9880d681SAndroid Build Coastguard Worker
90*9880d681SAndroid Build Coastguard Workerfor.end:
91*9880d681SAndroid Build Coastguard Worker  ret <4 x float> %call14
92*9880d681SAndroid Build Coastguard Worker}
93*9880d681SAndroid Build Coastguard Worker
94*9880d681SAndroid Build Coastguard Worker;; Check that we also perform vzeroupper when we return from a function.
95*9880d681SAndroid Build Coastguard Worker
96*9880d681SAndroid Build Coastguard Worker; CHECK: _test04
97*9880d681SAndroid Build Coastguard Workerdefine <4 x float> @test04(<4 x float> %a, <4 x float> %b) nounwind uwtable ssp {
98*9880d681SAndroid Build Coastguard Workerentry:
99*9880d681SAndroid Build Coastguard Worker  %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>
100*9880d681SAndroid Build Coastguard Worker  ; CHECK-NOT: vzeroupper
101*9880d681SAndroid Build Coastguard Worker  ; CHECK: call
102*9880d681SAndroid Build Coastguard Worker  %call = call <8 x float> @do_avx(<8 x float> %shuf) nounwind
103*9880d681SAndroid Build Coastguard Worker  %shuf2 = shufflevector <8 x float> %call, <8 x float> undef, <4 x i32> <i32 0, i32 1, i32 2, i32 3>
104*9880d681SAndroid Build Coastguard Worker  ; CHECK: vzeroupper
105*9880d681SAndroid Build Coastguard Worker  ; CHECK: ret
106*9880d681SAndroid Build Coastguard Worker  ret <4 x float> %shuf2
107*9880d681SAndroid Build Coastguard Worker}
108