Hi Jeff, Thanks for the reply. I didn't know that assert conveys information in the analysis phases. Now I understand how the compiler realize about that. The problem with asserts is we undefined them on release mode (the pre-processor will remove them), so the compiler will never see that. Basically I was thinking in something like asserts, but that are only visible for the compiler and don't affect the code. Something like __builtin_assume(x > 0); __builtin_assume(x < 10); where x is a variable. That way the compiler can do better optimizations. Thanks again, I will check again the extensions section of the manual. Regards, 2014-04-23 12:57 GMT-03:00 Jeff Law <law@xxxxxxxxxx>: > 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