https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77664
Bug ID: 77664 Summary: Missed optimization: signed int >= 0 && < unsigned short Product: gcc Version: 6.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: rtl-optimization Assignee: unassigned at gcc dot gnu.org Reporter: achurch+gcc at achurch dot org Target Milestone: --- Given the following code: extern void foo(void); void bar(int a, unsigned short b) { if (a >= 0 && a < b) foo(); } the "a >= 0 && a < b" test could be implemented as a single unsigned comparison, e.g. on x86-64: bar: cmp %esi,%edi jb foo ret GCC, however, misses this optimization (even at -O3) and generates two separate comparisons: bar: test %edi,%edi js 0f movzwl %si,%esi cmp %esi,%edi jl 1f 0: repz ret nopl (%rax) 1: jmp foo (The movzwl is also unnecessary per my reading of the x86-64 ABI, but that's a different issue.) FWIW, Clang 3.8.1 successfully optimizes this at -O and higher. (Component is a guess; please move if appropriate.)