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

* [Bug target/60641] Converting ushort to offset on x86_64 generates double movzwl
  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 ` rguenth at gcc dot gnu.org
  2014-05-26 12:46 ` akruppa at gmail dot com
  1 sibling, 0 replies; 3+ messages in thread
From: rguenth at gcc dot gnu.org @ 2014-03-25  9:25 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Target|                            |x86_64-*-*, i?86-*-*
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2014-03-25
          Component|tree-optimization           |target
     Ever confirmed|0                           |1

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
Confirmed on trunk and 4.8.


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

* [Bug target/60641] Converting ushort to offset on x86_64 generates double movzwl
  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
  1 sibling, 0 replies; 3+ messages in thread
From: akruppa at gmail dot com @ 2014-05-26 12:46 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Alex Kruppa <akruppa at gmail dot com> ---
With gcc-4.9.0, compiled from the official tarball, the foo() function does NOT
produce the double movzwl instruction any more, but the bar() function still
does.

Dump of assembler code for function foo:
   0x0000000000000000 <+0>:    movzwl (%rdi),%edx
   0x0000000000000003 <+3>:    cmpb   $0x0,(%rsi,%rdx,1)
   0x0000000000000007 <+7>:    mov    %rdx,%rax
   0x000000000000000a <+10>:    mov    $0x0,%edx
   0x000000000000000f <+15>:    cmove  %edx,%eax
   0x0000000000000012 <+18>:    retq   

Dump of assembler code for function bar:
   0x0000000000000020 <+0>:    movzwl %si,%eax
   0x0000000000000023 <+3>:    movzwl %si,%esi
   0x0000000000000026 <+6>:    mov    %esi,(%rdi,%rax,4)
   0x0000000000000029 <+9>:    retq


^ 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).