blob: ec2ee37f97c07590b6bbcb181cdeeae96c793cf3 [file] [log] [blame]
Mark de Weverb46fddf2020-10-31 13:07:06 +01001// RUN: %clang_cc1 -O1 -disable-llvm-passes -emit-llvm %s -o - -triple=x86_64-linux-gnu -verify
2// RUN: %clang_cc1 -O1 -disable-llvm-passes -emit-llvm %s -o - -triple=x86_64-linux-gnu | FileCheck %s
3
4void wl(int e){
5 // CHECK-LABEL: define{{.*}}wl
6 // CHECK: br {{.*}} !prof !6
7 while(e) [[likely]] ++e;
8}
9
10void wu(int e){
11 // CHECK-LABEL: define{{.*}}wu
Atmn Patelac73b732020-11-02 16:03:21 -050012 // CHECK: br {{.*}} !prof !10
Mark de Weverb46fddf2020-10-31 13:07:06 +010013 while(e) [[unlikely]] ++e;
14}
15
16void w_branch_elided(unsigned e){
17 // CHECK-LABEL: define{{.*}}w_branch_elided
18 // CHECK-NOT: br {{.*}} !prof
19 // expected-warning@+2 {{attribute 'likely' has no effect when annotating an infinite loop}}
20 // expected-note@+1 {{annotating the infinite loop here}}
21 while(1) [[likely]] ++e;
22}
23
24void fl(unsigned e)
25{
26 // CHECK-LABEL: define{{.*}}fl
27 // CHECK: br {{.*}} !prof !6
28 for(int i = 0; i != e; ++e) [[likely]];
29}
30
31void fu(int e)
32{
33 // CHECK-LABEL: define{{.*}}fu
Atmn Patelac73b732020-11-02 16:03:21 -050034 // CHECK: br {{.*}} !prof !10
Mark de Weverb46fddf2020-10-31 13:07:06 +010035 for(int i = 0; i != e; ++e) [[unlikely]];
36}
37
38void f_branch_elided()
39{
40 // CHECK-LABEL: define{{.*}}f_branch_elided
41 // CHECK-NOT: br {{.*}} !prof
42 for(;;) [[likely]];
43}
44
45void frl(int (&&e) [4])
46{
47 // CHECK-LABEL: define{{.*}}frl
48 // CHECK: br {{.*}} !prof !6
49 for(int i : e) [[likely]];
50}
51
52void fru(int (&&e) [4])
53{
54 // CHECK-LABEL: define{{.*}}fru
Atmn Patelac73b732020-11-02 16:03:21 -050055 // CHECK: br {{.*}} !prof !10
Mark de Weverb46fddf2020-10-31 13:07:06 +010056 for(int i : e) [[unlikely]];
57}
58
59// CHECK: !6 = !{!"branch_weights", i32 2000, i32 1}
Atmn Patelac73b732020-11-02 16:03:21 -050060// CHECK: !10 = !{!"branch_weights", i32 1, i32 2000}