shep@ALLSPICE.LCS.MIT.EDU (Tim Shepard) (03/21/89)
gcc-1.34 on 4.3bsd vax, foo.c (below) compiled with "gcc -S -O -c foo.c" Note the two addl3's with identical sources before L9: below. Note how r5 and r6 are subsequently each only used once. It looks like code has been moved out of the loop from two different basic blocks in the inner loop, but it doesn't look like cse ever got a crack at it. I do appreciate the fine balance between an optimizer looping forever and being very thorough. I won't complain too much if gcc is not improved to catch this case. -Tim foo.c: ----------------------cut here---------------- int nums[4][4]; int foo() { int i,j; int h = 0; int t = 0; for(i=0;i<4;i++) { for (j=0;j<4;j++) if (nums[i][j] < 0) { h += t; t = 0; } else { t *= 10; t += nums[i][j]; } h += t; } return h; } --------------------cut here------------------- foo.s: -----------------------cut here----------------- #NO_APP gcc_compiled.: .text .align 1 .globl _foo _foo: .word 0xc0 clrl r3 clrl r1 clrl r4 movab _nums,r7 L10: clrl r2 ashl $4,r4,r0 addl3 r7,r0,r6 addl3 r7,r0,r5 L9: tstl (r6)[r2] jgeq L7 addl2 r1,r3 clrl r1 jbr L6 L7: moval (r1)[r1],r0 addl3 r0,r0,r1 addl2 (r5)[r2],r1 L6: incl r2 cmpl r2,$3 jleq L9 addl2 r1,r3 incl r4 cmpl r4,$3 jleq L10 movl r3,r0 ret .comm _nums,64 -------------------------cut here---------------------