[llvm] [Transforms][Utils] Preserve branch weights in LoopSplitUtils (PR #213626)
Ashutosh Nema via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 3 02:50:00 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)) {
----------------
nema-ashutosh wrote:
Sure, switched to the extractBranchWeights overload, and also moved to setFittedBranchWeights to avoid the narrowing cast. hope its OK !
https://github.com/llvm/llvm-project/pull/213626
More information about the llvm-commits
mailing list