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

            Bug ID: 125734
           Summary: clz loop not detected for signed integer types where
                    it is always non-negative
           Product: gcc
           Version: 16.0
            Status: UNCONFIRMED
          Keywords: easyhack, missed-optimization
          Severity: enhancement
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: pinskia at gcc dot gnu.org
  Target Milestone: ---

Take:
```

int
nlz32_1 (int b) {
  int c = sizeof(b)*8;
  if (b < 0) return -1;
  while (b != 0) {
   b >>= 1;
   c --;
  }
  return c;
}
```

This fails to convert to `b<0?-1:(b==0?32:clz(b))`.

This is because is_rshift_by_1 checks TYPE_UNSIGNED but the check should be if
gimple_assign_rhs1 is non-negative.

Reply via email to