public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jeff Law <law@redhat.com>
To: Alexandre Oliva <aoliva@redhat.com>, gcc-patches@gcc.gnu.org
Subject: Re: [PR64164] drop copyrename, integrate into expand
Date: Tue, 31 Mar 2015 05:11:00 -0000	[thread overview]
Message-ID: <551A2C7C.8060005@redhat.com> (raw)
In-Reply-To: <orego9x6zw.fsf@livre.home>

On 03/28/2015 01:21 PM, Alexandre Oliva wrote:
> On Mar 27, 2015, Alexandre Oliva <aoliva@redhat.com> wrote:
>
>> This patch reworks the out-of-ssa expander to enable coalescing of SSA
>> partitions that don't share the same base name.  This is done only when
>> optimizing.
>
>> The test we use to tell whether two partitions can be merged no longer
>> demands them to have the same base variable when optimizing, so they
>> become eligible for coalescing, as they would after copyrename.  We then
>> compute the partitioning we'd get if all coalescible partitions were
>> coalesced, using this partition assignment to assign base vars numbers.
>> These base var numbers are then used to identify conflicts, which used
>> to be based on shared base vars or base types.
>
>> We now propagate base var names during coalescing proper, only towards
>> the leader variable.  I'm no longer sure this is still needed, but
>> something about handling variables and results led me this way and I
>> didn't revisit it.  I might rework that with a later patch, or a later
>> revision of this patch; it would require other means to identify
>> partitions holding result_decls during merging, or allow that and deal
>> with param and result decls in a different way during expand proper.
>
>> I had to fix two lingering bugs in order for the whole thing to work: we
>> perform conflict detection after abnormal coalescing, but we computed
>> live ranges involving only the partition leaders, so conflicts with
>> other names already coalesced wouldn't be detected.
>
> This early abnormal coalescing was only present for a few days in the
> trunk, and I was lucky enough to start working on a tree that had it.
> It turns out that the fix for it was thus rendered unnecessary, so I
> dropped it.  It was the fix for it, that didn't cover the live range
> check, that caused the two ICEs I saw in the regressions tests.  Since
> the ultimate cause of the problem is gone, and the change that
> introduced the check failures, both problems went *poof* after I updated
> the tree, resolved the conflicts and dropped the redundant code.
>
>> The other problem was that we didn't track default defs for parms as
>> live at entry, so they might end up coalesced.
>
> I improved this a little bit, using the bitmap of partitions containing
> default params to check that we only process function-entry defs for
> them, rather than for all param decls in case they end up in other
> partitions.
>
>> I guess none of these problems would have been exercised in practice,
>> because we wouldn't even consider merging ssa names associated with
>> different variables.
>
>> In the end, I verified that this fixed the codegen regression in the
>> PR64164 testcase, that failed to merge two partitions that could in
>> theory be merged, but that wasn't even considered due to differences in
>> the SSA var names.
>
>> I'd agree that disregarding the var names and dropping 4 passes is too
>> much of a change to fix this one problem, but...  it's something we
>> should have long tackled, and it gets this and other jobs done, so...
>
> Regstrapped on x86_64-linux-gnu native and on i686-pc-linux-gnu native
> on x86_64, so without lto plugin.  The only regression is in
> gcc.dg/guality/pr54200.c, that explicitly disables VTA.  When
> optimization is enabled, the different coalescing we perform now causes
> VTA-less variable tracking to lose track of variable "z".  This
> regression in non-VTA var-tracking is expected and, as richi put it in
> PR 64164, I guess we don't care about that, do we? :-)
>
> The other guality regressions I mentioned in my other email turned out
> not to be regressions, but preexisting failures that somehow did not
> make to the test_summary of my earlier pristine build.
>
> Is this ok to install?
>
>
> for  gcc/ChangeLog
>
> 	PR rtl-optimization/64164
> 	* Makefile.in (OBJS): Drop tree-ssa-copyrename.o.
> 	* tree-ssa-copyrename.c: Removed.
> 	* opts.c (default_options_table): Drop -ftree-copyrename.
> 	* passes.def: Drop all occurrences of pass_rename_ssa_copies.
> 	* common.opt (ftree-copyrename): Ignore.
> 	(ftree-coalesce-vars, ftree-coalesce-inlined-vars): Likewise.
> 	* doc/invoke.texi: Remove the ignored options above.
> 	* gimple-expr.c (gimple_can_coalesce_p): Allow coalescing
> 	across base variables when optimizing.
> 	* tree-ssa-coalesce.c (build_ssa_conflict_graph): Add
> 	param_defaults argument.  Process PARM_DECLs's default defs at
> 	the entry point.
> 	(attempt_coalesce): Add param_defaults argument, and
> 	track the presence of default defs for params in each
> 	partition.  Propagate base var to leader on merge, preferring
> 	parms and results, named vars, ignored vars, and then anon
> 	vars.  Refuse to merge a RESULT_DECL partition with a default
> 	PARM_DECL one.
> 	(coalesce_partitions): Add param_defaults argument,
> 	and pass it to attempt_coalesce.
> 	(dump_part_var_map): New.
> 	(compute_optimized_partition_bases): New, called by...
> 	(coalesce_ssa_name): ... when optimizing, disabling
> 	partition_view_bitmap's base assignment.  Pass local
> 	param_defaults to coalescer functions.
> 	* tree-ssa-live.c (var_map_base_init): Note use only when not
> 	optimizing.
> ---
>   gcc/Makefile.in           |    1
>   gcc/common.opt            |   12 +
>   gcc/doc/invoke.texi       |   29 ---
>   gcc/gimple-expr.c         |    7 -
>   gcc/opts.c                |    1
>   gcc/passes.def            |    5
>   gcc/tree-ssa-coalesce.c   |  342 ++++++++++++++++++++++++++++++-
>   gcc/tree-ssa-copyrename.c |  499 ---------------------------------------------
>   gcc/tree-ssa-live.c       |    5
>   9 files changed, 347 insertions(+), 554 deletions(-)
>   delete mode 100644 gcc/tree-ssa-copyrename.c
>
> diff --git a/gcc/gimple-expr.c b/gcc/gimple-expr.c
> index efc93b7..62ae577 100644
> --- a/gcc/gimple-expr.c
> +++ b/gcc/gimple-expr.c
> @@ -399,13 +399,14 @@ copy_var_decl (tree var, tree name, tree type)
>   bool
>   gimple_can_coalesce_p (tree name1, tree name2)
>   {
> -  /* First check the SSA_NAME's associated DECL.  We only want to
> -     coalesce if they have the same DECL or both have no associated DECL.  */
> +  /* First check the SSA_NAME's associated DECL.  Without
> +     optimization, we only want to coalesce if they have the same DECL
> +     or both have no associated DECL.  */
>     tree var1 = SSA_NAME_VAR (name1);
>     tree var2 = SSA_NAME_VAR (name2);
>     var1 = (var1 && (!VAR_P (var1) || !DECL_IGNORED_P (var1))) ? var1 : NULL_TREE;
>     var2 = (var2 && (!VAR_P (var2) || !DECL_IGNORED_P (var2))) ? var2 : NULL_TREE;
> -  if (var1 != var2)
> +  if (var1 != var2 && !optimize)
>       return false;
So when when the base variables are different and we are optimizing, 
this allows coalescing, right?

What I don't see is a corresponding change to var_map_base_init to 
ensure we build a conflict graph which includes objects when 
SSA_NAME_VARs are not the same.  I see a vague reference in 
var_map_base_init's header comment that refers us to coalesce_ssa_name.

It appears that compute_optimized_partition_bases handles this by 
creating a partitions of things that are related by copies/phis 
regardless of their underlying named object, type, etc.  Right?





> index 1d598b2..f8fd0ef 100644
> --- a/gcc/passes.def
> +++ b/gcc/passes.def
[ ... ]
Hard to argue with removing a pass that gets called 5 times!


> @@ -890,6 +900,36 @@ build_ssa_conflict_graph (tree_live_info_p liveinfo)
>   	    live_track_process_def (live, result, graph);
>   	}
>
> +      /* Pretend there are defs for params' default defs at the start
> +	 of the (post-)entry block.  We run after abnormal coalescing,
> +	 so we can't assume the leader variable is the default
> +	 definition, but because of SSA_NAME_VAR adjustments in
> +	 attempt_coalesce, we can assume that if there is any
> +	 PARM_DECL in the partition, it will be the leader's
> +	 SSA_NAME_VAR.  */
So the issue here is you want to iterate over the objects live at the 
entry block, which would include any SSA_NAMEs which result from 
PARM_DECLs.  I don't guess there's an easier way to do that other than 
iterating over everything live in that initial block?

And the second second EXECUTE_IF_SET_IN_BITMAP iterates over everything 
in the partitions associated with the SSA_NAMES that are live at the the 
entry block, right?

I don't guess it'd be more efficient to walk over the SSA_NAMEs looking 
for anything marked as a default definition, then map that back to a 
partition since we'd have to look at every SSA_NAME whereas your code 
only looks at paritions that are live in the entry block, then looks at 
the elements in those partitions.

> @@ -1126,11 +1166,12 @@ create_outofssa_var_map (coalesce_list_p cl, bitmap used_in_copy)
>
>   static inline bool
>   attempt_coalesce (var_map map, ssa_conflicts_p graph, int x, int y,
> -		  FILE *debug)
> +		  bitmap param_defaults, FILE *debug)
[ ... ]
So the bulk of the changes into this routine are really about picking a 
good leader, which presumably is how we're able to get the desired 
effects on debuginfo that we used to get from tree-ssa-copyrename.c?


> @@ -1158,6 +1199,70 @@ attempt_coalesce (var_map map, ssa_conflicts_p graph, int x, int y,
>       {
>         var1 = partition_to_var (map, p1);
>         var2 = partition_to_var (map, p2);
> +
> +      tree leader;
> +
> +      if (var1 == var2 || !SSA_NAME_VAR (var2)
> +	  || SSA_NAME_VAR (var1) == SSA_NAME_VAR (var2))
> +	{
> +	  leader = SSA_NAME_VAR (var1);
> +	  default_def = (leader && TREE_CODE (leader) == PARM_DECL
> +			 && (SSA_NAME_IS_DEFAULT_DEF (var1)
> +			     || bitmap_bit_p (param_defaults, p1)));
> +	}
So some comments about the various cases here might help.  I can sort 
them out if I read the code, but one could argue that a block comment on 
the rules for how to select the partition leader would be better.

Is the special casing of PARM_DECLs + RESULT_DECLs really a failing of 
not handling one or both properly when computing liveness information?

I'm not aware of an inherent reason why a PARM_DECL couldn't coalesce 
with a related RESULT_DECL if they are otherwise non-conflicting and 
related by a copy/phi.


> @@ -1272,6 +1415,178 @@ ssa_name_var_hash::equal (const value_type *n1, const compare_type *n2)
> +
> +/* Fill in MAP's partition_to_base_index, with one index for each
> +   partition of SSA names USED_IN_COPIES and related by CL
> +   coalesce possibilities.  */
> +
> +static void
> +compute_optimized_partition_bases (var_map map, bitmap used_in_copies,
> +				   coalesce_list_p cl)
Presumably ordering of unioning of the partitions doesn't matter here as 
we're looking at coalesce possibilities rather than things we have 
actually coalesced?  Thus it's OK (?) to handle the names occurring in 
abnormal PHIs after those names that are associated by a copy.

This is all probably OK, but I want to make sure I understand what's 
happening before a final approval.

jeff

  reply	other threads:[~2015-03-31  5:11 UTC|newest]

Thread overview: 127+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-27 18:04 Alexandre Oliva
2015-03-27 18:11 ` Alexandre Oliva
2015-03-28 19:22 ` Alexandre Oliva
2015-03-31  5:11   ` Jeff Law [this message]
2015-04-03 13:17     ` Alexandre Oliva
2015-04-06 16:08       ` Jeff Law
2015-04-24  1:56         ` Alexandre Oliva
2015-04-27 11:39           ` Richard Biener
2015-06-06  5:12             ` Alexandre Oliva
2015-06-08  8:16               ` Richard Biener
2015-06-09  8:58                 ` Christophe Lyon
2015-06-10  0:28               ` Alexandre Oliva
2015-06-10 13:36                 ` Richard Biener
2015-07-16  7:58                   ` Alexandre Oliva
2015-07-16  8:50                     ` Richard Biener
2015-07-16 21:33                       ` Alexandre Oliva
2015-07-18  8:26                         ` Alexandre Oliva
2015-07-21 13:25                           ` Richard Biener
2015-07-22 17:13                             ` Alexandre Oliva
2015-07-22 17:43                             ` Alexandre Oliva
2015-07-23 11:04                               ` Richard Biener
2015-07-23 15:42                                 ` Alexandre Oliva
2015-07-23 20:35                                   ` Segher Boessenkool
2015-07-23 21:24                                     ` H.J. Lu
2015-07-23 22:11                                       ` H.J. Lu
2015-07-24  1:31                                         ` David Edelsohn
2015-07-24  5:08                                           ` H.J. Lu
2015-07-24  9:26                                             ` Richard Biener
2015-07-24 12:50                                               ` H.J. Lu
2015-07-24 20:20                                           ` Alexandre Oliva
2015-07-25  2:37                                             ` David Edelsohn
2015-07-27 22:16                                               ` Alexandre Oliva
2015-07-27 22:31                                                 ` H.J. Lu
2015-07-24 18:51                                         ` Alexandre Oliva
2015-07-24 19:12                                           ` H.J. Lu
2015-07-24 19:31                                             ` David Edelsohn
2015-07-24 20:43                                               ` Alexandre Oliva
2015-07-24 20:47                                             ` Alexandre Oliva
2015-07-24 21:53                                               ` H.J. Lu
2015-07-25  7:17                                                 ` Richard Biener
2015-07-29 20:52                                         ` Alexandre Oliva
2015-07-29 21:06                                           ` H.J. Lu
2015-07-30 17:47                                             ` H.J. Lu
2015-08-03 23:46                                               ` Alexandre Oliva
2015-08-04  9:48                                                 ` Richard Biener
2015-08-05  0:39                                                   ` Alexandre Oliva
2015-08-05  9:14                                                     ` Richard Biener
2015-08-05 23:03                                                       ` Alexandre Oliva
2015-08-10  8:24                                                 ` James Greenhalgh
2015-08-10 15:14                                                   ` Jeff Law
2015-08-11  4:53                                                     ` Patrick Marlier
2015-08-14 19:03                                                       ` Alexandre Oliva
2015-08-15  8:57                                                         ` Andreas Schwab
2015-08-16 13:00                                                           ` Alexandre Oliva
     [not found]                                                             ` <m2k2sv8s21.fsf@linux-m68k.org>
2015-08-17  5:05                                                               ` Alexandre Oliva
2015-08-17  9:29                                                                 ` Kyrill Tkachov
2015-08-17 16:23                                                                   ` Andrew Pinski
2015-08-18 16:18                                                                 ` Kyrill Tkachov
2015-08-16 16:42                                                         ` Andreas Schwab
2015-08-17  2:57                                                           ` Alexandre Oliva
2015-08-17  8:23                                                             ` Andreas Schwab
2015-08-17  9:21                                                               ` Andreas Schwab
2015-08-17 11:58                                                               ` Alexandre Oliva
2015-08-17  7:48                                                         ` Christophe Lyon
2015-08-17 12:43                                                           ` Alexandre Oliva
2015-08-17 13:39                                                             ` Christophe Lyon
2015-08-18  6:53                                                               ` Alexandre Oliva
2015-08-19  6:50                                                                 ` Alexandre Oliva
2015-08-19 10:17                                                                   ` Richard Biener
2015-08-19 13:35                                                                   ` Andreas Schwab
2015-08-19 13:45                                                                     ` Andreas Schwab
2015-08-19 17:48                                                                       ` Alexandre Oliva
2015-08-20  1:44                                                                         ` Alexandre Oliva
2015-08-20 17:03                                                                           ` Jeff Law
2015-08-21  7:57                                                                           ` Alexandre Oliva
2015-08-21  8:38                                                                             ` Richard Biener
2015-08-21 12:17                                                                             ` Andreas Schwab
2015-08-21  8:11                                                                           ` Alexandre Oliva
2015-08-21  8:37                                                                             ` Richard Biener
2015-09-02 17:09                                                         ` Alan Lawrence
2015-09-02 22:34                                                           ` Alexandre Oliva
2015-09-03 10:58                                                             ` Alan Lawrence
2015-09-18 15:49                                                             ` Alan Lawrence
2015-09-23 20:44                                                               ` Alexandre Oliva
2015-09-25 11:39                                                                 ` Richard Biener
2015-10-09  5:26                                                                   ` [PR67828] don't unswitch loops on undefined SSA values (was: Re: [PR64164] drop copyrename, integrate into expand) Alexandre Oliva
2015-10-09  9:35                                                                     ` Richard Biener
2015-10-09  5:36                                                                   ` [PR67766] reorder return value copying from PARALLELs and CONCATs " Alexandre Oliva
2015-10-09  7:33                                                                     ` [PR67891] drop is_gimple_reg test from set_parm_rtl (was: [PR67766] reorder return value copying from PARALLELs and CONCATs) Alexandre Oliva
2015-10-09  9:40                                                                       ` Richard Biener
2015-10-10 13:20                                                                         ` [PR67891] drop is_gimple_reg test from set_parm_rtl Alexandre Oliva
2015-10-12 10:22                                                                           ` Richard Biener
2015-10-14  3:25                                                                             ` Alexandre Oliva
2015-10-14  9:28                                                                               ` Richard Biener
2015-11-03  1:11                                                                                 ` Alexandre Oliva
2015-11-03  3:14                                                                                   ` Jeff Law
2015-11-03  4:29                                                                                     ` Alexandre Oliva
2022-10-17 12:08                                                                                       ` Tag 'gcc/gimple-expr.cc:mark_addressable_2' as 'static' (was: [PR67891] drop is_gimple_reg test from set_parm_rtl) Thomas Schwinge
2015-10-09  9:36                                                                     ` [PR67766] reorder return value copying from PARALLELs and CONCATs (was: Re: [PR64164] drop copyrename, integrate into expand) Richard Biener
2015-09-29 11:31                                                                 ` [PR64164] drop copyrename, integrate into expand Szabolcs Nagy
2015-10-07 22:37                                                                   ` Alexandre Oliva
2015-10-08 10:00                                                                     ` Richard Biener
2015-10-09 21:10                                                                     ` Jeff Law
2015-11-05  5:09                                                                 ` Alexandre Oliva
2015-11-05 13:44                                                                   ` Richard Biener
2015-11-10 15:31                                                                   ` Alan Lawrence
2015-11-10 22:59                                                                     ` Alexandre Oliva
2015-11-10 23:43                                                                       ` Jeff Law
2015-11-11 18:10                                                                         ` Alexandre Oliva
2015-11-13  6:33                                                                           ` Jeff Law
2015-11-17  0:07                                                                             ` Alexandre Oliva
2015-11-24  5:41                                                                               ` Jeff Law
2015-07-24 18:21                                     ` Alexandre Oliva
2015-07-29 20:32                                     ` Alexandre Oliva
2015-04-29  3:51           ` Jeff Law
2015-03-31  6:55   ` Steven Bosscher
2015-03-31 13:30     ` Richard Biener
2015-03-31 14:06   ` Richard Biener
2015-04-03 13:30     ` Alexandre Oliva
2015-04-06 15:57       ` Jeff Law
2015-12-04 12:45 ` Dominik Vogt
2015-06-09 16:19 David Edelsohn
2015-06-09 18:36 ` Alexandre Oliva
2015-06-09 20:24   ` Alexandre Oliva
2015-06-09 20:59     ` Jakub Jelinek
2015-06-09 21:36     ` Eric Botcazou
2015-06-09 21:38       ` David Edelsohn

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=551A2C7C.8060005@redhat.com \
    --to=law@redhat.com \
    --cc=aoliva@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).