Skip to content

Commit 5f7a535

Browse files
committed
[SCEV] Cap the number of instructions scanned when infering flags
This addresses a comment from review on D109845. The concern was raised that an unbounded scan would be expensive. Long term plan is to cache this search - likely reusing the existing mechanism for loop side effects - but let's be simple and conservative for now.
1 parent 35ab211 commit 5f7a535

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

llvm/lib/Analysis/ScalarEvolution.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6597,9 +6597,19 @@ const Instruction *ScalarEvolution::getDefiningScopeBound(const SCEV *S) {
65976597
static bool
65986598
isGuaranteedToTransferExecutionToSuccessor(BasicBlock::const_iterator Begin,
65996599
BasicBlock::const_iterator End) {
6600-
return llvm::all_of( make_range(Begin, End), [](const Instruction &I) {
6601-
return isGuaranteedToTransferExecutionToSuccessor(&I);
6602-
});
6600+
// Limit number of instructions we look at, to avoid scanning through large
6601+
// blocks. The current limit is chosen arbitrarily.
6602+
unsigned ScanLimit = 32;
6603+
for (const Instruction &I : make_range(Begin, End)) {
6604+
if (isa<DbgInfoIntrinsic>(I))
6605+
continue;
6606+
if (--ScanLimit == 0)
6607+
return false;
6608+
6609+
if (!isGuaranteedToTransferExecutionToSuccessor(&I))
6610+
return false;
6611+
}
6612+
return true;
66036613
}
66046614

66056615
bool ScalarEvolution::isGuaranteedToTransferExecutionTo(const Instruction *A,

0 commit comments

Comments
 (0)