[llvm] [Transforms][Utils] Preserve branch weights in LoopSplitUtils (PR #213626)

Ramkumar Ramachandra via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 3 02:54:56 PDT 2026


================
@@ -506,7 +507,17 @@ static void rewriteLatch(Loop *PL, Value *IndOp, Value *SelEnd,
                                                /*Inclusive=*/!LatchComparesPHI);
   Value *NewCmp = B.CreateICmp(Pred, IndOp, Bound, "itr.chk");
   B.SetInsertPoint(Term);
-  B.CreateCondBr(NewCmp, PL->getHeader(), Exit);
+  auto *NewBr = B.CreateCondBr(NewCmp, PL->getHeader(), Exit);
+  // Carry the original latch's branch weights onto the clamped latch, matching
+  // by which original successor stayed in the loop (the "keep iterating" edge).
+  SmallVector<uint32_t, 2> Weights;
+  if (extractBranchWeights(*Term, Weights)) {
----------------
artagnon wrote:

Merging. By the way, if you can expose your email on GitHub, that would be good -- we generally don't prefer github-noreply emails in commit logs?

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


More information about the llvm-commits mailing list