Hi,

This patch series (2) implements zext/sext extension elimination using
value ranges stored in SSA. Implementation is what was suggested in the
thread https://gcc.gnu.org/ml/gcc/2014-05/msg00213.html.

I have broken this into:

Patch 1 - Changes to store zero and sign extended promotions
(SPR_SIGNED_AND_UNSIGNED) in SUBREG with SUBREG_PROMOTED_VAR_P.
Patch 2 - Enables Zext/sext extensions by checking the value range.

test-cases that motivated this and the asm difference with the patch are:

1.
short foo(unsigned char c)
{
  c = c & (unsigned char)0x0F;
  if( c > 7 )
    return((short)(c - 5));
  else
    return(( short )c);
}

        and     r0, r0, #15
        cmp     r0, #7
        subhi   r0, r0, #5
-       uxth    r0, r0
-       sxth    r0, r0
        bx      lr

2.
unsigned short
crc2(unsigned short crc, unsigned char data)
{
   unsigned char i, x16, carry;
   for (i = 0; i < 8; i++)
     {
       x16 = (data ^ crc) & 1;
       data >>= 1;
       if (x16 == 1)
         {
           crc ^= 0x4002;
           carry = 1;
         }
       else
         carry = 0;
      crc >>= 1;
       if (carry)
         crc |= 0x8000;
       else
         crc &= 0x7fff;
     }
   return crc;
}

-       mov     r3, #8
+       mov     r2, #8
 .L3:
-       eor     r2, r1, r0
-       sub     r3, r3, #1
-       tst     r2, #1
+       eor     r3, r1, r0
        mov     r1, r1, lsr #1
+       tst     r3, #1
        eorne   r0, r0, #16384
        moveq   r0, r0, lsr #1
        eorne   r0, r0, #2
        movne   r0, r0, lsr #1
        orrne   r0, r0, #32768
-       ands    r3, r3, #255
+       subs    r2, r2, #1
        bne     .L3
        bx      lr

Tested both patches on x86_64-unknown-linux-gnu and
arm-none-linux-gnueabi with no new regressions. Is this OK?

Thanks,
Kugan

Reply via email to