From patchwork Wed Jun 27 11:25:42 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 167625 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 6CD7EB7015 for ; Wed, 27 Jun 2012 21:26:00 +1000 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1341401161; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Date: From:To:Subject:Message-ID:User-Agent:MIME-Version:Content-Type: Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:Sender:Delivered-To; bh=JMS9goRcyJGli3VqNTKo ODgfjLs=; b=kVinF+c6dgI5kw6QgwmIygHlbZH64oRqZaWiG21/jU2Rw+xnS+6C DI/FRrKqMVmlhv7jrvQI/HkHHr36XhuWERIGKbiSUEii6gCClxjcQXzIPPurXA5z BjCGRCYzoDz0A4UetK2ZR2K7a1Ey+U9qj/laLzHgYIFBBOfOFO6dA1c= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Date:From:To:Subject:Message-ID:User-Agent:MIME-Version:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=bWKGYj7oiJaoRp1lsbY5z81FaKNdsX/LQKE1RT5vfxOnwQbhYh2vYtSL0sp5mV MTwVqtxsvpPvlFo9TEzsj1hsM9moYasWTPi8XqgdqoCLV/06EzDewMadVT9EzIzw p8sbcxE+806yE00OizPnWtb4b52lkiqT18opwsH0LSW30=; Received: (qmail 28810 invoked by alias); 27 Jun 2012 11:25:57 -0000 Received: (qmail 28775 invoked by uid 22791); 27 Jun 2012 11:25:56 -0000 X-SWARE-Spam-Status: No, hits=-5.4 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, RCVD_IN_DNSWL_HI, RCVD_IN_HOSTKARMA_W, TW_TM, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from cantor2.suse.de (HELO mx2.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 27 Jun 2012 11:25:43 +0000 Received: from relay1.suse.de (unknown [195.135.220.254]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx2.suse.de (Postfix) with ESMTP id 3EBBDA4597 for ; Wed, 27 Jun 2012 13:25:42 +0200 (CEST) Date: Wed, 27 Jun 2012 13:25:42 +0200 (CEST) From: Richard Guenther To: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix PR53774 Message-ID: User-Agent: Alpine 2.00 (LNX 1167 2008-08-23) MIME-Version: 1.0 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org This fixes PR53774, a case where reassoc produced non-canonical statements like a = 4 + b. The reason it did so was that it assigned a rank of zero to things that are not constant. Fixed by pre-computing a rank for all SSA default defs. Bootstrapped and tested on x86_64-unknown-linux-gnu, applied. Richard. 2012-06-27 Richard Guenther PR tree-optimization/53774 * tree-ssa-reassoc.c (get_rank): All default defs have precomputed rank. (init_reassoc): Precompute rank for all SSA default defs. Index: gcc/tree-ssa-reassoc.c =================================================================== --- gcc/tree-ssa-reassoc.c (revision 188987) +++ gcc/tree-ssa-reassoc.c (working copy) @@ -383,14 +383,10 @@ get_rank (tree e) int i, n; tree op; - if (TREE_CODE (SSA_NAME_VAR (e)) == PARM_DECL - && SSA_NAME_IS_DEFAULT_DEF (e)) + if (SSA_NAME_IS_DEFAULT_DEF (e)) return find_operand_rank (e); stmt = SSA_NAME_DEF_STMT (e); - if (gimple_bb (stmt) == NULL) - return 0; - if (gimple_code (stmt) == GIMPLE_PHI) return phi_rank (stmt); @@ -484,7 +480,7 @@ sort_by_operand_rank (const void *pa, co /* It's nicer for optimize_expression if constants that are likely to fold when added/multiplied//whatever are put next to each other. Since all constants have rank 0, order them by type. */ - if (oeb->rank == 0 && oea->rank == 0) + if (oeb->rank == 0 && oea->rank == 0) { if (constant_type (oeb->op) != constant_type (oea->op)) return constant_type (oeb->op) - constant_type (oea->op); @@ -3441,7 +3437,7 @@ transform_stmt_to_multiply (gimple_stmt_ print_gimple_stmt (dump_file, stmt, 0, 0); } - gimple_assign_set_rhs_with_ops_1 (gsi, MULT_EXPR, rhs1, rhs2, NULL_TREE); + gimple_assign_set_rhs_with_ops (gsi, MULT_EXPR, rhs1, rhs2); update_stmt (gsi_stmt (*gsi)); remove_visited_stmt_chain (rhs1); @@ -3647,7 +3643,6 @@ init_reassoc (void) { int i; long rank = 2; - tree param; int *bbs = XNEWVEC (int, last_basic_block + 1); /* Find the loops, so that we can prevent moving calculations in @@ -3666,24 +3661,15 @@ init_reassoc (void) bb_rank = XCNEWVEC (long, last_basic_block + 1); operand_rank = pointer_map_create (); - /* Give each argument a distinct rank. */ - for (param = DECL_ARGUMENTS (current_function_decl); - param; - param = DECL_CHAIN (param)) - { - if (gimple_default_def (cfun, param) != NULL) - { - tree def = gimple_default_def (cfun, param); - insert_operand_rank (def, ++rank); - } - } - - /* Give the chain decl a distinct rank. */ - if (cfun->static_chain_decl != NULL) - { - tree def = gimple_default_def (cfun, cfun->static_chain_decl); - if (def != NULL) - insert_operand_rank (def, ++rank); + /* Give each default definition a distinct rank. This includes + parameters and the static chain. Walk backwards over all + SSA names so that we get proper rank ordering according + to tree_swap_operands_p. */ + for (i = num_ssa_names - 1; i > 0; --i) + { + tree name = ssa_name (i); + if (name && SSA_NAME_IS_DEFAULT_DEF (name)) + insert_operand_rank (name, ++rank); } /* Set up rank for each BB */