Re: Linux 2.0.3x & gcc 2.8 [better use egcs for now]

Martin von Loewis (martin@mira.isdn.cs.tu-berlin.de)
Sat, 7 Feb 1998 01:27:36 +0100


> int f(long e)
> {
> *(&e) = e & 0x1234;
> return 0;
> }
>
> and found that egcs-1.0.1 _never_ optimizes the assignment away (no
> volatile is needed). So, people should maybe use that rather than
> gcc-2.8.0 for compiling 2.0.x.

Well, I get (with a more recent egcs, and with -O2 -fomit-frame-pointer)

.file "opt.c"
.version "01.01"
gcc2_compiled.:
.text
.align 16
.globl f
.type f,@function
f:
xorl %eax,%eax
ret
.Lfe1:
.size f,.Lfe1-f
.ident "GCC: (GNU) egcs-2.91.06 980122 (gcc-2.8.0 release)"

> IMHO, a single assignment to *(&x) can _never_ be optimized away
> (multiple such assignments could be folded into one possibly).

Sure it can. The memory modified is then never referenced again.
So whether it is changed or not is not observable behaviour.

> If such an optimization was allowed, programming threaded code with
> shared stack variables would become a nightmare...

Well, if you share references between threads, you have to mark
them as volatile - whether they are on the stack or not.

OTOH, I agree that programming threaded code is a nightmare :-)

Regards,
Martin
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu