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
RyuJIT: Mishandling of subrange assertion for rewritten call parameter #10925
Yeah, so with or without/different repro the problem persists - fgMorphLocalVar uses subrange assertions to avoid inserting the "normalize on load" cast.
That can't work correctly because such subrange assertions can be generated by an earlier small int assignment, if you store 16 bits to a variable then it's obvious that you must insert the normalization cast to get 32 bits out of a subsequent use of the variable.
Unfortunately, fixing this results in a small CQ regression:
Total bytes of diff: 59 (0.00% of base)
diff is a regression.
Top file regressions by size (bytes):
21 : System.Text.RegularExpressions.dasm (0.02% of base)
12 : System.Private.Xml.dasm (0.00% of base)
11 : System.Private.CoreLib.dasm (0.00% of base)
8 : Microsoft.CodeAnalysis.dasm (0.00% of base)
3 : System.Private.Uri.dasm (0.00% of base)
8 total files with size differences (0 improved, 8 regressed), 121 unchanged.
Top method regressions by size (bytes):
21 ( 4.82% of base) : System.Text.RegularExpressions.dasm - RegexCharClass:AddLowercaseRange(ushort,ushort,ref):this
12 ( 2.80% of base) : System.Private.Xml.dasm - XmlSqlBinaryReader:ParseMB32_(ubyte):int:this
8 ( 3.29% of base) : Microsoft.CodeAnalysis.dasm - DesktopAssemblyIdentityComparer:IsFrameworkAssembly(ref):bool
4 (10.00% of base) : System.Private.CoreLib.dasm - Math:Abs(short):short
4 (10.00% of base) : System.Private.CoreLib.dasm - Math:Abs(byte):byte
Top method regressions by size (percentage):
4 (10.00% of base) : System.Private.CoreLib.dasm - Math:Abs(short):short
4 (10.00% of base) : System.Private.CoreLib.dasm - Math:Abs(byte):byte
21 ( 4.82% of base) : System.Text.RegularExpressions.dasm - RegexCharClass:AddLowercaseRange(ushort,ushort,ref):this
8 ( 3.29% of base) : Microsoft.CodeAnalysis.dasm - DesktopAssemblyIdentityComparer:IsFrameworkAssembly(ref):bool
12 ( 2.80% of base) : System.Private.Xml.dasm - XmlSqlBinaryReader:ParseMB32_(ubyte):int:this
10 total methods with size differences (0 improved, 10 regressed), 112828 unchanged.
That's because there are valid cases when the normalization cast can be eliminated - when the variable is enregistered all 32 bits are valid, not only the lower 8/16 bits.
So perhaps a better solution is to make "normalize on load" variables also "normalize on store", that will make the subrange assertion valid since we generate a 32 bit store. But there's at least one case where we can't actually do that - dependent promoted struct fields. Hrm.
However, the initial example in #10660 (comment) still fails, though with a different value - -32766 instead of 1.
And dotnet/coreclr#21184 is also the reason why that example generates a different value now. Of course, it's still incorrect so there's still a bug to be fixed somewhere.
As mentioned above, the current example was actually fixed by another change but the example in that comment still fails. And anyway that comment example is the "original" example that started this, the current one is supposed to be a simplification but it turns out that it is too simple :)
I'm still not 100% sure where the bug really is. It could be that it's incorrect for morph to elide load normalization in some cases but it also looks like my magic division code in lowering is broken in this case. I think I'll just fix the later for now.
I tested all those 3 examples, they all fail even on Windows as well and they all pass after the fix. I ended up including the original example as test, due to its complexity it seems like it has a better chance to hit the bug. It's a rather elusive bug, at least because it requires spilled/not enregistered variables. That's why so far all examples that show the issue have exception handling in them.
I'm not sure that there aren't other bugs related to load normalization, it's a rather convoluted affair. And if there aren't anymore bugs then there may be CQ issues. While in the beginning I was thinking that morph is perhaps wrong not to insert the normalization cast in some cases, now it looks to me that in fact it's too aggressive at doing that.
But I'm 99.99% sure that the bug we're after now is actually in division lowering and that's what I fixed.
Activity
mikedn commentedon Nov 26, 2018
Hrm, apparently this does not reproduce anymore. However, the initial example in https://github.com/dotnet/coreclr/issues/18867#issuecomment-411234557 still fails, though with a different value - -32766 instead of 1.
mikedn commentedon Nov 26, 2018
Yeah, so with or without/different repro the problem persists -
fgMorphLocalVaruses subrange assertions to avoid inserting the "normalize on load" cast.That can't work correctly because such subrange assertions can be generated by an earlier small int assignment, if you store 16 bits to a variable then it's obvious that you must insert the normalization cast to get 32 bits out of a subsequent use of the variable.
Unfortunately, fixing this results in a small CQ regression:
That's because there are valid cases when the normalization cast can be eliminated - when the variable is enregistered all 32 bits are valid, not only the lower 8/16 bits.
So perhaps a better solution is to make "normalize on load" variables also "normalize on store", that will make the subrange assertion valid since we generate a 32 bit store. But there's at least one case where we can't actually do that - dependent promoted struct fields. Hrm.
mikedn commentedon Nov 29, 2018
The example in this issue has actually been fixed by dotnet/coreclr#21184
And dotnet/coreclr#21184 is also the reason why that example generates a different value now. Of course, it's still incorrect so there's still a bug to be fixed somewhere.
mikedn commentedon Dec 1, 2018
@jakobbotsch Could you update the example in this issue to the one in https://github.com/dotnet/coreclr/issues/18867#issuecomment-411234557 ?
As mentioned above, the current example was actually fixed by another change but the example in that comment still fails. And anyway that comment example is the "original" example that started this, the current one is supposed to be a simplification but it turns out that it is too simple :)
I'm still not 100% sure where the bug really is. It could be that it's incorrect for morph to elide load normalization in some cases but it also looks like my magic division code in lowering is broken in this case. I think I'll just fix the later for now.
jakobbotsch commentedon Dec 1, 2018
@mikedn Done. Not sure if it helps, but there are probably some way simpler examples over in Fuzzlyn. For example:
jakobbotsch/Fuzzlyn@f52cb42
jakobbotsch/Fuzzlyn@89eb6a3
jakobbotsch/Fuzzlyn@dcedff2
These have not been tested on Windows, however. But you can check out the ubuntu-x64-examples branch if you want to hunt for some simpler ones.
mikedn commentedon Dec 1, 2018
Thanks!
I tested all those 3 examples, they all fail even on Windows as well and they all pass after the fix. I ended up including the original example as test, due to its complexity it seems like it has a better chance to hit the bug. It's a rather elusive bug, at least because it requires spilled/not enregistered variables. That's why so far all examples that show the issue have exception handling in them.
I'm not sure that there aren't other bugs related to load normalization, it's a rather convoluted affair. And if there aren't anymore bugs then there may be CQ issues. While in the beginning I was thinking that morph is perhaps wrong not to insert the normalization cast in some cases, now it looks to me that in fact it's too aggressive at doing that.
But I'm 99.99% sure that the bug we're after now is actually in division lowering and that's what I fixed.