Sanjay Patel | daf34e9 | 2015-09-09 22:39:06 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm -disable-llvm-optzns -o - %s -O1 | FileCheck %s |
Sanjay Patel | a24296b | 2015-09-02 20:01:30 +0000 | [diff] [blame] | 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 | |
| 8 | void foo(); |
| 9 | void branch(int x) { |
| 10 | // CHECK-LABEL: define void @branch( |
| 11 | |
| 12 | // CHECK-NOT: builtin_unpredictable |
| 13 | // CHECK: !unpredictable [[METADATA:.+]] |
Sanjay Patel | a24296b | 2015-09-02 20:01:30 +0000 | [diff] [blame] | 14 | |
| 15 | // CHECK_O0-NOT: builtin_unpredictable |
| 16 | // CHECK_O0-NOT: !unpredictable |
| 17 | |
| 18 | if (__builtin_unpredictable(x > 0)) |
| 19 | foo (); |
| 20 | } |
| 21 | |
Sanjay Patel | a24296b | 2015-09-02 20:01:30 +0000 | [diff] [blame] | 22 | int unpredictable_switch(int x) { |
Sanjay Patel | daf34e9 | 2015-09-09 22:39:06 +0000 | [diff] [blame] | 23 | // CHECK-LABEL: @unpredictable_switch( |
| 24 | |
| 25 | // CHECK-NOT: builtin_unpredictable |
| 26 | // CHECK: !unpredictable [[METADATA:.+]] |
| 27 | |
| 28 | // CHECK_O0-NOT: builtin_unpredictable |
| 29 | // CHECK_O0-NOT: !unpredictable |
| 30 | |
Sanjay Patel | a24296b | 2015-09-02 20:01:30 +0000 | [diff] [blame] | 31 | switch(__builtin_unpredictable(x)) { |
| 32 | default: |
| 33 | return 0; |
| 34 | case 0: |
| 35 | case 1: |
| 36 | case 2: |
| 37 | return 1; |
| 38 | case 5: |
| 39 | return 5; |
| 40 | }; |
| 41 | |
| 42 | return 0; |
| 43 | } |
| 44 | |
Sanjay Patel | daf34e9 | 2015-09-09 22:39:06 +0000 | [diff] [blame] | 45 | // CHECK: [[METADATA]] = !{} |
| 46 | |