[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / CodeGen / builtin-unpredictable.c
blob13981d223d8ed38a99edc90c40906b72ffffdd7d
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
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.
9 #ifdef __cplusplus
10 extern "C" {
11 #endif
13 void foo(void);
14 void branch(int x) {
15 // CHECK-LABEL: define{{.*}} void @branch(
17 // CHECK-NOT: builtin_unpredictable
18 // CHECK: !unpredictable [[METADATA:.+]]
20 // CHECK_O0-NOT: builtin_unpredictable
21 // CHECK_O0-NOT: !unpredictable
23 if (__builtin_unpredictable(x > 0))
24 foo ();
27 int unpredictable_switch(int x) {
28 // CHECK-LABEL: @unpredictable_switch(
30 // CHECK-NOT: builtin_unpredictable
31 // CHECK: !unpredictable [[METADATA:.+]]
33 // CHECK_O0-NOT: builtin_unpredictable
34 // CHECK_O0-NOT: !unpredictable
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;
47 return 0;
50 #ifdef __cplusplus
52 #endif
55 // CHECK: [[METADATA]] = !{}