llvm/llvm-project

[x86] Eliminate `movzx` when upper part of register is irrelevant or overwritten

Open

#168,828 建立於 2025年11月20日

在 GitHub 查看
 (16 留言) (0 反應) (1 負責人)C++ (10,782 fork)batch import
backend:X86good first issuellvm:SelectionDAGmissed-optimization

倉庫指標

Star
 (26,378 star)
PR 合併指標
 (平均合併 1天 2小時) (30 天內合併 1,000 個 PR)

描述

export fn foo(x: u8) u32 {
    return @ctz(x >> 1);
}
foo:
        shr     dil
        movzx   eax, dil
        or      eax, 256
        tzcnt   eax, eax
        ret

Could be:

foo:
        shr     dil
        or      edi, 256
        tzcnt   eax, edi
        ret

The compiler could also look for things like or eax, -256 and eliminate movzx eax, al since the relevant bits are overwritten anyway.

貢獻者指南