Unnecessary spillage

Trevor Pering <pering@tongass.eecs.berkeley.edu>
Fri, 1 Sep 1995 22:27:04 GMT

          From comp.compilers

Related articles
Unnecessary spillage pering@tongass.eecs.berkeley.edu (Trevor Pering) (1995-09-01)
Re: Unnecessary spillage tim@franck.Princeton.EDU (1995-09-08)
| List of all articles for this month |

Newsgroups: comp.compilers
From: Trevor Pering <pering@tongass.eecs.berkeley.edu>
Keywords: optimize, registers
Organization: Compilers Central
Date: Fri, 1 Sep 1995 22:27:04 GMT

I am working on an optimizing phase for the Sather compiler.
(http://icsi.berkeley.edu/Sather) The Sather compiler compiles to ANSI
C, and lets a C compiler finish the job off. My optimizer is
concerned with optimizing expressions across procedure calls. It will
transform something like:


          C-source ASM Pseudocode (optimized)
        ----------- --------------------------
        a = x->y; ld a,y(x)
        c = a->q; ld c,q(a)
        foo(c); call foo
        b = x->y; ld b,y(x)


to:


        int L;
        L = x->y; ld a,y(x)
        a = L;
        c = a->q; ld c,q(a)
        foo(c); call foo
        b = L; mov b,a


if it can statically determine that foo() cannot in anyway change the
result of x->y (this optimization is difficult for the compiler, if
not impossible, because foo() may have side-effects). The gain in
this case is small, a move instead of a load (which can make a
difference with superscalar), but it has potential to be greater.


The problem is unnecessary register spillage. If the compiler is
running out of registers, this optimization can end up generating
something like:


ld a,y(x)
ld c,q(a)
push a
call foo
pop b


which is _worse_ than the original because the temporary variable L
must logically be saved across the call to foo.




The question I have is if anybody knows a good way to prevent this?
My best guess at this point would be to hueristically limit how many
optimizations are done to limit the amount of spillage -- either that
or attempting to (ug) move code around to help the C compiler.


        Thanks in advance for any suggestions/experience,
Trevor


--


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.