Re: while loop code generation

preston@tera.tera.com (Preston Briggs)
3 Jan 1998 16:31:14 -0500

          From comp.compilers

Related articles
while loop code generation ast@halcyon.com (1997-12-14)
Re: while loop code generation gclind01@spd.louisville.edu (1997-12-15)
Re: while loop code generation burley@cygnus.com (Craig Burley) (1997-12-15)
Re: while loop code generation tgl@netcom.com (Tom Lane) (1997-12-15)
Re: while loop code generation n8tm@aol.com (1997-12-15)
Re: while loop code generation tim@franck.Princeton.EDU.composers (1997-12-29)
Re: while loop code generation preston@tera.tera.com (1998-01-03)
| List of all articles for this month |
From: preston@tera.tera.com (Preston Briggs)
Newsgroups: comp.compilers
Date: 3 Jan 1998 16:31:14 -0500
Organization: /etc/organization
References: 97-12-112 97-12-117 97-12-167
Keywords: optimize, code

>> On page 227 of Fraser and Hanson's _A Retargetable C Compiler_,
>> they claim that the code
>> goto L+1
>> L: statement
>> L+1: if expression != 0 goto L
>> L+2:
>
>This technique is also often important when generating code for
>virtual machines, since with the 'obvious' opcodes, it saves an
>instruction. ...


All true, but there's a better way.


if expression == 0 goto L1
L: statement
if expression != 0 goto L
L1: ...


Sure, we have to replicate the test, but we save executing an
instruction. Sort of an obvious peephole fixup (remove jump-to-jump),
but I'd generate intermediate code for use by the optimizer in this
same fashion. Why? Because it creates a place to hang loop-invariant
code. The original code is less obvious in this respect.


Preston Briggs
--


Post a followup to this message

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