From patchwork Tue Aug 10 09:12:27 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 61348 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 4DE19B70D1 for ; Tue, 10 Aug 2010 19:12:38 +1000 (EST) Received: (qmail 22467 invoked by alias); 10 Aug 2010 09:12:36 -0000 Received: (qmail 22455 invoked by uid 22791); 10 Aug 2010 09:12:35 -0000 X-SWARE-Spam-Status: No, hits=-3.4 required=5.0 tests=AWL, BAYES_00, 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; Tue, 10 Aug 2010 09:12:29 +0000 Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.221.2]) by mx2.suse.de (Postfix) with ESMTP id 6DFFC87567 for ; Tue, 10 Aug 2010 11:12:27 +0200 (CEST) Date: Tue, 10 Aug 2010 11:12:27 +0200 (CEST) From: Richard Guenther To: gcc-patches@gcc.gnu.org Subject: [PATCH] Copy-propagate constants 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 teaches copyprop to also propagate copies of constants. Bootstrapped and tested on x86_64-unknown-linux-gnu, committed. Richard. 2010-08-10 Richard Guenther * tree-ssa-copy.c (set_copy_of_val): Use operand_equal_p. (copy_prop_visit_assignment): Simplify. (copy_prop_visit_stmt): Also visit assignments from constants. (copy_prop_visit_phi_node): Use operand_equal_p. Index: gcc/tree-ssa-copy.c =================================================================== --- gcc/tree-ssa-copy.c (revision 163032) +++ gcc/tree-ssa-copy.c (working copy) @@ -366,7 +366,8 @@ set_copy_of_val (tree var, tree val) old = copy_of[ver].value; copy_of[ver].value = val; - if (old != val) + if (old != val + || (val && !operand_equal_p (old, val, 0))) return true; return false; @@ -409,14 +410,9 @@ static enum ssa_prop_result copy_prop_visit_assignment (gimple stmt, tree *result_p) { tree lhs, rhs; - prop_value_t *rhs_val; lhs = gimple_assign_lhs (stmt); - rhs = gimple_assign_rhs1 (stmt); - - gcc_assert (gimple_assign_rhs_code (stmt) == SSA_NAME); - - rhs_val = get_copy_of_val (rhs); + rhs = valueize_val (gimple_assign_rhs1 (stmt)); if (TREE_CODE (lhs) == SSA_NAME) { @@ -425,14 +421,8 @@ copy_prop_visit_assignment (gimple stmt, if (!may_propagate_copy (lhs, rhs)) return SSA_PROP_VARYING; - /* Notice that in the case of assignments, we make the LHS be a - copy of RHS's value, not of RHS itself. This avoids keeping - unnecessary copy-of chains (assignments cannot be in a cycle - like PHI nodes), speeding up the propagation process. - This is different from what we do in copy_prop_visit_phi_node. - In those cases, we are interested in the copy-of chains. */ *result_p = lhs; - if (set_copy_of_val (*result_p, rhs_val->value)) + if (set_copy_of_val (*result_p, rhs)) return SSA_PROP_INTERESTING; else return SSA_PROP_NOT_INTERESTING; @@ -518,7 +508,8 @@ copy_prop_visit_stmt (gimple stmt, edge if (gimple_assign_single_p (stmt) && TREE_CODE (gimple_assign_lhs (stmt)) == SSA_NAME - && TREE_CODE (gimple_assign_rhs1 (stmt)) == SSA_NAME) + && (TREE_CODE (gimple_assign_rhs1 (stmt)) == SSA_NAME + || is_gimple_min_invariant (gimple_assign_rhs1 (stmt)))) { /* If the statement is a copy assignment, evaluate its RHS to see if the lattice value of its output has changed. */ @@ -631,7 +622,8 @@ copy_prop_visit_phi_node (gimple phi) /* If PHI_VAL and ARG don't have a common copy-of chain, then this PHI node cannot be a copy operation. */ - if (phi_val.value != arg_val->value) + if (phi_val.value != arg_val->value + && !operand_equal_p (phi_val.value, arg_val->value, 0)) { phi_val.value = lhs; break;