From patchwork Thu Jul 21 11:30:12 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 106034 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 553BFB7305 for ; Thu, 21 Jul 2011 21:30:51 +1000 (EST) Received: (qmail 26333 invoked by alias); 21 Jul 2011 11:30:47 -0000 Received: (qmail 26325 invoked by uid 22791); 21 Jul 2011 11:30:47 -0000 X-SWARE-Spam-Status: No, hits=-3.8 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD, TW_CF, TW_TM 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; Thu, 21 Jul 2011 11:30:14 +0000 Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.221.2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx2.suse.de (Postfix) with ESMTP id E3C338EE65 for ; Thu, 21 Jul 2011 13:30:12 +0200 (CEST) Date: Thu, 21 Jul 2011 13:30:12 +0200 (CEST) From: Richard Guenther To: gcc-patches@gcc.gnu.org Subject: [PATCH] Maintain single-use chains in forwprop better 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 is another place where we fail to properly keep single-use chains by leaving around dead code. This confuses propagation of comparisons which is restricted for non-single-uses. Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to trunk. Richard. 2011-07-21 Richard Guenther * tree-ssa-forwprop.c (combine_conversions): Return whether we have to run cfg-cleanup. Properly remove dead stmts. (ssa_forward_propagate_and_combine): Adjust. Index: gcc/tree-ssa-forwprop.c =================================================================== --- gcc/tree-ssa-forwprop.c.orig 2011-07-21 12:12:36.000000000 +0200 +++ gcc/tree-ssa-forwprop.c 2011-07-21 12:05:13.000000000 +0200 @@ -2136,9 +2136,10 @@ out: } /* Combine two conversions in a row for the second conversion at *GSI. - Returns true if there were any changes made. */ + Returns 1 if there were any changes made, 2 if cfg-cleanup needs to + run. Else it returns 0. */ -static bool +static int combine_conversions (gimple_stmt_iterator *gsi) { gimple stmt = gsi_stmt (*gsi); @@ -2155,15 +2156,15 @@ combine_conversions (gimple_stmt_iterato if (useless_type_conversion_p (TREE_TYPE (lhs), TREE_TYPE (op0))) { gimple_assign_set_rhs_code (stmt, TREE_CODE (op0)); - return true; + return 1; } if (TREE_CODE (op0) != SSA_NAME) - return false; + return 0; def_stmt = SSA_NAME_DEF_STMT (op0); if (!is_gimple_assign (def_stmt)) - return false; + return 0; if (CONVERT_EXPR_CODE_P (gimple_assign_rhs_code (def_stmt))) { @@ -2202,7 +2203,7 @@ combine_conversions (gimple_stmt_iterato gimple_assign_set_rhs1 (stmt, unshare_expr (defop0)); gimple_assign_set_rhs_code (stmt, TREE_CODE (defop0)); update_stmt (stmt); - return true; + return remove_prop_source_from_use (op0) ? 2 : 1; } /* Likewise, if the intermediate and initial types are either both @@ -2224,7 +2225,7 @@ combine_conversions (gimple_stmt_iterato { gimple_assign_set_rhs1 (stmt, defop0); update_stmt (stmt); - return true; + return remove_prop_source_from_use (op0) ? 2 : 1; } /* If we have a sign-extension of a zero-extended value, we can @@ -2235,7 +2236,7 @@ combine_conversions (gimple_stmt_iterato { gimple_assign_set_rhs1 (stmt, defop0); update_stmt (stmt); - return true; + return remove_prop_source_from_use (op0) ? 2 : 1; } /* Two conversions in a row are not needed unless: @@ -2264,7 +2265,7 @@ combine_conversions (gimple_stmt_iterato { gimple_assign_set_rhs1 (stmt, defop0); update_stmt (stmt); - return true; + return remove_prop_source_from_use (op0) ? 2 : 1; } /* A truncation to an unsigned type should be canonicalized as @@ -2288,11 +2289,11 @@ combine_conversions (gimple_stmt_iterato else gimple_assign_set_rhs_from_tree (gsi, tem); update_stmt (gsi_stmt (*gsi)); - return true; + return 1; } } - return false; + return 0; } /* Main entry point for the forward propagation and statement combine @@ -2454,7 +2455,12 @@ ssa_forward_propagate_and_combine (void) else if (CONVERT_EXPR_CODE_P (code) || code == FLOAT_EXPR || code == FIX_TRUNC_EXPR) - changed = combine_conversions (&gsi); + { + int did_something = combine_conversions (&gsi); + if (did_something == 2) + cfg_changed = true; + changed = did_something != 0; + } break; }