From patchwork Mon Oct 14 02:37:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleg Endo X-Patchwork-Id: 1996670 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=WHBME/7R; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XRhJC3MzDz1xsc for ; Mon, 14 Oct 2024 13:39:07 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5526B3856951 for ; Mon, 14 Oct 2024 02:39:05 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pl1-x644.google.com (mail-pl1-x644.google.com [IPv6:2607:f8b0:4864:20::644]) by sourceware.org (Postfix) with ESMTPS id 6622D3858C56 for ; Mon, 14 Oct 2024 02:38:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6622D3858C56 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 6622D3858C56 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::644 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1728873492; cv=none; b=KRkzu+JABZ+2TaEoFxUXeuCISEeNMr3lnqZTtzi1T9em7DjJBafU/1Hfcj8e6uxwTk24dgcdL0nM5K6fYkPuW4RNuRWEJ8PocilBWt51rq1iArFtgu7Rd0GCGFWSzHH3hhU/KuBvxerDiFq8GYEE9vomsZaLMN4X/BbTQqk8lgc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1728873492; c=relaxed/simple; bh=hkSdh4epdYvsiyDpYdeBf0YJzAcD6KtUUAIW39SDNtU=; h=DKIM-Signature:Message-ID:Subject:From:To:Date:MIME-Version; b=mt7hUP91PmqLo/Axo+4KW32zwLdWwfqCdKfqDQWTf0V8AgJILpqP3AkmVycbe8UxhCOZpZInnJCfjkRmKoZliYgBMqYyllb3JPRPw8mLYHNt6wHT8drrgev7ruZAdYvNhyB5qX9E5r8N2m9fPkRTdTeQbV4Lqgz2nh5P89+lUmg= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pl1-x644.google.com with SMTP id d9443c01a7336-20cb89a4e4cso11186305ad.3 for ; Sun, 13 Oct 2024 19:38:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1728873480; x=1729478280; darn=gcc.gnu.org; h=mime-version:user-agent:date:to:from:subject:message-id:from:to:cc :subject:date:message-id:reply-to; bh=lJbLLQkKVXDOnJ5IPCoQF+v/4VQUAiW4ZKv6TXAf1lI=; b=WHBME/7RK1UbVIfT9KUhxKGVLDASYxSKXxYtYsmfvRn17dnN+Hx1vj/aI8BHWn50U4 MLGFlpLY9nOdRDCUGhG5mDDDM/hKOLYWfCE4kPlDQw/OXzTg6NXFMj57oKC0skXDLDQD iWaEzKeITCCkYOXRl3RlXh5C/1E4UkeVTzUbRbZzhzNByslNA/rBQl+6vzwfF0phY2sO bPO7JroNKkfYFLa5p2Xp+5WDayO76BZ/0tOhXXvbfZslKfoo5YwEKp/Y9S4Mueu/C5M/ 2SsNeMWBeCQJwiIEHa4FzMzkdHFErLKLRXNKT7BzKqjhBE7OfCpvIRozjkssWiCJS+yU N4wA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728873480; x=1729478280; h=mime-version:user-agent:date:to:from:subject:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=lJbLLQkKVXDOnJ5IPCoQF+v/4VQUAiW4ZKv6TXAf1lI=; b=idMb6gmSReCYrIlzIsNqpGHmjLgGff/jqIKE5aMfCwt1IpiowNv0wcme1aq41hmAFF TroUk0z+Hs9LNVWUAXHi5HIRESgI0K0Ps9+lJpIvc/gHlpN+uAWE5W9l+nhxgBMr81pT 1IVXYRPlQlWvmaCgJ5yha6/i1ODLLU/mkP/nF/bg7ZS3FJqWwjQ0q7MvjDSpdulB4d2x WtSo98cjRnofIu4/7FhTATtRK3PMwCtGXMnr43ymcsZiPotFkgyQQqj3WH2kdTfFMW+K ftnQweOMX7H3OVD1ZX8R+/nm+SlRBI4UVlbmgSoWKh4zK4a1VY99VaHCYhLOaBqyxIZz gqvQ== X-Gm-Message-State: AOJu0YxfXzOBtKIx3O2jhMxElvCdxds9fn0WyebxoYUwWZ9RcoSPQ68R jKuv8NDV3ABNdJlYsVn/GoqnsyFbk30OxWx2vvflBweYNWfJbdsAZgYrsw4v X-Google-Smtp-Source: AGHT+IGWd1TYSUcmYryTDTycl9+KXI6iv6rBpY80Znt0geuS7dezLwmsKu9lH84X/3VVajhZM/1NIQ== X-Received: by 2002:a17:902:d501:b0:20b:951f:6dff with SMTP id d9443c01a7336-20ca131e652mr142856155ad.0.1728873480133; Sun, 13 Oct 2024 19:38:00 -0700 (PDT) Received: from localhost.localdomain ([2407:c800:3620:e800:7910:9280:8105:5a2]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-20c8c33cc13sm55974085ad.248.2024.10.13.19.37.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 13 Oct 2024 19:37:59 -0700 (PDT) Message-ID: <7f370a21984486ed57cd39b6ab427a1d576604f0.camel@gmail.com> Subject: [SH][committed] PR 113533 From: Oleg Endo To: gcc-patches Date: Mon, 14 Oct 2024 11:37:57 +0900 User-Agent: Evolution 3.50.4 (3.50.4-1.fc39) MIME-Version: 1.0 X-Spam-Status: No, score=-10.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, GIT_PATCH_0, KAM_NUMSUBJECT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org For memory loads/stores (that contain a MEM rtx) sh_rtx_costs would wrongly report a cost lower than 1 insn which is not accurate as it makes loads/stores appear cheaper than simple arithmetic insns. The cost of a load/store insn is at least 1 insn plus the cost of the address expression (some addressing modes can be considered more expensive than others due to additional constraints). Tested with make -k check RUNTESTFLAGS="--target_board=sh-sim\{-m2/-ml,-m2/- mb,-m2a/-mb,-m4/-ml,-m4/-mb,-m4a/-ml,-m4a/-mb}" CSiBE set shows a little bit of +/- code size movement due to some insn reordering. Difficult to judge whether it's all good or bad. Doesn't seem that significant. Thanks to Roger for the original patch proposal. Committed to master. gcc/ChangeLog: PR target/113533 * config/sh/sh.cc (sh_rtx_costs): Adjust cost estimation of MEM rtx to be always at least COST_N_INSNS (1). Forward speed argument to sh_address_cost. From b717c462b96e7870f8081d2bc330e4749a4b0538 Mon Sep 17 00:00:00 2001 From: Oleg Endo Date: Sun, 13 Oct 2024 11:36:38 +0900 Subject: [PATCH] SH: Fix cost estimation of mem load/store For memory loads/stores (that contain a MEM rtx) sh_rtx_costs would wrongly report a cost lower than 1 insn which is not accurate as it makes loads/stores appear cheaper than simple arithmetic insns. The cost of a load/store insn is at least 1 insn plus the cost of the address expression (some addressing modes can be considered more expensive than others due to additional constraints). gcc/ChangeLog: PR target/113533 * config/sh/sh.cc (sh_rtx_costs): Adjust cost estimation of MEM rtx to be always at least COST_N_INSNS (1). Forward speed argument to sh_address_cost. Co-authored-by: Roger Sayle --- gcc/config/sh/sh.cc | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/gcc/config/sh/sh.cc b/gcc/config/sh/sh.cc index 7391b8d..6ad202f 100644 --- a/gcc/config/sh/sh.cc +++ b/gcc/config/sh/sh.cc @@ -3230,9 +3230,9 @@ multcosts (rtx x ATTRIBUTE_UNUSED) scanned. In either case, *TOTAL contains the cost result. */ static bool sh_rtx_costs (rtx x, machine_mode mode ATTRIBUTE_UNUSED, int outer_code, int opno ATTRIBUTE_UNUSED, - int *total, bool speed ATTRIBUTE_UNUSED) + int *total, bool speed) { int code = GET_CODE (x); switch (code) @@ -3263,12 +3263,14 @@ sh_rtx_costs (rtx x, machine_mode mode ATTRIBUTE_UNUSED, int outer_code, return true; } return false; - /* The cost of a mem access is mainly the cost of the address mode. */ + /* The cost of a mem access is mainly the cost of the address mode on top + of the cost of the load/store insn itself. */ case MEM: *total = sh_address_cost (XEXP (x, 0), GET_MODE (x), MEM_ADDR_SPACE (x), - true); + speed) + + COSTS_N_INSNS (1); return true; case IF_THEN_ELSE: /* This case is required for the if_then_else negc pattern. */ @@ -3316,9 +3318,10 @@ sh_rtx_costs (rtx x, machine_mode mode ATTRIBUTE_UNUSED, int outer_code, if (MEM_P (XEXP (x, 0))) { *total = sh_address_cost (XEXP (XEXP (x, 0), 0), GET_MODE (XEXP (x, 0)), - MEM_ADDR_SPACE (XEXP (x, 0)), true); + MEM_ADDR_SPACE (XEXP (x, 0)), speed) + + COSTS_N_INSNS (1); return true; } return false; @@ -3334,9 +3337,10 @@ sh_rtx_costs (rtx x, machine_mode mode ATTRIBUTE_UNUSED, int outer_code, { /* Handle SH2A's movu.b and movu.w insn. */ *total = sh_address_cost (XEXP (XEXP (x, 0), 0), GET_MODE (XEXP (x, 0)), - MEM_ADDR_SPACE (XEXP (x, 0)), true); + MEM_ADDR_SPACE (XEXP (x, 0)), speed) + + COSTS_N_INSNS (1); return true; } return false; @@ -3349,16 +3353,18 @@ sh_rtx_costs (rtx x, machine_mode mode ATTRIBUTE_UNUSED, int outer_code, if (GET_CODE (xx) == SET && MEM_P (XEXP (xx, 0))) { *total = sh_address_cost (XEXP (XEXP (xx, 0), 0), GET_MODE (XEXP (xx, 0)), - MEM_ADDR_SPACE (XEXP (xx, 0)), true); + MEM_ADDR_SPACE (XEXP (xx, 0)), speed); + + COSTS_N_INSNS (1); return true; } if (GET_CODE (xx) == SET && MEM_P (XEXP (xx, 1))) { *total = sh_address_cost (XEXP (XEXP (xx, 1), 0), GET_MODE (XEXP (xx, 1)), - MEM_ADDR_SPACE (XEXP (xx, 1)), true); + MEM_ADDR_SPACE (XEXP (xx, 1)), speed); + + COSTS_N_INSNS (1); return true; } } -- libgit2 1.7.2