From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mout.gmx.net (mout.gmx.net [212.227.17.20]) by sourceware.org (Postfix) with ESMTPS id 539CA3858C5E; Thu, 12 Oct 2023 12:01:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 539CA3858C5E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmx.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1697112063; x=1697716863; i=vehre@gmx.de; bh=GXZHrdb9bhg2bYptyvaB0oj/t72XRQteP1se22hFgA0=; h=X-UI-Sender-Class:Date:From:To:Cc:Subject:In-Reply-To:References; b=P1Jm0okN/C0aJHBjWVtCQApVpJkBH3sGDE2y/DKJjfY1fmK0CjLMJmuy9KPeJEg54wMEoLxV7nt jdyZFt3oL+a4IGvTNjJZIyMsXf0Er3JN6wuMJXV806c0TkOEWx/f243Ec5znl/CHYajBXjjXC8gal hSGLC+t1zpTXLsL/Fw8mPlgSTpbE6vpY4V7Gld92uxqAN7xDLyHu065lhigihG+71am64H5TYIQz5 1FQlzO+lt0PEQxBMACdeGoP3PMgFKGN2V6TTFYpYG/Q1QVjA7CPoCWbblqvRW9W3PMgL/aVmg1p7n tvudJcYCCdrjZSZZMSCXpFVyfjFI9t6o1ffg== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from vepi2 ([79.194.173.146]) by mail.gmx.net (mrgmx105 [212.227.17.168]) with ESMTPSA (Nemesis) id 1M8QWG-1qvI5P2yg4-004Tyi; Thu, 12 Oct 2023 14:01:03 +0200 Date: Thu, 12 Oct 2023 14:01:02 +0200 From: Andre Vehreschild To: Richard Biener Cc: gcc-patches@gcc.gnu.org, Martin Jambor , fortran@gcc.gnu.org Subject: Re: [PATCH] tree-optimization/111779 - Handle some BIT_FIELD_REFs in SRA Message-ID: <20231012140102.19685017@vepi2> In-Reply-To: References: X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; x86_64-redhat-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:2gWSYej2NO7yCWd5r7gOQZ/Avuyq4iFBEB4I3C31aWzxhdWUnHC GKVwB8r54R1Z98Mj0rbqwwNNXxXDoOFarOrd4NfhQFbhgXM7CkoKkHtp4smPgVKdpTBNK0y PyFf99b/dVIgG+ViIT3vop8rKozrfXt3Yo8nGH9K407zB455JM7MY4K5Yn1F5sZJ8JaGbZ6 nEdUR1oJz36uEer/L9j+Q== UI-OutboundReport: notjunk:1;M01:P0:Vyt6B+bC59M=;7lHOx3DE78mtjdYUqrE10nBWh5G 9kMXt7EQ2gTJcLFFQ9LADlouzjmcKTDFP74NS8Lip14cYnbqtE8m4dOmoJEfU+7rhKsS1wmNZ DcneagaeinWem86k7j1Qt/XyNtSGSPeZoH2hRQ8XMNdrmt1Yk6vc/Xgja/Q1W7h9vF9/GwM85 IJmQXmQa88P1nvHM6r3M6BNHUwQpoSC9bOSh2tSn2KNPVUnsT4WyiZme0wwjxaqtgTmd6ibtF Drp8k8/MLX4HSF5IHxL6Ue3Ik1+oXqg5LQDCg/7fCCHDnfun/6u/yeBb8hlV6g3myI5pMY7Jn +Iv06llLiDLVFqVAFbjxWYnlM/1L68jfIL+fe300vkyP0A5eSwe6ETuiI505LfR1I2am+lY9s Flo4y3ZL0O5X8wJoSjfd9uTDtKAjYauObwSPX/ARZjiYOc39c4MuWa0GLd+OZ1PKvCb96PwoO GJ8inj90FQaZP/34x6s9rxIAf939ZORVx4ma4dEPzo5j3o0QBWJW8+hGOfUqAYszbN0sWubpS ZUzMn95MBi7J16fFOdFxPyL9z0xG9XGhEZ92PMMlYynlLJHEUWmEfvZfx/yHgxfxuXL47L+UX YpO7BM8IWFu6DWZyejiZSDYPd9U5+PJIT2KBQodaPvJT4yK53OMW4+0nhM4ntqHoRSfQx9wkB H6u5DLxn4jqNJu1kbZfhEJhGfK9Zgt6MdJdYPibLhPUxvk8IcH4R0R85Nknh/E5e/Rmrrrk4I V0Bjmt7jL+lIpQcqq9KTir+A3CSgd1bgHHL5PGN1J8BHlN7+Si9AEtn1npGhnXqNJqcLI0CGH p5VjBb6kqNFBJb220AzgCKngOnSVGBUgOG16kv6vzMFDwj3yzar6IWIVVPminU3+yhzfxUkRQ 7EiWEnmtQ0VSntObJB1PKDNLrGycplKuLu3VAZCTxTU9lfE95f+5Sul2g3vrM5LNYdFA5P5VX dO+46A== X-Spam-Status: No, score=-9.8 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS,TXREP 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: Hi Richard, being the one who wrote the surrounding code: The fortran part looks good to me. Ok for merge from the fortran side. - Andre On Thu, 12 Oct 2023 11:44:01 +0000 (UTC) Richard Biener wrote: > On Thu, 12 Oct 2023, Richard Biener wrote: > > > The following handles byte-aligned, power-of-two and byte-multiple > > sized BIT_FIELD_REF reads in SRA. In particular this should cover > > BIT_FIELD_REFs created by optimize_bit_field_compare. > > > > For gcc.dg/tree-ssa/ssa-dse-26.c we now SRA the BIT_FIELD_REF > > appearing there leading to more DSE, fully eliding the aggregates. > > > > This results in the same false positive -Wuninitialized as the > > older attempt to remove the folding from optimize_bit_field_compare, > > fixed by initializing part of the aggregate unconditionally. > > > > Bootstrapped and tested on x86_64-unknown-linux-gnu for all languages. > > > > Martin is on leave so I'll push this tomorrow unless the Fortran > > folks have objections. > > Err, and I forgot that hunk. It's > > diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc > index 7beefa2e69c..1b8be081a17 100644 > --- a/gcc/fortran/trans-expr.cc > +++ b/gcc/fortran/trans-expr.cc > @@ -12015,7 +12015,10 @@ gfc_trans_assignment_1 (gfc_expr * expr1, gfc_e= xpr * > expr2, bool init_flag, && !is_runtime_conformable (expr1, expr2); > > /* Only analyze the expressions for coarray properties, when in coarr= ay-lib > - mode. */ > + mode. Avoid false-positive uninitialized diagnostics with initial= izing > + the codimension flag unconditionally. */ > + lhs_caf_attr.codimension =3D false; > + rhs_caf_attr.codimension =3D false; > if (flag_coarray =3D=3D GFC_FCOARRAY_LIB) > { > lhs_caf_attr =3D gfc_caf_attr (expr1, false, &lhs_refs_comp); > > > > Thanks, > > Richard. > > > > PR tree-optimization/111779 > > gcc/ > > * tree-sra.cc (sra_handled_bf_read_p): New function. > > (build_access_from_expr_1): Handle some BIT_FIELD_REFs. > > (sra_modify_expr): Likewise. > > (make_fancy_name_1): Skip over BIT_FIELD_REF. > > > > gcc/fortran/ > > * trans-expr.cc (gfc_trans_assignment_1): Initialize > > lhs_caf_attr and rhs_caf_attr codimension flag to avoid > > false positive -Wuninitialized. > > > > gcc/testsuite/ > > * gcc.dg/tree-ssa/ssa-dse-26.c: Adjust for more DSE. > > * gcc.dg/vect/vect-pr111779.c: New testcase. > > --- > > gcc/testsuite/gcc.dg/tree-ssa/ssa-dse-26.c | 4 +- > > gcc/testsuite/gcc.dg/vect/vect-pr111779.c | 56 +++++++++++++++++++++= + > > gcc/tree-sra.cc | 24 ++++++++-- > > 3 files changed, 79 insertions(+), 5 deletions(-) > > create mode 100644 gcc/testsuite/gcc.dg/vect/vect-pr111779.c > > > > diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ssa-dse-26.c > > b/gcc/testsuite/gcc.dg/tree-ssa/ssa-dse-26.c index e3c33f49ef6..43152d= e5616 > > 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/ssa-dse-26.c > > +++ b/gcc/testsuite/gcc.dg/tree-ssa/ssa-dse-26.c > > @@ -31,5 +31,5 @@ constraint_equal (struct constraint a, struct constr= aint > > b) && constraint_expr_equal (a.rhs, b.rhs); > > } > > > > -/* { dg-final { scan-tree-dump-times "Deleted dead store: x =3D " 1 "= dse1" } > > } */ -/* { dg-final { scan-tree-dump-times "Deleted dead store: y =3D = " 1 > > "dse1" } } */ +/* { dg-final { scan-tree-dump-times "Deleted dead stor= e: x > > =3D " 2 "dse1" } } */ +/* { dg-final { scan-tree-dump-times "Deleted d= ead > > store: y =3D " 2 "dse1" } } */ diff --git > > a/gcc/testsuite/gcc.dg/vect/vect-pr111779.c > > b/gcc/testsuite/gcc.dg/vect/vect-pr111779.c new file mode 100644 index > > 00000000000..79b72aebc78 --- /dev/null > > +++ b/gcc/testsuite/gcc.dg/vect/vect-pr111779.c > > @@ -0,0 +1,56 @@ > > +#include > > +#include "tree-vect.h" > > + > > +struct C > > +{ > > + int c; > > + int d; > > + bool f :1; > > + float e; > > +}; > > + > > +struct A > > +{ > > + unsigned int a; > > + unsigned char c1, c2; > > + bool b1 : 1; > > + bool b2 : 1; > > + bool b3 : 1; > > + struct C b4; > > +}; > > + > > +void __attribute__((noipa)) > > +foo (const struct A * __restrict x, int y) > > +{ > > + int s =3D 0, i =3D 0; > > + for (i =3D 0; i < y; ++i) > > + { > > + const struct A a =3D x[i]; > > + s +=3D a.b4.f ? 1 : 0; > > + } > > + if (s !=3D 0) > > + __builtin_abort (); > > +} > > + > > +int > > +main () > > +{ > > + struct A x[100]; > > + int i; > > + > > + check_vect (); > > + > > + __builtin_memset (x, -1, sizeof (x)); > > +#pragma GCC novect > > + for (i =3D 0; i < 100; i++) > > + { > > + x[i].b1 =3D false; > > + x[i].b2 =3D false; > > + x[i].b3 =3D false; > > + x[i].b4.f =3D false; > > + } > > + foo (x, 100); > > + return 0; > > +} > > + > > +/* { dg-final { scan-tree-dump "LOOP VECTORIZED" "vect" { target vect= _int > > } } } */ diff --git a/gcc/tree-sra.cc b/gcc/tree-sra.cc > > index 56a8ba26135..24d0c20da6a 100644 > > --- a/gcc/tree-sra.cc > > +++ b/gcc/tree-sra.cc > > @@ -1113,6 +1113,21 @@ disqualify_base_of_expr (tree t, const char *re= ason) > > disqualify_candidate (t, reason); > > } > > > > +/* Return true if the BIT_FIELD_REF read EXPR is handled by SRA. */ > > + > > +static bool > > +sra_handled_bf_read_p (tree expr) > > +{ > > + uint64_t size, offset; > > + if (bit_field_size (expr).is_constant (&size) > > + && bit_field_offset (expr).is_constant (&offset) > > + && size % BITS_PER_UNIT =3D=3D 0 > > + && offset % BITS_PER_UNIT =3D=3D 0 > > + && pow2p_hwi (size)) > > + return true; > > + return false; > > +} > > + > > /* Scan expression EXPR and create access structures for all accesses= to > > candidates for scalarization. Return the created access or NULL i= f > > none is created. */ > > @@ -1123,7 +1138,8 @@ build_access_from_expr_1 (tree expr, gimple *stm= t, > > bool write) struct access *ret =3D NULL; > > bool partial_ref; > > > > - if (TREE_CODE (expr) =3D=3D BIT_FIELD_REF > > + if ((TREE_CODE (expr) =3D=3D BIT_FIELD_REF > > + && (write || !sra_handled_bf_read_p (expr))) > > || TREE_CODE (expr) =3D=3D IMAGPART_EXPR > > || TREE_CODE (expr) =3D=3D REALPART_EXPR) > > { > > @@ -1170,6 +1186,7 @@ build_access_from_expr_1 (tree expr, gimple *stm= t, > > bool write) case COMPONENT_REF: > > case ARRAY_REF: > > case ARRAY_RANGE_REF: > > + case BIT_FIELD_REF: > > ret =3D create_access (expr, stmt, write); > > break; > > > > @@ -1549,6 +1566,7 @@ make_fancy_name_1 (tree expr) > > obstack_grow (&name_obstack, buffer, strlen (buffer)); > > break; > > > > + case BIT_FIELD_REF: > > case ADDR_EXPR: > > make_fancy_name_1 (TREE_OPERAND (expr, 0)); > > break; > > @@ -1564,7 +1582,6 @@ make_fancy_name_1 (tree expr) > > } > > break; > > > > - case BIT_FIELD_REF: > > case REALPART_EXPR: > > case IMAGPART_EXPR: > > gcc_unreachable (); /* we treat these as scalars. */ > > @@ -3769,7 +3786,8 @@ sra_modify_expr (tree *expr, gimple_stmt_iterato= r > > *gsi, bool write) tree type, bfr, orig_expr; > > bool partial_cplx_access =3D false; > > > > - if (TREE_CODE (*expr) =3D=3D BIT_FIELD_REF) > > + if (TREE_CODE (*expr) =3D=3D BIT_FIELD_REF > > + && (write || !sra_handled_bf_read_p (*expr))) > > { > > bfr =3D *expr; > > expr =3D &TREE_OPERAND (*expr, 0); > > > =2D- Andre Vehreschild * Email: vehre ad gmx dot de