[size] Redundant uxth/sxth insn are generated

Bug #634682 reported by Yao Qi
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Linaro GCC
Triaged
Low
Kugan Vivekanandarajah

Bug Description

Compile this case by FSF GCC trunk reveals redundant uxth/sxth instructions.

short unPack( unsigned char c )
{
    /* Only want lower four bit nibble */
    c = c & (unsigned char)0x0F ;

    if( c > 7 ) {
        /* Negative nibble */
        return( ( short )( c - 16 ) ) ;
    }
    else
    {
        /* positive nibble */
        return( ( short )c ) ;
    }
}

# arm-none-linux-gnueabi-gcc -march=armv7-a -mthumb -Os unpack.c -S
unPack:
        @ args = 0, pretend = 0, frame = 0
        @ frame_needed = 0, uses_anonymous_args = 0
        @ link register save eliminated.
        and r0, r0, #15
        cmp r0, #7
        bls .L3
        subs r0, r0, #16
        uxth r0, r0
.L3:
        sxth r0, r0
        bx lr

uxth/sxth are still there with option {thumb,arm} {O2,O3}

Tags: size speed task
Revision history for this message
Yao Qi (yao-codesourcery) wrote :

It is found in eembc/automotive/idctrn01/bmark.c

Michael Hope (michaelh1)
tags: added: size task
Revision history for this message
Andrew Stubbs (ams-codesourcery) wrote :

This program has the same problem:

  unsigned char
  f (unsigned int c)
  {
    if (c < 50)
      return c;
    return 0;
  }

Upstream GCC (pre-4.6) with "-mcpu=cortex-a8 -O2" gives:

        cmp r0, #49
        uxtbls r0, r0
        movhi r0, #0
        bx lr

As far as I can see, the only compiler pass that could "know" that the zero-extend is redundant is the VRP pass (Value Range Propagation). It's not totally clear to me whether it's supposed to be able to remove/annotate the type conversion, and it's not working, or whether this is just not addressed anywhere in the compiler.

Revision history for this message
Ramana Radhakrishnan (ramana) wrote :

I don't see how this can be done without VRP at the RTL level to show that the value of c is bounded by 50 above.

Ramana

Changed in gcc-linaro:
importance: Undecided → Low
status: New → Triaged
tags: added: speed
Revision history for this message
Ramana Radhakrishnan (ramana) wrote :

Unless we can get VRP to deal with this in RTL I'm not sure how we could deal with this .

Ramana

Revision history for this message
Kugan Vivekanandarajah (kugan-vivekanandarajah) wrote :
Changed in gcc-linaro:
assignee: nobody → Kugan Vivekanandarajah (kugan-vivekanandarajah)
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.