From patchwork Tue Jun 27 12:01:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prathamesh Kulkarni X-Patchwork-Id: 113381 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp8138803vqr; Tue, 27 Jun 2023 05:02:39 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7/WY1sKDlqTlpCaz549iA8S0S7nhwkR8aztrz+gguf042FiKKty7QnQY2qiJCrrVAA1DNb X-Received: by 2002:a17:907:8688:b0:973:e349:43c8 with SMTP id qa8-20020a170907868800b00973e34943c8mr28330228ejc.69.1687867359583; Tue, 27 Jun 2023 05:02:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687867359; cv=none; d=google.com; s=arc-20160816; b=euFeTz+s/QMmqe4ndGDFwxAdwKeVN2Jkl53qwSPha9jOExn2Jgxr3PDPJvs77+hSE2 Kn4YWNN3iyc78QTA8ELwcFhnUvb2I4oa3EBiN5GFahOBcCjOlk4ng604pkiaP6MDKO9y tmoWeZO+PH7Ehl95uUzz/oWHT81UfejEsG1voUCJ5fpV+tVb31N+W/F+0j00KiBHBc4H Nz1Jawr1n0+wrQITQZnpxo9Zv0YyXcZaEJ3HUFqPThowGTMAmEzHFjEDsgUMIObNOiYh rvQ1aUjFGzTpvakA6xEn9SAqCK8riy7klitjy8ZI+7X1WW2MVRRQtHQk6WnYTo8FkoCO 8stQ== 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:to:subject :message-id:date:mime-version:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=Oonkb5+b2FjRI9z1RFpnFXzslZASWE+3GwvA2Pv9Juc=; fh=dlG5TvQASCJGDJgO85bMuWcJbCtoD20NfiHcjOBIqVM=; b=SZdHKmdoByPEuS4Xu3u2iLDAms9WLfQLAhENqhigGA4DL1OQ5YW60f9TTAvqn5tGec z9HkgskE2P7yeO1iMsnsUVFPF6dzUB98jNAyKlE2XVK+QSGRl0phEwHossuAXcsn/Cig 8x+S5vcP+jxEKDhRwLxSRvusflayo0vIwqjFGitKKppBQ+3T0FISPyKzc1xyqP0DIAIS pWZOzLtRY5G7/YC5j2hXr4ueEgglbcwZkhcX52FrHPd+S27DI5ud/t+i71qE3RwgdOy8 KNKsV4i1i8pFqCcXG331EGaV2PHK244YXCzPm0arSFx10lAH0UCB9c6nDyyF8vzAPzpv IgcQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=DhVXf6nG; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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 (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id b11-20020a170906d10b00b00989004c1498si3954656ejz.589.2023.06.27.05.02.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Jun 2023 05:02:39 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=DhVXf6nG; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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 72887385841C for ; Tue, 27 Jun 2023 12:02:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 72887385841C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1687867358; bh=Oonkb5+b2FjRI9z1RFpnFXzslZASWE+3GwvA2Pv9Juc=; h=Date:Subject:To:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=DhVXf6nGVwzMqZijAj2z/RfOh8ZD6xorePbVaXLhUoAqjv/13hkASq+mVBiwMn8mj l0GqhKX7k5IV3jUN3gkfF75gOCxK+rSYs2uwoL8UH0NRz+JDkKRFojwI8enyCzc1xl MCOFP4Y0vneXG9Fzr4nfCfHgHrVpoIPi9m71NKMU= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by sourceware.org (Postfix) with ESMTPS id 44D2B3858D28 for ; Tue, 27 Jun 2023 12:01:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 44D2B3858D28 Received: by mail-wm1-x32c.google.com with SMTP id 5b1f17b1804b1-3fa7512e599so54477975e9.2 for ; Tue, 27 Jun 2023 05:01:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687867314; x=1690459314; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=Oonkb5+b2FjRI9z1RFpnFXzslZASWE+3GwvA2Pv9Juc=; b=kY2R4hBqsEwwW5PlLUajHQP3+F+BysgDsmY0MC1WUEqUfJBZLH245s31w3ZJZHCLCW Pu3NXl+H9ZrDLwfQtzbgPVy/rJ97KUUI/yBThfl/OeiF0ZpPCJY05C+hgPqr5/9Rh9Bw zjewirT/5nwqfEs06yF7IHSX2O5pFho54osq5/kTiwsddp0s/l2nb9Ep1EvnvVrYA8ju qRqQfBQM2C4JIrQgJrGKTvYH4qBCQqydhw7S4dnhyFvY6pA+I/FH04yPrcu4cPfnXmns mob0aCQRtvFmyRDflqwQyiWZi7HgmmMu4Fqq7XJ1doyiTPIioZS/mHAgGG8v9JavrlzS +IJw== X-Gm-Message-State: AC+VfDxDeNzuFVMCA7nfJcIBBFEJ+kNvjkxJgiD2qSG0DriKSHoTbBGJ eELy6YA7JB1J7z7RYoLmkeGfrzwXQm2t1xntaizWmA== X-Received: by 2002:a05:6000:181:b0:30f:d218:584a with SMTP id p1-20020a056000018100b0030fd218584amr28171968wrx.23.1687867313760; Tue, 27 Jun 2023 05:01:53 -0700 (PDT) MIME-Version: 1.0 Date: Tue, 27 Jun 2023 17:31:18 +0530 Message-ID: Subject: [SVE] Fold svdupq to VEC_PERM_EXPR if elements are not constant To: Richard Sandiford , gcc Patches X-Spam-Status: No, score=-9.8 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 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: Prathamesh Kulkarni via Gcc-patches From: Prathamesh Kulkarni Reply-To: Prathamesh Kulkarni 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?1769857204116708096?= X-GMAIL-MSGID: =?utf-8?q?1769857204116708096?= 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. 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 } } */