brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.9 KiB · bc12865 Raw
50 lines · c
1// Test that big branch weights get scaled down to 32-bits, rather than just2// truncated.3 4// RUN: llvm-profdata merge %S/Inputs/c-counter-overflows.proftext -o %t.profdata5// RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name c-counter-overflows.c %s -o - -emit-llvm -fprofile-instrument-use=clang -fprofile-instrument-use-path=%t.profdata | FileCheck %s6 7typedef unsigned long long uint64_t;8 9int main(int argc, const char *argv[]) {10  // Need counts higher than 32-bits.11  // CHECK: br {{.*}} !prof ![[FOR:[0-9]+]]12  // max   = 0xffffffff013  // scale = 0xffffffff0 / 0xffffffff + 1 = 1714  // loop-body: 0xffffffff0 / 17 + 1 = 0xf0f0f0f0 + 1 = 4042322161 => -25264513515  // loop-exit: 0x000000001 / 17 + 1 = 0x00000000 + 1 =          1 =>          116  for (uint64_t I = 0; I < 0xffffffff0; ++I) {17    // max   = 0xffffffff * 15 = 0xefffffff118    // scale = 0xefffffff1 / 0xffffffff + 1 = 1619    // CHECK: br {{.*}} !prof ![[IF:[0-9]+]]20    if (I & 0xf) {21      // 0xefffffff1 / 16 + 1 = 0xefffffff + 1 = 4026531840 => -26843545622    } else {23      // 0x0ffffffff / 16 + 1 = 0x0fffffff + 1 =  268435456 =>  26843545624    }25 26    // max   = 0xffffffff * 5 = 0x4fffffffb27    // scale = 0x4fffffffb / 0xffffffff + 1 = 628    // CHECK: ], !prof ![[SWITCH:[0-9]+]]29    switch ((I & 0xf) / 5) {30    case 0:31      // 0x4fffffffb / 6 = 0xd5555554 + 1 = 3579139413 => -71582788332      break;33    case 1:34      // 0x4fffffffb / 6 = 0xd5555554 + 1 = 3579139413 => -71582788335      break;36    case 2:37      // 0x4fffffffb / 6 = 0xd5555554 + 1 = 3579139413 => -71582788338      break;39    default:40      // 0x0ffffffff / 6 = 0x2aaaaaaa + 1 =  715827883 =>  71582788341      break;42    }43  }44  return 0;45}46 47// CHECK-DAG: ![[FOR]] = !{!"branch_weights", i32 -252645135, i32 1}48// CHECK-DAG: ![[IF]]  = !{!"branch_weights", i32 -268435456, i32 268435456}49// CHECK-DAG: ![[SWITCH]] = !{!"branch_weights", i32 715827883, i32 -715827883, i32 -715827883, i32 -715827883}50