From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lf1-x130.google.com (mail-lf1-x130.google.com [IPv6:2a00:1450:4864:20::130]) by sourceware.org (Postfix) with ESMTPS id 476323858C31 for ; Mon, 15 May 2023 12:23:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 476323858C31 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-lf1-x130.google.com with SMTP id 2adb3069b0e04-4f26f437b30so5519319e87.1 for ; Mon, 15 May 2023 05:23:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1684153419; x=1686745419; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=tazlFXEXmsZx1k3ZqrpqCIBRpJbGFB+AQIRK1Yx1ob0=; b=lYGxmIGeBhT6o4S2xFex3ZQIO0GJrokwDluCwyqLUoTqMjuR4BJ+BkHgwDIa7i19GP mrn7meZGlRiRSSikY0A2f1N08BUj+s11upUMCMSAA2hKy4wSejEXK+zTmqSOWuLGQq+/ SPlzes6MG5zBxEEnGuGmxXGVgPJtTDeraFq31Y8aL1cFdcSyxoydmRrsuBPn3kfpbx0A 2VgC7xzPkPQ5J+0Ypfj/rt02gfGIZrvaa2Mjx0mBT1HCgCHYB98yx7oQc6eLS6vXtxQV Xj8bUzMVlXD+lAalSLGx15a5p9w2QMAjBpVTksjSf9+94bRdGEp1Vgug3lOzML5rqHDi XiRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684153419; x=1686745419; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=tazlFXEXmsZx1k3ZqrpqCIBRpJbGFB+AQIRK1Yx1ob0=; b=WqcgTUKR6NioQ3gd6mv8vgpQntLUgV4ZfaiYzjEu06kIXL8RSAK+SrAZM6JFEYuaqk RSk40ad2PKYl70cmmRnyZQ1Q1EJndGXprOUmELSFMs0xTrm6e8EwLnhwnjLa1f5hRBs/ EsdXUCLiEKw38AmO09iatzxGK9EgTofS7cwDuUudYMwOQVbHUtcfFrCOMHsCYV5jsRFs Sg357rMuHafCFJ9gDqujn0iCBd6IoYTzkjwCeNcNxX1NhSlO9818FwxsvnvRUW3PBcqi KBO5KctHpSehw/mdoX3LK6pjML2fefY0qhG1QYJmGYZJldnGoMXynpD1MoBg4FsRLfTI +N5g== X-Gm-Message-State: AC+VfDyumVPTN1FAg4U3G2McQoi20htVHN34R4MYzPQyN+G6aVB1l/AL b+1XL5Vtl8RUUdfNbl4dvzy7vg4ELJNiFNSuz9Y= X-Google-Smtp-Source: ACHHUZ5BPmOYHj/GI7h4GxVc0slNtIL9VMWje1ooDBLeegVKKH8KaIKCLv0PWWoPLB+KpnAeKldFbrnr3LJniiBrzqM= X-Received: by 2002:a19:7008:0:b0:4f1:42ea:c242 with SMTP id h8-20020a197008000000b004f142eac242mr6553256lfc.3.1684153418437; Mon, 15 May 2023 05:23:38 -0700 (PDT) MIME-Version: 1.0 References: <20221221131214.190579-1-dimitrije.milosevic@syrmia.com> <20221221131214.190579-3-dimitrije.milosevic@syrmia.com> In-Reply-To: From: Richard Biener Date: Mon, 15 May 2023 14:23:26 +0200 Message-ID: Subject: Re: [PATCH 2/2] ivopts: Revert register pressure cost when there are enough registers. To: =?UTF-8?B?RGltaXRyaWplIE1pbG/FoWV2acSH?= Cc: gcc-patches@gcc.gnu.org, djordje.todorovic@syrmia.com, jeffreyalaw@gmail.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Mon, May 15, 2023 at 12:44=E2=80=AFPM Richard Biener wrote: > > On Wed, Dec 21, 2022 at 2:12=E2=80=AFPM Dimitrije Milo=C5=A1evi=C4=87 > wrote: > > > > When there are enough registers, the register pressure cost is > > unnecessarily bumped by adding another n_cands. > > > > This behavior may result in register pressure costs for the case > > when there are enough registers being higher than for other cases. > > > > When there are enough registers, the register pressure cost should be > > equal to n_invs + n_cands. > > > > This used to be the case before c18101f. > > > > gcc/ChangeLog: > > > > * tree-ssa-loop-ivopts.cc (ivopts_estimate_reg_pressure): Adjus= t. > > > > Signed-off-by: Dimitrije Milosevic > > --- > > gcc/tree-ssa-loop-ivopts.cc | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/gcc/tree-ssa-loop-ivopts.cc b/gcc/tree-ssa-loop-ivopts.cc > > index 60c61dc9e49..3176482d0d9 100644 > > --- a/gcc/tree-ssa-loop-ivopts.cc > > +++ b/gcc/tree-ssa-loop-ivopts.cc > > @@ -6092,7 +6092,7 @@ ivopts_estimate_reg_pressure (struct ivopts_data = *data, unsigned n_invs, > > > > /* If we have enough registers. */ > > if (regs_needed + target_res_regs < available_regs) > > - cost =3D n_new; > > + return n_new; > > This still doesn't make much sense (before nor after). We're > comparing apples and oranges. > > I think it would make most sense to merge this case with the following > and thus do > the following. The distinction between the cases should be preserved > and attenuated > by the adding of n_cands at the end (as tie-breaker). > > Does this help the mips case? I'm going to throw it at x86_64-linux > bootstrap/regtest. > > Btw, I don't think using address complexity makes much sense for a port t= hat > has only one addressing mode so I guess a better approach for 1/2 would b= e > to make sure it is consistently the same value (I suppose it is not, othe= rwise > you wouldn't have changed it). Oh, and we're adding the > reg-pressure cost to the same bucket as well, and there we don't really k= now > how many times we're going to spill. That said, I think ->complexity sho= uld > rather go away - we are asking for address-cost already and IVOPTs uses > built RTX to query the target. > > But yes, I agree ivopts_estimate_reg_pressure has an issue. > > Sorry for the very long delay, > Richard. The patch below bootstraps and regtests ok on x86_64-unknown-linux-gnu, but I guess that doesn't mean much. Richard. > diff --git a/gcc/tree-ssa-loop-ivopts.cc b/gcc/tree-ssa-loop-ivopts.cc > index 6fbd2d59318..bc8493622de 100644 > --- a/gcc/tree-ssa-loop-ivopts.cc > +++ b/gcc/tree-ssa-loop-ivopts.cc > @@ -6077,8 +6077,9 @@ ivopts_estimate_reg_pressure (struct ivopts_data > *data, unsigned n_invs, > unsigned n_cands) > { > unsigned cost; > - unsigned n_old =3D data->regs_used, n_new =3D n_invs + n_cands; > - unsigned regs_needed =3D n_new + n_old, available_regs =3D target_avai= l_regs; > + unsigned n_old =3D data->regs_used; > + unsigned regs_needed =3D n_invs + n_cands + n_old; > + unsigned available_regs =3D target_avail_regs; > bool speed =3D data->speed; > > /* If there is a call in the loop body, the call-clobbered registers > @@ -6087,10 +6088,7 @@ ivopts_estimate_reg_pressure (struct > ivopts_data *data, unsigned n_invs, > available_regs =3D available_regs - target_clobbered_regs; > > /* If we have enough registers. */ > - if (regs_needed + target_res_regs < available_regs) > - cost =3D n_new; > - /* If close to running out of registers, try to preserve them. */ > - else if (regs_needed <=3D available_regs) > + if (regs_needed <=3D available_regs) > cost =3D target_reg_cost [speed] * regs_needed; > /* If we run out of available registers but the number of candidates > does not, we penalize extra registers using target_spill_cost. */ > > > > /* If close to running out of registers, try to preserve them. */ > > else if (regs_needed <=3D available_regs) > > cost =3D target_reg_cost [speed] * regs_needed; > > -- > > 2.25.1 > >