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

Assertion prop does not properly truncate stores to small-typed args #70607

Closed
jakobbotsch opened this issue Jun 11, 2022 · 2 comments · Fixed by #71336
Closed

Assertion prop does not properly truncate stores to small-typed args #70607

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

Comments

@jakobbotsch
Copy link
Member

public static void Main()
{
    System.Console.WriteLine(M(0));
}

[MethodImpl(MethodImplOptions.NoInlining)]
public static int M(byte arg0)
{
    IL.Emit.Ldc_I4(-1);
    IL.Emit.Starg(0);
    IL.Emit.Ldarg(0);
    return IL.Return<int>();
}

Expected: 255
Actual: 255 in debug, -1 in release

...

*************** In fgMorphBlocks()

Morphing BB01 of 'Program:M(ubyte):int'

fgMorphTree BB01, STMT00000 (before)
               [000002] -A---------ASG       ubyte 
               [000001] D------N---                         ├──▌  LCL_VAR   ubyte  V00 arg0         
               [000000] -----------                         └──▌  CNS_INT   int    -1
Notify VM instruction set (SSE2) must be supported.
GenTreeNode creates assertion:
               [000002] -A---------ASG       ubyte 
In BB01 New Local Constant Assertion: V00 == -1, index = #01

fgMorphTree BB01, STMT00001 (before)
               [000004] -----------RETURN    int   
               [000003] -----------                         └──▌  LCL_VAR   ubyte  V00 arg0         

Assertion prop in BB01:
Constant Assertion: V00 == -1, index = #01
               [000003] -----------CNS_INT   int    -1

fgMorphTree BB01, STMT00001 (after)
               [000004] -----+-----RETURN    int   
               [000003] -----+-----                         └──▌  CNS_INT   int    -1
@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 Jun 11, 2022
@ghost ghost added the untriaged New issue has not been triaged by the area owner label Jun 11, 2022
@ghost
Copy link

ghost commented Jun 11, 2022

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

Issue Details
public static void Main()
{
    System.Console.WriteLine(M(0));
}

[MethodImpl(MethodImplOptions.NoInlining)]
public static int M(byte arg0)
{
    IL.Emit.Ldc_I4(-1);
    IL.Emit.Starg(0);
    IL.Emit.Ldarg(0);
    return IL.Return<int>();
}

Expected: 255
Actual: 255 in debug, -1 in release

...

*************** In fgMorphBlocks()

Morphing BB01 of 'Program:M(ubyte):int'

fgMorphTree BB01, STMT00000 (before)
               [000002] -A---------ASG       ubyte 
               [000001] D------N---                         ├──▌  LCL_VAR   ubyte  V00 arg0         
               [000000] -----------                         └──▌  CNS_INT   int    -1
Notify VM instruction set (SSE2) must be supported.
GenTreeNode creates assertion:
               [000002] -A---------ASG       ubyte 
In BB01 New Local Constant Assertion: V00 == -1, index = #01

fgMorphTree BB01, STMT00001 (before)
               [000004] -----------RETURN    int   
               [000003] -----------                         └──▌  LCL_VAR   ubyte  V00 arg0         

Assertion prop in BB01:
Constant Assertion: V00 == -1, index = #01
               [000003] -----------CNS_INT   int    -1

fgMorphTree BB01, STMT00001 (after)
               [000004] -----+-----RETURN    int   
               [000003] -----+-----                         └──▌  CNS_INT   int    -1
Author: jakobbotsch
Assignees: -
Labels:

area-CodeGen-coreclr

Milestone: -

@jakobbotsch
Copy link
Member Author

This is a small repro of a problem in #70518 (comment).

@jakobbotsch jakobbotsch added bug and removed untriaged New issue has not been triaged by the area owner labels Jun 11, 2022
@TIHan TIHan mentioned this issue Jun 13, 2022
1 task
@ghost ghost added the in-pr There is an active PR which will close this issue when it is merged label Jun 13, 2022
@jakobbotsch jakobbotsch mentioned this issue Jun 14, 2022
1 task
@JulieLeeMSFT JulieLeeMSFT added this to the 7.0.0 milestone Jun 14, 2022
jakobbotsch added a commit that referenced this issue Jun 27, 2022
For small locals we need to cast these to the type of the local when the
assertion is created. Also add some checking on the loading side of
these assertions.

Fix #70607
@ghost ghost removed the in-pr There is an active PR which will close this issue when it is merged label Jun 27, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Jul 27, 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 bug
Projects
None yet
3 participants