An apparatus and method for removing stores to local variables that are
not aliased by other variables or to variables which have already been
removed by previous optimizations prior to performing dead store
elimination optimization are provided. With the method and apparatus,
instructions that include a memory reference to a local variable that is
not modified by other instructions are identified. For these
instructions, an identifier of the variable referenced is maintained in a
data structure along with the location of the store instruction in the
procedure (for a store instruction) or a load indicator (for a load
instruction). The data structure is then traversed to see if there are
any store instructions referencing a variable that does not have a
corresponding load instruction referencing the same variable. Such store
instructions are eliminated prior to performing traditional dead store
elimination.