From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id D90743857C4E; Wed, 24 Nov 2021 08:55:49 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D90743857C4E From: "cvs-commit at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/103345] missed optimization: add/xor individual bytes to form a word Date: Wed, 24 Nov 2021 08:55:49 +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: 12.0 X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: normal X-Bugzilla-Who: cvs-commit at gcc dot gnu.org X-Bugzilla-Status: ASSIGNED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: roger at nextmovesoftware dot com 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 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 24 Nov 2021 08:55:50 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D103345 --- Comment #4 from CVS Commits --- The master branch has been updated by Jakub Jelinek : https://gcc.gnu.org/g:04eccbbe3d9a4e9d2f8f43dba8ac4cb686029fb2 commit r12-5492-g04eccbbe3d9a4e9d2f8f43dba8ac4cb686029fb2 Author: Jakub Jelinek Date: Wed Nov 24 09:54:44 2021 +0100 bswap: Fix up symbolic merging for xor and plus [PR103376] On Mon, Nov 22, 2021 at 08:39:42AM -0000, Roger Sayle wrote: > This patch implements PR tree-optimization/103345 to merge adjacent > loads when combined with addition or bitwise xor. The current code > in gimple-ssa-store-merging.c's find_bswap_or_nop alreay handles ior, > so that all that's required is to treat PLUS_EXPR and BIT_XOR_EXPR in > the same way at BIT_IOR_EXPR. Unfortunately they aren't exactly the same. They work the same if alwa= ys at least one operand (or corresponding byte in it) is known to be 0, 0 | 0 =3D 0 ^ 0 =3D 0 + 0 =3D 0. But for | also x | x =3D x for any ot= her x, so perform_symbolic_merge has been accepting either that at least one of the bytes is 0 or that both are the same, but that is wrong for ^ and +. The following patch fixes that by passing through the code of binary operation and allowing non-zero masked1 =3D=3D masked2 through only for BIT_IOR_EXPR. Thinking more about it, perhaps we could do more for BIT_XOR_EXPR. We could allow masked1 =3D=3D masked2 case for it, but would need to do something different than the n->n =3D n1->n | n2->n; we do on all the bytes together. In particular, for masked1 =3D=3D masked2 if masked1 !=3D 0 (well, for 0 both variants are the same) and masked1 !=3D 0xff we would need to clear corresponding n->n byte instead of setting it to the input as x ^ x =3D 0 (but if we don't know what x and y are, the result is also don't know). Now, for plus it is much harder, because not only for non-zero operands we don't know what the result is, but it can modify upper bytes as well. So perhaps only if current's byte masked1 && masked2 set the resulting byte to 0xff (unknown) iff the byte above it is 0 and 0, and set that resulting byte to 0xff too. Also, even for | we could instead of return NULL just set the resulting byte to 0xff if it is different, perhaps it will be masked off later on. 2021-11-24 Jakub Jelinek PR tree-optimization/103376 * gimple-ssa-store-merging.c (perform_symbolic_merge): Add CODE argument. If CODE is not BIT_IOR_EXPR, ensure that one of mask= ed1 or masked2 is 0. (find_bswap_or_nop_1, find_bswap_or_nop, imm_store_chain_info::try_coalesce_bswap): Adjust perform_symbolic_merge callers. * gcc.c-torture/execute/pr103376.c: New test.=