Skip to content

JIT: Shorter x64 encoding for all 32bit negative immeds moved into 64bit register #134012

Description

@BoyBaykiller
static long Foo()
{
    return -1;
}
G_M17693_IG02:  ;; offset=0x0000
       48B8FFFFFFFFFFFFFFFF mov      rax, -1
						;; size=10 bbWeight=1 PerfScore 0.25

We currently use the 'B8' opcode which expects a full imm64 which is option 1.

1. B8 | MOV r64, imm64   | Move imm64 to r64.
2. C7 | MOV r/m64, imm32 | Move imm32 sign extended to 64-bits to r/m64.

Instead we should use option 2. when possible and save 3bytes (it needs one extra ModRM byte).
We already do the same optimization for the zero-extension case.

Activity

  1. added
    untriaged
    on Sep 15, 2026
  2. added
    area-CodeGen-coreclr
    on Sep 15, 2026
  3. dotnet-policy-service commented on Sep 15, 2026

    @dotnet-policy-service
    Contributor

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

  4. added this to the 12.0.0 milestone on Oct 9, 2026
  5. removed
    untriaged
    on Oct 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

area-CodeGen-coreclr

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions