Georg-Johann Lay wrote: > Andrew Haley schrieb: >> Georg-Johann Lay wrote: >>> David Hagood schrieb: >>>> On Sun, 2009-06-07 at 12:00 +0200, Georg-Johann Lay wrote: >>>>> in the test cases >>>>> >>>>> register unsigned char reg2 asm ("r2"); >>>>> As gcc 3.4.6 behaves as expected (e.g. in bar, the access to reg2 >>>>> remains in the loop), I wonder if this aggressive optimization is a >>>>> bug? >>>>> IMO that is a bug because reg2 is a fixed register and should >>>>> therefore be treated just like volatile. Unfortunately, gcc has >>>>> nothing like REG_VOLATILE_P to tag a reg being volatile, but as I >>>>> said global fixed registers should be treated that way. >>>> Try adding a volatile to the variable: >>>> >>>> register volatile unsigned char reg2 asm ("r2"); >>> That has no effect. Note that register is not a mem. Older versions of >>> gcc reported a warning on volatile register like "effect is not what you >>> might expect". Moreover, gcc cannot track volatile registers. >>> rtl.h reads: >>> >>> /* 1 in a MEM or ASM_OPERANDS expression if the memory reference is >>> volatile. >>> 1 in an INSN, CALL_INSN, JUMP_INSN, CODE_LABEL, BARRIER, or NOTE >>> if it has been deleted. >>> 1 in a REG expression if corresponds to a variable declared by the >>> user, >>> 0 for an internally generated temporary. >>> 1 in a SUBREG with a negative value. >>> 1 in a LABEL_REF, REG_LABEL_TARGET or REG_LABEL_OPERAND note for a >>> non-local label. >>> In a SYMBOL_REF, this flag is used for machine-specific >>> purposes. */ >>> unsigned int volatil : 1; >>> >>> What gcc knows is that some registers are or may be fixed, so it should >>> care about that. >> >> Surely if you're using a global register as a mailbox, all you have to do >> is read/write it with volatile asms. > > That does not work. The generated code is /exactly/ the same. Can you show a test case that use volatile asms, please? I am very surprised that does not work. > I did not write "register volatile" in my original post because volatile > is just syntactic sugar together with register. It is confusing and > misleading to use volatile together with register because gcc ignores it > and does not even report a warning. Indeed not, no. "register volatile" makes no sense. I don't see how volatile asm statements would fail, though. Andrew.