Skip to content

Commit b708aea

Browse files
nikictstellar
authored andcommitted
[SCEV] Don't perform implication checks with many predicates (llvm#158652)
When adding a new predicate to a union, we currently do a bidirectional implication for all the contained predicates. This means that the number of implication checks is quadratic in the number of total predicates (if they don't end up being eliminated). Fix this by not checking for implication if the number of predicates grows too large. The expectation is that if there is a large number of predicates, we should be discarding them later anyway, as expanding them would be too expensive. Fixes llvm#156114. (cherry picked from commit 7af659d)
1 parent 77a3b0e commit b708aea

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

llvm/lib/Analysis/ScalarEvolution.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15093,15 +15093,20 @@ void SCEVUnionPredicate::add(const SCEVPredicate *N, ScalarEvolution &SE) {
1509315093
return;
1509415094
}
1509515095

15096+
// Implication checks are quadratic in the number of predicates. Stop doing
15097+
// them if there are many predicates, as they should be too expensive to use
15098+
// anyway at that point.
15099+
bool CheckImplies = Preds.size() < 16;
15100+
1509615101
// Only add predicate if it is not already implied by this union predicate.
15097-
if (implies(N, SE))
15102+
if (CheckImplies && implies(N, SE))
1509815103
return;
1509915104

1510015105
// Build a new vector containing the current predicates, except the ones that
1510115106
// are implied by the new predicate N.
1510215107
SmallVector<const SCEVPredicate *> PrunedPreds;
1510315108
for (auto *P : Preds) {
15104-
if (N->implies(P, SE))
15109+
if (CheckImplies && N->implies(P, SE))
1510515110
continue;
1510615111
PrunedPreds.push_back(P);
1510715112
}

0 commit comments

Comments
 (0)