Hi Jakub, > On Thu, Oct 08, 2020 at 11:37:24AM +0000, Wilco Dijkstra via Gcc-patches > wrote: >> Which optimizations does it enable that aren't possible if the value is >> defined? > > See bugzilla. Note other compilers heavily optimize on those builtins > undefined at value zero.
You mean the PR94801, PR94793, PR95863 you mentioned before? The first doesn't seem to be a useful optimization (would anyone ever write that?), the other 2 would benefit from clz(0) being well defined. In particular, x86 without BMI would greatly benefit from setting CTZ_DEFINED_VALUE_AT_ZERO to 2. So I fail to see any "heavy" optimizations here that show a benefit of keeping the value undefined at zero. >> > We just should make sure that we optimize code like x ? __builtin_c[lt]z >> > (x) : 32; >> > etc. properly (and I believe we do). >> >> I think we do, but both the external and internal documentation are not clear >> enough that most targets actually do define a value and will optimize for it. >> Otherwise we wouldn't have this bug now... > > The documentation is very clear that the builtins are undefined at zero, > that is all that matters for users. If we don't change the undefinedness, at least we should try to explain the above idiom as a way to get a well-defined range that still results in a single instruction on most targets. Cheers, Wilco