llvm/llvm-project

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

Open

#168.828 aperta il 20 nov 2025

Vedi su GitHub
 (16 commenti) (0 reazioni) (1 assegnatario)C++ (10.782 fork)batch import
backend:X86good first issuellvm:SelectionDAGmissed-optimization

Metriche repository

Star
 (26.378 star)
Metriche merge PR
 (Merge medio 1g 2h) (1000 PR mergiate in 30 g)

Descrizione

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.

Guida contributor