From patchwork Tue Sep 5 10:32:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Li, Pan2 via Gcc-patches" X-Patchwork-Id: 137495 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ab0a:0:b0:3f2:4152:657d with SMTP id m10csp1589575vqo; Tue, 5 Sep 2023 03:32:59 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEdgPgi+4YC3lWXXYai2gODfCLR9ynbr2K5dK/jr8A1KytHVmKwc66GMDWCfJoA/2MWzvWQ X-Received: by 2002:a05:6512:68d:b0:500:a6c1:36f7 with SMTP id t13-20020a056512068d00b00500a6c136f7mr10062604lfe.3.1693909978939; Tue, 05 Sep 2023 03:32:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693909978; cv=none; d=google.com; s=arc-20160816; b=t9PJRNVmunXSM/vjL+1MbaU48Mk1+jsQhgIUqcRyADYVuKWss6az8WNJhdRnHPvHDd k0V0cDeskl/43QTGVUb8rpxzSVaJmHdPLVSuZ7X1JcyJoUCM4yPVLjtsGNSD03cfFOwa 9c7TP6ssKgC2CvzqxqbI4ltAWUx1pqL5f8yHiDPLl0ktz3TWdJaeB5SfVpzkPXgAJpE7 tb6CAXtqJH0ySTb1rvwMj3/9X6QFeUZ4KlBxwNUHTRDTe07Wr7EAdwcSEBpTK+C/WzZw +Qshva1FaBm8Inc08BpNQjhv4lY8EQo2FdkgueS3POkxjpOCXJffCT23od5Z2X/LGUFR 6fmA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:reply-to:from:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:to :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=SccNUKlcvyvzmjOkl9geOADP8rQHSIOhjAEtbOAI5EQ=; fh=SYenphyxW+C6B2iXrM3VHq8IUoJmB8HrI5Y/2XKXn00=; b=teJFtjdhSFTrin+MvK28pZ7RW5/Dj8iSfNurHb83mVQLGXPE20DOxZPOymGUjWTmlb IyYYU82+PrX17rS0FmQjZrcok04zeb7hMR5PezpRzy502oPDfpv0S+SeVlhjGRiE/zzJ spR5O8oujOW7Krvpt2iZvVLevmzOvcBN8DyR6ofMeVNzAuB6bhMvXkKEzQHk4GmizWge 6BqECMUlcG1syrZIHe12qXJbqYNcIb0Hr2aJY6O555DWSQOkepoivIwjDRXkJ2cItZcH eWZUn0MALzkZY3YsRNxb7PYd/4Wihh9Wo7aKIsNA1dmpudHUODJuvOUHyanRjH3WYZuQ phDA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=CVSD6e+c; 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 w8-20020aa7da48000000b0052322c44db3si7565459eds.678.2023.09.05.03.32.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Sep 2023 03:32:58 -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=CVSD6e+c; 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 A573D385842C for ; Tue, 5 Sep 2023 10:32:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A573D385842C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1693909977; bh=SccNUKlcvyvzmjOkl9geOADP8rQHSIOhjAEtbOAI5EQ=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=CVSD6e+cKERhjpmtUnSpgvQVfnNBJN/jbZDPUopWPhj7svJvOBWJ83OTzZ2/TLQyl 2arxP039MiwqfBMEUFtsM/Raa8dMFev+cAizBxTCP1ZIKJnUywr//dN32tjIH+KbuK 06bg5E4o1XKKcDuYBwA6zaUc4e7DoYzu3mDy/ubk= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.120]) by sourceware.org (Postfix) with ESMTPS id 459FE3858D32 for ; Tue, 5 Sep 2023 10:32:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 459FE3858D32 X-IronPort-AV: E=McAfee;i="6600,9927,10823"; a="375653436" X-IronPort-AV: E=Sophos;i="6.02,229,1688454000"; d="scan'208";a="375653436" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Sep 2023 03:32:08 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10823"; a="855932706" X-IronPort-AV: E=Sophos;i="6.02,229,1688454000"; d="scan'208";a="855932706" Received: from shvmail02.sh.intel.com ([10.239.244.9]) by fmsmga002.fm.intel.com with ESMTP; 05 Sep 2023 03:32:06 -0700 Received: from pli-ubuntu.sh.intel.com (pli-ubuntu.sh.intel.com [10.239.159.47]) by shvmail02.sh.intel.com (Postfix) with ESMTP id C7780100519E; Tue, 5 Sep 2023 18:32:05 +0800 (CST) To: gcc-patches@gcc.gnu.org Subject: [PATCH v1] RISC-V: Support FP SGNJ autovec for VLS mode Date: Tue, 5 Sep 2023 18:32:04 +0800 Message-Id: <20230905103204.2267415-1-pan2.li@intel.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-10.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_ASCII_DIVIDERS, KAM_SHORT, SPF_HELO_NONE, SPF_NONE, 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Pan Li via Gcc-patches From: "Li, Pan2 via Gcc-patches" Reply-To: pan2.li@intel.com Cc: yanzhang.wang@intel.com, 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: 1776193350237206903 X-GMAIL-MSGID: 1776193350237206903 From: Pan Li This patch would like to allow the VLS mode autovec for the floating-point binary operation MAX/MIN. Given below code example: void test(float * restrict out, float * restrict in1, float * restrict in2) { for (int i = 0; i < 128; i++) out[i] = __builtin_copysignf (in1[i], in2[i]); } Before this patch: test: csrr a4,vlenb slli a4,a4,1 li a5,128 bleu a5,a4,.L2 mv a5,a4 .L2: vsetvli zero,a5,e32,m8,ta,ma vle32.v v8,0(a1) vle32.v v16,0(a2) vsetvli a4,zero,e32,m8,ta,ma vfsgnj.vv v8,v8,v16 vsetvli zero,a5,e32,m8,ta,ma vse32.v v8,0(a0) ret After this patch: test: li a5,128 vsetvli zero,a5,e32,m1,ta,ma vle32.v v1,0(a1) vle32.v v2,0(a2) vfsgnj.vv v1,v1,v2 vse32.v v1,0(a0) ret Signed-off-by: Pan Li gcc/ChangeLog: * config/riscv/autovec-vls.md (copysign3): New pattern. * config/riscv/vector.md: Extend iterator for VLS. gcc/testsuite/ChangeLog: * gcc.target/riscv/rvv/autovec/vls/def.h: New macro. * gcc.target/riscv/rvv/autovec/vls/floating-point-sgnj-1.c: New test. * gcc.target/riscv/rvv/autovec/vls/floating-point-sgnj-2.c: New test. Signed-off-by: Pan Li --- gcc/config/riscv/autovec-vls.md | 22 ++++++++++ gcc/config/riscv/vector.md | 24 +++++------ .../gcc.target/riscv/rvv/autovec/vls/def.h | 8 ++++ .../rvv/autovec/vls/floating-point-sgnj-1.c | 43 +++++++++++++++++++ .../rvv/autovec/vls/floating-point-sgnj-2.c | 43 +++++++++++++++++++ 5 files changed, 128 insertions(+), 12 deletions(-) create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/autovec/vls/floating-point-sgnj-1.c create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/autovec/vls/floating-point-sgnj-2.c diff --git a/gcc/config/riscv/autovec-vls.md b/gcc/config/riscv/autovec-vls.md index 7ef29637e33..31b6c4ae714 100644 --- a/gcc/config/riscv/autovec-vls.md +++ b/gcc/config/riscv/autovec-vls.md @@ -255,6 +255,28 @@ (define_insn_and_split "3" [(set_attr "type" "vector")] ) +;; ------------------------------------------------------------------------- +;; Includes: +;; - vfsgnj.vv +;; - vfsgnj.vf +;; ------------------------------------------------------------------------- +(define_insn_and_split "copysign3" + [(set (match_operand:VLSF 0 "register_operand") + (unspec:VLSF + [(match_operand:VLSF 1 "register_operand") + (match_operand:VLSF 2 "register_operand")] UNSPEC_VCOPYSIGN))] + "TARGET_VECTOR && can_create_pseudo_p ()" + "#" + "&& 1" + [(const_int 0)] + { + riscv_vector::emit_vlmax_insn (code_for_pred (UNSPEC_VCOPYSIGN, mode), + riscv_vector::BINARY_OP, operands); + DONE; + } + [(set_attr "type" "vector")] +) + ;; ------------------------------------------------------------------------------- ;; ---- [INT] Unary operations ;; ------------------------------------------------------------------------------- diff --git a/gcc/config/riscv/vector.md b/gcc/config/riscv/vector.md index 9d7b4bbe1d4..fc985ff6a01 100644 --- a/gcc/config/riscv/vector.md +++ b/gcc/config/riscv/vector.md @@ -6166,8 +6166,8 @@ (define_insn "@pred__reverse_scalar" (symbol_ref "riscv_vector::get_frm_mode (operands[9])"))]) (define_insn "@pred_" - [(set (match_operand:VF 0 "register_operand" "=vd, vd, vr, vr") - (if_then_else:VF + [(set (match_operand:V_VLSF 0 "register_operand" "=vd, vd, vr, vr") + (if_then_else:V_VLSF (unspec: [(match_operand: 1 "vector_mask_operand" " vm, vm,Wc1,Wc1") (match_operand 5 "vector_length_operand" " rK, rK, rK, rK") @@ -6176,10 +6176,10 @@ (define_insn "@pred_" (match_operand 8 "const_int_operand" " i, i, i, i") (reg:SI VL_REGNUM) (reg:SI VTYPE_REGNUM)] UNSPEC_VPREDICATE) - (unspec:VF - [(match_operand:VF 3 "register_operand" " vr, vr, vr, vr") - (match_operand:VF 4 "register_operand" " vr, vr, vr, vr")] VCOPYSIGNS) - (match_operand:VF 2 "vector_merge_operand" " vu, 0, vu, 0")))] + (unspec:V_VLSF + [(match_operand:V_VLSF 3 "register_operand" " vr, vr, vr, vr") + (match_operand:V_VLSF 4 "register_operand" " vr, vr, vr, vr")] VCOPYSIGNS) + (match_operand:V_VLSF 2 "vector_merge_operand" " vu, 0, vu, 0")))] "TARGET_VECTOR" "vfsgnj.vv\t%0,%3,%4%p1" [(set_attr "type" "vfsgnj") @@ -6207,8 +6207,8 @@ (define_insn "@pred_ncopysign" (set_attr "mode" "")]) (define_insn "@pred__scalar" - [(set (match_operand:VF 0 "register_operand" "=vd, vd, vr, vr") - (if_then_else:VF + [(set (match_operand:V_VLSF 0 "register_operand" "=vd, vd, vr, vr") + (if_then_else:V_VLSF (unspec: [(match_operand: 1 "vector_mask_operand" " vm, vm,Wc1,Wc1") (match_operand 5 "vector_length_operand" " rK, rK, rK, rK") @@ -6217,11 +6217,11 @@ (define_insn "@pred__scalar" (match_operand 8 "const_int_operand" " i, i, i, i") (reg:SI VL_REGNUM) (reg:SI VTYPE_REGNUM)] UNSPEC_VPREDICATE) - (unspec:VF - [(match_operand:VF 3 "register_operand" " vr, vr, vr, vr") - (vec_duplicate:VF + (unspec:V_VLSF + [(match_operand:V_VLSF 3 "register_operand" " vr, vr, vr, vr") + (vec_duplicate:V_VLSF (match_operand: 4 "register_operand" " f, f, f, f"))] VCOPYSIGNS) - (match_operand:VF 2 "vector_merge_operand" " vu, 0, vu, 0")))] + (match_operand:V_VLSF 2 "vector_merge_operand" " vu, 0, vu, 0")))] "TARGET_VECTOR" "vfsgnj.vf\t%0,%3,%4%p1" [(set_attr "type" "vfsgnj") diff --git a/gcc/testsuite/gcc.target/riscv/rvv/autovec/vls/def.h b/gcc/testsuite/gcc.target/riscv/rvv/autovec/vls/def.h index 2e07e908736..c7df879dbde 100644 --- a/gcc/testsuite/gcc.target/riscv/rvv/autovec/vls/def.h +++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/vls/def.h @@ -175,6 +175,14 @@ typedef double v512df __attribute__ ((vector_size (4096))); a[i] = CALL (b[i], c[i]); \ } +#define DEF_CALL_VX(PREFIX, NUM, TYPE, CALL) \ + void __attribute__ ((noinline, noclone)) \ + PREFIX##_##TYPE##NUM (TYPE *restrict a, TYPE *restrict b, TYPE c) \ + { \ + for (int i = 0; i < NUM; ++i) \ + a[i] = CALL (b[i], c); \ + } + #define DEF_CONST(TYPE, VAL, NUM) \ void const_##TYPE##_##NUM (TYPE *restrict a) \ { \ diff --git a/gcc/testsuite/gcc.target/riscv/rvv/autovec/vls/floating-point-sgnj-1.c b/gcc/testsuite/gcc.target/riscv/rvv/autovec/vls/floating-point-sgnj-1.c new file mode 100644 index 00000000000..0cc18d91215 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/vls/floating-point-sgnj-1.c @@ -0,0 +1,43 @@ +/* { dg-do compile } */ +/* { dg-options "-march=rv64gcv_zvfh_zvl4096b -mabi=lp64d -O3 -fno-schedule-insns -fno-schedule-insns2 --param=riscv-autovec-lmul=m8 -ffast-math" } */ + +#include "def.h" + +DEF_CALL_VV (sgnj, 1, _Float16, __builtin_copysignf16) +DEF_CALL_VV (sgnj, 2, _Float16, __builtin_copysignf16) +DEF_CALL_VV (sgnj, 4, _Float16, __builtin_copysignf16) +DEF_CALL_VV (sgnj, 8, _Float16, __builtin_copysignf16) +DEF_CALL_VV (sgnj, 16, _Float16, __builtin_copysignf16) +DEF_CALL_VV (sgnj, 32, _Float16, __builtin_copysignf16) +DEF_CALL_VV (sgnj, 64, _Float16, __builtin_copysignf16) +DEF_CALL_VV (sgnj, 128, _Float16, __builtin_copysignf16) +DEF_CALL_VV (sgnj, 256, _Float16, __builtin_copysignf16) +DEF_CALL_VV (sgnj, 512, _Float16, __builtin_copysignf16) +DEF_CALL_VV (sgnj, 1024, _Float16, __builtin_copysignf16) +DEF_CALL_VV (sgnj, 2048, _Float16, __builtin_copysignf16) + +DEF_CALL_VV (sgnj, 1, float, __builtin_copysignf) +DEF_CALL_VV (sgnj, 2, float, __builtin_copysignf) +DEF_CALL_VV (sgnj, 4, float, __builtin_copysignf) +DEF_CALL_VV (sgnj, 8, float, __builtin_copysignf) +DEF_CALL_VV (sgnj, 16, float, __builtin_copysignf) +DEF_CALL_VV (sgnj, 32, float, __builtin_copysignf) +DEF_CALL_VV (sgnj, 64, float, __builtin_copysignf) +DEF_CALL_VV (sgnj, 128, float, __builtin_copysignf) +DEF_CALL_VV (sgnj, 256, float, __builtin_copysignf) +DEF_CALL_VV (sgnj, 512, float, __builtin_copysignf) +DEF_CALL_VV (sgnj, 1024, float, __builtin_copysignf) + +DEF_CALL_VV (sgnj, 1, double, __builtin_copysign) +DEF_CALL_VV (sgnj, 2, double, __builtin_copysign) +DEF_CALL_VV (sgnj, 4, double, __builtin_copysign) +DEF_CALL_VV (sgnj, 8, double, __builtin_copysign) +DEF_CALL_VV (sgnj, 16, double, __builtin_copysign) +DEF_CALL_VV (sgnj, 32, double, __builtin_copysign) +DEF_CALL_VV (sgnj, 64, double, __builtin_copysign) +DEF_CALL_VV (sgnj, 128, double, __builtin_copysign) +DEF_CALL_VV (sgnj, 256, double, __builtin_copysign) +DEF_CALL_VV (sgnj, 512, double, __builtin_copysign) + +/* { dg-final { scan-assembler-times {vfsgnj\.vv\s+v[0-9]+,\s*v[0-9]+,\s*v[0-9]+} 30 } } */ +/* { dg-final { scan-assembler-not {csrr} } } */ diff --git a/gcc/testsuite/gcc.target/riscv/rvv/autovec/vls/floating-point-sgnj-2.c b/gcc/testsuite/gcc.target/riscv/rvv/autovec/vls/floating-point-sgnj-2.c new file mode 100644 index 00000000000..3a66481070a --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/vls/floating-point-sgnj-2.c @@ -0,0 +1,43 @@ +/* { dg-do compile } */ +/* { dg-options "-march=rv64gcv_zvfh_zvl4096b -mabi=lp64d -O3 -fno-schedule-insns -fno-schedule-insns2 --param=riscv-autovec-lmul=m8 -ffast-math" } */ + +#include "def.h" + +DEF_CALL_VX (sgnj, 1, _Float16, __builtin_copysignf16) +DEF_CALL_VX (sgnj, 2, _Float16, __builtin_copysignf16) +DEF_CALL_VX (sgnj, 4, _Float16, __builtin_copysignf16) +DEF_CALL_VX (sgnj, 8, _Float16, __builtin_copysignf16) +DEF_CALL_VX (sgnj, 16, _Float16, __builtin_copysignf16) +DEF_CALL_VX (sgnj, 32, _Float16, __builtin_copysignf16) +DEF_CALL_VX (sgnj, 64, _Float16, __builtin_copysignf16) +DEF_CALL_VX (sgnj, 128, _Float16, __builtin_copysignf16) +DEF_CALL_VX (sgnj, 256, _Float16, __builtin_copysignf16) +DEF_CALL_VX (sgnj, 512, _Float16, __builtin_copysignf16) +DEF_CALL_VX (sgnj, 1024, _Float16, __builtin_copysignf16) +DEF_CALL_VX (sgnj, 2048, _Float16, __builtin_copysignf16) + +DEF_CALL_VX (sgnj, 1, float, __builtin_copysignf) +DEF_CALL_VX (sgnj, 2, float, __builtin_copysignf) +DEF_CALL_VX (sgnj, 4, float, __builtin_copysignf) +DEF_CALL_VX (sgnj, 8, float, __builtin_copysignf) +DEF_CALL_VX (sgnj, 16, float, __builtin_copysignf) +DEF_CALL_VX (sgnj, 32, float, __builtin_copysignf) +DEF_CALL_VX (sgnj, 64, float, __builtin_copysignf) +DEF_CALL_VX (sgnj, 128, float, __builtin_copysignf) +DEF_CALL_VX (sgnj, 256, float, __builtin_copysignf) +DEF_CALL_VX (sgnj, 512, float, __builtin_copysignf) +DEF_CALL_VX (sgnj, 1024, float, __builtin_copysignf) + +DEF_CALL_VX (sgnj, 1, double, __builtin_copysign) +DEF_CALL_VX (sgnj, 2, double, __builtin_copysign) +DEF_CALL_VX (sgnj, 4, double, __builtin_copysign) +DEF_CALL_VX (sgnj, 8, double, __builtin_copysign) +DEF_CALL_VX (sgnj, 16, double, __builtin_copysign) +DEF_CALL_VX (sgnj, 32, double, __builtin_copysign) +DEF_CALL_VX (sgnj, 64, double, __builtin_copysign) +DEF_CALL_VX (sgnj, 128, double, __builtin_copysign) +DEF_CALL_VX (sgnj, 256, double, __builtin_copysign) +DEF_CALL_VX (sgnj, 512, double, __builtin_copysign) + +/* { dg-final { scan-assembler-times {vfsgnj\.vv\s+v[0-9]+,\s*v[0-9]+,\s*v[0-9]+} 30 } } */ +/* { dg-final { scan-assembler-not {csrr} } } */