[llvm] [LoopRotate] Set loop back edge weight to not less than exit weight (PR #86496)

via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 28 00:01:56 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");
----------------
WenleiHe wrote:

> The heuristic wasn't based on guessing. I think those three expressions were bullet proofed

I was referring to the existing heuristic. With loop rotate, you cannot recover ground truth counts. And you have to make assumptions like "as if 0-trip count nearly never happens"/ "as if there are only 0-trip and 1-trip cases".

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


More information about the llvm-commits mailing list