This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: bug or feature? CSE optimizes away global, fixed register


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.

I don't disgree that this is a bug, but it it a very unusual case.

Andrew.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]