I fear that part of the problem is that the dataflow analysis code is somehow flawed, but I have tried everything (except standing on my head while typing) to get around this. Here's the commented code:
All of the following comments are with respect to SDCC 2.2.0a.
The following code shows the creation of an unnecessary temp to compute
the problem expression #1 marked below.
If the type of the variable d2 is "extern data unsigned long", the
generated code (correctly) does not need a temp.
If the type of the variable d2 is "extern data unsigned short", the
generated code (incorrectly) thinks it does need a temp.
Even worse, if the expression is coded as "d0 = d1 + d2 + (a0 >> 9);",
then the argument needs to be put in a temp as well!
However, if expression #2 is coded the "correct" way:
return ((xdata unsigned long*) &xa0)[l0];
then variable l0 requires the temp, but its high byte is ignored(!),
and the calculation in expression #1 is as I would expect.
I don't know if the intervening function calls are involved, but since my code requires them, I've left them in.
extern data unsigned long d0;
extern data unsigned long d1;
extern data unsigned short d2;
extern xdata unsigned char xa0;
extern void f1(void);
extern void f2(void);
extern void f3(void);
unsigned long f0(unsigned long a0)
unsigned short l0 = a0 & 0x7f;
d0 = (a0 >> 9) + d1 + d2; /* #1 */
return *((xdata unsigned long*) &xa0[l0]); /* #2 */
Log in to post a comment.