Skip to content

JIT: (bug) [ARM64] Vector64.ToVector128() zeroing of the upper lanes is dropped by the inverse-mov peephole (wrong code) #135529

Closed

Description

@EgorBo

On arm64, the mov v0.8b, v8.8b that implements Vector64<int>.ToVector128() (zeroing the upper 64 bits) is removed as redundant after an earlier mov v8.8b, v0.8b, so the upper lanes keep stale data.

Minimal Repro

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

public class Program
{
    [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)]
    static Vector64<int> GetLow(Vector128<int> v) => v.GetLower();

    [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)]
    static Vector128<int> Id(Vector128<int> v) => v;

    [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)]
    static Vector128<int> Test(Vector128<int> v)
    {
        Vector64<int> lo = GetLow(v);
        Vector128<int> r = Id(lo.ToVector128());
        return r + Id(lo.ToVector128());
    }

    public static int Main()
    {
        Vector128<int> r = Test(Vector128.Create(1, 2, 3, 4));
        Console.WriteLine($"Expected: <2, 4, 0, 0>, Actual: {r}");
        return r == Vector128.Create(2, 4, 0, 0) ? 100 : 1;
    }
}

Expected

Expected: <2, 4, 0, 0>, Actual: <2, 4, 0, 0>

Actual

Expected: <2, 4, 0, 0>, Actual: <2, 4, 3, 4>

Regression?

No. Reproduces on .NET 10.0.12 and main Release.

Notes

  • Test emits mov v8.8b, v0.8b after GetLow, but the mov v0.8b, v8.8b for ToVector128 before the first Id call is missing.
  • The "opposite move" case of IsRedundantMov (emitarm64.cpp; the size == EA_8BYTE branch only checks vector/scalar kind) removes the mov v0.8b, v8.8b emitted for ToVector128 (canSkip=false), although the earlier mov v8.8b, v0.8b doesn't imply that the upper lanes of v0 are zero.

Activity

  1. added this to the 12.0.0 milestone on Oct 9, 2026
  2. added
    area-CodeGen-coreclr
    on Oct 9, 2026
  3. dotnet-policy-service commented on Oct 9, 2026

    @dotnet-policy-service
    Contributor

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

  4. self-assigned this
    on Nov 13, 2026
  5. added a commit that references this issue on Nov 18, 2026
    b3a8e34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area-CodeGen-coreclr

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions