From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by sourceware.org (Postfix) with ESMTPS id CFF683858C33 for ; Tue, 27 Jun 2023 19:03:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CFF683858C33 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-3fa8cd4a113so28738655e9.2 for ; Tue, 27 Jun 2023 12:03:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1687892618; x=1690484618; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :from:to:cc:subject:date:message-id:reply-to; bh=SgSQ6S4GEiHAxi/6MPRVIx2aARPKtxFaYXLgvaAJ1j8=; b=L/YAvYQ4748YpgypxhqCj6A8btdyUKln1op0qFetJ5fq86ayHCb02NxG7Wx+LI5YYR 9FBUj1o93KlpQm3+ZZjVg8+pPkp0+la1wupEulc49EWoZdysvJHkPQi3IMlhEhnKpdia OoYT+mcZVx8OlzUEhQRDywUq1M5wA9gF+bbjA4YIxeyEkLAIrgWC+0GlTGmDYyMP2UtM 9rHSRRweKqKs3ti6K1RkNaSgTPY1JqHro8T3j8ZAV4towRO9dgsw/usih9OOGWjtHjkL +cB/ue/QuaEA3Le5Alzc4mIJbFBsuZfL3pxaHY5WfyhmKlQ5uSPcSHqMjtgGadMm7DID WEZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687892618; x=1690484618; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=SgSQ6S4GEiHAxi/6MPRVIx2aARPKtxFaYXLgvaAJ1j8=; b=TMWE14BC+Zw3VqWan1tudhqL1zZ5w9WU/iM/jH+FN72VMNRXC4At6Lo+bLQpthY/3o KkaiOD6jPNE5cuOZh5QzmuR5RGbswNlUVCuQnUvWvbqc4iH+Ds6Zu4eARe4wbpjLoLq9 5AuPsJd69G/sY9SohvKOEiMlChmOasM2KvMvRyfWL9Xi6M+qOO5ZfeKilwMebozWVfTP hBmiJu8N0SE2j89mM6NQoLASRl/d9AuWe8tMKPR3bxVwXZ0unAoivd4EgrjCIgIT7yHt ot3E/r0ltn6+1DDUYyjlPDxlV/ScGglRoTqVoQF72DNsk6T94VDr7ZnPUIlmebTSk5fQ Kk7A== X-Gm-Message-State: AC+VfDwEpB1pmQEhlEqeNhOt4idFq7iadEL7GFuQ55f6yKsXM7Vko8Pu xQSDHYn5AAaQ3xhEq1u7E9O5tisrrz4+iIyWn/Y/Jw== X-Google-Smtp-Source: ACHHUZ5JRja/HzQBqx4+kBxS+Xv9ASiFTfyoi6XMkKBiJTF1VVy39ZEPm2CVyv7eJ7ZeQ6CLL/SqD4G+dCDykwY+Ql8= X-Received: by 2002:a05:600c:2945:b0:3f9:b31d:5689 with SMTP id n5-20020a05600c294500b003f9b31d5689mr17845033wmd.36.1687892618501; Tue, 27 Jun 2023 12:03:38 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Prathamesh Kulkarni Date: Wed, 28 Jun 2023 00:33:03 +0530 Message-ID: Subject: Re: [SVE] Fold svdupq to VEC_PERM_EXPR if elements are not constant To: Prathamesh Kulkarni , gcc Patches , richard.sandiford@arm.com Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,RCVD_IN_DNSWL_NONE,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 Wed, 28 Jun 2023 at 00:05, Richard Sandiford wrote: > > Prathamesh Kulkarni writes: > > Hi Richard, > > Sorry I forgot to commit this patch, which you had approved in: > > https://gcc.gnu.org/pipermail/gcc-patches/2023-April/615308.html > > > > Just for context for the following test: > > svint32_t f_s32(int32x4_t x) > > { > > return svdupq_s32 (x[0], x[1], x[2], x[3]); > > } > > > > -O3 -mcpu=generic+sve generates following code after interleave+zip1 patch: > > f_s32: > > dup s31, v0.s[1] > > mov v30.8b, v0.8b > > ins v31.s[1], v0.s[3] > > ins v30.s[1], v0.s[2] > > zip1 v0.4s, v30.4s, v31.4s > > dup z0.q, z0.q[0] > > ret > > > > Code-gen with attached patch: > > f_s32: > > dup z0.q, z0.q[0] > > ret > > > > Bootstrapped+tested on aarch64-linux-gnu. > > OK to commit ? > > > > Thanks, > > Prathamesh > > > > [SVE] Fold svdupq to VEC_PERM_EXPR if elements are not constant. > > > > gcc/ChangeLog: > > * config/aarch64/aarch64-sve-builtins-base.cc > > (svdupq_impl::fold_nonconst_dupq): New method. > > (svdupq_impl::fold): Call fold_nonconst_dupq. > > > > gcc/testsuite/ChangeLog: > > * gcc.target/aarch64/sve/acle/general/dupq_11.c: New test. > > OK, thanks. Thanks, pushed to trunk in 231f6b56c77c50f337f2529b3ae51e2083ce461d Thanks, Prathamesh > > Richard > > > diff --git a/gcc/config/aarch64/aarch64-sve-builtins-base.cc b/gcc/config/aarch64/aarch64-sve-builtins-base.cc > > index 95b4cb8a943..9010ecca6da 100644 > > --- a/gcc/config/aarch64/aarch64-sve-builtins-base.cc > > +++ b/gcc/config/aarch64/aarch64-sve-builtins-base.cc > > @@ -817,6 +817,52 @@ public: > > > > class svdupq_impl : public quiet > > { > > +private: > > + gimple * > > + fold_nonconst_dupq (gimple_folder &f) const > > + { > > + /* Lower lhs = svdupq (arg0, arg1, ..., argN} into: > > + tmp = {arg0, arg1, ..., arg} > > + lhs = VEC_PERM_EXPR (tmp, tmp, {0, 1, 2, N-1, ...}) */ > > + > > + if (f.type_suffix (0).bool_p > > + || BYTES_BIG_ENDIAN) > > + return NULL; > > + > > + tree lhs = gimple_call_lhs (f.call); > > + tree lhs_type = TREE_TYPE (lhs); > > + tree elt_type = TREE_TYPE (lhs_type); > > + scalar_mode elt_mode = SCALAR_TYPE_MODE (elt_type); > > + machine_mode vq_mode = aarch64_vq_mode (elt_mode).require (); > > + tree vq_type = build_vector_type_for_mode (elt_type, vq_mode); > > + > > + unsigned nargs = gimple_call_num_args (f.call); > > + vec *v; > > + vec_alloc (v, nargs); > > + for (unsigned i = 0; i < nargs; i++) > > + CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, gimple_call_arg (f.call, i)); > > + tree vec = build_constructor (vq_type, v); > > + tree tmp = make_ssa_name_fn (cfun, vq_type, 0); > > + gimple *g = gimple_build_assign (tmp, vec); > > + > > + gimple_seq stmts = NULL; > > + gimple_seq_add_stmt_without_update (&stmts, g); > > + > > + poly_uint64 lhs_len = TYPE_VECTOR_SUBPARTS (lhs_type); > > + vec_perm_builder sel (lhs_len, nargs, 1); > > + for (unsigned i = 0; i < nargs; i++) > > + sel.quick_push (i); > > + > > + vec_perm_indices indices (sel, 1, nargs); > > + tree mask_type = build_vector_type (ssizetype, lhs_len); > > + tree mask = vec_perm_indices_to_tree (mask_type, indices); > > + > > + gimple *g2 = gimple_build_assign (lhs, VEC_PERM_EXPR, tmp, tmp, mask); > > + gimple_seq_add_stmt_without_update (&stmts, g2); > > + gsi_replace_with_seq (f.gsi, stmts, false); > > + return g2; > > + } > > + > > public: > > gimple * > > fold (gimple_folder &f) const override > > @@ -832,7 +878,7 @@ public: > > { > > tree elt = gimple_call_arg (f.call, i); > > if (!CONSTANT_CLASS_P (elt)) > > - return NULL; > > + return fold_nonconst_dupq (f); > > builder.quick_push (elt); > > for (unsigned int j = 1; j < factor; ++j) > > builder.quick_push (build_zero_cst (TREE_TYPE (vec_type))); > > diff --git a/gcc/testsuite/gcc.target/aarch64/sve/acle/general/dupq_11.c b/gcc/testsuite/gcc.target/aarch64/sve/acle/general/dupq_11.c > > new file mode 100644 > > index 00000000000..f19f8deb1e5 > > --- /dev/null > > +++ b/gcc/testsuite/gcc.target/aarch64/sve/acle/general/dupq_11.c > > @@ -0,0 +1,31 @@ > > +/* { dg-do compile } */ > > +/* { dg-options "-O3 -fdump-tree-optimized" } */ > > + > > +#include > > +#include > > + > > +svint8_t f_s8(int8x16_t x) > > +{ > > + return svdupq_s8 (x[0], x[1], x[2], x[3], x[4], x[5], x[6], x[7], > > + x[8], x[9], x[10], x[11], x[12], x[13], x[14], x[15]); > > +} > > + > > +svint16_t f_s16(int16x8_t x) > > +{ > > + return svdupq_s16 (x[0], x[1], x[2], x[3], x[4], x[5], x[6], x[7]); > > +} > > + > > +svint32_t f_s32(int32x4_t x) > > +{ > > + return svdupq_s32 (x[0], x[1], x[2], x[3]); > > +} > > + > > +svint64_t f_s64(int64x2_t x) > > +{ > > + return svdupq_s64 (x[0], x[1]); > > +} > > + > > +/* { dg-final { scan-tree-dump "VEC_PERM_EXPR" "optimized" } } */ > > +/* { dg-final { scan-tree-dump-not "svdupq" "optimized" } } */ > > + > > +/* { dg-final { scan-assembler-times {\tdup\tz[0-9]+\.q, z[0-9]+\.q\[0\]\n} 4 } } */