From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 16694 invoked by alias); 26 Jun 2012 14:24:29 -0000 Received: (qmail 16681 invoked by uid 22791); 26 Jun 2012 14:24:27 -0000 X-SWARE-Spam-Status: No, hits=-4.3 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00,KHOP_THREADED,TW_TM X-Spam-Check-By: sourceware.org Received: from localhost (HELO gcc.gnu.org) (127.0.0.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 26 Jun 2012 14:24:15 +0000 From: "rguenth at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/53774] Reassociator generates non-canonical addition Date: Tue, 26 Jun 2012 14:24: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-Keywords: missed-optimization X-Bugzilla-Severity: normal X-Bugzilla-Who: rguenth at gcc dot gnu.org X-Bugzilla-Status: ASSIGNED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: rguenth at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Keywords Status AssignedTo Message-ID: In-Reply-To: References: 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: 2012-06/txt/msg01732.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53774 Richard Guenther changed: What |Removed |Added ---------------------------------------------------------------------------- Keywords| |missed-optimization Status|NEW |ASSIGNED AssignedTo|unassigned at gcc dot |rguenth at gcc dot gnu.org |gnu.org | --- Comment #2 from Richard Guenther 2012-06-26 14:24:13 UTC --- I am testing instead @@ -2299,8 +2299,16 @@ rewrite_expr_tree (gimple stmt, unsigned print_gimple_stmt (dump_file, stmt, 0, 0); } - gimple_assign_set_rhs1 (stmt, oe1->op); - gimple_assign_set_rhs2 (stmt, oe2->op); + if (tree_swap_operands_p (oe1->op, oe2->op, true)) + { + gimple_assign_set_rhs1 (stmt, oe2->op); + gimple_assign_set_rhs2 (stmt, oe1->op); + } + else + { + gimple_assign_set_rhs1 (stmt, oe1->op); + gimple_assign_set_rhs2 (stmt, oe2->op); + } update_stmt (stmt); if (rhs1 != oe1->op && rhs1 != oe2->op) remove_visited_stmt_chain (rhs1); which fixes it. OTOH there are many other places reassoc adjusts stmt operands (but it eventually relies on operand order). Adding a canonicalize_operand_order_and_update_stmt () wherever we call update_stmt afer adjusting operands might be better ... or simply calling fold_stmt on all stmts we touch which does the re-ordering, too. Well, I'm not really sure where we should enforce canonical ordering ...