[PATCH][X86] __builtin_ctz/clz sometimed defined for zero input

Sean Silva chisophugis at gmail.com
Mon Oct 27 20:03:40 PDT 2014


On Mon, Oct 27, 2014 at 7:17 PM, Chandler Carruth <chandlerc at google.com>
wrote:

>
> On Mon, Oct 27, 2014 at 7:07 PM, Sean Silva <chisophugis at gmail.com> wrote:
>
>> Curiously, it looks like GCC is depending on definedness for 0 in its own
>> headers:
>> https://github.com/gcc-mirror/gcc/blob/master/gcc/config/i386/lzcntintrin.h
>>
>> *shrug*
>>
>
> I don't think that's really a justification for much of anything though.
>
> We should still add UBSan checks for this, and make our code correct
> according to the spec for these builtins.
>
> Currently, I continue to prefer not using a builtin and instead defining
> the __lzcnt stuff with a ternary operator.
>

That is my preference as well.

If going forward we don't want to allow the 0 case to ever be defined, we
should change the comment above isCLZForZeroUndef which currently says "on
targets that support these operations in a way that provides well-defined
results for zero without loss of performance, it is a good idea to avoid
optimizing based on that undef behavior"; we should not claim it to be a
"good idea" if usage of that hook is deprecated.

-- Sean Silva
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20141027/cf47a5d3/attachment.html>


More information about the cfe-commits mailing list