[PATCH] D109682: [LoopBoundSplit] Check the condition of the first iteration in pre-loop using isLoopEntryGuardedByCond

JinGu Kang via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 21 07:48:30 PDT 2021


jaykang10 updated this revision to Diff 373933.
jaykang10 added a comment.

Following comment of @mkazantsev, updated patch.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D109682/new/

https://reviews.llvm.org/D109682

Files:
  llvm/lib/Transforms/Scalar/LoopBoundSplit.cpp


Index: llvm/lib/Transforms/Scalar/LoopBoundSplit.cpp
===================================================================
--- llvm/lib/Transforms/Scalar/LoopBoundSplit.cpp
+++ llvm/lib/Transforms/Scalar/LoopBoundSplit.cpp
@@ -43,7 +43,7 @@
   /// Bound llvm value
   Value *BoundValue;
   /// AddRec SCEV
-  const SCEV *AddRecSCEV;
+  const SCEVAddRecExpr *AddRecSCEV;
   /// Bound SCEV
   const SCEV *BoundSCEV;
 
@@ -59,15 +59,19 @@
   Cond.ICmp = ICmp;
   if (match(ICmp, m_ICmp(Cond.Pred, m_Value(Cond.AddRecValue),
                          m_Value(Cond.BoundValue)))) {
-    Cond.AddRecSCEV = SE.getSCEV(Cond.AddRecValue);
-    Cond.BoundSCEV = SE.getSCEV(Cond.BoundValue);
+    const SCEV *AddRecSCEV = SE.getSCEV(Cond.AddRecValue);
+    const SCEV *BoundSCEV = SE.getSCEV(Cond.BoundValue);
+    const SCEVAddRecExpr *LHSAddRecSCEV = dyn_cast<SCEVAddRecExpr>(AddRecSCEV);
+    const SCEVAddRecExpr *RHSAddRecSCEV = dyn_cast<SCEVAddRecExpr>(BoundSCEV);
     // Locate AddRec in LHSSCEV and Bound in RHSSCEV.
-    if (isa<SCEVAddRecExpr>(Cond.BoundSCEV) &&
-        !isa<SCEVAddRecExpr>(Cond.AddRecSCEV)) {
+    if (!LHSAddRecSCEV && RHSAddRecSCEV) {
       std::swap(Cond.AddRecValue, Cond.BoundValue);
-      std::swap(Cond.AddRecSCEV, Cond.BoundSCEV);
+      std::swap(AddRecSCEV, BoundSCEV);
       Cond.Pred = ICmpInst::getSwappedPredicate(Cond.Pred);
     }
+
+    Cond.AddRecSCEV = dyn_cast<SCEVAddRecExpr>(AddRecSCEV);
+    Cond.BoundSCEV = BoundSCEV;
   }
 }
 
@@ -125,15 +129,14 @@
   if (!SE.isAvailableAtLoopEntry(Cond.BoundSCEV, &L))
     return false;
 
-  const SCEVAddRecExpr *AddRecSCEV = dyn_cast<SCEVAddRecExpr>(Cond.AddRecSCEV);
   // Allowed AddRec as induction variable.
-  if (!AddRecSCEV)
+  if (!Cond.AddRecSCEV)
     return false;
 
-  if (!AddRecSCEV->isAffine())
+  if (!Cond.AddRecSCEV->isAffine())
     return false;
 
-  const SCEV *StepRecSCEV = AddRecSCEV->getStepRecurrence(SE);
+  const SCEV *StepRecSCEV = Cond.AddRecSCEV->getStepRecurrence(SE);
   // Allowed constant step.
   if (!isa<SCEVConstant>(StepRecSCEV))
     return false;
@@ -268,10 +271,9 @@
     // After transformation, we assume the split condition of the pre-loop is
     // always true. In order to guarantee it, we need to check the start value
     // of the split cond AddRec satisfies the split condition.
-    const SCEV *SplitAddRecStartSCEV =
-        cast<SCEVAddRecExpr>(SplitCandidateCond.AddRecSCEV)->getStart();
-    if (!SE.isKnownPredicate(SplitCandidateCond.Pred, SplitAddRecStartSCEV,
-                             SplitCandidateCond.BoundSCEV))
+    if (!SE.isLoopEntryGuardedByCond(&L, SplitCandidateCond.Pred,
+                                     SplitCandidateCond.AddRecSCEV->getStart(),
+                                     SplitCandidateCond.BoundSCEV))
       continue;
 
     SplitCandidateCond.BI = BI;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D109682.373933.patch
Type: text/x-patch
Size: 2839 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210921/3c12201f/attachment.bin>


More information about the llvm-commits mailing list