[llvm-commits] [llvm] r88869 - /llvm/trunk/lib/Analysis/LazyValueInfo.cpp
Chris Lattner
sabre at nondot.org
Sun Nov 15 12:02:12 PST 2009
Author: lattner
Date: Sun Nov 15 14:02:12 2009
New Revision: 88869
URL: http://llvm.org/viewvc/llvm-project?rev=88869&view=rev
Log:
teach LVI to infer edge information from switch instructions.
This allows JT to eliminate a ton of infeasible edges when
handling code like the templates in PatternMatch.h
Modified:
llvm/trunk/lib/Analysis/LazyValueInfo.cpp
Modified: llvm/trunk/lib/Analysis/LazyValueInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/LazyValueInfo.cpp?rev=88869&r1=88868&r2=88869&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/LazyValueInfo.cpp (original)
+++ llvm/trunk/lib/Analysis/LazyValueInfo.cpp Sun Nov 15 14:02:12 2009
@@ -403,8 +403,10 @@
}
-/// getEdgeValue - This method
+/// getEdgeValue - This method attempts to infer more complex
LVILatticeVal LVIQuery::getEdgeValue(BasicBlock *BBFrom, BasicBlock *BBTo) {
+ // TODO: Handle more complex conditionals. If (v == 0 || v2 < 1) is false, we
+ // know that v != 0.
if (BranchInst *BI = dyn_cast<BranchInst>(BBFrom->getTerminator())) {
// If this is a conditional branch and only one successor goes to BBTo, then
// we maybe able to infer something from the condition.
@@ -433,11 +435,27 @@
}
}
}
-
- // TODO: Info from switch.
-
- // TODO: Handle more complex conditionals. If (v == 0 || v2 < 1) is false, we
- // know that v != 0.
+
+ // 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) {
+ // We only know something if there is exactly one value that goes from
+ // BBFrom to BBTo.
+ unsigned NumEdges = 0;
+ ConstantInt *EdgeVal = 0;
+ for (unsigned i = 1, e = SI->getNumSuccessors(); i != e; ++i) {
+ if (SI->getSuccessor(i) != BBTo) continue;
+ if (NumEdges++) break;
+ EdgeVal = SI->getCaseValue(i);
+ }
+ assert(EdgeVal && "Missing successor?");
+ if (NumEdges == 1)
+ return LVILatticeVal::get(EdgeVal);
+ }
+ }
// Otherwise see if the value is known in the block.
return getBlockValue(BBFrom);
More information about the llvm-commits
mailing list