On Thu, Jun 6, 2013 at 3:42 PM, Bernd Schmidt <ber...@codesourcery.com> wrote: > There's a well-known benchmark which uselessly likes to declare local > variables as static. There exist at least two implementations to demote > these to normal register variables. See the discussion thread here: > http://gcc.gnu.org/ml/gcc-patches/2008-07/msg00982.html > These days, however, we can skip most of the work as pointed out by > Andrew Pinski: > http://gcc.gnu.org/ml/gcc-patches/2008-07/msg01035.html > PRE usually manages to eliminate all references to the static variable > except a final assignment. The only thing that's left to do is to > enhance DSE to recognize these as dead. So, the following patch is a > cut-down version of CodeSourcery's approach, originally written by > Nathan Froyd, modified to do exactly that. > > Bootstrapped and tested on x86_64-linux, all languages except Ada. OK?
Just a few quick questions: + /* We cannot optimize away a static used in multiple functions (as + might happen in C++). */ + && !DECL_NONLOCAL(var) it may also happen trivially with inlining. Which means a local pass can never "remove" vars safely. In theory we have IPA reference which tries to figure out whether a local static is read and/or written to (and from where). It's of course quite early analysis where FRE may not yet have optimized out all reads. But the trivial dead local static store elimination would simply eliminate all write-only and !TREE_ADDRESSABLE vars (and statements storing to it). For some reason this must be not enough so you write that local analysis code. Thus - I'm asking you to double-check a trivial implementation using the IPA reference result and double-check the issue with inlining introducing out-of-current-function uses. Thanks, Richard. > > Bernd