[PATCH] Add tests for PR tree-optimization/88531

2021-08-07 Thread H.J. Lu via Gcc-patches
PR tree-optimization/88531
* gcc.target/i386/pr88531-1a.c: New test.
* gcc.target/i386/pr88531-1b.c: Likewise.
* gcc.target/i386/pr88531-1c.c: Likewise.
* gcc.target/i386/pr88531-2a.c: Likewise.
* gcc.target/i386/pr88531-2b.c: Likewise.
* gcc.target/i386/pr88531-2c.c: Likewise.
---
 gcc/testsuite/gcc.target/i386/pr88531-1a.c | 19 +++
 gcc/testsuite/gcc.target/i386/pr88531-1b.c |  8 
 gcc/testsuite/gcc.target/i386/pr88531-1c.c |  8 
 gcc/testsuite/gcc.target/i386/pr88531-2a.c | 19 +++
 gcc/testsuite/gcc.target/i386/pr88531-2b.c |  6 ++
 gcc/testsuite/gcc.target/i386/pr88531-2c.c |  6 ++
 6 files changed, 66 insertions(+)
 create mode 100644 gcc/testsuite/gcc.target/i386/pr88531-1a.c
 create mode 100644 gcc/testsuite/gcc.target/i386/pr88531-1b.c
 create mode 100644 gcc/testsuite/gcc.target/i386/pr88531-1c.c
 create mode 100644 gcc/testsuite/gcc.target/i386/pr88531-2a.c
 create mode 100644 gcc/testsuite/gcc.target/i386/pr88531-2b.c
 create mode 100644 gcc/testsuite/gcc.target/i386/pr88531-2c.c

diff --git a/gcc/testsuite/gcc.target/i386/pr88531-1a.c 
b/gcc/testsuite/gcc.target/i386/pr88531-1a.c
new file mode 100644
index 000..d1c29b2c990
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr88531-1a.c
@@ -0,0 +1,19 @@
+/* { dg-do compile { target lp64 } } */
+/* { dg-options "-O3 -march=x86-64 -mfpmath=sse" } */
+
+#include 
+
+#define loop_t uint32_t
+#define idx_t uint32_t
+
+void loop(double * const __restrict__ dst,
+  double const * const __restrict__ src,
+  idx_t const * const __restrict__ idx,
+  loop_t const begin,
+  loop_t const end)
+{
+  for (loop_t i = begin; i < end; ++i)
+dst[i] = 42.0 * src[idx[i]];
+}
+
+/* { dg-final { scan-assembler-times "mulpd" 2 } } */
diff --git a/gcc/testsuite/gcc.target/i386/pr88531-1b.c 
b/gcc/testsuite/gcc.target/i386/pr88531-1b.c
new file mode 100644
index 000..812c8a10fab
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr88531-1b.c
@@ -0,0 +1,8 @@
+/* { dg-do compile } */
+/* { dg-options "-O3 -march=skylake -mfpmath=sse" } */
+
+#include "pr88531-1a.c"
+
+/* { dg-final { scan-assembler-times "vgatherdpd" 4 { target { ! lp64 } } } } 
*/
+/* { dg-final { scan-assembler-times "vgatherqpd" 4 { target lp64 } } } */
+/* { dg-final { scan-assembler-times "vmulpd" 4 } } */
diff --git a/gcc/testsuite/gcc.target/i386/pr88531-1c.c 
b/gcc/testsuite/gcc.target/i386/pr88531-1c.c
new file mode 100644
index 000..43fc5913ed3
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr88531-1c.c
@@ -0,0 +1,8 @@
+/* { dg-do compile } */
+/* { dg-options "-O3 -march=skylake-avx512 -mfpmath=sse" } */
+
+#include "pr88531-1a.c"
+
+/* { dg-final { scan-assembler-times "vgatherdpd" 4 { target { ! lp64 } } } } 
*/
+/* { dg-final { scan-assembler-times "vgatherqpd" 4 { target lp64 } } } */
+/* { dg-final { scan-assembler-times "vmulpd" 4 } } */
diff --git a/gcc/testsuite/gcc.target/i386/pr88531-2a.c 
b/gcc/testsuite/gcc.target/i386/pr88531-2a.c
new file mode 100644
index 000..8ab2b1385eb
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr88531-2a.c
@@ -0,0 +1,19 @@
+/* { dg-do compile } */
+/* { dg-options "-O3 -march=x86-64 -mfpmath=sse" } */
+
+#include 
+
+#define loop_t uint32_t
+#define idx_t uint32_t
+
+void loop(float * const __restrict__ dst,
+  float const * const __restrict__ src,
+  idx_t const * const __restrict__ idx,
+  loop_t const begin,
+  loop_t const end)
+{
+  for (loop_t i = begin; i < end; ++i)
+dst[i] = 42.0 * src[idx[i]];
+}
+
+/* { dg-final { scan-assembler-times "mulps" 1 } } */
diff --git a/gcc/testsuite/gcc.target/i386/pr88531-2b.c 
b/gcc/testsuite/gcc.target/i386/pr88531-2b.c
new file mode 100644
index 000..011607c3d54
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr88531-2b.c
@@ -0,0 +1,6 @@
+/* { dg-do compile } */
+/* { dg-options "-O3 -march=skylake -mfpmath=sse" } */
+
+#include "pr88531-2a.c"
+
+/* { dg-final { scan-assembler-times "vmulps" 2 } } */
diff --git a/gcc/testsuite/gcc.target/i386/pr88531-2c.c 
b/gcc/testsuite/gcc.target/i386/pr88531-2c.c
new file mode 100644
index 000..0f7ec3832f8
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr88531-2c.c
@@ -0,0 +1,6 @@
+/* { dg-do compile } */
+/* { dg-options "-O3 -march=skylake-avx512 -mfpmath=sse" } */
+
+#include "pr88531-2a.c"
+
+/* { dg-final { scan-assembler-times "vmulps" 2 } } */
-- 
2.31.1



[PATCH] x86: Optimize load of const all 1s float vectors

2021-08-07 Thread H.J. Lu via Gcc-patches
Update vector_all_ones_operand to return true for const all 1s float
vectors.

gcc/

PR target/101804
* config/i386/predicates.md (vector_all_ones_operand): Return
true for const all 1s float vectors.

gcc/testsuite/

PR target/101804
* gcc.target/i386/avx2-gather-2.c: Pass -march=skylake instead
of "-mavx2 -mtune=skylake".  Scan vpcmpeqd.
---
 gcc/config/i386/predicates.md | 7 ---
 gcc/testsuite/gcc.target/i386/avx2-gather-2.c | 3 ++-
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/gcc/config/i386/predicates.md b/gcc/config/i386/predicates.md
index 6aa1ea32627..9637e64ea58 100644
--- a/gcc/config/i386/predicates.md
+++ b/gcc/config/i386/predicates.md
@@ -1126,9 +1126,10 @@ (define_predicate "float_vector_all_ones_operand"
 
 /* Return true if operand is a vector constant that is all ones. */
 (define_predicate "vector_all_ones_operand"
-  (and (match_code "const_vector")
-   (match_test "INTEGRAL_MODE_P (GET_MODE (op))")
-   (match_test "op == CONSTM1_RTX (GET_MODE (op))")))
+  (ior (and (match_code "const_vector")
+   (match_test "INTEGRAL_MODE_P (GET_MODE (op))")
+   (match_test "op == CONSTM1_RTX (GET_MODE (op))"))
+   (match_operand 0 "float_vector_all_ones_operand")))
 
 ; Return true when OP is operand acceptable for vector memory operand.
 ; Only AVX can have misaligned memory operand.
diff --git a/gcc/testsuite/gcc.target/i386/avx2-gather-2.c 
b/gcc/testsuite/gcc.target/i386/avx2-gather-2.c
index 1a704afd834..ad5ef73107c 100644
--- a/gcc/testsuite/gcc.target/i386/avx2-gather-2.c
+++ b/gcc/testsuite/gcc.target/i386/avx2-gather-2.c
@@ -1,6 +1,7 @@
 /* { dg-do compile } */
-/* { dg-options "-O3 -mavx2 -fdump-tree-vect-details -mtune=skylake" } */
+/* { dg-options "-O3 -fdump-tree-vect-details -march=skylake" } */
 
 #include "avx2-gather-1.c"
 
 /* { dg-final { scan-tree-dump-times "vectorized 1 loops in function" 16 
"vect" } } */
+/* { dg-final { scan-assembler "vpcmpeqd" } } */
-- 
2.31.1



[PATCH 2/2] fortran: Ignore unused args in scalarization [PR97896]

2021-08-07 Thread Mikael Morin via Gcc-patches

The KIND argument of the INDEX intrinsic is a compile time constant
that is used at compile time only to resolve to a kind-specific library
method.  It is otherwise completely ignored at runtime, and there is
no code generated for it as the library procedure has no kind argument.
This confuses the scalarizer which expects to see every argument
of elemental functions to be used when calling a procedure.
This change removes the argument from the scalarization lists
at the beginning of the scalarization process, so that the argument
is completely ignored.

gcc/fortran/
PR fortran/97896
* trans-array.h (gfc_get_intrinsic_for_expr,
gfc_get_proc_ifc_for_expr): New.
* trans-array.c (gfc_get_intrinsic_for_expr,
arg_evaluated_for_scalarization): New.
(gfc_walk_elemental_function_args): Add intrinsic procedure
as argument.  Count arguments.  Check arg_evaluated_for_scalarization.
* trans-intrinsic.c (gfc_walk_intrinsic_function): Update call.
* trans-stmt.c (get_intrinsic_for_code): New.
(gfc_trans_call): Update call.

gcc/testsuite/
PR fortran/97896
* gfortran.dg/index_5.f90: New.
---
 gcc/fortran/trans-array.c | 61 ++-
 gcc/fortran/trans-array.h |  3 ++
 gcc/fortran/trans-intrinsic.c |  1 +
 gcc/fortran/trans-stmt.c  | 20 +
 gcc/testsuite/gfortran.dg/index_5.f90 | 23 ++
 5 files changed, 107 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gfortran.dg/index_5.f90

diff --git a/gcc/fortran/trans-array.c b/gcc/fortran/trans-array.c
index c5d61f0065c..aae79c8cbd4 100644
--- a/gcc/fortran/trans-array.c
+++ b/gcc/fortran/trans-array.c
@@ -11177,6 +11177,59 @@ gfc_get_proc_ifc_for_expr (gfc_expr *procedure_ref)
 }
 
 
+/* Given an expression referring to an intrinsic function call,
+   return the intrinsic symbol.  */
+
+gfc_intrinsic_sym *
+gfc_get_intrinsic_for_expr (gfc_expr *call)
+{
+  if (call == NULL)
+return NULL;
+
+  /* Normal procedure case.  */
+  if (call->expr_type == EXPR_FUNCTION)
+return call->value.function.isym;
+  else
+return NULL;
+}
+
+
+/* Indicates whether an argument to an intrinsic function should be used in
+   scalarization.  It is usually the case, except for some intrinsics
+   requiring the value to be constant, and using the value at compile time only.
+   As the value is not used at runtime in those cases, we don’t produce code
+   for it, and it should not be visible to the scalarizer.
+   FUNCTION is the intrinsic function being called, ACTUAL_ARG is the actual
+   argument being examined in that call, and ARG_NUM the index number
+   of ACTUAL_ARG in the list of arguments.
+   The intrinsic procedure’s dummy argument associated with ACTUAL_ARG is
+   identified using the name in ACTUAL_ARG if it is present (that is: if it’s
+   a keyword argument), otherwise using ARG_NUM.  */
+
+static bool
+arg_evaluated_for_scalarization (gfc_intrinsic_sym *function,
+ gfc_actual_arglist &actual_arg, int arg_num)
+{
+  if (function != NULL)
+{
+  switch (function->id)
+	{
+	  case GFC_ISYM_INDEX:
+	if ((actual_arg.name == NULL && arg_num == 3)
+		|| (actual_arg.name != NULL
+		&& strcmp ("kind", actual_arg.name) == 0))
+	  return false;
+	  /* Fallthrough.  */
+
+	  default:
+	break;
+	}
+}
+
+  return true;
+}
+
+
 /* Walk the arguments of an elemental function.
PROC_EXPR is used to check whether an argument is permitted to be absent.  If
it is NULL, we don't do the check and the argument is assumed to be present.
@@ -11184,6 +11237,7 @@ gfc_get_proc_ifc_for_expr (gfc_expr *procedure_ref)
 
 gfc_ss *
 gfc_walk_elemental_function_args (gfc_ss * ss, gfc_actual_arglist *arg,
+  gfc_intrinsic_sym *intrinsic_sym,
   gfc_symbol *proc_ifc, gfc_ss_type type)
 {
   gfc_formal_arglist *dummy_arg;
@@ -11200,10 +11254,13 @@ gfc_walk_elemental_function_args (gfc_ss * ss, gfc_actual_arglist *arg,
   else
 dummy_arg = NULL;
 
+  int arg_num = 0;
   scalar = 1;
   for (; arg; arg = arg->next)
 {
-  if (!arg->expr || arg->expr->expr_type == EXPR_NULL)
+  if (!arg->expr
+	  || arg->expr->expr_type == EXPR_NULL
+	  || !arg_evaluated_for_scalarization (intrinsic_sym, *arg, arg_num))
 	goto loop_continue;
 
   newss = gfc_walk_subexpr (head, arg->expr);
@@ -11236,6 +11293,7 @@ gfc_walk_elemental_function_args (gfc_ss * ss, gfc_actual_arglist *arg,
 }
 
 loop_continue:
+  arg_num++;
   if (dummy_arg != NULL)
 	dummy_arg = dummy_arg->next;
 }
@@ -11296,6 +11354,7 @@ gfc_walk_function_expr (gfc_ss * ss, gfc_expr * expr)
 
   ss = gfc_walk_elemental_function_args (old_ss,
 	 expr->value.function.actual,
+	 gfc_get_intrinsic_for_expr (expr),
 	 gfc_get_proc_ifc_for_expr (expr),
 	 GFC_SS_REFERENCE);
   if (ss != old_ss
diff --git a/gcc/fortran/trans-array.h b/gcc/fortran/trans-array.h
in

[PATCH 0/2] fortran: Ignore unused arguments for scalarisation [PR97896]

2021-08-07 Thread Mikael Morin via Gcc-patches
Hello,

This is a variant of the patch series previously posted for master at [1], 
without patches 1 to 5.
It has a more limited impact, which makes it more suitable for the release 
branches.

The problematic case is intrinsic procedures where an argument is actually not 
used in the code generated (KIND argument of INDEX in the testcase), which 
confuses the scalariser.

Thomas König comitted a change to workaround the problem, but it regressed in 
PR97896.  These patch put the workaround where I think it is more appropriate, 
namely at the beginning of the scalarisation procedure.  This is the patch 2 of 
the series, preceded with the revert in patch 1.  I intend to commit both of 
them squashed together.

Regression-tested on x86_64-linux-gnu.  Ok for 11 branch? 


[1] https://gcc.gnu.org/pipermail/fortran/2021-August/056317.html

Mikael Morin (2):
  Revert "Remove KIND argument from INDEX so it does not mess up
scalarization."
  fortran: Ignore unused args in scalarization [PR97896]

 gcc/fortran/intrinsic.c   | 48 +++--
 gcc/fortran/intrinsic.h   |  3 +-
 gcc/fortran/iresolve.c| 21 ++---
 gcc/fortran/trans-array.c | 61 ++-
 gcc/fortran/trans-array.h |  3 ++
 gcc/fortran/trans-decl.c  | 24 +--
 gcc/fortran/trans-intrinsic.c |  1 +
 gcc/fortran/trans-stmt.c  | 20 +
 gcc/testsuite/gfortran.dg/index_5.f90 | 23 ++
 9 files changed, 121 insertions(+), 83 deletions(-)
 create mode 100644 gcc/testsuite/gfortran.dg/index_5.f90

-- 
2.30.2



[PATCH 1/2] Revert "Remove KIND argument from INDEX so it does not mess up scalarization."

2021-08-07 Thread Mikael Morin via Gcc-patches

This reverts commit d09847357b965a2c2cda063827ce362d4c9c86f2 except for
its testcase.

gcc/fortran/
* intrinsic.c (add_sym_4ind): Remove.
(add_functions): Use add_sym4 instead of add_sym4ind.
Don’t special case the index intrinsic.
* iresolve.c (gfc_resolve_index_func): Use the individual arguments
directly instead of the full argument list.
* intrinsic.h (gfc_resolve_index_func): Update the declaration
accordingly.
* trans-decl.c (gfc_get_extern_function_decl): Don’t modify the
list of arguments in the case of the index intrinsic.
---
 gcc/fortran/intrinsic.c  | 48 ++--
 gcc/fortran/intrinsic.h  |  3 ++-
 gcc/fortran/iresolve.c   | 21 --
 gcc/fortran/trans-decl.c | 24 +---
 4 files changed, 14 insertions(+), 82 deletions(-)

diff --git a/gcc/fortran/intrinsic.c b/gcc/fortran/intrinsic.c
index 219f04f2317..577e25a7671 100644
--- a/gcc/fortran/intrinsic.c
+++ b/gcc/fortran/intrinsic.c
@@ -888,39 +888,6 @@ add_sym_4 (const char *name, gfc_isym_id id, enum klass cl, int actual_ok, bt ty
 	   (void *) 0);
 }
 
-/* Add a symbol to the function list where the function takes 4
-   arguments and resolution may need to change the number or
-   arrangement of arguments. This is the case for INDEX, which needs
-   its KIND argument removed.  */
-
-static void
-add_sym_4ind (const char *name, gfc_isym_id id, enum klass cl, int actual_ok,
-	  bt type, int kind, int standard,
-	  bool (*check) (gfc_expr *, gfc_expr *, gfc_expr *, gfc_expr *),
-	  gfc_expr *(*simplify) (gfc_expr *, gfc_expr *, gfc_expr *,
- gfc_expr *),
-	  void (*resolve) (gfc_expr *, gfc_actual_arglist *),
-	  const char *a1, bt type1, int kind1, int optional1,
-	  const char *a2, bt type2, int kind2, int optional2,
-	  const char *a3, bt type3, int kind3, int optional3,
-	  const char *a4, bt type4, int kind4, int optional4 )
-{
-  gfc_check_f cf;
-  gfc_simplify_f sf;
-  gfc_resolve_f rf;
-
-  cf.f4 = check;
-  sf.f4 = simplify;
-  rf.f1m = resolve;
-
-  add_sym (name, id, cl, actual_ok, type, kind, standard, cf, sf, rf,
-	   a1, type1, kind1, optional1, INTENT_IN,
-	   a2, type2, kind2, optional2, INTENT_IN,
-	   a3, type3, kind3, optional3, INTENT_IN,
-	   a4, type4, kind4, optional4, INTENT_IN,
-	   (void *) 0);
-}
-
 
 /* Add a symbol to the subroutine list where the subroutine takes
4 arguments.  */
@@ -2223,11 +2190,11 @@ add_functions (void)
 
   /* The resolution function for INDEX is called gfc_resolve_index_func
  because the name gfc_resolve_index is already used in resolve.c.  */
-  add_sym_4ind ("index", GFC_ISYM_INDEX, CLASS_ELEMENTAL, ACTUAL_YES,
-		BT_INTEGER, di, GFC_STD_F77,
-		gfc_check_index, gfc_simplify_index, gfc_resolve_index_func,
-		stg, BT_CHARACTER, dc, REQUIRED, ssg, BT_CHARACTER, dc, REQUIRED,
-		bck, BT_LOGICAL, dl, OPTIONAL, kind, BT_INTEGER, di, OPTIONAL);
+  add_sym_4 ("index", GFC_ISYM_INDEX, CLASS_ELEMENTAL, ACTUAL_YES,
+	 BT_INTEGER, di, GFC_STD_F77,
+	 gfc_check_index, gfc_simplify_index, gfc_resolve_index_func,
+	 stg, BT_CHARACTER, dc, REQUIRED, ssg, BT_CHARACTER, dc, REQUIRED,
+	 bck, BT_LOGICAL, dl, OPTIONAL, kind, BT_INTEGER, di, OPTIONAL);
 
   make_generic ("index", GFC_ISYM_INDEX, GFC_STD_F77);
 
@@ -4530,10 +4497,9 @@ resolve_intrinsic (gfc_intrinsic_sym *specific, gfc_expr *e)
 
   arg = e->value.function.actual;
 
-  /* Special case hacks for MIN, MAX and INDEX.  */
+  /* Special case hacks for MIN and MAX.  */
   if (specific->resolve.f1m == gfc_resolve_max
-  || specific->resolve.f1m == gfc_resolve_min
-  || specific->resolve.f1m == gfc_resolve_index_func)
+  || specific->resolve.f1m == gfc_resolve_min)
 {
   (*specific->resolve.f1m) (e, arg);
   return;
diff --git a/gcc/fortran/intrinsic.h b/gcc/fortran/intrinsic.h
index 2148f89e194..b195e0b271a 100644
--- a/gcc/fortran/intrinsic.h
+++ b/gcc/fortran/intrinsic.h
@@ -521,7 +521,8 @@ void gfc_resolve_ibits (gfc_expr *, gfc_expr *, gfc_expr *, gfc_expr *);
 void gfc_resolve_ibset (gfc_expr *, gfc_expr *, gfc_expr *);
 void gfc_resolve_image_index (gfc_expr *, gfc_expr *, gfc_expr *);
 void gfc_resolve_image_status (gfc_expr *, gfc_expr *, gfc_expr *);
-void gfc_resolve_index_func (gfc_expr *, gfc_actual_arglist *);
+void gfc_resolve_index_func (gfc_expr *, gfc_expr *, gfc_expr *, gfc_expr *,
+			 gfc_expr *);
 void gfc_resolve_ierrno (gfc_expr *);
 void gfc_resolve_ieor (gfc_expr *, gfc_expr *, gfc_expr *);
 void gfc_resolve_ichar (gfc_expr *, gfc_expr *, gfc_expr *);
diff --git a/gcc/fortran/iresolve.c b/gcc/fortran/iresolve.c
index e17fe45f080..598c0409b66 100644
--- a/gcc/fortran/iresolve.c
+++ b/gcc/fortran/iresolve.c
@@ -1276,27 +1276,16 @@ gfc_resolve_ior (gfc_expr *f, gfc_expr *i, gfc_expr *j)
 
 
 void
-gfc_resolve_index_func (gfc_expr *f, gfc_actual_arglist *a)
+gfc_resolve_index_func (gfc_expr *f, gfc_expr *str,
+	

Re: Go patch committed: Support unsafe.Add and unsafe.Slice

2021-08-07 Thread Ian Lance Taylor via Gcc-patches
On Mon, Aug 2, 2021 at 3:23 PM Ian Lance Taylor  wrote:
>
> The upcoming Go 1.17 release adds two new functions to the unsafe
> package: unsafe.Add and unsafe.Slice.  These functions must be
> implemented in the compiler.  This patch implements them for gccgo.
> Bootstrapped and ran Go testsuite on x86_64-pc-linux-gnu.  Committed
> to mainline.

This patch makes unsafe.Add and unsafe.Slice work when they appear in
functions that can be inlined across packages.  Bootstrapped and ran
Go testsuite on x86_64-pc-linux-gnu.  Committed to mainline.

Ian
b00c45d66d337e18a02674075ca792fd38094acf
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index 9ed527f7eb4..b983fdab35c 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-747f3a2d78c073e9b03dd81914d0edb7ddc5be14
+d5d51242efc432fa62d4e9b141b01c280af32d19
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
diff --git a/gcc/go/gofrontend/export.cc b/gcc/go/gofrontend/export.cc
index e99c680f709..3d11334884d 100644
--- a/gcc/go/gofrontend/export.cc
+++ b/gcc/go/gofrontend/export.cc
@@ -106,11 +106,12 @@ class Collect_export_references : public Traverse
 {
  public:
   Collect_export_references(Export* exp,
+   const std::map& packages,
 Unordered_set(Named_object*)* exports,
 Unordered_set(const Package*)* imports)
 : Traverse(traverse_expressions
| traverse_types),
-  exp_(exp), exports_(exports), imports_(imports),
+  exp_(exp), packages_(packages), exports_(exports), imports_(imports),
   inline_fcn_worklist_(NULL), exports_finalized_(false)
   { }
 
@@ -150,6 +151,8 @@ class Collect_export_references : public Traverse
 
   // The exporter.
   Export* exp_;
+  // The list of packages known to this compilation.
+  const std::map& packages_;
   // The set of named objects to export.
   Unordered_set(Named_object*)* exports_;
   // Set containing all directly and indirectly imported packages.
@@ -257,6 +260,24 @@ Collect_export_references::expression(Expression** pexpr)
   return TRAVERSE_CONTINUE;
 }
 
+  const Call_expression* call = expr->call_expression();
+  if (call != NULL)
+{
+  const Builtin_call_expression* bce = call->builtin_call_expression();
+  if (bce != NULL
+ && (bce->code() == Builtin_call_expression::BUILTIN_ADD
+ || bce->code() == Builtin_call_expression::BUILTIN_SLICE))
+   {
+ // This is a reference to unsafe.Add or unsafe.Slice.  Make
+ // sure we list the "unsafe" package in the imports and give
+ // it a package index.
+ const std::map::const_iterator p =
+   this->packages_.find("unsafe");
+ go_assert(p != this->packages_.end());
+ this->imports_->insert(p->second);
+   }
+}
+
   return TRAVERSE_CONTINUE;
 }
 
@@ -589,7 +610,7 @@ Export::export_globals(const std::string& package_name,
   // Track all imported packages mentioned in export data.
   Unordered_set(const Package*) all_imports;
 
-  Collect_export_references collect(this, &exports, &all_imports);
+  Collect_export_references collect(this, packages, &exports, &all_imports);
 
   // Walk the set of inlinable routine bodies collected above. This
   // can potentially expand the exports set.
@@ -1274,6 +1295,25 @@ Export::package_index(const Package* pkg) const
   return index;
 }
 
+// Return the index of the "unsafe" package.
+
+int
+Export::unsafe_package_index() const
+{
+  for (Unordered_map(const Package*, int)::const_iterator p =
+this->packages_.begin();
+   p != this->packages_.end();
+   ++p)
+{
+  if (p->first->pkgpath() == "unsafe")
+   {
+ go_assert(p->second != 0);
+ return p->second;
+   }
+}
+  go_unreachable();
+}
+
 // Return the index of a type.
 
 int
diff --git a/gcc/go/gofrontend/export.h b/gcc/go/gofrontend/export.h
index c93bced4eb4..1f613434cab 100644
--- a/gcc/go/gofrontend/export.h
+++ b/gcc/go/gofrontend/export.h
@@ -216,6 +216,11 @@ class Export : public String_dump
   int
   package_index(const Package* p) const;
 
+  // Return the index of the "unsafe" package, which must be one of
+  // the exported packages.
+  int
+  unsafe_package_index() const;
+
  private:
   Export(const Export&);
   Export& operator=(const Export&);
@@ -377,6 +382,11 @@ class Export_function_body : public String_dump
   package_index(const Package* p) const
   { return this->exp_->package_index(p); }
 
+  // Return the index of the "unsafe" package.
+  int
+  unsafe_package_index() const
+  { return this->exp_->unsafe_package_index(); }
+
   // Record a temporary statement and return its index.
   unsigned int
   record_temporary(const Temporary_statement*);
diff --git a/gcc/go/gofrontend/expressions.cc b/gcc/go/gofrontend/expressions.cc
index 33177a709ab..f462b0e2a34 100644
--- a/gcc/go/gofrontend/expr

Re: [r12-2789 Regression] FAIL: gcc.dg/tree-ssa/gen-vect-11b.c scan-tree-dump-times vect "vectorized 0 loops" 1 on Linux/x86_64

2021-08-07 Thread Jeff Law via Gcc-patches




On 8/6/2021 11:24 PM, Jeff Law wrote:



On 8/6/2021 2:59 PM, sunil.k.pandey via Gcc-patches wrote:

On Linux/x86_64,

f31da42e047e8018ca6ad9809273bc7efb6ffcaf is the first bad commit
commit f31da42e047e8018ca6ad9809273bc7efb6ffcaf
Author: Richard Biener 
Date:   Fri Aug 6 14:39:05 2021 +0200

 tree-optimization/101801 - remove vect_worthwhile_without_simd_p

caused

FAIL: gcc.dg/tree-ssa/gen-vect-11b.c scan-tree-dump-times vect 
"vectorized 0 loops" 1
Note I'm seeing this on some of the embedded targets as well. Just to 
pick one, xstormy16-elf.  There are certainly others though.
This change is also causing execution errors for gcc.dg/sabd_1.c on 
bfin-elf, cris-elf, and rx-elf.


Jeff



[PATCH] libstdc++: Tweak timeout for testsuite/std/ranges/iota/max_size_type.cc

2021-08-07 Thread Hans-Peter Nilsson
A simulator can easily spend more than 10 minutes running this
test-case, and the default timeout is at 5 minutes. Better allow
even slower machines; use 4 as the factor.

Regarding relative runtime numbers (very local; mmixware simulator for
mmix-knuth-mmixware): test01 and test05 finish momentarily; test02 at
about 2 minutes, and test03 about 2m30, but test04 itself runs for
more than 6 minutes and so timed out.

Not sure if it's better to split up this test, as the excessive
runtime may be unintended, but this seemed simplest.

Ok to commit?

libstdc++-v3:
* testsuite/std/ranges/iota/max_size_type.cc: Set
dg-timeout-factor to 4.
---
 libstdc++-v3/testsuite/std/ranges/iota/max_size_type.cc | 1 +
 1 file changed, 1 insertion(+)

diff --git a/libstdc++-v3/testsuite/std/ranges/iota/max_size_type.cc 
b/libstdc++-v3/testsuite/std/ranges/iota/max_size_type.cc
index 983bdfbdaa6c..a52e8e6231aa 100644
--- a/libstdc++-v3/testsuite/std/ranges/iota/max_size_type.cc
+++ b/libstdc++-v3/testsuite/std/ranges/iota/max_size_type.cc
@@ -17,6 +17,7 @@

 // { dg-options "-std=gnu++2a" }
 // { dg-do run { target c++2a } }
+// { dg-timeout-factor 4 }

 #include 
 #include 
-- 
2.20.1



Re: [PATCH] libstdc++: Tweak timeout for testsuite/std/ranges/iota/max_size_type.cc

2021-08-07 Thread Jonathan Wakely via Gcc-patches
On Sun, 8 Aug 2021, 03:42 Hans-Peter Nilsson,  wrote:

> A simulator can easily spend more than 10 minutes running this
> test-case, and the default timeout is at 5 minutes. Better allow
> even slower machines; use 4 as the factor.
>
> Regarding relative runtime numbers (very local; mmixware simulator for
> mmix-knuth-mmixware): test01 and test05 finish momentarily; test02 at
> about 2 minutes, and test03 about 2m30, but test04 itself runs for
> more than 6 minutes and so timed out.
>

Strange, it does fewer iterations than test03. I guess the arithmetic is
slower.


Not sure if it's better to split up this test, as the excessive
> runtime may be unintended, but this seemed simplest.
>
> Ok to commit?
>


Ok, thanks.



> libstdc++-v3:
> * testsuite/std/ranges/iota/max_size_type.cc: Set
> dg-timeout-factor to 4.
> ---
>  libstdc++-v3/testsuite/std/ranges/iota/max_size_type.cc | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/libstdc++-v3/testsuite/std/ranges/iota/max_size_type.cc
> b/libstdc++-v3/testsuite/std/ranges/iota/max_size_type.cc
> index 983bdfbdaa6c..a52e8e6231aa 100644
> --- a/libstdc++-v3/testsuite/std/ranges/iota/max_size_type.cc
> +++ b/libstdc++-v3/testsuite/std/ranges/iota/max_size_type.cc
> @@ -17,6 +17,7 @@
>
>  // { dg-options "-std=gnu++2a" }
>  // { dg-do run { target c++2a } }
> +// { dg-timeout-factor 4 }
>
>  #include 
>  #include 
> --
> 2.20.1
>
>