From patchwork Thu Oct 31 13:34:43 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Jambor X-Patchwork-Id: 287491 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]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 47C5F2C03BF for ; Fri, 1 Nov 2013 00:34:58 +1100 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; q=dns; s=default; b=QpUAa5dulyzoAFkr4 Pt6HORfUXW1yxyZUHsoRMgDRLfmCTnddSbzHtlf7CKHvmoaiI0vTvO8WWd+NuRiN /im9jXMyHfyzf/qczlBhGa3w1qTkMChqAzHmAQErmMPZlIAsfgjpNyjcTQ7ZiFEH lcnOuE8SN/SUfqK9pVS/6Cnr0I= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; s=default; bh=eur+v81Qw0DiiC4g/iH1BdH rULI=; b=rxsFf0VNCcKQQAu54Dha7hz+vVRwGMvZc+jeJysIzHUOIUoSjUoyO1Q 8UDODVebVB12Da2Yg7DeYU9dIIsf7Rz+lxAc5nPpgCvMYRdfpio9Il5EagI0XFpS ePZweFwr0zJoi2NKQaf9N6P1YZvfVAMgTvZkVxWmkp3bi2k82kp8= Received: (qmail 17640 invoked by alias); 31 Oct 2013 13:34:49 -0000 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 Received: (qmail 17627 invoked by uid 89); 31 Oct 2013 13:34:49 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.3 required=5.0 tests=AWL, BAYES_00 autolearn=ham version=3.3.2 X-HELO: mx2.suse.de Received: from cantor2.suse.de (HELO mx2.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 31 Oct 2013 13:34:46 +0000 Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id D599BA598D; Thu, 31 Oct 2013 14:34:43 +0100 (CET) Date: Thu, 31 Oct 2013 14:34:43 +0100 From: Martin Jambor To: Jakub Jelinek Cc: Steven Bosscher , Vladimir Makarov , GCC Patches Subject: Re: [PATCH, PR 10474] Split live-ranges of function arguments to help shrink-wrapping Message-ID: <20131031133443.GA2961@virgil.suse> Mail-Followup-To: Jakub Jelinek , Steven Bosscher , Vladimir Makarov , GCC Patches References: <20131021163237.GA11578@virgil.suse> <5265EA56.6050707@redhat.com> <20131023164630.GB22314@virgil.suse> <20131025151905.GA29905@virgil.suse> <20131030231641.GK27813@tucnak.zalov.cz> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20131030231641.GK27813@tucnak.zalov.cz> User-Agent: Mutt/1.5.21 (2010-09-15) X-IsSubscribed: yes On Thu, Oct 31, 2013 at 12:16:41AM +0100, Jakub Jelinek wrote: > On Fri, Oct 25, 2013 at 05:19:06PM +0200, Martin Jambor wrote: > > 2013-10-23 Martin Jambor > > > > PR rtl-optimization/10474 > > * ira.c (find_moveable_pseudos): Do not calculate dominance info > > nor df analysis. > > (interesting_dest_for_shprep): New function. > > (split_live_ranges_for_shrink_wrap): Likewise. > > (ira): Calculate dominance info and df analysis. Call > > split_live_ranges_for_shrink_wrap. > > > > testsuite/ > > * gcc.dg/pr10474.c: New testcase. > > * gcc.dg/ira-shrinkwrap-prep-1.c: Likewise. > > * gcc.dg/ira-shrinkwrap-prep-2.c: Likewise. > > Unfortunately this patch breaks i686-linux bootstrap, Because of this, PR 58934 and perhaps other problems, and because I have reasons to doubt that I will be able to resolve them today or tomorrow (for example seeing postreload in the backraces makes me think I'll need some help :-), I am about to commit the following to revert my patch, after it passed C and C++ bootstrap and x86_64-linux. Sorry for the breakage, Martin 2013-10-31 Martin Jambor PR rtl-optimization/58934 Revert: 2013-10-30 Martin Jambor PR rtl-optimization/10474 * ira.c (find_moveable_pseudos): Do not calculate dominance info nor df analysis. (interesting_dest_for_shprep): New function. (split_live_ranges_for_shrink_wrap): Likewise. (ira): Calculate dominance info and df analysis. Call split_live_ranges_for_shrink_wrap. testsuite/ * gcc.dg/pr10474.c: New testcase. * gcc.dg/ira-shrinkwrap-prep-1.c: Likewise. * gcc.dg/ira-shrinkwrap-prep-2.c: Likewise. diff --git a/gcc/ira.c b/gcc/ira.c index d959109..1a26fed 100644 --- b/gcc/ira.c +++ a/gcc/ira.c @@ -3990,6 +3990,9 @@ pseudo_replaced_reg.release (); pseudo_replaced_reg.safe_grow_cleared (max_regs); + df_analyze (); + calculate_dominance_info (CDI_DOMINATORS); + i = 0; bitmap_initialize (&live, 0); bitmap_initialize (&used, 0); @@ -4309,196 +4312,7 @@ regstat_free_ri (); regstat_init_n_sets_and_refs (); regstat_compute_ri (); -} - - -/* If insn is interesting for parameter range-splitting shring-wrapping - preparation, i.e. it is a single set from a hard register to a pseudo, which - is live at CALL_DOM, return the destination. Otherwise return NULL. */ - -static rtx -interesting_dest_for_shprep (rtx insn, basic_block call_dom) -{ - rtx set = single_set (insn); - if (!set) - return NULL; - rtx src = SET_SRC (set); - rtx dest = SET_DEST (set); - if (!REG_P (src) || !HARD_REGISTER_P (src) - || !REG_P (dest) || HARD_REGISTER_P (dest) - || (call_dom && !bitmap_bit_p (df_get_live_in (call_dom), REGNO (dest)))) - return NULL; - return dest; -} - -/* Split live ranges of pseudos that are loaded from hard registers in the - first BB in a BB that dominates all non-sibling call if such a BB can be - found and is not in a loop. Return true if the function has made any - changes. */ - -static bool -split_live_ranges_for_shrink_wrap (void) -{ - basic_block bb, call_dom = NULL; - basic_block first = single_succ (ENTRY_BLOCK_PTR); - rtx insn, last_interesting_insn = NULL; - bitmap_head need_new, reachable; - vec queue; - - if (!flag_shrink_wrap) - return false; - - bitmap_initialize (&need_new, 0); - bitmap_initialize (&reachable, 0); - queue.create (n_basic_blocks); - - FOR_EACH_BB (bb) - FOR_BB_INSNS (bb, insn) - if (CALL_P (insn) && !SIBLING_CALL_P (insn)) - { - if (bb == first) - { - bitmap_clear (&need_new); - bitmap_clear (&reachable); - queue.release (); - return false; - } - - bitmap_set_bit (&need_new, bb->index); - bitmap_set_bit (&reachable, bb->index); - queue.quick_push (bb); - break; - } - - if (queue.is_empty ()) - { - bitmap_clear (&need_new); - bitmap_clear (&reachable); - queue.release (); - return false; - } - - while (!queue.is_empty ()) - { - edge e; - edge_iterator ei; - - bb = queue.pop (); - FOR_EACH_EDGE (e, ei, bb->succs) - if (e->dest != EXIT_BLOCK_PTR - && bitmap_set_bit (&reachable, e->dest->index)) - queue.quick_push (e->dest); - } - queue.release (); - - FOR_BB_INSNS (first, insn) - { - rtx dest = interesting_dest_for_shprep (insn, NULL); - if (!dest) - continue; - - if (DF_REG_DEF_COUNT (REGNO (dest)) > 1) - { - bitmap_clear (&need_new); - bitmap_clear (&reachable); - return false; - } - - for (df_ref use = DF_REG_USE_CHAIN (REGNO(dest)); - use; - use = DF_REF_NEXT_REG (use)) - { - if (NONDEBUG_INSN_P (DF_REF_INSN (use)) - && GET_CODE (DF_REF_REG (use)) == SUBREG) - { - /* This is necessary to avoid hitting an assert at - postreload.c:2294 in libstc++ testcases on x86_64-linux. I'm - not really sure what the probblem actually is there. */ - bitmap_clear (&need_new); - bitmap_clear (&reachable); - return false; - } - - int ubbi = DF_REF_BB (use)->index; - if (bitmap_bit_p (&reachable, ubbi)) - bitmap_set_bit (&need_new, ubbi); - } - last_interesting_insn = insn; - } - - bitmap_clear (&reachable); - if (!last_interesting_insn) - { - bitmap_clear (&need_new); - return false; - } - - call_dom = nearest_common_dominator_for_set (CDI_DOMINATORS, &need_new); - bitmap_clear (&need_new); - if (call_dom == first) - return false; - - loop_optimizer_init (AVOID_CFG_MODIFICATIONS); - while (bb_loop_depth (call_dom) > 0) - call_dom = get_immediate_dominator (CDI_DOMINATORS, call_dom); - loop_optimizer_finalize (); - - if (call_dom == first) - return false; - - calculate_dominance_info (CDI_POST_DOMINATORS); - if (dominated_by_p (CDI_POST_DOMINATORS, first, call_dom)) - { - free_dominance_info (CDI_POST_DOMINATORS); - return false; - } - free_dominance_info (CDI_POST_DOMINATORS); - - if (dump_file) - fprintf (dump_file, "Will split live ranges of parameters at BB %i\n", - call_dom->index); - - bool ret = false; - FOR_BB_INSNS (first, insn) - { - rtx dest = interesting_dest_for_shprep (insn, call_dom); - if (!dest) - continue; - - rtx newreg = NULL_RTX; - df_ref use, next; - for (use = DF_REG_USE_CHAIN (REGNO(dest)); use; use = next) - { - rtx uin = DF_REF_INSN (use); - next = DF_REF_NEXT_REG (use); - - basic_block ubb = BLOCK_FOR_INSN (uin); - if (ubb == call_dom - || dominated_by_p (CDI_DOMINATORS, ubb, call_dom)) - { - if (!newreg) - newreg = ira_create_new_reg (dest); - validate_change (uin, DF_REF_LOC (use), newreg, true); - } - } - - if (newreg) - { - rtx new_move = gen_move_insn (newreg, dest); - emit_insn_after (new_move, bb_note (call_dom)); - if (dump_file) - { - fprintf (dump_file, "Split live-range of register "); - print_rtl_single (dump_file, dest); - } - ret = true; - } - - if (insn == last_interesting_insn) - break; - } - apply_change_group (); - return ret; + free_dominance_info (CDI_DOMINATORS); } /* Perform the second half of the transformation started in @@ -4709,16 +4523,7 @@ allocation because of -O0 usage or because the function is too big. */ if (ira_conflicts_p) - { - df_analyze (); - calculate_dominance_info (CDI_DOMINATORS); - - find_moveable_pseudos (); - if (split_live_ranges_for_shrink_wrap ()) - df_analyze (); - - free_dominance_info (CDI_DOMINATORS); - } + find_moveable_pseudos (); max_regno_before_ira = max_reg_num (); ira_setup_eliminable_regset (true); diff --git a/gcc/testsuite/gcc.dg/ira-shrinkwrap-prep-1.c b/gcc/testsuite/gcc.dg/ira-shrinkwrap-prep-1.c new file mode 100644 index 0000000..fe497c2 --- b/gcc/testsuite/gcc.dg/ira-shrinkwrap-prep-1.c +++ /dev/null @@ -1,31 +0,0 @@ -/* { dg-do compile } */ -/* { dg-options "-O3 -fdump-rtl-ira -fdump-rtl-pro_and_epilogue" } */ - -int __attribute__((noinline, noclone)) -foo (int a) -{ - return a + 5; -} - -static int g; - -int __attribute__((noinline, noclone)) -bar (int a) -{ - int r; - - if (a) - { - r = foo (a); - g = r + a; - } - else - r = a+1; - return r; -} - -/* { dg-final { scan-rtl-dump "Will split live ranges of parameters" "ira" } } */ -/* { dg-final { scan-rtl-dump "Split live-range of register" "ira" } } */ -/* { dg-final { scan-rtl-dump "Performing shrink-wrapping" "pro_and_epilogue" } } */ -/* { dg-final { cleanup-rtl-dump "ira" } } */ -/* { dg-final { cleanup-rtl-dump "pro_and_epilogue" } } */ diff --git a/gcc/testsuite/gcc.dg/ira-shrinkwrap-prep-2.c b/gcc/testsuite/gcc.dg/ira-shrinkwrap-prep-2.c new file mode 100644 index 0000000..872a757 --- b/gcc/testsuite/gcc.dg/ira-shrinkwrap-prep-2.c +++ /dev/null @@ -1,36 +0,0 @@ -/* { dg-do compile } */ -/* { dg-options "-O3 -fdump-rtl-ira -fdump-rtl-pro_and_epilogue" } */ - -int __attribute__((noinline, noclone)) -foo (int a) -{ - return a + 5; -} - -static int g; - -int __attribute__((noinline, noclone)) -bar (int a) -{ - int r; - - if (a) - { - r = a; - while (r < 500) - if (r % 2) - r = foo (r); - else - r = foo (r+1); - g = r + a; - } - else - r = g+1; - return r; -} - -/* { dg-final { scan-rtl-dump "Will split live ranges of parameters" "ira" } } */ -/* { dg-final { scan-rtl-dump "Split live-range of register" "ira" } } */ -/* { dg-final { scan-rtl-dump "Performing shrink-wrapping" "pro_and_epilogue" } } */ -/* { dg-final { cleanup-rtl-dump "ira" } } */ -/* { dg-final { cleanup-rtl-dump "pro_and_epilogue" } } */ diff --git a/gcc/testsuite/gcc.dg/pr10474.c b/gcc/testsuite/gcc.dg/pr10474.c new file mode 100644 index 0000000..ee085c3 --- b/gcc/testsuite/gcc.dg/pr10474.c +++ /dev/null @@ -1,16 +0,0 @@ -/* { dg-do compile } */ -/* { dg-options "-O3 -fdump-rtl-pro_and_epilogue" } */ - -void f(int *i) -{ - if (!i) - return; - else - { - __builtin_printf("Hi"); - *i=0; - } -} - -/* { dg-final { scan-rtl-dump "Performing shrink-wrapping" "pro_and_epilogue" } } */ -/* { dg-final { cleanup-rtl-dump "pro_and_epilogue" } } */