[Bug tree-optimization/90594] New: [9/10 regression] Spurious popcount emitted

wilco at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Thu May 23 11:30:00 GMT 2019


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90594

            Bug ID: 90594
           Summary: [9/10 regression] Spurious popcount emitted
           Product: gcc
           Version: 9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: wilco at gcc dot gnu.org
  Target Milestone: ---

The following testcase emits a popcount which computes the final pointer value.
This is redundant given the loop already computes the pointer value. The
popcount causes the code to be significantly larger and slower than previous
GCC versions.

int *bad_popcount (unsigned x, int *p)
{
  for (; x != 0; )
    {
      int tmp = __builtin_ctz (x);
      x = x & (x - 1);
      *p++ = tmp;
    }
  return p;
}

GCC8:
        cbz     w0, .L2
.L3:
        rbit    w2, w0
        clz     w2, w2
        str     w2, [x1], 4
        sub     w2, w0, #1
        ands    w0, w0, w2
        bne     .L3
.L2:
        mov     x0, x1
        ret

GCC9:
        cbz     w0, .L12
        mov     x4, x1
        mov     w2, w0
.L11:
        rbit    w3, w2
        clz     w3, w3
        str     w3, [x4], 4
        sub     w3, w2, #1
        ands    w2, w2, w3
        bne     .L11
        fmov    s0, w0
        cnt     v0.8b, v0.8b
        addv    b0, v0.8b
        umov    w0, v0.b[0]
        sub     w0, w0, #1
        add     x0, x0, 1
        add     x0, x1, x0, lsl 2
        ret
.L12:
        mov     x0, x1
        ret


More information about the Gcc-bugs mailing list