-
Notifications
You must be signed in to change notification settings - Fork 15.5k
Open
Labels
Description
#include <stdint.h>
uint32_t f(uint16_t x) {
if (x >= 8192) {
__builtin_unreachable();
}
return (uint16_t)(x << 3);
}
uint32_t g(uint16_t x) {
if (x >= 8192) {
__builtin_unreachable();
}
return (uint16_t)(x << 3) | ((uint32_t)x << 16);
}Expected behavior: x fits in 13 bits, so x << 3 fits in 16 bits and the cast can be optimized out. Current lowering:
f(unsigned short):
shl edi, 3
movzx eax, di ; unnecessary
ret
g(unsigned short):
mov eax, edi
and eax, 8191 ; unnecessary
shl edi, 16
lea eax, [rdi + 8*rax]
retIR recognizes shift as non-wrapping with shl nuw, so this is just a missed opt in isel.