aboutsummaryrefslogtreecommitdiff
path: root/lib/Transforms/Scalar/JumpThreading.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2008-04-21 02:57:57 +0000
committerChris Lattner <sabre@nondot.org>2008-04-21 02:57:57 +0000
commit2cc675180b06d0a2173365a4015606933f1a285d (patch)
tree913370e3716a8e5c4efc1ff189057ca19b92a6c1 /lib/Transforms/Scalar/JumpThreading.cpp
parent54b9c3ba2a5b0aa8fda817bcc72c370040cfb3f8 (diff)
Use the new SplitBlockPredecessors to implement a todo.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@50022 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Scalar/JumpThreading.cpp')
-rw-r--r--lib/Transforms/Scalar/JumpThreading.cpp20
1 files changed, 16 insertions, 4 deletions
diff --git a/lib/Transforms/Scalar/JumpThreading.cpp b/lib/Transforms/Scalar/JumpThreading.cpp
index 358b8e284a..3bca7ff19a 100644
--- a/lib/Transforms/Scalar/JumpThreading.cpp
+++ b/lib/Transforms/Scalar/JumpThreading.cpp
@@ -17,6 +17,7 @@
#include "llvm/Pass.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/Statistic.h"
+#include "llvm/Transforms/Utils/BasicBlockUtils.h"
#include "llvm/Transforms/Utils/Local.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Compiler.h"
@@ -194,10 +195,21 @@ bool JumpThreading::ThreadBlock(BasicBlock *BB) {
SuccBB = SI->getSuccessor(SI->findCaseValue(PredCst));
}
- // TODO: If there are multiple preds with the same incoming value for the PHI,
- // factor them together so we get one thread block for the whole group. This
- // is important for things like "phi i1 [true, true, false, true, x]" where
- // we only need to clone the block for the true blocks once.
+ // If there are multiple preds with the same incoming value for the PHI,
+ // factor them together so we get one block to thread for the whole group.
+ // This is important for things like "phi i1 [true, true, false, true, x]"
+ // where we only need to clone the block for the true blocks once.
+ SmallVector<BasicBlock*, 16> CommonPreds;
+ for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i)
+ if (PN->getIncomingValue(i) == PredCst)
+ CommonPreds.push_back(PN->getIncomingBlock(i));
+ if (CommonPreds.size() != 1) {
+ DOUT << " Factoring out " << CommonPreds.size()
+ << " common predecessors.\n";
+ PredBB = SplitBlockPredecessors(BB, &CommonPreds[0], CommonPreds.size(),
+ ".thr_comm", this);
+ }
+
DOUT << " Threading edge from '" << PredBB->getNameStart() << "' to '"
<< SuccBB->getNameStart() << "' with cost: " << JumpThreadCost