area-CodeGen-coreclrhelp wantedin-pr
仓库指标
- Star
- (17,886 star)
- PR 合并指标
- (平均合并 12天 11小时) (30 天内合并 661 个 PR)
描述
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