From patchwork Thu Nov 23 11:59:52 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: 168898 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce62:0:b0:403:3b70:6f57 with SMTP id o2csp390294vqx; Thu, 23 Nov 2023 04:01:42 -0800 (PST) X-Google-Smtp-Source: AGHT+IEzgEcYY6+An70BYWf3jbGqO+DHpIQ/v9N28ZjVdAKQvcSOJ2leDNeS1+3wbv8wLDh2/OsX X-Received: by 2002:a05:620a:2cc2:b0:77d:617f:491f with SMTP id tc2-20020a05620a2cc200b0077d617f491fmr4352783qkn.24.1700740902044; Thu, 23 Nov 2023 04:01:42 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1700740902; cv=pass; d=google.com; s=arc-20160816; b=hPRq5glMK0g2x20lcRrrGAjH6ah9936ELG7mzcIQNNWTN+uSj5nxxyz9gLYOcrIP2I 4yjxp0LceCfPMpNbxvrH9SbKHpkCE/edVZoSEgXNPLVIDpHrSHn/lWv+EaoaMJmAhn8h dScxPtwUOME8PFHsQ8FFv4mLr6haLvXo8svOELo6mEV5tuWZklqJN0mM8g1fr56qVRku fUsAPKDGo2ExOi1wPHarTEVHpcmF325ZsffpqWRVEPmCyWNUVgVCsYOGFsABp1ld/NDM RcgFDvLfefmywhCrWPg746qiejjAv2egmUIDAcR3JtzpJhjxNVpqH+v3K1rKAMEp/IHM XERQ== 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=qsCdsyRNmjYAurBnsg9TONt2TqRhY/gxwS/SVz/gnCQ=; fh=idvV5TQ1gmHAoU8u1GUGfjilVySOK+BR5TeZLoSouN8=; b=EmUpyF8SRaB0U6fe44UvaS1NQ56rl5y5V0aLXZb4F1T5qOQdw9STceP8iDlV1l08lO wpMtYtvXFldq1EJYYydD0qXzQ6YvlYvneKhiOjE2pRakfu2lbY33lJVuCJtQMRjJqcxk KJJMr0cYsXSp+xjTfPIdGujogTSBetwSTfJOz2MP7ASdcx6etF2nF2HOyUMKFwBttEOH 2Q7m6CY2WyL5uYUtYiu+RdwBEeJgfI9uVcA3bvgEIOcPHjAvu40bxvM+VoMztyQ09A2Y mv6Hnn6Odvp0rfQnyFIqTAfqrznjJqTMMoB0cwTkavtxHs1KHpkyjOEQFGGPZdufqLXk lS9Q== 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 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 i2-20020a05620a248200b0077bfe7fb75fsi996165qkn.645.2023.11.23.04.01.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Nov 2023 04:01:42 -0800 (PST) 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; arc=pass (i=1); 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 E83E338618B8 for ; Thu, 23 Nov 2023 12:01:05 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtpbgeu1.qq.com (smtpbgeu1.qq.com [52.59.177.22]) by sourceware.org (Postfix) with ESMTPS id 7C0DF385828A for ; Thu, 23 Nov 2023 12:00:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7C0DF385828A 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 7C0DF385828A Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=52.59.177.22 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700740807; cv=none; b=b+HaMJASFsPVWqOBrAYgDu6M6ScwMHpQYSs9xc0iN/hx0uJB7M2I0Z8oniALIyUPUBx3ztzPAWWrU5c3vjWH7+GDOjZ1CmXASdJc++mwa1LF1fKPWQJeAqvMmJ1Id2TUgpmrtKxTey0+XpVHdzfUxQQRg5YRuDOdxE44Ro9E4yA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700740807; c=relaxed/simple; bh=Ymst1jQbs024afOEKtNAgKkajHpFCa1p00Gp495wvWU=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=jMo48ZfAsUhcXapTCI1imVZO8/X5hiRu2yT2Hso3y33ennliaGii3u21i5QOWqfOc9hX6bTkNOWJXRLCTYQRu4UGUTNBgIF5hSzcX3j6wN6weOtghUgs5CctEmlTKC8LAE7o19QH5sJNRyaE3Nt97NIbDUcLegPb3WY8v0F/TlE= ARC-Authentication-Results: i=1; server2.sourceware.org X-QQ-mid: bizesmtp79t1700740795te8l3im6 Received: from rios-cad122.hadoop.rioslab.org ( [58.60.1.26]) by bizesmtp.qq.com (ESMTP) with id ; Thu, 23 Nov 2023 19:59:54 +0800 (CST) X-QQ-SSF: 01400000000000G0V000000A0000000 X-QQ-FEAT: tgzXWVxr7yg1fRa+fUj/wlM7rq+g0UCQ1+gVpg2JW9iv+NLHJi60LCI0D2ze4 GfqoCcQPrhjnLuzJ1P+1ubwcxOHeSAv6oQDmzCVfFsmn6JaFhWGa9c5R6Z6qPfp66VRnRp3 VIEm1hoR74K0iCyace+LsWdgqy69gQb70FoCg+pLQKowYl0difyny4BpzCif9q7EQBl7jAg Z+R7419LJaNKDkMGTfEv0wogBCgo+NzDFSm6wBvg8yV+ppeQkTurIPQsySyKCMZ/MBMwMGg ZuqnkV0Ct8WwX2E8wfS12LguUyrJ6R+XCUv/bD6atKLVFi3enlPRPKuUQt6concOPC7fiW+ nK1/A2TqeHxZ2096dOvB2R1y0F+W0ZSqOVOmKObeB9K6jfW9gpZy8/Ug2FbhgyC4WiRusjz npZDP7yQ+dbP8GquIZtURQ== X-QQ-GoodBg: 2 X-BIZMAIL-ID: 10160698618383901538 From: Juzhe-Zhong To: gcc-patches@gcc.gnu.org Cc: Juzhe-Zhong Subject: [Committed V2] RISC-V: Disable AVL propagation of vrgather instruction Date: Thu, 23 Nov 2023 19:59:52 +0800 Message-Id: <20231123115952.1502588-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_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.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: 1783356092099480213 X-GMAIL-MSGID: 1783356092099480213 This patch fixes following FAILs in zvl1024b of both RV32/RV64: FAIL: gcc.c-torture/execute/990128-1.c -O2 execution test FAIL: gcc.c-torture/execute/990128-1.c -O2 -flto -fno-use-linker-plugin -flto-partition=none execution test FAIL: gcc.c-torture/execute/990128-1.c -O2 -flto -fuse-linker-plugin -fno-fat-lto-objects execution test FAIL: gcc.c-torture/execute/990128-1.c -O3 -fomit-frame-pointer -funroll-loops -fpeel-loops -ftracer -finline-functions execution test FAIL: gcc.c-torture/execute/990128-1.c -O3 -g execution test FAIL: gcc.dg/torture/pr58955-2.c -O3 -fomit-frame-pointer -funroll-loops -fpeel-loops -ftracer -finline-functions execution test The root case can be simpliy described in this following small case: https://godbolt.org/z/7GaxbEGzG #include "riscv_vector.h" typedef int64_t v1024b __attribute__ ((vector_size (128))); void foo (void *out, void *in, int64_t a, int64_t b) { v1024b v = {a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a}; v1024b v2 = {b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b}; v1024b index = *(v1024b*)in; v1024b v3 = __builtin_shuffle (v, v2, index); __riscv_vse64_v_i64m1 (out, (vint64m1_t)v3, 10); } Incorrect ASM: foo: li a5,31 vsetivli zero,10,e64,m1,ta,mu vmv.v.x v2,a5 vl1re64.v v1,0(a1) vmv.v.x v4,a2 vand.vv v1,v1,v2 vmv.v.x v3,a3 vmsgeu.vi v0,v1,16 vrgather.vv v2,v4,v1 --> AVL = VLMAX according to codes. vadd.vi v1,v1,-16 vrgather.vv v2,v3,v1,v0.t --> AVL = VLMAX according to codes. vse64.v v2,0(a0) --> AVL = 10 according to codes. ret For vrgather dest, source, index instruction, when index may has the value > the following store AVL that is index value > 10. In this situation, the codes above will end up with: The source vector of vrgather has undefined value on index >= AVL (which is 10 in this case). So disable AVL propagation for vrgather instruction. PR target/112599 PR/target/112670 gcc/ChangeLog: * config/riscv/riscv-avlprop.cc (alv_can_be_propagated_p): New function. (vlmax_ta_p): Disable vrgather AVL propagation. gcc/testsuite/ChangeLog: * gcc.target/riscv/rvv/autovec/pr112599-1.c: New test. --- gcc/config/riscv/riscv-avlprop.cc | 13 ++++++++++++- .../gcc.target/riscv/rvv/autovec/pr112599-1.c | 17 +++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/autovec/pr112599-1.c diff --git a/gcc/config/riscv/riscv-avlprop.cc b/gcc/config/riscv/riscv-avlprop.cc index 1f6ba405342..68b9af07d99 100644 --- a/gcc/config/riscv/riscv-avlprop.cc +++ b/gcc/config/riscv/riscv-avlprop.cc @@ -104,10 +104,21 @@ avlprop_type_to_str (enum avlprop_type type) } } +/* Return true if the AVL of the INSN can be propagated. */ +static bool +alv_can_be_propagated_p (rtx_insn *rinsn) +{ + /* The index of "vrgather dest, source, index" may pick up the + element which has index >= AVL, so we can't strip the elements + that has index >= AVL of source register. */ + return get_attr_type (rinsn) != TYPE_VGATHER; +} + static bool vlmax_ta_p (rtx_insn *rinsn) { - return vlmax_avl_type_p (rinsn) && tail_agnostic_p (rinsn); + return vlmax_avl_type_p (rinsn) && tail_agnostic_p (rinsn) + && alv_can_be_propagated_p (rinsn); } static machine_mode diff --git a/gcc/testsuite/gcc.target/riscv/rvv/autovec/pr112599-1.c b/gcc/testsuite/gcc.target/riscv/rvv/autovec/pr112599-1.c new file mode 100644 index 00000000000..911b6922b4a --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/pr112599-1.c @@ -0,0 +1,17 @@ +/* { dg-do compile } */ +/* { dg-options "-march=rv64gcv_zvfh_zfh_zvl1024b -mabi=lp64d -O3 --param=riscv-autovec-preference=fixed-vlmax" } */ + +#include "riscv_vector.h" + +typedef int64_t v1024b __attribute__ ((vector_size (128))); + +void foo (void *out, void *in, int64_t a, int64_t b) +{ + v1024b v = {a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a}; + v1024b v2 = {b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b}; + v1024b index = *(v1024b*)in; + v1024b v3 = __builtin_shuffle (v, v2, index); + __riscv_vse64_v_i64m1 (out, (vint64m1_t)v3, 10); +} + +/* { dg-final { scan-assembler {vsetivli\s+zero,\s*16} } } */