dotnet/runtime

[JIT] X64 - Possible comparison optimization using `and` with a small type

Open

#81.520 geöffnet am 2. Feb. 2023

Auf GitHub ansehen
 (1 Kommentar) (0 Reaktionen) (0 zugewiesene Personen)C# (5.445 Forks)batch import
arch-x64area-CodeGen-coreclrhelp wantedtenet-performance

Repository-Metriken

Stars
 (17.886 Stars)
PR-Merge-Metriken
 (Durchschn. Merge 12T 11h) (661 gemergte PRs in 30 T)

Beschreibung

using System.Runtime.CompilerServices;

static class Program
{
    [MethodImpl(MethodImplOptions.NoInlining)]
    public static void SideEffect()
    {
    }

    public static bool Test(byte p, int i)
    {
        if ((p & 0xffffff00) != 0)
        {
            SideEffect();
            return true;
        }
        return false;
    }
}

The (p & 0xffffff00) != 0 condition in this case can never be true. So, we could optimize this by folding it into false thus will eliminate the true path.

This will probably not have a lot of impact.

Contributor Guide