Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!uunet!snorkelwacker!spdcc!ima!esegue!compilers-sender From: jhallen@wpi.wpi.edu (Joseph H Allen) Newsgroups: comp.compilers Subject: Gotos Message-ID: <1989Nov12.222530.14148@esegue.segue.boston.ma.us> Date: 12 Nov 89 22:25:30 GMT Sender: compilers-sender@esegue.segue.boston.ma.us Reply-To: jhallen@wpi.wpi.edu (Joseph H Allen) Organization: Worcester Polytechnic Institute, Worcester, Mass. Lines: 52 Approved: compilers@esegue.segue.boston.ma.us 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: if( ) { XXX YYY <-------+----- These don't get duplicated return; | } | else | { | ZZZ | YYY <-------+ return; } 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: if( ) { XXX goto here; } else { ZZZ here: YYY return; } (Please ignore the fact that for this example you can just move the 'YYY return' outside the if construct. Assume that it is a more complicated case where you just can't do that) Joe [Depends on the compiler; I've seen some that depend on loops in the source code and punt if gotos change it at all, and I've seen others that turn everything into low-level gotos in intermediate code and then rediscover the control structure from that. Comments from actual compiler writers are welcome. The last C compiler I wrote was the original PCC for the RT PC and it avoided the problem by doing almost no optimization at all. The assembler postpass did tail merging, but at the time we hadn't ported it. -John] -- Send compilers articles to compilers@esegue.segue.boston.ma.us {spdcc | ima | lotus}!esegue. Meta-mail to compilers-request@esegue. Please send responses to the author of the message, not the poster.