[Bug middle-end/112629] Missed-optimization: constant << (b + signed_constant)
pinskia at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Sun Nov 19 21:04:30 GMT 2023
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112629
--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Note we could do it even for unsigned if we know that (a+4) will not wrap.
That is:
```
#include <limits.h>
int optimized_shift(unsigned shift) {
if ((shift < 0) | (shift > (unsigned)INT_MAX)) __builtin_unreachable();
return 1 << (shift + 4);
}
```
LLVM is able to handle both cases.
More information about the Gcc-bugs
mailing list