From patchwork Mon Sep 16 08:10:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xianmiao Qu X-Patchwork-Id: 1985994 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.a=rsa-sha256 header.s=default header.b=BAzj+BKO; 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 4X6d0v1rd5z1y1m for ; Mon, 16 Sep 2024 18:11:42 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D86B9385843B for ; Mon, 16 Sep 2024 08:11:39 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from out30-118.freemail.mail.aliyun.com (out30-118.freemail.mail.aliyun.com [115.124.30.118]) by sourceware.org (Postfix) with ESMTPS id E6EBE3858D20 for ; Mon, 16 Sep 2024 08:11:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E6EBE3858D20 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linux.alibaba.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org E6EBE3858D20 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=115.124.30.118 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1726474280; cv=none; b=ZyfWoRrb4pqh0pKnPnMD2Re7ahMOUeLAmFMVJCKLpITN5hh0bzv1GDXC3Sz6Dlnp6aq6ax+JHMExScK7c/07H8Bv1nF0OPp3VMKNdsX4RKJLVh6PDbROL7r1EHW7DNzjO6EiMAc6/gcIQNKcqAflRoM6UNYP1g5RgMhuejVTvT4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1726474280; c=relaxed/simple; bh=J5Wa+ecQDhmtiydvt+vrqzSVzCZNyzlXLhCgDmCFer0=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=sutyWg1d8Z5apa7ccepLXNnl/wkaupJ1WIGG+8LlZ/rn/jwvzM4yIitI/YgPC/aj+7XYtOnniDyH1qt8Lga3THj6hdD0nM2VUvsRUKSewpI6NCsfX0EBpn4TJB6RwgLO0n9TN6r+PvkrUrrYCW+1bZkpZx99+yEBtWLo+b9gdcc= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1726474276; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=ZcEYXgGigosdpq/YQW0fsu+ZnFY1V7xNzT9Pape+8aY=; b=BAzj+BKOyXqOj7Fckzf3fli3kBlpLb0MhLAVdnUgnLYDpIr4+odZuuotGhhmQ9Xkn/NsrVsWe0gLjdLLPy09gcwOJQSKQ0G+7EdVzMPy4Vy8HH7EdzvCs/uGpGtheBT4tiJ16TrkuGOjAPz0X2Qo9PBQfts5WSKvh/WyOzRaHXo= Received: from localhost(mailfrom:cooper.qu@linux.alibaba.com fp:SMTPD_---0WF20t21_1726474271) by smtp.aliyun-inc.com; Mon, 16 Sep 2024 16:11:11 +0800 From: Xianmiao Qu To: gcc-patches@gcc.gnu.org, jeffreyalaw@gmail.com, kito.cheng@gmail.com Cc: Xianmiao Qu Subject: [PATCH 1/2] RISC-V: Fix the outer_code when calculating the cost of SET expression. Date: Mon, 16 Sep 2024 16:10:56 +0800 Message-Id: <20240916081056.29251-1-cooper.qu@linux.alibaba.com> X-Mailer: git-send-email 2.39.3 (Apple Git-146) MIME-Version: 1.0 X-Spam-Status: No, score=-26.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, ENV_AND_HDR_SPF_MATCH, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, UNPARSEABLE_RELAY, USER_IN_DEF_DKIM_WL, USER_IN_DEF_SPF_WL 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 I think it is a typo. When calculating the 'SET_SRC (x)' cost, outer_code should be set to SET. gcc/ * config/riscv/riscv.cc (riscv_rtx_costs): Fix the outer_code when calculating the cost of SET expression. --- gcc/config/riscv/riscv.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc index 6efe14ff199f..1b4a5c39c667 100644 --- a/gcc/config/riscv/riscv.cc +++ b/gcc/config/riscv/riscv.cc @@ -3775,7 +3775,7 @@ riscv_rtx_costs (rtx x, machine_mode mode, int outer_code, int opno ATTRIBUTE_UN *total = COSTS_N_INSNS (1); return true; } - riscv_rtx_costs (SET_SRC (x), mode, outer_code, opno, total, speed); + riscv_rtx_costs (SET_SRC (x), mode, SET, opno, total, speed); return true; } From patchwork Mon Sep 16 08:11:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xianmiao Qu X-Patchwork-Id: 1985995 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.a=rsa-sha256 header.s=default header.b=JiL0Ox+C; 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 4X6d141MKGz1y1m for ; Mon, 16 Sep 2024 18:11:52 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0C1563858C3A for ; Mon, 16 Sep 2024 08:11:50 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from out30-98.freemail.mail.aliyun.com (out30-98.freemail.mail.aliyun.com [115.124.30.98]) by sourceware.org (Postfix) with ESMTPS id 260593858C33 for ; Mon, 16 Sep 2024 08:11:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 260593858C33 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linux.alibaba.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 260593858C33 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=115.124.30.98 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1726474290; cv=none; b=xfRDGU33syEMSNDnrA2qQmAjaR4032M0bzNOTo2PFAA2doB6T5cFW1vfvZib9IoYIeynqi8YAzb/pfZeb7dRuIzO1VzP4m0uBdvahc2TvI5WqfFGkIBqUGi4GUEnbVUk++Q9dW8cdXVnjY2IpInQrEt27ukbaBrAmgqbj8Ixf0w= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1726474290; c=relaxed/simple; bh=qcycODqqOGQGWj87ByieOfrINh9iCvtgziZL+kkNkvs=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=CZnzX2YJRQDK+OESBXjJRQ2TiN6aTWbfwXrLGK8JUe28XNGyk9lvp973zYTS4RvyrQTY8+AEjBB98Zn0kASS/j1kaHnoZ90D2ESCyrTzti0R70TyWfj+TAQ+eZM/pzMD+4WCjBUZdQB8clzUWKX4DhOOicQlCvdZRtDVV4V6WEY= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1726474285; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=Cy2+1+zvHj/xsbiMfksyAAMI1v+MEq4DcvfMHj52K5s=; b=JiL0Ox+CCllsIITm0Hz84tdovKuQ+NCtsBxeG75dTFoxB5KDEpkTmnysn4drxPIQe1Uyy+3FHiovxRtYbwZNvB77OB/4jnaRd1qbCPnC0UVN2ZZhrZ3w0F55zMw/GIZFXodita74F3UHUMPZiQ8rd96uJkDPjdvJp4S8hYU5Zz4= Received: from localhost(mailfrom:cooper.qu@linux.alibaba.com fp:SMTPD_---0WF3Kt1V_1726474282) by smtp.aliyun-inc.com; Mon, 16 Sep 2024 16:11:22 +0800 From: Xianmiao Qu To: gcc-patches@gcc.gnu.org, jeffreyalaw@gmail.com, kito.cheng@gmail.com Cc: Xianmiao Qu Subject: [PATCH 2/2] RISC-V: Optimize the cost of the LO_SUM expression. Date: Mon, 16 Sep 2024 16:11:21 +0800 Message-Id: <20240916081121.29707-1-cooper.qu@linux.alibaba.com> X-Mailer: git-send-email 2.39.3 (Apple Git-146) MIME-Version: 1.0 X-Spam-Status: No, score=-27.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, ENV_AND_HDR_SPF_MATCH, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, UNPARSEABLE_RELAY, USER_IN_DEF_DKIM_WL, USER_IN_DEF_SPF_WL 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 Currently, the cost of the LO_SUM expression is based on the cost of calculating the first subexpression. When the first subexpression is a register, the cost result will be zero. It seems a bit unreasonable for a SET expression to have a zero cost when its source is LO_SUM. Moreover, having a cost of zero for the expression will lead the loop invariant pass to calculate its benefits of being moved outside the loop as zero, thus preventing the out-of-loop placement of the loop invariant. As an example, consider the following test case: long a; long b[]; long *c; foo () { for (;;) *c = b[a]; } When compiling with -march=rv64gc -mabi=lp64d -Os, the following code is generated: .cfi_startproc lui a5,%hi(c) ld a4,%lo(c)(a5) lui a2,%hi(b) lui a1,%hi(a) .L2: ld a5,%lo(a)(a1) addi a3,a2,%lo(b) slli a5,a5,3 add a5,a5,a3 ld a5,0(a5) sd a5,0(a4) j .L2 After adjust the cost of the LO_SUM expression, the instruction addi will be moved outside the loop: .cfi_startproc lui a5,%hi(c) ld a3,%lo(c)(a5) lui a4,%hi(b) lui a2,%hi(a) addi a4,a4,%lo(b) .L2: ld a5,%lo(a)(a2) slli a5,a5,3 add a5,a5,a4 ld a5,0(a5) sd a5,0(a3) j .L2 gcc/ * config/riscv/riscv.cc (riscv_rtx_costs): Optimize the cost of the LO_SUM expression. --- gcc/config/riscv/riscv.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc index 1b4a5c39c667..cb9692dad715 100644 --- a/gcc/config/riscv/riscv.cc +++ b/gcc/config/riscv/riscv.cc @@ -3994,7 +3994,10 @@ riscv_rtx_costs (rtx x, machine_mode mode, int outer_code, int opno ATTRIBUTE_UN return false; case LO_SUM: - *total = set_src_cost (XEXP (x, 0), mode, speed); + if (outer_code == SET && REG_P (XEXP (x, 0))) + *total = COSTS_N_INSNS (1); + else + *total = set_src_cost (XEXP (x, 0), mode, speed); return true; case LT: