From patchwork Wed Jun 14 09:00:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Li, Pan2 via Gcc-patches" X-Patchwork-Id: 107819 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1095873vqr; Wed, 14 Jun 2023 02:01:38 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5uklPiOoKX6E3MS3q1tsilkOBvd8iA4aykEphhD3GaC5WV5TsyyzJMCqSVgBRgiDFyfTLK X-Received: by 2002:a17:906:ef07:b0:96f:678:d2fc with SMTP id f7-20020a170906ef0700b0096f0678d2fcmr14238998ejs.22.1686733298503; Wed, 14 Jun 2023 02:01:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686733298; cv=none; d=google.com; s=arc-20160816; b=DZ91rPUNGfATbwyklS3gjkVyFpfrZ+sydl4rFIKueN+cTRY+VrFbVYSfR+VvBNcRhR zeTd4HuOdcX3oE/XjyLQU99o+oB1T7HGbfX4mmzJBhStxmTpWkjAWl7c5SyWVVCyn485 O+vGUsSjR/7pcrYNV8N4d2i+mf+3tlAzLu3QGTOOaWm1jHKpDaFaIBQCnj0ZCqZnfced 73QvKQfbF0boMp5aWOtIlyvZaelotfMyIcfzyYeOklOdje3uGwYnaASY8DJKuZ0nYfjU DgBoyPn7ATdbS6NAb4J0dPDSDBz8jowskRgjq07WZp4gyTw7V0mZWvAXDUEjofuvTajq gvZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=WgD1DC95+Qe6InJ8kK8NAs5sJ9z0c35EsJxpyadIsUQ=; b=YgmaJhreNdVB6p93TF+Hd9ph4fBV0J4RaNw/+QcePVHc2Ev4HVYQ7mBnowcYVb2IxO 8AgOV7ZooVo+ihbU7EehqpoMy0YcvxpyBZI6YdBm2Nh2nWBDkLy13ciM2Pgc9Ayx3Kj7 HLbKkMXORamhAb+wPwuGWgiEGwFexq1N0+G9FDXovGpH7iQ3mbReZ31aIKFmuJhnq9dW IFojGfe+gnjMvcPqIZaPoffjeePqG7Q9wO7hk342AGz+PwyJemePOI7hsCDx4qNvhssQ 1OnB5o6EdH32Zy9RNIuwvT/wTB+eK7vkJGuNNdxJx0QVcaz7N18KgCLEpLvESBdDN8hk A0TA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=nXrl9eaL; 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"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id kt27-20020a170906aadb00b00982855ce82csi60150ejb.401.2023.06.14.02.01.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Jun 2023 02:01:38 -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; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=nXrl9eaL; 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"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2C4943858289 for ; Wed, 14 Jun 2023 09:01:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2C4943858289 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1686733297; bh=WgD1DC95+Qe6InJ8kK8NAs5sJ9z0c35EsJxpyadIsUQ=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=nXrl9eaLi/JU53k0sVmenndXegfjUpvtE38E2lRscPyG6q85PKn/ecpis8SidBwBC MD0hcdI5SASHhEjwksYqLorRZa5o9oql1fFMMKnn2m+mKp60Gg/2rfuS1I5hK9DHRj g6+3pus6BBWVLPa74Sl8t2Nrw6XYRJWVGYovHKKg= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by sourceware.org (Postfix) with ESMTPS id CCCB83858414 for ; Wed, 14 Jun 2023 09:00:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CCCB83858414 X-IronPort-AV: E=McAfee;i="6600,9927,10740"; a="343258838" X-IronPort-AV: E=Sophos;i="6.00,242,1681196400"; d="scan'208";a="343258838" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Jun 2023 02:00:39 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10740"; a="1042117978" X-IronPort-AV: E=Sophos;i="6.00,242,1681196400"; d="scan'208";a="1042117978" Received: from shvmail03.sh.intel.com ([10.239.245.20]) by fmsmga005.fm.intel.com with ESMTP; 14 Jun 2023 02:00:37 -0700 Received: from pli-ubuntu.sh.intel.com (pli-ubuntu.sh.intel.com [10.239.159.47]) by shvmail03.sh.intel.com (Postfix) with ESMTP id B75D21005682; Wed, 14 Jun 2023 17:00:36 +0800 (CST) To: gcc-patches@gcc.gnu.org Cc: juzhe.zhong@rivai.ai, rdapp.gcc@gmail.com, jeffreyalaw@gmail.com, pan2.li@intel.com, yanzhang.wang@intel.com, kito.cheng@gmail.com Subject: [PATCH v3] RISC-V: Bugfix for vec_init repeating auto vectorization in RV32 Date: Wed, 14 Jun 2023 17:00:35 +0800 Message-Id: <20230614090035.5470-1-pan2.li@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230614005859.960040-1-pan2.li@intel.com> References: <20230614005859.960040-1-pan2.li@intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-10.9 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_NUMSUBJECT, KAM_SHORT, SPF_HELO_NONE, SPF_NONE, 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.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Pan Li via Gcc-patches From: "Li, Pan2 via Gcc-patches" Reply-To: pan2.li@intel.com Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1768637741862842239?= X-GMAIL-MSGID: =?utf-8?q?1768668055360161232?= From: Pan Li When constructing a vector mask from individual elements we wrongly assumed that we can broadcast BITS_PER_WORD (i.e. XLEN). The maximum is actually the vector element length (i.e. ELEN). This patch fixes this. After this patch, below failures on RV32 will be fixed. FAIL: gcc.target/riscv/rvv/autovec/partial/multiple_rgroup_run-2.c execution test FAIL: gcc.target/riscv/rvv/autovec/partial/multiple_rgroup_run-2.c execution test FAIL: gcc.target/riscv/rvv/autovec/partial/multiple_rgroup_run-2.c execution test FAIL: gcc.target/riscv/rvv/autovec/partial/multiple_rgroup_run-2.c execution test FAIL: gcc.target/riscv/rvv/autovec/vls-vlmax/repeat_run-3.c -std=c99 -O3 -ftree-vectorize --param riscv-autovec-preference=fixed-vlmax execution test Signed-off-by: Pan Li gcc/ChangeLog: * config/riscv/riscv-v.cc (rvv_builder::get_merge_scalar_mask): Take elen instead of scalar BITS_PER_WORD. (expand_vector_init_merge_repeating_sequence): Use inner_bits_size instead of scaler BITS_PER_WORD. Signed-off-by: Pan Li --- gcc/config/riscv/riscv-v.cc | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/gcc/config/riscv/riscv-v.cc b/gcc/config/riscv/riscv-v.cc index e07d5c2901a..01f647bc0bd 100644 --- a/gcc/config/riscv/riscv-v.cc +++ b/gcc/config/riscv/riscv-v.cc @@ -399,10 +399,17 @@ rvv_builder::get_merge_scalar_mask (unsigned int index_in_pattern) const { unsigned HOST_WIDE_INT mask = 0; unsigned HOST_WIDE_INT base_mask = (1ULL << index_in_pattern); + /* Here we construct a mask pattern that will later be broadcast + to a vector register. The maximum broadcast size for vmv.v.x/vmv.s.x + is determined by the length of a vector element (ELEN) and not by + XLEN so make sure we do not exceed it. One example is -march=zve32* + which mandates ELEN == 32 but can be combined with -march=rv64 + with XLEN == 64. */ + unsigned int elen = TARGET_VECTOR_ELEN_64 ? 64 : 32; - gcc_assert (BITS_PER_WORD % npatterns () == 0); + gcc_assert (elen % npatterns () == 0); - int limit = BITS_PER_WORD / npatterns (); + int limit = elen / npatterns (); for (int i = 0; i < limit; i++) mask |= base_mask << (i * npatterns ()); @@ -1928,7 +1935,7 @@ expand_vector_init_merge_repeating_sequence (rtx target, rtx mask = gen_reg_rtx (mask_mode); rtx dup = gen_reg_rtx (dup_mode); - if (full_nelts <= BITS_PER_WORD) /* vmv.s.x. */ + if (full_nelts <= builder.inner_bits_size ()) /* vmv.s.x. */ { rtx ops[] = {dup, gen_scalar_move_mask (dup_mask_mode), RVV_VUNDEF (dup_mode), merge_mask}; @@ -1938,7 +1945,8 @@ expand_vector_init_merge_repeating_sequence (rtx target, else /* vmv.v.x. */ { rtx ops[] = {dup, force_reg (GET_MODE_INNER (dup_mode), merge_mask)}; - rtx vl = gen_int_mode (CEIL (full_nelts, BITS_PER_WORD), Pmode); + rtx vl = gen_int_mode (CEIL (full_nelts, builder.inner_bits_size ()), + Pmode); emit_nonvlmax_integer_move_insn (code_for_pred_broadcast (dup_mode), ops, vl); }