From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 28824 invoked by alias); 21 May 2013 07:57:24 -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 28744 invoked by uid 55); 21 May 2013 07:57:12 -0000 From: "rguenther at suse dot de" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/57303] [4.7/4.8/4.9 Regression] struct miscompiled at -O1 and above Date: Tue, 21 May 2013 07:57: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.9.0 X-Bugzilla-Keywords: wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: rguenther at suse dot de X-Bugzilla-Status: ASSIGNED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: rguenth at gcc dot gnu.org X-Bugzilla-Target-Milestone: 4.7.4 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: 2013-05/txt/msg01390.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57303 --- Comment #7 from rguenther at suse dot de --- On Mon, 20 May 2013, glisse at gcc dot gnu.org wrote: > http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57303 > > --- Comment #6 from Marc Glisse --- > I wonder if, in addition to fixing the sink pass, we should add an optimization > like the following (it passes bootstrap+testsuite, but I am not so sure where > it should go and what it should look like exactly). > > --- gimple-fold.c (revision 199093) > +++ gimple-fold.c (working copy) > @@ -1174,20 +1174,27 @@ fold_stmt_1 (gimple_stmt_iterator *gsi, > if ((commutative_tree_code (subcode) > || commutative_ternary_tree_code (subcode)) > && tree_swap_operands_p (gimple_assign_rhs1 (stmt), > gimple_assign_rhs2 (stmt), false)) > { > tree tem = gimple_assign_rhs1 (stmt); > gimple_assign_set_rhs1 (stmt, gimple_assign_rhs2 (stmt)); > gimple_assign_set_rhs2 (stmt, tem); > changed = true; > } > + /* Remove *p = *p. */ > + if (!inplace && TREE_CODE_CLASS (subcode) == tcc_reference > + && operand_equal_p (lhs, gimple_assign_rhs1 (stmt), 0)) > + { > + gsi_remove (gsi, true); > + return true; > + } The obvious place would be dead store elimination. But beware that the above, if not _literally_ being *p = *p can be changing the effective type of the memory location and thus might be not dead in terms of type-based aliasing rules (which basically means that we need to do sth more clever than just removing the store).