On Thu, Oct 08, 2020 at 11:04:01AM +0000, Wilco Dijkstra wrote: > > Perhaps another way out of this would be document and enforce that > > __builtin_c[lt]z{,l,ll} etc calls are undefined at zero, but C[TL]Z ifn > > calls are defined there based on *_DEFINED_VALUE_AT_ZERO (*) == 2, and then > > we would need to make sure that e.g. in simplify_count_trailing_zeroes > > we emit a .CTZ or __builtin_ctz call depending on whether it is undefined > > there or not; or give .C[TL]Z an additional argument (0/1) which would tell > > if it is defined at zero or not. > > I think a better way forward would be to make the builtin_clz/ctz more > defined. > Having undefined values is a source of unnecessary bugs given practically all > modern targets return the number of bits for the zero input - it is relatively > easy to ensure this on the few targets that don't.
Well, e.g. i?86/x86_64 in most commonly used CPU flags is really undefined (the register is unchanged). And -1 is also quite commonly used value, e.g. powerpc, gcn, xtensa. Jakub