[Bug tree-optimization/126698] New: Fold ceil (X / 2^C) ==/!= 0 -> X ==/!= 0

"ktkachov at gcc dot gnu.org via Gcc-bugs" <[email protected]>
Newsgroups gmane.comp.gcc.bugs
Message-ID <[email protected]/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126698

            Bug ID: 126698
           Summary: Fold ceil (X / 2^C) ==/!= 0   ->   X ==/!= 0
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Keywords: easyhack, missed-optimization
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ktkachov at gcc dot gnu.org
  Target Milestone: ---

int f (unsigned x) { return ((x >> 4) + ((x & 15) != 0)) == 0; }

Currently generates for aarch64 -O2:
f:
        tst     w0, 15
        lsr     w0, w0, 4
        cinc    w0, w0, ne
        cmp     w0, 0
        cset    w0, eq
        ret

but can generate just:
f:
        cmp     w0, #0
        cset    w0, eq
        ret
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.