Put your code... (was Re: gotos

Rahul Dhesi dhesi at bsu-cs.UUCP
Fri Apr 29 13:54:29 AEST 1988


In article <1988Apr27.164212.12535 at utzoo.uucp> henry at utzoo.uucp (Henry
Spencer) writes:

>It doesn't take much of an optimizer
>to notice that the instruction sequences preceding an unconditional control-
>flow merge are identical, and condense them into one by branching to the
>beginning of the sequence rather than the end.  Any peephole optimizer
>worthy of the name ought to be willing to do this.

My reading of the original article by kenny at uiucdcsb.cs.uiuc.edu is
that kenny's example (a CPU simulator) would duplicate code in such a
way that a peephole optimizer would not find it.  A peephole optimizer
scans the code through a window of limited size, and rearranges code in
that window so that the net effect of the window remains unchanged.  I
don't think you can remove duplicate code in different places this
way.

Perhaps one could write a special-case optimizer that works only on
switch statements, looking for and eliminating duplicate code preceding
break statements.  But if such duplicate code occurs only rarely,
having everybody's compiler include such an optimizer may be overkill,
and it might prove far simpler to do the optimization manually (i.e.,
using gotos) and keep the optimizer simple.
-- 
Rahul Dhesi         UUCP:  <backbones>!{iuvax,pur-ee,uunet}!bsu-cs!dhesi



More information about the Comp.lang.c mailing list