Skip to content

Consuming static readonly Vector128<T> fields results in non-optimal codegen #13514

@GrabYourPitchforks

Description

@GrabYourPitchforks

Sample code:

private static readonly Vector128<sbyte> Vector0x0F = Vector128.Create((sbyte)0x0F);

public static int GetMask(Vector128<sbyte> data)
{
    return Sse2.MoveMask(Sse2.Add(data, Vector0x0F));
}

Codegen:

00007ffc`19901370 c5f877          vzeroupper
00007ffc`19901373 c5f91001        vmovupd xmm0,xmmword ptr [rcx]
00007ffc`19901377 48b8482ca75ea8010000 mov rax,1A85EA72C48h
00007ffc`19901381 488b00          mov     rax,qword ptr [rax]  ; this dereference could be avoided
00007ffc`19901384 c5f9fc4008      vpaddb  xmm0,xmm0,xmmword ptr [rax+8]
00007ffc`19901389 c5f9d7c0        vpmovmskb eax,xmm0
00007ffc`1990138d c3              ret

Since the static ctor has already been run, the JIT could be optimized to burn into the codegen the exact memory location of where the Vector0x0F field lives. This would allow eliding the dereference highlighted in the above codegen sample.

/cc @tannergooding

category:cq
theme:basic-cq
skill-level:expert
cost:medium

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