From patchwork Fri Nov 17 07:35:49 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: 166005 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9910:0:b0:403:3b70:6f57 with SMTP id i16csp359518vqn; Thu, 16 Nov 2023 23:36:23 -0800 (PST) X-Google-Smtp-Source: AGHT+IEYd9mDGtVuAasE1MT5BNunOAd04V40b/Jq4S1Ac/EWCuZ+vnwkobMfU0YlH9UbgUFPnlnq X-Received: by 2002:a05:6214:16cc:b0:66d:1112:e870 with SMTP id d12-20020a05621416cc00b0066d1112e870mr11497763qvz.22.1700206583592; Thu, 16 Nov 2023 23:36:23 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1700206583; cv=pass; d=google.com; s=arc-20160816; b=S9f2GgdjRj+NMkuYNqACftfzZPAtoTqalJtKVc/BIIGvCHsIGWxDSpmIwqrgZR+OOK 7dsrjudSNsDyj+kKfMeKRkzaMo4jW/kiNIfrYtoGUu1cgzTaYK0VqNA1nz2t9NPxI9dv CXwh55jOS8c9Kq2H5OyUHgolNl0o/GspH5M6sRfqLTJ0VRQgg35V1289au6FHp2JAEp2 0EDXPw7pdUOy3B8XRJjOjYs68V6xuExGpahDOjsIpG5uxZec/28ZMXZ226QzDaWSPT3F 0yc2ZynXNX/S+g/LpaKHHlvwwDqgYX2DdCUaZU+0l6qxklGMjgXj2hAbSET0zlXX057v Q64w== ARC-Message-Signature: i=2; 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:arc-filter:dmarc-filter:delivered-to; bh=ih4wZxPD/XgJOCE0hERzrR9p98qEAB2jeCZPHtas8Wo=; fh=12MRPJmZ1mgDpHqWoogMKqnaGRGM2b7lcuJroqfjJiw=; b=qHv3HiiLs0JnDjXUINvECPgKvgUW487XeW/APfJn4XHvfSBMiIOR2mkUIts0GorYL1 oR/Cxpy+zqzhjVuGZXDXsAq4KIXG4kYVMTw2VxSWpr6a+kPUyX+oDlYjsdxC7Vh9QmkR IE/+RIoo7PaW97x8R793lsDPXYLVBtEUyP3ob6clcfAr8tWSSJzvvnvj6cF8AcojyVTS p3begPDOGzxQ9s7Fg5e0YlRgT+aDyLfEPKETyrnhH7sYZxcarIu7BHwTS2mRRgaiMutH wan73uH9QrakU1j1nXUOjIlCtCu+CoISxokhmK0axCPZ5DsxvEODZEjYOAK32FDZj+jK t11A== ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); 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 (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id q14-20020a0cfa0e000000b0065afc27a1fcsi1126088qvn.594.2023.11.16.23.36.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Nov 2023 23:36:23 -0800 (PST) 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; arc=pass (i=1); 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 5F7133858409 for ; Fri, 17 Nov 2023 07:36:23 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtpbguseast3.qq.com (smtpbguseast3.qq.com [54.243.244.52]) by sourceware.org (Postfix) with ESMTPS id 571453858D28 for ; Fri, 17 Nov 2023 07:35:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 571453858D28 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=rivai.ai Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=rivai.ai ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 571453858D28 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=54.243.244.52 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700206560; cv=none; b=L364fEW9gB3RVgyrmPW9jjBxr8uXrR5pLdTN2huEea/iEFsv3X1zld6DvG1S8Yr2uCZGptgiywWLgaPDW7mqg+ezoOiEyLPUhGSvWN5gz4XQlx6Ha+Epka+M/iOQVhnNaLHFlkugHfV0WpY0/zBnKNkGBHKrggYXCkaN/UnRl4k= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700206560; c=relaxed/simple; bh=Qp9Am3r68lDYlTrzxLUQ7T28E/H0gFKfp+J+4kvEOQQ=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=HXpRos2brFtA1K5VozUqknpLGy126GRd8GgrqFt+vHMTDXuhbwZ0wmTD8Lp6ia9Kp8CJv+WORUsFV1FjHvGON062BmKokoqWXBMvcG7GBeHJERdOsRxWtwGl1rrEzT2C/4CKCKcSe1GQ7MKqzQWxc2u4d/OB6Q+OTuaHv85AU40= ARC-Authentication-Results: i=1; server2.sourceware.org X-QQ-mid: bizesmtp83t1700206551tjkr27mc Received: from rios-cad122.hadoop.rioslab.org ( [58.60.1.26]) by bizesmtp.qq.com (ESMTP) with id ; Fri, 17 Nov 2023 15:35:50 +0800 (CST) X-QQ-SSF: 01400000000000G0V000000A0000000 X-QQ-FEAT: QityeSR92A2BNenm7EoNlTCmDo/0AuW45kAhVcFijIBnQDUDZlgmz/298DbO7 BYpTul/p8ObU8iEmo0ChmKDKEZgab0BYIhDtqnBVQEU6k4NdQOXTcYB3yyqUsSskTkw2QIV ggUso7/TMLmnDyl5GV4lcJjnbaIpCdAHS6HXt/HL6BFefP24xVJIgzxENuhUIAdFnXRz76i V1PLMXKxbj6Ps2s7VvLdGwhq30ub4StPffO29NihYYebD2CAluw7E9uk97nn8tlglzjzVAh 8r+Zv9hOyXf9aXXF5ot5PmkuZHA5cmu6pf+1DgC5gh7ZnROChbLBX/S/GYIXNDJqLSdk8qX RME7KmIwjs/+Dj0emGDvrKWLU9zslCQ1Fb3VfVdngiNAb1csXFiWGhbPzBoMFGDgAxkBSjx HHAIz/qQcK4= X-QQ-GoodBg: 2 X-BIZMAIL-ID: 827745176810110729 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 bug of tuple move splitter[PR112561] Date: Fri, 17 Nov 2023 15:35:49 +0800 Message-Id: <20231117073549.1841897-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=-9.8 required=5.0 tests=BAYES_00, GIT_PATCH_0, HEXHASH_WORD, KAM_DMARC_STATUS, KAM_SHORT, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_PASS, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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: 1782795818800586211 X-GMAIL-MSGID: 1782795818800586211 Fix segment fault on tuple move: bbl loader z 0000000000000000 ra 00000000000102ac sp 0000003ffffffaf0 gp 000000000001c0b8 tp 0000000000000000 t0 00000000000104a0 t1 000000000000000f t2 0000000000000000 s0 0000000000000000 s1 0000000000000000 a0 0000003ffffffb30 a1 0000003ffffffb58 a2 0000000000000000 a3 0000000000000000 a4 0000000000000000 a5 000000000001c340 a6 0000000000000004 a7 0000000000000004 s2 0000000000000000 s3 0000000000000000 s4 0000000000000000 s5 0000000000000000 s6 0000000000000000 s7 0000000000000000 s8 0000000000000000 s9 0000000000000000 sA 0000000000000000 sB 0000000000000000 t3 0000000000000000 t4 0000000000000000 t5 0000000000000000 t6 0000000000000000 pc 00000000000101aa va/inst 0000000000000004 sr 8000000200006620 User store segfault @ 0x0000000000000004 PR target/112561 gcc/ChangeLog: * config/riscv/riscv-v.cc (emit_vlmax_insn_lra): Add VLS optimization. (expand_tuple_move): Fix bug gcc/testsuite/ChangeLog: * gcc.target/riscv/rvv/autovec/pr112561.c: New test. --- gcc/config/riscv/riscv-v.cc | 21 ++++++++++++++++--- .../gcc.target/riscv/rvv/autovec/pr112561.c | 16 ++++++++++++++ 2 files changed, 34 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/autovec/pr112561.c diff --git a/gcc/config/riscv/riscv-v.cc b/gcc/config/riscv/riscv-v.cc index 6a2009ffb05..08bbb657a06 100644 --- a/gcc/config/riscv/riscv-v.cc +++ b/gcc/config/riscv/riscv-v.cc @@ -374,10 +374,24 @@ void emit_vlmax_insn_lra (unsigned icode, unsigned insn_flags, rtx *ops, rtx vl) { gcc_assert (!can_create_pseudo_p ()); + machine_mode mode = GET_MODE (ops[0]); - insn_expander e (insn_flags, true); - e.set_vl (vl); - e.emit_insn ((enum insn_code) icode, ops); + if (imm_avl_p (mode)) + { + /* Even though VL is a real hardreg already allocated since + it is post-RA now, we still gain benefits that we emit + vsetivli zero, imm instead of vsetvli VL, zero which is + we can be more flexible in post-RA instruction scheduling. */ + insn_expander e (insn_flags, false); + e.set_vl (gen_int_mode (GET_MODE_NUNITS (mode), Pmode)); + e.emit_insn ((enum insn_code) icode, ops); + } + else + { + insn_expander e (insn_flags, true); + e.set_vl (vl); + e.emit_insn ((enum insn_code) icode, ops); + } } /* Emit an RVV insn with a predefined vector length. Contrary to @@ -2148,6 +2162,7 @@ expand_tuple_move (rtx *ops) offset = ops[2]; } + emit_vlmax_vsetvl (subpart_mode, ops[4]); if (MEM_P (ops[1])) { /* Load operations. */ diff --git a/gcc/testsuite/gcc.target/riscv/rvv/autovec/pr112561.c b/gcc/testsuite/gcc.target/riscv/rvv/autovec/pr112561.c new file mode 100644 index 00000000000..25e61fa12c0 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/pr112561.c @@ -0,0 +1,16 @@ +/* { dg-do run { target { riscv_v } } } */ +/* { dg-options "-O3 -ftree-vectorize --param=riscv-autovec-preference=fixed-vlmax -mcmodel=medlow" } */ + +int printf(char *, ...); +int a, b, c, e; +short d[7][7] = {}; +int main() { + short f; + c = 0; + for (; c <= 6; c++) { + e |= d[c][c] & 1; + b &= f & 3; + } + printf("%d\n", a); + return 0; +}