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

Reply via email to