From patchwork Fri Jun 2 06:31:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "juzhe.zhong@rivai.ai" X-Patchwork-Id: 102317 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp829929vqr; Thu, 1 Jun 2023 23:32:26 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6sOU5KF8TATexQdysS+C3vfj7EhOxoIuLACS+SLUMpnGF3wXnrovGkGU98c3R/n0aolU2o X-Received: by 2002:a2e:994f:0:b0:2ad:1ba2:eff9 with SMTP id r15-20020a2e994f000000b002ad1ba2eff9mr990393ljj.20.1685687546232; Thu, 01 Jun 2023 23:32:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685687546; cv=none; d=google.com; s=arc-20160816; b=oAx4gPordusKWZH+kfMn+MCYzQPKtMOCfDb3k0D+CQ7qrqEs6KrFgylIByn1enkZv5 vwIH2h1D657t+e9PR1J1EzapSDa4SzC4OWHkXb0988aMRJrIuUXzGRUhg5nGrly1Ecds pkYY8xd9OtQR3c+iYU8z3fJpsw4gTdcRMN42MDoa1fFQpH0TomGNXoZHyrz7byxXz4WT NWMpvxcOskih97e4hVZrGiP1nt+Q8K/0xWdTjutZgTPhOoo5pzoDKA5VdaAfd7xwQ+NP Jh/dk2hwOL0tgzPIboV7oXm1oIBcCxJmrrq8+/Ou83qZEW/P/SWjPFFw/O8HzTOvTzmJ AO5g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:feedback-id :content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:dmarc-filter:delivered-to; bh=Rss8y2/YlySQt0zgN2cDNExGVCpFLfzZKuPevLhQfwA=; b=hRcQzry33Yjnn+hlGokAI3RazDun0yz2VHNkcdJYeHZ3Kwm7OxD4PbJF9O/1DdYgWP wjtp24485I5X+iHxXlCxdo19IrDA/5ToZLeb1JF/ruCe3KY2eRpMUAJJF455jUOOaZG+ mUPWVevcGf8lv07qlCpIPdSz8ZG1iD2/VZ5Yc3h7IfJvDgd09JLG7xfOvxMk60aKqNNK YBizdJ3cH5psKuzCb4sO5nB4GepVIR4sRRHBd8MIddG9cV+GetZiUsmMhoQWvM13g4WQ AfhWXdaUA64OKLpsiH5jB47jiqWzuC06UG0OR7ISGcymJWbEoJhFoDUF2TrGPf5Mo3h5 zVpg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id y14-20020a056402134e00b00516402203d7si166380edw.199.2023.06.01.23.32.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Jun 2023 23:32:26 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2D7843858409 for ; Fri, 2 Jun 2023 06:32:21 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtpbgjp3.qq.com (smtpbgjp3.qq.com [54.92.39.34]) by sourceware.org (Postfix) with ESMTPS id 94D353858C53 for ; Fri, 2 Jun 2023 06:31:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 94D353858C53 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=rivai.ai Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=rivai.ai X-QQ-mid: bizesmtp80t1685687504tjjscxgc Received: from server1.localdomain ( [58.60.1.22]) by bizesmtp.qq.com (ESMTP) with id ; Fri, 02 Jun 2023 14:31:43 +0800 (CST) X-QQ-SSF: 01400000000000F0R000000A0000000 X-QQ-FEAT: 5QxEZ1enDv/BsSNAQtRlUZ5dxCBvFVvq5rHosXCbvn6ZEUtgZQYvUzxm5dG0k E3TorliHuFdhfztq3vofSx4OaBNUGsng8wyr0+L6HR1ohHrb04TrPcileBTOX7NDBFQaTgq IRQ4FJHdsT8bCtySwdAVnGs2GJ4f6WCStq4TmujtfQ3Erj4glbczzyawXYnH1pJg96HkO2f rkvszQi+1ubOSd+J44t7qDd8LNF1cJK5owMF3MUgMbzEsxt9d8UOQiFn+DYhn8+w/H09rHg DI4DovczYpcmZvL0I5lQbHtFkzR2/ZKNhm71eUeP2Uw2nF/3UK/sHm9Ia0lHSCdwbl13vYZ 4H3i2a881SQWze5Cp0vgezW9Si3MptDaQu341rquR3G8yghq+NIrOlJhZmBzn8mhlqp8uV7 U1QflN3x+Mtz/VPR196+6w== X-QQ-GoodBg: 2 X-BIZMAIL-ID: 13221081490105774826 From: juzhe.zhong@rivai.ai To: gcc-patches@gcc.gnu.org Cc: kito.cheng@gmail.com, kito.cheng@sifive.com, palmer@dabbelt.com, palmer@rivosinc.com, jeffreyalaw@gmail.com, rdapp.gcc@gmail.com, Juzhe-Zhong Subject: [PATCH] RISC-V: Optimize reverse series index vector Date: Fri, 2 Jun 2023 14:31:40 +0800 Message-Id: <20230602063140.29401-1-juzhe.zhong@rivai.ai> X-Mailer: git-send-email 2.36.1 MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:rivai.ai:qybglogicsvrgz:qybglogicsvrgz7a-one-0 X-Spam-Status: No, score=-10.3 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, KAM_SHORT, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_PASS, 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.29 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 Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767571504601484770?= X-GMAIL-MSGID: =?utf-8?q?1767571504601484770?= From: Juzhe-Zhong This patch optimizes the following seriese vector: [nunits - 1, nunits - 2, ...., 0] Before this patch: vid vmul vadd After this patch: vid vrsub This patch is an obvious and simple optimization, ok for trunk? gcc/ChangeLog: * config/riscv/riscv-v.cc (expand_vec_series): Optimize reverse series index vector. gcc/testsuite/ChangeLog: * gcc.target/riscv/rvv/autovec/vls-vlmax/perm-4.c: Add assembly check. --- gcc/config/riscv/riscv-v.cc | 17 +++++++++++++++++ .../riscv/rvv/autovec/vls-vlmax/perm-4.c | 2 ++ 2 files changed, 19 insertions(+) diff --git a/gcc/config/riscv/riscv-v.cc b/gcc/config/riscv/riscv-v.cc index 1cd3bd3438e..75cf00b7eba 100644 --- a/gcc/config/riscv/riscv-v.cc +++ b/gcc/config/riscv/riscv-v.cc @@ -530,6 +530,8 @@ expand_vec_series (rtx dest, rtx base, rtx step) machine_mode mode = GET_MODE (dest); machine_mode mask_mode; gcc_assert (get_mask_mode (mode).exists (&mask_mode)); + poly_int64 nunits_m1 = GET_MODE_NUNITS (mode) - 1; + poly_int64 value; /* VECT_IV = BASE + I * STEP. */ @@ -545,6 +547,21 @@ expand_vec_series (rtx dest, rtx base, rtx step) rtx step_adj; if (rtx_equal_p (step, const1_rtx)) step_adj = vid; + else if (rtx_equal_p (step, constm1_rtx) && poly_int_rtx_p (base, &value) + && known_eq (nunits_m1, value)) + { + /* Special case: + {nunits - 1, nunits - 2, ... , 0}. + nunits can be either const_int or const_poly_int. + + Code sequence: + vid.v v + vrsub nunits - 1, v. */ + rtx ops[] = {dest, vid, gen_int_mode (nunits_m1, GET_MODE_INNER (mode))}; + insn_code icode = code_for_pred_sub_reverse_scalar (mode); + emit_vlmax_insn (icode, RVV_BINOP, ops); + return; + } else { step_adj = gen_reg_rtx (mode); diff --git a/gcc/testsuite/gcc.target/riscv/rvv/autovec/vls-vlmax/perm-4.c b/gcc/testsuite/gcc.target/riscv/rvv/autovec/vls-vlmax/perm-4.c index 179c8274a92..aa328810c30 100644 --- a/gcc/testsuite/gcc.target/riscv/rvv/autovec/vls-vlmax/perm-4.c +++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/vls-vlmax/perm-4.c @@ -56,3 +56,5 @@ TEST_ALL (PERMUTE) /* { dg-final { scan-assembler-times {vrgather\.vv\tv[0-9]+,\s*v[0-9]+,\s*v[0-9]+} 31 } } */ +/* { dg-final { scan-assembler-times {vrsub\.vi} 24 } } */ +/* { dg-final { scan-assembler-times {vrsub\.vx} 7 } } */