Skip to content

Commit 9ef9c15

Browse files
committed
MandatoryGenericSpecializer: run optimizations in a loop
To avoid phase ordering problems of the involved optimizations, iterate until we reach a fixed point.
1 parent 4f64770 commit 9ef9c15

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

lib/SILOptimizer/Transforms/GenericSpecializer.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,10 +226,20 @@ void MandatoryGenericSpecializer::run() {
226226
continue;
227227

228228
// Perform generic specialization and other related optimzations.
229-
bool changed = optimize(func, cha);
230229

231-
if (changed)
232-
invalidateAnalysis(func, SILAnalysis::InvalidationKind::Everything);
230+
// To avoid phase ordering problems of the involved optimizations, iterate
231+
// until we reach a fixed point.
232+
// This should always happen, but to be on the save side, limit the number
233+
// of iterations to 10 (which is more than enough - usually the loop runs
234+
// 1 to 3 times).
235+
for (int i = 0; i < 10; i++) {
236+
bool changed = optimize(func, cha);
237+
if (changed) {
238+
invalidateAnalysis(func, SILAnalysis::InvalidationKind::Everything);
239+
} else {
240+
break;
241+
}
242+
}
233243

234244
// Continue specializing called functions.
235245
for (SILBasicBlock &block : *func) {

0 commit comments

Comments
 (0)