2020-10-11 21:07:12 +08:00
|
|
|
// RUN: %clang_cc1 -O1 -disable-llvm-passes -emit-llvm %s -o - -triple=x86_64-linux-gnu | opt --lower-expect -S | FileCheck %s
|
2020-10-04 20:21:00 +08:00
|
|
|
|
|
|
|
// Verifies the output of __builtin_expect versus the output of the likelihood
|
|
|
|
// attributes. They should generate the same probabilities for the branches.
|
|
|
|
|
|
|
|
extern bool a();
|
|
|
|
extern bool b();
|
|
|
|
extern bool c();
|
|
|
|
|
|
|
|
void ab1(int &i) {
|
|
|
|
// CHECK-LABEL: define{{.*}}ab1
|
2020-10-11 21:07:12 +08:00
|
|
|
// CHECK: br {{.*}} !prof !6
|
|
|
|
// CHECK: br {{.*}} !prof !6
|
|
|
|
// CHECK: br {{.*}} !prof !6
|
2020-10-04 20:21:00 +08:00
|
|
|
if (__builtin_expect(a() && b() && a(), 1)) {
|
|
|
|
++i;
|
|
|
|
} else {
|
|
|
|
--i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void al(int &i) {
|
|
|
|
// CHECK-LABEL: define{{.*}}al
|
2020-10-11 21:07:12 +08:00
|
|
|
// CHECK: br {{.*}} !prof !6
|
|
|
|
// CHECK: br {{.*}} !prof !6
|
|
|
|
// CHECK: br {{.*}} !prof !6
|
2020-10-04 20:21:00 +08:00
|
|
|
if (a() && b() && c()) [[likely]] {
|
|
|
|
++i;
|
|
|
|
} else {
|
|
|
|
--i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ab0(int &i) {
|
|
|
|
// CHECK-LABEL: define{{.*}}ab0
|
2020-10-11 21:07:12 +08:00
|
|
|
// CHECK: br {{.*}}end{{$}}
|
|
|
|
// CHECK: br {{.*}}end{{$}}
|
|
|
|
// CHECK: br {{.*}}end{{$}}
|
2020-11-14 14:44:14 +08:00
|
|
|
// CHECK: br {{.*}} !prof !9
|
2020-10-04 20:21:00 +08:00
|
|
|
if (__builtin_expect(a() && b() && c(), 0)) {
|
|
|
|
++i;
|
|
|
|
} else {
|
|
|
|
--i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void au(int &i) {
|
|
|
|
// CHECK-LABEL: define{{.*}}au
|
|
|
|
// CHECK: br {{.*}}else{{$}}
|
|
|
|
// CHECK: br {{.*}}else{{$}}
|
2020-11-14 14:44:14 +08:00
|
|
|
// CHECK: br {{.*}} !prof !9
|
2020-10-04 20:21:00 +08:00
|
|
|
if (a() && b() && c()) [[unlikely]] {
|
|
|
|
++i;
|
|
|
|
} else {
|
|
|
|
--i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ob1(int &i) {
|
|
|
|
// CHECK-LABEL: define{{.*}}ob1
|
|
|
|
// CHECK: br {{.*}}false{{$}}
|
|
|
|
// CHECK: br {{.*}}rhs{{$}}
|
2020-10-11 21:07:12 +08:00
|
|
|
// CHECK: br {{.*}}end{{$}}
|
|
|
|
// CHECK: br {{.*}} !prof !6
|
2020-10-04 20:21:00 +08:00
|
|
|
if (__builtin_expect(a() || b() || a(), 1)) {
|
|
|
|
i = 0;
|
|
|
|
} else {
|
|
|
|
--i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ol(int &i) {
|
|
|
|
// CHECK-LABEL: define{{.*}}ol
|
|
|
|
// CHECK: br {{.*}}false{{$}}
|
|
|
|
// CHECK: br {{.*}}false2{{$}}
|
2020-10-11 21:07:12 +08:00
|
|
|
// CHECK: br {{.*}} !prof !6
|
2020-10-04 20:21:00 +08:00
|
|
|
if (a() || b() || c()) [[likely]] {
|
|
|
|
i = 0;
|
|
|
|
} else {
|
|
|
|
--i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ob0(int &i) {
|
|
|
|
// CHECK-LABEL: define{{.*}}ob0
|
2020-11-14 14:44:14 +08:00
|
|
|
// CHECK: br {{.*}} !prof !9
|
|
|
|
// CHECK: br {{.*}} !prof !9
|
|
|
|
// CHECK: br {{.*}} !prof !9
|
2020-10-04 20:21:00 +08:00
|
|
|
if (__builtin_expect(a() || b() || c(), 0)) {
|
|
|
|
i = 0;
|
|
|
|
} else {
|
|
|
|
--i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ou(int &i) {
|
|
|
|
// CHECK-LABEL: define{{.*}}ou
|
2020-11-14 14:44:14 +08:00
|
|
|
// CHECK: br {{.*}} !prof !9
|
|
|
|
// CHECK: br {{.*}} !prof !9
|
|
|
|
// CHECK: br {{.*}} !prof !9
|
2020-10-04 20:21:00 +08:00
|
|
|
if (a() || b() || c()) [[unlikely]] {
|
|
|
|
i = 0;
|
|
|
|
} else {
|
|
|
|
--i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void nb1(int &i) {
|
|
|
|
// CHECK-LABEL: define{{.*}}nb1
|
2020-10-11 21:07:12 +08:00
|
|
|
// CHECK: br {{.*}} !prof !6
|
2020-10-04 20:21:00 +08:00
|
|
|
if (__builtin_expect(!a(), 1)) {
|
|
|
|
++i;
|
|
|
|
} else {
|
|
|
|
--i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void nl(int &i) {
|
|
|
|
// CHECK-LABEL: define{{.*}}nl
|
2020-10-11 21:07:12 +08:00
|
|
|
// CHECK: br {{.*}} !prof !6
|
|
|
|
if (bool d = !a()) [[likely]] {
|
2020-10-04 20:21:00 +08:00
|
|
|
++i;
|
|
|
|
} else {
|
|
|
|
--i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void nb0(int &i) {
|
|
|
|
// CHECK-LABEL: define{{.*}}nb0
|
2020-11-14 14:44:14 +08:00
|
|
|
// CHECK: br {{.*}} !prof !9
|
2020-10-04 20:21:00 +08:00
|
|
|
if (__builtin_expect(!a(), 0)) {
|
|
|
|
++i;
|
|
|
|
} else {
|
|
|
|
--i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void nu(int &i) {
|
|
|
|
// CHECK-LABEL: define{{.*}}nu
|
2020-11-14 14:44:14 +08:00
|
|
|
// CHECK: br {{.*}} !prof !9
|
2020-10-11 21:07:12 +08:00
|
|
|
if (bool d = !a()) [[unlikely]] {
|
2020-10-04 20:21:00 +08:00
|
|
|
++i;
|
|
|
|
} else {
|
|
|
|
--i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void tb1(int &i) {
|
|
|
|
// CHECK-LABEL: define{{.*}}tb1
|
|
|
|
// CHECK: br {{.*}}false{{$}}
|
|
|
|
// CHECK: br {{.*}}end{{$}}
|
|
|
|
// CHECK: br {{.*}}end{{$}}
|
2020-10-11 21:07:12 +08:00
|
|
|
// CHECK: br {{.*}} !prof !6
|
2020-10-04 20:21:00 +08:00
|
|
|
if (__builtin_expect(a() ? b() : c(), 1)) {
|
|
|
|
++i;
|
|
|
|
} else {
|
|
|
|
--i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void tl(int &i) {
|
|
|
|
// CHECK-LABEL: define{{.*}}tl
|
|
|
|
// CHECK: br {{.*}}false{{$}}
|
|
|
|
// CHECK: br {{.*}}end{{$}}
|
|
|
|
// CHECK: br {{.*}}end{{$}}
|
2020-10-11 21:07:12 +08:00
|
|
|
// CHECK: br {{.*}} !prof !6
|
2020-10-04 20:21:00 +08:00
|
|
|
if (bool d = a() ? b() : c()) [[likely]] {
|
|
|
|
++i;
|
|
|
|
} else {
|
|
|
|
--i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void tl2(int &i) {
|
|
|
|
// CHECK-LABEL: define{{.*}}tl
|
|
|
|
// CHECK: br {{.*}}false{{$}}
|
2020-10-11 21:07:12 +08:00
|
|
|
// CHECK: br {{.*}} !prof !6
|
|
|
|
// CHECK: br {{.*}} !prof !6
|
2020-10-04 20:21:00 +08:00
|
|
|
if (a() ? b() : c()) [[likely]] {
|
|
|
|
++i;
|
|
|
|
} else {
|
|
|
|
--i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void tb0(int &i) {
|
|
|
|
// CHECK-LABEL: define{{.*}}tb0
|
|
|
|
// CHECK: br {{.*}}false{{$}}
|
|
|
|
// CHECK: br {{.*}}end{{$}}
|
|
|
|
// CHECK: br {{.*}}end{{$}}
|
2020-11-14 14:44:14 +08:00
|
|
|
// CHECK: br {{.*}} !prof !9
|
2020-10-04 20:21:00 +08:00
|
|
|
if (__builtin_expect(a() ? b() : c(), 0)) {
|
|
|
|
++i;
|
|
|
|
} else {
|
|
|
|
--i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void tu(int &i) {
|
|
|
|
// CHECK-LABEL: define{{.*}}tu
|
|
|
|
// CHECK: br {{.*}}false{{$}}
|
|
|
|
// CHECK: br {{.*}}end{{$}}
|
|
|
|
// CHECK: br {{.*}}end{{$}}
|
2020-11-14 14:44:14 +08:00
|
|
|
// CHECK: br {{.*}} !prof !9
|
2020-10-04 20:21:00 +08:00
|
|
|
if (bool d = a() ? b() : c()) [[unlikely]] {
|
|
|
|
++i;
|
|
|
|
} else {
|
|
|
|
--i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void tu2(int &i) {
|
|
|
|
// CHECK-LABEL: define{{.*}}tu
|
|
|
|
// CHECK: br {{.*}}false{{$}}
|
2020-11-14 14:44:14 +08:00
|
|
|
// CHECK: br {{.*}} !prof !9
|
|
|
|
// CHECK: br {{.*}} !prof !9
|
2020-10-04 20:21:00 +08:00
|
|
|
if (a() ? b() : c()) [[unlikely]] {
|
|
|
|
++i;
|
|
|
|
} else {
|
|
|
|
--i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-31 15:15:46 +08:00
|
|
|
// CHECK: !6 = !{!"branch_weights", i32 2000, i32 1}
|
2020-11-14 14:44:14 +08:00
|
|
|
// CHECK: !9 = !{!"branch_weights", i32 1, i32 2000}
|