From patchwork Wed Feb 28 04:16:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Li, Pan2" X-Patchwork-Id: 207662 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp3127985dyb; Tue, 27 Feb 2024 20:17:11 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCX5ZRSQrqzVjow1yTzMp4vfC0cu4z1FvA0VYYrxtcChpw/6f5TXaJEKaMvF1FkUY6KUPDTsuUrGE3x6YPFJ6VcjGnZ/Ug== X-Google-Smtp-Source: AGHT+IF6JygmXzL1cg3BYEIHAg8wBU8mejCWdksYnZJB1HbFd1Jtz1cXL3nYhbiIbM4VzJu3jbPN X-Received: by 2002:a67:e34e:0:b0:472:6b2c:9c52 with SMTP id s14-20020a67e34e000000b004726b2c9c52mr957795vsm.21.1709093831000; Tue, 27 Feb 2024 20:17:11 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709093830; cv=pass; d=google.com; s=arc-20160816; b=JOa7FGE3+R7epT7LWgn3i3+0fauHrQCKW/ZohQvD9dWl8VRJxXCeN4GTWaQag7I5hS cE/WHq7dc4GFZoY/r59Ntrfc+IKtjrTRA7fWjk6zVcoLP8k2aZR7QZ8gQTIeBwgPiCXB bffuxiBVYsQWfUKg5lpuYfaQlYVwfeMbYf5vSvIkIRBvgAE7jQLSodmkCXfRHfH5gkYt 08YsjZbnhD7tRoedi4ezAk/cUgLUS3ORP+pvHDmCZetjFH60jchGSvYXT1zwgqmDFDuv qfSDV7TL+LkNN2VuyuyaP8nWazsjdfYMLB6Dd7v7vXlFz+EzyxC0elwg7oqexvu6cbnt 74zQ== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature:arc-filter:dmarc-filter:delivered-to; bh=FgGYizlpwtb9+bJ8kB2134LFw2S6mI7hMVAA4d0+1sw=; fh=HOahLdxVPwEOTyfS+vjJu5aPtFjN/ZnZsgwt1+wU8BI=; b=BpfbzwkLo1PJJ5RVmvnzKCkFvwe32ELeSKvyy7eWzfqF/oN/BMj5Aso8VTqdusq79b FCtdXv81EZj72C3Ukqi8I0zmczuKVguiIVubD9/qKIuHbmhMRayHsvaYEpdzitiy61/I HhZALVaR79wlk8MKK6IVtFijv4QtyV0M35rEMAz/hY1eRV5FWO9TFkQsQejo8K8pWiXI CAi3gsEDNoRtn9KWgYu4Fx6ilzw8cJhmT7GIPmFteNRLfSNiXi5RBg1xJ3P3YDbhzc3t OB9oS9qNrHMLkQfXjtOwBPUFd/nNR2L8Iu7tc4ORETluvVPQUDUPXroh1uv+ysfnjbuQ m6GA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="nv1x/vmd"; 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"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id ow22-20020a05620a821600b00785ca459548si8698575qkn.113.2024.02.27.20.17.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 20:17:10 -0800 (PST) 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; dkim=pass header.i=@intel.com header.s=Intel header.b="nv1x/vmd"; 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"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B1C253858C5F for ; Wed, 28 Feb 2024 04:17:10 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.15]) by sourceware.org (Postfix) with ESMTPS id 62FFA3858C98 for ; Wed, 28 Feb 2024 04:16:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 62FFA3858C98 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=intel.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 62FFA3858C98 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=192.198.163.15 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709093793; cv=none; b=Zq5M/myHWMmyvoR1Eo2Z9MD4Jeka++f7W2+H85+HI/YJqQM6mCaKFC7H0KnSb5Ajy+8Ol+JzgieCUdHP7rpFxhmmnNJPf/dhdkSaAEcGZUOwgy0O4CBM10F/ylWBDFkIfVYXxikNZJKspApYgJPbl5tCLUM3FMrIwJh17ydaR2w= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709093793; c=relaxed/simple; bh=5dLaOpWjuQabOI/FwxVEj+YkrDs18Zh/W29tozvzR/Q=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=oD3MvtMBDhQ4VykTxC+JXtfwMTl1CH2prbChD3NBQB4/94E/FTujzfC1x3A6/3m7OaFsZurDQolbU0u9qQneZzMCR4q3NOHdM5RTLACL88k6smCWTXxj+bPq/BPn2xleD1Y3EgzRdDd9zJ1Cz4hV34VONFHarUx2123njPmbrE0= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1709093792; x=1740629792; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=5dLaOpWjuQabOI/FwxVEj+YkrDs18Zh/W29tozvzR/Q=; b=nv1x/vmd95gFfM5yMRrlyXpqGg5D7m8LXd66mkfq9dcD0gwJA1nCH0dt vQkzgwtZ8LIIzhRooQRZ499aPnJVgcX1zM3GgJqlBwevKL54OswFmatZn GqLEY+BLFGsTPux5cjwebtRrfXvWbol3H31asj5eFWN0vQli7RBZ9kxTf 4kuPd51fLsnR9nzlP9VxLBnmsWucI3sI6YBotKkUxhTWTUtY/r713ElFJ UHHP8eSPNJiQE9L2/DqElv2F0PmMlbet9t2h0ITo0zWX3CPa+MrhqRanX TPguAg6kTL6RrkZ+39bgReXP024SOajqxpAyTYB03/HwzDEj8TleljUJd Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10996"; a="3640709" X-IronPort-AV: E=Sophos;i="6.06,189,1705392000"; d="scan'208";a="3640709" Received: from fmviesa006.fm.intel.com ([10.60.135.146]) by fmvoesa109.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Feb 2024 20:16:30 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,189,1705392000"; d="scan'208";a="7506473" Received: from shvmail03.sh.intel.com ([10.239.245.20]) by fmviesa006.fm.intel.com with ESMTP; 27 Feb 2024 20:16:27 -0800 Received: from pli-ubuntu.sh.intel.com (pli-ubuntu.sh.intel.com [10.239.159.47]) by shvmail03.sh.intel.com (Postfix) with ESMTP id B52171006FE3; Wed, 28 Feb 2024 12:16:26 +0800 (CST) From: pan2.li@intel.com To: gcc-patches@gcc.gnu.org Cc: juzhe.zhong@rivai.ai, kito.cheng@gmail.com, yanzhang.wang@intel.com, rdapp.gcc@gmail.com, jeffreyalaw@gmail.com, Pan Li Subject: [PATCH v2] RISC-V: Introduce gcc option mrvv-vector-bits for RVV Date: Wed, 28 Feb 2024 12:16:25 +0800 Message-Id: <20240228041625.1469884-1-pan2.li@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240223080558.2644800-1-pan2.li@intel.com> References: <20240223080558.2644800-1-pan2.li@intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-11.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, SPF_HELO_NONE, SPF_NONE, 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: 1791676254160017510 X-GMAIL-MSGID: 1792114772867025134 From: Pan Li This patch would like to introduce one new gcc option for RVV. To appoint the bits size of one RVV vector register. Valid arguments to '-mrvv-vector-bits=' are: * zvl The zvl will pick up the zvl*b from the march option. For example, the mrvv-vector-bits will be 1024 when march=rv64gcv_zvl1024b. The below test are passed for this patch. * The riscv fully regression test. gcc/ChangeLog: * config/riscv/riscv-opts.h (enum rvv_vector_bits_enum): New enum for different RVV vector bits. * config/riscv/riscv.cc (riscv_convert_vector_bits): New func to get the RVV vector bits, with given min_vlen. (riscv_convert_vector_chunks): Combine the mrvv-vector-bits option with min_vlen to RVV vector chunks. (riscv_override_options_internal): Update comments and rename the vector chunks. * config/riscv/riscv.opt: Add option mrvv-vector-bits. gcc/testsuite/ChangeLog: * gcc.target/riscv/rvv/base/rvv-vector-bits-1.c: New test. * gcc.target/riscv/rvv/base/rvv-vector-bits-2.c: New test. * gcc.target/riscv/rvv/base/rvv-vector-bits-3.c: New test. Signed-off-by: Pan Li --- gcc/config/riscv/riscv-opts.h | 7 +++++ gcc/config/riscv/riscv.cc | 31 +++++++++++++++---- gcc/config/riscv/riscv.opt | 11 +++++++ .../riscv/rvv/base/rvv-vector-bits-1.c | 7 +++++ .../riscv/rvv/base/rvv-vector-bits-2.c | 7 +++++ .../riscv/rvv/base/rvv-vector-bits-3.c | 25 +++++++++++++++ 6 files changed, 82 insertions(+), 6 deletions(-) create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/rvv-vector-bits-1.c create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/rvv-vector-bits-2.c create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/rvv-vector-bits-3.c diff --git a/gcc/config/riscv/riscv-opts.h b/gcc/config/riscv/riscv-opts.h index 4edddbadc37..0162e00515b 100644 --- a/gcc/config/riscv/riscv-opts.h +++ b/gcc/config/riscv/riscv-opts.h @@ -129,6 +129,13 @@ enum vsetvl_strategy_enum { VSETVL_OPT_NO_FUSION, }; +/* RVV vector bits for option -mrvv-vector-bits + zvl indicates take the bits of zvl*b provided by march as vector bits. + */ +enum rvv_vector_bits_enum { + RVV_VECTOR_BITS_ZVL, +}; + #define TARGET_ZICOND_LIKE (TARGET_ZICOND || (TARGET_XVENTANACONDOPS && TARGET_64BIT)) /* Bit of riscv_zvl_flags will set contintuly, N-1 bit will set if N-bit is diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc index 5e984ee2a55..d18e5226bce 100644 --- a/gcc/config/riscv/riscv.cc +++ b/gcc/config/riscv/riscv.cc @@ -8801,13 +8801,32 @@ riscv_init_machine_status (void) return ggc_cleared_alloc (); } -/* Return the VLEN value associated with -march. +static int +riscv_convert_vector_bits (int min_vlen) +{ + int rvv_bits = 0; + + switch (rvv_vector_bits) + { + case RVV_VECTOR_BITS_ZVL: + rvv_bits = min_vlen; + break; + default: + gcc_unreachable (); + } + + return rvv_bits; +} + +/* Return the VLEN value associated with -march and -mwrvv-vector-bits. TODO: So far we only support length-agnostic value. */ static poly_uint16 -riscv_convert_vector_bits (struct gcc_options *opts) +riscv_convert_vector_chunks (struct gcc_options *opts) { int chunk_num; int min_vlen = TARGET_MIN_VLEN_OPTS (opts); + int rvv_bits = riscv_convert_vector_bits (min_vlen); + if (min_vlen > 32) { /* When targetting minimum VLEN > 32, we should use 64-bit chunk size. @@ -8826,7 +8845,7 @@ riscv_convert_vector_bits (struct gcc_options *opts) - TARGET_MIN_VLEN = 2048bit: [256,256] - TARGET_MIN_VLEN = 4096bit: [512,512] FIXME: We currently DON'T support TARGET_MIN_VLEN > 4096bit. */ - chunk_num = min_vlen / 64; + chunk_num = rvv_bits / 64; } else { @@ -8848,7 +8867,7 @@ riscv_convert_vector_bits (struct gcc_options *opts) if (TARGET_VECTOR_OPTS_P (opts)) { if (opts->x_riscv_autovec_preference == RVV_FIXED_VLMAX) - return (int) min_vlen / (riscv_bytes_per_vector_chunk * 8); + return (int) rvv_bits / (riscv_bytes_per_vector_chunk * 8); else return poly_uint16 (chunk_num, chunk_num); } @@ -8920,8 +8939,8 @@ riscv_override_options_internal (struct gcc_options *opts) if (TARGET_VECTOR && TARGET_BIG_ENDIAN) sorry ("Current RISC-V GCC does not support RVV in big-endian mode"); - /* Convert -march to a chunks count. */ - riscv_vector_chunks = riscv_convert_vector_bits (opts); + /* Convert -march and -mrvv-vector-bits to a chunks count. */ + riscv_vector_chunks = riscv_convert_vector_chunks (opts); } /* Implement TARGET_OPTION_OVERRIDE. */ diff --git a/gcc/config/riscv/riscv.opt b/gcc/config/riscv/riscv.opt index 20685c42aed..42ea8efd05d 100644 --- a/gcc/config/riscv/riscv.opt +++ b/gcc/config/riscv/riscv.opt @@ -607,3 +607,14 @@ Enum(stringop_strategy) String(vector) Value(STRATEGY_VECTOR) mstringop-strategy= Target RejectNegative Joined Enum(stringop_strategy) Var(stringop_strategy) Init(STRATEGY_AUTO) Specify stringop expansion strategy. + +Enum +Name(rvv_vector_bits) Type(enum rvv_vector_bits_enum) +The possible RVV vector register lengths: + +EnumValue +Enum(rvv_vector_bits) String(zvl) Value(RVV_VECTOR_BITS_ZVL) + +mrvv-vector-bits= +Target RejectNegative Joined Enum(rvv_vector_bits) Var(rvv_vector_bits) Init(RVV_VECTOR_BITS_ZVL) +-mrvv-vector-bits=zvl Set the number of bits in zvl for an RVV vector register. diff --git a/gcc/testsuite/gcc.target/riscv/rvv/base/rvv-vector-bits-1.c b/gcc/testsuite/gcc.target/riscv/rvv/base/rvv-vector-bits-1.c new file mode 100644 index 00000000000..24bc4211cde --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/rvv/base/rvv-vector-bits-1.c @@ -0,0 +1,7 @@ +/* { dg-do compile } */ +/* { dg-options "-march=rv64gcv_zvl256b -mabi=lp64 -mrvv-vector-bits=128 -O3" } */ + +#include "riscv_vector.h" + +/* { dg-error "unrecognized argument in option '-mrvv-vector-bits=128'" "" { target { "riscv*-*-*" } } 0 } */ +/* { dg-message "note: valid arguments to '-mrvv-vector-bits=' are: zvl" "" { target { "riscv*-*-*" } } 0 } */ diff --git a/gcc/testsuite/gcc.target/riscv/rvv/base/rvv-vector-bits-2.c b/gcc/testsuite/gcc.target/riscv/rvv/base/rvv-vector-bits-2.c new file mode 100644 index 00000000000..f4f8ff6a6fb --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/rvv/base/rvv-vector-bits-2.c @@ -0,0 +1,7 @@ +/* { dg-do compile } */ +/* { dg-options "-march=rv64gcv_zvl256b -mabi=lp64 -mrvv-vector-bits=invalid-bits -O3" } */ + +#include "riscv_vector.h" + +/* { dg-error "unrecognized argument in option '-mrvv-vector-bits=invalid-bits" "" { target { "riscv*-*-*" } } 0 } */ +/* { dg-message "note: valid arguments to '-mrvv-vector-bits=' are: zvl" "" { target { "riscv*-*-*" } } 0 } */ diff --git a/gcc/testsuite/gcc.target/riscv/rvv/base/rvv-vector-bits-3.c b/gcc/testsuite/gcc.target/riscv/rvv/base/rvv-vector-bits-3.c new file mode 100644 index 00000000000..962cc8ffa6d --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/rvv/base/rvv-vector-bits-3.c @@ -0,0 +1,25 @@ +/* { dg-do compile } */ +/* { dg-options "-march=rv64gcv_zvl128b -mabi=lp64 -mrvv-vector-bits=zvl -O3 -fno-schedule-insns -fno-schedule-insns2" } */ +/* { dg-final { check-function-bodies "**" "" } } */ + +/* +** test_rvv_vector_bits_zvl: +** ... +** vsetivli\s+zero,\s*4,\s*e32,\s*m1,\s*ta,\s*ma +** vle32\.v\s+v[0-9]+,\s*0\(a0\) +** vle32\.v\s+v[0-9]+,\s*0\(a1\) +** vadd\.vv\s+v[0-9]+,\s*v[0-9]+,\s*v[0-9]+ +** vse32\.v\s+v[0-9]+,\s*0\(a2\) +** ... +** vle32\.v\s+v[0-9]+,\s*0\(a0\) +** vle32\.v\s+v[0-9]+,\s*0\(a1\) +** vadd\.vv\s+v[0-9]+,\s*v[0-9]+,\s*v[0-9]+ +** vse32\.v\s+v[0-9]+,\s*0\(a2\) +** ret +** ... +*/ +void test_rvv_vector_bits_zvl (int *a, int *b, int *out) +{ + for (int i = 0; i < 8; i++) + out[i] = a[i] + b[i]; +}