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



Jakub Jelinek <jakub at gcc dot gnu.org> changed:



           What    |Removed                     |Added

----------------------------------------------------------------------------

                 CC|                            |jakub at gcc dot gnu.org



--- Comment #7 from Jakub Jelinek <jakub at gcc dot gnu.org> 2012-12-07 
09:44:40 UTC ---

I've tried to rewrite this as C, but managed to turn it into something that is

miscompiled at a different spot.  The fortran testcase starts having

__builtin_unreachable () in it in the *.cunroll pass, this one already in

*.cunrolli pass.  Still, I believe it doesn't do any out of bounds access

anywhere.  -O2 on x86_64-linux.



double s[4] = { 1.0, 2.0, 3.0, 4.0 }, pol_x[2] = { 5.0, 6.0 };



__attribute__((noinline)) int

foo (void)

{

  double coef_x[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };

  int lxp = 0;

  if (lxp <= 1)

    do

      {

    double t = pol_x[lxp];

    long S;

    long l = lxp * 4L - 1;

    for (S = 1; S <= 4; S++)

      coef_x[S + l] = coef_x[S + l] + s[S - 1] * t;

      }

    while (lxp++ != 1);

  asm volatile ("" : : "r" (coef_x) : "memory");

  for (lxp = 0; lxp < 8; lxp++)

    if (coef_x[lxp] != ((lxp & 3) + 1) * (5.0 + (lxp >= 4)))

      __builtin_abort ();

  return 1;

}



int

main ()

{

  asm volatile ("" : : : "memory");

  if (!foo ())

    __builtin_abort ();

  return 0;

}



Works with r193067, fails with r193100, haven't tried to bisect exactly, but

would guess this is r193098 again.  For the outer loop it prints:



Analyzing # of iterations of loop 1

  exit condition [0, + , 1](no_overflow) != 1

  bounds on difference of bases: 1 ... 1

  result:

    # of iterations 1, bounded by 1

Loop 1 iterates 1 times.

Loop 1 iterates at most 1 times.



but that is wrong, the outer loop iterates exactly 2 times.



  <bb 3>:

  # lxp_1 = PHI <0(2), lxp_21(15)>

...

  <bb 6>:

  lxp_21 = lxp_1 + 1;

  if (lxp_1 != 1)

    goto <bb 15>;

  else

    goto <bb 7>;



  <bb 15>:

  goto <bb 3>;



If it used lxp_21 in the condition, that would be correct, but it uses the

previous value of the IV.

Reply via email to