1 // RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm -disable-llvm-passes -o - %s -O1 | FileCheck %s
2 // RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm -disable-llvm-passes -o - -x c++ %s -O1 | FileCheck %s
3 // RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm -o - %s -O0 | FileCheck %s --check-prefix=CHECK_O0
4
5 // When optimizing, the builtin should be converted to metadata.
6 // When not optimizing, there should be no metadata created for the builtin.
7 // In both cases, the builtin should be removed from the code.
8
9 #ifdef __cplusplus
10 extern "C" {
11 #endif
12
13 void foo(void);
branch(int x)14 void branch(int x) {
15 // CHECK-LABEL: define{{.*}} void @branch(
16
17 // CHECK-NOT: builtin_unpredictable
18 // CHECK: !unpredictable [[METADATA:.+]]
19
20 // CHECK_O0-NOT: builtin_unpredictable
21 // CHECK_O0-NOT: !unpredictable
22
23 if (__builtin_unpredictable(x > 0))
24 foo ();
25 }
26
unpredictable_switch(int x)27 int unpredictable_switch(int x) {
28 // CHECK-LABEL: @unpredictable_switch(
29
30 // CHECK-NOT: builtin_unpredictable
31 // CHECK: !unpredictable [[METADATA:.+]]
32
33 // CHECK_O0-NOT: builtin_unpredictable
34 // CHECK_O0-NOT: !unpredictable
35
36 switch(__builtin_unpredictable(x)) {
37 default:
38 return 0;
39 case 0:
40 case 1:
41 case 2:
42 return 1;
43 case 5:
44 return 5;
45 };
46
47 return 0;
48 }
49
50 #ifdef __cplusplus
51 }
52 #endif
53
54
55 // CHECK: [[METADATA]] = !{}
56
57