Consider the following testcase - a variant from
http://gcc.gnu.org/ml/gcc-help/2006-07/msg00177.html :

=========================================================
#include <stdio.h>

volatile char s[256][3];

int main()
{
    int i, j=0;

    for (i = 0; i < 256; i++)
        if (i >= 128 && i < 256)
            { printf("%d ", s[i - 128][0]); ++j; }
    printf("\nj = %d\n", j);
    return 0;
}
=========================================================

This program should generate the following output
(wrapped to 80 characters per line):

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 
j = 128

With -Os I get the output

-125 4 -21 -8 -16 93 -119 -24 0 -127 17 80 -2 89 -61 3 0 2 100 10 61 100 0 0 0
0
 -107 0 0 0 0 12 0 4 0 -108 8 0 -127 5 0 4 0 112 8 0 0 11 0 0 0 -28 64 0 -107 2 
0 0 0 17 0 0 -126 17 0 4 0 8 0 0 0 -2 111 4 -1 1 0 -1 -126 0 0 0 0 0 0 0 0 0 0
0
 0 0 0 0 0 -1 -1 0 -1 0 0 0 -108 -8 64 0 -52 -80 64 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 
j = 255

Parts of the if-condition ionside the loop have been optimized out.
Happens only on the 4.1 branch.


-- 
           Summary: [4.1 regression] Wrong code with if condition in loop
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Keywords: wrong-code, monitored
          Severity: blocker
          Priority: P3
         Component: tree-optimization
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: reichelt at gcc dot gnu dot org
 GCC build triplet: i686-pc-linux-gnu
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu


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

Reply via email to