aboutsummaryrefslogtreecommitdiff
path: root/lib/Transforms/Scalar/SCCP.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2004-01-12 17:40:36 +0000
committerChris Lattner <sabre@nondot.org>2004-01-12 17:40:36 +0000
commit84831642e4ecdb8188df48fc62bb89cd41033daa (patch)
treec93ad912bd3f998504f998fc23afb23b0b2dc8e7 /lib/Transforms/Scalar/SCCP.cpp
parentd56147dc72a8ec245a5b5ad94013293b8b77849d (diff)
Fix fairly severe bug in my last checking where we treated all unfoldable
constants as being "true" when evaluating branches. This was introduced because we now create constantexprs for the constants instead of failing the fold. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@10778 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Scalar/SCCP.cpp')
-rw-r--r--lib/Transforms/Scalar/SCCP.cpp15
1 files changed, 12 insertions, 3 deletions
diff --git a/lib/Transforms/Scalar/SCCP.cpp b/lib/Transforms/Scalar/SCCP.cpp
index 3c92afe8cf..a570ba8b13 100644
--- a/lib/Transforms/Scalar/SCCP.cpp
+++ b/lib/Transforms/Scalar/SCCP.cpp
@@ -362,8 +362,10 @@ void SCCP::getFeasibleSuccessors(TerminatorInst &TI, std::vector<bool> &Succs) {
Succs[0] = true;
} else {
InstVal &BCValue = getValueState(BI->getCondition());
- if (BCValue.isOverdefined()) {
- // Overdefined condition variables mean the branch could go either way.
+ if (BCValue.isOverdefined() ||
+ (BCValue.isConstant() && !isa<ConstantBool>(BCValue.getConstant()))) {
+ // Overdefined condition variables, and branches on unfoldable constant
+ // conditions, mean the branch could go either way.
Succs[0] = Succs[1] = true;
} else if (BCValue.isConstant()) {
// Constant condition variables mean the branch can only go a single way
@@ -375,7 +377,8 @@ void SCCP::getFeasibleSuccessors(TerminatorInst &TI, std::vector<bool> &Succs) {
Succs[0] = Succs[1] = true;
} else if (SwitchInst *SI = dyn_cast<SwitchInst>(&TI)) {
InstVal &SCValue = getValueState(SI->getCondition());
- if (SCValue.isOverdefined()) { // Overdefined condition?
+ if (SCValue.isOverdefined() || // Overdefined condition?
+ (SCValue.isConstant() && !isa<ConstantInt>(SCValue.getConstant()))) {
// All destinations are executable!
Succs.assign(TI.getNumSuccessors(), true);
} else if (SCValue.isConstant()) {
@@ -419,6 +422,9 @@ bool SCCP::isEdgeFeasible(BasicBlock *From, BasicBlock *To) {
// Overdefined condition variables mean the branch could go either way.
return true;
} else if (BCValue.isConstant()) {
+ // Not branching on an evaluatable constant?
+ if (!isa<ConstantBool>(BCValue.getConstant())) return true;
+
// Constant condition variables mean the branch can only go a single way
return BI->getSuccessor(BCValue.getConstant() ==
ConstantBool::False) == To;
@@ -435,6 +441,9 @@ bool SCCP::isEdgeFeasible(BasicBlock *From, BasicBlock *To) {
return true;
} else if (SCValue.isConstant()) {
Constant *CPV = SCValue.getConstant();
+ if (!isa<ConstantInt>(CPV))
+ return true; // not a foldable constant?
+
// 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...