summaryrefslogtreecommitdiff
path: root/lib/Transforms
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2003-10-08 15:47:41 +0000
committerChris Lattner <sabre@nondot.org>2003-10-08 15:47:41 +0000
commit7d275f459b885b84d9acb5e2292c7d3b6ebd8a6c (patch)
treeb33c91ce60b67161af5baf05e268db5c5197442a /lib/Transforms
parent0d4379a5b041fc52442b1d7e44f2e344bf316e1c (diff)
downloadllvm-7d275f459b885b84d9acb5e2292c7d3b6ebd8a6c.tar.gz
llvm-7d275f459b885b84d9acb5e2292c7d3b6ebd8a6c.tar.bz2
llvm-7d275f459b885b84d9acb5e2292c7d3b6ebd8a6c.tar.xz
Avoid building data structures we don't really need. This improves the runtime
of a test that Bill Wendling sent me from 228.5s to 105s. Obviously there is more improvement to be had, but this is a nice speedup which should be "felt" by many programs. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@8962 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms')
-rw-r--r--lib/Transforms/Scalar/SCCP.cpp49
1 files changed, 39 insertions, 10 deletions
diff --git a/lib/Transforms/Scalar/SCCP.cpp b/lib/Transforms/Scalar/SCCP.cpp
index b9aba13915..7d48185768 100644
--- a/lib/Transforms/Scalar/SCCP.cpp
+++ b/lib/Transforms/Scalar/SCCP.cpp
@@ -381,17 +381,46 @@ bool SCCP::isEdgeFeasible(BasicBlock *From, BasicBlock *To) {
if (!BBExecutable.count(From)) return false;
// Check to make sure this edge itself is actually feasible now...
- TerminatorInst *FT = From->getTerminator();
- std::vector<bool> SuccFeasible;
- getFeasibleSuccessors(*FT, SuccFeasible);
-
- // Check all edges from From to To. If any are feasible, return true.
- for (unsigned i = 0, e = SuccFeasible.size(); i != e; ++i)
- if (FT->getSuccessor(i) == To && SuccFeasible[i])
+ TerminatorInst *TI = From->getTerminator();
+ if (BranchInst *BI = dyn_cast<BranchInst>(TI)) {
+ if (BI->isUnconditional())
return true;
-
- // Otherwise, none of the edges are actually feasible at this time...
- return false;
+ else {
+ InstVal &BCValue = getValueState(BI->getCondition());
+ if (BCValue.isOverdefined()) {
+ // Overdefined condition variables mean the branch could go either way.
+ return true;
+ } else if (BCValue.isConstant()) {
+ // Constant condition variables mean the branch can only go a single way
+ return BI->getSuccessor(BCValue.getConstant() ==
+ ConstantBool::False) == To;
+ }
+ return false;
+ }
+ } else if (InvokeInst *II = dyn_cast<InvokeInst>(TI)) {
+ // Invoke instructions successors are always executable.
+ return true;
+ } else if (SwitchInst *SI = dyn_cast<SwitchInst>(TI)) {
+ InstVal &SCValue = getValueState(SI->getCondition());
+ if (SCValue.isOverdefined()) { // Overdefined condition?
+ // All destinations are executable!
+ return true;
+ } else if (SCValue.isConstant()) {
+ Constant *CPV = SCValue.getConstant();
+ // Make sure to skip the "default value" which isn't a value
+ for (unsigned i = 1, E = SI->getNumSuccessors(); i != E; ++i)
+ if (SI->getSuccessorValue(i) == CPV) // Found the taken branch...
+ return SI->getSuccessor(i) == To;
+
+ // Constant value not equal to any of the branches... must execute
+ // default branch then...
+ return SI->getDefaultDest() == To;
+ }
+ return false;
+ } else {
+ std::cerr << "Unknown terminator instruction: " << *TI;
+ abort();
+ }
}
// visit Implementations - Something changed in this instruction... Either an