xref: /llvm-project/clang/test/CodeGen/AArch64/cpu-supports.c (revision 474f5d2aefb44430b89ed72774a3c1d26a0adfb1)
1207e5cccSFangrui Song // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --check-globals --global-value-regex ".*"
2207e5cccSFangrui Song // RUN: %clang_cc1 -triple aarch64-none-linux-gnu -emit-llvm -o - %s | FileCheck %s
3207e5cccSFangrui Song 
4207e5cccSFangrui Song //.
5207e5cccSFangrui Song // CHECK: @__aarch64_cpu_features = external dso_local global { i64 }
6207e5cccSFangrui Song //.
7207e5cccSFangrui Song // CHECK-LABEL: @main(
8207e5cccSFangrui Song // CHECK-NEXT:  entry:
9207e5cccSFangrui Song // CHECK-NEXT:    [[RETVAL:%.*]] = alloca i32, align 4
10207e5cccSFangrui Song // CHECK-NEXT:    store i32 0, ptr [[RETVAL]], align 4
11207e5cccSFangrui Song // CHECK-NEXT:    [[TMP0:%.*]] = load i64, ptr @__aarch64_cpu_features, align 8
12207e5cccSFangrui Song // CHECK-NEXT:    [[TMP1:%.*]] = and i64 [[TMP0]], 70368744177664
13207e5cccSFangrui Song // CHECK-NEXT:    [[TMP2:%.*]] = icmp eq i64 [[TMP1]], 70368744177664
14207e5cccSFangrui Song // CHECK-NEXT:    [[TMP3:%.*]] = and i1 true, [[TMP2]]
15207e5cccSFangrui Song // CHECK-NEXT:    br i1 [[TMP3]], label [[IF_THEN:%.*]], label [[IF_END:%.*]]
16207e5cccSFangrui Song // CHECK:       if.then:
17207e5cccSFangrui Song // CHECK-NEXT:    store i32 1, ptr [[RETVAL]], align 4
18207e5cccSFangrui Song // CHECK-NEXT:    br label [[RETURN:%.*]]
19207e5cccSFangrui Song // CHECK:       if.end:
20207e5cccSFangrui Song // CHECK-NEXT:    [[TMP4:%.*]] = load i64, ptr @__aarch64_cpu_features, align 8
216f013dbcSAlexandros Lamprineas // CHECK-NEXT:    [[TMP5:%.*]] = and i64 [[TMP4]], 17936857268992
226f013dbcSAlexandros Lamprineas // CHECK-NEXT:    [[TMP6:%.*]] = icmp eq i64 [[TMP5]], 17936857268992
23207e5cccSFangrui Song // CHECK-NEXT:    [[TMP7:%.*]] = and i1 true, [[TMP6]]
24207e5cccSFangrui Song // CHECK-NEXT:    br i1 [[TMP7]], label [[IF_THEN1:%.*]], label [[IF_END2:%.*]]
25207e5cccSFangrui Song // CHECK:       if.then1:
26207e5cccSFangrui Song // CHECK-NEXT:    store i32 2, ptr [[RETVAL]], align 4
27207e5cccSFangrui Song // CHECK-NEXT:    br label [[RETURN]]
28207e5cccSFangrui Song // CHECK:       if.end2:
29207e5cccSFangrui Song // CHECK-NEXT:    [[TMP8:%.*]] = load i64, ptr @__aarch64_cpu_features, align 8
30*474f5d2aSAlexandros Lamprineas // CHECK-NEXT:    [[TMP9:%.*]] = and i64 [[TMP8]], 162133984766132992
31*474f5d2aSAlexandros Lamprineas // CHECK-NEXT:    [[TMP10:%.*]] = icmp eq i64 [[TMP9]], 162133984766132992
32207e5cccSFangrui Song // CHECK-NEXT:    [[TMP11:%.*]] = and i1 true, [[TMP10]]
33207e5cccSFangrui Song // CHECK-NEXT:    br i1 [[TMP11]], label [[IF_THEN3:%.*]], label [[IF_END4:%.*]]
34207e5cccSFangrui Song // CHECK:       if.then3:
35207e5cccSFangrui Song // CHECK-NEXT:    store i32 3, ptr [[RETVAL]], align 4
36207e5cccSFangrui Song // CHECK-NEXT:    br label [[RETURN]]
37207e5cccSFangrui Song // CHECK:       if.end4:
38207e5cccSFangrui Song // CHECK-NEXT:    br i1 false, label [[IF_THEN5:%.*]], label [[IF_END6:%.*]]
39207e5cccSFangrui Song // CHECK:       if.then5:
40207e5cccSFangrui Song // CHECK-NEXT:    store i32 4, ptr [[RETVAL]], align 4
41207e5cccSFangrui Song // CHECK-NEXT:    br label [[RETURN]]
42207e5cccSFangrui Song // CHECK:       if.end6:
43207e5cccSFangrui Song // CHECK-NEXT:    store i32 0, ptr [[RETVAL]], align 4
44207e5cccSFangrui Song // CHECK-NEXT:    br label [[RETURN]]
45207e5cccSFangrui Song // CHECK:       return:
46207e5cccSFangrui Song // CHECK-NEXT:    [[TMP12:%.*]] = load i32, ptr [[RETVAL]], align 4
47207e5cccSFangrui Song // CHECK-NEXT:    ret i32 [[TMP12]]
48207e5cccSFangrui Song //
49207e5cccSFangrui Song int main(void) {
50207e5cccSFangrui Song   if (__builtin_cpu_supports("sb"))
51207e5cccSFangrui Song     return 1;
52207e5cccSFangrui Song 
53207e5cccSFangrui Song   if (__builtin_cpu_supports("sve2-aes+memtag"))
54207e5cccSFangrui Song     return 2;
55207e5cccSFangrui Song 
56*474f5d2aSAlexandros Lamprineas   if (__builtin_cpu_supports("sme2+wfxt"))
57207e5cccSFangrui Song     return 3;
58207e5cccSFangrui Song 
59207e5cccSFangrui Song   if (__builtin_cpu_supports("avx2"))
60207e5cccSFangrui Song     return 4;
61207e5cccSFangrui Song 
62207e5cccSFangrui Song   return 0;
63207e5cccSFangrui Song }
64207e5cccSFangrui Song //.
65207e5cccSFangrui Song // CHECK: [[META0:![0-9]+]] = !{i32 1, !"wchar_size", i32 4}
66207e5cccSFangrui Song // CHECK: [[META1:![0-9]+]] = !{!"{{.*}}clang version {{.*}}"}
67207e5cccSFangrui Song //.
68