[Bug target/54673] [SH] Unnecessary sign extension of logical operation results

olegendo at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Sun Feb 17 11:38:00 GMT 2013


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

--- Comment #2 from Oleg Endo <olegendo at gcc dot gnu.org> 2013-02-17 11:38:21 UTC ---
A related reduced example from CSiBE bzip2.c (compressStream):


typedef struct
{
  int _r[3];
  short _flags;
} FILE;


void BZ2_bzWriteOpen (int* e, FILE* f, int a, int b, int c);

FILE* outputHandleJustInCase;

void
compressStream (FILE *stream, unsigned char* ibuf)
{
  int bzerr;

  if ((stream->_flags & 0x0040) != 0)
    return;

  BZ2_bzWriteOpen (&bzerr, stream, 0, 0, 0);

  while (fgetc (stream) != -1)
    fread (ibuf, 1, 5000, stream);

  if ((stream->_flags & 0x0040) != 0)
    return;

  outputHandleJustInCase = 0;
}


... compiled with -O2 -m4 it contains the following sequence twice:

        mov.w   @(12,r4),r0
        and     #64,r0
        exts.w  r0,r1
        tst     r1,r1

the exts.w can be replaced with a reg copy, which is better for SH2A and SH4*:

        mov.w   @(12,r4),r0
        and     #64,r0
        mov     r0,r1
        tst     r1,r1



More information about the Gcc-bugs mailing list