Skip to content

Forward substitution for relops misses LCL_FLD uses #62524

Closed

Description

@SingleAccretion

Reproduction:

using System;
using System.Runtime.CompilerServices;

Console.WriteLine(Problem(new() { Value = 1 }));

[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)]
private static int Problem(StructWithIndex a)
{
    bool k = a.Value == 1;
    a = default;
    if (k)
    {
        return 1;
    }

    return a.Index;
}

struct StructWithIndex
{
    public int Index;
    public int Value;
}

Run with DOTNET_JitNoStructPromotion=1 and DOTNET_JitNoCSE=1.

Expected result: prints 1.
Actual result: prints 0.

Cause: the interference checks in the forward substitution algorithm use gtHasRef which does not pay attention to LCL_FLD nodes:

optRedundantRelop in BB01; jump tree is
N004 (  5,  5) [000014] ------------              *  JTRUE     void
N003 (  3,  3) [000013] J------N----              \--*  EQ        int    $142
N001 (  1,  1) [000011] ------------                 +--*  LCL_VAR   int    V02 tmp1         u:1 (last use) $141
N002 (  1,  1) [000012] ------------                 \--*  CNS_INT   int    0 $40
 ... checking previous tree
N003 (  5,  4) [000008] IA------R---              *  ASG       struct (init) $VN.Void
N002 (  3,  2) [000005] D------N----              +--*  LCL_VAR   struct<StructWithIndex, 8> V00 arg0         d:2
N001 (  1,  1) [000007] ------------              \--*  CNS_INT   int    0 $40
 -- prev tree VN is not related
 ... checking previous tree
N005 (  8,  6) [000010] -A--G---R---              *  ASG       int    $141
N004 (  1,  1) [000009] D------N----              +--*  LCL_VAR   int    V02 tmp1         d:1 $141
N003 (  8,  6) [000004] ----G-------              \--*  EQ        int    $141
N001 (  3,  4) [000002] ------------                 +--*  LCL_FLD   int    V00 arg0         u:1[+4] Fseq[Value] (last use) $140
N002 (  1,  1) [000003] ------------                 \--*  CNS_INT   int    1 $42
  -- prev tree has relop with reversed liberal VN
 -- prev tree is viable candidate for relop fwd sub!
 -- done! new jump tree is
N004 (  5,  5) [000014] ----G-------              *  JTRUE     void
N003 (  8,  6) [000021] J---G--N----              \--*  NE        int    $142
N001 (  3,  4) [000022] ------------                 +--*  LCL_FLD   int    V00 arg0         [+4] Fseq[Value] (last use) $140
N002 (  1,  1) [000023] ------------                 \--*  CNS_INT   int    1 $42

Activity

  1. ghost added
    area-CodeGen-coreclr
    on Dec 8, 2021
  2. ghost added
    untriaged
    on Dec 8, 2021
  3. added this to the 7.0.0 milestone on Dec 8, 2021
  4. removed
    untriaged
    on Dec 8, 2021
  5. ghost added
    in-pr
    on Dec 9, 2021
  6. ghost removed
    in-pr
    on Dec 9, 2021
  7. ghost locked as resolved and limited conversation to collaborators on Jan 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

area-CodeGen-coreclrbug

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions