mirror of
https://github.com/RPCSX/llvm.git
synced 2025-01-21 03:37:47 +00:00
Remove duplicated code; NFC
ICmpInst::makeConstantRange does exactly the same thing as ConstantRange::makeExactICmpRegion. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@283059 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
afbfbca525
commit
f6a95d4da8
@ -1185,10 +1185,6 @@ public:
|
||||
return !isEquality(P);
|
||||
}
|
||||
|
||||
/// Initialize a set of values that all satisfy the predicate with C.
|
||||
/// Make a ConstantRange for a relation with a constant value.
|
||||
static ConstantRange makeConstantRange(Predicate pred, const APInt &C);
|
||||
|
||||
/// Exchange the two operands to this instruction in such a way that it does
|
||||
/// not modify the semantics of the instruction. The predicate value may be
|
||||
/// changed to retain the same result if the predicate is order dependent
|
||||
|
@ -2157,7 +2157,7 @@ static Value *simplifyICmpWithConstant(CmpInst::Predicate Pred, Value *LHS,
|
||||
return nullptr;
|
||||
|
||||
// Rule out tautological comparisons (eg., ult 0 or uge 0).
|
||||
ConstantRange RHS_CR = ICmpInst::makeConstantRange(Pred, *C);
|
||||
ConstantRange RHS_CR = ConstantRange::makeExactICmpRegion(Pred, *C);
|
||||
if (RHS_CR.isEmptySet())
|
||||
return ConstantInt::getFalse(GetCompareTy(RHS));
|
||||
if (RHS_CR.isFullSet())
|
||||
|
@ -1707,8 +1707,8 @@ static LazyValueInfo::Tristate getPredicateResult(unsigned Pred, Constant *C,
|
||||
}
|
||||
|
||||
// Handle more complex predicates.
|
||||
ConstantRange TrueValues =
|
||||
ICmpInst::makeConstantRange((ICmpInst::Predicate)Pred, CI->getValue());
|
||||
ConstantRange TrueValues = ConstantRange::makeExactICmpRegion(
|
||||
(ICmpInst::Predicate)Pred, CI->getValue());
|
||||
if (TrueValues.contains(CR))
|
||||
return LazyValueInfo::True;
|
||||
if (TrueValues.inverse().contains(CR))
|
||||
|
@ -5994,8 +5994,8 @@ ScalarEvolution::computeExitLimitFromICmp(const Loop *L,
|
||||
if (const SCEVAddRecExpr *AddRec = dyn_cast<SCEVAddRecExpr>(LHS))
|
||||
if (AddRec->getLoop() == L) {
|
||||
// Form the constant range.
|
||||
ConstantRange CompRange(
|
||||
ICmpInst::makeConstantRange(Cond, RHSC->getAPInt()));
|
||||
ConstantRange CompRange =
|
||||
ConstantRange::makeExactICmpRegion(Cond, RHSC->getAPInt());
|
||||
|
||||
const SCEV *Ret = AddRec->getNumIterationsInRange(CompRange, *this);
|
||||
if (!isa<SCEVCouldNotCompute>(Ret)) return Ret;
|
||||
|
@ -3472,69 +3472,6 @@ ICmpInst::Predicate ICmpInst::getUnsignedPredicate(Predicate pred) {
|
||||
}
|
||||
}
|
||||
|
||||
/// Initialize a set of values that all satisfy the condition with C.
|
||||
///
|
||||
ConstantRange
|
||||
ICmpInst::makeConstantRange(Predicate pred, const APInt &C) {
|
||||
APInt Lower(C);
|
||||
APInt Upper(C);
|
||||
uint32_t BitWidth = C.getBitWidth();
|
||||
switch (pred) {
|
||||
default: llvm_unreachable("Invalid ICmp opcode to ConstantRange ctor!");
|
||||
case ICmpInst::ICMP_EQ: ++Upper; break;
|
||||
case ICmpInst::ICMP_NE: ++Lower; break;
|
||||
case ICmpInst::ICMP_ULT:
|
||||
Lower = APInt::getMinValue(BitWidth);
|
||||
// Check for an empty-set condition.
|
||||
if (Lower == Upper)
|
||||
return ConstantRange(BitWidth, /*isFullSet=*/false);
|
||||
break;
|
||||
case ICmpInst::ICMP_SLT:
|
||||
Lower = APInt::getSignedMinValue(BitWidth);
|
||||
// Check for an empty-set condition.
|
||||
if (Lower == Upper)
|
||||
return ConstantRange(BitWidth, /*isFullSet=*/false);
|
||||
break;
|
||||
case ICmpInst::ICMP_UGT:
|
||||
++Lower; Upper = APInt::getMinValue(BitWidth); // Min = Next(Max)
|
||||
// Check for an empty-set condition.
|
||||
if (Lower == Upper)
|
||||
return ConstantRange(BitWidth, /*isFullSet=*/false);
|
||||
break;
|
||||
case ICmpInst::ICMP_SGT:
|
||||
++Lower; Upper = APInt::getSignedMinValue(BitWidth); // Min = Next(Max)
|
||||
// Check for an empty-set condition.
|
||||
if (Lower == Upper)
|
||||
return ConstantRange(BitWidth, /*isFullSet=*/false);
|
||||
break;
|
||||
case ICmpInst::ICMP_ULE:
|
||||
Lower = APInt::getMinValue(BitWidth); ++Upper;
|
||||
// Check for a full-set condition.
|
||||
if (Lower == Upper)
|
||||
return ConstantRange(BitWidth, /*isFullSet=*/true);
|
||||
break;
|
||||
case ICmpInst::ICMP_SLE:
|
||||
Lower = APInt::getSignedMinValue(BitWidth); ++Upper;
|
||||
// Check for a full-set condition.
|
||||
if (Lower == Upper)
|
||||
return ConstantRange(BitWidth, /*isFullSet=*/true);
|
||||
break;
|
||||
case ICmpInst::ICMP_UGE:
|
||||
Upper = APInt::getMinValue(BitWidth); // Min = Next(Max)
|
||||
// Check for a full-set condition.
|
||||
if (Lower == Upper)
|
||||
return ConstantRange(BitWidth, /*isFullSet=*/true);
|
||||
break;
|
||||
case ICmpInst::ICMP_SGE:
|
||||
Upper = APInt::getSignedMinValue(BitWidth); // Min = Next(Max)
|
||||
// Check for a full-set condition.
|
||||
if (Lower == Upper)
|
||||
return ConstantRange(BitWidth, /*isFullSet=*/true);
|
||||
break;
|
||||
}
|
||||
return ConstantRange(Lower, Upper);
|
||||
}
|
||||
|
||||
CmpInst::Predicate CmpInst::getSwappedPredicate(Predicate pred) {
|
||||
switch (pred) {
|
||||
default: llvm_unreachable("Unknown cmp predicate!");
|
||||
|
@ -2320,7 +2320,8 @@ Instruction *InstCombiner::foldICmpAddConstant(ICmpInst &Cmp,
|
||||
// Fold icmp pred (add X, C2), C.
|
||||
Value *X = Add->getOperand(0);
|
||||
Type *Ty = Add->getType();
|
||||
auto CR = Cmp.makeConstantRange(Cmp.getPredicate(), *C).subtract(*C2);
|
||||
auto CR =
|
||||
ConstantRange::makeExactICmpRegion(Cmp.getPredicate(), *C).subtract(*C2);
|
||||
const APInt &Upper = CR.getUpper();
|
||||
const APInt &Lower = CR.getLower();
|
||||
if (Cmp.isSigned()) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user