[tree-ssa PATCH] Fix PR 12187
Steven Bosscher
s.bosscher@student.tudelft.nl
Tue Sep 16 09:48:00 GMT 2003
Op di 16-09-2003, om 02:52 schreef Diego Novillo:
> On Sun, 2003-09-14 at 18:05, Steven Bosscher wrote:
> > Op zo 14-09-2003, om 23:53 schreef Steven Bosscher:
> > > Diego, we have a "may_alias_global_mem_p()", but
> > > what if a pointer declared in a nested function aliases a host
> > > associated variable??
> >
> > i.e. should something like this patch also go in:
> >
> Yes. This is better. For all intents and purposes, the variable
> inherited from the outer function is a global memory alias to the
> inner
> one.
>
> OK if it passes bootstrap and regression tests.
Whoops, my msg never reached the list...
Here's the patch I proposed:
Index: tree-dfa.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-dfa.c,v
retrieving revision 1.1.4.159
diff -c -3 -p -r1.1.4.159 tree-dfa.c
*** tree-dfa.c 14 Sep 2003 13:36:12 -0000 1.1.4.159
--- tree-dfa.c 16 Sep 2003 09:33:45 -0000
*************** add_referenced_var (tree var, struct wal
*** 2521,2527 ****
/* Mark local statics and global variables as global memory aliases
to avoid DCE killing seemingly dead stores to them. */
! if (decl_function_context (var) == 0 || TREE_STATIC (var))
v_ann->may_alias_global_mem = 1;
is_addressable = TREE_ADDRESSABLE (var)
--- 2521,2528 ----
/* Mark local statics and global variables as global memory aliases
to avoid DCE killing seemingly dead stores to them. */
! if (decl_function_context (var) != current_function_decl
! || TREE_STATIC (var))
v_ann->may_alias_global_mem = 1;
is_addressable = TREE_ADDRESSABLE (var)
It does bootstrap, but makes the compiler really pessimistic in the
presence of nested functions. The test case,
int main()
{
int a;
void test(int i)
{
a = i;
};
a = 0;
test (42);
if (a != 42)
abort ();
exit (0);
}
gets "optimized" to this,
main ()
{
int a;
static test;
extern abort;
extern exit;
a = 0;
{
int i;
(void)0;
a = 42;
};
if (a != 42)
{
abort ()
}
else
{
(void)0
};
exit (0);
}
since we now mark "a" as "may alias global memory" (in reality it may
not, of course). This will eliminate lots of optimization opportunities
for gfortran, since in Fortran nested functions are used quite often.
What exactly do you think is wrong with the first patch I sent?
(I am surprised anyway about this result. Can't we detect that a is not
volatile and cannot be clobbered between "a = 0;" and "a = 42;", and
between "a = 42;" and the if-statement??)
Gr.
Steven
More information about the Gcc-patches
mailing list