Skip to content

JIT: Invalid result on x86 with forward sub #66242

Closed

Description

@jakobbotsch

Description

The following program computes the wrong result in x86 when optimizing.

Reproduction Steps

// Generated by Fuzzlyn v1.5 on 2022-02-27 18:35:07
// Run on X86 Windows
// Seed: 14567735315501116995
// Reduced from 12.1 KiB to 0.5 KiB in 00:01:37
// Debug: Outputs 2
// Release: Outputs 1
public struct S0
{
    public ulong F1;
}

public struct S1
{
    public S0 F6;
}

public class Program
{
    public static short s_3;
    public static void Main()
    {
        var vr3 = new S1();
        if (vr3.F6.F1 < M4(ref vr3))
        {
            int vr9 = s_3++;
        }

        System.Console.WriteLine(s_3);
    }

    public static uint M4(ref S1 arg1)
    {
        int var0 = s_3++;
        arg1.F6.F1 = 16700531892663534200UL;
        return 1;
    }
}

Expected behavior

Same result.

Actual behavior

Different results.

Regression?

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 Mar 5, 2022
  2. ghost added
    untriaged
    on Mar 5, 2022
  3. added this to the 7.0.0 milestone on Mar 5, 2022
  4. EgorBo commented on Mar 5, 2022

    @EgorBo
    Member

    Address-exposed issue?

    *************** Starting PHASE Forward Substitution
    
    
    ===> BB01
        [000003]:  not asg (single-use lcl)
        [000013]:  [000014] is only use of [000012] (V02)  -- fwd subbing [000008]; new next stmt is
    STMT00003 ( ??? ... ??? )
                   [000018] --CXG-------              *  JTRUE     void  
                   [000017] N-CXG----U--              \--*  GE        int   
                   [000008] ------------                 +--*  LCL_FLD   long   V00 loc0         [+0] Fseq[F6, F1]
                   [000016] --CXG----U--                 \--*  CAST      long <- ulong <- uint
                   [000011] --CXG-------                    \--*  CALL      int    Program.M4
                   [000010] ------------ arg0                  \--*  LCL_VAR_ADDR byref  V00 loc0         
    
    removing useless STMT00002 ( 0x008[E-] ... 0x01B )
                   [000013] -A--G-------              *  ASG       long  
                   [000012] D------N----              +--*  LCL_VAR   long   V02 tmp0         
                   [000008] ------------              \--*  LCL_FLD   long   V00 loc0         [+0] Fseq[F6, F1]
     from BB01
        [000003]:  not asg (single-use lcl)
    
    
    ===> BB02
        [000025]:  not asg (single-use lcl)
    
    
    ===> BB03
    
    *************** Finishing PHASE Forward Substitution
    
  5. self-assigned this
    on Mar 5, 2022
  6. ghost added
    in-pr
    on Mar 5, 2022
  7. ghost removed
    in-pr
    on Mar 6, 2022
  8. ghost added
    in-pr
    on Mar 6, 2022
  9. removed
    untriaged
    on Mar 7, 2022
  10. ghost removed
    in-pr
    on Mar 7, 2022
  11. added a commit that references this issue on Mar 8, 2022
  12. added a commit that references this issue on Mar 14, 2022
  13. ghost locked as resolved and limited conversation to collaborators on Apr 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

arch-x86area-CodeGen-coreclr

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions