Skip to content

Conversation

@TIHan
Copy link
Contributor

@TIHan TIHan commented Feb 6, 2023

Description

When I allowed LONG types in #81454 , I noticed some regressions. They were caused by the IR tree looking like this:
CAST(long <- CAST(int <- short <- long))

On x64, this would emit:

movsx    rdx, cx
movsxd   rdx, edx

The movsxd is redundant as movsx has already sign-extended to 8 bytes and we only ever emit movsx as an 8-byte operation; there will never be a case where we emit movsx edx, cx on 64-bit. Therefore, we can skip emitting movsxd if we know the previous instruction sign-extended the register all the way to 8 bytes.

Example diffs:

        imul     rdx, rdx, 60
        sub      rcx, rdx
        movsx    rdx, word  ptr [rbp-40H]
-       movsxd   rdx, edx
        imul     rdx, rdx, 60
        mov      r8, 0xD1FFAB1E
        cmp      rdx, r8
        jg       G_M18963_IG34
-						;; size=182 bbWeight=0.50 PerfScore 18.88
+						;; size=179 bbWeight=0.50 PerfScore 18.75
        movsx    rax, word  ptr [rcx]
-       cdqe     
        imul     rax, rax, 60
        mov      rdx, 0xD1FFAB1E
        cmp      rax, rdx
        jg       SHORT G_M26742_IG06
-						;; size=25 bbWeight=1.00 PerfScore 7.75
+						;; size=23 bbWeight=1.00 PerfScore 7.50

The cdqe instruction is simply an optimization for size when trying to emit movsxd rax, eax - so it's expected that this was also skipped.

Acceptance Criteria

  • CI passes
  • Disasm tests

@ghost ghost added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Feb 6, 2023
@ghost ghost assigned TIHan Feb 6, 2023
@ghost
Copy link

ghost commented Feb 6, 2023

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

Issue Details

null

Author: TIHan
Assignees: TIHan
Labels:

area-CodeGen-coreclr

Milestone: -

@TIHan TIHan changed the title Allow GT_CAST for long to small types on 64bit [JIT] ARM64/X64 - Allow GT_CAST for long to small types on 64bit Feb 6, 2023
@TIHan TIHan changed the title [JIT] ARM64/X64 - Allow GT_CAST for long to small types on 64bit [JIT] X64 - Peephole optimization to skip emitting movsx Feb 6, 2023
@TIHan TIHan changed the title [JIT] X64 - Peephole optimization to skip emitting movsx [JIT] X64 - Peephole optimization to skip emitting movsxd Feb 6, 2023
@TIHan
Copy link
Contributor Author

TIHan commented Feb 7, 2023

Diffs

@dotnet/jit-contrib @BruceForstall - no regressions, decent number of improvements - should be a quick and easy review

@TIHan TIHan marked this pull request as ready for review February 7, 2023 20:09
@TIHan TIHan merged commit 4d51539 into dotnet:main Feb 9, 2023
@TIHan TIHan deleted the cast-long-short-opt branch February 9, 2023 17:46
@ghost ghost locked as resolved and limited conversation to collaborators Mar 11, 2023
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.

2 participants