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
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)));
}
}
// 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>
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);
// 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
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
// 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;
}
}