[X86] Missing use of 8-/16-bit `cmp` for comparing truncated values
Open
backend:X86
missed-optimization
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
Code like:
```c
#include
void ext(void);
void gt_u8(long a, long b) {
if ((uint8_t)a > (uint8_t)b) ext();
}
```
compiled with `-O3`, compiles to:
```asm
gt_u8:
movzx eax, dil
movzx ecx, sil
cmp eax, ecx
ja ext@PLT
ret
```
but could compile to:
```asm
gt_u8:
cmp dil, sil
ja ext@PLT
ret
```
This applies to 8-bit and 16-bit types, and both `>` and `>=`.
Also happens with one arg being an immediate (though for the 16-bit case that may be actually undesirable due to slow data16).
https://c.godbolt.org/z/9hKc6shfc
Contributor guide
Assessment
This issue has not been assessed yet.