mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-25 12:12:47 +01:00
[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
This commit is contained in:
parent
9c1bc49f11
commit
b568083407
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user