From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id EB2DC3857705; Wed, 23 Aug 2023 02:17:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EB2DC3857705 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1692757026; bh=ZpxLg2PBYMO2AvNtdB3tRi3SfNo3TMmbyuk7zqiLubw=; h=From:To:Subject:Date:In-Reply-To:References:From; b=Em1/MP9ZEAeZCSwUE9UiD/WXwEm3t0tHaHjhE/LAWYKCBocUiNodquDAtCvwof/gF 1+PIW8omfASe0s4pUvzXPcfgywHaZLNIAc5aqGJvCQWAPxerYeilGY4HMozHdnwDpz Ea7AEuVExKqxSjJwD2BozjzCNOJNgM2dyyhxVtk0= From: "pinskia at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/95034] Failure to convert xor pattern (made out of or+and) to xor Date: Wed, 23 Aug 2023 02:16:53 +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: 11.0 X-Bugzilla-Keywords: easyhack, 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=3D95034 --- Comment #6 from Andrew Pinski --- So after phiopt2 we end up with: ``` _1 =3D a_3(D) | b_4(D); if (_1 !=3D 0) goto ; [50.00%] else goto ; [50.00%] [local count: 536870912]: _5 =3D a_3(D) & b_4(D); _7 =3D ~_5; [local count: 1073741824]: # iftmp.0_2 =3D PHI <_7(3), 0(2)> ``` Phi-opt does not support more than one statement inside the middle BB so it does nothing here. But if we rewrite it such that the 2 statements were not inside the middle = BB by phiopt2, we get the xor as expected. That is: ``` bool f(bool a, bool b) { bool c =3D a | b; bool d =3D a & b; d =3D !d; return c ? d : false; } ``` Will produce: ``` _8 =3D a_3(D) ^ b_4(D); return _8; ``` >From the phiopt2 dump: ``` Folded into the sequence: _8 =3D a_3(D) ^ b_4(D); ``` I wonder if we could support more than 1 statement in the middle BBs iff the resulting simplifications only reference one SSA_NAME of the statements max= ...=