[llvm] 4919365 - [ValueTracking] reduce code duplication; NFC
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 14 05:38:34 PDT 2021
Author: Sanjay Patel
Date: 2021-04-14T08:32:42-04:00
New Revision: 49193653974ae96b756b8ff13668d07d6252aa77
URL: https://github.com/llvm/llvm-project/commit/49193653974ae96b756b8ff13668d07d6252aa77
DIFF: https://github.com/llvm/llvm-project/commit/49193653974ae96b756b8ff13668d07d6252aa77.diff
LOG: [ValueTracking] reduce code duplication; NFC
The start value can't be null for something to be a non-zero
recurrence, so hoist that common check out of the switch.
Subsequent checks may be incomplete or over-specified as noted in:
D100408
Added:
Modified:
llvm/lib/Analysis/ValueTracking.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index d61f5ac47c70..2d933489447d 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -2213,33 +2213,31 @@ static bool rangeMetadataExcludesValue(const MDNode* Ranges, const APInt& Value)
return true;
}
+/// Try to detect a recurrence that monotonically increases from a non-zero
+/// starting value. These are common as induction variables.
static bool isNonZeroRecurrence(const PHINode *PN) {
- // Try and detect a recurrence that monotonically increases from a
- // starting value, as these are common as induction variables.
BinaryOperator *BO = nullptr;
Value *Start = nullptr, *Step = nullptr;
const APInt *StartC, *StepC;
if (!matchSimpleRecurrence(PN, BO, Start, Step) ||
- !match(Start, m_APInt(StartC)))
+ !match(Start, m_APInt(StartC)) || StartC->isNullValue())
return false;
switch (BO->getOpcode()) {
case Instruction::Add:
return match(Step, m_APInt(StepC)) &&
- ((BO->hasNoUnsignedWrap() && !StartC->isNullValue() &&
- !StepC->isNullValue()) ||
+ ((BO->hasNoUnsignedWrap() && !StepC->isNullValue()) ||
(BO->hasNoSignedWrap() && StartC->isStrictlyPositive() &&
StepC->isNonNegative()));
case Instruction::Mul:
- return !StartC->isNullValue() && match(Step, m_APInt(StepC)) &&
+ return match(Step, m_APInt(StepC)) &&
((BO->hasNoUnsignedWrap() && !StepC->isNullValue()) ||
(BO->hasNoSignedWrap() && StepC->isStrictlyPositive()));
case Instruction::Shl:
- return !StartC->isNullValue() &&
- (BO->hasNoUnsignedWrap() || BO->hasNoSignedWrap());
+ return BO->hasNoUnsignedWrap() || BO->hasNoSignedWrap();
case Instruction::AShr:
case Instruction::LShr:
- return !StartC->isNullValue() && BO->isExact();
+ return BO->isExact();
default:
return false;
}
More information about the llvm-commits
mailing list