dotnet/runtime

Chained comparison of two integers against a constant is not coalesced

Open

#101.347 aperta il 21 apr 2024

Vedi su GitHub
 (1 commento) (0 reazioni) (0 assegnatari)C# (5445 fork)batch import
area-CodeGen-coreclrhelp wantedin-prtenet-performance

Metriche repository

Star
 (17.886 star)
Metriche merge PR
 (Merge medio 12g 11h) (661 PR mergiate in 30 g)

Descrizione

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

Guida contributor