Take the following program, it should run and work correct and not call abort 
but with -O1/-O2 on the 
mainline we call abort because LIM pulls out the call to f of the loop but 
should not because f1 can 
modify the global memory (and does).  If I uncomment the store to the global 
memory in the function 
containing the loop we get the correct code as LIM sees that the call to f has 
a VUSE and call to f1 has a 
V_MAY_DEF.

int f(void) __attribute__((pure));
int lll;
int f() { return lll; }
int f1() { lll++; return lll % 2;}
int g(void)
{
  int k, l;
  k=0;
//lll = 0;
  for(l =0;l<10;l++)
    if (f1 ())
     k = f();
  return k;
}
void abort ();

int main(void)
{
  if (g() != 9)
   abort ();
}

-- 
           Summary: [4.0 Regression] LIM is pulling out a pure function even
                    though there is something which can modify global memory
           Product: gcc
           Version: 4.0.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P2
         Component: tree-optimization
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: pinskia at gcc dot gnu dot org
                CC: dnovillo at gcc dot gnu dot org,drow at gcc dot gnu dot
                    org,gcc-bugs at gcc dot gnu dot org


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

Reply via email to