delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1994/10/14/02:32:50

Date: Fri, 14 Oct 94 09:57:24 JST
From: Stephen Turnbull <turnbull AT shako DOT sk DOT tsukuba DOT ac DOT jp>
To: eliz AT is DOT elta DOT co DOT il
Cc: OKRA AT max DOT tiac DOT net, djgpp AT sun DOT soe DOT clarkson DOT edu
Subject: this is optimization?

   >   I was going over the asm output of a program and I came across this 
   > little snippet:

   I'm not sure about this, but can it be that the asm output is
   generated *before* the optimizer does its thing?

No, no.  Think a sec.  (Or watch what happens under -O using -v.)
    Note that the GNU optimizer is platform independent.  Thus the
assembler's code translator has to come in different versions for
Sparc, 386, 68k, MIPS, and Alpha, but the rest of the compiler suite,
including the optimizer, does not (or not very much).  So what happens
is that the optimizer mangles a platform-independent intermediate form
of code (C for the GNU optimizer, proprietary compilers often use
proprietary codes---this is the only reasonable way to implement
global optimization without platform dependence), and these get
translated into platform-dependent stereotyped sequences.  These
stereotyped sequences often need to protect certain values or make
them available in stereotyped places on some platforms but not on
others.  But if what the program is really interested in is some side
effect of a function, a useless register op will get generated.  (Eg,
many C functions are declared as returning non-void, either implicitly
int---bad practice!---or explicitly---as in the string library, but
callers rarely use the value.  The "optimized code" will often show
the value being moved into some standard place for return values,
typically eax.  Casting such a call to void might help the code
generator, but it might not.)  Since the platform independent
optimizer doesn't know the peculiarities of each machine, it can't do
anything about such infelicities.
    OTOH, a local, AKA peephole, optimizer, looks at the generated
code in assembler/machine form and eliminates such sequences of ops.
    Bottom line is the GCC optimizer never sees the generated
assembler, or it sould be smarter about register thrashing.  I think
BTW that this kind of thing is less common (or easier to avoid) on
elegant architectures like the 68k series.  That's why bit-flickers
like it.
    --Steve

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019