From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24199 invoked by alias); 11 Apr 2014 11:28:11 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 24146 invoked by uid 55); 11 Apr 2014 11:28:06 -0000 From: "rguenther at suse dot de" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/55022] [4.8/4.9 Regression] air.f90 is miscompliled with -m64 -O2 -fgraphite-identity after revision 190619 Date: Fri, 11 Apr 2014 11:28:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Version: 4.8.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: rguenther at suse dot de X-Bugzilla-Status: ASSIGNED X-Bugzilla-Priority: P4 X-Bugzilla-Assigned-To: rguenth at gcc dot gnu.org X-Bugzilla-Target-Milestone: 4.8.3 X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2014-04/txt/msg00810.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55022 --- Comment #20 from 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 --- > > 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; }