Skip to content

Commit ae7e5b5

Browse files
committed
LICM: add limits for the number of alias checks to avoid large compile times in corner cases
Avoid quadratic complexity in corner cases. Usually, these limits will not be exceeded.
1 parent bc2bb5b commit ae7e5b5

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

lib/SILOptimizer/LoopTransforms/LICM.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -937,14 +937,20 @@ void LoopTreeOptimization::analyzeCurrentLoop(
937937
}
938938
}
939939

940-
for (auto *AI : ReadOnlyApplies) {
941-
if (!mayWriteTo(AA, BCA, sideEffects, AI)) {
942-
HoistUp.insert(AI);
940+
// Avoid quadratic complexity in corner cases. Usually, this limit will not be exceeded.
941+
if (ReadOnlyApplies.size() * sideEffects.size() < 8000) {
942+
for (auto *AI : ReadOnlyApplies) {
943+
if (!mayWriteTo(AA, BCA, sideEffects, AI)) {
944+
HoistUp.insert(AI);
945+
}
943946
}
944947
}
945-
for (auto *LI : Loads) {
946-
if (!mayWriteTo(AA, sideEffects, LI)) {
947-
HoistUp.insert(LI);
948+
// Avoid quadratic complexity in corner cases. Usually, this limit will not be exceeded.
949+
if (Loads.size() * sideEffects.size() < 8000) {
950+
for (auto *LI : Loads) {
951+
if (!mayWriteTo(AA, sideEffects, LI)) {
952+
HoistUp.insert(LI);
953+
}
948954
}
949955
}
950956

0 commit comments

Comments
 (0)