Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / CodeGen / builtin-cpu-supports.c
blob796611c1fcd9afd35192c67116b0b4676729d7f6
1 // RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -emit-llvm < %s| FileCheck %s
3 // Test that we have the structure definition, the gep offsets, the name of the
4 // global, the bit grab, and the icmp correct.
5 extern void a(const char *);
7 // CHECK: @__cpu_model = external dso_local global { i32, i32, i32, [1 x i32] }
8 // CHECK: @__cpu_features2 = external dso_local global [3 x i32]
10 int main(void) {
11 __builtin_cpu_init();
13 // CHECK: call void @__cpu_indicator_init
15 if (__builtin_cpu_supports("sse4.2"))
16 a("sse4.2");
18 // CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds ({ i32, i32, i32, [1 x i32] }, ptr @__cpu_model, i32 0, i32 3, i32 0)
19 // CHECK: [[AND:%[^ ]+]] = and i32 [[LOAD]], 256
20 // CHECK: = icmp eq i32 [[AND]], 256
22 if (__builtin_cpu_supports("gfni"))
23 a("gfni");
25 // CHECK: [[LOAD:%[^ ]+]] = load i32, ptr @__cpu_features2
26 // CHECK: [[AND:%[^ ]+]] = and i32 [[LOAD]], 1
27 // CHECK: = icmp eq i32 [[AND]], 1
29 return 0;
32 // CHECK: declare dso_local void @__cpu_indicator_init()
34 // CHECK-LABEL: define{{.*}} @baseline(
35 // CHECK: [[LOAD:%.*]] = load i32, ptr getelementptr inbounds ([[[#]] x i32], ptr @__cpu_features2, i32 0, i32 1)
36 // CHECK-NEXT: and i32 [[LOAD]], -2147483648
37 int baseline() { return __builtin_cpu_supports("x86-64"); }
39 // CHECK-LABEL: define{{.*}} @v2(
40 // CHECK: [[LOAD:%.*]] = load i32, ptr getelementptr inbounds ([[[#]] x i32], ptr @__cpu_features2, i32 0, i32 2)
41 // CHECK-NEXT: and i32 [[LOAD]], 1
42 int v2() { return __builtin_cpu_supports("x86-64-v2"); }
44 // CHECK-LABEL: define{{.*}} @v3(
45 // CHECK: [[LOAD:%.*]] = load i32, ptr getelementptr inbounds ([[[#]] x i32], ptr @__cpu_features2, i32 0, i32 2)
46 // CHECK-NEXT: and i32 [[LOAD]], 2
47 int v3() { return __builtin_cpu_supports("x86-64-v3"); }
49 // CHECK-LABEL: define{{.*}} @v4(
50 // CHECK: [[LOAD:%.*]] = load i32, ptr getelementptr inbounds ([[[#]] x i32], ptr @__cpu_features2, i32 0, i32 2)
51 // CHECK-NEXT: and i32 [[LOAD]], 4
52 int v4() { return __builtin_cpu_supports("x86-64-v4"); }