From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by sourceware.org (Postfix) with ESMTPS id 057CA3858D20 for ; Mon, 26 Jun 2023 07:51:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 057CA3858D20 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 32BFC218B2; Mon, 26 Jun 2023 07:51:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1687765871; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=O8cWgopU7Y7+t3U5e0lZ4m2adFYFYToiGYsOTao2Cgg=; b=J89/DGBMJRPZ1zBZ05HYPm4peAR5+OoY9Bjq7dIW4mqZlyzzflSwHop+f+sWbOBYpCqn4a PfxJkPg5i+hLeZxNTeCHHi2scu4t0AyUnX8Vl0n9KNMzbb6mkk9y5fbUOIakRfHDkp9tIl AD/boXX3ZiORJRXnsBC2eWOAfOlQVSw= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1687765871; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=O8cWgopU7Y7+t3U5e0lZ4m2adFYFYToiGYsOTao2Cgg=; b=PMiZQIKeBrQBba2BhPEEH/qpXk0vRn3paAghsC5q/Fs5Y7CleJVGzolWDIAX9L1ATL8DHa SIxDQvQBaM6VpsBw== Received: from wotan.suse.de (wotan.suse.de [10.160.0.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id 220C12C141; Mon, 26 Jun 2023 07:51:11 +0000 (UTC) Date: Mon, 26 Jun 2023 07:51:11 +0000 (UTC) From: Richard Biener To: Ju-Zhe Zhong cc: gcc-patches@gcc.gnu.org, richard.sandiford@arm.com, jeffreyalaw@gmail.com Subject: Re: [PATCH] GIMPLE_FOLD: Fix gimple fold for LEN_MASK_{LOAD,STORE} In-Reply-To: <20230626014940.36902-1-juzhe.zhong@rivai.ai> Message-ID: References: <20230626014940.36902-1-juzhe.zhong@rivai.ai> User-Agent: Alpine 2.22 (LSU 394 2020-01-19) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-10.9 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,SPF_HELO_NONE,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: On Mon, 26 Jun 2023, juzhe.zhong@rivai.ai wrote: > 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 ? Err, but then the IFN_LEN_LOAD case is wrong as well - we surely do not want differing behavior here. So please fix them both? > 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" } } */ > -- Richard Biener SUSE Software Solutions Germany GmbH, Frankenstrasse 146, 90461 Nuernberg, Germany; GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman; HRB 36809 (AG Nuernberg)