From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 5FFCB3858D35; Fri, 5 May 2023 08:17:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5FFCB3858D35 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1683274647; bh=RpnzA6lMec9nAWMGL4O5mirAkLGx+dChW0RGiiQbrV0=; h=From:To:Subject:Date:In-Reply-To:References:From; b=LdvUH8PqlQr5ZLFjC6QNtQ8omgMjPcb+XNsfVlfI1wYukD8dUCcWVWsuTJXB9pozj /XGkfiu6F3XLjCLgJyz9Mqw5jBEF9DrgO9n+5fwyJ4ZrsERol0FO7p79spO/DjdvMh cltfXMq7MR1aB8GOfWiIiwfmfMUNcSti7FxF3GXY= From: "pinskia at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/27504] x && (x & y) not optimized to x & y Date: Fri, 05 May 2023 08:17:26 +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: 4.2.0 X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: enhancement X-Bugzilla-Who: pinskia 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=3D27504 --- Comment #4 from Andrew Pinski --- (In reply to Andrew Pinski from comment #3) > Confirmed again. > So looking at the IR, it took until PHI-OPT4 to be able to convert it int= o: > [local count: 1073741824]: > if (x_3(D) !=3D 0) > goto ; [50.00%] > else > goto ; [50.00%] >=20 > [local count: 536870913]: > _1 =3D x_3(D) & 85; > _5 =3D _1 !=3D 0; > _6 =3D (int) _5; >=20 > [local count: 1073741824]: > # iftmp.0_2 =3D PHI <_6(3), 0(2)> In GCC 12+, phiopt2 is able to convert that into the above. One thing that could be tried is to replace x_3 with 0 and see if _6 would simplify down to 0 (other the phi argument). This could be part of phiopt b= ut would need a lot of work really. Note VRP is able to handle the other way around already: that is: `(x & 0x55) && x ` But that is simplier.=