Skip to content

If compReturnBB is unreachable we should remove it #48740

@AndyAyersMS

Description

@AndyAyersMS

We create compReturnBB anticipating redirection of existing returns, but we do that before we take tail calls into account, so we may not actually redirect any returns there. Because the block is marked with BBF_DONT_REMOVE it hangs around and ends up creating a dead epilog. Here's an example; note IG06 is unreachable.

Probably not super common, but we should consider some other method of keeping the block around until morph (like an artificial ref count that we retract), or perhaps not creating it until it is needed.

; Assembly listing for method System.Type:get_Attributes():int:this
; Emitting BLENDED_CODE for X64 CPU with AVX - Windows
; Tier-1 compilation
; optimized code
; optimized using profile data
; rbp based frame
; fully interruptible
; with IBC profile data, edge weights are valid, and fgCalledCount is 89
; Final local variable assignments
;
;  V00 this         [V00,T00] (  6,  4   )     ref  ->  rax         this class-hnd
;  V01 OutArgs      [V01    ] (  1,  1   )  lclBlk (32) [rsp+0x00]   "OutgoingArgSpace"
;* V02 tmp1         [V02    ] (  0,  0   )     int  ->  zero-ref    "guarded devirt return temp"
;* V03 tmp2         [V03    ] (  0,  0   )     ref  ->  zero-ref    class-hnd exact "guarded devirt this exact temp"
;  V04 tmp3         [V04,T01] (  1,  0   )     int  ->  rax         "Single return block return value"
;
; Lcl frame size = 32

G_M30881_IG01:              ;; offset=0000H
       55                   push     rbp
       4883EC20             sub      rsp, 32
       488D6C2420           lea      rbp, [rsp+20H]
       48894D10             mov      gword ptr [rbp+10H], rcx
       488D0D00000000       lea      rcx, [(reloc)]
       488D5510             lea      rdx, [rbp+10H]
       FF1500000000         call     [CORINFO_HELP_PROF_FCN_ENTER]
       488B4D10             mov      rcx, gword ptr [rbp+10H]
       488BC1               mov      rax, rcx
                                                ;; bbWeight=1    PerfScore 8.00
G_M30881_IG02:              ;; offset=0026H
       48BA48A7649DFC7F0000 mov      rdx, 0x7FFC9D64A748
       483910               cmp      qword ptr [rax], rdx
       751E                 jne      SHORT G_M30881_IG04
       488D0D00000000       lea      rcx, [(reloc)]
       488D5510             lea      rdx, [rbp+10H]
       FF1500000000         call     [CORINFO_HELP_PROF_FCN_TAILCALL]
       488BC8               mov      rcx, rax
                                                ;; bbWeight=1    PerfScore 7.50
G_M30881_IG03:              ;; offset=0049H
       488D6500             lea      rsp, [rbp]
       5D                   pop      rbp
       E900000000           jmp      hackishModuleName:hackishMethodName()
                                                ;; bbWeight=1    PerfScore 3.00
G_M30881_IG04:              ;; offset=0053H
       488D0D00000000       lea      rcx, [(reloc)]
       488D5510             lea      rdx, [rbp+10H]
       FF1500000000         call     [CORINFO_HELP_PROF_FCN_TAILCALL]
       488BC8               mov      rcx, rax
       488B00               mov      rax, qword ptr [rax]
       488B4078             mov      rax, qword ptr [rax+120]
       488B00               mov      rax, qword ptr [rax]
                                                ;; bbWeight=0    PerfScore 0.00
G_M30881_IG05:              ;; offset=0071H
       488D6500             lea      rsp, [rbp]
       5D                   pop      rbp
       48FFE0               rex.jmp  rax
                                                ;; bbWeight=0    PerfScore 0.00
G_M30881_IG06:              ;; offset=0079H
       488D0D00000000       lea      rcx, [(reloc)]
       488D5510             lea      rdx, [rbp+10H]
       FF1500000000         call     [CORINFO_HELP_PROF_FCN_LEAVE]
       90                   nop
                                                ;; bbWeight=0    PerfScore 0.00
G_M30881_IG07:              ;; offset=008BH
       488D6500             lea      rsp, [rbp]
       5D                   pop      rbp
       C3                   ret

category:cq
theme:block-opts

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions