From 58cfb15910ced16c45903f5860bb99e1aa37de47 Mon Sep 17 00:00:00 2001
From: David Malcolm <dmalcolm@redhat.com>
Date: Fri, 6 Jul 2018 13:52:58 -0400
Subject: [PATCH 55/58] FIXME: more test cases

---
 gcc/opt-problem.cc                             | 29 +++++++++++++++++++++-----
 gcc/opt-problem.h                              |  7 +++++++
 gcc/testsuite/gcc.dg/vect/vect-alias-check-4.c | 11 ++++++----
 gcc/testsuite/gcc.dg/vect/vect-remarks-1.c     | 18 ++++++++++++++++
 gcc/testsuite/gcc.dg/vect/vect-remarks.c       | 18 ----------------
 gcc/tree-vect-data-refs.c                      |  5 ++++-
 6 files changed, 60 insertions(+), 28 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/vect/vect-remarks-1.c
 delete mode 100644 gcc/testsuite/gcc.dg/vect/vect-remarks.c

diff --git a/gcc/opt-problem.cc b/gcc/opt-problem.cc
index 86e2877..cde8bce 100644
--- a/gcc/opt-problem.cc
+++ b/gcc/opt-problem.cc
@@ -31,15 +31,27 @@ along with GCC; see the file COPYING3.  If not see
 
 /* FIXME.  */
 
+opt_report::opt_report ()
+: m_loc (UNKNOWN_LOCATION)
+{
+}
+
+/* FIXME.  */
+
 bool
 opt_report::remark (dump_location_t loc, int opt, const char *gmsgid, ...)
 {
+  if (!flag_remarks)
+    return false;
+
   va_list ap;
   va_start (ap, gmsgid);
   bool ret = emit_diagnostic_valist (DK_REMARK, loc.get_location_t (), opt,
 				     gmsgid, &ap);
   va_end (ap);
 
+  m_loc = loc.get_location_t ();
+
   // FIXME: but also create an optinfo (but we don't want a duplicate remark)
   return ret;
 }
@@ -64,15 +76,22 @@ opt_problem::report_reason (opt_report &report)
   pretty_printer pp;
   pp_show_color (&pp) = pp_show_color (global_dc->printer);
   pp_string (&pp, m_text);
-  pp_string (&pp, ": ");
-  pp_begin_quote (&pp, show_color);
-  pp_gimple_stmt_1 (&pp, m_stmt, 0, TDF_SLIM);
-  pp_end_quote (&pp, show_color);
+  if (m_stmt)
+    {
+      pp_string (&pp, ": ");
+      pp_begin_quote (&pp, show_color);
+      pp_gimple_stmt_1 (&pp, m_stmt, 0, TDF_SLIM);
+      pp_end_quote (&pp, show_color);
+    }
 
   print_impl_location (&pp, m_impl_location);
 
   const char *msg = pp_formatted_text (&pp);
 
-  inform (gimple_location_safe (m_stmt), "%s", msg);
+  location_t loc = gimple_location_safe (m_stmt);
+  if (loc == UNKNOWN_LOCATION)
+    loc = report.get_location ();
+
+  inform (loc, "%s", msg);
 #endif
 }
diff --git a/gcc/opt-problem.h b/gcc/opt-problem.h
index a252414..f036199 100644
--- a/gcc/opt-problem.h
+++ b/gcc/opt-problem.h
@@ -30,8 +30,15 @@ along with GCC; see the file COPYING3.  If not see
 class opt_report
 {
 public:
+  opt_report ();
+
   bool remark (dump_location_t, int, const char *, ...)
     ATTRIBUTE_GCC_DIAG(4,5);
+
+  location_t get_location () const { return m_loc; }
+
+ private:
+  location_t m_loc;
 };
 
 /* When -fopt-info is enabled: information about why an optimization
diff --git a/gcc/testsuite/gcc.dg/vect/vect-alias-check-4.c b/gcc/testsuite/gcc.dg/vect/vect-alias-check-4.c
index 1e5fc27..b08b4b4 100644
--- a/gcc/testsuite/gcc.dg/vect/vect-alias-check-4.c
+++ b/gcc/testsuite/gcc.dg/vect/vect-alias-check-4.c
@@ -1,6 +1,6 @@
 /* { dg-do compile } */
 /* { dg-require-effective-target vect_int } */
-/* { dg-additional-options "--param vect-max-version-for-alias-checks=0" } */
+/* { dg-additional-options "--param vect-max-version-for-alias-checks=0 -fremarks" } */
 
 #define N 16
 
@@ -14,22 +14,25 @@ union u { struct s2 f; struct s3 g; };
 void
 f1 (int a[][N], int b[][N])
 {
-  for (int i = 0; i < N; ++i)
+  for (int i = 0; i < N; ++i) /* { dg-remark "couldn't vectorize loop" } */
     a[0][i] += b[0][i];
+  /* { dg-message "will not create alias checks, as --param vect-max-version-for-alias-checks == 0" "" { target *-*-* } .-2 } */
 }
 
 void
 f2 (union u *a, union u *b)
 {
-  for (int i = 0; i < N; ++i)
+  for (int i = 0; i < N; ++i) /* { dg-remark "couldn't vectorize loop" } */
     a->f.b.a[i] += b->g.e.a[i];
+  /* { dg-message "will not create alias checks, as --param vect-max-version-for-alias-checks == 0" "" { target *-*-* } .-2 } */
 }
 
 void
 f3 (struct s1 *a, struct s1 *b)
 {
-  for (int i = 0; i < N - 1; ++i)
+  for (int i = 0; i < N - 1; ++i) /* { dg-remark "couldn't vectorize loop" } */
     a->a[i + 1] += b->a[i];
+  /* { dg-message "possible dependence between data-refs" "" { target *-*-* } .-2 } */
 }
 
 /* { dg-final { scan-tree-dump-not "LOOP VECTORIZED" "vect" } } */
diff --git a/gcc/testsuite/gcc.dg/vect/vect-remarks-1.c b/gcc/testsuite/gcc.dg/vect/vect-remarks-1.c
new file mode 100644
index 0000000..5006742
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/vect/vect-remarks-1.c
@@ -0,0 +1,18 @@
+/* { dg-do compile } */
+/* { dg-options "-fremarks -O3" } */
+
+extern void accumulate (int x, int *a);
+
+int test_1 (int arr[], int n)
+{
+  int sum = 0;
+  for (int i = 0; i < n; ++i) /* { dg-remark "couldn't vectorize loop" } */
+    accumulate (arr[i], &sum); /* { dg-message "statement clobbers memory: 'accumulate .*'" } */
+  return sum;
+}
+
+void test_2 (int *dst, int *src_a, int *src_b, int n)
+{
+  for (int i = 0; i < n; i++) /* { dg-remark "loop vectorized" } */
+    dst[i] = src_a[i] + src_b[i];
+}
diff --git a/gcc/testsuite/gcc.dg/vect/vect-remarks.c b/gcc/testsuite/gcc.dg/vect/vect-remarks.c
deleted file mode 100644
index 5006742..0000000
--- a/gcc/testsuite/gcc.dg/vect/vect-remarks.c
+++ /dev/null
@@ -1,18 +0,0 @@
-/* { dg-do compile } */
-/* { dg-options "-fremarks -O3" } */
-
-extern void accumulate (int x, int *a);
-
-int test_1 (int arr[], int n)
-{
-  int sum = 0;
-  for (int i = 0; i < n; ++i) /* { dg-remark "couldn't vectorize loop" } */
-    accumulate (arr[i], &sum); /* { dg-message "statement clobbers memory: 'accumulate .*'" } */
-  return sum;
-}
-
-void test_2 (int *dst, int *src_a, int *src_b, int n)
-{
-  for (int i = 0; i < n; i++) /* { dg-remark "loop vectorized" } */
-    dst[i] = src_a[i] + src_b[i];
-}
diff --git a/gcc/tree-vect-data-refs.c b/gcc/tree-vect-data-refs.c
index 80dd4b1..eceb6f2 100644
--- a/gcc/tree-vect-data-refs.c
+++ b/gcc/tree-vect-data-refs.c
@@ -161,7 +161,10 @@ vect_mark_for_runtime_alias_test (ddr_p ddr, loop_vec_info loop_vinfo)
   struct loop *loop = LOOP_VINFO_LOOP (loop_vinfo);
 
   if ((unsigned) PARAM_VALUE (PARAM_VECT_MAX_VERSION_FOR_ALIAS_CHECKS) == 0)
-    return opt_result::failure ("FIXME", NULL);
+    // FIXME: formatted print?
+    return opt_result::failure ("will not create alias checks, as"
+				" --param vect-max-version-for-alias-checks"
+				" == 0", NULL);
 
   opt_result res
     = runtime_alias_check_p (ddr, loop,
-- 
1.8.5.3

