Skip to content

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

Closed
@rfellers

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!

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