Skip to content

JIT: (bug) Rejecting a GDV candidate permanently marks the base virtual method as NOINLINE process-wide #133974

Closed

Description

@EgorBo

A guarded-devirtualization inline rejection for a synchronized override can set CORINFO_FLG_BAD_INLINEE on the base virtual method. Subsequent unrelated exact calls to Base.M in the same process lose inlining and allocation removal based on tier-up order.

Minimal Repro

using System;
using System.Runtime.CompilerServices;
using System.Threading;

class Base { public virtual int M() => 42; }
class Derived : Base { [MethodImpl(MethodImplOptions.Synchronized)] public override int M() => 43; }

class Program
{
    [MethodImpl(MethodImplOptions.NoInlining)]
    static int Poison(Base b) => b.M();

    [MethodImpl(MethodImplOptions.NoInlining)]
    static int Test()
    {
        Base b = new Base();
        return b.M();
    }

    static void Main(string[] args)
    {
        int sum = 0;
        if (args.Length == 0)
        {
            Base d = new Derived();
            for (int i = 0; i < 100; i++)
            {
                for (int j = 0; j < 100; j++) sum += Poison(d);
                Thread.Sleep(15);
            }
        }
        for (int i = 0; i < 100; i++)
        {
            for (int j = 0; j < 100; j++) sum += Test();
            Thread.Sleep(15);
        }
        Console.WriteLine(sum);
    }
}

Requires DOTNET_TieredPGO=1, DOTNET_TC_CallCountThreshold=1, DOTNET_TC_CallCountingDelayMs=0, and DOTNET_JitDisasm=Test; pass any argument for the baseline and no arguments to poison Base.M first.

Expected

Test() should still inline Base.M, fold the return value, and eliminate the Base allocation:

; Assembly listing for method Program:Test():int (Tier1)
       mov      eax, 42
       ret
; Total bytes of code 6
420000

Actual

After the separate Poison method tiers up first, Test() is still devirtualized but no longer inlined:

; Assembly listing for method Program:Test():int (Tier1)
       call     CORINFO_HELP_NEWSFAST
       mov      rcx, rax
       call     [Base:M():int:this]
; Total bytes of code 34
850000

Notes

impMarkInlineCandidate builds InlineResult from the base call node for GDV candidates, so InlineResult::Report propagates CALLEE_* failures via setMethodAttribs to gtCallMethHnd (Base.M) rather than the guarded target (Derived.M).
The effect is process-wide and order-dependent because CORINFO_FLG_BAD_INLINEE is a VM-level method attribute.
Reproduces on released .NET 10.0.12 as the same 6-byte vs 34-byte Tier1 codegen difference.

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. self-assigned this
    on Sep 15, 2026
  5. added a commit that references this issue on Sep 16, 2026
    3b0af17
  6. changed the title [-]JIT (bug): Rejecting a GDV candidate permanently marks the base virtual method as NOINLINE process-wide[/-] [+]JIT: (bug) Rejecting a GDV candidate permanently marks the base virtual method as NOINLINE process-wide[/+] on Sep 16, 2026
  7. added a commit that references this issue on Sep 18, 2026
    d0c8de6
  8. locked and limited conversation to collaborators on Oct 17, 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