[clang] 551caec - Make likelihood lit test less brittle
Mark de Wever via cfe-commits
cfe-commits at lists.llvm.org
Mon Oct 12 09:58:34 PDT 2020
Author: Mark de Wever
Date: 2020-10-12T18:58:21+02:00
New Revision: 551caec4a8af79483823e2940d40afb4c1df5da1
URL: https://github.com/llvm/llvm-project/commit/551caec4a8af79483823e2940d40afb4c1df5da1
DIFF: https://github.com/llvm/llvm-project/commit/551caec4a8af79483823e2940d40afb4c1df5da1.diff
LOG: Make likelihood lit test less brittle
Jeremy Morse discovered an issue with the lit test introduced in D88363. The
test gives different results for Sony's `-O1`.
The test needs to run at `-O1` otherwise the likelihood attribute will be
ignored. Instead of running all `-O1` passes it only runs the lower-expect pass
which is needed to lower `__builtin_expect`.
Differential Revision: https://reviews.llvm.org/D89204
Added:
Modified:
clang/test/CodeGenCXX/attr-likelihood-if-vs-builtin-expect.cpp
Removed:
################################################################################
diff --git a/clang/test/CodeGenCXX/attr-likelihood-if-vs-builtin-expect.cpp b/clang/test/CodeGenCXX/attr-likelihood-if-vs-builtin-expect.cpp
index 5e73cd096742..5872c4c5273f 100644
--- a/clang/test/CodeGenCXX/attr-likelihood-if-vs-builtin-expect.cpp
+++ b/clang/test/CodeGenCXX/attr-likelihood-if-vs-builtin-expect.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -O1 -emit-llvm %s -o - -triple=x86_64-linux-gnu | FileCheck %s
+// RUN: %clang_cc1 -O1 -disable-llvm-passes -emit-llvm %s -o - -triple=x86_64-linux-gnu | opt --lower-expect -S | FileCheck %s
// Verifies the output of __builtin_expect versus the output of the likelihood
// attributes. They should generate the same probabilities for the branches.
@@ -9,9 +9,9 @@ extern bool c();
void ab1(int &i) {
// CHECK-LABEL: define{{.*}}ab1
- // CHECK: br {{.*}} !prof !2
- // CHECK: br {{.*}} !prof !2
- // CHECK: br {{.*}} !prof !2
+ // CHECK: br {{.*}} !prof !6
+ // CHECK: br {{.*}} !prof !6
+ // CHECK: br {{.*}} !prof !6
if (__builtin_expect(a() && b() && a(), 1)) {
++i;
} else {
@@ -21,9 +21,9 @@ void ab1(int &i) {
void al(int &i) {
// CHECK-LABEL: define{{.*}}al
- // CHECK: br {{.*}} !prof !2
- // CHECK: br {{.*}} !prof !2
- // CHECK: br {{.*}} !prof !2
+ // CHECK: br {{.*}} !prof !6
+ // CHECK: br {{.*}} !prof !6
+ // CHECK: br {{.*}} !prof !6
if (a() && b() && c()) [[likely]] {
++i;
} else {
@@ -33,9 +33,10 @@ void al(int &i) {
void ab0(int &i) {
// CHECK-LABEL: define{{.*}}ab0
- // CHECK: br {{.*}}else{{$}}
- // CHECK: br {{.*}}else{{$}}
- // CHECK: br {{.*}} !prof !8
+ // CHECK: br {{.*}}end{{$}}
+ // CHECK: br {{.*}}end{{$}}
+ // CHECK: br {{.*}}end{{$}}
+ // CHECK: br {{.*}} !prof !10
if (__builtin_expect(a() && b() && c(), 0)) {
++i;
} else {
@@ -47,7 +48,7 @@ void au(int &i) {
// CHECK-LABEL: define{{.*}}au
// CHECK: br {{.*}}else{{$}}
// CHECK: br {{.*}}else{{$}}
- // CHECK: br {{.*}} !prof !8
+ // CHECK: br {{.*}} !prof !10
if (a() && b() && c()) [[unlikely]] {
++i;
} else {
@@ -59,7 +60,8 @@ void ob1(int &i) {
// CHECK-LABEL: define{{.*}}ob1
// CHECK: br {{.*}}false{{$}}
// CHECK: br {{.*}}rhs{{$}}
- // CHECK: br {{.*}} !prof !2
+ // CHECK: br {{.*}}end{{$}}
+ // CHECK: br {{.*}} !prof !6
if (__builtin_expect(a() || b() || a(), 1)) {
i = 0;
} else {
@@ -71,7 +73,7 @@ void ol(int &i) {
// CHECK-LABEL: define{{.*}}ol
// CHECK: br {{.*}}false{{$}}
// CHECK: br {{.*}}false2{{$}}
- // CHECK: br {{.*}} !prof !2
+ // CHECK: br {{.*}} !prof !6
if (a() || b() || c()) [[likely]] {
i = 0;
} else {
@@ -81,9 +83,9 @@ void ol(int &i) {
void ob0(int &i) {
// CHECK-LABEL: define{{.*}}ob0
- // CHECK: br {{.*}} !prof !8
- // CHECK: br {{.*}} !prof !8
- // CHECK: br {{.*}} !prof !8
+ // CHECK: br {{.*}} !prof !10
+ // CHECK: br {{.*}} !prof !10
+ // CHECK: br {{.*}} !prof !10
if (__builtin_expect(a() || b() || c(), 0)) {
i = 0;
} else {
@@ -93,9 +95,9 @@ void ob0(int &i) {
void ou(int &i) {
// CHECK-LABEL: define{{.*}}ou
- // CHECK: br {{.*}} !prof !8
- // CHECK: br {{.*}} !prof !8
- // CHECK: br {{.*}} !prof !8
+ // CHECK: br {{.*}} !prof !10
+ // CHECK: br {{.*}} !prof !10
+ // CHECK: br {{.*}} !prof !10
if (a() || b() || c()) [[unlikely]] {
i = 0;
} else {
@@ -105,7 +107,7 @@ void ou(int &i) {
void nb1(int &i) {
// CHECK-LABEL: define{{.*}}nb1
- // CHECK: storemerge{{.*}} !prof !8
+ // CHECK: br {{.*}} !prof !6
if (__builtin_expect(!a(), 1)) {
++i;
} else {
@@ -115,8 +117,8 @@ void nb1(int &i) {
void nl(int &i) {
// CHECK-LABEL: define{{.*}}nl
- // CHECK: storemerge{{.*}} !prof !8
- if (!a()) [[likely]] {
+ // CHECK: br {{.*}} !prof !6
+ if (bool d = !a()) [[likely]] {
++i;
} else {
--i;
@@ -125,7 +127,7 @@ void nl(int &i) {
void nb0(int &i) {
// CHECK-LABEL: define{{.*}}nb0
- // CHECK: storemerge{{.*}} !prof !2
+ // CHECK: br {{.*}} !prof !10
if (__builtin_expect(!a(), 0)) {
++i;
} else {
@@ -135,8 +137,8 @@ void nb0(int &i) {
void nu(int &i) {
// CHECK-LABEL: define{{.*}}nu
- // CHECK: storemerge{{.*}} !prof !2
- if (!a()) [[unlikely]] {
+ // CHECK: br {{.*}} !prof !10
+ if (bool d = !a()) [[unlikely]] {
++i;
} else {
--i;
@@ -148,7 +150,7 @@ void tb1(int &i) {
// CHECK: br {{.*}}false{{$}}
// CHECK: br {{.*}}end{{$}}
// CHECK: br {{.*}}end{{$}}
- // CHECK: storemerge{{.*}} !prof !2
+ // CHECK: br {{.*}} !prof !6
if (__builtin_expect(a() ? b() : c(), 1)) {
++i;
} else {
@@ -161,7 +163,7 @@ void tl(int &i) {
// CHECK: br {{.*}}false{{$}}
// CHECK: br {{.*}}end{{$}}
// CHECK: br {{.*}}end{{$}}
- // CHECK: storemerge{{.*}} !prof !2
+ // CHECK: br {{.*}} !prof !6
if (bool d = a() ? b() : c()) [[likely]] {
++i;
} else {
@@ -172,8 +174,8 @@ void tl(int &i) {
void tl2(int &i) {
// CHECK-LABEL: define{{.*}}tl
// CHECK: br {{.*}}false{{$}}
- // CHECK: br {{.*}} !prof !2
- // CHECK: br {{.*}} !prof !2
+ // CHECK: br {{.*}} !prof !6
+ // CHECK: br {{.*}} !prof !6
if (a() ? b() : c()) [[likely]] {
++i;
} else {
@@ -186,7 +188,7 @@ void tb0(int &i) {
// CHECK: br {{.*}}false{{$}}
// CHECK: br {{.*}}end{{$}}
// CHECK: br {{.*}}end{{$}}
- // CHECK: storemerge{{.*}} !prof !8
+ // CHECK: br {{.*}} !prof !10
if (__builtin_expect(a() ? b() : c(), 0)) {
++i;
} else {
@@ -199,7 +201,7 @@ void tu(int &i) {
// CHECK: br {{.*}}false{{$}}
// CHECK: br {{.*}}end{{$}}
// CHECK: br {{.*}}end{{$}}
- // CHECK: storemerge{{.*}} !prof !8
+ // CHECK: br {{.*}} !prof !10
if (bool d = a() ? b() : c()) [[unlikely]] {
++i;
} else {
@@ -210,8 +212,8 @@ void tu(int &i) {
void tu2(int &i) {
// CHECK-LABEL: define{{.*}}tu
// CHECK: br {{.*}}false{{$}}
- // CHECK: br {{.*}} !prof !8
- // CHECK: br {{.*}} !prof !8
+ // CHECK: br {{.*}} !prof !10
+ // CHECK: br {{.*}} !prof !10
if (a() ? b() : c()) [[unlikely]] {
++i;
} else {
@@ -219,5 +221,5 @@ void tu2(int &i) {
}
}
-// CHECK: !2 = !{!"branch_weights", i32 2000, i32 1}
-// CHECK: !8 = !{!"branch_weights", i32 1, i32 2000}
+// CHECK: !6 = !{!"branch_weights", i32 2000, i32 1}
+// CHECK: !10 = !{!"branch_weights", i32 1, i32 2000}
More information about the cfe-commits
mailing list