[llvm] 2e9fd75 - [SCEV] Handle ULE in applyLoopGuards.

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Sat Oct 10 08:27:51 PDT 2020


Author: Florian Hahn
Date: 2020-10-10T16:26:28+01:00
New Revision: 2e9fd754b41cba2253c066e9e8a7ab4770432550

URL: https://github.com/llvm/llvm-project/commit/2e9fd754b41cba2253c066e9e8a7ab4770432550
DIFF: https://github.com/llvm/llvm-project/commit/2e9fd754b41cba2253c066e9e8a7ab4770432550.diff

LOG: [SCEV] Handle ULE in applyLoopGuards.

Handle ULE predicate in similar fashion to ULT predicate in
applyLoopGuards.

Added: 
    

Modified: 
    llvm/lib/Analysis/ScalarEvolution.cpp
    llvm/test/Analysis/ScalarEvolution/max-backedge-taken-count-guard-info.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp
index 7e69af2e4a95..899fb44a7769 100644
--- a/llvm/lib/Analysis/ScalarEvolution.cpp
+++ b/llvm/lib/Analysis/ScalarEvolution.cpp
@@ -12754,6 +12754,16 @@ const SCEV *ScalarEvolution::applyLoopGuards(const SCEV *Expr, const Loop *L) {
       }
       break;
     }
+    case CmpInst::ICMP_ULE: {
+      if (!containsAddRecurrence(RHS)) {
+        const SCEV *Base = LHS;
+        auto I = RewriteMap.find(LHSUnknown->getValue());
+        if (I != RewriteMap.end())
+          Base = I->second;
+        RewriteMap[LHSUnknown->getValue()] = getUMinExpr(Base, RHS);
+      }
+      break;
+    }
     case CmpInst::ICMP_EQ:
       if (isa<SCEVConstant>(RHS))
         RewriteMap[LHSUnknown->getValue()] = RHS;

diff  --git a/llvm/test/Analysis/ScalarEvolution/max-backedge-taken-count-guard-info.ll b/llvm/test/Analysis/ScalarEvolution/max-backedge-taken-count-guard-info.ll
index 020d9d3a74f4..f961c83808a3 100644
--- a/llvm/test/Analysis/ScalarEvolution/max-backedge-taken-count-guard-info.ll
+++ b/llvm/test/Analysis/ScalarEvolution/max-backedge-taken-count-guard-info.ll
@@ -116,7 +116,7 @@ exit:
 define void @test_guard_ule_12(i32* nocapture %a, i64 %N) {
 ; CHECK-LABEL: Determining loop execution counts for: @test_guard_ule_12
 ; CHECK-NEXT:  Loop %loop: backedge-taken count is %N
-; CHECK-NEXT:  Loop %loop: max backedge-taken count is -1
+; CHECK-NEXT:  Loop %loop: max backedge-taken count is 12
 ; CHECK-NEXT:  Loop %loop: Predicated backedge-taken count is %N
 ;
 entry:


        


More information about the llvm-commits mailing list