From patchwork Sun Sep 24 03:17:01 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: 144034 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp472377vqu; Sat, 23 Sep 2023 20:17:46 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFiiXHkNg9An7ykf+sv8SbFLhCfA72ecamPhfew/mtIdIbf7w+Wl5S0ny6uvAdn/YiOR5Jn X-Received: by 2002:a05:6402:b1b:b0:52b:c980:43f3 with SMTP id bm27-20020a0564020b1b00b0052bc98043f3mr2953093edb.28.1695525465960; Sat, 23 Sep 2023 20:17:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695525465; cv=none; d=google.com; s=arc-20160816; b=SGrdS3vZRxBOG7uSMDvQzxgKbk6JOwrvGkFxu0rg8YnUn7b1BWW5Lcc92+xa1jdxB+ VXpiwHAVjtwfwXyTHsqDNoxZbe8R6A/ox/gcQBKD5T9ADWq++r4Cm4Gqz8rqvl65IY8A FOWI9ULyTmxr1eXHdgmNjZqrqjw81sv4lws1ImKod7ORDOptFUYp9JG9h01305VaziHl XUNkhpwZbP3UurnoXYBtPXsaB7OjO2aM/3KYeXr7z+2sHkwBN5MbjLVi1n7cDZr+7fdu eyftHjqxYDIBkZSpVwGm1VP1YoNDaaaxQp5f295ACKofN/rd/YzTQs9rIw6xzUP+/Njg vmVQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=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=/oST6NgHML+G2yKAx6pOEPK05Uq90k/RyEc9KdOqHzQ=; fh=12MRPJmZ1mgDpHqWoogMKqnaGRGM2b7lcuJroqfjJiw=; b=aDn5ayZTQ+KsqZAUw5yYYNk9kQudJaYLL7k1SVDuJgibBG9i8ao5cTVOIpymT5BDwD RCMqA8+SHsFb1ywztV02yqpLEkeWy2zKupxA/4D4fFDFm114cPzA6dUPIUwkzoZHcy6z 2ZHeRm+h72pM1NWiMEO3uhWX93K7IsMfXjcpivCquU16yGz9UaklyyJdY5DBdtChA9su O0rYAoemzS2dwuknZF3ob55hb3fUeYu/2vTprTeU3mbuXz+GDYb+smQTOrs/efPqY2ui 2ZgOtY/MKN+D1EJoQLMWR2hGuiedUwD2IIrmFqynaxKrlAYfP74/AHC033WNXREHiq/c Zsmw== 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 y21-20020a056402135500b0052de6d60c1fsi5895689edw.570.2023.09.23.20.17.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Sep 2023 20:17:45 -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 5466E3857353 for ; Sun, 24 Sep 2023 03:17:39 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtpbgbr1.qq.com (smtpbgbr1.qq.com [54.207.19.206]) by sourceware.org (Postfix) with ESMTPS id C071E3858CDB for ; Sun, 24 Sep 2023 03:17:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C071E3858CDB 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: bizesmtp81t1695525423tavdyvvx Received: from rios-cad122.hadoop.rioslab.org ( [58.60.1.26]) by bizesmtp.qq.com (ESMTP) with id ; Sun, 24 Sep 2023 11:17:02 +0800 (CST) X-QQ-SSF: 01400000000000G0V000000A0000000 X-QQ-FEAT: W+onFc5Tw4Pb7C1S/byxRfRxbbRlDo7IxiInMoPTo7c7MvdNslCyriNNbpUXb qoWuLxb8IL/VqosqQUPFTz0B6ZUluDZ9w5g1zJ8cT412j9AkrK7GjwLjYfDCSoYICO2t1P8 HApPpizDoaitb7+yX2SfzVZgG1F5dC8OW0IMU9QWQB7IJEss8HbxlSaBUsYH0K95pquBpWU s/J+xHSZsFhnSpvJEh3uHP1i6E71mmYClndrmZgugSkCJOqF4pj3GyZEWjKVY3JQrWrT5gE KGgQSaVqkYN4F9kTKX633qRClccE1sSvE7/l85I5FU6D6HJ8fGAsIDt45GScQFNJ4H7xFpV Dr+//l6XAuwGpftWAiu7r8HwW37jL2JUR/JmhQzztqEmBCRR+xB5B0hSkj5Pg== X-QQ-GoodBg: 2 X-BIZMAIL-ID: 9460074541527630876 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 AVL/VL bug of VSETVL PASS[PR111548] Date: Sun, 24 Sep 2023 11:17:01 +0800 Message-Id: <20230924031701.398742-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.30 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777887310665568937 X-GMAIL-MSGID: 1777887310665568937 This patch fixes that AVL/VL reg incorrect fetch in VSETVL PASS. C/C++ regression passed. But gfortran didn't run yet. I am still finding a way to run it. Will commit it when I pass the fortran regression. PR target/111548 gcc/ChangeLog: * config/riscv/riscv-vsetvl.cc (earliest_pred_can_be_fused_p): gcc/testsuite/ChangeLog: * gcc.target/riscv/rvv/autovec/pr111548.c: New test. --- gcc/config/riscv/riscv-vsetvl.cc | 16 +++++------- .../gcc.target/riscv/rvv/autovec/pr111548.c | 25 +++++++++++++++++++ 2 files changed, 31 insertions(+), 10 deletions(-) create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/autovec/pr111548.c diff --git a/gcc/config/riscv/riscv-vsetvl.cc b/gcc/config/riscv/riscv-vsetvl.cc index e0f61148ef3..7af33e7ea6f 100644 --- a/gcc/config/riscv/riscv-vsetvl.cc +++ b/gcc/config/riscv/riscv-vsetvl.cc @@ -1514,7 +1514,6 @@ earliest_pred_can_be_fused_p (const bb_info *earliest_pred, const vector_insn_info &earliest_info, const vector_insn_info &expr, rtx *vlmax_vl) { - rtx vl = NULL_RTX; /* Backward VLMAX VL: bb 3: vsetivli zero, 1 ... -> vsetvli t1, zero @@ -1526,10 +1525,9 @@ earliest_pred_can_be_fused_p (const bb_info *earliest_pred, We should forward "t1". */ if (!earliest_info.has_avl_reg () && expr.has_avl_reg ()) { - rtx avl = expr.get_avl (); + rtx avl_or_vl_reg = expr.get_avl_or_vl_reg (); + gcc_assert (avl_or_vl_reg); const insn_info *last_insn = earliest_info.get_insn (); - if (vlmax_avl_p (avl)) - vl = get_vl (expr.get_insn ()->rtl ()); /* To fuse demand on earlest edge, we make sure AVL/VL didn't change from the consume insn to the predecessor of the edge. */ @@ -1538,17 +1536,15 @@ earliest_pred_can_be_fused_p (const bb_info *earliest_pred, && after_or_same_p (i, last_insn); i = i->prev_nondebug_insn ()) { - if (!vl && find_access (i->defs (), REGNO (avl))) + if (find_access (i->defs (), REGNO (avl_or_vl_reg))) return false; - if (vl && find_access (i->defs (), REGNO (vl))) - return false; - if (vl && find_access (i->uses (), REGNO (vl))) + if (find_access (i->uses (), REGNO (avl_or_vl_reg))) return false; } + if (vlmax_vl && vlmax_avl_p (expr.get_avl ())) + *vlmax_vl = avl_or_vl_reg; } - if (vlmax_vl) - *vlmax_vl = vl; return true; } diff --git a/gcc/testsuite/gcc.target/riscv/rvv/autovec/pr111548.c b/gcc/testsuite/gcc.target/riscv/rvv/autovec/pr111548.c new file mode 100644 index 00000000000..9bdf42dbed8 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/pr111548.c @@ -0,0 +1,25 @@ +/* { dg-do compile } */ +/* { dg-options "-march=rv64gcv -mabi=lp64d -Ofast -Wno-implicit-int -Wno-implicit-function-declaration -Wno-int-conversion" } */ + +a, c, d; /* { dg-warning "data definition has no type or storage class" } */ +*b; /* { dg-warning "data definition has no type or storage class" } */ +h() { + int e; + i(); + for (;;) { + unsigned f; + char *g; + f = a; + for (; f; f--) { + if (*g == '"') + e = !e; + *b = g++; + } + if (c) + break; + f = d; + for (; d;) + if (e) + b++; + } +}