Reputation: 6200
You can hint give GCC hints about the likelihood of a particular branch taken by using __builtin_expect
. Without that, does it have any default assumptions. That is, will code like
if(error) { /*unlikely path*/ return FAILURE;}
return SUCCESS;
perform better/worse than
if(!error) {/*likely path*/ return SUCCESS;}
return FAILURE;
Upvotes: 1
Views: 46
Reputation: 780
As any modern compiler, gcc will also perform code analysis. If the code analysis yields any useable / provable information, it chooses some optimization (cf. basic block reordering). gcc will at least perform static code analysis, while clang (maybe using extensions) will also analyze the execution flow graph.
Upvotes: 1