@@ -216,19 +216,24 @@ bool JumpThreading::runOnFunction(Function &F) {
216
216
}
217
217
218
218
// / 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) {
221
222
// / Ignore PHI nodes, these will be flattened when duplication happens.
222
223
BasicBlock::const_iterator I = BB->getFirstNonPHI ();
223
224
224
225
// FIXME: THREADING will delete values that are just used to compute the
225
226
// branch, so they shouldn't count against the duplication cost.
226
227
227
-
228
228
// Sum up the cost of each instruction until we get to the terminator. Don't
229
229
// include the terminator because the copy won't include it.
230
230
unsigned Size = 0 ;
231
231
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
+
232
237
// Debugger intrinsics don't incur code size.
233
238
if (isa<DbgInfoIntrinsic>(I)) continue ;
234
239
@@ -1337,7 +1342,7 @@ bool JumpThreading::ThreadEdge(BasicBlock *BB,
1337
1342
return false ;
1338
1343
}
1339
1344
1340
- unsigned JumpThreadCost = getJumpThreadDuplicationCost (BB);
1345
+ unsigned JumpThreadCost = getJumpThreadDuplicationCost (BB, Threshold );
1341
1346
if (JumpThreadCost > Threshold) {
1342
1347
DEBUG (dbgs () << " Not threading BB '" << BB->getName ()
1343
1348
<< " ' - Cost is too high: " << JumpThreadCost << " \n " );
@@ -1481,7 +1486,7 @@ bool JumpThreading::DuplicateCondBranchOnPHIIntoPred(BasicBlock *BB,
1481
1486
return false ;
1482
1487
}
1483
1488
1484
- unsigned DuplicationCost = getJumpThreadDuplicationCost (BB);
1489
+ unsigned DuplicationCost = getJumpThreadDuplicationCost (BB, Threshold );
1485
1490
if (DuplicationCost > Threshold) {
1486
1491
DEBUG (dbgs () << " Not duplicating BB '" << BB->getName ()
1487
1492
<< " ' - Cost is too high: " << DuplicationCost << " \n " );
0 commit comments