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

            Bug ID: 83768
           Summary: ARM: wrong optimization
           Product: gcc
           Version: 5.4.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: sorganov at gmail dot com
  Target Milestone: ---

GCC 5.4.0 optimizes the following code to empty function, when in fact the code
does clear 'count' bytes starting from 'buf' (it looks strange as it's a
simplified version of real code). Note that GCC 6.3.0 produces correct code for
the case.

$ cat clean.c
void clean(unsigned char* buf, int count)
{
  int linear = 0;
  do {
    count -= linear;
    while(linear--)
      *buf++ = 0;
    linear = count;
  } while(linear > 0);
}

Could you please tell if/when this has been already fixed in 5.4.x versions,
and is there any particular optimization I can turn off as a work-around for
GCC 5.4.0?

$ /opt/arm-linux-5.4/bin/arm-linux-gnueabi-gcc -v
Using built-in specs.
COLLECT_GCC=/opt/arm-linux-5.4/bin/arm-linux-gnueabi-gcc
COLLECT_LTO_WRAPPER=/opt/arm-linux-5.4/libexec/gcc/arm-linux-gnueabi/5.4.0/lto-wrapper
Target: arm-linux-gnueabi
Configured with: ../src/gcc-5.4.0/configure --prefix=/opt/arm-linux-5.4
--target=arm-linux-gnueabi --disable-multilib --disable-nls --enable-shared
--enable-threads --enable-tls --disable-decimal-float --disable-libmudflap
--disable-libquadmath --disable-libsanitizer --disable-libssp
--disable-multilib --with-float=hard --with-gnu-as --with-gnu-ld
--without-cloog --without-isl
--with-sysroot=/opt/arm-linux-5.4/arm-linux-gnueabi/sysroot
--enable-languages=c,c++ --enable-__cxa_atexit --enable-static --enable-shared
--enable-threads --enable-long-long --disable-lto --disable-libgomp
Thread model: posix
gcc version 5.4.0 (GCC) 
$ /opt/arm-linux-5.4/bin/arm-linux-gnueabi-gcc -O2 -c clean.c -o clean.o
-save-temps && cat clean.s
        .cpu arm10tdmi
        .eabi_attribute 28, 1
        .fpu vfp
        .eabi_attribute 20, 1
        .eabi_attribute 21, 1
        .eabi_attribute 23, 3
        .eabi_attribute 24, 1
        .eabi_attribute 25, 1
        .eabi_attribute 26, 2
        .eabi_attribute 30, 2
        .eabi_attribute 34, 0
        .eabi_attribute 18, 4
        .arm
        .syntax divided
        .file   "clean.c"
        .text
        .align  2
        .global clean
        .type   clean, %function
clean:
        @ args = 0, pretend = 0, frame = 0
        @ frame_needed = 0, uses_anonymous_args = 0
        @ link register save eliminated.
        bx      lr
        .size   clean, .-clean
        .ident  "GCC: (GNU) 5.4.0"
        .section        .note.GNU-stack,"",%progbits
$

Reply via email to