Re: loop: will this optimize?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



pieniek <edek.pienkowski@xxxxxxxxx> writes:

> 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.

This optimization is called loop unswitching.  You can enable it in gcc
with the -funswitch-loops option.  This option is turned on by -O3, but
not by -O2.

Ian


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux