This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Infering that the condition of a for loop is initially true?

On 2017-09-14 22:36:34 +0200, Geza Herman wrote:
> Do you plan adding something like __builtin_assume to GCC? It is useful,
> because of this idiom to help the compiler to optimize better:
> #ifdef MY_DEBUG
> #define MY_ASSERT(assertion) do { if (!(assertion)) ... } while (0)
> #else
> #define MY_ASSERT(assertion) __builtin_assume(assertion)
> #endif
> It is not the same as "if (!(assertion)) __builtin_unreachable();" because
> __builtin_assume discards any side effects of "assertion".

Yes, that would be better. Because of possible side effects with
condition + __builtin_unreachable(), MPFR currently has:

# define MPFR_ASSUME(x)                                 \
    (! __builtin_constant_p (!!(x) || !(x)) || (x) ?    \
     (void) 0 : __builtin_unreachable())
#elif defined(_MSC_VER)
# define MPFR_ASSUME(x) __assume(x)
# define MPFR_ASSUME(x) ((void) 0)

(and the MPFR_ASSERTD() macro does either an assertion checking
or does MPFR_ASSUME(), depending on whether or not one wants
full assertions).

Vincent Lefèvre <> - Web: <>
100% accessible validated (X)HTML - Blog: <>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]