dotnet/runtime

Chained comparison of two integers against a constant is not coalesced

オープン

#101,347 opened on 2024/04/21

 (1 件のコメント) (0 件のリアクション) (0 人の担当者)C# (5,445 件のフォーク)batch import
area-CodeGen-coreclrhelp wantedin-prtenet-performance

Repository metrics

Stars
 (17,886 個のスター)
PR merge metrics
 (平均マージ 12d 11h) (30d で 661 merged PRs)

説明

Description

Given the snippet

static bool Test(int a, int b) => a is 0x80 && b is 0x80;

.NET emits

       cmp      ecx, 128
       jne      SHORT G_M000_IG05
       xor      eax, eax
       cmp      edx, 128
       sete     al
       ret      
G_M000_IG05:                ;; offset=0x0014
       xor      eax, eax
       ret      

While Clang emits

        xor     edi, 128
        xor     esi, 128
        or      esi, edi
        sete    al
        ret

It would be nice if JIT/ILC could emit branchless comparison for such patterns.

Configuration

.NET 8.0.3

Regression?

No

コントリビューターガイド