Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Test] JIT: Prototype a simple inter-procedural analysis #108567

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

hez2010
Copy link
Contributor

@hez2010 hez2010 commented Oct 5, 2024

Prototype a simple inter-procedural analysis relying on tiering (thus no NAOT support).

  1. Do analysis for tier-0 methods and save the analysis result.
  2. Use the analysis result while compiling for tier-1.

To simplify the prototype, this only records local num less than 128.

Opening a draft PR to check the cost and benefits.

Example:

static int Test()
{
    var x = new Foo();
    SetValue(x);
    return x.Value;
}

[MethodImpl(MethodImplOptions.NoInlining)]
static void SetValue(Foo obj)
{
    obj.Value = 42;
}

class Foo
{
    public int Value { get; set; }
}

Codegen:

; Assembly listing for method Program:Test():int (Tier0)
; Emitting BLENDED_CODE for X64 with AVX - Windows
; Tier0 code
; rbp based frame
; partially interruptible
; compiling with minopt
; Final local variable assignments
;
;  V00 OutArgs      [V00    ] (  1,  1   )  struct (32) [rsp+0x00]  do-not-enreg[XS] addr-exposed "OutgoingArgSpace"
;  V01 tmp1         [V01    ] (  1,  1   )     ref  ->  [rbp-0x08]  do-not-enreg[] must-init class-hnd exact "NewObj constructor temp" <Program+Foo>
;
; Lcl frame size = 48

G_M58954_IG01:  ;; offset=0x0000
       push     rbp
       sub      rsp, 48
       lea      rbp, [rsp+0x30]
       xor      eax, eax
       mov      qword ptr [rbp-0x08], rax
                                                ;; size=16 bbWeight=1 PerfScore 3.00
G_M58954_IG02:  ;; offset=0x0010
       mov      rcx, 0x7FFAA3B61938      ; Program+Foo
       call     CORINFO_HELP_NEWSFAST
       mov      gword ptr [rbp-0x08], rax
       mov      rcx, gword ptr [rbp-0x08]
       call     [Program+Foo:.ctor():this]
       mov      rcx, gword ptr [rbp-0x08]
       call     [Program:SetValue(Program+Foo)]
       mov      rcx, gword ptr [rbp-0x08]
       cmp      dword ptr [rcx], ecx
       call     [Program+Foo:get_Value():int:this]
       nop
                                                ;; size=52 bbWeight=1 PerfScore 17.50
G_M58954_IG03:  ;; offset=0x0044
       add      rsp, 48
       pop      rbp
       ret
                                                ;; size=6 bbWeight=1 PerfScore 1.75

; Total bytes of code 74, prolog size 16, PerfScore 22.25, instruction count 19, allocated bytes for code 74 (MethodHash=347c19b5) for method Program:Test():int (Tier0)
; ============================================================

; Assembly listing for method Program:Test():int (Instrumented Tier0)
; Emitting BLENDED_CODE for X64 with AVX - Windows
; Instrumented Tier0 code
; rbp based frame
; partially interruptible
; compiling with minopt
; Final local variable assignments
;
;  V00 OutArgs      [V00    ] (  1,  1   )  struct (32) [rsp+0x00]  do-not-enreg[XS] addr-exposed "OutgoingArgSpace"
;  V01 tmp1         [V01    ] (  1,  1   )     ref  ->  [rbp-0x08]  do-not-enreg[] must-init class-hnd exact "NewObj constructor temp" <Program+Foo>
;
; Lcl frame size = 48

G_M58954_IG01:  ;; offset=0x0000
       push     rbp
       sub      rsp, 48
       lea      rbp, [rsp+0x30]
       xor      eax, eax
       mov      qword ptr [rbp-0x08], rax
                                                ;; size=16 bbWeight=1 PerfScore 3.00
G_M58954_IG02:  ;; offset=0x0010
       mov      rcx, 0x7FFAA3B61938      ; Program+Foo
       call     CORINFO_HELP_NEWSFAST
       mov      gword ptr [rbp-0x08], rax
       mov      rcx, gword ptr [rbp-0x08]
       call     [Program+Foo:.ctor():this]
       mov      rcx, gword ptr [rbp-0x08]
       call     [Program:SetValue(Program+Foo)]
       mov      rcx, gword ptr [rbp-0x08]
       cmp      dword ptr [rcx], ecx
       call     [Program+Foo:get_Value():int:this]
       nop
                                                ;; size=52 bbWeight=1 PerfScore 17.50
G_M58954_IG03:  ;; offset=0x0044
       add      rsp, 48
       pop      rbp
       ret
                                                ;; size=6 bbWeight=1 PerfScore 1.75

; Total bytes of code 74, prolog size 16, PerfScore 22.25, instruction count 19, allocated bytes for code 74 (MethodHash=347c19b5) for method Program:Test():int (Instrumented Tier0)
; ============================================================

; Assembly listing for method Program:Test():int (Tier1)
; Emitting BLENDED_CODE for X64 with AVX - Windows
; Tier1 code
; optimized code
; optimized using Synthesized PGO
; rsp based frame
; partially interruptible
; with Synthesized PGO: fgCalledCount is 100
; No PGO data
; 0 inlinees with PGO data; 3 single block inlinees; 0 inlinees without PGO data
; Final local variable assignments
;
;  V00 OutArgs      [V00    ] (  1,  1   )  struct (32) [rsp+0x00]  do-not-enreg[XS] addr-exposed "OutgoingArgSpace"
;* V01 tmp1         [V01    ] (  0,  0   )    long  ->  zero-ref    class-hnd exact "NewObj constructor temp" <Program+Foo>
;  V02 tmp2         [V02    ] (  4,  4   )  struct (16) [rsp+0x28]  do-not-enreg[XSF] addr-exposed "stack allocated ref class temp" <Program+Foo>
;
; Lcl frame size = 56

G_M58954_IG01:  ;; offset=0x0000
       sub      rsp, 56
                                                ;; size=4 bbWeight=1 PerfScore 0.25
G_M58954_IG02:  ;; offset=0x0004
       xor      ecx, ecx
       mov      qword ptr [rsp+0x28], rcx
       mov      dword ptr [rsp+0x30], ecx
       mov      rcx, 0x7FFAA3B61938      ; Program+Foo
       mov      qword ptr [rsp+0x28], rcx
       lea      rcx, [rsp+0x28]
       call     [Program:SetValue(Program+Foo)]
       mov      eax, dword ptr [rsp+0x30]
                                                ;; size=41 bbWeight=1 PerfScore 8.00
G_M58954_IG03:  ;; offset=0x002D
       add      rsp, 56
       ret
                                                ;; size=5 bbWeight=1 PerfScore 1.25

; Total bytes of code 50, prolog size 4, PerfScore 9.50, instruction count 11, allocated bytes for code 50 (MethodHash=347c19b5) for method Program:Test():int (Tier1)
; ============================================================

@hez2010 hez2010 marked this pull request as draft October 5, 2024 04:57
@dotnet-issue-labeler dotnet-issue-labeler bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Oct 5, 2024
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Oct 5, 2024
Copy link
Contributor

Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.

@hez2010 hez2010 force-pushed the inter-analysis-noarray branch 3 times, most recently from 9672e8e to e05fed6 Compare October 5, 2024 05:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI community-contribution Indicates that the PR has been added by a community member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant