From patchwork Wed Jun 11 10:05:17 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhenqiang Chen X-Patchwork-Id: 31751 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-yh0-f69.google.com (mail-yh0-f69.google.com [209.85.213.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 5FC982054B for ; Wed, 11 Jun 2014 10:05:36 +0000 (UTC) Received: by mail-yh0-f69.google.com with SMTP id b6sf21704739yha.4 for ; Wed, 11 Jun 2014 03:05:36 -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=et8EPyACsmy3FSYeCLrpMySr814YXD+a4pfMh1wnhOw=; b=euEth5qWuddYvnMNBfgQNwmRl6O65fRaD1Zk7wYwY1jnwlqNEaIWAcZ2eqlfavYU+5 VSN0NkuhiDbLZ0Fa6lRc2PfCrnQZRlUQZC4+GKg4oUUKOILyk/oI1TYYWZCqya2Yp/su 5NDIBPCkfkq9wWFaTNSErodwzqSznA7Jk81zaWUdHKrIom9rcJy1bZE1ZXrxPf/4qSIL DETDP3ndXemSEreFbS1wvycvWLsHq3rkLRaaYQIngfsNfSiRhho1Bue39ngbYPaadbWl SOWxfSS0jgFTXDEyfxka/ZAf38hL7gSj2BtXvjA7283NYoQIrpxCfQF4KOCD8a7yaon2 qJTw== X-Gm-Message-State: ALoCoQkdtD0gIy4D6C5FJ+j2CS+E1uRdM0YRGtdSkA71DKZuQH5znW/achWZD9rbDpbnvyCi1UB1 X-Received: by 10.236.124.240 with SMTP id x76mr1537566yhh.27.1402481136065; Wed, 11 Jun 2014 03:05:36 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.24.181 with SMTP id 50ls2437190qgr.92.gmail; Wed, 11 Jun 2014 03:05:35 -0700 (PDT) X-Received: by 10.52.121.19 with SMTP id lg19mr930253vdb.54.1402481135922; Wed, 11 Jun 2014 03:05:35 -0700 (PDT) Received: from mail-ve0-x229.google.com (mail-ve0-x229.google.com [2607:f8b0:400c:c01::229]) by mx.google.com with ESMTPS id mb10si12805912vcb.59.2014.06.11.03.05.35 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 11 Jun 2014 03:05:35 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2607:f8b0:400c:c01::229 as permitted sender) client-ip=2607:f8b0:400c:c01::229; Received: by mail-ve0-f169.google.com with SMTP id pa12so4082449veb.14 for ; Wed, 11 Jun 2014 03:05:35 -0700 (PDT) X-Received: by 10.52.52.168 with SMTP id u8mr2511646vdo.25.1402481135796; Wed, 11 Jun 2014 03:05:35 -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.54.6 with SMTP id vs6csp290083vcb; Wed, 11 Jun 2014 03:05:35 -0700 (PDT) X-Received: by 10.66.250.161 with SMTP id zd1mr12094053pac.61.1402481134517; Wed, 11 Jun 2014 03:05:34 -0700 (PDT) Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id qs6si37522995pbc.21.2014.06.11.03.05.34 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Jun 2014 03:05:34 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-369981-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Received: (qmail 15446 invoked by alias); 11 Jun 2014 10:05:22 -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 15429 invoked by uid 89); 11 Jun 2014 10:05:22 -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-f52.google.com Received: from mail-la0-f52.google.com (HELO mail-la0-f52.google.com) (209.85.215.52) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Wed, 11 Jun 2014 10:05:21 +0000 Received: by mail-la0-f52.google.com with SMTP id s18so4733052lam.11 for ; Wed, 11 Jun 2014 03:05:17 -0700 (PDT) MIME-Version: 1.0 X-Received: by 10.112.63.194 with SMTP id i2mr2205476lbs.10.1402481117463; Wed, 11 Jun 2014 03:05:17 -0700 (PDT) Received: by 10.112.13.36 with HTTP; Wed, 11 Jun 2014 03:05:17 -0700 (PDT) In-Reply-To: References: Date: Wed, 11 Jun 2014 18:05:17 +0800 Message-ID: Subject: Re: [PATCH, loop2_invariant, 1/2] Check only one register class From: Zhenqiang Chen To: Steven Bosscher 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::229 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:06, Steven Bosscher wrote: > On Tue, Jun 10, 2014 at 11:22 AM, Zhenqiang Chen wrote: >> Hi, >> >> For loop2-invariant pass, when flag_ira_loop_pressure is enabled, >> function gain_for_invariant checks the pressures of all register >> classes. This does not make sense since one invariant might impact >> only one register class. >> >> The patch enhances functions get_inv_cost and gain_for_invariant to >> check only the register pressure of the invariant if possible. > > This patch may work for targets with more-or-less orthogonal reg > classes, but not if there is a lot of overlap between reg classes. Yes. I need check the overlap between reg classes. Patch is updated to check all overlap reg classes by reg_classes_intersect_p: if (! flag_ira_loop_pressure) @@ -1129,6 +1135,8 @@ get_inv_cost (struct invariant *inv, int *comp_cost, unsigned *regs_needed) pressure_class = get_pressure_class_and_nregs (inv->insn, &nregs); regs_needed[pressure_class] += nregs; + *cl = pressure_class; + ret = 1; } if (!inv->cheap_address @@ -1169,6 +1177,8 @@ get_inv_cost (struct invariant *inv, int *comp_cost, unsigned *regs_needed) EXECUTE_IF_SET_IN_BITMAP (inv->depends_on, 0, depno, bi) { bool check_p; + enum reg_class dep_cl = ALL_REGS; + int dep_ret; dep = invariants[depno]; @@ -1176,7 +1186,7 @@ get_inv_cost (struct invariant *inv, int *comp_cost, unsigned *regs_needed) if (dep->move) continue; - get_inv_cost (dep, &acomp_cost, aregs_needed); + dep_ret = get_inv_cost (dep, &acomp_cost, aregs_needed, &dep_cl); if (! flag_ira_loop_pressure) check_p = aregs_needed[0] != 0; @@ -1186,6 +1196,12 @@ get_inv_cost (struct invariant *inv, int *comp_cost, unsigned *regs_needed) if (aregs_needed[ira_pressure_classes[i]] != 0) break; check_p = i < ira_pressure_classes_num; + + if ((dep_ret > 1) || ((dep_ret == 1) && (*cl != dep_cl))) + { + *cl = ALL_REGS; + ret ++; + } } if (check_p /* We need to check always_executed, since if the original value of @@ -1219,6 +1235,7 @@ get_inv_cost (struct invariant *inv, int *comp_cost, unsigned *regs_needed) } (*comp_cost) += acomp_cost; } + return ret; } /* Calculates gain for eliminating invariant INV. REGS_USED is the number @@ -1233,10 +1250,12 @@ gain_for_invariant (struct invariant *inv, unsigned *regs_needed, bool speed, bool call_p) { int comp_cost, size_cost; + enum reg_class cl; + int ret; actual_stamp++; - get_inv_cost (inv, &comp_cost, regs_needed); + ret = get_inv_cost (inv, &comp_cost, regs_needed, &cl); if (! flag_ira_loop_pressure) { @@ -1245,6 +1264,11 @@ gain_for_invariant (struct invariant *inv, unsigned *regs_needed, - estimate_reg_pressure_cost (new_regs[0], regs_used, speed, call_p)); } + else if (ret == 0) + return -1; + else if ((ret == 1) && (cl == NO_REGS)) + /* Hoist it anyway since it does not impact register pressure. */ + return 1; else { int i; @@ -1253,6 +1277,10 @@ gain_for_invariant (struct invariant *inv, unsigned *regs_needed, for (i = 0; i < ira_pressure_classes_num; i++) { pressure_class = ira_pressure_classes[i]; + + if (!reg_classes_intersect_p (pressure_class, cl)) + continue; + if ((int) new_regs[pressure_class] + (int) regs_needed[pressure_class] + LOOP_DATA (curr_loop)->max_reg_pressure[pressure_class] diff --git a/gcc/loop-invariant.c b/gcc/loop-invariant.c index c76a2a0..6e43b49 100644 --- a/gcc/loop-invariant.c +++ b/gcc/loop-invariant.c @@ -1092,16 +1092,22 @@ get_pressure_class_and_nregs (rtx insn, int *nregs) } /* Calculates cost and number of registers needed for moving invariant INV - out of the loop and stores them to *COST and *REGS_NEEDED. */ + out of the loop and stores them to *COST and *REGS_NEEDED. *CL will be + the REG_CLASS of INV. Return + 0: if INV is invalid. + 1: if INV and its depends_on have same reg_class + > 1: if INV and its depends_on have different reg_classes. */ -static void -get_inv_cost (struct invariant *inv, int *comp_cost, unsigned *regs_needed) +static int +get_inv_cost (struct invariant *inv, int *comp_cost, unsigned *regs_needed, + enum reg_class *cl) { int i, acomp_cost; unsigned aregs_needed[N_REG_CLASSES]; unsigned depno; struct invariant *dep; bitmap_iterator bi; + int ret = 2; /* Find the representative of the class of the equivalent invariants. */ inv = invariants[inv->eqto]; @@ -1117,7 +1123,7 @@ get_inv_cost (struct invariant *inv, int *comp_cost, unsigned *regs_needed) if (inv->move || inv->stamp == actual_stamp) - return; + return 0; inv->stamp = actual_stamp;