Re: Gotos

Preston Briggs <preston@rice.edu>
Mon, 13 Nov 89 12:08:47 CST

          From comp.compilers

Related articles
Gotos jhallen@wpi.wpi.edu (1989-11-12)
Re: Gotos preston@rice.edu (Preston Briggs) (1989-11-13)
Re: Gotos bright@dataio.Data-IO.COM (1989-11-17)
| List of all articles for this month |
Date: Mon, 13 Nov 89 12:08:47 CST
From: Preston Briggs <preston@rice.edu>
Newsgroups: comp.compilers
In-Reply-To: <1989Nov12.222530.14148@esegue.segue.boston.ma.us>
Organization: Rice University, Houston

In article <1989Nov12.222530.14148@esegue.segue.boston.ma.us> you write:
>How much of an effect do gotos have on register and other optimization
>techniques? In particular, do C optimizing compilers take a simple minded
>view towards gotos or does data flow analysis actually follow goto paths?
>
>The reason I ask is, I know some compilers (WATCOM C compiler on IBM PCs I
>think is one) combine common endings:


"tail merging" or "cross jumping"


>But mine doesn't. So is it better to just let the code be duplicated or
>is it o.k. to use gotos to prevent the duplication:


Coloring register allocators don't have any special problem with goto's.
Generally, global (within a procedure) optimizations require data flow
analysis, and the point of the analysis is not to be confused by the
flow graph.


On the other hand, goto's can degrade the optimization.
In your example,




xxx yyy
zzz zzz
| |
\ /
-------------
|
V


converted into


xxx yyy
| |
\ /
-------------
|
zzz
|
V


lowers the effectiveness of value numbering and constant propagation
on "zzz." Additionally, the register allocation may be slightly worse
since the graph could have become more contrained.


(If xxx and yyy define a register used in zzz, tail merging will
  force the register allocator to use the same register in both
  xxx and yyy. This doesn't sound too bad, but it's a loss and the
  losses accumulate.)


Basically, I would avoid tail-merging in the source (and goto's in general).
The only payoff is in code space and there's a speed penalty.
In a compiler, I would only do it at the last second (after register
allocation) if at all.


Do any of the IBM PC-class C compilers do global optimizations?
Global constant propagation? Graph coloring register allocation?


Preston Briggs
preston@titan.rice.edu
[The Metaware compilers are reputed to do graph coloring, though it's a
trick to make it work on something as asymmetrical as a 286. Also, I wonder
if one can do useful graph coloring without infringing IBM's patents. -John]





Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.