aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Analysis
diff options
context:
space:
mode:
authorOwen Anderson <resistor@mac.com>2010-08-10 23:20:01 +0000
committerOwen Anderson <resistor@mac.com>2010-08-10 23:20:01 +0000
commit625051be7e30d70ba44878a0f3b4d4195902a8ef (patch)
treecfbe72df1a7babd6d0a981c0d52d0e686ac732ff /lib/Analysis
parentbb47d3b47187e5e0b8f1a627c172894c228199da (diff)
downloadexternal_llvm-625051be7e30d70ba44878a0f3b4d4195902a8ef.zip
external_llvm-625051be7e30d70ba44878a0f3b4d4195902a8ef.tar.gz
external_llvm-625051be7e30d70ba44878a0f3b4d4195902a8ef.tar.bz2
Now that we're using ConstantRange to represent potential values, make use of that represenation to
create constraints from comparisons other than eq/neq. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@110742 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis')
-rw-r--r--lib/Analysis/LazyValueInfo.cpp43
1 files changed, 35 insertions, 8 deletions
diff --git a/lib/Analysis/LazyValueInfo.cpp b/lib/Analysis/LazyValueInfo.cpp
index 7ec35cd..4877823 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; }
@@ -507,13 +512,35 @@ 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<ICmpInst>(BI->getCondition()))
- if (ICI->isEquality() && ICI->getOperand(0) == Val &&
- isa<Constant>(ICI->getOperand(1))) {
- // 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<Constant>(ICI->getOperand(1)));
- return LVILatticeVal::getNot(cast<Constant>(ICI->getOperand(1)));
+ if (ICI->getOperand(0) == Val && isa<Constant>(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<Constant>(ICI->getOperand(1)));
+ return LVILatticeVal::getNot(cast<Constant>(ICI->getOperand(1)));
+ } else if (ConstantInt *CI =
+ dyn_cast<ConstantInt>(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 +757,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;