https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115674
Bug ID: 115674 Summary: "Checking if number is within interval" missed optimization when number is from a smaller int type Product: gcc Version: 14.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: rtl-optimization Assignee: unassigned at gcc dot gnu.org Reporter: Explorer09 at gmail dot com Target Milestone: --- ```c #include <stdbool.h> #include <stdint.h> bool func1(uint8_t x) { uint32_t value; value = x; if (value < 0xC2 || value > 0xF4) { return false; } return true; } bool func2(uint8_t x) { uint32_t value; value = x; if ((uint8_t)value < 0xC2 || (uint8_t)value > 0xF4) { return false; } return true; } ``` x86_64 gcc with -Os option produces: ```x86asm func1: movzx edi, dil sub edi, 194 cmp edi, 50 setbe al ret func2: add edi, 62 cmp dil, 50 setbe al ret ``` For x86-64, the expected result is func1 transformed to func2. For ARM and RISC-V targets, I expect the other way around, that is, transform func2 to func1, so that it saves a "bitwise AND 0xFF" operation.