https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126710
Drea Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Ever confirmed|0 |1
Summary|Missing CLZ detection |missed ifcvt optimization
| |with clz
Last reconfirmed| |2026-08-08
Blocks|114527 |
Status|UNCONFIRMED |NEW
--- Comment #1 from Drea Pinski <pinskia at gcc dot gnu.org> ---
So currently clz is produced from sccp.
But what is produced is interesting.
```
value_11 = value_4(D) >> 1;
if (value_11 != 0)
goto <bb 4>; [89.00%]
else
goto <bb 5>; [11.00%]
<bb 4> [local count: 105119324]:
_9 = .CLZ (value_11, 64);
_13 = (unsigned int) _9;
_10 = _13 + 4294967295;
_1 = (int) _10;
<bb 5> [local count: 150883496]:
# _3 = PHI <64(2), 63(3), _1(4)>
```
A few things here, first this:
```
_13 = (unsigned int) _9;
_10 = _13 + 4294967295;
_1 = (int) _10;
```
We should see _9 - 1 does not overflow and change this back into:
_1 = _9 + -1;
That leaves us with:
```
t_4 = a_3(D) >> 1;
if (t_4 != 0)
goto <bb 3>; [48.89%]
else
goto <bb 4>; [51.11%]
<bb 3> [local count: 524952376]:
_1 = .CLZ (t_4, 32);
_5 = _1 + -1;
<bb 4> [local count: 1073741824]:
# _2 = PHI <_5(3), 31(2)>
```
Which should be optimized to:
.CLZ (a_3, 32)
iff a_3 is non-zero.
Referenced Bugs:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114527
[Bug 114527] [meta-bug] missed sccp (final value) optimizations