From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qt1-x829.google.com (mail-qt1-x829.google.com [IPv6:2607:f8b0:4864:20::829]) by sourceware.org (Postfix) with ESMTPS id 0D5E8385E839 for ; Wed, 8 Mar 2023 03:27:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0D5E8385E839 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=rivosinc.com Received: by mail-qt1-x829.google.com with SMTP id cf14so16886838qtb.10 for ; Tue, 07 Mar 2023 19:27:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20210112.gappssmtp.com; s=20210112; t=1678246067; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=VUyWDNSCfd9tpMrPfw0bXIPkIR42DMUKLXD7a4GvbNw=; b=oJ93Mx1tgu/vyx5y8aPR9d95Tgfr/G5rvz9j1hjkYXkHbnr7F4hmn7swJRpqYREi0V 9LPgekMCYwYjhPddM4d4qvcBbpCM4KBmhXSYWuvE6q7wlSnMukGJ8CQTsPpgKHRuzK5H bX85/pjj77U2qaCCNPiUq6R+3QfUISv1hUiKsxZILncyjVr1cPrg72vYAVYdP01X6pPl A2BzmZeUvPzr7PyUZCdqnw2eMTAQgcv8KJk1I2GaNbzPD/ApOCC/76lgLxc6UO08TXGP RO7jvh547HDX5rbaW7S88rTkqhEV7i/0vC3jKd5yZPfGPzGkoZzU1KGEN8KtYSGoQdGx GpSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678246067; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=VUyWDNSCfd9tpMrPfw0bXIPkIR42DMUKLXD7a4GvbNw=; b=4C6/OC/bMVmDA4abRrEAmkVS1xDTQhbAp8+ADLjTijKccYtb2fOHpYA9oj+ap6cCBF +jJUoz9Kb/fffX1RA5zrr2d4bYtdVZvMZnYjCfxBg4UJJ5mAdHIxy4L3DaUETdjnXMlu EAUd1aGlAGHX0WQiDw4U1IDJshFSKqCrKJV++NnkcReeUp6zLKReB0hZZ9/Oe7r7hJ2X lOGOjNTlIMz7gn3lc4idJcblqUO266S0zU5MRTH3lp4cK/Gwh45U1G7oH7gsTGproiZD Tso265ENwiF1hk6mtkNByuM86+0Azb18/qVGjwsalFiSJo5rMincTmx8qKfKLHDIJzYZ mqMg== X-Gm-Message-State: AO0yUKWfxH6gAeH7xvNVEJt9gErJm3PBj00VKSz7LBgx3Wxps9W2oe3V pWWClfSvqedt6dCKbVglPkUpxEvGX6qU9E3TWhQ= X-Google-Smtp-Source: AK7set+wVlVSXtRBrs6mhucTjJ/S2RakAZdlhk5OzOyX435CxG2v1KEcHuazc/ehdfKPsCO8fwpUvg== X-Received: by 2002:ac8:5e0c:0:b0:3b8:6d70:9fe2 with SMTP id h12-20020ac85e0c000000b003b86d709fe2mr19479733qtx.59.1678246067225; Tue, 07 Mar 2023 19:27:47 -0800 (PST) Received: from system76-pc.ba.rivosinc.com ([136.57.172.92]) by smtp.gmail.com with ESMTPSA id v21-20020ac87295000000b003b6382f66b1sm10759696qto.29.2023.03.07.19.27.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Mar 2023 19:27:46 -0800 (PST) From: Michael Collison To: gcc-patches@gcc.gnu.org Subject: [PATCH v3 5/6] RISC-V: autovec: Add autovectorization patterns for add & sub Date: Tue, 7 Mar 2023 22:27:39 -0500 Message-Id: <20230308032740.989275-6-collison@rivosinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230308032740.989275-1-collison@rivosinc.com> References: <20230308032740.989275-1-collison@rivosinc.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-12.1 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,GIT_PATCH_0,KAM_ASCII_DIVIDERS,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 List-Id: 2023-03-02 Michael Collison Juzhe Zhong * config/riscv/riscv.md (riscv_vector_preferred_simd_mode): Include vector-iterators.md. * config/riscv/vector-auto.md: New file containing autovectorization patterns. * config/riscv/vector-iterators.md (UNSPEC_VADD/UNSPEC_VSUB): New unspecs for autovectorization patterns. * config/riscv/vector.md: Remove include of vector-iterators.md and include vector-auto.md. --- gcc/config/riscv/riscv.md | 1 + gcc/config/riscv/vector-auto.md | 172 +++++++++++++++++++++++++++ gcc/config/riscv/vector-iterators.md | 2 + gcc/config/riscv/vector.md | 4 +- 4 files changed, 177 insertions(+), 2 deletions(-) create mode 100644 gcc/config/riscv/vector-auto.md diff --git a/gcc/config/riscv/riscv.md b/gcc/config/riscv/riscv.md index 6c3176042fb..a504ace72e5 100644 --- a/gcc/config/riscv/riscv.md +++ b/gcc/config/riscv/riscv.md @@ -131,6 +131,7 @@ (include "predicates.md") (include "constraints.md") (include "iterators.md") +(include "vector-iterators.md") ;; .................... ;; diff --git a/gcc/config/riscv/vector-auto.md b/gcc/config/riscv/vector-auto.md new file mode 100644 index 00000000000..5227a73d96d --- /dev/null +++ b/gcc/config/riscv/vector-auto.md @@ -0,0 +1,172 @@ +;; Machine description for RISC-V 'V' Extension for GNU compiler. +;; Copyright (C) 2022-2023 Free Software Foundation, Inc. +;; Contributed by Juzhe Zhong (juzhe.zhong@rivai.ai), RiVAI Technologies Ltd. +;; Contributed by Michael Collison (collison@rivosinc.com, Rivos Inc. + +;; This file is part of GCC. + +;; GCC is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation; either version 3, or (at your option) +;; any later version. + +;; GCC is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with GCC; see the file COPYING3. If not see +;; . + + +;; ------------------------------------------------------------------------- +;; ---- [INT] Addition +;; ------------------------------------------------------------------------- +;; Includes: +;; - vadd.vv +;; - vadd.vx +;; - vadd.vi +;; ------------------------------------------------------------------------- + +(define_expand "add3" + [(match_operand:VI 0 "register_operand") + (match_operand:VI 1 "register_operand") + (match_operand:VI 2 "vector_arith_operand")] + "TARGET_VECTOR" +{ + using namespace riscv_vector; + + rtx merge = RVV_VUNDEF (mode); + rtx vl = emit_vlmax_vsetvl (mode); + rtx mask_policy = get_mask_policy_no_pred(); + rtx tail_policy = get_tail_policy_no_pred(); + rtx mask = CONSTM1_RTX(mode); + rtx vlmax_avl_p = get_avl_type_rtx(NONVLMAX); + + emit_insn(gen_pred_add(operands[0], mask, merge, operands[1], operands[2], + vl, tail_policy, mask_policy, vlmax_avl_p)); + + DONE; +}) + +(define_expand "cond_add" + [(match_operand:VI 0 "register_operand") + (match_operand: 1 "register_operand") + (match_operand:VI 2 "register_operand") + (match_operand:VI 3 "vector_reg_or_const_dup_operand") + (match_operand:VI 4 "register_operand")] + "TARGET_VECTOR" +{ + using namespace riscv_vector; + + rtx merge = operands[4]; + rtx vl = emit_vlmax_vsetvl (mode); + rtx mask_policy = get_mask_policy_no_pred(); + rtx tail_policy = get_tail_policy_no_pred(); + rtx mask = operands[1]; + rtx vlmax_avl_p = get_avl_type_rtx(NONVLMAX); + + emit_insn(gen_pred_add(operands[0], mask, merge, operands[2], operands[3], + vl, tail_policy, mask_policy, vlmax_avl_p)); + DONE; +}) + +(define_expand "len_add" + [(match_operand:VI 0 "register_operand") + (match_operand:VI 1 "register_operand") + (match_operand:VI 2 "vector_reg_or_const_dup_operand") + (match_operand 3 "p_reg_or_const_csr_operand")] + "TARGET_VECTOR" +{ + using namespace riscv_vector; + + rtx merge = RVV_VUNDEF (mode); + rtx vl = operands[3]; + rtx mask_policy = get_mask_policy_no_pred(); + rtx tail_policy = get_tail_policy_no_pred(); + rtx mask = CONSTM1_RTX(mode); + rtx vlmax_avl_p = get_avl_type_rtx(NONVLMAX); + + emit_insn(gen_pred_add(operands[0], mask, merge, operands[1], operands[2], + vl, tail_policy, mask_policy, vlmax_avl_p)); + DONE; +}) + + +;; ------------------------------------------------------------------------- +;; ---- [INT] Subtraction +;; ------------------------------------------------------------------------- +;; Includes: +;; - vsub.vv +;; - vsub.vx +;; - vadd.vi +;; - vrsub.vx +;; - vrsub.vi +;; ------------------------------------------------------------------------- + +(define_expand "sub3" + [(match_operand:VI 0 "register_operand") + (match_operand:VI 1 "register_operand") + (match_operand:VI 2 "register_operand")] + "TARGET_VECTOR" +{ + using namespace riscv_vector; + + rtx merge = RVV_VUNDEF (mode); + rtx vl = emit_vlmax_vsetvl (mode); + rtx mask_policy = get_mask_policy_no_pred(); + rtx tail_policy = get_tail_policy_no_pred(); + rtx mask = CONSTM1_RTX(mode); + rtx vlmax_avl_p = get_avl_type_rtx(NONVLMAX); + + emit_insn(gen_pred_sub(operands[0], mask, merge, operands[1], operands[2], + vl, tail_policy, mask_policy, vlmax_avl_p)); + + DONE; +}) + +(define_expand "cond_sub" + [(match_operand:VI 0 "register_operand") + (match_operand: 1 "register_operand") + (match_operand:VI 2 "register_operand") + (match_operand:VI 3 "register_operand") + (match_operand:VI 4 "register_operand")] + "TARGET_VECTOR" +{ + using namespace riscv_vector; + + rtx merge = operands[4]; + rtx vl = emit_vlmax_vsetvl (mode); + rtx mask_policy = get_mask_policy_no_pred(); + rtx tail_policy = get_tail_policy_no_pred(); + rtx mask = operands[1]; + rtx vlmax_avl_p = get_avl_type_rtx(NONVLMAX); + + emit_insn(gen_pred_sub(operands[0], mask, merge, operands[2], operands[3], + vl, tail_policy, mask_policy, vlmax_avl_p)); + + DONE; +}) + +(define_expand "len_sub" + [(match_operand:VI 0 "register_operand") + (match_operand:VI 1 "register_operand") + (match_operand:VI 2 "register_operand") + (match_operand 3 "p_reg_or_const_csr_operand")] + "TARGET_VECTOR" +{ + using namespace riscv_vector; + + rtx merge = RVV_VUNDEF (mode); + rtx vl = operands[3]; + rtx mask_policy = get_mask_policy_no_pred(); + rtx tail_policy = get_tail_policy_no_pred(); + rtx mask = CONSTM1_RTX(mode); + rtx vlmax_avl_p = get_avl_type_rtx(NONVLMAX); + + emit_insn(gen_pred_sub(operands[0], mask, merge, operands[1], operands[2], + vl, tail_policy, mask_policy, vlmax_avl_p)); + + DONE; +}) diff --git a/gcc/config/riscv/vector-iterators.md b/gcc/config/riscv/vector-iterators.md index 61e141e7b64..af80143ce90 100644 --- a/gcc/config/riscv/vector-iterators.md +++ b/gcc/config/riscv/vector-iterators.md @@ -34,6 +34,8 @@ UNSPEC_VMULHU UNSPEC_VMULHSU + UNSPEC_VADD + UNSPEC_VSUB UNSPEC_VADC UNSPEC_VSBC UNSPEC_VMADC diff --git a/gcc/config/riscv/vector.md b/gcc/config/riscv/vector.md index 2d4eb8bf1cd..85e531c83ef 100644 --- a/gcc/config/riscv/vector.md +++ b/gcc/config/riscv/vector.md @@ -26,8 +26,6 @@ ;; - Auto-vectorization (TBD) ;; - Combine optimization (TBD) -(include "vector-iterators.md") - (define_constants [ (INVALID_ATTRIBUTE 255) (X0_REGNUM 0) @@ -350,6 +348,8 @@ (symbol_ref "INTVAL (operands[4])")] (const_int INVALID_ATTRIBUTE))) +(include "vector-auto.md") + ;; ----------------------------------------------------------------- ;; ---- Miscellaneous Operations ;; ----------------------------------------------------------------- -- 2.34.1