From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 62353385841E; Wed, 13 Mar 2024 21:41:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 62353385841E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1710366107; bh=uQISPh4Pk+gPwjrTd0bdce5M3dqrPhhPYmsd/vcLIik=; h=From:To:Subject:Date:In-Reply-To:References:From; b=KvxfTi6jm3boer6q7TcJXikE7BG+LD0MMx67NK/ol0JA3IG4Sv/YtPiNqWiIMHcM6 H3RDtFCp7df1KTNzE64NXjf3oNm9FBoOYlP6gNq8TsRYhvYnhqfzDKW5uVHWe1hlTG SJi3AKm1fzrSHnQGBLOz1ZvIkAexQeO6bkJPVQxc= From: "pinskia at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/114326] Missed optimization for A || B when !B implies A. Date: Wed, 13 Mar 2024 21:41:47 +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: 14.0 X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: normal 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=3D114326 --- Comment #3 from Andrew Pinski --- (In reply to ptomsich from comment #2) > To copy the last piece of info from our internal tracker... >=20 > LLVM learned this new trick only in the run-up to LLVM 18. > Up until then, GCC and LLVM performed identically on this snippet. Yes it looks like it is pattern matching what I suggested (well with and without the and). Note we do need another pattern, one without the bit_and: (simplify (bit_ior (ne@n4 @0 @1) (cmp (bit_xor @0 @1) @2)) (bit_ior @n4=20 (cmp { build_zero_cst (TREE_TYPE (@0)); } @2)) ) And we need one more for bit_ior: (simplify (bit_ior (ne@n4 @0 @1) (cmp (bit_ior (bit_xor @0 @1) @2) @3)) (bit_ior @n4=20 (cmp @2 @3)) ) Note it looks like clang does not handle non-contants that well, (they hand= le d =3D=3D 0 though). E.g.: ``` int foo(void); int cmp1(unsigned d1, unsigned d2, unsigned c, unsigned d) { int t =3D ((d1 ^ d2) & c ) =3D=3D (d); int t1 =3D d1 !=3D d2; int tt =3D t | t1; return tt; } ``` Should be optimized to: int foo(void); int cmp1(unsigned d1, unsigned d2, unsigned c, unsigned d) { int t =3D 0 =3D=3D d; int t1 =3D d1 !=3D d2; int tt =3D t | t1; return tt; } ```=