https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78420
--- Comment #26 from Jakub Jelinek <jakub at gcc dot gnu.org> --- (In reply to Jason Merrill from comment #25) > (In reply to Jakub Jelinek from comment #23) > > One possibility would be a __builtin_constant_p-like builtin that would fold > > to false much earlier than the current __builtin_constant_p, e.g. during > > gimplification. > > I think this would only be useful for C++ constexpr evaluation, since most > uses in C depend on being folded after inlining. E.g. the kernel ilog2 macro or generally C macro constexpr-like programming would benefit from that too. One needs to use just macros, not inline functions, sure. But especially now that c_fully_fold can fold rvalues containing const variables, it can do quite a lot. The description of kernel ilog2 says: * ilog2 - log of base 2 of 32-bit or a 64-bit unsigned value * @n - parameter * * constant-capable log of base 2 calculation * - this can be used to initialise global variables from constant data, hence * the massive ternary operator construction * * selects the appropriately-sized optimised version depending on sizeof(n) so they mostly care that it is usable in constant expressions, if it is used elsewhere, it can be optimized through inlining etc. Another possible use case is PR83653, there I came up with ugly, but working, workaround, essentially this __builtin_early_constant_p, but only working in macros and not usable in constant expressions. Store __builtin_constant_p into static const int variable inside a statement expression (when optimizing only), hoping that the static const int var will be optimized away and all it will do is force early evaluation of the __builtin_constant_p.