This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: RFA: New optimization: Convert local statics into non-statics


Hi Michael,

Where do you handle the following situation? :

int foo(int i) {
  static int s = 0;
  if (bar(i))
    s = 1;
  return s;
}

Assume that bar() is a function which calls foo() (which is then indirectly recursive), in this way:

int bar(int i) {
  if (i) { foo(i-1); return 0; }
  return 1;
}

An outer call to foo(1) needs to return 1, not 0.

Sadly as far as I can see this case is the deal breaker. My current patch does not handle it correctly and the only way I could think of to resolve it is to limit the optimization to leaf functions. But at the time the pass is executed, very early on in the optimization sequence, I do not think that there is any way to tell if a function is a leaf function.


The other problems reported by other posters can all be solved, but not recursion. :-( So I am going to have to withdraw my patch for now and consider some other way of handling local statics.

Cheers
  Nick



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]