loop: will this optimize?

pieniek edek.pienkowski@gmail.com
Thu Apr 14 17:05:00 GMT 2011


Hi,

if a loop contains if-s on a constant boolean, will gcc create two loop 
versions, for the boolean being true and the boolean being false, if the 
boolean switches on some heavy code (in this case, costly debugging 
code)? The boolean in question being not a template param or not really 
const either, just constant during the loop run.

I do understand that if the boolean is off (no heavy code) this does 
boils down to a couple of jumps not taken or taken, but, with these ifs 
removed, the loop can benefit from things like vectorisation. Right?

So, the question rephrased, is there any benefit of templating some 
function containing a loop based on the bool value (or writing the code 
in both versions anyhow)? The goal would be to make the fast (call it 
release) version of the loop really fast.

Edek



More information about the Gcc-help mailing list