[PATCH] Added llvm.is.constant intrinsic

Joerg Sonnenberger joerg at britannica.bec.de
Tue Jul 1 05:13:14 PDT 2014


On Tue, Jul 01, 2014 at 01:59:13PM +0200, Sobczak, Janusz wrote:
> What uses of _builtin_constant_p() are sensible and what uses are, in
> fact, abuses is an interesting topic for a discussion. Nevertheless,
> current status is that one can use __builtin_constant_p() in inline
> functions and it will work as expected when compiled with gcc but
> __builtin_constant_p() would always return false if compiled with clang.

Because they are not constant, yes. Code not compiling with -O0 was a
problem for a long time on Linux for exactly this reason.

> This macro swaps the bytes at compile time if it is possible or calls arch
> specific, fast swab implementations if 'x' is not known to be constant
> (i.e. calls __builtin_swab() if compiler supports it).

We are doing similar things in NetBSD. The question remains why it is
not the other way around -- call __builtin_swab if it is available and
"manual" logic otherwise. That one will get proper compile-time
evaluation if possible. This is exactly the kind of situation I
was talking about initially.

Joerg



More information about the llvm-commits mailing list