[PATCH] libstdc++: Add c++2a

2020-10-15 Thread Thomas Rodgers
From: Thomas Rodgers 

This should address the cumulative comments (modulo the discussion going
on on the reflector about specification issues/questions).

libstdc++/Changelog:
libstdc++-v3/doc/doxygen/user.cfg.in (INPUT): Add new header.
libstdc++-v3/include/Makefile.am (std_headers): Add new header.
libstdc++-v3/include/Makefile.in: Regenerate.
libstdc++-v3/include/precompiled/stdc++.h: Includ new header.
libstdc++-v3/include/std/streambuf
(__detail::__streambuf_core_access): Define.
(basic_streambuf): Befriend __detail::__streambuf_core_access.
libstdc++-v3/include/std/syncstream: New header.
libstdc++-v3/include/std/version: Add __cpp_lib_syncbuf:
libstdc++-v3/testsuite/27_io/basic_syncbuf/1.cc: New test.
libstdc++-v3/testsuite/27_io/basic_syncbuf/2.cc: Likewise.
libstdc++-v3/testsuite/27_io/basic_syncbuf/basic_ops/1.cc:
Likewise.
libstdc++-v3/testsuite/27_io/basic_syncbuf/requirements/types.cc:
Likewise.
libstdc++-v3/testsuite/27_io/basic_syncbuf/sync_ops/1.cc:
Likewise.
libstdc++-v3/testsuite/27_io/basic_syncstream/1.cc: Likewise.
libstdc++-v3/testsuite/27_io/basic_syncstream/2.cc: Likewise.
libstdc++-v3/testsuite/27_io/basic_syncstream/basic_ops/1.cc:
Likewise.
libstdc++-v3/testsuite/27_io/basic_syncstream/requirements/types.cc:
Likewise.
---
 libstdc++-v3/doc/doxygen/user.cfg.in  |   1 +
 libstdc++-v3/include/Makefile.am  |   1 +
 libstdc++-v3/include/Makefile.in  |   1 +
 libstdc++-v3/include/precompiled/stdc++.h |   2 +-
 libstdc++-v3/include/std/sstream  |   2 +-
 libstdc++-v3/include/std/syncstream   | 276 ++
 libstdc++-v3/include/std/version  |   4 +
 .../testsuite/27_io/basic_syncbuf/1.cc|  28 ++
 .../testsuite/27_io/basic_syncbuf/2.cc|  27 ++
 .../27_io/basic_syncbuf/basic_ops/1.cc| 138 +
 .../27_io/basic_syncbuf/requirements/types.cc |  42 +++
 .../27_io/basic_syncbuf/sync_ops/1.cc | 130 +
 .../testsuite/27_io/basic_syncstream/1.cc |  28 ++
 .../testsuite/27_io/basic_syncstream/2.cc |  27 ++
 .../27_io/basic_syncstream/basic_ops/1.cc | 135 +
 .../basic_syncstream/requirements/types.cc|  43 +++
 16 files changed, 883 insertions(+), 2 deletions(-)
 create mode 100644 libstdc++-v3/include/std/syncstream
 create mode 100644 libstdc++-v3/testsuite/27_io/basic_syncbuf/1.cc
 create mode 100644 libstdc++-v3/testsuite/27_io/basic_syncbuf/2.cc
 create mode 100644 libstdc++-v3/testsuite/27_io/basic_syncbuf/basic_ops/1.cc
 create mode 100644 
libstdc++-v3/testsuite/27_io/basic_syncbuf/requirements/types.cc
 create mode 100644 libstdc++-v3/testsuite/27_io/basic_syncbuf/sync_ops/1.cc
 create mode 100644 libstdc++-v3/testsuite/27_io/basic_syncstream/1.cc
 create mode 100644 libstdc++-v3/testsuite/27_io/basic_syncstream/2.cc
 create mode 100644 libstdc++-v3/testsuite/27_io/basic_syncstream/basic_ops/1.cc
 create mode 100644 
libstdc++-v3/testsuite/27_io/basic_syncstream/requirements/types.cc

diff --git a/libstdc++-v3/doc/doxygen/user.cfg.in 
b/libstdc++-v3/doc/doxygen/user.cfg.in
index 9b49a15d31b..320f6dea688 100644
--- a/libstdc++-v3/doc/doxygen/user.cfg.in
+++ b/libstdc++-v3/doc/doxygen/user.cfg.in
@@ -897,6 +897,7 @@ INPUT  = @srcdir@/doc/doxygen/doxygroups.cc 
\
  include/streambuf \
  include/string \
  include/string_view \
+ include/syncstream \
  include/system_error \
  include/thread \
  include/tuple \
diff --git a/libstdc++-v3/include/Makefile.am b/libstdc++-v3/include/Makefile.am
index 28d273924ee..61aaff7a2f4 100644
--- a/libstdc++-v3/include/Makefile.am
+++ b/libstdc++-v3/include/Makefile.am
@@ -73,6 +73,7 @@ std_headers = \
${std_srcdir}/shared_mutex \
${std_srcdir}/span \
${std_srcdir}/sstream \
+   ${std_srcdir}/syncstream \
${std_srcdir}/stack \
${std_srcdir}/stdexcept \
${std_srcdir}/stop_token \
diff --git a/libstdc++-v3/include/precompiled/stdc++.h 
b/libstdc++-v3/include/precompiled/stdc++.h
index 7518a98c25a..8899c323a28 100644
--- a/libstdc++-v3/include/precompiled/stdc++.h
+++ b/libstdc++-v3/include/precompiled/stdc++.h
@@ -141,6 +141,6 @@
 #include 
 #include 
 #include 
-// #include 
+#include 
 #include 
 #endif
diff --git a/libstdc++-v3/include/std/sstream b/libstdc++-v3/include/std/sstream
index b0d1decfe63..5379f025eef 100644
--- a/libstdc++-v3/include/std/sstream
+++ b/libstdc++-v3/include/std/sstream
@@ -137,7 +137,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
   // 27.8.2.2 Assign and swap:
 
   basic_stringbuf&
-  operator=(const basic_stringbuf&) = delete;
+ operator=(const basic_stringbuf&) = 

Go patch committed: Don't export function type parameter names

2020-10-15 Thread Ian Lance Taylor via Gcc-patches
This patch to the Go frontend stops exporting function type parameter
names.  When hashing a function type the parameter names are ignored.
Therefore, we should not write them into the export data.  Otherwise,
minor changes in the order in which we process the types can cause the
export data to change uselessly, leading to unnecessary rebuilds.
Bootstrapped and ran Go testsuite on x86_64-pc-linux-gnu.  Committed
to mainline.

Ian
1e8e49f135c814bd268289609dd0aea305ed546e
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index 53551030eae..7496770f018 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-71e161daafa1e19c2c53e28fffc3954d88a4cdb2
+3b6252d2d3ce559826303dac07538da6e78940d8
 
 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/types.cc b/gcc/go/gofrontend/types.cc
index e7a742f6366..eb9c766b742 100644
--- a/gcc/go/gofrontend/types.cc
+++ b/gcc/go/gofrontend/types.cc
@@ -5182,7 +5182,11 @@ Function_type::do_export(Export* exp) const
first = false;
  else
exp->write_c_string(", ");
- exp->write_name(p->name());
+ // The hash for a function type ignores parameter names, so
+ // we don't want to write them out here.  If we did write
+ // them out, we could get spurious changes in export data
+ // when recompiling a package.
+ exp->write_name("");
  exp->write_c_string(" ");
  if (!is_varargs || p + 1 != this->parameters_->end())
exp->write_type(p->type());
@@ -5213,7 +5217,7 @@ Function_type::do_export(Export* exp) const
first = false;
  else
exp->write_c_string(", ");
- exp->write_name(p->name());
+ exp->write_name("");
  exp->write_c_string(" ");
  exp->write_type(p->type());
}


[RFC] Remove include/precompiled/expc++.h

2020-10-15 Thread Jonathan Wakely via Gcc-patches

Ed,

In commit r232377 (aka 2be75957b80b640c0aac4356ab861edd0c2f1b9d in the
git repo) you added a new header to the include/precompiled directory.
That wasn't mentioned in the ChangeLog, wasn't in the patch posted to
https://gcc.gnu.org/legacy-ml/libstdc++/2016-01/msg00016.html and
wasn't added to include/Makefile.am, which means it never gets
precompiled, and never gets installed.

I don't think it was meant to be committed, so I think we should
remove it. Any objection?

We *could* add it to the build so it gets installed ... but meh.

commit e26e9e928d5562387bc48fc4735a000eceb8d171
Author: Jonathan Wakely 
Date:   Fri Oct 16 00:19:17 2020

libstdc++: Remove unused header

This header was not part of the patch submitted and reviewed, and was
not added to include/Makefile.am so never gets installed anyway. It
appears to have been committed by mistake, so let's remove it.

libstdc++-v3/ChangeLog:

* include/precompiled/expc++.h: Removed.

diff --git a/libstdc++-v3/include/precompiled/expc++.h b/libstdc++-v3/include/precompiled/expc++.h
deleted file mode 100644
index 28b6fe9420b..000
--- a/libstdc++-v3/include/precompiled/expc++.h
+++ /dev/null
@@ -1,57 +0,0 @@
-// C++ includes used for precompiling extensions -*- C++ -*-
-
-// Copyright (C) 2006-2020 Free Software Foundation, Inc.
-//
-// This file is part of the GNU ISO C++ Library.  This library is free
-// software; you can redistribute it and/or modify it under the
-// terms of the GNU General Public License as published by the
-// Free Software Foundation; either version 3, or (at your option)
-// any later version.
-
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-// GNU General Public License for more details.
-
-// Under Section 7 of GPL version 3, you are granted additional
-// permissions described in the GCC Runtime Library Exception, version
-// 3.1, as published by the Free Software Foundation.
-
-// You should have received a copy of the GNU General Public License and
-// a copy of the GCC Runtime Library Exception along with this program;
-// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
-// .
-
-/** @file expc++.h
- *  This is an implementation file for a precompiled header.
- */
-
-#if __cplusplus < 201103L
-#include 
-#endif
-
-#if __cplusplus > 201103L
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#endif


[PATCH] c++: Fix verify_ctor_sanity ICE [PR96241]

2020-10-15 Thread Marek Polacek via Gcc-patches
The code added in r10-6437 caused us to create a CONSTRUCTOR when we're
{}-initializing an aggregate.  Then we pass this new CONSTRUCTOR down to
cxx_eval_constant_expression which, if the CONSTRUCTOR isn't TREE_CONSTANT
or reduced_constant_expression_p, calls cxx_eval_bare_aggregate.  In
this case the CONSTRUCTOR wasn't reduced_constant_expression_p because
for r_c_e_p a CONST_DECL isn't good enough so it returns false.  So we
go to cxx_eval_bare_aggregate where we crash, because ctx->ctor wasn't
set up properly.  So my fix is to do so.  Since we're value-initializing,
I'm not setting CONSTRUCTOR_NO_CLEARING.

Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk/10?

gcc/cp/ChangeLog:

PR c++/96241
* constexpr.c (cxx_eval_array_reference): Set up ctx->ctor if we
are initializing an aggregate.

gcc/testsuite/ChangeLog:

PR c++/96241
* g++.dg/cpp1y/constexpr-96241.C: New test.
---
 gcc/cp/constexpr.c   |  4 ++
 gcc/testsuite/g++.dg/cpp1y/constexpr-96241.C | 47 
 2 files changed, 51 insertions(+)
 create mode 100644 gcc/testsuite/g++.dg/cpp1y/constexpr-96241.C

diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c
index a118f8a810b..5193047670c 100644
--- a/gcc/cp/constexpr.c
+++ b/gcc/cp/constexpr.c
@@ -3657,10 +3657,14 @@ cxx_eval_array_reference (const constexpr_ctx *ctx, 
tree t,
  initializer, it's initialized from {}.  But use build_value_init
  directly for non-aggregates to avoid creating a garbage CONSTRUCTOR.  */
   tree val;
+  constexpr_ctx new_ctx;
   if (CP_AGGREGATE_TYPE_P (elem_type))
 {
   tree empty_ctor = build_constructor (init_list_type_node, NULL);
   val = digest_init (elem_type, empty_ctor, tf_warning_or_error);
+  new_ctx = *ctx;
+  new_ctx.ctor = build_constructor (elem_type, NULL);
+  ctx = _ctx;
 }
   else
 val = build_value_init (elem_type, tf_warning_or_error);
diff --git a/gcc/testsuite/g++.dg/cpp1y/constexpr-96241.C 
b/gcc/testsuite/g++.dg/cpp1y/constexpr-96241.C
new file mode 100644
index 000..107f2b09de9
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1y/constexpr-96241.C
@@ -0,0 +1,47 @@
+// PR c++/96241
+// { dg-do compile { target c++14 } }
+
+#define assert(expr) static_assert (expr, #expr)
+
+enum E { o };
+
+struct S {
+  int e = o;
+};
+
+using T = S[3];
+
+constexpr struct S s[1][1][1] = { };
+assert (0 == s[0][0][0].e);
+
+constexpr int
+fn0 ()
+{
+  return T{}[0].e;
+}
+assert(fn0 () == 0);
+
+constexpr int
+fn1 ()
+{
+  S d[1];
+  int x = d[0].e;
+  return x;
+}
+assert(fn1 () == 0);
+
+constexpr int
+fn2 ()
+{
+  S d[1];
+  return d[0].e;
+}
+assert(fn2 () == 0);
+
+constexpr int
+fn3 ()
+{
+  struct X { int e = o; } d[1]{};
+  return d[0].e;
+}
+assert(fn3 () == 0);

base-commit: 7dbf96e2a2a673d78a23da9155c0b4c4c36621c7
-- 
2.26.2



Re: Extend builtin fnspecs

2020-10-15 Thread Marek Polacek via Gcc-patches
On Thu, Oct 15, 2020 at 11:50:28PM +0200, Jan Hubicka wrote:
> Hi,
> this patch implements the discussed change to fnspecs to make it
> possible to specify parameters that are read and written.  In addition
> to original plan I ended up adding 'b' for functions that are barriers
> (since those alias even with local refs) and 'o','O' for parameters that
> are written only (output parameters) so there is diffence betwen strcat
> and memcpy, for example.
> 
> Bootstrapped/regtested x86_64-linux, OK?
> 
> Honza
> 
> 2020-10-15  Jan Hubicka  
> 
>   * attr-fnspec.h: Update toplevel comment.
>   (attr_fnspec::attr_fnspec): New constructor.
>   (attr_fnspec::arg_read_p,
>   attr_fnspec::arg_written_p,
>   attr_fnspec::arg_access_size_given_by_arg_p,
>   attr_fnspec::arg_single_access_p
>   attr_fnspec::loads_known_p
>   attr_fnspec::stores_known_p,
>   attr_fnspec::clobbers_errno_p): New member functions.
>   (gimple_call_fnspec): Declare.
>   (builtin_fnspec): Declare.
>   * builtins.c: Include attr-fnspec.h
>   (builtin_fnspec): New function.
>   * builtins.def (BUILT_IN_MEMCPY): Do not specify RET1 fnspec.
>   (BUILT_IN_MEMMOVE): Do not specify RET1 fnspec.
>   (BUILT_IN_MEMSET): Do not specify RET1 fnspec.
>   (BUILT_IN_STRCAT): Do not specify RET1 fnspec.
>   (BUILT_IN_STRCPY): Do not specify RET1 fnspec.
>   (BUILT_IN_STRNCAT): Do not specify RET1 fnspec.
>   (BUILT_IN_STRNCPY): Do not specify RET1 fnspec.
>   (BUILT_IN_MEMCPY_CHK): Do not specify RET1 fnspec.
>   (BUILT_IN_MEMMOVE_CHK): Do not specify RET1 fnspec.
>   (BUILT_IN_MEMSET_CHK): Do not specify RET1 fnspec.
>   (BUILT_IN_STRCAT_CHK): Do not specify RET1 fnspec.
>   (BUILT_IN_STRCPY_CHK): Do not specify RET1 fnspec.
>   (BUILT_IN_STRNCAT_CHK): Do not specify RET1 fnspec.
>   (BUILT_IN_STRNCPY_CHK): Do not specify RET1 fnspec.
>   * gimple.c (gimple_call_fnspec): Return attr_fnspec.
>   (gimple_call_arg_flags): Update.
>   (gimple_call_return_flags): Update.
>   * tree-ssa-alias.c (check_fnspec): New function.
>   (ref_maybe_used_by_call_p_1): Use fnspec for builtin handling.
>   (call_may_clobber_ref_p_1): Likewise.
>   (attr_fnspec::verify): Update verifier.
>   * calls.c (decl_fnspec): New function.
>   (decl_return_flags): Use it.
> diff --git a/gcc/attr-fnspec.h b/gcc/attr-fnspec.h
> index d38b84a969e..e524798c4ca 100644
> --- a/gcc/attr-fnspec.h
> +++ b/gcc/attr-fnspec.h
> @@ -27,11 +27,19 @@
>   '.' specifies that nothing is known.
> character 1  specifies additional function properties
>   ' 'specifies that nothing is known
> + 'p' or 'P' specifies that function is pure except for described side
> + effects.
> + 'c' or 'C' specifies that function is const except for described side
> + effects.
> + 'b' specifies that functions is a memory barrier.
> +   The uppercase letter in addition specifies that function clobbers errno.
>  
> character 2+2i specifies properties of argument number i as follows:
>   'x' or 'X' specifies that parameter is unused.
>   'r' or 'R' specifies that the memory pointed to by the parameter is only
>   read and does not escape
> + 'o' or 'O' specifies that the memory pointed to by the parameter is only
> + written and does not escape
>   'w' or 'W' specifies that the memory pointed to by the parameter does 
> not
>   escape
>   '.' specifies that nothing is known.
> @@ -42,6 +50,10 @@
> character 3+2i specifies additional properties of argument number i
> as follows:
>   ' 'nothing is known
> + 't' the size of value written/read corresponds to the size of
> + of the pointed-to type of the argument type
> + '1'...'9'  the size of value written/read is given by the specified
> + argument
>   */
>  
>  #ifndef ATTR_FNSPEC_H
> @@ -72,6 +84,12 @@ public:
>  if (flag_checking)
>verify ();
>}
> +  attr_fnspec (const char *str)
> +  : str (str), len (strlen (str))
> +  {
> +if (flag_checking)
> +  verify ();
> +  }
>attr_fnspec (const_tree identifier)
>: str (TREE_STRING_POINTER (identifier)),
>  len (TREE_STRING_LENGTH (identifier))
> @@ -79,6 +97,17 @@ public:
>  if (flag_checking)
>verify ();
>}
> +  attr_fnspec ()
> +  : str (NULL), len (0)
> +  {
> +  }
> +
> +  /* Return true if fn spec is known.  */
> +  bool
> +  known_p ()
> +  {
> +return len;
> +  }
>  
>/* Return true if arg I is specified.  */
>bool
> @@ -94,7 +123,7 @@ public:
>{
>  unsigned int idx = arg_idx (i);
>  gcc_checking_assert (arg_specified_p (i));
> -return str[idx] == 'R' || str[idx] == 'W';
> +return str[idx] == 'R' || str[idx] == 'O' || str[idx] == 'W';
>}
>  
>/* True if argument is used.  */
> @@ -115,6 +144,56 @@ public:
>  

Re: [PATCH] libgccjit: add some reflection functions in the jit C api

2020-10-15 Thread David Malcolm via Gcc-patches
On Thu, 2020-10-15 at 13:39 -0400, Antoni Boucher wrote:
> Thanks. I updated the patch with these changes.

Thanks for patch; review below.  Sorry if it seems excessively nitpicky
in places.

> 2020-09-1  Antoni Boucher  
> 
> gcc/jit/
> PR target/96889
> * docs/topics/compatibility.rst (LIBGCCJIT_ABI_14): New ABI tag.

15 now.

> * docs/topics/functions.rst: Add documentation for the
> functions gcc_jit_function_get_return_type and
> gcc_jit_function_get_param_count
> * libgccjit.c: New functions:
>   * gcc_jit_function_get_return_type;
>   * gcc_jit_function_get_param_count;
>   * gcc_jit_function_type_get_return_type;
>   * gcc_jit_function_type_get_param_count;
>   * gcc_jit_function_type_get_param_type;
>   * gcc_jit_type_unqualified;
>   * gcc_jit_type_is_array;
>   * gcc_jit_type_is_bool;
>   * gcc_jit_type_is_function_ptr_type;
>   * gcc_jit_type_is_int;
>   * gcc_jit_type_is_pointer;
>   * gcc_jit_type_is_vector;
>   * gcc_jit_vector_type_get_element_type;
>   * gcc_jit_vector_type_get_num_units;
>   * gcc_jit_struct_get_field;
>   * gcc_jit_type_is_struct;
>   * gcc_jit_struct_get_field_count;

This isn't valid ChangeLog format; it will fail the git hooks.

> * libgccjit.h

Likewise.

> * jit-recording.h: New functions (is_struct and is_vector)
> * libgccjit.map (LIBGCCJIT_ABI_14): New ABI tag.

15 now.

> 
> gcc/testsuite/
> PR target/96889
> * jit.dg/all-non-failing-tests.h: Add test-reflection.c.
> * jit.dg/test-reflection.c: New test.

[...]


> diff --git a/gcc/jit/docs/topics/functions.rst 
> b/gcc/jit/docs/topics/functions.rst
> index eb40d64010e..9819c28cda2 100644
> --- a/gcc/jit/docs/topics/functions.rst
> +++ b/gcc/jit/docs/topics/functions.rst
> @@ -171,6 +171,16 @@ Functions
> underlying string, so it is valid to pass in a pointer to an on-stack
> buffer.
>  
> +.. function::  size_t \
> +   gcc_jit_function_get_param_count (gcc_jit_function *func)
> +
> +   Get the number of parameters of the function.
> +
> +.. function::  gcc_jit_type \*
> +   gcc_jit_function_get_return_type (gcc_jit_function *func)
> +
> +   Get the return type of the function.
> +

The documentation part of the patch is incomplete: it hasn't been
updated to add all the new entrypoints.
Also, the return type of gcc_jit_function_get_param_count is
inconsistent (size_t above, but ssize_t below).


> diff --git a/gcc/jit/jit-recording.h b/gcc/jit/jit-recording.h
> index 30e37aff387..525b8bc921d 100644
> --- a/gcc/jit/jit-recording.h
> +++ b/gcc/jit/jit-recording.h
> @@ -538,7 +538,9 @@ public:
>virtual bool is_bool () const = 0;
>virtual type *is_pointer () = 0;
>virtual type *is_array () = 0;
> +  virtual struct_ *is_struct () { return NULL; }

Can't you use dyn_cast_struct for this?
Or is this about looking through decorated_type? e.g. for const and
volatile variants?

I guess my question is, what is the purpose of gcc_jit_type_is_struct?

>virtual bool is_void () const { return false; }
> +  virtual vector_type *is_vector () { return NULL; }

Likewise, can't you use dyn_cast_vector_type for this?

>virtual bool has_known_size () const { return true; }
>  
>bool is_numeric () const
> @@ -595,6 +597,8 @@ public:
>bool is_bool () const FINAL OVERRIDE;
>type *is_pointer () FINAL OVERRIDE { return dereference (); }
>type *is_array () FINAL OVERRIDE { return NULL; }
> +  vector_type *is_vector () FINAL OVERRIDE { return NULL; }
> +  struct_ *is_struct () FINAL OVERRIDE { return NULL; }

Likewise, and this is redundant, as it's merely copying the base class
implementation.

>bool is_void () const FINAL OVERRIDE { return m_kind == GCC_JIT_TYPE_VOID; 
> }
>  
>  public:
> @@ -629,6 +633,8 @@ public:
>bool is_bool () const FINAL OVERRIDE { return false; }
>type *is_pointer () FINAL OVERRIDE { return m_other_type; }
>type *is_array () FINAL OVERRIDE { return NULL; }
> +  vector_type *is_vector () FINAL OVERRIDE { return NULL; }
> +  struct_ *is_struct () FINAL OVERRIDE { return NULL; }

Likewise.


> @@ -655,6 +661,7 @@ public:
>bool is_bool () const FINAL OVERRIDE { return m_other_type->is_bool (); }
>type *is_pointer () FINAL OVERRIDE { return m_other_type->is_pointer (); }
>type *is_array () FINAL OVERRIDE { return m_other_type->is_array (); }
> +  struct_ *is_struct () FINAL OVERRIDE { return m_other_type->is_struct (); }

Aha: with a decorated type you look through the decoration.

>  protected:
>type *m_other_type;
> @@ -737,6 +744,8 @@ public:
>  
>void replay_into (replayer *) FINAL OVERRIDE;
>  
> +  vector_type *is_vector () FINAL OVERRIDE { return this; }
> +

Extend builtin fnspecs

2020-10-15 Thread Jan Hubicka
Hi,
this patch implements the discussed change to fnspecs to make it
possible to specify parameters that are read and written.  In addition
to original plan I ended up adding 'b' for functions that are barriers
(since those alias even with local refs) and 'o','O' for parameters that
are written only (output parameters) so there is diffence betwen strcat
and memcpy, for example.

Bootstrapped/regtested x86_64-linux, OK?

Honza

2020-10-15  Jan Hubicka  

* attr-fnspec.h: Update toplevel comment.
(attr_fnspec::attr_fnspec): New constructor.
(attr_fnspec::arg_read_p,
attr_fnspec::arg_written_p,
attr_fnspec::arg_access_size_given_by_arg_p,
attr_fnspec::arg_single_access_p
attr_fnspec::loads_known_p
attr_fnspec::stores_known_p,
attr_fnspec::clobbers_errno_p): New member functions.
(gimple_call_fnspec): Declare.
(builtin_fnspec): Declare.
* builtins.c: Include attr-fnspec.h
(builtin_fnspec): New function.
* builtins.def (BUILT_IN_MEMCPY): Do not specify RET1 fnspec.
(BUILT_IN_MEMMOVE): Do not specify RET1 fnspec.
(BUILT_IN_MEMSET): Do not specify RET1 fnspec.
(BUILT_IN_STRCAT): Do not specify RET1 fnspec.
(BUILT_IN_STRCPY): Do not specify RET1 fnspec.
(BUILT_IN_STRNCAT): Do not specify RET1 fnspec.
(BUILT_IN_STRNCPY): Do not specify RET1 fnspec.
(BUILT_IN_MEMCPY_CHK): Do not specify RET1 fnspec.
(BUILT_IN_MEMMOVE_CHK): Do not specify RET1 fnspec.
(BUILT_IN_MEMSET_CHK): Do not specify RET1 fnspec.
(BUILT_IN_STRCAT_CHK): Do not specify RET1 fnspec.
(BUILT_IN_STRCPY_CHK): Do not specify RET1 fnspec.
(BUILT_IN_STRNCAT_CHK): Do not specify RET1 fnspec.
(BUILT_IN_STRNCPY_CHK): Do not specify RET1 fnspec.
* gimple.c (gimple_call_fnspec): Return attr_fnspec.
(gimple_call_arg_flags): Update.
(gimple_call_return_flags): Update.
* tree-ssa-alias.c (check_fnspec): New function.
(ref_maybe_used_by_call_p_1): Use fnspec for builtin handling.
(call_may_clobber_ref_p_1): Likewise.
(attr_fnspec::verify): Update verifier.
* calls.c (decl_fnspec): New function.
(decl_return_flags): Use it.
diff --git a/gcc/attr-fnspec.h b/gcc/attr-fnspec.h
index d38b84a969e..e524798c4ca 100644
--- a/gcc/attr-fnspec.h
+++ b/gcc/attr-fnspec.h
@@ -27,11 +27,19 @@
  '.'   specifies that nothing is known.
character 1  specifies additional function properties
  ' 'specifies that nothing is known
+ 'p' or 'P' specifies that function is pure except for described side
+   effects.
+ 'c' or 'C' specifies that function is const except for described side
+   effects.
+ 'b'   specifies that functions is a memory barrier.
+   The uppercase letter in addition specifies that function clobbers errno.
 
character 2+2i specifies properties of argument number i as follows:
  'x' or 'X' specifies that parameter is unused.
  'r' or 'R' specifies that the memory pointed to by the parameter is only
read and does not escape
+ 'o' or 'O' specifies that the memory pointed to by the parameter is only
+   written and does not escape
  'w' or 'W' specifies that the memory pointed to by the parameter does not
escape
  '.'   specifies that nothing is known.
@@ -42,6 +50,10 @@
character 3+2i specifies additional properties of argument number i
as follows:
  ' 'nothing is known
+ 't'   the size of value written/read corresponds to the size of
+   of the pointed-to type of the argument type
+ '1'...'9'  the size of value written/read is given by the specified
+   argument
  */
 
 #ifndef ATTR_FNSPEC_H
@@ -72,6 +84,12 @@ public:
 if (flag_checking)
   verify ();
   }
+  attr_fnspec (const char *str)
+  : str (str), len (strlen (str))
+  {
+if (flag_checking)
+  verify ();
+  }
   attr_fnspec (const_tree identifier)
   : str (TREE_STRING_POINTER (identifier)),
 len (TREE_STRING_LENGTH (identifier))
@@ -79,6 +97,17 @@ public:
 if (flag_checking)
   verify ();
   }
+  attr_fnspec ()
+  : str (NULL), len (0)
+  {
+  }
+
+  /* Return true if fn spec is known.  */
+  bool
+  known_p ()
+  {
+return len;
+  }
 
   /* Return true if arg I is specified.  */
   bool
@@ -94,7 +123,7 @@ public:
   {
 unsigned int idx = arg_idx (i);
 gcc_checking_assert (arg_specified_p (i));
-return str[idx] == 'R' || str[idx] == 'W';
+return str[idx] == 'R' || str[idx] == 'O' || str[idx] == 'W';
   }
 
   /* True if argument is used.  */
@@ -115,6 +144,56 @@ public:
 return str[idx] == 'r' || str[idx] == 'R';
   }
 
+  /* True if memory reached by the argument is read.
+ Valid only if all loads are known.  */
+  bool
+  arg_read_p (unsigned int i)
+  {
+unsigned int idx = arg_idx 

libgo patch committed: Correct types in __go_ptrace shim

2020-10-15 Thread Ian Lance Taylor via Gcc-patches
This libgo patch by Nikhil Benesch uses the correct types in the
__go_ptrace shim.  This makes them match the types declared in Go and
the types declared by the C ptrace function, i.e., void*.  This avoids
a warning about an implicit int-to-pointer cast on some platforms.
Bootstrapped and ran Go tests on x86_64-pc-linux-gnu.  Committed to
mainline.

Ian
f33ac3b0cd9f88be8faadded88e40a511f01c32a
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index a7e6a7257f0..53551030eae 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-d36e74c7a1aa94fc5cf393dc705b8a1271cb01c7
+71e161daafa1e19c2c53e28fffc3954d88a4cdb2
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
diff --git a/libgo/runtime/go-varargs.c b/libgo/runtime/go-varargs.c
index 9cb4a7e79bd..d8f7dc55ea4 100644
--- a/libgo/runtime/go-varargs.c
+++ b/libgo/runtime/go-varargs.c
@@ -122,7 +122,7 @@ __go_syscall6(uintptr_t flag, uintptr_t a1, uintptr_t a2, 
uintptr_t a3,
 // a variadic function within glibc.
 
 long
-__go_ptrace(int request, pid_t pid, uintptr_t addr, uintptr_t data)
+__go_ptrace(int request, pid_t pid, void *addr, void *data)
 {
   return ptrace (request, pid, addr, data);
 }


Re: [wwwdocs] Add note about keeping replies on the mailing list

2020-10-15 Thread Jonathan Wakely via Gcc-patches

On 15/10/20 09:34 +0200, Gerald Pfeifer wrote:

On Mon, 15 Jun 2020, Jonathan Wakely via Gcc-patches wrote:

I can't count the number of times I've tried to help somebody on the
gcc-help list and they assume that means I want to be their personal
support person in a private email conversation.

This is unlikely to change anything, because nobody will read it, but
at least I can point to something.

Martin L. suggested mentioning "Reply All" so here's a revised patch.

OK for wwwdocs?


Yes, please.

And apologies; I clearly missed a number of wwwdocs patches those
last couple of months. :-(



Oh, I forgot about this one :-)

I still had the branch though, so it's now pushed.




Re: [RFC] Automatic linking of libatomic via gcc.c or ...? [PR81358] (dependency for libgomp on nvptx dep, configure overriddable, ...)

2020-10-15 Thread Joseph Myers
On Thu, 15 Oct 2020, Tobias Burnus wrote:

> Hi Joseph, hi Jakub,
> 
> (a) For the driver route:
> 
> On 10/15/20 12:22 AM, Joseph Myers wrote:
> > I think it should be somewhere in the expansion of %(link_gcc_c_sequence)
> > (i.e. LINK_GCC_C_SEQUENCE_SPEC, which has various target-specific
> > definitions), since that's what expands to something like -lgcc -lc -lgcc.
> > Maybe after the first -lgcc and before the -lc, since libatomic has
> > references to libc functions.
> 
> Lightly tested draft patch attached. (--enable-autolink-libatomic is 'no' by
> default)

I think the configure option should be on by default.

I'd expect only gcc.c to define LINK_LIBATOMIC_SPEC rather than 
duplicating it in gnu-user.h.

I'd expect either a default definition of LINK_LIBATOMIC_SPEC to "" when 
the configure option is disabled, or else conditionals in the macros that 
use LINK_LIBATOMIC_SPEC to avoid them using an undefined macro.

> When trying the patch, one runs into the problem that -latomic
> fails in the target configure for libgomp ("error: C compiler
> cannot create executables"). Any suggestion? (That's on x86_64-gnu-linux.)

Yes, making this change means you need to ensure the build of target 
libraries and testcases can find the in-build-tree libatomic (and that 
tests can find it at runtime as needed in the shared library case), just 
like it already needs to be able to find the in-build-tree libgcc.

In the case of libgcc, the libgcc build process copies the libraries into 
the host-side gcc/ object directory.  Maybe doing that for libatomic would 
be simpler than teaching lots of separate places how to find libatomic in 
the build tree (though for any tests that might use shared libatomic at 
runtime, it's still necessary to ensure that works for testing GCC).

-- 
Joseph S. Myers
jos...@codesourcery.com


libgo patch committed: Fix path to x/net/route package in Makefile

2020-10-15 Thread Ian Lance Taylor via Gcc-patches
This libgo patch by Nikhil Benesch corrects a Makefile typo in the
path to the x/net/route package.  Bootstrapped and ran Go testsuite on
x86_64-pc-linux-gnu.  Committed to mainline.

Ian
6949fbefe28134744a86c5d7b8d9c17fcf3a16a0
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index ce96537e346..a7e6a7257f0 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-94808b9af5cd9b9102ae9680a0e5f124c6793815
+d36e74c7a1aa94fc5cf393dc705b8a1271cb01c7
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
diff --git a/libgo/Makefile.am b/libgo/Makefile.am
index 76cdc8ef217..26e83850435 100644
--- a/libgo/Makefile.am
+++ b/libgo/Makefile.am
@@ -1096,7 +1096,7 @@ if LIBGO_IS_BSD
 $(eval $(call PACKAGE_template,golang.org/x/net/route))
 
 golangorg_x_net_route_lo = \
-   golang.org/net/route.lo
+   golang.org/x/net/route.lo
 
 endif
 


Go patch committed: Export type for string/bool constants

2020-10-15 Thread Ian Lance Taylor via Gcc-patches
This patch to the Go frontend includes the type in the export data
when an inlinable function refers to a string or bool constant.  The
patch consolidates the identical code for constant type export into a
pair of static methods.  This fixes https://golang.org/issue/35739.
Bootstrapped and ran Go testsuite on x86_64-pc-linux-gnu.  Committed
to mainline.

Ian
727a2e1c4ad1c3978a08423b1c020dc213154df0
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index 45a7b422a29..ce96537e346 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-b73a8f17dfe8d7c7ecc9ccd0317be5abe71c5509
+94808b9af5cd9b9102ae9680a0e5f124c6793815
 
 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/expressions.cc b/gcc/go/gofrontend/expressions.cc
index 0350e51d3a6..e76bc6997c1 100644
--- a/gcc/go/gofrontend/expressions.cc
+++ b/gcc/go/gofrontend/expressions.cc
@@ -1823,6 +1823,31 @@ Expression::make_unknown_reference(Named_object* no, 
Location location)
   return new Unknown_expression(no, location);
 }
 
+// Start exporting a type conversion for a constant, if needed.  This
+// returns whether we need to export a closing parenthesis.
+
+bool
+Expression::export_constant_type(Export_function_body* efb, Type* type)
+{
+  if (type == NULL
+  || type->is_abstract()
+  || type == efb->type_context())
+return false;
+  efb->write_c_string("$convert(");
+  efb->write_type(type);
+  efb->write_c_string(", ");
+  return true;
+}
+
+// Finish a type conversion for a constant.
+
+void
+Expression::finish_export_constant_type(Export_function_body* efb, bool needed)
+{
+  if (needed)
+efb->write_c_string(")");
+}
+
 // A boolean expression.
 
 class Boolean_expression : public Expression
@@ -1878,8 +1903,7 @@ class Boolean_expression : public Expression
   { return 1; }
 
   void
-  do_export(Export_function_body* efb) const
-  { efb->write_c_string(this->val_ ? "$true" : "$false"); }
+  do_export(Export_function_body* efb) const;
 
   void
   do_dump_expression(Ast_dump_context* ast_dump_context) const
@@ -1926,6 +1950,16 @@ Boolean_expression::do_determine_type(const 
Type_context* context)
 this->type_ = Type::lookup_bool_type();
 }
 
+// Export a boolean constant.
+
+void
+Boolean_expression::do_export(Export_function_body* efb) const
+{
+  bool exported_type = Expression::export_constant_type(efb, this->type_);
+  efb->write_c_string(this->val_ ? "$true" : "$false");
+  Expression::finish_export_constant_type(efb, exported_type);
+}
+
 // Import a boolean constant.
 
 Expression*
@@ -2055,7 +2089,9 @@ String_expression::export_string(String_dump* exp,
 void
 String_expression::do_export(Export_function_body* efb) const
 {
+  bool exported_type = Expression::export_constant_type(efb, this->type_);
   String_expression::export_string(efb, this);
+  Expression::finish_export_constant_type(efb, exported_type);
 }
 
 // Import a string expression.
@@ -2547,16 +2583,7 @@ Integer_expression::export_integer(String_dump* exp, 
const mpz_t val)
 void
 Integer_expression::do_export(Export_function_body* efb) const
 {
-  bool added_type = false;
-  if (this->type_ != NULL
-  && !this->type_->is_abstract()
-  && this->type_ != efb->type_context())
-{
-  efb->write_c_string("$convert(");
-  efb->write_type(this->type_);
-  efb->write_c_string(", ");
-  added_type = true;
-}
+  bool exported_type = Expression::export_constant_type(efb, this->type_);
 
   Integer_expression::export_integer(efb, this->val_);
   if (this->is_character_constant_)
@@ -2564,8 +2591,7 @@ Integer_expression::do_export(Export_function_body* efb) 
const
   // A trailing space lets us reliably identify the end of the number.
   efb->write_c_string(" ");
 
-  if (added_type)
-efb->write_c_string(")");
+  Expression::finish_export_constant_type(efb, exported_type);
 }
 
 // Import an integer, floating point, or complex value.  This handles
@@ -2953,23 +2979,13 @@ Float_expression::export_float(String_dump *exp, const 
mpfr_t val)
 void
 Float_expression::do_export(Export_function_body* efb) const
 {
-  bool added_type = false;
-  if (this->type_ != NULL
-  && !this->type_->is_abstract()
-  && this->type_ != efb->type_context())
-{
-  efb->write_c_string("$convert(");
-  efb->write_type(this->type_);
-  efb->write_c_string(", ");
-  added_type = true;
-}
+  bool exported_type = Expression::export_constant_type(efb, this->type_);
 
   Float_expression::export_float(efb, this->val_);
   // A trailing space lets us reliably identify the end of the number.
   efb->write_c_string(" ");
 
-  if (added_type)
-efb->write_c_string(")");
+  Expression::finish_export_constant_type(efb, exported_type);
 }
 
 // Dump a floating point number to the dump file.
@@ -3184,23 +3200,13 @@ Complex_expression::export_complex(String_dump* exp, 
const mpc_t val)
 void
 

Re: [PATCH] libstdc++: Add c++2a

2020-10-15 Thread Jonathan Wakely via Gcc-patches

On 15/10/20 07:46 -0700, Thomas Rodgers wrote:

+  template ,
+   typename _Alloc = allocator<_CharT>>
+class basic_osyncstream : public basic_ostream<_CharT, _Traits>
+{
+public:
+  // Types:
+  using char_type = _CharT;
+  using traits_type = _Traits;
+  using allocator_type = _Alloc;
+  using int_type = typename traits_type::int_type;
+  using pos_type = typename traits_type::pos_type;
+  using off_type = typename traits_type::off_type;
+  using syncbuf_type = basic_syncbuf<_CharT, _Traits, _Alloc>;
+  using streambuf_type = typename syncbuf_type::streambuf_type;
+
+  using __ostream_type = basic_ostream<_CharT, _Traits>;
+
+private:
+  syncbuf_type _M_syncbuf;
+
+public:
+  basic_osyncstream(streambuf_type* __buf, const allocator_type& __a)
+   : _M_syncbuf(__buf, __a)
+  { this->init(&_M_syncbuf); }
+
+  explicit basic_osyncstream(streambuf_type* __buf)
+   : _M_syncbuf(__buf)
+  { this->init(&_M_syncbuf); }
+
+  basic_osyncstream(basic_ostream& __os,
+   const allocator_type& __a)
+   : basic_osyncstream(__os.rdbuf(), __a)
+  { this->init(&_M_syncbuf); }
+
+  explicit basic_osyncstream(basic_ostream& __os)
+   : basic_osyncstream(__os.rdbuf())
+  { this->init(&_M_syncbuf); }
+
+  basic_osyncstream(basic_osyncstream&& __rhs) noexcept
+   : __ostream_type(std::move(__rhs)),
+   _M_syncbuf(std::move(__rhs._M_syncbuf))
+  { __ostream_type::set_rdbuf(&_M_syncbuf); }
+
+  ~basic_osyncstream() = default;
+
+  basic_osyncstream& operator=(basic_osyncstream&& __rhs) noexcept
+  {
+   if (&__rhs != this)


Rather than adding std::__addressof here, I'm not sure we need the
check for self-assignment at all. The ostream base's move assignment
is safe on self-assignment, and the syncbuf is too (because it checks
for it).


+ {
+   __ostream_type::operator=(std::move(__rhs));
+   _M_syncbuf = std::move(__rhs._M_syncbuf);
+   __ostream_type::set_rdbuf(&_M_syncbuf);


I think this set_rdbuf is not needed.

I think the move assignment could be defaulted.


+ }
+   return *this;
+  }
+
+  syncbuf_type* rdbuf() const noexcept
+  { return const_cast(&_M_syncbuf); }
+
+  streambuf_type* get_wrapped() const noexcept
+  { return _M_syncbuf.get_wrapped(); }
+
+  void emit()
+  { _M_syncbuf.emit(); }


This needs to check the result of _M_syncbuf.emit() and possibly set
failbit.




Re: [PATCH] libgccjit: Handle truncation and extension for casts [PR 95498]

2020-10-15 Thread Antoni Boucher via Gcc-patches

Hi.
Sorry for the long delay.

I attached the updated patch.

For your question, the current code already works with boolean and reals 
and casts between integers and pointers is currently not supported.


The tests now pass: I'm assuming I had to clean the build folder or 
something to make that work.


David, any more insight about whether this is the good solution for the 
problem?


Thanks.

On Tue, Jul 21, 2020 at 11:29:57PM +0200, Andrea Corallo wrote:

Hi Antoni,

a couple of nits and some thoughts.

Antoni Boucher via Gcc-patches  writes:


2020-07-12  Antoni Boucher  

gcc/jit/
PR target/95498
* jit-playback.c: Add support to handle truncation and extension

  ^^^
  here we usually add the function that gets
modified, you can look at other changelog entries as example.


diff --git a/gcc/jit/jit-playback.c b/gcc/jit/jit-playback.c
index 0fddf04da87..4f4a1080c36 100644
--- a/gcc/jit/jit-playback.c
+++ b/gcc/jit/jit-playback.c
@@ -61,22 +61,39 @@ along with GCC; see the file COPYING3.  If not see

 /* gcc::jit::playback::context::build_cast uses the convert.h API,
which in turn requires the frontend to provide a "convert"
-   function, apparently as a fallback.
-
-   Hence we provide this dummy one, with the requirement that any casts
-   are handled before reaching this.  */
+   function, apparently as a fallback for casts that can be simplified
+   (truncation, extension). */
 extern tree convert (tree type, tree expr);

 tree
 convert (tree dst_type, tree expr)
 {
-  gcc_assert (gcc::jit::active_playback_ctxt);
-  gcc::jit::active_playback_ctxt->add_error (NULL, "unhandled conversion");
-  fprintf (stderr, "input expression:\n");
-  debug_tree (expr);
-  fprintf (stderr, "requested type:\n");
-  debug_tree (dst_type);
-  return error_mark_node;
+  tree t_ret = NULL;
+  t_ret = targetm.convert_to_type (dst_type, expr);
+  if (t_ret)
+  return t_ret;

   ^^^
   indent nit

+  enum tree_code dst_code = TREE_CODE (dst_type);
+  switch (dst_code)
+{
+case INTEGER_TYPE:
+case ENUMERAL_TYPE:
+  t_ret = convert_to_integer (dst_type, expr);
+  goto maybe_fold;
+
+default:
+  gcc_assert (gcc::jit::active_playback_ctxt);
+  gcc::jit::active_playback_ctxt->add_error (NULL, "unhandled conversion");
+  fprintf (stderr, "input expression:\n");
+  debug_tree (expr);
+  fprintf (stderr, "requested type:\n");
+  debug_tree (dst_type);
+  return error_mark_node;
+
+maybe_fold:
+  if (TREE_CODE (t_ret) != C_MAYBE_CONST_EXPR)
+   t_ret = fold (t_ret);
+  return t_ret;
+}
 }


Looking at 'convert' at c-convert.c:66 the INTEGER_TYPE case here looks
good, but given the set of casts we accept as input I guess we should
handle also POINTER_TYPE, BOOLEAN_TYPE and REAL_TYPE.  What do you think
about?

Hope it helps

Bests

 Andrea
>From 3f42dc30d9276d7b830103479a3b03f5fc9027ec Mon Sep 17 00:00:00 2001
From: Antoni Boucher 
Date: Sun, 5 Jul 2020 19:07:30 -0400
Subject: [PATCH] This patch handles truncation and extension for casts in jit.

2020-07-12  Antoni Boucher  

gcc/jit/
PR target/95498
* jit-playback.c (convert): Add support to handle truncation and
extension in the convert function.

gcc/testsuite/
PR target/95498
* jit.dg/all-non-failing-tests.h: New test.
* jit.dg/test-cast.c: New test.

Signed-off-by: Antoni Boucher 
---
 gcc/jit/jit-playback.c   | 39 
 gcc/testsuite/jit.dg/all-non-failing-tests.h | 10 +++
 gcc/testsuite/jit.dg/test-cast.c | 66 
 3 files changed, 104 insertions(+), 11 deletions(-)
 create mode 100644 gcc/testsuite/jit.dg/test-cast.c

diff --git a/gcc/jit/jit-playback.c b/gcc/jit/jit-playback.c
index 4fac64dcab7..6cfe0371ec3 100644
--- a/gcc/jit/jit-playback.c
+++ b/gcc/jit/jit-playback.c
@@ -61,22 +61,39 @@ along with GCC; see the file COPYING3.  If not see
 
 /* gcc::jit::playback::context::build_cast uses the convert.h API,
which in turn requires the frontend to provide a "convert"
-   function, apparently as a fallback.
-
-   Hence we provide this dummy one, with the requirement that any casts
-   are handled before reaching this.  */
+   function, apparently as a fallback for casts that can be simplified
+   (truncation, extension). */
 extern tree convert (tree type, tree expr);
 
 tree
 convert (tree dst_type, tree expr)
 {
-  gcc_assert (gcc::jit::active_playback_ctxt);
-  gcc::jit::active_playback_ctxt->add_error (NULL, "unhandled conversion");
-  fprintf (stderr, "input expression:\n");
-  debug_tree (expr);
-  fprintf (stderr, "requested type:\n");
-  debug_tree (dst_type);
-  return error_mark_node;
+  tree t_ret = NULL;
+  t_ret = targetm.convert_to_type (dst_type, expr);
+  if (t_ret)
+  return t_ret;
+  enum tree_code dst_code = TREE_CODE (dst_type);
+  switch (dst_code)
+{
+case INTEGER_TYPE:
+case 

[committed] libstdc++: Fix typos in copyright notice

2020-10-15 Thread Jonathan Wakely via Gcc-patches
It looks like I did a s/a/__a/ substition in one of these headers, and
then copied it to the other one.

libstdc++-v3/ChangeLog:

* include/std/concepts: Fix typos in copyright notice.
* include/std/ranges: Likewise.

Committed to trunk. I'll backport it to gcc-10 too.

commit 7dbf96e2a2a673d78a23da9155c0b4c4c36621c7
Author: Jonathan Wakely 
Date:   Thu Oct 15 19:19:15 2020

libstdc++: Fix typos in copyright notice

It looks like I did a s/a/__a/ substition in one of these headers, and
then copied it to the other one.

libstdc++-v3/ChangeLog:

* include/std/concepts: Fix typos in copyright notice.
* include/std/ranges: Likewise.

diff --git a/libstdc++-v3/include/std/concepts 
b/libstdc++-v3/include/std/concepts
index 9ffed7007d9..e710a5e6ecd 100644
--- a/libstdc++-v3/include/std/concepts
+++ b/libstdc++-v3/include/std/concepts
@@ -17,8 +17,8 @@
 // permissions described in the GCC Runtime Library Exception, version
 // 3.1, as published by the Free Software Foundation.
 
-// You should have received __a copy of the GNU General Public License and
-// __a copy of the GCC Runtime Library Exception along with this program;
+// You should have received a copy of the GNU General Public License and
+// a copy of the GCC Runtime Library Exception along with this program;
 // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 // .
 
diff --git a/libstdc++-v3/include/std/ranges b/libstdc++-v3/include/std/ranges
index 55e7c4de234..b03ae399fa6 100644
--- a/libstdc++-v3/include/std/ranges
+++ b/libstdc++-v3/include/std/ranges
@@ -17,8 +17,8 @@
 // permissions described in the GCC Runtime Library Exception, version
 // 3.1, as published by the Free Software Foundation.
 
-// You should have received __a copy of the GNU General Public License and
-// __a copy of the GCC Runtime Library Exception along with this program;
+// You should have received a copy of the GNU General Public License and
+// a copy of the GCC Runtime Library Exception along with this program;
 // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 // .
 


Re: [PATCH] libstdc++: Add c++2a

2020-10-15 Thread Jonathan Wakely via Gcc-patches

On 15/10/20 07:46 -0700, Thomas Rodgers wrote:

From: Thomas Rodgers 

* Note: depends on a sufficiently C++20ified basic_stringbuf<>.

libstdc++/Changelog:
libstdc++-v3/include/Makefile.am (std_headers): Add new header.
libstdc++-v3/include/Makefile.in: Regenerate.
libstdc++-v3/include/std/streambuf
   (__detail::__streambuf_core_access): Define.
   (basic_streambuf): Befriend __detail::__streambuf_core_access.
libstdc++-v3/include/std/syncstream: New header.
libstdc++-v3/include/std/version: Add __cpp_lib_syncbuf:
libstdc++-v3/testsuite/27_io/basic_syncbuf/1.cc: New test.
libstdc++-v3/testsuite/27_io/basic_syncbuf/2.cc: Likewise.
libstdc++-v3/testsuite/27_io/basic_syncbuf/basic_ops/1.cc:
   Likewise.
libstdc++-v3/testsuite/27_io/basic_syncbuf/requirements/types.cc:
   Likewise.
libstdc++-v3/testsuite/27_io/basic_syncbuf/sync_ops/1.cc:
   Likewise.
libstdc++-v3/testsuite/27_io/basic_syncstream/1.cc: Likewise.
libstdc++-v3/testsuite/27_io/basic_syncstream/2.cc: Likewise.
libstdc++-v3/testsuite/27_io/basic_syncstream/basic_ops/1.cc:
   Likewise.
libstdc++-v3/testsuite/27_io/basic_syncstream/requirements/types.cc:
   Likewise.

---
libstdc++-v3/include/Makefile.am  |   1 +
libstdc++-v3/include/Makefile.in  |   1 +
libstdc++-v3/include/std/streambuf|  81 +
libstdc++-v3/include/std/syncstream   | 333 ++
libstdc++-v3/include/std/version  |   4 +
.../testsuite/27_io/basic_syncbuf/1.cc|  28 ++
.../testsuite/27_io/basic_syncbuf/2.cc|  27 ++
.../27_io/basic_syncbuf/basic_ops/1.cc| 138 
.../27_io/basic_syncbuf/requirements/types.cc |  42 +++
.../27_io/basic_syncbuf/sync_ops/1.cc | 130 +++
.../testsuite/27_io/basic_syncstream/1.cc |  28 ++
.../testsuite/27_io/basic_syncstream/2.cc |  27 ++
.../27_io/basic_syncstream/basic_ops/1.cc | 135 +++
.../basic_syncstream/requirements/types.cc|  43 +++
14 files changed, 1018 insertions(+)
create mode 100644 libstdc++-v3/include/std/syncstream
create mode 100644 libstdc++-v3/testsuite/27_io/basic_syncbuf/1.cc
create mode 100644 libstdc++-v3/testsuite/27_io/basic_syncbuf/2.cc
create mode 100644 libstdc++-v3/testsuite/27_io/basic_syncbuf/basic_ops/1.cc
create mode 100644 
libstdc++-v3/testsuite/27_io/basic_syncbuf/requirements/types.cc
create mode 100644 libstdc++-v3/testsuite/27_io/basic_syncbuf/sync_ops/1.cc
create mode 100644 libstdc++-v3/testsuite/27_io/basic_syncstream/1.cc
create mode 100644 libstdc++-v3/testsuite/27_io/basic_syncstream/2.cc
create mode 100644 libstdc++-v3/testsuite/27_io/basic_syncstream/basic_ops/1.cc
create mode 100644 
libstdc++-v3/testsuite/27_io/basic_syncstream/requirements/types.cc

diff --git a/libstdc++-v3/include/Makefile.am b/libstdc++-v3/include/Makefile.am
index 28d273924ee..61aaff7a2f4 100644
--- a/libstdc++-v3/include/Makefile.am
+++ b/libstdc++-v3/include/Makefile.am
@@ -73,6 +73,7 @@ std_headers = \
${std_srcdir}/shared_mutex \
${std_srcdir}/span \
${std_srcdir}/sstream \
+   ${std_srcdir}/syncstream \
${std_srcdir}/stack \
${std_srcdir}/stdexcept \
${std_srcdir}/stop_token \
diff --git a/libstdc++-v3/include/std/streambuf 
b/libstdc++-v3/include/std/streambuf
index cae35e75bda..d6053e4c1ed 100644
--- a/libstdc++-v3/include/std/streambuf
+++ b/libstdc++-v3/include/std/streambuf
@@ -48,6 +48,84 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION

#define _IsUnused __attribute__ ((__unused__))

+  template
+class basic_streambuf;
+
+#if __cplusplus > 201703L
+  namespace __detail
+  {
+struct __streambuf_core_access
+{
+  template
+   static void
+   _S_imbue(basic_streambuf<_CharT, _Traits>& __b, const locale& __loc)
+   { __b.imbue(__loc); }
+
+  template
+   static basic_streambuf<_CharT, _Traits>*
+   _S_setbuf(basic_streambuf<_CharT, _Traits>& __b,
+ _CharT* __c, streamsize __n)
+   { return __b.setbuf(__c, __n); }
+
+  template
+   static typename _Traits::pos_type
+   _S_seekoff(basic_streambuf<_CharT, _Traits>& __b,
+  typename _Traits::off_type __off, ios_base::seekdir __dir,
+  ios_base::openmode __mode)
+ { return __b.seekoff(__off, __dir, __mode); }
+
+  template
+   static typename _Traits::pos_type
+   _S_seekpos(basic_streambuf<_CharT, _Traits>& __b,
+  typename _Traits::pos_type __pos, ios_base::openmode __mode)
+   { return __b.seekpos(__pos, __mode); }
+
+  template
+   static int
+   _S_sync(basic_streambuf<_CharT, _Traits>& __b)
+   { return __b.sync(); }
+
+  template
+   static streamsize
+   _S_showmanyc(basic_streambuf<_CharT, _Traits>& __b)
+   { return __b.showmanyc(); }
+
+  template
+   static streamsize
+   

*PING* [PATCH] PR fortran/95979 - [10/11 Regression] ICE in get_kind, at fortran/simplify.c:129

2020-10-15 Thread Harald Anlauf
*ping*

> Gesendet: Donnerstag, 08. Oktober 2020 um 20:44 Uhr
> Von: "Harald Anlauf" 
> An: "fortran" , "gcc-patches" 
> Betreff: [PATCH] PR fortran/95979 - [10/11 Regression] ICE in get_kind, at 
> fortran/simplify.c:129
>
> Dear all,
>
> the present PR turned out to be fixable rather easily, once Paul had the
> idea to add another attempt of simplification of elemental intrinsics
> for array-valued arguments.  There was some fallout which required only
> small adjustments, see commit message below.
>
> Regtested cleanly on x86_64-pc-linux-gnu.
>
> OK for master / 10-branch?
>
> Thanks,
> Harald
>
>
> PR fortran/95979 - ICE in get_kind, at fortran/simplify.c:129
>
> Simplification of the elemental intrinsic INDEX with constant array-valued
> arguments failed with an ICE or did not reduce to a constant array, depending
> also on the presence of the optional KIND argument.  Add a further attempt of
> simplification in the case of elemental intrinsics, and make sure the KIND
> argument is not removed prematurely during simplification of INDEX.
>
> gcc/fortran/ChangeLog:
>
>   PR fortran/95979
>   * expr.c (gfc_check_init_expr): Fix check of return code from
>   gfc_intrinsic_func_interface.
>   * intrinsic.c (gfc_intrinsic_func_interface): Add further attempt
>   of simplification of elemental intrinsics with array arguments.
>   * iresolve.c (gfc_resolve_index_func): Keep optional KIND argument
>   for simplification of elemental use of INDEX.
>
> gcc/testsuite/ChangeLog:
>
>   PR fortran/95979
>   * gfortran.dg/index_4.f90: New test.
>
>


Re: [PATCH] libstdc++: Add c++2a

2020-10-15 Thread Jonathan Wakely via Gcc-patches

On 15/10/20 07:46 -0700, Thomas Rodgers wrote:

From: Thomas Rodgers 

* Note: depends on a sufficiently C++20ified basic_stringbuf<>.

libstdc++/Changelog:
libstdc++-v3/include/Makefile.am (std_headers): Add new header.
libstdc++-v3/include/Makefile.in: Regenerate.
libstdc++-v3/include/std/streambuf
   (__detail::__streambuf_core_access): Define.
   (basic_streambuf): Befriend __detail::__streambuf_core_access.
libstdc++-v3/include/std/syncstream: New header.
libstdc++-v3/include/std/version: Add __cpp_lib_syncbuf:
libstdc++-v3/testsuite/27_io/basic_syncbuf/1.cc: New test.
libstdc++-v3/testsuite/27_io/basic_syncbuf/2.cc: Likewise.
libstdc++-v3/testsuite/27_io/basic_syncbuf/basic_ops/1.cc:
   Likewise.
libstdc++-v3/testsuite/27_io/basic_syncbuf/requirements/types.cc:
   Likewise.
libstdc++-v3/testsuite/27_io/basic_syncbuf/sync_ops/1.cc:
   Likewise.
libstdc++-v3/testsuite/27_io/basic_syncstream/1.cc: Likewise.
libstdc++-v3/testsuite/27_io/basic_syncstream/2.cc: Likewise.
libstdc++-v3/testsuite/27_io/basic_syncstream/basic_ops/1.cc:
   Likewise.
libstdc++-v3/testsuite/27_io/basic_syncstream/requirements/types.cc:
   Likewise.

---
libstdc++-v3/include/Makefile.am  |   1 +
libstdc++-v3/include/Makefile.in  |   1 +
libstdc++-v3/include/std/streambuf|  81 +
libstdc++-v3/include/std/syncstream   | 333 ++
libstdc++-v3/include/std/version  |   4 +
.../testsuite/27_io/basic_syncbuf/1.cc|  28 ++
.../testsuite/27_io/basic_syncbuf/2.cc|  27 ++
.../27_io/basic_syncbuf/basic_ops/1.cc| 138 
.../27_io/basic_syncbuf/requirements/types.cc |  42 +++
.../27_io/basic_syncbuf/sync_ops/1.cc | 130 +++
.../testsuite/27_io/basic_syncstream/1.cc |  28 ++
.../testsuite/27_io/basic_syncstream/2.cc |  27 ++
.../27_io/basic_syncstream/basic_ops/1.cc | 135 +++
.../basic_syncstream/requirements/types.cc|  43 +++
14 files changed, 1018 insertions(+)
create mode 100644 libstdc++-v3/include/std/syncstream
create mode 100644 libstdc++-v3/testsuite/27_io/basic_syncbuf/1.cc
create mode 100644 libstdc++-v3/testsuite/27_io/basic_syncbuf/2.cc
create mode 100644 libstdc++-v3/testsuite/27_io/basic_syncbuf/basic_ops/1.cc
create mode 100644 
libstdc++-v3/testsuite/27_io/basic_syncbuf/requirements/types.cc
create mode 100644 libstdc++-v3/testsuite/27_io/basic_syncbuf/sync_ops/1.cc
create mode 100644 libstdc++-v3/testsuite/27_io/basic_syncstream/1.cc
create mode 100644 libstdc++-v3/testsuite/27_io/basic_syncstream/2.cc
create mode 100644 libstdc++-v3/testsuite/27_io/basic_syncstream/basic_ops/1.cc
create mode 100644 
libstdc++-v3/testsuite/27_io/basic_syncstream/requirements/types.cc

diff --git a/libstdc++-v3/include/Makefile.am b/libstdc++-v3/include/Makefile.am
index 28d273924ee..61aaff7a2f4 100644
--- a/libstdc++-v3/include/Makefile.am
+++ b/libstdc++-v3/include/Makefile.am
@@ -73,6 +73,7 @@ std_headers = \
${std_srcdir}/shared_mutex \
${std_srcdir}/span \
${std_srcdir}/sstream \
+   ${std_srcdir}/syncstream \


The new header should also be added to include/precompiled/stdc++.h
and doc/doxygen/user.cfg.in


${std_srcdir}/stack \
${std_srcdir}/stdexcept \
${std_srcdir}/stop_token \
diff --git a/libstdc++-v3/include/std/streambuf 
b/libstdc++-v3/include/std/streambuf
index cae35e75bda..d6053e4c1ed 100644
--- a/libstdc++-v3/include/std/streambuf
+++ b/libstdc++-v3/include/std/streambuf
@@ -48,6 +48,84 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION

#define _IsUnused __attribute__ ((__unused__))

+  template
+class basic_streambuf;
+
+#if __cplusplus > 201703L
+  namespace __detail
+  {
+struct __streambuf_core_access
+{
+  template
+   static void
+   _S_imbue(basic_streambuf<_CharT, _Traits>& __b, const locale& __loc)
+   { __b.imbue(__loc); }


As discussed on IRC, this doesn't work. But as discussed below, I
don't think it's needed at all.


+#endif // C++20
+
  template
streamsize
__copy_streambufs_eof(basic_streambuf<_CharT, _Traits>*,
@@ -456,6 +534,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
  { return this->xsputn(__s, __n); }

protected:
+#if __cplusplus > 201703L
+  friend __detail::__streambuf_core_access;
+#endif
  /**
   *  @brief  Base constructor.
   *
diff --git a/libstdc++-v3/include/std/syncstream 
b/libstdc++-v3/include/std/syncstream
new file mode 100644
index 000..0a034ed03f4
--- /dev/null
+++ b/libstdc++-v3/include/std/syncstream
@@ -0,0 +1,333 @@
+//  -*- C++ -*-
+
+// Copyright (C) 2020 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; 

Re: [PATCH] arm: Implement vceqq_p64, vceqz_p64 and vceqzq_p64 intrinsics

2020-10-15 Thread Andrea Corallo via Gcc-patches
Hi Christophe,

I've spotted two very minors.

Christophe Lyon via Gcc-patches  writes:

[...]

> +/* For vceqq_p64, we rely on vceq_p64 for each of the two elements.  */
> +__extension__ extern __inline uint64x2_t
> +__attribute__  ((__always_inline__, __gnu_inline__, __artificial__))
> +vceqq_p64 (poly64x2_t __a, poly64x2_t __b)
> +{
> +  poly64_t __high_a = vget_high_p64 (__a);
> +  poly64_t __high_b = vget_high_p64 (__b);
> +  uint64x1_t __high = vceq_p64(__high_a, __high_b);
^^^
   space
> +
> +  poly64_t __low_a = vget_low_p64 (__a);
> +  poly64_t __low_b = vget_low_p64 (__b);
> +  uint64x1_t __low = vceq_p64(__low_a, __low_b);

Same

> +  return vcombine_u64 (__low, __high);
> +}
> +
> +__extension__ extern __inline uint64x2_t
> +__attribute__  ((__always_inline__, __gnu_inline__, __artificial__))
> +vceqzq_p64 (poly64x2_t __a)
> +{
> +  poly64x2_t __b = vreinterpretq_p64_u32 (vdupq_n_u32 (0));
> +  return vceqq_p64 (__a, __b);
> +}

Thanks

  Andrea


Re: [PATCH] libgccjit: add some reflection functions in the jit C api

2020-10-15 Thread Andrea Corallo via Gcc-patches
Antoni Boucher  writes:

> Thanks. I updated the patch with these changes.
>
> Is there any tool to automatically check the style?

Yes, we have in contrib check_GNU_style.sh and check_GNU_style.py.

  Andrea


Re: [PATCH] libgccjit: add some reflection functions in the jit C api

2020-10-15 Thread Antoni Boucher via Gcc-patches

Thanks. I updated the patch with these changes.

Is there any tool to automatically check the style?

On Thu, Oct 15, 2020 at 06:23:18PM +0200, Andrea Corallo wrote:

Antoni Boucher via Jit  writes:

Hi Antoni,

Just had a quick look, please find some quite minor comments in line.


From b0edc9eb8e8d3ba9e1c6a8d061a8627c0b0cf102 Mon Sep 17 00:00:00 2001
From: Antoni Boucher 
Date: Sat, 1 Aug 2020 17:52:17 -0400
Subject: [PATCH] This patch add some reflection functions in the jit C api
 [PR96889]

2020-09-1  Antoni Boucher  

gcc/jit/
PR target/96889
* docs/topics/compatibility.rst (LIBGCCJIT_ABI_14): New ABI tag.
* docs/topics/functions.rst: Add documentation for the
functions gcc_jit_function_get_return_type and
gcc_jit_function_get_param_count
* libgccjit.c: New functions:
  * gcc_jit_function_get_return_type;
  * gcc_jit_function_get_param_count;
  * gcc_jit_function_type_get_return_type;
  * gcc_jit_function_type_get_param_count;
  * gcc_jit_function_type_get_param_type;
  * gcc_jit_type_unqualified;
  * gcc_jit_type_is_array;
  * gcc_jit_type_is_bool;
  * gcc_jit_type_is_function_ptr_type;
  * gcc_jit_type_is_int;
  * gcc_jit_type_is_pointer;
  * gcc_jit_type_is_vector;
  * gcc_jit_vector_type_get_element_type;
  * gcc_jit_vector_type_get_num_units;
  * gcc_jit_struct_get_field;
  * gcc_jit_type_is_struct;
  * gcc_jit_struct_get_field_count;
* libgccjit.h
* jit-recording.h: New functions (is_struct and is_vector)
* libgccjit.map (LIBGCCJIT_ABI_14): New ABI tag.

gcc/testsuite/
PR target/96889
* jit.dg/all-non-failing-tests.h: Add test-reflection.c.
* jit.dg/test-reflection.c: New test.
---
 gcc/jit/docs/topics/compatibility.rst|  41 +++
 gcc/jit/docs/topics/functions.rst|  10 +
 gcc/jit/jit-recording.h  |  16 ++
 gcc/jit/libgccjit.c  | 254 +++
 gcc/jit/libgccjit.h  | 117 +
 gcc/jit/libgccjit.map|  21 ++
 gcc/testsuite/jit.dg/all-non-failing-tests.h |  10 +
 gcc/testsuite/jit.dg/test-reflection.c   |  89 +++
 8 files changed, 558 insertions(+)
 create mode 100644 gcc/testsuite/jit.dg/test-reflection.c

diff --git a/gcc/jit/docs/topics/compatibility.rst 
b/gcc/jit/docs/topics/compatibility.rst
index 6bfa101ed71..16f24d20a75 100644
--- a/gcc/jit/docs/topics/compatibility.rst
+++ b/gcc/jit/docs/topics/compatibility.rst
@@ -226,3 +226,44 @@ entrypoints:
 
 ``LIBGCCJIT_ABI_14`` covers the addition of
 :func:`gcc_jit_global_set_initializer`
+
+.. _LIBGCCJIT_ABI_15:
+
+``LIBGCCJIT_ABI_15``
+
+``LIBGCCJIT_ABI_15`` covers the addition of reflection functions via API
+entrypoints:
+
+  * :func:`gcc_jit_function_get_return_type`
+
+  * :func:`gcc_jit_function_get_param_count`
+
+  * :func:`gcc_jit_type_is_array`
+
+  * :func:`gcc_jit_type_is_bool`
+
+  * :func:`gcc_jit_type_is_int`
+
+  * :func:`gcc_jit_type_is_pointer`
+
+  * :func:`gcc_jit_type_is_struct`
+
+  * :func:`gcc_jit_type_is_vector`
+
+  * :func:`gcc_jit_type_unqualified`
+
+  * :func:`gcc_jit_type_is_function_ptr_type`
+
+  * :func:`gcc_jit_function_type_get_return_type`
+
+  * :func:`gcc_jit_function_type_get_param_count`
+
+  * :func:`gcc_jit_function_type_get_param_type`
+
+  * :func:`gcc_jit_vector_type_get_num_units`
+
+  * :func:`gcc_jit_vector_type_get_element_type`
+
+  * :func:`gcc_jit_struct_get_field`
+
+  * :func:`gcc_jit_struct_get_field_count`
diff --git a/gcc/jit/docs/topics/functions.rst 
b/gcc/jit/docs/topics/functions.rst
index eb40d64010e..9819c28cda2 100644
--- a/gcc/jit/docs/topics/functions.rst
+++ b/gcc/jit/docs/topics/functions.rst
@@ -171,6 +171,16 @@ Functions
underlying string, so it is valid to pass in a pointer to an on-stack
buffer.

+.. function::  size_t \
+   gcc_jit_function_get_param_count (gcc_jit_function *func)
+
+   Get the number of parameters of the function.
+
+.. function::  gcc_jit_type \*
+   gcc_jit_function_get_return_type (gcc_jit_function *func)
+
+   Get the return type of the function.
+
 Blocks
 --
 .. type:: gcc_jit_block
diff --git a/gcc/jit/jit-recording.h b/gcc/jit/jit-recording.h
index 30e37aff387..525b8bc921d 100644
--- a/gcc/jit/jit-recording.h
+++ b/gcc/jit/jit-recording.h
@@ -538,7 +538,9 @@ public:
   virtual bool is_bool () const = 0;
   virtual type *is_pointer () = 0;
   virtual type *is_array () = 0;
+  virtual struct_ *is_struct () { return NULL; }
   virtual bool is_void () const { return false; }
+  virtual vector_type *is_vector () { return NULL; }
   virtual bool has_known_size () const { return true; }

   bool 

[PATCH] Hashtable refactoring and simplification

2020-10-15 Thread François Dumont via Gcc-patches
I'd like to integrate some of the refactoring I had to do as part of my 
work on support of custom pointers in unordered containers.


Those are of course the abi compatible changes.

Thanks to the changes on _Hash_node type definition I was able to get 
rid of _Hash_code_base partial specialization. I also removed the 
smaller _Hashtable_base::_Equal_hash_code helper type. For this one I 
wonder if you prefer to keep it in place of the new 
_S_equals/_S_node_equals overloads ?


I also review where typedef are done. Mostly those done in 
_Hashtable_base have been moved in _Insert_base because it is the type 
making use of it and moreover _Insert_base knowns about the allocator 
whereas _Hashtable_base don't. It is mandatory to know the allocator to 
support its custom pointers.


Patch generated with -b option cause there is an indentation issue in 
_Hashtable_base definition.


    libstdc++: Refactor _Hashtable to prepare for custom pointers

    Limit usage of node pointers in _Hashtable implementation details 
so that when
    we move to allocator custom pointer type we do not need to add an 
_Alloc

    template parameter everywhere which would impact abi.

    This is done by reviewing node type definition. It is now based on 
new basic

    types which are not pointer dependant. The _Hashtable helper
    types are now using those new node base types and do not receive 
node pointers.


    libstdc++-v3/ChangeLog

    * include/bits/hashtable_policy.h
    (_Hash_node_value_base<>): Remove _Hash_node_base inheritance.
    (_Hash_node_code_cache): New.
    (_Hash_node_value): 
New.
    (_Hash_node<>): Inherits _Hash_node_base<> and 
_Hash_node_value<>.

    (_Map_base<>::__node_type): Remove.
    (_Map_base<>::iterator): Remove.
    (_Insert_base<>::__hash_cached): New.
    (_Insert_base<>::__constant_iterators): New.
    (_Insert_base<>::__hashtable_alloc): New.
    (_Insert_base<>::__node_type): Remove.
    (_Insert_base<>::__node_ptr): New.
    (_Hash_code_base<>): Remove specializations.
    (_Hash_code_base<>::__node_type): Remove.
    (_Hash_code_base<>::_M_bucket_index(const __node_type*, 
size_t)):

    Replace by...
    (_Hash_code_base<>::_M_bucket_index(const 
_Hash_node_value<>&, size_t)):

    ...this.
    (_Hash_code_base<>::_M_store_code(__node_type*, __hash_code)):
    Replace by...
(_Hash_code_base<>::_M_store_code(_Hash_node_code_cache<>&, __hash_code)):
    ...this.
    (_Hash_code_base<>::_M_copy_code(__node_type*, const 
__node_type*)):

    Replace by...
(_Hash_code_base<>::_M_copy_code(_Hash_node_code_cache<>&,
    const _Hash_node_code_base<>&)): ...this.
    (_Hashtable_base<>::__constant_iterators): Remove.
    (_Hashtable_base<>::__unique_keys): Remove.
    (_Hashtable_base<>::__node_type): Remove.
    (_Hashtable_base<>::iterator): Remove.
    (_Hashtable_base<>::const_iterator): Remove.
    (_Hashtable_base<>::local_iterator): Remove.
    (_Hashtable_base<>::const_local_iterator): Remove.
    (_Hashtable_base<>::__ireturn_type): Remove.
(_Hashtable_base<>::_Equal_hash_code<>::_S_equals): Replace by...
    (_Hashtable_base<>::_S_equals(__hash_code, const 
_Hash_node_code_hash<>&)):

    ...this.
(_Hashtable_base<>::_Equal_hash_code<>::_S_node_equals): Replace by...
    (_Hashtable_base<>::_S_node_equals(__hash_code,
    const _Hash_node_code_hash<>&)): ...this.
    (_Hashtable_base<>::_Equal_hash_code<>): Remove.
    (_Hashtable_base<>::_M_equals): Adapt.
    (_Hashtable_baxe<>::_M_node_equals): Adapt.
    (_Equality<>::_M_equal): Adapt.
    (_Hashtable_alloc<>::__node_ptr): New.
    (_Hashtable_alloc<>::__bucket_type): Rename into...
    (_Hashtable_alloc<>::__node_base_ptr): ...this.
    (_Hashtable_alloc<>::__bucket_alloc_type): Rename into...
    (_Hashtable_alloc<>::__buckets_alloc_type): ...this.
    (_Hashtable_alloc<>::__bucket_alloc_traits): Rename into...
    (_Hashtable_alloc<>::__buckets_alloc_traits): ...this.
    (_Hashtable_alloc<>::__buckets_ptr): New.
    (_Hashtable_alloc<>::_M_allocate_node): Adapt.
    (_Hashtable_alloc<>::_M_deallocate_node): Adapt.
    (_Hashtable_alloc<>::_M_deallocate_node_ptr): Adapt.
    (_Hashtable_alloc<>::_M_deallocate_nodes): Adapt.
    (_Hashtable_alloc<>::_M_allocate_buckets): Adapt.
    (_Hashtable_alloc<>::_M_deallocate_buckets): Adapt.
    * include/bits/hashtable.h (_Hashtable<>): Adapt.

All unordered containers tests run successfully on Linux x86_64.

Ok to commit once all tests run ?

François

diff --git a/libstdc++-v3/include/bits/hashtable.h b/libstdc++-v3/include/bits/hashtable.h

[pushed] c++: Fix [[deprecated]] and implicit operator==. [PR97358]

2020-10-15 Thread Jason Merrill via Gcc-patches
Trying to diagnose the problem with an implicit copy function breaks if the
function isn't actually a copy function.

Tested x86_64-pc-linux-gnu, applying to trunk.

gcc/cp/ChangeLog:

PR c++/95844
* decl.c (copy_fn_p): Return false for a function that is neither a
constructor nor an assignment operator.
(move_signature_fn_p): Likewise.

gcc/testsuite/ChangeLog:

PR c++/95844
* g++.dg/cpp2a/spaceship-eq10.C: New test.
---
 gcc/cp/decl.c   |  8 
 gcc/testsuite/g++.dg/cpp2a/spaceship-eq10.C | 11 +++
 2 files changed, 19 insertions(+)
 create mode 100644 gcc/testsuite/g++.dg/cpp2a/spaceship-eq10.C

diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 2f1a2f0c554..5f370e60b4e 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -14169,6 +14169,10 @@ copy_fn_p (const_tree d)
accept those as copy functions.  */
 return 0;
 
+  if (!DECL_CONSTRUCTOR_P (d)
+  && DECL_NAME (d) != assign_op_identifier)
+return 0;
+
   args = FUNCTION_FIRST_USER_PARMTYPE (d);
   if (!args)
 return 0;
@@ -14242,6 +14246,10 @@ move_signature_fn_p (const_tree d)
   tree arg_type;
   bool result = false;
 
+  if (!DECL_CONSTRUCTOR_P (d)
+  && DECL_NAME (d) != assign_op_identifier)
+return 0;
+
   args = FUNCTION_FIRST_USER_PARMTYPE (d);
   if (!args)
 return 0;
diff --git a/gcc/testsuite/g++.dg/cpp2a/spaceship-eq10.C 
b/gcc/testsuite/g++.dg/cpp2a/spaceship-eq10.C
new file mode 100644
index 000..93f5e253af4
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/spaceship-eq10.C
@@ -0,0 +1,11 @@
+// PR c++/95844
+// { dg-do compile { target c++20 } }
+
+#include 
+
+struct F {
+  [[deprecated("oh no")]] std::strong_ordering operator<=>(const F&) const = 
default; // { dg-message "" }
+};
+void use_f(F f) {
+  void(f == f);// { dg-warning "deprecated" }
+}

base-commit: 08e712211efa4f969a64c69bdacf6ab45104a094
-- 
2.18.4



[PATCH] arm: Implement vceqq_p64, vceqz_p64 and vceqzq_p64 intrinsics

2020-10-15 Thread Christophe Lyon via Gcc-patches
This patch adds implementations for vceqq_p64, vceqz_p64 and
vceqzq_p64 intrinsics.

vceqq_p64 uses the existing vceq_p64 after splitting the input vectors
into their high and low halves.

vceqz[q] simply call the vceq and vceqq with a second argument equal
to zero.

The added (executable) testcases make sure that the poly64x2_t
variants have results with one element of all zeroes (false) and the
other element with all bits set to one (true).

2020-10-15  Christophe Lyon  

gcc/
* config/arm/arm_neon.h (vceqz_p64, vceqq_p64, vceqzq_p64): New.

gcc/testsuite/
* gcc.target/aarch64/advsimd-intrinsics/p64_p128.c: Add tests for
vceqz_p64, vceqq_p64 and vceqzq_p64.
---
 gcc/config/arm/arm_neon.h  | 31 +++
 .../aarch64/advsimd-intrinsics/p64_p128.c  | 46 +-
 2 files changed, 76 insertions(+), 1 deletion(-)

diff --git a/gcc/config/arm/arm_neon.h b/gcc/config/arm/arm_neon.h
index aa21730..f7eff37 100644
--- a/gcc/config/arm/arm_neon.h
+++ b/gcc/config/arm/arm_neon.h
@@ -16912,6 +16912,37 @@ vceq_p64 (poly64x1_t __a, poly64x1_t __b)
   return vreinterpret_u64_u32 (__m);
 }
 
+__extension__ extern __inline uint64x1_t
+__attribute__  ((__always_inline__, __gnu_inline__, __artificial__))
+vceqz_p64 (poly64x1_t __a)
+{
+  poly64x1_t __b = vreinterpret_p64_u32 (vdup_n_u32 (0));
+  return vceq_p64 (__a, __b);
+}
+
+/* For vceqq_p64, we rely on vceq_p64 for each of the two elements.  */
+__extension__ extern __inline uint64x2_t
+__attribute__  ((__always_inline__, __gnu_inline__, __artificial__))
+vceqq_p64 (poly64x2_t __a, poly64x2_t __b)
+{
+  poly64_t __high_a = vget_high_p64 (__a);
+  poly64_t __high_b = vget_high_p64 (__b);
+  uint64x1_t __high = vceq_p64(__high_a, __high_b);
+
+  poly64_t __low_a = vget_low_p64 (__a);
+  poly64_t __low_b = vget_low_p64 (__b);
+  uint64x1_t __low = vceq_p64(__low_a, __low_b);
+  return vcombine_u64 (__low, __high);
+}
+
+__extension__ extern __inline uint64x2_t
+__attribute__  ((__always_inline__, __gnu_inline__, __artificial__))
+vceqzq_p64 (poly64x2_t __a)
+{
+  poly64x2_t __b = vreinterpretq_p64_u32 (vdupq_n_u32 (0));
+  return vceqq_p64 (__a, __b);
+}
+
 /* The vtst_p64 intrinsic does not map to a single instruction.
We emulate it in way similar to vceq_p64 above but here we do
a reduction with max since if any two corresponding bits
diff --git a/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/p64_p128.c 
b/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/p64_p128.c
index a3210a9..6aed096 100644
--- a/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/p64_p128.c
+++ b/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/p64_p128.c
@@ -16,6 +16,11 @@ VECT_VAR_DECL(vbsl_expected,poly,64,2) [] = { 0xfff1,
 
 /* Expected results: vceq.  */
 VECT_VAR_DECL(vceq_expected,uint,64,1) [] = { 0x0 };
+VECT_VAR_DECL(vceq_expected,uint,64,2) [] = { 0x0, 0x };
+
+/* Expected results: vceqz.  */
+VECT_VAR_DECL(vceqz_expected,uint,64,1) [] = { 0x0 };
+VECT_VAR_DECL(vceqz_expected,uint,64,2) [] = { 0x0, 0x };
 
 /* Expected results: vcombine.  */
 VECT_VAR_DECL(vcombine_expected,poly,64,2) [] = { 0xfff0, 0x88 };
@@ -213,7 +218,7 @@ int main (void)
 
   /* vceq_p64 tests. */
 #undef TEST_MSG
-#define TEST_MSG "VCEQ"
+#define TEST_MSG "VCEQ/VCEQQ"
 
 #define TEST_VCOMP1(INSN, Q, T1, T2, T3, W, N) \
   VECT_VAR(vceq_vector_res, T3, W, N) =
\
@@ -227,16 +232,55 @@ int main (void)
   DECL_VARIABLE(vceq_vector, poly, 64, 1);
   DECL_VARIABLE(vceq_vector2, poly, 64, 1);
   DECL_VARIABLE(vceq_vector_res, uint, 64, 1);
+  DECL_VARIABLE(vceq_vector, poly, 64, 2);
+  DECL_VARIABLE(vceq_vector2, poly, 64, 2);
+  DECL_VARIABLE(vceq_vector_res, uint, 64, 2);
 
   CLEAN(result, uint, 64, 1);
+  CLEAN(result, uint, 64, 2);
 
   VLOAD(vceq_vector, buffer, , poly, p, 64, 1);
+  VLOAD(vceq_vector, buffer, q, poly, p, 64, 2);
 
   VDUP(vceq_vector2, , poly, p, 64, 1, 0x88);
+  VSET_LANE(vceq_vector2, q, poly, p, 64, 2, 0, 0x88);
+  VSET_LANE(vceq_vector2, q, poly, p, 64, 2, 1, 0xFFF1);
 
   TEST_VCOMP(vceq, , poly, p, uint, 64, 1);
+  TEST_VCOMP(vceq, q, poly, p, uint, 64, 2);
 
   CHECK(TEST_MSG, uint, 64, 1, PRIx64, vceq_expected, "");
+  CHECK(TEST_MSG, uint, 64, 2, PRIx64, vceq_expected, "");
+
+  /* vceqz_p64 tests. */
+#undef TEST_MSG
+#define TEST_MSG "VCEQZ/VCEQZQ"
+
+#define TEST_VCOMPZ1(INSN, Q, T1, T2, T3, W, N)
\
+  VECT_VAR(vceqz_vector_res, T3, W, N) =   \
+INSN##Q##_##T2##W(VECT_VAR(vceqz_vector, T1, W, N));   \
+  vst1##Q##_u##W(VECT_VAR(result, T3, W, N), VECT_VAR(vceqz_vector_res, T3, W, 
N))
+
+#define TEST_VCOMPZ(INSN, Q, T1, T2, T3, W, N) \
+  TEST_VCOMPZ1(INSN, Q, T1, T2, T3, W, N)
+
+  DECL_VARIABLE(vceqz_vector, poly, 64, 1);
+  

Re: [PATCH] IPA: compare VRP types.

2020-10-15 Thread Martin Jambor
On Thu, Oct 15 2020, Martin Liška wrote:
> Hello.
>
> As mentioned in the PR, since 74ca1c01d02e548f32aa26f9a887dcc0730703fb we 
> wrongly
> merge a pair of VRP ranges with a different TREE_TYPE (in the PR one is char 
> and second
> one is short). Then we merge 2 ranges and make an anti-range and bad things 
> happen.
>
> Patch can bootstrap on x86_64-linux-gnu and survives regression tests.
>
> Ready to be installed?
> Thanks,
> Martin
>
> gcc/ChangeLog:
>
>   PR ipa/97404
>   * ipa-prop.c (struct ipa_vr_ggc_hash_traits):
>   Compare types of VRP min and max as we can merge ranges of
>   different types.
>
> gcc/testsuite/ChangeLog:
>
>   PR ipa/97404
>   * gcc.c-torture/execute/pr97404.c: New test.
> ---
>   gcc/ipa-prop.c|  6 +++-
>   gcc/testsuite/gcc.c-torture/execute/pr97404.c | 28 +++
>   2 files changed, 33 insertions(+), 1 deletion(-)
>   create mode 100644 gcc/testsuite/gcc.c-torture/execute/pr97404.c
>
> diff --git a/gcc/ipa-prop.c b/gcc/ipa-prop.c
> index 63c652f4ffc..3d0ebefa4aa 100644
> --- a/gcc/ipa-prop.c
> +++ b/gcc/ipa-prop.c
> @@ -123,7 +123,11 @@ struct ipa_vr_ggc_hash_traits : public ggc_cache_remove 
> 
> static bool
> equal (const value_range *a, const value_range *b)
>   {
> -  return a->equal_p (*b);
> +  return (a->equal_p (*b)
> +   && types_compatible_p (TREE_TYPE (a->min ()),
> +  TREE_TYPE (b->min ()))
> +   && types_compatible_p (TREE_TYPE (a->max ()),
> +  TREE_TYPE (b->max (;

I think the best check is:

  types_compatible_p (a->type (), b->type ())

...which internally checks just the minima, but I understand the
intention is that the types are the same or at least compatible.

OK with that change.

Thanks!

Martin


Re: [RFC] Automatic linking of libatomic via gcc.c or ...? [PR81358] (dependency for libgomp on nvptx dep, configure overriddable, ...)

2020-10-15 Thread Tobias Burnus

Hi Joseph, hi Jakub,

(a) For the driver route:

On 10/15/20 12:22 AM, Joseph Myers wrote:

I think it should be somewhere in the expansion of %(link_gcc_c_sequence)
(i.e. LINK_GCC_C_SEQUENCE_SPEC, which has various target-specific
definitions), since that's what expands to something like -lgcc -lc -lgcc.
Maybe after the first -lgcc and before the -lc, since libatomic has
references to libc functions.


Lightly tested draft patch attached. (--enable-autolink-libatomic is 'no' by 
default)
Does this make sense, in principle?

When trying the patch, one runs into the problem that -latomic
fails in the target configure for libgomp ("error: C compiler
cannot create executables"). Any suggestion? (That's on x86_64-gnu-linux.)

(b) I start thinking that putting it into libgomp.spec – possibly with the new 
configure
--enable... flag and/or only for nvptx (which uses libatomic via
../libgomp/config/nvptx/atomic.c) – is the better solution.
Thoughts?

Tobias

-
Mentor Graphics (Deutschland) GmbH, Arnulfstraße 201, 80634 München / Germany
Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Alexander 
Walter
configure: Add --enable-autolink-libatomic, use in LINK_GCC_C_SEQUENCE_SPEC [PR81358]

ChangeLog:
	PR gcc/81358
	* Makefile.in (HOST_EXPORTS): Also export TARGET_CONFIGDIRS.

gcc/ChangeLog:

	PR gcc/81358
	* configure.ac: Add --enable-autolink-libatomic.
	* gcc.c (LINK_LIBATOMIC_SPEC): Conditionally define it.
	(LINK_GCC_C_SEQUENCE_SPEC): Use it.
	* config/gnu-user.h (LINK_LIBATOMIC_SPEC): Conditionally define it.
	(GNU_USER_TARGET_LINK_GCC_C_SEQUENCE_SPEC): Use it.
	* doc/install.texi: Add --enable-autolink-libatomic.
	* doc/tm.texi.in (LINK_LIBATOMIC_SPEC): Add.
	(LINK_GCC_C_SEQUENCE_SPEC): Update.
	* config.in: Regenerated.
	* configure: Regenerated.
	* doc/tm.texi: Regenerated.

 Makefile.in   |  1 +
 gcc/config.in |  6 ++
 gcc/config/gnu-user.h | 10 +-
 gcc/configure | 36 +---
 gcc/configure.ac  | 23 ++-
 gcc/doc/install.texi  |  8 
 gcc/doc/tm.texi   |  8 +++-
 gcc/doc/tm.texi.in|  8 +++-
 gcc/gcc.c | 10 +-
 9 files changed, 102 insertions(+), 8 deletions(-)

diff --git a/Makefile.in b/Makefile.in
index 36e369df6e7..7deb476905f 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -221,6 +221,7 @@ HOST_EXPORTS = \
 	RANLIB_FOR_TARGET="$(RANLIB_FOR_TARGET)"; export RANLIB_FOR_TARGET; \
 	READELF_FOR_TARGET="$(READELF_FOR_TARGET)"; export READELF_FOR_TARGET; \
 	TOPLEVEL_CONFIGURE_ARGUMENTS="$(TOPLEVEL_CONFIGURE_ARGUMENTS)"; export TOPLEVEL_CONFIGURE_ARGUMENTS; \
+	TARGET_CONFIGDIRS="$(TARGET_CONFIGDIRS)"; export TARGET_CONFIGDIRS; \
 	HOST_LIBS="$(STAGE1_LIBS)"; export HOST_LIBS; \
 	GMPLIBS="$(HOST_GMPLIBS)"; export GMPLIBS; \
 	GMPINC="$(HOST_GMPINC)"; export GMPINC; \
diff --git a/gcc/config/gnu-user.h b/gcc/config/gnu-user.h
index ff2e880b1fa..73a34118949 100644
--- a/gcc/config/gnu-user.h
+++ b/gcc/config/gnu-user.h
@@ -109,8 +109,16 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 #define LINK_EH_SPEC "%{!static|static-pie:--eh-frame-hdr} "
 #endif
 
+#if !defined(LINK_LIBATOMIC_SPEC) && defined(ENABLE_AUTOLINK_LIBATOMIC)
+#  ifdef LD_AS_NEEDED_OPTION
+#define LINK_LIBATOMIC_SPEC LD_AS_NEEDED_OPTION " -latomic " LD_NO_AS_NEEDED_OPTION
+#  else
+#define LINK_LIBATOMIC_SPEC "-latomic"
+#  endif
+#endif
+
 #define GNU_USER_TARGET_LINK_GCC_C_SEQUENCE_SPEC \
-  "%{static|static-pie:--start-group} %G %{!nolibc:%L} \
+  "%{static|static-pie:--start-group} %G %{!nolibc:" LINK_LIBATOMIC_SPEC " %L} \
%{static|static-pie:--end-group}%{!static:%{!static-pie:%G}}"
 
 #undef LINK_GCC_C_SEQUENCE_SPEC
diff --git a/gcc/configure.ac b/gcc/configure.ac
index 26a5d8e3619..a6e795986c0 100644
--- a/gcc/configure.ac
+++ b/gcc/configure.ac
@@ -1102,6 +1102,28 @@ AC_ARG_WITH(multilib-list,
 :,
 with_multilib_list=default)
 
+# If libatomic is available, whether it should be linked automatically
+AC_ARG_ENABLE(autolink-libatomic,
+[AS_HELP_STRING([--enable-autolink-libatomic],
+		[enable automatic linking of libatomic (ignored if not built)])],
+[
+  case $enable_autolink_libatomic in
+yes | no) ;;
+*) AC_MSG_ERROR(['$enable_autolink_libatomic' is an invalid value for
+--enable-autolink-libatomic.  Valid choices are 'yes' and 'no'.]) ;;
+  esac
+], [enable_autolink_libatomic=''])
+
+if test x$enable_autolink_libatomic = xyes; then
+  if echo " ${TARGET_CONFIGDIRS} " | grep " libatomic " > /dev/null 2>&1 ; then
+AC_DEFINE(ENABLE_AUTOLINK_LIBATOMIC, 1,
+	[Define if libatomic should always be linked.])
+  else
+AC_MSG_WARN([libatomic is not build for this target, --enable-autolink-libatomic ignored])
+  fi
+fi
+
+
 # -
 # Checks for other programs
 # -
@@ -7106,4 +7128,3 @@ done
 ], 
 [subdirs='$subdirs'])
 AC_OUTPUT
-
diff --git a/gcc/doc/install.texi 

Re: [PATCH] libgccjit: add some reflection functions in the jit C api

2020-10-15 Thread Andrea Corallo via Gcc-patches
Antoni Boucher via Jit  writes:

Hi Antoni,

Just had a quick look, please find some quite minor comments in line.

> From b0edc9eb8e8d3ba9e1c6a8d061a8627c0b0cf102 Mon Sep 17 00:00:00 2001
> From: Antoni Boucher 
> Date: Sat, 1 Aug 2020 17:52:17 -0400
> Subject: [PATCH] This patch add some reflection functions in the jit C api
>  [PR96889]
>
> 2020-09-1  Antoni Boucher  
>
> gcc/jit/
> PR target/96889
> * docs/topics/compatibility.rst (LIBGCCJIT_ABI_14): New ABI tag.
> * docs/topics/functions.rst: Add documentation for the
> functions gcc_jit_function_get_return_type and
> gcc_jit_function_get_param_count
> * libgccjit.c: New functions:
>   * gcc_jit_function_get_return_type;
>   * gcc_jit_function_get_param_count;
>   * gcc_jit_function_type_get_return_type;
>   * gcc_jit_function_type_get_param_count;
>   * gcc_jit_function_type_get_param_type;
>   * gcc_jit_type_unqualified;
>   * gcc_jit_type_is_array;
>   * gcc_jit_type_is_bool;
>   * gcc_jit_type_is_function_ptr_type;
>   * gcc_jit_type_is_int;
>   * gcc_jit_type_is_pointer;
>   * gcc_jit_type_is_vector;
>   * gcc_jit_vector_type_get_element_type;
>   * gcc_jit_vector_type_get_num_units;
>   * gcc_jit_struct_get_field;
>   * gcc_jit_type_is_struct;
>   * gcc_jit_struct_get_field_count;
> * libgccjit.h
> * jit-recording.h: New functions (is_struct and is_vector)
> * libgccjit.map (LIBGCCJIT_ABI_14): New ABI tag.
>
> gcc/testsuite/
> PR target/96889
> * jit.dg/all-non-failing-tests.h: Add test-reflection.c.
> * jit.dg/test-reflection.c: New test.
> ---
>  gcc/jit/docs/topics/compatibility.rst|  41 +++
>  gcc/jit/docs/topics/functions.rst|  10 +
>  gcc/jit/jit-recording.h  |  16 ++
>  gcc/jit/libgccjit.c  | 254 +++
>  gcc/jit/libgccjit.h  | 117 +
>  gcc/jit/libgccjit.map|  21 ++
>  gcc/testsuite/jit.dg/all-non-failing-tests.h |  10 +
>  gcc/testsuite/jit.dg/test-reflection.c   |  89 +++
>  8 files changed, 558 insertions(+)
>  create mode 100644 gcc/testsuite/jit.dg/test-reflection.c
>
> diff --git a/gcc/jit/docs/topics/compatibility.rst 
> b/gcc/jit/docs/topics/compatibility.rst
> index 6bfa101ed71..16f24d20a75 100644
> --- a/gcc/jit/docs/topics/compatibility.rst
> +++ b/gcc/jit/docs/topics/compatibility.rst
> @@ -226,3 +226,44 @@ entrypoints:
>  
>  ``LIBGCCJIT_ABI_14`` covers the addition of
>  :func:`gcc_jit_global_set_initializer`
> +
> +.. _LIBGCCJIT_ABI_15:
> +
> +``LIBGCCJIT_ABI_15``
> +
> +``LIBGCCJIT_ABI_15`` covers the addition of reflection functions via API
> +entrypoints:
> +
> +  * :func:`gcc_jit_function_get_return_type`
> +
> +  * :func:`gcc_jit_function_get_param_count`
> +
> +  * :func:`gcc_jit_type_is_array`
> +
> +  * :func:`gcc_jit_type_is_bool`
> +
> +  * :func:`gcc_jit_type_is_int`
> +
> +  * :func:`gcc_jit_type_is_pointer`
> +
> +  * :func:`gcc_jit_type_is_struct`
> +
> +  * :func:`gcc_jit_type_is_vector`
> +
> +  * :func:`gcc_jit_type_unqualified`
> +
> +  * :func:`gcc_jit_type_is_function_ptr_type`
> +
> +  * :func:`gcc_jit_function_type_get_return_type`
> +
> +  * :func:`gcc_jit_function_type_get_param_count`
> +
> +  * :func:`gcc_jit_function_type_get_param_type`
> +
> +  * :func:`gcc_jit_vector_type_get_num_units`
> +
> +  * :func:`gcc_jit_vector_type_get_element_type`
> +
> +  * :func:`gcc_jit_struct_get_field`
> +
> +  * :func:`gcc_jit_struct_get_field_count`
> diff --git a/gcc/jit/docs/topics/functions.rst 
> b/gcc/jit/docs/topics/functions.rst
> index eb40d64010e..9819c28cda2 100644
> --- a/gcc/jit/docs/topics/functions.rst
> +++ b/gcc/jit/docs/topics/functions.rst
> @@ -171,6 +171,16 @@ Functions
> underlying string, so it is valid to pass in a pointer to an on-stack
> buffer.
>  
> +.. function::  size_t \
> +   gcc_jit_function_get_param_count (gcc_jit_function *func)
> +
> +   Get the number of parameters of the function.
> +
> +.. function::  gcc_jit_type \*
> +   gcc_jit_function_get_return_type (gcc_jit_function *func)
> +
> +   Get the return type of the function.
> +
>  Blocks
>  --
>  .. type:: gcc_jit_block
> diff --git a/gcc/jit/jit-recording.h b/gcc/jit/jit-recording.h
> index 30e37aff387..525b8bc921d 100644
> --- a/gcc/jit/jit-recording.h
> +++ b/gcc/jit/jit-recording.h
> @@ -538,7 +538,9 @@ public:
>virtual bool is_bool () const = 0;
>virtual type *is_pointer () = 0;
>virtual type *is_array () = 0;
> +  virtual struct_ *is_struct () { return NULL; }
>virtual bool is_void () const { return false; }
> +  virtual vector_type 

Re: [PATCH] libgccjit: add some reflection functions in the jit C api

2020-10-15 Thread Antoni Boucher via Gcc-patches

Hi.
I added all the functions I need in this new patch.
Please tell me if that looks good and I'll add documentation for those 
functions.

Thanks.

On Fri, Oct 02, 2020 at 04:24:26PM -0400, David Malcolm wrote:

On Fri, 2020-10-02 at 16:17 -0400, David Malcolm wrote:

On Tue, 2020-09-01 at 21:01 -0400, Antoni Boucher via Jit wrote:
> Hello.
> This WIP patch implements new reflection functions in the C API as
> mentioned in bug 96889.
> I'm looking forward for feedbacks on this patch.
> It's WIP because I'll probably add a few more reflection functions.
> Thanks.

Sorry about the belated review, looks like I missed this one.

At a high level, it seems reasonable.

Do you have a copyright assignment in place for GCC contributions?
See https://gcc.gnu.org/contribute.html

[...]


diff --git a/gcc/jit/docs/topics/compatibility.rst

> b/gcc/jit/docs/topics/compatibility.rst
> index bb3387fa583..7e786194ded 100644
> --- a/gcc/jit/docs/topics/compatibility.rst
> +++ b/gcc/jit/docs/topics/compatibility.rst
> @@ -219,3 +219,14 @@ entrypoints:
>* :func:`gcc_jit_version_minor`
>
>* :func:`gcc_jit_version_patchlevel`
> +
> +.. _LIBGCCJIT_ABI_14:
> +
> +``LIBGCCJIT_ABI_14``
> +
> +``LIBGCCJIT_ABI_14`` covers the addition of reflection functions
> via API
> +entrypoints:
> +
> +  * :func:`gcc_jit_function_get_return_type`
> +
> +  * :func:`gcc_jit_function_get_param_count`

This will now need bumping to 15; 14 covers the addition of
gcc_jit_global_set_initializer.

[...]

> +/* Public entrypoint.  See description in libgccjit.h.
> +
> +   After error-checking, the real work is done by the
> +   gcc::jit::recording::function::get_return_type method, in
> +   jit-recording.h.  */
> +
> +gcc_jit_type *
> +gcc_jit_function_get_return_type (gcc_jit_function *func)
> +{

This one is missing a:
  RETURN_NULL_IF_FAIL (func, NULL, NULL, "NULL function");


> +return (gcc_jit_type *)func->get_return_type ();
> +}

[...]

> diff --git a/gcc/jit/libgccjit.h b/gcc/jit/libgccjit.h
> index 1c5a12e9c01..6999ce25ca2 100644
> --- a/gcc/jit/libgccjit.h
> +++ b/gcc/jit/libgccjit.h

[...]

> @@ -1503,6 +1511,22 @@ gcc_jit_version_minor (void);
>  extern int
>  gcc_jit_version_patchlevel (void);
>
> +#define LIBGCCJIT_HAVE_gcc_jit_function_reflection
> +
> +/* Reflection functions to get the number of parameters and return
> types of
> +   a function from the C API.

"return type", is better grammar, I think, given that "function" is
singular.

> +
> +   "vec_type" should be a vector type, created using
> gcc_jit_type_get_vector.

This line about "vec_type" seems to be a leftover from a copy


> +   This API entrypoint was added in LIBGCCJIT_ABI_14; you can test
> for its
> +   presence using
> + #ifdef LIBGCCJIT_HAVE_gcc_jit_function_reflection

Version number will need bumping, as mentioned above.

[...]

> diff --git a/gcc/jit/libgccjit.map b/gcc/jit/libgccjit.map
> index 6137dd4b4b0..b28f81a7a32 100644
> --- a/gcc/jit/libgccjit.map
> +++ b/gcc/jit/libgccjit.map
> @@ -186,4 +186,10 @@ LIBGCCJIT_ABI_13 {
>  gcc_jit_version_major;
>  gcc_jit_version_minor;
>  gcc_jit_version_patchlevel;
> -} LIBGCCJIT_ABI_12;
> \ No newline at end of file
> +} LIBGCCJIT_ABI_12;
> +
> +LIBGCCJIT_ABI_14 {
> +  global:
> +gcc_jit_function_get_return_type;
> +gcc_jit_function_get_param_count;
> +} LIBGCCJIT_ABI_13;

Likewise.

[...]

Otherwise looks good to me.

Bonus points for adding C++ bindings (and docs for them), but I don't
know of anyone using the C++ bindings.



Also, please add "PR jit/96889" to the ChangeLog entries, and [PR96889]
to the subject line.

Dave

>From b0edc9eb8e8d3ba9e1c6a8d061a8627c0b0cf102 Mon Sep 17 00:00:00 2001
From: Antoni Boucher 
Date: Sat, 1 Aug 2020 17:52:17 -0400
Subject: [PATCH] This patch add some reflection functions in the jit C api
 [PR96889]

2020-09-1  Antoni Boucher  

gcc/jit/
PR target/96889
* docs/topics/compatibility.rst (LIBGCCJIT_ABI_14): New ABI tag.
* docs/topics/functions.rst: Add documentation for the
functions gcc_jit_function_get_return_type and
gcc_jit_function_get_param_count
* libgccjit.c: New functions:
  * gcc_jit_function_get_return_type;
  * gcc_jit_function_get_param_count;
  * gcc_jit_function_type_get_return_type;
  * gcc_jit_function_type_get_param_count;
  * gcc_jit_function_type_get_param_type;
  * gcc_jit_type_unqualified;
  * gcc_jit_type_is_array;
  * gcc_jit_type_is_bool;
  * gcc_jit_type_is_function_ptr_type;
  * gcc_jit_type_is_int;
  * gcc_jit_type_is_pointer;
  * gcc_jit_type_is_vector;
  * gcc_jit_vector_type_get_element_type;
  * gcc_jit_vector_type_get_num_units;
  * gcc_jit_struct_get_field;
  * gcc_jit_type_is_struct;
  * 

Re: [PATCH] IPA: compare VRP types.

2020-10-15 Thread Richard Biener via Gcc-patches
On October 15, 2020 5:04:11 PM GMT+02:00, "Martin Liška"  wrote:
>Hello.
>
>As mentioned in the PR, since 74ca1c01d02e548f32aa26f9a887dcc0730703fb
>we wrongly
>merge a pair of VRP ranges with a different TREE_TYPE (in the PR one is
>char and second
>one is short). Then we merge 2 ranges and make an anti-range and bad
>things happen.
>
>Patch can bootstrap on x86_64-linux-gnu and survives regression tests.
>
>Ready to be installed?

One check should suffice. Min ant max of a range should have compatible types. 

>Thanks,
>Martin
>
>gcc/ChangeLog:
>
>   PR ipa/97404
>   * ipa-prop.c (struct ipa_vr_ggc_hash_traits):
>   Compare types of VRP min and max as we can merge ranges of
>   different types.
>
>gcc/testsuite/ChangeLog:
>
>   PR ipa/97404
>   * gcc.c-torture/execute/pr97404.c: New test.
>---
>  gcc/ipa-prop.c|  6 +++-
> gcc/testsuite/gcc.c-torture/execute/pr97404.c | 28 +++
>  2 files changed, 33 insertions(+), 1 deletion(-)
>  create mode 100644 gcc/testsuite/gcc.c-torture/execute/pr97404.c
>
>diff --git a/gcc/ipa-prop.c b/gcc/ipa-prop.c
>index 63c652f4ffc..3d0ebefa4aa 100644
>--- a/gcc/ipa-prop.c
>+++ b/gcc/ipa-prop.c
>@@ -123,7 +123,11 @@ struct ipa_vr_ggc_hash_traits : public
>ggc_cache_remove 
>static bool
>equal (const value_range *a, const value_range *b)
>  {
>-  return a->equal_p (*b);
>+  return (a->equal_p (*b)
>+&& types_compatible_p (TREE_TYPE (a->min ()),
>+   TREE_TYPE (b->min ()))
>+&& types_compatible_p (TREE_TYPE (a->max ()),
>+   TREE_TYPE (b->max (;
>  }
>static const bool empty_zero_p = true;
>static void
>diff --git a/gcc/testsuite/gcc.c-torture/execute/pr97404.c
>b/gcc/testsuite/gcc.c-torture/execute/pr97404.c
>new file mode 100644
>index 000..7e5ce231725
>--- /dev/null
>+++ b/gcc/testsuite/gcc.c-torture/execute/pr97404.c
>@@ -0,0 +1,28 @@
>+/* PR ipa/97404 */
>+/* { dg-additional-options "-fno-inline" } */
>+
>+char a, b;
>+long c;
>+short d, e;
>+long *f = 
>+int g;
>+char h(signed char i) { return 0; }
>+static short j(short i, int k) { return i < 0 ? 0 : i >> k; }
>+void l(void);
>+void m(void)
>+{
>+  e = j(d | 9766, 11);
>+*f = e;
>+}
>+void l(void)
>+{
>+  a = 5 | g;
>+b = h(a);
>+}
>+int main()
>+{
>+  m();
>+  if (c != 4)
>+__builtin_abort();
>+  return 0;
>+}



Re: [PATCH] c++: Improve printing of pointers-to-members [PR97406, PR85901]

2020-10-15 Thread Jason Merrill via Gcc-patches

On 10/14/20 3:52 PM, Marek Polacek wrote:

This PR points out that when printing the parameter mapping for a
pointer-to-member-function, the output was truncated:

   [with T = void (X::*]

Fixed by printing the abstract declarator for pointers-to-members in
cxx_pretty_printer::type_id.  So now we print:

   [with T = void (X::*)()]

But when I tried a pointer-to-data-member, I got

   [with T = ‘offset_type’ not supported by simple_type_specifier)‘offset_type’ 
not supported by direct_abstract_declarator]

so had to fix that too so that we now print:

   [with T = int X::*]

or

   [with T = int (X::*)[5]]

when the type is an array type.  Which is what PR85901 was about.

Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?


OK.


gcc/cp/ChangeLog:

PR c++/97406
PR c++/85901
* cxx-pretty-print.c (pp_cxx_type_specifier_seq): Handle OFFSET_TYPE.
(cxx_pretty_printer::abstract_declarator): Fix the printing of ')'.
(cxx_pretty_printer::direct_abstract_declarator): Handle OFFSET_TYPE.
(cxx_pretty_printer::type_id): Likewise.  Print the abstract declarator
for pointers-to-members.

gcc/testsuite/ChangeLog:

PR c++/97406
PR c++/85901
* g++.dg/diagnostic/ptrtomem1.C: New test.
* g++.dg/diagnostic/ptrtomem2.C: New test.
---
  gcc/cp/cxx-pretty-print.c   | 33 -
  gcc/testsuite/g++.dg/diagnostic/ptrtomem1.C | 31 +++
  gcc/testsuite/g++.dg/diagnostic/ptrtomem2.C | 14 +
  3 files changed, 77 insertions(+), 1 deletion(-)
  create mode 100644 gcc/testsuite/g++.dg/diagnostic/ptrtomem1.C
  create mode 100644 gcc/testsuite/g++.dg/diagnostic/ptrtomem2.C

diff --git a/gcc/cp/cxx-pretty-print.c b/gcc/cp/cxx-pretty-print.c
index 8bea79b93a2..058b9c2f4fc 100644
--- a/gcc/cp/cxx-pretty-print.c
+++ b/gcc/cp/cxx-pretty-print.c
@@ -1420,6 +1420,16 @@ pp_cxx_type_specifier_seq (cxx_pretty_printer *pp, tree 
t)
}
/* fall through */
  
+case OFFSET_TYPE:

+  if (TYPE_PTRDATAMEM_P (t))
+   {
+ pp_cxx_type_specifier_seq (pp, TREE_TYPE (t));
+ pp_cxx_whitespace (pp);
+ pp_cxx_ptr_operator (pp, t);
+ break;
+   }
+  /* fall through */
+
  default:
if (!(TREE_CODE (t) == FUNCTION_DECL && DECL_CONSTRUCTOR_P (t)))
pp_c_specifier_qualifier_list (pp, t);
@@ -1753,7 +1763,20 @@ pp_cxx_function_definition (cxx_pretty_printer *pp, tree 
t)
  void
  cxx_pretty_printer::abstract_declarator (tree t)
  {
-  if (TYPE_PTRMEM_P (t))
+  /* pp_cxx_ptr_operator prints '(' for a pointer-to-member function,
+ or a pointer-to-data-member of array type:
+
+   void (X::*)()
+   int (X::*)[5]
+
+ but not for a pointer-to-data-member of non-array type:
+
+   int X::*
+
+ so be mindful of that.  */
+  if (TYPE_PTRMEMFUNC_P (t)
+  || (TYPE_PTRDATAMEM_P (t)
+ && TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE))
  pp_cxx_right_paren (this);
else if (INDIRECT_TYPE_P (t))
  {
@@ -1785,6 +1808,11 @@ cxx_pretty_printer::direct_abstract_declarator (tree t)
direct_abstract_declarator (TYPE_PTRMEMFUNC_FN_TYPE (t));
break;
  
+case OFFSET_TYPE:

+  if (TYPE_PTRDATAMEM_P (t))
+   direct_abstract_declarator (TREE_TYPE (t));
+  break;
+
  case METHOD_TYPE:
  case FUNCTION_TYPE:
pp_cxx_parameter_declaration_clause (this, t);
@@ -1837,7 +1865,10 @@ cxx_pretty_printer::type_id (tree t)
  case UNDERLYING_TYPE:
  case DECLTYPE_TYPE:
  case TEMPLATE_ID_EXPR:
+case OFFSET_TYPE:
pp_cxx_type_specifier_seq (this, t);
+  if (TYPE_PTRMEM_P (t))
+   abstract_declarator (t);
break;
  
  case TYPE_PACK_EXPANSION:

diff --git a/gcc/testsuite/g++.dg/diagnostic/ptrtomem1.C 
b/gcc/testsuite/g++.dg/diagnostic/ptrtomem1.C
new file mode 100644
index 000..bb1327f7af1
--- /dev/null
+++ b/gcc/testsuite/g++.dg/diagnostic/ptrtomem1.C
@@ -0,0 +1,31 @@
+// PR c++/97406
+// { dg-do compile { target c++20 } }
+
+struct X {
+  void f() { }
+  int a;
+  int arr[5];
+};
+
+// Duplicated so that I can check dg-message.
+template
+requires (sizeof(T)==1) // { dg-message {\[with T = void \(X::\*\)\(\)\]} }
+void f1(T)
+{ }
+
+template
+requires (sizeof(T)==1) // { dg-message {\[with T = int X::\*\]} }
+void f2(T)
+{ }
+
+template
+requires (sizeof(T)==1) // dg-message {\[with T = int \(X::\*\)\[5\]\]} }
+void f3(T)
+{ }
+
+int main()
+{
+  f1(::f); // { dg-error "no matching function for call" }
+  f2(::a); // { dg-error "no matching function for call" }
+  f3(::arr); // { dg-error "no matching function for call" }
+}
diff --git a/gcc/testsuite/g++.dg/diagnostic/ptrtomem2.C 
b/gcc/testsuite/g++.dg/diagnostic/ptrtomem2.C
new file mode 100644
index 000..f3b29a07a99
--- /dev/null
+++ b/gcc/testsuite/g++.dg/diagnostic/ptrtomem2.C
@@ -0,0 +1,14 @@
+// PR c++/85901
+// { dg-do compile { target c++11 } }
+
+template struct A;
+

[PING][PATCH][omp, simt] Handle alternative IV

2020-10-15 Thread Tom de Vries
On 10/2/20 3:21 PM, Tom de Vries wrote:
> Hi,
> 
> Consider the test-case libgomp.c/pr81778.c added in this commit, with
> this core loop (note: CANARY_SIZE set to 0 for simplicity):
> ...
>   int s = 1;
>   #pragma omp target simd
>   for (int i = N - 1; i > -1; i -= s)
> a[i] = 1;
> ...
> which, given that N is 32, sets a[0..31] to 1.
> 
> After omp-expand, this looks like:
> ...
>:
>   simduid.7 = .GOMP_SIMT_ENTER (simduid.7);
>   .omp_simt.8 = .GOMP_SIMT_ENTER_ALLOC (simduid.7);
>   D.3193 = -s;
>   s.9 = s;
>   D.3204 = .GOMP_SIMT_LANE ();
>   D.3205 = -s.9;
>   D.3206 = (int) D.3204;
>   D.3207 = D.3205 * D.3206;
>   i = D.3207 + 31;
>   D.3209 = 0;
>   D.3210 = -s.9;
>   D.3211 = D.3210 - i;
>   D.3210 = -s.9;
>   D.3212 = D.3211 / D.3210;
>   D.3213 = (unsigned int) D.3212;
>   D.3213 = i >= 0 ? D.3213 : 0;
> 
>:
>   if (D.3209 < D.3213)
> goto ; [87.50%]
>   else
> goto ; [12.50%]
> 
>:
>   a[i] = 1;
>   D.3215 = -s.9;
>   D.3219 = .GOMP_SIMT_VF ();
>   D.3216 = (int) D.3219;
>   D.3220 = D.3215 * D.3216;
>   i = D.3220 + i;
>   D.3209 = D.3209 + 1;
>   goto ; [100.00%]
> ...
> 
> On nvptx, the first time bb6 is executed, i is in the 0..31 range (depending
> on the lane that is executing) at bb entry.
> 
> So we have the following sequence:
> - a[0..31] is set to 1
> - i is updated to -32..-1
> - D.3209 is updated to 1 (being 0 initially)
> - bb19 is executed, and if condition (D.3209 < D.3213) == (1 < 32) evaluates
>   to true
> - bb6 is once more executed, which should not happen because all the elements
>   that needed to be handled were already handled.
> - consequently, elements that should not be written are written
> - with CANARY_SIZE == 0, we may run into a libgomp error:
>   ...
>   libgomp: cuCtxSynchronize error: an illegal memory access was encountered
>   ...
>   and with CANARY_SIZE unmodified, we run into:
>   ...
>   Expected 0, got 1 at base[-961]
>   Aborted (core dumped)
>   ...
> 
> The cause of this is as follows:
> - because the step s is a variable rather than a constant, an alternative
>   IV (D.3209 in our example) is generated in expand_omp_simd, and the
>   loop condition is tested in terms of the alternative IV rather than
>   the original IV (i in our example).
> - the SIMT code in expand_omp_simd works by modifying step and initial value.
> - The initial value fd->loop.n1 is loaded into a variable n1, which is
>   modified by the SIMT code and then used there-after.
> - The step fd->loop.step is loaded into a variable step, which is is modified
>   by the SIMT code, but afterwards there are uses of both step and
>   fd->loop.step.
> - There are uses of fd->loop.step in the alternative IV handling code,
>   which should use step instead.
> 
> Fix this by introducing an additional variable orig_step, which is not
> modified by the SIMT code and replacing all remaining uses of fd->loop.step
> by either step or orig_step.
> 
> Build on x86_64-linux with nvptx accelerator, tested libgomp.
> 
> This fixes for-5.c and for-6.c FAILs I'm currently seeing on a quadro m1200
> with driver 450.66.
> 
> OK for trunk?
> 

Ping.

Thanks,
- Tom

> [omp, simt] Handle alternative IV
> 
> gcc/ChangeLog:
> 
> 2020-10-02  Tom de Vries  
> 
>   * omp-expand.c (expand_omp_simd): Add step_orig, and replace uses of
>   fd->loop.step by either step or orig_step.
> 
> libgomp/ChangeLog:
> 
> 2020-10-02  Tom de Vries  
> 
>   * testsuite/libgomp.c/pr81778.c: New test.
> 
> ---
>  gcc/omp-expand.c  | 11 
>  libgomp/testsuite/libgomp.c/pr81778.c | 48 
> +++
>  2 files changed, 54 insertions(+), 5 deletions(-)
> 
> diff --git a/gcc/omp-expand.c b/gcc/omp-expand.c
> index 99cb4f9dda4..80e35ac0294 100644
> --- a/gcc/omp-expand.c
> +++ b/gcc/omp-expand.c
> @@ -6307,6 +6307,7 @@ expand_omp_simd (struct omp_region *region, struct 
> omp_for_data *fd)
>n2 = OMP_CLAUSE_DECL (innerc);
>  }
>tree step = fd->loop.step;
> +  tree orig_step = step; /* May be different from step if is_simt.  */
>  
>bool is_simt = omp_find_clause (gimple_omp_for_clauses (fd->for_stmt),
> OMP_CLAUSE__SIMT_);
> @@ -6455,7 +6456,7 @@ expand_omp_simd (struct omp_region *region, struct 
> omp_for_data *fd)
>tree altv = NULL_TREE, altn2 = NULL_TREE;
>if (fd->collapse == 1
>&& !broken_loop
> -  && TREE_CODE (fd->loops[0].step) != INTEGER_CST)
> +  && TREE_CODE (orig_step) != INTEGER_CST)
>  {
>/* The vectorizer currently punts on loops with non-constant steps
>for the main IV (can't compute number of iterations and gives up
> @@ -6471,7 +6472,7 @@ expand_omp_simd (struct omp_region *region, struct 
> omp_for_data *fd)
>   itype = signed_type_for (itype);
>t = build_int_cst (itype, (fd->loop.cond_code == LT_EXPR ? -1 : 1));
>t = fold_build2 (PLUS_EXPR, itype,
> -fold_convert (itype, fd->loop.step), t);
> +  

[PATCH] IPA: compare VRP types.

2020-10-15 Thread Martin Liška

Hello.

As mentioned in the PR, since 74ca1c01d02e548f32aa26f9a887dcc0730703fb we 
wrongly
merge a pair of VRP ranges with a different TREE_TYPE (in the PR one is char 
and second
one is short). Then we merge 2 ranges and make an anti-range and bad things 
happen.

Patch can bootstrap on x86_64-linux-gnu and survives regression tests.

Ready to be installed?
Thanks,
Martin

gcc/ChangeLog:

PR ipa/97404
* ipa-prop.c (struct ipa_vr_ggc_hash_traits):
Compare types of VRP min and max as we can merge ranges of
different types.

gcc/testsuite/ChangeLog:

PR ipa/97404
* gcc.c-torture/execute/pr97404.c: New test.
---
 gcc/ipa-prop.c|  6 +++-
 gcc/testsuite/gcc.c-torture/execute/pr97404.c | 28 +++
 2 files changed, 33 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gcc.c-torture/execute/pr97404.c

diff --git a/gcc/ipa-prop.c b/gcc/ipa-prop.c
index 63c652f4ffc..3d0ebefa4aa 100644
--- a/gcc/ipa-prop.c
+++ b/gcc/ipa-prop.c
@@ -123,7 +123,11 @@ struct ipa_vr_ggc_hash_traits : public ggc_cache_remove 

   static bool
   equal (const value_range *a, const value_range *b)
 {
-  return a->equal_p (*b);
+  return (a->equal_p (*b)
+ && types_compatible_p (TREE_TYPE (a->min ()),
+TREE_TYPE (b->min ()))
+ && types_compatible_p (TREE_TYPE (a->max ()),
+TREE_TYPE (b->max (;
 }
   static const bool empty_zero_p = true;
   static void
diff --git a/gcc/testsuite/gcc.c-torture/execute/pr97404.c 
b/gcc/testsuite/gcc.c-torture/execute/pr97404.c
new file mode 100644
index 000..7e5ce231725
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/execute/pr97404.c
@@ -0,0 +1,28 @@
+/* PR ipa/97404 */
+/* { dg-additional-options "-fno-inline" } */
+
+char a, b;
+long c;
+short d, e;
+long *f = 
+int g;
+char h(signed char i) { return 0; }
+static short j(short i, int k) { return i < 0 ? 0 : i >> k; }
+void l(void);
+void m(void)
+{
+  e = j(d | 9766, 11);
+*f = e;
+}
+void l(void)
+{
+  a = 5 | g;
+b = h(a);
+}
+int main()
+{
+  m();
+  if (c != 4)
+__builtin_abort();
+  return 0;
+}
--
2.28.0



[PATCH] aarch64: Add bfloat16 vldN_lane_bf16 + vldNq_lane_bf16 intrisics

2020-10-15 Thread Andrea Corallo via Gcc-patches
Hi all,

I'd like to submit the following patch implementing the bfloat16_t
neon related load intrinsics: vld2_lane_bf16, vld2q_lane_bf16,
vld3_lane_bf16, vld3q_lane_bf16 vld4_lane_bf16, vld4q_lane_bf16.

Please see refer to:
ACLE 
ISA  

Regtested and bootstrapped.

Thanks!

  Andrea

>From 1d50cba9d3751b80ea416264d21645d890472ced Mon Sep 17 00:00:00 2001
From: Andrea Corallo 
Date: Thu, 15 Oct 2020 10:16:18 +0200
Subject: [PATCH] aarch64: Add bfloat16 vldN_lane_bf16 + vldNq_lane_bf16
 intrisics

gcc/ChangeLog

2020-10-15  Andrea Corallo  

* config/aarch64/arm_neon.h (__LDX_LANE_FUNC): Move to the bottom
of the file so we can use these also for defining the bf16 related
intrinsics.
(vld2_lane_bf16, vld2q_lane_bf16, vld3_lane_bf16, vld3q_lane_bf16)
(vld4_lane_bf16, vld4q_lane_bf16): Add new intrinsics.

gcc/testsuite/ChangeLog

2020-10-15  Andrea Corallo  

* gcc.target/aarch64/advsimd-intrinsics/bf16_vldN_lane_1.c: New
testcase.
* gcc.target/aarch64/advsimd-intrinsics/bf16_vldN_lane_2.c:
Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vld2_lane_bf16_indices_1.c:
Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vld2q_lane_bf16_indices_1.c:
Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vld3_lane_bf16_indices_1.c:
Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vld3q_lane_bf16_indices_1.c:
Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vld4_lane_bf16_indices_1.c:
Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vld4q_lane_bf16_indices_1.c:
Likewise.
---
 gcc/config/aarch64/arm_neon.h | 792 +-
 .../advsimd-intrinsics/bf16_vldN_lane_1.c |  74 ++
 .../advsimd-intrinsics/bf16_vldN_lane_2.c |  52 ++
 .../vld2_lane_bf16_indices_1.c|  17 +
 .../vld2q_lane_bf16_indices_1.c   |  17 +
 .../vld3_lane_bf16_indices_1.c|  17 +
 .../vld3q_lane_bf16_indices_1.c   |  17 +
 .../vld4_lane_bf16_indices_1.c|  17 +
 .../vld4q_lane_bf16_indices_1.c   |  17 +
 9 files changed, 629 insertions(+), 391 deletions(-)
 create mode 100644 
gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/bf16_vldN_lane_1.c
 create mode 100644 
gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/bf16_vldN_lane_2.c
 create mode 100644 
gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/vld2_lane_bf16_indices_1.c
 create mode 100644 
gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/vld2q_lane_bf16_indices_1.c
 create mode 100644 
gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/vld3_lane_bf16_indices_1.c
 create mode 100644 
gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/vld3q_lane_bf16_indices_1.c
 create mode 100644 
gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/vld4_lane_bf16_indices_1.c
 create mode 100644 
gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/vld4q_lane_bf16_indices_1.c

diff --git a/gcc/config/aarch64/arm_neon.h b/gcc/config/aarch64/arm_neon.h
index d943f63a274..2bb20e15069 100644
--- a/gcc/config/aarch64/arm_neon.h
+++ b/gcc/config/aarch64/arm_neon.h
@@ -20792,311 +20792,6 @@ vld4q_dup_p64 (const poly64_t * __a)
   return ret;
 }
 
-/* vld2_lane */
-
-#define __LD2_LANE_FUNC(intype, vectype, largetype, ptrtype, mode,\
-qmode, ptrmode, funcsuffix, signedtype)   \
-__extension__ extern __inline intype \
-__attribute__ ((__always_inline__, __gnu_inline__,__artificial__)) \
-vld2_lane_##funcsuffix (const ptrtype * __ptr, intype __b, const int __c)  \
-{ \
-  __builtin_aarch64_simd_oi __o;  \
-  largetype __temp;   \
-  __temp.val[0] = \
-vcombine_##funcsuffix (__b.val[0], vcreate_##funcsuffix (0)); \
-  __temp.val[1] = \
-vcombine_##funcsuffix (__b.val[1], vcreate_##funcsuffix (0)); \
-  __o = __builtin_aarch64_set_qregoi##qmode (__o, \
-   (signedtype) __temp.val[0],\
-   0);\
-  __o = __builtin_aarch64_set_qregoi##qmode (__o, \
-   (signedtype) __temp.val[1],\
-   1);\
-  __o =__builtin_aarch64_ld2_lane##mode (  
   \
- (__builtin_aarch64_simd_##ptrmode *) __ptr, __o, __c);   \
-  __b.val[0] = (vectype) __builtin_aarch64_get_dregoidi (__o, 0); \
-  __b.val[1] = 

Re: [PATCH] MIPS/libphobos: Fix switchcontext.S assembly for MIPS I ISA

2020-10-15 Thread Maciej W. Rozycki
On Tue, 13 Oct 2020, Richard Biener wrote:

> >  Jakub, Richard: I should have cc-ed you for the backports to GCC 8/9/10.  
> > OK to backport as a fatal build failure fix, or shall we leave this as it 
> > stands?  FAOD the L.D and S.D assembly instructions have been supported in 
> > binutils as long as the MIPS port has, i.e. from:
> > 
> > commit 45b1470513cfef2af6fd5532d33a54a840b4600a
> > Author: Ian Lance Taylor 
> > Date:   Wed Aug 18 19:40:37 1993 +
> 
> Sure.

 Thanks, backported to GCC 10 & 9.  There has been no libphobos or the D 
frontend in GCC 8, so no backport needed there.

  Maciej


[PATCH] libstdc++: Add c++2a

2020-10-15 Thread Thomas Rodgers
From: Thomas Rodgers 

* Note: depends on a sufficiently C++20ified basic_stringbuf<>.

libstdc++/Changelog:
libstdc++-v3/include/Makefile.am (std_headers): Add new header.
libstdc++-v3/include/Makefile.in: Regenerate.
libstdc++-v3/include/std/streambuf
(__detail::__streambuf_core_access): Define.
(basic_streambuf): Befriend __detail::__streambuf_core_access.
libstdc++-v3/include/std/syncstream: New header.
libstdc++-v3/include/std/version: Add __cpp_lib_syncbuf:
libstdc++-v3/testsuite/27_io/basic_syncbuf/1.cc: New test.
libstdc++-v3/testsuite/27_io/basic_syncbuf/2.cc: Likewise.
libstdc++-v3/testsuite/27_io/basic_syncbuf/basic_ops/1.cc:
Likewise.
libstdc++-v3/testsuite/27_io/basic_syncbuf/requirements/types.cc:
Likewise.
libstdc++-v3/testsuite/27_io/basic_syncbuf/sync_ops/1.cc:
Likewise.
libstdc++-v3/testsuite/27_io/basic_syncstream/1.cc: Likewise.
libstdc++-v3/testsuite/27_io/basic_syncstream/2.cc: Likewise.
libstdc++-v3/testsuite/27_io/basic_syncstream/basic_ops/1.cc:
Likewise.
libstdc++-v3/testsuite/27_io/basic_syncstream/requirements/types.cc:
Likewise.

---
 libstdc++-v3/include/Makefile.am  |   1 +
 libstdc++-v3/include/Makefile.in  |   1 +
 libstdc++-v3/include/std/streambuf|  81 +
 libstdc++-v3/include/std/syncstream   | 333 ++
 libstdc++-v3/include/std/version  |   4 +
 .../testsuite/27_io/basic_syncbuf/1.cc|  28 ++
 .../testsuite/27_io/basic_syncbuf/2.cc|  27 ++
 .../27_io/basic_syncbuf/basic_ops/1.cc| 138 
 .../27_io/basic_syncbuf/requirements/types.cc |  42 +++
 .../27_io/basic_syncbuf/sync_ops/1.cc | 130 +++
 .../testsuite/27_io/basic_syncstream/1.cc |  28 ++
 .../testsuite/27_io/basic_syncstream/2.cc |  27 ++
 .../27_io/basic_syncstream/basic_ops/1.cc | 135 +++
 .../basic_syncstream/requirements/types.cc|  43 +++
 14 files changed, 1018 insertions(+)
 create mode 100644 libstdc++-v3/include/std/syncstream
 create mode 100644 libstdc++-v3/testsuite/27_io/basic_syncbuf/1.cc
 create mode 100644 libstdc++-v3/testsuite/27_io/basic_syncbuf/2.cc
 create mode 100644 libstdc++-v3/testsuite/27_io/basic_syncbuf/basic_ops/1.cc
 create mode 100644 
libstdc++-v3/testsuite/27_io/basic_syncbuf/requirements/types.cc
 create mode 100644 libstdc++-v3/testsuite/27_io/basic_syncbuf/sync_ops/1.cc
 create mode 100644 libstdc++-v3/testsuite/27_io/basic_syncstream/1.cc
 create mode 100644 libstdc++-v3/testsuite/27_io/basic_syncstream/2.cc
 create mode 100644 libstdc++-v3/testsuite/27_io/basic_syncstream/basic_ops/1.cc
 create mode 100644 
libstdc++-v3/testsuite/27_io/basic_syncstream/requirements/types.cc

diff --git a/libstdc++-v3/include/Makefile.am b/libstdc++-v3/include/Makefile.am
index 28d273924ee..61aaff7a2f4 100644
--- a/libstdc++-v3/include/Makefile.am
+++ b/libstdc++-v3/include/Makefile.am
@@ -73,6 +73,7 @@ std_headers = \
${std_srcdir}/shared_mutex \
${std_srcdir}/span \
${std_srcdir}/sstream \
+   ${std_srcdir}/syncstream \
${std_srcdir}/stack \
${std_srcdir}/stdexcept \
${std_srcdir}/stop_token \
diff --git a/libstdc++-v3/include/std/streambuf 
b/libstdc++-v3/include/std/streambuf
index cae35e75bda..d6053e4c1ed 100644
--- a/libstdc++-v3/include/std/streambuf
+++ b/libstdc++-v3/include/std/streambuf
@@ -48,6 +48,84 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
 #define _IsUnused __attribute__ ((__unused__))
 
+  template
+class basic_streambuf;
+
+#if __cplusplus > 201703L
+  namespace __detail
+  {
+struct __streambuf_core_access
+{
+  template
+   static void
+   _S_imbue(basic_streambuf<_CharT, _Traits>& __b, const locale& __loc)
+   { __b.imbue(__loc); }
+
+  template
+   static basic_streambuf<_CharT, _Traits>*
+   _S_setbuf(basic_streambuf<_CharT, _Traits>& __b,
+ _CharT* __c, streamsize __n)
+   { return __b.setbuf(__c, __n); }
+
+  template
+   static typename _Traits::pos_type
+   _S_seekoff(basic_streambuf<_CharT, _Traits>& __b,
+  typename _Traits::off_type __off, ios_base::seekdir __dir,
+  ios_base::openmode __mode)
+ { return __b.seekoff(__off, __dir, __mode); }
+
+  template
+   static typename _Traits::pos_type
+   _S_seekpos(basic_streambuf<_CharT, _Traits>& __b,
+  typename _Traits::pos_type __pos, ios_base::openmode __mode)
+   { return __b.seekpos(__pos, __mode); }
+
+  template
+   static int
+   _S_sync(basic_streambuf<_CharT, _Traits>& __b)
+   { return __b.sync(); }
+
+  template
+   static streamsize
+   _S_showmanyc(basic_streambuf<_CharT, _Traits>& __b)
+   { return __b.showmanyc(); }
+
+  template
+   static streamsize
+   

[committed][nvptx, testsuite] Xfail stack atomics

2020-10-15 Thread Tom de Vries
Hi,

Nvptx currently doesn't support atomics if it involves a stack address.
PR97444 is open about.

Xfail corresponding execution fails in gcc.dg/atomic.  Tested on nvptx.

Committed to trunk.

Thanks,
- Tom

[nvptx, testsuite] Xfail stack atomics

gcc/testsuite/ChangeLog:

2020-10-15  Tom de Vries  

* gcc.dg/atomic/c11-atomic-exec-6.c: Xfail execution for nvptx.
* gcc.dg/atomic/c11-atomic-exec-7.c: Same.
* gcc.dg/atomic/stdatomic-op-5.c: Same.

---
 gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-6.c | 1 +
 gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-7.c | 1 +
 gcc/testsuite/gcc.dg/atomic/stdatomic-op-5.c| 1 +
 3 files changed, 3 insertions(+)

diff --git a/gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-6.c 
b/gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-6.c
index 2dc91c510ba..900559b81b9 100644
--- a/gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-6.c
+++ b/gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-6.c
@@ -3,6 +3,7 @@
still occurs.  */
 /* { dg-do run } */
 /* { dg-options "-std=c11 -pedantic-errors" } */
+/* { dg-xfail-run-if "PR97444: stack atomics" { nvptx*-*-* } }*/
 
 #define TEST_POINTER_ADD_SUB(TYPE) \
   do   \
diff --git a/gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-7.c 
b/gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-7.c
index eb7082d8d33..d83f186 100644
--- a/gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-7.c
+++ b/gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-7.c
@@ -2,6 +2,7 @@
we generate correct code.  */
 /* { dg-do run } */
 /* { dg-options "-std=c11 -pedantic-errors -fdump-tree-original" } */
+/* { dg-xfail-run-if "PR97444: stack atomics" { nvptx*-*-* } }*/
 
 #include 
 #include 
diff --git a/gcc/testsuite/gcc.dg/atomic/stdatomic-op-5.c 
b/gcc/testsuite/gcc.dg/atomic/stdatomic-op-5.c
index daba8ec3513..f0e8581fda9 100644
--- a/gcc/testsuite/gcc.dg/atomic/stdatomic-op-5.c
+++ b/gcc/testsuite/gcc.dg/atomic/stdatomic-op-5.c
@@ -2,6 +2,7 @@
we generate correct code.  */
 /* { dg-do run } */
 /* { dg-options "-std=c11 -pedantic-errors -fdump-tree-original" } */
+/* { dg-xfail-run-if "PR97444: stack atomics" { nvptx*-*-* } }*/
 
 #include 
 


Re: [PATCH] Fix ICE in vectorizable_live_operation

2020-10-15 Thread Richard Biener
On Thu, 15 Oct 2020, Jeff Law wrote:

> 
> On 10/15/20 3:49 AM, Richard Biener wrote:
> > This fixes the case where the insertion iterator for the live stmt
> > is the end of a BB by adjusting the dominance query to the definition
> > of the def we're substituting.
> >
> > Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed.
> >
> > 2020-10-15  Richard Biener  
> >
> > * tree-vect-loop.c (vectorizable_live_operation): Adjust
> > dominance query.
> >
> > * gcc.dg/vect/bb-slp-52.c: New testcase.
> 
> Assuming this is a fix for the issue I sent privately last night.?

Yes.

> Thanks a ton!
> 
> 
> Jeff
> 
> 
> 

-- 
Richard Biener 
SUSE Software Solutions Germany GmbH, Maxfeldstrasse 5, 90409 Nuernberg,
Germany; GF: Felix Imend


[committed][nvptx] Remove -m32

2020-10-15 Thread Tom de Vries
Hi,

The nvptx port has an -m32 option, but it's not clear whether this
was ever build/tested/used.

Don't expose to user anymore.  Tested on nvptx.

Committed to trunk.

Thanks,
- Tom

[nvptx] Remove -m32

gcc/ChangeLog:

2020-10-15  Tom de Vries  

PR target/97436
* config/nvptx/nvptx.opt (m32): Comment out.
* doc/invoke.texi (NVPTX options): Remove -m32.

gcc/testsuite/ChangeLog:

2020-10-15  Tom de Vries  

PR target/97436
* gcc.target/nvptx/atomic_fetch-3.c: Remove.

---
 gcc/config/nvptx/nvptx.opt  |  8 +---
 gcc/doc/invoke.texi |  7 +++
 gcc/testsuite/gcc.target/nvptx/atomic_fetch-3.c | 24 
 3 files changed, 8 insertions(+), 31 deletions(-)

diff --git a/gcc/config/nvptx/nvptx.opt b/gcc/config/nvptx/nvptx.opt
index 38454222d42..045e3548f2d 100644
--- a/gcc/config/nvptx/nvptx.opt
+++ b/gcc/config/nvptx/nvptx.opt
@@ -17,9 +17,11 @@
 ; along with GCC; see the file COPYING3.  If not see
 ; .
 
-m32
-Target Report RejectNegative InverseMask(ABI64)
-Generate code for a 32-bit ABI.
+; It's not clear whether this was ever build/tested/used, so this is no longer
+; exposed to the user.
+;m32
+;Target Report RejectNegative InverseMask(ABI64)
+;Generate code for a 32-bit ABI.
 
 m64
 Target Report RejectNegative Mask(ABI64)
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 289d81614b2..631a119181c 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -1109,7 +1109,7 @@ Objective-C and Objective-C++ Dialects}.
 -march=@var{arch}  -mbmx  -mno-bmx  -mcdx  -mno-cdx}
 
 @emph{Nvidia PTX Options}
-@gccoptlist{-m32  -m64  -mmainkernel  -moptimize}
+@gccoptlist{-m64  -mmainkernel  -moptimize}
 
 @emph{OpenRISC Options}
 @gccoptlist{-mboard=@var{name}  -mnewlib  -mhard-mul  -mhard-div @gol
@@ -25614,11 +25614,10 @@ These options are defined for Nvidia PTX:
 
 @table @gcctabopt
 
-@item -m32
 @itemx -m64
-@opindex m32
 @opindex m64
-Generate code for 32-bit or 64-bit ABI.
+Ignored, but preserved for backward compatibility.  Only 64-bit ABI is
+supported.
 
 @item -misa=@var{ISA-string}
 @opindex march
diff --git a/gcc/testsuite/gcc.target/nvptx/atomic_fetch-3.c 
b/gcc/testsuite/gcc.target/nvptx/atomic_fetch-3.c
deleted file mode 100644
index 36a83ebba9b..000
--- a/gcc/testsuite/gcc.target/nvptx/atomic_fetch-3.c
+++ /dev/null
@@ -1,24 +0,0 @@
-/* Test the nvptx atomic instructions for __atomic_fetch_OP for
-   SImode arguments.  */
-
-/* { dg-do compile } */
-/* { dg-options "-O2 -m32" } */
-
-int
-main()
-{
-  unsigned long a = ~0;
-  unsigned b = 0xa;
-
-  __atomic_fetch_add (, b, 0);
-  __atomic_fetch_and (, b, 0);
-  __atomic_fetch_or (, b, 0);
-  __atomic_fetch_xor (, b, 0);
-  
-  return a;
-}
-
-/* { dg-final { scan-assembler "atom.add.u32" } } */
-/* { dg-final { scan-assembler "atom.b32.and" } } */
-/* { dg-final { scan-assembler "atom.b32.or" } } */
-/* { dg-final { scan-assembler "atom.b32.xor" } } */


Re: [PATCH] Fix ICE in vectorizable_live_operation

2020-10-15 Thread Jeff Law via Gcc-patches


On 10/15/20 3:49 AM, Richard Biener wrote:
> This fixes the case where the insertion iterator for the live stmt
> is the end of a BB by adjusting the dominance query to the definition
> of the def we're substituting.
>
> Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed.
>
> 2020-10-15  Richard Biener  
>
>   * tree-vect-loop.c (vectorizable_live_operation): Adjust
>   dominance query.
>
>   * gcc.dg/vect/bb-slp-52.c: New testcase.

Assuming this is a fix for the issue I sent privately last night. 
Thanks a ton!


Jeff




Re: [PATCH] fold x << (n % C) to x << (n & C-1) if C meets power2

2020-10-15 Thread Segher Boessenkool
Hi!

On Thu, Oct 15, 2020 at 03:52:01PM +0800, guojiufu wrote:
> I just had a check on below patch for PR66552.
> https://gcc.gnu.org/pipermail/gcc-patches/2020-February/540930.html
> It seems this patch works fine now. This patch fixes PR66552 which
> request to optimizes (x shift (n mod C)) to
> (x shift (n bit_and (C - 1))) when C is a constant and power of two.

>  /* Optimize TRUNC_MOD_EXPR by a power of two into a BIT_AND_EXPR,
> i.e. "X % C" into "X & (C - 1)", if X and C are positive.
> Also optimize A % (C << N)  where C is a power of 2,
> -   to A & ((C << N) - 1).  */
> +   to A & ((C << N) - 1).  And optimize "A shift (B % C)" where C
> +   is a power of 2, shift operation included "<<" and ">>" and assume
> +   (B % C) will not be negative as shifts negative values would be UB,
> +   to  "A shift (B & (C - 1))".  */

Maybe this can be phrased better?  Not that I have any proposed text :-/

The patch looks good to me, fwiw.


Segher


Re: Handle POINTER_PLUS_EXPR in jump functions

2020-10-15 Thread Jakub Jelinek via Gcc-patches
On Thu, Oct 15, 2020 at 02:39:26PM +0200, Jan Hubicka wrote:
> > Both of these tests FAIL everywhere:
> > FAIL: gcc.dg/ipa/modref-1.c (test for excess errors)
> > FAIL: gcc.dg/ipa/modref-1.c scan-ipa-dump modref "param offset: 1"
> > FAIL: gcc.dg/ipa/modref-1.c scan-ipa-dump modref "param offset: 2"
> > FAIL: gcc.dg/tree-ssa/modref-4.c (test for excess errors)
> > FAIL: gcc.dg/tree-ssa/modref-4.c scan-tree-dump modref1 "param offset: 1"
> > UNRESOLVED: gcc.dg/tree-ssa/modref-4.c scan-tree-dump modref2 "param 
> > offset: 2"
> > UNRESOLVED: gcc.dg/tree-ssa/modref-4.c scan-tree-dump modref2 "return 0"
> > 
> > I've tried to fix most of things, but
> > FAIL: gcc.dg/tree-ssa/modref-4.c scan-tree-dump modref1 "return 0"
> > remains (it isn't even optimized in optimized dump).
> > 
> > Committed to trunk as obvious anyway, but please tweak the modref-4.c
> > test according to what you meant.
> > 
> > 2020-10-15  Jakub Jelinek  
> > 
> > * gcc.dg/ipa/modref-1.c: Remove space between param offset: and number
> > in scan-ipa-dump.
> > (b): Declare return type to void.
> > (main): Declare return type to int.  Change c to array of 3 chars.
> > * gcc.dg/tree-ssa/modref-4.c: Remove space between param offset: and
> > number in scan-ipa-dump.  Use modref1 instead of modref2.
> > (b): Declare return type to void.
> > (main): Declare return type to int.  Change c to array of 3 chars.
> Sorry for that - I had fixed versions of the testcases but must have
> mixed the up.   I will look at the reutrn 0 case.

Note that even if it optimized as much as it ever could, return 0 is not the
correct value, while c[0] is unmodified and the optimization
correctly proves that it isn't and optimizes it into 0, c[2] is modified -
it is changed from 0 to 1.  Perhaps you meant c[4]={0,1,0,0}; and check
if c[0]+c[3] is optimized into 0?

Jakub



Re: libgfortran caf API help needed: Fixing fnspec strings in trans-decl

2020-10-15 Thread Jan Hubicka
> Hi Honza,
> 
> attached is the patch to fix the fnspec-strings for the caf-api. I have tested
> it and got no regressions with gcc-testsuite and with the opencoarray's
> testsuite. So that seems fine. Hope this helps and again thank you for your
> instant support on IRC.

Thanks a lot for fixing this! Once the patch is in, I will enable the
verifier.  (and most of support was done by Richi anyway :)

Honza
> 
> Regards,
>   Andre
> 
> On Wed, 7 Oct 2020 13:28:56 +0200
> Tobias Burnus  wrote:
> 
> > Hi Andre,
> > 
> > On 10/7/20 12:21 PM, Andre Vehreschild wrote:
> > > I am confused. Given that on 2. Oct. 2020 you committed changes to the
> > > caf-fn_spec strings means: you don't need anymore help on this?  
> > 
> > Do you mean the change by the patch "Perforate fnspec attribute strings"?
> > (https://gcc.gnu.org/g:762cca0023c9bdbd762c44f33a954845bbccd568)
> > That one just added spaces for the updated fnspec format.
> > 
> > Otherwise:
> > See gcc/attr-fnspec.h for a description.
> > 
> > I suggest also to have a look at the commit log at
> > https://gcc.gnu.org/g:2595f25cdaf4f16d04a1078a487b2ecc126cae29
> > and at the PR https://gcc.gnu.org/PR92123 for gotchas.
> > 
> > Tobias
> > 
> > -
> > Mentor Graphics (Deutschland) GmbH, Arnulfstraße 201, 80634 München / 
> > Germany
> > Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung,
> > Alexander Walter
> 
> 
> -- 
> Andre Vehreschild * Email: vehre ad gmx dot de 

> diff --git a/gcc/fortran/trans-decl.c b/gcc/fortran/trans-decl.c
> index 5940a1fd10c..fca1622edd1 100644
> --- a/gcc/fortran/trans-decl.c
> +++ b/gcc/fortran/trans-decl.c
> @@ -3832,9 +3832,9 @@ gfc_build_builtin_function_decls (void)
>pppchar_type
>   = build_pointer_type (build_pointer_type (pchar_type_node));
> 
> -  gfor_fndecl_caf_init = gfc_build_library_function_decl (
> - get_identifier (PREFIX("caf_init")), void_type_node,
> - 2, pint_type, pppchar_type);
> +  gfor_fndecl_caf_init = gfc_build_library_function_decl_with_spec (
> + get_identifier (PREFIX("caf_init")), ". W W ",
> + void_type_node, 2, pint_type, pppchar_type);
> 
>gfor_fndecl_caf_finalize = gfc_build_library_function_decl (
>   get_identifier (PREFIX("caf_finalize")), void_type_node, 0);
> @@ -3848,47 +3848,47 @@ gfc_build_builtin_function_decls (void)
>   2, integer_type_node, integer_type_node);
> 
>gfor_fndecl_caf_register = gfc_build_library_function_decl_with_spec (
> - get_identifier (PREFIX("caf_register")), "R R W W W W R ",
> + get_identifier (PREFIX("caf_register")), ". . . W w w w . ",
>   void_type_node, 7,
>   size_type_node, integer_type_node, ppvoid_type_node, pvoid_type_node,
>   pint_type, pchar_type_node, size_type_node);
> 
>gfor_fndecl_caf_deregister = gfc_build_library_function_decl_with_spec 
> (
> - get_identifier (PREFIX("caf_deregister")), "W R W W R ",
> + get_identifier (PREFIX("caf_deregister")), ". W . w w . ",
>   void_type_node, 5,
>   ppvoid_type_node, integer_type_node, pint_type, pchar_type_node,
>   size_type_node);
> 
>gfor_fndecl_caf_get = gfc_build_library_function_decl_with_spec (
> - get_identifier (PREFIX("caf_get")), ". R . R R W R R R W ",
> + get_identifier (PREFIX("caf_get")), ". r . . r r w . . . w ",
>   void_type_node, 10,
>   pvoid_type_node, size_type_node, integer_type_node, pvoid_type_node,
>   pvoid_type_node, pvoid_type_node, integer_type_node, integer_type_node,
>   boolean_type_node, pint_type);
> 
>gfor_fndecl_caf_send = gfc_build_library_function_decl_with_spec (
> - get_identifier (PREFIX("caf_send")), ". R . R R R R R R W R ",
> + get_identifier (PREFIX("caf_send")), ". r . . w r r . . . w ",
>   void_type_node, 11,
>   pvoid_type_node, size_type_node, integer_type_node, pvoid_type_node,
>   pvoid_type_node, pvoid_type_node, integer_type_node, integer_type_node,
>   boolean_type_node, pint_type, pvoid_type_node);
> 
>gfor_fndecl_caf_sendget = gfc_build_library_function_decl_with_spec (
> - get_identifier (PREFIX("caf_sendget")), ". R . R R R R . R R R R R R ",
> + get_identifier (PREFIX("caf_sendget")), ". r . . w r r . . r r . . . w 
> ",
>   void_type_node, 14, pvoid_type_node, size_type_node, integer_type_node,
>   pvoid_type_node, pvoid_type_node, pvoid_type_node, size_type_node,
>   integer_type_node, pvoid_type_node, pvoid_type_node, integer_type_node,
>   integer_type_node, boolean_type_node, integer_type_node);
> 
>gfor_fndecl_caf_get_by_ref = gfc_build_library_function_decl_with_spec 
> (
> - get_identifier (PREFIX("caf_get_by_ref")), ". R W R R R R R W R ",
> + get_identifier (PREFIX("caf_get_by_ref")), ". r . w r . . . . w . ",
>   void_type_node,
>   10, pvoid_type_node, integer_type_node, pvoid_type_node,
>   pvoid_type_node, integer_type_node, integer_type_node,
>   

Re: Fix toplevel comment in attr-fnspec.h

2020-10-15 Thread Jan Hubicka
> On Thu, 15 Oct 2020, Jan Hubicka wrote:
> 
> > Hi,
> > this patch fixes some confussion I managed to introduce into the
> > toplevel comment.
> > 
> > OK?
> > 
> > Honza
> > * attr-fnspec.h: Fix toplevel comment.
> > diff --git a/gcc/attr-fnspec.h b/gcc/attr-fnspec.h
> > index 921bb48ae6a..30c0becfdf2 100644
> > --- a/gcc/attr-fnspec.h
> > +++ b/gcc/attr-fnspec.h
> > @@ -30,12 +30,11 @@
> >  
> > character 2+2i specifies properties of argument number i as follows:
> >   'x' or 'X' specifies that parameter is unused.
> > - 'r' or 'R' specifies that parameter is only read and memory pointed 
> > to is
> > -   never dereferenced.
> > - 'w' or 'W' specifies that parameter is only written to.
> > + 'r' or 'R' specifies that parameter is only read and it does not 
> > escape
> 
>  'specifies that the memory pointed to by the parameter is only read and 
> does not escape'
> 
> > + 'w' or 'W' specifies that parameter does not escape
> 
>  'specifies that the memory pointed to by the parameter does not escape'
> 
> >   '.'   specifies that nothing is known.
> > -   The uppercase letter in addition specifies that parameter
> > -   is non-escaping. 
> > +   The uppercase letter in addition specifies that parameter is 
> > read/written
> > +   only dirrectly (i.e. *param is ok, but **param is not)
> 
> The uppercase letter in addition specifies that the memory pointed to
> by the parameter is not dereferenced.  For 'r' only read applies
> transitively to pointers read from the pointed-to memory.

Thanks a lot!  This is what I comitted.

gcc/ChangeLog:

2020-10-15  Jan Hubicka  
Richard Biener  

* attr-fnspec.h: Fix toplevel comment.

diff --git a/gcc/attr-fnspec.h b/gcc/attr-fnspec.h
index 921bb48ae6a..d38b84a969e 100644
--- a/gcc/attr-fnspec.h
+++ b/gcc/attr-fnspec.h
@@ -30,12 +30,14 @@
 
character 2+2i specifies properties of argument number i as follows:
  'x' or 'X' specifies that parameter is unused.
- 'r' or 'R' specifies that parameter is only read and memory pointed to is
-   never dereferenced.
- 'w' or 'W' specifies that parameter is only written to.
+ 'r' or 'R' specifies that the memory pointed to by the parameter is only
+   read and does not escape
+ 'w' or 'W' specifies that the memory pointed to by the parameter does not
+   escape
  '.'   specifies that nothing is known.
-   The uppercase letter in addition specifies that parameter
-   is non-escaping. 
+   The uppercase letter in addition specifies that the memory pointed to
+   by the parameter is not dereferenced.  For 'r' only read applies
+   transitively to pointers read from the pointed-to memory.
 
character 3+2i specifies additional properties of argument number i
as follows:


Re: libgfortran caf API help needed: Fixing fnspec strings in trans-decl

2020-10-15 Thread Andre Vehreschild
Hi Honza,

attached is the patch to fix the fnspec-strings for the caf-api. I have tested
it and got no regressions with gcc-testsuite and with the opencoarray's
testsuite. So that seems fine. Hope this helps and again thank you for your
instant support on IRC.

Regards,
Andre

On Wed, 7 Oct 2020 13:28:56 +0200
Tobias Burnus  wrote:

> Hi Andre,
> 
> On 10/7/20 12:21 PM, Andre Vehreschild wrote:
> > I am confused. Given that on 2. Oct. 2020 you committed changes to the
> > caf-fn_spec strings means: you don't need anymore help on this?  
> 
> Do you mean the change by the patch "Perforate fnspec attribute strings"?
> (https://gcc.gnu.org/g:762cca0023c9bdbd762c44f33a954845bbccd568)
> That one just added spaces for the updated fnspec format.
> 
> Otherwise:
> See gcc/attr-fnspec.h for a description.
> 
> I suggest also to have a look at the commit log at
> https://gcc.gnu.org/g:2595f25cdaf4f16d04a1078a487b2ecc126cae29
> and at the PR https://gcc.gnu.org/PR92123 for gotchas.
> 
> Tobias
> 
> -
> Mentor Graphics (Deutschland) GmbH, Arnulfstraße 201, 80634 München / Germany
> Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung,
> Alexander Walter


-- 
Andre Vehreschild * Email: vehre ad gmx dot de 
diff --git a/gcc/fortran/trans-decl.c b/gcc/fortran/trans-decl.c
index 5940a1fd10c..fca1622edd1 100644
--- a/gcc/fortran/trans-decl.c
+++ b/gcc/fortran/trans-decl.c
@@ -3832,9 +3832,9 @@ gfc_build_builtin_function_decls (void)
   pppchar_type
 	= build_pointer_type (build_pointer_type (pchar_type_node));

-  gfor_fndecl_caf_init = gfc_build_library_function_decl (
-	get_identifier (PREFIX("caf_init")), void_type_node,
-	2, pint_type, pppchar_type);
+  gfor_fndecl_caf_init = gfc_build_library_function_decl_with_spec (
+	get_identifier (PREFIX("caf_init")), ". W W ",
+	void_type_node, 2, pint_type, pppchar_type);

   gfor_fndecl_caf_finalize = gfc_build_library_function_decl (
 	get_identifier (PREFIX("caf_finalize")), void_type_node, 0);
@@ -3848,47 +3848,47 @@ gfc_build_builtin_function_decls (void)
 	2, integer_type_node, integer_type_node);

   gfor_fndecl_caf_register = gfc_build_library_function_decl_with_spec (
-	get_identifier (PREFIX("caf_register")), "R R W W W W R ",
+	get_identifier (PREFIX("caf_register")), ". . . W w w w . ",
 	void_type_node, 7,
 	size_type_node, integer_type_node, ppvoid_type_node, pvoid_type_node,
 	pint_type, pchar_type_node, size_type_node);

   gfor_fndecl_caf_deregister = gfc_build_library_function_decl_with_spec (
-	get_identifier (PREFIX("caf_deregister")), "W R W W R ",
+	get_identifier (PREFIX("caf_deregister")), ". W . w w . ",
 	void_type_node, 5,
 	ppvoid_type_node, integer_type_node, pint_type, pchar_type_node,
 	size_type_node);

   gfor_fndecl_caf_get = gfc_build_library_function_decl_with_spec (
-	get_identifier (PREFIX("caf_get")), ". R . R R W R R R W ",
+	get_identifier (PREFIX("caf_get")), ". r . . r r w . . . w ",
 	void_type_node, 10,
 	pvoid_type_node, size_type_node, integer_type_node, pvoid_type_node,
 	pvoid_type_node, pvoid_type_node, integer_type_node, integer_type_node,
 	boolean_type_node, pint_type);

   gfor_fndecl_caf_send = gfc_build_library_function_decl_with_spec (
-	get_identifier (PREFIX("caf_send")), ". R . R R R R R R W R ",
+	get_identifier (PREFIX("caf_send")), ". r . . w r r . . . w ",
 	void_type_node, 11,
 	pvoid_type_node, size_type_node, integer_type_node, pvoid_type_node,
 	pvoid_type_node, pvoid_type_node, integer_type_node, integer_type_node,
 	boolean_type_node, pint_type, pvoid_type_node);

   gfor_fndecl_caf_sendget = gfc_build_library_function_decl_with_spec (
-	get_identifier (PREFIX("caf_sendget")), ". R . R R R R . R R R R R R ",
+	get_identifier (PREFIX("caf_sendget")), ". r . . w r r . . r r . . . w ",
 	void_type_node,	14, pvoid_type_node, size_type_node, integer_type_node,
 	pvoid_type_node, pvoid_type_node, pvoid_type_node, size_type_node,
 	integer_type_node, pvoid_type_node, pvoid_type_node, integer_type_node,
 	integer_type_node, boolean_type_node, integer_type_node);

   gfor_fndecl_caf_get_by_ref = gfc_build_library_function_decl_with_spec (
-	get_identifier (PREFIX("caf_get_by_ref")), ". R W R R R R R W R ",
+	get_identifier (PREFIX("caf_get_by_ref")), ". r . w r . . . . w . ",
 	void_type_node,
 	10, pvoid_type_node, integer_type_node, pvoid_type_node,
 	pvoid_type_node, integer_type_node, integer_type_node,
 	boolean_type_node, boolean_type_node, pint_type, integer_type_node);

   gfor_fndecl_caf_send_by_ref = gfc_build_library_function_decl_with_spec (
-	get_identifier (PREFIX("caf_send_by_ref")), ". R R R R R R R W R ",
+	get_identifier (PREFIX("caf_send_by_ref")), ". r . r r . . . . w . ",
 	void_type_node,	10, pvoid_type_node, integer_type_node, pvoid_type_node,
 	pvoid_type_node, integer_type_node, integer_type_node,
 	boolean_type_node, boolean_type_node, pint_type, integer_type_node);
@@ -3896,7 +3896,7 @@ 

Re: Fix handling of symbols in other partition in symtab_node::binds_to_current_def_p

2020-10-15 Thread Richard Biener via Gcc-patches
On Thu, Oct 15, 2020 at 2:37 PM Jan Hubicka  wrote:
>
> > On Thu, Oct 15, 2020 at 1:53 PM Jan Hubicka  wrote:
> > >
> > > Hi,
> > > this patch makes binds_to_current_def_p to return true when the current
> > > def is in other partition.  This is needed for modref to propagate info
> > > on loads across partition boundary.
> >
> > Hmm, but partitioning shouldn't influence what a def binds to so this looks
> > like a wrong (possibly pessimizing) change?
>
> If you have symbol in ohter partition you get
>   definition == false
>   in_other_partition == true
> So previously we returned false at the first check, now we proceed
> testing if the definition binds locally from the visibility and
> resolution info (eventually looking for LDPR_PREVAILING_DEF*)

Ah, I misread - so the patch fixes what I thought it introduces.

Nice.

Richard.

> Honza
> >
> > > Bootstrapped/regtsted x86_64-linux, comitted.
> > >
> > > * symtab.c (symtab_node::binds_to_current_def_p): Also accept 
> > > symbols
> > > defined in other partition.
> > > diff --git a/gcc/symtab.c b/gcc/symtab.c
> > > index 207c9e75890..bc2865f4121 100644
> > > --- a/gcc/symtab.c
> > > +++ b/gcc/symtab.c
> > > @@ -2391,7 +2391,7 @@ symbol_table::symbol_suffix_separator ()
> > >  bool
> > >  symtab_node::binds_to_current_def_p (symtab_node *ref)
> > >  {
> > > -  if (!definition)
> > > +  if (!definition && !in_other_partition)
> > >  return false;
> > >if (transparent_alias)
> > >  return definition


Re: Handle POINTER_PLUS_EXPR in jump functions

2020-10-15 Thread Jan Hubicka
> On Wed, Oct 14, 2020 at 03:40:33PM +0200, Jan Hubicka wrote:
> > this patch adds logic to handle POINTER_PLUS_EXPR in compute_parm_map
> > that I originally did not since I tought that all such adjustments are
> > done by ancestor function.
> > 
> > Bootstrapped/regtested x86_64-linux, will commit it shortly.
> > Honza
> > 
> > gcc/ChangeLog:
> > 
> > 2020-10-14  Jan Hubicka  
> > 
> > * ipa-modref.c (compute_parm_map): Handle POINTER_PLUS_EXPR in
> > PASSTHROUGH.
> > 
> > gcc/testsuite/ChangeLog:
> > 
> > 2020-10-14  Jan Hubicka  
> > 
> > * gcc.dg/ipa/modref-1.c: New test.
> > * gcc.dg/tree-ssa/modref-4.c: New test.
> 
> Both of these tests FAIL everywhere:
> FAIL: gcc.dg/ipa/modref-1.c (test for excess errors)
> FAIL: gcc.dg/ipa/modref-1.c scan-ipa-dump modref "param offset: 1"
> FAIL: gcc.dg/ipa/modref-1.c scan-ipa-dump modref "param offset: 2"
> FAIL: gcc.dg/tree-ssa/modref-4.c (test for excess errors)
> FAIL: gcc.dg/tree-ssa/modref-4.c scan-tree-dump modref1 "param offset: 1"
> UNRESOLVED: gcc.dg/tree-ssa/modref-4.c scan-tree-dump modref2 "param offset: 
> 2"
> UNRESOLVED: gcc.dg/tree-ssa/modref-4.c scan-tree-dump modref2 "return 0"
> 
> I've tried to fix most of things, but
> FAIL: gcc.dg/tree-ssa/modref-4.c scan-tree-dump modref1 "return 0"
> remains (it isn't even optimized in optimized dump).
> 
> Committed to trunk as obvious anyway, but please tweak the modref-4.c
> test according to what you meant.
> 
> 2020-10-15  Jakub Jelinek  
> 
>   * gcc.dg/ipa/modref-1.c: Remove space between param offset: and number
>   in scan-ipa-dump.
>   (b): Declare return type to void.
>   (main): Declare return type to int.  Change c to array of 3 chars.
>   * gcc.dg/tree-ssa/modref-4.c: Remove space between param offset: and
>   number in scan-ipa-dump.  Use modref1 instead of modref2.
>   (b): Declare return type to void.
>   (main): Declare return type to int.  Change c to array of 3 chars.
Sorry for that - I had fixed versions of the testcases but must have
mixed the up.   I will look at the reutrn 0 case.

Honza


Re: [PATCH] [PR rtl-optimization/97249]Simplify vec_select of paradoxical subreg.

2020-10-15 Thread Richard Sandiford via Gcc-patches
Hongtao Liu via Gcc-patches  writes:
> +   /* Simplify vec_select of a subreg of X to just a vec_select of X
> +  when X has same component mode as vec_select.  */
> +   int l2;
> +   if (GET_CODE (trueop0) == SUBREG
> +   && GET_MODE_INNER (mode)
> +  == GET_MODE_INNER (GET_MODE (XEXP (trueop0, 0)))

Better to use SUBREG_REG here and below.

> +   && (GET_MODE_NUNITS (GET_MODE (trueop0))).is_constant ()
> +   && (GET_MODE_NUNITS (mode)).is_constant ()
> +   && (GET_MODE_NUNITS (GET_MODE (XEXP (trueop0, 0
> +   .is_constant ()
> +   && known_le (l1, l2))
> + {
> +   unsigned HOST_WIDE_INT subreg_offset = 0;
> +   gcc_assert (known_eq (XVECLEN (trueop1, 0), l1));
> +   gcc_assert (can_div_trunc_p (exact_div (subreg_lsb (trueop0), 
> BITS_PER_UNIT),
> +GET_MODE_SIZE (GET_MODE_INNER 
> (mode)),
> +_offset));

can_div_trunc_p discards the remainder, whereas it looks like here
you want an exact multiple.

I don't think it's absolutely guaranteed that the “if” condition makes
the division by GET_MODE_SIZE exact.  E.g. in principle you could have
a subreg of a vector of TIs in which the subreg offset is misaligned by
a DI offset.

I'm not sure the subreg_lsb conversion is correct though.  On big-endian
targets, lane numbering follows memory layout, just like subreg byte
offsets do.  So ISTM that using SUBREG_BYTE (as per the earlier patch)
was correct.

In summary, I think the "if” condition should include something like:

  constant_mulitple_p (SUBREG_BYTE (trueop0),
   GET_MODE_UNIT_BITSIZE (mode),
   _offset)

Thanks,
Richard


Re: [PATCH] Add if-chain to switch conversion pass.

2020-10-15 Thread Richard Biener via Gcc-patches
On Mon, Oct 12, 2020 at 3:02 PM Martin Liška  wrote:
>
> On 10/12/20 2:44 PM, Martin Liška wrote:
> > On 10/7/20 10:00 AM, Richard Biener wrote:
> >> As said I'd have a BB-local pass over BBs recording the index variable
> >> and the range covered by the BBs gcond, plus recording how many excess
> >> stmts there are for eventual code motion.
> >>
> >> Only after that BB-local pass start to group BBs in a walk from dominated 
> >> to
> >> dominating BBs looking for common indexes and building a case vector.
> >>
> >> The main thing is to avoid repeatedly analyzing BBs conditions (so the 
> >> first
> >> pass could be also a on-demand precompute thing) and making the
> >> case vector build optimal.
> >
> > I have a patch that does that using the infrastructure from 
> > tree-ssa-reassoc.
> > Now I would like to implement the code hoisting. Am I right that we want
> > something like:
> >
> > if (index == C0)
> >goto BB_0;
> > else
> > {
> >BB1_to_hoist_stmts;
> >if (index == C1)
> >  goto BB_1;
> >else
> >{
> >  BB2_to_hoist_stmts;
> >  if (index == C2)
> >goto BB_2;
> >  else
> >goto default_BB;
> >}
> > }
> >
> > be converted into:
> >
> > switch(index)
> > {
> > case C0:
> >   goto BB_0;
> > case C1:
> >   BB1_to_hoist_stmts;
> >   goto BB_1;
> > case C2:
> >   BB1_to_hoist_stmts;
> >   BB2_to_hoist_stmts;
> >   goto BB_2;
> > else:
> >   BB1_to_hoist_stmts;
> >   BB2_to_hoist_stmts;
> >   goto default_BB;
> > }
> >
> > ?
>
> Reading again Richi's comment:
>
> > ifcombine simply hoists any stmts without side-effects up the
> > dominator tree and thus only requires BBs without side-effects
> > (IIRC there's a predicate fn for that).
>
> we likely want to hoist the statements "up" to the gswitch BB?

Yes.  code sinking later will sink what can be sunk.

> Martin
>
> >
> > Thanks,
> > Martin
>


Re: Fix handling of symbols in other partition in symtab_node::binds_to_current_def_p

2020-10-15 Thread Jan Hubicka
> On Thu, Oct 15, 2020 at 1:53 PM Jan Hubicka  wrote:
> >
> > Hi,
> > this patch makes binds_to_current_def_p to return true when the current
> > def is in other partition.  This is needed for modref to propagate info
> > on loads across partition boundary.
> 
> Hmm, but partitioning shouldn't influence what a def binds to so this looks
> like a wrong (possibly pessimizing) change?

If you have symbol in ohter partition you get
  definition == false
  in_other_partition == true
So previously we returned false at the first check, now we proceed
testing if the definition binds locally from the visibility and
resolution info (eventually looking for LDPR_PREVAILING_DEF*)

Honza
> 
> > Bootstrapped/regtsted x86_64-linux, comitted.
> >
> > * symtab.c (symtab_node::binds_to_current_def_p): Also accept 
> > symbols
> > defined in other partition.
> > diff --git a/gcc/symtab.c b/gcc/symtab.c
> > index 207c9e75890..bc2865f4121 100644
> > --- a/gcc/symtab.c
> > +++ b/gcc/symtab.c
> > @@ -2391,7 +2391,7 @@ symbol_table::symbol_suffix_separator ()
> >  bool
> >  symtab_node::binds_to_current_def_p (symtab_node *ref)
> >  {
> > -  if (!definition)
> > +  if (!definition && !in_other_partition)
> >  return false;
> >if (transparent_alias)
> >  return definition


Re: Fix toplevel comment in attr-fnspec.h

2020-10-15 Thread Richard Biener
On Thu, 15 Oct 2020, Jan Hubicka wrote:

> Hi,
> this patch fixes some confussion I managed to introduce into the
> toplevel comment.
> 
> OK?
> 
> Honza
>   * attr-fnspec.h: Fix toplevel comment.
> diff --git a/gcc/attr-fnspec.h b/gcc/attr-fnspec.h
> index 921bb48ae6a..30c0becfdf2 100644
> --- a/gcc/attr-fnspec.h
> +++ b/gcc/attr-fnspec.h
> @@ -30,12 +30,11 @@
>  
> character 2+2i specifies properties of argument number i as follows:
>   'x' or 'X' specifies that parameter is unused.
> - 'r' or 'R' specifies that parameter is only read and memory pointed to 
> is
> - never dereferenced.
> - 'w' or 'W' specifies that parameter is only written to.
> + 'r' or 'R' specifies that parameter is only read and it does not escape

 'specifies that the memory pointed to by the parameter is only read and 
does not escape'

> + 'w' or 'W' specifies that parameter does not escape

 'specifies that the memory pointed to by the parameter does not escape'

>   '.' specifies that nothing is known.
> -   The uppercase letter in addition specifies that parameter
> -   is non-escaping. 
> +   The uppercase letter in addition specifies that parameter is read/written
> +   only dirrectly (i.e. *param is ok, but **param is not)

The uppercase letter in addition specifies that the memory pointed to
by the parameter is not dereferenced.  For 'r' only read applies
transitively to pointers read from the pointed-to memory.

>  
> character 3+2i specifies additional properties of argument number i
> as follows:
> 

-- 
Richard Biener 
SUSE Software Solutions Germany GmbH, Maxfeldstrasse 5, 90409 Nuernberg,
Germany; GF: Felix Imend


Re: Fix handling of symbols in other partition in symtab_node::binds_to_current_def_p

2020-10-15 Thread Richard Biener via Gcc-patches
On Thu, Oct 15, 2020 at 1:53 PM Jan Hubicka  wrote:
>
> Hi,
> this patch makes binds_to_current_def_p to return true when the current
> def is in other partition.  This is needed for modref to propagate info
> on loads across partition boundary.

Hmm, but partitioning shouldn't influence what a def binds to so this looks
like a wrong (possibly pessimizing) change?

> Bootstrapped/regtsted x86_64-linux, comitted.
>
> * symtab.c (symtab_node::binds_to_current_def_p): Also accept symbols
> defined in other partition.
> diff --git a/gcc/symtab.c b/gcc/symtab.c
> index 207c9e75890..bc2865f4121 100644
> --- a/gcc/symtab.c
> +++ b/gcc/symtab.c
> @@ -2391,7 +2391,7 @@ symbol_table::symbol_suffix_separator ()
>  bool
>  symtab_node::binds_to_current_def_p (symtab_node *ref)
>  {
> -  if (!definition)
> +  if (!definition && !in_other_partition)
>  return false;
>if (transparent_alias)
>  return definition


[PATCH] fix TARGET_MEM_REF dumping

2020-10-15 Thread Richard Biener
This fixes the missing constant offset from TARGET_MEM_REF dumping.

Bootstrapped/teste don x86_64-unknown-linux-ngu, pushed.

2020-10-15  Richard Biener  

* tree-pretty-print.c (dump_mem_ref): Print constant offset
also for TARGET_MEM_REF.
---
 gcc/tree-pretty-print.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/gcc/tree-pretty-print.c b/gcc/tree-pretty-print.c
index ed6407c0222..64ac5ab6cec 100644
--- a/gcc/tree-pretty-print.c
+++ b/gcc/tree-pretty-print.c
@@ -1542,8 +1542,7 @@ dump_mem_ref (pretty_printer *pp, tree node, int spc, 
dump_flags_t flags)
   dump_generic_node (pp, op1type, spc, flags | TDF_SLIM, false);
   pp_right_paren (pp);
   dump_generic_node (pp, op0, spc, flags, false);
-  if (TREE_CODE (node) == MEM_REF
- && !integer_zerop (op1))
+  if (!integer_zerop (op1))
{
  pp_string (pp, " + ");
  dump_generic_node (pp, op1, spc, flags, false);
-- 
2.26.2


[PATCH] tree-optimization/97428 - split SLP groups for loop vectorization

2020-10-15 Thread Richard Biener
This enables SLP store group splitting also for loop vectorization.
For the existing testcase gcc.dg/vect/vect-complex-5.c this then
generates much better code, likewise for the PR97428 testcase.

Both of those have a splitting opportunity splitting the group
into two equal (vector-sized) halves, still the patch enables
quite arbitrary splitting since generally the interleaving scheme
results in quite awkward code for even small groups.  If any
problems surface with this it's easy to restrict the splitting
to known-good cases.  Is there any additional constraints for
non-constant sized vectors?  Note this interacts with vector
size iteration (but comparing interleaving cost with SLP cost
of a smaller vector size doesn't reliably pick the smaller
vector size).

Bootstrapped / tested on x86_64-unknown-linux-gnu.

2020-10-15  Richard Biener  

PR tree-optimization/97428
* tree-vect-slp.c (vect_analyze_slp_instance): Split store
groups also for loop vectorization.

* gcc.dg/vect/vect-complex-5.c: Expect to SLP.
* gcc.dg/vect/pr97428.c: Likewise.
---
 gcc/testsuite/gcc.dg/vect/pr97428.c|  1 +
 gcc/testsuite/gcc.dg/vect/vect-complex-5.c |  2 +-
 gcc/tree-vect-slp.c| 46 ++
 3 files changed, 40 insertions(+), 9 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/vect/pr97428.c 
b/gcc/testsuite/gcc.dg/vect/pr97428.c
index b5b02dca9de..49d53738256 100644
--- a/gcc/testsuite/gcc.dg/vect/pr97428.c
+++ b/gcc/testsuite/gcc.dg/vect/pr97428.c
@@ -40,4 +40,5 @@ void foo_i2(dcmlx4_t dst[], const dcmlx_t src[], int n)
load and store groups.  */
 /* { dg-final { scan-tree-dump "Detected interleaving load of size 8" "vect" } 
} */
 /* { dg-final { scan-tree-dump "Detected interleaving store of size 16" "vect" 
} } */
+/* { dg-final { scan-tree-dump-times "vectorizing stmts using SLP" 2 "vect" } 
} */
 /* { dg-final { scan-tree-dump-not "gap of 6 elements" "vect" } } */
diff --git a/gcc/testsuite/gcc.dg/vect/vect-complex-5.c 
b/gcc/testsuite/gcc.dg/vect/vect-complex-5.c
index a2e3590ed98..06486375449 100644
--- a/gcc/testsuite/gcc.dg/vect/vect-complex-5.c
+++ b/gcc/testsuite/gcc.dg/vect/vect-complex-5.c
@@ -40,4 +40,4 @@ main (void)
   return 0;
 }
 
-/* { dg-final { scan-tree-dump-times "vectorizing stmts using SLP" 0 "vect" } 
} */
+/* { dg-final { scan-tree-dump-times "vectorizing stmts using SLP" 2 "vect" } 
} */
diff --git a/gcc/tree-vect-slp.c b/gcc/tree-vect-slp.c
index d0fa6dce8a8..1310a12cbba 100644
--- a/gcc/tree-vect-slp.c
+++ b/gcc/tree-vect-slp.c
@@ -2283,20 +2283,20 @@ vect_analyze_slp_instance (vec_info *vinfo,
   scalar_stmts.release ();
 }
 
-  /* For basic block SLP, try to break the group up into multiples of the
- vector size.  */
+  /* Try to break the group up into pieces.  */
   unsigned HOST_WIDE_INT const_nunits;
-  if (is_a  (vinfo)
-  && STMT_VINFO_GROUPED_ACCESS (stmt_info)
+  if (STMT_VINFO_GROUPED_ACCESS (stmt_info)
   && DR_IS_WRITE (STMT_VINFO_DATA_REF (stmt_info))
   && nunits.is_constant (_nunits))
 {
-  /* We consider breaking the group only on VF boundaries from the existing
-start.  */
   for (i = 0; i < group_size; i++)
-   if (!matches[i]) break;
+   if (!matches[i])
+ break;
 
-  if (i >= const_nunits && i < group_size)
+  /* For basic block SLP, try to break the group up into multiples of the
+vector size.  */
+  if (is_a  (vinfo)
+ && (i >= const_nunits && i < group_size))
{
  /* Split into two groups at the first vector boundary before i.  */
  gcc_assert ((const_nunits & (const_nunits - 1)) == 0);
@@ -2323,6 +2323,36 @@ vect_analyze_slp_instance (vec_info *vinfo,
  rest, max_tree_size);
  return res;
}
+
+  /* For loop vectorization split into arbitrary pieces of size > 1.  */
+  if (is_a  (vinfo)
+ && (i > 1 && i < group_size))
+   {
+ gcc_assert ((const_nunits & (const_nunits - 1)) == 0);
+ unsigned group1_size = i;
+
+ if (dump_enabled_p ())
+   dump_printf_loc (MSG_NOTE, vect_location,
+"Splitting SLP group at stmt %u\n", i);
+
+ stmt_vec_info rest = vect_split_slp_store_group (stmt_info,
+  group1_size);
+ /* Loop vectorization cannot handle gaps in stores, make sure
+the split group appears as strided.  */
+ STMT_VINFO_STRIDED_P (rest) = 1;
+ DR_GROUP_GAP (rest) = 0;
+ STMT_VINFO_STRIDED_P (stmt_info) = 1;
+ DR_GROUP_GAP (stmt_info) = 0;
+
+ bool res = vect_analyze_slp_instance (vinfo, bst_map, stmt_info,
+   max_tree_size);
+ if (i + 1 < group_size)
+   res |= vect_analyze_slp_instance (vinfo, bst_map,
+ rest, 

Fix toplevel comment in attr-fnspec.h

2020-10-15 Thread Jan Hubicka
Hi,
this patch fixes some confussion I managed to introduce into the
toplevel comment.

OK?

Honza
* attr-fnspec.h: Fix toplevel comment.
diff --git a/gcc/attr-fnspec.h b/gcc/attr-fnspec.h
index 921bb48ae6a..30c0becfdf2 100644
--- a/gcc/attr-fnspec.h
+++ b/gcc/attr-fnspec.h
@@ -30,12 +30,11 @@
 
character 2+2i specifies properties of argument number i as follows:
  'x' or 'X' specifies that parameter is unused.
- 'r' or 'R' specifies that parameter is only read and memory pointed to is
-   never dereferenced.
- 'w' or 'W' specifies that parameter is only written to.
+ 'r' or 'R' specifies that parameter is only read and it does not escape
+ 'w' or 'W' specifies that parameter does not escape
  '.'   specifies that nothing is known.
-   The uppercase letter in addition specifies that parameter
-   is non-escaping. 
+   The uppercase letter in addition specifies that parameter is read/written
+   only dirrectly (i.e. *param is ok, but **param is not)
 
character 3+2i specifies additional properties of argument number i
as follows:


Fix handling of symbols in other partition in symtab_node::binds_to_current_def_p

2020-10-15 Thread Jan Hubicka
Hi,
this patch makes binds_to_current_def_p to return true when the current
def is in other partition.  This is needed for modref to propagate info
on loads across partition boundary.

Bootstrapped/regtsted x86_64-linux, comitted.

* symtab.c (symtab_node::binds_to_current_def_p): Also accept symbols
defined in other partition.
diff --git a/gcc/symtab.c b/gcc/symtab.c
index 207c9e75890..bc2865f4121 100644
--- a/gcc/symtab.c
+++ b/gcc/symtab.c
@@ -2391,7 +2391,7 @@ symbol_table::symbol_suffix_separator ()
 bool
 symtab_node::binds_to_current_def_p (symtab_node *ref)
 {
-  if (!definition)
+  if (!definition && !in_other_partition)
 return false;
   if (transparent_alias)
 return definition


Re: [PATCH 1/2] aarch64: Remove support for extract-based addresses [PR96998]

2020-10-15 Thread Richard Sandiford via Gcc-patches
Alex Coplan  writes:
> @@ -11707,32 +11638,12 @@ aarch64_branch_cost (bool speed_p, bool 
> predictable_p)
>  /* Return true if the RTX X in mode MODE is a zero or sign extract
> usable in an ADD or SUB (extended register) instruction.  */
>  static bool
> -aarch64_rtx_arith_op_extract_p (rtx x, scalar_int_mode mode)
> -{
> -  /* Catch add with a sign extract.
> - This is add__multp2.  */
> -  if (GET_CODE (x) == SIGN_EXTRACT
> -  || GET_CODE (x) == ZERO_EXTRACT)
> -{
> -  rtx op0 = XEXP (x, 0);
> -  rtx op1 = XEXP (x, 1);
> -  rtx op2 = XEXP (x, 2);
> -
> -  if (GET_CODE (op0) == MULT
> -   && CONST_INT_P (op1)
> -   && op2 == const0_rtx
> -   && CONST_INT_P (XEXP (op0, 1))
> -   && aarch64_is_extend_from_extract (mode,
> -  XEXP (op0, 1),
> -  op1))
> - {
> -   return true;
> - }
> -}
> +aarch64_rtx_arith_op_extract_p (rtx x)
> +{
>/* The simple case , XD, XN, XM, [us]xt.
>   No shift.  */
> -  else if (GET_CODE (x) == SIGN_EXTEND
> -|| GET_CODE (x) == ZERO_EXTEND)
> +  if (GET_CODE (x) == SIGN_EXTEND
> +  || GET_CODE (x) == ZERO_EXTEND)
>  return REG_P (XEXP (x, 0));
>  
>return false;

Didn't notice this last time, sorry, but:

s/the RTX X in mode MODE/X/

now that there's no longer a mode parameter.

OK with that change if 2/2 is approved.

Thanks,
Richard


Re: [PATCH] openmp: Implement support for OMP_TARGET_OFFLOAD

2020-10-15 Thread Jakub Jelinek via Gcc-patches
On Thu, Oct 15, 2020 at 12:50:18PM +0200, Jakub Jelinek via Gcc-patches wrote:
> If nothing of this is valid (i.e. mandatory forbids all the fallback), then
> your patch implements it, but if e.g. only if (false) is allowed and nothing
> else, then we are ATM in trouble (we pass -2 for if false as well as it is
> returned from omp_get_initial_device (); thankfully, OpenMP 5.0 changed it
> (something that should be implemented in libgomp too), so that
> omp_get_initial_device () is now required to be omp_get_num_devices (),
> i.e. the host device is always the last one; so, we would do fallback
> for -2 and not for anything else), if also omp_get_initial_device ()
> number is valid, then we should allow fallback for devices -2 and
> omp_get_initial_device () and punt on everything else.

Ok, the first response indicates that both if (false) and
omp_get_initial_device () are valid.
Therefore, I think until omp_get_initial_device () value is changed, we
want in resolve_device:
  if (device_id < 0 || device_id >= gomp_get_num_devices ())
{
  if (device_id != GOMP_DEVICE_HOST_FALLBACK)
gomp_fatal (...);
  return NULL;
}
and do gomp_fatal also for further return NULLs in the function.
And then in
  if (devicep == NULL
  || !(devicep->capabilities & GOMP_OFFLOAD_CAP_OPENMP_400)
  /* All shared memory devices should use the GOMP_target_ext function.  */
  || devicep->capabilities & GOMP_OFFLOAD_CAP_SHARED_MEM
  || !(fn_addr = gomp_get_target_fn_addr (devicep, fn)))
return gomp_target_fallback (fn, hostaddrs);
and similar do gomp_fatal before the gomp_target_fallback call
if target-offload-var ICV is mandatory and devicep != NULL.

And when we change omp_get_initial_device (), we'd use
device_id > gomp_get_num_devices () above instead, and
call gomp_fatal there only for
(device_id != GOMP_DEVICE_HOST_FALLBACK
 && device_id != gomp_get_num_devices ())

Jakub



Re: [PATCH] openmp: Implement support for OMP_TARGET_OFFLOAD

2020-10-15 Thread Jakub Jelinek via Gcc-patches
On Wed, Oct 14, 2020 at 09:32:42PM +0100, Kwok Cheung Yeung wrote:
> I'm not sure how this can be tested automatically, as the behaviour depends
> on whether the compiler has been built with offloading support, and whether
> any supported offloading hardware has been installed on the system. I have
> not included any testcases for now.

Not testing it is probably fine, unless we added some effective targets
that the test would be run only if the offloading is (or is not present) and
we would expect failures etc.

I'm really not sure what the behavior should be in various cases though,
so I've asked on omp-lang and will see what the committee members think.

The fuzzy things are e.g.:
void foo () {}  
   
#pragma omp declare target to (foo) 
   

   
int 
   
main () 
   
{   
   
  #pragma omp target if(false)  
   
  foo ();   // Is this ok?  
   
  omp_set_default_device (omp_get_initial_device ());   
   
  #pragma omp target
   
  foo ();   // What about this? 
   
  #pragma omp target device (omp_get_initial_device ()) 
   
  foo ();   // Or this? 
   
  #pragma omp target device (omp_get_num_devices () + 42)   
   
  foo ();   // This one is clearly an error 
   
  if (omp_get_num_devices () == 3)  
   
{   
   
  #pragma omp target device (1) 
   
  foo ();   // This would be an error if we can't offload to device 1   
   
}   
   
}   
   

   
Also, what about the case where there are no offloading devices at all, 
   
so the default device defaults to the initial device number?
   

If nothing of this is valid (i.e. mandatory forbids all the fallback), then
your patch implements it, but if e.g. only if (false) is allowed and nothing
else, then we are ATM in trouble (we pass -2 for if false as well as it is
returned from omp_get_initial_device (); thankfully, OpenMP 5.0 changed it
(something that should be implemented in libgomp too), so that
omp_get_initial_device () is now required to be omp_get_num_devices (),
i.e. the host device is always the last one; so, we would do fallback
for -2 and not for anything else), if also omp_get_initial_device ()
number is valid, then we should allow fallback for devices -2 and
omp_get_initial_device () and punt on everything else.

Jakub



Re: [PATCH] [PR rtl-optimization/97249]Simplify vec_select of paradoxical subreg.

2020-10-15 Thread Hongtao Liu via Gcc-patches
On Thu, Oct 15, 2020 at 4:14 PM Hongtao Liu  wrote:
>
> On Thu, Oct 15, 2020 at 1:37 AM Segher Boessenkool
>  wrote:
> >
> > Hi!
> >
> > On Wed, Oct 14, 2020 at 01:43:45PM +0800, Hongtao Liu wrote:
> > > On Wed, Oct 14, 2020 at 4:01 AM Segher Boessenkool
> > >  wrote:
> > > > On Tue, Oct 13, 2020 at 04:40:53PM +0800, Hongtao Liu wrote:
> > > > >   For rtx like
> > > > >   (vec_select:V2SI (subreg:V4SI (inner:V2SI) 0)
> > > > >(parallel [(const_int 0) (const_int 1)]))
> > > > >  it could be simplified as inner.
> > > >
> > > > You could even simplify any vec_select of a subreg of X to just a
> > > > vec_select of X, by changing the selection vector a bit (well, only do
> > >
> > > Yes, when SUBREG_BYTE of trueop0 is not 0, we need to add offset to 
> > > selection.
> >
> > Exactly.
> >
> > > > this if that is a constant vector, I suppose).  Not just for paradoxical
> > > > subregs either, just for *all* subregs.
> > >
> > > Yes, and only when X has the same inner mode and more elements.
> >
> > No, for *all*.  The mode of the first argument of vec_select does not
> > have to equal its result mode.
> >
> > Any (constant indices) vec_select of a subreg can be written as just a
> > vec_select.
> >
> > > +   /* Simplify vec_select of a subreg of X to just a vec_select of X
> > > +  when available.  */
> >
> > What does "when available" mean here?
> >
>
> When X has same component mode as vec_select, i'll add this to comments.
>
> > > +   int l2;
> > > +   if (GET_CODE (trueop0) == SUBREG
> > > +   && (GET_MODE_INNER (mode)
> > > +   == GET_MODE_INNER (GET_MODE (XEXP (trueop0, 0
> >
> > Don't use unnecessary parens here please, it makes it harder to read
> > (there are quite enough parens already :-) )
> >
>
> Yes.
>
> > > +   gcc_assert (can_div_trunc_p (SUBREG_BYTE (trueop0),
> > > +GET_MODE_SIZE (GET_MODE_INNER 
> > > (mode)),
> > > +_offset));
> >
> > Why is this needed?
>
> I only found this interface for poly_uint64 division to get subreg_offset.
>
> >
> > > +   bool success = true;
> > > +   for (int i = 0;i != l1; i++)
> >
> > (space after ; )
> >
> > > + {
> > > +   rtx j = XVECEXP (trueop1, 0, i);
> >
> > (i and j and k ususally are integers, not rtx)
> >
> > > +   if (!CONST_INT_P (j)
> > > +   || known_ge (UINTVAL (j), l2 - subreg_offset))
> > > + {
> > > +   success = false;
> > > +   break;
> > > + }
> > > + }
> >
> > You don't have to test if the input RTL is valid.  You can assume it is.
> >
>
> This test is for something like (vec_select:v2di (subreg:v4di
> (reg:v2di) 0)(parallel [ (const_int 2) (const_int 3)])).
> const_int 2 here is out of range. Are you meaning the upper rtx wouldn't 
> exist?
>

Remove the test.

> > > +   if (success)
> > > + {
> > > +   rtx par = trueop1;
> > > +   if (subreg_offset)
> > > + {
> > > +   rtvec vec = rtvec_alloc (l1);
> > > +   for (int i = 0; i < l1; i++)
> > > + RTVEC_ELT (vec, i)
> > > +   = GEN_INT (INTVAL (XVECEXP (trueop1, 0, i)
> > > +  + subreg_offset));
> > > +   par = gen_rtx_PARALLEL (VOIDmode, vec);
> > > + }
> > > +   return gen_rtx_VEC_SELECT (mode, XEXP (trueop0, 0), par);
> > > + }
> > > + }
> >
> > subreg_offset will differ in meaning if big-endian; is this correct
> Yes.
> > there, do all the stars align so this code works out fine there as well?
> >
>
> i found it's a bit tricky to adjust selection index for target
> BYTES_BIG_ENDIA != WORDS_BIG_ENDIAN.
> Especially for component mode smaller than word, Any interface to handle this?
>

Use subreg_lsb to get offset from least significant bits, suppose this
could be independent of big/little-endian.

> > Looks fine otherwise, thanks :-)
> >
> >
> > Segher
>
>
>
> --
> BR,
> Hongtao

Update Patch.

-- 
BR,
Hongtao
From 2b56fed24fe7ef7f49bcac131bbc7f51f36b0a6a Mon Sep 17 00:00:00 2001
From: liuhongt 
Date: Tue, 13 Oct 2020 15:35:29 +0800
Subject: [PATCH] Simplify vec_select of a subreg of X to just a vec_select of
 X.

gcc/ChangeLog
	PR rtl-optimization/97249
	* simplify-rtx.c (simplify_binary_operation_1): Simplify
	vec_select of a subreg of X to a vec_select of X when
	available.

gcc/testsuite/ChangeLog

	* gcc.target/i386/pr97249-1.c: New test.
---
 gcc/simplify-rtx.c| 43 +++
 gcc/testsuite/gcc.target/i386/pr97249-1.c | 30 
 2 files changed, 73 insertions(+)
 create mode 100644 gcc/testsuite/gcc.target/i386/pr97249-1.c

diff --git a/gcc/simplify-rtx.c b/gcc/simplify-rtx.c
index 869f0d11b2e..ff831bcec8f 

[PATCH] Fix ICE in vectorizable_live_operation

2020-10-15 Thread Richard Biener
This fixes the case where the insertion iterator for the live stmt
is the end of a BB by adjusting the dominance query to the definition
of the def we're substituting.

Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed.

2020-10-15  Richard Biener  

* tree-vect-loop.c (vectorizable_live_operation): Adjust
dominance query.

* gcc.dg/vect/bb-slp-52.c: New testcase.
---
 gcc/testsuite/gcc.dg/vect/bb-slp-52.c | 15 +++
 gcc/tree-vect-loop.c  |  7 +--
 2 files changed, 20 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/vect/bb-slp-52.c

diff --git a/gcc/testsuite/gcc.dg/vect/bb-slp-52.c 
b/gcc/testsuite/gcc.dg/vect/bb-slp-52.c
new file mode 100644
index 000..5194af8cc40
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/vect/bb-slp-52.c
@@ -0,0 +1,15 @@
+/* { dg-do compile } */
+
+int a, e;
+void g(float);
+typedef struct {
+  float b, c;
+} d;
+d f;
+void h(double i, double j) {
+  if (a && e)
+return;
+  f.b = j;
+  f.c = i;
+  g(i);
+}
diff --git a/gcc/tree-vect-loop.c b/gcc/tree-vect-loop.c
index 0a315e6..991fd457229 100644
--- a/gcc/tree-vect-loop.c
+++ b/gcc/tree-vect-loop.c
@@ -8395,8 +8395,11 @@ vectorizable_live_operation (vec_info *vinfo,
   were not code-generated yet so it is not too bad.
   ???  In fact we'd likely want to avoid this situation
   in the first place.  */
-   if (gimple_code (use_stmt) != GIMPLE_PHI
-   && !vect_stmt_dominates_stmt_p (gsi_stmt (*gsi), use_stmt))
+   if (TREE_CODE (new_tree) == SSA_NAME
+   && !SSA_NAME_IS_DEFAULT_DEF (new_tree)
+   && gimple_code (use_stmt) != GIMPLE_PHI
+   && !vect_stmt_dominates_stmt_p (SSA_NAME_DEF_STMT (new_tree),
+   use_stmt))
  {
enum tree_code code = gimple_assign_rhs_code (use_stmt);
gcc_assert (code == CONSTRUCTOR
-- 
2.26.2


[Ada] Get finalization right when a function returns a function call

2020-10-15 Thread Pierre-Marie de Rodat
When a function returns a function call, we want to avoid making an
unnecessary copy. This is particularly important because of a bug
which had the effect that when a copy was generated, the copied
object was never finalized. If, as in the case of the example for this
ticket, finalization was being used to reclaim storage, then this
lack of finalization introduced a storage leak. Other bugs uncovered
and fixed along the way included incorrect computation of the
Predicates_Ignored attribute (incorrect in two different ways) and
an incorrect implementation of the RM rule that, roughly speaking,
assertion policies are to be ignored in checking the legality of
a static expression.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* checks.adb (Apply_Predicate_Check): Generate "infinite
recursion" warning message even if run-time predicate checking
is disabled.
* exp_ch6.adb (Expand_Simple_Function_Return): In testing
whether the returned expression is a function call, look for the
case where the call has been transformed into a dereference of
an access value that designates the result of a function call.
* sem_ch3.adb (Analyze_Object_Declaration): Legality checking
for a static expression is unaffected by assertion policy (and,
in particular, enabling/disabling of subtype predicates.  To get
the right legality checking, we need to call
Check_Expression_Against_Static_Predicate for a static
expression even if predicate checking is disabled for the given
predicate-bearing subtype.  On the other hand, we don't want to
call Make_Predicate_Check unless predicate checking is enabled.
* sem_ch7.adb (Uninstall_Declarations.Preserve_Full_Attributes):
Preserve the Predicates_Ignored attribute.
* sem_eval.adb (Check_Expression_Against_Static_Predicate):
Previously callers ensured that this procedure was only called
if predicate checking was enabled; that is no longer the case,
so predicates-disabled case must be handled.
* sem_prag.adb (Analyze_Pragma): Fix bug in setting
Predicates_Ignored attribute in Predicate pragma case.diff --git a/gcc/ada/checks.adb b/gcc/ada/checks.adb
--- a/gcc/ada/checks.adb
+++ b/gcc/ada/checks.adb
@@ -2744,13 +2744,9 @@ package body Checks is
   Par : Node_Id;
   S   : Entity_Id;
 
+  Check_Disabled : constant Boolean := (not Predicate_Enabled (Typ))
+or else not Predicate_Check_In_Scope (N);
begin
-  if not Predicate_Enabled (Typ)
-or else not Predicate_Check_In_Scope (N)
-  then
- return;
-  end if;
-
   S := Current_Scope;
   while Present (S) and then not Is_Subprogram (S) loop
  S := Scope (S);
@@ -2759,7 +2755,9 @@ package body Checks is
   --  If the check appears within the predicate function itself, it means
   --  that the user specified a check whose formal is the predicated
   --  subtype itself, rather than some covering type. This is likely to be
-  --  a common error, and thus deserves a warning.
+  --  a common error, and thus deserves a warning. We want to emit this
+  --  warning even if predicate checking is disabled (in which case the
+  --  warning is still useful even if it is not strictly accurate).
 
   if Present (S) and then S = Predicate_Function (Typ) then
  Error_Msg_NE
@@ -2774,9 +2772,15 @@ package body Checks is
Parent (N), Typ);
  end if;
 
- Insert_Action (N,
-   Make_Raise_Storage_Error (Sloc (N),
- Reason => SE_Infinite_Recursion));
+ if not Check_Disabled then
+Insert_Action (N,
+  Make_Raise_Storage_Error (Sloc (N),
+Reason => SE_Infinite_Recursion));
+return;
+ end if;
+  end if;
+
+  if Check_Disabled then
  return;
   end if;
 


diff --git a/gcc/ada/exp_ch6.adb b/gcc/ada/exp_ch6.adb
--- a/gcc/ada/exp_ch6.adb
+++ b/gcc/ada/exp_ch6.adb
@@ -7318,6 +7318,13 @@ package body Exp_Ch6 is
   Exp : Node_Id := Expression (N);
   pragma Assert (Present (Exp));
 
+  Exp_Is_Function_Call : constant Boolean :=
+Nkind (Exp) = N_Function_Call
+  or else (Nkind (Exp) = N_Explicit_Dereference
+   and then Is_Entity_Name (Prefix (Exp))
+   and then Ekind (Entity (Prefix (Exp))) = E_Constant
+   and then Is_Related_To_Func_Return (Entity (Prefix (Exp;
+
   Exp_Typ : constant Entity_Id := Etype (Exp);
   --  The type of the expression (not necessarily the same as R_Type)
 
@@ -7533,7 +7540,7 @@ package body Exp_Ch6 is
 Decl : Node_Id;
 Ent  : Entity_Id;
  begin
-if Nkind (Exp) /= N_Function_Call
+if not Exp_Is_Function_Call
   and then Has_Discriminants (Ubt)
   and then 

[Ada] Crash on subtype of fixed-point type

2020-10-15 Thread Pierre-Marie de Rodat
This patch fixes a compiler abort on a subtype of a fixed-point type
with a 'Small smaller than one. The bounds of a declared subtype of a
fixed-point type where rescaled twice, leading to meaningless values
(constraint-violating) for those bounds.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* freeze.adb (Freeze_Fixed_Point_Type): Do not scale the bounds
of a declared subtype using the 'Small of the type;  this is
done during resolution of the bound itself, unlike what is done
for the bounds of the base type, which are used to determine its
required size. Previous code performed this scaling twice,
leading to meaningless values for such a subtype.diff --git a/gcc/ada/freeze.adb b/gcc/ada/freeze.adb
--- a/gcc/ada/freeze.adb
+++ b/gcc/ada/freeze.adb
@@ -8494,21 +8494,21 @@ package body Freeze is
   Set_Analyzed (Lo, False);
   Analyze (Lo);
 
-  --  Resolve with universal fixed if the base type, and the base type if
-  --  it is a subtype. Note we can't resolve the base type with itself,
-  --  that would be a reference before definition.
+  --  Resolve with universal fixed if the base type, and with the base
+  --  type if we are freezing a subtype. Note we can't resolve the base
+  --  type with itself, that would be a reference before definition.
+  --  The resolution of the bounds of a subtype, if they are given by real
+  --  literals,  includes the setting of the Corresponding_Integer_Value,
+  --  as for other literals of a fixed-point type.
 
   if Typ = Btyp then
  Resolve (Lo, Universal_Fixed);
+ Set_Corresponding_Integer_Value
+   (Lo, UR_To_Uint (Realval (Lo) / Small));
   else
  Resolve (Lo, Btyp);
   end if;
 
-  --  Set corresponding integer value for bound
-
-  Set_Corresponding_Integer_Value
-(Lo, UR_To_Uint (Realval (Lo) / Small));
-
   --  Similar processing for high bound
 
   Set_Etype (Hi, Empty);
@@ -8517,13 +8517,12 @@ package body Freeze is
 
   if Typ = Btyp then
  Resolve (Hi, Universal_Fixed);
+ Set_Corresponding_Integer_Value
+   (Hi, UR_To_Uint (Realval (Hi) / Small));
   else
  Resolve (Hi, Btyp);
   end if;
 
-  Set_Corresponding_Integer_Value
-(Hi, UR_To_Uint (Realval (Hi) / Small));
-
   --  Set type of range to correspond to bounds
 
   Set_Etype (Rng, Etype (Lo));




Re: [PATCH] openmp: Add support for omp_get_supported_active_levels

2020-10-15 Thread Jakub Jelinek via Gcc-patches
On Thu, Oct 15, 2020 at 10:38:56AM +0100, Kwok Cheung Yeung wrote:
> Okay to apply this patch?

Ok, thanks.

> commit 3f6f8808f74598e274bfb8245c08a5428ee1b3fd
> Author: Kwok Cheung Yeung 
> Date:   Thu Oct 15 02:32:09 2020 -0700
> 
> Amend documentation for omp_get_max_active_levels and 
> omp_get_supported_active_levels
> 
> 2020-10-15  Kwok Cheung Yeung  
> 
>   libgomp/
>   * libgomp.texi (omp_get_max_active_levels): Modify description.
>   (omp_get_supported_active_levels): Make descriptions consistent.
> 
> diff --git a/libgomp/libgomp.texi b/libgomp/libgomp.texi
> index 4a5e56f..7c6d5fd 100644
> --- a/libgomp/libgomp.texi
> +++ b/libgomp/libgomp.texi
> @@ -167,7 +167,7 @@ linkage, and do not throw exceptions.
>  * omp_get_default_device::  Get the default device for target regions
>  * omp_get_dynamic:: Dynamic teams setting
>  * omp_get_level::   Number of parallel regions
> -* omp_get_max_active_levels::   Maximum number of active regions
> +* omp_get_max_active_levels::   Current maximum number of active regions
>  * omp_get_max_task_priority::   Maximum task priority value that can be set
>  * omp_get_max_threads:: Maximum number of threads of parallel region
>  * omp_get_nested::  Nested parallel regions
> @@ -177,7 +177,7 @@ linkage, and do not throw exceptions.
>  * omp_get_num_threads:: Size of the active team
>  * omp_get_proc_bind::   Whether theads may be moved between CPUs
>  * omp_get_schedule::Obtain the runtime scheduling method
> -* omp_get_supported_active_levels:: Maximum number of active levels supported
> +* omp_get_supported_active_levels:: Maximum number of active regions 
> supported
>  * omp_get_team_num::Get team number
>  * omp_get_team_size::   Number of threads in a team
>  * omp_get_thread_limit::Maximum number of threads
> @@ -380,7 +380,7 @@ which enclose the calling call.
>  
>  
>  @node omp_get_max_active_levels
> -@section @code{omp_get_max_active_levels} -- Maximum number of active regions
> +@section @code{omp_get_max_active_levels} -- Current maximum number of 
> active regions
>  @table @asis
>  @item @emph{Description}:
>  This function obtains the maximum allowed number of nested, active parallel 
> regions.


Jakub



[Ada] Refine type from Nat to Pos in Make_Index

2020-10-15 Thread Pierre-Marie de Rodat
Refine types to make the code easier to understand. Semantics is not
affected; all the callers have been already respecting the more
restrictive type of parameter anyway.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* sem_ch3.ads, sem_ch3.adb (Make_Index): Refined type of
parameter.
(Constrain_Index): Likewise.
(Array_Type_Declaration): Refine type of a local counter
variable; remove a trivially useless initialization.diff --git a/gcc/ada/sem_ch3.adb b/gcc/ada/sem_ch3.adb
--- a/gcc/ada/sem_ch3.adb
+++ b/gcc/ada/sem_ch3.adb
@@ -440,7 +440,7 @@ package body Sem_Ch3 is
   Related_Nod  : Node_Id;
   Related_Id   : Entity_Id;
   Suffix   : Character;
-  Suffix_Index : Nat);
+  Suffix_Index : Pos);
--  Process an index constraint S in a constrained array declaration. The
--  constraint can be a subtype name, or a range with or without an explicit
--  subtype mark. The index is the corresponding index of the unconstrained
@@ -5987,9 +5987,9 @@ package body Sem_Ch3 is
   Element_Type  : Entity_Id;
   Implicit_Base : Entity_Id;
   Index : Node_Id;
-  Nb_Index  : Nat;
+  Nb_Index  : Pos;
   Priv  : Entity_Id;
-  Related_Id: Entity_Id := Empty;
+  Related_Id: Entity_Id;
 
begin
   if Nkind (Def) = N_Constrained_Array_Definition then
@@ -14100,7 +14100,7 @@ package body Sem_Ch3 is
   Related_Nod  : Node_Id;
   Related_Id   : Entity_Id;
   Suffix   : Character;
-  Suffix_Index : Nat)
+  Suffix_Index : Pos)
is
   Def_Id : Entity_Id;
   R  : Node_Id := Empty;
@@ -19120,7 +19120,7 @@ package body Sem_Ch3 is
  (N: Node_Id;
   Related_Nod  : Node_Id;
   Related_Id   : Entity_Id := Empty;
-  Suffix_Index : Nat   := 1)
+  Suffix_Index : Pos   := 1)
is
   R  : Node_Id;
   T  : Entity_Id;


diff --git a/gcc/ada/sem_ch3.ads b/gcc/ada/sem_ch3.ads
--- a/gcc/ada/sem_ch3.ads
+++ b/gcc/ada/sem_ch3.ads
@@ -195,7 +195,7 @@ package Sem_Ch3 is
  (N: Node_Id;
   Related_Nod  : Node_Id;
   Related_Id   : Entity_Id := Empty;
-  Suffix_Index : Nat   := 1);
+  Suffix_Index : Pos   := 1);
--  Process an index that is given in an array declaration, an entry
--  family declaration or a loop iteration. The index is given by an index
--  declaration (a 'box'), or by a discrete range. The later can be the name




[Ada] Do not use maximal values from System in runtime units

2020-10-15 Thread Pierre-Marie de Rodat
This changes a few runtime units to use explicit bounds based on
Long_Long_Integer instead of maximal values from System, which may
become very large when 128-bit types are supported.

They are used for index types and memory byte counts and, therefore,
the magnitude provided by Long_Long_Integer is sufficient for them.

No functional changes.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* libgnat/a-cfinve.adb (Int): Use subtype of Long_Long_Integer.
* libgnat/a-cofove.adb (Int): Likewise.
* libgnat/a-cgcaso.adb (T): Likewise.
* libgnat/a-cogeso.adb (T): Likewise.
* libgnat/g-debpoo.ads (Byte_Count): Use Long_Long_Integer'Size.diff --git a/gcc/ada/libgnat/a-cfinve.adb b/gcc/ada/libgnat/a-cfinve.adb
--- a/gcc/ada/libgnat/a-cfinve.adb
+++ b/gcc/ada/libgnat/a-cfinve.adb
@@ -40,7 +40,7 @@ is
--  When growing a container, multiply current capacity by this. Doubling
--  leads to amortized linear-time copying.
 
-   type Int is range System.Min_Int .. System.Max_Int;
+   subtype Int is Long_Long_Integer;
 
procedure Free is
  new Ada.Unchecked_Deallocation (Elements_Array, Elements_Array_Ptr);


diff --git a/gcc/ada/libgnat/a-cgcaso.adb b/gcc/ada/libgnat/a-cgcaso.adb
--- a/gcc/ada/libgnat/a-cgcaso.adb
+++ b/gcc/ada/libgnat/a-cgcaso.adb
@@ -29,12 +29,10 @@
 
 --  This algorithm was adapted from GNAT.Heap_Sort_G (see g-hesorg.ad[sb])
 
-with System;
-
 procedure Ada.Containers.Generic_Constrained_Array_Sort
   (Container : in out Array_Type)
 is
-   type T is range System.Min_Int .. System.Max_Int;
+   subtype T is Long_Long_Integer;
 
function To_Index (J : T) return Index_Type;
pragma Inline (To_Index);


diff --git a/gcc/ada/libgnat/a-cofove.adb b/gcc/ada/libgnat/a-cofove.adb
--- a/gcc/ada/libgnat/a-cofove.adb
+++ b/gcc/ada/libgnat/a-cofove.adb
@@ -33,7 +33,7 @@ package body Ada.Containers.Formal_Vectors with
   SPARK_Mode => Off
 is
 
-   type Int is range System.Min_Int .. System.Max_Int;
+   subtype Int is Long_Long_Integer;
 
function To_Array_Index (Index : Index_Type'Base) return Count_Type'Base;
 


diff --git a/gcc/ada/libgnat/a-cogeso.adb b/gcc/ada/libgnat/a-cogeso.adb
--- a/gcc/ada/libgnat/a-cogeso.adb
+++ b/gcc/ada/libgnat/a-cogeso.adb
@@ -29,10 +29,8 @@
 
 --  This algorithm was adapted from GNAT.Heap_Sort (see g-heasor.ad[sb])
 
-with System;
-
 procedure Ada.Containers.Generic_Sort (First, Last : Index_Type'Base) is
-   type T is range System.Min_Int .. System.Max_Int;
+   subtype T is Long_Long_Integer;
 
function To_Index (J : T) return Index_Type;
pragma Inline (To_Index);


diff --git a/gcc/ada/libgnat/g-debpoo.ads b/gcc/ada/libgnat/g-debpoo.ads
--- a/gcc/ada/libgnat/g-debpoo.ads
+++ b/gcc/ada/libgnat/g-debpoo.ads
@@ -299,7 +299,7 @@ package GNAT.Debug_Pools is
--  If Valid is True, Size_In_Storage_Elements is set to the size of this
--  chunk of memory.
 
-   type Byte_Count is mod System.Max_Binary_Modulus;
+   type Byte_Count is mod 2 ** Long_Long_Integer'Size;
--  Type used for maintaining byte counts, needs to be large enough to
--  to accommodate counts allowing for repeated use of the same memory.
 




[Ada] Fix access to uninitialized global variable when emitting error

2020-10-15 Thread Pierre-Marie de Rodat
When calling Error_Msg_FE with a message string that contains "<<"
insertion characters, the error reporting machinery was accessing
uninitialized Error_Msg_Warn variable to decide whether to emit error or
a warning.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* sem_util.adb (Bad_Predicated_Subtype_Use): Emit an
unconditional error, not a conditional warning.diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb
--- a/gcc/ada/sem_util.adb
+++ b/gcc/ada/sem_util.adb
@@ -982,7 +982,7 @@ package body Sem_Util is
Reason => PE_Bad_Predicated_Generic_Type));
 
 else
-   Error_Msg_FE (Msg & "<<", N, Typ);
+   Error_Msg_FE (Msg, N, Typ);
 end if;
 
  else




[Ada] Ada2020: AI12-0003 Specifying the standard storage pool

2020-10-15 Thread Pierre-Marie de Rodat
The standard storage pool can be specified in a Default_Storage_Pool
pragma or aspect. This new feature is documented in AI12-0003-1.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* sem_prag.adb (Analyze_Pragma): Adding semantic support of
Standard to Default_Storage_Pool.
* freeze.adb (Freeze_Entity): If pragma Default_Storage_Pool
applies and it is set to Standard then use the global pool as
the associated storage pool of the access type.diff --git a/gcc/ada/freeze.adb b/gcc/ada/freeze.adb
--- a/gcc/ada/freeze.adb
+++ b/gcc/ada/freeze.adb
@@ -6387,7 +6387,7 @@ package body Freeze is
 end if;
 
  --  The pool applies to named and anonymous access types, but not
- --  to subprogram and to  internal types generated for 'Access
+ --  to subprogram and to internal types generated for 'Access
  --  references.
 
  elsif Is_Access_Type (E)
@@ -6412,6 +6412,11 @@ package body Freeze is
if Nkind (Default_Pool) = N_Null then
   Set_No_Pool_Assigned (E);
 
+   --  Case of pragma Default_Storage_Pool (Standard)
+
+   elsif Entity (Default_Pool) = Standard_Standard then
+  Set_Associated_Storage_Pool (E, RTE (RE_Global_Pool_Object));
+
--  Case of pragma Default_Storage_Pool (storage_pool_NAME)
 
else


diff --git a/gcc/ada/sem_prag.adb b/gcc/ada/sem_prag.adb
--- a/gcc/ada/sem_prag.adb
+++ b/gcc/ada/sem_prag.adb
@@ -15314,7 +15314,7 @@ package body Sem_Prag is
  -- Default_Storage_Pool --
  --
 
- --  pragma Default_Storage_Pool (storage_pool_NAME | null);
+ --  pragma Default_Storage_Pool (storage_pool_NAME | null | Standard);
 
  when Pragma_Default_Storage_Pool => Default_Storage_Pool : declare
 Pool : Node_Id;
@@ -15355,6 +15355,18 @@ package body Sem_Prag is
 
   Set_Etype (Pool, Empty);
 
+   --  Case of Default_Storage_Pool (Standard);
+
+   elsif Nkind (Pool) = N_Identifier
+ and then Chars (Pool) = Name_Standard
+   then
+  Analyze (Pool);
+
+  if Entity (Pool) /= Standard_Standard then
+ Error_Pragma_Arg
+   ("package Standard is not directly visible", Arg1);
+  end if;
+
--  Case of Default_Storage_Pool (storage_pool_NAME);
 
else
@@ -15362,7 +15374,7 @@ package body Sem_Prag is
   --  argument is "null".
 
   if Is_Configuration_Pragma then
- Error_Pragma_Arg ("NULL expected", Arg1);
+ Error_Pragma_Arg ("NULL or Standard expected", Arg1);
   end if;
 
   --  The expected type for a non-"null" argument is




[Ada] Fix range check on constrained array with expanded index name

2020-10-15 Thread Pierre-Marie de Rodat
When detecting a type name we must look for both identifiers and
expanded names.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* sem_ch3.adb (Analyze_Subtype_Declaration): Recognize both
identifiers and expanded names; use high-level Is_Scalar_Type
instead of low-level membership test.diff --git a/gcc/ada/sem_ch3.adb b/gcc/ada/sem_ch3.adb
--- a/gcc/ada/sem_ch3.adb
+++ b/gcc/ada/sem_ch3.adb
@@ -5829,8 +5829,8 @@ package body Sem_Ch3 is
Target_Index := First_Index (Indic_Typ);
 
while Present (Subt_Index) loop
-  if ((Nkind (Subt_Index) = N_Identifier
-and then Ekind (Entity (Subt_Index)) in Scalar_Kind)
+  if ((Nkind (Subt_Index) in N_Expanded_Name | N_Identifier
+and then Is_Scalar_Type (Entity (Subt_Index)))
or else Nkind (Subt_Index) = N_Subtype_Indication)
 and then
   Nkind (Scalar_Range (Etype (Subt_Index))) = N_Range




[Ada] Wrong use of Scope_Depth_Value

2020-10-15 Thread Pierre-Marie de Rodat
We've recently found that Scope_Depth_Value is sometimes called on the
wrong nodes.

This is fixed by adding proper assertions and updating the problematic
call.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* einfo.ads, einfo.adb (Scope_Depth_Value,
Set_Scope_Depth_Value): Add assertions on valid nodes and update
documentation accordingly.
(Write_Field22_Name): Sync with change in Scope_Depth_Value.
* sem_ch8.adb (Find_Direct_Name): Fix call to Scope_Depth_Value.diff --git a/gcc/ada/einfo.adb b/gcc/ada/einfo.adb
--- a/gcc/ada/einfo.adb
+++ b/gcc/ada/einfo.adb
@@ -3311,6 +3311,13 @@ package body Einfo is
 
function Scope_Depth_Value (Id : E) return U is
begin
+  pragma Assert
+(Ekind (Id) in
+   Concurrent_Kind | Entry_Kind| Generic_Unit_Kind |
+   E_Package   | E_Package_Body| Subprogram_Kind   |
+   E_Block | E_Subprogram_Body |
+   E_Private_Type .. E_Limited_Private_Subtype |
+   E_Void  | E_Loop| E_Return_Statement);
   return Uint22 (Id);
end Scope_Depth_Value;
 
@@ -6582,7 +6589,13 @@ package body Einfo is
 
procedure Set_Scope_Depth_Value (Id : E; V : U) is
begin
-  pragma Assert (not Is_Record_Type (Id));
+  pragma Assert
+(Ekind (Id) in
+   Concurrent_Kind | Entry_Kind| Generic_Unit_Kind |
+   E_Package   | E_Package_Body| Subprogram_Kind   |
+   E_Block | E_Subprogram_Body |
+   E_Private_Type .. E_Limited_Private_Subtype |
+   E_Void  | E_Loop| E_Return_Statement);
   Set_Uint22 (Id, V);
end Set_Scope_Depth_Value;
 
@@ -10873,21 +10886,18 @@ package body Einfo is
  when Formal_Kind =>
 Write_Str ("Protected_Formal");
 
- when E_Block
-| E_Entry
-| E_Entry_Family
-| E_Function
-| E_Generic_Function
-| E_Generic_Package
-| E_Generic_Procedure
-| E_Loop
+ when Concurrent_Kind
+| Entry_Kind
+| Generic_Unit_Kind
 | E_Package
 | E_Package_Body
-| E_Procedure
-| E_Protected_Type
-| E_Return_Statement
+| Subprogram_Kind
+| E_Block
 | E_Subprogram_Body
-| E_Task_Type
+| E_Private_Type .. E_Limited_Private_Subtype
+| E_Void
+| E_Loop
+| E_Return_Statement
  =>
 Write_Str ("Scope_Depth_Value");
 


diff --git a/gcc/ada/einfo.ads b/gcc/ada/einfo.ads
--- a/gcc/ada/einfo.ads
+++ b/gcc/ada/einfo.ads
@@ -4280,14 +4280,16 @@ package Einfo is
 --   the Scope will be Standard.
 
 --Scope_Depth (synthesized)
---   Applies to program units, blocks, concurrent types and entries, and
---   also to record types, i.e. to any entity that can appear on the scope
---   stack. Yields the scope depth value, which for those entities other
---   than records is simply the scope depth value, for record entities, it
---   is the Scope_Depth of the record scope.
+--   Applies to program units, blocks, loops, return statements,
+--   concurrent types, private types and entries, and also to record types,
+--   i.e. to any entity that can appear on the scope stack. Yields the
+--   scope depth value, which for those entities other than records is
+--   simply the scope depth value, for record entities, it is the
+--   Scope_Depth of the record scope.
 
 --Scope_Depth_Value (Uint22)
---   Defined in program units, blocks, concurrent types, and entries.
+--   Defined in program units, blocks, loops, return statements,
+--   concurrent types, private types and entries.
 --   Indicates the number of scopes that statically enclose the declaration
 --   of the unit or type. Library units have a depth of zero. Note that
 --   record types can act as scopes but do NOT have this field set (see


diff --git a/gcc/ada/sem_ch8.adb b/gcc/ada/sem_ch8.adb
--- a/gcc/ada/sem_ch8.adb
+++ b/gcc/ada/sem_ch8.adb
@@ -5752,7 +5752,7 @@ package body Sem_Ch8 is
--  outside the instance.
 
if From_Actual_Package (E)
- and then Scope_Depth (E2) < Scope_Depth (Inst)
+ and then Scope_Depth (Scope (E2)) < Scope_Depth (Inst)
then
   goto Found;
else




[Ada] Cleanup defensive guards for Null_Exclusion_Present

2020-10-15 Thread Pierre-Marie de Rodat
In routine Process_Subtype we had two calls to Null_Exclusion_Present
(P): one guarded by "Present (P)" and the other by "Nkind (P) in ...".
Now both calls are guarded by the conjunction of those guards.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* sem_ch3.adb (Process_Subtype): Combine guards for
Null_Exclusion_Present in May_Have_Null_Exclusion; use this
combined guard when checking AI-231.diff --git a/gcc/ada/sem_ch3.adb b/gcc/ada/sem_ch3.adb
--- a/gcc/ada/sem_ch3.adb
+++ b/gcc/ada/sem_ch3.adb
@@ -21541,21 +21541,12 @@ package body Sem_Ch3 is
  Check_Incomplete (S);
  P := Parent (S);
 
- --  Ada 2005 (AI-231): Static check
-
- if Ada_Version >= Ada_2005
-   and then Present (P)
-   and then Null_Exclusion_Present (P)
-   and then Nkind (P) /= N_Access_To_Object_Definition
-   and then not Is_Access_Type (Entity (S))
- then
-Error_Msg_N ("`NOT NULL` only allowed for an access type", S);
- end if;
-
  --  The following mirroring of assertion in Null_Exclusion_Present is
  --  ugly, can't we have a range, a static predicate or even a flag???
 
  May_Have_Null_Exclusion :=
+   Present (P)
+ and then
Nkind (P) in N_Access_Definition
   | N_Access_Function_Definition
   | N_Access_Procedure_Definition
@@ -21571,6 +21562,17 @@ package body Sem_Ch3 is
   | N_Parameter_Specification
   | N_Subtype_Declaration;
 
+ --  Ada 2005 (AI-231): Static check
+
+ if Ada_Version >= Ada_2005
+   and then May_Have_Null_Exclusion
+   and then Null_Exclusion_Present (P)
+   and then Nkind (P) /= N_Access_To_Object_Definition
+   and then not Is_Access_Type (Entity (S))
+ then
+Error_Msg_N ("`NOT NULL` only allowed for an access type", S);
+ end if;
+
  --  Create an Itype that is a duplicate of Entity (S) but with the
  --  null-exclusion attribute.
 




[Ada] Spurious visibility on private with package

2020-10-15 Thread Pierre-Marie de Rodat
When a generic package has a private with clause, this clause may not be
properly uninstalled, causing entities to be visible that shouldn't be.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* sem_ch10.adb (Install_With_Clause): Fix implementation of Ada
2005 AI-262 by taking into account generic packages.  Minor
reformatting.
* libgnat/a-cbhase.ads, libgnat/a-cbhase.adb: Remove use clause
on runtime unit spec.diff --git a/gcc/ada/libgnat/a-cbhase.adb b/gcc/ada/libgnat/a-cbhase.adb
--- a/gcc/ada/libgnat/a-cbhase.adb
+++ b/gcc/ada/libgnat/a-cbhase.adb
@@ -42,6 +42,7 @@ with System; use type System.Address;
 package body Ada.Containers.Bounded_Hashed_Sets with
   SPARK_Mode => Off
 is
+   use Ada.Finalization;
 
pragma Warnings (Off, "variable ""Busy*"" is not referenced");
pragma Warnings (Off, "variable ""Lock*"" is not referenced");


diff --git a/gcc/ada/libgnat/a-cbhase.ads b/gcc/ada/libgnat/a-cbhase.ads
--- a/gcc/ada/libgnat/a-cbhase.ads
+++ b/gcc/ada/libgnat/a-cbhase.ads
@@ -36,7 +36,7 @@ with Ada.Iterator_Interfaces;
 private with Ada.Containers.Hash_Tables;
 with Ada.Containers.Helpers;
 private with Ada.Streams;
-private with Ada.Finalization; use Ada.Finalization;
+private with Ada.Finalization;
 
 generic
type Element_Type is private;
@@ -592,7 +592,7 @@ private
 
No_Element : constant Cursor := (Container => null, Node => 0);
 
-   type Iterator is new Limited_Controlled and
+   type Iterator is new Ada.Finalization.Limited_Controlled and
  Set_Iterator_Interfaces.Forward_Iterator with
record
   Container : Set_Access;


diff --git a/gcc/ada/sem_ch10.adb b/gcc/ada/sem_ch10.adb
--- a/gcc/ada/sem_ch10.adb
+++ b/gcc/ada/sem_ch10.adb
@@ -5303,8 +5303,9 @@ package body Sem_Ch10 is
   --  analyzing the private part of the package).
 
   if Private_Present (With_Clause)
-and then Nkind (Unit (Parent (With_Clause))) = N_Package_Declaration
-and then not (Private_With_OK)
+and then Nkind (Unit (Parent (With_Clause)))
+   in N_Package_Declaration | N_Generic_Package_Declaration
+and then not Private_With_OK
   then
  return;
   end if;
@@ -5371,7 +5372,7 @@ package body Sem_Ch10 is
 Set_Is_Visible_Lib_Unit (Uname);
 
 --  If the unit is a wrapper package for a compilation unit that is
---  a subprogrm instance, indicate that the instance itself is a
+--  a subprogram instance, indicate that the instance itself is a
 --  visible unit. This is necessary if the instance is inlined.
 
 if Is_Wrapper_Package (Uname) then
@@ -6464,7 +6465,7 @@ package body Sem_Ch10 is
 null;
 
  elsif Nkind (Item) = N_With_Clause
-and then Context_Installed (Item)
+   and then Context_Installed (Item)
  then
 --  Remove items from one with'ed unit
 
@@ -6818,12 +6819,12 @@ package body Sem_Ch10 is
   -- In_Regular_With_Clause --
   
 
-  function In_Regular_With_Clause (E : Entity_Id) return Boolean
-  is
+  function In_Regular_With_Clause (E : Entity_Id) return Boolean is
  Item : Node_Id;
 
   begin
  Item := First (Context_Items (Comp_Unit));
+
  while Present (Item) loop
 if Nkind (Item) = N_With_Clause
 
@@ -6836,6 +6837,7 @@ package body Sem_Ch10 is
 then
return True;
 end if;
+
 Next (Item);
  end loop;
 




[Ada] Bring defensive guard for Null_Exclusion_Present up to date

2020-10-15 Thread Pierre-Marie de Rodat
An expression for May_Have_Null_Exclusion variable mirrors an assertion
in Null_Exclusion_Present. The assertion was then extended with another
node kind and so May_Have_Null_Exclusion got out of date.

The May_Have_Null_Exclusion is just a defensive code, so compilation is
not affected.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* sem_ch3.adb (Process_Subtype): Sync May_Have_Null_Exclusion
with assertion in Null_Exclusion_Present; clarify the scope of
local variables.diff --git a/gcc/ada/sem_ch3.adb b/gcc/ada/sem_ch3.adb
--- a/gcc/ada/sem_ch3.adb
+++ b/gcc/ada/sem_ch3.adb
@@ -21487,14 +21487,6 @@ package body Sem_Ch3 is
   Related_Id  : Entity_Id := Empty;
   Suffix  : Character := ' ') return Entity_Id
is
-  P   : Node_Id;
-  Def_Id  : Entity_Id;
-  Error_Node  : Node_Id;
-  Full_View_Id: Entity_Id;
-  Subtype_Mark_Id : Entity_Id;
-
-  May_Have_Null_Exclusion : Boolean;
-
   procedure Check_Incomplete (T : Node_Id);
   --  Called to verify that an incomplete type is not used prematurely
 
@@ -21519,6 +21511,16 @@ package body Sem_Ch3 is
  end if;
   end Check_Incomplete;
 
+  --  Local variables
+
+  P   : Node_Id;
+  Def_Id  : Entity_Id;
+  Error_Node  : Node_Id;
+  Full_View_Id: Entity_Id;
+  Subtype_Mark_Id : Entity_Id;
+
+  May_Have_Null_Exclusion : Boolean;
+
--  Start of processing for Process_Subtype
 
begin
@@ -21550,7 +21552,8 @@ package body Sem_Ch3 is
 Error_Msg_N ("`NOT NULL` only allowed for an access type", S);
  end if;
 
- --  The following is ugly, can't we have a range or even a flag???
+ --  The following mirroring of assertion in Null_Exclusion_Present is
+ --  ugly, can't we have a range, a static predicate or even a flag???
 
  May_Have_Null_Exclusion :=
Nkind (P) in N_Access_Definition
@@ -21562,6 +21565,7 @@ package body Sem_Ch3 is
   | N_Derived_Type_Definition
   | N_Discriminant_Specification
   | N_Formal_Object_Declaration
+  | N_Function_Specification
   | N_Object_Declaration
   | N_Object_Renaming_Declaration
   | N_Parameter_Specification




[Ada] Remove obsolete DSP comment

2020-10-15 Thread Pierre-Marie de Rodat
Remove a reference to the "depressed stack pointer" method of doing
returns of caller-unknown-size subtypes. DSP was removed from the
compiler years ago.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* exp_ch6.adb (Expand_Simple_Function_Return): Remove DSP part
of comment, and reformat.diff --git a/gcc/ada/exp_ch6.adb b/gcc/ada/exp_ch6.adb
--- a/gcc/ada/exp_ch6.adb
+++ b/gcc/ada/exp_ch6.adb
@@ -7556,15 +7556,14 @@ package body Exp_Ch6 is
  Set_Enclosing_Sec_Stack_Return (N);
 
  --  Optimize the case where the result is a function call. In this
- --  case either the result is already on the secondary stack, or is
- --  already being returned with the stack pointer depressed and no
- --  further processing is required except to set the By_Ref flag
- --  to ensure that gigi does not attempt an extra unnecessary copy.
- --  (actually not just unnecessary but harmfully wrong in the case
- --  of a controlled type, where gigi does not know how to do a copy).
- --  To make up for a gcc 2.8.1 deficiency (???), we perform the copy
- --  for array types if the constrained status of the target type is
- --  different from that of the expression.
+ --  case the result is already on the secondary stack and no further
+ --  processing is required except to set the By_Ref flag to ensure
+ --  that gigi does not attempt an extra unnecessary copy. (Actually
+ --  not just unnecessary but wrong in the case of a controlled type,
+ --  where gigi does not know how to do a copy.) To make up for a gcc
+ --  2.8.1 deficiency (???), we perform the copy for array types if the
+ --  constrained status of the target type is different from that of
+ --  the expression.
 
  if Requires_Transient_Scope (Exp_Typ)
and then




[Ada] Ada_2020: Add aspect Aggregate to standard container units

2020-10-15 Thread Pierre-Marie de Rodat
This patch adds the Ada_2020 aspect Aggregate to standard containers
(vectors, maps, and sets) that support the new construct. This patch
also refines the resolution of record vs. container aggregates, and the
resolution of the aggregate primitive Add_Indexed when the given name
corresponds to an existing overloaded primitive.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* exp_aggr.adb (Expand_N_Aggregate): A record aggregate requires
a non-private type.
* sem_ch13.adb (Valid_Assign_Indexed): New subprogram local to
Resolve_Aspect_Aggregate, to handle the case when the
corresponding name appearing in the aspect specification for an
indexed aggregate is an overloaded operation.
* libgnat/a-convec.ads, libgnat/a-convec.adb,
libgnat/a-coinve.ads, libgnat/a-coinve.adb,
libgnat/a-cobove.ads, libgnat/a-cobove.adb,
libgnat/a-cdlili.ads, libgnat/a-cdlili.adb,
libgnat/a-cbdlli.ads, libgnat/a-cbdlli.adb,
libgnat/a-cohama.ads, libgnat/a-cihama.ads,
libgnat/a-cbhama.ads, libgnat/a-cborma.ads,
libgnat/a-ciorma.ads, libgnat/a-coorma.ads,
libgnat/a-cihase.ads, libgnat/a-cohase.ads,
libgnat/a-cbhase.ads, libgnat/a-cborse.ads,
libgnat/a-ciorse.ads, libgnat/a-coorse.ads: Add Ada_2020 aspect
Aggregate to types declared in standard containers, as well as
new subprograms where required.diff --git a/gcc/ada/exp_aggr.adb b/gcc/ada/exp_aggr.adb
--- a/gcc/ada/exp_aggr.adb
+++ b/gcc/ada/exp_aggr.adb
@@ -6758,7 +6758,9 @@ package body Exp_Aggr is
begin
   --  Record aggregate case
 
-  if Is_Record_Type (Etype (N)) then
+  if Is_Record_Type (Etype (N))
+and then not Is_Private_Type (Etype (N))
+  then
  Expand_Record_Aggregate (N);
 
   elsif Has_Aspect (Etype (N), Aspect_Aggregate) then


diff --git a/gcc/ada/libgnat/a-cbdlli.adb b/gcc/ada/libgnat/a-cbdlli.adb
--- a/gcc/ada/libgnat/a-cbdlli.adb
+++ b/gcc/ada/libgnat/a-cbdlli.adb
@@ -204,6 +204,18 @@ is
   Insert (Container, No_Element, New_Item, Count);
end Append;
 
+   ---
+   -- Append_One --
+   ---
+
+   procedure Append_One
+ (Container : in out List;
+  New_Item  : Element_Type)
+   is
+   begin
+  Insert (Container, No_Element, New_Item, 1);
+   end Append_One;
+

-- Assign --



diff --git a/gcc/ada/libgnat/a-cbdlli.ads b/gcc/ada/libgnat/a-cbdlli.ads
--- a/gcc/ada/libgnat/a-cbdlli.ads
+++ b/gcc/ada/libgnat/a-cbdlli.ads
@@ -54,8 +54,9 @@ is
   Constant_Indexing => Constant_Reference,
   Variable_Indexing => Reference,
   Default_Iterator  => Iterate,
-  Iterator_Element  => Element_Type;
-
+  Iterator_Element  => Element_Type,
+  Aggregate => (Empty=> Empty_List,
+Add_Unnamed  => Append_One);
pragma Preelaborable_Initialization (List);
 
type Cursor is private;
@@ -149,6 +150,10 @@ is
   New_Item  : Element_Type;
   Count : Count_Type := 1);
 
+   procedure Append_One
+ (Container : in out List;
+  New_Item  : Element_Type);
+
procedure Delete
  (Container : in out List;
   Position  : in out Cursor;


diff --git a/gcc/ada/libgnat/a-cbhama.ads b/gcc/ada/libgnat/a-cbhama.ads
--- a/gcc/ada/libgnat/a-cbhama.ads
+++ b/gcc/ada/libgnat/a-cbhama.ads
@@ -56,7 +56,9 @@ is
   Constant_Indexing => Constant_Reference,
   Variable_Indexing => Reference,
   Default_Iterator  => Iterate,
-  Iterator_Element  => Element_Type;
+  Iterator_Element  => Element_Type,
+  Aggregate => (Empty => Empty_Map,
+Add_Named => Insert);
 
pragma Preelaborable_Initialization (Map);
 


diff --git a/gcc/ada/libgnat/a-cbhase.ads b/gcc/ada/libgnat/a-cbhase.ads
--- a/gcc/ada/libgnat/a-cbhase.ads
+++ b/gcc/ada/libgnat/a-cbhase.ads
@@ -58,7 +58,9 @@ is
type Set (Capacity : Count_Type; Modulus : Hash_Type) is tagged private
  with Constant_Indexing => Constant_Reference,
   Default_Iterator  => Iterate,
-  Iterator_Element  => Element_Type;
+  Iterator_Element  => Element_Type,
+  Aggregate => (Empty   => Empty_Set,
+Add_Unnamed => Include);
 
pragma Preelaborable_Initialization (Set);
 


diff --git a/gcc/ada/libgnat/a-cborma.ads b/gcc/ada/libgnat/a-cborma.ads
--- a/gcc/ada/libgnat/a-cborma.ads
+++ b/gcc/ada/libgnat/a-cborma.ads
@@ -57,7 +57,9 @@ is
   Constant_Indexing => Constant_Reference,
   Variable_Indexing => Reference,
   Default_Iterator  => Iterate,
-  Iterator_Element  => Element_Type;
+  Iterator_Element  => Element_Type,
+  Aggregate => (Empty => Empty_Map,
+Add_Named => Insert);
 
pragma Preelaborable_Initialization (Map);
 


diff --git a/gcc/ada/libgnat/a-cborse.ads 

[Ada] Double evaluation of predicate

2020-10-15 Thread Pierre-Marie de Rodat
In some case involving a type with a predicate and an inner package with
a subprogram referencing the type, GNAT would call Add_Predicate twice
on the same pragma node, causing tree sharing conflicts.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* sem_ch13.adb (Add_Predicates): Prevent analyzing twice the
same pragma in case an inner package references the type with a
predicate (as opposed to defining the type).diff --git a/gcc/ada/sem_ch13.adb b/gcc/ada/sem_ch13.adb
--- a/gcc/ada/sem_ch13.adb
+++ b/gcc/ada/sem_ch13.adb
@@ -9746,7 +9746,7 @@ package body Sem_Ch13 is
 
 elsif Nkind (Ritem) = N_Aspect_Specification
   and then Present (Aspect_Rep_Item (Ritem))
-  and then Scope (Typ) /= Current_Scope
+  and then Scope_Depth (Scope (Typ)) > Scope_Depth (Current_Scope)
 then
declare
   Prag : constant Node_Id := Aspect_Rep_Item (Ritem);




[Ada] Do not remove side effects from any object declarations in SPARK

2020-10-15 Thread Pierre-Marie de Rodat
In GNATprove mode we special-case the removal of side effect to do
nothing for object declarations. However, this special casing applied
only to some object declarations; now it applies to all.

This patch only affects GNATprove, where it prevents recursive expansion
of object declaration of a very particular record type (with explicitly
specified Size attribute to be less than 64 and having no
discriminants).

Compilation is not affected.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* exp_util.adb (Remove_Side_Effects): Move special-casing for
GNATprove to be applied to all object declarations.diff --git a/gcc/ada/exp_util.adb b/gcc/ada/exp_util.adb
--- a/gcc/ada/exp_util.adb
+++ b/gcc/ada/exp_util.adb
@@ -11324,6 +11324,14 @@ package body Exp_Util is
 and then Is_Class_Wide_Type (Etype (Exp))
   then
  return;
+
+  --  An expression which is in SPARK mode is considered side effect free
+  --  if the resulting value is captured by a variable or a constant.
+
+  elsif GNATprove_Mode
+and then Nkind (Parent (Exp)) = N_Object_Declaration
+  then
+ return;
   end if;
 
   --  The remaining processing is done with all checks suppressed
@@ -11576,15 +11584,6 @@ package body Exp_Util is
   --  Otherwise we generate a reference to the expression
 
   else
- --  An expression which is in SPARK mode is considered side effect
- --  free if the resulting value is captured by a variable or a
- --  constant.
-
- if GNATprove_Mode
-   and then Nkind (Parent (Exp)) = N_Object_Declaration
- then
-goto Leave;
-
  --  When generating C code we cannot consider side effect free object
  --  declarations that have discriminants and are initialized by means
  --  of a function call since on this target there is no secondary
@@ -11598,7 +11597,7 @@ package body Exp_Util is
  --  be identified here to avoid entering into a never-ending loop
  --  generating internal object declarations.
 
- elsif Modify_Tree_For_C
+ if Modify_Tree_For_C
and then Nkind (Parent (Exp)) = N_Object_Declaration
and then
  (Nkind (Exp) /= N_Function_Call




[Ada] Remove excessive defensive calls to Is_Type

2020-10-15 Thread Pierre-Marie de Rodat
It is excessive for Is_Type to guard a call to Is_Discrete_Type, because
both are implemented as Ekind membership test and are equally likely to
fail or succeed.

Part of a cleanup in code related to propagation of subtype predicate
flags.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* sem_ch3.adb (Access_Subprogram_Declaration): Remove extra
parens.
(Make_Index): Remove excessive calls to Is_Type.diff --git a/gcc/ada/sem_ch3.adb b/gcc/ada/sem_ch3.adb
--- a/gcc/ada/sem_ch3.adb
+++ b/gcc/ada/sem_ch3.adb
@@ -1185,7 +1185,7 @@ package body Sem_Ch3 is
 end;
  end if;
 
- if not (Is_Type (Etype (Desig_Type))) then
+ if not Is_Type (Etype (Desig_Type)) then
 Error_Msg_N
   ("expect type in function specification",
Result_Definition (T_Def));
@@ -19214,7 +19214,6 @@ package body Sem_Ch3 is
  if Nkind (Low_Bound (N)) = N_Attribute_Reference
and then Attribute_Name (Low_Bound (N)) = Name_First
and then Is_Entity_Name (Prefix (Low_Bound (N)))
-   and then Is_Type (Entity (Prefix (Low_Bound (N
and then Is_Discrete_Type (Entity (Prefix (Low_Bound (N
  then
 --  The type of the index will be the type of the prefix, as long
@@ -19266,7 +19265,6 @@ package body Sem_Ch3 is
 
  if Is_Entity_Name (Prefix (N))
and then Comes_From_Source (N)
-   and then Is_Type (Entity (Prefix (N)))
and then Is_Discrete_Type (Entity (Prefix (N)))
  then
 Def_Id := Entity (Prefix (N));




[Ada] Ada2020: AI12-0180 Using subprograms and entries in invariants

2020-10-15 Thread Pierre-Marie de Rodat
This patch implements AI12-0180, so protected subprograms and invariants
are directly visible within Invariant aspects.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* sem_ch13.adb (Visible_Component): Enable this code for task
and protected types, as well as record and private types.
* sem_ch13.ads (Replace_Type_References_Generic): Update
comment.  Move the efficiency comment into the body, because
it's about the implementation.diff --git a/gcc/ada/sem_ch13.adb b/gcc/ada/sem_ch13.adb
--- a/gcc/ada/sem_ch13.adb
+++ b/gcc/ada/sem_ch13.adb
@@ -14498,11 +14498,9 @@ package body Sem_Ch13 is
 
   function Visible_Component (Comp : Name_Id) return Entity_Id;
   --  Given an identifier in the expression, check whether there is a
-  --  discriminant or component of the type that is directy visible, and
-  --  rewrite it as the corresponding selected component of the formal of
-  --  the subprogram. The entity is located by a sequential search, which
-  --  seems acceptable given the typical size of component lists and check
-  --  expressions. Possible optimization ???
+  --  discriminant, component, protected procedure, or entry of the type
+  --  that is directy visible, and rewrite it as the corresponding selected
+  --  component of the formal of the subprogram.
 
   --
   -- Replace_Type_Ref --
@@ -14677,14 +14675,20 @@ package body Sem_Ch13 is
 
   function Visible_Component (Comp : Name_Id) return Entity_Id is
  E : Entity_Id;
-
   begin
- --  Types with nameable components are records and discriminated
- --  private types.
+ --  Types with nameable components are record, task, and protected
+ --  types, and discriminated private types.
 
- if Ekind (T) = E_Record_Type
+ if Ekind (T) in E_Record_Type
+   | E_Task_Type
+   | E_Protected_Type
or else (Is_Private_Type (T) and then Has_Discriminants (T))
  then
+--  This is a sequential search, which seems acceptable
+--  efficiency-wise, given the typical size of component
+--  lists, protected operation lists, task item lists, and
+--  check expressions.
+
 E := First_Entity (T);
 while Present (E) loop
if Comes_From_Source (E) and then Chars (E) = Comp then
@@ -14695,7 +14699,7 @@ package body Sem_Ch13 is
 end loop;
  end if;
 
- --  Nothing by that name, or the type has no components
+ --  Nothing by that name
 
  return Empty;
   end Visible_Component;


diff --git a/gcc/ada/sem_ch13.ads b/gcc/ada/sem_ch13.ads
--- a/gcc/ada/sem_ch13.ads
+++ b/gcc/ada/sem_ch13.ads
@@ -164,6 +164,11 @@ package Sem_Ch13 is
--  parameter does the actual replacement of node N, which is either a
--  simple direct reference to T, or a selected component that represents
--  an appropriately qualified occurrence of T.
+   --
+   --  This also replaces each reference to a component, entry, or protected
+   --  procedure with a selected component whose prefix is the parameter.
+   --  For example, Component_Name becomes Parameter.Component_Name, where
+   --  Parameter is the parameter, which is of type T.
 
function Rep_Item_Too_Late
  (T : Entity_Id;




[Ada] Warn on unknown aspect

2020-10-15 Thread Pierre-Marie de Rodat
Rather than generating a hard error on unknown aspects, generate a
warning which is friendlier wrt compatibility across versions and is
similar to what is done for unknown pragmas.

We keep an error when -gnatd2 is used for now, for strict conformance
until the Ada RM is also changed to allow this behavior.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* par-ch13.adb (Get_Aspect_Specifications): Generate a warning
rather than an error on unknown aspects unless -gnatd2 is used.
(Aspect_Specifications_Present): Improve detection of unknown
aspects.
* debug.adb (Debug_Flag_2): Update document.diff --git a/gcc/ada/debug.adb b/gcc/ada/debug.adb
--- a/gcc/ada/debug.adb
+++ b/gcc/ada/debug.adb
@@ -1032,6 +1032,9 @@ package body Debug is
--   flag also suppresses the additional messages explaining why a
--   non-static expression is non-static (see Sem_Eval.Why_Not_Static).
--   This avoids having to worry about these messages in ACATS testing.
+   --   Finally, this flag is also used for strict legality check, in
+   --   particular it will generate an error instead a warning when
+   --   encountering an unknown pragma.
 
--  d3   Causes Comperr to dump the contents of the node for which an abort
--   was detected (normally only the Node_Id of the node is output).


diff --git a/gcc/ada/par-ch13.adb b/gcc/ada/par-ch13.adb
--- a/gcc/ada/par-ch13.adb
+++ b/gcc/ada/par-ch13.adb
@@ -153,9 +153,7 @@ package body Ch13 is
 Result := True;
  else
 Scan; -- past identifier
-Result := Token = Tok_Arrow or else
-  Token = Tok_Comma or else
-  Token = Tok_Semicolon;
+Result := Token in Tok_Arrow | Tok_Comma | Tok_Is | Tok_Semicolon;
  end if;
 
   --  If earlier than Ada 2012, check for valid aspect identifier (possibly
@@ -178,7 +176,7 @@ package body Ch13 is
 --  defaulted True value. Further checks when analyzing aspect
 --  specification, which may include further aspects.
 
-elsif Token = Tok_Comma or else Token = Tok_Semicolon then
+elsif Token in Tok_Comma | Tok_Semicolon then
Result := True;
 
 elsif Token = Tok_Apostrophe then
@@ -265,7 +263,8 @@ package body Ch13 is
  --  The aspect mark is not recognized
 
  if A_Id = No_Aspect then
-Error_Msg_N ("& is not a valid aspect identifier", Token_Node);
+Error_Msg_Warn := not Debug_Flag_2;
+Error_Msg_N ("<<& is not a valid aspect identifier", Token_Node);
 OK := False;
 
 --  Check bad spelling
@@ -274,7 +273,7 @@ package body Ch13 is
if Is_Bad_Spelling_Of (Token_Name, Aspect_Names (J)) then
   Error_Msg_Name_1 := Aspect_Names (J);
   Error_Msg_N -- CODEFIX
-("\possible misspelling of%", Token_Node);
+("\<

[Ada] Add support for compile time evaluation of Shift_Right_Arithmetic

2020-10-15 Thread Pierre-Marie de Rodat
After recent changes to evaluate logical Shift operations at compile
time, do the same for the more complicated case of
Shift_Right_Arithmetic as well as for Shift_Right/Shift_Left for signed
integers.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* sem_eval.adb (Eval_Intrinsic_Call, Fold_Shift): Add support
for Shift_Right_Arithmetic and for signed integers.
* exp_ch4.adb (Expand_N_Op_Rotate_Left,
Expand_N_Op_Rotate_Right, Expand_N_Op_Shift_Left,
Expand_N_Op_Shift_Right_Arithmetic): Minor reformatting and code
cleanup to ensure a consistent handling. Update comments and add
assertion.diff --git a/gcc/ada/exp_ch4.adb b/gcc/ada/exp_ch4.adb
--- a/gcc/ada/exp_ch4.adb
+++ b/gcc/ada/exp_ch4.adb
@@ -10265,15 +10265,17 @@ package body Exp_Ch4 is
   --  where Bits is the shift count mod Esize (the mod operation here
   --  deals with ludicrous large shift counts, which are apparently OK).
 
-  --  What about nonbinary modulus ???
+  if Modify_Tree_For_C then
+ declare
+Loc : constant Source_Ptr := Sloc (N);
+Rtp : constant Entity_Id  := Etype (Right_Opnd (N));
+Typ : constant Entity_Id  := Etype (N);
 
-  declare
- Loc : constant Source_Ptr := Sloc (N);
- Rtp : constant Entity_Id  := Etype (Right_Opnd (N));
- Typ : constant Entity_Id  := Etype (N);
+ begin
+--  Sem_Intr should prevent getting there with a non binary modulus
+
+pragma Assert (not Non_Binary_Modulus (Typ));
 
-  begin
- if Modify_Tree_For_C then
 Rewrite (Right_Opnd (N),
   Make_Op_Rem (Loc,
 Left_Opnd  => Relocate_Node (Right_Opnd (N)),
@@ -10298,8 +10300,8 @@ package body Exp_Ch4 is
   Duplicate_Subexpr_No_Checks (Right_Opnd (N));
 
 Analyze_And_Resolve (N, Typ);
- end if;
-  end;
+ end;
+  end if;
end Expand_N_Op_Rotate_Left;
 
--
@@ -10318,22 +10320,24 @@ package body Exp_Ch4 is
   --  where Bits is the shift count mod Esize (the mod operation here
   --  deals with ludicrous large shift counts, which are apparently OK).
 
-  --  What about nonbinary modulus ???
+  if Modify_Tree_For_C then
+ declare
+Loc : constant Source_Ptr := Sloc (N);
+Rtp : constant Entity_Id  := Etype (Right_Opnd (N));
+Typ : constant Entity_Id  := Etype (N);
 
-  declare
- Loc : constant Source_Ptr := Sloc (N);
- Rtp : constant Entity_Id  := Etype (Right_Opnd (N));
- Typ : constant Entity_Id  := Etype (N);
+ begin
+--  Sem_Intr should prevent getting there with a non binary modulus
 
-  begin
- Rewrite (Right_Opnd (N),
-   Make_Op_Rem (Loc,
- Left_Opnd  => Relocate_Node (Right_Opnd (N)),
- Right_Opnd => Make_Integer_Literal (Loc, Esize (Typ;
+pragma Assert (not Non_Binary_Modulus (Typ));
+
+Rewrite (Right_Opnd (N),
+  Make_Op_Rem (Loc,
+Left_Opnd  => Relocate_Node (Right_Opnd (N)),
+Right_Opnd => Make_Integer_Literal (Loc, Esize (Typ;
 
- Analyze_And_Resolve (Right_Opnd (N), Rtp);
+Analyze_And_Resolve (Right_Opnd (N), Rtp);
 
- if Modify_Tree_For_C then
 Rewrite (N,
   Make_Op_Or (Loc,
 Left_Opnd =>
@@ -10351,8 +10355,8 @@ package body Exp_Ch4 is
   Duplicate_Subexpr_No_Checks (Right_Opnd (N));
 
 Analyze_And_Resolve (N, Typ);
- end if;
-  end;
+ end;
+  end if;
end Expand_N_Op_Rotate_Right;
 

@@ -10382,6 +10386,10 @@ package body Exp_Ch4 is
 Hi: Uint;
 
  begin
+--  Sem_Intr should prevent getting there with a non binary modulus
+
+pragma Assert (not Non_Binary_Modulus (Typ));
+
 if Compile_Time_Known_Value (Right) then
if Expr_Value (Right) >= Siz then
   Rewrite (N, Make_Integer_Literal (Loc, 0));
@@ -10439,7 +10447,14 @@ package body Exp_Ch4 is
   Binary_Op_Validity_Checks (N);
 
   --  If we are in Modify_Tree_For_C mode, there is no shift right
-  --  arithmetic in C, so we rewrite in terms of logical shifts.
+  --  arithmetic in C, so we rewrite in terms of logical shifts for
+  --  modular integers, and keep the Shift_Right intrinsic for signed
+  --  integers: even though doing a shift on a signed integer is not
+  --  fully guaranteed by the C standard, this is what C compilers
+  --  implement in practice.
+  --  Consider also taking advantage of this for modular integers by first
+  --  performing an unchecked conversion of the modular integer to a signed
+  --  integer of the same sign, and then 

Re: [PATCH] openmp: Add support for omp_get_supported_active_levels

2020-10-15 Thread Kwok Cheung Yeung

On 14/10/2020 9:20 am, Jakub Jelinek wrote:

On Tue, Oct 13, 2020 at 07:05:10PM +0100, Kwok Cheung Yeung wrote:

+* omp_get_supported_active_levels:: Maxiumum number of active levels supported


Sorry for not catching it during review, but there is a typo above.  Fixed
with patch below, committed to trunk.



Thanks.


+@node omp_get_supported_active_levels
+@section @code{omp_get_supported_active_levels} -- Maximum number of active 
regions supported


I also wonder about the different wording between the above two places,
don't you want the same wording as earlier here?



Yes, they should be the same... I think I was playing around with wording (since 
the description for omp_get_max_active_levels is 'Maximum number of active 
regions' - different by one extra word!), and forgot to make them consistent.


Maybe we should change the description of omp_get_max_active_levels to 'Current 
maximum number of active regions', to make it more obvious that it can be 
changed? 'omp_get_supported_active_levels' can then be 'Maximum number of active 
regions supported'.


Okay to apply this patch?

Kwok
commit 3f6f8808f74598e274bfb8245c08a5428ee1b3fd
Author: Kwok Cheung Yeung 
Date:   Thu Oct 15 02:32:09 2020 -0700

Amend documentation for omp_get_max_active_levels and 
omp_get_supported_active_levels

2020-10-15  Kwok Cheung Yeung  

libgomp/
* libgomp.texi (omp_get_max_active_levels): Modify description.
(omp_get_supported_active_levels): Make descriptions consistent.

diff --git a/libgomp/libgomp.texi b/libgomp/libgomp.texi
index 4a5e56f..7c6d5fd 100644
--- a/libgomp/libgomp.texi
+++ b/libgomp/libgomp.texi
@@ -167,7 +167,7 @@ linkage, and do not throw exceptions.
 * omp_get_default_device::  Get the default device for target regions
 * omp_get_dynamic:: Dynamic teams setting
 * omp_get_level::   Number of parallel regions
-* omp_get_max_active_levels::   Maximum number of active regions
+* omp_get_max_active_levels::   Current maximum number of active regions
 * omp_get_max_task_priority::   Maximum task priority value that can be set
 * omp_get_max_threads:: Maximum number of threads of parallel region
 * omp_get_nested::  Nested parallel regions
@@ -177,7 +177,7 @@ linkage, and do not throw exceptions.
 * omp_get_num_threads:: Size of the active team
 * omp_get_proc_bind::   Whether theads may be moved between CPUs
 * omp_get_schedule::Obtain the runtime scheduling method
-* omp_get_supported_active_levels:: Maximum number of active levels supported
+* omp_get_supported_active_levels:: Maximum number of active regions supported
 * omp_get_team_num::Get team number
 * omp_get_team_size::   Number of threads in a team
 * omp_get_thread_limit::Maximum number of threads
@@ -380,7 +380,7 @@ which enclose the calling call.
 
 
 @node omp_get_max_active_levels
-@section @code{omp_get_max_active_levels} -- Maximum number of active regions
+@section @code{omp_get_max_active_levels} -- Current maximum number of active 
regions
 @table @asis
 @item @emph{Description}:
 This function obtains the maximum allowed number of nested, active parallel 
regions.


[patch] vxworks: allow self configured definition of _WRS_VXWORKS_MAJOR

2020-10-15 Thread Olivier Hainque
Hello,

While performing experimental builds for testing
purposes, I had occasional uses of the possibility to
enforce a _WRS_VXWORKS_MAJOR in an environment where
it was not available from the system headers, by way
of a self-spec at configuration time.

This patch adjusts _vxworks-versions.h to help support
that.

The experiments also exposed that _WRS_VXWORKS_MINOR
is only provided when really meaningful, e.g. from
6.4 to 6.9, and that it is possibly omitted even in
very recent VxWorks 7 configurations. We just then pick
a conervative default to 0 in such cases.

Tested with a few regular build & test sequences
for VxWworks 6.9 and 7.2 in addition to the experimental
ones.

Olivier


2020-10-15  Olivier Hainque  

gcc/
* config/vxworks/_vxworks-versions.h: Only include
version.h if _WRS_VXWORKS_MAJOR is not defined.
Provide a default _WRS_VXWORKS_MINOR (0).

--- a/gcc/config/vxworks/_vxworks-versions.h
+++ b/gcc/config/vxworks/_vxworks-versions.h
@@ -22,17 +22,29 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  
If not, see
 #ifndef _VXWORKS_VERSIONS_H
 #define _VXWORKS_VERSIONS_H  1
 
-/* All we need is access to the bare _WRS_VXWORKS_MAJOR/MINOR macros
-   exposed by version.h.  Cheat a bit to make sure we don't drag additional
-   header files, which can easily cause #include ordering nightmares.  */
+/* All we need is access to the bare _WRS_VXWORKS_MAJOR/MINOR macros,
+   exposed by version.h or already provided somehow (e.g. with a self
+   spec for some reason).  When resorting to system headers, cheat a
+   bit to make sure we don't drag additional header files, which can
+   easily cause #include ordering nightmares.  */
 
+#if !defined(_WRS_VXWORKS_MAJOR)
 #pragma push_macro("_WRS_KERNEL")
 #undef _WRS_KERNEL
 #include 
 #pragma pop_macro("_WRS_KERNEL")
+#endif
+
+/* A lot depends on the MAJOR so we really need to make sure we have
+   that.  MINOR is less critical and many environments don't actually
+   define it unless it is really meaningful (e.g. 6.4 through 6.9).  */
 
 #if !defined(_WRS_VXWORKS_MAJOR)
-#error "VxWorks version macros needed but not defined"
+#error "_WRS_VXWORKS_MAJOR undefined"
+#endif
+
+#if !defined(_WRS_VXWORKS_MINOR)
+#define _WRS_VXWORKS_MINOR 0
 #endif
 
 #define _VXWORKS_MAJOR_GT(MAJOR) (_WRS_VXWORKS_MAJOR > (MAJOR))


Re: [PING][PATCH v2] combine: Don't turn (mult (extend x) 2^n) into extract [PR96998]

2020-10-15 Thread Alex Coplan via Gcc-patches
Hi Segher,

On 12/10/2020 12:14, Segher Boessenkool wrote:
> On Mon, Oct 12, 2020 at 05:19:58PM +0100, Richard Sandiford wrote:
> > 
> > I agree there's a target bug here.  Please see the explanation I posted
> > in: https://gcc.gnu.org/pipermail/gcc-patches/2020-September/554518.html
> > (especially the first sentence quoted below :-)).
> > 
> > The situation as things stand is that aarch64 has a bug: it accepts
> > an odd sign_extract representation of addresses, but doesn't accept
> > that same odd form of address as an LEA.  We have two options:
> > 
> > (a) add back instructions that recognise the odd form of LEA, or
> > (b) remove the code that accepts the odd addresses
> > 
> > I think (b) is the way to go here.
> 
> Either seems to be fine.
> 
> > But doing that on its own
> > would regress code quality.  The reason we recognised the odd
> > addresses in the first place was because that was the rtl that
> > combine happened to generate for an important case.
> > 
> > So if we go for (b) but fix the aarch64 bug strictly before the
> > combine patch, we would need to:
> 
> This is necessary to be able to evaluate what such a combine patch
> does in practice -- so there is no other way.
> 
> > (1) Apply the target fix and adjust the testsuite markup to make sure
> > that the git commit doesn't regress anyone's test results.
> 
> It is normal to regress the testsuite for a little while.
> 
> > (2) Apply the combine patch and revert the testsuite markup changes
> > from (1).
> > 
> > That seems like make-work, and would still show as a blip for
> > people doing performance tracking.
> 
> Yes, that is make-work.  Just regress the testsuite.
> 
> You do not even have to apply the target patch first (but you need to
> send it as separate patch, so that other people can test it!)
> 
> > If you prefer, we could fix the aarch64 bug and patch combine as a
> > single commit.  See:
> > 
> > https://gcc.gnu.org/pipermail/gcc-patches/2020-September/554257.html
> > 
> > for the full patch, including the aarch64 bugfix.
> 
> I need separate patches, so that I can see what the current combine
> does, without ICEing all over.  That is all.  Send it as a series of two
> patches, or something.

Apologies for the misunderstanding and my inaccurate summary in the previous
email, there is of course a target bug here as well.

I've sent the patches as a two-patch series where the first patch fixes the
AArch64 bug and the second restores code quality with the patch to combine:
https://gcc.gnu.org/pipermail/gcc-patches/2020-October/556237.html
https://gcc.gnu.org/pipermail/gcc-patches/2020-October/556238.html

Thanks,
Alex


Re: GCC 9 backports

2020-10-15 Thread Martin Liška

On 10/2/20 1:15 PM, Martin Liška wrote:

On 10/2/20 12:05 PM, Martin Liška wrote:

There are 2 more I've just tested.

Martin


and one more.

Martin


and one more.

Martin
>From 12c9413228d2955126ff5c45194f8aacf1aa81f6 Mon Sep 17 00:00:00 2001
From: Martin Liska 
Date: Tue, 13 Oct 2020 16:44:47 +0200
Subject: [PATCH] IPA: fix profile handling in IRA

gcc/ChangeLog:

	PR ipa/97295
	* profile-count.c (profile_count::to_frequency): Move part of
	gcc_assert to STATIC_ASSERT.
	* regs.h (REG_FREQ_FROM_BB): Do not use count.to_frequency for
	a function that does not have count_max initialized.

(cherry picked from commit 508e2d88a4c512e8b8685cf5ba201ad48e6bb58d)
---
 gcc/profile-count.c | 4 ++--
 gcc/regs.h  | 3 ++-
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/gcc/profile-count.c b/gcc/profile-count.c
index 8c58f8666f0..8d3340041fc 100644
--- a/gcc/profile-count.c
+++ b/gcc/profile-count.c
@@ -262,8 +262,8 @@ profile_count::to_frequency (struct function *fun) const
 return BB_FREQ_MAX;
   if (*this == profile_count::zero ())
 return 0;
-  gcc_assert (REG_BR_PROB_BASE == BB_FREQ_MAX
-	  && fun->cfg->count_max.initialized_p ());
+  STATIC_ASSERT (REG_BR_PROB_BASE == BB_FREQ_MAX);
+  gcc_assert (fun->cfg->count_max.initialized_p ());
   profile_probability prob = probability_in (fun->cfg->count_max);
   if (!prob.initialized_p ())
 return REG_BR_PROB_BASE;
diff --git a/gcc/regs.h b/gcc/regs.h
index 48b2e708160..2a19940281b 100644
--- a/gcc/regs.h
+++ b/gcc/regs.h
@@ -128,7 +128,8 @@ extern size_t reg_info_p_size;
or profile driven feedback is available and the function is never executed,
frequency is always equivalent.  Otherwise rescale the basic block
frequency.  */
-#define REG_FREQ_FROM_BB(bb) (optimize_function_for_size_p (cfun)	  \
+#define REG_FREQ_FROM_BB(bb) ((optimize_function_for_size_p (cfun)	  \
+			   || !cfun->cfg->count_max.initialized_p ()) \
 			  ? REG_FREQ_MAX  \
 			  : ((bb)->count.to_frequency (cfun)	  \
 * REG_FREQ_MAX / BB_FREQ_MAX)		  \
-- 
2.28.0



[PATCH 2/2] combine: Don't turn (mult (extend x) 2^n) into extract

2020-10-15 Thread Alex Coplan via Gcc-patches
Currently, make_extraction() identifies where we can emit an ASHIFT of
an extend in place of an extraction, but fails to make the corresponding
canonicalization/simplification when presented with a MULT by a power of
two. Such a representation is canonical when representing a left-shifted
address inside a MEM.

This patch remedies this situation: after the patch, make_extraction()
now also identifies RTXs such as:

(mult:DI (subreg:DI (reg:SI r)) (const_int 2^n))

and rewrites this as:

(mult:DI (sign_extend:DI (reg:SI r)) (const_int 2^n))

instead of using a sign_extract.

(This patch also fixes up a comment in expand_compound_operation() which
appears to have suffered from bitrot.)

This fixes several quality regressions on AArch64 after removing support for
addresses represented as sign_extract insns (1/2).

In particular, after the fix for PR96998, for the relevant testcase, we
have:

.L2:
sxtwx0, w0  // 8[c=4 l=4]  *extendsidi2_aarch64/0
add x0, x19, x0, lsl 2  // 39   [c=8 l=4]  *add_lsl_di
bl  h   // 11   [c=4 l=4]  *call_value_insn/1
b   .L2 // 54   [c=4 l=4]  jump

and after this patch, we have:

.L2:
add x0, x19, w0, sxtw 2 // 39   [c=8 l=4]  *add_extendsi_shft_di
bl  h   // 11   [c=4 l=4]  *call_value_insn/1
b   .L2 // 54   [c=4 l=4]  jump

which restores the original optimal sequence we saw before the AArch64
patch.

Testing:
 * Bootstrapped and regtested on aarch64-linux-gnu, arm-linux-gnueabihf,
   and x86_64-linux-gnu.

OK for trunk?

Thanks,
Alex

---

gcc/ChangeLog:

* combine.c (expand_compound_operation): Tweak variable name in
comment to match source.
(make_extraction): Handle mult by power of two in addition to
ashift.

---
 gcc/combine.c | 37 ++---
 1 file changed, 22 insertions(+), 15 deletions(-)
diff --git a/gcc/combine.c b/gcc/combine.c
index 4782e1d9dcc..88f3925aee7 100644
--- a/gcc/combine.c
+++ b/gcc/combine.c
@@ -7419,8 +7419,8 @@ expand_compound_operation (rtx x)
 }
 
   /* If we reach here, we want to return a pair of shifts.  The inner
- shift is a left shift of BITSIZE - POS - LEN bits.  The outer
- shift is a right shift of BITSIZE - LEN bits.  It is arithmetic or
+ shift is a left shift of MODEWIDTH - POS - LEN bits.  The outer
+ shift is a right shift of MODEWIDTH - LEN bits.  It is arithmetic or
  logical depending on the value of UNSIGNEDP.
 
  If this was a ZERO_EXTEND or ZERO_EXTRACT, this pair of shifts will be
@@ -7650,20 +7650,27 @@ make_extraction (machine_mode mode, rtx inner, HOST_WIDE_INT pos,
 	is_mode = GET_MODE (SUBREG_REG (inner));
   inner = SUBREG_REG (inner);
 }
-  else if (GET_CODE (inner) == ASHIFT
+  else if ((GET_CODE (inner) == ASHIFT || GET_CODE (inner) == MULT)
 	   && CONST_INT_P (XEXP (inner, 1))
-	   && pos_rtx == 0 && pos == 0
-	   && len > UINTVAL (XEXP (inner, 1)))
-{
-  /* We're extracting the least significant bits of an rtx
-	 (ashift X (const_int C)), where LEN > C.  Extract the
-	 least significant (LEN - C) bits of X, giving an rtx
-	 whose mode is MODE, then shift it left C times.  */
-  new_rtx = make_extraction (mode, XEXP (inner, 0),
-			 0, 0, len - INTVAL (XEXP (inner, 1)),
-			 unsignedp, in_dest, in_compare);
-  if (new_rtx != 0)
-	return gen_rtx_ASHIFT (mode, new_rtx, XEXP (inner, 1));
+	   && pos_rtx == 0 && pos == 0)
+{
+  const HOST_WIDE_INT ci = INTVAL (XEXP (inner, 1));
+  const auto code = GET_CODE (inner);
+  const HOST_WIDE_INT shift_amt = (code == MULT) ? exact_log2 (ci) : ci;
+
+  if (shift_amt > 0 && len > (unsigned HOST_WIDE_INT)shift_amt)
+	{
+	  /* We're extracting the least significant bits of an rtx
+	 (ashift X (const_int C)) or (mult X (const_int (2^C))),
+	 where LEN > C.  Extract the least significant (LEN - C) bits
+	 of X, giving an rtx whose mode is MODE, then shift it left
+	 C times.  */
+	  new_rtx = make_extraction (mode, XEXP (inner, 0),
+ 0, 0, len - shift_amt,
+ unsignedp, in_dest, in_compare);
+	  if (new_rtx)
+	return gen_rtx_fmt_ee (code, mode, new_rtx, XEXP (inner, 1));
+	}
 }
   else if (GET_CODE (inner) == TRUNCATE
 	   /* If trying or potentionally trying to extract


[PATCH 1/2] aarch64: Remove support for extract-based addresses [PR96998]

2020-10-15 Thread Alex Coplan via Gcc-patches
This patch fixes a bug in the AArch64 backend. Currently, we accept an
odd sign_extract representation of addresses, but don't accept that same
odd form of address as an LEA.

This is the cause of PR96998. In the testcase given in the PR, combine
produces:

(insn 9 8 10 3 (set (mem:SI (plus:DI (sign_extract:DI (mult:DI (subreg:DI 
(reg/v:SI 92 [ g ]) 0)
(const_int 4 [0x4]))
(const_int 34 [0x22])
(const_int 0 [0]))
(reg/f:DI 96)) [3 *i_5+0 S4 A32])
(asm_operands:SI ("") ("=Q") 0 []
 []
 [] test.c:11)) "test.c":11:5 -1
 (expr_list:REG_DEAD (reg/v:SI 92 [ g ])
(nil)))

Then LRA reloads the address and we ICE because we fail to recognize the
sign_extract:

(insn 33 8 34 3 (set (reg:DI 100)
(sign_extract:DI (ashift:DI (subreg:DI (reg/v:SI 92 [ g ]) 0)
(const_int 2 [0x2]))
(const_int 34 [0x22])
(const_int 0 [0]))) "test.c":11:5 -1
 (nil))

This patch removes the support for this sign_extract representation of
addresses, fixing PR96998.

Now this by itself will cause code quality regressions. So this patch is
paired with a follow-on patch to combine that allows us to write this
sign_extract operation as an extend instead, which will allow the
combination to go ahead with the simpler canonical form.

For the testcase in the PR, prior to the ICE being introduced, we had
the following assembly for the body of the loop (at -O2):

.L2:
add x0, x19, x0, sxtw 2 // 39   [c=8 l=4] *add_extvdi_multp2
bl  h   // 11   [c=4 l=4]  *call_value_insn/1
b   .L2 // 54   [c=4 l=4]  jump

After this patch, the ICE is fixed, but we have the less optimal:

.L2:
sxtwx0, w0  // 8[c=4 l=4]  *extendsidi2_aarch64/0
add x0, x19, x0, lsl 2  // 39   [c=8 l=4]  *add_lsl_di
bl  h   // 11   [c=4 l=4]  *call_value_insn/1
b   .L2 // 54   [c=4 l=4]  jump

The follow-on patch to combine will fix this code quality regression, as
well as the following two regressions introduced by this patch:

PASS->FAIL: gcc.target/aarch64/extend.c scan-assembler ldr\tw[0-9]+,.*sxtw #?2]
PASS->FAIL: gcc.target/aarch64/index.c scan-assembler-not [us]xtw\t

Bootstrapped and regtested on aarch64-none-linux-gnu.

OK for trunk (with follow-on patch to combine?)

Thanks,
Alex

---

gcc/ChangeLog:

PR target/96998
* config/aarch64/aarch64.c (aarch64_is_extend_from_extract): Delete.
(aarch64_classify_index): Remove extract-based address handling.
(aarch64_strip_extend): Likewise.
(aarch64_rtx_arith_op_extract_p): Likewise, remove now-unsued parameter.
Update callers...
(aarch64_rtx_costs): ... here.

gcc/testsuite/ChangeLog:

PR target/96998
* gcc.c-torture/compile/pr96998.c: New test.

---
 gcc/config/aarch64/aarch64.c  | 105 ++
 gcc/testsuite/gcc.c-torture/compile/pr96998.c |  15 +++
 2 files changed, 23 insertions(+), 97 deletions(-)
 create mode 100644 gcc/testsuite/gcc.c-torture/compile/pr96998.c
diff --git a/gcc/config/aarch64/aarch64.c b/gcc/config/aarch64/aarch64.c
index a8cc545c370..562ccd87ff7 100644
--- a/gcc/config/aarch64/aarch64.c
+++ b/gcc/config/aarch64/aarch64.c
@@ -2886,33 +2886,6 @@ aarch64_is_noplt_call_p (rtx sym)
   return false;
 }
 
-/* Return true if the offsets to a zero/sign-extract operation
-   represent an expression that matches an extend operation.  The
-   operands represent the parameters from
-
-   (extract:MODE (mult (reg) (MULT_IMM)) (EXTRACT_IMM) (const_int 0)).  */
-bool
-aarch64_is_extend_from_extract (scalar_int_mode mode, rtx mult_imm,
-rtx extract_imm)
-{
-  HOST_WIDE_INT mult_val, extract_val;
-
-  if (! CONST_INT_P (mult_imm) || ! CONST_INT_P (extract_imm))
-return false;
-
-  mult_val = INTVAL (mult_imm);
-  extract_val = INTVAL (extract_imm);
-
-  if (extract_val > 8
-  && extract_val < GET_MODE_BITSIZE (mode)
-  && exact_log2 (extract_val & ~7) > 0
-  && (extract_val & 7) <= 4
-  && mult_val == (1 << (extract_val & 7)))
-return true;
-
-  return false;
-}
-
 /* Emit an insn that's a simple single-set.  Both the operands must be
known to be valid.  */
 inline static rtx_insn *
@@ -8936,22 +8909,6 @@ aarch64_classify_index (struct aarch64_address_info *info, rtx x,
   index = XEXP (XEXP (x, 0), 0);
   shift = INTVAL (XEXP (x, 1));
 }
-  /* (sign_extract:DI (mult:DI (reg:DI) (const_int scale)) 32+shift 0) */
-  else if ((GET_CODE (x) == SIGN_EXTRACT
-	|| GET_CODE (x) == ZERO_EXTRACT)
-	   && GET_MODE (x) == DImode
-	   && GET_CODE (XEXP (x, 0)) == MULT
-	   && GET_MODE (XEXP (XEXP (x, 0), 0)) == DImode
-	   && CONST_INT_P (XEXP (XEXP (x, 0), 1)))
-{
-  type = (GET_CODE (x) == SIGN_EXTRACT)
-	? ADDRESS_REG_SXTW : ADDRESS_REG_UXTW;
-  index = XEXP (XEXP (x, 

Re: [PATCH, rs6000] Add non-relative jump table support on Power Linux

2020-10-15 Thread HAO CHEN GUI via Gcc-patches

Segher,

    I re-wrote the patch based on parameterized name.

    The attachments are the patch diff file and change log file.

    Bootstrapped and tested on powerpc64le-linux-gnu with no 
regressions.  Is this okay for trunk? Any recommendations? Thanks a lot.



On 29/9/2020 上午 6:46, Segher Boessenkool wrote:

Hi hao Chen,

On Wed, Sep 09, 2020 at 04:55:29PM +0800, HAO CHEN GUI wrote:

     Thanks for your advice. I removed macros defined in linux64.h and
linux.h. So they take relative jump tables by default. When
no-relative-jumptables is set, the absolute jump tables are taken. All
things relevant to section relocations are put in another patch. Thanks
again.

[ Please do not insert patches into discussions ]


+/* Implement TARGET_ASM_GENERATE_PIC_ADDR_DIFF_VEC.
+   Return true if rs6000_relative_jumptables is set.  */

Don't just say what the code does (we can see that ;-) ); say *why*.
Of course it is terribly simple in this case, so maybe just that first
line is plenty.


+/* Specify the machine mode that this machine uses
+   for the index in the tablejump instruction.  */
+#define CASE_VECTOR_MODE \
+  (TARGET_32BIT || rs6000_relative_jumptables ? SImode : Pmode)

If TARGET_32BIT is true, SImode and Pmode are the same, so this is
simpler said as

#define CASE_VECTOR_MODE (rs6000_relative_jumptables ? SImode : Pmode)


I'll have the tablejump* patterns converted to paremeterized names
hopefully tonight or tomorrow, which will make your patch much easier
to read.  It looks like it will be fine, thanks :-)


Segher
* config/rs6000/rs6000-protos.h (rs6000_output_addr_vec_elt): Declare.
* config/rs6000/rs6000.c (TARGET_ASM_GENERATE_PIC_ADDR_DIFF_VEC):
Define.
(rs6000_gen_pic_addr_diff_vec, rs6000_output_addr_vec_elt): Implement.
* config/rs6000/rs6000.h (CASE_VECTOR_PC_RELATIVE,
CASE_VECTOR_MODE, ASM_OUTPUT_ADDR_VEC_ELT): Define.
* config/rs6000/rs6000.md (tablejump_absolute,
tablejump_absolute_nospec): New expanders.
* config/rs6000/rs6000.opt (mrelative-jumptables): Add
mrelative-jumptables.
diff --git a/gcc/config/rs6000/rs6000-protos.h 
b/gcc/config/rs6000/rs6000-protos.h
index 25fa5dd57cd..49ab51042c5 100644
--- a/gcc/config/rs6000/rs6000-protos.h
+++ b/gcc/config/rs6000/rs6000-protos.h
@@ -155,6 +155,7 @@ extern void rs6000_split_logical (rtx [], enum rtx_code, 
bool, bool, bool);
 extern bool rs6000_function_pcrel_p (struct function *);
 extern bool rs6000_pcrel_p (void);
 extern bool rs6000_fndecl_pcrel_p (const_tree);
+extern void rs6000_output_addr_vec_elt (FILE *, int);
 
 /* Different PowerPC instruction formats that are used by GCC.  There are
various other instruction formats used by the PowerPC hardware, but these
diff --git a/gcc/config/rs6000/rs6000.c b/gcc/config/rs6000/rs6000.c
index b58eeae2b98..7e441f7e730 100644
--- a/gcc/config/rs6000/rs6000.c
+++ b/gcc/config/rs6000/rs6000.c
@@ -1367,6 +1367,9 @@ static const struct attribute_spec 
rs6000_attribute_table[] =
 #undef TARGET_ASM_OUTPUT_ADDR_CONST_EXTRA
 #define TARGET_ASM_OUTPUT_ADDR_CONST_EXTRA rs6000_output_addr_const_extra
 
+#undef  TARGET_ASM_GENERATE_PIC_ADDR_DIFF_VEC
+#define TARGET_ASM_GENERATE_PIC_ADDR_DIFF_VEC rs6000_gen_pic_addr_diff_vec
+
 #undef TARGET_LEGITIMIZE_ADDRESS
 #define TARGET_LEGITIMIZE_ADDRESS rs6000_legitimize_address
 
@@ -27053,6 +27056,27 @@ rs6000_emit_xxspltidp_v2df (rtx dst, long value)
   emit_insn( gen_xxspltidp_v2df_inst (dst, GEN_INT (value)));
 }
 
+/* Implement TARGET_ASM_GENERATE_PIC_ADDR_DIFF_VEC.
+   Marco relative jumpstables indicates addr_diff_vec or addr_vec.  */
+
+static bool
+rs6000_gen_pic_addr_diff_vec (void)
+{
+  return rs6000_relative_jumptables;
+}
+
+void
+rs6000_output_addr_vec_elt (FILE *file, int value)
+{
+  const char *directive = TARGET_64BIT ? DOUBLE_INT_ASM_OP : "\t.long\t";
+  char buf[100];
+
+  fprintf (file, "%s", directive);
+  ASM_GENERATE_INTERNAL_LABEL (buf, "L", value);
+  assemble_name (file, buf);
+  fprintf (file, "\n");
+}
+
 struct gcc_target targetm = TARGET_INITIALIZER;
 
 #include "gt-rs6000.h"
diff --git a/gcc/config/rs6000/rs6000.h b/gcc/config/rs6000/rs6000.h
index bbd8060e143..4a948e25f71 100644
--- a/gcc/config/rs6000/rs6000.h
+++ b/gcc/config/rs6000/rs6000.h
@@ -1754,15 +1754,15 @@ typedef struct rs6000_args
 
 /* #define LEGITIMATE_PIC_OPERAND_P (X) */
 
-/* Specify the machine mode that this machine uses
-   for the index in the tablejump instruction.  */
-#define CASE_VECTOR_MODE SImode
-
 /* Define as C expression which evaluates to nonzero if the tablejump
instruction expects the table to contain offsets from the address of the
table.
Do not define this if the table should contain absolute addresses.  */
-#define CASE_VECTOR_PC_RELATIVE 1
+#define CASE_VECTOR_PC_RELATIVE rs6000_relative_jumptables
+
+/* Specify the machine mode that this machine uses
+   for the index in the tablejump instruction.  */
+#define CASE_VECTOR_MODE 

Re: GCC 10 backports

2020-10-15 Thread Martin Liška

And one more patch I've just tested.

Martin
>From 13febeded26dd6e00f57b39b48520e049209651b Mon Sep 17 00:00:00 2001
From: Martin Liska 
Date: Tue, 13 Oct 2020 16:44:47 +0200
Subject: [PATCH] IPA: fix profile handling in IRA

gcc/ChangeLog:

	PR ipa/97295
	* profile-count.c (profile_count::to_frequency): Move part of
	gcc_assert to STATIC_ASSERT.
	* regs.h (REG_FREQ_FROM_BB): Do not use count.to_frequency for
	a function that does not have count_max initialized.

(cherry picked from commit 508e2d88a4c512e8b8685cf5ba201ad48e6bb58d)
---
 gcc/profile-count.c | 4 ++--
 gcc/regs.h  | 3 ++-
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/gcc/profile-count.c b/gcc/profile-count.c
index c89914ff8a0..aaefc11ff3d 100644
--- a/gcc/profile-count.c
+++ b/gcc/profile-count.c
@@ -270,8 +270,8 @@ profile_count::to_frequency (struct function *fun) const
 return BB_FREQ_MAX;
   if (*this == zero ())
 return 0;
-  gcc_assert (REG_BR_PROB_BASE == BB_FREQ_MAX
-	  && fun->cfg->count_max.initialized_p ());
+  STATIC_ASSERT (REG_BR_PROB_BASE == BB_FREQ_MAX);
+  gcc_assert (fun->cfg->count_max.initialized_p ());
   profile_probability prob = probability_in (fun->cfg->count_max);
   if (!prob.initialized_p ())
 return REG_BR_PROB_BASE;
diff --git a/gcc/regs.h b/gcc/regs.h
index 1decd2c2d2a..11416c47f6f 100644
--- a/gcc/regs.h
+++ b/gcc/regs.h
@@ -128,7 +128,8 @@ extern size_t reg_info_p_size;
or profile driven feedback is available and the function is never executed,
frequency is always equivalent.  Otherwise rescale the basic block
frequency.  */
-#define REG_FREQ_FROM_BB(bb) (optimize_function_for_size_p (cfun)	  \
+#define REG_FREQ_FROM_BB(bb) ((optimize_function_for_size_p (cfun)	  \
+			   || !cfun->cfg->count_max.initialized_p ()) \
 			  ? REG_FREQ_MAX  \
 			  : ((bb)->count.to_frequency (cfun)	  \
 * REG_FREQ_MAX / BB_FREQ_MAX)		  \
-- 
2.28.0



[committed][nvptx, testsuite] Remove dg-skip-if for ptxas oom

2020-10-15 Thread Tom de Vries
Hi,

There's a dg-skip-if for nvptx that is related to ptxas oom.

If I remove it, the test-case passes for me (with ptxas from cuda 9.1).

I've tested it on a range of cudas, from 5.0 to 11.1 and did not
manage to reproduce the fail.

Remove the dg-skip-if.  Tested on nvptx.

Committed to trunk.

Thanks,
- Tom

[nvptx, testsuite] Remove dg-skip-if for ptxas oom

gcc/testsuite/ChangeLog:

2020-10-15  Tom de Vries  

* gcc.c-torture/compile/limits-externdecl.c: Remove dg-skip-if for
nvptx.

---
 gcc/testsuite/gcc.c-torture/compile/limits-externdecl.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/gcc/testsuite/gcc.c-torture/compile/limits-externdecl.c 
b/gcc/testsuite/gcc.c-torture/compile/limits-externdecl.c
index d3828015a75..3a2e5ac19b9 100644
--- a/gcc/testsuite/gcc.c-torture/compile/limits-externdecl.c
+++ b/gcc/testsuite/gcc.c-torture/compile/limits-externdecl.c
@@ -1,4 +1,3 @@
-/* { dg-skip-if "ptxas runs out of memory" { nvptx-*-* } } */
 /* { dg-skip-if "Array too big" { "pdp11-*-*" } { "-mint32" } } */
 
 /* { dg-require-effective-target int32plus } */


[committed][nvptx, testsuite] Remove xfail for PR84958

2020-10-15 Thread Tom de Vries
Hi,

The xfail in gcc.dg/tree-ssa/pr84512.c for PR84958 has started to xpass,
presumably because of commit 744fd446c32 "tree-ssa-sccvn.c (class pass_fre):
Add may_iterate pass parameter".

Remove the xfail.  Tested on nvptx.

Committed to trunk.

Thanks,
- Tom

[nvptx, testsuite] Remove xfail for PR84958

gcc/testsuite/ChangeLog:

2020-10-15  Tom de Vries  

* gcc.dg/tree-ssa/pr84512.c: Remove xfail for nvptx.

---
 gcc/testsuite/gcc.dg/tree-ssa/pr84512.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr84512.c 
b/gcc/testsuite/gcc.dg/tree-ssa/pr84512.c
index 48d829afa6e..3c027012670 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/pr84512.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/pr84512.c
@@ -13,4 +13,4 @@ int foo()
 }
 
 /* Listed targets xfailed due to PR84958.  */
-/* { dg-final { scan-tree-dump "return 285;" "optimized" { xfail { amdgcn*-*-* 
nvptx*-*-* } } } } */
+/* { dg-final { scan-tree-dump "return 285;" "optimized" { xfail { amdgcn*-*-* 
} } } } */


[committed][nvptx, testsuite] Fix xpass with ident-0b.c

2020-10-15 Thread Tom de Vries
Hi,

For nvptx, I see:
...
XPASS: c-c++-common/ident-0b.c  -Wc++-compat   scan-assembler-not GCC:
...

Fix this by requiring effective target ident_directive.  Tested on nvptx.

Committed to trunk.

Thanks,
- Tom

[nvptx, testsuite] Fix xpass with ident-0b.c

gcc/testsuite/ChangeLog:

2020-10-15  Tom de Vries  

* c-c++-common/ident-0b.c: Require effective target ident_directive.

---
 gcc/testsuite/c-c++-common/ident-0b.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/gcc/testsuite/c-c++-common/ident-0b.c 
b/gcc/testsuite/c-c++-common/ident-0b.c
index 67b593c63ad..b46d85010d9 100644
--- a/gcc/testsuite/c-c++-common/ident-0b.c
+++ b/gcc/testsuite/c-c++-common/ident-0b.c
@@ -2,6 +2,7 @@
  * Make sure scan-assembler-not turns off .ident unless -fident in testcase */
 /* { dg-do compile } */
 /* { dg-options "-fident" } */
+/* { dg-require-effective-target ident_directive }*/
 /* { dg-skip-if "no assembler .ident support" { { hppa*-*-hpux* && { ! lp64 } 
} || powerpc*-*-darwin* } } */
 int i;
 


[committed][nvptx, testsuite] Disable default xfails

2020-10-15 Thread Tom de Vries
Hi,

For nvptx, I run into a couple of XPASSes due to nvptx not being listed in:
...
  { xfail { ! { long list of targets } } }
...

Add nvptx to the list to get a PASS.  Tested on nvptx.

Committed to trunk.

Thanks,
- Tom

[nvptx, testsuite] Disable default xfails

gcc/testsuite/ChangeLog:

2020-10-15  Tom de Vries  

* gcc.dg/attr-alloc_size-11.c: Don't xfail for nvptx.
* gcc.dg/tree-ssa/20040204-1.c: Same.

---
 gcc/testsuite/gcc.dg/attr-alloc_size-11.c  | 4 ++--
 gcc/testsuite/gcc.dg/tree-ssa/20040204-1.c | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/attr-alloc_size-11.c 
b/gcc/testsuite/gcc.dg/attr-alloc_size-11.c
index a3d95c4e587..8332b39930c 100644
--- a/gcc/testsuite/gcc.dg/attr-alloc_size-11.c
+++ b/gcc/testsuite/gcc.dg/attr-alloc_size-11.c
@@ -47,8 +47,8 @@ typedef __SIZE_TYPE__size_t;
 
 /* The following tests fail because of missing range information.  The xfail
exclusions are PR79356.  */
-TEST (signed char, SCHAR_MIN + 2, ALLOC_MAX);   /* { dg-warning "argument 1 
range \\\[13, \[0-9\]+\\\] exceeds maximum object size 12" "missing range info 
for signed char" { xfail { ! { aarch64*-*-* arm*-*-* avr-*-* alpha*-*-* 
ia64-*-* mips*-*-* or1k*-*-* pdp11*-*-* powerpc*-*-* sparc*-*-* s390*-*-* 
visium-*-* msp430-*-* } } } } */
-TEST (short, SHRT_MIN + 2, ALLOC_MAX); /* { dg-warning "argument 1 range 
\\\[13, \[0-9\]+\\\] exceeds maximum object size 12" "missing range info for 
short" { xfail { ! { aarch64*-*-* arm*-*-* alpha*-*-* avr-*-* ia64-*-* 
mips*-*-* or1k*-*-* pdp11*-*-* powerpc*-*-* sparc*-*-* s390x-*-* visium-*-* 
msp430-*-* } } } } */
+TEST (signed char, SCHAR_MIN + 2, ALLOC_MAX);   /* { dg-warning "argument 1 
range \\\[13, \[0-9\]+\\\] exceeds maximum object size 12" "missing range info 
for signed char" { xfail { ! { aarch64*-*-* arm*-*-* avr-*-* alpha*-*-* 
ia64-*-* mips*-*-* or1k*-*-* pdp11*-*-* powerpc*-*-* sparc*-*-* s390*-*-* 
visium-*-* msp430-*-* nvptx*-*-*} } } } */
+TEST (short, SHRT_MIN + 2, ALLOC_MAX); /* { dg-warning "argument 1 range 
\\\[13, \[0-9\]+\\\] exceeds maximum object size 12" "missing range info for 
short" { xfail { ! { aarch64*-*-* arm*-*-* alpha*-*-* avr-*-* ia64-*-* 
mips*-*-* or1k*-*-* pdp11*-*-* powerpc*-*-* sparc*-*-* s390x-*-* visium-*-* 
msp430-*-* nvptx*-*-* } } } } */
 TEST (int, INT_MIN + 2, ALLOC_MAX);/* { dg-warning "argument 1 range 
\\\[13, \[0-9\]+\\\] exceeds maximum object size 12" } */
 TEST (int, -3, ALLOC_MAX); /* { dg-warning "argument 1 range 
\\\[13, \[0-9\]+\\\] exceeds maximum object size 12" } */
 TEST (int, -2, ALLOC_MAX); /* { dg-warning "argument 1 range 
\\\[13, \[0-9\]+\\\] exceeds maximum object size 12" } */
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/20040204-1.c 
b/gcc/testsuite/gcc.dg/tree-ssa/20040204-1.c
index b7d50ecd6d6..b9f8fd21ac9 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/20040204-1.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/20040204-1.c
@@ -33,4 +33,4 @@ void test55 (int x, int y)
that the && should be emitted (based on BRANCH_COST).  Fix this
by teaching dom to look through && and register all components
as true.  */
-/* { dg-final { scan-tree-dump-times "link_error" 0 "optimized" { xfail { ! 
"alpha*-*-* arm*-*-* aarch64*-*-* powerpc*-*-* cris-*-* hppa*-*-* i?86-*-* 
mmix-*-* mips*-*-* m68k*-*-* moxie-*-* nds32*-*-* s390*-*-* sh*-*-* sparc*-*-* 
visium-*-* x86_64-*-* riscv*-*-* or1k*-*-* msp430-*-* pru*-*-*" } } } } */
+/* { dg-final { scan-tree-dump-times "link_error" 0 "optimized" { xfail { ! 
"alpha*-*-* arm*-*-* aarch64*-*-* powerpc*-*-* cris-*-* hppa*-*-* i?86-*-* 
mmix-*-* mips*-*-* m68k*-*-* moxie-*-* nds32*-*-* s390*-*-* sh*-*-* sparc*-*-* 
visium-*-* x86_64-*-* riscv*-*-* or1k*-*-* msp430-*-* pru*-*-* nvptx*-*-*" } } 
} } */


[committed][nvptx, testsuite] Remove dg-skip-if for ptxas crashes

2020-10-15 Thread Tom de Vries
Hi,

There's a dg-skip-if for nvptx that is related to a ptxas crash.

If I remove it, the test-case passes for me (with ptxas from cuda 9.1).

I've tested this on a range of cudas, from 5.0 to 11.1 and did not
manage to reproduce the fail.

Remove the dg-skip-if.  Tested on nvptx.

Committed to trunk.

Thanks,
- Tom

[nvptx, testsuite] Remove dg-skip-if for ptxas crashes

gcc/testsuite/ChangeLog:

2020-10-15  Tom de Vries  

* gcc.c-torture/execute/981019-1.c: Remove dg-skip-if for nvptx.

---
 gcc/testsuite/gcc.c-torture/execute/981019-1.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/gcc/testsuite/gcc.c-torture/execute/981019-1.c 
b/gcc/testsuite/gcc.c-torture/execute/981019-1.c
index 1cf3741dc0e..5d1f009009b 100644
--- a/gcc/testsuite/gcc.c-torture/execute/981019-1.c
+++ b/gcc/testsuite/gcc.c-torture/execute/981019-1.c
@@ -1,5 +1,3 @@
-/* { dg-skip-if "ptxas seg faults" { nvptx-*-* } { "-O3*" } { "" } } */
-
 extern int f2(void);
 extern int f3(void);
 extern void f1(void);


[committed][nvptx, testsuite] Remove dg-skip-if for ptxas crash fixed in cuda 8.0

2020-10-15 Thread Tom de Vries
Hi,

The test-case gcc.c-torture/execute/pr68185.c has a dg-skip-if for nvptx due
to "ptxas crashes or executes incorrectly".

I've managed to reproduce the problem using cuda 7.5:
...
FAIL: gcc.c-torture/execute/pr68185.c   -O0  (test for excess errors)
Excess errors:
nvptx-as: ptxas terminated with signal 11 [Segmentation fault], core dumped
...
but it's fixed starting cuda 8.0.

Remove the dg-skip-if.  Tested on nvptx.

Committed to trunk.

Thanks,
- Tom

[nvptx, testsuite] Remove dg-skip-if for ptxas crash fixed in cuda 8.0

gcc/testsuite/ChangeLog:

2020-10-15  Tom de Vries  

* gcc.c-torture/execute/pr68185.c: Remove dg-skip-if for nvptx.

---
 gcc/testsuite/gcc.c-torture/execute/pr68185.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/gcc/testsuite/gcc.c-torture/execute/pr68185.c 
b/gcc/testsuite/gcc.c-torture/execute/pr68185.c
index a41a557df95..d82fd0ad2f7 100644
--- a/gcc/testsuite/gcc.c-torture/execute/pr68185.c
+++ b/gcc/testsuite/gcc.c-torture/execute/pr68185.c
@@ -1,4 +1,3 @@
-/* { dg-skip-if "ptxas crashes or executes incorrectly" { nvptx-*-* } { "-O0" 
"-Os" } { "" } } Reported 2015-11-20  */
 
 int a, b, d = 1, e, f, o, u, w = 1, z;
 short c, q, t;


[committed][nvptx, testsuite] Remove xpassing xfails for ptxas crashes

2020-10-15 Thread Tom de Vries
Hi,

There's a couple of nvptx xfails that are related to ptxas crashes,
which are xpassing for me (with ptxas from cuda 9.1).

I've tested these on a range of cudas, from 5.0 to 11.1 and did not
manage to reproduce the fails.

Remove the xfails.  Tested on nvptx.

Committed to trunk.

Thanks,
- Tom

[nvptx, testsuite] Remove xpassing xfails for ptxas crashes

gcc/testsuite/ChangeLog:

2020-10-15  Tom de Vries  

* gcc.c-torture/compile/pr42717.c: Remove nvptx xfail.
* gcc.c-torture/compile/pr61684.c: Same.
* gcc.c-torture/execute/pr20601-1.c: Same.
* gcc.c-torture/execute/pr52129.c: Same.
* gcc.c-torture/execute/pr59221.c: Same.
* gcc.dg/pr68671.c: Same.

---
 gcc/testsuite/gcc.c-torture/compile/pr42717.c   | 1 -
 gcc/testsuite/gcc.c-torture/compile/pr61684.c   | 1 -
 gcc/testsuite/gcc.c-torture/execute/pr20601-1.c | 1 -
 gcc/testsuite/gcc.c-torture/execute/pr52129.c   | 1 -
 gcc/testsuite/gcc.c-torture/execute/pr59221.c   | 1 -
 gcc/testsuite/gcc.dg/pr68671.c  | 1 -
 6 files changed, 6 deletions(-)

diff --git a/gcc/testsuite/gcc.c-torture/compile/pr42717.c 
b/gcc/testsuite/gcc.c-torture/compile/pr42717.c
index 7f6fb9db5cf..4fe6f93e797 100644
--- a/gcc/testsuite/gcc.c-torture/compile/pr42717.c
+++ b/gcc/testsuite/gcc.c-torture/compile/pr42717.c
@@ -1,4 +1,3 @@
-/* { dg-xfail-if "ptxas crashes" { nvptx-*-* } { "-O0" } { "" } } */
 static signed char
 foo (signed char si1, unsigned char si2)
 {
diff --git a/gcc/testsuite/gcc.c-torture/compile/pr61684.c 
b/gcc/testsuite/gcc.c-torture/compile/pr61684.c
index 9a7b52feb9e..f5b53b73a0d 100644
--- a/gcc/testsuite/gcc.c-torture/compile/pr61684.c
+++ b/gcc/testsuite/gcc.c-torture/compile/pr61684.c
@@ -1,5 +1,4 @@
 /* PR tree-optimization/61684 */
-/* { dg-xfail-if "ptxas crashes" { nvptx-*-* } { "*" } { "-O0" "-O1" "-Os" } } 
*/
 
 int a, c;
 static int *b = 0;
diff --git a/gcc/testsuite/gcc.c-torture/execute/pr20601-1.c 
b/gcc/testsuite/gcc.c-torture/execute/pr20601-1.c
index 6eab1ef1ea7..7c13c913819 100644
--- a/gcc/testsuite/gcc.c-torture/execute/pr20601-1.c
+++ b/gcc/testsuite/gcc.c-torture/execute/pr20601-1.c
@@ -1,5 +1,4 @@
 /* PR tree-optimization/20601 */
-/* { dg-xfail-if "ptxas crashes" { nvptx-*-* } { "-O1" } { "" } } */
 extern void abort (void);
 extern void exit (int);
 
diff --git a/gcc/testsuite/gcc.c-torture/execute/pr52129.c 
b/gcc/testsuite/gcc.c-torture/execute/pr52129.c
index ab43ca60cfe..a60bfa8bb6a 100644
--- a/gcc/testsuite/gcc.c-torture/execute/pr52129.c
+++ b/gcc/testsuite/gcc.c-torture/execute/pr52129.c
@@ -1,5 +1,4 @@
 /* PR target/52129 */
-/* { dg-xfail-if "ptxas crashes" { nvptx-*-* } { "-O1" } { "" } } */
 
 extern void abort (void);
 struct S { void *p; unsigned int q; };
diff --git a/gcc/testsuite/gcc.c-torture/execute/pr59221.c 
b/gcc/testsuite/gcc.c-torture/execute/pr59221.c
index b3072271bfb..0cd425948fc 100644
--- a/gcc/testsuite/gcc.c-torture/execute/pr59221.c
+++ b/gcc/testsuite/gcc.c-torture/execute/pr59221.c
@@ -1,4 +1,3 @@
-/* { dg-xfail-if "ptxas crashes" { nvptx-*-* } { "*" } { "-O0" "-Os" } } */
 
 
 int a = 1, b, d;
diff --git a/gcc/testsuite/gcc.dg/pr68671.c b/gcc/testsuite/gcc.dg/pr68671.c
index 9b473ca8f00..bec4639f80a 100644
--- a/gcc/testsuite/gcc.dg/pr68671.c
+++ b/gcc/testsuite/gcc.dg/pr68671.c
@@ -1,7 +1,6 @@
 /* PR tree-optimization/68671 */
 /* { dg-do run } */
 /* { dg-options " -O2 -fno-tree-dce" } */
-/* { dg-xfail-if "ptxas crashes" { nvptx-*-* } } */
 
 volatile int a = -1;
 volatile int b;


Re: Handle POINTER_PLUS_EXPR in jump functions

2020-10-15 Thread Jakub Jelinek via Gcc-patches
On Wed, Oct 14, 2020 at 03:40:33PM +0200, Jan Hubicka wrote:
> this patch adds logic to handle POINTER_PLUS_EXPR in compute_parm_map
> that I originally did not since I tought that all such adjustments are
> done by ancestor function.
> 
> Bootstrapped/regtested x86_64-linux, will commit it shortly.
> Honza
> 
> gcc/ChangeLog:
> 
> 2020-10-14  Jan Hubicka  
> 
>   * ipa-modref.c (compute_parm_map): Handle POINTER_PLUS_EXPR in
>   PASSTHROUGH.
> 
> gcc/testsuite/ChangeLog:
> 
> 2020-10-14  Jan Hubicka  
> 
>   * gcc.dg/ipa/modref-1.c: New test.
>   * gcc.dg/tree-ssa/modref-4.c: New test.

Both of these tests FAIL everywhere:
FAIL: gcc.dg/ipa/modref-1.c (test for excess errors)
FAIL: gcc.dg/ipa/modref-1.c scan-ipa-dump modref "param offset: 1"
FAIL: gcc.dg/ipa/modref-1.c scan-ipa-dump modref "param offset: 2"
FAIL: gcc.dg/tree-ssa/modref-4.c (test for excess errors)
FAIL: gcc.dg/tree-ssa/modref-4.c scan-tree-dump modref1 "param offset: 1"
UNRESOLVED: gcc.dg/tree-ssa/modref-4.c scan-tree-dump modref2 "param offset: 2"
UNRESOLVED: gcc.dg/tree-ssa/modref-4.c scan-tree-dump modref2 "return 0"

I've tried to fix most of things, but
FAIL: gcc.dg/tree-ssa/modref-4.c scan-tree-dump modref1 "return 0"
remains (it isn't even optimized in optimized dump).

Committed to trunk as obvious anyway, but please tweak the modref-4.c
test according to what you meant.

2020-10-15  Jakub Jelinek  

* gcc.dg/ipa/modref-1.c: Remove space between param offset: and number
in scan-ipa-dump.
(b): Declare return type to void.
(main): Declare return type to int.  Change c to array of 3 chars.
* gcc.dg/tree-ssa/modref-4.c: Remove space between param offset: and
number in scan-ipa-dump.  Use modref1 instead of modref2.
(b): Declare return type to void.
(main): Declare return type to int.  Change c to array of 3 chars.

--- gcc/testsuite/gcc.dg/ipa/modref-1.c.jj  2020-10-14 17:03:00.302245922 
+0200
+++ gcc/testsuite/gcc.dg/ipa/modref-1.c 2020-10-15 10:13:43.044535887 +0200
@@ -8,16 +8,17 @@ void a(char *ptr, char *ptr2)
 }
 
 __attribute__((noinline))
-b(char *ptr)
+void b(char *ptr)
 {
   a(ptr+1,[2]);
 }
-main()
+
+int main()
 {
-  char c[2]={0,1,0};
+  char c[3]={0,1,0};
   b(c);
   return c[0]+c[2];
 }
 /* Check that both param offsets are determined correctly.  */
-/* { dg-final { scan-ipa-dump "param offset: 1" "modref"  } } */
-/* { dg-final { scan-ipa-dump "param offset: 2" "modref"  } } */
+/* { dg-final { scan-ipa-dump "param offset:1" "modref"  } } */
+/* { dg-final { scan-ipa-dump "param offset:2" "modref"  } } */
--- gcc/testsuite/gcc.dg/tree-ssa/modref-4.c.jj 2020-10-14 17:03:00.333245482 
+0200
+++ gcc/testsuite/gcc.dg/tree-ssa/modref-4.c2020-10-15 10:12:14.039825998 
+0200
@@ -8,18 +8,19 @@ void a(char *ptr, char *ptr2)
 }
 
 __attribute__((noinline))
-b(char *ptr)
+void b(char *ptr)
 {
   a(ptr+1,[2]);
 }
-main()
+
+int main()
 {
-  char c[2]={0,1,0};
+  char c[3]={0,1,0};
   b(c);
   return c[0]+c[2];
 }
 /* Check that both param offsets are determined correctly and the computation
is optimized out.  */
-/* { dg-final { scan-tree-dump "param offset: 1" "modref1"  } } */
-/* { dg-final { scan-tree-dump "param offset: 2" "modref2"  } } */
-/* { dg-final { scan-tree-dump "return 0" "modref2"  } } */
+/* { dg-final { scan-tree-dump "param offset:1" "modref1"  } } */
+/* { dg-final { scan-tree-dump "param offset:2" "modref1"  } } */
+/* { dg-final { scan-tree-dump "return 0" "modref1"  } } */

Jakub



Re: [PATCH] [PR rtl-optimization/97249]Simplify vec_select of paradoxical subreg.

2020-10-15 Thread Hongtao Liu via Gcc-patches
On Thu, Oct 15, 2020 at 1:37 AM Segher Boessenkool
 wrote:
>
> Hi!
>
> On Wed, Oct 14, 2020 at 01:43:45PM +0800, Hongtao Liu wrote:
> > On Wed, Oct 14, 2020 at 4:01 AM Segher Boessenkool
> >  wrote:
> > > On Tue, Oct 13, 2020 at 04:40:53PM +0800, Hongtao Liu wrote:
> > > >   For rtx like
> > > >   (vec_select:V2SI (subreg:V4SI (inner:V2SI) 0)
> > > >(parallel [(const_int 0) (const_int 1)]))
> > > >  it could be simplified as inner.
> > >
> > > You could even simplify any vec_select of a subreg of X to just a
> > > vec_select of X, by changing the selection vector a bit (well, only do
> >
> > Yes, when SUBREG_BYTE of trueop0 is not 0, we need to add offset to 
> > selection.
>
> Exactly.
>
> > > this if that is a constant vector, I suppose).  Not just for paradoxical
> > > subregs either, just for *all* subregs.
> >
> > Yes, and only when X has the same inner mode and more elements.
>
> No, for *all*.  The mode of the first argument of vec_select does not
> have to equal its result mode.
>
> Any (constant indices) vec_select of a subreg can be written as just a
> vec_select.
>
> > +   /* Simplify vec_select of a subreg of X to just a vec_select of X
> > +  when available.  */
>
> What does "when available" mean here?
>

When X has same component mode as vec_select, i'll add this to comments.

> > +   int l2;
> > +   if (GET_CODE (trueop0) == SUBREG
> > +   && (GET_MODE_INNER (mode)
> > +   == GET_MODE_INNER (GET_MODE (XEXP (trueop0, 0
>
> Don't use unnecessary parens here please, it makes it harder to read
> (there are quite enough parens already :-) )
>

Yes.

> > +   gcc_assert (can_div_trunc_p (SUBREG_BYTE (trueop0),
> > +GET_MODE_SIZE (GET_MODE_INNER 
> > (mode)),
> > +_offset));
>
> Why is this needed?

I only found this interface for poly_uint64 division to get subreg_offset.

>
> > +   bool success = true;
> > +   for (int i = 0;i != l1; i++)
>
> (space after ; )
>
> > + {
> > +   rtx j = XVECEXP (trueop1, 0, i);
>
> (i and j and k ususally are integers, not rtx)
>
> > +   if (!CONST_INT_P (j)
> > +   || known_ge (UINTVAL (j), l2 - subreg_offset))
> > + {
> > +   success = false;
> > +   break;
> > + }
> > + }
>
> You don't have to test if the input RTL is valid.  You can assume it is.
>

This test is for something like (vec_select:v2di (subreg:v4di
(reg:v2di) 0)(parallel [ (const_int 2) (const_int 3)])).
const_int 2 here is out of range. Are you meaning the upper rtx wouldn't exist?

> > +   if (success)
> > + {
> > +   rtx par = trueop1;
> > +   if (subreg_offset)
> > + {
> > +   rtvec vec = rtvec_alloc (l1);
> > +   for (int i = 0; i < l1; i++)
> > + RTVEC_ELT (vec, i)
> > +   = GEN_INT (INTVAL (XVECEXP (trueop1, 0, i)
> > +  + subreg_offset));
> > +   par = gen_rtx_PARALLEL (VOIDmode, vec);
> > + }
> > +   return gen_rtx_VEC_SELECT (mode, XEXP (trueop0, 0), par);
> > + }
> > + }
>
> subreg_offset will differ in meaning if big-endian; is this correct
Yes.
> there, do all the stars align so this code works out fine there as well?
>

i found it's a bit tricky to adjust selection index for target
BYTES_BIG_ENDIA != WORDS_BIG_ENDIAN.
Especially for component mode smaller than word, Any interface to handle this?

> Looks fine otherwise, thanks :-)
>
>
> Segher



-- 
BR,
Hongtao


*PING^3* [PATCH] doc: gcc.c: Update documentation for spec files

2020-10-15 Thread Armin Brauns via Gcc-patches
On 02/10/2020 19.20, Armin Brauns wrote:
> On 06/09/2020 17.23, Armin Brauns wrote:
>> There were some differences between the actual code in do_spec_1, its
>> source comment, and the documentation in doc/invoke.texi. These should
>> now be resolved.
> PING: https://gcc.gnu.org/pipermail/gcc-patches/2020-September/553321.html

PING: https://gcc.gnu.org/pipermail/gcc-patches/2020-September/553321.html



[PATCH] tree-optimization/97482 - fix split_constant_offset of nop-conversions

2020-10-15 Thread Richard Biener
split_constant_offset is confused about a nop-conversion from
unsigned long to sizetype and tries to prove non-overflowing
of the inner operation.  Obviously the conversion could have been
elided so make sure split_constant_offset handles this properly.

It also makes sure that convert_to_ptrofftype does not introduce
conversions not necessary which in this case is the source for
the unnecessary conversion.

Bootstrapped on x86_64-unknown-linux-gnu, testing in progress.

2020-10-15  Richard Biener  

PR tree-optimization/97482
* tree-data-ref.c (split_constant_offset_1): Handle
trivial conversions better.
* fold-const.c (convert_to_ptrofftype_loc): Elide conversion
if the offset is already ptrofftype_p.

* gcc.dg/vect/pr97428.c: New testcase.
---
 gcc/fold-const.c|  2 ++
 gcc/testsuite/gcc.dg/vect/pr97428.c | 43 +
 gcc/tree-data-ref.c |  4 ++-
 3 files changed, 48 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gcc.dg/vect/pr97428.c

diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index 0cc80adf632..ebd32bb2e04 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -15489,6 +15489,8 @@ ptr_difference_const (tree e1, tree e2, poly_int64_pod 
*diff)
 tree
 convert_to_ptrofftype_loc (location_t loc, tree off)
 {
+  if (ptrofftype_p (TREE_TYPE (off)))
+return off;
   return fold_convert_loc (loc, sizetype, off);
 }
 
diff --git a/gcc/testsuite/gcc.dg/vect/pr97428.c 
b/gcc/testsuite/gcc.dg/vect/pr97428.c
new file mode 100644
index 000..b5b02dca9de
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/vect/pr97428.c
@@ -0,0 +1,43 @@
+/* { dg-do compile } */
+
+typedef struct { double re, im; } dcmlx_t;
+typedef struct { double re[4], im[4]; } dcmlx4_t;
+
+void foo_i2(dcmlx4_t dst[], const dcmlx_t src[], int n)
+{
+  for (int i = 0; i < n; ++i) {
+dcmlx_t s00 = src[i*4+0];
+dcmlx_t s01 = src[i*4+1];
+dcmlx_t s02 = src[i*4+2];
+dcmlx_t s03 = src[i*4+3];
+
+dcmlx_t s10 = src[i*4+0+n];
+dcmlx_t s11 = src[i*4+1+n];
+dcmlx_t s12 = src[i*4+2+n];
+dcmlx_t s13 = src[i*4+3+n];
+
+dst[i*2+0].re[0] = s00.re;
+dst[i*2+0].re[1] = s01.re;
+dst[i*2+0].re[2] = s02.re;
+dst[i*2+0].re[3] = s03.re;
+dst[i*2+0].im[0] = s00.im;
+dst[i*2+0].im[1] = s01.im;
+dst[i*2+0].im[2] = s02.im;
+dst[i*2+0].im[3] = s03.im;
+
+dst[i*2+1].re[0] = s10.re;
+dst[i*2+1].re[1] = s11.re;
+dst[i*2+1].re[2] = s12.re;
+dst[i*2+1].re[3] = s13.re;
+dst[i*2+1].im[0] = s10.im;
+dst[i*2+1].im[1] = s11.im;
+dst[i*2+1].im[2] = s12.im;
+dst[i*2+1].im[3] = s13.im;
+  }
+}
+
+/* The first step to produce optimal code is to appropriately detect the
+   load and store groups.  */
+/* { dg-final { scan-tree-dump "Detected interleaving load of size 8" "vect" } 
} */
+/* { dg-final { scan-tree-dump "Detected interleaving store of size 16" "vect" 
} } */
+/* { dg-final { scan-tree-dump-not "gap of 6 elements" "vect" } } */
diff --git a/gcc/tree-data-ref.c b/gcc/tree-data-ref.c
index 5505ba46778..3bf460cccfd 100644
--- a/gcc/tree-data-ref.c
+++ b/gcc/tree-data-ref.c
@@ -754,7 +754,9 @@ split_constant_offset_1 (tree type, tree op0, enum 
tree_code code, tree op1,
&& TYPE_PRECISION (type) >= TYPE_PRECISION (itype)
&& (POINTER_TYPE_P (type) || INTEGRAL_TYPE_P (type)))
  {
-   if (INTEGRAL_TYPE_P (itype) && TYPE_OVERFLOW_WRAPS (itype))
+   if (INTEGRAL_TYPE_P (itype) && TYPE_OVERFLOW_WRAPS (itype)
+   && (TYPE_PRECISION (type) > TYPE_PRECISION (itype)
+   || TYPE_UNSIGNED (itype) != TYPE_UNSIGNED (type)))
  {
/* Split the unconverted operand and try to prove that
   wrapping isn't a problem.  */
-- 
2.26.2


[PATCH] fold x << (n % C) to x << (n & C-1) if C meets power2

2020-10-15 Thread guojiufu via Gcc-patches
Hi,

I just had a check on below patch for PR66552.
https://gcc.gnu.org/pipermail/gcc-patches/2020-February/540930.html
It seems this patch works fine now. This patch fixes PR66552 which
request to optimizes (x shift (n mod C)) to
(x shift (n bit_and (C - 1))) when C is a constant and power of two.

As tests, bootstrap and regtests pass on ppc64le. Is it ok for trunk?

Jiufu Guo

gcc/ChangeLog
2020-10-14  Li Jia He  

PR tree-optimization/66552
* match.pd (x << (n % C) -> x << (n & C-1)): New simplification.

testsuite/ChangeLog
2020-10-14  Li Jia He  

PR tree-optimization/66552
* testsuite/gcc.dg/pr66552.c: New testcase.


---
 gcc/match.pd   | 11 ++-
 gcc/testsuite/gcc.dg/pr66552.c | 14 ++
 2 files changed, 24 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gcc.dg/pr66552.c

diff --git a/gcc/match.pd b/gcc/match.pd
index c3b88168ac4..9070812fe7b 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -607,12 +607,21 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
 /* Optimize TRUNC_MOD_EXPR by a power of two into a BIT_AND_EXPR,
i.e. "X % C" into "X & (C - 1)", if X and C are positive.
Also optimize A % (C << N)  where C is a power of 2,
-   to A & ((C << N) - 1).  */
+   to A & ((C << N) - 1).  And optimize "A shift (B % C)" where C
+   is a power of 2, shift operation included "<<" and ">>" and assume
+   (B % C) will not be negative as shifts negative values would be UB,
+   to  "A shift (B & (C - 1))".  */
 (match (power_of_two_cand @1)
  INTEGER_CST@1)
 (match (power_of_two_cand @1)
  (lshift INTEGER_CST@1 @2))
 (for mod (trunc_mod floor_mod)
+ (for shift (lshift rshift)
+  (simplify
+   (shift @0 (mod @1 (power_of_two_cand@2 @3)))
+   (if (integer_pow2p (@3) && tree_int_cst_sgn (@3) > 0)
+(shift @0 (bit_and @1 (minus @2 { build_int_cst (TREE_TYPE (@2),
+ 1); }))
  (simplify
   (mod @0 (convert?@3 (power_of_two_cand@1 @2)))
   (if ((TYPE_UNSIGNED (type)
diff --git a/gcc/testsuite/gcc.dg/pr66552.c b/gcc/testsuite/gcc.dg/pr66552.c
new file mode 100644
index 000..7583c9ad25a
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr66552.c
@@ -0,0 +1,14 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-lower" } */
+
+unsigned a(unsigned x, int n)
+{
+  return x >> (n % 32);
+}
+
+unsigned b(unsigned x, int n)
+{
+  return x << (n % 32);
+}
+
+/* { dg-final { scan-tree-dump-not " % " "lower" } } */
-- 
2.25.1



  1   2   >