[llvm] 5c0fb02 - [ValueTracking] Don't require non-zero step for add nuw
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 14 10:06:29 PDT 2021
Author: Nikita Popov
Date: 2021-04-14T19:06:18+02:00
New Revision: 5c0fb026c93b33dd107f6ff50723d7eed911e1ce
URL: https://github.com/llvm/llvm-project/commit/5c0fb026c93b33dd107f6ff50723d7eed911e1ce
DIFF: https://github.com/llvm/llvm-project/commit/5c0fb026c93b33dd107f6ff50723d7eed911e1ce.diff
LOG: [ValueTracking] Don't require non-zero step for add nuw
It's okay if the step is zero, we'll just stay at the same non-zero
value in that case. The valuable part of this is that the step
doesn't even need to be a constant anymore.
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 d78acdbb1cd9..c1e7cf7d1191 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -2227,11 +2227,9 @@ static bool isNonZeroRecurrence(const PHINode *PN) {
case Instruction::Add:
// Starting from non-zero and stepping away from zero can never wrap back
// to zero.
- // TODO: The constant step requirement is not needed with NUW.
- return match(Step, m_APInt(StepC)) &&
- ((BO->hasNoUnsignedWrap() && !StepC->isNullValue()) ||
- (BO->hasNoSignedWrap() &&
- StartC->isNegative() == StepC->isNegative()));
+ return BO->hasNoUnsignedWrap() ||
+ (BO->hasNoSignedWrap() && match(Step, m_APInt(StepC)) &&
+ StartC->isNegative() == StepC->isNegative());
case Instruction::Mul:
return match(Step, m_APInt(StepC)) &&
((BO->hasNoUnsignedWrap() && !StepC->isNullValue()) ||
diff --git a/llvm/test/Analysis/ValueTracking/monotonic-phi.ll b/llvm/test/Analysis/ValueTracking/monotonic-phi.ll
index fb7865d1c323..af23450b3da9 100644
--- a/llvm/test/Analysis/ValueTracking/monotonic-phi.ll
+++ b/llvm/test/Analysis/ValueTracking/monotonic-phi.ll
@@ -88,9 +88,7 @@ define i1 @test_add_nuw_unknown_step(i8 %n, i8 %r, i8 %s) {
; CHECK-NEXT: [[CMP1:%.*]] = icmp eq i8 [[A]], [[N:%.*]]
; CHECK-NEXT: br i1 [[CMP1]], label [[EXIT:%.*]], label [[LOOP]]
; CHECK: exit:
-; CHECK-NEXT: [[ADD:%.*]] = or i8 [[A]], [[R:%.*]]
-; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[ADD]], 0
-; CHECK-NEXT: ret i1 [[CMP]]
+; CHECK-NEXT: ret i1 false
;
entry:
br label %loop
More information about the llvm-commits
mailing list