https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124833
Bug ID: 124833
Summary: clz not detected in some cases for a loop
Product: gcc
Version: 16.0
Status: UNCONFIRMED
Keywords: missed-optimization
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: pinskia at gcc dot gnu.org
Target Milestone: ---
Take:
```
int
__attribute__ ((noinline, noclone))
foo (unsigned int b) {
int c = 0;
while (b) {
b >>= 1;
c++;
}
return c;
}
int
__attribute__ ((noinline, noclone))
foo1 (unsigned int b) {
int c = 0;
if (b==0) return c;
unsigned t;
do {
t = b;
b >>= 1;
c++;
}while (t > 1);
return c;
}
```
GCC is able to detect clz for foo but not foo1.