Bug ID: 77664
           Summary: Missed optimization: signed int >= 0 && < unsigned
           Product: gcc
           Version: 6.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: rtl-optimization
          Assignee: unassigned at gcc dot
          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)

the "a >= 0 && a < b" test could be implemented as a single unsigned
comparison, e.g. on x86-64:

   cmp %esi,%edi
   jb foo

GCC, however, misses this optimization (even at -O3) and generates two separate

   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.)

Reply via email to