[Bug other/79469] Feature request: provide `__builtin_assume` builtin function to allow more aggressive optimizations and to match clang
felix.von.s at posteo dot de
gcc-bugzilla@gcc.gnu.org
Fri Apr 17 11:43:48 GMT 2020
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79469
--- Comment #2 from felix <felix.von.s at posteo dot de> ---
I realised recently that this is already expressible:
#define __builtin_assume(expr) \
(__builtin_pure_p(expr) \
? ((expr) \
? (void) 0 \
: __builtin_unreachable()) \
: (void) 0 /* XXX: warn about side effects */)
where __builtin_pure_p has the same definition that I gave under PR 6906:
#define __builtin_pure_p(expr) \
(__builtin_object_size(((void) (expr), ""), 2))
As for the corner case I gave earlier, GCC manages to optimise the is_pow2 loop
away at -O2 and -O3 (though not entirely at -O1), and it apparently considers
statement-expressions that contain more than one statement, or any kind of
loop, to have side effects. One can always check __OPTIMIZE__ to prevent
spurious code from being generated at -O0. So this solution apparently performs
no worse :)
More information about the Gcc-bugs
mailing list