When compiling the following function for a coldfire target, such as mcf5249: (using the following command line: m68k-elf-gcc saturate.c -mcpu=5249 -O1 -S)
int saturate(int x) { return (x == (short)x ? x : (x >> 31) ^ 0x7FFF); } gcc produces: saturate: link.w %fp,#0 move.l 8(%fp),%d0 move.w %d0,%a0 cmp.l %a0,%d0 jeq .L2 add.l %d0,%d0 subx.l %d0,%d0 eor.l #32767,%d0 .L2: unlk %fp rts Where a0 is compared to d0 without a sign extension so the upper half of a0 remtains whatever was already there. This is with gcc: 4.5.0 20100401 (experimental) (GCC) configured with: --target=m68k-elf --prefix=/usr/local --enable-languages=c --disable-libssp --with-arch=cf --with-cpu=5249 Also observed with gcc 3.4.6 so likely not a regression. -- Summary: [m68k] Wrong code due to missing sign extension Product: gcc Version: 4.5.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: target AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: nizze86 at hotmail dot com GCC target triplet: m68k-elf-* http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43676