[gnu.gcc.bug] Gnu C Compiler 1.30's strength reduction is too strong

ado@NCIFCRF.GOV (Arthur David Olson) (11/13/88)

(We're running SunOS 4.0 on a Sun 3/110.)

Description:
	The Gnu C Compiler (version 1.30)'s -fstrength-reduce option sometimes
	produces incorrect code.

Repeat-By:
	Script started on Sat Nov 12 14:26:28 1988
	elsie$ cat try.c
	int
	main()
	{
		int	i, j;

		i = 0;
		for ( ; ; ) {
			printf("%d\n", i);
			++i;
			for (j = 0; j < 1; ++j)
				++i;
		}
	}
	elsie$ gcc -v -O try.c
	gcc version 1.30
	 /usr/local/lib/gcc-cpp -v -undef -D__GNU__ -D__GNUC__ -Dmc68000 -Dsun -Dunix -D__OPTIMIZE__ -D__HAVE_68881__ -Dmc68020 try.c /tmp/cca19947.cpp
	GNU CPP version 1.30
	 /usr/local/lib/gcc-cc1 /tmp/cca19947.cpp -quiet -dumpbase try.c -O -version -o /tmp/cca19947.s
	GNU C version 1.30 (68k, MIT syntax) compiled by GNU C version 1.30.
	 as -mc68020 /tmp/cca19947.s -o try.o
	 ld -e start -dc -dp /lib/crt0.o /lib/Mcrt1.o try.o /usr/local/lib/gcc-gnulib -lc
	elsie$ a.out | head -2
	0
>>>>	2
	elsie$ gcc -v -O -fstrength-reduce try.c
	gcc version 1.30
	 /usr/local/lib/gcc-cpp -v -undef -D__GNU__ -D__GNUC__ -Dmc68000 -Dsun -Dunix -D__OPTIMIZE__ -D__HAVE_68881__ -Dmc68020 try.c /tmp/cca19954.cpp
	GNU CPP version 1.30
	 /usr/local/lib/gcc-cc1 /tmp/cca19954.cpp -quiet -dumpbase try.c -fstrength-reduce -O -version -o /tmp/cca19954.s
	GNU C version 1.30 (68k, MIT syntax) compiled by GNU C version 1.30.
	 as -mc68020 /tmp/cca19954.s -o try.o
	 ld -e start -dc -dp /lib/crt0.o /lib/Mcrt1.o try.o /usr/local/lib/gcc-gnulib -lc
	a.elsie$ a.out | head -2
	0
>>>>	1
	elsie$ exit

	script done on Sat Nov 12 14:27:22 1988

	Note the changed output on the lines marked with ">>>>" above.

	For reference, here's a side-by-side difference listing of the
	assembly language produced.

		Script started on Sat Nov 12 14:21:59 1988
		elsie$ gcc -O -S try.c -o try.s-nostrength
		elsie$ gcc -O -S -fstrength-reduce try.c -o try.s-strength
		elsie$ sdiff -w80 try.s-nostrength try.s-strength
		#NO_APP                                   #NO_APP
		.text                                     .text
		LC0:                                      LC0:
			.ascii "%d\12\0"                  	.ascii "%d\12\0"
			.even                             	.even
		.globl _main                              .globl _main
		_main:                                    _main:
			link a6,#0                        	link a6,#0
			movel d2,sp@-                     	movel d2,sp@-
			clrl d2                           	clrl d2
		L2:                                       L2:
			movel d2,sp@-                     	movel d2,sp@-
			pea LC0                           	pea LC0
			jbsr _printf                      	jbsr _printf
			addql #1,d2                       	addql #1,d2
			clrl d0                           	clrl d0
			addqw #8,sp                       	addqw #8,sp
		L8:                                       L8:
			addql #1,d2                    <  
			addql #1,d0                       	addql #1,d0
			andb #0xc,cc                      	andb #0xc,cc
			jle L8                            	jle L8
			jra L2                            	jra L2
			movel a6@(-4),d2                  	movel a6@(-4),d2
			unlk a6                           	unlk a6
			rts                               	rts
		elsie$ exit

		script done on Sat Nov 12 14:23:06 1988
-- 
	Arthur David Olson    ado@ncifcrf.gov    ADO is an Ampex trademark.