Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JIT: Invalid result computed with modulo operation #71600

Closed
jakobbotsch opened this issue Jul 3, 2022 · 2 comments · Fixed by #71615
Closed

JIT: Invalid result computed with modulo operation #71600

jakobbotsch opened this issue Jul 3, 2022 · 2 comments · Fixed by #71615
Assignees
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI
Milestone

Comments

@jakobbotsch
Copy link
Member

// Generated by Fuzzlyn v1.5 on 2022-07-03 14:40:52
// Run on Arm64 MacOS
// Seed: 5960657379714964908
// Reduced from 328.5 KiB to 0.8 KiB in 00:02:08
// Debug: Outputs 0
// Release: Outputs 1
public struct S0
{
    public long F0;
    public long F1;
    public S0(long f1): this()
    {
        F1 = f1;
    }
}

public struct S1
{
    public uint F1;
    public ushort F2;
    public S0 F4;
    public S1(ulong f5): this()
    {
    }

    public long M82(ref short[] arg0)
    {
        Program.s_13 = this.F1++;
        S1 var1 = new S1(0);
        return Program.s_39[0].F1;
    }
}

public class Program
{
    public static uint s_13;
    public static short[] s_28;
    public static S0[] s_39;
    public static void Main()
    {
        S0[] vr2 = new S0[]{new S0(-1)};
        s_39 = vr2;
        S1 vr3 = default(S1);
        M80(vr3);
    }

    public static void M80(S1 arg0)
    {
        arg0.F2 += (ushort)(arg0.F1 % (uint)arg0.M82(ref s_28));
        System.Console.WriteLine(arg0.F2);
    }
}
@dotnet-issue-labeler dotnet-issue-labeler bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Jul 3, 2022
@ghost ghost added the untriaged New issue has not been triaged by the area owner label Jul 3, 2022
@ghost
Copy link

ghost commented Jul 3, 2022

Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.

Issue Details
// Generated by Fuzzlyn v1.5 on 2022-07-03 14:40:52
// Run on Arm64 MacOS
// Seed: 5960657379714964908
// Reduced from 328.5 KiB to 0.8 KiB in 00:02:08
// Debug: Outputs 0
// Release: Outputs 1
public struct S0
{
    public long F0;
    public long F1;
    public S0(long f1): this()
    {
        F1 = f1;
    }
}

public struct S1
{
    public uint F1;
    public ushort F2;
    public S0 F4;
    public S1(ulong f5): this()
    {
    }

    public long M82(ref short[] arg0)
    {
        Program.s_13 = this.F1++;
        S1 var1 = new S1(0);
        return Program.s_39[0].F1;
    }
}

public class Program
{
    public static uint s_13;
    public static short[] s_28;
    public static S0[] s_39;
    public static void Main()
    {
        S0[] vr2 = new S0[]{new S0(-1)};
        s_39 = vr2;
        S1 vr3 = default(S1);
        M80(vr3);
    }

    public static void M80(S1 arg0)
    {
        arg0.F2 += (ushort)(arg0.F1 % (uint)arg0.M82(ref s_28));
        System.Console.WriteLine(arg0.F2);
    }
}
Author: jakobbotsch
Assignees: -
Labels:

area-CodeGen-coreclr

Milestone: -

@jakobbotsch
Copy link
Member Author

The mod transform reorders the read of arg0.F1 and the function call arg0.M82(...):

fgMorphTree (before 17):
               [000024] --CXG------UMOD      int   
               [000011] -----------                         ├──▌  LCL_FLD   int    V00 arg0         [+0]
               [000023] --CXG------                         └──▌  CAST      int <- uint <- long
               [000015] --CXG------                            └──▌  CALL      long   S1.M82
               [000013] ----------- this                          ├──▌  LCL_VAR_ADDR byref  V00 arg0         
               [000014] H---------- arg1                          └──▌  CNS_INT(h) long   0x1bdae801f10 static Fseq[s_28]

...

fgMorphTree (after 17):
               [000047] -ACXG+-----COMMA     int   
               [000041] -ACXG+-----                         ├──▌  ASG       int   
               [000040] D----+-N---                         │  ├──▌  LCL_VAR   int    V05 tmp4         
               [000023] --CXG+-----                         │  └──▌  CAST      int <- uint <- long
               [000015] --CXG+-----                         │     └──▌  CALL      long   S1.M82
               [000013] -----+----- this in x0              │        ├──▌  LCL_VAR   byref  V00 arg0         
               [000014] H----+----- arg1 in x1              │        └──▌  CNS_INT(h) long   0x1bdae801f10 static Fseq[s_28]
               [000046] ---XG+-----                         └──▌  SUB       int   
               [000048] n---G+-----                            ├──▌  IND       int   
               [000011] -----+-----                            │  └──▌  LCL_VAR   byref  V00 arg0         
               [000045] ---XG+-----                            └──▌  MUL       int   
               [000024] ---XG+-----                               ├──▌  UDIV      int   
               [000049] n---G+-----                               │  ├──▌  IND       int   
               [000043] -----+-----                               │  │  └──▌  LCL_VAR   byref  V00 arg0         
               [000044] -----+-----                               │  └──▌  LCL_VAR   int    V05 tmp4         
               [000042] -----+-----                               └──▌  LCL_VAR   int    V05 tmp4         

This is probably exposed by recent local morph changes causing us to forward sub the access of arg0.F1.

@ghost ghost added the in-pr There is an active PR which will close this issue when it is merged label Jul 4, 2022
@jakobbotsch jakobbotsch added this to the 7.0.0 milestone Jul 4, 2022
@jakobbotsch jakobbotsch self-assigned this Jul 4, 2022
@ghost ghost removed the untriaged New issue has not been triaged by the area owner label Jul 4, 2022
@ghost ghost removed the in-pr There is an active PR which will close this issue when it is merged label Jul 6, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Aug 5, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant