From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by sourceware.org (Postfix) with ESMTP id 636973857C63 for ; Thu, 15 Jul 2021 20:42:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 636973857C63 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id E91CE31B; Thu, 15 Jul 2021 13:42:53 -0700 (PDT) Received: from localhost (e121540-lin.manchester.arm.com [10.32.98.126]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 739093F694; Thu, 15 Jul 2021 13:42:53 -0700 (PDT) From: Richard Sandiford To: Robin Dapp Mail-Followup-To: Robin Dapp , gcc-patches@gcc.gnu.org, richard.sandiford@arm.com Cc: gcc-patches@gcc.gnu.org Subject: Re: [PATCH 3/7] ifcvt: Improve costs handling for noce_convert_multiple. References: <20210625160905.23786-1-rdapp@linux.ibm.com> <20210625160905.23786-4-rdapp@linux.ibm.com> Date: Thu, 15 Jul 2021 21:42:52 +0100 In-Reply-To: <20210625160905.23786-4-rdapp@linux.ibm.com> (Robin Dapp's message of "Fri, 25 Jun 2021 18:09:01 +0200") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 15 Jul 2021 20:42:56 -0000 Robin Dapp writes: > When noce_convert_multiple is called the original costs are not yet > initialized. Therefore, up to now, costs were only ever unfairly > compared against COSTS_N_INSNS (2). This would lead to > default_noce_conversion_profitable_p () rejecting all but the most > contrived of sequences. > > This patch temporarily initialized the original costs by counting > a compare and all the sets inside the then_bb. > --- > gcc/ifcvt.c | 30 ++++++++++++++++++++++++++---- > 1 file changed, 26 insertions(+), 4 deletions(-) > > diff --git a/gcc/ifcvt.c b/gcc/ifcvt.c > index 6006055f26a..ac0c142c9fe 100644 > --- a/gcc/ifcvt.c > +++ b/gcc/ifcvt.c > @@ -3382,14 +3382,17 @@ noce_convert_multiple_sets (struct noce_if_info *= if_info) > (SET (REG) (REG)) insns suitable for conversion to a series > of conditional moves. Also check that we have more than one set > (other routines can handle a single set better than we would), and > - fewer than PARAM_MAX_RTL_IF_CONVERSION_INSNS sets. */ > + fewer than PARAM_MAX_RTL_IF_CONVERSION_INSNS sets. While going > + through the insns store the sum of their potential costs in COST. */ >=20=20 > static bool > -bb_ok_for_noce_convert_multiple_sets (basic_block test_bb) > +bb_ok_for_noce_convert_multiple_sets (basic_block test_bb, unsigned *cos= t) > { > rtx_insn *insn; > unsigned count =3D 0; > unsigned param =3D param_max_rtl_if_conversion_insns; > + bool speed_p =3D optimize_bb_for_speed_p (test_bb); > + unsigned potential_cost =3D 0; >=20=20 > FOR_BB_INSNS (test_bb, insn) > { > @@ -3425,9 +3428,13 @@ bb_ok_for_noce_convert_multiple_sets (basic_block = test_bb) > if (!can_conditionally_move_p (GET_MODE (dest))) > return false; >=20=20 > + potential_cost +=3D pattern_cost (set, speed_p); > + It looks like this is an existing (potential) problem, but default_noce_conversion_profitable_p uses seq_cost, which in turn uses insn_cost. And insn_cost has an optional target hook behind it, which allows for costing based on insn attributes etc. For a true apples-with-apples comparison we should use insn_cost here too. > count++; > } >=20=20 > + *cost +=3D potential_cost; > + > /* If we would only put out one conditional move, the other strategies > this pass tries are better optimized and will be more appropriate. > Some targets want to strictly limit the number of conditional moves > @@ -3475,11 +3482,23 @@ noce_process_if_block (struct noce_if_info *if_in= fo) > to calculate a value for x. > ??? For future expansion, further expand the "multiple X" rules. */ >=20=20 > - /* First look for multiple SETS. */ > + /* First look for multiple SETS. The original costs already > + include a compare that we will be needing either way. I think the detail that COSTS_N_INSNS (2) is the default is useful here. (In other words, I'd forgotten by the time I'd poked around other bits of ifcvt and was about to ask why we didn't cost the condition =E2=80=9Cproper= ly=E2=80=9D.) So how about something like: The original costs already include a base cost of COSTS_N_INSNS (2): one instruction for the compare (which we will be needing either way) and one instruction for the branch. > + When > + comparing costs we want to use the branch instruction cost and > + the sets vs. the cmovs generated here. Therefore subtract > + the costs of the compare before checking. > + ??? Actually, instead of the branch instruction costs we might want > + to use COSTS_N_INSNS (BRANCH_COST ()) as in other places.*/ Hmm, not sure about the ??? either way. The units of BRANCH_COST aren't entirely clear. But it's a ???, so keeping it is fine. Formatting nit: should be two spaces between =E2=80=9C.=E2=80=9D and =E2=80= =9C*/=E2=80=9D. Looks good otherwise, thanks. Richard > + > + unsigned potential_cost =3D if_info->original_cost - COSTS_N_INSNS (1); > + unsigned old_cost =3D if_info->original_cost; > if (!else_bb > && HAVE_conditional_move > - && bb_ok_for_noce_convert_multiple_sets (then_bb)) > + && bb_ok_for_noce_convert_multiple_sets (then_bb, &potential_cost)) > { > + /* Temporarily set the original costs to what we estimated so > + we can determine if the transformation is worth it. */ > + if_info->original_cost =3D potential_cost; > if (noce_convert_multiple_sets (if_info)) > { > if (dump_file && if_info->transform_name) > @@ -3487,6 +3506,9 @@ noce_process_if_block (struct noce_if_info *if_info) > if_info->transform_name); > return TRUE; > } > + > + /* Restore the original costs. */ > + if_info->original_cost =3D old_cost; > } >=20=20 > bool speed_p =3D optimize_bb_for_speed_p (test_bb);