From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from server.nextmovesoftware.com (server.nextmovesoftware.com [162.254.253.69]) by sourceware.org (Postfix) with ESMTPS id 194493858D20 for ; Tue, 15 Mar 2022 07:25:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 194493858D20 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=nextmovesoftware.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=nextmovesoftware.com DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=nextmovesoftware.com; s=default; h=Content-Type:MIME-Version:Message-ID: Date:Subject:In-Reply-To:References:Cc:To:From:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=xjP+H0Dr4BIWv7mArDQDsjWHMX5PVAgnvK7HTC1ee0s=; b=ctf79mquZgi3Eg7HrAYqHG58OH YxlcfVJt1xdDQ4X4+k0KpPfV6kOQQgeQq5YLlUN4xeY0T/UnFFB1Kdbz/DcO2dNIwVBHMOABqHp3E lK81qZW6ExCfUUTPBwGDBI9eMVNpduIfdlcCsJs/oYbGgBneU4rJzan/18Z8X/Pde7eAA015+tY1A 6o0jqvQDrNVI9BHq+YrKxj7CEu/tm7OraedfF3iDqFChimlw4SnOSl5CV1hB1TRB94jpYNibGe/LJ D1by9WjzRc4Gz3Kyeh2dUprAh0GSwsqvWnXL5kLGax7KhwYJKRz07WghYq2k3mYNF5ZS39QQARO2f wxF3FzXA==; Received: from host86-186-213-42.range86-186.btcentralplus.com ([86.186.213.42]:50591 helo=Dell) by server.nextmovesoftware.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1nU1YW-0001RI-Ai; Tue, 15 Mar 2022 03:25:20 -0400 From: "Roger Sayle" To: "'Richard Biener'" , "'GCC Patches'" Cc: "'Marc Glisse'" References: <032301d835a2$86214110$9263c330$@nextmovesoftware.com> <6ee61d3-ffac-7667-9dc0-692699e9e12f@hippo.saclay.inria.fr> In-Reply-To: Subject: RE: [PATCH] PR tree-optimization/101895: Fold VEC_PERM to help recognize FMA. Date: Tue, 15 Mar 2022 07:25:17 -0000 Message-ID: <006301d8383d$d34e1560$79ea4020$@nextmovesoftware.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_NextPart_000_0064_01D8383D.D3508660" X-Mailer: Microsoft Outlook 16.0 Thread-Index: AQFgw7Pw456NkByIDsl9zRgLWzxDYwIbkzkvAczOQc2tj62bsA== Content-Language: en-gb X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - server.nextmovesoftware.com X-AntiAbuse: Original Domain - gcc.gnu.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - nextmovesoftware.com X-Get-Message-Sender-Via: server.nextmovesoftware.com: authenticated_id: roger@nextmovesoftware.com X-Authenticated-Sender: server.nextmovesoftware.com: roger@nextmovesoftware.com X-Source: X-Source-Args: X-Source-Dir: X-Spam-Status: No, score=-12.4 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.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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-List-Received-Date: Tue, 15 Mar 2022 07:25:22 -0000 This is a multipart message in MIME format. ------=_NextPart_000_0064_01D8383D.D3508660 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Richard and Marc, Many thanks for both your feedback on my patch for PR 101895. Here's version 2 of this patch, incorporating all of the suggested = improvements. The one minor complication is that the :s qualifier doesn't = automatically recognize that a capture already has two (or N) uses in a pattern, so I have to manually confirm that there are no other uses of the mult using num_imm_uses. This revision has been tested on x86_64-pc-linux-gnu with make bootstrap and make -k check with no new failures. Ok for mainline? 2022-03-15 Roger Sayle Marc Glisse Richard Biener gcc/ChangeLog PR tree-optimization/101895 * match.pd (vec_same_elem_p): Handle CONSTRUCTOR_EXPR def. (plus (vec_perm (mult ...) ...) ...): New reordering simplification. gcc/testsuite/ChangeLog PR tree-optimization/101895 * gcc.target/i386/pr101895.c: New test case. Thanks in advance, Roger -- > -----Original Message----- > From: Richard Biener > Sent: 14 March 2022 07:38 > To: GCC Patches > Cc: Roger Sayle ; Marc Glisse > > Subject: Re: [PATCH] PR tree-optimization/101895: Fold VEC_PERM to = help > recognize FMA. >=20 > On Sun, Mar 13, 2022 at 12:39 AM Marc Glisse via Gcc-patches patches@gcc.gnu.org> wrote: > > > > On Fri, 11 Mar 2022, Roger Sayle wrote: > > > > +(match vec_same_elem_p > > + CONSTRUCTOR@0 > > + (if (uniform_vector_p (TREE_CODE (@0) =3D=3D SSA_NAME > > + ? gimple_assign_rhs1 (SSA_NAME_DEF_STMT = (@0)) > > +: @0)))) > > > > Ah, I didn't remember we needed that, we don't seem to be very > > consistent about it. Probably for this reason, the transformation > > "Prefer vector1 << scalar to vector1 << vector2" does not match > > > > typedef int vec __attribute__((vector_size(16))); vec f(vec a, int = b){ > > vec bb =3D { b, b, b, b }; > > return a << bb; > > } > > > > which is only optimized at vector lowering time. >=20 > Few more comments - since match.pd is matching in match.pd order the >=20 > (match vec_same_elem_p > @0 > (...)) >=20 > should come last. Please use >=20 > +(match vec_same_elem_p > + CONSTRUCTOR@0 > (if (TREE_CODE (@0) =3D=3D SSA_NAME > && uniform_vector_p (... >=20 > since otherwise we'll try uniform_vector_p twice on all CTORs (that = are not > uniform). >=20 > > +/* Push VEC_PERM earlier if that may help FMA perception = (PR101895). > > +*/ (for plusminus (plus minus) > > + (simplify > > + (plusminus (vec_perm (mult@0 @1 vec_same_elem_p@2) @0 @3) @4) > > + (plusminus (mult (vec_perm @1 @1 @3) @2) @4))) > > > > Don't you want :s on mult and vec_perm? >=20 > Yes. Also for plus you want :c on it , likewise you want :c on the = mult. The :c on > the plus will require splitting the plus and minus case :/ >=20 > Otherwise looks reasonable. >=20 > Richard. >=20 > > > > -- > > Marc Glisse ------=_NextPart_000_0064_01D8383D.D3508660 Content-Type: text/plain; name="patchvp3.txt" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="patchvp3.txt" diff --git a/gcc/match.pd b/gcc/match.pd=0A= index 97399e5..12c92f4 100644=0A= --- a/gcc/match.pd=0A= +++ b/gcc/match.pd=0A= @@ -7689,16 +7689,33 @@ and,=0A= /* VEC_PERM_EXPR (v, v, mask) -> v where v contains same element. */=0A= =0A= (match vec_same_elem_p=0A= + (vec_duplicate @0))=0A= +=0A= +(match vec_same_elem_p=0A= + CONSTRUCTOR@0=0A= + (if (TREE_CODE (@0) =3D=3D SSA_NAME=0A= + && uniform_vector_p (gimple_assign_rhs1 (SSA_NAME_DEF_STMT = (@0))))))=0A= +=0A= +(match vec_same_elem_p=0A= @0=0A= (if (uniform_vector_p (@0))))=0A= =0A= -(match vec_same_elem_p=0A= - (vec_duplicate @0))=0A= =0A= (simplify=0A= (vec_perm vec_same_elem_p@0 @0 @1)=0A= @0)=0A= =0A= +/* Push VEC_PERM earlier if that may help FMA perception (PR101895). */=0A= +(simplify=0A= + (plus:c (vec_perm:s (mult:c@0 @1 vec_same_elem_p@2) @0 @3) @4)=0A= + (if (TREE_CODE (@0) =3D=3D SSA_NAME && num_imm_uses (@0) =3D=3D 2)=0A= + (plus (mult (vec_perm @1 @1 @3) @2) @4)))=0A= +(simplify=0A= + (minus (vec_perm:s (mult:c@0 @1 vec_same_elem_p@2) @0 @3) @4)=0A= + (if (TREE_CODE (@0) =3D=3D SSA_NAME && num_imm_uses (@0) =3D=3D 2)=0A= + (minus (mult (vec_perm @1 @1 @3) @2) @4)))=0A= +=0A= +=0A= /* Match count trailing zeroes for simplify_count_trailing_zeroes in = fwprop.=0A= The canonical form is array[((x & -x) * C) >> SHIFT] where C is a = magic=0A= constant which when multiplied by a power of 2 contains a unique = value=0A= diff --git a/gcc/testsuite/gcc.target/i386/pr101895.c = b/gcc/testsuite/gcc.target/i386/pr101895.c=0A= new file mode 100644=0A= index 0000000..4d0f1cb=0A= --- /dev/null=0A= +++ b/gcc/testsuite/gcc.target/i386/pr101895.c=0A= @@ -0,0 +1,11 @@=0A= +/* { dg-do compile } */=0A= +/* { dg-options "-O2 -march=3Dcascadelake" } */=0A= +=0A= +void foo(float * __restrict__ a, float b, float *c) {=0A= + a[0] =3D c[0]*b + a[0];=0A= + a[1] =3D c[2]*b + a[1];=0A= + a[2] =3D c[1]*b + a[2];=0A= + a[3] =3D c[3]*b + a[3];=0A= +}=0A= +=0A= +/* { dg-final { scan-assembler "vfmadd" } } */=0A= ------=_NextPart_000_0064_01D8383D.D3508660--