[gnu.gcc.bug] missed optimization with gcc 1.36

andy@CSVAX.CALTECH.EDU (Andy Fyfe) (02/09/90)

I wrote the following code to implement the asni ldiv function:
    typedef struct {
	long quot;
	long rem;
    } ldiv_t;

    ldiv_t
    ldiv(long a, long b)
    {
	ldiv_t r;

	__asm__("divsl%.l %3,%0:%1"
	    : "=r" (r.rem), "=r" (r.quot) : "1" (a), "g" (b));

	return r;
    }

The code produced by "gcc -O" is correct, but the "divsl" instruction
is followed by 4 redundant moves (and hence an unnecessary save and
restore of a register).  Here is the assembler output of gcc:
    #NO_APP
    gcc_compiled.:
    .text
	    .even
    .globl _ldiv
    _ldiv:
	    link a6,#0
	    movel d2,sp@-
	    movel a6@(8),d0
    #APP
	    divsll a6@(12),d1:d0
    #NO_APP
	    movel d1,d2
	    movel d0,d1
	    movel d1,d0
	    movel d2,d1
	    movel a6@(-4),d2
	    unlk a6
	    rts

[Aside: The sun optimizer, /lib/c2, removes the 4 moves.]