public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: 龙海涛 <longhaitao@otsc.com.cn>
To: John Love-Jensen <eljay@adobe.com>
Cc: MSX to GCC <gcc-help@gcc.gnu.org>
Subject: Re: a question about code optimization
Date: Wed, 09 Jan 2008 17:06:00 -0000	[thread overview]
Message-ID: <47842617.6010004@otsc.com.cn> (raw)
In-Reply-To: <C3A2317F.29C3B%eljay@adobe.com>

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
> 

  reply	other threads:[~2008-01-09  1:40 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <C3A0E1D1.29B03%eljay@adobe.com>
2008-01-04 14:38 ` 龙海涛
2008-01-05 14:25   ` John Love-Jensen
2008-01-09 17:06     ` 龙海涛 [this message]
2008-01-09 23:03       ` 龙海涛
2008-01-10 19:51       ` John Love-Jensen
2007-12-22  5:41 龙海涛
2007-12-22 10:20 ` Christoph Bartoschek
2007-12-25  3:00   ` 龙海涛

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=47842617.6010004@otsc.com.cn \
    --to=longhaitao@otsc.com.cn \
    --cc=eljay@adobe.com \
    --cc=gcc-help@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).