[clang] [llvm] Reapply "[llvm][IR] Extend BranchWeightMetadata to track provenance o… (PR #95281)

Paul Kirth via cfe-commits cfe-commits at lists.llvm.org
Wed Jun 12 13:27:57 PDT 2024


================
@@ -241,9 +264,11 @@ void scaleProfData(Instruction &I, uint64_t S, uint64_t T) {
   if (ProfDataName->getString() == "branch_weights" &&
       ProfileData->getNumOperands() > 0) {
     // Using APInt::div may be expensive, but most cases should fit 64 bits.
-    APInt Val(128, mdconst::dyn_extract<ConstantInt>(ProfileData->getOperand(1))
-                       ->getValue()
-                       .getZExtValue());
+    APInt Val(128,
+              mdconst::dyn_extract<ConstantInt>(
+                  ProfileData->getOperand(getBranchWeightOffset(ProfileData)))
+                  ->getValue()
+                  .getZExtValue());
----------------
ilovepi wrote:

I think between the existing ‘getBranchWeights’ and the ‘getNumBranches’ in https://github.com/llvm/llvm-project/pull/90146 we should be able to avoid most issues. 

Ideally, the only place that should be setting the operand directly would be things in this file. 

Let me take a pass over the existing users outside of this file to see if there is a way to do that. 

https://github.com/llvm/llvm-project/pull/95281


More information about the cfe-commits mailing list