[llvm] 0ad793f - [SCEV] Also use info from assumes in applyLoopGuards.

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 28 05:14:56 PDT 2020


Author: Florian Hahn
Date: 2020-09-28T13:14:24+01:00
New Revision: 0ad793f321ed8714870cacf0421e60cf9a3b7468

URL: https://github.com/llvm/llvm-project/commit/0ad793f321ed8714870cacf0421e60cf9a3b7468
DIFF: https://github.com/llvm/llvm-project/commit/0ad793f321ed8714870cacf0421e60cf9a3b7468.diff

LOG: [SCEV] Also use info from assumes in applyLoopGuards.

Similar to collecting information from branches guarding a loop, we can
also collect information from assumes dominating the loop header.

Fixes PR47247.

Reviewed By: jdoerfert

Differential Revision: https://reviews.llvm.org/D87854

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 42043f93e27e..e6ece25c12f2 100644
--- a/llvm/lib/Analysis/ScalarEvolution.cpp
+++ b/llvm/lib/Analysis/ScalarEvolution.cpp
@@ -12658,6 +12658,18 @@ const SCEV *ScalarEvolution::applyLoopGuards(const SCEV *Expr, const Loop *L) {
                      getSCEV(Cmp->getOperand(1)), RewriteMap);
   }
 
+  // Also collect information from assumptions dominating the loop.
+  for (auto &AssumeVH : AC.assumptions()) {
+    if (!AssumeVH)
+      continue;
+    auto *AssumeI = cast<CallInst>(AssumeVH);
+    auto *Cmp = dyn_cast<ICmpInst>(AssumeI->getOperand(0));
+    if (!Cmp || !DT.dominates(AssumeI, L->getHeader()))
+      continue;
+    CollectCondition(Cmp->getPredicate(), getSCEV(Cmp->getOperand(0)),
+                     getSCEV(Cmp->getOperand(1)), RewriteMap);
+  }
+
   if (RewriteMap.empty())
     return Expr;
   return SCEVParameterRewriter::rewrite(Expr, *this, RewriteMap);

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 52ae3c902c3a..0cdd2d77313a 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
@@ -278,7 +278,7 @@ exit:
 define void @test_guard_and_assume(i32* nocapture readonly %data, i64 %count) {
 ; CHECK-LABEL: @test_guard_and_assume
 ; CHECK:       Loop %loop: backedge-taken count is (-1 + %count)
-; CHECK-NEXT:  Loop %loop: max backedge-taken count is -2
+; CHECK-NEXT:  Loop %loop: max backedge-taken count is 3
 ; CHECK-NEXT:  Loop %loop: Predicated backedge-taken count is (-1 + %count)
 ;
 entry:


        


More information about the llvm-commits mailing list