Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / CodeGenCXX / static-initializer-branch-weights.cpp
blob121b9b2029959a8b775e1a53311d7d94d9fa0726
1 // RUN: %clang_cc1 -emit-llvm -std=c++1z %s -o - -triple=x86_64-linux-gnu | FileCheck %s
3 struct S { S(); ~S(); };
5 // CHECK-LABEL: define {{.*}}global_var_init
6 // CHECK-NOT: br
7 // CHECK: call void @_ZN1SC1Ev(ptr {{[^,]*}} @global)
8 S global;
10 // CHECK-LABEL: define {{.*}}global_var_init
11 // FIXME: Do we really need thread-safe initialization here? We don't run
12 // global ctors on multiple threads. (If we were to do so, we'd need thread-safe
13 // init for B<int>::member and B<int>::inline_member too.)
14 // CHECK: load atomic i8, ptr @_ZGV13inline_global acquire, align 8
15 // CHECK: icmp eq i8 {{.*}}, 0
16 // CHECK: br i1
17 // CHECK-NOT: !prof
18 // CHECK: call void @_ZN1SC1Ev(ptr {{[^,]*}} @inline_global)
19 inline S inline_global;
21 // CHECK-LABEL: define {{.*}}global_var_init
22 // CHECK-NOT: br
23 // CHECK: call void @_ZN1SC1Ev(ptr {{[^,]*}} @thread_local_global)
24 thread_local S thread_local_global;
26 // CHECK-LABEL: define {{.*}}global_var_init
27 // CHECK: load i8, ptr @_ZGV26thread_local_inline_global
28 // CHECK: icmp eq i8 {{.*}}, 0
29 // CHECK: br i1
30 // CHECK-NOT: !prof
31 // CHECK: call void @_ZN1SC1Ev(ptr {{[^,]*}} @thread_local_inline_global)
32 thread_local inline S thread_local_inline_global;
34 struct A {
35 static S member;
36 static thread_local S thread_local_member;
38 // CHECK-LABEL: define {{.*}}global_var_init
39 // CHECK: load atomic i8, ptr @_ZGVN1A13inline_memberE acquire, align 8
40 // CHECK: icmp eq i8 {{.*}}, 0
41 // CHECK: br i1
42 // CHECK-NOT: !prof
43 // CHECK: call void @_ZN1SC1Ev(ptr {{[^,]*}} @_ZN1A13inline_memberE)
44 static inline S inline_member;
46 // CHECK-LABEL: define {{.*}}global_var_init
47 // CHECK: load i8, ptr @_ZGVN1A26thread_local_inline_memberE
48 // CHECK: icmp eq i8 {{.*}}, 0
49 // CHECK: br i1
50 // CHECK-NOT: !prof
51 // CHECK: call void @_ZN1SC1Ev(ptr {{[^,]*}} @_ZN1A26thread_local_inline_memberE)
52 static thread_local inline S thread_local_inline_member;
55 // CHECK-LABEL: define{{.*}} void @_Z1fv()
56 void f() {
57 // CHECK: load atomic i8, ptr @_ZGVZ1fvE12static_local acquire, align 8
58 // CHECK: icmp eq i8 {{.*}}, 0
59 // CHECK: br i1 {{.*}}, !prof ![[WEIGHTS_LOCAL:[0-9]*]]
60 static S static_local;
62 // CHECK: load i8, ptr @_ZGVZ1fvE19static_thread_local,
63 // CHECK: icmp eq i8 {{.*}}, 0
64 // CHECK: br i1 {{.*}}, !prof ![[WEIGHTS_THREAD_LOCAL:[0-9]*]]
65 static thread_local S static_thread_local;
68 // CHECK-LABEL: define {{.*}}global_var_init
69 // CHECK-NOT: br
70 // CHECK: call void @_ZN1SC1Ev(ptr {{[^,]*}} @_ZN1A6memberE)
71 S A::member;
73 // CHECK-LABEL: define {{.*}}global_var_init
74 // CHECK-NOT: br
75 // CHECK: call void @_ZN1SC1Ev(ptr {{[^,]*}} @_ZN1A19thread_local_memberE)
76 thread_local S A::thread_local_member;
78 template <typename T> struct B {
79 // CHECK-LABEL: define {{.*}}global_var_init
80 // CHECK: load i8, ptr @_ZGVN1BIiE6memberE
81 // CHECK: icmp eq i8 {{.*}}, 0
82 // CHECK: br i1
83 // CHECK-NOT: !prof
84 // CHECK: call void @_ZN1SC1Ev(ptr {{[^,]*}} @_ZN1BIiE6memberE)
85 static S member;
87 // CHECK-LABEL: define {{.*}}global_var_init
88 // CHECK: load i8, ptr @_ZGVN1BIiE13inline_memberE
89 // CHECK: icmp eq i8 {{.*}}, 0
90 // CHECK: br i1
91 // CHECK-NOT: !prof
92 // CHECK: call void @_ZN1SC1Ev(ptr {{[^,]*}} @_ZN1BIiE13inline_memberE)
93 static inline S inline_member;
95 // CHECK-LABEL: define {{.*}}global_var_init
96 // CHECK: load i8, ptr @_ZGVN1BIiE19thread_local_memberE
97 // CHECK: icmp eq i8 {{.*}}, 0
98 // CHECK: br i1
99 // CHECK-NOT: !prof
100 // CHECK: call void @_ZN1SC1Ev(ptr {{[^,]*}} @_ZN1BIiE19thread_local_memberE)
101 static thread_local S thread_local_member;
103 // CHECK-LABEL: define {{.*}}global_var_init
104 // CHECK: load i8, ptr @_ZGVN1BIiE26thread_local_inline_memberE
105 // CHECK: icmp eq i8 {{.*}}, 0
106 // CHECK: br i1
107 // CHECK-NOT: !prof
108 // CHECK: call void @_ZN1SC1Ev(ptr {{[^,]*}} @_ZN1BIiE26thread_local_inline_memberE)
109 static thread_local inline S thread_local_inline_member;
111 template<typename T> S B<T>::member;
112 template<typename T> thread_local S B<T>::thread_local_member;
114 template<typename ...T> void use(T &...);
115 void use_b() {
116 use(B<int>::member, B<int>::inline_member, B<int>::thread_local_member,
117 B<int>::thread_local_inline_member);
120 // CHECK-LABEL: define {{.*}}tls_init()
121 // CHECK: load i8, ptr @__tls_guard, align 1
122 // CHECK: icmp eq i8 {{.*}}, 0
123 // CHECK: br i1 {{.*}}, !prof ![[WEIGHTS_THREAD_LOCAL]]
125 // CHECK-DAG: ![[WEIGHTS_THREAD_LOCAL]] = !{!"branch_weights", i32 1, i32 1023}
126 // CHECK-DAG: ![[WEIGHTS_LOCAL]] = !{!"branch_weights", i32 1, i32 1048575}