[Bug tree-optimization/55022] [4.8/4.9 Regression] air.f90 is miscompliled with -m64 -O2 -fgraphite-identity after revision 190619

rguenther at suse dot de gcc-bugzilla@gcc.gnu.org
Fri Apr 11 11:28:00 GMT 2014


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

--- Comment #20 from rguenther at suse dot de <rguenther at suse dot de> ---
On Fri, 11 Apr 2014, kargov at gmail dot com wrote:

> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55022
> 
> --- Comment #19 from Vladimir Kargov <kargov at gmail dot com> ---
> > if you are refering to negate_expr () negating a /[fl] CST as a /[fl] -CST
> then yes, that looks suspicious
> Yes, the one.
> 
> The function converts expressions "x * -C" into "-x * C". In the case where x
> is an expression of form "a /[fl] b" or "a /[cl] b" this optimization is
> generally invalid. For example:
> (1 /[fl] 2) * -1 = 0 * -1 = 0 will turn into (1 /[fl] -2) * 1 = -1 * 1 = -1
> (1 /[cl] 2) * -1 = 1 * -1 = -1 will turn into (1 /[cl] -2) * 1 = 0 * 1 = 0
> In general, it appears that the optimization will be incorrect for any floor
> and ceiling divisions with a non-zero remainder since after negation they will
> be rounded to a different integer.
> 
> The problem can be seen in the following function when compiled with "-O3
> -fgraphite-identity":
> 
> void f(int *limit, int minLen, int maxLen)
> {
>   int i;
> 
>   for (i = minLen; i <= maxLen; i++) {
>     limit[i] = i;
>   }
> }
> 
> In this case constant folding will be transforming expression "(((signed long)
> maxLen_5(D) - (signed long) minLen_3(D)) /[fl] 4294967296) * -1" (i.e. 0) into
> "((signed long) maxLen_5(D) - (signed long) minLen_3(D)) /[fl] -4294967296"
> (i.e. -4294967296).
> 
> Since Graphite abundantly uses floor division, this breaks a lot of code,
> including bzip2 build
> (https://groups.google.com/forum/#!topic/gcc-graphite/WaCUu0xg4Kc) and this
> bug.
> 
> Removing floor and ceiling division as in comment 18 will fix it.

I can't seem to observe the above with the testcase or sth like
the following suitable for the testsuite:

/* { dg-do run } */
/* { dg-options "-O3 -fgraphite-identity" } */

extern void abort (void);

void __attribute__((noinline,noclone))
f(int *limit, int minLen, int maxLen)
{
  int i;

  for (i = minLen; i <= maxLen; i++) {
      limit[i] = i;
  }
}

int main()
{
  int limit[256], i;
  f (limit, 0, 255);
  for (i = 0; i < 256; ++i)
    {
      if (limit[i] != i)
        abort ();
      __asm__ volatile ("" : : : "memory");
    }
  return 0;
}



More information about the Gcc-bugs mailing list