Hello.

There are 4 patches I'm going to install.
Patches can bootstrap on x86_64-linux-gnu and survives regression tests.

Martin
>From d0337d6690f925a323f6b271e9a138ae463c9e7e Mon Sep 17 00:00:00 2001
From: marxin <marxin@138bc75d-0d04-0410-961f-82ee72b054a4>
Date: Fri, 3 Feb 2017 15:22:47 +0000
Subject: [PATCH 1/4] Backport r245155

gcc/ChangeLog:

2017-02-03  Martin Liska  <mli...@suse.cz>

	PR lto/66295
	* multiple_target.c (create_dispatcher_calls): Redirect edge
	from a caller of a dispatcher.
	(expand_target_clones): Make the clones local.
	(ipa_target_clone): Do both target clones and resolvers.
	(ipa_dispatcher_calls): Remove the pass.
	(pass_dispatcher_calls::gate): Likewise.
	(make_pass_dispatcher_calls): Likewise.
	* passes.def (pass_target_clone): Put as very first IPA early
	pass.

gcc/testsuite/ChangeLog:

2017-02-03  Martin Liska  <mli...@suse.cz>

	PR lto/66295
	* gcc.target/i386/mvc9.c: New test.
---
 gcc/multiple_target.c                | 71 +++++-------------------------------
 gcc/passes.def                       |  3 +-
 gcc/testsuite/gcc.target/i386/mvc9.c | 28 ++++++++++++++
 3 files changed, 39 insertions(+), 63 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/i386/mvc9.c

diff --git a/gcc/multiple_target.c b/gcc/multiple_target.c
index 5edd8bb2ced..11e3fe7bc7b 100644
--- a/gcc/multiple_target.c
+++ b/gcc/multiple_target.c
@@ -94,6 +94,7 @@ create_dispatcher_calls (struct cgraph_node *node)
 	inode->resolve_alias (cgraph_node::get (resolver_decl));
 
       e->redirect_callee (inode);
+      e->redirect_call_stmt_to_callee ();
       /*  Since REDIRECT_CALLEE modifies NEXT_CALLER field we move to
 	  previously set NEXT_CALLER.  */
       e = NULL;
@@ -290,6 +291,7 @@ expand_target_clones (struct cgraph_node *node, bool definition)
       create_new_asm_name (attr, suffix);
       /* Create new target clone.  */
       cgraph_node *new_node = create_target_clone (node, definition, suffix);
+      new_node->local.local = false;
       XDELETEVEC (suffix);
 
       /* Set new attribute for the clone.  */
@@ -341,17 +343,19 @@ expand_target_clones (struct cgraph_node *node, bool definition)
   return ret;
 }
 
-static bool target_clone_pass;
-
 static unsigned int
 ipa_target_clone (void)
 {
   struct cgraph_node *node;
 
-  target_clone_pass = false;
+  bool target_clone_pass = false;
   FOR_EACH_FUNCTION (node)
-    if (node->definition)
-      target_clone_pass |= expand_target_clones (node, true);
+    target_clone_pass |= expand_target_clones (node, node->definition);
+
+  if (target_clone_pass)
+    FOR_EACH_FUNCTION (node)
+      create_dispatcher_calls (node);
+
   return 0;
 }
 
@@ -367,7 +371,7 @@ const pass_data pass_data_target_clone =
   0,				/* properties_provided */
   0,				/* properties_destroyed */
   0,				/* todo_flags_start */
-  0				/* todo_flags_finish */
+  TODO_update_ssa		/* todo_flags_finish */
 };
 
 class pass_target_clone : public simple_ipa_opt_pass
@@ -395,58 +399,3 @@ make_pass_target_clone (gcc::context *ctxt)
 {
   return new pass_target_clone (ctxt);
 }
-
-static unsigned int
-ipa_dispatcher_calls (void)
-{
-  struct cgraph_node *node;
-
-  FOR_EACH_FUNCTION (node)
-    if (!node->definition)
-      target_clone_pass |= expand_target_clones (node, false);
-  if (target_clone_pass)
-    FOR_EACH_FUNCTION (node)
-      create_dispatcher_calls (node);
-  return 0;
-}
-
-namespace {
-
-const pass_data pass_data_dispatcher_calls =
-{
-  SIMPLE_IPA_PASS,		/* type */
-  "dispachercalls",		/* name */
-  OPTGROUP_NONE,		/* optinfo_flags */
-  TV_NONE,			/* tv_id */
-  ( PROP_ssa | PROP_cfg ),	/* properties_required */
-  0,				/* properties_provided */
-  0,				/* properties_destroyed */
-  0,				/* todo_flags_start */
-  0				/* todo_flags_finish */
-};
-
-class pass_dispatcher_calls : public simple_ipa_opt_pass
-{
-public:
-  pass_dispatcher_calls (gcc::context *ctxt)
-    : simple_ipa_opt_pass (pass_data_dispatcher_calls, ctxt)
-  {}
-
-  /* opt_pass methods: */
-  virtual bool gate (function *);
-  virtual unsigned int execute (function *) { return ipa_dispatcher_calls (); }
-};
-
-bool
-pass_dispatcher_calls::gate (function *)
-{
-  return true;
-}
-
-} // anon namespace
-
-simple_ipa_opt_pass *
-make_pass_dispatcher_calls (gcc::context *ctxt)
-{
-  return new pass_dispatcher_calls (ctxt);
-}
diff --git a/gcc/passes.def b/gcc/passes.def
index 7aed1444542..7db9c9577cf 100644
--- a/gcc/passes.def
+++ b/gcc/passes.def
@@ -132,6 +132,7 @@ along with GCC; see the file COPYING3.  If not see
       POP_INSERT_PASSES ()
   POP_INSERT_PASSES ()
 
+  NEXT_PASS (pass_target_clone);
   NEXT_PASS (pass_ipa_chkp_produce_thunks);
   NEXT_PASS (pass_ipa_auto_profile);
   NEXT_PASS (pass_ipa_free_inline_summary);
@@ -151,7 +152,6 @@ along with GCC; see the file COPYING3.  If not see
   NEXT_PASS (pass_ipa_devirt);
   NEXT_PASS (pass_ipa_cp);
   NEXT_PASS (pass_ipa_cdtor_merge);
-  NEXT_PASS (pass_target_clone);
   NEXT_PASS (pass_ipa_hsa);
   NEXT_PASS (pass_ipa_inline);
   NEXT_PASS (pass_ipa_pure_const);
@@ -169,7 +169,6 @@ along with GCC; see the file COPYING3.  If not see
      compiled unit.  */
   INSERT_PASSES_AFTER (all_late_ipa_passes)
   NEXT_PASS (pass_ipa_pta);
-  NEXT_PASS (pass_dispatcher_calls);
   NEXT_PASS (pass_omp_simd_clone);
   TERMINATE_PASS_LIST ()
 
diff --git a/gcc/testsuite/gcc.target/i386/mvc9.c b/gcc/testsuite/gcc.target/i386/mvc9.c
new file mode 100644
index 00000000000..69e3cefb7d1
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/mvc9.c
@@ -0,0 +1,28 @@
+/* { dg-do run } */
+/* { dg-require-ifunc "" } */
+/* { dg-options "-flto -O2" { target lto } } */
+
+__attribute__((target_clones("avx","arch=slm","arch=core-avx2","default")))
+int
+foo ()
+{
+  return -2;
+}
+
+int
+bar ()
+{
+  return 2;
+}
+
+int
+main ()
+{
+  int r = 0;
+  r += bar ();
+  r += foo ();
+  r += bar ();
+  r += foo ();
+  r += bar ();
+  return r - 2;
+}
-- 
2.12.0

>From 053c84d56e3e8a70a978f5180d05422756bfb155 Mon Sep 17 00:00:00 2001
From: marxin <marxin@138bc75d-0d04-0410-961f-82ee72b054a4>
Date: Wed, 22 Feb 2017 09:45:42 +0000
Subject: [PATCH 2/4] Backport r245647

gcc/ChangeLog:

2017-02-22  Martin Liska  <mli...@suse.cz>

	PR lto/79587
	* data-streamer-in.c (streamer_read_gcov_count): Remove assert.
	* data-streamer-out.c (streamer_write_gcov_count_stream):
	Likewise.
	* value-prof.c (stream_out_histogram_value): Make assert more
	precise based on type of counter.

gcc/testsuite/ChangeLog:

2017-02-22  Martin Liska  <mli...@suse.cz>

	PR lto/79587
	* gcc.dg/tree-prof/pr79587.c: New test.
---
 gcc/data-streamer-in.c                   |  1 -
 gcc/data-streamer-out.c                  |  1 -
 gcc/testsuite/gcc.dg/tree-prof/pr79587.c | 26 ++++++++++++++++++++++++++
 gcc/value-prof.c                         | 12 +++++++++++-
 4 files changed, 37 insertions(+), 3 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/tree-prof/pr79587.c

diff --git a/gcc/data-streamer-in.c b/gcc/data-streamer-in.c
index 2625af6470e..787688d9c3e 100644
--- a/gcc/data-streamer-in.c
+++ b/gcc/data-streamer-in.c
@@ -181,6 +181,5 @@ gcov_type
 streamer_read_gcov_count (struct lto_input_block *ib)
 {
   gcov_type ret = streamer_read_hwi (ib);
-  gcc_assert (ret >= 0);
   return ret;
 }
diff --git a/gcc/data-streamer-out.c b/gcc/data-streamer-out.c
index e476530579d..47b5fec49d5 100644
--- a/gcc/data-streamer-out.c
+++ b/gcc/data-streamer-out.c
@@ -340,7 +340,6 @@ streamer_write_hwi_stream (struct lto_output_stream *obs, HOST_WIDE_INT work)
 void
 streamer_write_gcov_count_stream (struct lto_output_stream *obs, gcov_type work)
 {
-  gcc_assert (work >= 0);
   gcc_assert ((HOST_WIDE_INT) work == work);
   streamer_write_hwi_stream (obs, work);
 }
diff --git a/gcc/testsuite/gcc.dg/tree-prof/pr79587.c b/gcc/testsuite/gcc.dg/tree-prof/pr79587.c
new file mode 100644
index 00000000000..517e0819919
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-prof/pr79587.c
@@ -0,0 +1,26 @@
+/* { dg-require-effective-target lto } */
+/* { dg-options "-O2 -flto" } */
+
+unsigned long global = -12345;
+
+unsigned long
+__attribute__((noinline))
+test(unsigned long v, unsigned long v2)
+{
+  unsigned long x = v % v2;
+
+  return x;
+}
+
+int main(int argc, char **argv)
+{
+  unsigned long r = 0;
+
+  for (int i = 0; i < 100; i++)
+    r += test(argc, global);
+
+  if (r != 100)
+    __builtin_abort ();
+
+  return 0;
+}
diff --git a/gcc/value-prof.c b/gcc/value-prof.c
index 89f6b865766..2e423954db1 100644
--- a/gcc/value-prof.c
+++ b/gcc/value-prof.c
@@ -384,7 +384,17 @@ stream_out_histogram_value (struct output_block *ob, histogram_value hist)
       break;
     }
   for (i = 0; i < hist->n_counters; i++)
-    streamer_write_gcov_count (ob, hist->hvalue.counters[i]);
+    {
+      /* When user uses an unsigned type with a big value, constant converted
+	 to gcov_type (a signed type) can be negative.  */
+      gcov_type value = hist->hvalue.counters[i];
+      if (hist->type == HIST_TYPE_SINGLE_VALUE && i == 0)
+	;
+      else
+	gcc_assert (value >= 0);
+
+      streamer_write_gcov_count (ob, value);
+    }
   if (hist->hvalue.next)
     stream_out_histogram_value (ob, hist->hvalue.next);
 }
-- 
2.12.0

>From 3dd19950d560ac22011dac425518ec1383725df9 Mon Sep 17 00:00:00 2001
From: marxin <marxin@138bc75d-0d04-0410-961f-82ee72b054a4>
Date: Tue, 14 Mar 2017 11:59:59 +0000
Subject: [PATCH 3/4] Backport r246119

gcc/ChangeLog:

2017-03-14  Martin Liska  <mli...@suse.cz>

	PR lto/66295
	* multiple_target.c (expand_target_clones): Drop local.local
	flag for default implementation.

gcc/testsuite/ChangeLog:

2017-03-14  Martin Liska  <mli...@suse.cz>

	PR lto/66295
	* gcc.dg/tree-prof/pr66295.c: New test.
---
 gcc/multiple_target.c                    |  1 +
 gcc/testsuite/gcc.dg/tree-prof/pr66295.c | 34 ++++++++++++++++++++++++++++++++
 2 files changed, 35 insertions(+)
 create mode 100644 gcc/testsuite/gcc.dg/tree-prof/pr66295.c

diff --git a/gcc/multiple_target.c b/gcc/multiple_target.c
index 11e3fe7bc7b..a314fae41f2 100644
--- a/gcc/multiple_target.c
+++ b/gcc/multiple_target.c
@@ -334,6 +334,7 @@ expand_target_clones (struct cgraph_node *node, bool definition)
   tree attributes = make_attribute ("target", "default",
 				    DECL_ATTRIBUTES (node->decl));
   DECL_ATTRIBUTES (node->decl) = attributes;
+  node->local.local = false;
   location_t saved_loc = input_location;
   input_location = DECL_SOURCE_LOCATION (node->decl);
   bool ret
diff --git a/gcc/testsuite/gcc.dg/tree-prof/pr66295.c b/gcc/testsuite/gcc.dg/tree-prof/pr66295.c
new file mode 100644
index 00000000000..1ab7e6c8f64
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-prof/pr66295.c
@@ -0,0 +1,34 @@
+/* { dg-require-ifunc "" } */
+/* { dg-options "-O2" } */
+
+static double bar (double *__restrict, double *__restrict, int)
+__attribute__ ((target_clones("avx,avx2,avx512f,default")));
+
+double
+foo (double *__restrict a, double *__restrict b, int n)
+{
+  return bar (a,b,n);
+}
+
+double
+bar (double *__restrict a, double *__restrict b, int n)	/* { dg-error "attribute\[^\n\r]*foo\[^\n\r]* is unknown" } */
+{
+  double s;
+  int i;
+  s = 0.0;
+  for (i=0; i<n; i++)
+    s += a[i] + b[i];
+
+  return s;
+}
+
+#define N 5
+
+int main ()
+{
+  double a[N] = {1.2f, 1.2f, 1.2f, 1.2f, 1.2f };
+  double b[N] = {1.2f, 1.2f, 1.2f, 1.2f, 1.2f };
+
+  __builtin_printf ("value: %.5f\n", foo (a, b, N));
+  return 0;
+}
-- 
2.12.0

>From 4bccc95d0ad5463dac83e56a3c515ff393ad9421 Mon Sep 17 00:00:00 2001
From: segher <segher@138bc75d-0d04-0410-961f-82ee72b054a4>
Date: Thu, 16 Mar 2017 18:18:58 +0000
Subject: [PATCH 4/4] Backport r246206

gcc/testsuite/ChangeLog:

2017-03-16  Segher Boessenkool  <seg...@kernel.crashing.org>

	* gcc.dg/tree-prof/pr66295.c: Skip unless on an x86 target.
---
 gcc/testsuite/gcc.dg/tree-prof/pr66295.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/gcc/testsuite/gcc.dg/tree-prof/pr66295.c b/gcc/testsuite/gcc.dg/tree-prof/pr66295.c
index 1ab7e6c8f64..e83e821387f 100644
--- a/gcc/testsuite/gcc.dg/tree-prof/pr66295.c
+++ b/gcc/testsuite/gcc.dg/tree-prof/pr66295.c
@@ -1,4 +1,5 @@
 /* { dg-require-ifunc "" } */
+/* { dg-skip-if "" { ! { i?86-*-* x86_64-*-* } } } */
 /* { dg-options "-O2" } */
 
 static double bar (double *__restrict, double *__restrict, int)
-- 
2.12.0

Reply via email to