<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/64167>64167</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
LoopIdiom: recognize clz pattern
</td>
</tr>
<tr>
<th>Labels</th>
<td>
llvm:optimizations
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
jroelofs
</td>
</tr>
</table>
<pre>
This should be recognized as CLZ:
```
unsigned clz_a(unsigned a) {
int i;
for (i=0;i<32;i++)
if (a & (1<<(31-i)))
return i;
return 32;
}
```
https://clang.godbolt.org/z/4cW3aE6Ks
rdar://8459039
The original bug report was added in 659c793a4e306d815e97ef2c35ce4b7657d957b5
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJxsUk1r3DAQ_TXji8gij_ylgw_ZbA2lOQYKvZTRh20FrbVIckv31xd7k00DhYcsyW_mzUOPUnLTYm0P9RHqU0FrnkPsX2OwPoypUMH86V9ml1iaw-oNU5ZFq8O0uKs1jBJ7ev4B4hH4Cfj72vA37Md12SUM0_76kwC7-wUBSgbt8cZjbsnMgXg_sjFEBtg5ECcO4uhAPAncN3jcId-ZjLlxoxIDbLZNCeJpA3aifHAb84Y7n7Fo8xqXT4JvV7vIm5X29F9Pt3XO-ZI28zgADtrTMh2mYFTw-RDiBDhcAYdKfxf0pfmWbkXRULzXdFUtuZD_Nn2ZLQvRTW4hz9Q6sWgvIWb2mxIjY6xhbmFNLXUrBVVW8MZ0ZW1la0fUota2Um1Tt0bWraoL0wsjhaTC9mUjedVhKXkx99SS5oYqJQxXaISuRW1H2WgaW4ldXbgeOQreYlt2KEp-EKo0jaBKGK3GriGouD2T8wfvf503u4VLabV9U5VNW3hS1qc9VYgbA8RjuGR3dlfKLiwJELe8xX77-aDWKUHFvUs5fTTMLnvbP4dw-Wpc2Fp8ZG9LE7tQzjYuxRp9__kxJpfnVR10OAMOu_7t83CJ4dXqDDjs4ybAYZ_4bwAAAP__Qs_hvg">