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

David Li via cfe-commits cfe-commits at lists.llvm.org
Wed Jun 12 13:19:11 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());
----------------
david-xl wrote:

How can we prevent this in the future? Is it possible to put branch origin data at the end? If not, probably better introduce some helper to get branch weight instead of doing getOperand(getBranchWeightOffset(..)).

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


More information about the cfe-commits mailing list