Re: how to generate code for (a,b):=(b,a)

Christopher Glaeser <cdg@nullstone.com>
13 May 1997 22:46:30 -0400

          From comp.compilers

Related articles
[4 earlier articles]
Re: how to generate code for (a,b):=(b,a) Robert.Harley@inria.fr (1997-05-08)
Re: how to generate code for (a,b):=(b,a) dlmoore@ix.netcom.com (David L Moore) (1997-05-08)
Re: how to generate code for (a,b):=(b,a) preston@cs.rice.edu (1997-05-08)
Re: how to generate code for (a,b):=(b,a) cliffc@risc.sps.mot.com (Cliff Click) (1997-05-12)
Re: how to generate code for (a,b):=(b,a) wilson@cs.utexas.edu (1997-05-12)
Re: how to generate code for (a,b):=(b,a) tim@wfn-shop.Princeton.EDU (1997-05-13)
Re: how to generate code for (a,b):=(b,a) cdg@nullstone.com (Christopher Glaeser) (1997-05-13)
Re: how to generate code for (a,b):=(b,a) genew@vip.net (1997-05-13)
Re: how to generate code for (a,b):=(b,a) bobduff@world.std.com (1997-05-13)
Re: how to generate code for (a,b):=(b,a) will@ccs.neu.edu (William D Clinger) (1997-05-17)
Re: how to generate code for (a,b):=(b,a) wilson@cs.utexas.edu (1997-05-17)
Re: how to generate code for (a,b):=(b,a) boehm@mti.mti.sgi.com (Hans-Juergen Boehm) (1997-05-17)
Re: how to generate code for (a,b):=(b,a) boehm@mti.mti.sgi.com (Hans-Juergen Boehm) (1997-05-17)
[7 later articles]
| List of all articles for this month |
From: Christopher Glaeser <cdg@nullstone.com>
Newsgroups: comp.compilers
Date: 13 May 1997 22:46:30 -0400
Organization: Nullstone Corporation
References: 97-05-058 97-05-129 97-05-148
Keywords: optimize, code

Paul Wilson wrote:


> >When you don't have any free registers, it should be possible to achieve
> >the same result with a series of xors instead of moves. For example, two
> >registers can be exchanged with the sequence:
> > xor a,b
> > xor b,a
> > xor a,b
>
> This is very likely to confuse a conservative garbage collector if
> these are pointer variables. I'd hope that compiler writers wouldn't
> use such optimizations casually, especially if they're not clearly
> better than the alternatives.


Yes, if the xor's are expanded in the IL, it can confuse the optimizer,
but there are other ways to implement this so the intent of the
operation (i.e. swap the contents of a and b) is preserved and obvious.
For example, a new "swap" pseudo instruction could be added to the IL
which is expanded by the codegenerator or assembler. Of course, there
are still scheduling implications, but no extra registers are needed,
and the optimizer should be able to track the values through the swap
instruction.


Best regards,
Christopher Glaeser cdg@nullstone.com
Nullstone Corporation http://www.nullstone.com
--


Post a followup to this message

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