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
[win/x86] (uint)double.MaxValue produces different value with optimizations on vs. off #13651
using System;
using System.Threading;
using System.Runtime.CompilerServices;
class Program
{
[MethodImpl(MethodImplOptions.NoInlining)]
static void foo()
{
double x = double.MaxValue;
Console.WriteLine((uint)x);
}
static void Main(string[] args)
{
for (; ; ) { foo(); Thread.Sleep(1); }
}
}
Result
Prints 0s first and then changes to 4294967295 once tier 1 code kicks in
The JIT helper and the VC++ helper behave differently. Tiering aside, this is also an inconsistency between x64 (which always generates 0) and x86 (which generates when optimizing 4294967295).
I wonder if the JIT could simply call CORINFO_HELP_DBL2UINT from gtFoldExprConst somehow. Otherwise we'll probably need to copy that to the JIT code.
The JIT designs should be compatible with cross-compilation.
Yes, so that leaves the JIT with the following choices:
stop constant folding when the result is undefined
try to emulate whatever the helper provided by the VM is doing
The first is probably going to be safer, the second may just move the problem somewhere else - VM's own helpers aren't all written in ASM so they too may sometimes be affected by C++ compiler changes. And even if the JIT copies the VM helper implementation, due to cross-compiling it is not guaranteed that the behavior will be the same. Hopefully such cases are rare.
Activity
jkotas commentedon Oct 26, 2019
cc @dotnet/jit-contrib
This is fallout from VS2017->VS2019 update for official builds. The bug is likely in gtFoldExprConst.
jkotas commentedon Oct 26, 2019
Disabling CoreFX tests against this issue: dotnet/corefx@f9ececd
mikedn commentedon Oct 26, 2019
Tier 0 code:
Tier 1 code:
The
gtFoldExprConstcode generated by VC++:The JIT helper and the VC++ helper behave differently. Tiering aside, this is also an inconsistency between x64 (which always generates 0) and x86 (which generates when optimizing 4294967295).
I wonder if the JIT could simply call
CORINFO_HELP_DBL2UINTfromgtFoldExprConstsomehow. Otherwise we'll probably need to copy that to the JIT code.jkotas commentedon Oct 26, 2019
This does not work for cross-compilation. The JIT designs should be compatible with cross-compilation.
mikedn commentedon Oct 26, 2019
Yes, so that leaves the JIT with the following choices:
The first is probably going to be safer, the second may just move the problem somewhere else - VM's own helpers aren't all written in ASM so they too may sometimes be affected by C++ compiler changes. And even if the JIT copies the VM helper implementation, due to cross-compiling it is not guaranteed that the behavior will be the same. Hopefully such cases are rare.
sandreenko commentedon Oct 26, 2019
That looks like a more stable solution.
Sounds similar to #10905
briansull commentedon Jun 30, 2020
This no longer repros, the code consistently prints 0:
Tier 0 code:
Tier 1 code:
briansull commentedon Jun 30, 2020
Possibly caused by dotnet/coreclr#27384
commit c322db1
Author: Vladimir Sadov [email protected]
Date: Fri Oct 25 10:14:45 2019 -0700
And possibly fixed with commit: 75421f7
briansull commentedon Jun 30, 2020
This issue is fixed