Skip to content

Fix reporting of live var ranges after callf+always pairs#58815

Merged
jakobbotsch merged 3 commits intodotnet:mainfrom
jakobbotsch:fix-57752-2
Sep 9, 2021
Merged

Fix reporting of live var ranges after callf+always pairs#58815
jakobbotsch merged 3 commits intodotnet:mainfrom
jakobbotsch:fix-57752-2

Conversation

@jakobbotsch
Copy link
Copy Markdown
Member

We were basing the decision on whether a home update was needed on the
live out variables of the previous block, but that block is skipped for
callf+finally pairs. Change the logic to use the callf block instead.

Fix #57752

We were basing the decision on whether a home update was needed on the
live out variables of the previous block, but that block is skipped for
callf+finally pairs. Change the logic to use the callf block instead.

Fix dotnet#57752
@ghost ghost added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Sep 8, 2021
@ghost
Copy link
Copy Markdown

ghost commented Sep 8, 2021

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

Issue Details

We were basing the decision on whether a home update was needed on the
live out variables of the previous block, but that block is skipped for
callf+finally pairs. Change the logic to use the callf block instead.

Fix #57752

Author: jakobbotsch
Assignees: -
Labels:

area-CodeGen-coreclr

Milestone: -

@jakobbotsch
Copy link
Copy Markdown
Member Author

This also fixes several cases of wrongly reported live var ranges. For example:

-; Variable debug info: 16 live ranges, 5 vars for method System.Configuration.BaseConfigurationRecord:OnStreamChanged(System.String):this
+; Variable debug info: 17 live ranges, 5 vars for method System.Configuration.BaseConfigurationRecord:OnStreamChanged(System.String):this
   0(   UNKNOWN) : From 00000000h to 00000022h, in rcx
   0(   UNKNOWN) : From 00000022h to 00000026h, in rcx
   0(   UNKNOWN) : From 00000026h to 00000030h, in rbp[16] (1 slot)
   0(   UNKNOWN) : From 00000030h to 0000003Ah, in rcx
   0(   UNKNOWN) : From 0000003Ah to 0000008Eh, in rbp[16] (1 slot)
-  0(   UNKNOWN) : From 0000008Eh to 000000CFh, in rcx
+  0(   UNKNOWN) : From 0000008Eh to 0000009Bh, in rcx
+  0(   UNKNOWN) : From 0000009Bh to 000000CFh, in rbp[16] (1 slot)
   0(   UNKNOWN) : From 000000CFh to 000000D3h, in rcx
   0(   UNKNOWN) : From 0000011Fh to 0000012Bh, in rbp[16] (1 slot)
   0(   UNKNOWN) : From 00000143h to 00000162h, in rbp[16] (1 slot)

That's in the following function:

; Assembly listing for method System.Configuration.BaseConfigurationRecord:OnStreamChanged(System.String):this
; Emitting BLENDED_CODE for X64 CPU with SSE2 - Windows
; ReadyToRun compilation
; optimized code
; rbp based frame
; fully interruptible
; No matching PGO data
; 0 inlinees with PGO data; 10 single block inlinees; 1 inlinees without PGO data
; Final local variable assignments
;
;  V00 this         [V00,T00] ( 12, 12   )     ref  ->  [rbp+10H]   this class-hnd EH-live single-def
;  V01 arg1         [V01,T04] (  3,  3   )     ref  ->  rsi         class-hnd single-def
;  V02 loc0         [V02,T13] (  2,  2   )    bool  ->  rax
;  V03 loc1         [V03,T05] (  4,  4   )     ref  ->  rsi         class-hnd single-def
;* V04 loc2         [V04,T16] (  0,  0   )     ref  ->  zero-ref    class-hnd EH-live single-def
;  V05 loc3         [V05    ] (  3,  3   )    bool  ->  [rbp-20H]   do-not-enreg[XB] must-init addr-exposed ld-addr-op single-def
;  V06 loc4         [V06,T06] (  4,  4   )     ref  ->  rax         class-hnd single-def
;* V07 loc5         [V07    ] (  0,  0   )     ref  ->  zero-ref    class-hnd single-def
;  V08 OutArgs      [V08    ] (  1,  1   )  lclBlk (32) [rsp+00H]   "OutgoingArgSpace"
;  V09 tmp1         [V09,T07] (  2,  4   )   byref  ->  rax         single-def "Inlining Arg"
;  V10 tmp2         [V10,T15] (  2,  2   )     int  ->  rax         single-def "Inline stloc first use temp"
;  V11 tmp3         [V11,T14] (  2,  2   )     ref  ->  rax         class-hnd single-def "Inline return value spill temp"
;  V12 tmp4         [V12    ] (  2,  2   )     ref  ->  [rbp-28H]   do-not-enreg[XB] must-init addr-exposed ld-addr-op class-hnd single-def "Inline ldloca(s) first use temp"
;  V13 tmp5         [V13,T08] (  2,  4   )   byref  ->  rax         single-def "Inlining Arg"
;  V14 tmp6         [V14,T01] (  4,  8   )     ref  ->  rsi         class-hnd single-def "Inlining Arg"
;  V15 tmp7         [V15,T09] (  2,  4   )     ref  ->  rdi         class-hnd single-def "Inlining Arg"
;  V16 tmp8         [V16,T02] (  4,  8   )     ref  ->  rbx         class-hnd exact single-def "NewObj constructor temp"
;  V17 tmp9         [V17,T10] (  2,  4   )     ref  ->  rax         class-hnd single-def "dup spill"
;  V18 tmp10        [V18,T12] (  3,  3   )     ref  ->  rax         single-def
;  V19 tmp11        [V19,T11] (  2,  4   )     ref  ->  rcx         single-def "argument with side effect"
;  V20 PSPSym       [V20    ] (  1,  1   )    long  ->  [rbp-30H]   do-not-enreg[X] addr-exposed "PSPSym"
;  V21 rat0         [V21,T03] (  3,  6   )     ref  ->  rax         "delegate invoke call"
;
; Lcl frame size = 56

G_M54305_IG01:              ;; offset=0000H
 000001a5`376d4ee0        55                   push     rbp
 000001a5`376d4ee1        57                   push     rdi
 000001a5`376d4ee2        56                   push     rsi
 000001a5`376d4ee3        53                   push     rbx
 000001a5`376d4ee4        4883EC38             sub      rsp, 56
 000001a5`376d4ee8        488D6C2450           lea      rbp, [rsp+50H]
 000001a5`376d4eed        33C0                 xor      eax, eax
 000001a5`376d4eef        488945E0             mov      qword ptr [rbp-20H], rax
 000001a5`376d4ef3        488945D8             mov      qword ptr [rbp-28H], rax
 000001a5`376d4ef7        488965D0             mov      qword ptr [rbp-30H], rsp
 000001a5`376d4efb        48894D10             mov      gword ptr [rbp+10H], rcx
 000001a5`376d4eff        488BF2               mov      rsi, rdx
; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ (mov: 2) 32B boundary ...............................
                                                ;; bbWeight=1    PerfScore 9.25
G_M54305_IG02:              ;; offset=0022H
 000001a5`376d4f02        488D55E0             lea      rdx, [rbp-20H]
 000001a5`376d4f06        FF1500000000         call     [System.Threading.Monitor:Enter()]
 000001a5`376d4f0c        488B4D10             mov      rcx, gword ptr [rbp+10H]
 000001a5`376d4f10        488D4178             lea      rax, bword ptr [rcx+120]
 000001a5`376d4f14        8B00                 mov      eax, dword ptr [rax]
 000001a5`376d4f16        A802                 test     al, 2
 000001a5`376d4f18        7550                 jne      SHORT G_M54305_IG04
 000001a5`376d4f1a        FF1500000000         call     [System.Configuration.BaseConfigurationRecord:get_ConfigStreamInfo():System.Configuration.BaseConfigurationRecord+ConfigRecordStreamInfo:this]
; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ (call: 0 ; jcc erratum) 32B boundary ...............................
 000001a5`376d4f20        488BC8               mov      rcx, rax
 000001a5`376d4f23        3909                 cmp      dword ptr [rcx], ecx
 000001a5`376d4f25        FF1500000000         call     [ConfigRecordStreamInfo:get_StreamInfos():System.Collections.Specialized.HybridDictionary:this]
 000001a5`376d4f2b        488BC8               mov      rcx, rax
 000001a5`376d4f2e        488BD6               mov      rdx, rsi
 000001a5`376d4f31        4C8D1D00000000       lea      r11, [(reloc 0x4000000000425fc0)]
 000001a5`376d4f38        3909                 cmp      dword ptr [rcx], ecx
 000001a5`376d4f3a        FF1500000000         call     [hackishModuleName:hackishMethodName(System.Object):System.Object:this]
; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ (call: 0 ; jcc erratum) 32B boundary ...............................
 000001a5`376d4f40        488BC8               mov      rcx, rax
 000001a5`376d4f43        FF1500000000         call     [CORINFO_HELP_READYTORUN_CHKCAST]
 000001a5`376d4f49        4885C0               test     rax, rax
 000001a5`376d4f4c        741C                 je       SHORT G_M54305_IG04
 000001a5`376d4f4e        80782800             cmp      byte  ptr [rax+40], 0
 000001a5`376d4f52        7416                 je       SHORT G_M54305_IG04
 000001a5`376d4f54        488B7008             mov      rsi, gword ptr [rax+8]
                                                ;; bbWeight=1    PerfScore 35.00
G_M54305_IG03:              ;; offset=0078H
 000001a5`376d4f58        807DE000             cmp      byte  ptr [rbp-20H], 0
 000001a5`376d4f5c        741D                 je       SHORT G_M54305_IG06
 000001a5`376d4f5e        488B4D10             mov      rcx, gword ptr [rbp+10H]
; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ (mov: 2) 32B boundary ...............................
 000001a5`376d4f62        FF1500000000         call     [System.Threading.Monitor:Exit()]
 000001a5`376d4f68        EB11                 jmp      SHORT G_M54305_IG06
                                                ;; bbWeight=1    PerfScore 9.00
G_M54305_IG04:              ;; offset=008AH
 000001a5`376d4f6a        488B4D10             mov      rcx, gword ptr [rbp+10H]
 000001a5`376d4f6e        488BCC               mov      rcx, rsp
 000001a5`376d4f71        E8AD000000           call     G_M54305_IG13
                                                ;; bbWeight=1    PerfScore 2.25
G_M54305_IG05:              ;; offset=0096H
 000001a5`376d4f76        E99E000000           jmp      G_M54305_IG11
                                                ;; bbWeight=1    PerfScore 2.00
G_M54305_IG06:              ;; offset=009BH
 000001a5`376d4f7b        4885F6               test     rsi, rsi
 000001a5`376d4f7e        742B                 je       SHORT G_M54305_IG07
; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ (je: 0 ; jcc erratum) 32B boundary ...............................
 000001a5`376d4f80        4C8D4DD8             lea      r9, [rbp-28H]
 000001a5`376d4f84        488B4D10             mov      rcx, gword ptr [rbp+10H]
 000001a5`376d4f88        488BD6               mov      rdx, rsi
 000001a5`376d4f8b        4533C0               xor      r8d, r8d
 000001a5`376d4f8e        FF1500000000         call     [System.Configuration.BaseConfigurationRecord:FindFactoryRecord(System.String,bool,byref):System.Configuration.FactoryRecord:this]
 000001a5`376d4f94        33D2                 xor      rdx, rdx
 000001a5`376d4f96        488955D8             mov      gword ptr [rbp-28H], rdx
 000001a5`376d4f9a        4883C050             add      rax, 80
 000001a5`376d4f9e        F60002               test     byte  ptr [rax], 2
; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ (test: 1) 32B boundary ...............................
 000001a5`376d4fa1        0F95C0               setne    al
 000001a5`376d4fa4        0FB6C0               movzx    rax, al
 000001a5`376d4fa7        85C0                 test     eax, eax
 000001a5`376d4fa9        7454                 je       SHORT G_M54305_IG10
                                                ;; bbWeight=1    PerfScore 13.25
G_M54305_IG07:              ;; offset=00CBH
 000001a5`376d4fab        488B4D10             mov      rcx, gword ptr [rbp+10H]
 000001a5`376d4faf        488B7128             mov      rsi, gword ptr [rcx+40]
 000001a5`376d4fb3        488B7920             mov      rdi, gword ptr [rcx+32]
 000001a5`376d4fb7        3936                 cmp      dword ptr [rsi], esi
 000001a5`376d4fb9        FF1500000000         call     [CORINFO_HELP_READYTORUN_NEW]
 000001a5`376d4fbf        488BD8               mov      rbx, rax
; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ (mov: 2) 32B boundary ...............................
 000001a5`376d4fc2        488BCB               mov      rcx, rbx
 000001a5`376d4fc5        FF1500000000         call     [System.EventArgs:.ctor()]
 000001a5`376d4fcb        488B1500000000       mov      rdx, qword ptr [(reloc 0x4000000000422170)]
 000001a5`376d4fd2        488D0C13             lea      rcx, bword ptr [rbx+rdx]
 000001a5`376d4fd6        488BD7               mov      rdx, rdi
 000001a5`376d4fd9        FF1500000000         call     [CORINFO_HELP_ASSIGN_REF]
 000001a5`376d4fdf        488B4630             mov      rax, gword ptr [rsi+48]
; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ (mov: 3) 32B boundary ...............................
 000001a5`376d4fe3        4885C0               test     rax, rax
 000001a5`376d4fe6        740D                 je       SHORT G_M54305_IG08
 000001a5`376d4fe8        488B4808             mov      rcx, gword ptr [rax+8]
 000001a5`376d4fec        488BD6               mov      rdx, rsi
 000001a5`376d4fef        4C8BC3               mov      r8, rbx
 000001a5`376d4ff2        FF5018               call     qword ptr [rax+24]System.Configuration.Internal.InternalConfigEventHandler:Invoke()
                                                ;; bbWeight=1    PerfScore 29.00
G_M54305_IG08:              ;; offset=0115H
 000001a5`376d4ff5        90                   nop
                                                ;; bbWeight=1    PerfScore 0.25
G_M54305_IG09:              ;; offset=0116H
 000001a5`376d4ff6        4883C438             add      rsp, 56
 000001a5`376d4ffa        5B                   pop      rbx
 000001a5`376d4ffb        5E                   pop      rsi
 000001a5`376d4ffc        5F                   pop      rdi
 000001a5`376d4ffd        5D                   pop      rbp
 000001a5`376d4ffe        C3                   ret
                                                ;; bbWeight=1    PerfScore 3.25
G_M54305_IG10:              ;; offset=011FH
 000001a5`376d4fff        488B4D10             mov      rcx, gword ptr [rbp+10H]
; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ (mov: 3) 32B boundary ...............................
 000001a5`376d5003        488B4928             mov      rcx, gword ptr [rcx+40]
 000001a5`376d5007        488B5510             mov      rdx, gword ptr [rbp+10H]
 000001a5`376d500b        4C8BC6               mov      r8, rsi
 000001a5`376d500e        4533C9               xor      r9d, r9d
 000001a5`376d5011        3909                 cmp      dword ptr [rcx], ecx
 000001a5`376d5013        FF1500000000         call     [System.Configuration.Internal.InternalConfigRoot:ClearResult()]
                                                ;; bbWeight=1    PerfScore 10.50
G_M54305_IG11:              ;; offset=0139H
 000001a5`376d5019        90                   nop
                                                ;; bbWeight=1    PerfScore 0.25
G_M54305_IG12:              ;; offset=013AH
 000001a5`376d501a        4883C438             add      rsp, 56
 000001a5`376d501e        5B                   pop      rbx
 000001a5`376d501f        5E                   pop      rsi
; ............................... 32B boundary ...............................
 000001a5`376d5020        5F                   pop      rdi
 000001a5`376d5021        5D                   pop      rbp
 000001a5`376d5022        C3                   ret
                                                ;; bbWeight=1    PerfScore 3.25
G_M54305_IG13:              ;; offset=0143H
 000001a5`376d5023        55                   push     rbp
 000001a5`376d5024        57                   push     rdi
 000001a5`376d5025        56                   push     rsi
 000001a5`376d5026        53                   push     rbx
 000001a5`376d5027        4883EC28             sub      rsp, 40
 000001a5`376d502b        488B6920             mov      rbp, qword ptr [rcx+32]
 000001a5`376d502f        48896C2420           mov      qword ptr [rsp+20H], rbp
 000001a5`376d5034        488D6D50             lea      rbp, [rbp+50H]
                                                ;; bbWeight=1    PerfScore 7.75
G_M54305_IG14:              ;; offset=0158H
 000001a5`376d5038        807DE000             cmp      byte  ptr [rbp-20H], 0
 000001a5`376d503c        740A                 je       SHORT G_M54305_IG15
 000001a5`376d503e        488B4D10             mov      rcx, gword ptr [rbp+10H]
; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ (mov: 2) 32B boundary ...............................
 000001a5`376d5042        FF1500000000         call     [System.Threading.Monitor:Exit()]
                                                ;; bbWeight=1    PerfScore 7.00
G_M54305_IG15:              ;; offset=0168H
 000001a5`376d5048        90                   nop
                                                ;; bbWeight=1    PerfScore 0.25
G_M54305_IG16:              ;; offset=0169H
 000001a5`376d5049        4883C428             add      rsp, 40
 000001a5`376d504d        5B                   pop      rbx
 000001a5`376d504e        5E                   pop      rsi
 000001a5`376d504f        5F                   pop      rdi
 000001a5`376d5050        5D                   pop      rbp
 000001a5`376d5051        C3                   ret
                                                ;; bbWeight=1    PerfScore 3.25

; Total bytes of code 370, prolog size 34, PerfScore 172.50, instruction count 118, allocated bytes for code 370 (MethodHash=a4d32bde) for method System.Configuration.BaseConfigurationRecord:OnStreamChanged(System.String):this
; ============================================================

According to the previous live var ranges, this is in rcx in the entire G_M54305_IG06 group, which looks wrong. After the change we report the stack home which seems better.

@jakobbotsch
Copy link
Copy Markdown
Member Author

cc @dotnet/jit-contrib

@jakobbotsch jakobbotsch merged commit d93136a into dotnet:main Sep 9, 2021
@jakobbotsch jakobbotsch deleted the fix-57752-2 branch September 9, 2021 08:20
@ghost ghost locked as resolved and limited conversation to collaborators Oct 9, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

JIT: Assertion failed '!m_VariableLiveRanges->back().m_EndEmitLocation.Valid()'

2 participants