This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: a question about code optimization


John Love-Jensen åé:
Hi,

So my questions is:
is gcc *smart* enough that she can determine when to do the optimization?

Yes.


GCC can do the optimization when the optimizer has sufficient information to
be certain that there are no side effects.

GCC can not do the optimization when there is a black-box routine involved.
Although there may be some aspects outside of the black-box routine that may
be optimized.

There is another compiler, LLVM, that does holistic optimizations.  If I
recall correct, there is an effort to add (or perhaps merely to investigate
adding) holistic optimizations into GCC.
thanks for your patient answer :)

another question:

--------code begin----------------
vector<int> a;
...
for(int i = 0; i < a.size(); i++)
{
	/*do something*/
}
-------code end---------------------

i asked that if this can be optimized to this:
----------code begin--------------
vector<int> a;
...
int size = a.size();
for(int i = 0; i < size; i++)
{
	/*do something*/
}
----------code end-----------------

last time we discussed one situation may influence the optimization:

a) in function size() we may change some global variables.

there is another situation:

b) in the /*do something*/ block, we may use a.push_back(...) or some other functions
that can change the size of a. if this happen, of course we can not do the optimization.

so can gcc know what functions may change the size of a?
is gcc smart enough to optimize the code if those functions are not used?

i am sorry because i am not familiar with the optimization term.



--Eljay




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]