From patchwork Tue Apr 18 23:25:15 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: 85111 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp3192050vqo; Tue, 18 Apr 2023 16:26:00 -0700 (PDT) X-Google-Smtp-Source: AKy350Zz7Kdj3sC+vJz02lIXdiA939ZT0xICOUEKY3uHIXgni20QYP/YqUuOCGbrpqY1Xy4QgE+P X-Received: by 2002:a05:6402:342:b0:504:ecfa:fa6c with SMTP id r2-20020a056402034200b00504ecfafa6cmr3451560edw.1.1681860359788; Tue, 18 Apr 2023 16:25:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681860359; cv=none; d=google.com; s=arc-20160816; b=h1HG0FJKrOD4NH0PC+LP9ogsTO46A6I226hKHCKekETJ8j7aO6VOEWsGsdGq7Mn39c G7OmyZd3PZVL3p+y11Wr2ljltD4HstVHuFbBcABidR1nEODY2uIVp2xDOn/x6HkpbnPB 3g/FHndCrniz9x/rh3eMeJB01QqBnl0dt0TTRULKd2mfGs4TQ7YsHWOq67fqeE2mNfMP mEd0sA+LelJ51Dx7HPSqiXsPOxi3lTV2FIlDC61q8iS/KKGd4sFS6W+pjqP+PcYHadXO 5oe50qXN5W350SVHJxs87eRl+ot64agPLT9J9yJ7iNuv0tpxKdFjBUC9C6tOQPuZRWE+ UQiw== 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=z9/VYJkbenIpPWIZ4Vwi7YLFW0fsix2L6IREILBg/yA=; b=oyIKaP0Z8/bVtCtI7Yid2LPLKAIBDYDvK7Dp3px/uDMBL0CttgX4ZWlHUbLd7l0UmF B2cz3HnRMZkMxhZPEsbOFRQPfCAu6D9or8Psx4WcNZ7p/b878BdTXFYi/3yixBZTqWk8 iVWc+zW2dw3yeld25JDPUEdAhSgK6H3hUmP47Kek3C1o9VEmSuz5g4QKGGdxsg93tGOE ZlUKr8rY68oxnEDSa5n2skE0uTBNCRbjQRhA+NoCNZuG+7qYD11suKv/lrlpnggBtmZW WmCN2gzQyt6zLYNK6c3oBOh0LumR65pqTh0ynbEgt7MUvSkwPbNkMurT1P0e6c6QOjSH UObA== ARC-Authentication-Results: i=1; mx.google.com; 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" Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id n4-20020aa7d044000000b0050686277b75si9181412edo.94.2023.04.18.16.25.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Apr 2023 16:25:59 -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; 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" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id DF1143858288 for ; Tue, 18 Apr 2023 23:25:52 +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 5377C3858D1E for ; Tue, 18 Apr 2023 23:25:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5377C3858D1E 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: bizesmtp88t1681860317tr6g2u1e Received: from server1.localdomain ( [58.60.1.22]) by bizesmtp.qq.com (ESMTP) with id ; Wed, 19 Apr 2023 07:25:16 +0800 (CST) X-QQ-SSF: 01400000000000F0P000000A0000000 X-QQ-FEAT: XBN7tc9DADI9R5vyhoiUNHg4O/H7xUslY8uwBfd7GmsoBXcygRlgJhhNkiHp7 FOWULSCKvPaS09Ido0g/xbnD6KToy4MInIm3Fw6BTJaKV4t1WcL9qPsE4jk3ZvTbH/Jxj76 ZERIBsLjl2ELxxxif9WZJigRZEgp3RFo6Tc2DVu4jMO7zQaX3WZB10wD6M7L6ibcwLQoCQ+ hf4sLeaxefF0+mrZ49H3i+hb2RRQPVnqjLrlaoZ+S9KIV6JUwkKjD7bjbZoI0Hb54ZfcCfB eoziikjI6igyjWoK5S1T2SoX3FgOtAdqkH9xev/FaP62Q1n9hAmr2CuvNI6ZaNZNsPG+NUK 4IXAqIp0dNZMBPrqEuV6OladMqJPZnR63BGNixyzbEuIapuWmfY2r7LIF/tVg== X-QQ-GoodBg: 2 X-BIZMAIL-ID: 13608338053448696505 From: juzhe.zhong@rivai.ai To: gcc-patches@gcc.gnu.org Cc: kito.cheng@gmail.com, palmer@dabbelt.com, jeffreyalaw@gmail.com, Ju-Zhe Zhong Subject: [PATCH] RISC-V: Fix bug reported by PR109535 Date: Wed, 19 Apr 2023 07:25:15 +0800 Message-Id: <20230418232515.95891-1-juzhe.zhong@rivai.ai> X-Mailer: git-send-email 2.36.1 MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:rivai.ai:qybglogicsvr:qybglogicsvr7 X-Spam-Status: No, score=-10.5 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, KAM_NUMSUBJECT, KAM_SHORT, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE, 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.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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1763558408913742477?= X-GMAIL-MSGID: =?utf-8?q?1763558408913742477?= From: Ju-Zhe Zhong Fix bug reported by google/highway who is using rvv intrinsic: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109535 PR 109535 gcc/ChangeLog: * config/riscv/riscv-vsetvl.cc (count_regno_occurrences): New function. (pass_vsetvl::cleanup_insns): Fix bug. gcc/testsuite/ChangeLog: * gcc.target/riscv/rvv/base/pr109535.c: New test. --- gcc/config/riscv/riscv-vsetvl.cc | 15 ++++++++++++++- .../gcc.target/riscv/rvv/base/pr109535.c | 11 +++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/pr109535.c diff --git a/gcc/config/riscv/riscv-vsetvl.cc b/gcc/config/riscv/riscv-vsetvl.cc index 1b66e3b9eeb..b570b003a1e 100644 --- a/gcc/config/riscv/riscv-vsetvl.cc +++ b/gcc/config/riscv/riscv-vsetvl.cc @@ -1592,6 +1592,19 @@ backward_propagate_worthwhile_p (const basic_block cfg_bb, return true; } +/* Count the number of REGNO in RINSN. */ +static int +count_regno_occurrences (rtx_insn *rinsn, unsigned int regno) +{ + int count = 0; + extract_insn (rinsn); + for (int i = 0; i < recog_data.n_operands; i++) + if (REG_P (recog_data.operand[i]) + && REGNO (recog_data.operand[i]) == regno) + count++; + return count; +} + avl_info::avl_info (const avl_info &other) { m_value = other.get_value (); @@ -3924,7 +3937,7 @@ pass_vsetvl::cleanup_insns (void) const if (!has_vl_op (rinsn) || !REG_P (get_vl (rinsn))) continue; rtx avl = get_vl (rinsn); - if (count_occurrences (PATTERN (rinsn), avl, 0) == 1) + if (count_regno_occurrences (rinsn, REGNO (avl)) == 1) { /* Get the list of uses for the new instruction. */ auto attempt = crtl->ssa->new_change_attempt (); diff --git a/gcc/testsuite/gcc.target/riscv/rvv/base/pr109535.c b/gcc/testsuite/gcc.target/riscv/rvv/base/pr109535.c new file mode 100644 index 00000000000..7582fe9c392 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/rvv/base/pr109535.c @@ -0,0 +1,11 @@ +/* { dg-do compile } */ +/* { dg-options "-O3 -march=rv32gcv -mabi=ilp32d" } */ + +#include "riscv_vector.h" + +void foo(void *in1, void *in2, void *in3, void *out, size_t vl) { + vint8m1_t a = __riscv_vle8_v_i8m1(in1, vl); + vint8m1_t b = __riscv_vadd_vx_i8m1 (a, vl, vl); + __riscv_vse8_v_i8m1(out, b, vl); +} +