public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jan Hubicka <hubicka@ucw.cz>
To: Jeff Law <law@redhat.com>
Cc: mliska <mliska@suse.cz>, gcc-patches@gcc.gnu.org, hubicka@ucw.cz
Subject: Re: [PATCH 3/5] IPA ICF pass
Date: Thu, 26 Jun 2014 18:46:00 -0000	[thread overview]
Message-ID: <20140626184614.GB29056@kam.mff.cuni.cz> (raw)
In-Reply-To: <53A9E021.8000400@redhat.com>

Jeff,
thanks for review! I did some passes over the patch before it got to the ML, I am
happy to have independent opinion. 
> >+@item -fipa-icf
> >+@opindex fipa-icf
> >+Perform Identical Code Folding for functions and read-only variables.
> >+Behavior is similar to Gold Linker ICF optimization. Symbols proved
> >+as semantically equivalent are redirected to corresponding symbol. The pass
> >+sensitively decides for usage of alias, thunk or local redirection.
> >+This flag is enabled by default at @option{-O2}.
> So you've added this at -O2, what is the general compile-time
> impact? Would it make more sense to instead have it be part of -O3,
> particularly since ICF is rarely going to improve performance (sans
> icache issues).

I think code size optimization not sacrifying any (or too much of) performance are
generally very welcome at -O2.  Compared to LLVM and Microsoft compilers we are
on code bloat side at -O2.

http://hubicka.blogspot.ca/2014/04/linktime-optimization-in-gcc-2-firefox.html
has some numbers for -O2 GGC/LLVM.

I believe this is result of tunning for relatively small benchamrks (SPECS) and
I hope we could revisit -O2 for code size considerations for 4.10 somewhat.  If
tuned well, ICF has no reason to be expnesive wrt compile time. So lets shoot
for that.  The considerable donwside of enabling ICF IMO should be only
disturbing effect on debug info.
> >+  return true;
> >+}
> Isn't this really checking for equivalence? "do correspond" seems
> awkward here.

The function turns the names equivalent on first invocation for a given name
and later checks that this tentative equivalence holds.

Not sure what is best name for it (originaly it was verify that did not sound
right to me either)
> 
> >+
> >+/* Verification function for edges E1 and E2.  */
> >+
> >+bool
> >+func_checker::compare_edge (edge e1, edge e2)
> >+{
> >+  if (e1->flags != e2->flags)
> >+    return false;
> Presumably there's no flags we can safely ignore.  So absolute
> equality seems reasonable here.

Yep
> >+/* Compare two types if are same aliases in case of strict aliasing
> >+   is enabled.  */
> >+bool
> >+sem_item::compare_for_aliasing (tree t1, tree t2)
> >+{
> >+  if (flag_strict_aliasing)
> >+    {
> >+      alias_set_type s1 = get_deref_alias_set (TREE_TYPE (t1));
> >+      alias_set_type s2 = get_deref_alias_set (TREE_TYPE (t2));
> >+
> >+      return s1 == s2;
> >+    }
> >+
> >+  return true;
> >+}
> Is returning TRUE really the conservatively correct thing to do in
> the absence of aliasing information?  Isn't that case really "I
> don't know" in which case the proper return value is FALSE?

I think with -fno-strict-aliasing the set should be 0 (Richi?) and thus we can
compare for equality.  We probably can be on agressive side and let 0 alias
set prevail the non-0.  But that can be done incrementally.

We also need to match type inheritance equality for polymorphic types. I will
add function for that into ipa-devirt.

> >+/* References independent hash function.  */
> >+
> >+hashval_t
> >+sem_function::get_hash (void)
> >+{
> >+  if(!hash)
> >+    {
> >+      hash = 177454; /* Random number for function type.  */
> >+
> >+      hash = iterative_hash_object (arg_count, hash);
> >+      hash = iterative_hash_object (bb_count, hash);
> >+      hash = iterative_hash_object (edge_count, hash);
> >+      hash = iterative_hash_object (cfg_checksum, hash);
> Does CFG_CHECKSUM encompass the bb/edge counts?

It is one used by profiling code to match profiles, so it should.
> >+    SE_EXIT_FALSE();
> >+
> >+  if (!equals_wpa (item))
> >+    return false;
> >+
> >+  /* Checking function arguments.  */
> >+  tree decl1 = DECL_ATTRIBUTES (decl);
> >+  tree decl2 = DECL_ATTRIBUTES (compared_func->decl);
> So are there any attributes we can safely ignore?  Probably not.
> However, we ought to handle the case where the attributes appear in
> different orders.

There are few, like we can ignore "weak" or "visibility" attribute because we do
produce alias with proper visibility anyway.  My plan is to start removing those
attributes from declarations once they are turned into suitable representation
in symbol table (or for attributes like const/noreturn/pure where we have explicit
decl flags).  This will make our life bit easier later, too.

We probably then can whitelist some attributes, but I would deal with this later.
> >+/* Returns cgraph_node.  */
> >+
> >+struct cgraph_node *
> >+sem_function::get_node (void)
> >+{
> >+  return cgraph (node);
> >+}
> >+
> >+/* Initialize semantic item by info reachable during LTO WPA phase.  */
> >+
> >+void
> >+sem_function::init_wpa (void)
> >+{
> >+  parse_tree_args ();
> >+}
> inline? Worth or not worth the headache?

We ought to autoinline simple wrappers even at -Os (for size)
(I am not agains explicit inline keywords here tough)
> 
> 
> >+
> >+bool
> >+sem_function::compare_bb (sem_bb_t *bb1, sem_bb_t *bb2, tree func1, tree func2)
> So this routine walks down the gimple statements and compares them
> for equality.  Would it make sense to have the equality testing in
> gimple?  That way if someone adds a new gimple code the places they
> need to check/update are at least somewhat more localized?

There are few places that does equality testing (tailmerge) AFAIK.  They are all somewhat
different - I think we can export this equality machinery with reosnable API and try to turn
those to use it, but it may be good incremental project IMO.
> 
> 
> >+
> >+      for (i = 0; i < size1; ++i)
> >+	{
> >+	  t1 = gimple_phi_arg (phi1, i)->def;
> >+	  t2 = gimple_phi_arg (phi2, i)->def;
> >+
> >+	  if (!compare_operand (t1, t2, func1, func2))
> >+	    SE_EXIT_FALSE ();
> >+
> >+	  e1 = gimple_phi_arg_edge (phi1, i);
> >+	  e2 = gimple_phi_arg_edge (phi2, i);
> >+
> >+	  if (!checker.compare_edge (e1, e2))
> >+	    SE_EXIT_FALSE ();
> >+	}
> I don't think we guarantee any particular order on the PHI args.
> ISTM you'd want to sort them or something so as not to reject a
> possible duplicate simply because of ordering issues.
> 
> Related, I'm not sure bb indexes are even guaranteed to have any
> stable ordering.  So ISTM you'd want to do something like a DFS walk
> to set a index for each block, then sort the PHI arguments based on
> DFS index to get a stable, consistent check here.

Yep, there are no resonable orders on it.  If function starts same in source code they ought
to end up same here.  Plan was to first match for exact equality and then play with 
smarter tricks here.
> 
> I'm starting to gloss over things....  It feels like we've got too
> much stuff in this one file.  Breaking things out would help (like
> for example the hashing/equality bits).  I'd like to see things
> broken out a bit and reposted for further reviewing.

Yep, the pass has grown up to be rather long. The gimple equality testing is the
main body of work, so perhaps doing this in separate file is good idea.

Honza
> 
> Jeff

  parent reply	other threads:[~2014-06-26 18:46 UTC|newest]

Thread overview: 70+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-16 10:07 [PATCH 1/5] New Identical Code Folding IPA pass mliska
2014-06-16 10:07 ` [PATCH 5/5] New tests introduction mliska
2014-06-17 19:53   ` Jeff Law
2014-06-30 12:14     ` Martin Liška
2014-10-19  8:19       ` Andreas Schwab
2014-10-23 12:34         ` Martin Liška
2014-06-16 10:07 ` [PATCH 2/5] Existing call graph infrastructure enhancement mliska
2014-06-17 20:00   ` Jeff Law
2014-06-30 11:49     ` Martin Liška
2014-06-30 18:54       ` Jeff Law
2014-07-17 14:54         ` Martin Liška
2014-08-25  9:56           ` Martin Liška
2014-08-25 16:12             ` Jan Hubicka
2014-08-27 21:12             ` Jeff Law
2014-09-24 14:23   ` Martin Liška
2014-09-24 15:01     ` Jan Hubicka
2014-09-26 10:19       ` Martin Liška
2014-06-16 10:07 ` [PATCH 3/5] IPA ICF pass mliska
2014-06-20  7:32   ` Trevor Saunders
2014-06-26 11:18     ` Martin Liška
2014-07-05 21:44     ` Gerald Pfeifer
2014-07-05 22:53       ` Jan Hubicka
2014-07-17 15:23         ` Martin Liška
2014-09-26 12:20           ` Martin Liška
2014-09-26 14:44             ` Markus Trippelsdorf
2014-09-26 23:27               ` Jan Hubicka
2014-09-27  5:59                 ` Markus Trippelsdorf
2014-09-27  7:47                   ` Markus Trippelsdorf
2014-09-27 10:46                     ` Martin Liška
2014-09-27 10:37                   ` Martin Liška
2014-09-28  2:21                     ` Jan Hubicka
2014-10-10 23:54                       ` Fakturace
2014-10-11  0:02                       ` Martin Liška
2014-10-11  8:23                         ` Jan Hubicka
2014-10-13 13:20                           ` Martin Liška
2014-10-13 13:29                             ` Jan Hubicka
2014-09-27 10:32                 ` Martin Liška
2014-09-26 20:47             ` Jan Hubicka
2014-10-11  0:08               ` Martin Liška
2014-10-11  8:26                 ` Jan Hubicka
2014-10-13 15:17                 ` Martin Liška
2014-10-14 16:12                   ` Jan Hubicka
2014-10-15 17:06                     ` Martin Liška
2014-10-22 21:20                       ` Jiong Wang
2014-11-06  3:01                         ` Joey Ye
2014-11-06  9:03                           ` Jan Hubicka
2014-11-13 22:26                       ` H.J. Lu
2015-01-20 21:29                         ` H.J. Lu
2014-09-26 22:27             ` Jan Hubicka
2014-10-11  0:23               ` Martin Liška
2014-10-11  9:05                 ` Jan Hubicka
2014-06-24 20:31   ` Jeff Law
2014-06-26 16:02     ` Martin Liška
2014-06-26 18:46     ` Jan Hubicka [this message]
2014-06-30 12:05       ` Martin Liška
2014-07-01 23:45         ` Trevor Saunders
2014-06-30 19:06       ` Jeff Law
2014-06-16 10:07 ` [PATCH 4/5] Existing tests fix mliska
2014-06-17 19:52   ` Jeff Law
2014-06-17 20:50     ` Rainer Orth
2014-06-18  9:02       ` Martin Liška
2014-06-30 12:12     ` Martin Liška
2014-09-26 12:21       ` Martin Liška
2014-06-17 19:49 ` [PATCH 1/5] New Identical Code Folding IPA pass Jeff Law
2014-06-18 19:05   ` Jan Hubicka
2014-06-17 20:09 ` Paolo Carlini
2014-06-18  8:46   ` Martin Liška
2014-06-18  8:49     ` Paolo Carlini
2014-06-17 20:17 ` David Malcolm
2014-06-18  8:10   ` Martin Liška

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=20140626184614.GB29056@kam.mff.cuni.cz \
    --to=hubicka@ucw.cz \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=law@redhat.com \
    --cc=mliska@suse.cz \
    /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).