From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4666 invoked by alias); 4 Jan 2013 12:09:02 -0000 Received: (qmail 4545 invoked by uid 48); 4 Jan 2013 12:08:36 -0000 From: "jakub at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/55875] New: [4.8 Regression] IVopts caused miscompilation Date: Fri, 04 Jan 2013 12:09:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: jakub at gcc dot gnu.org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 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 X-SW-Source: 2013-01/txt/msg00301.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55875 Bug #: 55875 Summary: [4.8 Regression] IVopts caused miscompilation Classification: Unclassified Product: gcc Version: 4.8.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization AssignedTo: unassigned@gcc.gnu.org ReportedBy: jakub@gcc.gnu.org The following testcase is miscompiled at -O3 on x86_64-linux starting with http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=192989 (ok, that revision doesn't compile, needs r192900 follow-up). struct A { short int a1; unsigned char a2; unsigned int a3; }; struct B { unsigned short b1; const A *b2; }; B b; __attribute__((noinline, noclone)) int foo (unsigned x) { __asm volatile ("" : "+r" (x) : : "memory"); return x; } inline void bar (const int &) { } __attribute__((noinline)) void baz () { const A *a = b.b2; unsigned int i; unsigned short n = b.b1; for (i = 0; i < n; ++i) if (a[i].a1 == 11) { if (i > 0 && (a[i - 1].a2 & 1)) continue; bar (foo (2)); return; } } int main () { A a[4] = { { 10, 0, 0 }, { 11, 1, 0 }, { 11, 1, 0 }, { 11, 1, 0 } }; b.b1 = 4; b.b2 = a; baz (); return 0; } In *.slp we have: : if (i_21 != 0) goto ; else goto ; : _11 = i_21 + 4294967295; _12 = (long unsigned int) _11; _13 = _12 * 8; _14 = a_4 + _13; _15 = _14->a2; but ivopts turns that into: : i_25 = (unsigned int) ivtmp.9_31; if (i_25 != 0) goto ; else goto ; : _28 = ivtmp.9_31 * 8; _27 = a_4 + _28; _26 = _27 + 34359738362; _15 = MEM[base: _26, offset: 0B]; which is wrong, i_21 + -1U wrapped around (and wasn't executed for i_21 being 0), while 34359738362 is 0xffffffffULL * 8 + 2, thus it ignores the wrapping and does what the original code would do for _12 = (long unsigned int) i_21; _77 = _12 + 4294967295; _13 = _77 * 8; i.e. as if the -1U addition was done in the wider precision.