aboutsummaryrefslogtreecommitdiff
path: root/lib/Transforms/Utils/Local.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2003-08-23 23:18:19 +0000
committerChris Lattner <sabre@nondot.org>2003-08-23 23:18:19 +0000
commit7d6c24cdbf41522818ec9ae7b8d3b624660853c1 (patch)
treeebdcd3b3314d591d04a82f730b24f670e7f015e1 /lib/Transforms/Utils/Local.cpp
parent2231d5892b13775e8cd4420318d2c6f82817e44a (diff)
Implement SimplifyCFG/2003-08-17-FoldSwitch.ll:test5
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@8093 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Utils/Local.cpp')
-rw-r--r--lib/Transforms/Utils/Local.cpp13
1 files changed, 13 insertions, 0 deletions
diff --git a/lib/Transforms/Utils/Local.cpp b/lib/Transforms/Utils/Local.cpp
index e668dc3d4a..52973f8724 100644
--- a/lib/Transforms/Utils/Local.cpp
+++ b/lib/Transforms/Utils/Local.cpp
@@ -80,6 +80,9 @@ bool ConstantFoldTerminator(BasicBlock *BB) {
// single branch instruction!
ConstantInt *CI = dyn_cast<ConstantInt>(SI->getCondition());
BasicBlock *TheOnlyDest = SI->getSuccessor(0); // The default dest
+ BasicBlock *DefaultDest = TheOnlyDest;
+ assert(TheOnlyDest == SI->getDefaultDest() &&
+ "Default destination is not successor #0?");
// Figure out which case it goes to...
for (unsigned i = 1, e = SI->getNumSuccessors(); i != e; ++i) {
@@ -89,6 +92,16 @@ bool ConstantFoldTerminator(BasicBlock *BB) {
break;
}
+ // Check to see if this branch is going to the same place as the default
+ // dest. If so, eliminate it as an explicit compare.
+ if (SI->getSuccessor(i) == DefaultDest) {
+ // Remove this entry...
+ DefaultDest->removePredecessor(SI->getParent());
+ SI->removeCase(i);
+ --i; --e; // Don't skip an entry...
+ continue;
+ }
+
// Otherwise, check to see if the switch only branches to one destination.
// We do this by reseting "TheOnlyDest" to null when we find two non-equal
// destinations.