From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lj1-x230.google.com (mail-lj1-x230.google.com [IPv6:2a00:1450:4864:20::230]) by sourceware.org (Postfix) with ESMTPS id E6BCD3858D37 for ; Wed, 19 Apr 2023 12:33:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E6BCD3858D37 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-lj1-x230.google.com with SMTP id h2so2561842ljh.13 for ; Wed, 19 Apr 2023 05:33:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1681907589; x=1684499589; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=OMnxG+s7j4Bi6mdStqhu/V6gxIDfzNhtzBKirQZuj+c=; b=FSusWRXkm99npbtOkDFGY6VIajYDWp7gKOOY56+KSp6z56KzfKCNbBtL08TLGQXnQv wCbunsoeJJI0uyvMTmzx8bjwIqp5YzoPYckbUCZ/kIvZPU7PjvHtjxvYympA3XQCBzGH 1+46f0bxmsUlouytOtONgcrQNsD3aRr0JVRvMBMQHNWyWfMk82l0mDBNPoeRaP9JuZ1x nP6pjfCPQlaJ3tqgC8DlAvJf7pS6rL2UcvvVKZLGuR/s6bZf4FcdhNZiD8Vg8gY55HMv nCGsM1PeWK+y3jBWgHOeKrBKJYV7SpdiTlySZDyAEjN10QrutSpX7pEHkyAQLHa739Xe 2x4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681907589; x=1684499589; h=content-transfer-encoding:cc: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=OMnxG+s7j4Bi6mdStqhu/V6gxIDfzNhtzBKirQZuj+c=; b=LzEwO8d4LXVvaBimQC1G/UKBT7i9mgmz9k8srZJlSRAPIPz33ynBXs3JNy7uCHC+Vu FyXtb1ulG7X3uUrB+hIr4ZJRPOwi+XaMk9g/1nrFe1IMtkGdRGcXoq9Rw0mK2DtN9piP +2lB/NP56jVcR++MGivDm0UbuNFDuWDlHM9SVhYk4FaO0Xhdt8ZUMg6vcNuV4EKWTTSh E/ZdhMx0EziLFgP44YN23GeneNF9MtY5IFaEfNqYv96ae4Y3VuVOmZqMdzBm+UfQ+7L7 5/AWojRAOWs4IDXrSuLvlx9Z4kdOHJxEWu2yLrrUwuJGxkZHDB3vRe+xR23IDrKi6Z/n 0XkQ== X-Gm-Message-State: AAQBX9d+R0OSp/5DEQh0+0pBo8moY+AGfsivzhbaO775hJfEgLEv1u2K LF8o3V9ci3RIagQha/AndW5pOwi1/nF8hW5iKcg= X-Google-Smtp-Source: AKy350byUZe4dvkkGFNvAO2ZpB0q5/lq0MPht/a/XGn1B0myzSLZcqH/3pCN87+vWtizODqrQJK5b/tF3gb1umSMqlU= X-Received: by 2002:a2e:9812:0:b0:2a8:ea22:28b3 with SMTP id a18-20020a2e9812000000b002a8ea2228b3mr895727ljj.3.1681907588903; Wed, 19 Apr 2023 05:33:08 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Richard Biener Date: Wed, 19 Apr 2023 14:32:01 +0200 Message-ID: Subject: Re: [match.pd] [SVE] Add pattern to transform svrev(svrev(v)) --> v To: Prathamesh Kulkarni Cc: gcc Patches , Richard Sandiford Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-1.0 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,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, Apr 19, 2023 at 2:20=E2=80=AFPM Prathamesh Kulkarni wrote: > > On Wed, 19 Apr 2023 at 16:17, Richard Biener = wrote: > > > > On Wed, Apr 19, 2023 at 11:21=E2=80=AFAM Prathamesh Kulkarni > > wrote: > > > > > > On Tue, 11 Apr 2023 at 19:36, Prathamesh Kulkarni > > > wrote: > > > > > > > > On Tue, 11 Apr 2023 at 14:17, Richard Biener wrote: > > > > > > > > > > On Wed, Apr 5, 2023 at 10:39=E2=80=AFAM Prathamesh Kulkarni via G= cc-patches > > > > > wrote: > > > > > > > > > > > > Hi, > > > > > > For the following test: > > > > > > > > > > > > svint32_t f(svint32_t v) > > > > > > { > > > > > > return svrev_s32 (svrev_s32 (v)); > > > > > > } > > > > > > > > > > > > We generate 2 rev instructions instead of nop: > > > > > > f: > > > > > > rev z0.s, z0.s > > > > > > rev z0.s, z0.s > > > > > > ret > > > > > > > > > > > > The attached patch tries to fix that by trying to recognize the= following > > > > > > pattern in match.pd: > > > > > > v1 =3D VEC_PERM_EXPR (v0, v0, mask) > > > > > > v2 =3D VEC_PERM_EXPR (v1, v1, mask) > > > > > > --> > > > > > > v2 =3D v0 > > > > > > if mask is { nelts - 1, nelts - 2, nelts - 3, ... } > > > > > > > > > > > > Code-gen with patch: > > > > > > f: > > > > > > ret > > > > > > > > > > > > Bootstrap+test passes on aarch64-linux-gnu, and SVE bootstrap i= n progress. > > > > > > Does it look OK for stage-1 ? > > > > > > > > > > I didn't look at the patch but tree-ssa-forwprop.cc:simplify_perm= utation should > > > > > handle two consecutive permutes with the is_combined_permutation_= identity > > > > > which might need tweaking for VLA vectors > > > > Hi Richard, > > > > Thanks for the suggestions. The attached patch modifies > > > > is_combined_permutation_identity > > > > to recognize the above pattern. > > > > Does it look OK ? > > > > Bootstrap+test in progress on aarch64-linux-gnu and x86_64-linux-gn= u. > > > Hi, > > > ping https://gcc.gnu.org/pipermail/gcc-patches/2023-April/615502.html > > > > Can you instead of def_stmt pass in a bool whether rhs1 is equal to rhs= 2 > > and amend the function comment accordingly, say, > > > > tem =3D VEC_PERM ; > > res =3D VEC_PERM ; > > > > SAME_P specifies whether op0 and op1 compare equal. */ > > > > + if (def_stmt) > > + gcc_checking_assert (is_gimple_assign (def_stmt) > > + && gimple_assign_rhs_code (def_stmt) =3D=3D VE= C_PERM_EXPR); > > this is then unnecessary > > > > mask =3D fold_ternary (VEC_PERM_EXPR, TREE_TYPE (mask1), mask1, mask= 1, mask2); > > + > > + /* For VLA masks, check for the following pattern: > > + v1 =3D VEC_PERM_EXPR (v0, v0, mask) > > + v2 =3D VEC_PERM_EXPR (v1, v1, mask) > > + --> > > + v2 =3D v0 > > > > you are not using 'mask' so please defer fold_ternary until after your > > special-case. > > > > + if (operand_equal_p (mask1, mask2, 0) > > + && !VECTOR_CST_NELTS (mask1).is_constant () > > + && def_stmt > > + && operand_equal_p (gimple_assign_rhs1 (def_stmt), > > + gimple_assign_rhs2 (def_stmt), 0)) > > + { > > + vec_perm_builder builder; > > + if (tree_to_vec_perm_builder (&builder, mask1)) > > + { > > + poly_uint64 nelts =3D TYPE_VECTOR_SUBPARTS (TREE_TYPE (mask1)= ); > > + vec_perm_indices sel (builder, 1, nelts); > > + if (sel.series_p (0, 1, nelts - 1, -1)) > > + return 1; > > + } > > + return 0; > > > > I'm defering to Richard whether this is the correct way to check for a = vector > > reversing mask (I wonder how constructing such mask is even possible) > Hi Richard, > Thanks for the suggestions, I have updated the patch accordingly. > > The following hunk from svrev_impl::fold() constructs mask in reverse: > /* Permute as { nelts - 1, nelts - 2, nelts - 3, ... }. */ > poly_int64 nelts =3D TYPE_VECTOR_SUBPARTS (TREE_TYPE (f.lhs)); > vec_perm_builder builder (nelts, 1, 3); > for (int i =3D 0; i < 3; ++i) > builder.quick_push (nelts - i - 1); > return fold_permute (f, builder); > > To see if mask chooses elements in reverse, I borrowed it from function c= omment > for series_p in vec-perm-indices.cc: > /* Return true if index OUT_BASE + I * OUT_STEP selects input > element IN_BASE + I * IN_STEP. For example, the call to test > whether a permute reverses a vector of N elements would be: > > series_p (0, 1, N - 1, -1) > > which would return true for { N - 1, N - 2, N - 3, ... }. */ Looks good from my side now, but as said I defer to Richard for the check. Richard. > Thanks, > Prathamesh > > > > Richard. > > > > > Thanks, > > > Prathamesh > > > > > > > > Thanks, > > > > Prathamesh > > > > > > > > > > Richard. > > > > > > > > > > > > > > > > > Thanks, > > > > > > Prathamesh