[PATCH] Teach builtin clz, ctz, and popcount to be const

Richard Smith richard at metafoo.co.uk
Tue Jun 11 12:26:57 PDT 2013


On Tue, Jun 11, 2013 at 8:01 AM, Justin Bogner <mail at justinbogner.com>wrote:

> Joerg Sonnenberg wrote:
> > On Tue, Jun 11, 2013 at 12:18:55AM -0600, Justin Bogner wrote:
> >> The clz, ctz, and popcount builtins are trivial to add constant folded
> >> implementations of, and gcc accepts them in const contexts.
> >
> > Can you test the constant folding with
> > char foo[f(x) == val ? 1 : -1];
> >
> > or so?
>
> Do you mean something like this?


A testcase which is less likely to pass by accident would be better (for
instance, your popcount tests would succeed if the builtin just returned
its argument, and tests with a '1' in the sign bit would be useful).

You should also ensure that __builtin_clz(0) and __builtin_ctz(0) are not
treated as constants.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130611/17669c08/attachment.html>


More information about the cfe-commits mailing list