Skip to content

Commit 7af659d

Browse files
authored
[SCEV] Don't perform implication checks with many predicates (#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 #156114.
1 parent 63dc07f commit 7af659d

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
@@ -15176,15 +15176,20 @@ void SCEVUnionPredicate::add(const SCEVPredicate *N, ScalarEvolution &SE) {
1517615176
return;
1517715177
}
1517815178

15179+
// Implication checks are quadratic in the number of predicates. Stop doing
15180+
// them if there are many predicates, as they should be too expensive to use
15181+
// anyway at that point.
15182+
bool CheckImplies = Preds.size() < 16;
15183+
1517915184
// Only add predicate if it is not already implied by this union predicate.
15180-
if (implies(N, SE))
15185+
if (CheckImplies && implies(N, SE))
1518115186
return;
1518215187

1518315188
// Build a new vector containing the current predicates, except the ones that
1518415189
// are implied by the new predicate N.
1518515190
SmallVector<const SCEVPredicate *> PrunedPreds;
1518615191
for (auto *P : Preds) {
15187-
if (N->implies(P, SE))
15192+
if (CheckImplies && N->implies(P, SE))
1518815193
continue;
1518915194
PrunedPreds.push_back(P);
1519015195
}

0 commit comments

Comments
 (0)