JIT: Avoid cloning cold descendant loops quadratically #96580
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When we have a loop nest where we clone multiple ancestor loops we would clone descendant loops every time, ending up with a total quadratic number of cloned loops in terms of the depth of the loop nest.
Instead of producing these multiple versions of cold loops (each of which is optimized for a particular hot ancestor loop) we can reuse the first cold loop we cloned. This has the effect of exiting all the "hot" versions of ancestor loops if the cloning conditions of a descendant loop fails, but it gets rid of the quadratic loop cloning problem.
Size improvements expected, with a few regressions where RBO was able to fully optimize away some cold loop nests before, and now cannot because they are entered in new, strange ways.
Example:
Flow graph before; a total of 20 loops after cloning has run.
Flow graph after; a total of 5 natural loops after cloning has run, and 5 more unnatural ones.
Assembly diff:
(Easiest to review with whitespace disabled.)
Addresses part of #8558