llvm / llvm/llvm-project

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

Open
#168,828 16 comments 0 reactions 1 assignee Claimed by @stomfaig View on GitHub
backend:X86 good first issue llvm:SelectionDAG missed-optimization
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

```zig
export fn foo(x: u8) u32 {
return @ctz(x >> 1);
}
```

```asm
foo:
shr dil
movzx eax, dil
or eax, 256
tzcnt eax, eax
ret
```

Could be:

```asm
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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.