diff mbox

[PR43513,1/3] Replace vla with array - Implementation.

Message ID 201109241729.26112.ebotcazou@adacore.com
State New
Headers show

Commit Message

Eric Botcazou Sept. 24, 2011, 3:29 p.m. UTC
> This is an updated version of the patch. I have 2 new patches and an
> updated testcase which I will sent out individually.
>
> Patch set was bootstrapped and reg-tested on x86_64.
>
> Ok for trunk?
>
> Thanks,
> - Tom
>
> 2011-07-30  Tom de Vries  <tom@codesourcery.com>
>
> 	PR middle-end/43513
> 	* Makefile.in (tree-ssa-ccp.o): Add $(PARAMS_H) to rule.
> 	* tree-ssa-ccp.c (params.h): Include.
> 	(fold_builtin_alloca_for_var): New function.
> 	(ccp_fold_stmt): Use fold_builtin_alloca_for_var.

We have detected another fallout on some Ada code: the transformation replaces 
a call to __builtin_alloca with &var, i.e. it introduces an aliased variable, 
which invalidates the points-to information of some subsequent call, fooling 
DSE into thinking that it can eliminate a live store.

The brute force approach


works, but we might want to be move clever.  Thoughts?

Comments

Richard Biener Sept. 25, 2011, 8:57 a.m. UTC | #1
On Sat, Sep 24, 2011 at 5:29 PM, Eric Botcazou <ebotcazou@adacore.com> wrote:
>> This is an updated version of the patch. I have 2 new patches and an
>> updated testcase which I will sent out individually.
>>
>> Patch set was bootstrapped and reg-tested on x86_64.
>>
>> Ok for trunk?
>>
>> Thanks,
>> - Tom
>>
>> 2011-07-30  Tom de Vries  <tom@codesourcery.com>
>>
>>       PR middle-end/43513
>>       * Makefile.in (tree-ssa-ccp.o): Add $(PARAMS_H) to rule.
>>       * tree-ssa-ccp.c (params.h): Include.
>>       (fold_builtin_alloca_for_var): New function.
>>       (ccp_fold_stmt): Use fold_builtin_alloca_for_var.
>
> We have detected another fallout on some Ada code: the transformation replaces
> a call to __builtin_alloca with &var, i.e. it introduces an aliased variable,
> which invalidates the points-to information of some subsequent call, fooling
> DSE into thinking that it can eliminate a live store.

Ugh, yeah.  I suppose PTA assigned a HEAP var as pointed-to object for the
original pointer, even if the transformed stmt

 orig_ptr_1 = &a;

has the points-to information preserved for orig_ptr_1 further propagation of
&a will make accesses through orig_ptr_1 have different alias properties.

What should work in this special case of a singleton points-to set of orig_ptr_1
(might want to check that) is, do

  SET_DECL_PT_UID (decl-of-a, DECL_UID (pointed-to orig_ptr_1));

The brute force approach is not acceptable (it'll wreck IPA points-to info).

A helper like pt_solution_singleton_p (struct pt_solution *pt, unsigned *uid)
whould be nice to have for this.

Note that we don't have points-to information computed during the first
CCP pass, so the above should be conditional on SSA_NAME_PTR_INFO
being present and not ! ->anything (but then assert that we actually do have
a singleton, or fail the folding).

Richard.

> The brute force approach
>
> Index: tree-ssa-ccp.c
> ===================================================================
> --- tree-ssa-ccp.c      (revision 179038)
> +++ tree-ssa-ccp.c      (working copy)
> @@ -2014,7 +2014,10 @@ do_ssa_ccp (void)
>   ccp_initialize ();
>   ssa_propagate (ccp_visit_stmt, ccp_visit_phi_node);
>   if (ccp_finalize ())
> -    return (TODO_cleanup_cfg | TODO_update_ssa | TODO_remove_unused_locals);
> +    return (TODO_cleanup_cfg
> +           | TODO_update_ssa
> +           | TODO_rebuild_alias
> +           | TODO_remove_unused_locals);
>   else
>     return 0;
>  }
>
> works, but we might want to be move clever.  Thoughts?
>
> --
> Eric Botcazou
>
Eric Botcazou Sept. 26, 2011, 10:05 a.m. UTC | #2
> Ugh, yeah.  I suppose PTA assigned a HEAP var as pointed-to object for the
> original pointer, even if the transformed stmt
>
>  orig_ptr_1 = &a;
>
> has the points-to information preserved for orig_ptr_1 further propagation
> of &a will make accesses through orig_ptr_1 have different alias
> properties.

AFAICS it's an escaping problem: the new variable isn't seen as escaping at 
some call point.  Testcase attached, compile opt22.adb at -O but make sure 
your tree is up-to-date.

> What should work in this special case of a singleton points-to set of
> orig_ptr_1 (might want to check that) is, do
>
>   SET_DECL_PT_UID (decl-of-a, DECL_UID (pointed-to orig_ptr_1));
>
> The brute force approach is not acceptable (it'll wreck IPA points-to
> info).

OK, thanks for the tip.


2011-09-26  Eric Botcazou  <ebotcazou@adacore.com>

        * gnat.dg/opt22.adb: New test.
        * gnat.dg/opt22_pkg.ad[sb]: New helper.
diff mbox

Patch

Index: tree-ssa-ccp.c
===================================================================
--- tree-ssa-ccp.c      (revision 179038)
+++ tree-ssa-ccp.c      (working copy)
@@ -2014,7 +2014,10 @@  do_ssa_ccp (void)
   ccp_initialize ();
   ssa_propagate (ccp_visit_stmt, ccp_visit_phi_node);
   if (ccp_finalize ())
-    return (TODO_cleanup_cfg | TODO_update_ssa | TODO_remove_unused_locals);
+    return (TODO_cleanup_cfg
+           | TODO_update_ssa
+           | TODO_rebuild_alias
+           | TODO_remove_unused_locals);
   else
     return 0;
 }