summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2008-01-28 00:32:30 +0000
committerChris Lattner <sabre@nondot.org>2008-01-28 00:32:30 +0000
commit1b706dd680745f4f7d6e6e62cf4777dc161abd9a (patch)
tree425243f36e02327cde8557dbc7c51f405a181718 /llvm/lib
parent02bf44436ffbec63d3f989b58e8b433432039442 (diff)
downloadbcm5719-llvm-1b706dd680745f4f7d6e6e62cf4777dc161abd9a.tar.gz
bcm5719-llvm-1b706dd680745f4f7d6e6e62cf4777dc161abd9a.zip
Fix PR1938 by forcing the code that uses an undefined value to branch one
way or the other. Rewriting the code itself prevents subsequent analysis passes from making contradictory conclusions about the code that could cause an infeasible path to be made feasible. llvm-svn: 46427
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Transforms/Scalar/SCCP.cpp23
1 files changed, 19 insertions, 4 deletions
diff --git a/llvm/lib/Transforms/Scalar/SCCP.cpp b/llvm/lib/Transforms/Scalar/SCCP.cpp
index d5c98fc4955..07e70099769 100644
--- a/llvm/lib/Transforms/Scalar/SCCP.cpp
+++ b/llvm/lib/Transforms/Scalar/SCCP.cpp
@@ -1313,15 +1313,30 @@ bool SCCPSolver::ResolvedUndefsIn(Function &F) {
continue;
}
- // If the edge to the first successor isn't thought to be feasible yet, mark
- // it so now.
- if (KnownFeasibleEdges.count(Edge(BB, TI->getSuccessor(0))))
+ // If the edge to the second successor isn't thought to be feasible yet,
+ // mark it so now. We pick the second one so that this goes to some
+ // enumerated value in a switch instead of going to the default destination.
+ if (KnownFeasibleEdges.count(Edge(BB, TI->getSuccessor(1))))
continue;
// Otherwise, it isn't already thought to be feasible. Mark it as such now
// and return. This will make other blocks reachable, which will allow new
// values to be discovered and existing ones to be moved in the lattice.
- markEdgeExecutable(BB, TI->getSuccessor(0));
+ markEdgeExecutable(BB, TI->getSuccessor(1));
+
+ // This must be a conditional branch of switch on undef. At this point,
+ // force the old terminator to branch to the first successor. This is
+ // required because we are now influencing the dataflow of the function with
+ // the assumption that this edge is taken. If we leave the branch condition
+ // as undef, then further analysis could think the undef went another way
+ // leading to an inconsistent set of conclusions.
+ if (BranchInst *BI = dyn_cast<BranchInst>(TI)) {
+ BI->setCondition(ConstantInt::getFalse());
+ } else {
+ SwitchInst *SI = cast<SwitchInst>(TI);
+ SI->setCondition(SI->getCaseValue(1));
+ }
+
return true;
}
OpenPOWER on IntegriCloud