1; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py
2; RUN: opt < %s -mtriple=x86_64-unknown-linux-gnu -passes="print<cost-model>" 2>&1 -disable-output -mattr=+sse2 | FileCheck %s -check-prefixes=SSE2
3; RUN: opt < %s -mtriple=x86_64-unknown-linux-gnu -passes="print<cost-model>" 2>&1 -disable-output -mattr=+sse4.2 | FileCheck %s -check-prefixes=SSE42
4; RUN: opt < %s -mtriple=x86_64-unknown-linux-gnu -passes="print<cost-model>" 2>&1 -disable-output -mattr=+avx | FileCheck %s -check-prefixes=AVX,AVX1
5; RUN: opt < %s -mtriple=x86_64-unknown-linux-gnu -passes="print<cost-model>" 2>&1 -disable-output -mattr=+avx2 | FileCheck %s -check-prefixes=AVX,AVX2
6; RUN: opt < %s -mtriple=x86_64-unknown-linux-gnu -passes="print<cost-model>" 2>&1 -disable-output -mattr=+xop,+avx | FileCheck %s -check-prefixes=AVX,AVX1
7; RUN: opt < %s -mtriple=x86_64-unknown-linux-gnu -passes="print<cost-model>" 2>&1 -disable-output -mattr=+xop,+avx2 | FileCheck %s -check-prefixes=AVX,AVX2
8; RUN: opt < %s -mtriple=x86_64-unknown-linux-gnu -passes="print<cost-model>" 2>&1 -disable-output -mattr=+avx512f | FileCheck %s -check-prefixes=AVX,AVX512,AVX512F
9; RUN: opt < %s -mtriple=x86_64-unknown-linux-gnu -passes="print<cost-model>" 2>&1 -disable-output -mattr=+avx512bw | FileCheck %s -check-prefixes=AVX,AVX512,AVX512BW
10
11; Verify the cost of vector bswap instructions.
12
13declare <2 x i64> @llvm.bswap.v2i64(<2 x i64>)
14declare <4 x i32> @llvm.bswap.v4i32(<4 x i32>)
15declare <8 x i16> @llvm.bswap.v8i16(<8 x i16>)
16
17declare <4 x i64> @llvm.bswap.v4i64(<4 x i64>)
18declare <8 x i32> @llvm.bswap.v8i32(<8 x i32>)
19declare <16 x i16> @llvm.bswap.v16i16(<16 x i16>)
20
21declare <8 x i64> @llvm.bswap.v8i64(<8 x i64>)
22declare <16 x i32> @llvm.bswap.v16i32(<16 x i32>)
23declare <32 x i16> @llvm.bswap.v32i16(<32 x i16>)
24
25define <2 x i64> @var_bswap_v2i64(<2 x i64> %a) {
26; SSE2-LABEL: 'var_bswap_v2i64'
27; SSE2-NEXT:  Cost Model: Found an estimated cost of 7 for instruction: %bswap = call <2 x i64> @llvm.bswap.v2i64(<2 x i64> %a)
28; SSE2-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret <2 x i64> %bswap
29;
30; SSE42-LABEL: 'var_bswap_v2i64'
31; SSE42-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: %bswap = call <2 x i64> @llvm.bswap.v2i64(<2 x i64> %a)
32; SSE42-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret <2 x i64> %bswap
33;
34; AVX-LABEL: 'var_bswap_v2i64'
35; AVX-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: %bswap = call <2 x i64> @llvm.bswap.v2i64(<2 x i64> %a)
36; AVX-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret <2 x i64> %bswap
37;
38  %bswap = call <2 x i64> @llvm.bswap.v2i64(<2 x i64> %a)
39  ret <2 x i64> %bswap
40}
41
42define <4 x i64> @var_bswap_v4i64(<4 x i64> %a) {
43; SSE2-LABEL: 'var_bswap_v4i64'
44; SSE2-NEXT:  Cost Model: Found an estimated cost of 14 for instruction: %bswap = call <4 x i64> @llvm.bswap.v4i64(<4 x i64> %a)
45; SSE2-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret <4 x i64> %bswap
46;
47; SSE42-LABEL: 'var_bswap_v4i64'
48; SSE42-NEXT:  Cost Model: Found an estimated cost of 2 for instruction: %bswap = call <4 x i64> @llvm.bswap.v4i64(<4 x i64> %a)
49; SSE42-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret <4 x i64> %bswap
50;
51; AVX1-LABEL: 'var_bswap_v4i64'
52; AVX1-NEXT:  Cost Model: Found an estimated cost of 4 for instruction: %bswap = call <4 x i64> @llvm.bswap.v4i64(<4 x i64> %a)
53; AVX1-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret <4 x i64> %bswap
54;
55; AVX2-LABEL: 'var_bswap_v4i64'
56; AVX2-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: %bswap = call <4 x i64> @llvm.bswap.v4i64(<4 x i64> %a)
57; AVX2-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret <4 x i64> %bswap
58;
59; AVX512-LABEL: 'var_bswap_v4i64'
60; AVX512-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: %bswap = call <4 x i64> @llvm.bswap.v4i64(<4 x i64> %a)
61; AVX512-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret <4 x i64> %bswap
62;
63  %bswap = call <4 x i64> @llvm.bswap.v4i64(<4 x i64> %a)
64  ret <4 x i64> %bswap
65}
66
67define <8 x i64> @var_bswap_v8i64(<8 x i64> %a) {
68; SSE2-LABEL: 'var_bswap_v8i64'
69; SSE2-NEXT:  Cost Model: Found an estimated cost of 28 for instruction: %bswap = call <8 x i64> @llvm.bswap.v8i64(<8 x i64> %a)
70; SSE2-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret <8 x i64> %bswap
71;
72; SSE42-LABEL: 'var_bswap_v8i64'
73; SSE42-NEXT:  Cost Model: Found an estimated cost of 4 for instruction: %bswap = call <8 x i64> @llvm.bswap.v8i64(<8 x i64> %a)
74; SSE42-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret <8 x i64> %bswap
75;
76; AVX1-LABEL: 'var_bswap_v8i64'
77; AVX1-NEXT:  Cost Model: Found an estimated cost of 8 for instruction: %bswap = call <8 x i64> @llvm.bswap.v8i64(<8 x i64> %a)
78; AVX1-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret <8 x i64> %bswap
79;
80; AVX2-LABEL: 'var_bswap_v8i64'
81; AVX2-NEXT:  Cost Model: Found an estimated cost of 2 for instruction: %bswap = call <8 x i64> @llvm.bswap.v8i64(<8 x i64> %a)
82; AVX2-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret <8 x i64> %bswap
83;
84; AVX512F-LABEL: 'var_bswap_v8i64'
85; AVX512F-NEXT:  Cost Model: Found an estimated cost of 4 for instruction: %bswap = call <8 x i64> @llvm.bswap.v8i64(<8 x i64> %a)
86; AVX512F-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret <8 x i64> %bswap
87;
88; AVX512BW-LABEL: 'var_bswap_v8i64'
89; AVX512BW-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: %bswap = call <8 x i64> @llvm.bswap.v8i64(<8 x i64> %a)
90; AVX512BW-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret <8 x i64> %bswap
91;
92  %bswap = call <8 x i64> @llvm.bswap.v8i64(<8 x i64> %a)
93  ret <8 x i64> %bswap
94}
95
96define <4 x i32> @var_bswap_v4i32(<4 x i32> %a) {
97; SSE2-LABEL: 'var_bswap_v4i32'
98; SSE2-NEXT:  Cost Model: Found an estimated cost of 7 for instruction: %bswap = call <4 x i32> @llvm.bswap.v4i32(<4 x i32> %a)
99; SSE2-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret <4 x i32> %bswap
100;
101; SSE42-LABEL: 'var_bswap_v4i32'
102; SSE42-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: %bswap = call <4 x i32> @llvm.bswap.v4i32(<4 x i32> %a)
103; SSE42-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret <4 x i32> %bswap
104;
105; AVX-LABEL: 'var_bswap_v4i32'
106; AVX-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: %bswap = call <4 x i32> @llvm.bswap.v4i32(<4 x i32> %a)
107; AVX-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret <4 x i32> %bswap
108;
109  %bswap = call <4 x i32> @llvm.bswap.v4i32(<4 x i32> %a)
110  ret <4 x i32> %bswap
111}
112
113define <8 x i32> @var_bswap_v8i32(<8 x i32> %a) {
114; SSE2-LABEL: 'var_bswap_v8i32'
115; SSE2-NEXT:  Cost Model: Found an estimated cost of 14 for instruction: %bswap = call <8 x i32> @llvm.bswap.v8i32(<8 x i32> %a)
116; SSE2-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret <8 x i32> %bswap
117;
118; SSE42-LABEL: 'var_bswap_v8i32'
119; SSE42-NEXT:  Cost Model: Found an estimated cost of 2 for instruction: %bswap = call <8 x i32> @llvm.bswap.v8i32(<8 x i32> %a)
120; SSE42-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret <8 x i32> %bswap
121;
122; AVX1-LABEL: 'var_bswap_v8i32'
123; AVX1-NEXT:  Cost Model: Found an estimated cost of 4 for instruction: %bswap = call <8 x i32> @llvm.bswap.v8i32(<8 x i32> %a)
124; AVX1-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret <8 x i32> %bswap
125;
126; AVX2-LABEL: 'var_bswap_v8i32'
127; AVX2-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: %bswap = call <8 x i32> @llvm.bswap.v8i32(<8 x i32> %a)
128; AVX2-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret <8 x i32> %bswap
129;
130; AVX512-LABEL: 'var_bswap_v8i32'
131; AVX512-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: %bswap = call <8 x i32> @llvm.bswap.v8i32(<8 x i32> %a)
132; AVX512-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret <8 x i32> %bswap
133;
134  %bswap = call <8 x i32> @llvm.bswap.v8i32(<8 x i32> %a)
135  ret <8 x i32> %bswap
136}
137
138define <16 x i32> @var_bswap_v16i32(<16 x i32> %a) {
139; SSE2-LABEL: 'var_bswap_v16i32'
140; SSE2-NEXT:  Cost Model: Found an estimated cost of 28 for instruction: %bswap = call <16 x i32> @llvm.bswap.v16i32(<16 x i32> %a)
141; SSE2-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret <16 x i32> %bswap
142;
143; SSE42-LABEL: 'var_bswap_v16i32'
144; SSE42-NEXT:  Cost Model: Found an estimated cost of 4 for instruction: %bswap = call <16 x i32> @llvm.bswap.v16i32(<16 x i32> %a)
145; SSE42-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret <16 x i32> %bswap
146;
147; AVX1-LABEL: 'var_bswap_v16i32'
148; AVX1-NEXT:  Cost Model: Found an estimated cost of 8 for instruction: %bswap = call <16 x i32> @llvm.bswap.v16i32(<16 x i32> %a)
149; AVX1-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret <16 x i32> %bswap
150;
151; AVX2-LABEL: 'var_bswap_v16i32'
152; AVX2-NEXT:  Cost Model: Found an estimated cost of 2 for instruction: %bswap = call <16 x i32> @llvm.bswap.v16i32(<16 x i32> %a)
153; AVX2-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret <16 x i32> %bswap
154;
155; AVX512F-LABEL: 'var_bswap_v16i32'
156; AVX512F-NEXT:  Cost Model: Found an estimated cost of 4 for instruction: %bswap = call <16 x i32> @llvm.bswap.v16i32(<16 x i32> %a)
157; AVX512F-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret <16 x i32> %bswap
158;
159; AVX512BW-LABEL: 'var_bswap_v16i32'
160; AVX512BW-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: %bswap = call <16 x i32> @llvm.bswap.v16i32(<16 x i32> %a)
161; AVX512BW-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret <16 x i32> %bswap
162;
163  %bswap = call <16 x i32> @llvm.bswap.v16i32(<16 x i32> %a)
164  ret <16 x i32> %bswap
165}
166
167define <8 x i16> @var_bswap_v8i16(<8 x i16> %a) {
168; SSE2-LABEL: 'var_bswap_v8i16'
169; SSE2-NEXT:  Cost Model: Found an estimated cost of 7 for instruction: %bswap = call <8 x i16> @llvm.bswap.v8i16(<8 x i16> %a)
170; SSE2-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret <8 x i16> %bswap
171;
172; SSE42-LABEL: 'var_bswap_v8i16'
173; SSE42-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: %bswap = call <8 x i16> @llvm.bswap.v8i16(<8 x i16> %a)
174; SSE42-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret <8 x i16> %bswap
175;
176; AVX-LABEL: 'var_bswap_v8i16'
177; AVX-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: %bswap = call <8 x i16> @llvm.bswap.v8i16(<8 x i16> %a)
178; AVX-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret <8 x i16> %bswap
179;
180  %bswap = call <8 x i16> @llvm.bswap.v8i16(<8 x i16> %a)
181  ret <8 x i16> %bswap
182}
183
184define <16 x i16> @var_bswap_v16i16(<16 x i16> %a) {
185; SSE2-LABEL: 'var_bswap_v16i16'
186; SSE2-NEXT:  Cost Model: Found an estimated cost of 14 for instruction: %bswap = call <16 x i16> @llvm.bswap.v16i16(<16 x i16> %a)
187; SSE2-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret <16 x i16> %bswap
188;
189; SSE42-LABEL: 'var_bswap_v16i16'
190; SSE42-NEXT:  Cost Model: Found an estimated cost of 2 for instruction: %bswap = call <16 x i16> @llvm.bswap.v16i16(<16 x i16> %a)
191; SSE42-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret <16 x i16> %bswap
192;
193; AVX1-LABEL: 'var_bswap_v16i16'
194; AVX1-NEXT:  Cost Model: Found an estimated cost of 4 for instruction: %bswap = call <16 x i16> @llvm.bswap.v16i16(<16 x i16> %a)
195; AVX1-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret <16 x i16> %bswap
196;
197; AVX2-LABEL: 'var_bswap_v16i16'
198; AVX2-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: %bswap = call <16 x i16> @llvm.bswap.v16i16(<16 x i16> %a)
199; AVX2-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret <16 x i16> %bswap
200;
201; AVX512-LABEL: 'var_bswap_v16i16'
202; AVX512-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: %bswap = call <16 x i16> @llvm.bswap.v16i16(<16 x i16> %a)
203; AVX512-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret <16 x i16> %bswap
204;
205  %bswap = call <16 x i16> @llvm.bswap.v16i16(<16 x i16> %a)
206  ret <16 x i16> %bswap
207}
208
209define <32 x i16> @var_bswap_v32i16(<32 x i16> %a) {
210; SSE2-LABEL: 'var_bswap_v32i16'
211; SSE2-NEXT:  Cost Model: Found an estimated cost of 28 for instruction: %bswap = call <32 x i16> @llvm.bswap.v32i16(<32 x i16> %a)
212; SSE2-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret <32 x i16> %bswap
213;
214; SSE42-LABEL: 'var_bswap_v32i16'
215; SSE42-NEXT:  Cost Model: Found an estimated cost of 4 for instruction: %bswap = call <32 x i16> @llvm.bswap.v32i16(<32 x i16> %a)
216; SSE42-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret <32 x i16> %bswap
217;
218; AVX1-LABEL: 'var_bswap_v32i16'
219; AVX1-NEXT:  Cost Model: Found an estimated cost of 8 for instruction: %bswap = call <32 x i16> @llvm.bswap.v32i16(<32 x i16> %a)
220; AVX1-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret <32 x i16> %bswap
221;
222; AVX2-LABEL: 'var_bswap_v32i16'
223; AVX2-NEXT:  Cost Model: Found an estimated cost of 2 for instruction: %bswap = call <32 x i16> @llvm.bswap.v32i16(<32 x i16> %a)
224; AVX2-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret <32 x i16> %bswap
225;
226; AVX512F-LABEL: 'var_bswap_v32i16'
227; AVX512F-NEXT:  Cost Model: Found an estimated cost of 4 for instruction: %bswap = call <32 x i16> @llvm.bswap.v32i16(<32 x i16> %a)
228; AVX512F-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret <32 x i16> %bswap
229;
230; AVX512BW-LABEL: 'var_bswap_v32i16'
231; AVX512BW-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: %bswap = call <32 x i16> @llvm.bswap.v32i16(<32 x i16> %a)
232; AVX512BW-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret <32 x i16> %bswap
233;
234  %bswap = call <32 x i16> @llvm.bswap.v32i16(<32 x i16> %a)
235  ret <32 x i16> %bswap
236}
237