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

bobduff@world.std.com (Robert A Duff)
13 May 1997 22:54:47 -0400

          From comp.compilers

Related articles
[6 earlier articles]
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)
Re: how to generate code for (a,b):=(b,a) Dave@occl-cam.demon.co.uk (Dave Lloyd) (1997-05-22)
Re: how to generate code for (a,b):=(b,a) Dave@occl-cam.demon.co.uk (Dave Lloyd) (1997-05-22)
[5 later articles]
| List of all articles for this month |

From: bobduff@world.std.com (Robert A Duff)
Newsgroups: comp.compilers
Date: 13 May 1997 22:54:47 -0400
Organization: The World Public Access UNIX, Brookline, MA
References: 97-05-058 97-05-129 97-05-148
Keywords: optimize, code, GC

In article 97-05-148,
Paul Wilson <wilson@cs.utexas.edu> wrote:
>> 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.


IMHO, this is the fault of the GC, not the compiler. So-called
"conservative" GC's are supposed to work properly in "hostile"
environments. In this case, the compiler is doing something perfectly
valid according to the language definition (and might in fact be a
useful optimization).


If the GC and the compiler have a contract between them, then all is
well. If the GC wants to go around collecting garbage according to what
it *thinks* the compiler might do, well, I have no sypathy for the GC
when it's wrong.


- Bob
[Conservative GC has to make a lot of tradeoffs -- if you were being 100%
conservative, it couldn't ever free anything since any chunk of apparently
free memory might have had a pointer arbitrarily disguised or written to a
file. Real programs rarely do things like that, which is why conservative
GC works well in practice even though it can be confused by non-pointer
values that look like pointers. As someone else already noted, unless you
have GC in preemptive threads this actually isn't a problem since all of
the xored pointers will be gone before the GC has a chance to run. -John]


--


Post a followup to this message

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