From patchwork Thu Dec 28 13:56:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: YunQiang Su X-Patchwork-Id: 82915 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id EBD283858C52 for ; Thu, 28 Dec 2023 13:57:49 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EBD283858C52 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1703771870; bh=uwFJVzIPanjODfcok9DAK/wuMXaBaN88+zBiajLtrxY=; h=From:To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From; b=sfmJdVe3ADvZEKVUPGpPYfoJt0/QXPYMQVoFTd63mK0vMHQhKhca3LAa1zLINPpDS B8FewABTCEx9pbsZPqjze3C6XG40xwRnK44fFQ2H7Pi38mFMpTh4ZeVoCNYhiD9570 NgEu+b8Z8kqcS2Clxs15u1L6IUSOk/FmE6xZHIqY= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.170]) by sourceware.org (Postfix) with ESMTPS id 8619C3858D28; Thu, 28 Dec 2023 13:57:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8619C3858D28 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 8619C3858D28 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=209.85.214.170 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1703771828; cv=none; b=czqIl/Pa48p9tO3E6AT9izO/ud1350crppYP+A0l9ac5bPFpSaNkGR4f6NqCgTsKdNaml4Lw2IP6tqXMfO9o2lJkl990RkdJyyWFex17eskJ7cTLJKxzYYFFLBFD67i0CTiXtikMXB+kyudVpeJiqTx7qQHFW7CaPVnSDVkFMg8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1703771828; c=relaxed/simple; bh=053QeUZnBA8cSZerGhfCJeK1s9M0UQn5IwgT5p6wBaE=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=sjOf0wN3V3/s4INeouSsOBGlI6q1e5k29KPRTrUM7EzVrxhDeIkJRcL7HyS3sFioCx1pK1lmZ8tETB+g4BWOVGjMklKUkAxRQWcF1G6/zcGMe7WxhByyUw4VjurOkUGi4FeCFSnX1yehkqwiBNow1g00kP/6fkK5WoOHNvAeQ1k= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-1d422c9f894so36913785ad.3; Thu, 28 Dec 2023 05:57:06 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703771825; x=1704376625; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=uwFJVzIPanjODfcok9DAK/wuMXaBaN88+zBiajLtrxY=; b=ENV5QsGQpc0ZL8r+jX5Oj9PET8MBPeO5pjciR2u24wL4W1C/uUs8YofqmeY1Jy/P+x OiwBnZLktSgVHfJ0a+xxsOX1IyF8p40/qoZU5XREcMCuGjv0vWt6rxwWaLgP8a93nWQh DXY0uB5wrfTHDmoU1px+9h4iRUuiIB8ZSNCoWAQrr0oB5i3x98R6o1nQQkwS0W0RxeZ3 vY40DcSrOTSA6Ja5TfyliqE7BNnDqQAOlJs76heKq3l1k2gjZfdr05a6q6a2a7uOiIwX nuNJ2owCsLlprydEd11dX0ftSpvjf4+zCZMfajkqSp1lAoNQWvBPCZblIdyfY+8uIi1c 0kOg== X-Gm-Message-State: AOJu0YxvxndwLV51yGj0FfDdw6v876bjQH1tzV1Q8MqKO0AfCIpeW6O7 olD60mI2mkxJ+SeyYCJLHsA/jXHl9+kBv6jq X-Google-Smtp-Source: AGHT+IGpeEgC1Mkwy1YAkJIOcM/GTC2dtdGynf1gE8qEizs8fVBqJO5c05zB55WEXpzCQWV200xEWw== X-Received: by 2002:a17:902:b58b:b0:1d4:1d90:f75b with SMTP id a11-20020a170902b58b00b001d41d90f75bmr11564082pls.17.1703771824532; Thu, 28 Dec 2023 05:57:04 -0800 (PST) Received: from localhost.localdomain ([149.248.38.156]) by smtp.gmail.com with ESMTPSA id y11-20020a1709027c8b00b001c755810f89sm13991724pll.181.2023.12.28.05.57.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Dec 2023 05:57:04 -0800 (PST) From: YunQiang Su To: gcc-patches@gcc.gnu.org Cc: YunQiang Su Subject: [PATCH] MIPS: Implement TARGET_INSN_COSTS Date: Thu, 28 Dec 2023 21:56:31 +0800 Message-Id: <20231228135631.3581609-1-syq@gcc.gnu.org> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-Spam-Status: No, score=-11.1 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, 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 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+patchwork=sourceware.org@gcc.gnu.org MIPS backend had some information about INSN, including length, count etc. And since some instructions are more costly, let's add a new attr `perf_ratio`. It's default value is (const_int 1). The return value of mips_insn_cost is insn_count * perf_ratio * 4. The magic `4` here, is due to that `rtx_cost` returns 4 for simple instructions. gcc * config/mips/mips.cc (mips_insn_cost): New function. TARGET_INSN_COST: defined to mips_insn_cost. * config/mips/mips.md (perf_ratio): New attr. --- gcc/config/mips/mips.cc | 14 ++++++++++++++ gcc/config/mips/mips.md | 4 ++++ 2 files changed, 18 insertions(+) diff --git a/gcc/config/mips/mips.cc b/gcc/config/mips/mips.cc index 9180dbbf843..fddb1519d76 100644 --- a/gcc/config/mips/mips.cc +++ b/gcc/config/mips/mips.cc @@ -4170,6 +4170,18 @@ mips_set_reg_reg_cost (machine_mode mode) } } +/* Implement TARGET_INSN_COSTS. */ + +static int +mips_insn_cost (rtx_insn *x, bool speed ATTRIBUTE_UNUSED) +{ + if (GET_CODE (PATTERN (x)) != SET) + return pattern_cost (PATTERN (x), speed); + return get_attr_insn_count (x) + * get_attr_perf_ratio (x) + * 4; +} + /* Implement TARGET_RTX_COSTS. */ static bool @@ -23069,6 +23081,8 @@ mips_bit_clear_p (enum machine_mode mode, unsigned HOST_WIDE_INT m) #define TARGET_RTX_COSTS mips_rtx_costs #undef TARGET_ADDRESS_COST #define TARGET_ADDRESS_COST mips_address_cost +#undef TARGET_INSN_COST +#define TARGET_INSN_COST mips_insn_cost #undef TARGET_NO_SPECULATION_IN_DELAY_SLOTS_P #define TARGET_NO_SPECULATION_IN_DELAY_SLOTS_P mips_no_speculation_in_delay_slots_p diff --git a/gcc/config/mips/mips.md b/gcc/config/mips/mips.md index 0666310734e..d6c4ba13f47 100644 --- a/gcc/config/mips/mips.md +++ b/gcc/config/mips/mips.md @@ -312,6 +312,10 @@ (define_attr "sync_insn2" "nop,and,xor,not" ;; "11" specifies MEMMODEL_ACQUIRE. (define_attr "sync_memmodel" "" (const_int 10)) +;; Performance ratio. Used by mips_insn_cost: it returns insn_count*perf_ratio*4. +;; Add this attr to the slow INSNs. +(define_attr "perf_ratio" "" (const_int 1)) + ;; Accumulator operand for madd patterns. (define_attr "accum_in" "none,0,1,2,3,4,5" (const_string "none"))