From patchwork Tue Jul 1 07:16:20 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhenqiang Chen X-Patchwork-Id: 32843 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-oa0-f71.google.com (mail-oa0-f71.google.com [209.85.219.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 5EC8D20672 for ; Tue, 1 Jul 2014 07:16:41 +0000 (UTC) Received: by mail-oa0-f71.google.com with SMTP id n16sf58570272oag.10 for ; Tue, 01 Jul 2014 00:16:41 -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=N81QD7y6mxWc4nP9faBOhiS+aeiQj5eVkxnFyMUShrw=; b=CkgE9qR9UFvTWMLnnWKBgoOv9rzALFu1AUah+JbqDp6LEBnGeU3YhR0a3HOmJ8ihOf R/jc4lKe5RwS69XFBg+lPzKeG6PlquDXYqAyrZ6D/8WPyfLjEiYx8jU0XinbRD2Hs4gs pjvf1e/PfOXroVRCc1IJ9jGp8MsRTh0Rw47AZEySpHkYOSKq8dvtLRRovSvjkqqWp0WQ +Nx35iXDNupYN2KMu9iFnX+nekH4VW7cgAVlDjdSFtNQ+v1yLd9W4ubqW6iL+9Z/7gbn hzl6txYktRbBS5KStuOH+lkO5GDGiWVoPWUHSLqjS9LmNvxcjFugw7c5vBnE5L0yGFnJ cS7Q== X-Gm-Message-State: ALoCoQkl6AjMNogwFqJU28O6gPPT5tFq2o7rSdSqqMxqvWXmWv2/ysqJZVEFnUNo/wBxZ4K3sPR8 X-Received: by 10.42.85.142 with SMTP id q14mr22593515icl.16.1404199001585; Tue, 01 Jul 2014 00:16:41 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.16.148 with SMTP id 20ls283084qgb.78.gmail; Tue, 01 Jul 2014 00:16:41 -0700 (PDT) X-Received: by 10.220.103.141 with SMTP id k13mr42691082vco.25.1404199001475; Tue, 01 Jul 2014 00:16:41 -0700 (PDT) Received: from mail-vc0-x231.google.com (mail-vc0-x231.google.com [2607:f8b0:400c:c03::231]) by mx.google.com with ESMTPS id un15si11093315veb.69.2014.07.01.00.16.41 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 01 Jul 2014 00:16:41 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2607:f8b0:400c:c03::231 as permitted sender) client-ip=2607:f8b0:400c:c03::231; Received: by mail-vc0-f177.google.com with SMTP id ij19so8498400vcb.36 for ; Tue, 01 Jul 2014 00:16:41 -0700 (PDT) X-Received: by 10.58.235.130 with SMTP id um2mr2033756vec.18.1404199001343; Tue, 01 Jul 2014 00:16:41 -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.221.37.5 with SMTP id tc5csp195310vcb; Tue, 1 Jul 2014 00:16:40 -0700 (PDT) X-Received: by 10.68.201.226 with SMTP id kd2mr58314014pbc.157.1404199000451; Tue, 01 Jul 2014 00:16:40 -0700 (PDT) Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id gu4si25890821pac.206.2014.07.01.00.16.39 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 01 Jul 2014 00:16:40 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-371557-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Received: (qmail 17748 invoked by alias); 1 Jul 2014 07:16:27 -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 17724 invoked by uid 89); 1 Jul 2014 07:16:26 -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-f54.google.com Received: from mail-la0-f54.google.com (HELO mail-la0-f54.google.com) (209.85.215.54) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Tue, 01 Jul 2014 07:16:24 +0000 Received: by mail-la0-f54.google.com with SMTP id mc6so5670582lab.27 for ; Tue, 01 Jul 2014 00:16:20 -0700 (PDT) MIME-Version: 1.0 X-Received: by 10.112.129.9 with SMTP id ns9mr32241937lbb.23.1404198980654; Tue, 01 Jul 2014 00:16:20 -0700 (PDT) Received: by 10.112.13.36 with HTTP; Tue, 1 Jul 2014 00:16:20 -0700 (PDT) In-Reply-To: References: Date: Tue, 1 Jul 2014 15:16:20 +0800 Message-ID: Subject: Re: [PATCH, loop2_invariant, 2/2] Change heuristics for identical invariants From: Zhenqiang Chen To: Steven Bosscher , 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::231 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 10 June 2014 19:16, Steven Bosscher wrote: > On Tue, Jun 10, 2014 at 11:23 AM, Zhenqiang Chen wrote: >> * loop-invariant.c (struct invariant): Add a new member: eqno; >> (find_identical_invariants): Update eqno; >> (create_new_invariant): Init eqno; >> (get_inv_cost): Compute comp_cost wiht eqno; >> (gain_for_invariant): Take spill cost into account. > > Look OK except ... > >> @@ -1243,7 +1256,13 @@ gain_for_invariant (struct invariant *inv, >> unsigned *regs_needed, >> + IRA_LOOP_RESERVED_REGS >> - ira_class_hard_regs_num[cl]; >> if (size_cost > 0) >> - return -1; >> + { >> + int spill_cost = target_spill_cost [speed] * (int) regs_needed[cl]; >> + if (comp_cost <= spill_cost) >> + return -1; >> + >> + return 2; >> + } >> else >> size_cost = 0; >> } > > ... why "return 2", instead of just falling through to "return > comp_cost - size_cost;"? The updated patch removes the check on spill cost since the check seams not sound and tests show it does not help much on the result. Bootstrap and no make check regression on X86-64. OK for trunk? Thanks! -Zhenqiang ChangeLog: 2014-07-01 Zhenqiang Chen * loop-invariant.c (struct invariant): Add a new member: eqno; (find_identical_invariants): Update eqno; (create_new_invariant): Init eqno; (get_inv_cost): Compute comp_cost wiht eqno; return; @@ -513,7 +517,12 @@ find_identical_invariants (invariant_htab_type *eq, struct invariant *inv) mode = GET_MODE (expr); if (mode == VOIDmode) mode = GET_MODE (SET_DEST (set)); - inv->eqto = find_or_insert_inv (eq, expr, mode, inv)->invno; + + tmp = find_or_insert_inv (eq, expr, mode, inv); + inv->eqto = tmp->invno; + + if (tmp->invno != inv->invno && inv->always_executed) + tmp->eqno++; if (dump_file && inv->eqto != inv->invno) fprintf (dump_file, @@ -722,6 +731,10 @@ create_new_invariant (struct def *def, rtx insn, bitmap depends_on, inv->invno = invariants.length (); inv->eqto = ~0u; + + /* Itself. */ + inv->eqno = 1; + if (def) def->invno = inv->invno; invariants.safe_push (inv); @@ -1136,7 +1149,7 @@ get_inv_cost (struct invariant *inv, int *comp_cost, unsigned *regs_needed, if (!inv->cheap_address || inv->def->n_addr_uses < inv->def->n_uses) - (*comp_cost) += inv->cost; + (*comp_cost) += inv->cost * inv->eqno; #ifdef STACK_REGS { diff --git a/gcc/loop-invariant.c b/gcc/loop-invariant.c index d47d461..bd67eb9 100644 --- a/gcc/loop-invariant.c +++ b/gcc/loop-invariant.c @@ -104,6 +104,9 @@ struct invariant /* The number of the invariant with the same value. */ unsigned eqto; + /* The number of invariants which eqto this. */ + unsigned eqno; + /* If we moved the invariant out of the loop, the register that contains its value. */ rtx reg; @@ -498,6 +501,7 @@ find_identical_invariants (invariant_htab_type *eq, struct invariant *inv) struct invariant *dep; rtx expr, set; enum machine_mode mode; + struct invariant *tmp; if (inv->eqto != ~0u)