From patchwork Wed Jun 14 11:56:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lehua Ding X-Patchwork-Id: 107918 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1185970vqr; Wed, 14 Jun 2023 04:56:48 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5aL0ia1yyygHPc6Zftq/v0hudGu+60oiQqteeMeFw0TLAxhDnldh6y+6mKyw+8VhscX+cQ X-Received: by 2002:a17:907:8a09:b0:961:be96:b0e7 with SMTP id sc9-20020a1709078a0900b00961be96b0e7mr17980172ejc.48.1686743807888; Wed, 14 Jun 2023 04:56:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686743807; cv=none; d=google.com; s=arc-20160816; b=aa8anKPRSTpqC+cauibYR72D2kRNaJS7YcXKxdzx/SSRPUlHUGHtCHj/Hwi4GM3A32 6rHcQo2WyhoKUZqp2fP5c5mq3GdpHVPhcGdPpi5vkC6dV8pH5WPN7XheZPrQxQ5+iWJM KNd8eQzzTCMhqx6f3E1+QRF40rE2TA5yM6igrWYwn9f3AJ1/oi2KriOqCQPP1+NBQBos SOJvkX+O2/NKeDrwq4pfpHhcWYupU28QRCXChp6XpzUL6pQIGc8m3EUjxIRmIdcS2rdG eQ+yiICQhN2Nf/FjexMUW9hcLL/TQNW44+Uk9FDa2qxtJ55kGGYUXOFnlTOB8QWm7w4F LQoQ== 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=M9xLWFh4Zuvd2WJ4IgATdWUe6QZeJPLDJIUrQDZ5Q6M=; b=QWTWvOSIsdulvCDRNEUD4KzTdx9AjGNwsInXRJPdsxoIsfT4WNuh7kN1ROKkUjWBhV KPIARwOZJNwojhtMjS7PcskS5HxVSgIefRWohcO8kUx6p3EkZ1ZY5URfiZzFZ+3+wZSb +Kgos1ApnMB8CVWlpesP/z66U3/uh6KFdMa9T4DHdLYj1EfEbNfsj8e49MJtLnYIOxJg JDnuIiKp7knNtN2GHsdHla9mr9rhBqMUgxLuvM3H+asekr3V59w6VU6dzcHclX/qI5PD jSDn6QkHyeqyns1XcckmGI8izSirE2Lurcru6/Y7N3Pnxhfg9aL/cOhxJf+oWUjt9cuz 5Yqw== ARC-Authentication-Results: i=1; mx.google.com; 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 sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id b3-20020a170906038300b0098236e5735esi2486925eja.928.2023.06.14.04.56.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Jun 2023 04:56:47 -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; 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 8A2E2385770B for ; Wed, 14 Jun 2023 11:56:42 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtpbguseast1.qq.com (smtpbguseast1.qq.com [54.204.34.129]) by sourceware.org (Postfix) with ESMTPS id 258843858D1E for ; Wed, 14 Jun 2023 11:56:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 258843858D1E 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: bizesmtp65t1686743772tgek51f3 Received: from rios-cad5.localdomain ( [58.60.1.11]) by bizesmtp.qq.com (ESMTP) with id ; Wed, 14 Jun 2023 19:56:11 +0800 (CST) X-QQ-SSF: 01400000000000B0E000000A0000000 X-QQ-FEAT: s7lzof/HE2PNVwZLZJxlJq9s3TRx3hNgzjTAmOr2EN/ETDyJiYzVti2vCBBNQ ExhVgQQbzWzxyYrT3TPnz4D86faiovNaaLxQvj+f83u9fPQdbh6ZsrPUa09JLMFxEVPHQbP 1U94LrrEe7fytCP7HInnxfr0cTh2S4hqQ7wdPd+NsGNL5JExZcHnfu3HSa7AGGsBM+C268f 0M8fQvnoWhx6GYE5xcjt6NjtHwn7bdiGwofXiLsLNDFzhxaivwqn4MeSQ9NvXQlpQHxhDWf e/YBMUO3rppuYs6d7YV4vB6YKLE509rt5dXG5rG4kO40Uy/xV5h/duasviHP4Y0CZ0RZDgS j4Nx04babfrcoCfrZXAt7ZrOM0tGkebZGqRO2P6boGeniSlx3dkPuM+tkHUt4BfrED0GZz+ iMLWQozi6WE= X-QQ-GoodBg: 2 X-BIZMAIL-ID: 14501006733461560462 From: Lehua Ding To: gcc-patches@gcc.gnu.org Cc: juzhe.zhong@rivai.ai, rdapp.gcc@gamil.com, jeffreyalaw@gamil.com, palmer@rivosinc.com Subject: [PATCH V2] RISC-V: Ensure vector args and return use function stack to pass [PR110119] Date: Wed, 14 Jun 2023 19:56:11 +0800 Message-Id: <20230614115611.2227435-1-lehua.ding@rivai.ai> X-Mailer: git-send-email 2.36.3 MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:rivai.ai:qybglogicsvrgz:qybglogicsvrgz5a-3 X-Spam-Status: No, score=-11.6 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H5, 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?1768675753180010136?= X-GMAIL-MSGID: =?utf-8?q?1768679074904031696?= The V2 patch address comments from Juzhe, thanks. Hi, The reason for this bug is that in the case where the vector register is set to a fixed length (with `--param=riscv-autovec-preference=fixed-vlmax` option), TARGET_PASS_BY_REFERENCE thinks that variables of type vint32m1 can be passed through two scalar registers, but when GCC calls FUNCTION_VALUE (call function riscv_get_arg_info inside) it returns NULL_RTX. These two functions are not unified. The current treatment is to pass all vector arguments and returns through the function stack, and a new calling convention for vector registers will be added in the future. Best, Lehua PR target/110119 gcc/ChangeLog: * config/riscv/riscv.cc (riscv_get_arg_info): Return NULL_RTX for vector mode (riscv_pass_by_reference): Return true for vector mode gcc/testsuite/ChangeLog: * gcc.target/riscv/rvv/base/pr110119-1.c: New test. * gcc.target/riscv/rvv/base/pr110119-2.c: New test. --- gcc/config/riscv/riscv.cc | 17 ++++++++---- .../gcc.target/riscv/rvv/base/pr110119-1.c | 26 +++++++++++++++++++ .../gcc.target/riscv/rvv/base/pr110119-2.c | 26 +++++++++++++++++++ 3 files changed, 64 insertions(+), 5 deletions(-) create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/pr110119-1.c create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/pr110119-2.c diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc index dd5361c2bd2a..e5ae4e81b7a5 100644 --- a/gcc/config/riscv/riscv.cc +++ b/gcc/config/riscv/riscv.cc @@ -3915,13 +3915,13 @@ riscv_get_arg_info (struct riscv_arg_info *info, const CUMULATIVE_ARGS *cum, riscv_pass_in_vector_p (type); } - /* TODO: Currently, it will cause an ICE for --param - riscv-autovec-preference=fixed-vlmax. So, we just return NULL_RTX here - let GCC generate loads/stores. Ideally, we should either warn the user not - to use an RVV vector type as function argument or support the calling - convention directly. */ + /* All current vector arguments and return values are passed through the + function stack. Ideally, we should either warn the user not to use an RVV + vector type as function argument or support a calling convention + with better performance. */ if (riscv_v_ext_mode_p (mode)) return NULL_RTX; + if (named) { riscv_aggregate_field fields[2]; @@ -4106,6 +4106,13 @@ riscv_pass_by_reference (cumulative_args_t cum_v, const function_arg_info &arg) return false; } + /* All current vector arguments and return values are passed through the + function stack. Ideally, we should either warn the user not to use an RVV + vector type as function argument or support a calling convention + with better performance. */ + if (riscv_v_ext_mode_p (arg.mode)) + return true; + /* Pass by reference if the data do not fit in two integer registers. */ return !IN_RANGE (size, 0, 2 * UNITS_PER_WORD); } diff --git a/gcc/testsuite/gcc.target/riscv/rvv/base/pr110119-1.c b/gcc/testsuite/gcc.target/riscv/rvv/base/pr110119-1.c new file mode 100644 index 000000000000..f16502bcfeec --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/rvv/base/pr110119-1.c @@ -0,0 +1,26 @@ +/* { dg-do compile } */ +/* { dg-options "-march=rv64gcv --param=riscv-autovec-preference=fixed-vlmax" } */ + +#include "riscv_vector.h" + +typedef int8_t vnx2qi __attribute__ ((vector_size (2))); + +__attribute__ ((noipa)) vnx2qi +f_vnx2qi (int8_t a, int8_t b, int8_t *out) +{ + vnx2qi v = {a, b}; + return v; +} + +__attribute__ ((noipa)) vnx2qi +f_vnx2qi_2 (vnx2qi a, int8_t *out) +{ + return a; +} + +__attribute__ ((noipa)) vint32m1_t +f_vint32m1 (int8_t *a, int8_t *out) +{ + vint32m1_t v = *(vint32m1_t *) a; + return v; +} diff --git a/gcc/testsuite/gcc.target/riscv/rvv/base/pr110119-2.c b/gcc/testsuite/gcc.target/riscv/rvv/base/pr110119-2.c new file mode 100644 index 000000000000..b233ff1e9040 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/rvv/base/pr110119-2.c @@ -0,0 +1,26 @@ +/* { dg-do compile } */ +/* { dg-options "-march=rv64gczve32x --param=riscv-autovec-preference=fixed-vlmax" } */ + +#include +#include "riscv_vector.h" + +__attribute__ ((noipa)) vint32m1x3_t +foo1 (int32_t *in, int vl) +{ + vint32m1x3_t v = __riscv_vlseg3e32_v_i32m1x3 (in, vl); + return v; +} + +__attribute__ ((noipa)) void +foo2 (vint32m1x3_t a, int32_t *out, int vl) +{ + __riscv_vsseg3e32_v_i32m1x3 (out, a, vl); +} + +__attribute__ ((noipa)) vint32m1x3_t +foo3 (vint32m1x3_t a, int32_t *out, int32_t *in, int vl) +{ + __riscv_vsseg3e32_v_i32m1x3 (out, a, vl); + vint32m1x3_t v = __riscv_vlseg3e32_v_i32m1x3 (in, vl); + return v; +}