This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: helping the compiler with asserts-hints to optimize
- From: Jonathan Wakely <jwakely dot gcc at gmail dot com>
- To: Agustin Perez Paladini <agudpp at gmail dot com>
- Cc: Jeff Law <law at redhat dot com>, gcc-help <gcc-help at gcc dot gnu dot org>
- Date: Wed, 23 Apr 2014 17:56:38 +0100
- Subject: Re: helping the compiler with asserts-hints to optimize
- Authentication-results: sourceware.org; auth=none
- References: <CAOjwP-tXR+bxSSQGc2uOgaLGMVWSLb8LKPb81zR-eb7wfA3Umg at mail dot gmail dot com> <5357E302 dot 2000709 at redhat dot com> <CAOjwP-vDO1qmwi8GGi-k4uE2S3gbez-oOKenwc0P8QpL6Ckk4g at mail dot gmail dot com> <CAH6eHdQMAXS09rizvsU=2D8vNDbSwrhi1Xjm6E9kopAKs=ifmg at mail dot gmail dot com>
On 23 April 2014 17:50, Jonathan Wakely wrote:
> On 23 April 2014 17:24, Agustin Perez Paladini wrote:
>> 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.
>
> You can use __buitlin_expect and __builtin_unreachable to do that.
Or just __builtin_unreachable alone
#define ASSUME(X) if (!(X)) __builtin_unreachable()
This tells the compiler X is always true. Isn't that what you want?