This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug tree-optimization/42154] New: [4.5 Regression] Wrong code from (early) SRA


struct A { char x[1]; };
extern void abort (void);
void __attribute__((noinline,noclone))
foo (struct A a)
{
  if (a.x[0] != 'a')
    abort ();
}
int main ()
{
  struct A a;
  int i;
  for (i = 0; i < 1; ++i)
    a.x[i] = 'a';
  foo (a);
  return 0;
}

fails at -O1 because (early) SRA converts

<bb 2>:
  i_2 = 0;
  goto <bb 4>;

<bb 3>:
  a.x[i_1] = 97;
  i_3 = i_1 + 1;

<bb 4>:
  # i_1 = PHI <0(2), i_3(3)>
  if (i_1 <= 0)
    goto <bb 3>;
  else
    goto <bb 5>;

<bb 5>:
  foo (a);

to

<bb 2>:
  i_2 = 0;
  goto <bb 4>;

<bb 3>:
  a$x$_9 = 97;
  i_3 = i_1 + 1;

<bb 4>:
  # i_1 = PHI <0(2), i_3(3)>
  # a$x$_7 = PHI <a$x$_4(D)(2), a$x$_9(3)>
  if (i_1 <= 0)
    goto <bb 3>;
  else
    goto <bb 5>;

<bb 5>:
  a.x[i_1] = a$x$_7;
  foo (a);


see how the store to a.x[i_1] is wrong as i_1 does no longer have the same
value as before (SRA invalidly moved it out of the loop).  SRA should have
replaced i_1 with zero as it reasoned there is only one element and only
because of that it SRAd this.


-- 
           Summary: [4.5 Regression] Wrong code from (early) SRA
           Product: gcc
           Version: 4.5.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: tree-optimization
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: rguenth at gcc dot gnu dot org


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]