This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Incorrect movem optimization on m68k
- To: gcc-bugs at gcc dot gnu dot org
- Subject: Incorrect movem optimization on m68k
- From: Tony Mantler <eek at escape dot ca>
- Date: Thu, 2 Mar 2000 05:13:51 -0600
- Organisation: Judean People's Front; Department of Whips, Chains, Thumb-Screws, Six Tons of Whipping Cream, the Entire Soprano Section of the Mormon Tabernacle Choir and Guest Apperances of Eva Peron aka Eric Conspiracy Secret Laboratories
Hi bug guys,
I've got gcc 2.95.2 (debian package 20000220) running on and compiling for
an m68k mac, and I'm finding that gcc is optimizing away a large chunk of a
rather important movem instruction.
The sample code is as follows:
int main(int argc, char *argv[]) {
long stack[5];
long out;
printf("Pointer: %u\n", &stack[0]);
asm volatile ("moveml %1/%2/%3/%4,%0@-"
: "=a" (out)
: "d" (0), "d" (0), "d" (0), "d" (0), "0" (&stack[4]));
printf("Pointer: %u\n", out);
}
Compiled with 'gcc foo.c -o foo' yields the correct program output:
Pointer: 4026530540
Pointer: 4026530540
'objdump -d foo' shows (note the correct movem instruction):
[...]
800003a8 <main>:
800003a8: 4e56 ffe8 linkw %fp,#-24
800003ac: 48e7 3800 moveml %d2-%d4,%sp@-
800003b0: 70ec moveq #-20,%d0
800003b2: d08e addl %fp,%d0
800003b4: 2f00 movel %d0,%sp@-
800003b6: 4879 8000 0446 pea 80000446 <_IO_stdin_used+0x4>
800003bc: 61ff ffff ff26 bsrl 800002e4 <_init+0x6c>
800003c2: 508f addql #8,%sp
800003c4: 4280 clrl %d0
800003c6: 4281 clrl %d1
800003c8: 4282 clrl %d2
800003ca: 4283 clrl %d3
800003cc: 78ec moveq #-20,%d4
800003ce: d88e addl %fp,%d4
800003d0: 2044 moveal %d4,%a0
800003d2: 43e8 0010 lea %a0@(16),%a1
800003d6: 2049 moveal %a1,%a0
800003d8: 48e0 f000 moveml %d0-%d3,%a0@-
800003dc: 2008 movel %a0,%d0
800003de: 2d40 ffe8 movel %d0,%fp@(-24)
800003e2: 2f2e ffe8 movel %fp@(-24),%sp@-
800003e6: 4879 8000 0446 pea 80000446 <_IO_stdin_used+0x4>
800003ec: 61ff ffff fef6 bsrl 800002e4 <_init+0x6c>
800003f2: 508f addql #8,%sp
800003f4: 4cee 001c ffdc moveml %fp@(-36),%d2-%d4
800003fa: 4e5e unlk %fp
800003fc: 4e75 rts
800003fe: 4e75 rts
[...]
Compiled with 'gcc -O foo.c -o foo' yields incorrect program output:
Pointer: 4026530524
Pointer: 4026530536
and 'objdump -f foo' shows why (note the incorrect shortened movem
instruction):
[...]
800003a8 <main>:
800003a8: 4e56 ffec linkw %fp,#-20
800003ac: 2f0a movel %a2,%sp@-
800003ae: 486e ffec pea %fp@(-20)
800003b2: 4879 8000 0422 pea 80000422 <_IO_stdin_used+0x4>
800003b8: 45f9 8000 02e4 lea 800002e4 <_init+0x6c>,%a2
800003be: 4e92 jsr %a2@
800003c0: 4280 clrl %d0
800003c2: 41ee fffc lea %fp@(-4),%a0
800003c6: 48e0 8000 moveml %d0,%a0@-
800003ca: 2f08 movel %a0,%sp@-
800003cc: 4879 8000 0422 pea 80000422 <_IO_stdin_used+0x4>
800003d2: 4e92 jsr %a2@
800003d4: 246e ffe8 moveal %fp@(-24),%a2
800003d8: 4e5e unlk %fp
800003da: 4e75 rts
[...]
Perhaps I'm asking too much for the contents of an asm volatile macro to
appear in the final binary as it appears in the code file, ;P but since it
breaks the linux kernel (see include/video/fbcon.h) I think it deserves a
fix.
Cheers - Tony :)
--
Tony Mantler Renaissance Nerd Extraordinaire eek@escape.ca
Winnipeg, Manitoba, Canada http://www.escape.ca/~eek