From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 86A02385703F; Wed, 24 Aug 2022 02:51:21 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 86A02385703F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1661309481; bh=1V/qjyNE36oWVAH/91o1XumtBWCrHkq2a3JJudCJdUE=; h=From:To:Subject:Date:From; b=o1pfxH8QD419YU4m4C8Gf+j2GpUajvwZRH+jHya4xc/FJzP3ow3qEGcRxbxOQGTrD 5/Hk/MYww1ql0W49464Chy4Q9Qz6yeDhovDfXS1Ck8hxVjlZZdF8GVf8HRpGFqY2C0 a838koeGq60/BSrKHaGEACUvlvabRZhTeRthOMcw= From: "llvm at rifkin dot dev" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/106727] New: Missed fold / canonicalization for checking if a number is a power of 2 Date: Wed, 24 Aug 2022 02:51:21 +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: 12.1.1 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: llvm at rifkin dot dev 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 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=3D106727 Bug ID: 106727 Summary: Missed fold / canonicalization for checking if a number is a power of 2 Product: gcc Version: 12.1.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: llvm at rifkin dot dev Target Milestone: --- These two are equivalent but generate different code: bool foo(unsigned n) { return std::popcount(n) <=3D 1; } bool bar(unsigned n) { return (n & (n - 1)) =3D=3D 0; } https://godbolt.org/z/crrxnfWo7 For systems that don't have popcount instructions it would be very benefici= al to transform foo -> bar. For systems that do have popcount instructions it still would be beneficial to canonicalize the two.=