Re: helping the compiler with asserts-hints to optimize

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 04/23/14 09:45, Agustin Perez Paladini wrote:
Hi,
I was wondering the existence of some kind of builtins methods to help
the compiler to increase the optimization giving information of
possible values for certain variables.

For example, in many cases we use assert(); to ensure some constraints
(some variable will contain certain values or ranges). I think this
will be very helpful information for the compiler to do better
optimizations.

I saw the expected builtin function but is only for expressions and is
not necessary the same.
There's a variety of builtins and other mechanisms to give hints to the optimizer.

As you noted, assert() conveys certain information to the analysis phases. Specifically, it can allow the compiler to narrow the range of the expression in the assert which may allow simplifications to be performed.

__builtin_unreachable/__builtin_abort come immediately to mind. They primarily affect the CFG -- but simplifications in the CFG from __builtin_unreachable/__builtin_abort usage also allow the compiler to do range narrowing on the conditionals leading to the unreachable/abort. The net effect is similar to asserts.

There's hints for branch probability, alignments, etc. Others control the characteristics of functions (pure, const, non-returning, malloc-like, etc).

I'd suggest reading the GCC manual with particular attention to the extensions section.

jeff




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux