From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtpbg153.qq.com (smtpbg153.qq.com [13.245.218.24]) by sourceware.org (Postfix) with ESMTPS id C63EA3858D20 for ; Mon, 26 Jun 2023 01:49:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C63EA3858D20 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=rivai.ai Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=rivai.ai X-QQ-mid: bizesmtp73t1687744183tbi8la54 Received: from rios-cad5.localdomain ( [58.60.1.11]) by bizesmtp.qq.com (ESMTP) with id ; Mon, 26 Jun 2023 09:49:42 +0800 (CST) X-QQ-SSF: 01400000000000G0S000000A0000000 X-QQ-FEAT: zT6n3Y95oi32We5D7YvQ1E4erUO/ZQyYMsC9WD9UJdaqw/EjkLsiaZVhRWSfi Mu2IIOsl39O58noPbncikExCiyXbr9Yz5j9fZPWClhkiCFbROjvDcLuWBujh8A9UOFborSE vEa1A8BJAvM8YxXX6aFj8arBdPq8XrBLRdYekS4CUjK6WY33fg35klZEg2AGz7trFzFohi9 YaBoxUJSrgt/4JWyqk6H5qVXrvKA7F2s+CjQxUX7R1/KcN9xUE3mRs/SlvA+kz6mF3MDFj4 2K6VZMbze2D7lwkYBd0AzxF7+KeoEdBjHeW9WozfUtkDt1Es3BzLjK2saaSP9PzmnS024/b QSEgGDWHK+5UzNQj5K++AX2J0OF/F+SKvHWW8id218cYtJNv7vYlfz3CjBJ/g== X-QQ-GoodBg: 2 X-BIZMAIL-ID: 64045151480093613 From: juzhe.zhong@rivai.ai To: gcc-patches@gcc.gnu.org Cc: richard.sandiford@arm.com, rguenther@suse.de, jeffreyalaw@gmail.com, Ju-Zhe Zhong Subject: [PATCH] GIMPLE_FOLD: Fix gimple fold for LEN_MASK_{LOAD,STORE} Date: Mon, 26 Jun 2023 09:49:40 +0800 Message-Id: <20230626014940.36902-1-juzhe.zhong@rivai.ai> X-Mailer: git-send-email 2.36.3 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:rivai.ai:qybglogicsvrgz:qybglogicsvrgz7a-one-0 X-Spam-Status: No, score=-12.2 required=5.0 tests=BAYES_00,GIT_PATCH_0,KAM_DMARC_STATUS,KAM_SHORT,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 List-Id: From: Ju-Zhe Zhong Hi, previous I made a mistake on GIMPLE_FOLD of LEN_MASK_{LOAD,STORE}. We should fold LEN_MASK_{LOAD,STORE} (bias+len) == vf (nunits instead of bytesize) && mask = all trues mask into: MEM_REF [...]. This patch added testcase to test gimple fold of LEN_MASK_{LOAD,STORE}. Ok for trunk ? gcc/ChangeLog: * gimple-fold.cc (gimple_fold_partial_load_store_mem_ref): Fix LEN_MASK_{LOAD,STORE}. gcc/testsuite/ChangeLog: * gcc.target/riscv/rvv/autovec/partial/gimple_fold-1.c: New test. --- gcc/gimple-fold.cc | 16 ++++--- .../riscv/rvv/autovec/partial/gimple_fold-1.c | 43 +++++++++++++++++++ 2 files changed, 54 insertions(+), 5 deletions(-) create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/autovec/partial/gimple_fold-1.c diff --git a/gcc/gimple-fold.cc b/gcc/gimple-fold.cc index 3d46b76edeb..94e79c32218 100644 --- a/gcc/gimple-fold.cc +++ b/gcc/gimple-fold.cc @@ -5397,19 +5397,25 @@ gimple_fold_partial_load_store_mem_ref (gcall *call, tree vectype, bool mask_p) unsigned int nargs = gimple_call_num_args (call); tree bias = gimple_call_arg (call, nargs - 1); gcc_assert (TREE_CODE (bias) == INTEGER_CST); - if (maybe_ne (wi::to_poly_widest (basic_len) - wi::to_widest (bias), - GET_MODE_SIZE (TYPE_MODE (vectype)))) - return NULL_TREE; - /* For LEN_MASK_{LOAD,STORE}, we should also check whether - the mask is all ones mask. */ internal_fn ifn = gimple_call_internal_fn (call); if (ifn == IFN_LEN_MASK_LOAD || ifn == IFN_LEN_MASK_STORE) { + /* We fold LEN_MASK_{LOAD,STORE} into MEM_REF when (len + bias) == VF + and mask = all trues mask. */ + if (maybe_ne (wi::to_poly_widest (basic_len) + wi::to_widest (bias), + GET_MODE_NUNITS (TYPE_MODE (vectype)))) + return NULL_TREE; tree mask = gimple_call_arg (call, internal_fn_mask_index (ifn)); if (!integer_all_onesp (mask)) return NULL_TREE; } + else + { + if (maybe_ne (wi::to_poly_widest (basic_len) - wi::to_widest (bias), + GET_MODE_SIZE (TYPE_MODE (vectype)))) + return NULL_TREE; + } } unsigned HOST_WIDE_INT align = tree_to_uhwi (alias_align); diff --git a/gcc/testsuite/gcc.target/riscv/rvv/autovec/partial/gimple_fold-1.c b/gcc/testsuite/gcc.target/riscv/rvv/autovec/partial/gimple_fold-1.c new file mode 100644 index 00000000000..23407a2d3f4 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/partial/gimple_fold-1.c @@ -0,0 +1,43 @@ +/* { dg-do compile } */ +/* { dg-options "-march=rv32gcv -mabi=ilp32d --param riscv-autovec-preference=fixed-vlmax --param riscv-autovec-lmul=m8 -O3 -fdump-tree-optimized-details" } */ + +#include + +#define SZ 255 + +#define DEF(TYPE) void fn_##TYPE (TYPE *__restrict a); + +#define RUN(TYPE) \ + TYPE a##TYPE[SZ]; \ + for (int i = 0; i < SZ; i++) \ + { \ + a##TYPE[i] = 127; \ + } \ + fn_##TYPE (a##TYPE); + +#define RUN_ALL() \ + RUN (int8_t) \ + RUN (int16_t) \ + RUN (int32_t) \ + RUN (int64_t) \ + RUN (uint8_t) \ + RUN (uint16_t) \ + RUN (uint32_t) \ + RUN (uint64_t) + +DEF (int8_t) +DEF (int16_t) +DEF (int32_t) +DEF (int64_t) +DEF (uint8_t) +DEF (uint16_t) +DEF (uint32_t) +DEF (uint64_t) + +int +main () +{ + RUN_ALL () +} + +/* { dg-final { scan-tree-dump-times "\.LEN_MASK_STORE" 6 "optimized" } } */ -- 2.36.3