From patchwork Fri Oct 9 12:00:31 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Bin.Cheng" X-Patchwork-Id: 528188 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.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id D6BA6140B04 for ; Fri, 9 Oct 2015 23:00:43 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=mGtvAupv; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; q=dns; s=default; b=CxrHRDjTjySaxfCEJG VI0Ac5fqgIM+O/swt99SGr82TwTT8A9+cAJGxFCaph6ugr41uHnFIrRif/O6I41N WQg78oK56+odEVEkyT9EVdl/3lFdV7PImTJNJrkuRofQvGpZAcLLLmufvUeRQVfP pwp/TOK1bT+qxHqh0nsHuKb3Y= 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 :mime-version:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; s=default; bh=BzkXGkBiKQ9gYYyqQyKonGJG Q0M=; b=mGtvAupvwVs1Vdrd86mUG8DZRIrLfVzo52Q0JQgahAY52fggmjTO3kHs ogHBwc2X/EpfBvzpyUgQGcWSIDMLn/XR3o/HWC03RxWAwlT9KpwO4Bt6ITvAvVOG mYQ7LugV41iLVbf6nl9ehdrWzZqb3Ycf2cZra2FwrxuN1jjm0Bs= Received: (qmail 124626 invoked by alias); 9 Oct 2015 12:00:36 -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 124615 invoked by uid 89); 9 Oct 2015 12:00:35 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.2 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-vk0-f41.google.com Received: from mail-vk0-f41.google.com (HELO mail-vk0-f41.google.com) (209.85.213.41) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Fri, 09 Oct 2015 12:00:33 +0000 Received: by vkgd64 with SMTP id d64so50023875vkg.0 for ; Fri, 09 Oct 2015 05:00:31 -0700 (PDT) MIME-Version: 1.0 X-Received: by 10.31.153.129 with SMTP id b123mr2469379vke.117.1444392031564; Fri, 09 Oct 2015 05:00:31 -0700 (PDT) Received: by 10.103.65.1 with HTTP; Fri, 9 Oct 2015 05:00:31 -0700 (PDT) In-Reply-To: References: <000001d0f9d2$1254f370$36feda50$@arm.com> <56092466.30100@redhat.com> <5609772B.4090809@redhat.com> Date: Fri, 9 Oct 2015 20:00:31 +0800 Message-ID: Subject: Re: [PATCH GCC]Improve rtl loop inv cost by checking if the inv can be propagated to address uses From: "Bin.Cheng" To: Jeff Law Cc: Bernd Schmidt , Bin Cheng , gcc-patches List X-IsSubscribed: yes On Wed, Sep 30, 2015 at 11:33 AM, Bin.Cheng wrote: > On Tue, Sep 29, 2015 at 1:21 AM, Jeff Law wrote: >> On 09/28/2015 05:28 AM, Bernd Schmidt wrote: >>> >>> On 09/28/2015 11:43 AM, Bin Cheng wrote: >>>> >>>> Bootstrap and test on x86_64 and x86_32. Will test it on aarch64. So >>>> any >>>> comments? >>>> >>>> Thanks, >>>> bin >>>> >>>> 2015-09-28 Bin Cheng >>>> >>>> * loop-invariant.c (struct def): New field cant_fwprop_to_addr_uses. >>>> (inv_cant_fwprop_to_addr_use): New function. >>>> (record_use): Call inv_cant_fwprop_to_addr_use, set the new field. >>>> (get_inv_cost): Count cost if inv can't be propagated into its >>>> address uses. >>> >>> >>> It looks at least plausible. >> >> Definitely plausible. Many targets have restrictions on the immediate >> offsets, so this potentially affects many targets (in a good way). > Here is some more information. > For spec2k6 on x86, no regression or obvious improvement. > For spec2k6 on aarch64, several cases are improved. > Given the results and your positive feedback, I will continue to work > on this patch when I get back from holiday. I further bootstrap and test attached patch on aarch64. Also three cases in spec2k6/fp are improved by 3~6%, two cases in spec2k6/fp are regressed by ~2%. Overall score is improved by ~0.8% for spec2k6/fp on aarch64 of my run. I may later analyze the regression. So is this patch OK? Thanks, bin 2015-10-09 Bin Cheng * loop-invariant.c (struct def): New field cant_prop_to_addr_uses. (inv_cant_prop_to_addr_use): New function. (record_use): Call inv_cant_prop_to_addr_use, set the new field. (get_inv_cost): Count cost if inv can't be propagated into its address uses. > >> >> >> Another option which I think has had some >>> >>> discussion recently would be to just move everything, and leave it to >>> cprop to put things back together if the costs allow it. >> >> I go back and forth on this kind of approach. > Hmm, either way we need to model rtx/register pressure costs, in loop > invariant or cprop. > > Thanks, > bin > >> >> jeff diff --git a/gcc/loop-invariant.c b/gcc/loop-invariant.c index 52c8ae8..3c2395c 100644 --- a/gcc/loop-invariant.c +++ b/gcc/loop-invariant.c @@ -99,6 +99,8 @@ struct def unsigned n_uses; /* Number of such uses. */ unsigned n_addr_uses; /* Number of uses in addresses. */ unsigned invno; /* The corresponding invariant. */ + bool cant_prop_to_addr_uses; /* True if the corresponding inv can't be + propagated into its address uses. */ }; /* The data stored for each invariant. */ @@ -762,6 +764,34 @@ create_new_invariant (struct def *def, rtx_insn *insn, bitmap depends_on, return inv; } +/* Given invariant DEF and its address USE, check if the corresponding + invariant expr can be propagated into the use or not. */ + +static bool +inv_cant_prop_to_addr_use (struct def *def, df_ref use) +{ + struct invariant *inv; + rtx *pos = DF_REF_REAL_LOC (use), def_set; + rtx_insn *use_insn = DF_REF_INSN (use); + rtx_insn *def_insn; + bool ok; + + inv = invariants[def->invno]; + /* No need to check if address expression is expensive. */ + if (!inv->cheap_address) + return true; + + def_insn = inv->insn; + def_set = single_set (def_insn); + if (!def_set) + return true; + + validate_unshare_change (use_insn, pos, SET_SRC (def_set), true); + ok = verify_changes (0); + cancel_changes (0); + return !ok; +} + /* Record USE at DEF. */ static void @@ -777,7 +807,11 @@ record_use (struct def *def, df_ref use) def->uses = u; def->n_uses++; if (u->addr_use_p) - def->n_addr_uses++; + { + def->n_addr_uses++; + if (!def->cant_prop_to_addr_uses && inv_cant_prop_to_addr_use (def, use)) + def->cant_prop_to_addr_uses = true; + } } /* Finds the invariants USE depends on and store them to the DEPENDS_ON @@ -1158,7 +1192,9 @@ get_inv_cost (struct invariant *inv, int *comp_cost, unsigned *regs_needed, if (!inv->cheap_address || inv->def->n_uses == 0 - || inv->def->n_addr_uses < inv->def->n_uses) + || inv->def->n_addr_uses < inv->def->n_uses + /* Count cost if the inv can't be propagated into address uses. */ + || inv->def->cant_prop_to_addr_uses) (*comp_cost) += inv->cost * inv->eqno; #ifdef STACK_REGS