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
// Generated by Fuzzlyn v1.5 on 2022-09-11 14:55:09// Run on Arm64 MacOS// Seed: 6196300087286376006// Reduced from 63.7 KiB to 0.9 KiB in 00:00:14// Debug: Outputs 1// Release: Outputs 0publicclassC0{publicsbyteF6;}publicclassC1{publicboolF0;publicsbyteF1;publicushortF7;publicC1(boolf0){F0=f0;}}publicstructS0{publicC0F2;publicsbyteF5;publicS0(C0f2,sbytef5):this(){F2=f2;F5=f5;}}publicclassProgram{publicstaticS0s_3=newS0(newC0(),1);publicstaticS0s_13=newS0(newC0(),0);publicstaticvoidMain(){C1vr0=newC1(true);C1[]vr1=newC1[]{newC1(true)};for(intvr2=0;vr2<2;vr2++){vr1[0]=vr0;if(vr1[0].F0){vr1[0].F1=s_3.F5;}vr1[0].F7=vr1[0].F7;System.Console.WriteLine(s_13.F2.F6);s_13.F2.F6=vr0.F1;}}}
Repros on win-x64 too. Does not repro with .NET 6, but repros with .NET 7 from two months ago, so not a recent regression it seems.
We seem to hoist the access of vr1[0] out of the loop, even though it is modified inside the loop. Looks pretty similar to #54118.
It was exposed by #58696 which allows us to now reason about this code in VN/hoisting.
We properly mark vr1[0] as having a loop dependency on the LHS, but on the RHS we hit the MapSelect cache and thus the tree on the right does not get the mark (annotated with some comments):
#54118 was in the product for years and this seems like an even harder to hit variant of that (that one was only found by fuzzing). I don't think this is needed for 7.0.
Seems like we just need to add similar logic to the caching side?
Yes, we probably need to introduce a dedicated cache for MapSelect and communicate the memory dependency back from MapSelectWork (and cache it in the dedicated cache). I started working on it but it was not a priori clear to me that there always is a "most conservative" memory dependency to put in the cache. The other alternative is to walk the VN and call optRecordLoopMemoryDependence for all the loop dependencies in the cached case, but seems it would be expensive.
Might also be that we can early out when we hit the first optRecordLoopMemoryDependence, but it wasn't totally clear to me either.
Activity
jakobbotsch commentedon Sep 12, 2022
We seem to hoist the access of
vr1[0]out of the loop, even though it is modified inside the loop. Looks pretty similar to #54118.It was exposed by #58696 which allows us to now reason about this code in VN/hoisting.
jakobbotsch commentedon Sep 12, 2022
The problem seems to come when we value number
We properly mark
vr1[0]as having a loop dependency on the LHS, but on the RHS we hit theMapSelectcache and thus the tree on the right does not get the mark (annotated with some comments):jakobbotsch commentedon Sep 12, 2022
#54118 was in the product for years and this seems like an even harder to hit variant of that (that one was only found by fuzzing). I don't think this is needed for 7.0.
AndyAyersMS commentedon Sep 13, 2022
Seems like we just need to add similar logic to the caching side?
jakobbotsch commentedon Sep 13, 2022
Yes, we probably need to introduce a dedicated cache for
MapSelectand communicate the memory dependency back fromMapSelectWork(and cache it in the dedicated cache). I started working on it but it was not a priori clear to me that there always is a "most conservative" memory dependency to put in the cache. The other alternative is to walk the VN and calloptRecordLoopMemoryDependencefor all the loop dependencies in the cached case, but seems it would be expensive.Might also be that we can early out when we hit the first
optRecordLoopMemoryDependence, but it wasn't totally clear to me either.AndyAyersMS commentedon Mar 31, 2023
We should fix this in .NET 8.
JIT: Cache memory dependencies for VN map selects
JIT: Cache memory dependencies for VN map selects (#89241)