This is a small extract from a benchmark. It shows that -O1 -ftree-loop-linear 
generates a couple
of empty loops, and incorrect behavior. 

/* main.c */
#include <stdio.h>

extern void init();

double mid_wts[8][35];
double  in_pats[1][35];

double  do_mid_forward(int patt)
{
double  sum;
int     neurode, i;

for (neurode=0;neurode<8; neurode++)
{
        sum = 0.0;
        for (i=0; i<35; i++)
        { 
                sum += mid_wts[neurode][i]*in_pats[patt][i];
        }
        sum = 1.0/(1.0+sum);
}
return sum;
}


double value;

main()
{
  init();
  printf(" %e\n", do_mid_forward (0));
}

/* init.c */
extern double mid_wts[8][35];
extern double  in_pats[1][35];

double value;

void init()
{
int i;
int neurode;

value=(double)1.0 - (double) 0.5;

for (neurode = 0; neurode<8; neurode++)
   for (i=0; i<35; i++)
      mid_wts[neurode][i] = value;

for (i=0; i<35; i++)
   in_pats[0][i] = 1.234;
}

% cc -c -O0 init.c
% cc -O1 -ftree-loop-linear main.c init.o
% ./a.out
 -2.384238e+11

Assembly file for ppc-darwin shows a couple of do-nothing empty loops. 
Remove -ftree-loop-linear and program behaves correctly.

-- 
           Summary: -ftree-loop-linear  doesn't work right in small loop
           Product: gcc
           Version: 4.0.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: tree-optimization
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: fjahanian at apple dot com
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: powerpc-apple-darwin
  GCC host triplet: powerpc-apple-darwin
GCC target triplet: powerpc-apple-darwin


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

Reply via email to