[llvm] 0d91075 - [ValueTracking] Don't require strictly positive for mul nsw recurrence

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 14 10:40:12 PDT 2021


Author: Nikita Popov
Date: 2021-04-14T19:39:59+02:00
New Revision: 0d91075f772d3f0e2cf6449b534a726d4d944c62

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

LOG: [ValueTracking] Don't require strictly positive for mul nsw recurrence

Just like in the mul nuw case, it's sufficient that the step is
non-zero. If the step is negative, then the values will jump
between positive and negative, "crossing" zero, but the value of
the recurrence is never actually zero.

Added: 
    

Modified: 
    llvm/lib/Analysis/ValueTracking.cpp
    llvm/test/Analysis/ValueTracking/monotonic-phi.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index c1e7cf7d1191..d8963c6ee838 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -2231,9 +2231,8 @@ static bool isNonZeroRecurrence(const PHINode *PN) {
            (BO->hasNoSignedWrap() && match(Step, m_APInt(StepC)) &&
             StartC->isNegative() == StepC->isNegative());
   case Instruction::Mul:
-    return match(Step, m_APInt(StepC)) &&
-           ((BO->hasNoUnsignedWrap() && !StepC->isNullValue()) ||
-            (BO->hasNoSignedWrap() && StepC->isStrictlyPositive()));
+    return (BO->hasNoUnsignedWrap() || BO->hasNoSignedWrap()) &&
+           match(Step, m_APInt(StepC)) && !StepC->isNullValue();
   case Instruction::Shl:
     return BO->hasNoUnsignedWrap() || BO->hasNoSignedWrap();
   case Instruction::AShr:

diff  --git a/llvm/test/Analysis/ValueTracking/monotonic-phi.ll b/llvm/test/Analysis/ValueTracking/monotonic-phi.ll
index af23450b3da9..a19de34c62b0 100644
--- a/llvm/test/Analysis/ValueTracking/monotonic-phi.ll
+++ b/llvm/test/Analysis/ValueTracking/monotonic-phi.ll
@@ -339,8 +339,7 @@ define i1 @test_mul_nsw_negative_step(i8 %n) {
 ; CHECK-NEXT:    [[CMP1:%.*]] = icmp eq i8 [[A]], [[N:%.*]]
 ; CHECK-NEXT:    br i1 [[CMP1]], label [[EXIT:%.*]], label [[LOOP]]
 ; CHECK:       exit:
-; CHECK-NEXT:    [[CMP:%.*]] = icmp eq i8 [[A]], 0
-; CHECK-NEXT:    ret i1 [[CMP]]
+; CHECK-NEXT:    ret i1 false
 ;
 entry:
   br label %loop


        


More information about the llvm-commits mailing list