Skip to content

JIT: (bug) Half reciprocal estimate intrinsics bypass ReadyToRun non-deterministic intrinsic policy #133962

Closed

Description

@EgorBo

Half.ReciprocalEstimate and Half.ReciprocalSqrtEstimate can be expanded into hardware estimate instructions in ReadyToRun images, bypassing the policy that blocks non-deterministic estimate intrinsics from R2R code.

Minimal Repro

using System;
using System.Runtime.CompilerServices;

public static class Program
{
    [MethodImpl(MethodImplOptions.NoInlining)]
    public static Half Test(Half x) => Half.ReciprocalEstimate(x);

    [MethodImpl(MethodImplOptions.NoInlining)]
    public static Half TestRSqrt(Half x) => Half.ReciprocalSqrtEstimate(x);

    [MethodImpl(MethodImplOptions.NoInlining)]
    public static float TestF(float x) => MathF.ReciprocalEstimate(x);

    [MethodImpl(MethodImplOptions.NoInlining)]
    public static float TestFRSqrt(float x) => MathF.ReciprocalSqrtEstimate(x);

    public static void Main()
    {
        Console.WriteLine(Test((Half)3.0f));
        Console.WriteLine(TestRSqrt((Half)3.0f));
        Console.WriteLine(TestF(3.0f));
        Console.WriteLine(TestFRSqrt(3.0f));
    }
}

Reproduces when crossgen2 compiles the assembly as ReadyToRun with an estimate-capable target ISA such as avx10v1.

Expected

The estimate APIs stay as calls in the R2R image, matching the MathF estimate intrinsics and preserving deterministic ReadyToRun behavior across hardware.

Actual

The Half estimate overloads bake hardware estimate instructions into the R2R body, while the equivalent MathF APIs remain calls:

; Program:Test(System.Half):System.Half
       vrcpsh   xmm0, xmm1, xmm0

; Program:TestRSqrt(System.Half):System.Half
       vrsqrtsh xmm0, xmm1, xmm0

; Program:TestF(float):float
       call     [System.MathF:ReciprocalEstimate(float):float]

; Program:TestFRSqrt(float):float
       call     [System.MathF:ReciprocalSqrtEstimate(float):float]

Notes

Half.Sqrt shares the importer case but is IEEE-exact; only the two estimate intrinsics need the guard.
The Half intrinsic path uses compOpportunisticallyDependsOn and never calls BlockNonDeterministicIntrinsics, unlike Compiler::impEstimateIntrinsic for MathF.
A likely fix is to split the Half estimate cases and apply the same R2R blocking and exact-ISA dependency policy as the existing estimate intrinsic path.

Activity

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