From patchwork Sun Nov 19 14:08:03 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: 166811 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9910:0:b0:403:3b70:6f57 with SMTP id i16csp1665613vqn; Sun, 19 Nov 2023 06:08:38 -0800 (PST) X-Google-Smtp-Source: AGHT+IHEmJsg048hhwPugdNbAXpV/hdy7PD7IBQBab8hpb2s6MKKXnPNCF6iCfRLOt1SC2qLbtMT X-Received: by 2002:a05:622a:190d:b0:421:c996:88b2 with SMTP id w13-20020a05622a190d00b00421c99688b2mr6781200qtc.35.1700402917895; Sun, 19 Nov 2023 06:08:37 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1700402917; cv=pass; d=google.com; s=arc-20160816; b=rJ2mL+4aiO2p8xGojF1B8wzCx8y9ci/17E+ipEsYDL08L+OZ/FAcPvZsLK//CX92aQ aAkz92YWZdMsgB9M2iBw5K8ikKOLpHybTurdrTkDU+mhFgGBxdxyCH4K5wSCwUvYA+1L Nn3E6ZVw0Ucmif7esvli6FjF2/+7cwqVo8pNcWlotzTjuWiJljk5xzSGkpJUkVAYVaQp ews2L3XTcaME1qpvi5oX36NDY9LBK91eRFVAqAKwnkBhy9PDynvSZengm5hoAll6WTH3 04/Xyo/wcDgLSv+/P30LtAbiByE+t6D6FmgQsXMMcohmXvwHLndkoFG3zGFC5oKKCSVf Br8w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=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:arc-filter:dmarc-filter:delivered-to; bh=pklnUc2k/lGcHXpcVqMn179ofUd4BxLhZy4CaXML5kA=; fh=idvV5TQ1gmHAoU8u1GUGfjilVySOK+BR5TeZLoSouN8=; b=KdJLaNuohMMnfA+84wrBqViRDH5kgZ+ZhalvoA5Ctbfyc9Rj6FTe8OM6bknQPYf/L0 k0w1mMcTgjnVTOwoMoz9UoNRZiwA0MeMq1/VhXcnVhNPx79FXqxum1divdmkPmgnRgzC VAm14nTpjl+agbkKDmAuasbsIMDqBF3Fb5sLDkTPqA9wPi6lLQ26QHfoV3nJYaz0W89o ccDtP4+CjqWRMfdj4CSaXYY+dzD1NONtI6u3B8oogar8hUYOJW3bw7L4Yn2Sb3dMYsR7 dO6jP3pvfA1GDgwQlW5zOMXEY9lgBFgD1tY+7CmGszzQJQF3Z8lIiVNeDnw0zm7qepn5 7q+g== ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); 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 (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id u26-20020a05622a199a00b0041cbbbc2eeesi5546173qtc.379.2023.11.19.06.08.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Nov 2023 06:08:37 -0800 (PST) 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; arc=pass (i=1); 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 A588C3858C78 for ; Sun, 19 Nov 2023 14:08:37 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtpbgau1.qq.com (smtpbgau1.qq.com [54.206.16.166]) by sourceware.org (Postfix) with ESMTPS id 75ACA3858D33 for ; Sun, 19 Nov 2023 14:08:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 75ACA3858D33 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=rivai.ai Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=rivai.ai ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 75ACA3858D33 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=54.206.16.166 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700402894; cv=none; b=WNRgPdl9AuhXS9SR2Np714TP5KkBwyZIiij4LK0G5TdixlIqynyStbT2uppTees0R/p0gq7CQilbIjQxsP9KquPVc0oilpwPMPHPG8gIkaEJNh2/kR01cwckDy0bobpCOaKGnwGhgm9oAMoC9+MRcvRoDtXPwnD/I5U/AMLqxnw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700402894; c=relaxed/simple; bh=RPDuMEdr68CXB4UtpMzDxMC7TLb+kq/oFUaDQFWQ+io=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=NBgeiJAPVfZO/Vc2k0G5tSTe9k4OxRmRhM7FXPOLVc0mpvYmeCEDhiXkF2SeDCCxH4zykgDHZMiH2cOjpVcNnPHJJSyrKpY3rstytU0IZ1aYF+3hCw0nFkeEBGDmd9gt0TC4A4VVG8+j2Etlho41olkVWdkeDH2d1lcvFTLJVq8= ARC-Authentication-Results: i=1; server2.sourceware.org X-QQ-mid: bizesmtp73t1700402885tg6ckske Received: from rios-cad121.hadoop.rioslab.org ( [58.60.1.9]) by bizesmtp.qq.com (ESMTP) with id ; Sun, 19 Nov 2023 22:08:04 +0800 (CST) X-QQ-SSF: 01400000000000G0V000000A0000000 X-QQ-FEAT: znfcQSa1hKaypnhTkC7wfH0fG4N6C5gXq555jK8REYidwn/zoX+iwIJ1U3L3S 2FIeu93rDCXFBmy+6WSbUkl8kPCMCjEGjIdR/aLVyeH17x1EdDmfd3YyHfG3fFTXXmHSY1y zFA0az9In0OoDH1+F9PL5ScTRs5Hab/+9aF8brN2cxerwFvwCKBlwrW597Cseos7t2VNDm4 bQnHamDM9S/j4oVNOtzNiGEsrqsB0REXouwwR+ywSBVCjugp6g5t2xkF5U28wafWI9PrHsT /HUyUWJyfe0oG0ACoLKN/G8Wg8kMUixiUIB8Jd0rKsug9B5ih/GEX6RE1lnOP8jeFmuS2Gj bR2teYU2VHJV/3fN8Pvw71eh6ppF/4MU2uL72jZkD8nB0bFDlhAuJoiDyr8qeXXF3E4voKO FzxeUgnTnH8= X-QQ-GoodBg: 2 X-BIZMAIL-ID: 13158198000202640369 From: Juzhe-Zhong To: gcc-patches@gcc.gnu.org Cc: Juzhe-Zhong Subject: [Committed V2] RISC-V: Optimize constant AVL for LRA pattern Date: Sun, 19 Nov 2023 22:08:03 +0800 Message-Id: <20231119140803.4168318-1-juzhe.zhong@rivai.ai> X-Mailer: git-send-email 2.36.3 MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:rivai.ai:qybglogicsvrgz:qybglogicsvrgz7a-one-0 X-Spam-Status: No, score=-12.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, 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.30 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783001689627926300 X-GMAIL-MSGID: 1783001689627926300 This optimization was discovered in the tuple move splitted bug fix patch. Before this patch: vsetivli zero,4,e16,mf2,ta,ma lhu a3,96(a5) vlseg8e16.v v1,(a5) lw a4,%lo(e)(a2) vsetvli a6,zero,e64,m2,ta,ma addi a0,a7,8 vse16.v v1,0(a7) vse16.v v2,0(a0) addi a0,a0,8 vse16.v v3,0(a0) addi a0,a0,8 vse16.v v4,0(a0) addi a0,a0,8 vse16.v v5,0(a0) addi a0,a0,8 vse16.v v6,0(a0) addi a0,a0,8 vse16.v v7,0(a0) addi a0,a0,8 vse16.v v8,0(a0) After this patch: vsetivli zero,4,e64,m2,ta,ma addi a0,a7,8 vlseg8e16.v v1,(a5) vse16.v v1,0(a7) vse16.v v2,0(a0) addi a0,a0,8 vse16.v v3,0(a0) addi a0,a0,8 vse16.v v4,0(a0) addi a0,a0,8 vse16.v v5,0(a0) addi a0,a0,8 vse16.v v6,0(a0) addi a0,a0,8 vse16.v v7,0(a0) addi a0,a0,8 vse16.v v8,0(a0) gcc/ChangeLog: * config/riscv/riscv-v.cc (emit_vlmax_insn_lra): Optimize constant AVL. gcc/testsuite/ChangeLog: * gcc.target/riscv/rvv/autovec/post-ra-avl.c: New test. --- gcc/config/riscv/riscv-v.cc | 20 ++++++++++++++++--- .../riscv/rvv/autovec/post-ra-avl.c | 16 +++++++++++++++ 2 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/autovec/post-ra-avl.c diff --git a/gcc/config/riscv/riscv-v.cc b/gcc/config/riscv/riscv-v.cc index f769c1474e0..594cc4dd145 100644 --- a/gcc/config/riscv/riscv-v.cc +++ b/gcc/config/riscv/riscv-v.cc @@ -374,10 +374,24 @@ void emit_vlmax_insn_lra (unsigned icode, unsigned insn_flags, rtx *ops, rtx vl) { gcc_assert (!can_create_pseudo_p ()); + machine_mode mode = GET_MODE (ops[0]); - insn_expander e (insn_flags, true); - e.set_vl (vl); - e.emit_insn ((enum insn_code) icode, ops); + if (imm_avl_p (mode)) + { + /* Even though VL is a real hardreg already allocated since + it is post-RA now, we still gain benefits that we emit + vsetivli zero, imm instead of vsetvli VL, zero which is + we can be more flexible in post-RA instruction scheduling. */ + insn_expander e (insn_flags, false); + e.set_vl (gen_int_mode (GET_MODE_NUNITS (mode), Pmode)); + e.emit_insn ((enum insn_code) icode, ops); + } + else + { + insn_expander e (insn_flags, true); + e.set_vl (vl); + e.emit_insn ((enum insn_code) icode, ops); + } } /* Emit an RVV insn with a predefined vector length. Contrary to diff --git a/gcc/testsuite/gcc.target/riscv/rvv/autovec/post-ra-avl.c b/gcc/testsuite/gcc.target/riscv/rvv/autovec/post-ra-avl.c new file mode 100644 index 00000000000..f3d12bac7cd --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/post-ra-avl.c @@ -0,0 +1,16 @@ +/* { dg-do compile } */ +/* { dg-options "-O3 -march=rv64gcv -mabi=lp64d --param=riscv-autovec-preference=fixed-vlmax" } */ + +int a, b, c, e; +short d[7][7] = {}; +int foo() { + short f; + c = 0; + for (; c <= 6; c++) { + e |= d[c][c] & 1; + b &= f & 3; + } + return a; +} + +/* { dg-final { scan-assembler-times {vsetvli\s+[a-x0-9]+,\s*zero} 1 } } */