🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.gcc.bug
Article #2861

missed optimization with gcc 1.36 (sun3)

#2861
From: Andy Fyfe
Date: Fri, 09 Feb 1990 09:55
41 lines
1291 bytes
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.]
Technical Details
Message-ID: <9002090955.AA07499@csvax.caltech.edu>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!clyde.concordia.ca!uunet!tut.cis.ohio-state.edu!CSVAX.CALTECH.EDU!andy

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!clyde.concordia.ca!uunet!tut.cis.ohio-state.edu!CSVAX.CALTECH.EDU!andy
From: andy@CSVAX.CALTECH.EDU (Andy Fyfe)
Newsgroups: gnu.gcc.bug
Subject: missed optimization with gcc 1.36 (sun3)
Message-ID: <9002090955.AA07499@csvax.caltech.edu>
Date: 9 Feb 90 09:55:02 GMT
Sender: daemon@tut.cis.ohio-state.edu
Distribution: gnu
Organization: GNUs Not Usenet
Lines: 41