diff options
author | Nuno Lopes <nunoplopes@sapo.pt> | 2012-06-28 16:13:37 +0000 |
---|---|---|
committer | Nuno Lopes <nunoplopes@sapo.pt> | 2012-06-28 16:13:37 +0000 |
commit | e50487796d49624bf174bd08a86d20fcdbfb45c1 (patch) | |
tree | 4ea44bb17f03e8627a147ba7a3ecb78fa8bf6708 /lib/Analysis | |
parent | 62d7afad8faf7a1fbbf3402f8e23ce4ece9ab108 (diff) | |
download | external_llvm-e50487796d49624bf174bd08a86d20fcdbfb45c1.zip external_llvm-e50487796d49624bf174bd08a86d20fcdbfb45c1.tar.gz external_llvm-e50487796d49624bf174bd08a86d20fcdbfb45c1.tar.bz2 |
make LazyValueInfo analyze the default case of switch statements (we know that in the default branch the value cannot be any of the switch cases)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@159353 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis')
-rw-r--r-- | lib/Analysis/LazyValueInfo.cpp | 31 |
1 files changed, 15 insertions, 16 deletions
diff --git a/lib/Analysis/LazyValueInfo.cpp b/lib/Analysis/LazyValueInfo.cpp index 83786dd..9140786 100644 --- a/lib/Analysis/LazyValueInfo.cpp +++ b/lib/Analysis/LazyValueInfo.cpp @@ -835,24 +835,23 @@ static bool getEdgeValueLocal(Value *Val, BasicBlock *BBFrom, // 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 (SI->getCondition() == Val) { - // We don't know anything in the default case. - if (SI->getDefaultDest() == BBTo) { - Result.markOverdefined(); - return true; - } - - unsigned BitWidth = Val->getType()->getIntegerBitWidth(); - ConstantRange EdgesVals(BitWidth, false/*isFullSet*/); - for (SwitchInst::CaseIt i = SI->case_begin(), e = SI->case_end(); - i != e; ++i) { - if (i.getCaseSuccessor() != BBTo) continue; - ConstantRange EdgeVal(i.getCaseValue()->getValue()); + if (SI->getCondition() != Val) + return false; + + bool DefaultCase = SI->getDefaultDest() == BBTo; + unsigned BitWidth = Val->getType()->getIntegerBitWidth(); + ConstantRange EdgesVals(BitWidth, DefaultCase/*isFullSet*/); + + for (SwitchInst::CaseIt i = SI->case_begin(), e = SI->case_end(); + i != e; ++i) { + ConstantRange EdgeVal(i.getCaseValue()->getValue()); + if (DefaultCase) + EdgesVals = EdgesVals.difference(EdgeVal); + else if (i.getCaseSuccessor() == BBTo) EdgesVals = EdgesVals.unionWith(EdgeVal); - } - Result = LVILatticeVal::getRange(EdgesVals); - return true; } + Result = LVILatticeVal::getRange(EdgesVals); + return true; } return false; } |