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

[JIT]: Codegen for manual devirtualization #60492

Closed
omariom opened this issue Oct 15, 2021 · 4 comments
Closed

[JIT]: Codegen for manual devirtualization #60492

omariom opened this issue Oct 15, 2021 · 4 comments
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI untriaged New issue has not been triaged by the area owner

Comments

@omariom
Copy link
Contributor

omariom commented Oct 15, 2021

This code (sharplab)..

    public T WithManualDevirt(int index)
    {
        var listStore = _listStore;
        
        if (listStore is SingleItemList<T> singleItem)
            return singleItem.EntryAt(index);
            
        return listStore.EntryAt(index);
    }

generates the following assembly:

       mov rcx, [rcx+8]
       mov rax, rcx
       test rax, rax
       je short L001d
       mov r8, 0x7fff4a8ad9c0
       cmp [rax], r8
       je short L001d
       xor eax, eax
L001d: test rax, rax
       je short L0026
       mov eax, [rax+8]
       ret
L0026: mov rax, [rcx]
       mov rax, [rax+0x40]
       mov rax, [rax+0x20]
       jmp rax

I think it could be simpler, with less tests and jumps

       mov rcx, [rcx+8]
       mov rax, rcx
       test rax, rax
       je short L0026
       mov r8, 0x7fff4a8ad9c0
       cmp [rax], r8
       jne short L0026
       mov eax, [rax+8]
       ret
L0026: mov rax, [rcx]
       mov rax, [rax+0x40]
       mov rax, [rax+0x20]
       jmp rax

sharplab is now on 5.0, but 6.0 rc2 generates the same code.

@dotnet-issue-labeler dotnet-issue-labeler bot added area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI untriaged New issue has not been triaged by the area owner labels Oct 15, 2021
@ghost
Copy link

ghost commented Oct 15, 2021

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

Issue Details

This code (sharlab)..

    public T WithManualDevirt(int index)
    {
        var listStore = _listStore;
        
        if (listStore is SingleItemList<T> singleItem)
            return singleItem.EntryAt(index);
            
        return listStore.EntryAt(index);
    }

generates the following assembly:

       mov rcx, [rcx+8]
       mov rax, rcx
       test rax, rax
       je short L001d
       mov r8, 0x7fff4a8ad9c0
       cmp [rax], r8
       je short L001d
       xor eax, eax
L001d: test rax, rax
       je short L0026
       mov eax, [rax+8]
       ret
L0026: mov rax, [rcx]
       mov rax, [rax+0x40]
       mov rax, [rax+0x20]
       jmp rax

I think it could be simpler, with less tests and jumps

       mov rcx, [rcx+8]
       mov rax, rcx
       test rax, rax
       je short L0026
       mov r8, 0x7fff4a8ad9c0
       cmp [rax], r8
       jne short L0026
       mov eax, [rax+8]
       ret
L0026: mov rax, [rcx]
       mov rax, [rax+0x40]
       mov rax, [rax+0x20]
       jmp rax

sharplab is now on 5.0, but 6.0 rc2 generates the same code.

Author: omariom
Assignees: -
Labels:

area-CodeGen-coreclr, untriaged

Milestone: -

@Sergio0694
Copy link
Contributor

Potentially related to #36649?
cc. @EgorBo

@EgorBo
Copy link
Member

EgorBo commented Oct 16, 2021

Yes, there were two solutions there: 1) In some cases our inlined castclass/isinst produces a bit suboptimal IR 2) Jump-threading optimization gives up on GT_PHI nodes currently

image

@EgorBo
Copy link
Member

EgorBo commented Oct 16, 2021

Thanks for reminding me this issue! But I think we can close it as dup of #36649

@omariom omariom closed this as completed Oct 16, 2021
@ghost ghost locked as resolved and limited conversation to collaborators Nov 15, 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 untriaged New issue has not been triaged by the area owner
Projects
None yet
Development

No branches or pull requests

3 participants