From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id C40383858D35; Sat, 24 Jun 2023 22:12:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C40383858D35 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1687644763; bh=/6ewfJr5bI+H4ZbljyV12/pioQFAIjW4Oa1TSw7lhdU=; h=From:To:Subject:Date:In-Reply-To:References:From; b=wpLDleoMctKvpHQ2u0WJUkThAlTTQQ0mkmLd6WwX9XQFcbqANQMEV2yTwVXAJHISg pM7cMpW6b33DpKCcAf9fsWgxlhxb2LSMoHWZOxmg7RIG4OiGllvNXInNjOAPzbHGok +xyExY4oUZNUo0Id9t2b033Z4d/9pELYxZAM7xrM= From: "vanyacpp at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/109986] missing fold (~a | b) ^ a => ~(a & b) Date: Sat, 24 Jun 2023 22:12:43 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: middle-end X-Bugzilla-Version: 14.0 X-Bugzilla-Keywords: easyhack, missed-optimization X-Bugzilla-Severity: enhancement X-Bugzilla-Who: vanyacpp at gmail dot com 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=3D109986 --- Comment #3 from Ivan Sorokin --- I tried to investigate why GCC is able to simplify `(a | b) ^ a` and `(a | = ~b) ^ a` from comment 2, but not similarly looking `(~a | b) ^ a` from comment = 0. `(a | b) ^ a` matches the following pattern from match.pd: /* (X | Y) ^ X -> Y & ~ X*/ (simplify (bit_xor:c (convert1? (bit_ior:c @@0 @1)) (convert2? @0)) (if (tree_nop_conversion_p (type, TREE_TYPE (@0))) (convert (bit_and @1 (bit_not @0))))) `(a | ~b) ^ a` matches another pattern: /* (~X | C) ^ D -> (X | C) ^ (~D ^ C) if (~D ^ C) can be simplified. */ (simplify (bit_xor:c (bit_ior:cs (bit_not:s @0) @1) @2) (bit_xor (bit_ior @0 @1) (bit_xor! (bit_not! @2) @1))) With substitution `X =3D b, C =3D a, D =3D a` it gives: (b | a) ^ (~a ^ a) (b | a) ^ -1 ~(b | a) `(~a | b) ^ a` is not simplifiable by this pattern because it requires that= `~D ^ C` is simplifiable further, but `~a ^ b` is not. In any case, even if it = were applicable it would produce `(a | b) ^ (~a ^ b)` which has more operations = than the original expression.=