From f9065a904fca1018d6ea3e1536b9b3368c084725 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sun, 20 Apr 2008 21:18:09 +0000 Subject: [PATCH] we can only thread blocks when there is a pred we can determine the succ of. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@50003 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Scalar/JumpThreading.cpp | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/lib/Transforms/Scalar/JumpThreading.cpp b/lib/Transforms/Scalar/JumpThreading.cpp index e203f2d4a4f..9f870ab78ab 100644 --- a/lib/Transforms/Scalar/JumpThreading.cpp +++ b/lib/Transforms/Scalar/JumpThreading.cpp @@ -134,15 +134,30 @@ bool JumpThreading::ThreadBlock(BasicBlock &BB) { PHINode *PN = dyn_cast(Condition); if (!PN || PN->getParent() != &BB) return false; + // See if the phi node has any constant values. If so, we can determine where + // the corresponding predecessor will branch. + unsigned PredNo = ~0U; + for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i) { + if (isa(PN->getIncomingValue(i))) { + PredNo = i; + break; + } + } + + // If no incoming value has a constant, we don't know the destination of any + // predecessors. + if (PredNo == ~0U) + return false; + // See if the cost of duplicating this block is low enough. unsigned JumpThreadCost = getJumpThreadDuplicationCost(BB); if (JumpThreadCost > Threshold) { DOUT << " Not threading BB '" << BB.getNameStart() - << "': Cost is too high: " << JumpThreadCost << "\n"; + << "' - Cost is too high: " << JumpThreadCost << "\n"; return false; } - DOUT << " Threading BB '" << BB.getNameStart() << "'. Cost is : " + DOUT << " Threading BB '" << BB.getNameStart() << "'. Cost is: " << JumpThreadCost << "\n"; return false;