Skip to content

JIT: (bug) negating the first operand of a scalar FMA drops the negation from the copied upper lanes #133553

Closed

Description

@EgorBo

Repro

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

class Program
{
    [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)]
    static Vector128<float> Test(Vector128<float> a, Vector128<float> b, Vector128<float> c) =>
        Fma.MultiplyAddScalar(-a, b, c);

    static void Main()
    {
        if (!Fma.IsSupported)
            throw new PlatformNotSupportedException("FMA is required.");

        // lane 0 = (-2)*10 + 1; lanes 1..3 are copied from the first operand, which is -a.
        var r = Test(Vector128.Create(2.0f, 3.0f, 4.0f, 5.0f),
                     Vector128.Create(10.0f),
                     Vector128.Create(1.0f));
        Console.WriteLine($"{r.GetElement(0)} {r.GetElement(1)} {r.GetElement(2)} {r.GetElement(3)}");
    }
}

Expected

-19 -3 -4 -5

Actual

-19 3 4 5

MultiplyAddScalar copies lanes 1..3 from its first operand, so they must come from -a, but
they come from the un-negated a instead.

Platform

Windows x64 with FMA, local Checked build of dotnet/runtime main (ef97eb5).
Also reproduces on release .NET 11.0.100-rc.1.26420.103, and at MinOpts.

Activity

  1. added this to the 12.0.0 milestone on Sep 10, 2026
  2. added
    area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI
    on Sep 10, 2026
  3. dotnet-policy-service commented on Sep 10, 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. added a commit that references this issue on Sep 10, 2026
    24d55c0
  5. EgorBo commented on Sep 18, 2026

    @EgorBo
    MemberAuthor

    Affected SDK versions:

    • 10.0.401
    • 11.0.100-rc.2.26467.112
  6. locked and limited conversation to collaborators on Oct 19, 2026
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 SuperPMI

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions