diff options
| author | Duncan P. N. Exon Smith <dexonsmith@apple.com> | 2014-03-11 18:18:10 +0000 |
|---|---|---|
| committer | Duncan P. N. Exon Smith <dexonsmith@apple.com> | 2014-03-11 18:18:10 +0000 |
| commit | 38402dc917f346261f82ac0c23cad9ae3e106bdf (patch) | |
| tree | e54e259258ace9477a76833446b177c925ab1779 /clang/test/Profile | |
| parent | f164d9404df19e747399be915b93cba2447d2778 (diff) | |
| download | bcm5719-llvm-38402dc917f346261f82ac0c23cad9ae3e106bdf.tar.gz bcm5719-llvm-38402dc917f346261f82ac0c23cad9ae3e106bdf.zip | |
PGO: Scale large counters down to 32-bits
PGO counters are 64-bit and branch weights are 32-bit. Scale them down
when necessary, instead of just taking the lower 32 bits.
<rdar://problem/16276448>
llvm-svn: 203592
Diffstat (limited to 'clang/test/Profile')
| -rw-r--r-- | clang/test/Profile/Inputs/c-counter-overflows.profdata | 10 | ||||
| -rw-r--r-- | clang/test/Profile/c-counter-overflows.c | 49 |
2 files changed, 59 insertions, 0 deletions
diff --git a/clang/test/Profile/Inputs/c-counter-overflows.profdata b/clang/test/Profile/Inputs/c-counter-overflows.profdata new file mode 100644 index 00000000000..377a08502d1 --- /dev/null +++ b/clang/test/Profile/Inputs/c-counter-overflows.profdata @@ -0,0 +1,10 @@ +main 8 +1 +68719476720 +64424509425 +68719476720 +21474836475 +21474836475 +21474836475 +4294967295 + diff --git a/clang/test/Profile/c-counter-overflows.c b/clang/test/Profile/c-counter-overflows.c new file mode 100644 index 00000000000..ddbe6d1c97c --- /dev/null +++ b/clang/test/Profile/c-counter-overflows.c @@ -0,0 +1,49 @@ +// Test that big branch weights get scaled down to 32-bits, rather than just +// truncated. + +// RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name c-counter-overflows.c %s -o - -emit-llvm -fprofile-instr-use=%S/Inputs/c-counter-overflows.profdata | FileCheck %s + +#include <stdint.h> + +// PGOGEN: @[[MAIN:__llvm_pgo_ctr[0-9]*]] = private global [2 x i64] zeroinitializer +int main(int argc, const char *argv[]) { + // Need counts higher than 32-bits. + // CHECK: br {{.*}} !prof ![[FOR:[0-9]+]] + // max = 0xffffffff0 + // scale = 0xffffffff0 / 0xffffffff + 1 = 17 + // loop-body: 0xffffffff0 / 17 + 1 = 0xf0f0f0f0 + 1 = 4042322161 => -252645135 + // loop-exit: 0x000000001 / 17 + 1 = 0x00000000 + 1 = 1 => 1 + for (uint64_t I = 0; I < 0xffffffff0; ++I) { + // max = 0xffffffff * 15 = 0xefffffff1 + // scale = 0xefffffff1 / 0xffffffff + 1 = 16 + // CHECK: br {{.*}} !prof ![[IF:[0-9]+]] + if (I & 0xf) { + // 0xefffffff1 / 16 + 1 = 0xefffffff + 1 = 4026531840 => -268435456 + } else { + // 0x0ffffffff / 16 + 1 = 0x0fffffff + 1 = 268435456 => 268435456 + } + + // max = 0xffffffff * 5 = 0x4fffffffb + // scale = 0x4fffffffb / 0xffffffff + 1 = 6 + // CHECK: ], !prof ![[SWITCH:[0-9]+]] + switch ((I & 0xf) / 5) { + case 0: + // 0x4fffffffb / 6 = 0xd5555554 + 1 = 3579139413 => -715827883 + break; + case 1: + // 0x4fffffffb / 6 = 0xd5555554 + 1 = 3579139413 => -715827883 + break; + case 2: + // 0x4fffffffb / 6 = 0xd5555554 + 1 = 3579139413 => -715827883 + break; + default: + // 0x0ffffffff / 6 = 0x2aaaaaaa + 1 = 715827883 => 715827883 + break; + } + } + return 0; +} + +// CHECK-DAG: ![[FOR]] = metadata !{metadata !"branch_weights", i32 -252645135, i32 1} +// CHECK-DAG: ![[IF]] = metadata !{metadata !"branch_weights", i32 -268435456, i32 268435456} +// CHECK-DAG: ![[SWITCH]] = metadata !{metadata !"branch_weights", i32 715827883, i32 -715827883, i32 -715827883, i32 -715827883} |

