From patchwork Mon Dec 11 12:01:56 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: 176634 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp6991230vqy; Mon, 11 Dec 2023 04:02:39 -0800 (PST) X-Google-Smtp-Source: AGHT+IFi43cwYyCNkce5GDqk1Z/A2MpNyKIZr/v4TzJZOv26zj4BZtgoBnG5Jc0/ca1rqNzRLnIp X-Received: by 2002:a05:6871:64c9:b0:1fa:fc26:7f81 with SMTP id rk9-20020a05687164c900b001fafc267f81mr5151249oab.14.1702296159448; Mon, 11 Dec 2023 04:02:39 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1702296159; cv=pass; d=google.com; s=arc-20160816; b=iCaKWzVQWQiPy3piPwfJl8FlKJp5dDXw4MCgFsKce9K3j0piZSgcWO0bQCQcYwxF3X KEMj0pTL6BS2c80tn8vGj3QhbtdS8CdX2OvbYKC8bew0GwTRjgrNDIIwrtdX+4ORHJ01 aJIEhDROivf0Esl0t/vQk5hF1wO0E2doVpmEl+g91G2Qx0QFC+LSTTHj+FXcdbHEPvZY LBOAxDFHt04T7wBWGfI0mlUEiHYJJk7vYyPG07d1leKhJ8yqrPgRpwvuHz4Nugf33Reb uEVrkoXWd3RN9WwVHexYaRgADk/KfiRKnqy+j6HNANsAdY4Q0QauM8LKHoAYjDGf1AGB 1Yig== 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=Gh4GHrTI6/jBPM8Jqb5KVVDMMYdPxVr6p4mNlxyCJIo=; fh=12MRPJmZ1mgDpHqWoogMKqnaGRGM2b7lcuJroqfjJiw=; b=ar1PuUx5j7J50DunPKVz0Q2y4u5YalOhsfm46+Tmcx5nzAE3TROGOAn6F5Ph1d+y5c hrOdjNSbEWxcyxhZf0bPkNCXFwbENITj4zWXrMKBW7ZyTgxAl0DHlqaohh4q/UqPcqFh 1mhT3Cm/TRJk0C+dk3SHjSRzUGVRJHPFkXBfTCNGU8dgpV88e12EWEv6RdgUhZvIVDgC 3IlINRqKTwTkz5oGzbiQgDvkDWgATz9YB7I1jcj1NXlO6Zpnh2aeOXezbMH3MyA8ac0m /nD0YdL01OTUmXWa5UeXi/tihfm6dQeO5UGw7UzRkXeT3ZhecQbjnKEaSg7W5KUVnzEJ J2fg== 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 e16-20020ab078d0000000b007cb00ccef7csi73656uau.16.2023.12.11.04.02.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 04:02:39 -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 CEC483857BAE for ; Mon, 11 Dec 2023 12:02:37 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtpbgau1.qq.com (smtpbgau1.qq.com [54.206.16.166]) by sourceware.org (Postfix) with ESMTPS id 41A0D3858CD1 for ; Mon, 11 Dec 2023 12:02:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 41A0D3858CD1 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 41A0D3858CD1 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=54.206.16.166 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702296134; cv=none; b=Igclv0Bh/1LZG6m9i1fC4bBmQChvAkkHtLJ/MAc3z8noXSL8PqyTYrzs41d+mhx+R9k95EFIRZ2N+PPx+Jp8rZ2s/E+Mrl3eb0c84Avuxn0kUtIVmzcQd6ryvycuJPJhTdhKu9D93bSyzeRreAvOYCNeuQ57oV50u477KKhaPiQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702296134; c=relaxed/simple; bh=0ZDR/ufnbtpa5yniMMsTBo9HuTBl0Hj2taVPPC1KzYA=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=Wzgr5a4v0fSr+YoHwoqEy6h/FDjyY+R1BGF7P7Kx/+4834Vxm2zfK7a56J/dGGnKp1QvUXsAhtwPOg+biYn+ey/U6cgg+05OEzfAF7+39Plew9VDofcFmvP1l6WZuMNVofSRBdr2KT3qpaFpMVBpRPYnn8OH3HAeBBOzwrte/3k= ARC-Authentication-Results: i=1; server2.sourceware.org X-QQ-mid: bizesmtp88t1702296123t79ql6zv Received: from rios-cad122.hadoop.rioslab.org ( [58.60.1.26]) by bizesmtp.qq.com (ESMTP) with id ; Mon, 11 Dec 2023 20:02:02 +0800 (CST) X-QQ-SSF: 01400000000000G0V000000A0000000 X-QQ-FEAT: zT6n3Y95oi37LIZZdx1DJ8sj9Q2IEwbrOAbNIZRMxPeE9bd7nZ64SJbjVH4Dg yVn22VlwVN1ePo3bTE68OPLPJ/4spgdvf4RLDFpU9CbEI+d2yUegM1uctqNYRTETduIP9Zb EbvigTxuqd9Jcb2eX/gAhnb8paUZv8meMN0cqBJUxBvX08eAAbWqepEO8Htb4Z5GH5SyEFX PMGNgjzo60wro09Vf/yaUATN8mObxmEDkPssFCpZzYXNyqBPqVAUC4Q64e2cgiCk64ID/fv WEU5cNt7rpUKeU55GrKFDQQa6TtRX1UVMSXi/g/3wRC/sjCPN/YlyOUhSc/F+PlsMx6Emo9 zetO5O2kImldgvbbr8MipbNpzYy5GleIylQtPwpvntu8X3vH4dtFy7qKXz6YmknVcbyrWmw WXEs++9i2no= X-QQ-GoodBg: 2 X-BIZMAIL-ID: 10369054247036546050 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: Robostify shuffle index used by vrgather and fix regression Date: Mon, 11 Dec 2023 20:01:56 +0800 Message-Id: <20231211120156.1720292-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_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: 1784986897992021505 X-GMAIL-MSGID: 1784986897992021505 Notice there are some regression FAILs: FAIL: gcc.target/riscv/rvv/autovec/pr110950.c -O3 -ftree-vectorize scan-assembler-times vslide1up\\.vx 1 FAIL: gcc.target/riscv/rvv/autovec/vls-vlmax/perm-4.c -std=c99 -O3 -ftree-vectorize --param riscv-autovec-preference=fixed-vlmax scan-assembler-times vrgather\\.vv\\tv[0-9]+,\\s*v[0-9]+,\\s*v[0-9]+ 19 FAIL: gcc.target/riscv/rvv/autovec/vls-vlmax/perm-4.c -std=c99 -O3 -ftree-vectorize --param riscv-autovec-preference=fixed-vlmax scan-assembler-times vrgatherei16\\.vv\\tv[0-9]+,\\s*v[0-9]+,\\s*v[0-9]+ 12 FAIL: gcc.target/riscv/rvv/autovec/vls/perm-4.c -O3 -ftree-vectorize --param riscv-autovec-preference=scalable scan-assembler-times vrgather\\.vv\\tv[0-9]+,\\s*v[0-9]+,\\s*v[0-9]+ 19 FAIL: gcc.target/riscv/rvv/autovec/vls/perm-4.c -O3 -ftree-vectorize --param riscv-autovec-preference=scalable scan-assembler-times vrgatherei16\\.vv\\tv[0-9]+,\\s*v[0-9]+,\\s*v[0-9]+ 12 pr110950 is not a regression, adapt testcase is enough. The rest FAILs which is caused by this patch: https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=d9dd06ad51b7479f09acb88adf404664a1e18b2a need to be recovered back. Robostify the gather index to fixe those FAILs. gcc/ChangeLog: * config/riscv/riscv-v.cc (get_gather_index_mode): New function. (shuffle_series_patterns): Robostify shuffle index. (shuffle_generic_patterns): Ditto. gcc/testsuite/ChangeLog: * gcc.target/riscv/rvv/autovec/pr110950.c: Adapt test. --- gcc/config/riscv/riscv-v.cc | 80 +++++++++++-------- .../gcc.target/riscv/rvv/autovec/pr110950.c | 2 +- 2 files changed, 49 insertions(+), 33 deletions(-) diff --git a/gcc/config/riscv/riscv-v.cc b/gcc/config/riscv/riscv-v.cc index 484c690c3db..944b37b5df7 100644 --- a/gcc/config/riscv/riscv-v.cc +++ b/gcc/config/riscv/riscv-v.cc @@ -2923,6 +2923,39 @@ struct expand_vec_perm_d bool testing_p; }; +/* Return the appropriate index mode for gather instructions. */ +opt_machine_mode +get_gather_index_mode (struct expand_vec_perm_d *d) +{ + machine_mode sel_mode = related_int_vector_mode (d->vmode).require (); + poly_uint64 nunits = GET_MODE_NUNITS (d->vmode); + + if (GET_MODE_INNER (d->vmode) == QImode) + { + if (nunits.is_constant ()) + { + /* If indice is LMUL8 CONST_VECTOR and any element value + exceed the range of 0 ~ 255, Forbid such permutation + since we need vector HI mode to hold such indice and + we don't have it. */ + if (!d->perm.all_in_range_p (0, 255) + && !get_vector_mode (HImode, nunits).exists (&sel_mode)) + return opt_machine_mode (); + } + else + { + /* Permuting two SEW8 variable-length vectors need vrgatherei16.vv. + Otherwise, it could overflow the index range. */ + if (!get_vector_mode (HImode, nunits).exists (&sel_mode)) + return opt_machine_mode (); + } + } + else if (riscv_get_v_regno_alignment (sel_mode) > 1 + && GET_MODE_INNER (sel_mode) != HImode) + sel_mode = get_vector_mode (HImode, nunits).require (); + return sel_mode; +} + /* Recognize the patterns that we can use merge operation to shuffle the vectors. The value of Each element (index i) in selector can only be either i or nunits + i. We will check the pattern is actually monotonic. @@ -3428,12 +3461,10 @@ shuffle_series_patterns (struct expand_vec_perm_d *d) if (!have_series) return false; - /* Get a vector int-mode to be used for the permute selector. */ - machine_mode sel_mode = related_int_vector_mode (d->vmode).require (); - insn_code icode = optab_handler (vec_shl_insert_optab, sel_mode); - - /* We need to be able to insert an element and shift the vector. */ - if (need_insert && icode == CODE_FOR_nothing) + /* Disable shuffle if we can't find an appropriate integer index mode for + gather. */ + machine_mode sel_mode; + if (!get_gather_index_mode (d).exists (&sel_mode)) return false; /* Success! */ @@ -3448,7 +3479,12 @@ shuffle_series_patterns (struct expand_vec_perm_d *d) /* Insert the remaining element if necessary. */ if (need_insert) - emit_insn (GEN_FCN (icode) (series, series, gen_int_mode (el1, eltmode))); + { + insn_code icode = code_for_pred_slide (UNSPEC_VSLIDE1UP, sel_mode); + rtx ops[] + = {series, series, gen_int_mode (el1, GET_MODE_INNER (sel_mode))}; + emit_vlmax_insn (icode, BINARY_OP, ops); + } emit_vlmax_gather_insn (d->target, d->op0, series); @@ -3460,36 +3496,16 @@ shuffle_series_patterns (struct expand_vec_perm_d *d) static bool shuffle_generic_patterns (struct expand_vec_perm_d *d) { - machine_mode sel_mode = related_int_vector_mode (d->vmode).require (); - poly_uint64 nunits = GET_MODE_NUNITS (d->vmode); + machine_mode sel_mode; /* We don't enable SLP for non-power of 2 NPATTERNS. */ if (!pow2p_hwi (d->perm.encoding().npatterns ())) return false; - if (GET_MODE_INNER (d->vmode) == QImode) - { - if (nunits.is_constant ()) - { - /* If indice is LMUL8 CONST_VECTOR and any element value - exceed the range of 0 ~ 255, Forbid such permutation - since we need vector HI mode to hold such indice and - we don't have it. */ - if (!d->perm.all_in_range_p (0, 255) - && !get_vector_mode (HImode, nunits).exists (&sel_mode)) - return false; - } - else - { - /* Permuting two SEW8 variable-length vectors need vrgatherei16.vv. - Otherwise, it could overflow the index range. */ - if (!get_vector_mode (HImode, nunits).exists (&sel_mode)) - return false; - } - } - else if (riscv_get_v_regno_alignment (sel_mode) > 1 - && GET_MODE_INNER (sel_mode) != HImode) - sel_mode = get_vector_mode (HImode, nunits).require (); + /* Disable shuffle if we can't find an appropriate integer index mode for + gather. */ + if (!get_gather_index_mode (d).exists (&sel_mode)) + return false; /* Success! */ if (d->testing_p) diff --git a/gcc/testsuite/gcc.target/riscv/rvv/autovec/pr110950.c b/gcc/testsuite/gcc.target/riscv/rvv/autovec/pr110950.c index b927f1ea92a..17dd4397341 100644 --- a/gcc/testsuite/gcc.target/riscv/rvv/autovec/pr110950.c +++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/pr110950.c @@ -9,4 +9,4 @@ void b() { c[a] = d[-a]; } -/* { dg-final { scan-assembler-times {vslide1up\.vx} 1 } } */ +/* { dg-final { scan-assembler-times {vrgather} 1 } } */