[llvm] [VPlan] Preserve branch weights from VPlan0 through to codegen. (PR #213143)

Mircea Trofin via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 17 10:33:15 PDT 2026


================
@@ -112,6 +114,23 @@ class VPPredicator {
 };
 } // namespace
 
+/// Returns the branch weights describing how often a block executing with
+/// probability \p Prob is entered, or nullptr if \p Prob carries no useful
+/// information, i.e. the block is never or always executed, or its probability
+/// is unknown.
+static MDNode *getWeightsForProbability(BranchProbability Prob,
----------------
mtrofin wrote:

For readability, would it make sense to use a local metadata value instead of MD_prof? IIUC the idea is to use the existing mechanism in VPlan for carrying metadata, and in this case the metadata would be pairs of i32 codifying the probability of executing a VPlan Block or Instruction. There are some differences from the IR MD_prof, iiuc:

- any VPlan instruction can carry these
- MD_prof encodes 2 complementary probabilities (well, OK, N in the case of `select`s). Here, we really mean to encode one probability, `first_number / (first_number + second_number)`


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


More information about the llvm-commits mailing list