Skip to content

Performance: JIT is emitting multiple conversion instructions when using float-math #77658

@hopperpl

Description

@hopperpl
    public float GetComp5(uint color) {
      return color * (255 / 31f);
    }

converted to

C.GetComp5(UInt32)
    L0000: vzeroupper
    L0003: mov eax, edx
    L0005: vxorps xmm0, xmm0, xmm0
    L0009: vcvtsi2sd xmm0, xmm0, rax                 ; <-- 2x conversion, should use cvtsi2ss
    L000e: vcvtsd2ss xmm0, xmm0, xmm0
    L0012: vmulss xmm0, xmm0, [0x7ff9f52004a0]
    L001a: ret

there shouldn't be two conversions, integer directly to single-precision is possible


for reference, clang does this (in C++):

GetComp5(unsigned int):
        mov       edi, edi
        pxor      xmm0, xmm0
        cvtsi2ss  xmm0, rdi
        mulss     xmm0, DWORD PTR .LC2[rip]
        ret

Metadata

Metadata

Assignees

No one assigned

    Labels

    Priority:3Work that is nice to havearea-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMIgood first issueIssue should be easy to implement, good for first-time contributorsin-prThere is an active PR which will close this issue when it is mergedtenet-performancePerformance related issue

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions