dotnet/runtime

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

オープン

#81,520 opened on 2023/02/02

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

Repository metrics

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

説明

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.

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