[llvm] 7d274aa - [SCEV] Add support for `x != 0` to CollectCondition.

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 25 11:00:01 PDT 2020


Author: Florian Hahn
Date: 2020-09-25T18:58:55+01:00
New Revision: 7d274aa9bed00cdf1197b2f05140635be90f3362

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

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

Add support for NE predicates with 0 constants. Those can be translated
to UMaxExpr(x, 1).

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 8c6231b0f4a0..42043f93e27e 100644
--- a/llvm/lib/Analysis/ScalarEvolution.cpp
+++ b/llvm/lib/Analysis/ScalarEvolution.cpp
@@ -12622,6 +12622,12 @@ const SCEV *ScalarEvolution::applyLoopGuards(const SCEV *Expr, const Loop *L) {
       if (isa<SCEVConstant>(RHS))
         RewriteMap[LHSUnknown->getValue()] = RHS;
       break;
+    case CmpInst::ICMP_NE:
+      if (isa<SCEVConstant>(RHS) &&
+          cast<SCEVConstant>(RHS)->getValue()->isNullValue())
+        RewriteMap[LHSUnknown->getValue()] =
+            getUMaxExpr(LHS, getOne(RHS->getType()));
+      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 4f529eb4ea4b..52ae3c902c3a 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
@@ -249,7 +249,7 @@ exit:
 define void @test_guard_ult_ne(i32* nocapture readonly %data, i64 %count) {
 ; CHECK-LABEL: @test_guard_ult_ne
 ; 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