From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate.crashing.org (gate.crashing.org [63.228.1.57]) by sourceware.org (Postfix) with ESMTP id 52DDA3857C61 for ; Fri, 24 Jul 2020 12:25:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 52DDA3857C61 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=kernel.crashing.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=segher@kernel.crashing.org Received: from gate.crashing.org (localhost.localdomain [127.0.0.1]) by gate.crashing.org (8.14.1/8.14.1) with ESMTP id 06OCPTHK017975 for ; Fri, 24 Jul 2020 07:25:29 -0500 Received: (from segher@localhost) by gate.crashing.org (8.14.1/8.14.1/Submit) id 06OCPTeZ017974 for gcc-patches@gcc.gnu.org; Fri, 24 Jul 2020 07:25:29 -0500 X-Authentication-Warning: gate.crashing.org: segher set sender to segher@kernel.crashing.org using -f Date: Fri, 24 Jul 2020 07:25:29 -0500 From: Segher Boessenkool To: gcc-patches@gcc.gnu.org Subject: Re: [PATCH 4/5] MSP430: Implement TARGET_INSN_COST Message-ID: <20200724122529.GN32057@gate.crashing.org> References: <20200723154356.63ws2xairlmdufji@jozef-acer-manjaro> <20200723155614.jqjgkqtdrnwjahxo@jozef-acer-manjaro> <20200723183422.GE32057@gate.crashing.org> <20200724115048.fqz65oo7azxhtwtq@jozef-acer-manjaro> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200724115048.fqz65oo7azxhtwtq@jozef-acer-manjaro> User-Agent: Mutt/1.4.2.3i X-Spam-Status: No, score=-9.4 required=5.0 tests=BAYES_00, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_NONE, TXREP, T_SPF_HELO_PERMERROR, T_SPF_PERMERROR autolearn=no autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: Fri, 24 Jul 2020 12:25:32 -0000 Hi Jozef, On Fri, Jul 24, 2020 at 12:50:48PM +0100, Jozef Lawrynowicz wrote: > On Thu, Jul 23, 2020 at 01:34:22PM -0500, Segher Boessenkool wrote: > > On Thu, Jul 23, 2020 at 04:56:14PM +0100, Jozef Lawrynowicz wrote: > > > + /* The returned cost must be relative to COSTS_N_INSNS (1). An insn with a > > > + length of 2 bytes is the smallest possible size and so must be equivalent > > > + to COSTS_N_INSNS (1). */ > > > + return COSTS_N_INSNS (cost) / (2 * COSTS_N_INSNS (1)); > > > > This is the same as "cost / 2", so "length / 2" here, which doesn't look > > right. The returned value should have the same "unit" as COSTS_N_INSNS > > does, so maybe you want COSTS_N_INSNS (length / 2) ? > > Indeed it looks like I made a thinko in that calculation in TARGET_INSN_COSTS; > trying to make it verbose to show the thought behind the calculation backfired > :) > > Fixing it to return "COSTS_N_INSNS (length / 2)" actually made codesize > noticeably worse for most of my benchmarks. > I had to define BRANCH_COST to indicate branches are not cheap. > > In the original patch a cheap instruction would have a cost of 1. > When using the default BRANCH_COST of 1 to calculate the cost of a branch > compared to an insn (e.g. in ifcvt.c), BRANCH_COST would be wrapped in > COSTS_N_INSNS, scaling the cost to 4, which suitably disparaged > it vs the cheap insn cost of 1. > > With the fixed insn_cost calculation, a cheap instruction would cost 4 > with the COSTS_N_INSNS scaling, and a branch would cost the same, which is not > right. There isn't much you can do to battle the "default" cost of 4 -- this is pervasive throughout the compiler -- so it is much easier to go with the flow. > > It is already printed in the generated asm with -dp? Not sure if you > > want more detail than that. > > > > '-dp' > > Annotate the assembler output with a comment indicating which > > pattern and alternative is used. The length and cost of each > > instruction are also printed. > > > > During development I found it useful to see the insns in RTL format and their > costs alongside that. In hindsight, it doesn't really have much use in the > finalized patch, so I've removed it. There is -dP for that (capital P) :-) It isn't very pretty, not sure how that could be improved? > +/* The cost of a branch sequence is roughly 3 "cheap" instructions. */ > +#define BRANCH_COST(speed_p, predictable_p) 3 > + > +/* Override the default BRANCH_COST heuristic to indicate that it is preferable > + to retain short-circuit operations, this results in significantly better > + codesize and performance. */ > +#define LOGICAL_OP_NON_SHORT_CIRCUIT 0 That looks just fine :-) Segher