Skip to content

JIT bit test is not recognized for pattern matching syntax #107801

@EgorBo

Description

@EgorBo

Reported in https://devblogs.microsoft.com/dotnet/performance-improvements-in-net-9/?commentid=21177#comment-21177

The following two functions emit different codegen (suboptimal in case of Test1):

void Test1(char c)
{
    if (c is ' ' or '\t' or '\r' or '\n')
        Console.WriteLine("Hello, World!");
}


void Test2(char c)
{
    if (c == ' ' || c == '\t' || c == '\r' || c == '\n')
        Console.WriteLine("Hello, World!");
}

Codegen:

; Assembly listing for method Program:Test1(ushort):this (FullOpts)
       movzx    rcx, dx
       lea      eax, [rcx-0x09]
       cmp      eax, 4
       ja       SHORT G_M39625_IG04
       mov      ecx, eax
       lea      rax, [reloc @RWD00]
       mov      eax, dword ptr [rax+4*rcx]
       lea      rdx, G_M39625_IG02
       add      rax, rdx
       jmp      rax
G_M39625_IG04:
       cmp      ecx, 32
       je       SHORT G_M39625_IG06
G_M39625_IG05:
       ret      
G_M39625_IG06:
       mov      rcx, 0x21100204D88      ; 'Hello, World!'
       tail.jmp [System.Console:WriteLine(System.String)]
RWD00  	dd	00000029h ; case G_M39625_IG06
       	dd	00000029h ; case G_M39625_IG06
       	dd	00000028h ; case G_M39625_IG05
       	dd	00000028h ; case G_M39625_IG05
       	dd	00000029h ; case G_M39625_IG06
; Total bytes of code 57


; Assembly listing for method Program:Test2(ushort):this (FullOpts)
       movzx    rcx, dx
       cmp      ecx, 32
       ja       SHORT G_M37482_IG04
       mov      eax, 0xFFFFD9FF
       bt       rax, rcx
       jae      SHORT G_M37482_IG05
G_M37482_IG04:
       ret      
G_M37482_IG05:
       mov      rcx, 0x21100204D88      ; 'Hello, World!'
       tail.jmp [System.Console:WriteLine(System.String)]
; Total bytes of code 36

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMIhelp wanted[up-for-grabs] Good issue for external contributorsin-prThere is an active PR which will close this issue when it is merged

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions