dotnet/runtime

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

Open

#81,520 创建于 2023年2月2日

在 GitHub 查看
 (1 评论) (0 反应) (0 负责人)C# (5,445 fork)batch import
arch-x64area-CodeGen-coreclrhelp wantedtenet-performance

仓库指标

Star
 (17,886 star)
PR 合并指标
 (平均合并 12天 11小时) (30 天内合并 661 个 PR)

描述

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.

贡献者指南