Repository navigation
Description
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
dotnet-policy-service commentedon Sep 23, 2026
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.
Avoid repeated SIMD mask proof traversal in value numbering (#134530)