https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69615
--- Comment #5 from Peter Cordes <peter at cordes dot ca> --- Update: https://godbolt.org/g/ZQDY1G gcc7/8 optimizes this to and / cmp / jb, while gcc6.3 doesn't. void rangecheck_var(int64_t x, int64_t lim2) { //lim2 >>= 60; lim2 &= 0xf; // let the compiler figure out the limited range of limit if (x>=0 && x<lim2) ext(); } gcc7 also fixed the -mtune=haswell bug where we got `movl %edi, %eax; subl $0, %eax` instead of `test %edi,%edi`. gcc8.1 still has the missed optimization with a compile-time constant 0..INT_MAX-1 range: void r0_to_imax_1(int x){ if (x>=0 && x<=(INT_MAX-1)) ext(); } // clang and gcc use 2 branches