From patchwork Thu Sep 28 01:33:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Xu X-Patchwork-Id: 145668 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp3009332vqu; Wed, 27 Sep 2023 18:33:49 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE3HaZZZlNHKMvrGlRmKJ1iRJUOygn8F0qq22IcHipyKV+OokUnoAtgsv6DKmqEu7++D1X+ X-Received: by 2002:a5d:650d:0:b0:324:7a6b:d504 with SMTP id x13-20020a5d650d000000b003247a6bd504mr3140895wru.4.1695864829290; Wed, 27 Sep 2023 18:33:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695864829; cv=none; d=google.com; s=arc-20160816; b=a6yJq6X/DcYzKHKaSvkpUMRK5tFA3ZaurUWPRQ7ioZbTNj4NSWK4R+yhlbj0b2vo+n Nxwg1l/pQ+mxYc9x1OHJQ19jKOpfu6UVQiENtP1QlZPrbqH8MYpzjwmH2MbgVrv6j8kY xdNkRPOUXWUsJmFIr6V6b+o56U0SX1VVdlulbIPSiCh9+5gqP7iLO6eVNHbFqawFK2Ux XW4M8LvPPGiE0oGfYv04IhzpwAB3nsp6cU26lriAhGvZ5cBwyWQ/XtsX2ObIGXH7YuTq x5rjVaQTA693JEK4LtQVIyiJd1rYYZlJFC5TYRfBzT5smZ3KuJ5ASzwEkauddcttADcn FklQ== 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:message-id:date:subject:cc:to :from:dmarc-filter:delivered-to; bh=vNNHJh4TZ0DcxhZ54VziZz56gO9+RNlnfyr9opkZnKY=; fh=Qb/t3bub0qUevN32JfR0ksI5uuULifWToHOJuO7VEBY=; b=pJATXwxwc+Y5IrPn8CJ8iV8Zeuvqjr1cSxCeYwXiOojZlvvYSzCBPWpxxrDW3BpXAA 9TbQWrQ3Ghi0GoCjmsk8T1FNN3FZ2eQRWyt9mWeTBhdOu2wN4hy1iZ0OYhkPTWY6r6/Q tjjV17X7YE1hs3/euT12e33ve/KXxWd86XVJ1pDn1M1ZtOLHLY21WlJ/73CvFFHAkQgk C/aEMRRdLHQuea+G1FdV0J/AwTQZhGEQOvi+G2pVJEQ4Rgq3XxvkQGreYLOyg8qHI41J UeIBvq2pSP6xPBOXnCgObYOg9m9srPMhygeYzQklfoFKaJ9A+D74Kg7c+TqcU/9oPxhU a11g== 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 server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id uz3-20020a170907118300b009a191d7a0fasi14119239ejb.904.2023.09.27.18.33.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Sep 2023 18:33:49 -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 683553861820 for ; Thu, 28 Sep 2023 01:33:43 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from zg8tmty3ljk5ljewns4xndka.icoremail.net (zg8tmty3ljk5ljewns4xndka.icoremail.net [167.99.105.149]) by sourceware.org (Postfix) with ESMTP id 2948C3858402 for ; Thu, 28 Sep 2023 01:33:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2948C3858402 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=eswincomputing.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=eswincomputing.com Received: from host014-ubuntu-1804.lxd (unknown [10.12.130.31]) by app1 (Coremail) with SMTP id EwgMCgDXdMTb1xRl6n5NAA--.12234S4; Thu, 28 Sep 2023 09:33:15 +0800 (CST) From: Li Xu To: gcc-patches@gcc.gnu.org Cc: kito.cheng@gmail.com, palmer@dabbelt.com, juzhe.zhong@rivai.ai, xuli Subject: [PATCH v2] RISC-V: Bugfix for RTL check[PR111533] Date: Thu, 28 Sep 2023 01:33:14 +0000 Message-Id: <20230928013314.30176-1-xuli1@eswincomputing.com> X-Mailer: git-send-email 2.17.1 X-CM-TRANSID: EwgMCgDXdMTb1xRl6n5NAA--.12234S4 X-Coremail-Antispam: 1UD129KBjvJXoWxtFW7JFW7XrWrGw18GryfZwb_yoW7XrWUpa yDGw4ayrWkJFZxWw43tFyUJr43Zwn3KryYkwn3Aw17CF4DXrWqvan8tF13Aw15WF4Ygr13 uw1a9ryYkw1Yg3DanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUk214x267AKxVW8JVW5JwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK02 1l84ACjcxK6xIIjxv20xvE14v26w1j6s0DM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26r4U JVWxJr1l84ACjcxK6I8E87Iv67AKxVW0oVCq3wA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_Gc CE3s1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqx4xG64xvF2IEw4CE5I8CrVC2j2WlYx0E 2Ix0cI8IcVAFwI0_Jr0_Jr4lYx0Ex4A2jsIE14v26r1j6r4UMcvjeVCFs4IE7xkEbVWUJV W8JwACjcxG0xvY0x0EwIxGrwACjI8F5VA0II8E6IAqYI8I648v4I1lc2xSY4AK6svPMxAI w28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r4UMI8I3I0E5I8CrVAFwI0_Jr0_Jr 4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7AF67AKxVWUAVWUtwCIc40Y0x0EwIxG rwCI42IY6xIIjxv20xvE14v26r1j6r1xMIIF0xvE2Ix0cI8IcVCY1x0267AKxVWUJVW8Jw CI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Jr0_Gr1lIxAIcVC2 z280aVCY1x0267AKxVWUJVW8JbIYCTnIWIevJa73UjIFyTuYvjfUoOJ5UUUUU X-CM-SenderInfo: 50xoxi46hv4xpqfrz1xxwl0woofrz/ X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, KAM_SHORT, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP, WEIRD_PORT 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: 1778243159178249328 X-GMAIL-MSGID: 1778243159178249328 From: xuli Consider the flowing situation: BB5: local_dem(RVV Insn 1, AVL(reg zero)) RVV Insn 1: vmv.s.x, AVL (const_int 1) RVV Insn 2: vredsum.vs, AVL(reg zero) vmv.s.x has vl operand, the following code will get avl (cosnt_int) from RVV Insn 1. rtx avl = has_vl_op (insn->rtl ()) ? get_vl (insn->rtl ()) : dem.get_avl (); If use REGNO for const_int, the compiler will crash: during RTL pass: vsetvl res_debug.c: In function '__dn_count_labels': res_debug.c:1050:1: internal compiler error: RTL check: expected code 'reg', have 'const_int' in rhs_regno, at rtl.h:1934 1050 | } | ^ 0x8fb169 rtl_check_failed_code1(rtx_def const*, rtx_code, char const*, int, char const*) ../.././gcc/gcc/rtl.cc:770 0x1399818 rhs_regno(rtx_def const*) ../.././gcc/gcc/rtl.h:1934 0x1399818 anticipatable_occurrence_p ../.././gcc/gcc/config/riscv/riscv-vsetvl.cc:348 So in this case avl should be obtained from dem. Another issue is caused by the following code: HOST_WIDE_INT diff = INTVAL (builder.elt (i)) - i; during RTL pass: expand ../../.././gcc/libgfortran/generated/matmul_c4.c: In function 'matmul_c4': ../../.././gcc/libgfortran/generated/matmul_c4.c:2906:39: internal compiler error: RTL check: expected code 'const_int', have 'const_poly_int' in expand_const_vector, at config/riscv/riscv-v.cc:1149 The builder.elt (i) can be either const_int or const_poly_int. PR target/111533 gcc/ChangeLog: * config/riscv/riscv-v.cc (expand_const_vector): Fix bug. * config/riscv/riscv-vsetvl.cc (anticipatable_occurrence_p): Fix bug. gcc/testsuite/ChangeLog: * gcc.target/riscv/rvv/base/pr111533-1.c: New test. * gcc.target/riscv/rvv/base/pr111533-2.c: New test. --- gcc/config/riscv/riscv-v.cc | 5 ++-- gcc/config/riscv/riscv-vsetvl.cc | 3 +- .../gcc.target/riscv/rvv/base/pr111533-1.c | 15 ++++++++++ .../gcc.target/riscv/rvv/base/pr111533-2.c | 29 +++++++++++++++++++ 4 files changed, 48 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/pr111533-1.c create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/pr111533-2.c diff --git a/gcc/config/riscv/riscv-v.cc b/gcc/config/riscv/riscv-v.cc index 359fb2ced8b..26700cfc732 100644 --- a/gcc/config/riscv/riscv-v.cc +++ b/gcc/config/riscv/riscv-v.cc @@ -1149,8 +1149,9 @@ expand_const_vector (rtx target, rtx src) for (unsigned int i = 0; i < v.npatterns (); ++i) { /* Calculate the diff between the target sequence and - vid sequence. */ - HOST_WIDE_INT diff = INTVAL (builder.elt (i)) - i; + vid sequence. The elt (i) can be either const_int or + const_poly_int. */ + poly_int64 diff = rtx_to_poly_int64 (builder.elt (i)) - i; v.quick_push (gen_int_mode (diff, v.inner_mode ())); } /* Step 2: Generate result = VID + diff. */ diff --git a/gcc/config/riscv/riscv-vsetvl.cc b/gcc/config/riscv/riscv-vsetvl.cc index 7af33e7ea6f..af8c31d873c 100644 --- a/gcc/config/riscv/riscv-vsetvl.cc +++ b/gcc/config/riscv/riscv-vsetvl.cc @@ -307,8 +307,7 @@ anticipatable_occurrence_p (const bb_info *bb, const vector_insn_info dem) if (dem.has_avl_reg ()) { /* rs1 (avl) are not modified in the basic block prior to the VSETVL. */ - rtx avl - = has_vl_op (insn->rtl ()) ? get_vl (insn->rtl ()) : dem.get_avl (); + rtx avl = dem.get_avl_or_vl_reg (); if (dem.dirty_p ()) { gcc_assert (!vsetvl_insn_p (insn->rtl ())); diff --git a/gcc/testsuite/gcc.target/riscv/rvv/base/pr111533-1.c b/gcc/testsuite/gcc.target/riscv/rvv/base/pr111533-1.c new file mode 100644 index 00000000000..aba26dfac89 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/rvv/base/pr111533-1.c @@ -0,0 +1,15 @@ +/* { dg-do compile } */ +/* { dg-options "-march=rv64gcv -mabi=lp64d -O2 -ffast-math -ftree-vectorize" } */ + +#include + +typedef _Complex float GFC_COMPLEX_4; + +void +test (GFC_COMPLEX_4 *a, GFC_COMPLEX_4 *b, GFC_COMPLEX_4 c, ptrdiff_t i, ptrdiff_t j) +{ + ptrdiff_t l; + for (l = 0; l <= i; ++l) + c += b[l] * a[j]; + b[j] = c; +} diff --git a/gcc/testsuite/gcc.target/riscv/rvv/base/pr111533-2.c b/gcc/testsuite/gcc.target/riscv/rvv/base/pr111533-2.c new file mode 100644 index 00000000000..a4d2011b74b --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/rvv/base/pr111533-2.c @@ -0,0 +1,29 @@ +/* { dg-do compile } */ +/* { dg-options "-march=rv64gcv -mabi=lp64d -O2" } */ + +#include + +/* Return the number of DNS hierarchy levels in the name. */ +int +test (const char *name) { + int i, len, count; + + len = strlen(name); + for (i = 0, count = 0; i < len; i++) { + /* XXX need to check for \. or use named's nlabels(). */ + if (name[i] == '.') + count++; + } + + /* don't count initial wildcard */ + if (name[0] == '*') + if (count) + count--; + + /* don't count the null label for root. */ + /* if terminating '.' not found, must adjust */ + /* count to include last label */ + if (len > 0 && name[len-1] != '.') + count++; + return (count); +}