public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/106727] New: Missed fold / canonicalization for checking if a number is a power of 2
@ 2022-08-24  2:51 llvm at rifkin dot dev
  2022-08-24  3:06 ` [Bug middle-end/106727] " pinskia at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: llvm at rifkin dot dev @ 2022-08-24  2:51 UTC (permalink / raw)
  To: gcc-bugs

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.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-03-04 22:58 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-24  2:51 [Bug tree-optimization/106727] New: Missed fold / canonicalization for checking if a number is a power of 2 llvm at rifkin dot dev
2022-08-24  3:06 ` [Bug middle-end/106727] " pinskia at gcc dot gnu.org
2022-08-24  7:21 ` rguenth at gcc dot gnu.org
2024-03-04 22:57 ` pinskia at gcc dot gnu.org
2024-03-04 22:58 ` pinskia at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).