From patchwork Mon Oct 16 08:27:15 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: 153258 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp3314277vqb; Mon, 16 Oct 2023 01:28:14 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH5Mam13fuUlHWOPBTdJem+4QErTKIrKMxRO3Edyo73L+vIG8knWrtJIruqD2Ia8gjjin+A X-Received: by 2002:a05:622a:19a9:b0:403:e3ce:565b with SMTP id u41-20020a05622a19a900b00403e3ce565bmr42485636qtc.4.1697444894399; Mon, 16 Oct 2023 01:28:14 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697444894; cv=pass; d=google.com; s=arc-20160816; b=jNayk5kMsxjW9QXeazWiA7sGEVZdRf8V5FlI4fjhmeM25LhY3NqQxaRg775/Ta5xLY jFDOWYQifeXP1af7q706mbBUY1rZVZXnoyuQpQ9NeavcPXDF1d+kCgPMu3rLIYT+2ts4 UUpHUUmvDWV3qhWoq3fBfjV6IdsOmS6E4eB5boM+rrLBOJ5XKpN7dZU1wKOlFCa6thgt 9rTjeXF6StG+FNWcnu3fyKJmqSB1P6ns3HU3+fWcsFGYT7yoGdS5f5Rp1A61QQZE9axN ZwxTuaLjC9PzU8AQKbIZIOQvUysnrQRQCpJTFqwxQcQUIJfOWV3NBI1nnwArx85Ru6sy IspQ== 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=TjidSXlBDTfn292v0rhfQffQNggMDlUz0pp572/Zbnw=; fh=12MRPJmZ1mgDpHqWoogMKqnaGRGM2b7lcuJroqfjJiw=; b=O/OozwQl6lc9hJQwHkGXrpAl4GAPdfvcId+BMeLPq937Ldo4SHmLnntImjlsU2K6Op vumlN2Vn0Axvsb0u4QfqIhbL3jQpbZT03gVn7394sQMxGtJEe4SHbnMu26Cv3A8FmQbu AWqAxB1zNwAiK8+d8vEChpWbzoI+YGKkycyXrg+kX7RMa6Ltb5gIKBUYRn1yNF8d49Wb 1xxL1ihOJ2mjW8xIVGKWtWVYmYq2s51nnMovUJg7XuGkQaf8ub1KoYq6ADmyOz6neizt E3C/1H6cJVm8FqfynEuSSRhnYSFMnCV7BOJ4vH0tM8yE/K+d361Y39joDcjNIFKMJsLV kwQA== 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 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id cm16-20020a05622a251000b0041b6b847b6esi1860989qtb.771.2023.10.16.01.28.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Oct 2023 01:28:14 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; 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 2620:52:3:1:0:246e:9693:128c 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 125EC385701D for ; Mon, 16 Oct 2023 08:28:12 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtpbgsg1.qq.com (smtpbgsg1.qq.com [54.254.200.92]) by sourceware.org (Postfix) with ESMTPS id B87813858425 for ; Mon, 16 Oct 2023 08:27:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B87813858425 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 B87813858425 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=54.254.200.92 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697444849; cv=none; b=b36Ka2jCj+s1YLQCnPoR0K+6D68ByDquwgLnDAjz04vGnhXmPslhYRq7Jk2Xe3XaTPYOkS+Pc/XSpeK5hf6B5c/7uTK1eEkLqsKqZoOKXftSJ5PhOMyjPlh4PiUoU4RNg6kxdlhf018HDDOmleUF5ILWZ9JQqkK4+yVHaBSMAe4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697444849; c=relaxed/simple; bh=TOxTI0DcYcyaUVS1l+HPllvoclnpTdKCkPiidbS8KCk=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=Rlw8YvA+jkln8mdaCIUSD0N4J3Sp/Ejqz9ca5blCsQz5q0MAN7CXsGkGRDh7zp2Y2bWZSiN/tYbUGjTrftH7acDN7/WT58Qzolq63Xs/+Or5dTtPG8K3FY16NwzjBMvbWf7+Uu9e8W23Y4pVy3VXMO9Qrx+E2eQohWHwkCeUTzo= ARC-Authentication-Results: i=1; server2.sourceware.org X-QQ-mid: bizesmtp62t1697444839tmq9b7mx Received: from rios-cad121.hadoop.rioslab.org ( [58.60.1.9]) by bizesmtp.qq.com (ESMTP) with id ; Mon, 16 Oct 2023 16:27:16 +0800 (CST) X-QQ-SSF: 01400000000000G0V000000A0000000 X-QQ-FEAT: +ynUkgUhZJmvfTef+mTJslzj366D/5vQezYItExA7sLH1ENK9JU4paiOBd8UK qP6pug80bAj1eQ2Hf8NA7yN7mDwP+Qvxa/5jx11t3lU689FPsgRmDmD5k6UPWls1OxVI2GO Bl1CwhSHqsv/gkFsXekrJDyhLF9IrZPy36LDq5chtSHUZCyyvxYVIpgn4k/dLIKUCDlAzp/ RRoboPBIkCGoM+ae9druK9ag92gU3wg2/N1IZh0pMBhoP6mC2MPKXsntISiIukwJ+XlLAVt 77p05cD55VOxGMhsuU82cG/BLaySOteuO4la/JRGJYGEgUB+R6RJZ3EP+b3c2gg+Rl9rLhO DdRkTDwTYnYp/8CbjcjsR8gHxzteDpHjM2SIkOrBD2hk+BBksi6X+dv/D+0hPmgmdto69t9 XTPOsRDjjTw72HXqQOTsSw== X-QQ-GoodBg: 2 X-BIZMAIL-ID: 11879869944642312752 From: Juzhe-Zhong To: gcc-patches@gcc.gnu.org Cc: kito.cheng@gmail.com, kito.cheng@sifive.com, jeffreyalaw@gmail.com, rdapp.gcc@gmail.com, Juzhe-Zhong Subject: [PATCH] RISC-V: Use VLS modes if the NITERS is known and smaller than VLS mode elements. Date: Mon, 16 Oct 2023 16:27:15 +0800 Message-Id: <20231016082715.3417414-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, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, TXREP 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: 1779899977890847582 X-GMAIL-MSGID: 1779899977890847582 void foo8 (int64_t *restrict a) { for (int i = 0; i < 16; ++i) a[i] = a[i]-16; } We use VLS modes instead of VLA modes even it is specified by dynamic LMUL. gcc/ChangeLog: * config/riscv/riscv-vector-costs.cc (costs::preferred_new_lmul_p): Use VLS modes. gcc/testsuite/ChangeLog: * gcc.dg/vect/costmodel/riscv/rvv/no-dynamic-lmul-1.c: New test. --- gcc/config/riscv/riscv-vector-costs.cc | 13 ++-- .../costmodel/riscv/rvv/no-dynamic-lmul-1.c | 64 +++++++++++++++++++ 2 files changed, 73 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/no-dynamic-lmul-1.c diff --git a/gcc/config/riscv/riscv-vector-costs.cc b/gcc/config/riscv/riscv-vector-costs.cc index 11257f7c2bd..4482af2e039 100644 --- a/gcc/config/riscv/riscv-vector-costs.cc +++ b/gcc/config/riscv/riscv-vector-costs.cc @@ -530,10 +530,6 @@ costs::preferred_new_lmul_p (const vector_costs *uncast_other) const auto other_loop_vinfo = as_a (other->m_vinfo); class loop *loop = LOOP_VINFO_LOOP (this_loop_vinfo); - if (!LOOP_VINFO_CAN_USE_PARTIAL_VECTORS_P (this_loop_vinfo) - && LOOP_VINFO_CAN_USE_PARTIAL_VECTORS_P (other_loop_vinfo)) - return false; - if (loop_autovec_infos.get (loop) && loop_autovec_infos.get (loop)->end_p) return false; else if (loop_autovec_infos.get (loop)) @@ -567,6 +563,15 @@ costs::preferred_new_lmul_p (const vector_costs *uncast_other) const machine_mode biggest_mode = compute_local_live_ranges (program_points_per_bb, live_ranges_per_bb); + /* If we can use simple VLS modes to handle NITERS element. + We don't need to use VLA modes with partial vector auto-vectorization. */ + if (LOOP_VINFO_NITERS_KNOWN_P (this_loop_vinfo) + && known_le (tree_to_poly_int64 (LOOP_VINFO_NITERS (this_loop_vinfo)) + * GET_MODE_SIZE (biggest_mode).to_constant (), + (int) RVV_M8 * BYTES_PER_RISCV_VECTOR) + && pow2p_hwi (LOOP_VINFO_INT_NITERS (this_loop_vinfo))) + return vector_costs::better_main_loop_than_p (other); + /* Update live ranges according to PHI. */ update_local_live_ranges (other->m_vinfo, program_points_per_bb, live_ranges_per_bb); diff --git a/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/no-dynamic-lmul-1.c b/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/no-dynamic-lmul-1.c new file mode 100644 index 00000000000..7ede148396f --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/no-dynamic-lmul-1.c @@ -0,0 +1,64 @@ +/* { dg-do compile } */ +/* { dg-options "-march=rv64gcv_zvl4096b -mabi=lp64d -fdump-tree-vect-details" } */ + +#include + +void +foo (int8_t *restrict a) +{ + for (int i = 0; i < 4096; ++i) + a[i] = a[i]-16; +} + +void +foo2 (int16_t *restrict a) +{ + for (int i = 0; i < 2048; ++i) + a[i] = a[i]-16; +} + +void +foo3 (int32_t *restrict a) +{ + for (int i = 0; i < 1024; ++i) + a[i] = a[i]-16; +} + +void +foo4 (int64_t *restrict a) +{ + for (int i = 0; i < 512; ++i) + a[i] = a[i]-16; +} + +void +foo5 (int8_t *restrict a) +{ + for (int i = 0; i < 16; ++i) + a[i] = a[i]-16; +} + +void +foo6 (int16_t *restrict a) +{ + for (int i = 0; i < 16; ++i) + a[i] = a[i]-16; +} + +void +foo7 (int32_t *restrict a) +{ + for (int i = 0; i < 16; ++i) + a[i] = a[i]-16; +} + +void +foo8 (int64_t *restrict a) +{ + for (int i = 0; i < 16; ++i) + a[i] = a[i]-16; +} + +/* { dg-final { scan-tree-dump-not "Maximum lmul" "vect" } } */ +/* { dg-final { scan-assembler-times {vsetvli} 4 } } */ +/* { dg-final { scan-assembler-times {vsetivli} 4 } } */