[PATCH]: Fix unnecessary call clobbering due to type of global_var

Daniel Berlin dberlin@dberlin.org
Sun Dec 5 19:51:00 GMT 2004



On Sun, 5 Dec 2004, Diego Novillo wrote:

> Daniel Berlin wrote:
>
>>     * tree-ssa-alias.c (create_global_var): Use void_type_node,
>>     not size_type_node.
>> 
> OK.  Though, for the test case you had sent privately, we need to find out 
> why is GV created at all.

It's this code:

       /* Create .GLOBAL_VAR if we have too many call-clobbered
          variables.  We also create .GLOBAL_VAR when there no
          call-clobbered variables to prevent code motion
          transformations from re-arranging function calls that may
          have side effects.  For instance,

                 foo ()
                 {
                   int a = f ();
                   g ();
                   h (a);
                 }

          There are no call-clobbered variables in foo(), so it would
          be entirely possible for a pass to want to move the call to
          f() after the call to g().  If f() has side effects, that
          would be wrong.  Creating .GLOBAL_VAR in this case will
          insert VDEFs for it and prevent such transformations.  */
       if (n_clobbered == 0
           || ai->num_calls_found * n_clobbered >= (size_t) GLOBAL_VAR_THRESHOLD)
         create_global_var ();



In particular, the n_clobbered == 0 part.
Not only is nothing clobbered in my test case, there are no function 
calls.

So trivially, this should be "if ((n_clobbered == 0 && ai->num_calls_found  > 0)
 			   || .."

I'm about to submit a patch for this.

In the long run, we should probably find a nicer way of linking calls that 
could have side-effects together in chains, instead of global var.



More information about the Gcc-patches mailing list