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

            Bug ID: 114760
           Summary: traling zero count detection failure
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jiangning.liu at amperecomputing dot com
  Target Milestone: ---

For this small case, gcc failed to detect trailing zero count calculation, so
the x86 instruction tzcnt cannot be generated, but clang can generate it.

unsigned  ntz32_6a(unsigned x) {
  int n;

  n = 32;
  while (x != 0) {
    n = n - 1;
    x = x + x;
  }
  return n;
}

If we slightly change "x = x + x" to "x = x << 1", the optimization will just
work.

unsigned  ntz32_6a(unsigned x) {
  int n;

  n = 32;
  while (x != 0) {
    n = n - 1;
    x = x << 1;
  }
  return n;
}

It seems number_of_iterations_cltz/number_of_iterations_cltz_complement in
tree-ssa-loop-niter.cc or somewhere else need to be enhanced.

Reply via email to