aboutsummaryrefslogtreecommitdiffstats
path: root/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
commit6186e8c09f891f2baf264c0c81a90936edef5482 (patch)
tree18b4170569790fcb8f5f6159883c29d91fbd45b6 /lib
parent29325c15a51ede0e6f49e2dedd6c7af055c953b2 (diff)
downloadexternal_llvm-6186e8c09f891f2baf264c0c81a90936edef5482.zip
external_llvm-6186e8c09f891f2baf264c0c81a90936edef5482.tar.gz
external_llvm-6186e8c09f891f2baf264c0c81a90936edef5482.tar.bz2
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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@46427 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/Transforms/Scalar/SCCP.cpp23
1 files changed, 19 insertions, 4 deletions
diff --git a/lib/Transforms/Scalar/SCCP.cpp b/lib/Transforms/Scalar/SCCP.cpp
index d5c98fc..07e7009 100644
--- a/lib/Transforms/Scalar/SCCP.cpp
+++ b/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;
}