If the following code is compiled with -Os for ARM or ColdFire, the exit
condition for the loop is removed.
Replacing *tbl++ with tbl[i] or using unsigned long instead of volatile
unsigned long does not show the problem.
I suspect the post-increment optimization to be the problem, because the
PowerPC version does not show the problem.
Also: Using a different start-address for tbl, does not show the problem.

The problem has been reported also for 4.4.0.

typedef volatile unsigned long __vu32;
void bs()
{
    int i;
    __vu32 *tbl = (__vu32 *)0xffffff00;
    for(i = 0; i < 64; ++i){
//->      tbl[i] = (__vu32)10;
      *tbl++ = (__vu32)10;
    }
}
Cmd-line: arm-none-eabi-gcc -S -Os t.c
Output: 
        .cpu arm7tdmi
        .fpu softvfp
        .eabi_attribute 20, 1
        .eabi_attribute 21, 1
        .eabi_attribute 23, 3
        .eabi_attribute 24, 1
        .eabi_attribute 25, 1
        .eabi_attribute 26, 1
        .eabi_attribute 30, 4
        .eabi_attribute 18, 4
        .file   "t.c"
        .text
        .align  2
        .global bs
        .type   bs, %function
bs:
        @ Function supports interworking.
        @ args = 0, pretend = 0, frame = 0
        @ frame_needed = 0, uses_anonymous_args = 0
        @ link register save eliminated.
        mvn     r2, #255
.L2:
        mov     r3, #10
        str     r3, [r2], #4
        b       .L2
        .size   bs, .-bs
        .ident  "GCC: (Sourcery G++ Lite 2008q3-39) 4.3.2"


-- 
           Summary: Optimizer handles loops with volatiles and post-incr.
                    wrong
           Product: gcc
           Version: 4.3.2
            Status: UNCONFIRMED
          Severity: major
          Priority: P3
         Component: rtl-optimization
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: bastian dot schick at sciopta dot com
 GCC build triplet: i686-pc-linux-gnu
  GCC host triplet: i686-mingw32
GCC target triplet: i686-mingw32


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

Reply via email to