Skip to content

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

@Validark

Description

@Validark
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.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions