From patchwork Thu May 11 12:47:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robin Dapp X-Patchwork-Id: 92555 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp4342136vqo; Thu, 11 May 2023 05:48:14 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7CbJpfe0ukhb4oy0I1hYDyx39F4hHQOvQF5Gh+GUNuUHZItysRHxXgQpsjstArNdc3Jvr1 X-Received: by 2002:a17:907:3f28:b0:94f:5847:8a8 with SMTP id hq40-20020a1709073f2800b0094f584708a8mr20297751ejc.23.1683809293867; Thu, 11 May 2023 05:48:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683809293; cv=none; d=google.com; s=arc-20160816; b=ODz+9NabsDFyT4apCEkzvGfQccujTAtEdK0S1wwYVNB2ppvam7F2OtSW4+AbakOOH0 Ee+h9WQkxA/jLkCtYzbv5Wq/Br16jHBb0461wFeJ1M8yCfkdJ3L/9lugoZS0Yq88cb8i Y38cmXvVDlpEBCQpr11DWU9zMbfD0SeUDvPpPOdF+tLy5zf1nY9KEEc0Qsw9IE3Tz/zW HhoqnkflaQa8vSqGhth7APOUhySMA3TZ8ZX6wMBEKzBQ0BUKcWmBcYHsAZ61Nrq81/H3 HNro+W6TojNcjivypsC74NnQI9xM0NgRRDTRsemwSPFjXH+BSo7CdSMIXApRmhxCv3gX wwMg== 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:in-reply-to:references:to :content-language:subject:user-agent:mime-version:date:message-id :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=Nt8gfplXnOclYM6SVPG1MuXN1JTAnUApkQVLpmxVM38=; b=cXr7071J1utnabB1D9ioCs6Re80QiDdFVhNOxj+eE9n2XotiUwIhI8neps1ij0M1qf +RZYGhJjCbFSuwfOyAhhsRLA0sCHCtJXtetL0LfYbswQQ1sPFF8uvjG1w6m6jPWtBznj gjilEdX3VUdbG8I4tL3AU0soMdb5B9l56frfvI+J28r/1u1rcKkvuBzwC/5GXYqcNBCC g5gUTuC5+0fuSaU7VpEWFI2/htYyq2XGT8NOjkvypAUE5IsVhPKN01TuCCCOIKwnajoZ x6ptqyXycpXUolkaTZJEfipNUIKKBOLQ37s7f/zwk6iQWAoEq9IX382mv2QzkVnafPBm IqUw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=tWMtpjHW; 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=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id c13-20020a170906340d00b0096a74be3dcesi643675ejb.548.2023.05.11.05.48.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 May 2023 05:48:13 -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; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=tWMtpjHW; 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=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8060C3857030 for ; Thu, 11 May 2023 12:48:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8060C3857030 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1683809292; bh=Nt8gfplXnOclYM6SVPG1MuXN1JTAnUApkQVLpmxVM38=; h=Date:Subject:To:References:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=tWMtpjHWNtxlryYiBC37U1xFs5zogg7BBx13lthLa2o1kq4Bt1MzpR/j9hBa0Rcg7 AGtclTqRrrFF/AxvjT2a5qN8ywwbE50vBbyEqydEQxdIdAUZK2s0tGRxlsQvULaxEG 1DTBOISbsOWt9NkMPon6dxM0p/eW9w1Fi2Vs7W+Y= 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 651873858D33 for ; Thu, 11 May 2023 12:47:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 651873858D33 Received: by mail-ej1-x62a.google.com with SMTP id a640c23a62f3a-965a68abfd4so1615378466b.2 for ; Thu, 11 May 2023 05:47:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683809246; x=1686401246; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Nt8gfplXnOclYM6SVPG1MuXN1JTAnUApkQVLpmxVM38=; b=hFGUrsPPsyLKRPhXEmH3xWK088u4BqMoyovNkLhfEXqpYeSwlILPuNfIBGczKlWRg/ V6W+S99QRo6ITEw+2pmlVfN3ZMemnYLth24m1PedUeOZR+Lu1E4jgYOjpcqiQ9bRmaB9 CWItcOpiceOlsKV7llIT4umofYmA7taU8/jIJgdrxs8pFRGd/N5inxDFuvvakWLtZJFq 7VzkAlMVZDPbCn43Jxs6EaFev16ywnZvwHo8fTWPP7LAOgKmaMmQN89dSILCX9Jij8qy CXWE3mKn+e/ND5IxhAbiY5xccGydJ2InkI6i4IDZeUwa6eTh4Cj4Npq6nX4dfGQ6Rbxo xsRg== X-Gm-Message-State: AC+VfDyBkPIaGP2EJUlZ5X6JsFjJQjViXcAin8PVuVkRGdiHqhmjneCD GdE1hOLc2NLD09R5VIr0ByI= X-Received: by 2002:a17:907:3f83:b0:94e:8d26:f610 with SMTP id hr3-20020a1709073f8300b0094e8d26f610mr18925717ejc.28.1683809245724; Thu, 11 May 2023 05:47:25 -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 l2-20020a1709066b8200b00966447c76f3sm3970956ejr.39.2023.05.11.05.47.24 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 11 May 2023 05:47:25 -0700 (PDT) Message-ID: <3bd0d367-8ea4-3446-abe6-a7c7a5065248@gmail.com> Date: Thu, 11 May 2023 14:47:24 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.10.0 Subject: [PATCH v2] RISC-V: Allow vector constants in riscv_const_insns. Content-Language: en-US To: =?utf-8?b?6ZKf5bGF5ZOy?= , Jeff Law , gcc-patches , "kito.cheng" , "kito.cheng" , palmer , Michael Collison References: <46ca12b2-8ac6-030e-92dc-6b71ab2d4ee8@gmail.com> <4B555E0D49C3178B+2023050413074589268520@rivai.ai> <6B74F0215DD1EAD6+2023050708091558978410@rivai.ai> In-Reply-To: <6B74F0215DD1EAD6+2023050708091558978410@rivai.ai> X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, KAM_MANYTO, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, 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: , 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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1765602014337430473?= X-GMAIL-MSGID: =?utf-8?q?1765602014337430473?= > OK, you can go ahead commit patch. I am gonna send another patch to > fix this. I agree that we should handle more constants but I'd still rather go ahead now and fix things later. The patch is more about the test rather than the actual change anyway. Jeff already ack'ed v1, maybe waiting for Kito's OK to push still. (Minor) changes from v1: - Rebase vs Juzhe's patch - Change test format to match binops. This patch adds various vector constants to riscv_const_insns in order for them to be properly recognized as immediate operands. This then allows to emit vmv.v.i instructions via autovectorization. gcc/ChangeLog: * config/riscv/riscv.cc (riscv_const_insns): Add permissible vector constants. gcc/testsuite/ChangeLog: * gcc.target/riscv/rvv/autovec/vmv-imm-rv32.c: New test. * gcc.target/riscv/rvv/autovec/vmv-imm-rv64.c: New test. * gcc.target/riscv/rvv/autovec/vmv-imm-template.h: New test. * gcc.target/riscv/rvv/autovec/vmv-imm-run.c: New test. --- gcc/config/riscv/riscv.cc | 7 +++ .../riscv/rvv/autovec/vmv-imm-run.c | 57 +++++++++++++++++++ .../riscv/rvv/autovec/vmv-imm-rv32.c | 6 ++ .../riscv/rvv/autovec/vmv-imm-rv64.c | 6 ++ .../riscv/rvv/autovec/vmv-imm-template.h | 54 ++++++++++++++++++ 5 files changed, 130 insertions(+) create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/autovec/vmv-imm-run.c create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/autovec/vmv-imm-rv32.c create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/autovec/vmv-imm-rv64.c create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/autovec/vmv-imm-template.h diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc index 8f032250b0f..de578b5b899 100644 --- a/gcc/config/riscv/riscv.cc +++ b/gcc/config/riscv/riscv.cc @@ -1291,6 +1291,13 @@ riscv_const_insns (rtx x) return 1; } } + /* Constants from -16 to 15 can be loaded with vmv.v.i. + The Wc0, Wc1 constraints are already covered by the + vi constraint so we do not need to check them here + separately. */ + else if (TARGET_VECTOR && satisfies_constraint_vi (x)) + return 1; + /* TODO: We may support more const vector in the future. */ return x == CONST0_RTX (GET_MODE (x)) ? 1 : 0; } diff --git a/gcc/testsuite/gcc.target/riscv/rvv/autovec/vmv-imm-run.c b/gcc/testsuite/gcc.target/riscv/rvv/autovec/vmv-imm-run.c new file mode 100644 index 00000000000..309a296b686 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/vmv-imm-run.c @@ -0,0 +1,57 @@ +/* { dg-do run { target { riscv_vector } } } */ +/* { dg-additional-options "-std=c99 -fno-vect-cost-model --param=riscv-autovec-preference=scalable -fno-builtin" } */ + +#include "vmv-imm-template.h" + +#include +#include + +#define SZ 512 + +#define TEST_POS(TYPE,VAL) \ + TYPE a##TYPE##VAL[SZ]; \ + vmv_##VAL (a##TYPE##VAL, SZ); \ + for (int i = 0; i < SZ; i++) \ + assert (a##TYPE##VAL[i] == VAL); + +#define TEST_NEG(TYPE,VAL) \ + TYPE am##TYPE##VAL[SZ]; \ + vmv_m##VAL (am##TYPE##VAL, SZ); \ + for (int i = 0; i < SZ; i++) \ + assert (am##TYPE##VAL[i] == -VAL); + +int main () +{ + TEST_NEG(int8_t, 16) + TEST_NEG(int8_t, 15) + TEST_NEG(int8_t, 14) + TEST_NEG(int8_t, 13) + TEST_NEG(int16_t, 12) + TEST_NEG(int16_t, 11) + TEST_NEG(int16_t, 10) + TEST_NEG(int16_t, 9) + TEST_NEG(int32_t, 8) + TEST_NEG(int32_t, 7) + TEST_NEG(int32_t, 6) + TEST_NEG(int32_t, 5) + TEST_NEG(int64_t, 4) + TEST_NEG(int64_t, 3) + TEST_NEG(int64_t, 2) + TEST_NEG(int64_t, 1) + TEST_POS(uint8_t, 0) + TEST_POS(uint8_t, 1) + TEST_POS(uint8_t, 2) + TEST_POS(uint8_t, 3) + TEST_POS(uint16_t, 4) + TEST_POS(uint16_t, 5) + TEST_POS(uint16_t, 6) + TEST_POS(uint16_t, 7) + TEST_POS(uint32_t, 8) + TEST_POS(uint32_t, 9) + TEST_POS(uint32_t, 10) + TEST_POS(uint32_t, 11) + TEST_POS(uint64_t, 12) + TEST_POS(uint64_t, 13) + TEST_POS(uint64_t, 14) + TEST_POS(uint64_t, 15) +} diff --git a/gcc/testsuite/gcc.target/riscv/rvv/autovec/vmv-imm-rv32.c b/gcc/testsuite/gcc.target/riscv/rvv/autovec/vmv-imm-rv32.c new file mode 100644 index 00000000000..c419256cd45 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/vmv-imm-rv32.c @@ -0,0 +1,6 @@ +/* { dg-do compile } */ +/* { dg-additional-options "-std=c99 -march=rv32gcv -mabi=ilp32d -fno-vect-cost-model --param=riscv-autovec-preference=scalable -fno-builtin" } */ + +#include "vmv-imm-template.h" + +/* { dg-final { scan-assembler-times "vmv.v.i" 32 } } */ diff --git a/gcc/testsuite/gcc.target/riscv/rvv/autovec/vmv-imm-rv64.c b/gcc/testsuite/gcc.target/riscv/rvv/autovec/vmv-imm-rv64.c new file mode 100644 index 00000000000..520321e1c73 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/vmv-imm-rv64.c @@ -0,0 +1,6 @@ +/* { dg-do compile } */ +/* { dg-additional-options "-std=c99 -march=rv64gcv -fno-vect-cost-model --param=riscv-autovec-preference=scalable -fno-builtin" } */ + +#include "vmv-imm-template.h" + +/* { dg-final { scan-assembler-times "vmv.v.i" 32 } } */ diff --git a/gcc/testsuite/gcc.target/riscv/rvv/autovec/vmv-imm-template.h b/gcc/testsuite/gcc.target/riscv/rvv/autovec/vmv-imm-template.h new file mode 100644 index 00000000000..93ba5204c2e --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/vmv-imm-template.h @@ -0,0 +1,54 @@ +#include +#include + +#define VMV_POS(TYPE,VAL) \ + __attribute__ ((noipa)) \ + void vmv_##VAL (TYPE dst[], int n) \ + { \ + for (int i = 0; i < n; i++) \ + dst[i] = VAL; \ + } + +#define VMV_NEG(TYPE,VAL) \ + __attribute__ ((noipa)) \ + void vmv_m##VAL (TYPE dst[], int n) \ + { \ + for (int i = 0; i < n; i++) \ + dst[i] = -VAL; \ + } + +#define TEST_ALL() \ +VMV_NEG(int8_t,16) \ +VMV_NEG(int8_t,15) \ +VMV_NEG(int8_t,14) \ +VMV_NEG(int8_t,13) \ +VMV_NEG(int16_t,12) \ +VMV_NEG(int16_t,11) \ +VMV_NEG(int16_t,10) \ +VMV_NEG(int16_t,9) \ +VMV_NEG(int32_t,8) \ +VMV_NEG(int32_t,7) \ +VMV_NEG(int32_t,6) \ +VMV_NEG(int32_t,5) \ +VMV_NEG(int64_t,4) \ +VMV_NEG(int64_t,3) \ +VMV_NEG(int64_t,2) \ +VMV_NEG(int64_t,1) \ +VMV_POS(uint8_t,0) \ +VMV_POS(uint8_t,1) \ +VMV_POS(uint8_t,2) \ +VMV_POS(uint8_t,3) \ +VMV_POS(uint16_t,4) \ +VMV_POS(uint16_t,5) \ +VMV_POS(uint16_t,6) \ +VMV_POS(uint16_t,7) \ +VMV_POS(uint32_t,8) \ +VMV_POS(uint32_t,9) \ +VMV_POS(uint32_t,10) \ +VMV_POS(uint32_t,11) \ +VMV_POS(uint64_t,12) \ +VMV_POS(uint64_t,13) \ +VMV_POS(uint64_t,14) \ +VMV_POS(uint64_t,15) + +TEST_ALL()