From patchwork Mon Sep 4 11:14:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lehua Ding X-Patchwork-Id: 137448 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ab0a:0:b0:3f2:4152:657d with SMTP id m10csp1023845vqo; Mon, 4 Sep 2023 04:14:57 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF6ikrjYKAVjKYdrYDFJpwGigtZIyMXXCpFE6GF7P/tYUAZhvPPuf8aFfyWbOJq7Rl5oChc X-Received: by 2002:a05:6512:3b89:b0:500:cb2b:866f with SMTP id g9-20020a0565123b8900b00500cb2b866fmr8273779lfv.30.1693826096870; Mon, 04 Sep 2023 04:14:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693826096; cv=none; d=google.com; s=arc-20160816; b=brXc7DAelNB+NUNBWCM7o9B9vonNHJZ1kAi+S3s39S5gRfB+kNp595HX+2Qmn9/Sbp DkclQiBTJN311BOCGXoPJt5fnwf1LBdWSomK9dnBUS0LRSaFiLCVLjtym7eQrpSgeD44 DVKoTWQH44O+KtdqWXcHmujEE13I2gRu0brnyDy6IAe/pzqGMeLm2WRQQmzGhbBlbbjH IP/2DAcYnsl6+MccWkKQjMhIeOqZdRIyVNSvmn2xw88W23NpKgX33evwT43oxcAGHnRb F+D+cYQwZWL2WNMkGW+yrOtuoZmDPE9tbbdVM+FZN4tWQmdaRNAiC0pzlug/SZMD/VtQ +Juw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:feedback-id :content-transfer-encoding:mime-version:message-id:date:subject:to :from:dmarc-filter:delivered-to; bh=Gej3EQoMgtfm7/UaBan85wwCfjy/LTlI8TfdoxM8loI=; fh=flMKfU26Zf2bCSWDpkELM+XX9P5dENvjDCVykGrzV2k=; b=I2OPH9Zyp8R8TKui9VAwyAoAwAFRfgn56konL8g7+f7vGY5FuF8JpTqKlhE09WSfw+ bG/FEpsM8HGztcGi3BpbaWqO/k18rYDtjdIZIm8YlUjgbeOnI+c9Z83I1sCzNsU7xuGt UD9OL/FwsheqTVHdtp4oiQmhElyz0OI6LFfo4kgizHVYmhSM+mOnz9qBh7ZHpIiqNqHk 5VLb3E4Jr+mKzuQyAFa/I7tgnppN+qyTI8tvqHmjFNF2OdsJFadE7xgWoC/t74Ogvuj0 TlodM+zK2sTtYWYmFgRn7ZEzLbpI/tKqSBuvJFJUx7AUSXouHrQNu6pPYRVh0VyHSjOF gyCA== ARC-Authentication-Results: i=1; mx.google.com; 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" Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id i20-20020a0564020f1400b0052e1370eb9esi1975742eda.210.2023.09.04.04.14.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Sep 2023 04:14:56 -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; 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" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 44F563857B9B for ; Mon, 4 Sep 2023 11:14:50 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtpbgeu2.qq.com (smtpbgeu2.qq.com [18.194.254.142]) by sourceware.org (Postfix) with ESMTPS id 0DC3D3858425 for ; Mon, 4 Sep 2023 11:14:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0DC3D3858425 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: bizesmtp79t1693826051tncpzxwe Received: from rios-cad121.hadoop.rioslab.org ( [58.60.1.9]) by bizesmtp.qq.com (ESMTP) with id ; Mon, 04 Sep 2023 19:14:10 +0800 (CST) X-QQ-SSF: 01400000000000C0F000000A0000000 X-QQ-FEAT: LE7C6P2vL8RtlFK8WllpWma6UhwzwIdKt0fC5iLXXlnmPO/ZUZiSliMmJzG5t MpnBYSkFkI3hzm22Z+a7FutopHFAL7YUbpKWB7l7O25WS+61tg3rE5M41ZLTx/LfoGugBwF bWUOw0exZkn6dLYD6cNxSA0xCZDMn/jOqQk+r0rBUdUXJv684Z+NggUcKk947mB+vp8Nwbt tLWmOG/qX9rw++vQrkZCX4uJDwPkl8TgKh+yi/gRK+DS0c6ohMwYV28zcaSNpBm8gHio5oS QikLUK9+k1SJohjZUvgYm2mlWXwMkVjUtFWOwuVzZtpMicfkGoa1f86rb+RyF6qlt3fsbkf VzIzigiGSox0k2v6/BO2fX7dUYFXYlnOPppFcqplypWqqmQp6PnqjbqTmgtnXbU5hGhm4ih Wk/vXKtbdlQ= X-QQ-GoodBg: 2 X-BIZMAIL-ID: 16365638527407942940 From: Lehua Ding To: gcc-patches@gcc.gnu.org Subject: [PATCH] RISC-V: Keep vlmax vector operators in simple form until split1 pass Date: Mon, 4 Sep 2023 19:14:10 +0800 Message-Id: <20230904111410.3362365-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:qybglogicsvrgz6a-0 X-Spam-Status: No, score=-11.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_ASCII_DIVIDERS, KAM_DMARC_STATUS, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_PASS, TXREP, T_SPF_HELO_TEMPERROR 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: , Cc: kito.cheng@gmail.com, juzhe.zhong@rivai.ai Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776105393295763008 X-GMAIL-MSGID: 1776105393295763008 This patch keep vlmax vector pattern in simple before split1 pass which will allow more optimization (e.g. combine) before split1 pass. This patch changes the vlmax pattern in autovec.md to define_insn_and_split as much as possible and clean up some combine patterns that are no longer needed. This patch also fixed PR111232 bug which was caused by a combined failed. PR target/111232 gcc/ChangeLog: * config/riscv/autovec-opt.md (@pred_single_widen_mul): Delete. (*pred_widen_mulsu): Delete. (*pred_single_widen_mul): Delete. (*dual_widen_): Add new combine patterns. (*single_widen_sub): Ditto. (*single_widen_add): Ditto. (*single_widen_mult): Ditto. (*dual_widen_mulsu): Ditto. (*dual_widen_mulus): Ditto. (*dual_widen_): Ditto. (*single_widen_add): Ditto. (*single_widen_sub): Ditto. (*single_widen_mult): Ditto. * config/riscv/autovec.md (3): Change define_expand to define_insn_and_split. (2): Ditto. (abs2): Ditto. (smul3_highpart): Ditto. (umul3_highpart): Ditto. gcc/testsuite/ChangeLog: * gcc.target/riscv/rvv/autovec/widen/widen-4.c: Add more testcases. * gcc.target/riscv/rvv/autovec/widen/widen-complicate-4.c: Ditto. * gcc.target/riscv/rvv/autovec/pr111232.c: New test. --- gcc/config/riscv/autovec-opt.md | 294 ++++++++++++------ gcc/config/riscv/autovec.md | 82 +++-- .../gcc.target/riscv/rvv/autovec/pr111232.c | 18 ++ .../riscv/rvv/autovec/widen/widen-4.c | 7 +- .../rvv/autovec/widen/widen-complicate-4.c | 11 +- 5 files changed, 276 insertions(+), 136 deletions(-) create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/autovec/pr111232.c diff --git a/gcc/config/riscv/autovec-opt.md b/gcc/config/riscv/autovec-opt.md index d9863c76654..3aaee54f02a 100644 --- a/gcc/config/riscv/autovec-opt.md +++ b/gcc/config/riscv/autovec-opt.md @@ -18,67 +18,6 @@ ;; along with GCC; see the file COPYING3. If not see ;; . -;; We don't have vwmul.wv instruction like vwadd.wv in RVV. -;; This pattern is an intermediate RTL IR as a pseudo vwmul.wv to enhance -;; optimization of instructions combine. -(define_insn_and_split "@pred_single_widen_mul" - [(set (match_operand:VWEXTI 0 "register_operand" "=&vr,&vr") - (if_then_else:VWEXTI - (unspec: - [(match_operand: 1 "vector_mask_operand" "vmWc1,vmWc1") - (match_operand 5 "vector_length_operand" " rK, rK") - (match_operand 6 "const_int_operand" " i, i") - (match_operand 7 "const_int_operand" " i, i") - (match_operand 8 "const_int_operand" " i, i") - (reg:SI VL_REGNUM) - (reg:SI VTYPE_REGNUM)] UNSPEC_VPREDICATE) - (mult:VWEXTI - (any_extend:VWEXTI - (match_operand: 4 "register_operand" " vr, vr")) - (match_operand:VWEXTI 3 "register_operand" " vr, vr")) - (match_operand:VWEXTI 2 "vector_merge_operand" " vu, 0")))] - "TARGET_VECTOR && can_create_pseudo_p ()" - "#" - "&& 1" - [(const_int 0)] - { - insn_code icode = code_for_pred_vf2 (, mode); - rtx tmp = gen_reg_rtx (mode); - rtx ops[] = {tmp, operands[4]}; - riscv_vector::emit_vlmax_insn (icode, riscv_vector::UNARY_OP, ops); - - emit_insn (gen_pred (MULT, mode, operands[0], operands[1], operands[2], - operands[3], tmp, operands[5], operands[6], - operands[7], operands[8])); - DONE; - } - [(set_attr "type" "viwmul") - (set_attr "mode" "")]) - -;; This pattern it to enchance the instruction combine optimizations for complicate -;; sign and unsigned widening multiplication operations. -(define_insn "*pred_widen_mulsu" - [(set (match_operand:VWEXTI 0 "register_operand" "=&vr,&vr") - (if_then_else:VWEXTI - (unspec: - [(match_operand: 1 "vector_mask_operand" "vmWc1,vmWc1") - (match_operand 5 "vector_length_operand" " rK, rK") - (match_operand 6 "const_int_operand" " i, i") - (match_operand 7 "const_int_operand" " i, i") - (match_operand 8 "const_int_operand" " i, i") - (reg:SI VL_REGNUM) - (reg:SI VTYPE_REGNUM)] UNSPEC_VPREDICATE) - (mult:VWEXTI - (zero_extend:VWEXTI - (match_operand: 4 "register_operand" " vr, vr")) - (sign_extend:VWEXTI - (match_operand: 3 "register_operand" " vr, vr"))) - (match_operand:VWEXTI 2 "vector_merge_operand" " vu, 0")))] - "TARGET_VECTOR" - "vwmulsu.vv\t%0,%3,%4%p1" - [(set_attr "type" "viwmul") - (set_attr "mode" "")]) - ;; ----------------------------------------------------------------------------- ;; ---- Integer Compare Instructions Simplification ;; ----------------------------------------------------------------------------- @@ -406,45 +345,6 @@ [(set_attr "type" "vimovvx") (set_attr "mode" "")]) -;; We don't have vfwmul.wv instruction like vfwadd.wv in RVV. -;; This pattern is an intermediate RTL IR as a pseudo vfwmul.wv to enhance -;; optimization of instructions combine. -(define_insn_and_split "*pred_single_widen_mul" - [(set (match_operand:VWEXTF 0 "register_operand" "=&vr, &vr") - (if_then_else:VWEXTF - (unspec: - [(match_operand: 1 "vector_mask_operand" "vmWc1,vmWc1") - (match_operand 5 "vector_length_operand" " rK, rK") - (match_operand 6 "const_int_operand" " i, i") - (match_operand 7 "const_int_operand" " i, i") - (match_operand 8 "const_int_operand" " i, i") - (match_operand 9 "const_int_operand" " i, i") - (reg:SI VL_REGNUM) - (reg:SI VTYPE_REGNUM) - (reg:SI FRM_REGNUM)] UNSPEC_VPREDICATE) - (mult:VWEXTF - (float_extend:VWEXTF - (match_operand: 4 "register_operand" " vr, vr")) - (match_operand:VWEXTF 3 "register_operand" " vr, vr")) - (match_operand:VWEXTF 2 "vector_merge_operand" " vu, 0")))] - "TARGET_VECTOR && can_create_pseudo_p ()" - "#" - "&& 1" - [(const_int 0)] - { - insn_code icode = code_for_pred_extend (mode); - rtx tmp = gen_reg_rtx (mode); - rtx ops[] = {tmp, operands[4]}; - riscv_vector::emit_vlmax_insn (icode, riscv_vector::UNARY_OP, ops); - - emit_insn (gen_pred (MULT, mode, operands[0], operands[1], operands[2], - operands[3], tmp, operands[5], operands[6], - operands[7], operands[8], operands[9])); - DONE; - } - [(set_attr "type" "vfwmul") - (set_attr "mode" "")]) - ;; ------------------------------------------------------------------------- ;; ---- [FP] VFWMACC ;; ------------------------------------------------------------------------- @@ -845,7 +745,7 @@ DONE; }) -;; Combine FP sign_extend/zero_extend(vf2) and vcond_mask +;; Combine FP extend(vf2) and vcond_mask (define_insn_and_split "*cond_extend" [(set (match_operand:VWEXTF_ZVFHMIN 0 "register_operand") (if_then_else:VWEXTF_ZVFHMIN @@ -1003,3 +903,195 @@ riscv_vector::expand_cond_len_unop (icode, ops); DONE; }) + +;; ============================================================================= +;; Combine extend + binop to widen_binop +;; ============================================================================= + +(define_insn_and_split "*dual_widen_" + [(set (match_operand:VWEXTI 0 "register_operand") + (any_widen_binop:VWEXTI + (any_extend:VWEXTI + (match_operand: 1 "register_operand")) + (any_extend:VWEXTI + (match_operand: 2 "register_operand"))))] + "TARGET_VECTOR && can_create_pseudo_p ()" + "#" + "&& 1" + [(const_int 0)] +{ + insn_code icode = code_for_pred_dual_widen (, + , + mode); + riscv_vector::emit_vlmax_insn (icode, riscv_vector::BINARY_OP, operands); + DONE; +}) + +(define_insn_and_split "*single_widen_sub" + [(set (match_operand:VWEXTI 0 "register_operand") + (minus:VWEXTI + (match_operand:VWEXTI 1 "register_operand") + (any_extend:VWEXTI + (match_operand: 2 "register_operand"))))] + "TARGET_VECTOR && can_create_pseudo_p ()" + "#" + "&& 1" + [(const_int 0)] +{ + insn_code icode = code_for_pred_single_widen_sub (, + mode); + riscv_vector::emit_vlmax_insn (icode, riscv_vector::BINARY_OP, operands); + DONE; +}) + +(define_insn_and_split "*single_widen_add" + [(set (match_operand:VWEXTI 0 "register_operand") + (plus:VWEXTI + (any_extend:VWEXTI + (match_operand: 2 "register_operand")) + (match_operand:VWEXTI 1 "register_operand")))] + "TARGET_VECTOR && can_create_pseudo_p ()" + "#" + "&& 1" + [(const_int 0)] +{ + insn_code icode = code_for_pred_single_widen_add (, + mode); + riscv_vector::emit_vlmax_insn (icode, riscv_vector::BINARY_OP, operands); + DONE; +}) + +;; This combine pattern does not correspond to an single instruction, +;; i.e. there is no vwmul.wv instruction. This is a temporary pattern +;; produced by a combine pass and if there is no further combine into +;; vwmul.vv pattern, then fall back to extend pattern and vmul.vv pattern. +(define_insn_and_split "*single_widen_mult" + [(set (match_operand:VWEXTI 0 "register_operand") + (mult:VWEXTI + (any_extend:VWEXTI + (match_operand: 2 "register_operand")) + (match_operand:VWEXTI 1 "register_operand")))] + "TARGET_VECTOR && can_create_pseudo_p ()" + "#" + "&& 1" + [(const_int 0)] +{ + insn_code extend_icode = code_for_pred_vf2 (, mode); + rtx tmp = gen_reg_rtx (mode); + rtx extend_ops[] = {tmp, operands[2]}; + riscv_vector::emit_vlmax_insn (extend_icode, riscv_vector::UNARY_OP, extend_ops); + + rtx ops[] = {operands[0], operands[1], tmp}; + insn_code icode = code_for_pred (MULT, mode); + riscv_vector::emit_vlmax_insn (icode, riscv_vector::BINARY_OP, ops); + DONE; +}) + +(define_insn_and_split "*dual_widen_mulsu" + [(set (match_operand:VWEXTI 0 "register_operand") + (mult:VWEXTI + (sign_extend:VWEXTI + (match_operand: 1 "register_operand")) + (zero_extend:VWEXTI + (match_operand: 2 "register_operand"))))] + "TARGET_VECTOR && can_create_pseudo_p ()" + "#" + "&& 1" + [(const_int 0)] +{ + insn_code icode = code_for_pred_widen_mulsu (mode); + riscv_vector::emit_vlmax_insn (icode, riscv_vector::BINARY_OP, operands); + DONE; +}) + +(define_insn_and_split "*dual_widen_mulus" + [(set (match_operand:VWEXTI 0 "register_operand") + (mult:VWEXTI + (zero_extend:VWEXTI + (match_operand: 2 "register_operand")) + (sign_extend:VWEXTI + (match_operand: 1 "register_operand"))))] + "TARGET_VECTOR && can_create_pseudo_p ()" + "#" + "&& 1" + [(const_int 0)] +{ + insn_code icode = code_for_pred_widen_mulsu (mode); + riscv_vector::emit_vlmax_insn (icode, riscv_vector::BINARY_OP, operands); + DONE; +}) + +(define_insn_and_split "*dual_widen_" + [(set (match_operand:VWEXTF 0 "register_operand") + (any_widen_binop:VWEXTF + (float_extend:VWEXTF + (match_operand: 1 "register_operand")) + (float_extend:VWEXTF + (match_operand: 2 "register_operand"))))] + "TARGET_VECTOR && can_create_pseudo_p ()" + "#" + "&& 1" + [(const_int 0)] +{ + insn_code icode = code_for_pred_dual_widen (, mode); + riscv_vector::emit_vlmax_insn (icode, riscv_vector::BINARY_OP_FRM_DYN, operands); + DONE; +}) + +(define_insn_and_split "*single_widen_add" + [(set (match_operand:VWEXTF 0 "register_operand") + (plus:VWEXTF + (float_extend:VWEXTF + (match_operand: 2 "register_operand")) + (match_operand:VWEXTF 1 "register_operand")))] + "TARGET_VECTOR && can_create_pseudo_p ()" + "#" + "&& 1" + [(const_int 0)] +{ + insn_code icode = code_for_pred_single_widen_add (mode); + riscv_vector::emit_vlmax_insn (icode, riscv_vector::BINARY_OP_FRM_DYN, operands); + DONE; +}) + +(define_insn_and_split "*single_widen_sub" + [(set (match_operand:VWEXTF 0 "register_operand") + (minus:VWEXTF + (match_operand:VWEXTF 1 "register_operand") + (float_extend:VWEXTF + (match_operand: 2 "register_operand"))))] + "TARGET_VECTOR && can_create_pseudo_p ()" + "#" + "&& 1" + [(const_int 0)] +{ + insn_code icode = code_for_pred_single_widen_sub (mode); + riscv_vector::emit_vlmax_insn (icode, riscv_vector::BINARY_OP_FRM_DYN, operands); + DONE; +}) + +;; This combine pattern does not correspond to an single instruction, +;; i.e. there is no vfwmul.wv instruction. This is a temporary pattern +;; produced by a combine pass and if there is no further combine into +;; vfwmul.vv pattern, then fall back to extend pattern and vfmul.vv pattern. +(define_insn_and_split "*single_widen_mult" + [(set (match_operand:VWEXTF 0 "register_operand") + (mult:VWEXTF + (float_extend:VWEXTF + (match_operand: 2 "register_operand")) + (match_operand:VWEXTF 1 "register_operand")))] + "TARGET_VECTOR && can_create_pseudo_p ()" + "#" + "&& 1" + [(const_int 0)] +{ + insn_code extend_icode = code_for_pred_extend (mode); + rtx tmp = gen_reg_rtx (mode); + rtx extend_ops[] = {tmp, operands[2]}; + riscv_vector::emit_vlmax_insn (extend_icode, riscv_vector::UNARY_OP, extend_ops); + + rtx ops[] = {operands[0], operands[1], tmp}; + riscv_vector::emit_vlmax_insn (code_for_pred (MULT, mode), + riscv_vector::BINARY_OP_FRM_DYN, ops); + DONE; +}) diff --git a/gcc/config/riscv/autovec.md b/gcc/config/riscv/autovec.md index c220fda312e..98cd0c07625 100644 --- a/gcc/config/riscv/autovec.md +++ b/gcc/config/riscv/autovec.md @@ -419,12 +419,15 @@ ;; - vadd.vi/vsub.vi/... ;; ------------------------------------------------------------------------- -(define_expand "3" +(define_insn_and_split "3" [(set (match_operand:VI 0 "register_operand") (any_int_binop_no_shift:VI (match_operand:VI 1 "") (match_operand:VI 2 "")))] - "TARGET_VECTOR" + "TARGET_VECTOR && can_create_pseudo_p ()" + "#" + "&& 1" + [(const_int 0)] { riscv_vector::emit_vlmax_insn (code_for_pred (, mode), riscv_vector::BINARY_OP, operands); @@ -937,11 +940,14 @@ ;; Includes: ;; - vneg.v/vnot.v ;; ------------------------------------------------------------------------------- -(define_expand "2" +(define_insn_and_split "2" [(set (match_operand:VI 0 "register_operand") (any_int_unop:VI (match_operand:VI 1 "register_operand")))] - "TARGET_VECTOR" + "TARGET_VECTOR && can_create_pseudo_p ()" + "#" + "&& 1" + [(const_int 0)] { insn_code icode = code_for_pred (, mode); riscv_vector::emit_vlmax_insn (icode, riscv_vector::UNARY_OP, operands); @@ -952,10 +958,14 @@ ;; - [INT] ABS expansion to vmslt and vneg. ;; ------------------------------------------------------------------------------- -(define_expand "abs2" +(define_insn_and_split "abs2" [(set (match_operand:VI 0 "register_operand") - (match_operand:VI 1 "register_operand"))] - "TARGET_VECTOR" + (abs:VI + (match_operand:VI 1 "register_operand")))] + "TARGET_VECTOR && can_create_pseudo_p ()" + "#" + "&& 1" + [(const_int 0)] { rtx zero = gen_const_vec_duplicate (mode, GEN_INT (0)); machine_mode mask_mode = riscv_vector::get_mask_mode (mode); @@ -1457,12 +1467,15 @@ ;; - vfadd.vv/vfsub.vv/... ;; - vfadd.vf/vfsub.vf/... ;; ------------------------------------------------------------------------- -(define_expand "3" - [(match_operand:VF 0 "register_operand") - (any_float_binop:VF - (match_operand:VF 1 "register_operand") - (match_operand:VF 2 "register_operand"))] - "TARGET_VECTOR" +(define_insn_and_split "3" + [(set (match_operand:VF 0 "register_operand") + (any_float_binop:VF + (match_operand:VF 1 "register_operand") + (match_operand:VF 2 "register_operand")))] + "TARGET_VECTOR && can_create_pseudo_p ()" + "#" + "&& 1" + [(const_int 0)] { riscv_vector::emit_vlmax_insn (code_for_pred (, mode), riscv_vector::BINARY_OP_FRM_DYN, operands); @@ -1474,12 +1487,15 @@ ;; - vfmin.vv/vfmax.vv ;; - vfmin.vf/vfmax.vf ;; ------------------------------------------------------------------------- -(define_expand "3" - [(match_operand:VF 0 "register_operand") - (any_float_binop_nofrm:VF - (match_operand:VF 1 "register_operand") - (match_operand:VF 2 "register_operand"))] - "TARGET_VECTOR" +(define_insn_and_split "3" + [(set (match_operand:VF 0 "register_operand") + (any_float_binop_nofrm:VF + (match_operand:VF 1 "register_operand") + (match_operand:VF 2 "register_operand")))] + "TARGET_VECTOR && can_create_pseudo_p ()" + "#" + "&& 1" + [(const_int 0)] { riscv_vector::emit_vlmax_insn (code_for_pred (, mode), riscv_vector::BINARY_OP, operands); @@ -1537,22 +1553,30 @@ ;; - vmulhu.vv ;; ------------------------------------------------------------------------- -(define_expand "smul3_highpart" - [(match_operand:VFULLI 0 "register_operand") - (match_operand:VFULLI 1 "register_operand") - (match_operand:VFULLI 2 "register_operand")] - "TARGET_VECTOR" +(define_insn_and_split "smul3_highpart" + [(set (match_operand:VFULLI 0 "register_operand") + (smul_highpart:VFULLI + (match_operand:VFULLI 1 "register_operand") + (match_operand:VFULLI 2 "register_operand")))] + "TARGET_VECTOR && can_create_pseudo_p ()" + "#" + "&& 1" + [(const_int 0)] { insn_code icode = code_for_pred_mulh (UNSPEC_VMULHS, mode); riscv_vector::emit_vlmax_insn (icode, riscv_vector::BINARY_OP, operands); DONE; }) -(define_expand "umul3_highpart" - [(match_operand:VFULLI 0 "register_operand") - (match_operand:VFULLI 1 "register_operand") - (match_operand:VFULLI 2 "register_operand")] - "TARGET_VECTOR" +(define_insn_and_split "umul3_highpart" + [(set (match_operand:VFULLI 0 "register_operand") + (umul_highpart:VFULLI + (match_operand:VFULLI 1 "register_operand") + (match_operand:VFULLI 2 "register_operand")))] + "TARGET_VECTOR && can_create_pseudo_p ()" + "#" + "&& 1" + [(const_int 0)] { insn_code icode = code_for_pred_mulh (UNSPEC_VMULHU, mode); riscv_vector::emit_vlmax_insn (icode, riscv_vector::BINARY_OP, operands); diff --git a/gcc/testsuite/gcc.target/riscv/rvv/autovec/pr111232.c b/gcc/testsuite/gcc.target/riscv/rvv/autovec/pr111232.c new file mode 100644 index 00000000000..de815c5fac9 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/pr111232.c @@ -0,0 +1,18 @@ +/* { dg-do compile } */ +/* { dg-options "-march=rv64gcv -mabi=lp64d --param=riscv-autovec-preference=scalable -Ofast -fno-schedule-insns -fno-schedule-insns2" } */ + +#include + +int16_t +foo (int8_t *restrict x, int8_t *restrict y, int n) +{ + int16_t result = 0; + + for (int i = 0; i < n; i++) + { + result += (x[i] * y[i]); + } + return result; +} + +/* { dg-final { scan-assembler {\tvwmacc\.vv\tv[0-9]+,v[0-9]+,v[0-9]+} } } */ diff --git a/gcc/testsuite/gcc.target/riscv/rvv/autovec/widen/widen-4.c b/gcc/testsuite/gcc.target/riscv/rvv/autovec/widen/widen-4.c index c29a74c4f8b..26f27ea6283 100644 --- a/gcc/testsuite/gcc.target/riscv/rvv/autovec/widen/widen-4.c +++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/widen/widen-4.c @@ -16,8 +16,11 @@ #define TEST_ALL() \ TEST_TYPE (int16_t, int8_t, uint8_t) \ TEST_TYPE (int32_t, int16_t, uint16_t) \ - TEST_TYPE (int64_t, int32_t, uint32_t) + TEST_TYPE (int64_t, int32_t, uint32_t) \ + TEST_TYPE (int16_t, uint8_t, int8_t) \ + TEST_TYPE (int32_t, uint16_t, int16_t) \ + TEST_TYPE (int64_t, uint32_t, int32_t) TEST_ALL () -/* { dg-final { scan-assembler-times {\tvwmulsu\.vv} 3 } } */ +/* { dg-final { scan-assembler-times {\tvwmulsu\.vv} 6 } } */ diff --git a/gcc/testsuite/gcc.target/riscv/rvv/autovec/widen/widen-complicate-4.c b/gcc/testsuite/gcc.target/riscv/rvv/autovec/widen/widen-complicate-4.c index 15fdefc550b..aeac4cb79c2 100644 --- a/gcc/testsuite/gcc.target/riscv/rvv/autovec/widen/widen-complicate-4.c +++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/widen/widen-complicate-4.c @@ -21,11 +21,14 @@ #define TEST_ALL() \ TEST_TYPE (int16_t, int8_t, uint8_t) \ TEST_TYPE (int32_t, int16_t, uint16_t) \ - TEST_TYPE (int64_t, int32_t, uint32_t) + TEST_TYPE (int64_t, int32_t, uint32_t) \ + TEST_TYPE (int16_t, uint8_t, int8_t) \ + TEST_TYPE (int32_t, uint16_t, int16_t) \ + TEST_TYPE (int64_t, uint32_t, int32_t) TEST_ALL () -/* { dg-final { scan-assembler-times {\tvwmulsu\.vv} 6 } } */ -/* { dg-final { scan-assembler-times {\tvwmul\.vv} 3 } } */ -/* { dg-final { scan-assembler-times {\tvwmulu\.vv} 3 } } */ +/* { dg-final { scan-assembler-times {\tvwmulsu\.vv} 12 } } */ +/* { dg-final { scan-assembler-times {\tvwmul\.vv} 6 } } */ +/* { dg-final { scan-assembler-times {\tvwmulu\.vv} 6 } } */ /* { dg-final { scan-assembler-not {\tvmul} } } */