From patchwork Tue May 28 02:46:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: liuhongt X-Patchwork-Id: 1940199 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=nfzGl8gK; 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 4VpH6J3c8Kz20Pq for ; Tue, 28 May 2024 12:49:26 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BD035388459F for ; Tue, 28 May 2024 02:49:17 +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.16]) by sourceware.org (Postfix) with ESMTPS id 6183A3846096 for ; Tue, 28 May 2024 02:48:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6183A3846096 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 6183A3846096 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=192.198.163.16 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716864538; cv=none; b=QxSC/UUXr3Zr1Kpi2Ln/+oOHjfheLPTbxUF58dGYro1ino50m/Skw/lsPs3i1eUAFFhsIUdo9AY1nC4OhhWytdmiwdGblYbFTo7VYGPCy46YDX5yFbAfxMDehUsmTA1dnjqYtx6raGpxMTsFx9s12lcFWRmEstuxyYOjEvmxBV4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716864538; c=relaxed/simple; bh=bc4Fi43wispuAbL9Y9+QZ45k5rtC2VVG4GAEZH906uI=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=oFOW81ZrAlS0Tl3Rcb3CDVWdl5mClnFCshINZgYqJ4x6Lknp6zNV3h2ssAWadcMjGk9/0TtDhA8z3NJQCGuhDvhtLv+Cjz59lz0rLYDuZ/wHGKm4/ZQ9h3+mXvPUqaSwtKvxvA+cH4yFIbsCe3eUe2lk0xpsOMl0dtAmNisPeQQ= 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=1716864536; x=1748400536; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=bc4Fi43wispuAbL9Y9+QZ45k5rtC2VVG4GAEZH906uI=; b=nfzGl8gKzt+DYYOVxb1dRGHhYKskA9rRvPC7Df1BVkGGEJY+gVS78+SK I47WzWEJeqgYXLCczuz+LbYKqz/Mt3omPueFdYsyVbEbQ1XmpVVHa4RyT n5RK8dsBPLsZokTmR92UiBvUmfFM2E4VO1FSdoCksKClySaNrXv7zfpRb O93JCbdH0xUH56Z9dvMZmAVpdAZVVSGDw+N86n47TU8rSMny3Mqaz5IPw l1xYjL/C+uK/2wfRViUCQubaE8m7XBey5E6tH3ed+YxJ1ZGkbN3LNTcwx Y77xae6pwaVmYop2zvZbqpAUrsOGZd7Cm5aqQLYVBzR6vkrshwpj84zOB Q==; X-CSE-ConnectionGUID: CCoBivOoTLqQBQoE6e1chg== X-CSE-MsgGUID: hlxZCw/GRTCmbGfPGCI7ow== X-IronPort-AV: E=McAfee;i="6600,9927,11085"; a="11720016" X-IronPort-AV: E=Sophos;i="6.08,194,1712646000"; d="scan'208";a="11720016" Received: from fmviesa005.fm.intel.com ([10.60.135.145]) by fmvoesa110.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 May 2024 19:48:54 -0700 X-CSE-ConnectionGUID: MqHToaA+QQaxCJQVjkCENg== X-CSE-MsgGUID: pZUgmLPXQq29bs0X7ja+DA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,194,1712646000"; d="scan'208";a="39316230" Received: from shvmail03.sh.intel.com ([10.239.245.20]) by fmviesa005.fm.intel.com with ESMTP; 27 May 2024 19:48:53 -0700 Received: from shliclel4217.sh.intel.com (shliclel4217.sh.intel.com [10.239.240.127]) by shvmail03.sh.intel.com (Postfix) with ESMTP id 7F2AD10077F6; Tue, 28 May 2024 10:48:52 +0800 (CST) From: liuhongt To: gcc-patches@gcc.gnu.org Cc: ubizjak@gmail.com Subject: [PATCH] Reduce cost of MEM (A + imm). Date: Tue, 28 May 2024 10:46:52 +0800 Message-Id: <20240528024652.924198-1-hongtao.liu@intel.com> X-Mailer: git-send-email 2.31.1 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 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. Bootstrapped and regtested on x86_64-pc-linux-gnu{-m32,}. Ok for trunk? 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 | 19 ++++++++++++++++++- gcc/testsuite/gcc.target/i386/pr67325.c | 7 +++++++ 2 files changed, 25 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..3936223bd20 100644 --- a/gcc/config/i386/i386.cc +++ b/gcc/config/i386/i386.cc @@ -22194,7 +22194,24 @@ 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 + && CONST_INT_P (XEXP (addr, 1)) + && 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; +}