[llvm] [LoopPeel] Remove known trip count restriction when peeling last. (PR #140792)

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Fri May 23 09:01:56 PDT 2025


================
@@ -360,12 +357,17 @@ bool llvm::canPeelLastIteration(const Loop &L, ScalarEvolution &SE) {
 /// is known at the second-to-last.
 static bool shouldPeelLastIteration(Loop &L, CmpPredicate Pred,
                                     const SCEVAddRecExpr *LeftAR,
-                                    const SCEV *RightSCEV,
-                                    ScalarEvolution &SE) {
+                                    const SCEV *RightSCEV, ScalarEvolution &SE,
+                                    const TargetTransformInfo &TTI) {
   if (!canPeelLastIteration(L, SE))
     return false;
 
   const SCEV *BTC = SE.getBackedgeTakenCount(&L);
+  SCEVExpander Expander(SE, L.getHeader()->getDataLayout(), "loop-peel");
+  if (!SE.isKnownNonZero(BTC) && Expander.isHighCostExpansion(BTC, &L, SCEVCheapExpansionBudget, &TTI,
----------------
fhahn wrote:

Put up a separate patch: https://github.com/llvm/llvm-project/pull/141247

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


More information about the llvm-commits mailing list