Skip to content

JIT: Incorrect result computed with forward sub #65104

Closed

Description

@jakobbotsch

Description

The following program computes a wrong result on arm64.

Reproduction Steps

// Generated by Fuzzlyn v1.5 on 2022-02-08 16:14:33
// Run on Arm64 Linux
// Seed: 10380378818647712015
// Reduced from 169.3 KiB to 0.7 KiB in 00:44:43
// Debug: Outputs 0
// Release: Outputs 1
public class C0
{
}

public struct S0
{
    public uint F2;
    public C0 F4;
    public uint F5;
    public int F7;
    public short F9;
    public S0(uint f2, int f7): this()
    {
        F7 = f7;
    }

    public int M21(uint arg0)
    {
        S0[] var0 = new S0[]{new S0(0, 0)};
        var vr1 = new S0(this.F2++, Program.M23());
        return Program.s_8.F7;
    }
}

public class Program
{
    public static IRT s_rt;
    public static uint s_2;
    public static S0 s_8 = new S0(0, 1);
    public static void Main()
    {
        s_rt = new C();
        S0 vr8 = default(S0);
        ushort vr9 = (ushort)(vr8.F2 % (ushort)vr8.M21(s_2));
        s_rt.WriteLine(vr9);
    }

    public static byte M23()
    {
        return default(byte);
    }
}

public interface IRT
{
    void WriteLine<T>(T value);
}

public class C : IRT
{
    public void WriteLine<T>(T value)
    {
        System.Console.WriteLine(value);
    }
}

Expected behavior

Same result in debug and release.

Actual behavior

Differing results.

Regression?

Yes, does not repro with COMPlus_JitNoForwardSub=1.

Known Workarounds

No response

Configuration

No response

Other information

cc @dotnet/jit-contrib @AndyAyersMS

Activity

  1. ghost added
    area-CodeGen-coreclr
    on Feb 9, 2022
  2. ghost added
    untriaged
    on Feb 9, 2022
  3. added this to the 7.0.0 milestone on Feb 9, 2022
  4. removed
    untriaged
    on Feb 9, 2022
  5. AndyAyersMS commented on Feb 9, 2022

    @AndyAyersMS
    Member

    Suspect fgMorphModToSubMulDiv is doing an unsafe reordering.

  6. AndyAyersMS commented on Feb 10, 2022

    @AndyAyersMS
    Member

    fgMorphModToSubMulDiv is invoked in preorder which means we don't have up to date flag info for the child operands. This makes doing interference checking difficult. So, either we can

    (a) always spill
    (b) do some "cheap" analysis to avoid spilling for unaliased locals and constants
    (c) try moving this optimization to post-order

    Going to pursue (a) but am tempted by (c).

  7. ghost added
    in-pr
    on Feb 10, 2022
  8. ghost removed
    in-pr
    on Feb 11, 2022
  9. ghost locked as resolved and limited conversation to collaborators on Mar 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

arch-arm64area-CodeGen-coreclr

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions