From patchwork Thu Sep 12 04:38:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bohan Lei X-Patchwork-Id: 1984319 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=mTShCq/5; 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 4X44T64Xsfz1y1C for ; Thu, 12 Sep 2024 14:38:49 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E8AB13858406 for ; Thu, 12 Sep 2024 04:38:46 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from out30-111.freemail.mail.aliyun.com (out30-111.freemail.mail.aliyun.com [115.124.30.111]) by sourceware.org (Postfix) with ESMTPS id 0BA543858CDA for ; Thu, 12 Sep 2024 04:38:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0BA543858CDA 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 0BA543858CDA Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=115.124.30.111 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1726115909; cv=none; b=GvxpKi0c1QmRRh/KRWRYoYyRy4NCJqqRh/I1J5pJUDvhtUerAh7l8zglhXr/VrQg3pO7iTwsIGn9PQKAwttFjtLqHr8nv0gmvjSKJ+nTMQMM8Z6XD/ofuPwbWEupkgZfVD2ihwPWvnwFVCFCVjd0j9DB2aGhE48JV7NDmoPONLI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1726115909; c=relaxed/simple; bh=tbaQkis1FonwRe4/cssibYDAOgNm0/ESxd7zWDDcRrQ=; h=DKIM-Signature:Date:From:To:Message-ID:Subject:MIME-Version; b=Nfd3KhduTqQ3lzUbFMvwAHBm6jXTduG5L1lS2ZvB0VU7WHiKwjOeNMGl2veL3uX28C1zVN3Qj22JqwsEkDDSvFb7IS04ODbrZhGKPobjGIjEYIa0z6Y0/U5drLDiZknu317aCeLc0fMg+jXIXdo7/c3fi+zoxFQfT14SHpI2fiw= 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=1726115903; h=Date:From:To:Message-ID:Subject:MIME-Version:Content-Type; bh=tbaQkis1FonwRe4/cssibYDAOgNm0/ESxd7zWDDcRrQ=; b=mTShCq/5/T68MOQ4f6OUqFx6MZYRBIGYYKnSwbeEn916ui6wXFNAbxJMhcH3CZMksjnVP2OYmgPv8x0FUpOVWhhgHSU0qRS+iYMNLL2MxHmeG4W86EK+3hNVWAa8xm02PZ4rZEj8F+I4Z9M2KRMlsMsf9Gs18Bb6cNBnfb3ACsA= X-Alimail-AntiSpam: AC=PASS; BC=-1|-1; BR=01201311R201e4; CH=green; DM=||false|; DS=||; FP=0|-1|-1|-1|0|-1|-1|-1; HT=maildocker-contentspam033045046011; MF=garthlei@linux.alibaba.com; NM=1; PH=DW; RN=2; SR=0; TI=W4_0.2.3_v5ForWebDing_212DC423_1726115865139_o7001c27o; Received: from WS-web (garthlei@linux.alibaba.com[W4_0.2.3_v5ForWebDing_212DC423_1726115865139_o7001c27o]) at Thu, 12 Sep 2024 12:38:19 +0800 Date: Thu, 12 Sep 2024 12:38:19 +0800 From: "Bohan Lei" To: "gcc-patches" Cc: "juzhe.zhong" Message-ID: <4fc3649e-dbfd-46eb-b9fb-1acf2a95e332.garthlei@linux.alibaba.com> Subject: =?utf-8?q?=5BPATCH_v2=5D_RISC-V=3A_Eliminate_latter_vsetvl_when_fus?= =?utf-8?q?ed?= X-Mailer: [Alimail-Mailagent revision 23][W4_0.2.3][v5ForWebDing][Safari] MIME-Version: 1.0 x-aliyun-im-through: {"version":"v1.0"} References: <50924b9c-0ee4-4ee0-95da-0d4da724c71c.garthlei@linux.alibaba.com> x-aliyun-mail-creator: W4_0.2.3_v5ForWebDing_NjATW96aWxsYS81LjAgKE1hY2ludG9zaDsgSW50ZWwgTWFjIE9TIFggMTBfMTVfNykgQXBwbGVXZWJLaXQvNjA1LjEuMTUgKEtIVE1MLCBsaWtlIEdlY2tvKSBWZXJzaW9uLzE3LjQuMSBTYWZhcmkvNjA1LjEuMTU=XQ In-Reply-To: <50924b9c-0ee4-4ee0-95da-0d4da724c71c.garthlei@linux.alibaba.com> X-Spam-Status: No, score=-28.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, ENV_AND_HDR_SPF_MATCH, GIT_PATCH_0, KAM_SHORT, 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: , Reply-To: Bohan Lei Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org Resent to cc Juzhe. ------ Hi all, A simple assembly check has been added in this version. Previous version: https://gcc.gnu.org/pipermail/gcc-patches/2024-September/662783.html Thanks, Bohan ------ The current vsetvl pass eliminates a vsetvl instruction when the previous info is "available," but does not when "compatible." This can lead to not only redundancy, but also incorrect behaviors when the previous info happens to be compatible with a later vector instruction, which ends of using the vsetvl info that should have been eliminated, as is shown in the testcase. This patch eliminates the vsetvl when the previous info is "compatible." gcc/ChangeLog: * config/riscv/riscv-vsetvl.cc (pre_vsetvl::fuse_local_vsetvl_info): Delete vsetvl insn when `prev_info` is compatible gcc/testsuite/ChangeLog: * gcc.target/riscv/rvv/vsetvl/vsetvl_bug-4.c: New test. --- gcc/config/riscv/riscv-vsetvl.cc | 3 +++ .../riscv/rvv/vsetvl/vsetvl_bug-4.c | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vsetvl_bug-4.c diff --git a/gcc/config/riscv/riscv-vsetvl.cc b/gcc/config/riscv/riscv-vsetvl.cc index ce831685439..030ffbe2ebb 100644 --- a/gcc/config/riscv/riscv-vsetvl.cc +++ b/gcc/config/riscv/riscv-vsetvl.cc @@ -2796,6 +2796,9 @@ pre_vsetvl::fuse_local_vsetvl_info () curr_info.dump (dump_file, " "); } m_dem.merge (prev_info, curr_info); + if (!curr_info.vl_used_by_non_rvv_insn_p () + && vsetvl_insn_p (curr_info.get_insn ()->rtl ())) + m_delete_list.safe_push (curr_info); if (curr_info.get_read_vl_insn ()) prev_info.set_read_vl_insn (curr_info.get_read_vl_insn ()); if (dump_file && (dump_flags & TDF_DETAILS)) diff --git a/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vsetvl_bug-4.c b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vsetvl_bug-4.c new file mode 100644 index 00000000000..04a8ff2945a --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vsetvl_bug-4.c @@ -0,0 +1,19 @@ +/* { dg-do compile } */ +/* { dg-options "-march=rv64gcv -mabi=lp64d -O2 -fno-schedule-insns -fdump-rtl-vsetvl-details" } */ + +#include + +vuint16m1_t +foo (vuint16m1_t a, vuint16m1_t b, size_t avl) +{ + size_t vl; + vuint16m1_t ret; + uint16_t c = __riscv_vmv_x_s_u16m1_u16(a); + vl = __riscv_vsetvl_e8mf2 (avl); + ret = __riscv_vadd_vx_u16m1 (a, c, avl); + ret = __riscv_vadd_vv_u16m1 (ret, a, vl); + return ret; +} + +/* { dg-final { scan-rtl-dump "Eliminate insn" "vsetvl" } } */ +/* { dg-final { scan-assembler-times {vsetvli} 2 } } */