Skip to content
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

Loop inversion should consider top-tested loops #50204

Open
BruceForstall opened this issue Mar 24, 2021 · 0 comments · May be fixed by #105161
Open

Loop inversion should consider top-tested loops #50204

BruceForstall opened this issue Mar 24, 2021 · 0 comments · May be fixed by #105161
Assignees
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI in-pr There is an active PR which will close this issue when it is merged
Milestone

Comments

@BruceForstall
Copy link
Member

Compiler::optInvertWhileLoop() contains the check:

if (fgIsForwardBranch(block) == false)
{
    return;
}

This check is potentially expensive (it iterates over the block list because block numbers are not ordered when this is called).

It is also potentially unnecessary.

Without this check, the loop inversion code works just fine. Instead of the expected pattern, though, it turns top-tested, top-entry loops with an unconditional back-edge to top-tested, top-entry loops with a duplicated condition at the bottom and thus a conditional back-edge. So, it reduces the branches in a loop from 2 to 1, at the cost of the duplicated condition.

There are diffs when removing this check, so the code pattern does exist.

Investigate whether removing this check and enabling this transformation is worthwhile.

category:cq
theme:loop-opt
skill-level:intermediate
cost:small
impact:small

@BruceForstall BruceForstall added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Mar 24, 2021
@BruceForstall BruceForstall added this to the 6.0.0 milestone Mar 24, 2021
@BruceForstall BruceForstall self-assigned this Mar 24, 2021
@dotnet-issue-labeler dotnet-issue-labeler bot added the untriaged New issue has not been triaged by the area owner label Mar 24, 2021
@BruceForstall BruceForstall removed the untriaged New issue has not been triaged by the area owner label Mar 24, 2021
@BruceForstall BruceForstall modified the milestones: 6.0.0, 7.0.0 Jul 6, 2021
@BruceForstall BruceForstall modified the milestones: 7.0.0, 8.0.0 May 26, 2022
@BruceForstall BruceForstall modified the milestones: 8.0.0, 9.0.0 Jul 7, 2023
@amanasifkhalid amanasifkhalid linked a pull request Jul 19, 2024 that will close this issue
@dotnet-policy-service dotnet-policy-service bot added the in-pr There is an active PR which will close this issue when it is merged label Jul 19, 2024
@JulieLeeMSFT JulieLeeMSFT modified the milestones: 9.0.0, 10.0.0 Jul 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI in-pr There is an active PR which will close this issue when it is merged
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants