https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106727
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) <= 1; } bool bar(unsigned n) { return (n & (n - 1)) == 0; } https://godbolt.org/z/crrxnfWo7 For systems that don't have popcount instructions it would be very beneficial to transform foo -> bar. For systems that do have popcount instructions it still would be beneficial to canonicalize the two.