dotnet/runtime

JIT bit test is not recognized for pattern matching syntax

Open

#107.801 aberto em 13 de set. de 2024

Ver no GitHub
 (2 comments) (11 reactions) (0 assignees)C# (5.445 forks)batch import
area-CodeGen-coreclrhelp wantedin-pr

Métricas do repositório

Stars
 (17.886 stars)
Métricas de merge de PR
 (Mesclagem média 12d 11h) (661 fundiu PRs em 30d)

Description

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

Guia do colaborador