From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27178 invoked by alias); 10 Jun 2011 11:37:34 -0000 Received: (qmail 27169 invoked by uid 22791); 10 Jun 2011 11:37:33 -0000 X-SWARE-Spam-Status: No, hits=-3.3 required=5.0 tests=AWL,BAYES_00,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; Fri, 10 Jun 2011 11:37:19 +0000 Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.221.2]) by mx2.suse.de (Postfix) with ESMTP id 726F08726A for ; Fri, 10 Jun 2011 13:37:18 +0200 (CEST) Date: Fri, 10 Jun 2011 11:41:00 -0000 From: Richard Guenther To: gcc-patches@gcc.gnu.org Subject: [PATCH] Back to forward-scan for combine in forwprop Message-ID: User-Agent: Alpine 2.00 (LNX 1167 2008-08-23) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org X-SW-Source: 2011-06/txt/msg00827.txt.bz2 Dunno why I thought a backward scan was preferable (it would scan inserted stmts), but it clearly is better to first visit the defs of the uses of stmts we are trying to combine. The following patch uses some trick to make sure stmts inserted by the combining are processed as well. Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to trunk. Richard. 2011-06-10 Richard Guenther * tree-ssa-forwprop.c (ssa_forward_propagate_and_combine): Scan stmts forward when combining, visit inserted stmts when a stmt was changed. Index: gcc/tree-ssa-forwprop.c =================================================================== --- gcc/tree-ssa-forwprop.c (revision 174841) +++ gcc/tree-ssa-forwprop.c (working copy) @@ -2212,7 +2212,8 @@ ssa_forward_propagate_and_combine (void) FOR_EACH_BB (bb) { - gimple_stmt_iterator gsi; + gimple_stmt_iterator gsi, prev; + bool prev_initialized; /* Apply forward propagation to all stmts in the basic-block. Note we update GSI within the loop as necessary. */ @@ -2304,7 +2305,8 @@ ssa_forward_propagate_and_combine (void) /* Combine stmts with the stmts defining their operands. Note we update GSI within the loop as necessary. */ - for (gsi = gsi_last_bb (bb); !gsi_end_p (gsi);) + prev_initialized = false; + for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi);) { gimple stmt = gsi_stmt (gsi); bool changed = false; @@ -2386,9 +2388,24 @@ ssa_forward_propagate_and_combine (void) default:; } - /* If the stmt changed try combining it again. */ - if (!changed) - gsi_prev (&gsi); + if (changed) + { + /* If the stmt changed then re-visit it and the statements + inserted before it. */ + if (!prev_initialized) + gsi = gsi_start_bb (bb); + else + { + gsi = prev; + gsi_next (&gsi); + } + } + else + { + prev = gsi; + prev_initialized = true; + gsi_next (&gsi); + } } }