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

            Bug ID: 126710
           Summary: Missing CLZ detection
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Keywords: 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: ---
            Target: aarch64

Consider the C++
int clz_i(unsigned int value) {
  constexpr int W = sizeof(value) * 8;
  int r = 0;
  if (value == 0)
    return W;
  while (value >>= 1)
    ++r;
  return W - 1 - r;
}

int clz_l(unsigned long value) {
  constexpr int W = sizeof(value) * 8;
  int r = 0;
  if (value == 0)
    return W;
  while (value >>= 1)
    ++r;
  return W - 1 - r;
}

I think on aarch64 these can optimise to the CLZ instructions as they are
defined to be bit-width at zero and the rest is a standard final value
replacement?

Reply via email to