mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-23 11:13:28 +01:00
[LVI] NFC. Make getValueFromCondition return LVILatticeValue instead of changing reference argument
Instead of returning bool and setting LVILatticeValue reference argument return LVILattice value. Use overdefined value to denote the case when we didn't gather any information from the condition. This change was separated from the review "[LVI] Handle conditions in the form of (cond1 && cond2)" (https://reviews.llvm.org/D23200#inline-199531). Once getValueFromCondition returns LVILatticeValue we can cache the result in Visited map. llvm-svn: 278224
This commit is contained in:
parent
062c0daef0
commit
a77e404d5d
@ -859,9 +859,8 @@ bool LazyValueInfoCache::solveBlockValuePHINode(LVILatticeVal &BBLV,
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool getValueFromCondition(Value *Val, Value *Cond,
|
||||
LVILatticeVal &Result,
|
||||
bool isTrueDest = true);
|
||||
static LVILatticeVal getValueFromCondition(Value *Val, Value *Cond,
|
||||
bool isTrueDest = true);
|
||||
|
||||
// If we can determine a constraint on the value given conditions assumed by
|
||||
// the program, intersect those constraints with BBLV
|
||||
@ -879,9 +878,7 @@ void LazyValueInfoCache::intersectAssumeBlockValueConstantRange(Value *Val,
|
||||
if (!isValidAssumeForContext(I, BBI, DT))
|
||||
continue;
|
||||
|
||||
LVILatticeVal Result;
|
||||
if (getValueFromCondition(Val, I->getArgOperand(0), Result))
|
||||
BBLV = intersect(BBLV, Result);
|
||||
BBLV = intersect(BBLV, getValueFromCondition(Val, I->getArgOperand(0)));
|
||||
}
|
||||
}
|
||||
|
||||
@ -952,14 +949,10 @@ bool LazyValueInfoCache::solveBlockValueSelect(LVILatticeVal &BBLV,
|
||||
// condition itself? This shows up with idioms like e.g. select(a > 5, a, 5).
|
||||
// TODO: We could potentially refine an overdefined true value above.
|
||||
Value *Cond = SI->getCondition();
|
||||
LVILatticeVal TrueValTaken, FalseValTaken;
|
||||
if (!getValueFromCondition(SI->getTrueValue(), Cond, TrueValTaken, true))
|
||||
TrueValTaken.markOverdefined();
|
||||
if (!getValueFromCondition(SI->getFalseValue(), Cond, FalseValTaken, false))
|
||||
FalseValTaken.markOverdefined();
|
||||
|
||||
TrueVal = intersect(TrueVal, TrueValTaken);
|
||||
FalseVal = intersect(FalseVal, FalseValTaken);
|
||||
TrueVal = intersect(TrueVal,
|
||||
getValueFromCondition(SI->getTrueValue(), Cond, true));
|
||||
FalseVal = intersect(FalseVal,
|
||||
getValueFromCondition(SI->getFalseValue(), Cond, false));
|
||||
|
||||
// Handle clamp idioms such as:
|
||||
// %24 = constantrange<0, 17>
|
||||
@ -1174,14 +1167,13 @@ bool LazyValueInfoCache::solveBlockValueBinaryOp(LVILatticeVal &BBLV,
|
||||
return true;
|
||||
}
|
||||
|
||||
bool getValueFromCondition(Value *Val, Value *Cond, LVILatticeVal &Result,
|
||||
bool isTrueDest) {
|
||||
LVILatticeVal getValueFromCondition(Value *Val, Value *Cond, bool isTrueDest) {
|
||||
assert(Cond && "precondition");
|
||||
|
||||
// For now we only support ICmpInst conditions
|
||||
ICmpInst *ICI = dyn_cast<ICmpInst>(Cond);
|
||||
if (!ICI)
|
||||
return false;
|
||||
return LVILatticeVal::getOverdefined();
|
||||
|
||||
Value *LHS = ICI->getOperand(0);
|
||||
Value *RHS = ICI->getOperand(1);
|
||||
@ -1192,15 +1184,14 @@ bool getValueFromCondition(Value *Val, Value *Cond, LVILatticeVal &Result,
|
||||
// We know that V has the RHS constant if this is a true SETEQ or
|
||||
// false SETNE.
|
||||
if (isTrueDest == (Predicate == ICmpInst::ICMP_EQ))
|
||||
Result = LVILatticeVal::get(cast<Constant>(RHS));
|
||||
return LVILatticeVal::get(cast<Constant>(RHS));
|
||||
else
|
||||
Result = LVILatticeVal::getNot(cast<Constant>(RHS));
|
||||
return true;
|
||||
return LVILatticeVal::getNot(cast<Constant>(RHS));
|
||||
}
|
||||
}
|
||||
|
||||
if (!Val->getType()->isIntegerTy())
|
||||
return false;
|
||||
return LVILatticeVal::getOverdefined();
|
||||
|
||||
// Use ConstantRange::makeAllowedICmpRegion in order to determine the possible
|
||||
// range of Val guaranteed by the condition. Recognize comparisons in the from
|
||||
@ -1236,11 +1227,10 @@ bool getValueFromCondition(Value *Val, Value *Cond, LVILatticeVal &Result,
|
||||
if (Offset) // Apply the offset from above.
|
||||
TrueValues = TrueValues.subtract(Offset->getValue());
|
||||
|
||||
Result = LVILatticeVal::getRange(std::move(TrueValues));
|
||||
return true;
|
||||
return LVILatticeVal::getRange(std::move(TrueValues));
|
||||
}
|
||||
|
||||
return false;
|
||||
return LVILatticeVal::getOverdefined();
|
||||
}
|
||||
|
||||
/// \brief Compute the value of Val on the edge BBFrom -> BBTo. Returns false if
|
||||
@ -1269,7 +1259,8 @@ static bool getEdgeValueLocal(Value *Val, BasicBlock *BBFrom,
|
||||
|
||||
// If the condition of the branch is an equality comparison, we may be
|
||||
// able to infer the value.
|
||||
if (getValueFromCondition(Val, BI->getCondition(), Result, isTrueDest))
|
||||
Result = getValueFromCondition(Val, BI->getCondition(), isTrueDest);
|
||||
if (!Result.isOverdefined())
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user