Skip to content

JIT: (bug) VN ignores HWIntrinsic auxiliary type, so Avx2.GatherVector128 with int and long indices is treated as equal #134486

Closed

Description

@EgorBo

Two Avx2.GatherVector128 calls that differ only in index element type (vpgatherdd vs vpgatherqd) get the same liberal VN. RBO then folds a compare on the second gather's result, giving a wrong result in optimized code.

Minimal Repro

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

public unsafe class Program
{
    static int[] s_data = { 10, 11, 12, 13 };

    public static void Main()
    {
        fixed (int* p = s_data)
        {
            Console.WriteLine(Test(p, Vector128.Create(1, 0, 2, 0), Vector128.Create(11, 10, 12, 10)));
        }
    }

    [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)]
    public static int Test(int* p, Vector128<int> idx, Vector128<int> x)
    {
        Vector128<int> a = Avx2.GatherVector128(p, idx, 4);           // vpgatherdd: <11, 10, 12, 10>
        Vector128<int> b = Avx2.GatherVector128(p, idx.AsInt64(), 4); // vpgatherqd: <11, 12, 0, 0>
        if (a == x)
        {
            if (b == x)
                return 1;
            return 2;
        }
        return 3;
    }
}

Expected

2, which is also what DOTNET_JITMinOpts=1 prints.

Actual

1

Regression?

No, this isn't a regression. .NET 8.0.31, 9.0.20, 10.0.12, 11.0.0-rc.2 and main all print 1.

Notes

fgValueNumberHWIntrinsic builds the VN from the VNFunc, VNForSimdType(simdSize, simdBaseType) and the operand VNs. GetAuxiliaryType() is not part of it.
Possible fix: include the auxiliary type in the VN, or use distinct VNFuncs.
Not verified, but these may also be affected: arm64 AddWideningUpper/SubtractWideningUpper, AddSaturateScalar, and the AvxVnniInt8/AvxVnniInt16 overloads.

Activity

  1. added this to the 12.0.0 milestone on Sep 23, 2026
  2. added
    area-CodeGen-coreclr
    on Sep 23, 2026
  3. dotnet-policy-service commented on Sep 23, 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 23, 2026
    5b82fc4
  5. locked and limited conversation to collaborators on Oct 24, 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