From patchwork Tue Aug 15 14:02:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robin Dapp X-Patchwork-Id: 135665 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a888:0:b0:3f2:4152:657d with SMTP id x8csp451043vqo; Tue, 15 Aug 2023 07:03:30 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFCiUR6JDSjtbUwJuUl6nVS/5fyusmjVCDixnBoauzsCOviXXeZ2DBn+sXS2C73E4V06Bnq X-Received: by 2002:a19:4310:0:b0:4fb:89e3:5ac6 with SMTP id q16-20020a194310000000b004fb89e35ac6mr7130898lfa.62.1692108210338; Tue, 15 Aug 2023 07:03:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692108210; cv=none; d=google.com; s=arc-20160816; b=zXOF7xo2kgiZIgt0XYPW03KIf9XtS53QLwYqNmbI/Gw5IcpruzLPrzz8iTjwREZPfe 5dzlEWJwUGBpFIFqoJNsZSoQbyDEwRP950CwcwHTI3FATkIl5y9wLoaSMb+PFQzBjPhk 6/L2yIYTet9KwbzY2y4otNKAYQ/jeogP4aAHOtMNoGgHUufaWuEsH8YgnLXgbNGa2Mym Xim8m9QIHkGv+pzGHdrShmDRnyJC96ticdiFhh6c2JYeMc+KHcOBh1oWHRUBqrIier8G 4xGbljQq7JYA5SrdYW8fcuExqh/oszsUNEuumReSOCHx26K2ylG7LvGInmOpkUqqaFmk DN9g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:to:subject:content-language:cc:user-agent :mime-version:date:message-id:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=yANRAFyOFk3VQgD7YTRqij9TZ/VnMmVUwIUXtOLU7R8=; fh=RfNrlHQvzmof9NqH9dQWc9AEnQIKqQyorVQkBsH4SEI=; b=RVnaz2dvfmP2wgsHzBOUZzeQ9Z8HI/pv25Ykn7jhqkd6+c2jl6AjCcvoIxatcfkXpQ ma+45QOCkVBDmm5d/v5xmt3BDM1UIiMiHMJNS4NB5Jd+Sf8X6PAVSi8M/O987RbGAxJN +HaoIlccKvHskrRnwuZ0eYcfZYr+kx3+W0ycy4I3CGgPw7K9YVo2EC/+34rvOZ4peFsN ioy5BrLW4wTIajuDp79IaefcF3um3yjMNQA5wM8yFP2ruT9UpRn8A/+V5XHtkQNSLHjb yUsxIOC17cBYD+scYidzrWXwahzaCogKxzhhiUBWRzdDiOe2rjLtYxLs/GlCo1s/M1f2 bY+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=qdiFkQvp; 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"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id w2-20020aa7cb42000000b005222a59ce7asi9738848edt.22.2023.08.15.07.03.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Aug 2023 07:03:30 -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; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=qdiFkQvp; 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"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 805F3385697F for ; Tue, 15 Aug 2023 14:03:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 805F3385697F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1692108208; bh=yANRAFyOFk3VQgD7YTRqij9TZ/VnMmVUwIUXtOLU7R8=; h=Date:Cc:Subject:To:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=qdiFkQvpZ3UZq/jWSAQXS5b3pnBnEfqmSTkW2BPF3apBzpOuasPSAoS3gUcV4YlSM kpN3BZ4iW+3eX9v80tLHbUs7FyVkLEWTT/aPKYXvDl1qPKiUWs3lWmRZTplDGIi7yw KnRpyT6GU2UhCh6jftUu6hhdi5pTzG+om0z1pBZ4= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-ej1-x62a.google.com (mail-ej1-x62a.google.com [IPv6:2a00:1450:4864:20::62a]) by sourceware.org (Postfix) with ESMTPS id C41193857357 for ; Tue, 15 Aug 2023 14:02:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C41193857357 Received: by mail-ej1-x62a.google.com with SMTP id a640c23a62f3a-991c786369cso734735466b.1 for ; Tue, 15 Aug 2023 07:02:43 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692108162; x=1692712962; h=content-transfer-encoding:to:subject:from:content-language:cc :user-agent:mime-version:date:message-id:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=yANRAFyOFk3VQgD7YTRqij9TZ/VnMmVUwIUXtOLU7R8=; b=iW/+GMFXnWIsfHqEZUQMtJhA/bgROsLEXOUpL1PvUqE7jaJomXrRYlKZ5jEMSuHKIB myN8QLV9bg4Eu1wdm6hHqnoNp7YIL3dg5Ku/sHw2zPuXbh+VRWM3Ju/fkE0MV7/w/OTu IGWpuLrw1V+P9WJAnr0exQ+8i4Dkx9gwwIbnITM0MFt6SfFb2kOL5IaTezOQrwaY47Ae bphoSAAwPii+3vwSM55f2Y2ZBPvoR9XzlUrjEktzQVu6MaLQ02N/b0L5xv67jyNmlClk 4pOe5HHf3v+V5HiPYm19JLFQIzi1i4UIOoq/fDd7WY2xh3b+MG70LBMrC+ES3Y9Oms3o 3HCQ== X-Gm-Message-State: AOJu0Yy8+tA75Gzb37ks9ua4ExrWxJaBb/4WXF9VtNgcPe4wJDLNfOCl eAY9GEyIRs72DxZJGZuwmY3FViIKDHQ= X-Received: by 2002:a17:907:77cb:b0:993:f744:d230 with SMTP id kz11-20020a17090777cb00b00993f744d230mr9557854ejc.16.1692108161741; Tue, 15 Aug 2023 07:02:41 -0700 (PDT) Received: from [192.168.1.23] (ip-046-005-130-086.um12.pools.vodafone-ip.de. [46.5.130.86]) by smtp.gmail.com with ESMTPSA id kg2-20020a17090776e200b0098f99048053sm7197720ejc.148.2023.08.15.07.02.41 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 15 Aug 2023 07:02:41 -0700 (PDT) Message-ID: <4b3d91c7-6d6b-cfff-4279-ce991f761b16@gmail.com> Date: Tue, 15 Aug 2023 16:02:40 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 Cc: rdapp.gcc@gmail.com Content-Language: en-US Subject: [PATCH] IFN: Fix vector extraction into promoted subreg. To: gcc-patches X-Spam-Status: No, score=-9.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, 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.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Robin Dapp via Gcc-patches From: Robin Dapp Reply-To: Robin Dapp Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1774304059103470087 X-GMAIL-MSGID: 1774304059103470087 Hi, this patch fixes the case where vec_extract gets passed a promoted subreg (e.g. from a return value). When such a subreg is the destination of a vector extraction we create a separate pseudo register and ensure that the necessary promotion is performed afterwards. Before this patch a sign-extended subreg would erroneously not be zero-extended e.g. when used as return value. I added missing test cases for unsigned vec_extract on RISC-V that check the proper behavior. Testsuite and bootstrap done on x86, aarch64 and power10. Regards Robin gcc/ChangeLog: * internal-fn.cc (expand_vec_extract_optab_fn): Handle SUBREG_PROMOTED_VAR_P. gcc/testsuite/ChangeLog: * gcc.target/riscv/rvv/autovec/vls-vlmax/vec_extract-1u.c: New test. * gcc.target/riscv/rvv/autovec/vls-vlmax/vec_extract-2u.c: New test. * gcc.target/riscv/rvv/autovec/vls-vlmax/vec_extract-3u.c: New test. * gcc.target/riscv/rvv/autovec/vls-vlmax/vec_extract-4u.c: New test. * gcc.target/riscv/rvv/autovec/vls-vlmax/vec_extract-runu.c: New test. --- gcc/internal-fn.cc | 25 +++- .../rvv/autovec/vls-vlmax/vec_extract-1u.c | 63 ++++++++ .../rvv/autovec/vls-vlmax/vec_extract-2u.c | 69 +++++++++ .../rvv/autovec/vls-vlmax/vec_extract-3u.c | 69 +++++++++ .../rvv/autovec/vls-vlmax/vec_extract-4u.c | 70 +++++++++ .../rvv/autovec/vls-vlmax/vec_extract-runu.c | 137 ++++++++++++++++++ 6 files changed, 430 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/autovec/vls-vlmax/vec_extract-1u.c create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/autovec/vls-vlmax/vec_extract-2u.c create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/autovec/vls-vlmax/vec_extract-3u.c create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/autovec/vls-vlmax/vec_extract-4u.c create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/autovec/vls-vlmax/vec_extract-runu.c diff --git a/gcc/internal-fn.cc b/gcc/internal-fn.cc index 4f2b20a79e5..b1b12cc8369 100644 --- a/gcc/internal-fn.cc +++ b/gcc/internal-fn.cc @@ -3150,14 +3150,33 @@ expand_vec_extract_optab_fn (internal_fn, gcall *stmt, convert_optab optab) if (icode != CODE_FOR_nothing) { - create_output_operand (&ops[0], target, extract_mode); + /* Some backends like riscv sign-extend the extraction result to a full + Pmode register. If we are passed a promoted subreg as target make + sure not to use it as target directly. Instead, use a new pseudo + and perform the necessary extension afterwards. */ + rtx dest = target; + if (target && SUBREG_P (target) && SUBREG_PROMOTED_VAR_P (target)) + dest = gen_reg_rtx (extract_mode); + + create_output_operand (&ops[0], dest, extract_mode); + create_input_operand (&ops[1], src, outermode); create_convert_operand_from (&ops[2], pos, TYPE_MODE (TREE_TYPE (op1)), true); if (maybe_expand_insn (icode, 3, ops)) { - if (!rtx_equal_p (target, ops[0].value)) - emit_move_insn (target, ops[0].value); + if (!rtx_equal_p (dest, target)) + { + if (SUBREG_P (target) && SUBREG_PROMOTED_VAR_P (target)) + { + /* Have convert_move perform the subreg promotion. */ + rtx tmp = convert_to_mode (extract_mode, ops[0].value, 0); + convert_move (SUBREG_REG (target), tmp, + SUBREG_PROMOTED_SIGN (target)); + } + else + emit_move_insn (target, dest); + } return; } } diff --git a/gcc/testsuite/gcc.target/riscv/rvv/autovec/vls-vlmax/vec_extract-1u.c b/gcc/testsuite/gcc.target/riscv/rvv/autovec/vls-vlmax/vec_extract-1u.c new file mode 100644 index 00000000000..a35988ff55d --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/vls-vlmax/vec_extract-1u.c @@ -0,0 +1,63 @@ +/* { dg-do compile } */ +/* { dg-additional-options "-march=rv64gcv_zvfh -mabi=lp64d -Wno-pedantic -Wno-psabi" } */ + +#include + +typedef uint64_t vnx2di __attribute__((vector_size (16))); +typedef uint32_t vnx4si __attribute__((vector_size (16))); +typedef uint16_t vnx8hi __attribute__((vector_size (16))); +typedef uint8_t vnx16qi __attribute__((vector_size (16))); + +#define VEC_EXTRACT(S,V,IDX) \ + S \ + __attribute__((noipa)) \ + vec_extract_##V##_##IDX (V v) \ + { \ + return v[IDX]; \ + } + +#define VEC_EXTRACT_VAR1(S,V) \ + S \ + __attribute__((noipa)) \ + vec_extract_var_##V (V v, int8_t idx) \ + { \ + return v[idx]; \ + } + +#define TEST_ALL1(T) \ + T (uint64_t, vnx2di, 0) \ + T (uint64_t, vnx2di, 1) \ + T (uint32_t, vnx4si, 0) \ + T (uint32_t, vnx4si, 1) \ + T (uint32_t, vnx4si, 3) \ + T (uint16_t, vnx8hi, 0) \ + T (uint16_t, vnx8hi, 2) \ + T (uint16_t, vnx8hi, 6) \ + T (uint8_t, vnx16qi, 0) \ + T (uint8_t, vnx16qi, 1) \ + T (uint8_t, vnx16qi, 7) \ + T (uint8_t, vnx16qi, 11) \ + T (uint8_t, vnx16qi, 15) \ + +#define TEST_ALL_VAR1(T) \ + T (uint64_t, vnx2di) \ + T (uint32_t, vnx4si) \ + T (uint16_t, vnx8hi) \ + T (uint8_t, vnx16qi) \ + +TEST_ALL1 (VEC_EXTRACT) +TEST_ALL_VAR1 (VEC_EXTRACT_VAR1) + +/* { dg-final { scan-assembler-times {vset[i]*vli\s+[a-z0-9,]+,\s*e8,\s*m1,\s*ta,\s*ma} 6 } } */ +/* { dg-final { scan-assembler-times {vset[i]*vli\s+[a-z0-9,]+,\s*e16,\s*m1,\s*ta,\s*ma} 4 } } */ +/* { dg-final { scan-assembler-times {vset[i]*vli\s+[a-z0-9,]+,\s*e32,\s*m1,\s*ta,\s*ma} 4 } } */ +/* { dg-final { scan-assembler-times {vset[i]*vli\s+[a-z0-9,]+,\s*e64,\s*m1,\s*ta,\s*ma} 3 } } */ + +/* { dg-final { scan-assembler-times {\tvslidedown.vi} 9 } } */ +/* { dg-final { scan-assembler-times {\tvslidedown.vx} 4 } } */ + +/* { dg-final { scan-assembler-times {\tvmv.x.s} 17 } } */ + +/* { dg-final { scan-assembler-times {\tandi\ta0,a0,0xff} 6 } } */ +/* { dg-final { scan-assembler-times {\tslli\ta0,a0,48} 4 } } */ +/* { dg-final { scan-assembler-times {\tsrli\ta0,a0,48} 4 } } */ diff --git a/gcc/testsuite/gcc.target/riscv/rvv/autovec/vls-vlmax/vec_extract-2u.c b/gcc/testsuite/gcc.target/riscv/rvv/autovec/vls-vlmax/vec_extract-2u.c new file mode 100644 index 00000000000..8c3c16a7047 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/vls-vlmax/vec_extract-2u.c @@ -0,0 +1,69 @@ +/* { dg-do compile } */ +/* { dg-additional-options "-march=rv64gcv_zvfh -mabi=lp64d -Wno-pedantic -Wno-psabi" } */ + +#include + +typedef uint64_t vnx4di __attribute__((vector_size (32))); +typedef uint32_t vnx8si __attribute__((vector_size (32))); +typedef uint16_t vnx16hi __attribute__((vector_size (32))); +typedef uint8_t vnx32qi __attribute__((vector_size (32))); + +#define VEC_EXTRACT(S,V,IDX) \ + S \ + __attribute__((noipa)) \ + vec_extract_##V##_##IDX (V v) \ + { \ + return v[IDX]; \ + } + +#define VEC_EXTRACT_VAR2(S,V) \ + S \ + __attribute__((noipa)) \ + vec_extract_var_##V (V v, int16_t idx) \ + { \ + return v[idx]; \ + } + +#define TEST_ALL2(T) \ + T (uint64_t, vnx4di, 0) \ + T (uint64_t, vnx4di, 1) \ + T (uint64_t, vnx4di, 2) \ + T (uint64_t, vnx4di, 3) \ + T (uint32_t, vnx8si, 0) \ + T (uint32_t, vnx8si, 1) \ + T (uint32_t, vnx8si, 3) \ + T (uint32_t, vnx8si, 4) \ + T (uint32_t, vnx8si, 7) \ + T (uint16_t, vnx16hi, 0) \ + T (uint16_t, vnx16hi, 1) \ + T (uint16_t, vnx16hi, 7) \ + T (uint16_t, vnx16hi, 8) \ + T (uint16_t, vnx16hi, 15) \ + T (uint8_t, vnx32qi, 0) \ + T (uint8_t, vnx32qi, 1) \ + T (uint8_t, vnx32qi, 15) \ + T (uint8_t, vnx32qi, 16) \ + T (uint8_t, vnx32qi, 31) \ + +#define TEST_ALL_VAR2(T) \ + T (uint64_t, vnx4di) \ + T (uint32_t, vnx8si) \ + T (uint16_t, vnx16hi) \ + T (uint8_t, vnx32qi) \ + +TEST_ALL2 (VEC_EXTRACT) +TEST_ALL_VAR2 (VEC_EXTRACT_VAR2) + +/* { dg-final { scan-assembler-times {vset[i]*vli\s+[a-z0-9,]+,\s*e8,\s*m2,\s*ta,\s*ma} 6 } } */ +/* { dg-final { scan-assembler-times {vset[i]*vli\s+[a-z0-9,]+,\s*e16,\s*m2,\s*ta,\s*ma} 6 } } */ +/* { dg-final { scan-assembler-times {vset[i]*vli\s+[a-z0-9,]+,\s*e32,\s*m2,\s*ta,\s*ma} 6 } } */ +/* { dg-final { scan-assembler-times {vset[i]*vli\s+[a-z0-9,]+,\s*e64,\s*m2,\s*ta,\s*ma} 5 } } */ + +/* { dg-final { scan-assembler-times {\tvslidedown.vi} 15 } } */ +/* { dg-final { scan-assembler-times {\tvslidedown.vx} 4 } } */ + +/* { dg-final { scan-assembler-times {\tvmv.x.s} 23 } } */ + +/* { dg-final { scan-assembler-times {\tandi\ta0,a0,0xff} 6 } } */ +/* { dg-final { scan-assembler-times {\tslli\ta0,a0,48} 6 } } */ +/* { dg-final { scan-assembler-times {\tsrli\ta0,a0,48} 6 } } */ diff --git a/gcc/testsuite/gcc.target/riscv/rvv/autovec/vls-vlmax/vec_extract-3u.c b/gcc/testsuite/gcc.target/riscv/rvv/autovec/vls-vlmax/vec_extract-3u.c new file mode 100644 index 00000000000..ab49f29c3f2 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/vls-vlmax/vec_extract-3u.c @@ -0,0 +1,69 @@ +/* { dg-do compile } */ +/* { dg-additional-options "-march=rv64gcv_zvfh -mabi=lp64d -Wno-pedantic -Wno-psabi" } */ + +#include + +typedef uint64_t vnx8di __attribute__((vector_size (64))); +typedef uint32_t vnx16si __attribute__((vector_size (64))); +typedef uint16_t vnx32hi __attribute__((vector_size (64))); +typedef uint8_t vnx64qi __attribute__((vector_size (64))); + +#define VEC_EXTRACT(S,V,IDX) \ + S \ + __attribute__((noipa)) \ + vec_extract_##V##_##IDX (V v) \ + { \ + return v[IDX]; \ + } + +#define VEC_EXTRACT_VAR3(S,V) \ + S \ + __attribute__((noipa)) \ + vec_extract_var_##V (V v, int32_t idx) \ + { \ + return v[idx]; \ + } + +#define TEST_ALL3(T) \ + T (uint64_t, vnx8di, 0) \ + T (uint64_t, vnx8di, 2) \ + T (uint64_t, vnx8di, 4) \ + T (uint64_t, vnx8di, 6) \ + T (uint32_t, vnx16si, 0) \ + T (uint32_t, vnx16si, 2) \ + T (uint32_t, vnx16si, 6) \ + T (uint32_t, vnx16si, 8) \ + T (uint32_t, vnx16si, 14) \ + T (uint16_t, vnx32hi, 0) \ + T (uint16_t, vnx32hi, 2) \ + T (uint16_t, vnx32hi, 14) \ + T (uint16_t, vnx32hi, 16) \ + T (uint16_t, vnx32hi, 30) \ + T (uint8_t, vnx64qi, 0) \ + T (uint8_t, vnx64qi, 2) \ + T (uint8_t, vnx64qi, 30) \ + T (uint8_t, vnx64qi, 32) \ + T (uint8_t, vnx64qi, 63) \ + +#define TEST_ALL_VAR3(T) \ + T (uint64_t, vnx8di) \ + T (uint32_t, vnx16si) \ + T (uint16_t, vnx32hi) \ + T (uint8_t, vnx64qi) \ + +TEST_ALL3 (VEC_EXTRACT) +TEST_ALL_VAR3 (VEC_EXTRACT_VAR3) + +/* { dg-final { scan-assembler-times {vset[i]*vli\s+[a-z0-9,]+,\s*e8,\s*m4,\s*ta,\s*ma} 6 } } */ +/* { dg-final { scan-assembler-times {vset[i]*vli\s+[a-z0-9,]+,\s*e16,\s*m4,\s*ta,\s*ma} 6 } } */ +/* { dg-final { scan-assembler-times {vset[i]*vli\s+[a-z0-9,]+,\s*e32,\s*m4,\s*ta,\s*ma} 6 } } */ +/* { dg-final { scan-assembler-times {vset[i]*vli\s+[a-z0-9,]+,\s*e64,\s*m4,\s*ta,\s*ma} 5 } } */ + +/* { dg-final { scan-assembler-times {\tvslidedown.vi} 13 } } */ +/* { dg-final { scan-assembler-times {\tvslidedown.vx} 6 } } */ + +/* { dg-final { scan-assembler-times {\tvmv.x.s} 23 } } */ + +/* { dg-final { scan-assembler-times {\tandi\ta0,a0,0xff} 6 } } */ +/* { dg-final { scan-assembler-times {\tslli\ta0,a0,48} 6 } } */ +/* { dg-final { scan-assembler-times {\tsrli\ta0,a0,48} 6 } } */ diff --git a/gcc/testsuite/gcc.target/riscv/rvv/autovec/vls-vlmax/vec_extract-4u.c b/gcc/testsuite/gcc.target/riscv/rvv/autovec/vls-vlmax/vec_extract-4u.c new file mode 100644 index 00000000000..328d426e572 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/vls-vlmax/vec_extract-4u.c @@ -0,0 +1,70 @@ +/* { dg-do compile } */ +/* { dg-additional-options "-march=rv64gcv_zvfh -mabi=lp64d -Wno-pedantic -Wno-psabi" } */ + +#include + +typedef uint64_t vnx16di __attribute__((vector_size (128))); +typedef uint32_t vnx32si __attribute__((vector_size (128))); +typedef uint16_t vnx64hi __attribute__((vector_size (128))); +typedef uint8_t vnx128qi __attribute__((vector_size (128))); + +#define VEC_EXTRACT(S,V,IDX) \ + S \ + __attribute__((noipa)) \ + vec_extract_##V##_##IDX (V v) \ + { \ + return v[IDX]; \ + } + +#define VEC_EXTRACT_VAR4(S,V) \ + S \ + __attribute__((noipa)) \ + vec_extract_var_##V (V v, int64_t idx) \ + { \ + return v[idx]; \ + } + +#define TEST_ALL4(T) \ + T (uint64_t, vnx16di, 0) \ + T (uint64_t, vnx16di, 4) \ + T (uint64_t, vnx16di, 8) \ + T (uint64_t, vnx16di, 12) \ + T (uint32_t, vnx32si, 0) \ + T (uint32_t, vnx32si, 4) \ + T (uint32_t, vnx32si, 12) \ + T (uint32_t, vnx32si, 16) \ + T (uint32_t, vnx32si, 28) \ + T (uint16_t, vnx64hi, 0) \ + T (uint16_t, vnx64hi, 4) \ + T (uint16_t, vnx64hi, 28) \ + T (uint16_t, vnx64hi, 32) \ + T (uint16_t, vnx64hi, 60) \ + T (uint8_t, vnx128qi, 0) \ + T (uint8_t, vnx128qi, 4) \ + T (uint8_t, vnx128qi, 30) \ + T (uint8_t, vnx128qi, 60) \ + T (uint8_t, vnx128qi, 64) \ + T (uint8_t, vnx128qi, 127) \ + +#define TEST_ALL_VAR4(T) \ + T (uint64_t, vnx16di) \ + T (uint32_t, vnx32si) \ + T (uint16_t, vnx64hi) \ + T (uint8_t, vnx128qi) \ + +TEST_ALL4 (VEC_EXTRACT) +TEST_ALL_VAR4 (VEC_EXTRACT_VAR4) + +/* { dg-final { scan-assembler-times {vset[i]*vli\s+[a-z0-9,]+,\s*e8,\s*m8,\s*ta,\s*ma} 7 } } */ +/* { dg-final { scan-assembler-times {vset[i]*vli\s+[a-z0-9,]+,\s*e16,\s*m8,\s*ta,\s*ma} 6 } } */ +/* { dg-final { scan-assembler-times {vset[i]*vli\s+[a-z0-9,]+,\s*e32,\s*m8,\s*ta,\s*ma} 6 } } */ +/* { dg-final { scan-assembler-times {vset[i]*vli\s+[a-z0-9,]+,\s*e64,\s*m8,\s*ta,\s*ma} 5 } } */ + +/* { dg-final { scan-assembler-times {\tvslidedown.vi} 11 } } */ +/* { dg-final { scan-assembler-times {\tvslidedown.vx} 9 } } */ + +/* { dg-final { scan-assembler-times {\tvmv.x.s} 24 } } */ + +/* { dg-final { scan-assembler-times {\tandi\ta0,a0,0xff} 7 } } */ +/* { dg-final { scan-assembler-times {\tslli\ta0,a0,48} 6 } } */ +/* { dg-final { scan-assembler-times {\tsrli\ta0,a0,48} 6 } } */ diff --git a/gcc/testsuite/gcc.target/riscv/rvv/autovec/vls-vlmax/vec_extract-runu.c b/gcc/testsuite/gcc.target/riscv/rvv/autovec/vls-vlmax/vec_extract-runu.c new file mode 100644 index 00000000000..924e40c9dbb --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/vls-vlmax/vec_extract-runu.c @@ -0,0 +1,137 @@ +/* { dg-do run { target { riscv_vector } } } */ +/* { dg-additional-options "-std=c99 -Wno-pedantic -Wno-psabi" } */ + +#include +#include + +#include "vec_extract-1u.c" +#include "vec_extract-2u.c" +#include "vec_extract-3u.c" +#include "vec_extract-4u.c" + +#define CHECK(S, V, IDX) \ + __attribute__ ((noipa, optimize ("0"))) void check_##V##_##IDX () \ + { \ + V v; \ + for (int i = 0; i < sizeof (V) / sizeof (S); i++) \ + v[i] = (S) (INT_MAX - i); \ + S res = vec_extract_##V##_##IDX (v); \ + assert (res == (S) (INT_MAX - IDX)); \ + } + +#define CHECK_VAR(S, V) \ + __attribute__ ((noipa, optimize ("0"))) void check_var_##V (int32_t idx) \ + { \ + V v; \ + for (int i = 0; i < sizeof (V) / sizeof (S); i++) \ + v[i] = (S) (INT_MAX - i); \ + S res = vec_extract_var_##V (v, idx); \ + assert (res == (S) (INT_MAX - idx)); \ + } + +#define RUN(S, V, IDX) check_##V##_##IDX (); + +#define RUN_VAR(S, V) \ + for (int i = 0; i < sizeof (V) / sizeof (S); i++) \ + check_var_##V (i); + +#define RUN_ALL(T) \ + T (uint64_t, vnx2di, 0) \ + T (uint64_t, vnx2di, 1) \ + T (uint32_t, vnx4si, 0) \ + T (uint32_t, vnx4si, 1) \ + T (uint32_t, vnx4si, 3) \ + T (uint16_t, vnx8hi, 0) \ + T (uint16_t, vnx8hi, 2) \ + T (uint16_t, vnx8hi, 6) \ + T (uint8_t, vnx16qi, 0) \ + T (uint8_t, vnx16qi, 1) \ + T (uint8_t, vnx16qi, 7) \ + T (uint8_t, vnx16qi, 11) \ + T (uint8_t, vnx16qi, 15) \ + T (uint64_t, vnx4di, 0) \ + T (uint64_t, vnx4di, 1) \ + T (uint64_t, vnx4di, 2) \ + T (uint64_t, vnx4di, 3) \ + T (uint32_t, vnx8si, 0) \ + T (uint32_t, vnx8si, 1) \ + T (uint32_t, vnx8si, 3) \ + T (uint32_t, vnx8si, 4) \ + T (uint32_t, vnx8si, 7) \ + T (uint16_t, vnx16hi, 0) \ + T (uint16_t, vnx16hi, 1) \ + T (uint16_t, vnx16hi, 7) \ + T (uint16_t, vnx16hi, 8) \ + T (uint16_t, vnx16hi, 15) \ + T (uint8_t, vnx32qi, 0) \ + T (uint8_t, vnx32qi, 1) \ + T (uint8_t, vnx32qi, 15) \ + T (uint8_t, vnx32qi, 16) \ + T (uint8_t, vnx32qi, 31) \ + T (uint64_t, vnx8di, 0) \ + T (uint64_t, vnx8di, 2) \ + T (uint64_t, vnx8di, 4) \ + T (uint64_t, vnx8di, 6) \ + T (uint32_t, vnx16si, 0) \ + T (uint32_t, vnx16si, 2) \ + T (uint32_t, vnx16si, 6) \ + T (uint32_t, vnx16si, 8) \ + T (uint32_t, vnx16si, 14) \ + T (uint16_t, vnx32hi, 0) \ + T (uint16_t, vnx32hi, 2) \ + T (uint16_t, vnx32hi, 14) \ + T (uint16_t, vnx32hi, 16) \ + T (uint16_t, vnx32hi, 30) \ + T (uint8_t, vnx64qi, 0) \ + T (uint8_t, vnx64qi, 2) \ + T (uint8_t, vnx64qi, 30) \ + T (uint8_t, vnx64qi, 32) \ + T (uint8_t, vnx64qi, 63) \ + T (uint64_t, vnx16di, 0) \ + T (uint64_t, vnx16di, 4) \ + T (uint64_t, vnx16di, 8) \ + T (uint64_t, vnx16di, 12) \ + T (uint32_t, vnx32si, 0) \ + T (uint32_t, vnx32si, 4) \ + T (uint32_t, vnx32si, 12) \ + T (uint32_t, vnx32si, 16) \ + T (uint32_t, vnx32si, 28) \ + T (uint16_t, vnx64hi, 0) \ + T (uint16_t, vnx64hi, 4) \ + T (uint16_t, vnx64hi, 28) \ + T (uint16_t, vnx64hi, 32) \ + T (uint16_t, vnx64hi, 60) \ + T (uint8_t, vnx128qi, 0) \ + T (uint8_t, vnx128qi, 4) \ + T (uint8_t, vnx128qi, 30) \ + T (uint8_t, vnx128qi, 60) \ + T (uint8_t, vnx128qi, 64) \ + T (uint8_t, vnx128qi, 127) + +#define RUN_ALL_VAR(T) \ + T (uint64_t, vnx2di) \ + T (uint32_t, vnx4si) \ + T (uint16_t, vnx8hi) \ + T (uint8_t, vnx16qi) \ + T (uint64_t, vnx4di) \ + T (uint32_t, vnx8si) \ + T (uint16_t, vnx16hi) \ + T (uint8_t, vnx32qi) \ + T (uint64_t, vnx8di) \ + T (uint32_t, vnx16si) \ + T (uint16_t, vnx32hi) \ + T (uint8_t, vnx64qi) \ + T (uint64_t, vnx16di) \ + T (uint32_t, vnx32si) \ + T (uint16_t, vnx64hi) \ + T (uint8_t, vnx128qi) + +RUN_ALL (CHECK) +RUN_ALL_VAR (CHECK_VAR) + +int +main () +{ + RUN_ALL (RUN); + RUN_ALL_VAR (RUN_VAR); +}