From patchwork Thu Nov 23 11:04:09 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: 168873 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce62:0:b0:403:3b70:6f57 with SMTP id o2csp362238vqx; Thu, 23 Nov 2023 03:04:42 -0800 (PST) X-Google-Smtp-Source: AGHT+IHBT1I6t3bE3w/wF9hwOubOXoAgLc2Nt1ZQ5fZP3A2LTMLvXC1lqsvoDB4VPNOYyol8NSYB X-Received: by 2002:ad4:5c89:0:b0:656:3407:f45a with SMTP id o9-20020ad45c89000000b006563407f45amr7436755qvh.43.1700737482042; Thu, 23 Nov 2023 03:04:42 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1700737482; cv=pass; d=google.com; s=arc-20160816; b=TCrp4g6DbURjNZq2lW302HRJ1aXB0jBy+kCWBBDl92vSbs+qLF2q6dgB3p414uscXZ YXNjU8eCauCnEuKr4VHxaxElyDbltsnNPBAS3QKZWrQ9yEml80BZwj8gkk7JLfIf4EyD TB/swmw0kNM9oAJieyr3bsvaOiOczLIWuM7Of9acSGl2O3zywrgNT5uU5KQ8SsmAMsdl AMBYr66fmcOyTo9Hq/4D/IBHny+x9NeefdfIybPidkUTAso660Qvd8KvQOellSFPq0y4 ijyd6yYgCy1GWFH+5zhuJQHMHpiDQ3aTchY4t7vZ/JUFuqaKfmKNHqLftCjfxHL3ULZ+ ZViA== 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=pzeXanHYgyeKsw7mLLM7V+x21ZPdLB1gvvOEl+08res=; fh=12MRPJmZ1mgDpHqWoogMKqnaGRGM2b7lcuJroqfjJiw=; b=hwU2bGfpCc4dZuxunVnP2SrFA6KmqbKymvSvwHPCjx9FUOgN6Pd9EvVh0wHMqM4xU7 KRf5mCZii7jqtWKphwGDV6+rxI10uLetLzmIqJjnPc6TnnDz60iO6sB05zTsEKDbVZKk 7K0VRdvnCmfd4HO/1brGWBWWV6uZnBG1K0hetgERI5Gf/lc4BrC/GamYQwrNTE5Kofvy ojeje/cMbwF/iFR7uk3nfPlZuLXy5GMtFFPDquqyRJ7tcUXAs5oSPm6XDhdpfRd16v4D X7M+UWqlj33xJTcI/3B5YTYduke5Ba091PWmfm4d7EJnYH338+c4CujiR44f2MrmyQPt mVHw== 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 g9-20020ad45109000000b0067a048e8bb4si927781qvp.546.2023.11.23.03.04.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Nov 2023 03:04:42 -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 CC2D6385734F for ; Thu, 23 Nov 2023 11:04:41 +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 429233858C2D for ; Thu, 23 Nov 2023 11:04:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 429233858C2D 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 429233858C2D 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=1700737459; cv=none; b=ep8poD2FcTS/MF4FJCOgz0QKIlGzgSKFCiwVM+KbY/GpSYgWTxob5yJTPoP2AOSRhNHgDR3rMJQMcmS9tsuQOCXJoB3MAMDtjHbFaXjxR6gfFmWzdGod+2vvldUM3geFqWuvVuQ3PLUTDMiG4W0gtvg1qKUpcSZ83lkw6vs5+rs= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700737459; c=relaxed/simple; bh=kNnGvvqzsfNrRKGtInAvYWAbFC6M/f/VspCx44d/7gg=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=UKH+Be5wH5A0q4VWOqB4FJ026Xugb0+L50ySbVk1CBGBCqiiKHbv6nzOVb9mCoj3IrscufVV053CmNGlJrt/htX/IDRrf2w6thlTXRiVQFUq9CulzRcLd3iYhfBDAD1fTdjerNRFCmGzJ9NQ4kTMbIjvXq4myjbC5/1h+0oqnKc= ARC-Authentication-Results: i=1; server2.sourceware.org X-QQ-mid: bizesmtp91t1700737452to0321bh Received: from rios-cad122.hadoop.rioslab.org ( [58.60.1.26]) by bizesmtp.qq.com (ESMTP) with id ; Thu, 23 Nov 2023 19:04:10 +0800 (CST) X-QQ-SSF: 01400000000000G0V000000A0000000 X-QQ-FEAT: UQSQY+HvfIEILoRRwWceeZD0hdQR1bMauNcb7EAdmX/RJQlEj5ZtMsNTuL1pI 36YP+4sn1XfvCd4Bmbmz3AxsEZTXiykILAEGEnv3Yq0vPVVD0WhfTd/WMrimEUhZphkLniy jV1BtkOqNkgsj8p2dBpVAyi05LUjfenSs46EgTVMHCg3Tim0Wq/DA7LuuhL4aJAUerLgbEX LIaJzJUw/UiG+Mze1w0eEEfQbnv4T49/zGe3h/o4kuuAHvg5v39w9U6lmwlrRKYnsisWV7S //zsPICYyXFyWJqWXZxNclwoJLhHMvBNulQ/1WmRL+8r5ML015uz8PCBgYgttVn1FJtUXI/ 5gCW4XEKA1Pd23x9tMthe9/jQIOktsRTgOwO5rEGGRFgBR3A67Eew4LxqndbzZizPE+Ya64 L/GBLdXf+IHdSZId5kC9vw== X-QQ-GoodBg: 2 X-BIZMAIL-ID: 9108319982510506209 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: Disable AVL propagation of vrgather instruction Date: Thu, 23 Nov 2023 19:04:09 +0800 Message-Id: <20231123110409.3914102-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_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: 1783352505861045313 X-GMAIL-MSGID: 1783352505861045313 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 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} } } */