From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 48E283858C60; Sat, 16 Sep 2023 02:41:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 48E283858C60 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1694832066; bh=dDfQztrPw3eY2HkAW1FwwC+cziaU3UY2CRh+/C72KM4=; h=From:To:Subject:Date:From; b=Q8lBFYH4KFdUwqUlnC+Mb/gvG7jEQlELrz3eJYI3gGZXYbsPTvHMpAnOQXXOlYqP/ BMXP77w3qN3BWwLYy4np0c6iYEiIFR8PQF8pQzphvs8O0b7VrNbEqTgXjYc1K6gVNL s0Um/R2+jRlfxdu67KmnBO4pXp5czjEjvmgLzA7s= From: "pinskia at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/111431] New: a & (a == 0) is not optimized to 0 Date: Sat, 16 Sep 2023 02:41:05 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Version: 14.0 X-Bugzilla-Keywords: missed-optimization, xfail X-Bugzilla-Severity: normal X-Bugzilla-Who: pinskia at gcc dot gnu.org X-Bugzilla-Status: UNCONFIRMED 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: bug_id short_desc product version bug_status keywords bug_severity priority component assigned_to reporter target_milestone Message-ID: 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=3D111431 Bug ID: 111431 Summary: a & (a =3D=3D 0) is not optimized to 0 Product: gcc Version: 14.0 Status: UNCONFIRMED Keywords: missed-optimization, xfail Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: pinskia at gcc dot gnu.org Target Milestone: --- Take: ``` int foo (int a) { int b =3D !a; return (a & b); } ``` The general rule is: (a =3D=3D CST) & a transform into: (CST & 1) ? (a =3D=3D CST) : 0 So (simplify (bit_and:c (convert@2 (eq @0 INTEGER_CST@1)) @0) (if ((wi::to_wide (@1) & 1) !=3D 0) @2 { build_zero_cst (type); }))=