From patchwork Thu Mar 31 13:29:32 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bernd Schmidt X-Patchwork-Id: 89076 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 80363B6F7C for ; Fri, 1 Apr 2011 00:32:20 +1100 (EST) Received: (qmail 12726 invoked by alias); 31 Mar 2011 13:32:16 -0000 Received: (qmail 12713 invoked by uid 22791); 31 Mar 2011 13:32:15 -0000 X-SWARE-Spam-Status: No, hits=-1.7 required=5.0 tests=AWL, BAYES_00, TW_EG, TW_GC, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mail.codesourcery.com (HELO mail.codesourcery.com) (38.113.113.100) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 31 Mar 2011 13:32:10 +0000 Received: (qmail 9288 invoked from network); 31 Mar 2011 13:32:09 -0000 Received: from unknown (HELO ?84.152.157.219?) (bernds@127.0.0.2) by mail.codesourcery.com with ESMTPA; 31 Mar 2011 13:32:09 -0000 Message-ID: <4D9481BC.8030809@codesourcery.com> Date: Thu, 31 Mar 2011 15:29:32 +0200 From: Bernd Schmidt User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.15) Gecko/20110325 Lightning/1.0b3pre Thunderbird/3.1.9 MIME-Version: 1.0 To: Jeff Law CC: GCC Patches Subject: Re: [PATCH 5/6] Generate more shrink-wrapping opportunities References: <4D8A0703.9090306@codesourcery.com> <4D8A09E5.7070105@codesourcery.com> <4D948039.5020505@redhat.com> In-Reply-To: <4D948039.5020505@redhat.com> 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 On 03/31/2011 03:23 PM, Jeff Law wrote: > On 03/23/11 08:55, Bernd Schmidt wrote: >> The first basic block contains insns to move incoming argument registers >> to pseudos. When these pseudos live across calls, they get allocated to >> call-saved registers. This in turns disables shrink-wrapping, since the >> move instruction requires the prologue (saving the call-saved reg) to >> occur before it. > >> This patch addresses the problem by moving such moves downwards through >> the CFG until we find a place where the destination is used or the >> incoming argument is clobbered. > OK. Thanks for the reviews. This patch is still blocked by the issues raised by rth in 3/6 (and of course the full shrink-wrapping patch 4/6); I hope to have at least draft patches for the dwarf2out problems by the end of the week. We've also discovered a problem with this particular patch, it requires the additional fix posted below which I'll include in an eventual commit. > At some point I'll probably want to move this code to run > immediately after IRA completes and extend it in a few ways, but for now > it's OK as it stands. Note that the prepare_shrink_wrap code can be further enhanced by running a regcprop pass before thread_prologue_and_epilogue_insns, since that tends to eliminate uses of the call-used destination reg. I'm going to submit a patch for this once all the other shrink-wrapping bits are in. Bernd Index: function.c =================================================================== --- function.c (revision 318184) +++ function.c (working copy) @@ -5190,6 +5190,23 @@ emit_return_into_block (bool simple_p, b } #endif +/* Return true if BB has any active insns. */ +static bool +bb_active_p (basic_block bb) +{ + rtx label; + + /* Test whether there are active instructions in the last block. */ + label = BB_END (bb); + while (label && !LABEL_P (label)) + { + if (active_insn_p (label)) + break; + label = PREV_INSN (label); + } + return BB_HEAD (bb) != label || !LABEL_P (label); +} + /* Generate the prologue and epilogue RTL if the machine supports it. Thread this into place with notes indicating where the prologue ends and where the epilogue begins. Update the basic block information when possible. @@ -5275,19 +5292,8 @@ thread_prologue_and_epilogue_insns (void exit_fallthru_edge = find_fallthru_edge (EXIT_BLOCK_PTR->preds); if (exit_fallthru_edge != NULL) { - rtx label; - last_bb = exit_fallthru_edge->src; - /* Test whether there are active instructions in the last block. */ - label = BB_END (last_bb); - while (label && !LABEL_P (label)) - { - if (active_insn_p (label)) - break; - label = PREV_INSN (label); - } - - last_bb_active = BB_HEAD (last_bb) != label || !LABEL_P (label); + last_bb_active = bb_active_p (last_bb); } else { @@ -5344,6 +5350,10 @@ thread_prologue_and_epilogue_insns (void prepare_shrink_wrap (entry_edge->dest); + /* That may have inserted instructions into the last block. */ + if (last_bb && !last_bb_active) + last_bb_active = bb_active_p (last_bb); + bitmap_initialize (&bb_antic_flags, &bitmap_default_obstack); bitmap_initialize (&bb_on_list, &bitmap_default_obstack);