[Bug c/124838] __builtin_clzl(0) overoptimization even on targets with native lzcnt instruction
rguenth at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Fri Apr 10 08:22:52 GMT 2026
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124838
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |pinskia at gcc dot gnu.org
Resolution|WONTFIX |---
Keywords| |missed-optimization
Status|RESOLVED |NEW
Last reconfirmed| |2026-04-10
Ever confirmed|0 |1
--- Comment #9 from Richard Biener <rguenth at gcc dot gnu.org> ---
int bar3(unsigned long x) { return x ? __builtin_clzl(x) : 64; }
works, the pattern detection is confused by the conversion to unsinged long
which moved inside the conditional early:
return x != 0 ? (long unsigned int) __builtin_clzl (x) : 64;
without that phiopt1 could
phiopt match-simplify trying:
x_2(D) != 0 ? _4 : 64
Applying pattern match.pd:10864, gimple-match-9.cc:6415
phiopt match-simplify back:
_3 = .CLZ (x_2(D), 64);
result: _3
rejected because early
but phiopt2 then performs the transform. Not with the conversion though
as we match
(for func (CLZ)
(simplify
(cond (ne @0 integer_zerop@1) (func (convert?@3 @0)) INTEGER_CST@2)
I think we want to fix both, not reject early and add another
convert? around func and adjust phiopt to then consider the folding,
which it does not.
More information about the Gcc-bugs
mailing list