From patchwork Tue May 28 10:45:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: liuhongt X-Patchwork-Id: 1940407 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=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=XKyFLSq0; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; 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 [8.43.85.97]) (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 4VpTl34T6Tz20Pb for ; Tue, 28 May 2024 20:48:31 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8CECD384609D for ; Tue, 28 May 2024 10:48:28 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.18]) by sourceware.org (Postfix) with ESMTPS id 8C1F0385F024 for ; Tue, 28 May 2024 10:48:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8C1F0385F024 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=intel.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 8C1F0385F024 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=192.198.163.18 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716893291; cv=none; b=ro0UZAGXJEeUZD7aNtKAzmiYHL6PqYs64JyX79NdyVQU5Le+0bmZA3XUgRxXQ7xez1+Q7Am+8aCTy/CUNasmBFWZz8IaMbE2+8abT5J8Wks7YX17012UCxe3Oa7MkZOym0X+gguPBq29NMzpB7ENW42LANWPJtFNzwiKaXWvtaQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716893291; c=relaxed/simple; bh=+OMKBnPwyr/1Jb8smfAwhLhESWKo1iK86r1EO4kKLdU=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=sLsGI5UOLGkGvbyBV+B3CBQQTzMJq+eq11IeoPDWRPzEsZidt4s5Sqo86zk/ajYib03WJP/leKd3S0a8xgX2N1NqNFPvCMEsOQ1WQu8ZsL+HcP1DHFQi8KigJwiUZwCzjOy0UpvfgF/YECHhMYR9fonaU2LXeRKYWEh3+YRt2YM= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1716893283; x=1748429283; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=+OMKBnPwyr/1Jb8smfAwhLhESWKo1iK86r1EO4kKLdU=; b=XKyFLSq0+v0HnpIBwOM9YmMiprxP558WaqexNVEU5oPd4vh7A1XMQSM8 GyxKjUiO7gAtlfRKJEKhoa2dU7LhoPCT62Fth4zY2iFHOqiYGIUAVCM5+ hlXa+TgUneYMsHTNwTV6gzObCSvBfa9R/o7kbdDPPDa46kdSOlQ2II0SR +VKHatv6+BbkRhSNxWRcCGWM+qTJVMCMAPBr02Tm59/46gWuuBpjs3QfV bwjHHTihW4GB9f4dHrzst5DBW7zfj8IKNt+AizcCg4ibtIXve3UnlDM+/ NnCOY9DFJs43hae/NMVJe9SrUAPq+dtA17NLA7V5H3NpWyT0NOOTe24bl A==; X-CSE-ConnectionGUID: emmmmiHuQcedvJiUocbCwg== X-CSE-MsgGUID: Gut7nDknQr2eKFd47Tf8+g== X-IronPort-AV: E=McAfee;i="6600,9927,11085"; a="13001987" X-IronPort-AV: E=Sophos;i="6.08,195,1712646000"; d="scan'208";a="13001987" Received: from orviesa008.jf.intel.com ([10.64.159.148]) by fmvoesa112.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 May 2024 03:48:02 -0700 X-CSE-ConnectionGUID: +tDiaEWDQHGleMTcsa+l2Q== X-CSE-MsgGUID: ts26HzLfQg2uXaGc1Gp9/A== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,195,1712646000"; d="scan'208";a="35532359" Received: from shvmail03.sh.intel.com ([10.239.245.20]) by orviesa008.jf.intel.com with ESMTP; 28 May 2024 03:48:01 -0700 Received: from shliclel4217.sh.intel.com (shliclel4217.sh.intel.com [10.239.240.127]) by shvmail03.sh.intel.com (Postfix) with ESMTP id 13B471007C1B; Tue, 28 May 2024 18:48:00 +0800 (CST) From: liuhongt To: gcc-patches@gcc.gnu.org Cc: ubizjak@gmail.com Subject: [PATCH V2] Reduce cost of MEM (A + imm). Date: Tue, 28 May 2024 18:45:59 +0800 Message-Id: <20240528104559.1077691-1-hongtao.liu@intel.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Status: No, score=-12.1 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, SPF_HELO_NONE, SPF_NONE, 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+incoming=patchwork.ozlabs.org@gcc.gnu.org > IMO, there is no need for CONST_INT_P condition, we should also allow > symbol_ref, label_ref and const (all allowed by > x86_64_immediate_operand predicate), these all decay to an immediate > value. Changed. Bootstrapped and regtested on x86_64-pc-linux-gnu{-m32,}. Ok for trunk. For MEM, rtx_cost iterates each subrtx, and adds up the costs, so for MEM (reg) and MEM (reg + 4), the former costs 5, the latter costs 9, it is not accurate for x86. Ideally address_cost should be used, but it reduce cost too much. So current solution is make constant disp as cheap as possible. gcc/ChangeLog: PR target/67325 * config/i386/i386.cc (ix86_rtx_costs): Reduce cost of MEM (A + imm) to "cost of MEM (A)" + 1. gcc/testsuite/ChangeLog: * gcc.target/i386/pr67325.c: New test. --- gcc/config/i386/i386.cc | 18 +++++++++++++++++- gcc/testsuite/gcc.target/i386/pr67325.c | 7 +++++++ 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.target/i386/pr67325.c diff --git a/gcc/config/i386/i386.cc b/gcc/config/i386/i386.cc index 3e2a3a194f1..85d87b9f778 100644 --- a/gcc/config/i386/i386.cc +++ b/gcc/config/i386/i386.cc @@ -22194,7 +22194,23 @@ ix86_rtx_costs (rtx x, machine_mode mode, int outer_code_i, int opno, /* An insn that accesses memory is slightly more expensive than one that does not. */ if (speed) - *total += 1; + { + *total += 1; + rtx addr = XEXP (x, 0); + /* For MEM, rtx_cost iterates each subrtx, and adds up the costs, + so for MEM (reg) and MEM (reg + 4), the former costs 5, + the latter costs 9, it is not accurate for x86. Ideally + address_cost should be used, but it reduce cost too much. + So current solution is make constant disp as cheap as possible. */ + if (GET_CODE (addr) == PLUS + && x86_64_immediate_operand (XEXP (addr, 1), Pmode)) + { + *total += 1; + *total += rtx_cost (XEXP (addr, 0), Pmode, PLUS, 0, speed); + return true; + } + } + return false; case ZERO_EXTRACT: diff --git a/gcc/testsuite/gcc.target/i386/pr67325.c b/gcc/testsuite/gcc.target/i386/pr67325.c new file mode 100644 index 00000000000..c3c1e4c5b4d --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr67325.c @@ -0,0 +1,7 @@ +/* { dg-do compile { target { ! ia32 } } } */ +/* { dg-options "-O2" } */ +/* { dg-final { scan-assembler-not "(?:sar|shr)" } } */ + +int f(long*l){ + return *l>>32; +}