This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: random thought - optimizer
- To: Diego Novillo <dnovillo at redhat dot com>
- Subject: Re: random thought - optimizer
- From: "Zack Weinberg" <zackw at Stanford dot EDU>
- Date: Sun, 1 Jul 2001 20:35:52 -0700
- Cc: gcc at gcc dot gnu dot org
On Sun, Jul 01, 2001 at 11:25:34PM -0400, Diego Novillo wrote:
> >
> > Now, it seems to me that the as-if rule says we could generate instead
> >
> > init:
> > ret
> >
> That would be the wrong code to generate. Variable 'initialized'
> is only set to 0 the first time init() is executed. Subsequent
> calls to init() should see variable 'initialized' set to 1.
You've missed that 'initialized' is local to init() and its address is
never taken. Therefore, the existence and value of 'initialized' are
invisible to the rest of the program. Further, init() does nothing in
either case except set 'initialized'. I believe this means it can be
eliminated.
--
zw A man who has never gone to school may steal from a freight car, but
if he has a university education, he may steal the whole railroad.
-- Theodore Roosevelt