From patchwork Thu Aug 17 05:59:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "juzhe.zhong@rivai.ai" X-Patchwork-Id: 135847 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b82d:0:b0:3f2:4152:657d with SMTP id z13csp483084vqi; Wed, 16 Aug 2023 22:59:58 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHlltaI/NY69mjbKX5vbeh3wUkpElixp+OWTEsPxGv01Vjq3BlLyuaoP2Qv4DTtNJm5hnPs X-Received: by 2002:a05:6512:2396:b0:4f8:7568:e94b with SMTP id c22-20020a056512239600b004f87568e94bmr3615244lfv.56.1692251997822; Wed, 16 Aug 2023 22:59:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692251997; cv=none; d=google.com; s=arc-20160816; b=hJ2Yqdf8y3QQV3M1/ZP5K/zKLwBAeSA8/JzG4ykulLCuo+vR+MIx/MRN5mVWUNrYal /dMMpxj7eiSysFRqTuJr9f9eywIUxzoODP/N/AdrMEvnNDWECzunxcW6tD1fTYq/n3UH 9dXwMpKqy3zPdyaUNkSiyjo0AQkBDPxJuz4KsGTz6bY8JC9eTqBKn0PLz+g4VJ+IdwG2 Zmti+2GpavVB2PxWY7LYKZuAkd9WKxR4JKCBBTtVAu+1YAazkZsTUv2KwDkRkhPTxFpJ UAAfBMti5piyRRsOxQR2xZott5T4GugZ2wui3DdMYg5GEo6irkAM0nyppzg1EbiZZwf/ 5j0Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:feedback-id :content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:dmarc-filter:delivered-to; bh=Kw51Fj/kIe9yLj202uRCrYWeNkTc7xJfB4PfnH383o0=; fh=SuV1mxSfYh/fFJBV6FW8ZDQUWC7OLSIDYxyJSOKFLBQ=; b=PprckcMm2E5WPaZiSvoPzvaBbwJX/C5vaIRroXySM9Gm443ihWyQKuyqgu54VRMwzG 4nP+rdujNxgb5YtoW/zHYAJjMv7puLyCazlFRxPIce40ScTbWdz4yMPbicqXYE+ZSVZC dD/O6aPLaBCS76jMcWvpWM11TYPlvJTq+pp5vR4haXBTiwM87RvcFNS4B2iA95Mrc+qw Hd/zKbWE1rTIoiDMki37jyYq8qW3E+HVTCYcI8cqM+QY46aX/yOxWGuQXICCGZ6+nSOb QM96+m8TKwU7YKlixwwe7FEJYGK4oQeL4NRR1oSZkNONzsQCQvDZyNXlTTiTfQ0R/tEv wMyg== 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 y19-20020a50e613000000b00523b8072776si11446028edm.121.2023.08.16.22.59.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Aug 2023 22:59:57 -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 C1EB0385C6DB for ; Thu, 17 Aug 2023 05:59:51 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtpbg153.qq.com (smtpbg153.qq.com [13.245.218.24]) by sourceware.org (Postfix) with ESMTPS id 4DEFF3858D28 for ; Thu, 17 Aug 2023 05:59:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4DEFF3858D28 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: bizesmtp68t1692251949tveb8mh4 Received: from rios-cad122.hadoop.rioslab.org ( [58.60.1.8]) by bizesmtp.qq.com (ESMTP) with id ; Thu, 17 Aug 2023 13:59:08 +0800 (CST) X-QQ-SSF: 01400000000000G0V000000A0000000 X-QQ-FEAT: CR3LFp2JE4kJ5tnQ7A79gyfvfKUE1MrGMWQehNnPkkxoYvIPDFbG5gSmxG0aS wQeulhuAB/0hgzsi9OqrXI6i9Iq3fQO1yzOMRXDL3beZFOZuuzUUIvHS4rZmEBnioJPhxYj xUAd3PlppgFQpxTcKDrtybVOxEA6GCE0r1c+6Jn3lMDWiJa9lRUhN1zGqdDedLG0m5v45xz JhoRDEmp2m+szaDUvVWpkiPiRTbVfajHj4TDBKAvoCUnr1VRoTmfnqXpfJT/PRC517IZ1xV q2eY3tZXVBJRb3djGutnl3Zc2V6C6Tkj1dy47BECW8h6luDzBfCEkj9gjbCFyk4Z43CZZy5 RpK8PThedvmscecApu71Hb7RmMyP3c0NZLHhJKwy+hWadFHGkSieFfT9qJGDoLjvIClGIl7 X-QQ-GoodBg: 2 X-BIZMAIL-ID: 5150297322483405909 From: Juzhe-Zhong To: gcc-patches@gcc.gnu.org Cc: kito.cheng@gmail.com, kito.cheng@sifive.com, jeffreyalaw@gmail.com, rdapp.gcc@gmail.com, Juzhe-Zhong Subject: [PATCH] RISC-V: Fix incorrect VTYPE fusion for floating point scalar move insn[PR111037] Date: Thu, 17 Aug 2023 13:59:06 +0800 Message-Id: <20230817055906.2843802-1-juzhe.zhong@rivai.ai> X-Mailer: git-send-email 2.36.3 MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:rivai.ai:qybglogicsvrgz:qybglogicsvrgz7a-one-0 X-Spam-Status: No, score=-10.3 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, KAM_SHORT, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_PASS, 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: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1774454831260735856 X-GMAIL-MSGID: 1774454831260735856 void foo(_Float16 y, int64_t *i64p) { vint64m1_t vx =__riscv_vle64_v_i64m1 (i64p, 1); vx = __riscv_vadd_vv_i64m1 (vx, vx, 1); vfloat16m1_t vy =__riscv_vfmv_s_f_f16m1 (y, 1); asm volatile ("# use %0 %1" : : "vr"(vx), "vr" (vy)); } zve64f: foo: vsetivli zero,1,e16,mf4,ta,ma vle64.v v1,0(a0) vfmv.s.f v2,fa0 vsetvli zero,zero,e64,m1,ta,ma vadd.vv v1,v1,v1 zve64d: foo: vsetivli zero,1,e64,m1,ta,ma vle64.v v1,0(a0) vfmv.s.f v2,fa0 vadd.vv v1,v1,v1 PR target111037 gcc/ChangeLog: * config/riscv/riscv-vsetvl.cc (float_insn_valid_sew_p): New function. (second_sew_less_than_first_sew_p): Fix bug. (first_sew_less_than_second_sew_p): Ditto. gcc/testsuite/ChangeLog: * gcc.target/riscv/rvv/base/pr111037-1.c: New test. * gcc.target/riscv/rvv/base/pr111037-2.c: New test. --- gcc/config/riscv/riscv-vsetvl.cc | 22 +++++++++++++++++-- .../gcc.target/riscv/rvv/base/pr111037-1.c | 15 +++++++++++++ .../gcc.target/riscv/rvv/base/pr111037-2.c | 8 +++++++ 3 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/pr111037-1.c create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/pr111037-2.c diff --git a/gcc/config/riscv/riscv-vsetvl.cc b/gcc/config/riscv/riscv-vsetvl.cc index 08c487d82c0..79cbac01047 100644 --- a/gcc/config/riscv/riscv-vsetvl.cc +++ b/gcc/config/riscv/riscv-vsetvl.cc @@ -1183,18 +1183,36 @@ second_ratio_invalid_for_first_lmul_p (const vector_insn_info &info1, return calculate_sew (info1.get_vlmul (), info2.get_ratio ()) == 0; } +static bool +float_insn_valid_sew_p (const vector_insn_info &info, unsigned int sew) +{ + if (info.get_insn () && info.get_insn ()->is_real () + && get_attr_type (info.get_insn ()->rtl ()) == TYPE_VFMOVFV) + { + if (sew == 16) + return TARGET_VECTOR_ELEN_FP_16; + else if (sew == 32) + return TARGET_VECTOR_ELEN_FP_32; + else if (sew == 64) + return TARGET_VECTOR_ELEN_FP_64; + } + return true; +} + static bool second_sew_less_than_first_sew_p (const vector_insn_info &info1, const vector_insn_info &info2) { - return info2.get_sew () < info1.get_sew (); + return info2.get_sew () < info1.get_sew () + || !float_insn_valid_sew_p (info1, info2.get_sew ()); } static bool first_sew_less_than_second_sew_p (const vector_insn_info &info1, const vector_insn_info &info2) { - return info1.get_sew () < info2.get_sew (); + return info1.get_sew () < info2.get_sew () + || !float_insn_valid_sew_p (info2, info1.get_sew ()); } /* return 0 if LMUL1 == LMUL2. diff --git a/gcc/testsuite/gcc.target/riscv/rvv/base/pr111037-1.c b/gcc/testsuite/gcc.target/riscv/rvv/base/pr111037-1.c new file mode 100644 index 00000000000..0b7b32fc3e6 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/rvv/base/pr111037-1.c @@ -0,0 +1,15 @@ +/* { dg-do compile } */ +/* { dg-options "-march=rv32gc_zve64f_zvfh -mabi=ilp32d -O3" } */ + +#include "riscv_vector.h" + +void foo(_Float16 y, int64_t *i64p) +{ + vint64m1_t vx =__riscv_vle64_v_i64m1 (i64p, 1); + vx = __riscv_vadd_vv_i64m1 (vx, vx, 1); + vfloat16m1_t vy =__riscv_vfmv_s_f_f16m1 (y, 1); + asm volatile ("# use %0 %1" : : "vr"(vx), "vr" (vy)); +} + +/* { dg-final { scan-assembler-times {vsetivli\s+zero,\s*1,\s*e16,\s*mf4,\s*t[au],\s*m[au]} 1 } } */ +/* { dg-final { scan-assembler-times {vsetvli\s+zero,\s*zero,\s*e64,\s*m1,\s*t[au],\s*m[au]} 1 } } */ diff --git a/gcc/testsuite/gcc.target/riscv/rvv/base/pr111037-2.c b/gcc/testsuite/gcc.target/riscv/rvv/base/pr111037-2.c new file mode 100644 index 00000000000..ac50da71726 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/rvv/base/pr111037-2.c @@ -0,0 +1,8 @@ +/* { dg-do compile } */ +/* { dg-options "-march=rv32gc_zve64d_zvfh -mabi=ilp32d -O3" } */ + +#include "pr111037-1.c" + +/* { dg-final { scan-assembler-times {vsetivli\s+zero,\s*1,\s*e64,\s*m1,\s*t[au],\s*m[au]} 1 } } */ +/* { dg-final { scan-assembler-not {vsetvli} } } */ +/* { dg-final { scan-assembler-times {vsetivli} 1 } } */