llvm/llvm-project

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

Open

#168,828 opened on 2025年11月20日

GitHub で見る
 (16 comments) (0 reactions) (1 assignee)C++ (10,782 forks)batch import
backend:X86good first issuellvm:SelectionDAGmissed-optimization

Repository metrics

Stars
 (26,378 stars)
PR merge metrics
 (平均マージ 1d 2h) (30d で 1,000 merged PRs)

説明

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.

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