Hi,
in the test cases
register unsigned char reg2 asm ("r2");
void foo (void)
{
while (1)
{
while (x);
reg2 = 0;
while (!x);
}
}
void bar (void)
{
while (1)
reg2 = 0;
}
gcc 4.3.2 optimizes away the accesses to the global variable reg2 that
lives in general purpose reg r2.
Compiled with
avr-gcc -Os -ffixed-2
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?
The test case is a simplified excerpt of an application that uses global
register variables for communication with an interrupt service routine
(ISR).
This helps to improve the performance of a time critical, real-time
embedded application and works fine with gcc 3.4.6, but with 4.3.2 CSE
decides that reg2 is dead. The evil happens in rtl-optimize pass cse1.
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.
Without that feature gcc 4 is unsuitable for that application and global
registers are pretty much useless in asynchronous applications. A pity.
I did not try what avr-gcc 4.5 does, because it failed to compile (some
trunk revision).
Georg-Johann