From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 750053858D1E; Fri, 23 Dec 2022 07:53:18 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 750053858D1E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1671781998; bh=J1LE6Xi4EZGwKD+MKw9PDeij8XVTHa3BKGZFHLEb7+g=; h=From:To:Subject:Date:In-Reply-To:References:From; b=CvGa8TQKiwosgnZyijv9AnuJ6fV6gEx+92vOs0TVENOFoX7hEApdEsEp5t//nwTsC qAzbBR7R+suvavO1aHabq7r8uFEqsB2GUBbpVqrN+CxcprcMx9j6XDLcZs57fagNsa IW3l0suVKyD2v6CqLC6FNq8fPCAMk1Gvmin/b0F8= From: "krebbel at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/108199] Bitfields, unions and SRA and storage_order_attribute Date: Fri, 23 Dec 2022 07:53:17 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Version: 13.0 X-Bugzilla-Keywords: wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: krebbel at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D108199 --- Comment #7 from Andreas Krebbel --- (In reply to Andrew Pinski from comment #6) > (In reply to Andreas Krebbel from comment #5) > > In: > >=20 > > _1 =3D src_6(D)->a; > > dst$val_9 =3D _1; > > _2 =3D BIT_FIELD_REF ; > > _3 =3D _2 & 64; > > if (_3 !=3D 0) >=20 > There is only 2 accesses going on in the above IR because SRA removed the > 3rd when it replaced the access of dst.val with dst$val but didn't update > BIT_FIELD_REF to remove the byteswap ... Ok, got it. It isn't the removal of the assignment. As you say it happens in early SRA when changing dst.val to dst$val and with that going from the uni= on with the storage order marker to a long int without it. The marker on the BIT_FIELD_REF needs to be in sync with the marker on its inner reference. Dropping one without adjusting the other is the problem here. Thanks for the pointer! The following change helps with that testcase: diff --git a/gcc/tree-sra.c b/gcc/tree-sra.c index 8dfc923ed7e..6b1ce6e8b4a 100644 --- a/gcc/tree-sra.c +++ b/gcc/tree-sra.c @@ -3815,8 +3815,13 @@ sra_modify_expr (tree *expr, gimple_stmt_iterator *g= si, bool write) } } else - *expr =3D repl; - sra_stats.exprs++; + { + if (bfr && TYPE_REVERSE_STORAGE_ORDER (TREE_TYPE (*expr))) + REF_REVERSE_STORAGE_ORDER (bfr) =3D 0; + + *expr =3D repl; + sra_stats.exprs++; + } } else if (write && access->grp_to_be_debug_replaced) {=