From patchwork Tue May 13 09:49:05 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhenqiang Chen X-Patchwork-Id: 30019 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-oa0-f69.google.com (mail-oa0-f69.google.com [209.85.219.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 111CD20446 for ; Tue, 13 May 2014 09:49:24 +0000 (UTC) Received: by mail-oa0-f69.google.com with SMTP id i7sf416355oag.8 for ; Tue, 13 May 2014 02:49:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:mailing-list:precedence:list-id :list-unsubscribe:list-archive:list-post:list-help:sender :delivered-to:mime-version:in-reply-to:references:date:message-id :subject:from:to:cc:x-original-sender :x-original-authentication-results:content-type; bh=R9FvnmhQbm7MTnOrcx9+S6LzARy5ZbpkDOKFdQiFA6g=; b=AjI7I2jEmNSuIvHK0j4kRrfzyrKYwWZF5tjVIv49a9gl8MrvYZwC42I577KaXGD7H3 NEG/TzMJRUv/776x9sBdh9sdSvEXBWuVKmBeL42vkYtPtiJUxQqlxcFBQDepxROP4ncr cJOC8y+pilxmTIc8hjtCJ70PFWcR1aokPHvbgNmHAXk0BMBfO8CJxaBKh02Aw9qvjU/2 L0gyDOcd+O2E/LDRdSWPfW4VfO50oQ/l2K0xsDAZ0ZNIzlGdaqm87vdMGxy7QHZcBCEQ UFJv0uNC28dz9uscZqTdAJRHH7yTNpd3JPyeJluytol5jL5O9sDNZ+ShX9COBibltQNv ObFQ== X-Gm-Message-State: ALoCoQkIUxAaFj2tzvNmw5GRe4plcgE4kRYyb25fS+ytK7BnM/IQrX8JoCdPtZ08EEPN09R0Iz4j X-Received: by 10.182.106.229 with SMTP id gx5mr16871823obb.31.1399974564627; Tue, 13 May 2014 02:49:24 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.48.210 with SMTP id o76ls1732958qga.66.gmail; Tue, 13 May 2014 02:49:24 -0700 (PDT) X-Received: by 10.52.11.230 with SMTP id t6mr1132340vdb.27.1399974564445; Tue, 13 May 2014 02:49:24 -0700 (PDT) Received: from mail-ve0-x22f.google.com (mail-ve0-x22f.google.com [2607:f8b0:400c:c01::22f]) by mx.google.com with ESMTPS id ej2si2554617veb.149.2014.05.13.02.49.24 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 13 May 2014 02:49:24 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2607:f8b0:400c:c01::22f as permitted sender) client-ip=2607:f8b0:400c:c01::22f; Received: by mail-ve0-f175.google.com with SMTP id jw12so108410veb.6 for ; Tue, 13 May 2014 02:49:24 -0700 (PDT) X-Received: by 10.58.228.163 with SMTP id sj3mr7159496vec.28.1399974563892; Tue, 13 May 2014 02:49:23 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.220.221.72 with SMTP id ib8csp137292vcb; Tue, 13 May 2014 02:49:23 -0700 (PDT) X-Received: by 10.66.254.3 with SMTP id ae3mr63435277pad.49.1399974562918; Tue, 13 May 2014 02:49:22 -0700 (PDT) Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id hh2si12734893pac.43.2014.05.13.02.49.22 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 13 May 2014 02:49:22 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-367341-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Received: (qmail 8512 invoked by alias); 13 May 2014 09:49:11 -0000 Mailing-List: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org Precedence: list 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 8501 invoked by uid 89); 13 May 2014 09:49:10 -0000 X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.5 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-lb0-f179.google.com Received: from mail-lb0-f179.google.com (HELO mail-lb0-f179.google.com) (209.85.217.179) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Tue, 13 May 2014 09:49:09 +0000 Received: by mail-lb0-f179.google.com with SMTP id c11so70720lbj.24 for ; Tue, 13 May 2014 02:49:05 -0700 (PDT) MIME-Version: 1.0 X-Received: by 10.112.35.202 with SMTP id k10mr28167153lbj.14.1399974545382; Tue, 13 May 2014 02:49:05 -0700 (PDT) Received: by 10.112.13.36 with HTTP; Tue, 13 May 2014 02:49:05 -0700 (PDT) In-Reply-To: <536C70DA.1020504@redhat.com> References: <536C70DA.1020504@redhat.com> Date: Tue, 13 May 2014 17:49:05 +0800 Message-ID: Subject: Re: [PATCH, 2/2] shrink wrap a function with a single loop: split live_edge From: Zhenqiang Chen To: Jeff Law Cc: "gcc-patches@gcc.gnu.org" X-IsSubscribed: yes X-Original-Sender: zhenqiang.chen@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2607:f8b0:400c:c01::22f as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org; dkim=pass header.i=@gcc.gnu.org X-Google-Group-Id: 836684582541 On 9 May 2014 14:08, Jeff Law wrote: > On 05/08/14 02:07, Zhenqiang Chen wrote: >> >> Hi, >> >> The patch splits the live_edge for move_insn_for_shrink_wrap to sink >> the copy out of the entry block. >> >> Bootstrap and no make check regression on X86-64 and ARM. >> >> OK for trunk? >> >> Thanks! >> -Zhenqiang >> >> ChangeLog: >> 2014-05-08 Zhenqiang Chen >> >> * function.c (next_block_for_reg): Allow live_edge->dest has two >> predecessors. >> (move_insn_for_shrink_wrap): Split live_edge. >> (prepre_shrink_wrap): One more parameter for >> move_insn_for_shrink_wrap. >> >> >> diff --git a/gcc/function.c b/gcc/function.c >> index 764ac82..0be58e2 100644 >> --- a/gcc/function.c >> +++ b/gcc/function.c >> @@ -5381,7 +5381,7 @@ requires_stack_frame_p (rtx insn, HARD_REG_SET >> prologue_used, >> and if BB is its only predecessor. Return that block if so, >> otherwise return null. */ >> >> -static basic_block >> +static edge >> next_block_for_reg (basic_block bb, int regno, int end_regno) > > Comment for this function needs to be changed. You're no longer returning a > block, but the edge leading to the block. It also seems the name of the > function ought to change. The comment and function name are updated. > This looks basically OK. I'd like to see the requested cleanups made, then > the resulting new patch reposted for a final review. Here is the updated patch based on the cleaned shrink-wrapping code: ChangeLog: 2014-05-13 Zhenqiang Chen * shrink-wrap.c: Update comment. (next_block_for_reg): Rename to live_edge_for_reg. (live_edge_for_reg): Allow live_edge->dest has two predecessors. (move_insn_for_shrink_wrap): Split live_edge. (prepre_shrink_wrap): One more parameter for move_insn_for_shrink_wrap. edge_iterator ei; @@ -148,25 +148,30 @@ next_block_for_reg (basic_block bb, int regno, int end_regno) if (live_edge->flags & EDGE_ABNORMAL) return NULL; - if (EDGE_COUNT (live_edge->dest->preds) > 1) + /* When live_edge->dest->preds == 2, we can create a new block on + the edge to make it meet the requirement. */ + if (EDGE_COUNT (live_edge->dest->preds) > 2) return NULL; - return live_edge->dest; + return live_edge; } /* Try to move INSN from BB to a successor. Return true on success. USES and DEFS are the set of registers that are used and defined - after INSN in BB. */ + after INSN in BB. SPLIT_P indicates whether a live edge from BB + is splitted or not. */ static bool move_insn_for_shrink_wrap (basic_block bb, rtx insn, const HARD_REG_SET uses, - const HARD_REG_SET defs) + const HARD_REG_SET defs, + bool *split_p) { rtx set, src, dest; bitmap live_out, live_in, bb_uses, bb_defs; unsigned int i, dregno, end_dregno, sregno, end_sregno; basic_block next_block; + edge live_edge; /* Look for a simple register copy. */ set = single_set (insn); @@ -191,10 +196,24 @@ move_insn_for_shrink_wrap (basic_block bb, rtx insn, return false; /* See whether there is a successor block to which we could move INSN. */ - next_block = next_block_for_reg (bb, dregno, end_dregno); - if (!next_block) + live_edge = live_edge_for_reg (bb, dregno, end_dregno); + if (!live_edge) return false; + next_block = live_edge->dest; + /* Create a new basic block on the edge. */ + if (EDGE_COUNT (next_block->preds) == 2) + { + next_block = split_edge (live_edge); + + bitmap_copy (df_get_live_in (next_block), df_get_live_out (bb)); + df_set_bb_dirty (next_block); + + /* We should not split more than once for a function. */ + gcc_assert (!(*split_p)); + *split_p = true; + } + /* At this point we are committed to moving INSN, but let's try to move it as far as we can. */ do @@ -212,7 +231,9 @@ move_insn_for_shrink_wrap (basic_block bb, rtx insn, { for (i = dregno; i < end_dregno; i++) { - if (REGNO_REG_SET_P (bb_uses, i) || REGNO_REG_SET_P (bb_defs, i) + if (*split_p + || REGNO_REG_SET_P (bb_uses, i) + || REGNO_REG_SET_P (bb_defs, i) || REGNO_REG_SET_P (&DF_LIVE_BB_INFO (bb)->gen, i)) next_block = NULL; CLEAR_REGNO_REG_SET (live_out, i); @@ -223,7 +244,8 @@ move_insn_for_shrink_wrap (basic_block bb, rtx insn, Either way, SRC is now live on entry. */ for (i = sregno; i < end_sregno; i++) { - if (REGNO_REG_SET_P (bb_defs, i) + if (*split_p + || REGNO_REG_SET_P (bb_defs, i) || REGNO_REG_SET_P (&DF_LIVE_BB_INFO (bb)->gen, i)) next_block = NULL; SET_REGNO_REG_SET (live_out, i); @@ -252,21 +274,31 @@ move_insn_for_shrink_wrap (basic_block bb, rtx insn, /* If we don't need to add the move to BB, look for a single successor block. */ if (next_block) - next_block = next_block_for_reg (next_block, dregno, end_dregno); + { + live_edge = live_edge_for_reg (next_block, dregno, end_dregno); + if (!live_edge || EDGE_COUNT (live_edge->dest->preds) > 1) + break; + next_block = live_edge->dest; + } } while (next_block); - /* BB now defines DEST. It only uses the parts of DEST that overlap SRC - (next loop). */ - for (i = dregno; i < end_dregno; i++) + /* For the new created basic block, there is no dataflow info at all. + So skip the following dataflow update and check. */ + if (!(*split_p)) { - CLEAR_REGNO_REG_SET (bb_uses, i); - SET_REGNO_REG_SET (bb_defs, i); - } + /* BB now defines DEST. It only uses the parts of DEST that overlap SRC + (next loop). */ + for (i = dregno; i < end_dregno; i++) + { + CLEAR_REGNO_REG_SET (bb_uses, i); + SET_REGNO_REG_SET (bb_defs, i); + } - /* BB now uses SRC. */ - for (i = sregno; i < end_sregno; i++) - SET_REGNO_REG_SET (bb_uses, i); + /* BB now uses SRC. */ + for (i = sregno; i < end_sregno; i++) + SET_REGNO_REG_SET (bb_uses, i); + } emit_insn_after (PATTERN (insn), bb_note (bb)); delete_insn (insn); @@ -286,12 +318,14 @@ prepare_shrink_wrap (basic_block entry_block) rtx insn, curr, x; HARD_REG_SET uses, defs; df_ref *ref; + bool split_p = false; CLEAR_HARD_REG_SET (uses); CLEAR_HARD_REG_SET (defs); FOR_BB_INSNS_REVERSE_SAFE (entry_block, insn, curr) if (NONDEBUG_INSN_P (insn) - && !move_insn_for_shrink_wrap (entry_block, insn, uses, defs)) + && !move_insn_for_shrink_wrap (entry_block, insn, uses, defs, + &split_p)) { /* Add all defined registers to DEFs. */ for (ref = DF_INSN_DEFS (insn); *ref; ref++) diff --git a/gcc/shrink-wrap.c b/gcc/shrink-wrap.c index b302777..f11e920 100644 --- a/gcc/shrink-wrap.c +++ b/gcc/shrink-wrap.c @@ -1,4 +1,4 @@ -/* Expands front end tree to back end RTL for GCC. +/* Shrink-wrapping related optimizations. Copyright (C) 1987-2014 Free Software Foundation, Inc. This file is part of GCC. @@ -110,12 +110,12 @@ requires_stack_frame_p (rtx insn, HARD_REG_SET prologue_used, return false; } -/* See whether BB has a single successor that uses [REGNO, END_REGNO), - and if BB is its only predecessor. Return that block if so, - otherwise return null. */ +/* See whether there has a single live edge from BB, which dest uses + [REGNO, END_REGNO). Return the live edge if its dest bb has + one or two predecessors. Otherwise return NULL. */ -static basic_block -next_block_for_reg (basic_block bb, int regno, int end_regno) +static edge +live_edge_for_reg (basic_block bb, int regno, int end_regno) { edge e, live_edge;