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

kargov at gmail dot com gcc-bugzilla@gcc.gnu.org
Fri Apr 11 11:10:00 GMT 2014


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.



More information about the Gcc-bugs mailing list