This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Incrementing volatiles?
- To: egcs at cygnus dot com
- Subject: Incrementing volatiles?
- From: "Matthias Urlichs" <smurf at noris dot de>
- Date: Wed, 8 Jul 1998 23:20:04 +0200
Hi,
The following code, using egcs-current -O2 -fomit-frame-pointer
unsigned int foo; afoo() { foo++; }
volatile unsigned int bar; abar() { bar++; }
compiles, on ix86, to
afoo: incl foo
ret
abar: movl bar,%eax
incl %eax
movl %eax,bar
ret
But actually, it should be perfectly valid to compile both to code using
"incr". After all, both versions read the variable, do something with it,
and then write it out.
Is there a way to convince the optimizer to do this?
(The obvious solution, i.e. "(*(unsigned int *)&bar)++", doesn't count. ;-)
--
Matthias Urlichs
noris network GmbH