summaryrefslogtreecommitdiff
path: root/lib/Analysis/LazyValueInfo.cpp
diff options
context:
space:
mode:
authorOwen Anderson <resistor@mac.com>2010-08-24 21:59:42 +0000
committerOwen Anderson <resistor@mac.com>2010-08-24 21:59:42 +0000
commitdae90c6afb5f625244c5bb3962669bd1f8a3d5be (patch)
tree699b7f67677959fb957978b4c2750d29a0889e87 /lib/Analysis/LazyValueInfo.cpp
parent3197380143cdc18837722129ac888528b9fbfc2b (diff)
downloadllvm-dae90c6afb5f625244c5bb3962669bd1f8a3d5be.tar.gz
llvm-dae90c6afb5f625244c5bb3962669bd1f8a3d5be.tar.bz2
llvm-dae90c6afb5f625244c5bb3962669bd1f8a3d5be.tar.xz
Add support for inferring values for the default cases of switches.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@111971 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/LazyValueInfo.cpp')
-rw-r--r--lib/Analysis/LazyValueInfo.cpp25
1 files changed, 22 insertions, 3 deletions
diff --git a/lib/Analysis/LazyValueInfo.cpp b/lib/Analysis/LazyValueInfo.cpp
index 3ecaeed919..88fa15a88f 100644
--- a/lib/Analysis/LazyValueInfo.cpp
+++ b/lib/Analysis/LazyValueInfo.cpp
@@ -671,9 +671,28 @@ LVILatticeVal LVIQuery::getEdgeValue(BasicBlock *BBFrom, BasicBlock *BBTo) {
// If the edge was formed by a switch on the value, then we may know exactly
// what it is.
if (SwitchInst *SI = dyn_cast<SwitchInst>(BBFrom->getTerminator())) {
- // If BBTo is the default destination of the switch, we don't know anything.
- // Given a more powerful range analysis we could know stuff.
- if (SI->getCondition() == Val && SI->getDefaultDest() != BBTo) {
+ // If BBTo is the default destination of the switch, we know that it
+ // doesn't have the same value as any of the cases.
+ if (SI->getCondition() == Val) {
+ if (SI->getDefaultDest() == BBTo) {
+ const IntegerType *IT = cast<IntegerType>(Val->getType());
+ ConstantRange CR(IT->getBitWidth());
+
+ for (unsigned i = 1, e = SI->getNumSuccessors(); i != e; ++i) {
+ const APInt CaseVal = SI->getCaseValue(i)->getValue();
+ ConstantRange CaseRange(CaseVal, CaseVal+1);
+ CaseRange = CaseRange.inverse();
+ CR = CR.intersectWith(CaseRange);
+ }
+
+ LVILatticeVal Result;
+ if (CR.isFullSet() || CR.isEmptySet())
+ Result.markOverdefined();
+ else
+ Result.markConstantRange(CR);
+ return Result;
+ }
+
// We only know something if there is exactly one value that goes from
// BBFrom to BBTo.
unsigned NumEdges = 0;