blob: b06318e4c89237db26b5a3035733e45956322add [file] [log] [blame]
Sanjay Patela24296b2015-09-02 20:01:30 +00001// RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm -o - %s -O1 | FileCheck %s
2// RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm -o - %s -O0 | FileCheck %s --check-prefix=CHECK_O0
3
4// When optimizing, the builtin should be converted to metadata.
5// When not optimizing, there should be no metadata created for the builtin.
6// In both cases, the builtin should be removed from the code.
7
8void foo();
9void branch(int x) {
10// CHECK-LABEL: define void @branch(
11
12// CHECK-NOT: builtin_unpredictable
13// CHECK: !unpredictable [[METADATA:.+]]
14// CHECK: [[METADATA]] = !{}
15
16// CHECK_O0-NOT: builtin_unpredictable
17// CHECK_O0-NOT: !unpredictable
18
19 if (__builtin_unpredictable(x > 0))
20 foo ();
21}
22
23// TODO: Add metadata for unpredictable switches.
24int unpredictable_switch(int x) {
25 switch(__builtin_unpredictable(x)) {
26 default:
27 return 0;
28 case 0:
29 case 1:
30 case 2:
31 return 1;
32 case 5:
33 return 5;
34 };
35
36 return 0;
37}
38