From patchwork Thu Oct 13 17:04:59 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bernd Schmidt X-Patchwork-Id: 119570 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 3B04CB71BB for ; Fri, 14 Oct 2011 04:05:27 +1100 (EST) Received: (qmail 28038 invoked by alias); 13 Oct 2011 17:05:25 -0000 Received: (qmail 28019 invoked by uid 22791); 13 Oct 2011 17:05:23 -0000 X-SWARE-Spam-Status: No, hits=-1.6 required=5.0 tests=AWL,BAYES_00,TW_FC X-Spam-Check-By: sourceware.org Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 13 Oct 2011 17:05:05 +0000 Received: from nat-ies.mentorg.com ([192.94.31.2] helo=EU1-MAIL.mgc.mentorg.com) by relay1.mentorg.com with esmtp id 1REOiO-0003yF-92 from Bernd_Schmidt@mentor.com ; Thu, 13 Oct 2011 10:05:04 -0700 Received: from [127.0.0.1] ([172.16.63.104]) by EU1-MAIL.mgc.mentorg.com with Microsoft SMTPSVC(6.0.3790.1830); Thu, 13 Oct 2011 18:05:02 +0100 Message-ID: <4E971A3B.9090407@codesourcery.com> Date: Thu, 13 Oct 2011 19:04:59 +0200 From: Bernd Schmidt User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.20) Gecko/20110920 Lightning/1.0b3pre Thunderbird/3.1.12 MIME-Version: 1.0 To: gcc-patches@gcc.gnu.org, Richard Henderson , Alan Modra Subject: Re: Ping shrink wrap patches References: <20111013122705.GA9539@bubble.grove.modra.org> <4E9716D3.6000008@codesourcery.com> In-Reply-To: <4E9716D3.6000008@codesourcery.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 10/13/11 18:50, Bernd Schmidt wrote: > On 10/13/11 14:27, Alan Modra wrote: >> Without the ifcvt >> optimization for a function "int foo (int x)" we might have something >> like >> >> r29 = r3; // save r3 in callee saved reg >> if (some test) goto exit_label >> // main body of foo, calling other functions >> r3 = 0; >> return; >> exit_label: >> r3 = 1; >> return; >> >> Bernd's http://gcc.gnu.org/ml/gcc-patches/2011-10/msg00380.html quite >> happily rearranges the r29 assignment to be after the "if", and shrink >> wrapping occurs. With the ifcvt optimization we get >> >> r29 = r3; // save r3 in callee saved reg >> r3 = 1; >> if (some test) goto exit_label >> // main body of foo, calling other functions >> r3 = 0; >> exit_label: >> return; > > I wonder if this can't be described as another case for moving an insn > downwards in prepare_shrink_wrap, rather than stopping ifcvt? I.e. something like this? Minimally tested by inspecting some generated assembly. I haven't found a case where it enables extra shrink-wrapping on i686, but maybe it's different on ppc? Bernd Index: /local/src/egcs/scratch-trunk/gcc/function.c =================================================================== --- /local/src/egcs/scratch-trunk/gcc/function.c (revision 179848) +++ /local/src/egcs/scratch-trunk/gcc/function.c (working copy) @@ -5369,13 +5369,13 @@ static void prepare_shrink_wrap (basic_block entry_block) { rtx insn, curr; - FOR_BB_INSNS_SAFE (entry_block, insn, curr) + FOR_BB_INSNS_REVERSE_SAFE (entry_block, insn, curr) { basic_block next_bb; edge e, live_edge; edge_iterator ei; - rtx set, scan; - unsigned destreg, srcreg; + rtx set, src, dst, scan; + unsigned destreg; if (!NONDEBUG_INSN_P (insn)) continue; @@ -5383,12 +5383,14 @@ prepare_shrink_wrap (basic_block entry_b if (!set) continue; - if (!REG_P (SET_SRC (set)) || !REG_P (SET_DEST (set))) + src = SET_SRC (set); + dst = SET_DEST (set); + if (!(REG_P (src) || CONSTANT_P (src)) || !REG_P (dst)) continue; - srcreg = REGNO (SET_SRC (set)); - destreg = REGNO (SET_DEST (set)); - if (hard_regno_nregs[srcreg][GET_MODE (SET_SRC (set))] > 1 - || hard_regno_nregs[destreg][GET_MODE (SET_DEST (set))] > 1) + destreg = REGNO (dst); + if (hard_regno_nregs[destreg][GET_MODE (dst)] > 1) + continue; + if (REG_P (src) && hard_regno_nregs[REGNO (src)][GET_MODE (src)] > 1) continue; next_bb = entry_block; @@ -5436,7 +5438,8 @@ prepare_shrink_wrap (basic_block entry_b if (REG_NOTE_KIND (link) == REG_INC) record_hard_reg_sets (XEXP (link, 0), NULL, &set_regs); - if (TEST_HARD_REG_BIT (set_regs, srcreg) + if ((REG_P (src) + && TEST_HARD_REG_BIT (set_regs, REGNO (src))) || reg_referenced_p (SET_DEST (set), PATTERN (scan))) {