[llvm] bb8c7a9 - [ScalarEvolution] Make isKnownNonZero handle more cases.

Eli Friedman via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 13 15:37:18 PDT 2021


Author: Eli Friedman
Date: 2021-07-13T15:36:45-07:00
New Revision: bb8c7a980fe487eb322d38641db9145a6b6cb1d4

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

LOG: [ScalarEvolution] Make isKnownNonZero handle more cases.

Using an unsigned range instead of signed ranges is a bit more precise.

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

Added: 
    

Modified: 
    llvm/lib/Analysis/ScalarEvolution.cpp
    llvm/test/Analysis/ScalarEvolution/trip-count9.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp
index b3eaa66f6d6ac..99647bf86073c 100644
--- a/llvm/lib/Analysis/ScalarEvolution.cpp
+++ b/llvm/lib/Analysis/ScalarEvolution.cpp
@@ -9822,7 +9822,7 @@ bool ScalarEvolution::isKnownNonPositive(const SCEV *S) {
 }
 
 bool ScalarEvolution::isKnownNonZero(const SCEV *S) {
-  return isKnownNegative(S) || isKnownPositive(S);
+  return getUnsignedRangeMin(S) != 0;
 }
 
 std::pair<const SCEV *, const SCEV *>

diff  --git a/llvm/test/Analysis/ScalarEvolution/trip-count9.ll b/llvm/test/Analysis/ScalarEvolution/trip-count9.ll
index 34f7a1a40c584..93cb288644935 100644
--- a/llvm/test/Analysis/ScalarEvolution/trip-count9.ll
+++ b/llvm/test/Analysis/ScalarEvolution/trip-count9.ll
@@ -311,9 +311,9 @@ exit:
 define void @even_start1(i4 %n) {
 ; CHECK-LABEL: 'even_start1'
 ; CHECK-NEXT:  Determining loop execution counts for: @even_start1
-; CHECK-NEXT:  Loop %loop: backedge-taken count is (-2 + (2 smax (2 * %n)))<nsw>
+; CHECK-NEXT:  Loop %loop: backedge-taken count is (-2 + (2 * %n))
 ; CHECK-NEXT:  Loop %loop: max backedge-taken count is 4
-; CHECK-NEXT:  Loop %loop: Predicated backedge-taken count is (-2 + (2 smax (2 * %n)))<nsw>
+; CHECK-NEXT:  Loop %loop: Predicated backedge-taken count is (-2 + (2 * %n))
 ; CHECK-NEXT:   Predicates:
 ; CHECK:       Loop %loop: Trip multiple is 1
 ;
@@ -333,9 +333,9 @@ exit:
 define void @even_start1_step2(i4 %n) {
 ; CHECK-LABEL: 'even_start1_step2'
 ; CHECK-NEXT:  Determining loop execution counts for: @even_start1_step2
-; CHECK-NEXT:  Loop %loop: backedge-taken count is ((-2 + (3 smax (2 * %n)))<nsw> /u 2)
+; CHECK-NEXT:  Loop %loop: backedge-taken count is ((-2 + (2 * %n)) /u 2)
 ; CHECK-NEXT:  Loop %loop: max backedge-taken count is 2
-; CHECK-NEXT:  Loop %loop: Predicated backedge-taken count is ((-2 + (3 smax (2 * %n)))<nsw> /u 2)
+; CHECK-NEXT:  Loop %loop: Predicated backedge-taken count is ((-2 + (2 * %n)) /u 2)
 ; CHECK-NEXT:   Predicates:
 ; CHECK:       Loop %loop: Trip multiple is 1
 ;
@@ -443,9 +443,9 @@ exit:
 define void @even_nsw_start1(i4 %n) {
 ; CHECK-LABEL: 'even_nsw_start1'
 ; CHECK-NEXT:  Determining loop execution counts for: @even_nsw_start1
-; CHECK-NEXT:  Loop %loop: backedge-taken count is (-2 + (2 smax (2 * %n)))<nsw>
+; CHECK-NEXT:  Loop %loop: backedge-taken count is (-2 + (2 * %n))
 ; CHECK-NEXT:  Loop %loop: max backedge-taken count is 4
-; CHECK-NEXT:  Loop %loop: Predicated backedge-taken count is (-2 + (2 smax (2 * %n)))<nsw>
+; CHECK-NEXT:  Loop %loop: Predicated backedge-taken count is (-2 + (2 * %n))
 ; CHECK-NEXT:   Predicates:
 ; CHECK:       Loop %loop: Trip multiple is 1
 ;
@@ -465,9 +465,9 @@ exit:
 define void @even_nsw_start1_step2(i4 %n) {
 ; CHECK-LABEL: 'even_nsw_start1_step2'
 ; CHECK-NEXT:  Determining loop execution counts for: @even_nsw_start1_step2
-; CHECK-NEXT:  Loop %loop: backedge-taken count is ((-2 + (3 smax (2 * %n)))<nsw> /u 2)
+; CHECK-NEXT:  Loop %loop: backedge-taken count is ((-2 + (2 * %n)) /u 2)
 ; CHECK-NEXT:  Loop %loop: max backedge-taken count is 2
-; CHECK-NEXT:  Loop %loop: Predicated backedge-taken count is ((-2 + (3 smax (2 * %n)))<nsw> /u 2)
+; CHECK-NEXT:  Loop %loop: Predicated backedge-taken count is ((-2 + (2 * %n)) /u 2)
 ; CHECK-NEXT:   Predicates:
 ; CHECK:       Loop %loop: Trip multiple is 1
 ;


        


More information about the llvm-commits mailing list