-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change loop cloning to work with pre-header blocks #62665
Comments
Tagging subscribers to this area: @JulieLeeMSFT Issue DetailsAfter #62560, if a loop pre-header is created before loop cloning (say, immediately after, or during, loop recognition), loop cloning breaks the pre-header invariants by inserting loop choice conditions after the pre-header and before the cloned loops. Fix this so loop cloning preserves the pre-header, if it exists, so the pre-header invariants (and assertion checking) works.
|
As part of finding natural loops and creating the loop table, create a loop pre-header for every loop. This simplifies a lot of downstream phases, as the loop pre-header will be guaranteed to exist, and will already exist in the dominator tree. Introduce code to preserve an empty pre-header block through the optimization phases. Remove now unnecessary code in hoisting and elsewhere. Fixes dotnet#77033, dotnet#62665
* Always create loop pre-header As part of finding natural loops and creating the loop table, create a loop pre-header for every loop. This simplifies a lot of downstream phases, as the loop pre-header will be guaranteed to exist, and will already exist in the dominator tree. Introduce code to preserve an empty pre-header block through the optimization phases. Remove now unnecessary code in hoisting and elsewhere. Fixes #77033, #62665 * Fix loop unrolling to work with loop pre-headers * Add `optLoopsRequirePreHeaders` variable * Prevent removing pre-header blocks * Allow removing unreachable pre-headers Disallow creating pre-header after SSA is built * Make optLoopCloningEnabled() static * Teach loop cloning to expect and respect loop pre-headers * Remove special case pre-header handling in hoisting * Remove unused SSA update code in fgCreateLoopPreHeader * Remove unneeded pre-header code from fgDominate * Remove workaround to avoid extraneous LSRA diffs due to bbNum ordering * Update comments * Improve loop table rebuilding with pre-headers When the loop table is built, it looks around for various loop patterns, including looking for a guaranteed-executed, pre-loop constant initializer. This is used in loop cloning and loop unrolling. It needs to look "a little harder" in the case we created loop pre-headers, then rebuild the loop table (currently, only due to loop unrolling of loops that contain nested loops). The new code only allows for empty pre-headers. This works since in our current phase ordering, no hoisting happens by the time the loop table is rebuilt. (Actually, it's currently not necessary to do this at all, since the constant initializer info is only used by cloning and loop unrolling, both of which have finished by the time the loop table is rebuilt. However, we might someday choose to rebuild the loop table after cloning and before unrolling, at which point it would be necessary.) * Update comments
Fixed with #83956 |
After #62560, if a loop pre-header is created before loop cloning (say, immediately after, or during, loop recognition), loop cloning breaks the pre-header invariants by inserting loop choice conditions after the pre-header and before the cloned loops.
Fix this so loop cloning preserves the pre-header, if it exists, so the pre-header invariants (and assertion checking) works.
category:cq
theme:loop-opt
skill-level:expert
cost:medium
impact:small
The text was updated successfully, but these errors were encountered: