From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 5886B3858CDB; Sat, 23 Sep 2023 20:23:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5886B3858CDB DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1695500633; bh=3Q+GEusojet0xoFryBOu1U+s2qH2CgD0sv4sW24CAM4=; h=From:To:Subject:Date:In-Reply-To:References:From; b=CEsLyVgbG5PQOIxCDHxiVYeMbjhbPS2LTo5ybw/sqZXEgUWR820y1MCSTmXTh9CX7 A6MXNw7KlAsyRxufVWvMwBOSI3Z8Ni/cV2XQcPpaEX1NcJaMRD3iZmMC1YXpvDbY8g /qdTQcofXh7nzOhkg8/RbOSz6ST4KJZPItEAa24A= From: "pinskia at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/111542] [11/12/13/14 Regression] (a==0)&(b==0) into `(a|b) == 0` optimization sometimes gets in the way of other optimizations Date: Sat, 23 Sep 2023 20:23:50 +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: ASSIGNED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: pinskia at gcc dot gnu.org X-Bugzilla-Target-Milestone: 14.0 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=3D111542 --- Comment #3 from Andrew Pinski --- (In reply to Andrew Pinski from comment #2)=20 > Match pattern: > ``` > (for bitop (bit_ior bit_and) > cmp1 (eq ne ) > cmp2 (ne eq ) > (simplify > (bitop:c > (cmp1 @1 integer_zerop) > (cmp2 (bit_ior:c @0 @1) integer_zerop)) > { constant_boolean_node (bitop =3D=3D BIT_IOR_EXPR, type); })) > ``` But this breaks generic-match building of the function: tree generic_simplify_92 (location_t ARG_UNUSED (loc), const tree ARG_UNUSED (ty= pe), tree ARG_UNUSED (_p0), tree ARG_UNUSED (_p1), tree *captures, const enum tree_code ARG_UNUSED (bitop), const enum tree_code ARG_UNUSED (cmp1), const enum tree_code ARG_UNUSED (cmp2)) { const bool debug_dump =3D dump_file && (dump_flags & TDF_FOLDING); if (TREE_SIDE_EFFECTS (_p0)) goto next_after_fail192; if (TREE_SIDE_EFFECTS (_p1)) goto next_after_fail192; if (UNLIKELY (!dbg_cnt (match))) goto next_after_fail192; { tree _r; _r =3D constant_boolean_node (bitop =3D=3D BIT_IOR_EXPR, type); if (UNLIKELY (debug_dump)) generic_dump_logs ("match.pd", 136, __FILE__, __LINE__, true); return _r; } next_after_fail192:; return NULL_TREE; } captures is not used . I guess I could check TREE_SIDE_EFFECTS on @0/@1 to workaround that issue. Like so: ``` (for bitop (bit_ior bit_and) cmp1 (eq ne ) cmp2 (ne eq ) (simplify (bitop:c (cmp1 @1 integer_zerop) (cmp2 (bit_ior:c @0 @1) integer_zerop)) (if (GIMPLE || (!TREE_SIDE_EFFECTS (@0) && !TREE_SIDE_EFFECTS (@1))) { constant_boolean_node (bitop =3D=3D BIT_IOR_EXPR, type); }))) ``` I had assumed genmatch would generate that code that would use @0/@1 if they had side effects. Maybe because I match @0 twice, it assumed we would be u= sing the captures (I have not looked though).=