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]

gcc compile time support for assumptions

I'd like to know if gcc has implemented some generic way to help
optimizer job by allowing programmers to specify assumptions (or

This is somewhat different from assertions: suppose we have this simple

#include <assert.h>

int p(int a) {
  assert(a > 0);
  return a <= 0;

Compiling with #undef NDEBUG the code generated has a test for a's sign,
a branch for failed assertion and a branch to unconditionally return 0.

Compiling with #define NDEBUG the code generated has a test for a's sign
and the congruent return of 0 and 1.

Neither of this two compilations give the maximum optimization feasible.

If exists a way to write:

int p(int a) {
  assume(a > 0);
  return a <= 0;

this would be compiled with #define NDEBUG as if the assume was an
assert, but with #undef NDEBUG as an unconditional return 0.

In this way we'll get the maximum optimization.

This is a very simple example, but I guess that everyone get the many
possibilities that these gives.

Just to give another examples and to link this to a current thread:

assume(x != INT_MIN || y != -1);
return x % y;

Can be safely compiled with current inexact code also on ppc, i386, x86-64.

Of course the infrastructure is already present in current gcc optimizer
implementation, what I like to know is if there is some way to access it
 from compiled code (by example using specific builtin_).

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