http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52933

             Bug #: 52933
           Summary: SH Target: Use div0s for integer sign comparisons
    Classification: Unclassified
           Product: gcc
           Version: 4.8.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
        AssignedTo: unassig...@gcc.gnu.org
        ReportedBy: olege...@gcc.gnu.org
            Target: sh*-*-*


Created attachment 27130
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=27130
Experimental patch to use div0s for sign comparisons

The div0s instruction can be used to implement some integer sign comparison
patterns such as:

int a = ...;
int b = ...;

(a ^ b) >= 0;
(a < 0) == (b < 0);
(a ^ b) >> 31;

etc.

For example, the following function

bool test (int a, int b)
{
  return (a ^ b) >= 0;
}

is compiled into:
        xor     r4,r5
        not     r5,r0
        mov     #-31,r1
        shld    r1,r0
        rts
        extu.b  r0,r0

but could be:
        div0s   r5,r4
        mov     #-1,r0
        rts
        negc    r0,r0

Reply via email to