Skip to content

JIT: Physical promotion can create some writebacks too late #87611

Closed

Description

@jakobbotsch

Run with DOTNET_JitEnablePhysicalPromotion=1.

// Generated by Fuzzlyn v1.5 on 2023-06-15 11:14:42
// Run on X64 Windows
// Seed: 12107000858227890808
// Reduced from 443.3 KiB to 0.8 KiB in 00:02:06
// Debug: Outputs 1
// Release: Outputs 0
public struct S0
{
    public ushort F2;
    public short F3;
    public bool F5;
    public sbyte F7;
    public uint F8;
    public S0(ushort f2): this()
    {
        F2 = f2;
    }
}

public class Program
{
    public static IRuntime s_rt;
    public static uint s_1;
    public static void Main()
    {
        s_rt = new Runtime();
        S0 vr2 = new S0(1);
        var vr3 = vr2.F3;
        var vr4 = (short)M1(vr2, vr3);
        M1(vr2, vr4);
        s_rt.WriteLine(vr2.F2);
        s_rt.WriteLine(vr2.F2);
    }

    public static ref uint M1(S0 arg0, short arg1)
    {
        s_rt.WriteLine(arg0.F2);
        return ref s_1;
    }
}

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

public class Runtime : IRuntime
{
    public void WriteLine<T>(T value) => System.Console.WriteLine(value);
}

Physical promotion sees:

               [000025] --CXG------                         ▌  CALL      byref  Program:M1(S0,short):byref
               [000023] ----------- arg0                    ├──▌  LCL_VAR   struct<S0, 12> V00 loc0         
               [000021] --CXG------ arg1                    └──▌  CAST      int <- short <- int
               [000020] --CXG------                            └──▌  IND       int   
               [000018] --CXG------                               └──▌  CALL      byref  Program:M1(S0,short):byref
               [000016] ----------- arg0                             ├──▌  LCL_VAR   struct<S0, 12> V00 loc0         
               [000017] ----------- arg1                             └──▌  LCL_VAR   int    V01 loc1          (last use)

and creates

               [000025] -ACXG------                         ▌  CALL      byref  Program:M1(S0,short):byref
               [000023] ----------- arg0                    ├──▌  LCL_VAR   struct<S0, 12> V00 loc0         
               [000021] -ACXG------ arg1                    └──▌  CAST      int <- short <- int
               [000020] -ACXG------                            └──▌  IND       int   
               [000018] -ACXG------                               └──▌  CALL      byref  Program:M1(S0,short):byref
               [000089] -A--------- arg0                             ├──▌  COMMA     struct
               [000088] UA---------                                  │  ├──▌  STORE_LCL_FLD ushort V00 loc0         [+0]
               [000087] -----------                                  │  │  └──▌  LCL_VAR   int    V09 tmp6         
               [000016] -----------                                  │  └──▌  LCL_VAR   struct<S0, 12> V00 loc0          (last use)
               [000017] ----------- arg1                             └──▌  LCL_VAR   int    V01 loc1          (last use)

The inserted store [000088] happens too late. It should be inserted before [000023]. It is a result of the way we wait until we see the call to insert writebacks for the operands.

Activity

  1. ghost added
    untriaged
    on Jun 15, 2023
  2. ghost added
    area-CodeGen-coreclr
    on Jun 15, 2023
  3. added this to the 8.0.0 milestone on Jun 15, 2023
  4. removed
    untriaged
    on Jun 15, 2023
  5. self-assigned this
    on Jun 15, 2023
  6. ghost added
    in-pr
    on Jun 15, 2023
  7. added a commit that references this issue on Jun 19, 2023
    67f2385
  8. ghost removed
    in-pr
    on Jun 19, 2023
  9. ghost locked as resolved and limited conversation to collaborators on Jul 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area-CodeGen-coreclr

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions