This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: random thought - optimizer
- To: Joe Buck <jbuck at synopsys dot COM>
- Subject: Re: random thought - optimizer
- From: Daniel Berlin <dan at cgsoftware dot com>
- Date: Tue, 03 Jul 2001 13:36:15 -0400
- Cc: law at redhat dot com, amylaar at redhat dot com (Joern Rennecke),mark at codesourcery dot com (Mark Mitchell),zackw at stanford dot edu (Zack Weinberg), gcc at gcc dot gnu dot org (gcc at gcc dot gnu dot org)
- References: <200107031705.KAA00596@racerx.synopsys.com>
Joe Buck <jbuck@synopsys.COM> writes:
> Jeff writes:
>> If/when there's a way to tell that a MEM is local to a procedure, then it
>> is trivial for our SSA DCE optimizer to remove loads/stores to that variable
>> if they do not contribute to the externally visible result of the program.
>
> Terrific. This possibly has the potential to get rid of a major g++
> performance problem: when a temporary object with two or more fields
> is passed by an inline function, we almost always wind up with dead
> stores (ADDRESSOF takes care of the one-field case). Can the SSA
> DCE optimizer kill the dead stores?
Dead store elimination is pretty easy in SSA form, but I usually see
it seperate than DCE.
In fact, SSA-DS looks something like this:
dead_definition:
Figure out if the def is reached by some use. If so, it's not
dead. Otherwise, it's dead.
main
1. Traverse flow graph backwards, looking at each def (including
PHI's).
a. If the def is a phi, check if the phi is dead (if
dead_definition is true). If so, mark all
the phi uses as dead too.
b. If the def is a store, make sure it has no side effects, and if
it doesn't, see if dead_definition says it's dead. If so, mark
all it's uses as dead too.
(You also keep track of which defs you haven't seen any live uses for
yet, so you can recheck them later after you mark other things dead)
The trickiest part is figuring out if it's really reached by some use.
I've also simplified the algorithm a bit, but that's the gist.
I'll implement it if nobody has done it yet.
--
"I had to stop driving my car for a while... The tires got
dizzy.
"-Steven Wright