It seems there is again serious problem with peephole optimization in CodeWarrior for ColdFire 7.2
Compilation of simple program:
typedef struct {
uint32 Start;
uint32 Length;
} Objects_type;
Objects_type Objects[1024];
int main(void)
{
int k = 15;
Objects[k].Length |= 0x80000000;
}
with peephole "on" and Level1 optimization results in incorrect result:
; 24: Objects[k].Length |= 0x80000000;
; 25:
; 26:
;
0x00000004 0x41F900000000 lea _Objects,a0
0x0000000A 0x7207 moveq #7,d1
0x0000000C 0x03F01804 bset d1,(4,a0,d1.l)
The sequence above ignores value of "k" and modifies beginning of the table.
With the peephole "off" the result is O.K:
; 24: Objects[k].Length |= 0x80000000;
; 25:
; 26:
;
0x00000004 0x720F moveq #15,d1
0x00000006 0xE789 lsl.l #3,d1
0x00000008 0x41F900000000 lea _Objects,a0
0x0000000E 0x41F01804 lea (4,a0,d1.l),a0
0x00000012 0x2210 move.l (a0),d1
0x00000014 0x08C1001F bset #31,d1
0x00000018 0x2081 move.l d1,(a0)
;
Am I missing something or after all these problems with peephole in 7.1 we got another version of compiler with faulty optimization ?
The CPU tested is M5249C3.