public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/60641] New: Converting ushort to offset on x86_64 generates double movzwl
@ 2014-03-24 20:59 akruppa at gmail dot com
  2014-03-25  9:25 ` [Bug target/60641] " rguenth at gcc dot gnu.org
  2014-05-26 12:46 ` akruppa at gmail dot com
  0 siblings, 2 replies; 3+ messages in thread
From: akruppa at gmail dot com @ 2014-03-24 20:59 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 60641
           Summary: Converting ushort to offset on x86_64 generates double
                    movzwl
           Product: gcc
           Version: 4.7.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: akruppa at gmail dot com

The following test cases produce sub-optimal assembly output.
This was verified with these three versions of gcc:
gcc (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3
gcc (SUSE Linux) 4.7.3
gcc (Debian 4.8.2-16) 4.8.2


#include <stdlib.h>
unsigned short
foo (const unsigned short *start, const unsigned char *mask)
{
   unsigned short r = 0;
   unsigned short ux = *start;
   if (mask[ux])
     r = ux;
   return r;
}
void bar(unsigned int *s, unsigned short a)
{
  s[a] = a;
}


Compile with, e.g., 

gcc -std=c99 -g -W -Wall -O3 -c movzwl.c

The effect also occurs when using -O2 instead.

The foo() function contains:
   0x0000000000000000 <+0>:     movzwl (%rdi),%edx
   0x0000000000000003 <+3>:     xor    %eax,%eax
   0x0000000000000005 <+5>:     movzwl %dx,%ecx
   0x0000000000000008 <+8>:     cmpb   $0x0,(%rsi,%rcx,1)


The foo() function is:
   0x0000000000000010 <+0>:     movzwl %si,%eax
   0x0000000000000013 <+3>:     movzwl %si,%esi
   0x0000000000000016 <+6>:     mov    %esi,(%rdi,%rax,4)
   0x0000000000000019 <+9>:     retq   


In both cases, an unnecessary movzwl instruction is generated. This may be the
same issue as #36873, which was rejected because the test cases used volatile
accesses. These test cases here show that the duplicate movzwl occurs without
volatile as well.


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-05-26 12:46 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-03-24 20:59 [Bug tree-optimization/60641] New: Converting ushort to offset on x86_64 generates double movzwl akruppa at gmail dot com
2014-03-25  9:25 ` [Bug target/60641] " rguenth at gcc dot gnu.org
2014-05-26 12:46 ` akruppa at gmail dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).