Path: utzoo!telly!ddsw1!lll-winken!uunet!tut.cis.ohio-state.edu!osu-cis!mstar!karl From: karl@mstar.UUCP (Karl Fox) Newsgroups: gnu.gcc.bug Subject: gcc 1.28 optimization problem on m68k Message-ID: <933@mstar.UUCP> Date: 22 Sep 88 22:26:17 GMT Distribution: gnu Organization: Morning Star Technologies Inc, Columbus, OH Lines: 53 The following program is improperly optimized by gcc-1.28, using config-m68k.h, m68k.md, output-m68k.h and our own test tm.h that includes tm-m68k.h: % cat x.c int a = 0xE4; main() { register int b = a; printf("0x%X %d\n", b, (b & 0xF) + ((b >> 4) & 0xF)); } With -O, it prints "0xE4 2". Without -O, it prints "0xE4 18", the correct result. Looking at the assembler shows that it assumed that ((b & 0xF) + ((b >> 4) & 0xF)) == (((b >> 4) + b) & 0xF): % gcc -v -O -S x.c gcc version 1.28 /usr/local/lib/gcc-cpp -v -undef -D__GNU__ -D__GNUC__ -Dmc68000 -Dmasscomp -Dmc500 -Dunix -Dm68k -D_ATT -D__OPTIMIZE__ x.c /tmp/cca12047.cpp GNU CPP version 1.28 /usr/local/lib/gcc-cc1 /tmp/cca12047.cpp -quiet -dumpbase x.c -O -version -o x.s GNU C version 1.28 (68k, MIT syntax) compiled by GNU C version 1.28. % cat x.s #NO_APP .globl _a .data .even _a: .long 228 .text LC0: .ascii "0x%X %d\12\0" .even .globl _main _main: link a6,#0 move.l d2,sp@- move.l _a,d0 move.l d0,d1 asr.l #4,d1 add.l d0,d1 moveq #15,d2 and.l d2,d1 move.l d1,sp@- move.l d0,sp@- pea LC0 jbsr _printf move.l a6@(-4),d2 unlk a6 rts -- Karl Fox, Morning Star Technologies ...!{att,osu-cis,pyramid}!mstar!karl