aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Analysis/ValueTracking.cpp
diff options
context:
space:
mode:
authorNikita Popov <nikita.ppv@gmail.com>2021-04-14 19:04:01 +0200
committerNikita Popov <nikita.ppv@gmail.com>2021-04-14 19:06:18 +0200
commit5c0fb026c93b33dd107f6ff50723d7eed911e1ce (patch)
tree7387cf5567bc406361e77de202b107b422a50f1d /llvm/lib/Analysis/ValueTracking.cpp
parentf1bc1a82cf718a67d3271fc74c28f5845f0f1526 (diff)
downloadllvm-5c0fb026c93b33dd107f6ff50723d7eed911e1ce.zip
llvm-5c0fb026c93b33dd107f6ff50723d7eed911e1ce.tar.gz
llvm-5c0fb026c93b33dd107f6ff50723d7eed911e1ce.tar.bz2
[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.
Diffstat (limited to 'llvm/lib/Analysis/ValueTracking.cpp')
-rw-r--r--llvm/lib/Analysis/ValueTracking.cpp8
1 files changed, 3 insertions, 5 deletions
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index d78acdb..c1e7cf7 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()) ||