[llvm] b5a3b90 - [SCEV] Add support for `x == constant` to CollectCondition.

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 25 08:57:15 PDT 2020


Author: Florian Hahn
Date: 2020-09-25T16:56:49+01:00
New Revision: b5a3b901c73082c82f6eb387323cd61525423e2d

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

LOG: [SCEV] Add support for `x == constant` to CollectCondition.

Add support for EQ predicates with constant operand. In that case, using
the constant instead of an unknown expression should always be
beneficial.

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 ddca61e996e3..8c6231b0f4a0 100644
--- a/llvm/lib/Analysis/ScalarEvolution.cpp
+++ b/llvm/lib/Analysis/ScalarEvolution.cpp
@@ -12618,6 +12618,10 @@ const SCEV *ScalarEvolution::applyLoopGuards(const SCEV *Expr, const Loop *L) {
       }
       break;
     }
+    case CmpInst::ICMP_EQ:
+      if (isa<SCEVConstant>(RHS))
+        RewriteMap[LHSUnknown->getValue()] = RHS;
+      break;
     default:
       break;
     }

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 4696801a0695..3e6cbacff964 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
@@ -94,7 +94,7 @@ exit:
 define void @test_guard_eq_12(i32* nocapture %a, i64 %N) {
 ; CHECK-LABEL: Determining loop execution counts for: @test_guard_eq_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