Skip to content

RyuJIT doesn't elide frames for passtrough methods with multiple calls #46391

@SingleAccretion

Description

@SingleAccretion

Description

Consider the following three methods:

public static int TwoCalls(int a)
{
    var one = One(a);
    if (one > 0)
    {
        return one;
    }

    return Two(a);
}

[MethodImpl(MethodImplOptions.NoInlining)]
public static int One(int a) => a;

[MethodImpl(MethodImplOptions.NoInlining)]
public static int Two(int a) => a;

Today (tested on 3ae36b5 via Disasmo), the following code is generated for TwoCalls on x64:

G_M61010_IG01:
       push     rsi
       sub      rsp, 32
       mov      esi, ecx
						;; bbWeight=1    PerfScore 1.50
G_M61010_IG02:
       mov      ecx, esi
       call     ThrowawayTesting.Program:One(int):int
       test     eax, eax
       jle      SHORT G_M61010_IG04
						;; bbWeight=1    PerfScore 2.50
G_M61010_IG03:
       add      rsp, 32
       pop      rsi
       ret      
						;; bbWeight=0.50 PerfScore 0.88
G_M61010_IG04:
       mov      ecx, esi
						;; bbWeight=0.50 PerfScore 0.12
G_M61010_IG05:
       add      rsp, 32
       pop      rsi
       jmp      ThrowawayTesting.Program:Two(int):int

As can be seen, for each path, parameter in rcx is first moved to rsi and then moved back to rcx, causing the method to also save and restore rsi (which is undesirable, especially when more parameters are involved).

Metadata

Metadata

Assignees

Labels

area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMItenet-performancePerformance related issue

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions