Skip to content

ARM64 SIMD fails assertion where x86-64 SIMD does not #120414

@vivianlonging

Description

@vivianlonging

Description

During AOT compilation, I found a differently defined behavior between x86 and ARM for SIMD:
https://godbolt.org/z/PjPKEKPqc
On NativeAOT,
x86 computes this as "treat the 64bits of the Vector2 as the 64bits of a double, then duplicate the double into both lanes of a Vector128"
ARM fails to treat the 64bits of the Vector2 as the 64bits of a double (i.e. Unsafe.As/BitCast but only when SIMD instructions are involved in the function. - assertion error

I can't tell if this is an undefined behavior, a failure on x86-64 to recognize the bit difference in the assertion, or an error that ARM64 is failing the Assertion.

Reproduction Steps

https://godbolt.org/z/PjPKEKPqc

using System;
using System.Numerics;
using System.Runtime.Intrinsics;
using System.Runtime.CompilerServices;

class Program{
static Vector128<float> DuplicateFromVec2(Vector2 s) =>
    Vector128.Create(Unsafe.BitCast<Vector2, double>(s)).AsSingle();

Expected behavior

x86-64 and ARM64 should both pass or fail the assertion

Actual behavior

x86-64 passes the assertion while ARM64 does not

Regression?

No response

Known Workarounds

Writing the code without using Unsafe correspondence

Configuration

.NET NativeAOT
for x86 compilation - -O --targetarch x64 --instruction-set avx
for arm64 compilation- -O --targetarch arm64 --instruction-set neon
Actual testing on x86-64 Windows machine and godbolt

Other information

https://github.com/dotnet/runtime/blob/main/src/coreclr/jit/lower.cpp#L9039
Assertion failed

Metadata

Metadata

Assignees

Labels

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

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions