Re: Optimiziation questions (c++)

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

 



NightStrike wrote:

> By using 'max' instead of v.size(), I am eliminating a function call
> from every iteration of the for loop.  If the loop is iterated a large
> number of times, this could have an advantage.  However, is it all the
> same when you are optimizing?  Does g++ remove the need for the second
> method?

The compiler can hoist the condition out of the loop, but only if it can
determine that v is not modified inside the loop.  It might know this if
it can determine that all function calls inside the loop are pure, or if
v is a local auto variable that's not had its address taken.  There
could be other ways it can prove this, I don't know.  It's hard to
really say much in the abstract about what the compiler might or might
not do, because so much depends on the details of the code and the
information that the compiler has on hand.  A testcase is much more
valuable because you can look at the -S output and see for sure.

Brian

[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