From patchwork Thu May 15 06:57:59 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhenqiang Chen X-Patchwork-Id: 30222 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ob0-f198.google.com (mail-ob0-f198.google.com [209.85.214.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 4DCE320446 for ; Thu, 15 May 2014 06:58:20 +0000 (UTC) Received: by mail-ob0-f198.google.com with SMTP id va2sf3386643obc.9 for ; Wed, 14 May 2014 23:58:19 -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:date:message-id:subject:from:to:cc :x-original-sender:x-original-authentication-results:content-type; bh=8fMCBflIS5pP+Mb8ZpYPHQFc3KAkfJTfY0ecMi1TKWY=; b=TC7NycGuVyjsrE/YiZ0CNzoYBax1LTr6s69wMjpDfkEm+BbkzwpDxJMFTvhjj+sQ7p +18y5YrNwbNRvNHVSNpwuXCEG43NkGmgzLBIoH2NHg5opXizjjuR9pHbPxZFbRcCl94J +WdtEWGaFdUUpsOA/9tM9wNyP73HeD83UCoduYMtdfIQJAetjDcd0gvhQrOUNBRK0jZN /glPuCQWwO+YN0wkl4ChWU6Xz/tIvWHrM8QpBd3Kj9Bsq0ow9HUqfaD1w+Lgmx0p8MJ7 EbBocRBlGVMe0LRNk+ZXgUq9A22ZUn7v2Y5I5sy9MVCU97llcnvwt8wQfg05ngJ0GIg0 2QsQ== X-Gm-Message-State: ALoCoQk3aQOsJfnFsVNc0VouM/snTZK+DlA9GdYXTtZ0T+Zi9PWZtqFh3mahdzb88rkUhVvlX4mU X-Received: by 10.183.1.7 with SMTP id bc7mr4174570obd.47.1400137099931; Wed, 14 May 2014 23:58:19 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.40.74 with SMTP id w68ls112973qgw.53.gmail; Wed, 14 May 2014 23:58:19 -0700 (PDT) X-Received: by 10.52.189.97 with SMTP id gh1mr5993832vdc.0.1400137099846; Wed, 14 May 2014 23:58:19 -0700 (PDT) Received: from mail-vc0-x22c.google.com (mail-vc0-x22c.google.com [2607:f8b0:400c:c03::22c]) by mx.google.com with ESMTPS id xx5si769598vcb.72.2014.05.14.23.58.19 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 14 May 2014 23:58:19 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2607:f8b0:400c:c03::22c as permitted sender) client-ip=2607:f8b0:400c:c03::22c; Received: by mail-vc0-f172.google.com with SMTP id hr9so3810940vcb.17 for ; Wed, 14 May 2014 23:58:19 -0700 (PDT) X-Received: by 10.58.116.175 with SMTP id jx15mr6986565veb.9.1400137099745; Wed, 14 May 2014 23:58:19 -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 ib8csp298701vcb; Wed, 14 May 2014 23:58:19 -0700 (PDT) X-Received: by 10.68.102.34 with SMTP id fl2mr10162375pbb.2.1400137098727; Wed, 14 May 2014 23:58:18 -0700 (PDT) Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id sg3si4393770pac.93.2014.05.14.23.58.18 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 May 2014 23:58:18 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-367535-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Received: (qmail 18416 invoked by alias); 15 May 2014 06:58:06 -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 18401 invoked by uid 89); 15 May 2014 06:58:05 -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-la0-f48.google.com Received: from mail-la0-f48.google.com (HELO mail-la0-f48.google.com) (209.85.215.48) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Thu, 15 May 2014 06:58:03 +0000 Received: by mail-la0-f48.google.com with SMTP id mc6so442936lab.7 for ; Wed, 14 May 2014 23:57:59 -0700 (PDT) MIME-Version: 1.0 X-Received: by 10.152.8.7 with SMTP id n7mr6221855laa.22.1400137079459; Wed, 14 May 2014 23:57:59 -0700 (PDT) Received: by 10.112.13.36 with HTTP; Wed, 14 May 2014 23:57:59 -0700 (PDT) Date: Thu, 15 May 2014 14:57:59 +0800 Message-ID: Subject: [Committed] [PATCH, 1/2] shrink wrap a function with a single loop: copy propagation 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:c03::22c 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 15 May 2014 02:07, Jeff Law wrote: > On 05/13/14 04:04, Zhenqiang Chen wrote: >> >> After reading the code in regcprop.c, I think I should reuse the >> copyprop_hardreg_forward_1. So rewrite the patch, which is much simple >> and should handle HAVE_cc0. But not sure we'd handle DEBUG_INSN or >> not. >> >> 2014-05-13 Zhenqiang Chen >> >> * regcprop.c (skip_debug_insn_p): New decl. >> (replace_oldest_value_reg): Check skip_debug_insn_p. >> (copyprop_hardreg_forward_bb_without_debug_insn.): New function. >> * shrink-wrap.c (prepare_shrink_wrap): >> Call copyprop_hardreg_forward_bb_without_debug_insn. >> * function.h (copyprop_hardreg_forward_bb_without_debug_insn): >> New prototype. >> >> testsuite/ChangeLog: >> 2014-05-13 Zhenqiang Chen >> >> * shrink-wrap-loop.c: New test case. > > Basically OK. > > Can you create regcprop.h and put the prototype for > copyprop_hardreg_forward_bb_without_debug_insn in there? > > Then include regcprop.h in shrink-wrap.c. > > With that change, approved. Please post the final version for archival > purposes. Thanks. Committed @r210458 with the suggested changes. ChangeLog: 2014-05-15 Zhenqiang Chen * regcprop.h: New file. * regcprop.c (skip_debug_insn_p): New decl. (replace_oldest_value_reg): Check skip_debug_insn_p. (copyprop_hardreg_forward_bb_without_debug_insn.): New function. * shrink-wrap.c: include regcprop.h (prepare_shrink_wrap): Call copyprop_hardreg_forward_bb_without_debug_insn. testsuite/ChangeLog: 2014-05-15 Zhenqiang Chen * shrink-wrap-loop.c: New test case. diff --git a/gcc/regcprop.c b/gcc/regcprop.c index a710cc38..7a5a4f6 100644 --- a/gcc/regcprop.c +++ b/gcc/regcprop.c @@ -77,6 +77,7 @@ struct value_data }; static alloc_pool debug_insn_changes_pool; +static bool skip_debug_insn_p; static void kill_value_one_regno (unsigned, struct value_data *); static void kill_value_regno (unsigned, unsigned, struct value_data *); @@ -485,7 +486,7 @@ replace_oldest_value_reg (rtx *loc, enum reg_class cl, rtx insn, struct value_data *vd) { rtx new_rtx = find_oldest_value_reg (cl, *loc, vd); - if (new_rtx) + if (new_rtx && (!DEBUG_INSN_P (insn) || !skip_debug_insn_p)) { if (DEBUG_INSN_P (insn)) { @@ -1112,6 +1113,26 @@ debug_value_data (struct value_data *vd) vd->e[i].next_regno); } +/* Do copyprop_hardreg_forward_1 for a single basic block BB. + DEBUG_INSN is skipped since we do not want to involve DF related + staff as how it is handled in function pass_cprop_hardreg::execute. + + NOTE: Currently it is only used for shrink-wrap. Maybe extend it + to handle DEBUG_INSN for other uses. */ + +void +copyprop_hardreg_forward_bb_without_debug_insn (basic_block bb) +{ + struct value_data *vd; + vd = XNEWVEC (struct value_data, 1); + init_value_data (vd); + + skip_debug_insn_p = true; + copyprop_hardreg_forward_1 (bb, vd); + free (vd); + skip_debug_insn_p = false; +} + #ifdef ENABLE_CHECKING static void validate_value_data (struct value_data *vd) diff --git a/gcc/regcprop.h b/gcc/regcprop.h new file mode 100644 index 0000000..ab54eaf --- /dev/null +++ b/gcc/regcprop.h @@ -0,0 +1,27 @@ +/* Copy propagation on hard registers. + Copyright (C) 1989-2014 Free Software Foundation, Inc. + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free +Software Foundation; either version 3, or (at your option) any later +version. + +GCC is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with GCC; see the file COPYING3. If not see +. */ + +#ifndef GCC_REGCPROP_H +#define GCC_REGCPROP_H + +#include "basic-block.h" + +extern void copyprop_hardreg_forward_bb_without_debug_insn (basic_block bb); + +#endif /* GCC_REGCPROP_H */ diff --git a/gcc/shrink-wrap.c b/gcc/shrink-wrap.c index 6f0cd0c..f09cfe7 100644 --- a/gcc/shrink-wrap.c +++ b/gcc/shrink-wrap.c @@ -52,7 +52,7 @@ along with GCC; see the file COPYING3. If not see #include "params.h" #include "bb-reorder.h" #include "shrink-wrap.h" - +#include "regcprop.h" #ifdef HAVE_simple_return @@ -320,6 +320,15 @@ prepare_shrink_wrap (basic_block entry_block) df_ref *ref; bool split_p = false; + if (JUMP_P (BB_END (entry_block))) + { + /* To have more shrink-wrapping opportunities, prepare_shrink_wrap tries + to sink the copies from parameter to callee saved register out of + entry block. copyprop_hardreg_forward_bb_without_debug_insn is called + to release some dependences. */ + copyprop_hardreg_forward_bb_without_debug_insn (entry_block); + } + CLEAR_HARD_REG_SET (uses); CLEAR_HARD_REG_SET (defs); FOR_BB_INSNS_REVERSE_SAFE (entry_block, insn, curr) diff --git a/gcc/testsuite/gcc.dg/shrink-wrap-loop.c b/gcc/testsuite/gcc.dg/shrink-wrap-loop.c new file mode 100644 index 0000000..17dca4e --- /dev/null +++ b/gcc/testsuite/gcc.dg/shrink-wrap-loop.c @@ -0,0 +1,20 @@ +/* { dg-do compile { target { { x86_64-*-* } || { arm_thumb2 } } } } */ +/* { dg-options "-O2 -fdump-rtl-pro_and_epilogue" } */ + +int foo (int *p1, int *p2); + +int +test (int *p1, int *p2) +{ + int *p; + + for (p = p2; p != 0; p++) + { + if (!foo (p, p1)) + return 0; + } + + return 1; +} +/* { dg-final { scan-rtl-dump "Performing shrink-wrapping" "pro_and_epilogue" } } */ +/* { dg-final { cleanup-rtl-dump "pro_and_epilogue" } } */