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
JIT compiler bug: Incorrect caching of loop variable #13328
I can reproduce this on .Net Core 3.0, so I think this issue should be moved to dotnet/coreclr. Roslyn is the C# compiler, and so JIT bugs don't belong here.
That's interesting, VN figured out correctly that _a in while (_a == 1) is always 0.
Loop hoisting considers trees having constant VN to be invariant and decides to hoist _a (the entire comparison is of course constant but it doesn't make sense to hoist it). By now things have already gone south because illegal code motion has already occurred.
Now one may think that since the VN is constant the involved trees would end being substituted with actual constant nodes and the illegal code motion would be hidden. But only the liberal VN is constant, the conservative one is not.
Not clear what a good fix for this would be. It may be that loop hoisting needs to consider the conservative VN as well if it wants to hoist a constant, otherwise what it tries to hoist isn't really a constant.
Dump showing _a being hoisted into the pre-header for CSE to pick up:
@maythamfahmi
Did you hit this issue with you own real world code?
We are aware that this specific test case fails on older version of .net CoreCLR such as 2.2
Activity
svick commentedon Aug 28, 2019
I can reproduce this on .Net Core 3.0, so I think this issue should be moved to dotnet/coreclr. Roslyn is the C# compiler, and so JIT bugs don't belong here.
stephentoub commentedon Aug 28, 2019
cc: @AndyAyersMS, @jeffschwMSFT
AndyAyersMS commentedon Aug 28, 2019
@BruceForstall can you follow up?
mikedn commentedon Aug 28, 2019
I'm taking a look, this seems to be a bug in loop hoisting and I just fixed a different bug in it.
mikedn commentedon Aug 28, 2019
That's interesting, VN figured out correctly that
_ainwhile (_a == 1)is always 0.Loop hoisting considers trees having constant VN to be invariant and decides to hoist
_a(the entire comparison is of course constant but it doesn't make sense to hoist it). By now things have already gone south because illegal code motion has already occurred.Now one may think that since the VN is constant the involved trees would end being substituted with actual constant nodes and the illegal code motion would be hidden. But only the liberal VN is constant, the conservative one is not.
Not clear what a good fix for this would be. It may be that loop hoisting needs to consider the conservative VN as well if it wants to hoist a constant, otherwise what it tries to hoist isn't really a constant.
Dump showing
_abeing hoisted into the pre-header for CSE to pick up:BruceForstall commentedon Aug 28, 2019
@briansull PTAL
briansull commentedon Aug 28, 2019
Taking a look
BruceForstall commentedon Sep 4, 2019
I'm moving this to 3.1 for now.
maythamfahmi commentedon Sep 6, 2019
I have this issue on vs 2019 community 16.2.4, target framework .net core 2.2
briansull commentedon Sep 6, 2019
@maythamfahmi
Did you hit this issue with you own real world code?
We are aware that this specific test case fails on older version of .net CoreCLR such as 2.2
maythamfahmi commentedon Sep 12, 2019
@briansull no that was not real world so far, it is just me that was not a ware of it. Thank you for beeing active on it. :)
Fix issue #26417 = Incorrect caching of loop variable
Fix issue #26417 = Incorrect caching of loop variable
Fix issue #26417 = Incorrect caching of loop variable
New fix for #26417 - Don't allow the hoisting of GT_CLS_VARs that wer…
New fix for #26417 - Don't allow the hoisting of GT_CLS_VARs that wer…