Skip to content

Arm64: AdvSimd.AddWideningLower/SubtractWideningLower(x.GetLower(), y) compiles to UADDW/USUBW on .NET 11 #137322

Closed

Description

@dtaylorus

Description

On .NET 11.0.0 on Arm64, AdvSimd.SubtractWideningLower(Vector64<T>, Vector64<T>) and
AdvSimd.AddWideningLower(Vector64<T>, Vector64<T>) give wrong results when the first argument is
x.GetLower() of a Vector128<T>. The JIT drops the GetLower() and emits the wide form of
the instruction (USUBW/UADDW, the (Vector128<TWide>, Vector64<T>) overloads), so it uses all
128 bits of x, reinterpreted as the wide element type, instead of widening its low 64 bits
(USUBL/UADDL).

It happens for every element type tried (byte, sbyte, ushort). It also happens with
DOTNET_JitMinOpts=1, and in Native AOT. .NET 10.0.14 is correct.

Correct on .NET 11:

  • the same calls with a Vector64<T> argument that isn't GetLower();
  • x.GetLower() as the second argument of the wide forms;
  • MultiplyWideningLower, ZeroExtendWideningLower, DuplicateSelectedScalarToVector128 and
    AdvSimd.Arm64.ConvertToDouble with x.GetLower().

DuplicateSelectedScalarToVector128 and ConvertToDouble are the other two AdvSimd APIs whose
first parameter has both a Vector64 and a Vector128 overload.

Reproduction

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

static class Program
{
    [MethodImpl(MethodImplOptions.NoInlining)]
    static Vector128<ushort> SubL(Vector128<byte> v, Vector64<byte> w) => AdvSimd.SubtractWideningLower(v.GetLower(), w);

    [MethodImpl(MethodImplOptions.NoInlining)]
    static Vector128<ushort> SubL64(Vector64<byte> v, Vector64<byte> w) => AdvSimd.SubtractWideningLower(v, w);

    [MethodImpl(MethodImplOptions.NoInlining)]
    static Vector128<ushort> AddL(Vector128<byte> v, Vector64<byte> w) => AdvSimd.AddWideningLower(v.GetLower(), w);

    [MethodImpl(MethodImplOptions.NoInlining)]
    static Vector128<ushort> AddL64(Vector64<byte> v, Vector64<byte> w) => AdvSimd.AddWideningLower(v, w);

    static void Main()
    {
        var data = new byte[16];
        for (int i = 0; i < data.Length; i++) data[i] = (byte)(i * 37 + 11);
        var v = Vector128.Create(data);
        var w = Vector64.Create((byte)128);
        Console.WriteLine($"{Environment.Version}");
        Console.WriteLine($"SubtractWideningLower: {SubL(v, w)} expected {SubL64(v.GetLower(), w)}");
        Console.WriteLine($"AddWideningLower:      {AddL(v, w)} expected {AddL64(v.GetLower(), w)}");
    }
}

Expected behavior (.NET 10.0.14)

SubtractWideningLower: <65419, 65456, 65493, 65530, 31, 68, 105, 65422> expected <65419, 65456, 65493, 65530, 31, 68, 105, 65422>
AddWideningLower:      <139, 176, 213, 250, 287, 324, 361, 142> expected <139, 176, 213, 250, 287, 324, 361, 142>

Actual behavior (.NET 11.0.0)

SubtractWideningLower: <12171, 31189, 50207, 3689, 22451, 41469, 60487, 13713> expected <65419, 65456, 65493, 65530, 31, 68, 105, 65422>
AddWideningLower:      <12427, 31445, 50463, 3945, 22707, 41725, 60743, 13969> expected <139, 176, 213, 250, 287, 324, 361, 142>

DOTNET_JitDisasm for SubL and AddL:

ldr     q16, [fp, #0x20]
ldr     d17, [fp, #0x18]
usubw   v0.8h, v16.8h, v17.8b
ldr     q16, [fp, #0x20]
ldr     d17, [fp, #0x18]
uaddw   v0.8h, v16.8h, v17.8b

SubL64, given a Vector64, is correct:

ldr     d16, [fp, #0x18]
ldr     d17, [fp, #0x10]
usubl   v0.8h, v16.8b, v17.8b

Regression?

Yes: correct on .NET 10.0.14, wrong on .NET 11.0.0.

Known workarounds

Pass a Vector64<T> that isn't GetLower() of a register, such as a direct
Vector64.LoadUnsafe of the low half.

Configuration

  • .NET 11.0.0 (SDK 11.0.100), the JIT and Native AOT (PublishAot, osx-arm64).
  • macOS 27.2, Apple M6 (Arm64).
  • Found as a JPEG decoder's color conversion giving wrong colors (values off by up to 184)
    after moving it from .NET 10 to .NET 11.

Other information

From the instructions emitted, the GetLower() is contained or removed and the overload chosen
by the operand's new type, Vector128, picks the wide (W) instruction instead of the long (L)
one.

Activity

  1. added
    untriaged
    on Nov 11, 2026
  2. added
    area-CodeGen-coreclr
    on Nov 11, 2026
  3. dotnet-policy-service commented on Nov 11, 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. removed
    untriaged
    on Nov 12, 2026
  5. self-assigned this
    on Nov 12, 2026
  6. added a commit that references this issue on Nov 20, 2026
    e56caa3
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

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions