Skip to content

JIT: Avx.CompareScalar incorrectly folded with True/False comparison modes #125160

Closed

Description

@saucecontrol

Description

CompareScalar is supposed to return the upper elements of the first operand unchanged, but folding for True/False comparison modes returns a full Zero or AllBitsSet vector.

https://github.com/dotnet/runtime/blob/f62984ce62deecfb90a8ab991e972d1bc460b93e/src/coreclr/jit/gentree.cpp#L33828-L33842

Reproduction Steps

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

Console.WriteLine(CompareFalse(Vector128<float>.One, Vector128<float>.Zero));

[MethodImpl(MethodImplOptions.NoInlining)]
static Vector128<float> CompareFalse(Vector128<float> x, Vector128<float> y)
	=> Avx.CompareScalar(x, y, FloatComparisonMode.OrderedFalseSignaling);

Expected behavior

> dotnet run -c release -f net9.0

<0, 1, 1, 1>

Actual behavior

> dotnet run -c release -f net10.0

<0, 0, 0, 0>

Regression?

Yes

Known Workarounds

No response

Configuration

No response

Other information

No response

Activity

  1. added
    untriaged
    on Mar 4, 2026
  2. added
    area-CodeGen-coreclr
    on Mar 4, 2026
  3. dotnet-policy-service commented on Mar 4, 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 Mar 4, 2026
    cf92236
  5. removed
    untriaged
    on Mar 15, 2026
  6. added this to the 11.0.0 milestone on Mar 15, 2026
  7. AndyAyersMS commented on Jun 6, 2026

    @AndyAyersMS
    Member

    Note

    AI-assisted (Copilot CLI).

    Bug is still present in main at gentree.cpp:35400-35412: for NI_AVX_CompareScalar (and NI_AVX512_CompareMask with a mask retType), the True/False fold replaces the entire tree with gtNewZeroConNode/gtNewAllBitsSetConNode, which is correct for Compare/CompareMask but wrong for CompareScalar (upper elements must be preserved from op1).

    A ready-to-go fix exists in #125179 (Copilot SWE agent, March 2026): bail out of the fold for NI_AVX_CompareScalar, and use getSIMDTypeForSize to build the constant when retType is TYP_MASK. The PR went through review feedback from @saucecontrol and @EgorBo, addressed a CI test failure, then was auto-closed after 30 days of inactivity. Worth reviving rather than re-discovering.

  8. added a commit that references this issue on Jul 7, 2026
    6d7219c
  9. added a commit that references this issue on Jul 15, 2026
    1c65999
  10. locked and limited conversation to collaborators on Aug 6, 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-coreclr

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions