🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.gcc.bug
Article #2491

wasteful stack allocation

#2491
From: Drazen Borkovic
Date: Fri, 31 Mar 1989 00:19
59 lines
1969 bytes
Gcc 1.34 does not reuse space on stack that was used by
variable local to the block that has ended.

Variables k and kk in the bl.c could exist in the same place
on stack, but gcc allocates separate words for each of them.
Although not wrong, this is wasteful. 

Sun cc reuses that space.

======================================================================
Script started on Thu Mar 30 14:24:52 1989
!21 mars:c -> cat bl.c


void f (j)
  int j;
{
  int i;
  {
    int k;

    i = k+j;
  }
  {
    int kk;

    i = kk+j;
  }
}
!22 mars:c -> gcc -ansi -pedantic -Wall -Wwrite-strings -v -S bl.c
gcc version 1.34
 /usr/local/lib/gcc-cpp -v -undef -D__GNUC__ -T -$ -D__STRICT_ANSI__ -D__mc68000__ -D__sun__ -D__unix__ -pedantic -Wall -D__HAVE_68881__ bl.c /tmp/cca26952.cpp
GNU CPP version 1.34
 /usr/local/lib/gcc-cc1 /tmp/cca26952.cpp -quiet -dumpbase bl.c -Wall -Wwrite-strings -pedantic -ansi -version -o bl.s
GNU C version 1.34 (68k, MIT syntax) compiled by GNU C version 1.34.
!23 mars:c -> cat bl.s
#NO_APP
gcc_compiled.:
.text
        .even
.globl _f
_f:
        link a6,#-12
        movel a6@(-8),d0  # int k
        addl a6@(8),d0
        movel d0,a6@(-4)
        movel a6@(-12),d0  # int kk
        addl a6@(8),d0
        movel d0,a6@(-4)
L1:
        unlk a6
        rts
!24 mars:c -> exit

script done on Thu Mar 30 14:25:34 1989
======================================================================

Drazen Borkovic, Caltech 256-80, Pasadena, CA 91125      
e-mail: drazen@vlsi.caltech.edu 
Technical Details
Message-ID: <8903310019.AA00288@vlsi.caltech.edu>
Path: arc1-ca.pugleaf.net!utzoo!telly!attcan!dptcdc!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!VLSI.CALTECH.EDU!drazen

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!telly!attcan!dptcdc!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!VLSI.CALTECH.EDU!drazen
From: drazen@VLSI.CALTECH.EDU (Drazen Borkovic)
Newsgroups: gnu.gcc.bug
Subject: wasteful stack allocation
Message-ID: <8903310019.AA00288@vlsi.caltech.edu>
Date: 31 Mar 89 00:19:54 GMT
Sender: daemon@tut.cis.ohio-state.edu
Distribution: gnu
Organization: GNUs Not Usenet
Lines: 59