Skip to content

System.Runtime.Intrinsics.Vector128.Create() bug inside of for loop #43569

Closed

Description

@rfellers

Description

I believe that I have found a regression with the way Vector128 structs are created using Vector128.Create(float, float, float, float) when converting from doubles. For example, the following code console writes <1, 2, 3, 4> as expected:

double[] array = new[] { 1.0, 2, 3, 4 };

Vector128<float> x = Vector128.Create(Convert.ToSingle(array[0]), Convert.ToSingle(array[1]), Convert.ToSingle(array[2]), Convert.ToSingle(array[3]));

Console.WriteLine(x);

However, simply putting the code inside a for loop (or while for that matter) causes a console write of <1, 2, 3, 2>:

double[] array = new[] { 1.0, 2, 3, 4 };

Vector128<float> x = Vector128<float>.Zero;

for (int i = 0; i < 1; i++)
    x = Vector128.Create(Convert.ToSingle(array[0]), Convert.ToSingle(array[1]), Convert.ToSingle(array[2]), Convert.ToSingle(array[3]));

Console.WriteLine(x);

Configuration

dotnet 5.0.100-rc.2.20479.15
Windows 10 Enterprise 2004 (19041.572)
x64 in Release mode ... in Debug mode, things work as expected.

Regression

Yes, this is a regression. I tried this using .NET Core 3.1 (3.1.402) and got the expected output either way.

Other information

One way to work around this issue is to set the 3rd element again manually using WithElement() like so:

x = x.WithElement(3, Convert.ToSingle(array[3]));

Hope this is helpful, please let me know if you have any questions.

Thanks!

Activity

  1. EgorBo commented on Oct 19, 2020

    @EgorBo
    Member
    Assert failure(PID 35100 [0x0000891c], Thread: 18752 [0x4940]): Assertion failed 'tree->gtOper != GT_RET_EXPR' in 'Program:DoWork(double):double' during 'Morph - Inlining' (IL size 54)
    
        File: flowgraph.cpp Line: 23098
    

    Minimal repro:

    static float ToSingle(double value) => (float)value;
    
    [MethodImpl(MethodImplOptions.NoInlining)]
    static double DoWork(double a) => 
        Vector128.Create(1, 2, 3, ToSingle(a)).GetElement(0);

    Missing GTF_CALL flag? fgUpdateInlineReturnExpressionPlaceHolder just skips the tree and doesn't walk it to find GT_RET_EXPR it has to replace.

    /cc @dotnet/jit-contrib

  2. added
    area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI
    and removed
    untriagedNew issue has not been triaged by the area owner
    on Nov 20, 2020
  3. AndyAyersMS commented on Nov 20, 2020

    @AndyAyersMS
    Member

    Reopening to port fix to 5.0.

  4. added this to the 6.0.0 milestone on Nov 20, 2020
  5. AndyAyersMS commented on Nov 23, 2020

    @AndyAyersMS
    Member

    Fix is merged into 5.0 and should appear in 5.0.1.

  6. ghost locked as resolved and limited conversation to collaborators on Dec 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMIbug

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions