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 failed 'unreached' in 'MyClass:Foo(System.Numerics.Vector`1[Single]):this' during 'Do value numbering' (IL size 9) #51500

Closed
kunalspathak opened this issue Apr 19, 2021 · 12 comments
Assignees
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI
Milestone

Comments

@kunalspathak
Copy link
Member

kunalspathak commented Apr 19, 2021

Gets the assertion failure on windows/x64 when doing superpmi collection of System.Dynamic.Runtime.Tests.dll.

Repro steps:

python src\coreclr\scripts\superpmi.py collect --pmi -assemblies System.Dynamic.Runtime.Tests.dll
@kunalspathak kunalspathak added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Apr 19, 2021
@dotnet-issue-labeler dotnet-issue-labeler bot added the untriaged New issue has not been triaged by the area owner label Apr 19, 2021
@kunalspathak
Copy link
Member Author

@dotnet/jit-contrib , @briansull

@SingleAccretion
Copy link
Contributor

Reproduction:

[MethodImpl(MethodImplOptions.NoInlining)]
private static void Problem()
{
    VectorDefault(new Vector<float>());
}

[MethodImpl(MethodImplOptions.NoInlining)]
static void VectorDefault<T>(T d)
{
    d = default(T);
}

Taking a closer look...

@SingleAccretion
Copy link
Contributor

The issue is here:

// Is the type being stored different from the type computed by the rhs?
if ((rhs->TypeGet() != lhs->TypeGet()) && (lhs->OperGet() != GT_BLK))
{
// This means that there is an implicit cast on the rhs value
//
// We will add a cast function to reflect the possible narrowing of the rhs value
//
var_types castToType = lhs->TypeGet();
var_types castFromType = rhs->TypeGet();
bool isUnsigned = varTypeIsUnsigned(castFromType);
rhsVNPair = vnStore->VNPairForCast(rhsVNPair, castToType, castFromType, isUnsigned);
}

The relevant statement:

N004 (  9,  7) [000003] IA--G-------              *  ASG       simd16 (init)
N002 (  7,  5) [000005] *---G--N----              +--*  OBJ       simd16<System.Numerics.Vector`1[Single]>
N001 (  1,  1) [000000] -------N----              |  \--*  LCL_VAR   byref  V00 arg0         u:1 (last use)
N003 (  1,  1) [000002] ------------              \--*  CNS_INT   int    0

So, we have OBJ on the lhs, and CNS_INT on the rhs, and VNPairForCast is not equipped to handle that. The actual assert fires when we try to fold the cast from zero int to simd16.

As I am not an expert in this area, deferring the judgement on the proper fix to people who are.

@AndyAyersMS
Copy link
Member

AndyAyersMS commented Apr 19, 2021

This is a common IR idiom for zero-initialization of a struct (one might prefer to see a struct (or simd)-typed zero, but we use an int).

Suspect you should you skip trees where OperIsInitBlkOp is true, and let code below handle it.

@SingleAccretion
Copy link
Contributor

That sounds reasonable. Looks like the code in that branch was never prepared to handle GT_OBJs:

noway_assert(!"GT_OBJ can not be LHS when (tree->TypeGet() != TYP_STRUCT)!");

@AndyAyersMS I will see what I can do here, and hopefully learn something along the way, so I suppose you can assign me to this one.

@AndyAyersMS
Copy link
Member

Do we know why we just started seeing this, or was it just always there and the SPMI run was the first time we noticed?

@kunalspathak
Copy link
Member Author

Do we know why we just started seeing this, or was it just always there and the SPMI run was the first time we noticed?

Probably. We never ran SPMI on libraries tests. I noticed this while working on that pipeline. I am talking to @BruceForstall on how to surface these failures.

@SingleAccretion
Copy link
Contributor

Probably

Agreed.

@briansull
Copy link
Contributor

Triage Area: ValueNumbering

@JulieLeeMSFT
Copy link
Member

Added @jakobbotsch

@jakobbotsch
Copy link
Member

jakobbotsch commented Aug 3, 2021

Looks like @echesakovMSFT ended up fixing the original repro with #53116, gonna see if I can find a different repro before I close this.

@jakobbotsch
Copy link
Member

I haven't managed to find one, it looks like all places where we have a struct assignment on the left we call gtSetObjGcInfo which will change it to GT_BLK (for SIMD types).

@SingleAccretion SingleAccretion removed their assignment Aug 4, 2021
@ghost ghost locked as resolved and limited conversation to collaborators Sep 8, 2021
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
Projects
None yet
Development

No branches or pull requests

7 participants