From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp2.axis.com (smtp2.axis.com [195.60.68.18]) by sourceware.org (Postfix) with ESMTPS id 841C73858D3C for ; Wed, 29 Mar 2023 22:57:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 841C73858D3C Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=axis.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=axis.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=axis.com; q=dns/txt; s=axis-central1; t=1680130650; x=1711666650; h=from:to:subject:mime-version:content-transfer-encoding: message-id:date; bh=IC6T+AWFtZ/x2xY6b2ARTIBcpvnZ71NejviVDZlQrYU=; b=mG6blYHmQase2lwVWiZCEalzkRt+tXl2kXU8SCwJWx8j5HfKslUWz6zX zJr72lno0WlT5FvrNpoUXtg4BzhHOE+1Nh7trDNxeCmI3ledfkAlH17rj x4U7fJV0bNvNVQBCkOdXZ5QWksks7tbZiT4fBPz1ufHF7Yc9Y9obq28ux 6T2idvCzL1uA26tH+phJZ5O/7QzeFLmJb4xb1w6pK1JSg9mN2Ydnwxoim 5TdMJa5fupupmvt34LOGH6m9pjQXLnj2O14ABqQmfFOhga88jmQOxR3/D KokOcDLo5s2c5Ebz2+3AFR9Fyz1bTWYJXjp1LxWQJXKq6iCvYwpamzSlU A==; From: Hans-Peter Nilsson To: Subject: [committed] CRIS: Make rtx-cost 0 for many CONST_INT "quick" operands MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 8BIT Message-ID: <20230329225727.2D86420433@pchp3.se.axis.com> Date: Thu, 30 Mar 2023 00:57:27 +0200 X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,SPF_HELO_PASS,SPF_PASS,TXREP 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: Stepping through a gdb session inspecting costs that cause gcc.dg/tree-ssa/slsr-13.c to fail, exposed that before this patch, cris_rtx_costs told that a shift of 1 of a register costs 5, while adding two registers costs 4. Making the cost of a quick-immediate constant equal to using a register (default 0) reflects actual performance and size-cost better. It also happens to make gcc.dg/tree-ssa/slsr-13.c pass with what looks like better code being generated, and improves coremark performance by 0.4%. But, blindly doing this for *all* valid operands that fit the "quick-immediate" addressing mode, trips interaction with other factors*, with the end result mixed at best. So, do this only for MINUS and logical operations for the time being, and only for modes that fit in one register. *) Examples of "other factors": - A bad default implementation of insn_cost or actually, pattern_cost, that looks only at the set_src_cost and furthermore sees such a cost of 0 as invalid. (Compare to the more sane set_rtx_cost.) This naturally tripped up combine and ifcvt, causing all sorts of changes, good and bad. - Having the same cost, to compare a register with 0 as with -31..31, means a compare insn of an eliminable form no longer looks preferable. * config/cris/cris.cc (cris_rtx_costs) [CONST_INT]: Return 0 for many quick operands, for register-sized modes. --- gcc/config/cris/cris.cc | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/gcc/config/cris/cris.cc b/gcc/config/cris/cris.cc index 641e7ea25fb1..05dead9c0778 100644 --- a/gcc/config/cris/cris.cc +++ b/gcc/config/cris/cris.cc @@ -1884,7 +1884,28 @@ cris_rtx_costs (rtx x, machine_mode mode, int outer_code, int opno, if (val == 0) *total = 0; else if (val < 32 && val >= -32) - *total = 1; + switch (outer_code) + { + /* For modes that fit in one register we tell they cost + the same as with register operands. DImode operations + needs careful consideration for more basic reasons: + shifting by a non-word-size amount needs more + operations than an addition by a register pair. + Deliberately excluding SET, PLUS and comparisons and + also not including the full -64..63 range for (PLUS + and) MINUS. */ + case MINUS: case ASHIFT: case LSHIFTRT: + case ASHIFTRT: case AND: case IOR: + if (GET_MODE_SIZE(mode) <= UNITS_PER_WORD) + { + *total = 0; + break; + } + /* FALL THROUGH. */ + default: + *total = 1; + break; + } /* Eight or 16 bits are a word and cycle more expensive. */ else if (val <= 32767 && val >= -32768) *total = 2; -- 2.30.2