brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.3 KiB · df34e87 Raw
97 lines · c
1// RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm -o - %s -O1 -disable-llvm-passes | FileCheck %s --check-prefix=ALL --check-prefix=O12// RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm -o - %s -O0 | FileCheck %s --check-prefix=ALL --check-prefix=O03 4// In all tests, make sure that no expect is generated if optimizations are off.5// If optimizations are on, generate the correct expect and preserve other necessary operations.6 7int expect_taken(int x) {8// ALL-LABEL: define{{.*}} i32 @expect_taken9// O1:        call i64 @llvm.expect.i64(i64 {{%.*}}, i64 1)10// O0-NOT:    @llvm.expect11 12  if (__builtin_expect (x, 1))13    return 0;14  return x;15}16 17 18int expect_not_taken(int x) {19// ALL-LABEL: define{{.*}} i32 @expect_not_taken20// O1:        call i64 @llvm.expect.i64(i64 {{%.*}}, i64 0)21// O0-NOT:    @llvm.expect22 23  if (__builtin_expect (x, 0))24    return 0;25  return x;26}27 28 29int x;30int y(void);31void foo(void);32 33void expect_value_side_effects(void) {34// ALL-LABEL: define{{.*}} void @expect_value_side_effects()35// ALL:       [[CALL:%.*]] = call i32 @y36// O1:        [[SEXT:%.*]] = sext i32 [[CALL]] to i6437// O1:        call i64 @llvm.expect.i64(i64 {{%.*}}, i64 [[SEXT]])38// O0-NOT:    @llvm.expect39 40  if (__builtin_expect (x, y()))41    foo ();42}43 44 45// Make sure that issigprocmask() is called before bar()?46// There's no compare, so there's nothing to expect?47void isigprocmask(void);48long bar(void);49 50int main(void) {51// ALL-LABEL: define{{.*}} i32 @main()52// ALL:       call void @isigprocmask()53// ALL:       [[CALL:%.*]] = call i64 @bar()54// O1:        call i64 @llvm.expect.i64(i64 0, i64 [[CALL]])55// O0-NOT:    @llvm.expect56 57  (void) __builtin_expect((isigprocmask(), 0), bar());58}59 60 61int switch_cond(int x) {62// ALL-LABEL: define{{.*}} i32 @switch_cond63// O1:        call i64 @llvm.expect.i64(i64 {{%.*}}, i64 5)64// O0-NOT:    @llvm.expect65 66  switch(__builtin_expect(x, 5)) {67  default:68    return 0;69  case 0:70  case 1:71  case 2:72    return 1;73  case 5:74    return 5;75  };76 77  return 0;78}79 80int variable_expected(int stuff) {81// ALL-LABEL: define{{.*}} i32 @variable_expected(82// O1: call i64 @llvm.expect.i64(i64 {{%.*}}, i64 {{%.*}})83// O0-NOT: @llvm.expect84 85  int res = 0;86 87  switch (__builtin_expect(stuff, stuff)) {88  case 0:89    res = 1;90    break;91  default:92    break;93  }94 95  return res;96}97