Skip to content

RyuJIT generates redundant code when inlining string.IsNullOrEmpty #4207

@mikedn

Description

@mikedn

C# code:

static int Main(string[] args) {
    return string.IsNullOrEmpty(args[0]) ? 42 : 0;
}

ASM code:

G_M1504_IG02:
       83790800             cmp      dword ptr [rcx+8], 0
       7628                 jbe      SHORT G_M1504_IG06
       488B4110             mov      rax, gword ptr [rcx+16]
       4885C0               test     rax, rax
       7415                 je       SHORT G_M1504_IG04
       83780800             cmp      dword ptr [rax+8], 0
       0F94C0               sete     al          ; redundant
       0FB6C0               movzx    rax, al     ; redundant
       85C0                 test     eax, eax    ; redundant
       7507                 jne      SHORT G_M1504_IG04
       33C0                 xor      eax, eax

Basically the IL code after inline contains a ceq followed by a brtrue and the JIT compiler doesn't seem capable of folding them.

category:cq
theme:optimization
skill-level:expert
cost:large

Metadata

Metadata

Assignees

Labels

area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMIenhancementProduct code improvement that does NOT require public API changes/additionsoptimizationtenet-performancePerformance related issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions