[compiler-rt] 5c31b8b - Revert "Use uint64_t for branch weights instead of uint32_t"

Arthur Eubanks via llvm-commits llvm-commits at lists.llvm.org
Sat Oct 31 00:26:04 PDT 2020


Author: Arthur Eubanks
Date: 2020-10-31T00:25:32-07:00
New Revision: 5c31b8b94fddc7c109672964c72670430fe30887

URL: https://github.com/llvm/llvm-project/commit/5c31b8b94fddc7c109672964c72670430fe30887
DIFF: https://github.com/llvm/llvm-project/commit/5c31b8b94fddc7c109672964c72670430fe30887.diff

LOG: Revert "Use uint64_t for branch weights instead of uint32_t"

This reverts commit 10f2a0d662d8d72eaac48d3e9b31ca8dc90df5a4.

More uint64_t overflows.

Added: 
    clang/test/Profile/c-counter-overflows.c

Modified: 
    clang/lib/CodeGen/CodeGenPGO.cpp
    clang/test/CodeGen/catch-undef-behavior.c
    clang/test/CodeGenCXX/attr-likelihood-if-branch-weights.cpp
    clang/test/CodeGenCXX/attr-likelihood-if-vs-builtin-expect.cpp
    clang/test/CodeGenCXX/attr-likelihood-switch-branch-weights.cpp
    clang/test/CodeGenCXX/microsoft-abi-thread-safe-statics.cpp
    clang/test/CodeGenCXX/profile-remap.cpp
    clang/test/CodeGenCXX/static-initializer-branch-weights.cpp
    clang/test/Profile/c-captured.c
    clang/test/Profile/c-general.c
    clang/test/Profile/cxx-class.cpp
    clang/test/Profile/cxx-lambda.cpp
    clang/test/Profile/cxx-rangefor.cpp
    clang/test/Profile/cxx-templates.cpp
    clang/test/Profile/cxx-throws.cpp
    clang/test/Profile/gcc-flag-compatibility.c
    clang/test/Profile/objc-general.m
    compiler-rt/test/profile/Inputs/comdat_rename_1.cpp
    compiler-rt/test/profile/Inputs/comdat_rename_2.cpp
    compiler-rt/test/profile/Linux/instrprof-basic.c
    compiler-rt/test/profile/Linux/instrprof-cs.c
    compiler-rt/test/profile/instrprof-basic.c
    compiler-rt/test/profile/instrprof-dump.c
    compiler-rt/test/profile/instrprof-hostname.c
    compiler-rt/test/profile/instrprof-override-filename-then-reset-default.c
    compiler-rt/test/profile/instrprof-override-filename-with-env.c
    compiler-rt/test/profile/instrprof-override-filename.c
    compiler-rt/test/profile/instrprof-reset-counters.c
    compiler-rt/test/profile/instrprof-set-filename-then-reset-default.c
    compiler-rt/test/profile/instrprof-set-filename.c
    compiler-rt/test/profile/instrprof-without-libc.c
    compiler-rt/test/profile/instrprof-write-file-atexit-explicitly.c
    compiler-rt/test/profile/instrprof-write-file-only.c
    compiler-rt/test/profile/instrprof-write-file.c
    llvm/include/llvm/IR/Instructions.h
    llvm/include/llvm/IR/MDBuilder.h
    llvm/include/llvm/Transforms/Scalar/LowerExpectIntrinsic.h
    llvm/include/llvm/Transforms/Utils/MisExpect.h
    llvm/lib/Analysis/BranchProbabilityInfo.cpp
    llvm/lib/IR/Instructions.cpp
    llvm/lib/IR/MDBuilder.cpp
    llvm/lib/Transforms/IPO/SampleProfile.cpp
    llvm/lib/Transforms/Instrumentation/ControlHeightReduction.cpp
    llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
    llvm/lib/Transforms/Scalar/JumpThreading.cpp
    llvm/lib/Transforms/Scalar/LowerExpectIntrinsic.cpp
    llvm/lib/Transforms/Utils/CodeExtractor.cpp
    llvm/lib/Transforms/Utils/Local.cpp
    llvm/lib/Transforms/Utils/MisExpect.cpp
    llvm/lib/Transforms/Utils/SimplifyCFG.cpp
    llvm/test/Analysis/BranchProbabilityInfo/basic.ll
    llvm/test/Instrumentation/AddressSanitizer/basic.ll
    llvm/test/Transforms/CodeExtractor/MultipleExitBranchProb.ll
    llvm/test/Transforms/CorrelatedValuePropagation/profmd.ll
    llvm/test/Transforms/JumpThreading/threading_prof1.ll
    llvm/test/Transforms/JumpThreading/threading_prof2.ll
    llvm/test/Transforms/JumpThreading/update-edge-weight.ll
    llvm/test/Transforms/LoopUnroll/peel-loop-pgo-deopt.ll
    llvm/test/Transforms/LoopUnroll/peel-loop-pgo.ll
    llvm/test/Transforms/LoopUnroll/runtime-loop-branchweight.ll
    llvm/test/Transforms/LoopVectorize/check-prof-info.ll
    llvm/test/Transforms/LoopVectorize/tripcount.ll
    llvm/test/Transforms/LowerExpectIntrinsic/basic.ll
    llvm/test/Transforms/LowerExpectIntrinsic/expect-with-probability.ll
    llvm/test/Transforms/LowerExpectIntrinsic/expect_nonboolean.ll
    llvm/test/Transforms/LowerExpectIntrinsic/phi_merge.ll
    llvm/test/Transforms/LowerExpectIntrinsic/phi_or.ll
    llvm/test/Transforms/LowerExpectIntrinsic/phi_tern.ll
    llvm/test/Transforms/PGOProfile/branch1.ll
    llvm/test/Transforms/PGOProfile/branch2.ll
    llvm/test/Transforms/PGOProfile/chr.ll
    llvm/test/Transforms/PGOProfile/criticaledge.ll
    llvm/test/Transforms/PGOProfile/cspgo_profile_summary.ll
    llvm/test/Transforms/PGOProfile/fix_entry_count.ll
    llvm/test/Transforms/PGOProfile/icp_covariant_call_return.ll
    llvm/test/Transforms/PGOProfile/icp_covariant_invoke_return.ll
    llvm/test/Transforms/PGOProfile/icp_invoke.ll
    llvm/test/Transforms/PGOProfile/icp_vararg.ll
    llvm/test/Transforms/PGOProfile/indirect_call_promotion.ll
    llvm/test/Transforms/PGOProfile/indirect_call_promotion_musttail.ll
    llvm/test/Transforms/PGOProfile/indirect_call_promotion_vla.ll
    llvm/test/Transforms/PGOProfile/indirectbr.ll
    llvm/test/Transforms/PGOProfile/instr_entry_bb.ll
    llvm/test/Transforms/PGOProfile/landingpad.ll
    llvm/test/Transforms/PGOProfile/loop1.ll
    llvm/test/Transforms/PGOProfile/loop2.ll
    llvm/test/Transforms/PGOProfile/memop_size_opt.ll
    llvm/test/Transforms/PGOProfile/multiple_hash_profile.ll
    llvm/test/Transforms/PGOProfile/noreturncall.ll
    llvm/test/Transforms/PGOProfile/remap.ll
    llvm/test/Transforms/PGOProfile/select1.ll
    llvm/test/Transforms/PGOProfile/select2.ll
    llvm/test/Transforms/PGOProfile/switch.ll
    llvm/test/Transforms/PGOProfile/thinlto_cspgo_use.ll
    llvm/test/Transforms/PGOProfile/thinlto_indirect_call_promotion.ll
    llvm/test/Transforms/SCCP/switch.ll
    llvm/test/Transforms/SampleProfile/entry_counts_cold.ll
    llvm/test/Transforms/SampleProfile/indirect-call.ll
    llvm/test/Transforms/SampleProfile/inline-mergeprof-dup.ll
    llvm/test/Transforms/SampleProfile/inline-mergeprof.ll
    llvm/test/Transforms/SampleProfile/profile-format-compress.ll
    llvm/test/Transforms/SampleProfile/profile-format.ll
    llvm/test/Transforms/SimpleLoopUnswitch/basictest-profmd.ll
    llvm/test/Transforms/SimpleLoopUnswitch/trivial-unswitch-profmd.ll
    llvm/test/Transforms/SimplifyCFG/invoke_unwind.ll
    llvm/test/Transforms/SimplifyCFG/preserve-branchweights-switch-create.ll
    llvm/test/Transforms/SimplifyCFG/preserve-branchweights.ll
    llvm/test/Transforms/SimplifyCFG/switch-profmd.ll
    llvm/test/Transforms/Util/libcalls-shrinkwrap-double.ll
    llvm/test/Transforms/Util/libcalls-shrinkwrap-float.ll
    llvm/test/Transforms/Util/libcalls-shrinkwrap-long-double.ll
    llvm/unittests/Analysis/ProfileSummaryInfoTest.cpp
    mlir/test/Target/llvmir.mlir

Removed: 
    llvm/test/Analysis/BranchProbabilityInfo/basic_i32.ll
    llvm/test/Analysis/BranchProbabilityInfo/branch-large-weights.ll


################################################################################
diff  --git a/clang/lib/CodeGen/CodeGenPGO.cpp b/clang/lib/CodeGen/CodeGenPGO.cpp
index 871c468801ae..c11d99a348d1 100644
--- a/clang/lib/CodeGen/CodeGenPGO.cpp
+++ b/clang/lib/CodeGen/CodeGenPGO.cpp
@@ -1013,11 +1013,29 @@ 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 {
@@ -1025,9 +1043,12 @@ llvm::MDNode *CodeGenFunction::createProfileWeights(uint64_t TrueCount,
   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 *
@@ -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);

diff  --git a/clang/test/CodeGen/catch-undef-behavior.c b/clang/test/CodeGen/catch-undef-behavior.c
index c211e237c56b..3b44f7403b0b 100644
--- a/clang/test/CodeGen/catch-undef-behavior.c
+++ b/clang/test/CodeGen/catch-undef-behavior.c
@@ -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 }

diff  --git a/clang/test/CodeGenCXX/attr-likelihood-if-branch-weights.cpp b/clang/test/CodeGenCXX/attr-likelihood-if-branch-weights.cpp
index 47725eed0764..6327396a9285 100644
--- a/clang/test/CodeGenCXX/attr-likelihood-if-branch-weights.cpp
+++ b/clang/test/CodeGenCXX/attr-likelihood-if-branch-weights.cpp
@@ -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]]}

diff  --git a/clang/test/CodeGenCXX/attr-likelihood-if-vs-builtin-expect.cpp b/clang/test/CodeGenCXX/attr-likelihood-if-vs-builtin-expect.cpp
index 3994fb067418..5872c4c5273f 100644
--- a/clang/test/CodeGenCXX/attr-likelihood-if-vs-builtin-expect.cpp
+++ b/clang/test/CodeGenCXX/attr-likelihood-if-vs-builtin-expect.cpp
@@ -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}

diff  --git a/clang/test/CodeGenCXX/attr-likelihood-switch-branch-weights.cpp b/clang/test/CodeGenCXX/attr-likelihood-switch-branch-weights.cpp
index 3046b7505c56..5fb7a67a7d9e 100644
--- a/clang/test/CodeGenCXX/attr-likelihood-switch-branch-weights.cpp
+++ b/clang/test/CodeGenCXX/attr-likelihood-switch-branch-weights.cpp
@@ -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}

diff  --git a/clang/test/CodeGenCXX/microsoft-abi-thread-safe-statics.cpp b/clang/test/CodeGenCXX/microsoft-abi-thread-safe-statics.cpp
index 2db2c3382182..a5bb87414d6a 100644
--- a/clang/test/CodeGenCXX/microsoft-abi-thread-safe-statics.cpp
+++ b/clang/test/CodeGenCXX/microsoft-abi-thread-safe-statics.cpp
@@ -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}

diff  --git a/clang/test/CodeGenCXX/profile-remap.cpp b/clang/test/CodeGenCXX/profile-remap.cpp
index d6d43f599400..b519e55d2112 100644
--- a/clang/test/CodeGenCXX/profile-remap.cpp
+++ b/clang/test/CodeGenCXX/profile-remap.cpp
@@ -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}

diff  --git a/clang/test/CodeGenCXX/static-initializer-branch-weights.cpp b/clang/test/CodeGenCXX/static-initializer-branch-weights.cpp
index ebf502dd0c74..f9e77812714c 100644
--- a/clang/test/CodeGenCXX/static-initializer-branch-weights.cpp
+++ b/clang/test/CodeGenCXX/static-initializer-branch-weights.cpp
@@ -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}

diff  --git a/clang/test/Profile/c-captured.c b/clang/test/Profile/c-captured.c
index 4d5a80d98453..0e265a722917 100644
--- a/clang/test/Profile/c-captured.c
+++ b/clang/test/Profile/c-captured.c
@@ -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();

diff  --git a/clang/test/Profile/c-counter-overflows.c b/clang/test/Profile/c-counter-overflows.c
new file mode 100644
index 000000000000..5cb32bbc30af
--- /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: 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}

diff  --git a/clang/test/Profile/c-general.c b/clang/test/Profile/c-general.c
index da8a8f2810df..a7f03e872881 100644
--- a/clang/test/Profile/c-general.c
+++ b/clang/test/Profile/c-general.c
@@ -470,82 +470,82 @@ static void static_func() {
   }
 }
 
-// PGOUSE-DAG: ![[SL1]] = !{!"branch_weights", i64 101, i64 2}
-// PGOUSE-DAG: ![[SL2]] = !{!"branch_weights", i64 101, i64 2}
-// PGOUSE-DAG: ![[SL3]] = !{!"branch_weights", i64 76, i64 2}
-
-// PGOUSE-DAG: ![[EE1]] = !{!"branch_weights", i64 1, i64 2}
-// PGOUSE-DAG: ![[EE2]] = !{!"branch_weights", i64 52, i64 1}
-// PGOUSE-DAG: ![[EE3]] = !{!"branch_weights", i64 2, i64 51}
-// PGOUSE-DAG: ![[EE4]] = !{!"branch_weights", i64 26, i64 26}
-// PGOUSE-DAG: ![[EE5]] = !{!"branch_weights", i64 2, i64 1}
-// PGOUSE-DAG: ![[EE6]] = !{!"branch_weights", i64 2, i64 26}
-// PGOUSE-DAG: ![[EE7]] = !{!"branch_weights", i64 26, i64 1}
-
-// PGOUSE-DAG: ![[IF1]] = !{!"branch_weights", i64 101, i64 2}
-// PGOUSE-DAG: ![[IF2]] = !{!"branch_weights", i64 51, i64 51}
-// PGOUSE-DAG: ![[IF3]] = !{!"branch_weights", i64 51, i64 1}
-// PGOUSE-DAG: ![[IF4]] = !{!"branch_weights", i64 34, i64 18}
-// PGOUSE-DAG: ![[IF5]] = !{!"branch_weights", i64 34, i64 1}
-// PGOUSE-DAG: ![[IF6]] = !{!"branch_weights", i64 17, i64 2}
-// PGOUSE-DAG: ![[IF7]] = !{!"branch_weights", i64 100, i64 2}
-// PGOUSE-DAG: ![[IF8]] = !{!"branch_weights", i64 100, i64 2}
-
-// PGOUSE-DAG: ![[JM1]] = !{!"branch_weights", i64 2, i64 1}
-// PGOUSE-DAG: ![[JM2]] = !{!"branch_weights", i64 1, i64 2}
-// PGOUSE-DAG: ![[JM3]] = !{!"branch_weights", i64 1, i64 2}
-// PGOUSE-DAG: ![[JM4]] = !{!"branch_weights", i64 1, i64 2}
-// PGOUSE-DAG: ![[JM5]] = !{!"branch_weights", i64 3, i64 2}
-// PGOUSE-DAG: ![[JM6]] = !{!"branch_weights", i64 1, i64 2}
-// PGOUSE-DAG: ![[JM7]] = !{!"branch_weights", i64 1, i64 2, i64 2, i64 2}
-// PGOUSE-DAG: ![[JM8]] = !{!"branch_weights", i64 11, i64 2}
-// PGOUSE-DAG: ![[JM9]] = !{!"branch_weights", i64 10, i64 2}
-
-// PGOUSE-DAG: ![[SW1]] = !{!"branch_weights", i64 16, i64 1}
-// PGOUSE-DAG: ![[SW2]] = !{!"branch_weights", i64 6, i64 2, i64 3, i64 4, i64 5}
-// PGOUSE-DAG: ![[SW3]] = !{!"branch_weights", i64 1, i64 2}
-// PGOUSE-DAG: ![[SW4]] = !{!"branch_weights", i64 3, i64 2}
-// PGOUSE-DAG: ![[SW5]] = !{!"branch_weights", i64 4, i64 1}
-// PGOUSE-DAG: ![[SW6]] = !{!"branch_weights", i64 5, i64 1}
-// PGOUSE-DAG: ![[SW7]] = !{!"branch_weights", i64 1, i64 2, i64 2, i64 2, i64 2}
-// PGOUSE-DAG: ![[SW8]] = !{!"branch_weights", i64 5, i64 1}
-// PGOUSE-DAG: ![[SW9]] = !{!"branch_weights", i64 2, i64 5}
-
-// PGOUSE-DAG: ![[BS1]] = !{!"branch_weights", i64 33, i64 2}
-// PGOUSE-DAG: ![[BS2]] = !{!"branch_weights", i64 29, i64 2, i64 2, i64 2, i64 2, i64 1}
-// PGOUSE-DAG: ![[BS3]] = !{!"branch_weights", i64 1, i64 2}
-// PGOUSE-DAG: ![[BS4]] = !{!"branch_weights", i64 2, i64 2}
-// PGOUSE-DAG: ![[BS5]] = !{!"branch_weights", i64 12, i64 1}
-// PGOUSE-DAG: ![[BS6]] = !{!"branch_weights", i64 12, i64 3}
-// PGOUSE-DAG: ![[BS7]] = !{!"branch_weights", i64 2, i64 1}
-// PGOUSE-DAG: ![[BS8]] = !{!"branch_weights", i64 16, i64 1}
-// PGOUSE-DAG: ![[BS9]] = !{!"branch_weights", i64 16, i64 14}
-// PGOUSE-DAG: ![[BS10]] = !{!"branch_weights", i64 2, i64 1}
-// PGOUSE-DAG: ![[BS11]] = !{!"branch_weights", i64 3, i64 1}
-
-// PGOUSE-DAG: ![[BO1]] = !{!"branch_weights", i64 101, i64 2}
-// PGOUSE-DAG: ![[BO2]] = !{!"branch_weights", i64 67, i64 35}
-// PGOUSE-DAG: ![[BO3]] = !{!"branch_weights", i64 67, i64 35}
-// PGOUSE-DAG: ![[BO4]] = !{!"branch_weights", i64 67, i64 35}
-// PGOUSE-DAG: ![[BO5]] = !{!"branch_weights", i64 18, i64 18}
-// PGOUSE-DAG: ![[BO6]] = !{!"branch_weights", i64 51, i64 51}
-// PGOUSE-DAG: ![[BO7]] = !{!"branch_weights", i64 34, i64 18}
-// PGOUSE-DAG: ![[BL1]] = !{!"branch_weights", i64 52, i64 1}
-// PGOUSE-DAG: ![[BL2]] = !{!"branch_weights", i64 51, i64 2}
-// PGOUSE-DAG: ![[BL3]] = !{!"branch_weights", i64 26, i64 27}
-// PGOUSE-DAG: ![[BL4]] = !{!"branch_weights", i64 51, i64 2}
-// PGOUSE-DAG: ![[BL5]] = !{!"branch_weights", i64 52, i64 1}
-// PGOUSE-DAG: ![[BL6]] = !{!"branch_weights", i64 51, i64 2}
-// PGOUSE-DAG: ![[BL7]] = !{!"branch_weights", i64 26, i64 27}
-// PGOUSE-DAG: ![[BL8]] = !{!"branch_weights", i64 51, i64 2}
-// PGOUSE-DAG: ![[CO1]] = !{!"branch_weights", i64 1, i64 2}
-// PGOUSE-DAG: ![[CO2]] = !{!"branch_weights", i64 2, i64 1}
-
-// PGOUSE-DAG: ![[DF1]] = !{!"branch_weights", i64 11, i64 2}
-// PGOUSE-DAG: ![[DF2]] = !{!"branch_weights", i64 3, i64 3}
-// PGOUSE-DAG: ![[DF3]] = !{!"branch_weights", i64 9, i64 5}
-
-// PGOUSE-DAG: ![[ST1]] = !{!"branch_weights", i64 11, i64 2}
+// PGOUSE-DAG: ![[SL1]] = !{!"branch_weights", i32 101, i32 2}
+// PGOUSE-DAG: ![[SL2]] = !{!"branch_weights", i32 101, i32 2}
+// PGOUSE-DAG: ![[SL3]] = !{!"branch_weights", i32 76, i32 2}
+
+// PGOUSE-DAG: ![[EE1]] = !{!"branch_weights", i32 1, i32 2}
+// PGOUSE-DAG: ![[EE2]] = !{!"branch_weights", i32 52, i32 1}
+// PGOUSE-DAG: ![[EE3]] = !{!"branch_weights", i32 2, i32 51}
+// PGOUSE-DAG: ![[EE4]] = !{!"branch_weights", i32 26, i32 26}
+// PGOUSE-DAG: ![[EE5]] = !{!"branch_weights", i32 2, i32 1}
+// PGOUSE-DAG: ![[EE6]] = !{!"branch_weights", i32 2, i32 26}
+// PGOUSE-DAG: ![[EE7]] = !{!"branch_weights", i32 26, i32 1}
+
+// PGOUSE-DAG: ![[IF1]] = !{!"branch_weights", i32 101, i32 2}
+// PGOUSE-DAG: ![[IF2]] = !{!"branch_weights", i32 51, i32 51}
+// PGOUSE-DAG: ![[IF3]] = !{!"branch_weights", i32 51, i32 1}
+// PGOUSE-DAG: ![[IF4]] = !{!"branch_weights", i32 34, i32 18}
+// PGOUSE-DAG: ![[IF5]] = !{!"branch_weights", i32 34, i32 1}
+// PGOUSE-DAG: ![[IF6]] = !{!"branch_weights", i32 17, i32 2}
+// PGOUSE-DAG: ![[IF7]] = !{!"branch_weights", i32 100, i32 2}
+// PGOUSE-DAG: ![[IF8]] = !{!"branch_weights", i32 100, i32 2}
+
+// PGOUSE-DAG: ![[JM1]] = !{!"branch_weights", i32 2, i32 1}
+// PGOUSE-DAG: ![[JM2]] = !{!"branch_weights", i32 1, i32 2}
+// PGOUSE-DAG: ![[JM3]] = !{!"branch_weights", i32 1, i32 2}
+// PGOUSE-DAG: ![[JM4]] = !{!"branch_weights", i32 1, i32 2}
+// PGOUSE-DAG: ![[JM5]] = !{!"branch_weights", i32 3, i32 2}
+// PGOUSE-DAG: ![[JM6]] = !{!"branch_weights", i32 1, i32 2}
+// PGOUSE-DAG: ![[JM7]] = !{!"branch_weights", i32 1, i32 2, i32 2, i32 2}
+// PGOUSE-DAG: ![[JM8]] = !{!"branch_weights", i32 11, i32 2}
+// PGOUSE-DAG: ![[JM9]] = !{!"branch_weights", i32 10, i32 2}
+
+// PGOUSE-DAG: ![[SW1]] = !{!"branch_weights", i32 16, i32 1}
+// PGOUSE-DAG: ![[SW2]] = !{!"branch_weights", i32 6, i32 2, i32 3, i32 4, i32 5}
+// PGOUSE-DAG: ![[SW3]] = !{!"branch_weights", i32 1, i32 2}
+// PGOUSE-DAG: ![[SW4]] = !{!"branch_weights", i32 3, i32 2}
+// PGOUSE-DAG: ![[SW5]] = !{!"branch_weights", i32 4, i32 1}
+// PGOUSE-DAG: ![[SW6]] = !{!"branch_weights", i32 5, i32 1}
+// PGOUSE-DAG: ![[SW7]] = !{!"branch_weights", i32 1, i32 2, i32 2, i32 2, i32 2}
+// PGOUSE-DAG: ![[SW8]] = !{!"branch_weights", i32 5, i32 1}
+// PGOUSE-DAG: ![[SW9]] = !{!"branch_weights", i32 2, i32 5}
+
+// PGOUSE-DAG: ![[BS1]] = !{!"branch_weights", i32 33, i32 2}
+// PGOUSE-DAG: ![[BS2]] = !{!"branch_weights", i32 29, i32 2, i32 2, i32 2, i32 2, i32 1}
+// PGOUSE-DAG: ![[BS3]] = !{!"branch_weights", i32 1, i32 2}
+// PGOUSE-DAG: ![[BS4]] = !{!"branch_weights", i32 2, i32 2}
+// PGOUSE-DAG: ![[BS5]] = !{!"branch_weights", i32 12, i32 1}
+// PGOUSE-DAG: ![[BS6]] = !{!"branch_weights", i32 12, i32 3}
+// PGOUSE-DAG: ![[BS7]] = !{!"branch_weights", i32 2, i32 1}
+// PGOUSE-DAG: ![[BS8]] = !{!"branch_weights", i32 16, i32 1}
+// PGOUSE-DAG: ![[BS9]] = !{!"branch_weights", i32 16, i32 14}
+// PGOUSE-DAG: ![[BS10]] = !{!"branch_weights", i32 2, i32 1}
+// PGOUSE-DAG: ![[BS11]] = !{!"branch_weights", i32 3, i32 1}
+
+// PGOUSE-DAG: ![[BO1]] = !{!"branch_weights", i32 101, i32 2}
+// PGOUSE-DAG: ![[BO2]] = !{!"branch_weights", i32 67, i32 35}
+// PGOUSE-DAG: ![[BO3]] = !{!"branch_weights", i32 67, i32 35}
+// PGOUSE-DAG: ![[BO4]] = !{!"branch_weights", i32 67, i32 35}
+// PGOUSE-DAG: ![[BO5]] = !{!"branch_weights", i32 18, i32 18}
+// PGOUSE-DAG: ![[BO6]] = !{!"branch_weights", i32 51, i32 51}
+// PGOUSE-DAG: ![[BO7]] = !{!"branch_weights", i32 34, i32 18}
+// PGOUSE-DAG: ![[BL1]] = !{!"branch_weights", i32 52, i32 1}
+// PGOUSE-DAG: ![[BL2]] = !{!"branch_weights", i32 51, i32 2}
+// PGOUSE-DAG: ![[BL3]] = !{!"branch_weights", i32 26, i32 27}
+// PGOUSE-DAG: ![[BL4]] = !{!"branch_weights", i32 51, i32 2}
+// PGOUSE-DAG: ![[BL5]] = !{!"branch_weights", i32 52, i32 1}
+// PGOUSE-DAG: ![[BL6]] = !{!"branch_weights", i32 51, i32 2}
+// PGOUSE-DAG: ![[BL7]] = !{!"branch_weights", i32 26, i32 27}
+// PGOUSE-DAG: ![[BL8]] = !{!"branch_weights", i32 51, i32 2}
+// PGOUSE-DAG: ![[CO1]] = !{!"branch_weights", i32 1, i32 2}
+// PGOUSE-DAG: ![[CO2]] = !{!"branch_weights", i32 2, i32 1}
+
+// PGOUSE-DAG: ![[DF1]] = !{!"branch_weights", i32 11, i32 2}
+// PGOUSE-DAG: ![[DF2]] = !{!"branch_weights", i32 3, i32 3}
+// PGOUSE-DAG: ![[DF3]] = !{!"branch_weights", i32 9, i32 5}
+
+// PGOUSE-DAG: ![[ST1]] = !{!"branch_weights", i32 11, i32 2}
 
 int main(int argc, const char *argv[]) {
   simple_loops();

diff  --git a/clang/test/Profile/cxx-class.cpp b/clang/test/Profile/cxx-class.cpp
index 5d88892c5e13..ab90d195cdc6 100644
--- a/clang/test/Profile/cxx-class.cpp
+++ b/clang/test/Profile/cxx-class.cpp
@@ -31,7 +31,7 @@ class Simple {
     // CTRUSE-NOT: br {{.*}} !prof ![0-9]+
     // CTRUSE: ret
   }
-  // CTRUSE: ![[SC1]] = !{!"branch_weights", i64 100, i64 2}
+  // CTRUSE: ![[SC1]] = !{!"branch_weights", i32 100, i32 2}
 
   // DTRGEN-LABEL: define {{.*}} @_ZN6SimpleD2Ev(
   // DTRUSE-LABEL: define {{.*}} @_ZN6SimpleD2Ev(
@@ -44,7 +44,7 @@ class Simple {
     // DTRUSE-NOT: br {{.*}} !prof ![0-9]+
     // DTRUSE: ret
   }
-  // DTRUSE: ![[SD1]] = !{!"branch_weights", i64 100, i64 2}
+  // DTRUSE: ![[SD1]] = !{!"branch_weights", i32 100, i32 2}
 
   // MTHGEN-LABEL: define {{.*}} @_ZN6Simple6methodEv(
   // MTHUSE-LABEL: define {{.*}} @_ZN6Simple6methodEv(
@@ -57,7 +57,7 @@ class Simple {
     // MTHUSE-NOT: br {{.*}} !prof ![0-9]+
     // MTHUSE: ret
   }
-  // MTHUSE: ![[SM1]] = !{!"branch_weights", i64 100, i64 2}
+  // MTHUSE: ![[SM1]] = !{!"branch_weights", i32 100, i32 2}
 };
 
 class Derived : virtual public Simple {
@@ -73,7 +73,7 @@ class Derived : virtual public Simple {
     // VCTRUSE-NOT: br {{.*}} !prof ![0-9]+
     // VCTRUSE: ret
   }
-  // VCTRUSE: ![[SC1]] = !{!"branch_weights", i64 100, i64 2}
+  // VCTRUSE: ![[SC1]] = !{!"branch_weights", i32 100, i32 2}
 
   // VDTRGEN-LABEL: define {{.*}} @_ZN7DerivedD2Ev(
   // VDTRUSE-LABEL: define {{.*}} @_ZN7DerivedD2Ev(
@@ -86,7 +86,7 @@ class Derived : virtual public Simple {
     // VDTRUSE-NOT: br {{.*}} !prof ![0-9]+
     // VDTRUSE: ret
   }
-  // VDTRUSE: ![[SD1]] = !{!"branch_weights", i64 100, i64 2}
+  // VDTRUSE: ![[SD1]] = !{!"branch_weights", i32 100, i32 2}
 };
 
 // WRPGEN-LABEL: define {{.*}} @_Z14simple_wrapperv(
@@ -104,7 +104,7 @@ void simple_wrapper() {
   // WRPUSE-NOT: br {{.*}} !prof ![0-9]+
   // WRPUSE: ret
 }
-// WRPUSE: ![[SW1]] = !{!"branch_weights", i64 101, i64 2}
+// WRPUSE: ![[SW1]] = !{!"branch_weights", i32 101, i32 2}
 
 int main(int argc, const char *argv[]) {
   simple_wrapper();

diff  --git a/clang/test/Profile/cxx-lambda.cpp b/clang/test/Profile/cxx-lambda.cpp
index 3486e106d49f..08d78da40348 100644
--- a/clang/test/Profile/cxx-lambda.cpp
+++ b/clang/test/Profile/cxx-lambda.cpp
@@ -45,12 +45,12 @@ void lambdas() {
   if (i) {}
 }
 
-// PGOUSE-DAG: ![[LW1]] = !{!"branch_weights", i64 2, i64 1}
-// PGOUSE-DAG: ![[LW2]] = !{!"branch_weights", i64 11, i64 2}
-// PGOUSE-DAG: ![[LW3]] = !{!"branch_weights", i64 2, i64 1}
+// PGOUSE-DAG: ![[LW1]] = !{!"branch_weights", i32 2, i32 1}
+// PGOUSE-DAG: ![[LW2]] = !{!"branch_weights", i32 11, i32 2}
+// PGOUSE-DAG: ![[LW3]] = !{!"branch_weights", i32 2, i32 1}
 
-// LMBUSE-DAG: ![[LF1]] = !{!"branch_weights", i64 10, i64 2}
-// LMBUSE-DAG: ![[LF2]] = !{!"branch_weights", i64 10, i64 2}
+// LMBUSE-DAG: ![[LF1]] = !{!"branch_weights", i32 10, i32 2}
+// LMBUSE-DAG: ![[LF2]] = !{!"branch_weights", i32 10, i32 2}
 
 int main(int argc, const char *argv[]) {
   lambdas();

diff  --git a/clang/test/Profile/cxx-rangefor.cpp b/clang/test/Profile/cxx-rangefor.cpp
index bef1141d43a0..1d2f7f470cfe 100644
--- a/clang/test/Profile/cxx-rangefor.cpp
+++ b/clang/test/Profile/cxx-rangefor.cpp
@@ -33,10 +33,10 @@ void range_for() {
   if (sum) {}
 }
 
-// PGOUSE-DAG: ![[RF1]] = !{!"branch_weights", i64 5, i64 1}
-// PGOUSE-DAG: ![[RF2]] = !{!"branch_weights", i64 2, i64 4}
-// PGOUSE-DAG: ![[RF3]] = !{!"branch_weights", i64 2, i64 3}
-// PGOUSE-DAG: ![[RF4]] = !{!"branch_weights", i64 2, i64 1}
+// PGOUSE-DAG: ![[RF1]] = !{!"branch_weights", i32 5, i32 1}
+// PGOUSE-DAG: ![[RF2]] = !{!"branch_weights", i32 2, i32 4}
+// PGOUSE-DAG: ![[RF3]] = !{!"branch_weights", i32 2, i32 3}
+// PGOUSE-DAG: ![[RF4]] = !{!"branch_weights", i32 2, i32 1}
 
 int main(int argc, const char *argv[]) {
   range_for();

diff  --git a/clang/test/Profile/cxx-templates.cpp b/clang/test/Profile/cxx-templates.cpp
index 7c84141cb53a..7af6660f521d 100644
--- a/clang/test/Profile/cxx-templates.cpp
+++ b/clang/test/Profile/cxx-templates.cpp
@@ -32,8 +32,8 @@ template <unsigned N> void loop() {
   // ALL: ret
 }
 
-// T0USE-DAG: ![[T01]] = !{!"branch_weights", i64 1, i64 2}
-// T100USE-DAG: ![[T1001]] = !{!"branch_weights", i64 101, i64 2}
+// T0USE-DAG: ![[T01]] = !{!"branch_weights", i32 1, i32 2}
+// T100USE-DAG: ![[T1001]] = !{!"branch_weights", i32 101, i32 2}
 
 int main(int argc, const char *argv[]) {
   loop<0>();

diff  --git a/clang/test/Profile/cxx-throws.cpp b/clang/test/Profile/cxx-throws.cpp
index ee6f1871e2b2..f6c0f52b67a1 100644
--- a/clang/test/Profile/cxx-throws.cpp
+++ b/clang/test/Profile/cxx-throws.cpp
@@ -76,13 +76,13 @@ void unreachable(int i) {
   if (i) {}
 }
 
-// PGOUSE-DAG: ![[TH1]] = !{!"branch_weights", i64 101, i64 2}
-// PGOUSE-DAG: ![[TH2]] = !{!"branch_weights", i64 67, i64 35}
-// PGOUSE-DAG: ![[TH3]] = !{!"branch_weights", i64 34, i64 34}
-// PGOUSE-DAG: ![[TH4]] = !{!"branch_weights", i64 18, i64 18}
-// PGOUSE-EXC: ![[TH5]] = !{!"branch_weights", i64 34, i64 18}
-// PGOUSE-DAG: ![[TH6]] = !{!"branch_weights", i64 101, i64 1}
-// PGOUSE-DAG: ![[UN1]] = !{!"branch_weights", i64 2, i64 1}
+// PGOUSE-DAG: ![[TH1]] = !{!"branch_weights", i32 101, i32 2}
+// PGOUSE-DAG: ![[TH2]] = !{!"branch_weights", i32 67, i32 35}
+// PGOUSE-DAG: ![[TH3]] = !{!"branch_weights", i32 34, i32 34}
+// PGOUSE-DAG: ![[TH4]] = !{!"branch_weights", i32 18, i32 18}
+// PGOUSE-EXC: ![[TH5]] = !{!"branch_weights", i32 34, i32 18}
+// PGOUSE-DAG: ![[TH6]] = !{!"branch_weights", i32 101, i32 1}
+// PGOUSE-DAG: ![[UN1]] = !{!"branch_weights", i32 2, i32 1}
 
 int main(int argc, const char *argv[]) {
   throws();

diff  --git a/clang/test/Profile/gcc-flag-compatibility.c b/clang/test/Profile/gcc-flag-compatibility.c
index 703e20bedae7..743b7ff55555 100644
--- a/clang/test/Profile/gcc-flag-compatibility.c
+++ b/clang/test/Profile/gcc-flag-compatibility.c
@@ -32,7 +32,7 @@
 // RUN: llvm-profdata merge %S/Inputs/gcc-flag-compatibility.proftext -o %t.dir/some/path/file.prof
 // RUN: %clang %s -o - -Xclang -disable-llvm-passes -emit-llvm -S -fprofile-use=%t.dir/some/path/file.prof -fno-experimental-new-pass-manager | FileCheck -check-prefix=PROFILE-USE %s
 // RUN: %clang %s -o - -Xclang -disable-llvm-passes -emit-llvm -S -fprofile-use=%t.dir/some/path/file.prof -fexperimental-new-pass-manager | FileCheck -check-prefix=PROFILE-USE %s
-// PROFILE-USE: = !{!"branch_weights", i64 101, i64 2}
+// PROFILE-USE: = !{!"branch_weights", i32 101, i32 2}
 
 // Check that -fprofile-use=some/path reads some/path/default.profdata
 // This uses LLVM IR format profile.
@@ -54,7 +54,7 @@
 // RUN: %clang %s -o - -emit-llvm -S -fprofile-use=%t.dir/some/path/file.prof -fno-experimental-new-pass-manager | FileCheck -check-prefix=PROFILE-USE-IR %s
 // RUN: %clang %s -o - -emit-llvm -S -fprofile-use=%t.dir/some/path/file.prof -fexperimental-new-pass-manager | FileCheck -check-prefix=PROFILE-USE-IR %s
 
-// PROFILE-USE-IR: = !{!"branch_weights", i64 100, i64 1}
+// PROFILE-USE-IR: = !{!"branch_weights", i32 100, i32 1}
 
 int X = 0;
 

diff  --git a/clang/test/Profile/objc-general.m b/clang/test/Profile/objc-general.m
index 55a17e836aac..7a4cac941205 100644
--- a/clang/test/Profile/objc-general.m
+++ b/clang/test/Profile/objc-general.m
@@ -79,9 +79,9 @@ void consecutive_objc_for_ranges(NSArray *arr) {
     ++x;
 }
 
-// PGOUSE-DAG: ![[FR1]] = !{!"branch_weights", i64 2, i64 3}
-// PGOUSE-DAG: ![[FR2]] = !{!"branch_weights", i64 3, i64 2}
-// PGOUSE-DAG: ![[BL1]] = !{!"branch_weights", i64 2, i64 2}
+// PGOUSE-DAG: ![[FR1]] = !{!"branch_weights", i32 2, i32 3}
+// PGOUSE-DAG: ![[FR2]] = !{!"branch_weights", i32 3, i32 2}
+// PGOUSE-DAG: ![[BL1]] = !{!"branch_weights", i32 2, i32 2}
 
 int main(int argc, const char *argv[]) {
   A *a = [[A alloc] init];

diff  --git a/compiler-rt/test/profile/Inputs/comdat_rename_1.cpp b/compiler-rt/test/profile/Inputs/comdat_rename_1.cpp
index 533cb8725687..d7f1b1620ea7 100644
--- a/compiler-rt/test/profile/Inputs/comdat_rename_1.cpp
+++ b/compiler-rt/test/profile/Inputs/comdat_rename_1.cpp
@@ -21,13 +21,13 @@ int FOO::callee() {
 // CHECK-LABEL: define {{.*}}caller{{.*}}
 // CHECK-NOT: br i1 {{.*}}
 // CHECK: br {{.*}}label{{.*}}, label %[[BB2:.*]], !prof ![[PD2:[0-9]+]]
-// CHECK: {{.*}}[[BB2]]:
+// CHECK: {{.*}}[[BB2]]: 
 // CHECK: br {{.*}}label{{.*}}, label %{{.*}}, !prof !{{.*}}
 // CHECK: br {{.*}}label %[[BB3:.*]], label %{{.*}} !prof ![[PD3:[0-9]+]]
-// CHECK: {{.*}}[[BB3]]:
+// CHECK: {{.*}}[[BB3]]: 
 //
-// CHECK:![[PD1]] = !{!"branch_weights", i64 0, i64 1}
-// CHECK:![[PD2]] = !{!"branch_weights", i64 1, i64 0}
-// CHECK:![[PD3]] = !{!"branch_weights", i64 {{.*}}, i64 0}
+// CHECK:![[PD1]] = !{!"branch_weights", i32 0, i32 1}
+// CHECK:![[PD2]] = !{!"branch_weights", i32 1, i32 0}
+// CHECK:![[PD3]] = !{!"branch_weights", i32 {{.*}}, i32 0}
 
 void test(FOO *foo) { foo->caller(10); }

diff  --git a/compiler-rt/test/profile/Inputs/comdat_rename_2.cpp b/compiler-rt/test/profile/Inputs/comdat_rename_2.cpp
index c7ff1bee9de6..5cad79c9f9d8 100644
--- a/compiler-rt/test/profile/Inputs/comdat_rename_2.cpp
+++ b/compiler-rt/test/profile/Inputs/comdat_rename_2.cpp
@@ -14,5 +14,5 @@ int main() {
 // CHECK: {{.*}} call {{.*}}
 // CHECK-NOT: br i1 {{.*}}
 // CHECK: br {{.*}}label %[[BB1:.*]], label{{.*}}!prof ![[PD1:[0-9]+]]
-// CHECK: {{.*}}[[BB1]]:
-// CHECK:![[PD1]] = !{!"branch_weights", i64 0, i64 1}
+// CHECK: {{.*}}[[BB1]]: 
+// CHECK:![[PD1]] = !{!"branch_weights", i32 0, i32 1}

diff  --git a/compiler-rt/test/profile/Linux/instrprof-basic.c b/compiler-rt/test/profile/Linux/instrprof-basic.c
index 87b45c70a34b..7ae683d9bd9e 100644
--- a/compiler-rt/test/profile/Linux/instrprof-basic.c
+++ b/compiler-rt/test/profile/Linux/instrprof-basic.c
@@ -27,5 +27,5 @@ int main(int argc, const char *argv[]) {
   return 1;
 }
 
-// CHECK: ![[PD1]] = !{!"branch_weights", i64 1, i64 2}
-// CHECK: ![[PD2]] = !{!"branch_weights", i64 2, i64 1}
+// CHECK: ![[PD1]] = !{!"branch_weights", i32 1, i32 2}
+// CHECK: ![[PD2]] = !{!"branch_weights", i32 2, i32 1}

diff  --git a/compiler-rt/test/profile/Linux/instrprof-cs.c b/compiler-rt/test/profile/Linux/instrprof-cs.c
index aeaefd71dcf4..d825525a532d 100644
--- a/compiler-rt/test/profile/Linux/instrprof-cs.c
+++ b/compiler-rt/test/profile/Linux/instrprof-cs.c
@@ -30,6 +30,6 @@ int main() {
   return 0;
 }
 
-// CS: ![[PD1]] = !{!"branch_weights", i64 0, i64 1}
-// CS: ![[PD2]] = !{!"branch_weights", i64 1, i64 0}
-// CIS: ![[PD]] = !{!"branch_weights", i64 2, i64 2}
+// CS: ![[PD1]] = !{!"branch_weights", i32 0, i32 1}
+// CS: ![[PD2]] = !{!"branch_weights", i32 1, i32 0}
+// CIS: ![[PD]] = !{!"branch_weights", i32 2, i32 2}

diff  --git a/compiler-rt/test/profile/instrprof-basic.c b/compiler-rt/test/profile/instrprof-basic.c
index 97f166a74711..17631d1b9a98 100644
--- a/compiler-rt/test/profile/instrprof-basic.c
+++ b/compiler-rt/test/profile/instrprof-basic.c
@@ -73,9 +73,9 @@ int main(int argc, const char *argv[]) {
   return 1;
 }
 
-// ORIG: ![[PD1]] = !{!"branch_weights", i64 1, i64 2}
-// ORIG: ![[PD2]] = !{!"branch_weights", i64 2, i64 1}
-// MERGE: ![[PD1]] = !{!"branch_weights", i64 1, i64 3}
-// MERGE: ![[PD2]] = !{!"branch_weights", i64 3, i64 1}
-// PGOMERGE: ![[PD1]] = !{!"branch_weights", i64 0, i64 4}
-// PGOMERGE: ![[PD2]] = !{!"branch_weights", i64 4, i64 0}
+// ORIG: ![[PD1]] = !{!"branch_weights", i32 1, i32 2}
+// ORIG: ![[PD2]] = !{!"branch_weights", i32 2, i32 1}
+// MERGE: ![[PD1]] = !{!"branch_weights", i32 1, i32 3}
+// MERGE: ![[PD2]] = !{!"branch_weights", i32 3, i32 1}
+// PGOMERGE: ![[PD1]] = !{!"branch_weights", i32 0, i32 4}
+// PGOMERGE: ![[PD2]] = !{!"branch_weights", i32 4, i32 0}

diff  --git a/compiler-rt/test/profile/instrprof-dump.c b/compiler-rt/test/profile/instrprof-dump.c
index ac2d51214505..93c3c46f6916 100644
--- a/compiler-rt/test/profile/instrprof-dump.c
+++ b/compiler-rt/test/profile/instrprof-dump.c
@@ -58,5 +58,5 @@ __attribute__((noinline)) int bar(int X) {
 
 /*
 PROF: ![[ENT]] = !{!"function_entry_count", i64 2}  
-PROF: ![[PD1]] = !{!"branch_weights", i64 2, i64 2}
+PROF: ![[PD1]] = !{!"branch_weights", i32 2, i32 2}
 */

diff  --git a/compiler-rt/test/profile/instrprof-hostname.c b/compiler-rt/test/profile/instrprof-hostname.c
index 890b4e5fb852..b77cf8df158b 100644
--- a/compiler-rt/test/profile/instrprof-hostname.c
+++ b/compiler-rt/test/profile/instrprof-hostname.c
@@ -11,4 +11,4 @@ int main(int argc, const char *argv[]) {
     return 1;
   return 0;
 }
-// CHECK: ![[PD1]] = !{!"branch_weights", i64 1, i64 2}
+// CHECK: ![[PD1]] = !{!"branch_weights", i32 1, i32 2}

diff  --git a/compiler-rt/test/profile/instrprof-override-filename-then-reset-default.c b/compiler-rt/test/profile/instrprof-override-filename-then-reset-default.c
index 2031407b7e5f..3438227213ec 100644
--- a/compiler-rt/test/profile/instrprof-override-filename-then-reset-default.c
+++ b/compiler-rt/test/profile/instrprof-override-filename-then-reset-default.c
@@ -16,4 +16,4 @@ int main(int argc, const char *argv[]) {
   __llvm_profile_set_filename(0);
   return 0;
 }
-// CHECK: ![[PD1]] = !{!"branch_weights", i64 1, i64 2}
+// CHECK: ![[PD1]] = !{!"branch_weights", i32 1, i32 2}

diff  --git a/compiler-rt/test/profile/instrprof-override-filename-with-env.c b/compiler-rt/test/profile/instrprof-override-filename-with-env.c
index 5d6d1c1a7f5c..3f4e5c8d251c 100644
--- a/compiler-rt/test/profile/instrprof-override-filename-with-env.c
+++ b/compiler-rt/test/profile/instrprof-override-filename-with-env.c
@@ -11,4 +11,4 @@ int main(int argc, const char *argv[]) {
   bar();
   return 0;
 }
-// CHECK: ![[PD1]] = !{!"branch_weights", i64 1, i64 2}
+// CHECK: ![[PD1]] = !{!"branch_weights", i32 1, i32 2}

diff  --git a/compiler-rt/test/profile/instrprof-override-filename.c b/compiler-rt/test/profile/instrprof-override-filename.c
index 07b9e48ceda2..d2b6b69a7003 100644
--- a/compiler-rt/test/profile/instrprof-override-filename.c
+++ b/compiler-rt/test/profile/instrprof-override-filename.c
@@ -20,5 +20,5 @@ int main(int argc, const char *argv[]) {
   bar();
   return 0;
 }
-// FE: ![[PD1]] = !{!"branch_weights", i64 1, i64 2}
-// IR: ![[PD1]] = !{!"branch_weights", i64 0, i64 1}
+// FE: ![[PD1]] = !{!"branch_weights", i32 1, i32 2}
+// IR: ![[PD1]] = !{!"branch_weights", i32 0, i32 1}

diff  --git a/compiler-rt/test/profile/instrprof-reset-counters.c b/compiler-rt/test/profile/instrprof-reset-counters.c
index 604967161ba6..f15bc0d8e3a1 100644
--- a/compiler-rt/test/profile/instrprof-reset-counters.c
+++ b/compiler-rt/test/profile/instrprof-reset-counters.c
@@ -16,4 +16,4 @@ void foo(int N) {
   // CHECK: br i1 %{{.*}}, label %{{.*}}, label %{{.*}}, !prof ![[FOO:[0-9]+]]
   if (N) {}
 }
-// CHECK: ![[FOO]] = !{!"branch_weights", i64 2, i64 1}
+// CHECK: ![[FOO]] = !{!"branch_weights", i32 2, i32 1}

diff  --git a/compiler-rt/test/profile/instrprof-set-filename-then-reset-default.c b/compiler-rt/test/profile/instrprof-set-filename-then-reset-default.c
index 17460f3bc128..6c07994f08c6 100644
--- a/compiler-rt/test/profile/instrprof-set-filename-then-reset-default.c
+++ b/compiler-rt/test/profile/instrprof-set-filename-then-reset-default.c
@@ -15,4 +15,4 @@ int main(int argc, const char *argv[]) {
   __llvm_profile_set_filename(0);
   return 0;
 }
-// CHECK: ![[PD1]] = !{!"branch_weights", i64 1, i64 2}
+// CHECK: ![[PD1]] = !{!"branch_weights", i32 1, i32 2}

diff  --git a/compiler-rt/test/profile/instrprof-set-filename.c b/compiler-rt/test/profile/instrprof-set-filename.c
index 3b87c7dc3110..e130590325fe 100644
--- a/compiler-rt/test/profile/instrprof-set-filename.c
+++ b/compiler-rt/test/profile/instrprof-set-filename.c
@@ -56,5 +56,5 @@ int main(int argc, const char *argv[]) {
 #endif
   return 0;
 }
-// CHECK: ![[PD1]] = !{!"branch_weights", i64 1, i64 2}
+// CHECK: ![[PD1]] = !{!"branch_weights", i32 1, i32 2}
 // SHARED: Total functions: 2

diff  --git a/compiler-rt/test/profile/instrprof-without-libc.c b/compiler-rt/test/profile/instrprof-without-libc.c
index b823174c17b1..cd9fb5e1dd8e 100644
--- a/compiler-rt/test/profile/instrprof-without-libc.c
+++ b/compiler-rt/test/profile/instrprof-without-libc.c
@@ -54,7 +54,7 @@ int main(int argc, const char *argv[]) {
   return fclose(File);
 #endif
 }
-// CHECK: ![[PD1]] = !{!"branch_weights", i64 1, i64 2}
+// CHECK: ![[PD1]] = !{!"branch_weights", i32 1, i32 2}
 
 // CHECK-SYMBOLS-NOT: {{ }}___cxx_global_var_init
 // CHECK-SYMBOLS-NOT: {{ }}___llvm_profile_register_write_file_atexit

diff  --git a/compiler-rt/test/profile/instrprof-write-file-atexit-explicitly.c b/compiler-rt/test/profile/instrprof-write-file-atexit-explicitly.c
index 374203d11820..18c365af5003 100644
--- a/compiler-rt/test/profile/instrprof-write-file-atexit-explicitly.c
+++ b/compiler-rt/test/profile/instrprof-write-file-atexit-explicitly.c
@@ -14,4 +14,4 @@ int main(int argc, const char *argv[]) {
   __llvm_profile_set_filename(argv[1]);
   return 0;
 }
-// CHECK: ![[PD1]] = !{!"branch_weights", i64 1, i64 2}
+// CHECK: ![[PD1]] = !{!"branch_weights", i32 1, i32 2}

diff  --git a/compiler-rt/test/profile/instrprof-write-file-only.c b/compiler-rt/test/profile/instrprof-write-file-only.c
index d14614be2e23..f505cf64a5c7 100644
--- a/compiler-rt/test/profile/instrprof-write-file-only.c
+++ b/compiler-rt/test/profile/instrprof-write-file-only.c
@@ -32,4 +32,4 @@ int foo(int X) {
   // CHECK: br i1 %{{.*}}, label %{{.*}}, label %{{[^,]+$}}
   return X <= 0 ? -X : X;
 }
-// CHECK: ![[PD1]] = !{!"branch_weights", i64 1, i64 2}
+// CHECK: ![[PD1]] = !{!"branch_weights", i32 1, i32 2}

diff  --git a/compiler-rt/test/profile/instrprof-write-file.c b/compiler-rt/test/profile/instrprof-write-file.c
index 9c0220602432..e2f5e112e064 100644
--- a/compiler-rt/test/profile/instrprof-write-file.c
+++ b/compiler-rt/test/profile/instrprof-write-file.c
@@ -31,5 +31,5 @@ int foo(int X) {
   // CHECK2: br i1 %{{.*}}, label %{{.*}}, label %{{.*}}, !prof ![[PD2:[0-9]+]]
   return X <= 0 ? -X : X;
 }
-// CHECK: ![[PD1]] = !{!"branch_weights", i64 1, i64 2}
-// CHECK2: ![[PD2]] = !{!"branch_weights", i64 2, i64 1}
+// CHECK: ![[PD1]] = !{!"branch_weights", i32 1, i32 2}
+// CHECK2: ![[PD2]] = !{!"branch_weights", i32 2, i32 1}

diff  --git a/llvm/include/llvm/IR/Instructions.h b/llvm/include/llvm/IR/Instructions.h
index b32992bc779a..ea1a60d52c87 100644
--- a/llvm/include/llvm/IR/Instructions.h
+++ b/llvm/include/llvm/IR/Instructions.h
@@ -3494,7 +3494,7 @@ class SwitchInst : public Instruction {
 /// their prof branch_weights metadata.
 class SwitchInstProfUpdateWrapper {
   SwitchInst &SI;
-  Optional<SmallVector<uint64_t, 8>> Weights = None;
+  Optional<SmallVector<uint32_t, 8> > Weights = None;
   bool Changed = false;
 
 protected:

diff  --git a/llvm/include/llvm/IR/MDBuilder.h b/llvm/include/llvm/IR/MDBuilder.h
index 0a4b1660b7d1..11e2e2623257 100644
--- a/llvm/include/llvm/IR/MDBuilder.h
+++ b/llvm/include/llvm/IR/MDBuilder.h
@@ -58,10 +58,10 @@ class MDBuilder {
   //===------------------------------------------------------------------===//
 
   /// Return metadata containing two branch weights.
-  MDNode *createBranchWeights(uint64_t TrueWeight, uint64_t FalseWeight);
+  MDNode *createBranchWeights(uint32_t TrueWeight, uint32_t FalseWeight);
 
   /// Return metadata containing a number of branch weights.
-  MDNode *createBranchWeights(ArrayRef<uint64_t> Weights);
+  MDNode *createBranchWeights(ArrayRef<uint32_t> Weights);
 
   /// Return metadata specifying that a branch or switch is unpredictable.
   MDNode *createUnpredictable();

diff  --git a/llvm/include/llvm/Transforms/Scalar/LowerExpectIntrinsic.h b/llvm/include/llvm/Transforms/Scalar/LowerExpectIntrinsic.h
index 090b665c8872..22b2e649e4d4 100644
--- a/llvm/include/llvm/Transforms/Scalar/LowerExpectIntrinsic.h
+++ b/llvm/include/llvm/Transforms/Scalar/LowerExpectIntrinsic.h
@@ -32,8 +32,8 @@ struct LowerExpectIntrinsicPass : PassInfoMixin<LowerExpectIntrinsicPass> {
   PreservedAnalyses run(Function &F, FunctionAnalysisManager &);
 };
 
-extern cl::opt<uint64_t> LikelyBranchWeight;
-extern cl::opt<uint64_t> UnlikelyBranchWeight;
+extern cl::opt<uint32_t> LikelyBranchWeight;
+extern cl::opt<uint32_t> UnlikelyBranchWeight;
 }
 
 #endif

diff  --git a/llvm/include/llvm/Transforms/Utils/MisExpect.h b/llvm/include/llvm/Transforms/Utils/MisExpect.h
index cb45bd3fcef7..1dbe8cb95936 100644
--- a/llvm/include/llvm/Transforms/Utils/MisExpect.h
+++ b/llvm/include/llvm/Transforms/Utils/MisExpect.h
@@ -28,7 +28,7 @@ namespace misexpect {
 /// \param Weights A vector of profile weights for each target block
 /// \param Ctx The current LLVM context
 void verifyMisExpect(llvm::Instruction *I,
-                     const llvm::SmallVector<uint64_t, 4> &Weights,
+                     const llvm::SmallVector<uint32_t, 4> &Weights,
                      llvm::LLVMContext &Ctx);
 
 /// checkClangInstrumentation - verify if llvm.expect matches PGO profile

diff  --git a/llvm/lib/Analysis/BranchProbabilityInfo.cpp b/llvm/lib/Analysis/BranchProbabilityInfo.cpp
index 3249468fe942..267d415ff52b 100644
--- a/llvm/lib/Analysis/BranchProbabilityInfo.cpp
+++ b/llvm/lib/Analysis/BranchProbabilityInfo.cpp
@@ -38,7 +38,6 @@
 #include "llvm/Support/Casting.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/Debug.h"
-#include "llvm/Support/MathExtras.h"
 #include "llvm/Support/raw_ostream.h"
 #include <cassert>
 #include <cstdint>
@@ -435,28 +434,6 @@ bool BranchProbabilityInfo::calcUnreachableHeuristics(const BasicBlock *BB) {
   return true;
 }
 
-// Scales all values in Weights so that the total fits in 64 bits. Returns the
-// total.
-// FIXME: only scale by the minimum necessary to fit the total within 64 bits.
-static uint64_t ScaleWeights(MutableArrayRef<uint64_t> Weights) {
-  uint64_t Total = 0;
-  bool Overflowed = false;
-  for (uint64_t W : Weights) {
-    Total = SaturatingAdd(Total, W, &Overflowed);
-    if (Overflowed)
-      break;
-  }
-  if (Overflowed) {
-    uint64_t ScaledTotal = 0;
-    for (uint64_t &W : Weights) {
-      W /= UINT32_MAX;
-      ScaledTotal += W;
-    }
-    return ScaledTotal;
-  }
-  return Total;
-}
-
 // Propagate existing explicit probabilities from either profile data or
 // 'expect' intrinsic processing. Examine metadata against unreachable
 // heuristic. The probability of the edge coming to unreachable block is
@@ -481,7 +458,10 @@ bool BranchProbabilityInfo::calcMetadataWeights(const BasicBlock *BB) {
     return false;
 
   // Build up the final weights that will be used in a temporary buffer.
-  SmallVector<uint64_t, 2> Weights;
+  // Compute the sum of all weights to later decide whether they need to
+  // be scaled to fit in 32 bits.
+  uint64_t WeightSum = 0;
+  SmallVector<uint32_t, 2> Weights;
   SmallVector<unsigned, 2> UnreachableIdxs;
   SmallVector<unsigned, 2> ReachableIdxs;
   Weights.reserve(TI->getNumSuccessors());
@@ -490,10 +470,10 @@ bool BranchProbabilityInfo::calcMetadataWeights(const BasicBlock *BB) {
         mdconst::dyn_extract<ConstantInt>(WeightsNode->getOperand(I));
     if (!Weight)
       return false;
-    // TODO: remove scaling by UINT32_MAX and use full uint64_t range.
-    uint64_t WeightVal = Weight->getZExtValue();
-    Weights.push_back(WeightVal);
-    // WeightSum += WeightVal;
+    assert(Weight->getValue().getActiveBits() <= 32 &&
+           "Too many bits for uint32_t");
+    Weights.push_back(Weight->getZExtValue());
+    WeightSum += Weights.back();
     if (PostDominatedByUnreachable.count(TI->getSuccessor(I - 1)))
       UnreachableIdxs.push_back(I - 1);
     else
@@ -501,7 +481,20 @@ bool BranchProbabilityInfo::calcMetadataWeights(const BasicBlock *BB) {
   }
   assert(Weights.size() == TI->getNumSuccessors() && "Checked above");
 
-  uint64_t WeightSum = ScaleWeights(Weights);
+  // If the sum of weights does not fit in 32 bits, scale every weight down
+  // accordingly.
+  uint64_t ScalingFactor =
+      (WeightSum > UINT32_MAX) ? WeightSum / UINT32_MAX + 1 : 1;
+
+  if (ScalingFactor > 1) {
+    WeightSum = 0;
+    for (unsigned I = 0, E = TI->getNumSuccessors(); I != E; ++I) {
+      Weights[I] /= ScalingFactor;
+      WeightSum += Weights[I];
+    }
+  }
+  assert(WeightSum <= UINT32_MAX &&
+         "Expected weights to scale down to 32 bits");
 
   if (WeightSum == 0 || ReachableIdxs.size() == 0) {
     for (unsigned I = 0, E = TI->getNumSuccessors(); I != E; ++I)
@@ -512,8 +505,7 @@ bool BranchProbabilityInfo::calcMetadataWeights(const BasicBlock *BB) {
   // Set the probability.
   SmallVector<BranchProbability, 2> BP;
   for (unsigned I = 0, E = TI->getNumSuccessors(); I != E; ++I)
-    BP.push_back(
-        BranchProbability::getBranchProbability(Weights[I], WeightSum));
+    BP.push_back({ Weights[I], static_cast<uint32_t>(WeightSum) });
 
   // Examine the metadata against unreachable heuristic.
   // If the unreachable heuristic is more strong then we use it for this edge.

diff  --git a/llvm/lib/IR/Instructions.cpp b/llvm/lib/IR/Instructions.cpp
index eb9100a54509..b8663cdcbe83 100644
--- a/llvm/lib/IR/Instructions.cpp
+++ b/llvm/lib/IR/Instructions.cpp
@@ -4060,7 +4060,7 @@ MDNode *SwitchInstProfUpdateWrapper::buildProfBranchWeightsMD() {
          "num of prof branch_weights must accord with num of successors");
 
   bool AllZeroes =
-      all_of(Weights.getValue(), [](uint64_t W) { return W == 0; });
+      all_of(Weights.getValue(), [](uint32_t W) { return W == 0; });
 
   if (AllZeroes || Weights.getValue().size() < 2)
     return nullptr;
@@ -4078,10 +4078,10 @@ void SwitchInstProfUpdateWrapper::init() {
                      "not correspond to number of succesors");
   }
 
-  SmallVector<uint64_t, 8> Weights;
+  SmallVector<uint32_t, 8> Weights;
   for (unsigned CI = 1, CE = SI.getNumSuccessors(); CI <= CE; ++CI) {
     ConstantInt *C = mdconst::extract<ConstantInt>(ProfileData->getOperand(CI));
-    uint64_t CW = C->getValue().getZExtValue();
+    uint32_t CW = C->getValue().getZExtValue();
     Weights.push_back(CW);
   }
   this->Weights = std::move(Weights);
@@ -4109,7 +4109,7 @@ void SwitchInstProfUpdateWrapper::addCase(
 
   if (!Weights && W && *W) {
     Changed = true;
-    Weights = SmallVector<uint64_t, 8>(SI.getNumSuccessors(), 0);
+    Weights = SmallVector<uint32_t, 8>(SI.getNumSuccessors(), 0);
     Weights.getValue()[SI.getNumSuccessors() - 1] = *W;
   } else if (Weights) {
     Changed = true;
@@ -4142,7 +4142,7 @@ void SwitchInstProfUpdateWrapper::setSuccessorWeight(
     return;
 
   if (!Weights && *W)
-    Weights = SmallVector<uint64_t, 8>(SI.getNumSuccessors(), 0);
+    Weights = SmallVector<uint32_t, 8>(SI.getNumSuccessors(), 0);
 
   if (Weights) {
     auto &OldW = Weights.getValue()[idx];

diff  --git a/llvm/lib/IR/MDBuilder.cpp b/llvm/lib/IR/MDBuilder.cpp
index 871c620502c0..1f3bed3776d1 100644
--- a/llvm/lib/IR/MDBuilder.cpp
+++ b/llvm/lib/IR/MDBuilder.cpp
@@ -34,20 +34,20 @@ MDNode *MDBuilder::createFPMath(float Accuracy) {
   return MDNode::get(Context, Op);
 }
 
-MDNode *MDBuilder::createBranchWeights(uint64_t TrueWeight,
-                                       uint64_t FalseWeight) {
+MDNode *MDBuilder::createBranchWeights(uint32_t TrueWeight,
+                                       uint32_t FalseWeight) {
   return createBranchWeights({TrueWeight, FalseWeight});
 }
 
-MDNode *MDBuilder::createBranchWeights(ArrayRef<uint64_t> Weights) {
+MDNode *MDBuilder::createBranchWeights(ArrayRef<uint32_t> Weights) {
   assert(Weights.size() >= 1 && "Need at least one branch weights!");
 
   SmallVector<Metadata *, 4> Vals(Weights.size() + 1);
   Vals[0] = createString("branch_weights");
 
-  Type *Int64Ty = Type::getInt64Ty(Context);
+  Type *Int32Ty = Type::getInt32Ty(Context);
   for (unsigned i = 0, e = Weights.size(); i != e; ++i)
-    Vals[i + 1] = createConstant(ConstantInt::get(Int64Ty, Weights[i]));
+    Vals[i + 1] = createConstant(ConstantInt::get(Int32Ty, Weights[i]));
 
   return MDNode::get(Context, Vals);
 }

diff  --git a/llvm/lib/Transforms/IPO/SampleProfile.cpp b/llvm/lib/Transforms/IPO/SampleProfile.cpp
index fc95e0e34309..dbcf58f6daa7 100644
--- a/llvm/lib/Transforms/IPO/SampleProfile.cpp
+++ b/llvm/lib/Transforms/IPO/SampleProfile.cpp
@@ -1584,7 +1584,8 @@ void SampleProfileLoader::propagateWeights(Function &F) {
                             SortedCallTargets.size());
         } else if (!isa<IntrinsicInst>(&I)) {
           I.setMetadata(LLVMContext::MD_prof,
-                        MDB.createBranchWeights({BlockWeights[BB]}));
+                        MDB.createBranchWeights(
+                            {static_cast<uint32_t>(BlockWeights[BB])}));
         }
       }
     }
@@ -1599,17 +1600,24 @@ void SampleProfileLoader::propagateWeights(Function &F) {
                       << ((BranchLoc) ? Twine(BranchLoc.getLine())
                                       : Twine("<UNKNOWN LOCATION>"))
                       << ".\n");
-    SmallVector<uint64_t, 4> Weights;
-    uint64_t MaxWeight = 0;
+    SmallVector<uint32_t, 4> Weights;
+    uint32_t MaxWeight = 0;
     Instruction *MaxDestInst;
     for (unsigned I = 0; I < TI->getNumSuccessors(); ++I) {
       BasicBlock *Succ = TI->getSuccessor(I);
       Edge E = std::make_pair(BB, Succ);
       uint64_t Weight = EdgeWeights[E];
       LLVM_DEBUG(dbgs() << "\t"; printEdgeWeight(dbgs(), E));
+      // Use uint32_t saturated arithmetic to adjust the incoming weights,
+      // if needed. Sample counts in profiles are 64-bit unsigned values,
+      // but internally branch weights are expressed as 32-bit values.
+      if (Weight > std::numeric_limits<uint32_t>::max()) {
+        LLVM_DEBUG(dbgs() << " (saturated due to uint32_t overflow)");
+        Weight = std::numeric_limits<uint32_t>::max();
+      }
       // Weight is added by one to avoid propagation errors introduced by
       // 0 weights.
-      Weights.push_back(Weight + 1);
+      Weights.push_back(static_cast<uint32_t>(Weight + 1));
       if (Weight != 0) {
         if (Weight > MaxWeight) {
           MaxWeight = Weight;

diff  --git a/llvm/lib/Transforms/Instrumentation/ControlHeightReduction.cpp b/llvm/lib/Transforms/Instrumentation/ControlHeightReduction.cpp
index 1cb017110663..a99c58b74fb1 100644
--- a/llvm/lib/Transforms/Instrumentation/ControlHeightReduction.cpp
+++ b/llvm/lib/Transforms/Instrumentation/ControlHeightReduction.cpp
@@ -1865,9 +1865,9 @@ void CHR::fixupBranchesAndSelects(CHRScope *Scope,
         << " branches or selects";
   });
   MergedBR->setCondition(MergedCondition);
-  uint64_t Weights[] = {
-      CHRBranchBias.scale(1000),
-      CHRBranchBias.getCompl().scale(1000),
+  uint32_t Weights[] = {
+      static_cast<uint32_t>(CHRBranchBias.scale(1000)),
+      static_cast<uint32_t>(CHRBranchBias.getCompl().scale(1000)),
   };
   MDBuilder MDB(F.getContext());
   MergedBR->setMetadata(LLVMContext::MD_prof, MDB.createBranchWeights(Weights));

diff  --git a/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp b/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
index b9530ae1484a..dd70c1f77d9c 100644
--- a/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
+++ b/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
@@ -116,7 +116,6 @@
 #include <cstdint>
 #include <memory>
 #include <numeric>
-#include <stdint.h>
 #include <string>
 #include <unordered_map>
 #include <utility>
@@ -1831,7 +1830,7 @@ void llvm::setProfMetadata(Module *M, Instruction *TI,
   MDBuilder MDB(M->getContext());
   assert(MaxCount > 0 && "Bad max count");
   uint64_t Scale = calculateCountScale(MaxCount);
-  SmallVector<uint64_t, 4> Weights;
+  SmallVector<unsigned, 4> Weights;
   for (const auto &ECI : EdgeCounts)
     Weights.push_back(scaleBranchCount(ECI, Scale));
 

diff  --git a/llvm/lib/Transforms/Scalar/JumpThreading.cpp b/llvm/lib/Transforms/Scalar/JumpThreading.cpp
index a2bb49632342..12deaaa0af58 100644
--- a/llvm/lib/Transforms/Scalar/JumpThreading.cpp
+++ b/llvm/lib/Transforms/Scalar/JumpThreading.cpp
@@ -293,7 +293,7 @@ static void updatePredecessorProfileMetadata(PHINode *PN, BasicBlock *BB) {
     if (BP >= BranchProbability(50, 100))
       continue;
 
-    SmallVector<uint64_t, 2> Weights;
+    SmallVector<uint32_t, 2> Weights;
     if (PredBr->getSuccessor(0) == PredOutEdge.second) {
       Weights.push_back(BP.getNumerator());
       Weights.push_back(BP.getCompl().getNumerator());
@@ -2541,7 +2541,7 @@ void JumpThreadingPass::UpdateBlockFreqAndEdgeWeight(BasicBlock *PredBB,
   // shouldn't make edges extremely likely or unlikely based solely on static
   // estimation.
   if (BBSuccProbs.size() >= 2 && doesBlockHaveProfileData(BB)) {
-    SmallVector<uint64_t, 4> Weights;
+    SmallVector<uint32_t, 4> Weights;
     for (auto Prob : BBSuccProbs)
       Weights.push_back(Prob.getNumerator());
 

diff  --git a/llvm/lib/Transforms/Scalar/LowerExpectIntrinsic.cpp b/llvm/lib/Transforms/Scalar/LowerExpectIntrinsic.cpp
index b61ada102a68..33f73f6e163a 100644
--- a/llvm/lib/Transforms/Scalar/LowerExpectIntrinsic.cpp
+++ b/llvm/lib/Transforms/Scalar/LowerExpectIntrinsic.cpp
@@ -47,14 +47,14 @@ STATISTIC(ExpectIntrinsicsHandled,
 // 'select' instructions. It may be worthwhile to hoist these values to some
 // shared space, so they can be used directly by other passes.
 
-cl::opt<uint64_t> llvm::LikelyBranchWeight(
+cl::opt<uint32_t> llvm::LikelyBranchWeight(
     "likely-branch-weight", cl::Hidden, cl::init(2000),
     cl::desc("Weight of the branch likely to be taken (default = 2000)"));
-cl::opt<uint64_t> llvm::UnlikelyBranchWeight(
+cl::opt<uint32_t> llvm::UnlikelyBranchWeight(
     "unlikely-branch-weight", cl::Hidden, cl::init(1),
     cl::desc("Weight of the branch unlikely to be taken (default = 1)"));
 
-static std::tuple<uint64_t, uint64_t>
+static std::tuple<uint32_t, uint32_t>
 getBranchWeight(Intrinsic::ID IntrinsicID, CallInst *CI, int BranchCount) {
   if (IntrinsicID == Intrinsic::expect) {
     // __builtin_expect
@@ -69,8 +69,8 @@ getBranchWeight(Intrinsic::ID IntrinsicID, CallInst *CI, int BranchCount) {
     assert((TrueProb >= 0.0 && TrueProb <= 1.0) &&
            "probability value must be in the range [0.0, 1.0]");
     double FalseProb = (1.0 - TrueProb) / (BranchCount - 1);
-    uint64_t LikelyBW = ceil((TrueProb * (double)(INT32_MAX - 1)) + 1.0);
-    uint64_t UnlikelyBW = ceil((FalseProb * (double)(INT32_MAX - 1)) + 1.0);
+    uint32_t LikelyBW = ceil((TrueProb * (double)(INT32_MAX - 1)) + 1.0);
+    uint32_t UnlikelyBW = ceil((FalseProb * (double)(INT32_MAX - 1)) + 1.0);
     return std::make_tuple(LikelyBW, UnlikelyBW);
   }
 }
@@ -92,11 +92,11 @@ static bool handleSwitchExpect(SwitchInst &SI) {
 
   SwitchInst::CaseHandle Case = *SI.findCaseValue(ExpectedValue);
   unsigned n = SI.getNumCases(); // +1 for default case.
-  uint64_t LikelyBranchWeightVal, UnlikelyBranchWeightVal;
+  uint32_t LikelyBranchWeightVal, UnlikelyBranchWeightVal;
   std::tie(LikelyBranchWeightVal, UnlikelyBranchWeightVal) =
       getBranchWeight(Fn->getIntrinsicID(), CI, n + 1);
 
-  SmallVector<uint64_t, 16> Weights(n + 1, UnlikelyBranchWeightVal);
+  SmallVector<uint32_t, 16> Weights(n + 1, UnlikelyBranchWeightVal);
 
   uint64_t Index = (Case == *SI.case_default()) ? 0 : Case.getCaseIndex() + 1;
   Weights[Index] = LikelyBranchWeightVal;
@@ -248,7 +248,7 @@ static void handlePhiDef(CallInst *Expect) {
         return true;
       return false;
     };
-    uint64_t LikelyBranchWeightVal, UnlikelyBranchWeightVal;
+    uint32_t LikelyBranchWeightVal, UnlikelyBranchWeightVal;
     std::tie(LikelyBranchWeightVal, UnlikelyBranchWeightVal) = getBranchWeight(
         Expect->getCalledFunction()->getIntrinsicID(), Expect, 2);
 
@@ -318,7 +318,7 @@ template <class BrSelInst> static bool handleBrSelExpect(BrSelInst &BSI) {
   MDNode *Node;
   MDNode *ExpNode;
 
-  uint64_t LikelyBranchWeightVal, UnlikelyBranchWeightVal;
+  uint32_t LikelyBranchWeightVal, UnlikelyBranchWeightVal;
   std::tie(LikelyBranchWeightVal, UnlikelyBranchWeightVal) =
       getBranchWeight(Fn->getIntrinsicID(), CI, 2);
 

diff  --git a/llvm/lib/Transforms/Utils/CodeExtractor.cpp b/llvm/lib/Transforms/Utils/CodeExtractor.cpp
index 7d40c8772ef4..34a5499879ba 100644
--- a/llvm/lib/Transforms/Utils/CodeExtractor.cpp
+++ b/llvm/lib/Transforms/Utils/CodeExtractor.cpp
@@ -67,7 +67,6 @@
 #include <iterator>
 #include <map>
 #include <set>
-#include <stdint.h>
 #include <utility>
 #include <vector>
 
@@ -1364,7 +1363,7 @@ void CodeExtractor::calculateNewCallTerminatorWeights(
 
   // Update the branch weights for the exit block.
   Instruction *TI = CodeReplacer->getTerminator();
-  SmallVector<uint64_t, 8> BranchWeights(TI->getNumSuccessors(), 0);
+  SmallVector<unsigned, 8> BranchWeights(TI->getNumSuccessors(), 0);
 
   // Block Frequency distribution with dummy node.
   Distribution BranchDist;

diff  --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp
index c5700359e219..afbba4c83964 100644
--- a/llvm/lib/Transforms/Utils/Local.cpp
+++ b/llvm/lib/Transforms/Utils/Local.cpp
@@ -207,7 +207,7 @@ bool llvm::ConstantFoldTerminator(BasicBlock *BB, bool DeleteDeadConditions,
         // left, unless the metadata doesn't match the switch.
         if (NCases > 1 && MD && MD->getNumOperands() == 2 + NCases) {
           // Collect branch weights into a vector.
-          SmallVector<uint64_t, 8> Weights;
+          SmallVector<uint32_t, 8> Weights;
           for (unsigned MD_i = 1, MD_e = MD->getNumOperands(); MD_i < MD_e;
                ++MD_i) {
             auto *CI = mdconst::extract<ConstantInt>(MD->getOperand(MD_i));
@@ -2091,8 +2091,11 @@ CallInst *llvm::createCallMatchingInvoke(InvokeInst *II) {
   // If the invoke had profile metadata, try converting them for CallInst.
   uint64_t TotalWeight;
   if (NewCall->extractProfTotalWeight(TotalWeight)) {
+    // Set the total weight if it fits into i32, otherwise reset.
     MDBuilder MDB(NewCall->getContext());
-    auto NewWeights = MDB.createBranchWeights({TotalWeight});
+    auto NewWeights = uint32_t(TotalWeight) != TotalWeight
+                          ? nullptr
+                          : MDB.createBranchWeights({uint32_t(TotalWeight)});
     NewCall->setMetadata(LLVMContext::MD_prof, NewWeights);
   }
 

diff  --git a/llvm/lib/Transforms/Utils/MisExpect.cpp b/llvm/lib/Transforms/Utils/MisExpect.cpp
index 5b68f1ee358a..a16ca1fb8efa 100644
--- a/llvm/lib/Transforms/Utils/MisExpect.cpp
+++ b/llvm/lib/Transforms/Utils/MisExpect.cpp
@@ -93,7 +93,7 @@ void emitMisexpectDiagnostic(Instruction *I, LLVMContext &Ctx,
 namespace llvm {
 namespace misexpect {
 
-void verifyMisExpect(Instruction *I, const SmallVector<uint64_t, 4> &Weights,
+void verifyMisExpect(Instruction *I, const SmallVector<uint32_t, 4> &Weights,
                      LLVMContext &Ctx) {
   if (auto *MisExpectData = I->getMetadata(LLVMContext::MD_misexpect)) {
     auto *MisExpectDataName = dyn_cast<MDString>(MisExpectData->getOperand(0));
@@ -161,7 +161,7 @@ void checkFrontendInstrumentation(Instruction &I) {
     // Operand 0 is a string tag "branch_weights"
     if (MDString *Tag = cast<MDString>(MD->getOperand(0))) {
       if (Tag->getString().equals("branch_weights")) {
-        SmallVector<uint64_t, 4> RealWeights(NOps - 1);
+        SmallVector<uint32_t, 4> RealWeights(NOps - 1);
         for (unsigned i = 1; i < NOps; i++) {
           ConstantInt *Value =
               mdconst::dyn_extract<ConstantInt>(MD->getOperand(i));

diff  --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
index 56536bad0bb6..124a7c423e72 100644
--- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -238,7 +238,7 @@ class SimplifyCFGOpt {
                               const TargetTransformInfo &TTI);
   bool SimplifyTerminatorOnSelect(Instruction *OldTerm, Value *Cond,
                                   BasicBlock *TrueBB, BasicBlock *FalseBB,
-                                  uint64_t TrueWeight, uint64_t FalseWeight);
+                                  uint32_t TrueWeight, uint32_t FalseWeight);
   bool SimplifyBranchOnICmpChain(BranchInst *BI, IRBuilder<> &Builder,
                                  const DataLayout &DL);
   bool SimplifySwitchOnSelect(SwitchInst *SI, SelectInst *Select);
@@ -825,19 +825,19 @@ static bool ValuesOverlap(std::vector<ValueEqualityComparisonCase> &C1,
 
 // Set branch weights on SwitchInst. This sets the metadata if there is at
 // least one non-zero weight.
-static void setBranchWeights(SwitchInst *SI, ArrayRef<uint64_t> Weights) {
+static void setBranchWeights(SwitchInst *SI, ArrayRef<uint32_t> Weights) {
   // Check that there is at least one non-zero weight. Otherwise, pass
   // nullptr to setMetadata which will erase the existing metadata.
   MDNode *N = nullptr;
-  if (llvm::any_of(Weights, [](uint64_t W) { return W != 0; }))
+  if (llvm::any_of(Weights, [](uint32_t W) { return W != 0; }))
     N = MDBuilder(SI->getParent()->getContext()).createBranchWeights(Weights);
   SI->setMetadata(LLVMContext::MD_prof, N);
 }
 
 // Similar to the above, but for branch and select instructions that take
 // exactly 2 weights.
-static void setBranchWeights(Instruction *I, uint64_t TrueWeight,
-                             uint64_t FalseWeight) {
+static void setBranchWeights(Instruction *I, uint32_t TrueWeight,
+                             uint32_t FalseWeight) {
   assert(isa<BranchInst>(I) || isa<SelectInst>(I));
   // Check that there is at least one non-zero weight. Otherwise, pass
   // nullptr to setMetadata which will erase the existing metadata.
@@ -1025,6 +1025,16 @@ static void GetBranchWeights(Instruction *TI,
   }
 }
 
+/// Keep halving the weights until all can fit in uint32_t.
+static void FitWeights(MutableArrayRef<uint64_t> Weights) {
+  uint64_t Max = *std::max_element(Weights.begin(), Weights.end());
+  if (Max > UINT_MAX) {
+    unsigned Offset = 32 - countLeadingZeros(Max);
+    for (uint64_t &I : Weights)
+      I >>= Offset;
+  }
+}
+
 /// The specified terminator is a value equality comparison instruction
 /// (either a switch or a branch on "X == c").
 /// See if any of the predecessors of the terminator block are value comparisons
@@ -1210,7 +1220,10 @@ bool SimplifyCFGOpt::FoldValueComparisonIntoPredecessors(Instruction *TI,
         NewSI->addCase(V.Value, V.Dest);
 
       if (PredHasWeights || SuccHasWeights) {
-        SmallVector<uint64_t, 8> MDWeights(Weights.begin(), Weights.end());
+        // Halve the weights if any of them cannot fit in an uint32_t
+        FitWeights(Weights);
+
+        SmallVector<uint32_t, 8> MDWeights(Weights.begin(), Weights.end());
 
         setBranchWeights(NewSI, MDWeights);
       }
@@ -2941,7 +2954,10 @@ bool llvm::FoldBranchToCommonDest(BranchInst *BI, MemorySSAUpdater *MSSAU,
         PBI->setSuccessor(1, FalseDest);
       }
       if (NewWeights.size() == 2) {
-        SmallVector<uint64_t, 8> MDWeights(NewWeights.begin(),
+        // Halve the weights if any of them cannot fit in an uint32_t
+        FitWeights(NewWeights);
+
+        SmallVector<uint32_t, 8> MDWeights(NewWeights.begin(),
                                            NewWeights.end());
         setBranchWeights(PBI, MDWeights[0], MDWeights[1]);
       } else
@@ -3569,6 +3585,8 @@ static bool SimplifyCondBranchToCondBranch(BranchInst *PBI, BranchInst *BI,
     uint64_t NewWeights[2] = {PredCommon * (SuccCommon + SuccOther) +
                                   PredOther * SuccCommon,
                               PredOther * SuccOther};
+    // Halve the weights if any of them cannot fit in an uint32_t
+    FitWeights(NewWeights);
 
     setBranchWeights(PBI, NewWeights[0], NewWeights[1]);
   }
@@ -3604,6 +3622,8 @@ static bool SimplifyCondBranchToCondBranch(BranchInst *PBI, BranchInst *BI,
         uint64_t NewWeights[2] = {PredCommon * (SuccCommon + SuccOther),
                                   PredOther * SuccCommon};
 
+        FitWeights(NewWeights);
+
         setBranchWeights(NV, NewWeights[0], NewWeights[1]);
       }
     }
@@ -3625,8 +3645,8 @@ static bool SimplifyCondBranchToCondBranch(BranchInst *PBI, BranchInst *BI,
 bool SimplifyCFGOpt::SimplifyTerminatorOnSelect(Instruction *OldTerm,
                                                 Value *Cond, BasicBlock *TrueBB,
                                                 BasicBlock *FalseBB,
-                                                uint64_t TrueWeight,
-                                                uint64_t FalseWeight) {
+                                                uint32_t TrueWeight,
+                                                uint32_t FalseWeight) {
   // Remove any superfluous successor edges from the CFG.
   // First, figure out which successors to preserve.
   // If TrueBB and FalseBB are equal, only try to preserve one copy of that
@@ -3700,16 +3720,16 @@ bool SimplifyCFGOpt::SimplifySwitchOnSelect(SwitchInst *SI,
   BasicBlock *FalseBB = SI->findCaseValue(FalseVal)->getCaseSuccessor();
 
   // Get weight for TrueBB and FalseBB.
-  uint64_t TrueWeight = 0, FalseWeight = 0;
+  uint32_t TrueWeight = 0, FalseWeight = 0;
   SmallVector<uint64_t, 8> Weights;
   bool HasWeights = HasBranchWeights(SI);
   if (HasWeights) {
     GetBranchWeights(SI, Weights);
     if (Weights.size() == 1 + SI->getNumCases()) {
       TrueWeight =
-          (uint64_t)Weights[SI->findCaseValue(TrueVal)->getSuccessorIndex()];
+          (uint32_t)Weights[SI->findCaseValue(TrueVal)->getSuccessorIndex()];
       FalseWeight =
-          (uint64_t)Weights[SI->findCaseValue(FalseVal)->getSuccessorIndex()];
+          (uint32_t)Weights[SI->findCaseValue(FalseVal)->getSuccessorIndex()];
     }
   }
 

diff  --git a/llvm/test/Analysis/BranchProbabilityInfo/basic.ll b/llvm/test/Analysis/BranchProbabilityInfo/basic.ll
index a85d7b370b17..901dc9fce645 100644
--- a/llvm/test/Analysis/BranchProbabilityInfo/basic.ll
+++ b/llvm/test/Analysis/BranchProbabilityInfo/basic.ll
@@ -45,7 +45,7 @@ exit:
   ret i32 %result
 }
 
-!0 = !{!"branch_weights", i64 64, i64 4}
+!0 = !{!"branch_weights", i32 64, i32 4}
 
 define i32 @test3(i32 %i, i32 %a, i32 %b, i32 %c, i32 %d, i32 %e) {
 ; CHECK: Printing analysis {{.*}} for function 'test3'
@@ -89,7 +89,7 @@ exit:
   ret i32 %result
 }
 
-!1 = !{!"branch_weights", i64 4, i64 4, i64 64, i64 4, i64 4}
+!1 = !{!"branch_weights", i32 4, i32 4, i32 64, i32 4, i32 4}
 
 define i32 @test4(i32 %x) nounwind uwtable readnone ssp {
 ; CHECK: Printing analysis {{.*}} for function 'test4'
@@ -116,7 +116,7 @@ return:
   ret i32 %retval.0
 }
 
-!2 = !{!"branch_weights", i64 7, i64 6, i64 4, i64 4, i64 64}
+!2 = !{!"branch_weights", i32 7, i32 6, i32 4, i32 4, i32 64}
 
 declare void @coldfunc() cold
 
@@ -196,7 +196,7 @@ exit:
   ret i32 %result
 }
 
-!3 = !{!"branch_weights", i64 100, i64 1}
+!3 = !{!"branch_weights", i32 100, i32 1}
 
 define i32 @test_cold_call_sites(i32* %a) {
 ; Test that edges to blocks post-dominated by cold call sites
@@ -328,13 +328,13 @@ invoke.to0:
 ; CHECK: edge invoke.to0 -> invoke.to1 probability is 0x7ffff800 / 0x80000000 = 100.00% [HOT edge]
 ; CHECK: edge invoke.to0 -> lpad probability is 0x00000800 / 0x80000000 = 0.00%
   invoke i32 @InvokeCall() to label %invoke.to1 unwind label %lpad,
-     !prof !{!"branch_weights", i64 444}
+     !prof !{!"branch_weights", i32 444}
 
 invoke.to1:
 ; CHECK: invoke.to1 -> invoke.to2 probability is 0x55555555 / 0x80000000 = 66.67%
 ; CHECK: invoke.to1 -> lpad probability is 0x2aaaaaab / 0x80000000 = 33.33%
   invoke i32 @InvokeCall() to label %invoke.to2 unwind label %lpad,
-     !prof !{!"branch_weights", i64 222, i64 111}
+     !prof !{!"branch_weights", i32 222, i32 111}
   ret void
 
 invoke.to2:
@@ -435,7 +435,7 @@ exit:
   ret i32 %b
 }
 
-!4 = !{!"branch_weights", i64 0, i64 1}
+!4 = !{!"branch_weights", i32 0, i32 1}
 
 define i32 @test_unreachable_with_prof_equal(i32 %a, i32 %b) {
 ; CHECK: Printing analysis {{.*}} for function 'test_unreachable_with_prof_equal'
@@ -453,7 +453,7 @@ exit:
   ret i32 %b
 }
 
-!5 = !{!"branch_weights", i64 2147483647, i64 1}
+!5 = !{!"branch_weights", i32 2147483647, i32 1}
 
 define i32 @test_unreachable_with_prof_zero(i32 %a, i32 %b) {
 ; CHECK: Printing analysis {{.*}} for function 'test_unreachable_with_prof_zero'
@@ -471,7 +471,7 @@ exit:
   ret i32 %b
 }
 
-!6 = !{!"branch_weights", i64 0, i64 0}
+!6 = !{!"branch_weights", i32 0, i32 0}
 
 define i32 @test_unreachable_with_prof_less(i32 %a, i32 %b) {
 ; CHECK: Printing analysis {{.*}} for function 'test_unreachable_with_prof_less'
@@ -489,7 +489,7 @@ exit:
   ret i32 %b
 }
 
-!7 = !{!"branch_weights", i64 1, i64 0}
+!7 = !{!"branch_weights", i32 1, i32 0}
 
 define i32 @test_unreachable_with_switch_prof1(i32 %i, i32 %a, i32 %b, i32 %c, i32 %d, i32 %e) {
 ; CHECK: Printing analysis {{.*}} for function 'test_unreachable_with_switch_prof1'
@@ -532,7 +532,7 @@ exit:
   ret i32 %result
 }
 
-!8 = !{!"branch_weights", i64 4, i64 4, i64 64, i64 4, i64 4}
+!8 = !{!"branch_weights", i32 4, i32 4, i32 64, i32 4, i32 4}
 
 define i32 @test_unreachable_with_switch_prof2(i32 %i, i32 %a, i32 %b, i32 %c, i32 %d, i32 %e) {
 ; CHECK: Printing analysis {{.*}} for function 'test_unreachable_with_switch_prof2'
@@ -574,7 +574,7 @@ exit:
   ret i32 %result
 }
 
-!9 = !{!"branch_weights", i64 4, i64 4, i64 64, i64 4, i64 4}
+!9 = !{!"branch_weights", i32 4, i32 4, i32 64, i32 4, i32 4}
 
 define i32 @test_unreachable_with_switch_prof3(i32 %i, i32 %a, i32 %b, i32 %c, i32 %d, i32 %e) {
 ; CHECK: Printing analysis {{.*}} for function 'test_unreachable_with_switch_prof3'
@@ -615,7 +615,7 @@ exit:
   ret i32 %result
 }
 
-!10 = !{!"branch_weights", i64 0, i64 4, i64 64, i64 4, i64 4}
+!10 = !{!"branch_weights", i32 0, i32 4, i32 64, i32 4, i32 4}
 
 define i32 @test_unreachable_with_switch_prof4(i32 %i, i32 %a, i32 %b, i32 %c, i32 %d, i32 %e) {
 ; CHECK: Printing analysis {{.*}} for function 'test_unreachable_with_switch_prof4'
@@ -647,4 +647,4 @@ case_e:
 
 }
 
-!11 = !{!"branch_weights", i64 0, i64 4, i64 64, i64 4, i64 4}
+!11 = !{!"branch_weights", i32 0, i32 4, i32 64, i32 4, i32 4}

diff  --git a/llvm/test/Analysis/BranchProbabilityInfo/basic_i32.ll b/llvm/test/Analysis/BranchProbabilityInfo/basic_i32.ll
deleted file mode 100644
index 901dc9fce645..000000000000
--- a/llvm/test/Analysis/BranchProbabilityInfo/basic_i32.ll
+++ /dev/null
@@ -1,650 +0,0 @@
-; RUN: opt < %s -analyze -branch-prob -enable-new-pm=0 | FileCheck %s
-; RUN: opt < %s -analyze -lazy-branch-prob -enable-new-pm=0 | FileCheck %s
-; RUN: opt < %s -passes='print<branch-prob>' -disable-output 2>&1 | FileCheck %s
-
-define i32 @test1(i32 %i, i32* %a) {
-; CHECK: Printing analysis {{.*}} for function 'test1'
-entry:
-  br label %body
-; CHECK: edge entry -> body probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
-
-body:
-  %iv = phi i32 [ 0, %entry ], [ %next, %body ]
-  %base = phi i32 [ 0, %entry ], [ %sum, %body ]
-  %arrayidx = getelementptr inbounds i32, i32* %a, i32 %iv
-  %0 = load i32, i32* %arrayidx
-  %sum = add nsw i32 %0, %base
-  %next = add i32 %iv, 1
-  %exitcond = icmp eq i32 %next, %i
-  br i1 %exitcond, label %exit, label %body
-; CHECK: edge body -> exit probability is 0x04000000 / 0x80000000 = 3.12%
-; CHECK: edge body -> body probability is 0x7c000000 / 0x80000000 = 96.88% [HOT edge]
-
-exit:
-  ret i32 %sum
-}
-
-define i32 @test2(i32 %i, i32 %a, i32 %b) {
-; CHECK: Printing analysis {{.*}} for function 'test2'
-entry:
-  %cond = icmp ult i32 %i, 42
-  br i1 %cond, label %then, label %else, !prof !0
-; CHECK: edge entry -> then probability is 0x78787878 / 0x80000000 = 94.12% [HOT edge]
-; CHECK: edge entry -> else probability is 0x07878788 / 0x80000000 = 5.88%
-
-then:
-  br label %exit
-; CHECK: edge then -> exit probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
-
-else:
-  br label %exit
-; CHECK: edge else -> exit probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
-
-exit:
-  %result = phi i32 [ %a, %then ], [ %b, %else ]
-  ret i32 %result
-}
-
-!0 = !{!"branch_weights", i32 64, i32 4}
-
-define i32 @test3(i32 %i, i32 %a, i32 %b, i32 %c, i32 %d, i32 %e) {
-; CHECK: Printing analysis {{.*}} for function 'test3'
-entry:
-  switch i32 %i, label %case_a [ i32 1, label %case_b
-                                 i32 2, label %case_c
-                                 i32 3, label %case_d
-                                 i32 4, label %case_e ], !prof !1
-; CHECK: edge entry -> case_a probability is 0x06666666 / 0x80000000 = 5.00%
-; CHECK: edge entry -> case_b probability is 0x06666666 / 0x80000000 = 5.00%
-; CHECK: edge entry -> case_c probability is 0x66666666 / 0x80000000 = 80.00%
-; CHECK: edge entry -> case_d probability is 0x06666666 / 0x80000000 = 5.00%
-; CHECK: edge entry -> case_e probability is 0x06666666 / 0x80000000 = 5.00%
-
-case_a:
-  br label %exit
-; CHECK: edge case_a -> exit probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
-
-case_b:
-  br label %exit
-; CHECK: edge case_b -> exit probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
-
-case_c:
-  br label %exit
-; CHECK: edge case_c -> exit probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
-
-case_d:
-  br label %exit
-; CHECK: edge case_d -> exit probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
-
-case_e:
-  br label %exit
-; CHECK: edge case_e -> exit probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
-
-exit:
-  %result = phi i32 [ %a, %case_a ],
-                    [ %b, %case_b ],
-                    [ %c, %case_c ],
-                    [ %d, %case_d ],
-                    [ %e, %case_e ]
-  ret i32 %result
-}
-
-!1 = !{!"branch_weights", i32 4, i32 4, i32 64, i32 4, i32 4}
-
-define i32 @test4(i32 %x) nounwind uwtable readnone ssp {
-; CHECK: Printing analysis {{.*}} for function 'test4'
-entry:
-  %conv = sext i32 %x to i64
-  switch i64 %conv, label %return [
-    i64 0, label %sw.bb
-    i64 1, label %sw.bb
-    i64 2, label %sw.bb
-    i64 5, label %sw.bb1
-  ], !prof !2
-; CHECK: edge entry -> return probability is 0x0a8a8a8b / 0x80000000 = 8.24%
-; CHECK: edge entry -> sw.bb probability is 0x15151515 / 0x80000000 = 16.47%
-; CHECK: edge entry -> sw.bb1 probability is 0x60606060 / 0x80000000 = 75.29%
-
-sw.bb:
-  br label %return
-
-sw.bb1:
-  br label %return
-
-return:
-  %retval.0 = phi i32 [ 5, %sw.bb1 ], [ 1, %sw.bb ], [ 0, %entry ]
-  ret i32 %retval.0
-}
-
-!2 = !{!"branch_weights", i32 7, i32 6, i32 4, i32 4, i32 64}
-
-declare void @coldfunc() cold
-
-define i32 @test5(i32 %a, i32 %b, i1 %flag) {
-; CHECK: Printing analysis {{.*}} for function 'test5'
-entry:
-  br i1 %flag, label %then, label %else
-; CHECK: edge entry -> then probability is 0x07878788 / 0x80000000 = 5.88%
-; CHECK: edge entry -> else probability is 0x78787878 / 0x80000000 = 94.12% [HOT edge]
-
-then:
-  call void @coldfunc()
-  br label %exit
-; CHECK: edge then -> exit probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
-
-else:
-  br label %exit
-; CHECK: edge else -> exit probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
-
-exit:
-  %result = phi i32 [ %a, %then ], [ %b, %else ]
-  ret i32 %result
-}
-
-define i32 @test_cold_loop(i32 %a, i32 %b) {
-entry:
-  %cond1 = icmp eq i32 %a, 42
-  br i1 %cond1, label %header, label %exit
-
-header:
-  br label %body
-
-body:
-  %cond2 = icmp eq i32 %b, 42
-  br i1 %cond2, label %header, label %exit
-; CHECK: edge body -> header probability is 0x40000000 / 0x80000000 = 50.00%
-
-exit:
-  call void @coldfunc()
-  ret i32 %b
-}
-
-declare i32 @regular_function(i32 %i)
-
-define i32 @test_cold_call_sites_with_prof(i32 %a, i32 %b, i1 %flag, i1 %flag2) {
-; CHECK: Printing analysis {{.*}} for function 'test_cold_call_sites_with_prof'
-entry:
-  br i1 %flag, label %then, label %else
-; CHECK: edge entry -> then probability is 0x07878788 / 0x80000000 = 5.88%
-; CHECK: edge entry -> else probability is 0x78787878 / 0x80000000 = 94.12% [HOT edge]
-
-then:
-  br i1 %flag2, label %then2, label %else2, !prof !3
-; CHECK: edge then -> then2 probability is 0x7ebb907a / 0x80000000 = 99.01% [HOT edge]
-; CHECK: edge then -> else2 probability is 0x01446f86 / 0x80000000 = 0.99%
-
-then2:
-  br label %join
-; CHECK: edge then2 -> join probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
-
-else2:
-  br label %join
-; CHECK: edge else2 -> join probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
-
-join:
-  %joinresult = phi i32 [ %a, %then2 ], [ %b, %else2 ]
-  call void @coldfunc()
-  br label %exit
-; CHECK: edge join -> exit probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
-
-else:
-  br label %exit
-; CHECK: edge else -> exit probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
-
-exit:
-  %result = phi i32 [ %joinresult, %join ], [ %b, %else ]
-  ret i32 %result
-}
-
-!3 = !{!"branch_weights", i32 100, i32 1}
-
-define i32 @test_cold_call_sites(i32* %a) {
-; Test that edges to blocks post-dominated by cold call sites
-; are marked as not expected to be taken.
-; TODO(dnovillo) The calls to regular_function should not be merged, but
-; they are currently being merged. Convert this into a code generation test
-; after that is fixed.
-
-; CHECK: Printing analysis {{.*}} for function 'test_cold_call_sites'
-; CHECK: edge entry -> then probability is 0x07878788 / 0x80000000 = 5.88%
-; CHECK: edge entry -> else probability is 0x78787878 / 0x80000000 = 94.12% [HOT edge]
-
-entry:
-  %gep1 = getelementptr i32, i32* %a, i32 1
-  %val1 = load i32, i32* %gep1
-  %cond1 = icmp ugt i32 %val1, 1
-  br i1 %cond1, label %then, label %else
-
-then:
-  ; This function is not declared cold, but this call site is.
-  %val4 = call i32 @regular_function(i32 %val1) cold
-  br label %exit
-
-else:
-  %gep2 = getelementptr i32, i32* %a, i32 2
-  %val2 = load i32, i32* %gep2
-  %val3 = call i32 @regular_function(i32 %val2)
-  br label %exit
-
-exit:
-  %ret = phi i32 [ %val4, %then ], [ %val3, %else ]
-  ret i32 %ret
-}
-
-; CHECK-LABEL: test_invoke_code_callsite1
-define i32 @test_invoke_code_callsite1(i1 %c) personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) {
-entry:
-  br i1 %c, label %if.then, label %if.end
-; Edge "entry->if.end" should have higher probability based on the cold call
-; heuristic which treat %if.then as a cold block because the normal destination
-; of the invoke instruction in %if.then is post-dominated by ColdFunc().
-; CHECK:  edge entry -> if.then probability is 0x07878788 / 0x80000000 = 5.88%
-; CHECK:  edge entry -> if.end probability is 0x78787878 / 0x80000000 = 94.12% [HOT edge]
-
-if.then:
-  invoke i32 @InvokeCall()
-          to label %invoke.cont unwind label %lpad
-; CHECK:  edge if.then -> invoke.cont probability is 0x7ffff800 / 0x80000000 = 100.00% [HOT edge]
-; CHECK:  edge if.then -> lpad probability is 0x00000800 / 0x80000000 = 0.00%
-
-invoke.cont:
-  call void @ColdFunc() #0
-  br label %if.end
-
-lpad:
-  %ll = landingpad { i8*, i32 }
-          cleanup
-  br label %if.end
-
-if.end:
-  ret i32 0
-}
-
-; CHECK-LABEL: test_invoke_code_callsite2
-define i32 @test_invoke_code_callsite2(i1 %c) personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) {
-entry:
-  br i1 %c, label %if.then, label %if.end
-
-; CHECK:  edge entry -> if.then probability is 0x40000000 / 0x80000000 = 50.00%
-; CHECK:  edge entry -> if.end probability is 0x40000000 / 0x80000000 = 50.00%
-
-if.then:
-  invoke i32 @InvokeCall()
-          to label %invoke.cont unwind label %lpad
-; The cold call heuristic should not kick in when the cold callsite is in EH path.
-; CHECK:  edge if.then -> invoke.cont probability is 0x7ffff800 / 0x80000000 = 100.00% [HOT edge]
-; CHECK:  edge if.then -> lpad probability is 0x00000800 / 0x80000000 = 0.00%
-
-invoke.cont:
-  br label %if.end
-
-lpad:
-  %ll = landingpad { i8*, i32 }
-          cleanup
-  call void @ColdFunc() #0
-  br label %if.end
-
-if.end:
-  ret i32 0
-}
-
-; CHECK-LABEL: test_invoke_code_callsite3
-define i32 @test_invoke_code_callsite3(i1 %c) personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) {
-entry:
-  br i1 %c, label %if.then, label %if.end
-; CHECK: edge entry -> if.then probability is 0x07878788 / 0x80000000 = 5.88%
-; CHECK: edge entry -> if.end probability is 0x78787878 / 0x80000000 = 94.12% [HOT edge]
-
-if.then:
-  invoke i32 @InvokeCall()
-          to label %invoke.cont unwind label %lpad
-; Regardless of cold calls, edge weights from a invoke instruction should be
-; determined by the invoke heuristic.
-; CHECK: edge if.then -> invoke.cont probability is 0x7ffff800 / 0x80000000 = 100.00% [HOT edge]
-; CHECK: edge if.then -> lpad probability is 0x00000800 / 0x80000000 = 0.00%
-
-invoke.cont:
-  call void @ColdFunc() #0
-  br label %if.end
-
-lpad:
-  %ll = landingpad { i8*, i32 }
-          cleanup
-  call void @ColdFunc() #0
-  br label %if.end
-
-if.end:
-  ret i32 0
-}
-
-; CHECK-LABEL: test_invoke_code_profiled
-define void @test_invoke_code_profiled(i1 %c) personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) {
-entry:
-; CHECK: edge entry -> invoke.to0 probability is 0x7ffff800 / 0x80000000 = 100.00% [HOT edge]
-; CHECK: edge entry -> lpad probability is 0x00000800 / 0x80000000 = 0.00%
-  invoke i32 @InvokeCall() to label %invoke.to0 unwind label %lpad
-
-invoke.to0:
-; CHECK: edge invoke.to0 -> invoke.to1 probability is 0x7ffff800 / 0x80000000 = 100.00% [HOT edge]
-; CHECK: edge invoke.to0 -> lpad probability is 0x00000800 / 0x80000000 = 0.00%
-  invoke i32 @InvokeCall() to label %invoke.to1 unwind label %lpad,
-     !prof !{!"branch_weights", i32 444}
-
-invoke.to1:
-; CHECK: invoke.to1 -> invoke.to2 probability is 0x55555555 / 0x80000000 = 66.67%
-; CHECK: invoke.to1 -> lpad probability is 0x2aaaaaab / 0x80000000 = 33.33%
-  invoke i32 @InvokeCall() to label %invoke.to2 unwind label %lpad,
-     !prof !{!"branch_weights", i32 222, i32 111}
-  ret void
-
-invoke.to2:
-  ret void
-
-lpad:
-  %ll = landingpad { i8*, i32 }
-          cleanup
-  ret void
-}
-
-declare i32 @__gxx_personality_v0(...)
-declare void  @ColdFunc()
-declare i32 @InvokeCall()
-
-attributes #0 = { cold }
-
-
-define i32 @zero1(i32 %i, i32 %a, i32 %b) {
-; CHECK: Printing analysis {{.*}} for function 'zero1'
-entry:
-  %cond = icmp eq i32 %i, 0
-  br i1 %cond, label %then, label %else
-; CHECK: edge entry -> then probability is 0x30000000 / 0x80000000 = 37.50%
-; CHECK: edge entry -> else probability is 0x50000000 / 0x80000000 = 62.50%
-
-then:
-  br label %exit
-
-else:
-  br label %exit
-
-exit:
-  %result = phi i32 [ %a, %then ], [ %b, %else ]
-  ret i32 %result
-}
-
-define i32 @zero2(i32 %i, i32 %a, i32 %b) {
-; CHECK: Printing analysis {{.*}} for function 'zero2'
-entry:
-  %cond = icmp ne i32 %i, -1
-  br i1 %cond, label %then, label %else
-; CHECK: edge entry -> then probability is 0x50000000 / 0x80000000 = 62.50%
-; CHECK: edge entry -> else probability is 0x30000000 / 0x80000000 = 37.50%
-
-then:
-  br label %exit
-
-else:
-  br label %exit
-
-exit:
-  %result = phi i32 [ %a, %then ], [ %b, %else ]
-  ret i32 %result
-}
-
-define i32 @zero3(i32 %i, i32 %a, i32 %b) {
-; CHECK: Printing analysis {{.*}} for function 'zero3'
-entry:
-; AND'ing with a single bit bitmask essentially leads to a bool comparison,
-; meaning we don't have probability information.
-  %and = and i32 %i, 2
-  %tobool = icmp eq i32 %and, 0
-  br i1 %tobool, label %then, label %else
-; CHECK: edge entry -> then probability is 0x40000000 / 0x80000000 = 50.00%
-; CHECK: edge entry -> else probability is 0x40000000 / 0x80000000 = 50.00%
-
-then:
-; AND'ing with other bitmask might be something else, so we still assume the
-; usual probabilities.
-  %and2 = and i32 %i, 5
-  %tobool2 = icmp eq i32 %and2, 0
-  br i1 %tobool2, label %else, label %exit
-; CHECK: edge then -> else probability is 0x30000000 / 0x80000000 = 37.50%
-; CHECK: edge then -> exit probability is 0x50000000 / 0x80000000 = 62.50%
-
-else:
-  br label %exit
-
-exit:
-  %result = phi i32 [ %a, %then ], [ %b, %else ]
-  ret i32 %result
-}
-
-define i32 @test_unreachable_with_prof_greater(i32 %a, i32 %b) {
-; CHECK: Printing analysis {{.*}} for function 'test_unreachable_with_prof_greater'
-entry:
-  %cond = icmp eq i32 %a, 42
-  br i1 %cond, label %exit, label %unr, !prof !4
-
-; CHECK:  edge entry -> exit probability is 0x7fffffff / 0x80000000 = 100.00% [HOT edge]
-; CHECK:  edge entry -> unr probability is 0x00000001 / 0x80000000 = 0.00%
-
-unr:
-  unreachable
-
-exit:
-  ret i32 %b
-}
-
-!4 = !{!"branch_weights", i32 0, i32 1}
-
-define i32 @test_unreachable_with_prof_equal(i32 %a, i32 %b) {
-; CHECK: Printing analysis {{.*}} for function 'test_unreachable_with_prof_equal'
-entry:
-  %cond = icmp eq i32 %a, 42
-  br i1 %cond, label %exit, label %unr, !prof !5
-
-; CHECK:  edge entry -> exit probability is 0x7fffffff / 0x80000000 = 100.00% [HOT edge]
-; CHECK:  edge entry -> unr probability is 0x00000001 / 0x80000000 = 0.00%
-
-unr:
-  unreachable
-
-exit:
-  ret i32 %b
-}
-
-!5 = !{!"branch_weights", i32 2147483647, i32 1}
-
-define i32 @test_unreachable_with_prof_zero(i32 %a, i32 %b) {
-; CHECK: Printing analysis {{.*}} for function 'test_unreachable_with_prof_zero'
-entry:
-  %cond = icmp eq i32 %a, 42
-  br i1 %cond, label %exit, label %unr, !prof !6
-
-; CHECK:  edge entry -> exit probability is 0x7fffffff / 0x80000000 = 100.00% [HOT edge]
-; CHECK:  edge entry -> unr probability is 0x00000001 / 0x80000000 = 0.00%
-
-unr:
-  unreachable
-
-exit:
-  ret i32 %b
-}
-
-!6 = !{!"branch_weights", i32 0, i32 0}
-
-define i32 @test_unreachable_with_prof_less(i32 %a, i32 %b) {
-; CHECK: Printing analysis {{.*}} for function 'test_unreachable_with_prof_less'
-entry:
-  %cond = icmp eq i32 %a, 42
-  br i1 %cond, label %exit, label %unr, !prof !7
-
-; CHECK:  edge entry -> exit probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
-; CHECK:  edge entry -> unr probability is 0x00000000 / 0x80000000 = 0.00%
-
-unr:
-  unreachable
-
-exit:
-  ret i32 %b
-}
-
-!7 = !{!"branch_weights", i32 1, i32 0}
-
-define i32 @test_unreachable_with_switch_prof1(i32 %i, i32 %a, i32 %b, i32 %c, i32 %d, i32 %e) {
-; CHECK: Printing analysis {{.*}} for function 'test_unreachable_with_switch_prof1'
-entry:
-  switch i32 %i, label %case_a [ i32 1, label %case_b
-                                 i32 2, label %case_c
-                                 i32 3, label %case_d
-                                 i32 4, label %case_e ], !prof !8
-; Reachable probabilities keep their relation: 4/64/4/4 = 5.26% / 84.21% / 5.26% / 5.26%.
-; CHECK: edge entry -> case_a probability is 0x00000001 / 0x80000000 = 0.00%
-; CHECK: edge entry -> case_b probability is 0x06bca1af / 0x80000000 = 5.26%
-; CHECK: edge entry -> case_c probability is 0x6bca1af3 / 0x80000000 = 84.21% [HOT edge]
-; CHECK: edge entry -> case_d probability is 0x06bca1af / 0x80000000 = 5.26%
-; CHECK: edge entry -> case_e probability is 0x06bca1af / 0x80000000 = 5.26%
-
-case_a:
-  unreachable
-
-case_b:
-  br label %exit
-; CHECK: edge case_b -> exit probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
-
-case_c:
-  br label %exit
-; CHECK: edge case_c -> exit probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
-
-case_d:
-  br label %exit
-; CHECK: edge case_d -> exit probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
-
-case_e:
-  br label %exit
-; CHECK: edge case_e -> exit probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
-
-exit:
-  %result = phi i32 [ %b, %case_b ],
-                    [ %c, %case_c ],
-                    [ %d, %case_d ],
-                    [ %e, %case_e ]
-  ret i32 %result
-}
-
-!8 = !{!"branch_weights", i32 4, i32 4, i32 64, i32 4, i32 4}
-
-define i32 @test_unreachable_with_switch_prof2(i32 %i, i32 %a, i32 %b, i32 %c, i32 %d, i32 %e) {
-; CHECK: Printing analysis {{.*}} for function 'test_unreachable_with_switch_prof2'
-entry:
-  switch i32 %i, label %case_a [ i32 1, label %case_b
-                                 i32 2, label %case_c
-                                 i32 3, label %case_d
-                                 i32 4, label %case_e ], !prof !9
-; Reachable probabilities keep their relation: 64/4/4 = 88.89% / 5.56% / 5.56%.
-; CHECK: edge entry -> case_a probability is 0x00000001 / 0x80000000 = 0.00%
-; CHECK: edge entry -> case_b probability is 0x00000001 / 0x80000000 = 0.00%
-; CHECK: edge entry -> case_c probability is 0x71c71c71 / 0x80000000 = 88.89% [HOT edge]
-; CHECK: edge entry -> case_d probability is 0x071c71c7 / 0x80000000 = 5.56%
-; CHECK: edge entry -> case_e probability is 0x071c71c7 / 0x80000000 = 5.56%
-
-
-case_a:
-  unreachable
-
-case_b:
-  unreachable
-
-case_c:
-  br label %exit
-; CHECK: edge case_c -> exit probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
-
-case_d:
-  br label %exit
-; CHECK: edge case_d -> exit probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
-
-case_e:
-  br label %exit
-; CHECK: edge case_e -> exit probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
-
-exit:
-  %result = phi i32 [ %c, %case_c ],
-                    [ %d, %case_d ],
-                    [ %e, %case_e ]
-  ret i32 %result
-}
-
-!9 = !{!"branch_weights", i32 4, i32 4, i32 64, i32 4, i32 4}
-
-define i32 @test_unreachable_with_switch_prof3(i32 %i, i32 %a, i32 %b, i32 %c, i32 %d, i32 %e) {
-; CHECK: Printing analysis {{.*}} for function 'test_unreachable_with_switch_prof3'
-entry:
-  switch i32 %i, label %case_a [ i32 1, label %case_b
-                                 i32 2, label %case_c
-                                 i32 3, label %case_d
-                                 i32 4, label %case_e ], !prof !10
-; Reachable probabilities keep their relation: 64/4/4 = 88.89% / 5.56% / 5.56%.
-; CHECK: edge entry -> case_a probability is 0x00000000 / 0x80000000 = 0.00%
-; CHECK: edge entry -> case_b probability is 0x00000001 / 0x80000000 = 0.00%
-; CHECK: edge entry -> case_c probability is 0x71c71c71 / 0x80000000 = 88.89% [HOT edge]
-; CHECK: edge entry -> case_d probability is 0x071c71c7 / 0x80000000 = 5.56%
-; CHECK: edge entry -> case_e probability is 0x071c71c7 / 0x80000000 = 5.56%
-
-case_a:
-  unreachable
-
-case_b:
-  unreachable
-
-case_c:
-  br label %exit
-; CHECK: edge case_c -> exit probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
-
-case_d:
-  br label %exit
-; CHECK: edge case_d -> exit probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
-
-case_e:
-  br label %exit
-; CHECK: edge case_e -> exit probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
-
-exit:
-  %result = phi i32 [ %c, %case_c ],
-                    [ %d, %case_d ],
-                    [ %e, %case_e ]
-  ret i32 %result
-}
-
-!10 = !{!"branch_weights", i32 0, i32 4, i32 64, i32 4, i32 4}
-
-define i32 @test_unreachable_with_switch_prof4(i32 %i, i32 %a, i32 %b, i32 %c, i32 %d, i32 %e) {
-; CHECK: Printing analysis {{.*}} for function 'test_unreachable_with_switch_prof4'
-entry:
-  switch i32 %i, label %case_a [ i32 1, label %case_b
-                                 i32 2, label %case_c
-                                 i32 3, label %case_d
-                                 i32 4, label %case_e ], !prof !11
-; CHECK: edge entry -> case_a probability is 0x1999999a / 0x80000000 = 20.00%
-; CHECK: edge entry -> case_b probability is 0x1999999a / 0x80000000 = 20.00%
-; CHECK: edge entry -> case_c probability is 0x1999999a / 0x80000000 = 20.00%
-; CHECK: edge entry -> case_d probability is 0x1999999a / 0x80000000 = 20.00%
-; CHECK: edge entry -> case_e probability is 0x1999999a / 0x80000000 = 20.00%
-
-case_a:
-  unreachable
-
-case_b:
-  unreachable
-
-case_c:
-  unreachable
-
-case_d:
-  unreachable
-
-case_e:
-  unreachable
-
-}
-
-!11 = !{!"branch_weights", i32 0, i32 4, i32 64, i32 4, i32 4}

diff  --git a/llvm/test/Analysis/BranchProbabilityInfo/branch-large-weights.ll b/llvm/test/Analysis/BranchProbabilityInfo/branch-large-weights.ll
deleted file mode 100644
index 705d7f1e9390..000000000000
--- a/llvm/test/Analysis/BranchProbabilityInfo/branch-large-weights.ll
+++ /dev/null
@@ -1,48 +0,0 @@
-; RUN: opt < %s -passes='print<branch-prob>' -disable-output 2>&1 | FileCheck %s
-
-; CHECK: Printing analysis {{.*}} for function 'branch'
-; CHECK: edge  -> return probability is 0x40000000 / 0x80000000 = 50.00%
-; CHECK: edge  -> return2 probability is 0x40000000 / 0x80000000 = 50.00%
-define void @branch(i1 %x) {
-  br i1 %x, label %return, label %return2, !prof !1
-return:
-  ret void
-return2:
-  ret void
-}
-
-!1 = !{!"branch_weights",
-       i64 -4611686018427387904,
-       i64 -4611686018427387904}
-
-define void @switch(i32 %x) {
-  switch i32 %x, label %return [
-    i32 0, label %return2
-    i32 3, label %return2
-    i32 6, label %return2
-    i32 1, label %return2
-    i32 4, label %return2
-    i32 7, label %return2
-    i32 2, label %return2
-    i32 5, label %return2
-    i32 8, label %return2
-    i32 9, label %return2
-  ], !prof !2
-return:
-  ret void
-return2:
-  ret void
-}
-
-!2 = !{!"branch_weights",
-       i64 -4611686018427387904,
-       i64 -4611686018427387904,
-       i64 -4611686018427387904,
-       i64 -4611686018427387904,
-       i64 -4611686018427387904,
-       i64 -4611686018427387904,
-       i64 -4611686018427387904,
-       i64 -4611686018427387904,
-       i64 -4611686018427387904,
-       i64 -4611686018427387904,
-       i64 -4611686018427387904}

diff  --git a/llvm/test/Instrumentation/AddressSanitizer/basic.ll b/llvm/test/Instrumentation/AddressSanitizer/basic.ll
index cda84433754e..32462bb730c6 100644
--- a/llvm/test/Instrumentation/AddressSanitizer/basic.ll
+++ b/llvm/test/Instrumentation/AddressSanitizer/basic.ll
@@ -229,4 +229,4 @@ define void @test_swifterror_3() sanitize_address {
 ; CHECK: call void @__asan_init()
 
 ; PROF
-; CHECK: ![[PROF]] = !{!"branch_weights", i64 1, i64 100000}
+; CHECK: ![[PROF]] = !{!"branch_weights", i32 1, i32 100000}

diff  --git a/llvm/test/Transforms/CodeExtractor/MultipleExitBranchProb.ll b/llvm/test/Transforms/CodeExtractor/MultipleExitBranchProb.ll
index 18f73a72212d..8e362080dc48 100644
--- a/llvm/test/Transforms/CodeExtractor/MultipleExitBranchProb.ll
+++ b/llvm/test/Transforms/CodeExtractor/MultipleExitBranchProb.ll
@@ -28,7 +28,7 @@ ret i32 %val
 !llvm.module.flags = !{!0}
 !0 = !{i32 1, !"MaxFunctionCount", i32 10000}
 !1 = !{!"function_entry_count", i64 10000}
-!2 = !{!"branch_weights", i64 5, i64 5}
-!3 = !{!"branch_weights", i64 4, i64 1}
+!2 = !{!"branch_weights", i32 5, i32 5}
+!3 = !{!"branch_weights", i32 4, i32 1}
 
-; CHECK: [[COUNT1]] = !{!"branch_weights", i64 31, i64 8}
+; CHECK: [[COUNT1]] = !{!"branch_weights", i32 31, i32 8}

diff  --git a/llvm/test/Transforms/CorrelatedValuePropagation/profmd.ll b/llvm/test/Transforms/CorrelatedValuePropagation/profmd.ll
index 5975bd2447cb..493b4c2273e2 100644
--- a/llvm/test/Transforms/CorrelatedValuePropagation/profmd.ll
+++ b/llvm/test/Transforms/CorrelatedValuePropagation/profmd.ll
@@ -24,7 +24,7 @@ negative:
   i32 2, label %out
   i32 3, label %out
 ; CHECK-NEXT: !prof ![[MD0:[0-9]+]]
-  ], !prof !{!"branch_weights", i64 99, i64 1, i64 2, i64 3, i64 4, i64 5, i64 6}
+  ], !prof !{!"branch_weights", i32 99, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6}
 
 out:
   %p = phi i32 [ 1, %entry ], [ -1, %negative ], [ -1, %negative ], [ -1, %negative ], [ -1, %negative ], [ -1, %negative ]
@@ -51,7 +51,7 @@ positive:
   i32 0, label %out
   i32 -1, label %next
   i32 -2, label %next
-  ], !prof !{!"branch_weights", i64 99, i64 1, i64 2, i64 3}
+  ], !prof !{!"branch_weights", i32 99, i32 1, i32 2, i32 3}
 
 out:
   %p = phi i32 [ -1, %entry ], [ 1, %positive ], [ 1, %positive ]
@@ -78,7 +78,7 @@ positive:
   i32 1, label %next
   i32 -1, label %next
   i32 -2, label %next
-  ], !prof !{!"branch_weights", i64 99, i64 1, i64 2, i64 3}
+  ], !prof !{!"branch_weights", i32 99, i32 1, i32 2, i32 3}
 
 out:
   %p = phi i32 [ -1, %entry ], [ 1, %positive ]
@@ -108,12 +108,12 @@ negative:
   i32 1, label %out
   i32 2, label %out
   i32 3, label %out
-  ], !prof !{!"branch_weights", i64 99, i64 1, i64 2, i64 3, i64 4}
+  ], !prof !{!"branch_weights", i32 99, i32 1, i32 2, i32 3, i32 4}
 
 out:
   %p = phi i32 [ 1, %entry ], [ -1, %negative ], [ -1, %negative ], [ -1, %negative ], [ -1, %negative ], [ -1, %negative ]
   ret i32 %p
 }
 
-; CHECK: ![[MD0]] = !{!"branch_weights", i64 99, i64 4, i64 3}
-; CHECK: ![[MD1]] = !{!"branch_weights", i64 1, i64 99}
+; CHECK: ![[MD0]] = !{!"branch_weights", i32 99, i32 4, i32 3}
+; CHECK: ![[MD1]] = !{!"branch_weights", i32 1, i32 99}

diff  --git a/llvm/test/Transforms/JumpThreading/threading_prof1.ll b/llvm/test/Transforms/JumpThreading/threading_prof1.ll
index ff0926b768aa..1bfd4509714e 100644
--- a/llvm/test/Transforms/JumpThreading/threading_prof1.ll
+++ b/llvm/test/Transforms/JumpThreading/threading_prof1.ll
@@ -94,6 +94,6 @@ declare i32 @a()
 
 declare i32 @b()
 
-!0 = !{!"branch_weights", i64 2146410443, i64 1073205}
-;CHECK: ![[PROF1]] = !{!"branch_weights", i64 1073205, i64 2146410443}
-;CHECK: ![[PROF2]] = !{!"branch_weights", i64 2146410443, i64 1073205}
+!0 = !{!"branch_weights", i32 2146410443, i32 1073205}
+;CHECK: ![[PROF1]] = !{!"branch_weights", i32 1073205, i32 2146410443}
+;CHECK: ![[PROF2]] = !{!"branch_weights", i32 2146410443, i32 1073205}

diff  --git a/llvm/test/Transforms/JumpThreading/threading_prof2.ll b/llvm/test/Transforms/JumpThreading/threading_prof2.ll
index 9a3d0ee94dd0..b14b996f24ea 100644
--- a/llvm/test/Transforms/JumpThreading/threading_prof2.ll
+++ b/llvm/test/Transforms/JumpThreading/threading_prof2.ll
@@ -37,6 +37,6 @@ declare i32 @a()
 
 declare i32 @b()
 
-!0 = !{!"branch_weights", i64 2146410443, i64 1073205}
-;CHECK: ![[PROF1]] = !{!"branch_weights", i64 1073205, i64 2146410443}
-;CHECK: ![[PROF2]] = !{!"branch_weights", i64 2146410443, i64 1073205}
+!0 = !{!"branch_weights", i32 2146410443, i32 1073205}
+;CHECK: ![[PROF1]] = !{!"branch_weights", i32 1073205, i32 2146410443}
+;CHECK: ![[PROF2]] = !{!"branch_weights", i32 2146410443, i32 1073205}

diff  --git a/llvm/test/Transforms/JumpThreading/update-edge-weight.ll b/llvm/test/Transforms/JumpThreading/update-edge-weight.ll
index 071d4202b8df..e6a6093279de 100644
--- a/llvm/test/Transforms/JumpThreading/update-edge-weight.ll
+++ b/llvm/test/Transforms/JumpThreading/update-edge-weight.ll
@@ -3,7 +3,7 @@
 
 ; Test if edge weights are properly updated after jump threading.
 
-; CHECK: !2 = !{!"branch_weights", i64 1629125526, i64 518358122}
+; CHECK: !2 = !{!"branch_weights", i32 1629125526, i32 518358122}
 
 define void @foo(i32 %n) !prof !0 {
 entry:
@@ -40,5 +40,5 @@ declare void @c()
 declare void @d()
 
 !0 = !{!"function_entry_count", i64 1}
-!1 = !{!"branch_weights", i64 10, i64 5}
-!2 = !{!"branch_weights", i64 10, i64 1}
+!1 = !{!"branch_weights", i32 10, i32 5}
+!2 = !{!"branch_weights", i32 10, i32 1}

diff  --git a/llvm/test/Transforms/LoopUnroll/peel-loop-pgo-deopt.ll b/llvm/test/Transforms/LoopUnroll/peel-loop-pgo-deopt.ll
index d6408ff303c8..205a2832bb7a 100644
--- a/llvm/test/Transforms/LoopUnroll/peel-loop-pgo-deopt.ll
+++ b/llvm/test/Transforms/LoopUnroll/peel-loop-pgo-deopt.ll
@@ -77,14 +77,14 @@ attributes #1 = { nounwind optsize }
 !13 = !{i32 999000, i64 1, i32 10}
 !14 = !{i32 999999, i64 1, i32 10}
 !15 = !{!"function_entry_count", i64 1}
-!16 = !{!"branch_weights", i64 3001, i64 1001}
-!17 = !{!"branch_weights", i64 1, i64 0}
+!16 = !{!"branch_weights", i32 3001, i32 1001}
+!17 = !{!"branch_weights", i32 1, i32 0}
 
 ; This is a weights of deopt side-exit.
-;CHECK: !15 = !{!"branch_weights", i64 1, i64 0}
+;CHECK: !15 = !{!"branch_weights", i32 1, i32 0}
 ; This is a weights of latch and its copies.
-;CHECK: !16 = !{!"branch_weights", i64 3001, i64 1001}
-;CHECK: !17 = !{!"branch_weights", i64 2000, i64 1001}
-;CHECK: !18 = !{!"branch_weights", i64 999, i64 1001}
-;CHECK: !19 = !{!"branch_weights", i64 1, i64 1001}
+;CHECK: !16 = !{!"branch_weights", i32 3001, i32 1001}
+;CHECK: !17 = !{!"branch_weights", i32 2000, i32 1001}
+;CHECK: !18 = !{!"branch_weights", i32 999, i32 1001}
+;CHECK: !19 = !{!"branch_weights", i32 1, i32 1001}
 

diff  --git a/llvm/test/Transforms/LoopUnroll/peel-loop-pgo.ll b/llvm/test/Transforms/LoopUnroll/peel-loop-pgo.ll
index 17bc78832aca..38cd6e049e9f 100644
--- a/llvm/test/Transforms/LoopUnroll/peel-loop-pgo.ll
+++ b/llvm/test/Transforms/LoopUnroll/peel-loop-pgo.ll
@@ -101,10 +101,10 @@ attributes #1 = { nounwind optsize }
 !13 = !{i32 999000, i64 1, i32 10}
 !14 = !{i32 999999, i64 1, i32 10}
 !15 = !{!"function_entry_count", i64 1}
-!16 = !{!"branch_weights", i64 3001, i64 1001}
+!16 = !{!"branch_weights", i32 3001, i32 1001}
 
-;CHECK: !15 = !{!"branch_weights", i64 3001, i64 1001}
-;CHECK: !16 = !{!"branch_weights", i64 2000, i64 1001}
-;CHECK: !17 = !{!"branch_weights", i64 999, i64 1001}
-;CHECK: !18 = !{!"branch_weights", i64 1, i64 1001}
+;CHECK: !15 = !{!"branch_weights", i32 3001, i32 1001}
+;CHECK: !16 = !{!"branch_weights", i32 2000, i32 1001}
+;CHECK: !17 = !{!"branch_weights", i32 999, i32 1001}
+;CHECK: !18 = !{!"branch_weights", i32 1, i32 1001}
 

diff  --git a/llvm/test/Transforms/LoopUnroll/runtime-loop-branchweight.ll b/llvm/test/Transforms/LoopUnroll/runtime-loop-branchweight.ll
index 706840954868..c240d246bd1e 100644
--- a/llvm/test/Transforms/LoopUnroll/runtime-loop-branchweight.ll
+++ b/llvm/test/Transforms/LoopUnroll/runtime-loop-branchweight.ll
@@ -7,8 +7,8 @@
 ; CHECK: br i1 [[COND1:%.*]], label %for.end.loopexit.unr-lcssa.loopexit, label %for.body, !prof ![[#PROF:]], !llvm.loop ![[#LOOP:]]
 ; CHECK-LABEL: for.body.epil:
 ; CHECK: br i1 [[COND2:%.*]], label  %for.body.epil, label %for.end.loopexit.epilog-lcssa, !prof ![[#PROF2:]], !llvm.loop ![[#LOOP2:]]
-; CHECK: ![[#PROF]] = !{!"branch_weights", i64 1, i64 9999}
-; CHECK: ![[#PROF2]] = !{!"branch_weights", i64 3, i64 1}
+; CHECK: ![[#PROF]] = !{!"branch_weights", i32 1, i32 9999}
+; CHECK: ![[#PROF2]] = !{!"branch_weights", i32 3, i32 1}
 
 define i3 @test(i3* %a, i3 %n) {
 entry:
@@ -31,4 +31,4 @@ for.end:
   ret i3 %sum.0.lcssa
 }
 
-!0 = !{!"branch_weights", i64 1, i64 9999}
+!0 = !{!"branch_weights", i32 1, i32 9999}

diff  --git a/llvm/test/Transforms/LoopVectorize/check-prof-info.ll b/llvm/test/Transforms/LoopVectorize/check-prof-info.ll
index 53f8f4af375f..50b64d86c230 100644
--- a/llvm/test/Transforms/LoopVectorize/check-prof-info.ll
+++ b/llvm/test/Transforms/LoopVectorize/check-prof-info.ll
@@ -80,11 +80,11 @@ attributes #0 = { "use-soft-float"="false" }
 !llvm.module.flags = !{!0}
 !llvm.ident = !{!1}
 
-; CHECK: [[LP1_255]] = !{!"branch_weights", i64 1, i64 255}
-; CHECK: [[LP0_0]] = !{!"branch_weights", i64 0, i64 0}
-; CHECK-MASKED: [[LP1_63]] = !{!"branch_weights", i64 1, i64 63}
-; CHECK-MASKED: [[LP0_0]] = !{!"branch_weights", i64 0, i64 0}
-; CHECK: [[LP1_2]] = !{!"branch_weights", i64 1, i64 2}
+; CHECK: [[LP1_255]] = !{!"branch_weights", i32 1, i32 255}
+; CHECK: [[LP0_0]] = !{!"branch_weights", i32 0, i32 0}
+; CHECK-MASKED: [[LP1_63]] = !{!"branch_weights", i32 1, i32 63}
+; CHECK-MASKED: [[LP0_0]] = !{!"branch_weights", i32 0, i32 0}
+; CHECK: [[LP1_2]] = !{!"branch_weights", i32 1, i32 2}
 
 !0 = !{i32 1, !"wchar_size", i32 4}
 !1 = !{!"clang version 10.0.0 (https://github.com/llvm/llvm-project c292b5b5e059e6ce3e6449e6827ef7e1037c21c4)"}
@@ -92,5 +92,5 @@ attributes #0 = { "use-soft-float"="false" }
 !3 = !{!"int", !4, i64 0}
 !4 = !{!"omnipotent char", !5, i64 0}
 !5 = !{!"Simple C++ TBAA"}
-!6 = !{!"branch_weights", i64 1, i64 1023}
-!7 = !{!"branch_weights", i64 1, i64 1026}
+!6 = !{!"branch_weights", i32 1, i32 1023}
+!7 = !{!"branch_weights", i32 1, i32 1026}

diff  --git a/llvm/test/Transforms/LoopVectorize/tripcount.ll b/llvm/test/Transforms/LoopVectorize/tripcount.ll
index 48a9c9f1b2a5..e19f4aa85c02 100644
--- a/llvm/test/Transforms/LoopVectorize/tripcount.ll
+++ b/llvm/test/Transforms/LoopVectorize/tripcount.ll
@@ -207,8 +207,8 @@ for.end:                                          ; preds = %for.body
   ret i32 0
 }
 
-; CHECK: [[LP3]] = !{!"branch_weights", i64 10, i64 2490}
-; CHECK: [[LP6]] = !{!"branch_weights", i64 10, i64 0}
+; CHECK: [[LP3]] = !{!"branch_weights", i32 10, i32 2490}
+; CHECK: [[LP6]] = !{!"branch_weights", i32 10, i32 0}
 ; original loop has latchExitWeight=10 and backedgeTakenWeight=10,000,
 ; therefore estimatedBackedgeTakenCount=1,000 and estimatedTripCount=1,001.
 ; Vectorizing by 4 produces estimatedTripCounts of 1,001/4=250 and 1,001%4=1
@@ -217,6 +217,6 @@ for.end:                                          ; preds = %for.body
 ; loop invocation weights of 10 are the above {10, 2490} and {10, 0}.
 
 !0 = !{!"function_entry_count", i64 100}
-!1 = !{!"branch_weights", i64 100, i64 0}
-!2 = !{!"branch_weights", i64 10, i64 90}
-!3 = !{!"branch_weights", i64 10, i64 10000}
+!1 = !{!"branch_weights", i32 100, i32 0}
+!2 = !{!"branch_weights", i32 10, i32 90}
+!3 = !{!"branch_weights", i32 10, i32 10000}

diff  --git a/llvm/test/Transforms/LowerExpectIntrinsic/basic.ll b/llvm/test/Transforms/LowerExpectIntrinsic/basic.ll
index de967da4c19f..4324b7bd32bc 100644
--- a/llvm/test/Transforms/LowerExpectIntrinsic/basic.ll
+++ b/llvm/test/Transforms/LowerExpectIntrinsic/basic.ll
@@ -285,10 +285,10 @@ define i32 @test10(i64 %t6) {
 
 declare i1 @llvm.expect.i1(i1, i1) nounwind readnone
 
-; CHECK: !0 = !{!"branch_weights", i64 2000, i64 1}
+; CHECK: !0 = !{!"branch_weights", i32 2000, i32 1}
 ; CHECK: !1 = !{!"misexpect", i64 0, i64 2000, i64 1}
-; CHECK: !2 = !{!"branch_weights", i64 1, i64 2000}
+; CHECK: !2 = !{!"branch_weights", i32 1, i32 2000}
 ; CHECK: !3 = !{!"misexpect", i64 1, i64 2000, i64 1}
-; CHECK: !4 = !{!"branch_weights", i64 1, i64 1, i64 2000}
+; CHECK: !4 = !{!"branch_weights", i32 1, i32 1, i32 2000}
 ; CHECK: !5 = !{!"misexpect", i64 2, i64 2000, i64 1}
-; CHECK: !6 = !{!"branch_weights", i64 2000, i64 1, i64 1}
+; CHECK: !6 = !{!"branch_weights", i32 2000, i32 1, i32 1}

diff  --git a/llvm/test/Transforms/LowerExpectIntrinsic/expect-with-probability.ll b/llvm/test/Transforms/LowerExpectIntrinsic/expect-with-probability.ll
index 864dec7d07e4..8972ee01c12d 100644
--- a/llvm/test/Transforms/LowerExpectIntrinsic/expect-with-probability.ll
+++ b/llvm/test/Transforms/LowerExpectIntrinsic/expect-with-probability.ll
@@ -285,11 +285,11 @@ define i32 @test10(i64 %t6) {
 
 declare i1 @llvm.expect.with.probability.i1(i1, i1, double) nounwind readnone
 
-; CHECK: !0 = !{!"branch_weights", i64 1717986918, i64 429496731}
+; CHECK: !0 = !{!"branch_weights", i32 1717986918, i32 429496731}
 ; CHECK: !1 = !{!"misexpect", i64 0, i64 1717986918, i64 429496731}
-; CHECK: !2 = !{!"branch_weights", i64 429496731, i64 1717986918}
+; CHECK: !2 = !{!"branch_weights", i32 429496731, i32 1717986918}
 ; CHECK: !3 = !{!"misexpect", i64 1, i64 1717986918, i64 429496731}
-; CHECK: !4 = !{!"branch_weights", i64 214748366, i64 214748366, i64 1717986918}
+; CHECK: !4 = !{!"branch_weights", i32 214748366, i32 214748366, i32 1717986918}
 ; CHECK: !5 = !{!"misexpect", i64 2, i64 1717986918, i64 214748366}
-; CHECK: !6 = !{!"branch_weights", i64 1717986918, i64 214748366, i64 214748366}
+; CHECK: !6 = !{!"branch_weights", i32 1717986918, i32 214748366, i32 214748366}
 ; CHECK: !7 = !{!"misexpect", i64 0, i64 1717986918, i64 214748366}

diff  --git a/llvm/test/Transforms/LowerExpectIntrinsic/expect_nonboolean.ll b/llvm/test/Transforms/LowerExpectIntrinsic/expect_nonboolean.ll
index 8d6a66a2c4d2..736ddc32856c 100644
--- a/llvm/test/Transforms/LowerExpectIntrinsic/expect_nonboolean.ll
+++ b/llvm/test/Transforms/LowerExpectIntrinsic/expect_nonboolean.ll
@@ -99,6 +99,6 @@ attributes #1 = { nounwind readnone }
 
 !0 = !{i32 1, !"wchar_size", i32 4}
 !1 = !{!"clang version 5.0.0 (trunk 304373)"}
-; CHECK: [[LIKELY]] = !{!"branch_weights", i64 2000, i64 1}
-; CHECK: [[UNLIKELY]] = !{!"branch_weights", i64 1, i64 2000}
+; CHECK: [[LIKELY]] = !{!"branch_weights", i32 2000, i32 1}
+; CHECK: [[UNLIKELY]] = !{!"branch_weights", i32 1, i32 2000}
 

diff  --git a/llvm/test/Transforms/LowerExpectIntrinsic/phi_merge.ll b/llvm/test/Transforms/LowerExpectIntrinsic/phi_merge.ll
index a0e5eb427f0c..3b407c0f3a5a 100644
--- a/llvm/test/Transforms/LowerExpectIntrinsic/phi_merge.ll
+++ b/llvm/test/Transforms/LowerExpectIntrinsic/phi_merge.ll
@@ -352,5 +352,5 @@ declare i64 @llvm.expect.i64(i64, i64)
 !llvm.ident = !{!0}
 
 !0 = !{!"clang version 5.0.0 (trunk 302965)"}
-; CHECK: [[WEIGHT]] = !{!"branch_weights", i64 2000, i64 1}
-; CHECK: [[WEIGHT2]] = !{!"branch_weights", i64 1, i64 2000}
+; CHECK: [[WEIGHT]] = !{!"branch_weights", i32 2000, i32 1}
+; CHECK: [[WEIGHT2]] = !{!"branch_weights", i32 1, i32 2000}

diff  --git a/llvm/test/Transforms/LowerExpectIntrinsic/phi_or.ll b/llvm/test/Transforms/LowerExpectIntrinsic/phi_or.ll
index b01cc84ff12a..849baef3dca8 100644
--- a/llvm/test/Transforms/LowerExpectIntrinsic/phi_or.ll
+++ b/llvm/test/Transforms/LowerExpectIntrinsic/phi_or.ll
@@ -99,5 +99,5 @@ declare i64 @llvm.expect.i64(i64, i64)
 
 
 !0 = !{!"clang version 5.0.0 (trunk 302965)"}
-; CHECK: [[WEIGHT]] = !{!"branch_weights", i64 2000, i64 1}
-; CHECK: [[WEIGHT2]] = !{!"branch_weights", i64 1, i64 2000}
+; CHECK: [[WEIGHT]] = !{!"branch_weights", i32 2000, i32 1}
+; CHECK: [[WEIGHT2]] = !{!"branch_weights", i32 1, i32 2000}

diff  --git a/llvm/test/Transforms/LowerExpectIntrinsic/phi_tern.ll b/llvm/test/Transforms/LowerExpectIntrinsic/phi_tern.ll
index 8a7eb865d2dd..3c603d51b438 100644
--- a/llvm/test/Transforms/LowerExpectIntrinsic/phi_tern.ll
+++ b/llvm/test/Transforms/LowerExpectIntrinsic/phi_tern.ll
@@ -53,4 +53,4 @@ declare i64 @llvm.expect.i64(i64, i64)
 
 !0 = !{!"clang version 5.0.0 (trunk 302965)"}
 
-; CHECK: [[WEIGHT]] = !{!"branch_weights", i64 1, i64 2000}
+; CHECK: [[WEIGHT]] = !{!"branch_weights", i32 1, i32 2000}

diff  --git a/llvm/test/Transforms/PGOProfile/branch1.ll b/llvm/test/Transforms/PGOProfile/branch1.ll
index 423afa23992d..0b6f6862ccd3 100644
--- a/llvm/test/Transforms/PGOProfile/branch1.ll
+++ b/llvm/test/Transforms/PGOProfile/branch1.ll
@@ -37,10 +37,10 @@ entry:
   br i1 %cmp, label %if.then, label %if.end
 ; USE: br i1 %cmp, label %if.then, label %if.end
 ; USE-SAME: !prof ![[BW_ENTRY:[0-9]+]]
-; USE-DAG: ![[BW_ENTRY]] = !{!"branch_weights", i64 2, i64 1}
+; USE-DAG: ![[BW_ENTRY]] = !{!"branch_weights", i32 2, i32 1}
 ; USE-LARGE: br i1 %cmp, label %if.then, label %if.end
 ; USE-LARGE-SAME: !prof ![[BW_L_ENTRY:[0-9]+]]
-; USE-LARGE-DAG: ![[BW_L_ENTRY]] = !{!"branch_weights", i64 2863311530, i64 1431655765}
+; USE-LARGE-DAG: ![[BW_L_ENTRY]] = !{!"branch_weights", i32 -1431655766, i32 1431655765}
 
 if.then:
 ; GEN: if.then:

diff  --git a/llvm/test/Transforms/PGOProfile/branch2.ll b/llvm/test/Transforms/PGOProfile/branch2.ll
index bfb423e95756..7523c1f1b7d5 100644
--- a/llvm/test/Transforms/PGOProfile/branch2.ll
+++ b/llvm/test/Transforms/PGOProfile/branch2.ll
@@ -25,7 +25,7 @@ entry:
   br i1 %cmp, label %if.then, label %if.else
 ; USE: br i1 %cmp, label %if.then, label %if.else
 ; USE-SAME: !prof ![[BW_ENTRY:[0-9]+]]
-; USE: ![[BW_ENTRY]] = !{!"branch_weights", i64 1, i64 1}
+; USE: ![[BW_ENTRY]] = !{!"branch_weights", i32 1, i32 1}
 
 if.then:
 ; GEN: if.then:

diff  --git a/llvm/test/Transforms/PGOProfile/chr.ll b/llvm/test/Transforms/PGOProfile/chr.ll
index 78a07f2afede..0390b8eeee7d 100644
--- a/llvm/test/Transforms/PGOProfile/chr.ll
+++ b/llvm/test/Transforms/PGOProfile/chr.ll
@@ -2543,11 +2543,11 @@ bb3:
 !13 = !{i32 999999, i64 1, i32 2}
 
 !14 = !{!"function_entry_count", i64 100}
-!15 = !{!"branch_weights", i64 0, i64 1}
-!16 = !{!"branch_weights", i64 1, i64 1}
-!17 = !{!"branch_weights", i64 0, i64 0}
-; CHECK: !15 = !{!"branch_weights", i64 1000, i64 0}
-; CHECK: !16 = !{!"branch_weights", i64 0, i64 1}
-; CHECK: !17 = !{!"branch_weights", i64 1, i64 1}
-; CHECK: !18 = !{!"branch_weights", i64 1, i64 0}
-; CHECK: !19 = !{!"branch_weights", i64 0, i64 1000}
+!15 = !{!"branch_weights", i32 0, i32 1}
+!16 = !{!"branch_weights", i32 1, i32 1}
+!17 = !{!"branch_weights", i32 0, i32 0}
+; CHECK: !15 = !{!"branch_weights", i32 1000, i32 0}
+; CHECK: !16 = !{!"branch_weights", i32 0, i32 1}
+; CHECK: !17 = !{!"branch_weights", i32 1, i32 1}
+; CHECK: !18 = !{!"branch_weights", i32 1, i32 0}
+; CHECK: !19 = !{!"branch_weights", i32 0, i32 1000}

diff  --git a/llvm/test/Transforms/PGOProfile/criticaledge.ll b/llvm/test/Transforms/PGOProfile/criticaledge.ll
index e5726541fc6f..a2ed57255075 100644
--- a/llvm/test/Transforms/PGOProfile/criticaledge.ll
+++ b/llvm/test/Transforms/PGOProfile/criticaledge.ll
@@ -117,6 +117,6 @@ entry:
   ret i32 %i
 }
 
-; USE: ![[BW_SWITCH]] = !{!"branch_weights", i64 2, i64 1, i64 0, i64 2, i64 1, i64 1}
-; USE: ![[BW_SW_BB2]] = !{!"branch_weights", i64 2, i64 2}
-; USE: ![[BW_SW_DEFAULT]] = !{!"branch_weights", i64 1, i64 1}
+; USE: ![[BW_SWITCH]] = !{!"branch_weights", i32 2, i32 1, i32 0, i32 2, i32 1, i32 1}
+; USE: ![[BW_SW_BB2]] = !{!"branch_weights", i32 2, i32 2}
+; USE: ![[BW_SW_DEFAULT]] = !{!"branch_weights", i32 1, i32 1}

diff  --git a/llvm/test/Transforms/PGOProfile/cspgo_profile_summary.ll b/llvm/test/Transforms/PGOProfile/cspgo_profile_summary.ll
index 7fdb4b3f3841..23096d02f00b 100644
--- a/llvm/test/Transforms/PGOProfile/cspgo_profile_summary.ll
+++ b/llvm/test/Transforms/PGOProfile/cspgo_profile_summary.ll
@@ -132,7 +132,7 @@ entry:
 ; PGOSUMMARY: {{![0-9]+}} = !{!"MaxFunctionCount", i64 800000}
 ; PGOSUMMARY: {{![0-9]+}} = !{!"NumCounts", i64 14}
 ; PGOSUMMARY: {{![0-9]+}} = !{!"NumFunctions", i64 8}
-; PGOSUMMARY-DAG: ![[BW_PGO_BAR]] = !{!"branch_weights", i64 100000, i64 100000}
+; PGOSUMMARY-DAG: ![[BW_PGO_BAR]] = !{!"branch_weights", i32 100000, i32 100000}
 
 ; CSPGOSUMMARY: {{![0-9]+}} = !{i32 1, !"ProfileSummary", !1}
 ; CSPGOSUMMARY: {{![0-9]+}} = !{!"ProfileFormat", !"InstrProf"}
@@ -150,6 +150,6 @@ entry:
 ; CSPGOSUMMARY: {{![0-9]+}} = !{!"MaxInternalCount", i64 100000}
 ; CSPGOSUMMARY: {{![0-9]+}} = !{!"MaxFunctionCount", i64 200000}
 ; CSPGOSUMMARY: {{![0-9]+}} = !{!"NumCounts", i64 23}
-; CSPGOSUMMARY-DAG: ![[BW_CSPGO_BAR]] = !{!"branch_weights", i64 100000, i64 100000}
-; CSPGOSUMMARY-DAG: ![[BW1_CSPGO_FOO]] = !{!"branch_weights", i64 100000, i64 0}
-; CSPGOSUMMARY-DAG: ![[BW2_CSPGO_FOO]] = !{!"branch_weights", i64 0, i64 100000}
+; CSPGOSUMMARY-DAG: ![[BW_CSPGO_BAR]] = !{!"branch_weights", i32 100000, i32 100000}
+; CSPGOSUMMARY-DAG: ![[BW1_CSPGO_FOO]] = !{!"branch_weights", i32 100000, i32 0}
+; CSPGOSUMMARY-DAG: ![[BW2_CSPGO_FOO]] = !{!"branch_weights", i32 0, i32 100000}

diff  --git a/llvm/test/Transforms/PGOProfile/fix_entry_count.ll b/llvm/test/Transforms/PGOProfile/fix_entry_count.ll
index c6bbe1bde3fa..5923bc923a6a 100644
--- a/llvm/test/Transforms/PGOProfile/fix_entry_count.ll
+++ b/llvm/test/Transforms/PGOProfile/fix_entry_count.ll
@@ -31,4 +31,4 @@ for.end:
   ret i32 %sum
 }
 ; USE: ![[ENTRY_COUNT]] = !{!"function_entry_count", i64 1}
-; USE: ![[BW_FOR_COND]] = !{!"branch_weights", i64 96, i64 1}
+; USE: ![[BW_FOR_COND]] = !{!"branch_weights", i32 96, i32 1}

diff  --git a/llvm/test/Transforms/PGOProfile/icp_covariant_call_return.ll b/llvm/test/Transforms/PGOProfile/icp_covariant_call_return.ll
index 41fff42db41a..c2101a98d0d1 100644
--- a/llvm/test/Transforms/PGOProfile/icp_covariant_call_return.ll
+++ b/llvm/test/Transforms/PGOProfile/icp_covariant_call_return.ll
@@ -40,5 +40,5 @@ entry:
 
 !1 = !{!"VP", i32 0, i64 12345, i64 -3913987384944532146, i64 12345}
 ; ICALL-PROM-NOT: !1 = !{!"VP", i32 0, i64 12345, i64 -3913987384944532146, i64 12345}
-; ICALL-PROM: [[BRANCH_WEIGHT]] = !{!"branch_weights", i64 12345, i64 0}
+; ICALL-PROM: [[BRANCH_WEIGHT]] = !{!"branch_weights", i32 12345, i32 0}
 ; ICALL-PROM-NOT: !1 = !{!"VP", i32 0, i64 12345, i64 -3913987384944532146, i64 12345}

diff  --git a/llvm/test/Transforms/PGOProfile/icp_covariant_invoke_return.ll b/llvm/test/Transforms/PGOProfile/icp_covariant_invoke_return.ll
index f9ee43134956..d0f27ac73e78 100644
--- a/llvm/test/Transforms/PGOProfile/icp_covariant_invoke_return.ll
+++ b/llvm/test/Transforms/PGOProfile/icp_covariant_invoke_return.ll
@@ -108,5 +108,5 @@ eh.resume:
 
 !1 = !{!"VP", i32 0, i64 12345, i64 -3913987384944532146, i64 12345}
 ; ICALL-PROM-NOT: !1 = !{!"VP", i32 0, i64 12345, i64 -3913987384944532146, i64 12345}
-; ICALL-PROM: [[BRANCH_WEIGHT]] = !{!"branch_weights", i64 12345, i64 0}
+; ICALL-PROM: [[BRANCH_WEIGHT]] = !{!"branch_weights", i32 12345, i32 0}
 ; ICALL-PROM-NOT: !1 = !{!"VP", i32 0, i64 12345, i64 -3913987384944532146, i64 12345}

diff  --git a/llvm/test/Transforms/PGOProfile/icp_invoke.ll b/llvm/test/Transforms/PGOProfile/icp_invoke.ll
index 4d891b64e563..4d2eee9cbf74 100644
--- a/llvm/test/Transforms/PGOProfile/icp_invoke.ll
+++ b/llvm/test/Transforms/PGOProfile/icp_invoke.ll
@@ -103,4 +103,4 @@ declare void @__cxa_end_catch()
 !3 = !{!"VP", i32 0, i64 1, i64 -6116256810522035449, i64 1}
 ; ICP-NOT: !3 = !{!"VP", i32 0, i64 1, i64 -2732222848796217051, i64 1}
 ; ICP-NOT: !4 = !{!"VP", i32 0, i64 1, i64 -6116256810522035449, i64 1}
-; ICP: [[BRANCH_WEIGHT]] = !{!"branch_weights", i64 1, i64 0}
+; ICP: [[BRANCH_WEIGHT]] = !{!"branch_weights", i32 1, i32 0}

diff  --git a/llvm/test/Transforms/PGOProfile/icp_vararg.ll b/llvm/test/Transforms/PGOProfile/icp_vararg.ll
index 4503dfa3f418..ba803cf85c78 100644
--- a/llvm/test/Transforms/PGOProfile/icp_vararg.ll
+++ b/llvm/test/Transforms/PGOProfile/icp_vararg.ll
@@ -30,4 +30,4 @@ entry:
 }
 
 !1 = !{!"VP", i32 0, i64 12345, i64 989055279648259519, i64 12345}
-; ICALL-PROM: [[BRANCH_WEIGHT]] = !{!"branch_weights", i64 12345, i64 0}
+; ICALL-PROM: [[BRANCH_WEIGHT]] = !{!"branch_weights", i32 12345, i32 0}

diff  --git a/llvm/test/Transforms/PGOProfile/indirect_call_promotion.ll b/llvm/test/Transforms/PGOProfile/indirect_call_promotion.ll
index 5793a7f934fa..6a9b65211990 100644
--- a/llvm/test/Transforms/PGOProfile/indirect_call_promotion.ll
+++ b/llvm/test/Transforms/PGOProfile/indirect_call_promotion.ll
@@ -60,6 +60,6 @@ entry:
 
 !1 = !{!"VP", i32 0, i64 1600, i64 7651369219802541373, i64 1030, i64 -4377547752858689819, i64 410, i64 -6929281286627296573, i64 150, i64 -2545542355363006406, i64 10}
 
-; ICALL-PROM: [[BRANCH_WEIGHT]] = !{!"branch_weights", i64 1030, i64 570}
+; ICALL-PROM: [[BRANCH_WEIGHT]] = !{!"branch_weights", i32 1030, i32 570}
 ; ICALL-PROM: [[NEW_VP_METADATA]] = !{!"VP", i32 0, i64 570, i64 -4377547752858689819, i64 410}
-; ICALL-PROM-SAMPLEPGO: [[CALL_METADATA]] = !{!"branch_weights", i64 1030}
+; ICALL-PROM-SAMPLEPGO: [[CALL_METADATA]] = !{!"branch_weights", i32 1030}

diff  --git a/llvm/test/Transforms/PGOProfile/indirect_call_promotion_musttail.ll b/llvm/test/Transforms/PGOProfile/indirect_call_promotion_musttail.ll
index 1e900c0c43ce..e79e533c4af2 100644
--- a/llvm/test/Transforms/PGOProfile/indirect_call_promotion_musttail.ll
+++ b/llvm/test/Transforms/PGOProfile/indirect_call_promotion_musttail.ll
@@ -62,7 +62,7 @@ entry:
 !1 = !{!"VP", i32 0, i64 1600, i64 7651369219802541373, i64 1030, i64 -4377547752858689819, i64 410, i64 -6929281286627296573, i64 150, i64 -2545542355363006406, i64 10}
 !2 = !{!"VP", i32 0, i64 100, i64 7651369219802541373, i64 100}
 
-; ICALL-PROM: [[BRANCH_WEIGHT1]] = !{!"branch_weights", i64 1030, i64 570}
-; ICALL-PROM: [[BRANCH_WEIGHT2]] = !{!"branch_weights", i64 410, i64 160}
-; ICALL-PROM: [[BRANCH_WEIGHT3]] = !{!"branch_weights", i64 150, i64 10}
-; ICALL-PROM: [[BRANCH_WEIGHT4]] = !{!"branch_weights", i64 100, i64 0}
+; ICALL-PROM: [[BRANCH_WEIGHT1]] = !{!"branch_weights", i32 1030, i32 570}
+; ICALL-PROM: [[BRANCH_WEIGHT2]] = !{!"branch_weights", i32 410, i32 160}
+; ICALL-PROM: [[BRANCH_WEIGHT3]] = !{!"branch_weights", i32 150, i32 10}
+; ICALL-PROM: [[BRANCH_WEIGHT4]] = !{!"branch_weights", i32 100, i32 0}

diff  --git a/llvm/test/Transforms/PGOProfile/indirect_call_promotion_vla.ll b/llvm/test/Transforms/PGOProfile/indirect_call_promotion_vla.ll
index c29b96dca286..6a815275e4cf 100644
--- a/llvm/test/Transforms/PGOProfile/indirect_call_promotion_vla.ll
+++ b/llvm/test/Transforms/PGOProfile/indirect_call_promotion_vla.ll
@@ -24,5 +24,5 @@ entry:
   ret i32 %call
 }
 
-; CHECK: [[BRANCH_WEIGHT]] = !{!"branch_weights", i64 1500, i64 100}
+; CHECK: [[BRANCH_WEIGHT]] = !{!"branch_weights", i32 1500, i32 100}
 !1 = !{!"VP", i32 0, i64 1600, i64 -2545542355363006406, i64 1500}

diff  --git a/llvm/test/Transforms/PGOProfile/indirectbr.ll b/llvm/test/Transforms/PGOProfile/indirectbr.ll
index dd0a93862f27..ab4c52decf5f 100644
--- a/llvm/test/Transforms/PGOProfile/indirectbr.ll
+++ b/llvm/test/Transforms/PGOProfile/indirectbr.ll
@@ -26,7 +26,7 @@ if.then:
   indirectbr i8* %0, [label %return, label %label2, label %label3]
 ; USE:  indirectbr i8* %0, [label %return, label %label2, label %label3]
 ; USE-SAME: !prof ![[BW_INDBR:[0-9]+]]
-; USE: ![[BW_INDBR]] = !{!"branch_weights", i64 63, i64 20, i64 5}
+; USE: ![[BW_INDBR]] = !{!"branch_weights", i32 63, i32 20, i32 5}
 
 label2:
   br label %return

diff  --git a/llvm/test/Transforms/PGOProfile/instr_entry_bb.ll b/llvm/test/Transforms/PGOProfile/instr_entry_bb.ll
index c5382c35a3cd..80e30a3c576a 100644
--- a/llvm/test/Transforms/PGOProfile/instr_entry_bb.ll
+++ b/llvm/test/Transforms/PGOProfile/instr_entry_bb.ll
@@ -21,7 +21,7 @@ entry:
 ; GENA: %{{[0-9+]}} = atomicrmw add i64* getelementptr inbounds ([2 x i64], [2 x i64]* @__profc_test_br_2, i64 0, i64 0), i64 1 monotonic
 ; USE: br i1 %cmp, label %if.then, label %if.else
 ; USE-SAME: !prof ![[BW_ENTRY:[0-9]+]]
-; USE: ![[BW_ENTRY]] = !{!"branch_weights", i64 0, i64 1}
+; USE: ![[BW_ENTRY]] = !{!"branch_weights", i32 0, i32 1}
   %cmp = icmp sgt i32 %i, 0
   br i1 %cmp, label %if.then, label %if.else
 

diff  --git a/llvm/test/Transforms/PGOProfile/landingpad.ll b/llvm/test/Transforms/PGOProfile/landingpad.ll
index f08a4885d978..a0ca799fa8a4 100644
--- a/llvm/test/Transforms/PGOProfile/landingpad.ll
+++ b/llvm/test/Transforms/PGOProfile/landingpad.ll
@@ -132,6 +132,6 @@ declare i8* @__cxa_begin_catch(i8*)
 
 declare void @__cxa_end_catch()
 
-; USE: ![[BW_BAR_ENTRY]] = !{!"branch_weights", i64 2, i64 1}
-; USE: ![[BW_FOO_ENTRY]] = !{!"branch_weights", i64 3, i64 2}
-; USE: ![[BW_CATCH_DISPATCH]] = !{!"branch_weights", i64 2, i64 0}
+; USE: ![[BW_BAR_ENTRY]] = !{!"branch_weights", i32 2, i32 1}
+; USE: ![[BW_FOO_ENTRY]] = !{!"branch_weights", i32 3, i32 2}
+; USE: ![[BW_CATCH_DISPATCH]] = !{!"branch_weights", i32 2, i32 0}

diff  --git a/llvm/test/Transforms/PGOProfile/loop1.ll b/llvm/test/Transforms/PGOProfile/loop1.ll
index 3aaba3e4f683..34855750813c 100644
--- a/llvm/test/Transforms/PGOProfile/loop1.ll
+++ b/llvm/test/Transforms/PGOProfile/loop1.ll
@@ -32,7 +32,7 @@ for.cond:
   br i1 %cmp, label %for.body, label %for.end
 ; USE: br i1 %cmp, label %for.body, label %for.end
 ; USE-SAME: !prof ![[BW_FOR_COND:[0-9]+]]
-; USE: ![[BW_FOR_COND]] = !{!"branch_weights", i64 96, i64 4}
+; USE: ![[BW_FOR_COND]] = !{!"branch_weights", i32 96, i32 4}
 
 for.body:
 ; GEN: for.body:

diff  --git a/llvm/test/Transforms/PGOProfile/loop2.ll b/llvm/test/Transforms/PGOProfile/loop2.ll
index 218c1cf89de1..7e993db54ef7 100644
--- a/llvm/test/Transforms/PGOProfile/loop2.ll
+++ b/llvm/test/Transforms/PGOProfile/loop2.ll
@@ -78,6 +78,6 @@ for.end.outer:
   ret i32 %sum.0
 }
 
-; USE-DAG: ![[BW_FOR_COND_OUTER]] = !{!"branch_weights", i64 10, i64 6}
-; USE-DAG: ![[BW_FOR_COND_INNER]] = !{!"branch_weights", i64 33, i64 10}
+; USE-DAG: ![[BW_FOR_COND_OUTER]] = !{!"branch_weights", i32 10, i32 6}
+; USE-DAG: ![[BW_FOR_COND_INNER]] = !{!"branch_weights", i32 33, i32 10}
 

diff  --git a/llvm/test/Transforms/PGOProfile/memop_size_opt.ll b/llvm/test/Transforms/PGOProfile/memop_size_opt.ll
index 2f12c0690f3c..bc79fbc3e37e 100644
--- a/llvm/test/Transforms/PGOProfile/memop_size_opt.ll
+++ b/llvm/test/Transforms/PGOProfile/memop_size_opt.ll
@@ -143,7 +143,7 @@ for.end6:
   ret void
 }
 
-; MEMOP_OPT: [[SWITCH_BW]] = !{!"branch_weights", i64 457, i64 99}
+; MEMOP_OPT: [[SWITCH_BW]] = !{!"branch_weights", i32 457, i32 99}
 ; Should be 457 total left (original total count 556, minus 99 from specialized
 ; value 1, which is removed from VP array. Also, we only end up with 5 total
 ; values, since the default max number of promotions is 5 and therefore
@@ -180,8 +180,8 @@ for.end6:
 !25 = !{i32 999990, i64 1, i32 5}
 !26 = !{i32 999999, i64 1, i32 5}
 !27 = !{!"function_entry_count", i64 1}
-!28 = !{!"branch_weights", i64 20, i64 1}
-!29 = !{!"branch_weights", i64 556, i64 20}
+!28 = !{!"branch_weights", i32 20, i32 1}
+!29 = !{!"branch_weights", i32 556, i32 20}
 !30 = !{!"VP", i32 1, i64 556, i64 1, i64 99, i64 2, i64 88, i64 3, i64 77, i64 9, i64 72, i64 4, i64 66, i64 5, i64 55, i64 6, i64 44, i64 7, i64 33, i64 8, i64 22}
 !31 = !{!"VP", i32 1, i64 556, i64 1, i64 99, i64 2, i64 88, i64 3, i64 77, i64 9, i64 72, i64 4, i64 66, i64 5, i64 55, i64 6, i64 44, i64 7, i64 33, i64 8, i64 22}
 

diff  --git a/llvm/test/Transforms/PGOProfile/multiple_hash_profile.ll b/llvm/test/Transforms/PGOProfile/multiple_hash_profile.ll
index 87044fdd0cc3..f0011114f0d0 100644
--- a/llvm/test/Transforms/PGOProfile/multiple_hash_profile.ll
+++ b/llvm/test/Transforms/PGOProfile/multiple_hash_profile.ll
@@ -30,10 +30,10 @@ entry:
   %mul.i = select i1 %cmp.i, i32 1, i32 %i
 ; CHECK: %mul.i = select i1 %cmp.i, i32 1, i32 %i
 ; CHECK-SAME: !prof ![[BW:[0-9]+]]
-; CHECK: ![[BW]] = !{!"branch_weights", i64 12, i64 6}
+; CHECK: ![[BW]] = !{!"branch_weights", i32 12, i32 6}
 ; CHECKOLDHASH: %mul.i = select i1 %cmp.i, i32 1, i32 %i
 ; CHECKOLDHASH-SAME: !prof ![[BW:[0-9]+]]
-; CHECKOLDHASH: ![[BW]] = !{!"branch_weights", i64 6, i64 12}
+; CHECKOLDHASH: ![[BW]] = !{!"branch_weights", i32 6, i32 12}
   %retval.0.i = mul nsw i32 %mul.i, %i
   ret i32 %retval.0.i
 }

diff  --git a/llvm/test/Transforms/PGOProfile/noreturncall.ll b/llvm/test/Transforms/PGOProfile/noreturncall.ll
index cc990a3c6355..4470285e1edb 100644
--- a/llvm/test/Transforms/PGOProfile/noreturncall.ll
+++ b/llvm/test/Transforms/PGOProfile/noreturncall.ll
@@ -41,5 +41,5 @@ if.end7:
   %mul = mul nsw i32 %ret.0, %ret.0
   ret i32 %mul
 }
-; USE: ![[BW_ENTRY]] = !{!"branch_weights", i64 21, i64 0}
-; USE: ![[BW_IF]] = !{!"branch_weights", i64 0, i64 21}
+; USE: ![[BW_ENTRY]] = !{!"branch_weights", i32 21, i32 0}
+; USE: ![[BW_IF]] = !{!"branch_weights", i32 0, i32 21}

diff  --git a/llvm/test/Transforms/PGOProfile/remap.ll b/llvm/test/Transforms/PGOProfile/remap.ll
index a8a37a581f02..e84c3c40f835 100644
--- a/llvm/test/Transforms/PGOProfile/remap.ll
+++ b/llvm/test/Transforms/PGOProfile/remap.ll
@@ -25,4 +25,4 @@ if.end:
 ; USE-DAG: {{![0-9]+}} = !{i32 1, !"ProfileSummary", {{![0-9]+}}}
 ; USE-DAG: {{![0-9]+}} = !{!"DetailedSummary", {{![0-9]+}}}
 ; USE-DAG: ![[FUNC_ENTRY_COUNT]] = !{!"function_entry_count", i64 3}
-; USE-DAG: ![[BW_ENTRY]] = !{!"branch_weights", i64 2, i64 1}
+; USE-DAG: ![[BW_ENTRY]] = !{!"branch_weights", i32 2, i32 1}

diff  --git a/llvm/test/Transforms/PGOProfile/select1.ll b/llvm/test/Transforms/PGOProfile/select1.ll
index e23dbc06c9e9..47d83c84aa09 100644
--- a/llvm/test/Transforms/PGOProfile/select1.ll
+++ b/llvm/test/Transforms/PGOProfile/select1.ll
@@ -20,7 +20,7 @@ if.then:
 ;NOSELECT-NOT: call void @llvm.instrprof.increment.step
   %s = select i1 %cmp, i32 %add, i32 0
 ;USE: select i1 %cmp{{.*}}, !prof ![[BW_ENTRY:[0-9]+]]
-;USE: ![[BW_ENTRY]] = !{!"branch_weights", i64 1, i64 3}
+;USE: ![[BW_ENTRY]] = !{!"branch_weights", i32 1, i32 3}
 
   br label %if.end
 

diff  --git a/llvm/test/Transforms/PGOProfile/select2.ll b/llvm/test/Transforms/PGOProfile/select2.ll
index 24bbdb6a688d..e95d00b248f4 100644
--- a/llvm/test/Transforms/PGOProfile/select2.ll
+++ b/llvm/test/Transforms/PGOProfile/select2.ll
@@ -33,5 +33,5 @@ for.end:
 }
 
 ;USE: ![[ENTRY_COUNT]] = !{!"function_entry_count", i64 3}
-;USE: ![[BW_FOR_BR]] = !{!"branch_weights", i64 800, i64 3}
-;USE: ![[BW_FOR_SELECT]] = !{!"branch_weights", i64 300, i64 500}
+;USE: ![[BW_FOR_BR]] = !{!"branch_weights", i32 800, i32 3}
+;USE: ![[BW_FOR_SELECT]] = !{!"branch_weights", i32 300, i32 500}

diff  --git a/llvm/test/Transforms/PGOProfile/switch.ll b/llvm/test/Transforms/PGOProfile/switch.ll
index 2cb2eb14a175..ca7c5ba6df74 100644
--- a/llvm/test/Transforms/PGOProfile/switch.ll
+++ b/llvm/test/Transforms/PGOProfile/switch.ll
@@ -27,7 +27,7 @@ entry:
   ]
 ; USE: ]
 ; USE-SAME: !prof ![[BW_SWITCH:[0-9]+]]
-; USE: ![[BW_SWITCH]] = !{!"branch_weights", i64 3, i64 2, i64 0, i64 5}
+; USE: ![[BW_SWITCH]] = !{!"branch_weights", i32 3, i32 2, i32 0, i32 5}
 
 sw.bb:
 ; GEN: sw.bb:

diff  --git a/llvm/test/Transforms/PGOProfile/thinlto_cspgo_use.ll b/llvm/test/Transforms/PGOProfile/thinlto_cspgo_use.ll
index 41c2478aa99f..357115dc6501 100644
--- a/llvm/test/Transforms/PGOProfile/thinlto_cspgo_use.ll
+++ b/llvm/test/Transforms/PGOProfile/thinlto_cspgo_use.ll
@@ -14,8 +14,8 @@
 
 ; CSUSE: {{![0-9]+}} = !{i32 1, !"ProfileSummary", {{![0-9]+}}}
 ; CSUSE: {{![0-9]+}} = !{i32 1, !"CSProfileSummary", {{![0-9]+}}}
-; CSUSE-DAG: {{![0-9]+}} = !{!"branch_weights", i64 100000, i64 0}
-; CSUSE-DAG: {{![0-9]+}} = !{!"branch_weights", i64 0, i64 100000}
+; CSUSE-DAG: {{![0-9]+}} = !{!"branch_weights", i32 100000, i32 0}
+; CSUSE-DAG: {{![0-9]+}} = !{!"branch_weights", i32 0, i32 100000}
 
 source_filename = "cspgo.c"
 target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
@@ -79,4 +79,4 @@ attributes #0 = { "target-cpu"="x86-64" }
 !26 = !{i32 999990, i64 100000, i32 4}
 !27 = !{i32 999999, i64 1, i32 6}
 !29 = !{!"function_entry_count", i64 1}
-!30 = !{!"branch_weights", i64 100000, i64 1}
+!30 = !{!"branch_weights", i32 100000, i32 1}

diff  --git a/llvm/test/Transforms/PGOProfile/thinlto_indirect_call_promotion.ll b/llvm/test/Transforms/PGOProfile/thinlto_indirect_call_promotion.ll
index 2538f5ceb816..b4c9c6fc55a2 100644
--- a/llvm/test/Transforms/PGOProfile/thinlto_indirect_call_promotion.ll
+++ b/llvm/test/Transforms/PGOProfile/thinlto_indirect_call_promotion.ll
@@ -35,5 +35,5 @@ entry:
 ; Should not have a VP annotation on new indirect call (check before and after
 ; branch_weights annotation).
 ; ICALL-PROM-NOT: !"VP"
-; ICALL-PROM: [[BRANCH_WEIGHT]] = !{!"branch_weights", i64 1, i64 0}
+; ICALL-PROM: [[BRANCH_WEIGHT]] = !{!"branch_weights", i32 1, i32 0}
 ; ICALL-PROM-NOT: !"VP"

diff  --git a/llvm/test/Transforms/SCCP/switch.ll b/llvm/test/Transforms/SCCP/switch.ll
index 579010a59684..17653014b090 100644
--- a/llvm/test/Transforms/SCCP/switch.ll
+++ b/llvm/test/Transforms/SCCP/switch.ll
@@ -220,7 +220,7 @@ define internal i32 @test_ip_range(i32 %x) {
   i32 1, label %switch.1
   i32 2, label %switch.2
   i32 3, label %switch.3
-  ], !prof !{!"branch_weights", i64 1, i64 2, i64 3, i64 4, i64 5}
+  ], !prof !{!"branch_weights", i32 1, i32 2, i32 3, i32 4, i32 5}
 
 switch.default:
   ret i32 -1
@@ -251,4 +251,4 @@ define void @call_test_ip_range() {
 
 declare void @llvm.assume(i1)
 
-; CHECK: !1 = !{!"branch_weights", i64 1, i64 5, i64 3, i64 4}
+; CHECK: !1 = !{!"branch_weights", i32 1, i32 5, i32 3, i32 4}

diff  --git a/llvm/test/Transforms/SampleProfile/entry_counts_cold.ll b/llvm/test/Transforms/SampleProfile/entry_counts_cold.ll
index 58b47e94db56..95dda320b1fd 100644
--- a/llvm/test/Transforms/SampleProfile/entry_counts_cold.ll
+++ b/llvm/test/Transforms/SampleProfile/entry_counts_cold.ll
@@ -1,4 +1,3 @@
-; RUN: opt < %s -passes=sample-profile -sample-profile-file=%S/Inputs/entry_counts_cold.prof -S | FileCheck %s
 ; RUN: opt < %s -sample-profile -sample-profile-file=%S/Inputs/entry_counts_cold.prof -S | FileCheck %s
 ; ModuleID = 'temp.bc'
 source_filename = "temp.c"

diff  --git a/llvm/test/Transforms/SampleProfile/indirect-call.ll b/llvm/test/Transforms/SampleProfile/indirect-call.ll
index c745d2a7f1fa..cc7fc7a75fbe 100644
--- a/llvm/test/Transforms/SampleProfile/indirect-call.ll
+++ b/llvm/test/Transforms/SampleProfile/indirect-call.ll
@@ -123,7 +123,7 @@ else:
 
 ; CHECK-LABEL: @branch_prof_valid
 ; Check the conditional branch generated by indirect call promotion won't
-; have invalid profile like !{!"branch_weights", i64 0, i64 0}.
+; have invalid profile like !{!"branch_weights", i32 0, i32 0}.
 define void @branch_prof_valid(void ()* %t0) #0 !dbg !33 {
   %t1 = alloca void ()*
   store void ()* %t0, void ()** %t1
@@ -200,10 +200,10 @@ attributes #0 = {"use-sample-profile"}
 !4 = !DILocation(line: 4, scope: !3)
 !5 = !DILocation(line: 6, scope: !3)
 ; CHECK: ![[PROF]] = !{!"VP", i32 0, i64 3457, i64 9191153033785521275, i64 2059, i64 -1069303473483922844, i64 1398}
-; CHECK: ![[BR1]] = !{!"branch_weights", i64 4000, i64 4000}
-; CHECK: ![[BR2]] = !{!"branch_weights", i64 3000, i64 1000}
+; CHECK: ![[BR1]] = !{!"branch_weights", i32 4000, i32 4000}
+; CHECK: ![[BR2]] = !{!"branch_weights", i32 3000, i32 1000}
 ; CHECK: ![[VP]] = !{!"VP", i32 0, i64 8000, i64 -6391416044382067764, i64 1000}
-; CHECK: ![[BR3]] = !{!"branch_weights", i64 1, i64 0}
+; CHECK: ![[BR3]] = !{!"branch_weights", i32 1, i32 0}
 !6 = distinct !DISubprogram(name: "test_inline", scope: !1, file: !1, line: 6, unit: !0)
 !7 = !DILocation(line: 7, scope: !6)
 !8 = distinct !DISubprogram(name: "test_inline_strip", scope: !1, file: !1, line: 8, unit: !0)

diff  --git a/llvm/test/Transforms/SampleProfile/inline-mergeprof-dup.ll b/llvm/test/Transforms/SampleProfile/inline-mergeprof-dup.ll
index 8a1718ed71cb..8d1379a58229 100644
--- a/llvm/test/Transforms/SampleProfile/inline-mergeprof-dup.ll
+++ b/llvm/test/Transforms/SampleProfile/inline-mergeprof-dup.ll
@@ -76,5 +76,5 @@ attributes #0 = { "use-sample-profile" }
 ;; Check the profile of funciton sum is only merged once though the original callsite is replicted.
 ; CHECK: name: "sum"
 ; CHECK-NEXT: {!"function_entry_count", i64 46}
-; CHECK: !{!"branch_weights", i64 11, i64 37}
-; CHECK: !{!"branch_weights", i64 11, i64 1}
+; CHECK: !{!"branch_weights", i32 11, i32 37}
+; CHECK: !{!"branch_weights", i32 11, i32 1}

diff  --git a/llvm/test/Transforms/SampleProfile/inline-mergeprof.ll b/llvm/test/Transforms/SampleProfile/inline-mergeprof.ll
index 9e7ba205f2bd..01d1ecb78a5e 100644
--- a/llvm/test/Transforms/SampleProfile/inline-mergeprof.ll
+++ b/llvm/test/Transforms/SampleProfile/inline-mergeprof.ll
@@ -90,14 +90,14 @@ declare i32 @printf(i8*, ...)
 
 ; SCALE: name: "sum"
 ; SCALE-NEXT: {!"function_entry_count", i64 46}
-; SCALE: !{!"branch_weights", i64 11, i64 2}
+; SCALE: !{!"branch_weights", i32 11, i32 2}
 ; SCALE: !{!"branch_weights", i64 20}
 ; SCALE: name: "sub"
 ; SCALE-NEXT: {!"function_entry_count", i64 -1}
 
 ; MERGE: name: "sum"
 ; MERGE-NEXT: {!"function_entry_count", i64 46}
-; MERGE: !{!"branch_weights", i64 11, i64 23}
-; MERGE: !{!"branch_weights", i64 10}
+; MERGE: !{!"branch_weights", i32 11, i32 23}
+; MERGE: !{!"branch_weights", i32 10}
 ; MERGE: name: "sub"
 ; MERGE-NEXT: {!"function_entry_count", i64 3}

diff  --git a/llvm/test/Transforms/SampleProfile/profile-format-compress.ll b/llvm/test/Transforms/SampleProfile/profile-format-compress.ll
index 7808b59ae41f..8303db8f8888 100644
--- a/llvm/test/Transforms/SampleProfile/profile-format-compress.ll
+++ b/llvm/test/Transforms/SampleProfile/profile-format-compress.ll
@@ -30,9 +30,9 @@
 ; CHECK: call i32 (i8*, ...) @printf{{.*}} !prof ![[IDX3:[0-9]*]]
 ; CHECK: = !{!"TotalCount", i64 26781}
 ; CHECK: = !{!"MaxCount", i64 5553}
-; CHECK: ![[IDX1]] = !{!"branch_weights", i64 5392, i64 163}
-; CHECK: ![[IDX2]] = !{!"branch_weights", i64 5280, i64 113}
-; CHECK: ![[IDX3]] = !{!"branch_weights", i64 1}
+; CHECK: ![[IDX1]] = !{!"branch_weights", i32 5392, i32 163}
+; CHECK: ![[IDX2]] = !{!"branch_weights", i32 5280, i32 113}
+; CHECK: ![[IDX3]] = !{!"branch_weights", i32 1}
 
 ; Function Attrs: nounwind uwtable
 define i32 @_Z3sumii(i32 %x, i32 %y) #0 !dbg !4 {

diff  --git a/llvm/test/Transforms/SampleProfile/profile-format.ll b/llvm/test/Transforms/SampleProfile/profile-format.ll
index fb6b73674a00..f00bc73511d8 100644
--- a/llvm/test/Transforms/SampleProfile/profile-format.ll
+++ b/llvm/test/Transforms/SampleProfile/profile-format.ll
@@ -32,9 +32,9 @@
 ; CHECK: call i32 (i8*, ...) @printf{{.*}} !prof ![[IDX3:[0-9]*]]
 ; CHECK: = !{!"TotalCount", i64 26781}
 ; CHECK: = !{!"MaxCount", i64 5553}
-; CHECK: ![[IDX1]] = !{!"branch_weights", i64 5392, i64 163}
-; CHECK: ![[IDX2]] = !{!"branch_weights", i64 5280, i64 113}
-; CHECK: ![[IDX3]] = !{!"branch_weights", i64 1}
+; CHECK: ![[IDX1]] = !{!"branch_weights", i32 5392, i32 163}
+; CHECK: ![[IDX2]] = !{!"branch_weights", i32 5280, i32 113}
+; CHECK: ![[IDX3]] = !{!"branch_weights", i32 1}
 
 ; Function Attrs: nounwind uwtable
 define i32 @_Z3sumii(i32 %x, i32 %y) #0 !dbg !4 {

diff  --git a/llvm/test/Transforms/SimpleLoopUnswitch/basictest-profmd.ll b/llvm/test/Transforms/SimpleLoopUnswitch/basictest-profmd.ll
index 5d7fd07dec4f..858088bee7cc 100644
--- a/llvm/test/Transforms/SimpleLoopUnswitch/basictest-profmd.ll
+++ b/llvm/test/Transforms/SimpleLoopUnswitch/basictest-profmd.ll
@@ -16,7 +16,7 @@ loop_begin:
   switch i32 %c, label %default [
       i32 1, label %inc
       i32 2, label %dec
-  ], !prof !{!"branch_weights", i64 99, i64 1, i64 2}
+  ], !prof !{!"branch_weights", i32 99, i32 1, i32 2}
 
 inc:
   call void @incf()
@@ -30,5 +30,5 @@ default:
   ret i32 0
 }
 
-; CHECK: ![[MD0]] = !{!"branch_weights", i64 99, i64 1, i64 2}
-; CHECK: ![[MD1]] = !{!"branch_weights", i64 2, i64 1}
+; CHECK: ![[MD0]] = !{!"branch_weights", i32 99, i32 1, i32 2}
+; CHECK: ![[MD1]] = !{!"branch_weights", i32 2, i32 1}

diff  --git a/llvm/test/Transforms/SimpleLoopUnswitch/trivial-unswitch-profmd.ll b/llvm/test/Transforms/SimpleLoopUnswitch/trivial-unswitch-profmd.ll
index 8dfdab290027..2deb9ce92628 100644
--- a/llvm/test/Transforms/SimpleLoopUnswitch/trivial-unswitch-profmd.ll
+++ b/llvm/test/Transforms/SimpleLoopUnswitch/trivial-unswitch-profmd.ll
@@ -47,7 +47,7 @@ loop_begin:
   i32 0, label %loop0
   i32 1, label %loop1
   i32 2, label %loop_exit2
-  ], !prof !{!"branch_weights", i64 99, i64 100, i64 101, i64 102}
+  ], !prof !{!"branch_weights", i32 99, i32 100, i32 101, i32 102}
 
 loop0:
   call void @some_func()
@@ -118,7 +118,7 @@ loop_begin:
   i32 0, label %loop0
   i32 1, label %loop1
   i32 2, label %loop2
-  ], !prof !{!"branch_weights", i64 99, i64 100, i64 101, i64 102}
+  ], !prof !{!"branch_weights", i32 99, i32 100, i32 101, i32 102}
 
 loop0:
   call void @some_func()
@@ -194,7 +194,7 @@ loop_begin:
   i32 13, label %loop_exit1
   i32 2, label %loop2
   i32 42, label %loop_exit3
-  ], !prof !{!"branch_weights", i64 99, i64 100, i64 101, i64 113, i64 102, i64 142}
+  ], !prof !{!"branch_weights", i32 99, i32 100, i32 101, i32 113, i32 102, i32 142}
 
 loop0:
   call void @some_func()
@@ -221,8 +221,8 @@ loop_exit3:
   ret i32 0
 }
 
-; CHECK: ![[MD0]] = !{!"branch_weights", i64 300, i64 102}
-; CHECK: ![[MD1]] = !{!"branch_weights", i64 99, i64 100, i64 101}
-; CHECK: ![[MD2]] = !{!"branch_weights", i64 99, i64 100, i64 101, i64 102}
-; CHECK: ![[MD3]] = !{!"branch_weights", i64 102, i64 100, i64 101}
-; CHECK: ![[MD4]] = !{!"branch_weights", i64 99, i64 113, i64 142, i64 100, i64 101, i64 102}
+; CHECK: ![[MD0]] = !{!"branch_weights", i32 300, i32 102}
+; CHECK: ![[MD1]] = !{!"branch_weights", i32 99, i32 100, i32 101}
+; CHECK: ![[MD2]] = !{!"branch_weights", i32 99, i32 100, i32 101, i32 102}
+; CHECK: ![[MD3]] = !{!"branch_weights", i32 102, i32 100, i32 101}
+; CHECK: ![[MD4]] = !{!"branch_weights", i32 99, i32 113, i32 142, i32 100, i32 101, i32 102}

diff  --git a/llvm/test/Transforms/SimplifyCFG/invoke_unwind.ll b/llvm/test/Transforms/SimplifyCFG/invoke_unwind.ll
index eb5db55078fb..8559cda24358 100644
--- a/llvm/test/Transforms/SimplifyCFG/invoke_unwind.ll
+++ b/llvm/test/Transforms/SimplifyCFG/invoke_unwind.ll
@@ -17,7 +17,7 @@ Rethrow:
         resume { i8*, i32 } %exn
 }
 
-!0 = !{!"branch_weights", i64 369, i64 2}
+!0 = !{!"branch_weights", i32 369, i32 2}
 
 define i32 @test2() personality i32 (...)* @__gxx_personality_v0 {
 ; CHECK-LABEL: @test2(
@@ -76,4 +76,4 @@ lpad2:
 
 declare i32 @__gxx_personality_v0(...)
 
-; CHECK: ![[PROF]] = !{!"branch_weights", i64 371}
+; CHECK: ![[PROF]] = !{!"branch_weights", i32 371}

diff  --git a/llvm/test/Transforms/SimplifyCFG/preserve-branchweights-switch-create.ll b/llvm/test/Transforms/SimplifyCFG/preserve-branchweights-switch-create.ll
index ad34488aade9..32a30c3cab4f 100644
--- a/llvm/test/Transforms/SimplifyCFG/preserve-branchweights-switch-create.ll
+++ b/llvm/test/Transforms/SimplifyCFG/preserve-branchweights-switch-create.ll
@@ -129,12 +129,12 @@ sw.epilog:
   ret void
 }
 
-!0 = !{!"branch_weights", i64 64, i64 4}
-!1 = !{!"branch_weights", i64 4, i64 64}
-; CHECK: !0 = !{!"branch_weights", i64 256, i64 4352, i64 16}
-!2 = !{!"branch_weights", i64 4, i64 4, i64 8}
-!3 = !{!"branch_weights", i64 8, i64 8, i64 4}
-; CHECK: !1 = !{!"branch_weights", i64 32, i64 48, i64 96, i64 16}
-!4 = !{!"branch_weights", i64 7, i64 6, i64 4, i64 3}
-!5 = !{!"branch_weights", i64 17, i64 13, i64 9}
-; CHECK: !3 = !{!"branch_weights", i64 7, i64 3, i64 4, i64 6}
+!0 = !{!"branch_weights", i32 64, i32 4}
+!1 = !{!"branch_weights", i32 4, i32 64}
+; CHECK: !0 = !{!"branch_weights", i32 256, i32 4352, i32 16}
+!2 = !{!"branch_weights", i32 4, i32 4, i32 8}
+!3 = !{!"branch_weights", i32 8, i32 8, i32 4}
+; CHECK: !1 = !{!"branch_weights", i32 32, i32 48, i32 96, i32 16}
+!4 = !{!"branch_weights", i32 7, i32 6, i32 4, i32 3}
+!5 = !{!"branch_weights", i32 17, i32 13, i32 9}
+; CHECK: !3 = !{!"branch_weights", i32 7, i32 3, i32 4, i32 6}

diff  --git a/llvm/test/Transforms/SimplifyCFG/preserve-branchweights.ll b/llvm/test/Transforms/SimplifyCFG/preserve-branchweights.ll
index c83ba3cf8f65..66a34bab3e5b 100644
--- a/llvm/test/Transforms/SimplifyCFG/preserve-branchweights.ll
+++ b/llvm/test/Transforms/SimplifyCFG/preserve-branchweights.ll
@@ -636,38 +636,40 @@ exit:
   ret i32 %outval
 }
 
-!0 = !{!"branch_weights", i64 3, i64 5}
-!1 = !{!"branch_weights", i64 1, i64 1}
-!2 = !{!"branch_weights", i64 1, i64 2}
-!3 = !{!"branch_weights", i64 4, i64 3, i64 2, i64 1}
-!4 = !{!"branch_weights", i64 4, i64 3, i64 2, i64 1}
-!5 = !{!"branch_weights", i64 7, i64 6, i64 5}
-!6 = !{!"branch_weights", i64 1, i64 3}
-!7 = !{!"branch_weights", i64 33, i64 9, i64 8, i64 7}
-!8 = !{!"branch_weights", i64 33, i64 9, i64 8}
-!9 = !{!"branch_weights", i64 7, i64 6}
-!10 = !{!"branch_weights", i64 672646, i64 21604207}
-!11 = !{!"branch_weights", i64 6960, i64 21597248}
-!12 = !{!"these_are_not_the_branch_weights_you_are_looking_for", i64 3, i64 5}
-!13 = !{!"branch_weights", i64 2, i64 3}
-!14 = !{!"branch_weights", i64 4, i64 7}
-
-; CHECK: !0 = !{!"branch_weights", i64 5, i64 11}
-; CHECK: !1 = !{!"branch_weights", i64 1, i64 3}
-; CHECK: !2 = !{!"branch_weights", i64 1, i64 5}
-; CHECK: !3 = !{!"branch_weights", i64 7, i64 1, i64 2}
-; CHECK: !4 = !{!"branch_weights", i64 49, i64 12, i64 24, i64 35}
-; CHECK: !5 = !{!"branch_weights", i64 11, i64 5}
-; CHECK: !6 = !{!"branch_weights", i64 17, i64 15}
-; CHECK: !7 = !{!"branch_weights", i64 9, i64 7}
-; CHECK: !8 = !{!"branch_weights", i64 17, i64 9, i64 8, i64 7, i64 17}
-; CHECK: !9 = !{!"branch_weights", i64 24, i64 33}
-; CHECK: !10 = !{!"branch_weights", i64 8, i64 33}
-; CHECK: !11 = !{!"branch_weights", i64 14682349375088, i64 466591416422336}
-; CHECK: !12 = !{!"branch_weights", i64 3, i64 5}
-; CHECK: !13 = !{!"branch_weights", i64 22, i64 12}
-; CHECK: !14 = !{!"branch_weights", i64 34, i64 21}
-; CHECK: !15 = !{!"branch_weights", i64 33, i64 14}
-; CHECK: !16 = !{!"branch_weights", i64 47, i64 8}
-; CHECK: !17 = !{!"branch_weights", i64 6, i64 2}
-; CHECK: !18 = !{!"branch_weights", i64 8, i64 2}
+!0 = !{!"branch_weights", i32 3, i32 5}
+!1 = !{!"branch_weights", i32 1, i32 1}
+!2 = !{!"branch_weights", i32 1, i32 2}
+!3 = !{!"branch_weights", i32 4, i32 3, i32 2, i32 1}
+!4 = !{!"branch_weights", i32 4, i32 3, i32 2, i32 1}
+!5 = !{!"branch_weights", i32 7, i32 6, i32 5}
+!6 = !{!"branch_weights", i32 1, i32 3}
+!7 = !{!"branch_weights", i32 33, i32 9, i32 8, i32 7}
+!8 = !{!"branch_weights", i32 33, i32 9, i32 8}
+!9 = !{!"branch_weights", i32 7, i32 6}
+!10 = !{!"branch_weights", i32 672646, i32 21604207}
+!11 = !{!"branch_weights", i32 6960, i32 21597248}
+!12 = !{!"these_are_not_the_branch_weights_you_are_looking_for", i32 3, i32 5}
+!13 = !{!"branch_weights", i32 2, i32 3}
+!14 = !{!"branch_weights", i32 4, i32 7}
+
+; CHECK: !0 = !{!"branch_weights", i32 5, i32 11}
+; CHECK: !1 = !{!"branch_weights", i32 1, i32 3}
+; CHECK: !2 = !{!"branch_weights", i32 1, i32 5}
+; CHECK: !3 = !{!"branch_weights", i32 7, i32 1, i32 2}
+; CHECK: !4 = !{!"branch_weights", i32 49, i32 12, i32 24, i32 35}
+; CHECK: !5 = !{!"branch_weights", i32 11, i32 5}
+; CHECK: !6 = !{!"branch_weights", i32 17, i32 15}
+; CHECK: !7 = !{!"branch_weights", i32 9, i32 7}
+; CHECK: !8 = !{!"branch_weights", i32 17, i32 9, i32 8, i32 7, i32 17}
+; CHECK: !9 = !{!"branch_weights", i32 24, i32 33}
+; CHECK: !10 = !{!"branch_weights", i32 8, i32 33}
+;; The false weight prints out as a negative integer here, but inside llvm, we
+;; treat the weight as an unsigned integer.
+; CHECK: !11 = !{!"branch_weights", i32 112017436, i32 -735157296}
+; CHECK: !12 = !{!"branch_weights", i32 3, i32 5}
+; CHECK: !13 = !{!"branch_weights", i32 22, i32 12}
+; CHECK: !14 = !{!"branch_weights", i32 34, i32 21}
+; CHECK: !15 = !{!"branch_weights", i32 33, i32 14}
+; CHECK: !16 = !{!"branch_weights", i32 47, i32 8}
+; CHECK: !17 = !{!"branch_weights", i32 6, i32 2}
+; CHECK: !18 = !{!"branch_weights", i32 8, i32 2}

diff  --git a/llvm/test/Transforms/SimplifyCFG/switch-profmd.ll b/llvm/test/Transforms/SimplifyCFG/switch-profmd.ll
index cb62173500d0..c17214e18f20 100644
--- a/llvm/test/Transforms/SimplifyCFG/switch-profmd.ll
+++ b/llvm/test/Transforms/SimplifyCFG/switch-profmd.ll
@@ -12,7 +12,7 @@ define i32 @test_switch_to_unreachable(i32 %val) {
     i32 0, label %on0
     i32 1, label %on1
     i32 2, label %on2
-  ], !prof !{!"branch_weights", i64 99, i64 0, i64 1, i64 2}
+  ], !prof !{!"branch_weights", i32 99, i32 0, i32 1, i32 2}
 ; CHECK: !prof ![[MD0:[0-9]+]]
 
 otherwise:
@@ -32,4 +32,4 @@ on2:
   ret i32 %result2
 }
 
-; CHECK: ![[MD0]] = !{!"branch_weights", i64 99, i64 2, i64 1}
+; CHECK: ![[MD0]] = !{!"branch_weights", i32 99, i32 2, i32 1}

diff  --git a/llvm/test/Transforms/Util/libcalls-shrinkwrap-double.ll b/llvm/test/Transforms/Util/libcalls-shrinkwrap-double.ll
index 2d4cdfe5bb84..d015a9d4d601 100644
--- a/llvm/test/Transforms/Util/libcalls-shrinkwrap-double.ll
+++ b/llvm/test/Transforms/Util/libcalls-shrinkwrap-double.ll
@@ -238,4 +238,4 @@ define void @test_pow(i32 %int_val, double %exp) {
 
 declare double @pow(double, double)
 
-; CHECK: ![[BRANCH_WEIGHT]] = !{!"branch_weights", i64 1, i64 2000}
+; CHECK: ![[BRANCH_WEIGHT]] = !{!"branch_weights", i32 1, i32 2000}

diff  --git a/llvm/test/Transforms/Util/libcalls-shrinkwrap-float.ll b/llvm/test/Transforms/Util/libcalls-shrinkwrap-float.ll
index 52c894455542..4affc006e38f 100644
--- a/llvm/test/Transforms/Util/libcalls-shrinkwrap-float.ll
+++ b/llvm/test/Transforms/Util/libcalls-shrinkwrap-float.ll
@@ -188,4 +188,4 @@ declare float @log2f(float)
 declare float @logbf(float)
 declare float @log1pf(float)
 
-; CHECK: ![[BRANCH_WEIGHT]] = !{!"branch_weights", i64 1, i64 2000}
+; CHECK: ![[BRANCH_WEIGHT]] = !{!"branch_weights", i32 1, i32 2000}

diff  --git a/llvm/test/Transforms/Util/libcalls-shrinkwrap-long-double.ll b/llvm/test/Transforms/Util/libcalls-shrinkwrap-long-double.ll
index 24278cbd921c..54a31e5173f5 100644
--- a/llvm/test/Transforms/Util/libcalls-shrinkwrap-long-double.ll
+++ b/llvm/test/Transforms/Util/libcalls-shrinkwrap-long-double.ll
@@ -189,4 +189,4 @@ declare x86_fp80 @log2l(x86_fp80)
 declare x86_fp80 @logbl(x86_fp80)
 declare x86_fp80 @log1pl(x86_fp80)
 
-; CHECK: ![[BRANCH_WEIGHT]] = !{!"branch_weights", i64 1, i64 2000}
+; CHECK: ![[BRANCH_WEIGHT]] = !{!"branch_weights", i32 1, i32 2000}

diff  --git a/llvm/unittests/Analysis/ProfileSummaryInfoTest.cpp b/llvm/unittests/Analysis/ProfileSummaryInfoTest.cpp
index e6818c1ffadc..f36d3ba99775 100644
--- a/llvm/unittests/Analysis/ProfileSummaryInfoTest.cpp
+++ b/llvm/unittests/Analysis/ProfileSummaryInfoTest.cpp
@@ -339,7 +339,7 @@ TEST_F(ProfileSummaryInfoTest, SampleProf) {
   CallBase &CS1 = cast<CallBase>(*BB1->getFirstNonPHI());
   auto *CI2 = BB2->getFirstNonPHI();
   // Manually attach branch weights metadata to the call instruction.
-  SmallVector<uint64_t, 1> Weights;
+  SmallVector<uint32_t, 1> Weights;
   Weights.push_back(1000);
   MDBuilder MDB(M->getContext());
   CI2->setMetadata(LLVMContext::MD_prof, MDB.createBranchWeights(Weights));

diff  --git a/mlir/test/Target/llvmir.mlir b/mlir/test/Target/llvmir.mlir
index 31d5ecf0a551..89f71477325d 100644
--- a/mlir/test/Target/llvmir.mlir
+++ b/mlir/test/Target/llvmir.mlir
@@ -1265,7 +1265,7 @@ llvm.func @cond_br_weights(%cond : !llvm.i1, %arg0 : !llvm.i32,  %arg1 : !llvm.i
   llvm.return %arg1 : !llvm.i32
 }
 
-// CHECK: ![[NODE]] = !{!"branch_weights", i64 5, i64 10}
+// CHECK: ![[NODE]] = !{!"branch_weights", i32 5, i32 10}
 
 // -----
 


        


More information about the llvm-commits mailing list