Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / CodeGen / attr-cpuspecific.c
blob9150597e8c5a8470f8f79d68bb8603495c6c1a48
1 // RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK,LINUX
2 // RUN: %clang_cc1 -triple x86_64-windows-pc -fms-compatibility -emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK,WINDOWS
4 #ifdef _WIN64
5 #define ATTR(X) __declspec(X)
6 #else
7 #define ATTR(X) __attribute__((X))
8 #endif // _WIN64
10 // Each version should have an IFunc and an alias.
11 // LINUX: @SingleVersion = weak_odr alias void (), ptr @SingleVersion.ifunc
12 // LINUX: @TwoVersions = weak_odr alias void (), ptr @TwoVersions.ifunc
13 // LINUX: @OrderDispatchUsageSpecific = weak_odr alias void (), ptr @OrderDispatchUsageSpecific.ifunc
14 // LINUX: @TwoVersionsSameAttr = weak_odr alias void (), ptr @TwoVersionsSameAttr.ifunc
15 // LINUX: @ThreeVersionsSameAttr = weak_odr alias void (), ptr @ThreeVersionsSameAttr.ifunc
16 // LINUX: @OrderSpecificUsageDispatch = weak_odr alias void (), ptr @OrderSpecificUsageDispatch.ifunc
17 // LINUX: @NoSpecifics = weak_odr alias void (), ptr @NoSpecifics.ifunc
18 // LINUX: @HasGeneric = weak_odr alias void (), ptr @HasGeneric.ifunc
19 // LINUX: @HasParams = weak_odr alias void (i32, double), ptr @HasParams.ifunc
20 // LINUX: @HasParamsAndReturn = weak_odr alias i32 (i32, double), ptr @HasParamsAndReturn.ifunc
21 // LINUX: @GenericAndPentium = weak_odr alias i32 (i32, double), ptr @GenericAndPentium.ifunc
22 // LINUX: @DispatchFirst = weak_odr alias i32 (), ptr @DispatchFirst.ifunc
24 // LINUX: @SingleVersion.ifunc = weak_odr ifunc void (), ptr @SingleVersion.resolver
25 // LINUX: @TwoVersions.ifunc = weak_odr ifunc void (), ptr @TwoVersions.resolver
26 // LINUX: @OrderDispatchUsageSpecific.ifunc = weak_odr ifunc void (), ptr @OrderDispatchUsageSpecific.resolver
27 // LINUX: @TwoVersionsSameAttr.ifunc = weak_odr ifunc void (), ptr @TwoVersionsSameAttr.resolver
28 // LINUX: @ThreeVersionsSameAttr.ifunc = weak_odr ifunc void (), ptr @ThreeVersionsSameAttr.resolver
29 // LINUX: @OrderSpecificUsageDispatch.ifunc = weak_odr ifunc void (), ptr @OrderSpecificUsageDispatch.resolver
30 // LINUX: @NoSpecifics.ifunc = weak_odr ifunc void (), ptr @NoSpecifics.resolver
31 // LINUX: @HasGeneric.ifunc = weak_odr ifunc void (), ptr @HasGeneric.resolver
32 // LINUX: @HasParams.ifunc = weak_odr ifunc void (i32, double), ptr @HasParams.resolver
33 // LINUX: @HasParamsAndReturn.ifunc = weak_odr ifunc i32 (i32, double), ptr @HasParamsAndReturn.resolver
34 // LINUX: @GenericAndPentium.ifunc = weak_odr ifunc i32 (i32, double), ptr @GenericAndPentium.resolver
35 // LINUX: @DispatchFirst.ifunc = weak_odr ifunc i32 (), ptr @DispatchFirst.resolver
37 ATTR(cpu_specific(ivybridge))
38 void SingleVersion(void){}
39 // LINUX: define{{.*}} void @SingleVersion.S() #[[S:[0-9]+]]
40 // WINDOWS: define dso_local void @SingleVersion.S() #[[S:[0-9]+]]
42 ATTR(cpu_dispatch(ivybridge))
43 void SingleVersion(void);
44 // LINUX: define weak_odr ptr @SingleVersion.resolver()
45 // LINUX: call void @__cpu_indicator_init
46 // LINUX: %[[FEAT_INIT:.+]] = load i32, ptr getelementptr inbounds ({ i32, i32, i32, [1 x i32] }, ptr @__cpu_model, i32 0, i32 3, i32 0), align 4
47 // LINUX: %[[FEAT_JOIN:.+]] = and i32 %[[FEAT_INIT]], 525311
48 // LINUX: %[[FEAT_CHECK:.+]] = icmp eq i32 %[[FEAT_JOIN]], 525311
49 // LINUX: ret ptr @SingleVersion.S
50 // LINUX: call void @llvm.trap
51 // LINUX: unreachable
53 // WINDOWS: define weak_odr dso_local void @SingleVersion() comdat
54 // WINDOWS: call void @__cpu_indicator_init()
55 // WINDOWS: %[[FEAT_INIT:.+]] = load i32, ptr getelementptr inbounds ({ i32, i32, i32, [1 x i32] }, ptr @__cpu_model, i32 0, i32 3, i32 0), align 4
56 // WINDOWS: %[[FEAT_JOIN:.+]] = and i32 %[[FEAT_INIT]], 525311
57 // WINDOWS: %[[FEAT_CHECK:.+]] = icmp eq i32 %[[FEAT_JOIN]], 525311
58 // WINDOWS: call void @SingleVersion.S()
59 // WINDOWS-NEXT: ret void
60 // WINDOWS: call void @llvm.trap
61 // WINDOWS: unreachable
63 ATTR(cpu_specific(ivybridge))
64 void NotCalled(void){}
65 // LINUX: define{{.*}} void @NotCalled.S() #[[S]]
66 // WINDOWS: define dso_local void @NotCalled.S() #[[S:[0-9]+]]
68 // Done before any of the implementations. Also has an undecorated forward
69 // declaration.
70 void TwoVersions(void);
72 ATTR(cpu_dispatch(ivybridge, knl))
73 void TwoVersions(void);
74 // LINUX: define weak_odr ptr @TwoVersions.resolver()
75 // LINUX: call void @__cpu_indicator_init
76 // LINUX: %[[FEAT_INIT:.+]] = load i32, ptr getelementptr inbounds ({ i32, i32, i32, [1 x i32] }, ptr @__cpu_model, i32 0, i32 3, i32 0), align 4
77 // LINUX: %[[FEAT_JOIN:.+]] = and i32 %[[FEAT_INIT]], 59754495
78 // LINUX: %[[FEAT_CHECK:.+]] = icmp eq i32 %[[FEAT_JOIN]], 59754495
79 // LINUX: ret ptr @TwoVersions.Z
80 // LINUX: ret ptr @TwoVersions.S
81 // LINUX: call void @llvm.trap
82 // LINUX: unreachable
84 // WINDOWS: define weak_odr dso_local void @TwoVersions() comdat
85 // WINDOWS: call void @__cpu_indicator_init()
86 // WINDOWS: %[[FEAT_INIT:.+]] = load i32, ptr getelementptr inbounds ({ i32, i32, i32, [1 x i32] }, ptr @__cpu_model, i32 0, i32 3, i32 0), align 4
87 // WINDOWS: %[[FEAT_JOIN:.+]] = and i32 %[[FEAT_INIT]], 59754495
88 // WINDOWS: %[[FEAT_CHECK:.+]] = icmp eq i32 %[[FEAT_JOIN]], 59754495
89 // WINDOWS: call void @TwoVersions.Z()
90 // WINDOWS-NEXT: ret void
91 // WINDOWS: call void @TwoVersions.S()
92 // WINDOWS-NEXT: ret void
93 // WINDOWS: call void @llvm.trap
94 // WINDOWS: unreachable
96 ATTR(cpu_specific(ivybridge))
97 void TwoVersions(void){}
98 // CHECK: define {{.*}}void @TwoVersions.S() #[[S]]
100 ATTR(cpu_specific(knl))
101 void TwoVersions(void){}
102 // CHECK: define {{.*}}void @TwoVersions.Z() #[[K:[0-9]+]]
104 ATTR(cpu_specific(ivybridge, knl))
105 void TwoVersionsSameAttr(void){}
106 // CHECK: define {{.*}}void @TwoVersionsSameAttr.S() #[[S]]
107 // CHECK: define {{.*}}void @TwoVersionsSameAttr.Z() #[[K]]
109 ATTR(cpu_specific(atom, ivybridge, knl))
110 void ThreeVersionsSameAttr(void){}
111 // CHECK: define {{.*}}void @ThreeVersionsSameAttr.O() #[[O:[0-9]+]]
112 // CHECK: define {{.*}}void @ThreeVersionsSameAttr.S() #[[S]]
113 // CHECK: define {{.*}}void @ThreeVersionsSameAttr.Z() #[[K]]
115 ATTR(cpu_specific(knl))
116 void CpuSpecificNoDispatch(void) {}
117 // CHECK: define {{.*}}void @CpuSpecificNoDispatch.Z() #[[K:[0-9]+]]
119 ATTR(cpu_dispatch(knl))
120 void OrderDispatchUsageSpecific(void);
121 // LINUX: define weak_odr ptr @OrderDispatchUsageSpecific.resolver()
122 // LINUX: call void @__cpu_indicator_init
123 // LINUX: ret ptr @OrderDispatchUsageSpecific.Z
124 // LINUX: call void @llvm.trap
125 // LINUX: unreachable
127 // WINDOWS: define weak_odr dso_local void @OrderDispatchUsageSpecific() comdat
128 // WINDOWS: call void @__cpu_indicator_init()
129 // WINDOWS: call void @OrderDispatchUsageSpecific.Z()
130 // WINDOWS-NEXT: ret void
131 // WINDOWS: call void @llvm.trap
132 // WINDOWS: unreachable
134 // CHECK: define {{.*}}void @OrderDispatchUsageSpecific.Z()
136 ATTR(cpu_specific(knl))
137 void OrderSpecificUsageDispatch(void) {}
138 // CHECK: define {{.*}}void @OrderSpecificUsageDispatch.Z() #[[K:[0-9]+]]
140 void usages(void) {
141 SingleVersion();
142 // LINUX: @SingleVersion.ifunc()
143 // WINDOWS: @SingleVersion()
144 TwoVersions();
145 // LINUX: @TwoVersions.ifunc()
146 // WINDOWS: @TwoVersions()
147 TwoVersionsSameAttr();
148 // LINUX: @TwoVersionsSameAttr.ifunc()
149 // WINDOWS: @TwoVersionsSameAttr()
150 ThreeVersionsSameAttr();
151 // LINUX: @ThreeVersionsSameAttr.ifunc()
152 // WINDOWS: @ThreeVersionsSameAttr()
153 CpuSpecificNoDispatch();
154 // LINUX: @CpuSpecificNoDispatch.ifunc()
155 // WINDOWS: @CpuSpecificNoDispatch()
156 OrderDispatchUsageSpecific();
157 // LINUX: @OrderDispatchUsageSpecific.ifunc()
158 // WINDOWS: @OrderDispatchUsageSpecific()
159 OrderSpecificUsageDispatch();
160 // LINUX: @OrderSpecificUsageDispatch.ifunc()
161 // WINDOWS: @OrderSpecificUsageDispatch()
164 // LINUX: declare void @CpuSpecificNoDispatch.ifunc()
166 // has an extra config to emit!
167 ATTR(cpu_dispatch(ivybridge, knl, atom))
168 void TwoVersionsSameAttr(void);
169 // LINUX: define weak_odr ptr @TwoVersionsSameAttr.resolver()
170 // LINUX: ret ptr @TwoVersionsSameAttr.Z
171 // LINUX: ret ptr @TwoVersionsSameAttr.S
172 // LINUX: ret ptr @TwoVersionsSameAttr.O
173 // LINUX: call void @llvm.trap
174 // LINUX: unreachable
176 // WINDOWS: define weak_odr dso_local void @TwoVersionsSameAttr() comdat
177 // WINDOWS: call void @TwoVersionsSameAttr.Z
178 // WINDOWS-NEXT: ret void
179 // WINDOWS: call void @TwoVersionsSameAttr.S
180 // WINDOWS-NEXT: ret void
181 // WINDOWS: call void @TwoVersionsSameAttr.O
182 // WINDOWS-NEXT: ret void
183 // WINDOWS: call void @llvm.trap
184 // WINDOWS: unreachable
186 ATTR(cpu_dispatch(atom, ivybridge, knl))
187 void ThreeVersionsSameAttr(void){}
188 // LINUX: define weak_odr ptr @ThreeVersionsSameAttr.resolver()
189 // LINUX: call void @__cpu_indicator_init
190 // LINUX: ret ptr @ThreeVersionsSameAttr.Z
191 // LINUX: ret ptr @ThreeVersionsSameAttr.S
192 // LINUX: ret ptr @ThreeVersionsSameAttr.O
193 // LINUX: call void @llvm.trap
194 // LINUX: unreachable
196 // WINDOWS: define weak_odr dso_local void @ThreeVersionsSameAttr() comdat
197 // WINDOWS: call void @__cpu_indicator_init
198 // WINDOWS: call void @ThreeVersionsSameAttr.Z
199 // WINDOWS-NEXT: ret void
200 // WINDOWS: call void @ThreeVersionsSameAttr.S
201 // WINDOWS-NEXT: ret void
202 // WINDOWS: call void @ThreeVersionsSameAttr.O
203 // WINDOWS-NEXT: ret void
204 // WINDOWS: call void @llvm.trap
205 // WINDOWS: unreachable
207 ATTR(cpu_dispatch(knl))
208 void OrderSpecificUsageDispatch(void);
209 // LINUX: define weak_odr ptr @OrderSpecificUsageDispatch.resolver()
210 // LINUX: ret ptr @OrderSpecificUsageDispatch.Z
212 // WINDOWS: define weak_odr dso_local void @OrderSpecificUsageDispatch() comdat
213 // WINDOWS: call void @__cpu_indicator_init
214 // WINDOWS: call void @OrderSpecificUsageDispatch.Z
215 // WINDOWS-NEXT: ret void
217 // No Cpu Specific options.
218 ATTR(cpu_dispatch(atom, ivybridge, knl))
219 void NoSpecifics(void);
220 // LINUX: define weak_odr ptr @NoSpecifics.resolver()
221 // LINUX: call void @__cpu_indicator_init
222 // LINUX: ret ptr @NoSpecifics.Z
223 // LINUX: ret ptr @NoSpecifics.S
224 // LINUX: ret ptr @NoSpecifics.O
225 // LINUX: call void @llvm.trap
226 // LINUX: unreachable
228 // WINDOWS: define weak_odr dso_local void @NoSpecifics() comdat
229 // WINDOWS: call void @__cpu_indicator_init
230 // WINDOWS: call void @NoSpecifics.Z
231 // WINDOWS-NEXT: ret void
232 // WINDOWS: call void @NoSpecifics.S
233 // WINDOWS-NEXT: ret void
234 // WINDOWS: call void @NoSpecifics.O
235 // WINDOWS-NEXT: ret void
236 // WINDOWS: call void @llvm.trap
237 // WINDOWS: unreachable
239 ATTR(cpu_dispatch(atom, generic, ivybridge, knl))
240 void HasGeneric(void);
241 // LINUX: define weak_odr ptr @HasGeneric.resolver()
242 // LINUX: call void @__cpu_indicator_init
243 // LINUX: ret ptr @HasGeneric.Z
244 // LINUX: ret ptr @HasGeneric.S
245 // LINUX: ret ptr @HasGeneric.O
246 // LINUX: ret ptr @HasGeneric.A
247 // LINUX-NOT: call void @llvm.trap
249 // WINDOWS: define weak_odr dso_local void @HasGeneric() comdat
250 // WINDOWS: call void @__cpu_indicator_init
251 // WINDOWS: call void @HasGeneric.Z
252 // WINDOWS-NEXT: ret void
253 // WINDOWS: call void @HasGeneric.S
254 // WINDOWS-NEXT: ret void
255 // WINDOWS: call void @HasGeneric.O
256 // WINDOWS-NEXT: ret void
257 // WINDOWS: call void @HasGeneric.A
258 // WINDOWS-NEXT: ret void
259 // WINDOWS-NOT: call void @llvm.trap
261 ATTR(cpu_dispatch(atom, generic, ivybridge, knl))
262 void HasParams(int i, double d);
263 // LINUX: define weak_odr ptr @HasParams.resolver()
264 // LINUX: call void @__cpu_indicator_init
265 // LINUX: ret ptr @HasParams.Z
266 // LINUX: ret ptr @HasParams.S
267 // LINUX: ret ptr @HasParams.O
268 // LINUX: ret ptr @HasParams.A
269 // LINUX-NOT: call void @llvm.trap
271 // WINDOWS: define weak_odr dso_local void @HasParams(i32 %0, double %1) comdat
272 // WINDOWS: call void @__cpu_indicator_init
273 // WINDOWS: call void @HasParams.Z(i32 %0, double %1)
274 // WINDOWS-NEXT: ret void
275 // WINDOWS: call void @HasParams.S(i32 %0, double %1)
276 // WINDOWS-NEXT: ret void
277 // WINDOWS: call void @HasParams.O(i32 %0, double %1)
278 // WINDOWS-NEXT: ret void
279 // WINDOWS: call void @HasParams.A(i32 %0, double %1)
280 // WINDOWS-NEXT: ret void
281 // WINDOWS-NOT: call void @llvm.trap
283 ATTR(cpu_dispatch(atom, generic, ivybridge, knl))
284 int HasParamsAndReturn(int i, double d);
285 // LINUX: define weak_odr ptr @HasParamsAndReturn.resolver()
286 // LINUX: call void @__cpu_indicator_init
287 // LINUX: ret ptr @HasParamsAndReturn.Z
288 // LINUX: ret ptr @HasParamsAndReturn.S
289 // LINUX: ret ptr @HasParamsAndReturn.O
290 // LINUX: ret ptr @HasParamsAndReturn.A
291 // LINUX-NOT: call void @llvm.trap
293 // WINDOWS: define weak_odr dso_local i32 @HasParamsAndReturn(i32 %0, double %1) comdat
294 // WINDOWS: call void @__cpu_indicator_init
295 // WINDOWS: %[[RET:.+]] = musttail call i32 @HasParamsAndReturn.Z(i32 %0, double %1)
296 // WINDOWS-NEXT: ret i32 %[[RET]]
297 // WINDOWS: %[[RET:.+]] = musttail call i32 @HasParamsAndReturn.S(i32 %0, double %1)
298 // WINDOWS-NEXT: ret i32 %[[RET]]
299 // WINDOWS: %[[RET:.+]] = musttail call i32 @HasParamsAndReturn.O(i32 %0, double %1)
300 // WINDOWS-NEXT: ret i32 %[[RET]]
301 // WINDOWS: %[[RET:.+]] = musttail call i32 @HasParamsAndReturn.A(i32 %0, double %1)
302 // WINDOWS-NEXT: ret i32 %[[RET]]
303 // WINDOWS-NOT: call void @llvm.trap
305 ATTR(cpu_dispatch(atom, generic, pentium))
306 int GenericAndPentium(int i, double d);
307 // LINUX: define weak_odr ptr @GenericAndPentium.resolver()
308 // LINUX: call void @__cpu_indicator_init
309 // LINUX: ret ptr @GenericAndPentium.O
310 // LINUX: ret ptr @GenericAndPentium.B
311 // LINUX-NOT: ret ptr @GenericAndPentium.A
312 // LINUX-NOT: call void @llvm.trap
314 // WINDOWS: define weak_odr dso_local i32 @GenericAndPentium(i32 %0, double %1) comdat
315 // WINDOWS: call void @__cpu_indicator_init
316 // WINDOWS: %[[RET:.+]] = musttail call i32 @GenericAndPentium.O(i32 %0, double %1)
317 // WINDOWS-NEXT: ret i32 %[[RET]]
318 // WINDOWS: %[[RET:.+]] = musttail call i32 @GenericAndPentium.B(i32 %0, double %1)
319 // WINDOWS-NEXT: ret i32 %[[RET]]
320 // WINDOWS-NOT: call i32 @GenericAndPentium.A
321 // WINDOWS-NOT: call void @llvm.trap
323 ATTR(cpu_dispatch(atom, pentium))
324 int DispatchFirst(void);
325 // LINUX: define weak_odr ptr @DispatchFirst.resolver
326 // LINUX: ret ptr @DispatchFirst.O
327 // LINUX: ret ptr @DispatchFirst.B
329 // WINDOWS: define weak_odr dso_local i32 @DispatchFirst() comdat
330 // WINDOWS: %[[RET:.+]] = musttail call i32 @DispatchFirst.O()
331 // WINDOWS-NEXT: ret i32 %[[RET]]
332 // WINDOWS: %[[RET:.+]] = musttail call i32 @DispatchFirst.B()
333 // WINDOWS-NEXT: ret i32 %[[RET]]
335 ATTR(cpu_specific(atom))
336 int DispatchFirst(void) {return 0;}
337 // LINUX: define{{.*}} i32 @DispatchFirst.O
338 // LINUX: ret i32 0
340 // WINDOWS: define dso_local i32 @DispatchFirst.O()
341 // WINDOWS: ret i32 0
343 ATTR(cpu_specific(pentium))
344 int DispatchFirst(void) {return 1;}
345 // LINUX: define{{.*}} i32 @DispatchFirst.B
346 // LINUX: ret i32 1
348 // WINDOWS: define dso_local i32 @DispatchFirst.B
349 // WINDOWS: ret i32 1
351 ATTR(cpu_specific(knl))
352 void OrderDispatchUsageSpecific(void) {}
354 // CHECK: attributes #[[S]] = {{.*}}"target-features"="+avx,+cmov,+crc32,+cx16,+cx8,+f16c,+fsgsbase,+fxsr,+mmx,+pclmul,+popcnt,+rdrnd,+sahf,+sse,+sse2,+sse3,+sse4.1,+sse4.2,+ssse3,+x87,+xsave,+xsaveopt"
355 // CHECK-SAME: "tune-cpu"="ivybridge"
356 // CHECK: attributes #[[K]] = {{.*}}"target-features"="+adx,+aes,+avx,+avx2,+avx512cd,+avx512er,+avx512f,+avx512pf,+bmi,+bmi2,+cmov,+crc32,+cx16,+cx8,+evex512,+f16c,+fma,+fsgsbase,+fxsr,+invpcid,+lzcnt,+mmx,+movbe,+pclmul,+popcnt,+prefetchwt1,+prfchw,+rdrnd,+rdseed,+sahf,+sse,+sse2,+sse3,+sse4.1,+sse4.2,+ssse3,+x87,+xsave,+xsaveopt"
357 // CHECK-SAME: "tune-cpu"="knl"
358 // CHECK: attributes #[[O]] = {{.*}}"target-features"="+cmov,+cx16,+cx8,+fxsr,+mmx,+movbe,+sahf,+sse,+sse2,+sse3,+ssse3,+x87"
359 // CHECK-SAME: "tune-cpu"="atom"