[llvm] [LoopRotate] Set loop back edge weight to not less than exit weight (PR #86496)
Haohai Wen via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 27 23:57:12 PDT 2024
================
@@ -347,9 +347,19 @@ static void updateBranchWeights(BranchInst &PreHeaderBI, BranchInst &LoopBI,
// probabilities as if there are only 0-trip and 1-trip cases.
ExitWeight0 = OrigLoopExitWeight - OrigLoopBackedgeWeight;
}
+ } else {
+ if (OrigLoopExitWeight > OrigLoopBackedgeWeight) {
+ LLVM_DEBUG(
+ dbgs() << "WARNING: Bad loop back edge weight. Adjust it from "
+ << OrigLoopBackedgeWeight << " to " << OrigLoopExitWeight
+ << "\n");
----------------
HaohaiWen wrote:
The heuristic wasn't based on guessing. I think those three expressions were bullet proofed (@MatzeB , please correct me if I am wrong). It just have a pre request the profile data is accurate. What I'm trying is to fix inaccurate profile data.
```
// - x == x0 + x1 # counts to "exit" must stay the same.
// - y0 == x - x0 == x1 # how often loop was entered at all.
// - y1 == y - y0 # How often loop was repeated (after first iter.).
```
https://github.com/llvm/llvm-project/pull/86496
More information about the llvm-commits
mailing list