[llvm] [LoopUnroll] Use branch probability in multi-exit loop unrolling (PR #164799)

Marek Sedláček via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 12 05:36:41 PST 2026


================
@@ -482,10 +482,53 @@ CloneLoopBlocks(Loop *L, Value *NewIter, const bool UseEpilogRemainder,
   return NewLoop;
 }
 
+// Calculates the edge probability from Src to Dst.
+// Dst has to be a successor to Src.
+// This uses branch_probability metadata directly. If data are missing or
+// probability cannot be computed, then std::nullopt is returned.
+// This does not use BranchProbabilityInfo and the values computed by this
+// will vary from BPI because BPI has its own more advanced heuristics to
+// determine probabilities without metadata.
+static std::optional<BranchProbability>
+computeBranchProbabilityUsingMetadata(BasicBlock *Src, BasicBlock *Dst) {
----------------
mark-sed wrote:

Yeah that sounds reasonable, I'll look into that.

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


More information about the llvm-commits mailing list