Skip to content

Commit

Permalink
Merged master:5c31b8b94fdd into amd-gfx:84156f83019c
Browse files Browse the repository at this point in the history
Local branch amd-gfx 84156f8 Merged master:3eaec1fead4d into amd-gfx:d56063d98a2c
Remote branch master 5c31b8b Revert "Use uint64_t for branch weights instead of uint32_t"
  • Loading branch information
Sw authored and Sw committed Oct 31, 2020
2 parents 84156f8 + 5c31b8b commit 7e9078f
Show file tree
Hide file tree
Showing 126 changed files with 581 additions and 1,189 deletions.
36 changes: 30 additions & 6 deletions clang/lib/CodeGen/CodeGenPGO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1013,21 +1013,42 @@ void CodeGenPGO::loadRegionCounts(llvm::IndexedInstrProfReader *PGOReader,
RegionCounts = ProfRecord->Counts;
}

/// Scale an individual branch weight (add 1).
/// Calculate what to divide by to scale weights.
///
/// Given the maximum weight, calculate a divisor that will scale all the
/// weights to strictly less than UINT32_MAX.
static uint64_t calculateWeightScale(uint64_t MaxWeight) {
return MaxWeight < UINT32_MAX ? 1 : MaxWeight / UINT32_MAX + 1;
}

/// Scale an individual branch weight (and add 1).
///
/// Scale a 64-bit weight down to 32-bits using \c Scale.
///
/// According to Laplace's Rule of Succession, it is better to compute the
/// weight based on the count plus 1, so universally add 1 to the value.
static uint64_t scaleBranchWeight(uint64_t Weight) { return Weight + 1; }
///
/// \pre \c Scale was calculated by \a calculateWeightScale() with a weight no
/// greater than \c Weight.
static uint32_t scaleBranchWeight(uint64_t Weight, uint64_t Scale) {
assert(Scale && "scale by 0?");
uint64_t Scaled = Weight / Scale + 1;
assert(Scaled <= UINT32_MAX && "overflow 32-bits");
return Scaled;
}

llvm::MDNode *CodeGenFunction::createProfileWeights(uint64_t TrueCount,
uint64_t FalseCount) const {
// Check for empty weights.
if (!TrueCount && !FalseCount)
return nullptr;

// Calculate how to scale down to 32-bits.
uint64_t Scale = calculateWeightScale(std::max(TrueCount, FalseCount));

llvm::MDBuilder MDHelper(CGM.getLLVMContext());
return MDHelper.createBranchWeights(scaleBranchWeight(TrueCount),
scaleBranchWeight(FalseCount));
return MDHelper.createBranchWeights(scaleBranchWeight(TrueCount, Scale),
scaleBranchWeight(FalseCount, Scale));
}

llvm::MDNode *
Expand All @@ -1041,10 +1062,13 @@ CodeGenFunction::createProfileWeights(ArrayRef<uint64_t> Weights) const {
if (MaxWeight == 0)
return nullptr;

SmallVector<uint64_t, 16> ScaledWeights;
// Calculate how to scale down to 32-bits.
uint64_t Scale = calculateWeightScale(MaxWeight);

SmallVector<uint32_t, 16> ScaledWeights;
ScaledWeights.reserve(Weights.size());
for (uint64_t W : Weights)
ScaledWeights.push_back(scaleBranchWeight(W));
ScaledWeights.push_back(scaleBranchWeight(W, Scale));

llvm::MDBuilder MDHelper(CGM.getLLVMContext());
return MDHelper.createBranchWeights(ScaledWeights);
Expand Down
2 changes: 1 addition & 1 deletion clang/test/CodeGen/catch-undef-behavior.c
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,6 @@ void call_nonnull_variadic(int a, int *b) {
nonnull_variadic(a, b);
}

// CHECK-UBSAN: ![[WEIGHT_MD]] = !{!"branch_weights", i64 1048575, i64 1}
// CHECK-UBSAN: ![[WEIGHT_MD]] = !{!"branch_weights", i32 1048575, i32 1}

// CHECK-TRAP: attributes [[NR_NUW]] = { noreturn nounwind }
4 changes: 2 additions & 2 deletions clang/test/CodeGenCXX/attr-likelihood-if-branch-weights.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,5 +142,5 @@ void SwitchStmt() {
}
}

// CHECK: !7 = !{!"branch_weights", i64 [[UNLIKELY]], i64 [[LIKELY]]}
// CHECK: !8 = !{!"branch_weights", i64 [[LIKELY]], i64 [[UNLIKELY]]}
// CHECK: !7 = !{!"branch_weights", i32 [[UNLIKELY]], i32 [[LIKELY]]}
// CHECK: !8 = !{!"branch_weights", i32 [[LIKELY]], i32 [[UNLIKELY]]}
Original file line number Diff line number Diff line change
Expand Up @@ -221,5 +221,5 @@ void tu2(int &i) {
}
}

// CHECK: !6 = !{!"branch_weights", i64 2000, i64 1}
// CHECK: !10 = !{!"branch_weights", i64 1, i64 2000}
// CHECK: !6 = !{!"branch_weights", i32 2000, i32 1}
// CHECK: !10 = !{!"branch_weights", i32 1, i32 2000}
30 changes: 15 additions & 15 deletions clang/test/CodeGenCXX/attr-likelihood-switch-branch-weights.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,18 +177,18 @@ void TwoCasesDefaultLNU() {
}
}

// CHECK: !6 = !{!"branch_weights", i64 357913942, i64 715827883}
// CHECK: !7 = !{!"branch_weights", i64 536870912, i64 1}
// CHECK: !8 = !{!"branch_weights", i64 238609295, i64 715827883, i64 238609295}
// CHECK: !9 = !{!"branch_weights", i64 357913942, i64 1, i64 357913942}
// CHECK: !10 = !{!"branch_weights", i64 357913942, i64 715827883, i64 1}
// CHECK: !11 = !{!"branch_weights", i64 143165577, i64 143165577, i64 143165577, i64 715827883, i64 143165577}
// CHECK: !12 = !{!"branch_weights", i64 214748365, i64 214748365, i64 214748365, i64 1, i64 214748365}
// CHECK: !13 = !{!"branch_weights", i64 79536432, i64 79536432, i64 79536432, i64 79536432, i64 79536432, i64 79536432, i64 79536432, i64 715827883, i64 79536432}
// CHECK: !14 = !{!"branch_weights", i64 119304648, i64 119304648, i64 119304648, i64 119304648, i64 119304648, i64 119304648, i64 119304648, i64 1, i64 119304648}
// CHECK: !15 = !{!"branch_weights", i64 2000, i64 1}
// CHECK: !16 = !{!"branch_weights", i64 1, i64 2000}
// CHECK: !17 = !{!"branch_weights", i64 715827883, i64 357913942}
// CHECK: !18 = !{!"branch_weights", i64 1, i64 536870912}
// CHECK: !19 = !{!"branch_weights", i64 536870912, i64 536870912, i64 268435456}
// CHECK: !20 = !{!"branch_weights", i64 1, i64 715827883, i64 357913942}
// CHECK: !6 = !{!"branch_weights", i32 357913942, i32 715827883}
// CHECK: !7 = !{!"branch_weights", i32 536870912, i32 1}
// CHECK: !8 = !{!"branch_weights", i32 238609295, i32 715827883, i32 238609295}
// CHECK: !9 = !{!"branch_weights", i32 357913942, i32 1, i32 357913942}
// CHECK: !10 = !{!"branch_weights", i32 357913942, i32 715827883, i32 1}
// CHECK: !11 = !{!"branch_weights", i32 143165577, i32 143165577, i32 143165577, i32 715827883, i32 143165577}
// CHECK: !12 = !{!"branch_weights", i32 214748365, i32 214748365, i32 214748365, i32 1, i32 214748365}
// CHECK: !13 = !{!"branch_weights", i32 79536432, i32 79536432, i32 79536432, i32 79536432, i32 79536432, i32 79536432, i32 79536432, i32 715827883, i32 79536432}
// CHECK: !14 = !{!"branch_weights", i32 119304648, i32 119304648, i32 119304648, i32 119304648, i32 119304648, i32 119304648, i32 119304648, i32 1, i32 119304648}
// CHECK: !15 = !{!"branch_weights", i32 2000, i32 1}
// CHECK: !16 = !{!"branch_weights", i32 1, i32 2000}
// CHECK: !17 = !{!"branch_weights", i32 715827883, i32 357913942}
// CHECK: !18 = !{!"branch_weights", i32 1, i32 536870912}
// CHECK: !19 = !{!"branch_weights", i32 536870912, i32 536870912, i32 268435456}
// CHECK: !20 = !{!"branch_weights", i32 1, i32 715827883, i32 357913942}
4 changes: 2 additions & 2 deletions clang/test/CodeGenCXX/microsoft-abi-thread-safe-statics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,5 +96,5 @@ int g1() {
return i;
}

// CHECK-DAG: ![[unlikely_threadlocal]] = !{!"branch_weights", i64 1, i64 1023}
// CHECK-DAG: ![[unlikely_staticlocal]] = !{!"branch_weights", i64 1, i64 1048575}
// CHECK-DAG: ![[unlikely_threadlocal]] = !{!"branch_weights", i32 1, i32 1023}
// CHECK-DAG: ![[unlikely_staticlocal]] = !{!"branch_weights", i32 1, i32 1048575}
4 changes: 2 additions & 2 deletions clang/test/CodeGenCXX/profile-remap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ namespace Foo {
//
// FIXME: Laplace's rule of succession is applied to sample profiles...
// CHECK-SAMPLES-DAG: [[FUNC_ENTRY]] = !{!"function_entry_count", i64 1}
// CHECK-SAMPLES-DAG: [[BR_WEIGHTS]] = !{!"branch_weights", i64 11, i64 91}
// CHECK-SAMPLES-DAG: [[BR_WEIGHTS]] = !{!"branch_weights", i32 11, i32 91}
//
// ... but not to instruction profiles.
// CHECK-INSTR-DAG: [[FUNC_ENTRY]] = !{!"function_entry_count", i64 100}
// CHECK-INSTR-DAG: [[BR_WEIGHTS]] = !{!"branch_weights", i64 10, i64 90}
// CHECK-INSTR-DAG: [[BR_WEIGHTS]] = !{!"branch_weights", i32 10, i32 90}
4 changes: 2 additions & 2 deletions clang/test/CodeGenCXX/static-initializer-branch-weights.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,5 +122,5 @@ void use_b() {
// CHECK: icmp eq i8 {{.*}}, 0
// CHECK: br i1 {{.*}}, !prof ![[WEIGHTS_THREAD_LOCAL]]

// CHECK-DAG: ![[WEIGHTS_THREAD_LOCAL]] = !{!"branch_weights", i64 1, i64 1023}
// CHECK-DAG: ![[WEIGHTS_LOCAL]] = !{!"branch_weights", i64 1, i64 1048575}
// CHECK-DAG: ![[WEIGHTS_THREAD_LOCAL]] = !{!"branch_weights", i32 1, i32 1023}
// CHECK-DAG: ![[WEIGHTS_LOCAL]] = !{!"branch_weights", i32 1, i32 1048575}
9 changes: 0 additions & 9 deletions clang/test/Driver/aarch64-security-options.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,6 @@
// RUN: %clang -target aarch64--none-eabi -c %s -### -msign-return-address=all 2>&1 | \
// RUN: FileCheck %s --check-prefix=RA-ALL --check-prefix=KEY-A --check-prefix=BTE-OFF

// Check that the -msign-return-address= option can also accept the signing key
// to use.

// RUN: %clang -target aarch64--none-eabi -c %s -### -msign-return-address=non-leaf 2>&1 | \
// RUN: FileCheck %s --check-prefix=RA-NON-LEAF --check-prefix=KEY-B --check-prefix=BTE-OFF

// RUN: %clang -target aarch64--none-eabi -c %s -### -msign-return-address=all 2>&1 | \
// RUN: FileCheck %s --check-prefix=RA-ALL --check-prefix=KEY-B --check-prefix=BTE-OFF

// -mbranch-protection with standard
// RUN: %clang -target aarch64--none-eabi -c %s -### -mbranch-protection=standard 2>&1 | \
// RUN: FileCheck %s --check-prefix=RA-NON-LEAF --check-prefix=KEY-A --check-prefix=BTE-ON
Expand Down
2 changes: 1 addition & 1 deletion clang/test/Driver/arch-specific-libdir-rpath.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
// NO-RPATH-X86_64-NOT: "-rpath" "[[RESDIR]]{{(/|\\\\)lib(/|\\\\)linux(/|\\\\)x86_64}}"
//
// LIBPATH-AARCH64: -L[[RESDIR]]{{(/|\\\\)lib(/|\\\\)linux(/|\\\\)aarch64}}
// RPATH-AAARCH4: "-rpath" "[[RESDIR]]{{(/|\\\\)lib(/|\\\\)linux(/|\\\\)aarch64}}"
// RPATH-AARCH64: "-rpath" "[[RESDIR]]{{(/|\\\\)lib(/|\\\\)linux(/|\\\\)aarch64}}"
//
// NO-LIBPATH-NOT: "-L{{[^"]*Inputs(/|\\\\)resource_dir}}"
// NO-RPATH-NOT: "-rpath" {{.*(/|\\\\)Inputs(/|\\\\)resource_dir}}
2 changes: 1 addition & 1 deletion clang/test/Driver/arm-execute-only.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// CHECK-EXECUTE-ONLY-LONG-CALLS: error: option '-mexecute-only' cannot be specified with '-mlong-calls'

// RUN: %clang -target armv7m-eabi -x assembler -mexecute-only %s -c -### 2>&1 \
// RUN: | FileCheck %s -check-prefix CHECK-NO-EXECUTE-ONLY -check-prefix CHECK-NO-EXECUTE-ONLY-ASM
// RUN: | FileCheck %s --check-prefix=CHECK-NO-EXECUTE-ONLY-ASM
// CHECK-NO-EXECUTE-ONLY-ASM: warning: argument unused during compilation: '-mexecute-only'

// -mpure-code flag for GCC compatibility
Expand Down
1 change: 1 addition & 0 deletions clang/test/Driver/cl-denorms-are-zero.cl
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
// RUN: %clang -### -target amdgcn--amdhsa -nogpulib -c %s 2>&1 | FileCheck -check-prefixes=AMDGCN,AMDGCN-DENORM %s
// RUN: %clang -### -cl-denorms-are-zero -o - -target amdgcn--amdhsa -nogpulib -c %s 2>&1 | FileCheck -check-prefixes=AMDGCN,AMDGCN-FLUSH %s

// AMDGCN: "-triple" "amdgcn-unknown-amdhsa"
// AMDGCN-FLUSH: "-fdenormal-fp-math-f32=preserve-sign,preserve-sign"

// This should be omitted and default to ieee
Expand Down
2 changes: 1 addition & 1 deletion clang/test/Driver/fopenmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
// CHECK-LD-STATIC-GOMP: "{{.*}}ld{{(.exe)?}}"
// CHECK-LD-STATIC-GOMP: "-Bstatic" "-lgomp" "-Bdynamic"
// CHECK-LD-STATIC-GOMP-RT: "-lrt"
// CHECK-LD-STATIC-NO-GOMP-RT-NOT: "-lrt"
// CHECK-LD-STATIC-GOMP-NO-RT-NOT: "-lrt"
//
// CHECK-LD-STATIC-IOMP5: "{{.*}}ld{{(.exe)?}}"
// CHECK-LD-STATIC-IOMP5: "-Bstatic" "-liomp5" "-Bdynamic"
Expand Down
2 changes: 1 addition & 1 deletion clang/test/Driver/fsanitize-blacklist.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
// CHECK-DEFAULT-UBSAN-BLACKLIST: -fsanitize-system-blacklist={{.*}}ubsan_blacklist.txt

// Check that combining ubsan and another sanitizer results in both blacklists being used.
// RUN: %clang -target x86_64-linux-gnu -fsanitize=undefined,address -resource-dir=%S/Inputs/resource_dir %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-DEFAULT-UBSAN-BLACKLIST --check-prefix=CHECK-DEFAULT-ASAN-BLACKLIST --implicit-check-not=fdepfile-entry --implicit-check-not=-fsanitize-blacklist=
// RUN: %clang -target x86_64-linux-gnu -fsanitize=undefined,address -resource-dir=%S/Inputs/resource_dir %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-DEFAULT-UBSAN-BLACKLIST --check-prefix=CHECK-DEFAULT-BLACKLIST-ASAN --implicit-check-not=fdepfile-entry --implicit-check-not=-fsanitize-blacklist=

// Ignore -fsanitize-blacklist flag if there is no -fsanitize flag.
// RUN: %clang -target x86_64-linux-gnu -fsanitize-blacklist=%t.good %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-NO-SANITIZE --check-prefix=DELIMITERS
Expand Down
8 changes: 4 additions & 4 deletions clang/test/Driver/fuzzer.c
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// Test flags inserted by -fsanitize=fuzzer.

// RUN: %clang -fsanitize=fuzzer %s -target x86_64-apple-darwin14 -### 2>&1 | FileCheck --check-prefixes=CHECK-FUZZER-LIB,CHECK-COVERAGE-FLAGS %s
// RUN: %clang -fsanitize=fuzzer %s -target x86_64-apple-darwin14 -### 2>&1 | FileCheck --check-prefixes=CHECK-FUZZER-LIB,CHECK-COVERAGE %s
//
// CHECK-FUZZER-LIB: libclang_rt.fuzzer
// CHECK-COVERAGE: -fsanitize-coverage-inline-8bit-counters
// CHECK-COVERAGE-SAME: -fsanitize-coverage-indirect-calls
// CHECK-COVERAGE: -fsanitize-coverage-indirect-calls
// CHECK-COVERAGE-SAME: -fsanitize-coverage-trace-cmp
// CHECK-COVERAGE-SAME: -fsanitize-coverage-inline-8bit-counters
// CHECK-COVERAGE-SAME: -fsanitize-coverage-pc-table
// CHECK-FUZZER-LIB: libclang_rt.fuzzer

// RUN: %clang -fsanitize=fuzzer -target i386-unknown-linux -stdlib=platform %s -### 2>&1 | FileCheck --check-prefixes=CHECK-LIBCXX-LINUX %s
//
Expand Down
2 changes: 1 addition & 1 deletion clang/test/Driver/hip-phases.hip
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
//
// RUN: %clang -x hip -target x86_64-unknown-linux-gnu -ccc-print-phases \
// RUN: --cuda-gpu-arch=gfx803 --cuda-gpu-arch=gfx900 %s -fgpu-rdc 2>&1 \
// RUN: | FileCheck -check-prefixes=RDC2,CL2,RCL2 %s
// RUN: | FileCheck -check-prefixes=RDC2,RCL2 %s

// RUN: %clang -x hip -target x86_64-unknown-linux-gnu -ccc-print-phases \
// RUN: --cuda-gpu-arch=gfx803 --cuda-gpu-arch=gfx900 %s -fgpu-rdc -c 2>&1 \
Expand Down
5 changes: 3 additions & 2 deletions clang/test/Driver/rocm-detect.cl
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@

// RUN: %clang -### -v -target amdgcn-amd-amdhsa -mcpu=gfx902 -nogpulib \
// RUN: --rocm-path=%S/Inputs/rocm %s 2>&1 \
// RUN: | FileCheck -check-prefixes=COMMON,GFX902,NODEFAULTLIBS %s

// RUN: | FileCheck -check-prefixes=COMMON,NODEFAULTLIBS %s

// GFX902-DEFAULTLIBS: error: cannot find ROCm device library for gfx902. Provide its path via --rocm-path or --rocm-device-lib-path, or pass -nogpulib to build without ROCm device library

// NODEFAULTLIBS-NOT: error: cannot find

// COMMON: "-triple" "amdgcn-amd-amdhsa"
4 changes: 3 additions & 1 deletion clang/test/Driver/rocm-detect.hip
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@

// RUN: %clang -### -v -target x86_64-linux-gnu --cuda-gpu-arch=gfx902 -nogpulib \
// RUN: --rocm-path=%S/Inputs/rocm %s 2>&1 \
// RUN: | FileCheck -check-prefixes=COMMON,GFX902,NODEFAULTLIBS %s
// RUN: | FileCheck -check-prefixes=COMMON,NODEFAULTLIBS %s


// GFX902-DEFAULTLIBS: error: cannot find ROCm device library for gfx902. Provide its path via --rocm-path or --rocm-device-lib-path, or pass -nogpulib to build without ROCm device library

// NODEFAULTLIBS-NOT: error: cannot find

// COMMON: "-triple" "amdgcn-amd-amdhsa"
10 changes: 5 additions & 5 deletions clang/test/Profile/c-captured.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ void debug_captured() {
if (x) {} // This is DC2. Checked above.
}

// PGOUSE-DAG: ![[DC1]] = !{!"branch_weights", i64 2, i64 1}
// PGOUSE-DAG: ![[DC2]] = !{!"branch_weights", i64 2, i64 1}
// PGOUSE-DAG: ![[CS1]] = !{!"branch_weights", i64 2, i64 1}
// PGOUSE-DAG: ![[C11]] = !{!"branch_weights", i64 11, i64 2}
// PGOUSE-DAG: ![[C12]] = !{!"branch_weights", i64 2, i64 1}
// PGOUSE-DAG: ![[DC1]] = !{!"branch_weights", i32 2, i32 1}
// PGOUSE-DAG: ![[DC2]] = !{!"branch_weights", i32 2, i32 1}
// PGOUSE-DAG: ![[CS1]] = !{!"branch_weights", i32 2, i32 1}
// PGOUSE-DAG: ![[C11]] = !{!"branch_weights", i32 11, i32 2}
// PGOUSE-DAG: ![[C12]] = !{!"branch_weights", i32 2, i32 1}

int main(int argc, const char *argv[]) {
debug_captured();
Expand Down
49 changes: 49 additions & 0 deletions clang/test/Profile/c-counter-overflows.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Test that big branch weights get scaled down to 32-bits, rather than just
// truncated.

// RUN: llvm-profdata merge %S/Inputs/c-counter-overflows.proftext -o %t.profdata
// RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name c-counter-overflows.c %s -o - -emit-llvm -fprofile-instrument-use-path=%t.profdata | FileCheck %s

typedef unsigned long long uint64_t;

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]] = !{!"branch_weights", i32 -252645135, i32 1}
// CHECK-DAG: ![[IF]] = !{!"branch_weights", i32 -268435456, i32 268435456}
// CHECK-DAG: ![[SWITCH]] = !{!"branch_weights", i32 715827883, i32 -715827883, i32 -715827883, i32 -715827883}
Loading

0 comments on commit 7e9078f

Please sign in to comment.