From patchwork Thu Jan 4 01:58:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: YunQiang Su X-Patchwork-Id: 184891 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp5370502dyb; Wed, 3 Jan 2024 18:00:21 -0800 (PST) X-Google-Smtp-Source: AGHT+IEw7M2dmzirdjOyKRots2qf12gdF/P9YS9gBqpOgJRNf8UTN0kpIHtf62zq3vsFpg5Hjduk X-Received: by 2002:a05:622a:5cc:b0:428:1f1a:1a03 with SMTP id d12-20020a05622a05cc00b004281f1a1a03mr2252697qtb.59.1704333621745; Wed, 03 Jan 2024 18:00:21 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1704333621; cv=pass; d=google.com; s=arc-20160816; b=noOpO1PEzNDUzMcD3tS6p7dlP4PsnmTNyMCtbg2GYFKr341M8jYc0S73UUmruRejN6 9oHN5l2AOZ3nz5UpS+L54POZbqYy8vrkwWNNjSHYG2FbdusnTes41e1smDOJ0pRcSW1I YUp/amw1yaX7gIoxx/9S9RQnvU8m2120E560aOr9PJV4ZN5tui7xyjPrvFg7RRKwxHIC RHvoW9iIh9mzxGSPfNQtwFDn0K/gY0C73Ng/u5ChEScoCW9a3LE7SbfGv0DQNRugO2bJ KIB8w4Tj5uY/PrJHsnIL3tOHrtVBQmZaEU78VSEPue/JHRuM9gfsbthEr5uyGKFCLy0c 3c9w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:arc-filter:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=thnT/W+RB5VVxHQQ1hOoyy82fMfMuPtdo1V4N+T7XEw=; fh=Yb7vMu1xmO3w7lzcUJ3g87/936eZQp4GM8b6tTP+qWg=; b=U6bBAH81af1rz3DZdiM0CMuBcjCjBFm9Y95GcnpZAGlbgewmAjqXOJm6tC5pgiwzH8 sZv1oLK/ZNvBgF0vpCIQvGyVZQAZuGjZh6CONz0M0P/YXM7tbr1BZl0LvJE+K2QGwLt8 HEWOCwW1Cl2EkkQ0vEYEijRpmE1J4L33xo0hhM3viGTdCl41bc8ROO1R7G2vT1w5juJF 4K2amQ8n6vm48FYKlY4QYkovoLUs5jl0IIIAIied7Tr2DDdOmIPe57hqsOQKYOgPo7dB TrBaGwePDKxHcFMTC8ylxOEy2ydkr2LSnyZiLCMEgValXo9EiQqeGmoq2ThokOVWNlIB lVTQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=ZejQD1MT; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id 13-20020ac8590d000000b0042374c4031csi30870603qty.391.2024.01.03.18.00.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jan 2024 18:00:21 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=ZejQD1MT; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3D27C385800E for ; Thu, 4 Jan 2024 02:00:21 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3D27C385800E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1704333621; bh=thnT/W+RB5VVxHQQ1hOoyy82fMfMuPtdo1V4N+T7XEw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=ZejQD1MTloIB6Fd3y/QE6uCi+2IFgIkM9+0MrZzqXKYu3jubbUM0NMRIdyfudg2Wf xPzpdEy6oC7feH1RSPODhzVRaBV4KdWQTzrffly/H86EXnNiCOMYu/sYDHSPpPWnCK 7/FAgZi85Z0XbXhYfbPBQy7mMK4l57VDdQ9ts/YQ= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) by sourceware.org (Postfix) with ESMTPS id 413C23858409; Thu, 4 Jan 2024 01:58:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 413C23858409 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 413C23858409 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=209.85.214.176 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704333529; cv=none; b=ISYxUBi+1gT8dtwwEYRhHtGbVMTup0wHnZI+DWtAKV1Wund+PpjFAorifcSAk+fjYxc/QGzsmBd6JA2vSTEFDc4i8qX8b9bcaNOGBHUjw3AjZ4j+FvqvE6tohBf+CcwCKFemvO5yg9CM42rSZA9LkwIAoAkCrIUwo4g2DsQbONw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704333529; c=relaxed/simple; bh=8aaKtbnpR1ml00aBgh4PWCHeIOVVDeST4LNn92MUUBA=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=aDsikSOp3gPf4Qtv2pauQzIzibQ+9rWLnVmyXYS4+H3jcjqJMJXexDhfriJ8ptfoC+evMqmjUoD9zWoWIKBOoAeEJum/MgEwTDpCFebw8mAJHbcaUGVwwD+ws5Lx8QOB3dPqwQpO0mMMctXsj+LLqr2z/Of++QAyCXF3cBfoE74= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-1d427518d52so221965ad.0; Wed, 03 Jan 2024 17:58:40 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704333519; x=1704938319; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=thnT/W+RB5VVxHQQ1hOoyy82fMfMuPtdo1V4N+T7XEw=; b=LeoKCKJKpRjBQQ8nn+2oIlYO6Zf1yI6a4dcIRg0L1HKE7Ilc6aba2nEnVn57CfDWoP aGYyo1yupvzlXKsRow5w7jovNC383tJwluhXJBpSk3T0za7p+XIkw+t1d2Qps8V9VEue Pg0HO4kKqbozRjcMTChVNBFy+NdCgc6XGL1YjiCYgVpNNSn6ON3wcuaoJwfgMuTDbUDv gwIs7RafWU1HkJJVxF1nXnS3ATArEM3t7UGgn8//5XkMsfFHiRwT0bf2xQ0ulVkFyy/o 9lz/6xUREHxdW8su2nFIKZsSIe2QCMFTpkbfXcRZERZ05CFDlY5y6ohuHvu1JGd+KgLS WQGQ== X-Gm-Message-State: AOJu0YyPuMEF8xSgGMS2w0tw8hNNV/IiocHzmDf40Ud/g/FVRvMr5rEt q9x2kE2TB60J88Pf/w9hs/cr6B2QmMpBxg== X-Received: by 2002:a17:902:d54f:b0:1d4:b4a:9cd5 with SMTP id z15-20020a170902d54f00b001d40b4a9cd5mr3181477plf.48.1704333518836; Wed, 03 Jan 2024 17:58:38 -0800 (PST) Received: from localhost.localdomain ([149.248.38.156]) by smtp.gmail.com with ESMTPSA id e6-20020a170902744600b001d4b0ae7052sm7028122plt.135.2024.01.03.17.58.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jan 2024 17:58:38 -0800 (PST) From: YunQiang Su To: gcc-patches@gcc.gnu.org Cc: YunQiang Su Subject: [committed] MIPS: Implement TARGET_INSN_COSTS Date: Thu, 4 Jan 2024 09:58:17 +0800 Message-Id: <20240104015819.353901-2-syq@gcc.gnu.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240104015819.353901-1-syq@gcc.gnu.org> References: <20240104015819.353901-1-syq@gcc.gnu.org> MIME-Version: 1.0 X-Spam-Status: No, score=-10.8 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, 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+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787123331354441070 X-GMAIL-MSGID: 1787123331354441070 When combine some instructions, the generic `rtx_cost` may over estimate the cost of result RTL, due to that the RTL may be quite complex and `rtx_cost` has no information that this RTL can be convert to simple hardware instruction(s). In this case, Let's use `insn_count * perf_ratio` to estimate the cost if both of them are available. Otherwise fallback to pattern_cost. When non-speed, Let's use the length as cost. gcc * config/mips/mips.cc (mips_insn_cost): New function. gcc/testsuite * gcc.target/mips/data-sym-multi-pool.c: Skip Os or -O0. --- gcc/config/mips/mips.cc | 33 +++++++++++++++++++ .../gcc.target/mips/data-sym-multi-pool.c | 2 +- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/gcc/config/mips/mips.cc b/gcc/config/mips/mips.cc index 3131749d6ea..46b7d9b64ff 100644 --- a/gcc/config/mips/mips.cc +++ b/gcc/config/mips/mips.cc @@ -4170,6 +4170,37 @@ mips_set_reg_reg_cost (machine_mode mode) } } +/* Implement TARGET_INSN_COSTS. */ + +static int +mips_insn_cost (rtx_insn *x, bool speed) +{ + int cost; + int count; + int ratio; + + if (recog_memoized (x) < 0 + && GET_CODE (PATTERN (x)) != ASM_INPUT + && asm_noperands (PATTERN (x)) < 0) + goto pattern_cost; + + /* FIXME: return get_attr_length? More tests may be needed. */ + if (!speed) + goto pattern_cost; + + count = get_attr_insn_count (x); + ratio = get_attr_perf_ratio (x); + cost = count * ratio; + if (cost > 0) + return cost; + +pattern_cost: + cost = pattern_cost (PATTERN (x), speed); + /* If the cost is zero, then it's likely a complex insn. + FIXME: Return COSTS_N_INSNS (2)? More tests are needed. */ + return cost; +} + /* Implement TARGET_RTX_COSTS. */ static bool @@ -23069,6 +23100,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/testsuite/gcc.target/mips/data-sym-multi-pool.c b/gcc/testsuite/gcc.target/mips/data-sym-multi-pool.c index 3cf2d4f0248..8643095ff9f 100644 --- a/gcc/testsuite/gcc.target/mips/data-sym-multi-pool.c +++ b/gcc/testsuite/gcc.target/mips/data-sym-multi-pool.c @@ -1,6 +1,6 @@ /* { dg-do compile } */ /* { dg-options "-mips16 -mcode-readable=yes -fno-tree-vrp -fno-tree-dominator-opts" } */ -/* { dg-skip-if "per-function expected output" { *-*-* } { "-flto" } { "" } } */ +/* { dg-skip-if "per-function expected output" { *-*-* } { "-flto" "-O0" "-Os" } { "" } } */ /* This testcase generates multiple constant pools within a function body. */