1 // RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm -o - %s -O1 -disable-llvm-passes | FileCheck %s --check-prefix=ALL --check-prefix=O1
2 // RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm -o - %s -O0 | FileCheck %s --check-prefix=ALL --check-prefix=O0
5 int expect_taken(int x
) {
6 // ALL-LABEL: expect_taken
7 // O1: call i64 @llvm.expect.with.probability.i64(i64 {{%.*}}, i64 1, double 9.000000e-01)
8 // O0-NOT: @llvm.expect.with.probability
10 if (__builtin_expect_with_probability(x
== 100, 1, 0.9)) {
16 int expect_not_taken(int x
) {
17 // ALL-LABEL: expect_not_taken
18 // O1: call i64 @llvm.expect.with.probability.i64(i64 {{%.*}}, i64 0, double 9.000000e-01)
19 // O0-NOT: @llvm.expect.with.probability
21 if (__builtin_expect_with_probability(x
== 100, 0, 0.9)) {
28 static constexpr int prob
= 1;
32 int expect_taken_template(int x
) {
33 // ALL-LABEL: expect_taken_template
34 // O1: call i64 @llvm.expect.with.probability.i64(i64 {{%.*}}, i64 1, double 1.000000e+00)
35 // O0-NOT: @llvm.expect.with.probability
37 if (__builtin_expect_with_probability (x
== 100, 1, T::prob
)) {
44 return expect_taken_template
<S
>(global
);
53 void expect_value_side_effects() {
54 // ALL-LABEL: expect_value_side_effects
55 // ALL: [[CALL:%.*]] = call i32 @y
56 // O1: [[SEXT:%.*]] = sext i32 [[CALL]] to i64
57 // O1: call i64 @llvm.expect.with.probability.i64(i64 {{%.*}}, i64 [[SEXT]], double 6.000000e-01)
58 // O0-NOT: @llvm.expect.with.probability
60 if (__builtin_expect_with_probability(x
, y(), 0.6))
64 int switch_cond(int x
) {
65 // ALL-LABEL: switch_cond
66 // O1: call i64 @llvm.expect.with.probability.i64(i64 {{%.*}}, i64 1, double 8.000000e-01)
67 // O0-NOT: @llvm.expect.with.probability
69 switch (__builtin_expect_with_probability(x
, 1, 0.8)) {
84 constexpr double prob
= 0.8;
86 int variable_expected(int stuff
) {
87 // ALL-LABEL: variable_expected
88 // O1: call i64 @llvm.expect.with.probability.i64(i64 {{%.*}}, i64 {{%.*}}, double 8.000000e-01)
89 // O0-NOT: @llvm.expect.with.probability
93 switch(__builtin_expect_with_probability(stuff
, stuff
, prob
)) {