Transform assertion into optimization hints
Marc Glisse
marc.glisse@inria.fr
Tue Sep 18 06:11:00 GMT 2018
On Tue, 18 Sep 2018, François Dumont wrote:
> If your concern is rather that the condition got evaluated which will
> eventually slow down execution then I need to check generated code. Any good
> link explaining how to have a clear view on the generated code ?
This.
For a file like
#include <map>
void f();
void g(std::map<int,int> const&m){
if(m.count(42)>0)__builtin_unreachable();
f();
}
compiled with g++ file.c -O3 -S -fdump-tree-optimized, I get a
file.c.228t.optimized that contains quite a lot of code, not just a call
to f.
> Maybe a 'if __builtin_constant_p(_Condition)' could help if gcc doesn't do it
> itself already.
How would you use that precisely?
It may be easiest to use a different macro for trivial tests that can go
with __builtin_unreachable and for expensive tests that cannot.
--
Marc Glisse
More information about the Libstdc++
mailing list