Skip to content

Commit 2349531

Browse files
committed
Teach the jump threading optimization to stop scanning the basic block when calculating the cost after passing the threshold.
llvm-svn: 169135
1 parent 4c2094b commit 2349531

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

llvm/lib/Transforms/Scalar/JumpThreading.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -216,19 +216,24 @@ bool JumpThreading::runOnFunction(Function &F) {
216216
}
217217

218218
/// getJumpThreadDuplicationCost - Return the cost of duplicating this block to
219-
/// thread across it.
220-
static unsigned getJumpThreadDuplicationCost(const BasicBlock *BB) {
219+
/// thread across it. Stop scanning the block when passing the threshold.
220+
static unsigned getJumpThreadDuplicationCost(const BasicBlock *BB,
221+
unsigned Threshold) {
221222
/// Ignore PHI nodes, these will be flattened when duplication happens.
222223
BasicBlock::const_iterator I = BB->getFirstNonPHI();
223224

224225
// FIXME: THREADING will delete values that are just used to compute the
225226
// branch, so they shouldn't count against the duplication cost.
226227

227-
228228
// Sum up the cost of each instruction until we get to the terminator. Don't
229229
// include the terminator because the copy won't include it.
230230
unsigned Size = 0;
231231
for (; !isa<TerminatorInst>(I); ++I) {
232+
233+
// Stop scanning the block if we've reached the threshold.
234+
if (Size > Threshold)
235+
return Size;
236+
232237
// Debugger intrinsics don't incur code size.
233238
if (isa<DbgInfoIntrinsic>(I)) continue;
234239

@@ -1337,7 +1342,7 @@ bool JumpThreading::ThreadEdge(BasicBlock *BB,
13371342
return false;
13381343
}
13391344

1340-
unsigned JumpThreadCost = getJumpThreadDuplicationCost(BB);
1345+
unsigned JumpThreadCost = getJumpThreadDuplicationCost(BB, Threshold);
13411346
if (JumpThreadCost > Threshold) {
13421347
DEBUG(dbgs() << " Not threading BB '" << BB->getName()
13431348
<< "' - Cost is too high: " << JumpThreadCost << "\n");
@@ -1481,7 +1486,7 @@ bool JumpThreading::DuplicateCondBranchOnPHIIntoPred(BasicBlock *BB,
14811486
return false;
14821487
}
14831488

1484-
unsigned DuplicationCost = getJumpThreadDuplicationCost(BB);
1489+
unsigned DuplicationCost = getJumpThreadDuplicationCost(BB, Threshold);
14851490
if (DuplicationCost > Threshold) {
14861491
DEBUG(dbgs() << " Not duplicating BB '" << BB->getName()
14871492
<< "' - Cost is too high: " << DuplicationCost << "\n");

0 commit comments

Comments
 (0)