Skip to content

JIT: (bug) exponential compile time in ValueNumStore::IsVectorPerElementMask #134487

Closed

Description

@EgorBo

ValueNumStore::IsVectorPerElementMask recurses into both operands of bitwise HW intrinsic VNs without memoization, which is O(2^N) on a VN DAG. A short chain of m ^= m & k takes seconds to JIT, and each extra statement doubles the time. It reproduces on x64 without AVX-512 (or with DOTNET_EnableAVX512=0).

Minimal Repro

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

public class Program
{
    public static void Main()
    {
        var sw = Stopwatch.StartNew();
        Vector128<int> r = Test(Vector128.Create(1, 2, 3, 4), Vector128.Create(1, 0, 3, 0));
        Console.WriteLine($"{r} {sw.ElapsedMilliseconds} ms");
    }

    [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)]
    public static Vector128<int> Test(Vector128<int> a, Vector128<int> b)
    {
        Vector128<int> m = Vector128.Equals(a, b);
        Vector128<int> k = Vector128.GreaterThan(a, b);
        m ^= m & k; m ^= m & k; m ^= m & k; m ^= m & k; m ^= m & k;
        m ^= m & k; m ^= m & k; m ^= m & k; m ^= m & k; m ^= m & k;
        m ^= m & k; m ^= m & k; m ^= m & k; m ^= m & k; m ^= m & k;
        m ^= m & k; m ^= m & k; m ^= m & k; m ^= m & k; m ^= m & k;
        m ^= m & k; m ^= m & k; m ^= m & k; m ^= m & k; m ^= m & k;
        return Vector128.Equals(m, Vector128<int>.AllBitsSet);
    }
}

Expected

<-1, 0, -1, 0> with a few ms of JIT time.

Actual

<-1, 0, -1, 0> 4992 ms on 11.0.0-rc.2 Release and 11979 ms on main Checked, both with DOTNET_EnableAVX512=0.

Regression?

Yes, a regression in .NET 11, introduced by #126865. .NET 8.0.31, 9.0.20 and 10.0.12 take 0 ms.

Notes

For And/Or/Xor/..., it evaluates IsVectorPerElementMask(arg0) && IsVectorPerElementMask(arg1) with no visited set or budget. m_i is visited twice per level, so T(n) = 2·T(n-1).
EvalHWIntrinsicFunBinary (EQ/NE against a constant) triggers it before checking for AllBitsSet/Zero. optAssertionProp_HWIntrinsic triggers it too.
arm64 looks affected as well (about 13 s with the arm64 cross-JIT). Possible fix: add a depth/budget limit, memoize results, or check the constant first.

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 25, 2026
    81d3e24
  5. locked and limited conversation to collaborators on Oct 25, 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