Boost logo

Boost-Build :

From: Jim Babcock (jbabcock_at_[hidden])
Date: 2007-07-16 11:35:42

Chris Fairles wrote:
> Just so we're clear, here's the descriptions of the extra
> optimizations -O3 turns on.
> -funswitch-loops
> Move branches with loop invariant conditions out of the loop, with
> duplicates of the loop on both branches (modified according to result
> of the condition).
> So, for example:
> for i = 0 ... 100
> if (a > 0) f(i);
> else g(i);
> end for
> can become:
> if (a > 0)
> for i = 0..100
> f(i)
> end for
> else
> for i = 0..100
> g(i)
> end for
> end if
> It doubles code which can be an issue for embedded platforms but
> hopefully they're using -Os anyway. I can't conjure up a scenario
> where this might cause code to run slower.

There are lots of cases where this will run slower. Bigger code uses
more cache space, which can mean that things you want cached, aren't.
If the loop only runs for a few iterations, then expanding it this way
will trade a few cheap compares for a few expensive memory accesses.
It will also cause the program to take longer to load from disk, which
for most programs is the main bottleneck.

Boost-Build list run by bdawes at, david.abrahams at, gregod at, cpdaniel at, john at