in the following code, the compiler zero-extends the same byte twice... there's
something about using byte0 in an if () statement which triggers this -- if you
comment out the if() the problem goes away.

-dean

% cat redundant_movzbl.c
unsigned foo(unsigned char *p)
{
  unsigned byte0 = *p;
  unsigned len = __builtin_ctz(byte0) + 1;
  if (byte0 == 0) return 0;
  return len;
}
% ~/gcc/bin/gcc -g -O3 -Wall -c redundant_movzbl.c
% objdump -dr redundant_movzbl.o

redundant_movzbl.o:     file format elf64-x86-64

Disassembly of section .text:

0000000000000000 <foo>:
   0:   0f b6 07                movzbl (%rdi),%eax
   3:   31 d2                   xor    %edx,%edx
   5:   84 c0                   test   %al,%al
   7:   74 09                   je     12 <foo+0x12>
   9:   0f b6 c0                movzbl %al,%eax
   c:   0f bc c0                bsf    %eax,%eax
   f:   8d 50 01                lea    0x1(%rax),%edx
  12:   89 d0                   mov    %edx,%eax
  14:   c3                      retq

% ~/gcc/bin/gcc -v
Using built-in specs.
Target: x86_64-unknown-linux-gnu
Configured with: ../gcc/configure --prefix=/home/odo/gcc --enable-languages=c
--enable-targets=x86_64-unknown-linux-gnu x86_64-unknown-linux-gnu :
(reconfigured) ../gcc/configure --prefix=/home/odo/gcc --enable-languages=c
--without-mudflap --disable-biarch x86_64-unknown-linux-gnu : (reconfigured)
../gcc/configure --prefix=/home/odo/gcc --enable-languages=c --disable-multilib
--disable-biarch x86_64-unknown-linux-gnu
Thread model: posix
gcc version 4.3.0 20061104 (experimental)


-- 
           Summary: redundant movzbl
           Product: gcc
           Version: 4.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: dean at arctic dot org
 GCC build triplet: x86_64-unknown-linux-gnu
  GCC host triplet: x86_64-unknown-linux-gnu
GCC target triplet: x86_64-unknown-linux-gnu


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

Reply via email to