mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-01-31 20:51:52 +01:00
[SCEV] Clean up isKnownPredicateViaConstantRanges; NFCI
- ScalarEvolution::isKnownPredicateViaConstantRanges duplicates some logic already present in ConstantRange, use ConstantRange for those bits. - In some cases ScalarEvolution::isKnownPredicateViaConstantRanges returns `false` to mean "definitely false" (e.g. see the `LHSRange.getSignedMin().sge(RHSRange.getSignedMax())` case for `ICmpInst::ICMP_SLT`), but for `isKnownPredicateViaConstantRanges`, `false` actually means "don't know". Get rid of this extra bit of code to avoid confusion. llvm-svn: 259401
This commit is contained in:
parent
b45b869e7d
commit
49cbccc04a
@ -7268,70 +7268,27 @@ bool ScalarEvolution::isKnownPredicateViaConstantRanges(
|
||||
|
||||
// This code is split out from isKnownPredicate because it is called from
|
||||
// within isLoopEntryGuardedByCond.
|
||||
switch (Pred) {
|
||||
default:
|
||||
llvm_unreachable("Unexpected ICmpInst::Predicate value!");
|
||||
case ICmpInst::ICMP_SGT:
|
||||
std::swap(LHS, RHS);
|
||||
case ICmpInst::ICMP_SLT: {
|
||||
ConstantRange LHSRange = getSignedRange(LHS);
|
||||
ConstantRange RHSRange = getSignedRange(RHS);
|
||||
if (LHSRange.getSignedMax().slt(RHSRange.getSignedMin()))
|
||||
return true;
|
||||
if (LHSRange.getSignedMin().sge(RHSRange.getSignedMax()))
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
case ICmpInst::ICMP_SGE:
|
||||
std::swap(LHS, RHS);
|
||||
case ICmpInst::ICMP_SLE: {
|
||||
ConstantRange LHSRange = getSignedRange(LHS);
|
||||
ConstantRange RHSRange = getSignedRange(RHS);
|
||||
if (LHSRange.getSignedMax().sle(RHSRange.getSignedMin()))
|
||||
return true;
|
||||
if (LHSRange.getSignedMin().sgt(RHSRange.getSignedMax()))
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
case ICmpInst::ICMP_UGT:
|
||||
std::swap(LHS, RHS);
|
||||
case ICmpInst::ICMP_ULT: {
|
||||
ConstantRange LHSRange = getUnsignedRange(LHS);
|
||||
ConstantRange RHSRange = getUnsignedRange(RHS);
|
||||
if (LHSRange.getUnsignedMax().ult(RHSRange.getUnsignedMin()))
|
||||
return true;
|
||||
if (LHSRange.getUnsignedMin().uge(RHSRange.getUnsignedMax()))
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
case ICmpInst::ICMP_UGE:
|
||||
std::swap(LHS, RHS);
|
||||
case ICmpInst::ICMP_ULE: {
|
||||
ConstantRange LHSRange = getUnsignedRange(LHS);
|
||||
ConstantRange RHSRange = getUnsignedRange(RHS);
|
||||
if (LHSRange.getUnsignedMax().ule(RHSRange.getUnsignedMin()))
|
||||
return true;
|
||||
if (LHSRange.getUnsignedMin().ugt(RHSRange.getUnsignedMax()))
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
case ICmpInst::ICMP_NE: {
|
||||
if (getUnsignedRange(LHS).intersectWith(getUnsignedRange(RHS)).isEmptySet())
|
||||
return true;
|
||||
if (getSignedRange(LHS).intersectWith(getSignedRange(RHS)).isEmptySet())
|
||||
return true;
|
||||
|
||||
const SCEV *Diff = getMinusSCEV(LHS, RHS);
|
||||
if (isKnownNonZero(Diff))
|
||||
return true;
|
||||
break;
|
||||
}
|
||||
case ICmpInst::ICMP_EQ:
|
||||
// The check at the top of the function catches the case where
|
||||
// the values are known to be equal.
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
auto CheckRanges =
|
||||
[&](const ConstantRange &RangeLHS, const ConstantRange &RangeRHS) {
|
||||
return ConstantRange::makeSatisfyingICmpRegion(Pred, RangeRHS)
|
||||
.contains(RangeLHS);
|
||||
};
|
||||
|
||||
// The check at the top of the function catches the case where the values are
|
||||
// known to be equal.
|
||||
if (Pred == CmpInst::ICMP_EQ)
|
||||
return false;
|
||||
|
||||
if (Pred == CmpInst::ICMP_NE)
|
||||
return CheckRanges(getSignedRange(LHS), getSignedRange(RHS)) ||
|
||||
CheckRanges(getUnsignedRange(LHS), getUnsignedRange(RHS)) ||
|
||||
isKnownNonZero(getMinusSCEV(LHS, RHS));
|
||||
|
||||
if (CmpInst::isSigned(Pred))
|
||||
return CheckRanges(getSignedRange(LHS), getSignedRange(RHS));
|
||||
|
||||
return CheckRanges(getUnsignedRange(LHS), getUnsignedRange(RHS));
|
||||
}
|
||||
|
||||
bool ScalarEvolution::isKnownPredicateViaNoOverflow(ICmpInst::Predicate Pred,
|
||||
|
Loading…
x
Reference in New Issue
Block a user