You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Perf] Windows/x64: 1 Regression on 8/26/2025 4:33:14 PM +00:00 #119277
More importantly is that 1) we measure OSR code in this benchmark, and 2) we would expect this loop to be unrolled.
2 is the most important, as we would not expect to even require any indexing with unknown index here (which would make the bugfix zero diff). From looking at the graph, I suspect it regressed earlier this year and that the regression is already being tracked by #116754.
Here the header ends up being the block that has the longValue store and compare, and graph based loop inversion duplicates that condition outside the loop. In the end we are left with a shape that is not detected as a candidate for loop unrolling.
My guess is that old lexical loop inversion did not invert here and thus loop unrolling was able to recognize an unrollable loop.
It might be the case that graph inversion should be enhanced to realize in the above case that inversion may not benefit us since the loop is already amenable to be bottom-tested. The loop inversion here just results in a different condition being able to be bottom tested. But I would be weary to make a change like that at this point.
It might also be possible to teach loop unrolling to recognize it as an unrollable loop, even after the inversion happens based on the longValue IR. I think the problem is that loop unrolling just does not find the i = 0 initialization after we duplicate the longValue IR in front of the loop.
I know Aman was looking at ways for inversion / cloning / unrolling to be more synergistic, but I don't know if we have any great ideas on exactly how to pull this off.
Any change here is likely too risky for .NET 10.
For some multi-exit loops perhaps there's some notion of a preferred "last" exit? I think we would prefer an IV related update/exit over something else, so that we're not left with loop-live code that runs after the primary IV gets updated.
Abstractly it would be nice if the loop opts relied on SSA instead of their current heuristic-based searches for induction variable detection (and maybe invariance information). Not sure how much work that would be. Maybe even something like loop closed SSA?
Activity
DrewScoggins commentedon Sep 2, 2025
Related to #118990
DrewScoggins commentedon Sep 2, 2025
This change was backported, so if we make a fix we need to make sure that it is also backported.
DrewScoggins commentedon Sep 2, 2025
Related regressions:
dotnet-policy-service commentedon Sep 3, 2025
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.
jakobbotsch commentedon Sep 9, 2025
My results when comparing 5efdfd0 to 61b5219:
BenchmarkDotNet v0.14.1-nightly.20240924.187, Windows 10 (10.0.19045.6216/22H2/2022Update)
AMD Ryzen 9 5950X 3.40GHz, 1 CPU, 32 logical and 16 physical cores
.NET SDK 9.0.109
[Host] : .NET 9.0.8 (9.0.825.36511), X64 RyuJIT AVX2
Job-VNNUQH : .NET 10.0.0 (42.42.42.42424), X64 RyuJIT AVX2
Job-QIOBHF : .NET 10.0.0 (42.42.42.42424), X64 RyuJIT AVX2
OutlierMode=DontRemove PowerPlanMode=00000000-0000-0000-0000-000000000000 IterationTime=250ms
MaxIterationCount=20 MemoryRandomization=True MinIterationCount=15
WarmupCount=1
jakobbotsch commentedon Sep 9, 2025
There is an extra zero extension in the diff: https://www.diffchecker.com/ITu3PwJu/
That's expected from the bugfix in #118990.
More importantly is that 1) we measure OSR code in this benchmark, and 2) we would expect this loop to be unrolled.
2 is the most important, as we would not expect to even require any indexing with unknown index here (which would make the bugfix zero diff). From looking at the graph, I suspect it regressed earlier this year and that the regression is already being tracked by #116754.
jakobbotsch commentedon Sep 9, 2025
The loop shape of the linked loop above is ambiguous. Instead of the loop being detected as
we end up with a loop shape that is recognized as
Here the header ends up being the block that has the
longValuestore and compare, and graph based loop inversion duplicates that condition outside the loop. In the end we are left with a shape that is not detected as a candidate for loop unrolling.My guess is that old lexical loop inversion did not invert here and thus loop unrolling was able to recognize an unrollable loop.
It might be the case that graph inversion should be enhanced to realize in the above case that inversion may not benefit us since the loop is already amenable to be bottom-tested. The loop inversion here just results in a different condition being able to be bottom tested. But I would be weary to make a change like that at this point.
Any thoughts @AndyAyersMS?
jakobbotsch commentedon Sep 9, 2025
It might also be possible to teach loop unrolling to recognize it as an unrollable loop, even after the inversion happens based on the
longValueIR. I think the problem is that loop unrolling just does not find thei = 0initialization after we duplicate thelongValueIR in front of the loop.AndyAyersMS commentedon Sep 9, 2025
I know Aman was looking at ways for inversion / cloning / unrolling to be more synergistic, but I don't know if we have any great ideas on exactly how to pull this off.
Any change here is likely too risky for .NET 10.
For some multi-exit loops perhaps there's some notion of a preferred "last" exit? I think we would prefer an IV related update/exit over something else, so that we're not left with loop-live code that runs after the primary IV gets updated.
Abstractly it would be nice if the loop opts relied on SSA instead of their current heuristic-based searches for induction variable detection (and maybe invariance information). Not sure how much work that would be. Maybe even something like loop closed SSA?
jakobbotsch commentedon Sep 11, 2025
I do not think we will fix this in .NET 10.