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
The following program gives an invalid result when optimizations are turned on.
Reproduction Steps
// Generated by Fuzzlyn v1.5 on 2021-10-12 17:42:07// Run on .NET 6.0.0-rc.1.21451.13 on X64 Windows// Seed: 4133580165890247722// Reduced from 169.8 KiB to 0.3 KiB in 00:01:15// Debug: Outputs 65538// Release: Outputs -65538publicclassProgram{publicstaticints_7;publicstaticvoidMain(){varvr5=newlong[]{0};vr5[0]=s_7--;varvr14=newlong[]{0};vr14[0]=(-(1<<s_7)/-32767);System.Console.WriteLine(vr14[0]);}}
Expected behavior
Same result
Actual behavior
Not same result
Regression?
No response
Known Workarounds
No response
Configuration
No response
Other information
1 << s_7 is INT_MIN in the example, so negating it gives INT_MIN again. We probably have an optimization that is not valid for all inputs somewhere.
cc @dotnet/jit-contrib
Activity
ghost added
area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI
Activity
[-]RyuJIT: Invalidly optimized shift[/-][+]RyuJIT: Invalidly optimized negated division[/+]EgorBo commentedon Oct 12, 2021
Even more reduced sample:
It feels like it steps on UB territory, even native compilers are confused here: https://godbolt.org/z/zr9PP6MTc
jakobbotsch commentedon Oct 12, 2021
I think it's UB in C++ on platforms with two's complement but ECMA-335 defines that negating INT_MIN yield sINT_MIN, so I don't think it's UB for us.
EgorBo commentedon Oct 12, 2021
We have an opt
-(expr) / cns=>(expr) / -cnsI don't see how we can disable it hereSingleAccretion commentedon Oct 12, 2021
We may have to give up on it, unless we know that the
exprcannot beint.MinValue.EgorBo commentedon Oct 12, 2021
which means basically remove this opt for DIV entirely (native compilers are fine with it: https://godbolt.org/z/ov94qrsfv)
EgorBo commentedon Oct 12, 2021
I removed the opt and launched spmi to see diffs