From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 88F933857C69; Mon, 14 Jun 2021 22:04:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 88F933857C69 From: "pinskia at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/100864] (a&!b) | b is not opimized to a | b for comparisons Date: Mon, 14 Jun 2021 22:04:39 +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: enhancement X-Bugzilla-Who: pinskia at gcc dot gnu.org X-Bugzilla-Status: ASSIGNED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: pinskia 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 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: Mon, 14 Jun 2021 22:04:39 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D100864 --- Comment #5 from Andrew Pinski --- So what is done for A && !B (and A || !B), is the following: /* Simple range test simplifications. */ /* A < B || A >=3D B -> true. */ (for test1 (lt le le le ne ge) test2 (ge gt ge ne eq ne) (simplify (bit_ior:c (test1 @0 @1) (test2 @0 @1)) (if (INTEGRAL_TYPE_P (TREE_TYPE (@0)) || VECTOR_INTEGER_TYPE_P (TREE_TYPE (@0))) { constant_boolean_node (true, type); }))) /* A < B && A >=3D B -> false. */ (for test1 (lt lt lt le ne eq) test2 (ge gt eq gt eq gt) (simplify (bit_and:c (test1 @0 @1) (test2 @0 @1)) (if (INTEGRAL_TYPE_P (TREE_TYPE (@0)) || VECTOR_INTEGER_TYPE_P (TREE_TYPE (@0))) { constant_boolean_node (false, type); }))) But this could be expanded to other non-integer types. For float types e.g (with -ffast-math): int f(float a, float b) { int c =3D a =3D=3D b; int d =3D a !=3D b; return c & d; } Is not optimized until reassoc1. I will change that to be similar what I H= ave too.=