summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/Scalar/JumpThreading.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2008-04-25 04:12:29 +0000
committerChris Lattner <sabre@nondot.org>2008-04-25 04:12:29 +0000
commitf7de528463dbc1353cd56ffb3efc4abb563f2c4e (patch)
tree4f2e20067bab238a846f21514751eeaad8359871 /llvm/lib/Transforms/Scalar/JumpThreading.cpp
parent2ad5aef5e615c12feb21107c023df313f5c38726 (diff)
downloadbcm5719-llvm-f7de528463dbc1353cd56ffb3efc4abb563f2c4e.tar.gz
bcm5719-llvm-f7de528463dbc1353cd56ffb3efc4abb563f2c4e.zip
Don't infininitely thread branches when a threaded edge
goes back to the block, e.g.: Threading edge through bool from 'bb37.us.thread3829' to 'bb37.us' with cost: 1, across block: bb37.us: ; preds = %bb37.us.thread3829, %bb37.us, %bb33 %D1361.1.us = phi i32 [ %tmp36, %bb33 ], [ %D1361.1.us, %bb37.us ], [ 0, %bb37.us.thread3829 ] ; <i32> [#uses=2] %tmp39.us = icmp eq i32 %D1361.1.us, 0 ; <i1> [#uses=1] br i1 %tmp39.us, label %bb37.us, label %bb42.us llvm-svn: 50251
Diffstat (limited to 'llvm/lib/Transforms/Scalar/JumpThreading.cpp')
-rw-r--r--llvm/lib/Transforms/Scalar/JumpThreading.cpp22
1 files changed, 22 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/Scalar/JumpThreading.cpp b/llvm/lib/Transforms/Scalar/JumpThreading.cpp
index 92e40e66d43..be940254049 100644
--- a/llvm/lib/Transforms/Scalar/JumpThreading.cpp
+++ b/llvm/lib/Transforms/Scalar/JumpThreading.cpp
@@ -250,6 +250,13 @@ bool JumpThreading::ProcessJumpOnPHI(PHINode *PN) {
SuccBB = SI->getSuccessor(SI->findCaseValue(PredCst));
}
+ // If threading to the same block as we come from, we would infinite loop.
+ if (SuccBB == BB) {
+ DOUT << " Not threading BB '" << BB->getNameStart()
+ << "' - would thread to self!\n";
+ return false;
+ }
+
// And finally, do it!
DOUT << " Threading edge from '" << PredBB->getNameStart() << "' to '"
<< SuccBB->getNameStart() << "' with cost: " << JumpThreadCost
@@ -319,6 +326,13 @@ bool JumpThreading::ProcessBranchOnLogical(Value *V, BasicBlock *BB,
// 'true' block.
BasicBlock *SuccBB = BB->getTerminator()->getSuccessor(isAnd);
+ // If threading to the same block as we come from, we would infinite loop.
+ if (SuccBB == BB) {
+ DOUT << " Not threading BB '" << BB->getNameStart()
+ << "' - would thread to self!\n";
+ return false;
+ }
+
// And finally, do it!
DOUT << " Threading edge through bool from '" << PredBB->getNameStart()
<< "' to '" << SuccBB->getNameStart() << "' with cost: "
@@ -390,6 +404,14 @@ bool JumpThreading::ProcessBranchOnCompare(CmpInst *Cmp, BasicBlock *BB) {
// Next, get our successor.
BasicBlock *SuccBB = BB->getTerminator()->getSuccessor(!TrueDirection);
+ // If threading to the same block as we come from, we would infinite loop.
+ if (SuccBB == BB) {
+ DOUT << " Not threading BB '" << BB->getNameStart()
+ << "' - would thread to self!\n";
+ return false;
+ }
+
+
// And finally, do it!
DOUT << " Threading edge through bool from '" << PredBB->getNameStart()
<< "' to '" << SuccBB->getNameStart() << "' with cost: "
OpenPOWER on IntegriCloud