X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FAnalysis%2FLazyValueInfo.cpp;h=d3a437f9405057ea4b8af7545c86756fd533f30e;hb=bb0a9489e00d93e3944da0c7458f46e9ccb32c9f;hp=7ec35cdcc5bdb11c805d47dd8125b00e26f6eb1f;hpb=9f014061799c01bd6eb5947f95a330ee99798efc;p=oota-llvm.git diff --git a/lib/Analysis/LazyValueInfo.cpp b/lib/Analysis/LazyValueInfo.cpp index 7ec35cdcc5b..d3a437f9405 100644 --- a/lib/Analysis/LazyValueInfo.cpp +++ b/lib/Analysis/LazyValueInfo.cpp @@ -91,6 +91,11 @@ public: Res.markNotConstant(C); return Res; } + static LVILatticeVal getRange(ConstantRange CR) { + LVILatticeVal Res; + Res.markConstantRange(CR); + return Res; + } bool isUndefined() const { return Tag == undefined; } bool isConstant() const { return Tag == constant; } @@ -379,7 +384,6 @@ namespace { } // end anonymous namespace void LazyValueInfoCache::LVIValueHandle::deleted() { - Parent->ValueCache.erase(*this); for (std::set >::iterator I = Parent->OverDefinedCache.begin(), E = Parent->OverDefinedCache.end(); @@ -389,6 +393,10 @@ void LazyValueInfoCache::LVIValueHandle::deleted() { if (tmp->second == getValPtr()) Parent->OverDefinedCache.erase(tmp); } + + // This erasure deallocates *this, so it MUST happen after we're done + // using any and all members of *this. + Parent->ValueCache.erase(*this); } @@ -506,15 +514,38 @@ LVILatticeVal LVIQuery::getEdgeValue(BasicBlock *BBFrom, BasicBlock *BBTo) { // If the condition of the branch is an equality comparison, we may be // able to infer the value. - if (ICmpInst *ICI = dyn_cast(BI->getCondition())) - if (ICI->isEquality() && ICI->getOperand(0) == Val && - isa(ICI->getOperand(1))) { + ICmpInst *ICI = dyn_cast(BI->getCondition()); + if (ICI && ICI->getOperand(0) == Val && + isa(ICI->getOperand(1))) { + if (ICI->isEquality()) { // We know that V has the RHS constant if this is a true SETEQ or // false SETNE. if (isTrueDest == (ICI->getPredicate() == ICmpInst::ICMP_EQ)) return LVILatticeVal::get(cast(ICI->getOperand(1))); return LVILatticeVal::getNot(cast(ICI->getOperand(1))); } + + if (ConstantInt *CI = dyn_cast(ICI->getOperand(1))) { + // Calculate the range of values that would satisfy the comparison. + ConstantRange CmpRange(CI->getValue(), CI->getValue()+1); + ConstantRange TrueValues = + ConstantRange::makeICmpRegion(ICI->getPredicate(), CmpRange); + + // If we're interested in the false dest, invert the condition. + if (!isTrueDest) TrueValues = TrueValues.inverse(); + + // Figure out the possible values of the query BEFORE this branch. + LVILatticeVal InBlock = getBlockValue(BBFrom); + if (!InBlock.isConstantRange()) return InBlock; + + // Find all potential values that satisfy both the input and output + // conditions. + ConstantRange PossibleValues = + TrueValues.intersectWith(InBlock.getConstantRange()); + + return LVILatticeVal::getRange(PossibleValues); + } + } } } @@ -730,7 +761,7 @@ LazyValueInfo::getPredicateOnEdge(unsigned Pred, Value *V, Constant *C, ConstantRange TrueValues = ConstantRange::makeICmpRegion(Pred, RHS); if (CR.intersectWith(TrueValues).isEmptySet()) return False; - else if (CR.intersectWith(TrueValues) == CR) + else if (TrueValues.contains(CR)) return True; return Unknown;