[PATCH] vect: Use LOOP_VINFO_DATAREFS and LOOP_VINFO_DDRS consistently

2020-06-12 Thread Yangfei (Felix)
Hi,

This is minor code refactorings in tree-vect-data-refs.c and tree-vect-loop.c.
Use LOOP_VINFO_DATAREFS and LOOP_VINFO_DDRS when possible and rename
several parameters to make code more consistent.

Bootstrapped and tested on aarch64-linux-gnu.  OK?

Thanks,
Felix

gcc/

+2020-06-13  Felix Yang  
+
+   * tree-vect-data-refs.c (vect_verify_datarefs_alignment): Rename
+   parameter to loop_vinfo and update uses.  Use LOOP_VINFO_DATAREFS
+   when possible.
+   (vect_analyze_data_refs_alignment): Likewise, and use LOOP_VINFO_DDRS
+   when possible.
+   * tree-vect-loop.c (vect_dissolve_slp_only_groups): Use
+   LOOP_VINFO_DATAREFS when possible.
+   (update_epilogue_loop_vinfo): Likewise.


patch-v1.diff
Description: patch-v1.diff


[PATCH] libgomp: added a partial omp-tools.h for OMPD

2020-06-12 Thread y2s1982 via Gcc-patches
This patch adds a partial omp-tools.h from OpenMP project which
declares function prototypes and typedefs used in OMPD.

This patch also addressed all feedback.

2020-06-12  Tony Sim  

libgomp/ChangeLog:

* Makefile.am: Added new header.
* Makefile.in: Regenerate.
* omp-tools.h: New file.

---
 libgomp/Makefile.am |   2 +-
 libgomp/Makefile.in |   8 +-
 libgomp/omp-tools.h | 261 
 3 files changed, 266 insertions(+), 5 deletions(-)
 create mode 100644 libgomp/omp-tools.h

diff --git a/libgomp/Makefile.am b/libgomp/Makefile.am
index b84156291e8..217e6728d1c 100644
--- a/libgomp/Makefile.am
+++ b/libgomp/Makefile.am
@@ -74,7 +74,7 @@ libgomp_la_SOURCES += openacc.f90
 endif
 
 nodist_noinst_HEADERS = libgomp_f.h
-nodist_libsubinclude_HEADERS = omp.h openacc.h acc_prof.h
+nodist_libsubinclude_HEADERS = omp.h omp-tools.h openacc.h acc_prof.h
 if USE_FORTRAN
 nodist_finclude_HEADERS = omp_lib.h omp_lib.f90 omp_lib.mod omp_lib_kinds.mod \
openacc_lib.h openacc.f90 openacc.mod openacc_kinds.mod
diff --git a/libgomp/Makefile.in b/libgomp/Makefile.in
index 5ff2ac14db9..c844afd7f0d 100644
--- a/libgomp/Makefile.in
+++ b/libgomp/Makefile.in
@@ -16,7 +16,7 @@
 
 # Plugins for offload execution, Makefile.am fragment.
 #
-# Copyright (C) 2014-2019 Free Software Foundation, Inc.
+# Copyright (C) 2014-2020 Free Software Foundation, Inc.
 #
 # Contributed by Mentor Embedded.
 #
@@ -573,8 +573,8 @@ libgomp_la_SOURCES = alloc.c atomic.c barrier.c critical.c 
env.c \
affinity.c target.c splay-tree.c libgomp-plugin.c \
oacc-parallel.c oacc-host.c oacc-init.c oacc-mem.c \
oacc-async.c oacc-plugin.c oacc-cuda.c priority_queue.c \
-   affinity-fmt.c teams.c allocator.c oacc-profiling.c oacc-target.c \
-   $(am__append_4)
+   affinity-fmt.c teams.c allocator.c oacc-profiling.c \
+   oacc-target.c $(am__append_4)
 
 # Nvidia PTX OpenACC plugin.
 @PLUGIN_NVPTX_TRUE@libgomp_plugin_nvptx_version_info = -version-info 
$(libtool_VERSION)
@@ -610,7 +610,7 @@ libgomp_la_SOURCES = alloc.c atomic.c barrier.c critical.c 
env.c \
 @PLUGIN_GCN_TRUE@libgomp_plugin_gcn_la_LIBADD = libgomp.la $(PLUGIN_GCN_LIBS)
 @PLUGIN_GCN_TRUE@libgomp_plugin_gcn_la_LIBTOOLFLAGS = --tag=disable-static
 nodist_noinst_HEADERS = libgomp_f.h
-nodist_libsubinclude_HEADERS = omp.h openacc.h acc_prof.h
+nodist_libsubinclude_HEADERS = omp.h omp-tools.h openacc.h acc_prof.h
 @USE_FORTRAN_TRUE@nodist_finclude_HEADERS = omp_lib.h omp_lib.f90 omp_lib.mod 
omp_lib_kinds.mod \
 @USE_FORTRAN_TRUE@ openacc_lib.h openacc.f90 openacc.mod openacc_kinds.mod
 
diff --git a/libgomp/omp-tools.h b/libgomp/omp-tools.h
new file mode 100644
index 000..f6d45287aa6
--- /dev/null
+++ b/libgomp/omp-tools.h
@@ -0,0 +1,261 @@
+/* Copyright (C) 2020 Free Software Foundation, Inc.
+   Contributed by Yoosuk Sim .
+
+   This file is part of the GNU Offloading and Multi Processing Library
+   (libgomp).
+
+   Libgomp 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.
+
+   Libgomp 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
+   .  */
+
+/* This file contains prototypes of functions and data types defined
+   in the OMPD standard.  */
+
+#ifndef _OMP_TOOLS_H
+#define _OMP_TOOLS_H
+
+#ifdef __cplusplus
+extern "C" {
+# define __GOMPD_NOTHROW throw ()
+#else
+# define __GOMPD_NOTHROW __attribute__((__nothrow__))
+#endif
+
+typedef __UINT64_TYPE__ ompd_wait_id_t;
+
+typedef struct ompd_address_t {
+  ompd_seg_t segment;
+  ompd_addr_t address;
+} ompd_address_t;
+
+typedef struct ompd_frame_info_t {
+  ompd_address_t frame_address;
+  ompd_word_t frame_flag;
+} ompd_frame_info_t;
+
+typedef struct _ompd_aspace_handle ompd_address_space_handle_t;
+typedef struct _ompd_thread_handle ompd_thread_handle_t;
+typedef struct _ompd_parallel_handle ompd_parallel_handle_t;
+typedef struct _ompd_task_handle ompd_task_handle_t;
+
+typedef struct _ompd_aspace_cont ompd_address_space_context_t;
+typedef struct _ompd_thread_cont ompd_thread_context_t;
+
+typedef struct ompd_device_type_sizes_t {
+  __UINT8_TYPE__ sizeof_char;
+  __UINT8_TYPE__ sizeof_short;
+  __UINT8_TYPE__ sizeof_int;
+  

libgo patch committed: Correct arenaBaseOffset for aix/ppc

2020-06-12 Thread Ian Lance Taylor via Gcc-patches
This change by Clément Chigot corrects the value of arenaBaseOffset
for aix/ppc.  The existing value was correct for aix/ppc64, but not
for 32-bit ppc.  Bootstrapped and ran Go testsuite on
x86_64-pc-linux-gnu.  Committed to master.

Ian
75452d68672ff7da6e5a167924b6aeb07b5b2ed1
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index 284374820b0..c8b78bfda04 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-ea58b8491064fbed18a220571a3043c38dccf7c7
+74199467ea912138c1b76e9a156bb47886be1436
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
diff --git a/libgo/go/runtime/export_test.go b/libgo/go/runtime/export_test.go
index 6595fafe368..ab74e34d611 100644
--- a/libgo/go/runtime/export_test.go
+++ b/libgo/go/runtime/export_test.go
@@ -866,7 +866,7 @@ func FreePageAlloc(pp *PageAlloc) {
 //
 // This should not be higher than 0x100*pallocChunkBytes to support
 // mips and mipsle, which only have 31-bit address spaces.
-var BaseChunkIdx = ChunkIdx(chunkIndex(((0xc000*pageAlloc64Bit + 
0x100*pageAlloc32Bit) * pallocChunkBytes) + 0x0a00*sys.GoosAix))
+var BaseChunkIdx = ChunkIdx(chunkIndex(((0xc000*pageAlloc64Bit + 
0x100*pageAlloc32Bit) * pallocChunkBytes) + 
0x0a00*sys.GoosAix*sys.GoarchPpc64))
 
 // PageBase returns an address given a chunk index and a page index
 // relative to that chunk.
diff --git a/libgo/go/runtime/malloc.go b/libgo/go/runtime/malloc.go
index 266f5eba747..6df7eaa53bb 100644
--- a/libgo/go/runtime/malloc.go
+++ b/libgo/go/runtime/malloc.go
@@ -312,7 +312,7 @@ const (
//
// On other platforms, the user address space is contiguous
// and starts at 0, so no offset is necessary.
-   arenaBaseOffset = sys.GoarchAmd64*(1<<47) + 
(^0x0a00+1)*sys.GoosAix
+   arenaBaseOffset = sys.GoarchAmd64*(1<<47) + 
(^0x0a00+1)*sys.GoosAix*sys.GoarchPpc64
 
// Max number of threads to run garbage collection.
// 2, 3, and 4 are all plausible maximums depending


Re: [PATCH, RS6000 PR target/94954] Fix wrong codegen for vec_pack_to_short_fp32() builtin

2020-06-12 Thread Segher Boessenkool
Hi!

On Thu, Jun 11, 2020 at 11:22:33PM -0500, will schmidt wrote:
>   Fix codegen implementation for the builtin vec_pack_to_short_fp32.

> +;; Convert two vector F32 to packed vector f16.
> +(define_expand "convert_4f32_8f16"
> +  [(set (match_operand:V8HI 0 "register_operand" "=v")
> + (unspec:V8HI [(match_operand:V4SF 1 "register_operand" "v")
> +   (match_operand:V4SF 2 "register_operand" "v")]
> +  UNSPEC_CONVERT_4F32_8F16))]
> +  "TARGET_P9_VECTOR"
> +{
> +  rtx rtx_tmp_hi = gen_reg_rtx (V4SImode);
> +  rtx rtx_tmp_lo = gen_reg_rtx (V4SImode);
> +
> +  emit_insn (gen_vsx_xvcvsphp (rtx_tmp_hi, operands[1] ));
> +  emit_insn (gen_vsx_xvcvsphp (rtx_tmp_lo, operands[2] ));
> +  if (BYTES_BIG_ENDIAN)
> +emit_insn (gen_altivec_vpkuwum (operands[0], rtx_tmp_lo, rtx_tmp_hi));
> +  else
> +emit_insn (gen_altivec_vpkuwum (operands[0], rtx_tmp_hi, rtx_tmp_lo));
> +  DONE;
> +})

Why is this different from the 8i16, which doesn't have the swap of the
operands for BE?

If the comment before the pattern would say how it orders the elements,
that might clarify things.  (This really is documenting the unspec, but
there is no better place for documenting this afaics).


> +;; Generate xvcvsphp
> +(define_insn "vsx_xvcvsphp"
> +  [(set (match_operand:V4SI 0 "register_operand" "=wa")
> +(unspec:V4SI [(match_operand:V4SF 1 "vsx_register_operand" "wa")]
> +  UNSPEC_VSX_XVCVSPHP))]

(Should be a tab before the unspec as well, not eight spaces).

> --- a/gcc/testsuite/gcc.target/powerpc/builtins-1-p9-runnable.c
> +++ b/gcc/testsuite/gcc.target/powerpc/builtins-1-p9-runnable.c
> @@ -1,25 +1,37 @@
>  /* { dg-do run { target { powerpc*-*-linux* && { lp64 && p9vector_hw } } } } 
> */

Why the lp64 here?

>  /* { dg-require-effective-target powerpc_p9vector_ok } */

That is implied by p9vector_hw (or it should be, at least :-) )


Segher


Re: [PATCH] guard against calls with fewer arguments than the function type implies (PR 95581)

2020-06-12 Thread Segher Boessenkool
On Fri, Jun 12, 2020 at 10:46:33AM +0200, Richard Biener wrote:
> On Fri, Jun 12, 2020 at 2:31 AM Segher Boessenkool
>  wrote:
> > Why did this work before, and not anymore?  That sounds like a missing
> > or broken test?
> 
> It "worked" before because GIMPLE IL checking is not strict here
> because of too many existing "bugs" like this.  Well, quite a few
> years ago at least.

Ah.  So can that checking be made strict now then, if we are going to
rely on this?

Thanks,


Segher


[PATCH] ipa: special pass-through op for Fortran strides

2020-06-12 Thread Martin Jambor
Hi,

when Fortran functions pass array descriptors they receive as a
parameter to another function, they actually rebuild it.  Thanks to
work done mainly by Feng, IPA-CP can already handle the cases when
they pass directly the values loaded from the original descriptor.
Unfortunately, perhaps the most important one, stride, is first
checked against zero and is replaced with one in that case:

  _12 = *a_11(D).dim[0].stride;
  if (_12 != 0)
goto ; [50.00%]
  else
goto ; [50.00%]

  
// empty BB
  
  # iftmp.22_9 = PHI <_12(2), 1(3)>
   ...
   parm.6.dim[0].stride = iftmp.22_9;
   ...
   __x_MOD_foo (, b_31(D));

in the most important and hopefully common cases, the incoming value
is already 1 and we fail to propagate it.

I would therefore like to propose the following way of encoding this
situation in pass-through jump functions using using ASSERTT_EXPR
operation code meaning that if the incoming value is the same as the
"operand" in the jump function, it is passed on, otherwise the result
is unknown.  This of course captures only the single (but most
important) case but is an improvement and does not need enlarging the
jump function structure and is simple to pattern match.  Encoding that
zero needs to be changed to one would need another field and matching
it would be slightly more complicated too.

Bootstrapped and tested on x86_64-linux, LTO bootstrap is underway.  OK
if it passes?

Thanks,

Martin


2020-06-12  Martin Jambor  

* ipa-prop.h (ipa_pass_through_data): Expand comment describing
operation.
* ipa-prop.c (analyze_agg_content_value): Detect new special case and
encode it as ASSERT_EXPR.
* ipa-cp.c (values_equal_for_ipcp_p): Move before
ipa_get_jf_arith_result.
(ipa_get_jf_arith_result): Special case ASSERT_EXPR.

testsuite/
* gfortran.dg/ipcp-array-2.f90: New test.
---
 gcc/ipa-cp.c   |  48 ---
 gcc/ipa-prop.c | 148 ++---
 gcc/ipa-prop.h |  11 +-
 gcc/testsuite/gfortran.dg/ipcp-array-2.f90 |  45 +++
 4 files changed, 179 insertions(+), 73 deletions(-)
 create mode 100644 gcc/testsuite/gfortran.dg/ipcp-array-2.f90

diff --git a/gcc/ipa-cp.c b/gcc/ipa-cp.c
index b0c8f405260..4a2714c634f 100644
--- a/gcc/ipa-cp.c
+++ b/gcc/ipa-cp.c
@@ -1290,6 +1290,26 @@ initialize_node_lattices (struct cgraph_node *node)
   }
 }
 
+/* Return true iff X and Y should be considered equal values by IPA-CP.  */
+
+static bool
+values_equal_for_ipcp_p (tree x, tree y)
+{
+  gcc_checking_assert (x != NULL_TREE && y != NULL_TREE);
+
+  if (x == y)
+return true;
+
+  if (TREE_CODE (x) == ADDR_EXPR
+  && TREE_CODE (y) == ADDR_EXPR
+  && TREE_CODE (TREE_OPERAND (x, 0)) == CONST_DECL
+  && TREE_CODE (TREE_OPERAND (y, 0)) == CONST_DECL)
+return operand_equal_p (DECL_INITIAL (TREE_OPERAND (x, 0)),
+   DECL_INITIAL (TREE_OPERAND (y, 0)), 0);
+  else
+return operand_equal_p (x, y, 0);
+}
+
 /* Return the result of a (possibly arithmetic) operation on the constant
value INPUT.  OPERAND is 2nd operand for binary operation.  RES_TYPE is
the type of the parameter to which the result is passed.  Return
@@ -1307,6 +1327,14 @@ ipa_get_jf_arith_result (enum tree_code opcode, tree 
input, tree operand,
   if (!is_gimple_ip_invariant (input))
 return NULL_TREE;
 
+  if (opcode == ASSERT_EXPR)
+{
+  if (values_equal_for_ipcp_p (input, operand))
+   return input;
+  else
+   return NULL_TREE;
+}
+
   if (!res_type)
 {
   if (TREE_CODE_CLASS (opcode) == tcc_comparison)
@@ -1739,26 +1767,6 @@ ipcp_verify_propagated_values (void)
 }
 }
 
-/* Return true iff X and Y should be considered equal values by IPA-CP.  */
-
-static bool
-values_equal_for_ipcp_p (tree x, tree y)
-{
-  gcc_checking_assert (x != NULL_TREE && y != NULL_TREE);
-
-  if (x == y)
-return true;
-
-  if (TREE_CODE (x) ==  ADDR_EXPR
-  && TREE_CODE (y) ==  ADDR_EXPR
-  && TREE_CODE (TREE_OPERAND (x, 0)) == CONST_DECL
-  && TREE_CODE (TREE_OPERAND (y, 0)) == CONST_DECL)
-return operand_equal_p (DECL_INITIAL (TREE_OPERAND (x, 0)),
-   DECL_INITIAL (TREE_OPERAND (y, 0)), 0);
-  else
-return operand_equal_p (x, y, 0);
-}
-
 /* Return true iff X and Y should be considered equal contexts by IPA-CP.  */
 
 static bool
diff --git a/gcc/ipa-prop.c b/gcc/ipa-prop.c
index 71ac0e104d2..16483fb413a 100644
--- a/gcc/ipa-prop.c
+++ b/gcc/ipa-prop.c
@@ -1704,75 +1704,123 @@ analyze_agg_content_value (struct ipa_func_body_info 
*fbi,
 
   stmt = SSA_NAME_DEF_STMT (rhs1);
   if (!is_gimple_assign (stmt))
-   return;
+   break;
 
   rhs1 = gimple_assign_rhs1 (stmt);
 }
 
-  code = gimple_assign_rhs_code (stmt);
-  switch (gimple_assign_rhs_class (stmt))
+  if (gphi *phi = dyn_cast (stmt))
 {
-case GIMPLE_SINGLE_RHS:
-  if 

Re: gcc/testsuite/go: increase memory in issue4085b.go

2020-06-12 Thread Ian Lance Taylor via Gcc-patches
On Tue, May 19, 2020 at 6:35 AM CHIGOT, CLEMENT  wrote:
>
> Description:
>   On aix/ppc64, it's possible to allocate an array of 1<<50 int, because of 
> the
>   wider address space. Thus, increase it to 1<<59 like in Golang toolchain in
>   order to trigger the panic.
>
> Changelog:
> 2020-05-19 Clement Chigot 
>   * go.test/test/fixedbugs/issue4085b.go: increase the size of n2 in 64bit
>
>
> Please apply for me if approved.
> Could it be backported in gcc-8 and gcc-9 branch too ?

Thanks.  I've updated this file to the version that is in the Go 1.13
release, as appended.

Committed to master, GCC 10 branch, and GCC 9 branch.  Not committed
to GCC 8 branch as the file is different there.

Ian
diff --git a/gcc/testsuite/go.test/test/fixedbugs/issue4085b.go 
b/gcc/testsuite/go.test/test/fixedbugs/issue4085b.go
index 6bf315fcc2f..6304ce073aa 100644
--- a/gcc/testsuite/go.test/test/fixedbugs/issue4085b.go
+++ b/gcc/testsuite/go.test/test/fixedbugs/issue4085b.go
@@ -21,9 +21,11 @@ func main() {
shouldPanic("cap out of range", func() { _ = make(T, 0, int64(n)) })
var t *byte
if unsafe.Sizeof(t) == 8 {
-   var n2 int64 = 1 << 50
+   // Test mem > maxAlloc
+   var n2 int64 = 1 << 59
shouldPanic("len out of range", func() { _ = make(T, int(n2)) })
shouldPanic("cap out of range", func() { _ = make(T, 0, 
int(n2)) })
+   // Test elem.size*cap overflow
n2 = 1<<63 - 1
shouldPanic("len out of range", func() { _ = make(T, int(n2)) })
shouldPanic("cap out of range", func() { _ = make(T, 0, 
int(n2)) })


Re: BRIG FE testsuite: Fix all dump-scans (Was: Re: drop -aux{dir,base}, revamp -dump{dir,base})

2020-06-12 Thread Mike Stump via Gcc-patches
On Jun 11, 2020, at 7:28 AM, Martin Jambor  wrote:
> 
> On Tue, Jun 09 2020, Mike Stump wrote:
>> I think I'd prefer the fix on the other side, if reasonable.  I'd give
>> them some time to see about a fix there before selecting this patch.
> 
> given Alexandre's email, are you OK with the patch?

Yeah, if that's the change dumpbase is going, then we can follow along with it. 
 Ok.

Re: [PATCH] coroutines: Add a cleanup expression for g-r-o when needed [PR95477].

2020-06-12 Thread Iain Sandoe
Iain Sandoe  wrote:

> Nathan Sidwell  wrote:
> 
>> On 6/8/20 5:17 AM, Iain Sandoe wrote:

>>> +  r = gro_is_void_p ? integer_zero_node : rvalue (gro);
>>> +  /* The return object is constructed, even if the gro is void.  */
>> 
>> Would error_mark_node work here?  I presume we've already diagnosed the 
>> problem, so will result in no cascade of errors.
> 
> We have not diagnosed the problem - it’s valid to have a void g-r-o and a 
> non-void function
> return.
> 
> I am not sure the circumstance has been identified specifically where this 
> (valid) permutation
> is found together with a specialization of the traits that has a non-class 
> return type. (I spotted
> this as a corner-case while working on the code).
> 
> Perhaps I should construct a test-case and see how the other compilers handle 
> it.

I did this anyway …

To answer your original question, we need to diagnose this specifically.
clang does so, I’ve now matched the diagnostic for GCC.
we can then propagate an error_mark_node onwards.

OK now?
Iain

===

The PR reports that we fail to destroy the object initially created from
the get-return-object call.  Fixed by adding a cleanup when the DTOR is
non-trivial.  In addition, to meet the specific wording that the call to
get_return_object creates the glvalue for the return, we must construct
that in-place in the return object to avoid a second copy/move CTOR.

gcc/cp/ChangeLog:

PR c++/95477
* coroutines.cc (morph_fn_to_coro): Apply a cleanup to
the get return object when the DTOR is non-trivial.

gcc/testsuite/ChangeLog:

PR c++/95477
* g++.dg/coroutines/pr95477.C: New test.
* g++.dg/coroutines/void-gro-non-class-coro.C: New test.
---
 gcc/cp/coroutines.cc  | 69 ---
 gcc/testsuite/g++.dg/coroutines/pr95477.C | 37 ++
 .../coroutines/void-gro-non-class-coro.C  | 59 
 3 files changed, 155 insertions(+), 10 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/coroutines/pr95477.C
 create mode 100644 gcc/testsuite/g++.dg/coroutines/void-gro-non-class-coro.C

diff --git a/gcc/cp/coroutines.cc b/gcc/cp/coroutines.cc
index 11fca9954ac..d4f582e91e2 100644
--- a/gcc/cp/coroutines.cc
+++ b/gcc/cp/coroutines.cc
@@ -4280,12 +4280,34 @@ morph_fn_to_coro (tree orig, tree *resumer, tree 
*destroyer)
 
   tree gro = NULL_TREE;
   tree gro_bind_vars = NULL_TREE;
+  tree gro_cleanup_stmt = NULL_TREE;
   /* We have to sequence the call to get_return_object before initial
  suspend.  */
   if (gro_is_void_p)
-finish_expr_stmt (get_ro);
+r = get_ro;
+  else if (same_type_p (gro_type, fn_return_type))
+{
+ /* [dcl.fct.def.coroutine] / 7
+   The expression promise.get_return_object() is used to initialize the
+   glvalue result or... (see below)
+   Construct the return result directly.  */
+  if (TYPE_NEEDS_CONSTRUCTING (gro_type))
+   {
+ vec *arg = make_tree_vector_single (get_ro);
+ r = build_special_member_call (DECL_RESULT (orig),
+complete_ctor_identifier,
+, gro_type, LOOKUP_NORMAL,
+tf_warning_or_error);
+ release_tree_vector (arg);
+   }
+  else
+   r = build2_loc (fn_start, INIT_EXPR, gro_type,
+   DECL_RESULT (orig), get_ro);
+}
   else
 {
+  /* ... or ... Construct an object that will be used as the single
+   param to the CTOR for the return object.  */
   gro = build_lang_decl (VAR_DECL, get_identifier ("coro.gro"), gro_type);
   DECL_CONTEXT (gro) = current_scope ();
   DECL_ARTIFICIAL (gro) = true;
@@ -4302,8 +4324,21 @@ morph_fn_to_coro (tree orig, tree *resumer, tree 
*destroyer)
}
   else
r = build2_loc (fn_start, INIT_EXPR, gro_type, gro, get_ro);
-  finish_expr_stmt (r);
+  /* The constructed object might require a cleanup.  */
+  if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (gro_type))
+   {
+ tree cleanup
+   = build_special_member_call (gro, complete_dtor_identifier,
+NULL, gro_type, LOOKUP_NORMAL,
+tf_warning_or_error);
+ gro_cleanup_stmt = build_stmt (input_location, CLEANUP_STMT, NULL,
+cleanup, gro);
+   }
 }
+  finish_expr_stmt (r);
+
+  if (gro_cleanup_stmt)
+CLEANUP_BODY (gro_cleanup_stmt) = push_stmt_list ();
 
   /* Initialize the resume_idx_name to 0, meaning "not started".  */
   tree resume_idx_m
@@ -4345,16 +4380,15 @@ morph_fn_to_coro (tree orig, tree *resumer, tree 
*destroyer)
  promise was constructed.  We now supply a reference to that var,
  either as the return value (if it's the same type) or to the CTOR
  for an object of the return type.  */
-  if (gro_is_void_p)
-r = NULL_TREE;
-  else
-r = rvalue 

Re: [PATCH][GCC][Aarch64]: Fix for PR94880: Failure to recognize andn pattern

2020-06-12 Thread Andrew Pinski via Gcc-patches
On Fri, Jun 12, 2020 at 7:50 AM Przemyslaw Wirkus
 wrote:
>
> Hi all,
>
> Pattern "(x | y) - y" can be optimized to simple "(x & ~y)" andn pattern.

Isn't it better to do this transformation on the gimple level and not
in a target specific form?  Or at least do it in the RTL level in a
generic form rather than adding target specific patterns.

Thanks,
Andrew Pinski


>
> So, for the example code:
>
> $ cat main.c
> int
> f_i(int x, int y)
> {
> return (x | y) - y;
> }
>
> long long
> f_l(long long x, long long y)
> {
> return (x | y) - y;
> }
>
> typedef int v4si __attribute__ ((vector_size (16)));
> typedef long long v2di __attribute__ ((vector_size (16)));
>
> v4si
> f_v4si(v4si a, v4si b) {
> return (a | b) - b;
> }
>
> v2di
> f_v2di(v2di a, v2di b) {
> return (a | b) - b;
> }
>
> void
> f(v4si *d, v4si *a, v4si *b) {
> for (int i=0; i d[i] = (a[i] | b[i]) - b[i];
> }
>
> Before this patch:
> $ ./aarch64-none-linux-gnu-gcc -S -O2 main.c -dp
>
> f_i:
> orr w0, w0, w1// 8[c=4 l=4]  iorsi3/0
> sub w0, w0, w1// 14   [c=4 l=4]  subsi3
> ret   // 24   [c=0 l=4]  *do_return
> f_l:
> orr x0, x0, x1// 8[c=4 l=4]  iordi3/0
> sub x0, x0, x1// 14   [c=4 l=4]  subdi3/0
> ret   // 24   [c=0 l=4]  *do_return
> f_v4si:
> orr v0.16b, v0.16b, v1.16b// 8[c=8 l=4]  
> iorv4si3/0
> sub v0.4s, v0.4s, v1.4s   // 14 [c=8 l=4]  subv4si3
> ret   // 24   [c=0 l=4]  *do_return
> f_v2di:
> orr v0.16b, v0.16b, v1.16b// 8[c=8 l=4]  
> iorv2di3/0
> sub v0.2d, v0.2d, v1.2d   // 14 [c=8 l=4]  subv2di3
> ret   // 24   [c=0 l=4]  *do_return
>
> After this patch:
> $ ./aarch64-none-linux-gnu-gcc -S -O2 main.c -dp
>
> f_i:
> bic w0, w0, w1  // 13   [c=8 l=4]  *bic_and_not_si3
> ret // 23   [c=0 l=4]  *do_return
> f_l:
> bic x0, x0, x1  // 13   [c=8 l=4]  *bic_and_not_di3
> ret // 23   [c=0 l=4]  *do_return
> f_v4si:
> bic v0.16b, v0.16b, v1.16b  // 13   [c=16 l=4]  
> *bic_and_not_simd_v4si3
> ret // 23   [c=0 l=4]  *do_return
> f_v2di:
> bic v0.16b, v0.16b, v1.16b  // 13   [c=16 l=4]  
> *bic_and_not_simd_v2di3
> ret // 23   [c=0 l=4]  *do_return
>
> Bootstrapped and tested on aarch64-none-linux-gnu.
>
> OK for master ?
>
> Cheers,
> Przemyslaw
>
> gcc/ChangeLog:
>
> PR tree-optimization/94880
> * config/aarch64/aarch64.md (bic_and_not_3): New define_insn.
> * config/aarch64/aarch64-simd.md (bic_and_not_simd_3): New
> define_insn.
>
> gcc/testsuite/ChangeLog:
>
> PR tree-optimization/94880
> * gcc.target/aarch64/bic_and_not_di3.c: New test.
> * gcc.target/aarch64/bic_and_not_si3.c: New test.
> * gcc.target/aarch64/bic_and_not_v2di3.c: New test.
> * gcc.target/aarch64/bic_and_not_v4si3.c: New test.


Re: [PATCH] vectorizer: add _bb_vec_info::const_iterator

2020-06-12 Thread Nicholas Krause via Gcc-patches




On 6/12/20 11:49 AM, Richard Sandiford wrote:

Martin Liška  writes:

On 6/12/20 3:22 PM, Richard Sandiford wrote:

Martin Liška  writes:

diff --git a/gcc/tree-vect-patterns.c b/gcc/tree-vect-patterns.c
index 636ad59c001..eac372e6abc 100644
--- a/gcc/tree-vect-patterns.c
+++ b/gcc/tree-vect-patterns.c
@@ -5120,20 +5120,12 @@ vect_determine_precisions (vec_info *vinfo)
 else
   {
 bb_vec_info bb_vinfo = as_a  (vinfo);
-  gimple_stmt_iterator si = bb_vinfo->region_end;
-  gimple *stmt;
-  do
+  for (gimple *stmt: *bb_vinfo)
{
- if (!gsi_stmt (si))
-   si = gsi_last_bb (bb_vinfo->bb);
- else
-   gsi_prev ();
- stmt = gsi_stmt (si);
  stmt_vec_info stmt_info = vinfo->lookup_stmt (stmt);
  if (stmt_info && STMT_VINFO_VECTORIZABLE (stmt_info))
vect_determine_stmt_precisions (vinfo, stmt_info);
}
-  while (stmt != gsi_stmt (bb_vinfo->region_begin));
   }
   }


This loop wants a reverse iterator: it starts at the end and walks
backwards.  That's important because vect_determine_stmt_precisions
acts based on information recorded about later uses.


I thought that it may be a problematic change. Note that we don't a have
test coverage for the situation in testsuite (on x86_64). So I'm also
introducing reverse_iterator for this.


There's definitely coverage on aarch64.  Thought there would be on x86
too for the PAVG stuff, but obviously not.


diff --git a/gcc/tree-vect-stmts.c b/gcc/tree-vect-stmts.c
index cdd6f6c5e5d..766598862d4 100644
--- a/gcc/tree-vect-stmts.c
+++ b/gcc/tree-vect-stmts.c
@@ -1342,7 +1342,7 @@ vect_init_vector_1 (vec_info *vinfo, stmt_vec_info 
stmt_vinfo, gimple *new_stmt,
 else
  {
 bb_vec_info bb_vinfo = dyn_cast  (vinfo);
- gimple_stmt_iterator gsi_region_begin = bb_vinfo->region_begin;
+ gimple_stmt_iterator gsi_region_begin = bb_vinfo->begin ().gsi;
  gsi_insert_before (_region_begin, new_stmt, GSI_SAME_STMT);
  }
   }


Feels like this kind-of breaks the abstraction a bit.

Would it make sense instead to add the operators to gimple_stmt_iterator
itself and just make const_iterator a typedef of that?


Well, I'm planning to use the _bb_vec_info::const_iterator to jump in between
BBs, so it can't be a simple typedef.


But what happens to this code when that happens?  Is inserting at
begin().gsi meaningful?  I.e. is the stmt at *begin() guaranteed
to dominate all the SLP code even with multple BBs?

Personally I'd prefer either:

(a) const_iterator starts out as a typedef of gimple_stmt_iterator,
 and with your later changes becomes a derived class of it; or

(b) we just provide a region_begin() function that returns the gsi
 directly.


+  reverse_iterator rbegin () const
+{
+  reverse_iterator it = reverse_iterator (m_region_end);
+  if (*it == NULL)
+   return reverse_iterator (gsi_last_bb (m_region_end.bb));
+  else
+   return it;
+}


I think the else case should return “++it” instead, since AIUI
m_region_end is an exclusive rather than inclusive endpoint.

Also, one minor formatting nit, sorry: the other functions instead
indent the “{” block by the same amount as the function prototype,
which seems more consistent with the usual out-of-class formatting.

Thanks,
Richard


Hi Martin,

I was curious do we ever plan to use r-values here or in code that
can iterator? There was a new version in C++11 for r values that
is basically the same, but the deference operator * is overloaded
to do std::move(value) rather than what you have currently. Otherwise
the other comments about having a reverse iterator are all I have.

Doesn't seem useful here but just wanted to point it out with the
move to C++11,

Nick


--
Fundamentally an organism has conscious mental states if and only if 
there is something that it is like to be that organism--something it is 
like for the organism. - Thomas Nagel


Re: [PATCH] libgomp: added partial omp-tools.h for OMPD

2020-06-12 Thread Jakub Jelinek via Gcc-patches
On Fri, Jun 12, 2020 at 01:56:05PM -0400, y2s1982 wrote:
> This patch adds partial omp-tools.h continaing OMPD-specific functions and 
> data types.
> 
> 2020-06-12  Tony Sim 

You'll need two spaces before < for the script to recognize it as ChangeLog
snippet start (though, it will recognize just that libgomp/ChangeLog: as the
start).

> 
> libgomp/ChangeLog:
> 
>   * omp-tools.h: New file

Dot at the end.

> +/* This file contains prototypes of functions and data types defined 
> +   in ompt and ompd standard */

  in OMPT and OMPD standard.  */
(capitals on the standard in the comments, and end of comment is usually
full stop followed by 2 spaces).

> +typedef uint64_t ompt_wait_id_t;

The header doesn't include , so I think either we need to include
that header, or IMHO better replace all uint{N}_t uses with __UINT{N}_TYPE__
macros.
Also, ompt_wait_id_t is an OMPT type, I believe this is just a bug in the
standard and filed an issue for it.  So, for the OMPD part you should
typedef __UINT64_TYPE__ ompd_wait_id_t;
instead and:

+ompd_rc_t ompd_get_state (ompd_thread_handle_t *thread_handle, 
   
+ ompd_word_t *state, ompt_wait_id_t *wait_id) 
__GOMPD_NOTHROW;
use it in this prototype.

> +typedef ompd_rc_t (*ompd_callback_memory_alloc_fn_t) (ompd_size_t nbytes,
> + void **ptr) 
> __GOMPD_NOTHROW;

For brevity, I'd leave out all parameter names, omp.h doesn't have them
either.

> +
> +typedef ompd_rc_t (*ompd_callback_memory_free_fn_t) (void *ptr) 
> __GOMPD_NOTHROW;
> +
> +typedef ompd_rc_t (*ompd_callback_get_thread_context_for_thread_id_fn_t) (
> +ompd_address_space_context_t *address_space_context, ompd_thread_id_t 
> kind,
> +ompd_size_t sizeof_thread_id, const void *thread_id,
> +ompd_thread_context_t **thread_context) __GOMPD_NOTHROW;

I'd prefer the ( not at the end of line, but indented by two spaces on the
next line, i.e.
typedef ompd_rc_t (*ompd_callback_get_thread_context_for_thread_id_fn_t)
  (ompd_address_space_context_t *, ompd_thread_id_t, ompd_size_t, const void *,
   ompd_thread_context_t **) __GOMPD_NOTHROW;
(similarly for others).

> +#define ompt_id_none 0
> +#define ompt_data_none { 0 }
> +#define ompt_time_none 0
> +#define ompt_hwid_none 0
> +#define ompt_addr_none ~0
> +#define ompt_mutex_impl_none 0
> +#define ompt_wait_id_none 0

These are ompt_ defines, are they used in the OMPD part at all?  If not,
they should be removed.

> +
> +#define ompd_segment_none 0
> +
> +#ifdef __cplusplus
> +} // extern "C"
> +#endif
> +
> +#endif

The header itself isn't much useful, so IMHO in the same commit you want to
also add omp-tools.h to:
nodist_libsubinclude_HEADERS (right after omp.h) and regenerate Makefile.in
with automake 1.15.1 and autoconf 2.69.

Thanks.

Jakub



[PATCH] libgomp: added partial omp-tools.h for OMPD

2020-06-12 Thread y2s1982 via Gcc-patches
This patch adds partial omp-tools.h continaing OMPD-specific functions and data 
types.

2020-06-12  Tony Sim 

libgomp/ChangeLog:

* omp-tools.h: New file

---
 libgomp/omp-tools.h | 278 
 1 file changed, 278 insertions(+)
 create mode 100644 libgomp/omp-tools.h

diff --git a/libgomp/omp-tools.h b/libgomp/omp-tools.h
new file mode 100644
index 000..2ac23cde51f
--- /dev/null
+++ b/libgomp/omp-tools.h
@@ -0,0 +1,278 @@
+/* Copyright (C) 2020 Free Software Foundation, Inc.
+   Contributed by Yoosuk Sim .
+
+   This file is part of the GNU Offloading and Multi Processing Library
+   (libgomp).
+
+   Libgomp 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.
+
+   Libgomp 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
+   .  */
+
+/* This file contains prototypes of functions and data types defined 
+   in ompt and ompd standard */
+
+#ifndef _OMP_TOOLS_H
+#define _OMP_TOOLS_H
+
+#ifdef __cplusplus
+extern "C" {
+# define __GOMPD_NOTHROW throw ()
+#else
+# define __GOMPD_NOTHROW __attribute__((__nothrow__))
+#endif
+
+typedef uint64_t ompt_wait_id_t;
+
+typedef struct ompd_address_t {
+  ompd_seg_t segment;
+  ompd_addr_t address;
+} ompd_address_t;
+
+typedef struct ompd_frame_info_t {
+  ompd_address_t frame_address;
+  ompd_word_t frame_flag;
+} ompd_frame_info_t;
+
+typedef struct _ompd_aspace_handle ompd_address_space_handle_t;
+typedef struct _ompd_thread_handle ompd_thread_handle_t;
+typedef struct _ompd_parallel_handle ompd_parallel_handle_t;
+typedef struct _ompd_task_handle ompd_task_handle_t;
+
+typedef struct _ompd_aspace_cont ompd_address_space_context_t;
+typedef struct _ompd_thread_cont ompd_thread_context_t;
+
+typedef struct ompd_device_type_sizes_t {
+  uint8_t sizeof_char;
+  uint8_t sizeof_short;
+  uint8_t sizeof_int;
+  uint8_t sizeof_long;
+  uint8_t sizeof_long_long;
+  uint8_t sizeof_pointer;
+} ompd_device_type_sizes_t;
+
+
+const char **ompd_dll_locations;
+
+void ompd_dll_locations_valid (void) __GOMPD_NOTHROW;
+
+typedef ompd_rc_t (*ompd_callback_memory_alloc_fn_t) (ompd_size_t nbytes,
+ void **ptr) 
__GOMPD_NOTHROW;
+
+typedef ompd_rc_t (*ompd_callback_memory_free_fn_t) (void *ptr) 
__GOMPD_NOTHROW;
+
+typedef ompd_rc_t (*ompd_callback_get_thread_context_for_thread_id_fn_t) (
+ompd_address_space_context_t *address_space_context, ompd_thread_id_t kind,
+ompd_size_t sizeof_thread_id, const void *thread_id,
+ompd_thread_context_t **thread_context) __GOMPD_NOTHROW;
+
+typedef ompd_rc_t (*ompd_callback_sizeof_fn_t) (
+ompd_address_space_context_t *address_space_context,
+ompd_device_type_sizes_t *sizes) __GOMPD_NOTHROW;
+
+typedef ompd_rc_t (*ompd_callback_symbol_addr_fn_t) (
+ompd_address_space_context_t *address_space_context,
+ompd_thread_context_t *thread_context, const char *symbol_name,
+ompd_address_t *symbol_addr, const char *file_name) __GOMPD_NOTHROW;
+
+typedef ompd_rc_t (*ompd_callback_memory_read_fn_t) (
+ompd_address_space_context_t *address_space_context,
+ompd_thread_context_t *thread_context, const ompd_address_t *addr,
+ompd_size_t nbytes, void *buffer) __GOMPD_NOTHROW;
+
+typedef ompd_rc_t (*ompd_callback_memory_write_fn_t) (
+ompd_address_space_context_t *address_space_context,
+ompd_thread_context_t *thread_context, const ompd_address_t *addr,
+ompd_size_t nbytes, const void *buffer) __GOMPD_NOTHROW;
+
+typedef ompd_rc_t (*ompd_callback_device_host_fn_t) (
+ompd_address_space_context_t *address_space_context, const void *input,
+ompd_size_t unit_size, ompd_size_t count, void *output) __GOMPD_NOTHROW;
+
+typedef ompd_rc_t (*ompd_callback_print_string_fn_t) (const char *string,
+ int category) 
__GOMPD_NOTHROW;
+
+typedef struct ompd_callbacks_t {
+  ompd_callback_memory_alloc_fn_t alloc_memory;
+  ompd_callback_memory_free_fn_t free_memory;
+  ompd_callback_print_string_fn_t print_string;
+  ompd_callback_sizeof_fn_t sizeof_type;
+  ompd_callback_symbol_addr_fn_t symbol_addr_lookup;
+  ompd_callback_memory_read_fn_t read_memory;
+  

Re: [PATH 1/6] RISC-V: Add vector mask

2020-06-12 Thread Jim Wilson
On Fri, Jun 12, 2020 at 7:30 AM 戎杰杰(无音)  wrote:
> - The first version for vector extension and verified on rv64imafdcv linux 
> target with qemu.

There is no RISC-V vector extension.  There is only a draft proposal
to add one to the ISA.  Our policy has always been to wait for draft
proposals to be accepted into the ISA before we support them in the
mainline sources.  This is because if we make a release supporting a
draft, and the draft is incompatible with the final proposal, then we
will be stuck supporting two incompatible versions of the same feature
for a long time.

These patches are implementing an obsolete version of the vector
proposal, one which. is already seriously incompatible with current
drafts.  This is a v0.7.1 implementation, which is not compatible with
the current v0.9 draft.  Plans are to try to have a final proposal by
the end of year.

There is also the problem that this is not a fully general
implementation of the vector spec, but one that can only work on
Alibaba parts.  A correct fully general implementation should look
more like the arm sve port using sizeless types and polynomial
register sizes.

I would suggest creating a vendor branch, and adding your patches to
your vendor branch.

Jim


Re: [PATCH] vectorizer: add _bb_vec_info::const_iterator

2020-06-12 Thread Richard Sandiford
Martin Liška  writes:
> On 6/12/20 3:22 PM, Richard Sandiford wrote:
>> Martin Liška  writes:
>>> diff --git a/gcc/tree-vect-patterns.c b/gcc/tree-vect-patterns.c
>>> index 636ad59c001..eac372e6abc 100644
>>> --- a/gcc/tree-vect-patterns.c
>>> +++ b/gcc/tree-vect-patterns.c
>>> @@ -5120,20 +5120,12 @@ vect_determine_precisions (vec_info *vinfo)
>>> else
>>>   {
>>> bb_vec_info bb_vinfo = as_a  (vinfo);
>>> -  gimple_stmt_iterator si = bb_vinfo->region_end;
>>> -  gimple *stmt;
>>> -  do
>>> +  for (gimple *stmt: *bb_vinfo)
>>> {
>>> - if (!gsi_stmt (si))
>>> -   si = gsi_last_bb (bb_vinfo->bb);
>>> - else
>>> -   gsi_prev ();
>>> - stmt = gsi_stmt (si);
>>>   stmt_vec_info stmt_info = vinfo->lookup_stmt (stmt);
>>>   if (stmt_info && STMT_VINFO_VECTORIZABLE (stmt_info))
>>> vect_determine_stmt_precisions (vinfo, stmt_info);
>>> }
>>> -  while (stmt != gsi_stmt (bb_vinfo->region_begin));
>>>   }
>>>   }
>> 
>> This loop wants a reverse iterator: it starts at the end and walks
>> backwards.  That's important because vect_determine_stmt_precisions
>> acts based on information recorded about later uses.
>
> I thought that it may be a problematic change. Note that we don't a have
> test coverage for the situation in testsuite (on x86_64). So I'm also
> introducing reverse_iterator for this.

There's definitely coverage on aarch64.  Thought there would be on x86
too for the PAVG stuff, but obviously not.

>>> diff --git a/gcc/tree-vect-stmts.c b/gcc/tree-vect-stmts.c
>>> index cdd6f6c5e5d..766598862d4 100644
>>> --- a/gcc/tree-vect-stmts.c
>>> +++ b/gcc/tree-vect-stmts.c
>>> @@ -1342,7 +1342,7 @@ vect_init_vector_1 (vec_info *vinfo, stmt_vec_info 
>>> stmt_vinfo, gimple *new_stmt,
>>> else
>>>  {
>>> bb_vec_info bb_vinfo = dyn_cast  (vinfo);
>>> - gimple_stmt_iterator gsi_region_begin = bb_vinfo->region_begin;
>>> + gimple_stmt_iterator gsi_region_begin = bb_vinfo->begin ().gsi;
>>>   gsi_insert_before (_region_begin, new_stmt, GSI_SAME_STMT);
>>>  }
>>>   }
>> 
>> Feels like this kind-of breaks the abstraction a bit.
>> 
>> Would it make sense instead to add the operators to gimple_stmt_iterator
>> itself and just make const_iterator a typedef of that?
>
> Well, I'm planning to use the _bb_vec_info::const_iterator to jump in between
> BBs, so it can't be a simple typedef.

But what happens to this code when that happens?  Is inserting at
begin().gsi meaningful?  I.e. is the stmt at *begin() guaranteed
to dominate all the SLP code even with multple BBs?

Personally I'd prefer either:

(a) const_iterator starts out as a typedef of gimple_stmt_iterator,
and with your later changes becomes a derived class of it; or

(b) we just provide a region_begin() function that returns the gsi
directly.

> +  reverse_iterator rbegin () const
> +{
> +  reverse_iterator it = reverse_iterator (m_region_end);
> +  if (*it == NULL)
> + return reverse_iterator (gsi_last_bb (m_region_end.bb));
> +  else
> + return it;
> +}

I think the else case should return “++it” instead, since AIUI
m_region_end is an exclusive rather than inclusive endpoint.

Also, one minor formatting nit, sorry: the other functions instead
indent the “{” block by the same amount as the function prototype,
which seems more consistent with the usual out-of-class formatting.

Thanks,
Richard


Re: [PATCH] vectorizer: add _bb_vec_info::const_iterator

2020-06-12 Thread Richard Biener via Gcc-patches
On June 12, 2020 5:29:40 PM GMT+02:00, "Martin Liška"  wrote:
>On 6/12/20 3:02 PM, Richard Biener wrote:
>> For(gimple. *stmt : bb_vinfo->region_stmts())
>
>Hm, that will require region_stmts() returning one another object
>that will contain the begin/end methods.
>Is it what we want or do I miss something?

Yes, you usually need some kind of iterator container. There's also the vector 
of SLP graph entries we iterate over repeatedly for example. For BBs we want to 
iterate over PHIs, stmts and incoming and outgoing edges. So I expect these 
kind of wrappers to be the common case. 

Richard. 

>Martin



Re: [PATCH v2] tsan: Add param to disable func-entry-exit instrumentation

2020-06-12 Thread Marco Elver via Gcc-patches
On Fri, 12 Jun 2020 at 17:27, Martin Liška  wrote:
>
> On 6/12/20 4:19 PM, Marco Elver wrote:
> > On Fri, 12 Jun 2020, Jakub Jelinek wrote:
> >
> >> On Fri, Jun 12, 2020 at 04:07:57PM +0200, Marco Elver wrote:
> >>> gcc/ChangeLog:
> >>>
> >>> * params.opt: Add --param=tsan-instrument-func-entry-exit=.
> >>> * tsan.c (instrument_gimple): Make return value if func entry
> >>> and exit should be instrumented dependent on param.
> >>>
> >>> gcc/testsuite/ChangeLog:
> >>>
> >>> * c-c++-common/tsan/func_entry_exit.c: New test.
> >>> * c-c++-common/tsan/func_entry_exit_disabled.c: New test.
> >>
> >> Ok.
> >
> > Thanks!
> >
> > Somehow the commit message contained the old changelog entry, this is
> > the new one:
> >
> > gcc/ChangeLog:
> >
> >   * gimplify.c (gimplify_function_tree): Optimize and do not emit
> >   IFN_TSAN_FUNC_EXIT in a finally block if we do not need it.
> >   * params.opt: Add --param=tsan-instrument-func-entry-exit=.
> >   * tsan.c (instrument_memory_accesses): Make
> >   fentry_exit_instrument bool depend on new param.
> >
> > gcc/testsuite/ChangeLog:
> >
> >   * c-c++-common/tsan/func_entry_exit.c: New test.
> >   * c-c++-common/tsan/func_entry_exit_disabled.c: New test.
> >
> >
> > -- Marco
> >
>
> Do you already have a write access or should I install the patch?

I do -- I just pushed it.

Thanks,
-- Marco


Re: [PATCH] vectorizer: add _bb_vec_info::const_iterator

2020-06-12 Thread Martin Liška

On 6/12/20 3:02 PM, Richard Biener wrote:

For(gimple. *stmt : bb_vinfo->region_stmts())


Hm, that will require region_stmts() returning one another object
that will contain the begin/end methods.
Is it what we want or do I miss something?

Martin


Re: [PATCH] vectorizer: add _bb_vec_info::const_iterator

2020-06-12 Thread Martin Liška

On 6/12/20 3:22 PM, Richard Sandiford wrote:

Martin Liška  writes:

diff --git a/gcc/tree-vect-patterns.c b/gcc/tree-vect-patterns.c
index 636ad59c001..eac372e6abc 100644
--- a/gcc/tree-vect-patterns.c
+++ b/gcc/tree-vect-patterns.c
@@ -5120,20 +5120,12 @@ vect_determine_precisions (vec_info *vinfo)
else
  {
bb_vec_info bb_vinfo = as_a  (vinfo);
-  gimple_stmt_iterator si = bb_vinfo->region_end;
-  gimple *stmt;
-  do
+  for (gimple *stmt: *bb_vinfo)
{
- if (!gsi_stmt (si))
-   si = gsi_last_bb (bb_vinfo->bb);
- else
-   gsi_prev ();
- stmt = gsi_stmt (si);
  stmt_vec_info stmt_info = vinfo->lookup_stmt (stmt);
  if (stmt_info && STMT_VINFO_VECTORIZABLE (stmt_info))
vect_determine_stmt_precisions (vinfo, stmt_info);
}
-  while (stmt != gsi_stmt (bb_vinfo->region_begin));
  }
  }


This loop wants a reverse iterator: it starts at the end and walks
backwards.  That's important because vect_determine_stmt_precisions
acts based on information recorded about later uses.


I thought that it may be a problematic change. Note that we don't a have
test coverage for the situation in testsuite (on x86_64). So I'm also
introducing reverse_iterator for this.




@@ -5492,10 +5484,8 @@ vect_pattern_recog (vec_info *vinfo)
else
  {
bb_vec_info bb_vinfo = as_a  (vinfo);
-  for (si = bb_vinfo->region_begin;
-  gsi_stmt (si) != gsi_stmt (bb_vinfo->region_end); gsi_next ())
+  for (gimple *stmt: *bb_vinfo)
{
- gimple *stmt = gsi_stmt (si);
  stmt_vec_info stmt_info = bb_vinfo->lookup_stmt (stmt);
  if (!stmt_info || !STMT_VINFO_VECTORIZABLE (stmt_info))
continue;


Very minor, but I think it's more usual to have a space both sides of
the ":".  (That's also the formatting used by libstdc++-v3, and ties in
nicely with the formatting of infix operators.)  Same for the others.


Changed.




diff --git a/gcc/tree-vect-stmts.c b/gcc/tree-vect-stmts.c
index cdd6f6c5e5d..766598862d4 100644
--- a/gcc/tree-vect-stmts.c
+++ b/gcc/tree-vect-stmts.c
@@ -1342,7 +1342,7 @@ vect_init_vector_1 (vec_info *vinfo, stmt_vec_info 
stmt_vinfo, gimple *new_stmt,
else
 {
bb_vec_info bb_vinfo = dyn_cast  (vinfo);
- gimple_stmt_iterator gsi_region_begin = bb_vinfo->region_begin;
+ gimple_stmt_iterator gsi_region_begin = bb_vinfo->begin ().gsi;
  gsi_insert_before (_region_begin, new_stmt, GSI_SAME_STMT);
 }
  }


Feels like this kind-of breaks the abstraction a bit.

Would it make sense instead to add the operators to gimple_stmt_iterator
itself and just make const_iterator a typedef of that?


Well, I'm planning to use the _bb_vec_info::const_iterator to jump in between
BBs, so it can't be a simple typedef.


 We could then
reuse this work for BB iterators, etc.


diff --git a/gcc/tree-vectorizer.h b/gcc/tree-vectorizer.h
index 6c830ad09f4..8f80a7d1bce 100644
--- a/gcc/tree-vectorizer.h
+++ b/gcc/tree-vectorizer.h
@@ -787,12 +787,46 @@ loop_vec_info_for_loop (class loop *loop)
  typedef class _bb_vec_info : public vec_info
  {
  public:
+  struct const_iterator
+  {
+const_iterator (gimple_stmt_iterator _gsi): gsi (_gsi)
+{
+}


Again very minor, but I think the conventions say that this should
be defined on one line, like the later operator* is.  Space before
":" here too.


Likewise changed here.

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

Martin



Thanks,
Richard



>From 8859cb13a20d91222103577f21af2cd029344a5d Mon Sep 17 00:00:00 2001
From: Martin Liska 
Date: Thu, 11 Jun 2020 13:25:40 +0200
Subject: [PATCH] vectorizer: add _bb_vec_info::const_iterator

gcc/ChangeLog:

	* tree-vectorizer.h: Add the new const_iterator and
	reverse_iterator and all related functions.
	* tree-vect-patterns.c (vect_determine_precisions): Use the
	iterator.
	(vect_pattern_recog): Likewise.
	* tree-vect-slp.c (_bb_vec_info::_bb_vec_info): Likewise.
	(_bb_vec_info::~_bb_vec_info): Likewise.
	(vect_slp_check_for_constructors): Likewise.
	* tree-vect-stmts.c (vect_init_vector_1): Likewise.
---
 gcc/tree-vect-patterns.c | 16 +++--
 gcc/tree-vect-slp.c  | 28 ++-
 gcc/tree-vect-stmts.c|  2 +-
 gcc/tree-vectorizer.h| 74 ++--
 4 files changed, 87 insertions(+), 33 deletions(-)

diff --git a/gcc/tree-vect-patterns.c b/gcc/tree-vect-patterns.c
index 636ad59c001..e24dc848d7b 100644
--- a/gcc/tree-vect-patterns.c
+++ b/gcc/tree-vect-patterns.c
@@ -5120,20 +5120,14 @@ vect_determine_precisions (vec_info *vinfo)
   else
 {
   bb_vec_info bb_vinfo = as_a  (vinfo);
-  gimple_stmt_iterator si = bb_vinfo->region_end;
-  gimple *stmt;
-  do
+  for (_bb_vec_info::reverse_iterator it = bb_vinfo->rbegin ();
+	   it != bb_vinfo->rend (); ++it)
 	{
-	  if (!gsi_stmt (si))
-	si = gsi_last_bb 

Re: [PATCH v2] tsan: Add param to disable func-entry-exit instrumentation

2020-06-12 Thread Martin Liška

On 6/12/20 4:19 PM, Marco Elver wrote:

On Fri, 12 Jun 2020, Jakub Jelinek wrote:


On Fri, Jun 12, 2020 at 04:07:57PM +0200, Marco Elver wrote:

gcc/ChangeLog:

* params.opt: Add --param=tsan-instrument-func-entry-exit=.
* tsan.c (instrument_gimple): Make return value if func entry
and exit should be instrumented dependent on param.

gcc/testsuite/ChangeLog:

* c-c++-common/tsan/func_entry_exit.c: New test.
* c-c++-common/tsan/func_entry_exit_disabled.c: New test.


Ok.


Thanks!

Somehow the commit message contained the old changelog entry, this is
the new one:

gcc/ChangeLog:

* gimplify.c (gimplify_function_tree): Optimize and do not emit
IFN_TSAN_FUNC_EXIT in a finally block if we do not need it.
* params.opt: Add --param=tsan-instrument-func-entry-exit=.
* tsan.c (instrument_memory_accesses): Make
fentry_exit_instrument bool depend on new param.

gcc/testsuite/ChangeLog:

* c-c++-common/tsan/func_entry_exit.c: New test.
* c-c++-common/tsan/func_entry_exit_disabled.c: New test.


-- Marco



Do you already have a write access or should I install the patch?

Martin


[PATCH][GCC][Aarch64]: Fix for PR94880: Failure to recognize andn pattern

2020-06-12 Thread Przemyslaw Wirkus
Hi all,

Pattern "(x | y) - y" can be optimized to simple "(x & ~y)" andn pattern.

So, for the example code:

$ cat main.c
int
f_i(int x, int y)
{
return (x | y) - y;
}

long long
f_l(long long x, long long y)
{
return (x | y) - y;
}

typedef int v4si __attribute__ ((vector_size (16)));
typedef long long v2di __attribute__ ((vector_size (16)));

v4si
f_v4si(v4si a, v4si b) {
return (a | b) - b;
}

v2di
f_v2di(v2di a, v2di b) {
return (a | b) - b;
}

void
f(v4si *d, v4si *a, v4si *b) {
for (int i=0; i3): New define_insn.
* config/aarch64/aarch64-simd.md (bic_and_not_simd_3): New
define_insn.

gcc/testsuite/ChangeLog:

PR tree-optimization/94880
* gcc.target/aarch64/bic_and_not_di3.c: New test.
* gcc.target/aarch64/bic_and_not_si3.c: New test.
* gcc.target/aarch64/bic_and_not_v2di3.c: New test.
* gcc.target/aarch64/bic_and_not_v4si3.c: New test.


patch.patch
Description: patch.patch


Re: [PATCH, RS6000 PR target/94954] Fix wrong codegen for vec_pack_to_short_fp32() builtin

2020-06-12 Thread will schmidt via Gcc-patches
On Fri, 2020-06-12 at 10:24 -0400, David Edelsohn wrote:
> Hi, Will


Hi, 

> 
> On Fri, Jun 12, 2020 at 12:22 AM will schmidt <
> will_schm...@vnet.ibm.com> wrote:
> > 
> > 
> > Hi,
> >   Fix codegen implementation for the builtin
> > vec_pack_to_short_fp32.
> > 
> >   Regtests are underway against powerpc64
> > (power7be,power8le,power9le).
> >   (this is a power9 builtin, so should be a noop for most of
> > those).
> >   OK for trunk and backports?
> > 
> >   Thanks
> >   -Will
> > 
> > 
> > [gcc]
> >   target pr/94954
> > 
> > * config/rs6000/altivec.h
> > (vec_pack_to_short_fp32):  Update.
> > * config/rs6000/altivec.md (UNSPEC_CONVERT_4F32_8F16):  New
> > unspec.
> > (convert_4f32_8f16):  New define_expand.
> > * config/rs6000/rs6000-builtin.def (convert_4f32_8f16): New
> > builtin define
> > and overload.
> > * config/rs6000/rs6000-call.c
> > (P9V_BUILTIN_VEC_CONVERT_4F32_8F16): New
> > overloaded builtin entry.
> > * config/rs6000/vsx.md (UNSPEC_VSX_XVCVSPHP): New unspec.
> > (vsx_xvcvsphp): New define_insn.
> > 
> > [testsuite]
> > * testsuite/gcc.target/powerpc/builtins-1-p9-runnable.c:
> > Update.
> > 
> > diff --git a/gcc/config/rs6000/altivec.h
> > b/gcc/config/rs6000/altivec.h
> > index 0a7e8ab..ab10025 100644
> > --- a/gcc/config/rs6000/altivec.h
> > +++ b/gcc/config/rs6000/altivec.h
> > @@ -431,11 +431,11 @@
> >  /* Vector additions added in ISA 3.0.  */
> >  #define vec_first_match_index __builtin_vec_first_match_index
> >  #define vec_first_match_or_eos_index
> > __builtin_vec_first_match_or_eos_index
> >  #define vec_first_mismatch_index
> > __builtin_vec_first_mismatch_index
> >  #define vec_first_mismatch_or_eos_index
> > __builtin_vec_first_mismatch_or_eos_index
> > -#define vec_pack_to_short_fp32 __builtin_vec_convert_4f32_8i16
> > +#define vec_pack_to_short_fp32 __builtin_vec_convert_4f32_8f16
> >  #define vec_parity_lsbb __builtin_vec_vparity_lsbb
> >  #define vec_vctz __builtin_vec_vctz
> >  #define vec_cnttz __builtin_vec_vctz
> >  #define vec_vctzb __builtin_vec_vctzb
> >  #define vec_vctzd __builtin_vec_vctzd
> > diff --git a/gcc/config/rs6000/altivec.md
> > b/gcc/config/rs6000/altivec.md
> > index 159f24e..855e7cc 100644
> > --- a/gcc/config/rs6000/altivec.md
> > +++ b/gcc/config/rs6000/altivec.md
> > @@ -78,10 +78,11 @@
> > UNSPEC_VUNPACK_HI_SIGN_DIRECT
> > UNSPEC_VUNPACK_LO_SIGN_DIRECT
> > UNSPEC_VUPKHPX
> > UNSPEC_VUPKLPX
> > UNSPEC_CONVERT_4F32_8I16
> > +   UNSPEC_CONVERT_4F32_8F16
> > UNSPEC_DST
> > UNSPEC_DSTT
> > UNSPEC_DSTST
> > UNSPEC_DSTSTT
> > UNSPEC_LVSL
> > @@ -3215,10 +3216,32 @@
> >emit_insn (gen_altivec_vctuxs (rtx_tmp_lo, operands[2],
> > const0_rtx));
> >emit_insn (gen_altivec_vpkswss (operands[0], rtx_tmp_hi,
> > rtx_tmp_lo));
> >DONE;
> >  })
> > 
> > +
> > +;; Convert two vector F32 to packed vector f16.
> 
> Just for consistency, the comment above probably should be F16
> (capitalized) above.

Ok. I've fixed that locally. 

> Why does this pattern use V8HI mode instead of V8HF if this is for
> 8F16 in contrast to the existing 8I16 pattern?  Other than that
> (fundamental) question, the rest looks good.

Yeah, so even though the contents of the returned vector consists of
packed float data, the return type is still vector unsigned short.

I can't speak to the reasoning behind why the builtin was defined that
way. 

Thanks for the review, 

thanks,
-Will


> 
> Thanks, David
> 
> > +(define_expand "convert_4f32_8f16"
> > +  [(set (match_operand:V8HI 0 "register_operand" "=v")
> > +   (unspec:V8HI [(match_operand:V4SF 1 "register_operand" "v")
> > + (match_operand:V4SF 2 "register_operand"
> > "v")]
> > +UNSPEC_CONVERT_4F32_8F16))]
> > +  "TARGET_P9_VECTOR"
> > +{
> > +  rtx rtx_tmp_hi = gen_reg_rtx (V4SImode);
> > +  rtx rtx_tmp_lo = gen_reg_rtx (V4SImode);
> > +
> > +  emit_insn (gen_vsx_xvcvsphp (rtx_tmp_hi, operands[1] ));
> > +  emit_insn (gen_vsx_xvcvsphp (rtx_tmp_lo, operands[2] ));
> > +  if (BYTES_BIG_ENDIAN)
> > +emit_insn (gen_altivec_vpkuwum (operands[0], rtx_tmp_lo,
> > rtx_tmp_hi));
> > +  else
> > +emit_insn (gen_altivec_vpkuwum (operands[0], rtx_tmp_hi,
> > rtx_tmp_lo));
> > +  DONE;
> > +})
> > +
> > +
> >  ;; Generate
> >  ;;xxlxor/vxor SCRATCH0,SCRATCH0,SCRATCH0
> >  ;;vsubu?m SCRATCH2,SCRATCH1,%1
> >  ;;vmaxs? %0,%1,SCRATCH2"
> >  (define_expand "abs2"
> > diff --git a/gcc/config/rs6000/rs6000-builtin.def
> > b/gcc/config/rs6000/rs6000-builtin.def
> > index 8b1ddb0..47e9137 100644
> > --- a/gcc/config/rs6000/rs6000-builtin.def
> > +++ b/gcc/config/rs6000/rs6000-builtin.def
> > @@ -2208,10 +2208,11 @@ BU_P8V_OVERLOAD_3 (VPERMXOR,   "vpermxor")
> > 
> >  /* ISA 3.0 vector overloaded 2-argument functions. */
> >  BU_P9V_AV_2 (VSLV, "vslv", CONST,
> > vslv)
> >  BU_P9V_AV_2 (VSRV, "vsrv",   

[PATH 6/6] RISC-V: Add pass to delete redundancy vsetvl insn

2020-06-12 Thread 无音
gcc/ChangeLog:

* config.gcc (extra_objs): Include vector pass.
* config/riscv/t-riscv : Likewise.
* config/riscv/riscv-pass.c : New.
* config/riscv/riscv.opt (-mdelete-vsetvl): Likewise.
---
 gcc/config.gcc|   2 +-
 gcc/config/riscv/riscv-pass.c | 195 ++
 gcc/config/riscv/riscv.opt|   4 +
 gcc/config/riscv/t-riscv  |   4 +
 4 files changed, 204 insertions(+), 1 deletion(-)
 create mode 100755 gcc/config/riscv/riscv-pass.c

diff --git a/gcc/config.gcc b/gcc/config.gcc
index 4c4db7bcb7b..4308670746a 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -512,7 +512,7 @@ powerpc*-*-*)
  ;;
 riscv*)
  cpu_type=riscv
- extra_objs="riscv-builtins.o riscv-c.o"
+ extra_objs="riscv-builtins.o riscv-c.o riscv-pass.o"
  d_target_objs="riscv-d.o"
  extra_headers="riscv-vector.h"
  ;;
diff --git a/gcc/config/riscv/riscv-pass.c b/gcc/config/riscv/riscv-pass.c
new file mode 100755
index 000..376eeead1d2
--- /dev/null
+++ b/gcc/config/riscv/riscv-pass.c
@@ -0,0 +1,195 @@
+/* Subroutines used for code generation for RISC-V.
+   Copyright (C) 2011-2018 Free Software Foundation, Inc.
+   Contributed by Andrew Waterman (and...@sifive.com).
+   Based on MIPS target for GNU compiler.
+
+This file is part of GCC.
+
+GCC 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.
+
+GCC 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.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING3.  If not see
+.  */
+
+#define IN_TARGET_CODE 1
+
+#include "config.h"
+#include "system.h"
+#include "coretypes.h"
+#include "tm.h"
+#include "rtl.h"
+#include "regs.h"
+#include "insn-config.h"
+#include "insn-attr.h"
+#include "recog.h"
+#include "output.h"
+#include "alias.h"
+#include "tree.h"
+#include "stringpool.h"
+#include "attribs.h"
+#include "varasm.h"
+#include "stor-layout.h"
+#include "calls.h"
+#include "function.h"
+#include "explow.h"
+#include "memmodel.h"
+#include "emit-rtl.h"
+#include "reload.h"
+#include "tm_p.h"
+#include "target.h"
+#include "target-def.h"
+#include "basic-block.h"
+#include "expr.h"
+#include "optabs.h"
+#include "bitmap.h"
+#include "df.h"
+#include "diagnostic.h"
+#include "builtins.h"
+#include "predict.h"
+#include "backend.h"
+#include "pass_manager.h"
+#include "tree-pass.h"
+#include "context.h"
+#include "cfgrtl.h"
+
+
+static unsigned int
+xck_dvsetvl (void)
+{
+  basic_block bb;
+  rtx_insn *insn;
+
+  rtx pat;
+  rtx vector_insn;
+  rtx_insn *vsetvl_insn;
+  int unspec;
+
+  FOR_EACH_BB_FN (bb, cfun)
+{
+  vector_insn = NULL_RTX;
+  vsetvl_insn = NULL;
+
+  FOR_BB_INSNS_REVERSE (bb, insn)
+{
+  if (!NONDEBUG_INSN_P (insn))
+continue;
+
+  if (!NONJUMP_INSN_P(insn))
+vsetvl_insn = NULL;
+
+  pat =  PATTERN (insn);
+
+  if (GET_CODE (pat) == PARALLEL)
+pat = XVECEXP (pat, 0, 0);
+
+  if (GET_CODE (pat) != SET)
+continue;
+
+  pat =  SET_SRC (pat);
+
+  if (GET_CODE (pat) != UNSPEC)
+continue;
+
+  unspec = XINT (pat, 1);
+
+  if (unspec >= UNSPEC_VSTART
+  && unspec <= UNSPEC_VEND)
+vector_insn = insn;
+
+  if (unspec == UNSPEC_VSETVLI
+  || unspec == UNSPEC_VSETVLI_MAX
+  || unspec == UNSPEC_VSETVLR)
+{
+  if (vsetvl_insn
+  && rtx_equal_p(PATTERN(vsetvl_insn), PATTERN(insn)))
+{
+  bool deletex = true;
+
+  if (unspec == UNSPEC_VSETVLI
+  && reg_set_between_p(XVECEXP (pat, 0, 0), insn, 
vsetvl_insn))
+deletex = false;
+
+  if (unspec == UNSPEC_VSETVLR
+  && (reg_set_between_p(XVECEXP (pat, 0, 0), insn, 
vsetvl_insn)
+  || reg_set_between_p(XVECEXP (pat, 0, 1), insn, 
vsetvl_insn)))
+deletex = false;
+
+  if (deletex)
+delete_insn(vsetvl_insn);
+}
+
+  vsetvl_insn = insn;
+  vector_insn = NULL_RTX;
+}
+}
+}
+  return 0;
+}
+
+const pass_data pass_data_xck_dvsetvl =
+{
+  RTL_PASS,   /* type */
+  "dvsetvl",  /* name */
+  OPTGROUP_NONE,  /* optinfo_flags */
+  TV_NONE,/* tv_id */
+  0,  /* properties_required */
+  0,  /* properties_provided */
+  0,  /* properties_destroyed */
+  0,  /* 

[PATH 3/6] RISC-V: Add vector VLEN and SEW

2020-06-12 Thread 无音
gcc/ChangeLog:

* config/riscv/riscv-c.c (__riscv_vector): Define.
* config/riscv/riscv-opts.h (riscv_vlen): New.
* config/riscv/riscv-v.h (TARGET_VECTOR_VLEN): Define.
(UNITS_PER_VR_REG): Likewise.
(RISCV_VSEW_T): Likewise.
* config/riscv/riscv.opt (-mvlen): New.
---
 gcc/config/riscv/riscv-c.c|  3 +++
 gcc/config/riscv/riscv-opts.h |  6 ++
 gcc/config/riscv/riscv-v.h| 14 ++
 gcc/config/riscv/riscv.opt| 14 ++
 4 files changed, 37 insertions(+)

diff --git a/gcc/config/riscv/riscv-c.c b/gcc/config/riscv/riscv-c.c
index ca72de74a7b..96a661681bc 100644
--- a/gcc/config/riscv/riscv-c.c
+++ b/gcc/config/riscv/riscv-c.c
@@ -52,6 +52,9 @@ riscv_cpu_cpp_builtins (cpp_reader *pfile)
   if (TARGET_DIV && TARGET_MUL)
 builtin_define ("__riscv_muldiv");

+  if (TARGET_VECTOR)
+builtin_define_with_int_value("__riscv_vector", riscv_vlen);
+
   builtin_define_with_int_value ("__riscv_xlen", UNITS_PER_WORD * 8);
   if (TARGET_HARD_FLOAT)
 builtin_define_with_int_value ("__riscv_flen", UNITS_PER_FP_REG * 8);
diff --git a/gcc/config/riscv/riscv-opts.h b/gcc/config/riscv/riscv-opts.h
index f3031f2e523..87f3abd7826 100644
--- a/gcc/config/riscv/riscv-opts.h
+++ b/gcc/config/riscv/riscv-opts.h
@@ -46,4 +46,10 @@ enum riscv_microarchitecture_type {
 };
 extern enum riscv_microarchitecture_type riscv_microarchitecture;

+enum riscv_vlen_bits {
+  VLEN_64 = 64,
+  VLEN_128 = 128
+};
+extern enum riscv_vlen_bits riscv_vlen;
+
 #endif /* ! GCC_RISCV_OPTS_H */
diff --git a/gcc/config/riscv/riscv-v.h b/gcc/config/riscv/riscv-v.h
index 6e193f936a4..c17242b9d47 100755
--- a/gcc/config/riscv/riscv-v.h
+++ b/gcc/config/riscv/riscv-v.h
@@ -22,8 +22,22 @@ along with GCC; see the file COPYING3.  If not see
 #ifndef GCC_RISCV_V_H
 #define GCC_RISCV_V_H

+#define TARGET_VECTOR_VLEN(BITS) (TARGET_VECTOR && riscv_vlen == VLEN_##BITS )
+
 #define V_REG_FIRST 66
 #define V_REG_LAST  97
 #define V_REG_NUM   (V_REG_LAST - V_REG_FIRST + 1)

+#define UNITS_PER_VR_REG (riscv_vlen / 8)
+
+#define VR_REG_P(REGNO)  \
+  ((unsigned int) ((int) (REGNO) - V_REG_FIRST) < V_REG_NUM)
+
+typedef enum {
+RVV_E8 = 0,
+RVV_E16,
+RVV_E32,
+RVV_E64
+} RISCV_VSEW_T;
+
 #endif
diff --git a/gcc/config/riscv/riscv.opt b/gcc/config/riscv/riscv.opt
index 436d51faccd..25c5c9d3545 100644
--- a/gcc/config/riscv/riscv.opt
+++ b/gcc/config/riscv/riscv.opt
@@ -62,6 +62,20 @@ Enum(abi_type) String(lp64f) Value(ABI_LP64F)
 EnumValue
 Enum(abi_type) String(lp64d) Value(ABI_LP64D)

+mvlen=
+Target Report RejectNegative Joined Enum(vlen_bits) Var(riscv_vlen) 
Init(VLEN_128)
+Specify bits of vector register.
+
+Enum
+Name(vlen_bits) Type(enum riscv_vlen_bits)
+Supported VLEN (for use with the -mvlen= option):
+
+EnumValue
+Enum(vlen_bits) String(64) Value(VLEN_64)
+
+EnumValue
+Enum(vlen_bits) String(128) Value(VLEN_128)
+
 mfdiv
 Target Report Mask(FDIV)
 Use hardware floating-point divide and square root instructions.
-- 
2.24.3 (Apple Git-128)


[PATH 2/6] RISC-V: Add vector register

2020-06-12 Thread 无音
gcc/ChangeLog:

* config/riscv/riscv-v.h: New.
* config/riscv/riscv.h (FIRST_PSEUDO_REGISTER): Add vector register.
(FIRST_PSEUDO_REGISTER): Likewise.
(CALL_USED_REGISTERS): Likewise.
(reg_class): Likewise.
(REG_CLASS_NAMES): Likewise.
(REG_CLASS_CONTENTS): Likewise.
(REG_ALLOC_ORDER): Likewise.
(REGISTER_NAMES): Likewise.
(ADDITIONAL_REGISTER_NAMES): Likewise.
* config/riscv/constraints.md (v/u/w): New.
---
 gcc/config/riscv/constraints.md |  9 
 gcc/config/riscv/riscv-v.h  | 29 
 gcc/config/riscv/riscv.h| 84 -
 3 files changed, 109 insertions(+), 13 deletions(-)
 create mode 100755 gcc/config/riscv/riscv-v.h

diff --git a/gcc/config/riscv/constraints.md b/gcc/config/riscv/constraints.md
index b4de83f8324..fb3c7fac8a0 100644
--- a/gcc/config/riscv/constraints.md
+++ b/gcc/config/riscv/constraints.md
@@ -27,6 +27,15 @@
 (define_register_constraint "j" "SIBCALL_REGS"
   "@internal")

+(define_register_constraint "v" "TARGET_VECTOR ? V_REGS : NO_REGS"
+  "v0 - v31")
+
+(define_register_constraint "u" "TARGET_VECTOR ? V_NOMASK_REGS : NO_REGS"
+  "v1 - v31")
+
+(define_register_constraint "w" "TARGET_VECTOR ? VMASK_REGS : NO_REGS"
+  "vector mask register v0.")
+
 ;; Avoid using register t0 for JALR's argument, because for some
 ;; microarchitectures that is a return-address stack hint.
 (define_register_constraint "l" "JALR_REGS"
diff --git a/gcc/config/riscv/riscv-v.h b/gcc/config/riscv/riscv-v.h
new file mode 100755
index 000..6e193f936a4
--- /dev/null
+++ b/gcc/config/riscv/riscv-v.h
@@ -0,0 +1,29 @@
+/* Definition of RISC-V target for GNU compiler.
+   Copyright (C) 2011-2019 Free Software Foundation, Inc.
+   Contributed by Andrew Waterman (and...@sifive.com).
+   Based on MIPS target for GNU compiler.
+
+This file is part of GCC.
+
+GCC 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.
+
+GCC 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.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING3.  If not see
+.  */
+
+#ifndef GCC_RISCV_V_H
+#define GCC_RISCV_V_H
+
+#define V_REG_FIRST 66
+#define V_REG_LAST  97
+#define V_REG_NUM   (V_REG_LAST - V_REG_FIRST + 1)
+
+#endif
diff --git a/gcc/config/riscv/riscv.h b/gcc/config/riscv/riscv.h
index 5130dc826d7..5c4cbbcbf0f 100644
--- a/gcc/config/riscv/riscv.h
+++ b/gcc/config/riscv/riscv.h
@@ -24,6 +24,8 @@ along with GCC; see the file COPYING3.  If not see

 #include "config/riscv/riscv-opts.h"

+#include "riscv-v.h"
+
 /* Target CPU builtins.  */
 #define TARGET_CPU_CPP_BUILTINS() riscv_cpu_cpp_builtins (pfile)

@@ -232,9 +234,10 @@ along with GCC; see the file COPYING3.  If not see
- 32 floating point registers
- 2 fake registers:
  - ARG_POINTER_REGNUM
- - FRAME_POINTER_REGNUM */
+ - FRAME_POINTER_REGNUM
+   - 32 vector registers */

-#define FIRST_PSEUDO_REGISTER 66
+#define FIRST_PSEUDO_REGISTER 98

 /* x0, sp, gp, and tp are fixed.  */

@@ -246,7 +249,10 @@ along with GCC; see the file COPYING3.  If not see
   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
   /* Others.  */ \
-  1, 1 \
+  1, 1, \
+  /* Vector registers.  */ \
+  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
+  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
 }

 /* a0-a7, t0-t6, fa0-fa7, and ft0-ft11 are volatile across calls.
@@ -260,7 +266,10 @@ along with GCC; see the file COPYING3.  If not see
   1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, \
   1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, \
   /* Others.  */ \
-  1, 1 \
+  1, 1, \
+  /* Vector registers.  */   \
+  1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, \
+  1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, \
 }

 /* Internal macros to classify an ISA register's type.  */
@@ -358,6 +367,9 @@ enum reg_class
   GR_REGS, /* integer registers */
   FP_REGS, /* floating-point registers */
   FRAME_REGS, /* arg pointer and frame pointer */
+  VMASK_REGS,   /* vector mask register */
+  V_NOMASK_REGS,/* Vector registers except vector mask 
register */
+  V_REGS,   /* Vector registers */
   ALL_REGS, /* all registers */
   LIM_REG_CLASSES /* max value + 1 */
 };
@@ -378,6 +390,9 @@ enum reg_class
   "GR_REGS", \
   "FP_REGS", \
   "FRAME_REGS", \
+  "VMASK_REGS", \
+  "V_NOMASK_REGS",  \
+  "V_REGS",  

[PATH 1/6] RISC-V: Add vector mask

2020-06-12 Thread 无音
- The first version for vector extension and verified on rv64imafdcv linux 
target with qemu.

gcc/ChangeLog:

* common/config/riscv/riscv-common.c: Parse vector extension.
* config/riscv/riscv.opt (TARGET_VECTOR): New.
---
 gcc/common/config/riscv/riscv-common.c | 4 
 gcc/config/riscv/riscv.opt | 2 ++
 2 files changed, 6 insertions(+)

diff --git a/gcc/common/config/riscv/riscv-common.c 
b/gcc/common/config/riscv/riscv-common.c
index eeb75717db0..37472b867bc 100644
--- a/gcc/common/config/riscv/riscv-common.c
+++ b/gcc/common/config/riscv/riscv-common.c
@@ -568,6 +568,10 @@ riscv_parse_arch_string (const char *isa, int *flags, 
location_t loc)
   if (subset_list->lookup ("c"))
 *flags |= MASK_RVC;

+  *flags &= ~MASK_VECTOR;
+  if (subset_list->lookup ("v"))
+*flags |= MASK_VECTOR;
+
   if (current_subset_list)
 delete current_subset_list;

diff --git a/gcc/config/riscv/riscv.opt b/gcc/config/riscv/riscv.opt
index 3b25f9a1014..436d51faccd 100644
--- a/gcc/config/riscv/riscv.opt
+++ b/gcc/config/riscv/riscv.opt
@@ -128,6 +128,8 @@ Mask(RVC)

 Mask(RVE)

+Mask(VECTOR)
+
 mriscv-attribute
 Target Report Var(riscv_emit_attribute_p) Init(-1)
 Emit RISC-V ELF attribute.
-- 
2.24.3 (Apple Git-128)


Re: [PATCH, RS6000 PR target/94954] Fix wrong codegen for vec_pack_to_short_fp32() builtin

2020-06-12 Thread David Edelsohn via Gcc-patches
Hi, Will

On Fri, Jun 12, 2020 at 12:22 AM will schmidt  wrote:
>
>
> Hi,
>   Fix codegen implementation for the builtin vec_pack_to_short_fp32.
>
>   Regtests are underway against powerpc64 (power7be,power8le,power9le).
>   (this is a power9 builtin, so should be a noop for most of those).
>   OK for trunk and backports?
>
>   Thanks
>   -Will
>
>
> [gcc]
>   target pr/94954
>
> * config/rs6000/altivec.h (vec_pack_to_short_fp32):  Update.
> * config/rs6000/altivec.md (UNSPEC_CONVERT_4F32_8F16):  New unspec.
> (convert_4f32_8f16):  New define_expand.
> * config/rs6000/rs6000-builtin.def (convert_4f32_8f16): New builtin 
> define
> and overload.
> * config/rs6000/rs6000-call.c (P9V_BUILTIN_VEC_CONVERT_4F32_8F16): New
> overloaded builtin entry.
> * config/rs6000/vsx.md (UNSPEC_VSX_XVCVSPHP): New unspec.
> (vsx_xvcvsphp): New define_insn.
>
> [testsuite]
> * testsuite/gcc.target/powerpc/builtins-1-p9-runnable.c: Update.
>
> diff --git a/gcc/config/rs6000/altivec.h b/gcc/config/rs6000/altivec.h
> index 0a7e8ab..ab10025 100644
> --- a/gcc/config/rs6000/altivec.h
> +++ b/gcc/config/rs6000/altivec.h
> @@ -431,11 +431,11 @@
>  /* Vector additions added in ISA 3.0.  */
>  #define vec_first_match_index __builtin_vec_first_match_index
>  #define vec_first_match_or_eos_index __builtin_vec_first_match_or_eos_index
>  #define vec_first_mismatch_index __builtin_vec_first_mismatch_index
>  #define vec_first_mismatch_or_eos_index 
> __builtin_vec_first_mismatch_or_eos_index
> -#define vec_pack_to_short_fp32 __builtin_vec_convert_4f32_8i16
> +#define vec_pack_to_short_fp32 __builtin_vec_convert_4f32_8f16
>  #define vec_parity_lsbb __builtin_vec_vparity_lsbb
>  #define vec_vctz __builtin_vec_vctz
>  #define vec_cnttz __builtin_vec_vctz
>  #define vec_vctzb __builtin_vec_vctzb
>  #define vec_vctzd __builtin_vec_vctzd
> diff --git a/gcc/config/rs6000/altivec.md b/gcc/config/rs6000/altivec.md
> index 159f24e..855e7cc 100644
> --- a/gcc/config/rs6000/altivec.md
> +++ b/gcc/config/rs6000/altivec.md
> @@ -78,10 +78,11 @@
> UNSPEC_VUNPACK_HI_SIGN_DIRECT
> UNSPEC_VUNPACK_LO_SIGN_DIRECT
> UNSPEC_VUPKHPX
> UNSPEC_VUPKLPX
> UNSPEC_CONVERT_4F32_8I16
> +   UNSPEC_CONVERT_4F32_8F16
> UNSPEC_DST
> UNSPEC_DSTT
> UNSPEC_DSTST
> UNSPEC_DSTSTT
> UNSPEC_LVSL
> @@ -3215,10 +3216,32 @@
>emit_insn (gen_altivec_vctuxs (rtx_tmp_lo, operands[2], const0_rtx));
>emit_insn (gen_altivec_vpkswss (operands[0], rtx_tmp_hi, rtx_tmp_lo));
>DONE;
>  })
>
> +
> +;; Convert two vector F32 to packed vector f16.

Just for consistency, the comment above probably should be F16
(capitalized) above.

Why does this pattern use V8HI mode instead of V8HF if this is for
8F16 in contrast to the existing 8I16 pattern?  Other than that
(fundamental) question, the rest looks good.

Thanks, David

> +(define_expand "convert_4f32_8f16"
> +  [(set (match_operand:V8HI 0 "register_operand" "=v")
> +   (unspec:V8HI [(match_operand:V4SF 1 "register_operand" "v")
> + (match_operand:V4SF 2 "register_operand" "v")]
> +UNSPEC_CONVERT_4F32_8F16))]
> +  "TARGET_P9_VECTOR"
> +{
> +  rtx rtx_tmp_hi = gen_reg_rtx (V4SImode);
> +  rtx rtx_tmp_lo = gen_reg_rtx (V4SImode);
> +
> +  emit_insn (gen_vsx_xvcvsphp (rtx_tmp_hi, operands[1] ));
> +  emit_insn (gen_vsx_xvcvsphp (rtx_tmp_lo, operands[2] ));
> +  if (BYTES_BIG_ENDIAN)
> +emit_insn (gen_altivec_vpkuwum (operands[0], rtx_tmp_lo, rtx_tmp_hi));
> +  else
> +emit_insn (gen_altivec_vpkuwum (operands[0], rtx_tmp_hi, rtx_tmp_lo));
> +  DONE;
> +})
> +
> +
>  ;; Generate
>  ;;xxlxor/vxor SCRATCH0,SCRATCH0,SCRATCH0
>  ;;vsubu?m SCRATCH2,SCRATCH1,%1
>  ;;vmaxs? %0,%1,SCRATCH2"
>  (define_expand "abs2"
> diff --git a/gcc/config/rs6000/rs6000-builtin.def 
> b/gcc/config/rs6000/rs6000-builtin.def
> index 8b1ddb0..47e9137 100644
> --- a/gcc/config/rs6000/rs6000-builtin.def
> +++ b/gcc/config/rs6000/rs6000-builtin.def
> @@ -2208,10 +2208,11 @@ BU_P8V_OVERLOAD_3 (VPERMXOR,   "vpermxor")
>
>  /* ISA 3.0 vector overloaded 2-argument functions. */
>  BU_P9V_AV_2 (VSLV, "vslv", CONST, vslv)
>  BU_P9V_AV_2 (VSRV, "vsrv", CONST, vsrv)
>  BU_P9V_AV_2 (CONVERT_4F32_8I16, "convert_4f32_8i16", CONST, 
> convert_4f32_8i16)
> +BU_P9V_AV_2 (CONVERT_4F32_8F16, "convert_4f32_8f16", CONST, 
> convert_4f32_8f16)
>
>  BU_P9V_AV_2 (VFIRSTMATCHINDEX_V16QI, "first_match_index_v16qi",
>  CONST, first_match_index_v16qi)
>  BU_P9V_AV_2 (VFIRSTMATCHINDEX_V8HI, "first_match_index_v8hi",
>  CONST, first_match_index_v8hi)
> @@ -2238,10 +2239,11 @@ BU_P9V_AV_2 (VFIRSTMISMATCHOREOSINDEX_V4SI, 
> "first_mismatch_or_eos_index_v4si",
>
>  /* ISA 3.0 vector overloaded 2-argument functions. */
>  BU_P9V_OVERLOAD_2 (VSLV,   "vslv")
>  BU_P9V_OVERLOAD_2 (VSRV,   "vsrv")
>  BU_P9V_OVERLOAD_2 

Re: [PATCH v2] tsan: Add param to disable func-entry-exit instrumentation

2020-06-12 Thread Marco Elver via Gcc-patches
On Fri, 12 Jun 2020, Jakub Jelinek wrote:

> On Fri, Jun 12, 2020 at 04:07:57PM +0200, Marco Elver wrote:
> > gcc/ChangeLog:
> > 
> > * params.opt: Add --param=tsan-instrument-func-entry-exit=.
> > * tsan.c (instrument_gimple): Make return value if func entry
> > and exit should be instrumented dependent on param.
> > 
> > gcc/testsuite/ChangeLog:
> > 
> > * c-c++-common/tsan/func_entry_exit.c: New test.
> > * c-c++-common/tsan/func_entry_exit_disabled.c: New test.
> 
> Ok.

Thanks!

Somehow the commit message contained the old changelog entry, this is
the new one:

gcc/ChangeLog:

* gimplify.c (gimplify_function_tree): Optimize and do not emit
IFN_TSAN_FUNC_EXIT in a finally block if we do not need it.
* params.opt: Add --param=tsan-instrument-func-entry-exit=.
* tsan.c (instrument_memory_accesses): Make
fentry_exit_instrument bool depend on new param.

gcc/testsuite/ChangeLog:

* c-c++-common/tsan/func_entry_exit.c: New test.
* c-c++-common/tsan/func_entry_exit_disabled.c: New test.


-- Marco


[Patch] testsuite: Add offloading_enabled check and use it for xfail (PR95622)

2020-06-12 Thread Tobias Burnus

For real offloading compilers, the configure-time ENABLE_OFFLOAD
macro is set to true.  If it is set, some additional code paths
are enabled – which can affect code generation with -fopenmp/-fopenacc.

As the PR shows, this can make differences for passing/failing a
testcase. – In principle, it is supposed to *pass* with ENABLE_OFFLOAD
but until the PR is fixed, XFAIL those test cases.

OK for the trunk and GCC 10?
(The patches causing the to-be-xfailed issue will be backported.)

Tobias

-
Mentor Graphics (Deutschland) GmbH, Arnulfstraße 201, 80634 München / Germany
Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Alexander 
Walter
testsuite: Add offloading_enabled check and use it for xfail (PR95622)

gcc/testsuite/ChangeLog:

	PR middle-end/95622
	* lib/target-supports.exp (check_effective_target_offloading_enabled):
	New.
	* c-c++-common/goacc/kernels-alias-ipa-pta-2.c: Use it for xfail.
	* c-c++-common/goacc/kernels-alias-ipa-pta-4.c: Likewise.
	* c-c++-common/goacc/kernels-alias-ipa-pta.c: Likewise.

diff --git a/gcc/testsuite/c-c++-common/goacc/kernels-alias-ipa-pta-2.c b/gcc/testsuite/c-c++-common/goacc/kernels-alias-ipa-pta-2.c
index f16d698af0d..1f62337ff51 100644
--- a/gcc/testsuite/c-c++-common/goacc/kernels-alias-ipa-pta-2.c
+++ b/gcc/testsuite/c-c++-common/goacc/kernels-alias-ipa-pta-2.c
@@ -32,6 +32,7 @@ foo (void)
   free (c);
 }
 
-/* { dg-final { scan-tree-dump-times "(?n)= 0;$" 2 "optimized" } } */
+/* XFAIL: see PR middle-end/95622; fails if ENABLE_OFFLOAD is set.  */
+/* { dg-final { scan-tree-dump-times "(?n)= 0;$" 2 "optimized" { xfail offloading_enabled } } } */
 /* { dg-final { scan-tree-dump-times "(?n)= 1;$" 1 "optimized" } } */
 /* { dg-final { scan-tree-dump-times "(?n)= \\*a" 0 "optimized" } } */
diff --git a/gcc/testsuite/c-c++-common/goacc/kernels-alias-ipa-pta-4.c b/gcc/testsuite/c-c++-common/goacc/kernels-alias-ipa-pta-4.c
index 20b21dcb577..d7bc6cd6ff1 100644
--- a/gcc/testsuite/c-c++-common/goacc/kernels-alias-ipa-pta-4.c
+++ b/gcc/testsuite/c-c++-common/goacc/kernels-alias-ipa-pta-4.c
@@ -16,6 +16,7 @@ foo (void)
   }
 }
 
-/* { dg-final { scan-tree-dump-times "(?n)= 0;$" 2 "optimized" } } */
+/* XFAIL: see PR middle-end/95622; fails if ENABLE_OFFLOAD is set.  */
+/* { dg-final { scan-tree-dump-times "(?n)= 0;$" 2 "optimized" { xfail offloading_enabled } } } */
 /* { dg-final { scan-tree-dump-times "(?n)= 1;$" 1 "optimized" } } */
-/* { dg-final { scan-tree-dump-times "(?n)= \\*_\[0-9\];$" 0 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "(?n)= \\*_\[0-9\];$" 0 "optimized" { xfail offloading_enabled } } } */
diff --git a/gcc/testsuite/c-c++-common/goacc/kernels-alias-ipa-pta.c b/gcc/testsuite/c-c++-common/goacc/kernels-alias-ipa-pta.c
index 969b466e8a8..a6339283876 100644
--- a/gcc/testsuite/c-c++-common/goacc/kernels-alias-ipa-pta.c
+++ b/gcc/testsuite/c-c++-common/goacc/kernels-alias-ipa-pta.c
@@ -18,6 +18,7 @@ foo (void)
   }
 }
 
-/* { dg-final { scan-tree-dump-times "(?n)= 0;$" 2 "optimized" } } */
+/* XFAIL: see PR middle-end/95622; fails if ENABLE_OFFLOAD is set.  */
+/* { dg-final { scan-tree-dump-times "(?n)= 0;$" 2 "optimized" { xfail offloading_enabled } } } */
 /* { dg-final { scan-tree-dump-times "(?n)= 1;$" 1 "optimized" } } */
 /* { dg-final { scan-tree-dump-times "(?n)= \\*_\[0-9\]\\\[0\\\];$" 0 "optimized" } } */
diff --git a/gcc/testsuite/lib/target-supports.exp b/gcc/testsuite/lib/target-supports.exp
index 4dbeccd8346..862a0735b49 100644
--- a/gcc/testsuite/lib/target-supports.exp
+++ b/gcc/testsuite/lib/target-supports.exp
@@ -997,6 +997,12 @@ proc check_effective_target_fgraphite {} {
 } "-O1 -fgraphite"]
 }
 
+# Return 1 if compiled with --enable-offload-targets=
+# This affects host compilation as ENABLE_OFFLOAD then evaluates to true.
+proc check_effective_target_offloading_enabled {} {
+return [check_configured_with "--enable-offload-targets"]
+}
+
 # Return 1 if compilation with -fopenacc is error-free for trivial
 # code, 0 otherwise.
 


Re: [PATCH v2] tsan: Add param to disable func-entry-exit instrumentation

2020-06-12 Thread Jakub Jelinek via Gcc-patches
On Fri, Jun 12, 2020 at 04:07:57PM +0200, Marco Elver wrote:
> gcc/ChangeLog:
> 
>   * params.opt: Add --param=tsan-instrument-func-entry-exit=.
>   * tsan.c (instrument_gimple): Make return value if func entry
>   and exit should be instrumented dependent on param.
> 
> gcc/testsuite/ChangeLog:
> 
>   * c-c++-common/tsan/func_entry_exit.c: New test.
>   * c-c++-common/tsan/func_entry_exit_disabled.c: New test.

Ok.

Jakub



[PATCH v2] tsan: Add param to disable func-entry-exit instrumentation

2020-06-12 Thread Marco Elver via Gcc-patches
Adds param tsan-instrument-func-entry-exit, which controls if
__tsan_func_{entry,exit} calls should be emitted or not. The default
behaviour is to emit the calls.

This may be required by alternative race detection runtimes. One such
runtime is the Kernel Concurrency Sanitizer (KCSAN):

https://github.com/google/ktsan/wiki/KCSAN

After this change, GCC should satisfy all requirements for KCSAN:

https://lore.kernel.org/lkml/20200515150338.190344-7-el...@google.com/

gcc/ChangeLog:

* params.opt: Add --param=tsan-instrument-func-entry-exit=.
* tsan.c (instrument_gimple): Make return value if func entry
and exit should be instrumented dependent on param.

gcc/testsuite/ChangeLog:

* c-c++-common/tsan/func_entry_exit.c: New test.
* c-c++-common/tsan/func_entry_exit_disabled.c: New test.
---
v2:
* Instead of modifying the return value of instrument_gimple(), change
  the boolean expression for fentry_exit_instrument.
* Optimize gimplify and do not emit IFN_TSAN_FUNC_EXIT in a finally
  block if we do not need it.
* Change test to also look at gimple dump.
---
 gcc/gimplify.c|  3 +-
 gcc/params.opt|  4 +++
 .../c-c++-common/tsan/func_entry_exit.c   | 29 +++
 .../tsan/func_entry_exit_disabled.c   | 29 +++
 gcc/tsan.c|  4 ++-
 5 files changed, 67 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/c-c++-common/tsan/func_entry_exit.c
 create mode 100644 gcc/testsuite/c-c++-common/tsan/func_entry_exit_disabled.c

diff --git a/gcc/gimplify.c b/gcc/gimplify.c
index e14932fafaf..416fb609b94 100644
--- a/gcc/gimplify.c
+++ b/gcc/gimplify.c
@@ -15011,7 +15011,8 @@ gimplify_function_tree (tree fndecl)
   bind = new_bind;
 }
 
-  if (sanitize_flags_p (SANITIZE_THREAD))
+  if (sanitize_flags_p (SANITIZE_THREAD)
+  && param_tsan_instrument_func_entry_exit)
 {
   gcall *call = gimple_build_call_internal (IFN_TSAN_FUNC_EXIT, 0);
   gimple *tf = gimple_build_try (seq, call, GIMPLE_TRY_FINALLY);
diff --git a/gcc/params.opt b/gcc/params.opt
index 9b564bb046c..e29a44e7712 100644
--- a/gcc/params.opt
+++ b/gcc/params.opt
@@ -912,6 +912,10 @@ Set the maximum number of instructions executed in 
parallel in reassociated tree
 Common Joined UInteger Var(param_tsan_distinguish_volatile) IntegerRange(0, 1) 
Param
 Emit special instrumentation for accesses to volatiles.
 
+-param=tsan-instrument-func-entry-exit=
+Common Joined UInteger Var(param_tsan_instrument_func_entry_exit) Init(1) 
IntegerRange(0, 1) Param
+Emit instrumentation calls to __tsan_func_entry() and __tsan_func_exit().
+
 -param=uninit-control-dep-attempts=
 Common Joined UInteger Var(param_uninit_control_dep_attempts) Init(1000) 
IntegerRange(1, 65536) Param Optimization
 Maximum number of nested calls to search for control dependencies during 
uninitialized variable analysis.
diff --git a/gcc/testsuite/c-c++-common/tsan/func_entry_exit.c 
b/gcc/testsuite/c-c++-common/tsan/func_entry_exit.c
new file mode 100644
index 000..9c1b697411c
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/tsan/func_entry_exit.c
@@ -0,0 +1,29 @@
+/* { dg-do compile } */
+/* { dg-options "-fdump-tree-gimple -fdump-tree-optimized" } */
+
+int x;
+
+__attribute__((noinline))
+void fn1(void)
+{
+  x++;
+}
+
+__attribute__((noinline))
+void fn2(void)
+{
+  fn1();
+}
+
+__attribute__((noinline))
+int main(int argc, char *argv[])
+{
+  fn1();
+  fn2();
+  return 0;
+}
+
+// { dg-final { scan-tree-dump "TSAN_FUNC_EXIT" "gimple" } }
+// { dg-final { scan-tree-dump-times "__tsan_func_entry" 3 "optimized" } }
+// { dg-final { scan-tree-dump-times "__tsan_func_exit" 3 "optimized" } }
+// { dg-final { scan-tree-dump "__tsan_write" "optimized" } }
diff --git a/gcc/testsuite/c-c++-common/tsan/func_entry_exit_disabled.c 
b/gcc/testsuite/c-c++-common/tsan/func_entry_exit_disabled.c
new file mode 100644
index 000..63cc73b9eba
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/tsan/func_entry_exit_disabled.c
@@ -0,0 +1,29 @@
+/* { dg-do compile } */
+/* { dg-options "--param=tsan-instrument-func-entry-exit=0 -fdump-tree-gimple 
-fdump-tree-optimized" } */
+
+int x;
+
+__attribute__((noinline))
+void fn1(void)
+{
+  x++;
+}
+
+__attribute__((noinline))
+void fn2(void)
+{
+  fn1();
+}
+
+__attribute__((noinline))
+int main(int argc, char *argv[])
+{
+  fn1();
+  fn2();
+  return 0;
+}
+
+// { dg-final { scan-tree-dump-not "TSAN_FUNC_EXIT" "gimple" } }
+// { dg-final { scan-tree-dump-not "__tsan_func_entry" "optimized" } }
+// { dg-final { scan-tree-dump-not "__tsan_func_exit" "optimized" } }
+// { dg-final { scan-tree-dump "__tsan_write" "optimized" } }
diff --git a/gcc/tsan.c b/gcc/tsan.c
index 447acccfafd..4d6223454b5 100644
--- a/gcc/tsan.c
+++ b/gcc/tsan.c
@@ -804,7 +804,9 @@ instrument_memory_accesses (bool *cfg_changed)
  func_exit_seen = true;

[PATCH] Add .clang-tidy to git ignored.

2020-06-12 Thread Martin Liška

Installed as obvious.

ChangeLog:

* .gitignore: Add .clang-tidy.
---
 .gitignore | 1 +
 1 file changed, 1 insertion(+)

diff --git a/.gitignore b/.gitignore
index d9d3967a12c..d9eeaf2ed7a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -36,6 +36,7 @@ TAGS.sub
 .lvimrc
 
 .clang-format

+.clang-tidy
 .clangd
 compile_commands.json
 
--

2.26.2



Re: [PATCH] vectorizer: add _bb_vec_info::const_iterator

2020-06-12 Thread Richard Biener via Gcc-patches
On June 12, 2020 2:55:49 PM GMT+02:00, "Martin Liška"  wrote:
>On 6/12/20 1:43 PM, Richard Sandiford wrote:
>> Martin Liška  writes:
>>> On 6/12/20 12:46 PM, Richard Sandiford wrote:
 Martin Liška  writes:
> Hello.
>
> I'm working one extension of SLP which will allow to vectorize
>multiple
> BBs. This is a first step where I abstract
>_bb_vec_info::region_begin and
> _bb_vec_info::region end by providing an iterator.

 Nice.

> diff --git a/gcc/tree-vectorizer.h b/gcc/tree-vectorizer.h
> index 6c830ad09f4..542d49402d2 100644
> --- a/gcc/tree-vectorizer.h
> +++ b/gcc/tree-vectorizer.h
> @@ -787,12 +787,46 @@ loop_vec_info_for_loop (class loop *loop)
> typedef class _bb_vec_info : public vec_info
> {
> public:
> +  struct const_iterator
> +  {
> +const_iterator (gimple_stmt_iterator _gsi): gsi (_gsi)
> +{
> +}
> +
> +const_iterator &
> +operator++ (int)
> +{
> +  gsi_next (); return *this;
> +}

 Isn't this really operator++()?
>>>
>>> It is, but post-increment ++ operators have one integer argument (so
>that
>>> one can distinguish them from pre-increment operators:
>>> https://en.cppreference.com/w/cpp/language/operator_incdec)
>> 
>> Sure, but what I mean by:
>> 
 I.e. it returns a reference to the
 modified iterator instead of the value at the original iterator.
>> 
>> is that the above implements the semantics of a preincrement, not a
>> postincrement, so it should be operator++() rather than
>operator++(int).
>
>Ah, ok, I've got it.
>
>> 
>> In other words, the function (rightly) implements “++it” rather than
>“it++”.
>> 
>> With that fixed, it seems like a range-based for loop should work.
>
>Yes, it works. The syntax is really neat:
>
>for (gimple *stmt: *bb_vinfo)

I'd rather have what we iterate over more explicit like

For(gimple. *stmt : bb_vinfo->region_stmts()) 

Richard. 

>
>I've tested vect.exp and i386.exp. May I install the patch after proper
>testing?
>
>Thanks,
>Martin
>
>> 
>> Thanks,
>> Richard
>> 



Re: [stage1][PATCH] Lower VEC_COND_EXPR into internal functions.

2020-06-12 Thread Martin Liška

On 6/12/20 11:43 AM, Richard Biener wrote:

So ... how far are you with enforcing a split VEC_COND_EXPR?
Thus can we avoid the above completely (even as intermediate
state)?


Apparently, I'm quite close. Using the attached patch I see only 2 testsuite
failures:

FAIL: gcc.dg/tree-ssa/pr68714.c scan-tree-dump-times reassoc1 " <= " 1
FAIL: gcc.target/i386/pr78102.c scan-assembler-times pcmpeqq 3

The first one is about teaching reassoc about the SSA_NAMEs in VEC_COND_EXPR. I 
haven't
analyze the second failure.

I'm also not sure about the gimlification change, I see a superfluous 
assignments:
  vec_cond_cmp.5 = _1 == _2;
  vec_cond_cmp.6 = vec_cond_cmp.5;
  vec_cond_cmp.7 = vec_cond_cmp.6;
  _3 = VEC_COND_EXPR ;
?

So with the suggested patch, the EH should be gone as you suggested. Right?

Martin
>From 3589a849ba63d7289e547b44c9f7349ee23ee2ca Mon Sep 17 00:00:00 2001
From: Martin Liska 
Date: Mon, 9 Mar 2020 13:23:03 +0100
Subject: [PATCH] Lower VEC_COND_EXPR into internal functions.

gcc/ChangeLog:

2020-03-30  Martin Liska  

	* expr.c (expand_expr_real_2): Put gcc_unreachable, we should reach
	this path.
	(do_store_flag): Likewise here.
	* internal-fn.c (vec_cond_mask_direct): New.
	(vec_cond_direct): Likewise.
	(vec_condu_direct): Likewise.
	(vec_condeq_direct): Likewise.
	(expand_vect_cond_optab_fn): Move from optabs.c.
	(expand_vec_cond_optab_fn): New alias.
	(expand_vec_condu_optab_fn): Likewise.
	(expand_vec_condeq_optab_fn): Likewise.
	(expand_vect_cond_mask_optab_fn): Moved from optabs.c.
	(expand_vec_cond_mask_optab_fn): New alias.
	(direct_vec_cond_mask_optab_supported_p): New.
	(direct_vec_cond_optab_supported_p): Likewise.
	(direct_vec_condu_optab_supported_p): Likewise.
	(direct_vec_condeq_optab_supported_p): Likewise.
	* internal-fn.def (VCOND): New new internal optab
	function.
	(VCONDU): Likewise.
	(VCONDEQ): Likewise.
	(VCOND_MASK): Likewise.
	* optabs.c (expand_vec_cond_mask_expr): Removed.
	(expand_vec_cond_expr): Likewise.
	* optabs.h (expand_vec_cond_expr): Likewise.
	(vector_compare_rtx): Likewise.
	* passes.def: Add pass_gimple_isel.
	* tree-cfg.c (verify_gimple_assign_ternary): Add new
	GIMPLE check.
	* tree-pass.h (make_pass_gimple_isel): New.
	* tree-ssa-forwprop.c (pass_forwprop::execute): Do not forward
	VEC_COND_EXPR.
	* tree-vect-generic.c (expand_vector_divmod): Expand to SSA_NAME.
	* tree-vect-isel.c: New file.
	* Makefile.in: Add the file.
	* gimplify.c (gimplify_expr): Assign first argument of
	VEC_COND_EXPR to a SSA name.
	* tree-vect-stmts.c (vectorizable_condition): Assign first
	argument of VEC_COND_EXPR to a SSA name.

gcc/testsuite/ChangeLog:

	* g++.dg/vect/vec-cond-expr-eh.C: New test.
---
 gcc/Makefile.in  |   2 +
 gcc/expr.c   |  25 +-
 gcc/gimplify.c   |   6 +-
 gcc/internal-fn.c|  89 +++
 gcc/internal-fn.def  |   5 +
 gcc/optabs.c | 124 +-
 gcc/optabs.h |   7 +-
 gcc/passes.def   |   1 +
 gcc/testsuite/g++.dg/vect/vec-cond-expr-eh.C |  17 ++
 gcc/tree-cfg.c   |   7 +
 gcc/tree-pass.h  |   1 +
 gcc/tree-ssa-forwprop.c  |   4 +
 gcc/tree-vect-generic.c  |  35 ++-
 gcc/tree-vect-isel.c | 244 +++
 gcc/tree-vect-stmts.c|   4 +-
 15 files changed, 399 insertions(+), 172 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/vect/vec-cond-expr-eh.C
 create mode 100644 gcc/tree-vect-isel.c

diff --git a/gcc/Makefile.in b/gcc/Makefile.in
index 4f70c189b9d..4cbb9d23606 100644
--- a/gcc/Makefile.in
+++ b/gcc/Makefile.in
@@ -1631,6 +1631,7 @@ OBJS = \
 	tree-streamer-out.o \
 	tree-tailcall.o \
 	tree-vect-generic.o \
+	tree-vect-isel.o \
 	tree-vect-patterns.o \
 	tree-vect-data-refs.o \
 	tree-vect-stmts.o \
@@ -2600,6 +2601,7 @@ GTFILES = $(CPPLIB_H) $(srcdir)/input.h $(srcdir)/coretypes.h \
   $(srcdir)/dwarf2cfi.c \
   $(srcdir)/dwarf2out.c \
   $(srcdir)/tree-vect-generic.c \
+  $(srcdir)/tree-vect-isel.c \
   $(srcdir)/dojump.c $(srcdir)/emit-rtl.h \
   $(srcdir)/emit-rtl.c $(srcdir)/except.h $(srcdir)/explow.c $(srcdir)/expr.c \
   $(srcdir)/expr.h \
diff --git a/gcc/expr.c b/gcc/expr.c
index ca6b1c1291e..3c68b0d754c 100644
--- a/gcc/expr.c
+++ b/gcc/expr.c
@@ -9316,17 +9316,8 @@ expand_expr_real_2 (sepops ops, rtx target, machine_mode tmode,
   if (temp != 0)
 	return temp;
 
-  /* For vector MIN , expand it a VEC_COND_EXPR 
-	 and similarly for MAX .  */
   if (VECTOR_TYPE_P (type))
-	{
-	  tree t0 = make_tree (type, op0);
-	  tree t1 = make_tree (type, op1);
-	  tree comparison = build2 (code == MIN_EXPR ? LE_EXPR : GE_EXPR,
-type, t0, t1);
-	  return expand_vec_cond_expr (type, comparison, t0, t1,
-   original_target);
-	}
+	

Re: [PATCH] vectorizer: add _bb_vec_info::const_iterator

2020-06-12 Thread Richard Sandiford
Martin Liška  writes:
> diff --git a/gcc/tree-vect-patterns.c b/gcc/tree-vect-patterns.c
> index 636ad59c001..eac372e6abc 100644
> --- a/gcc/tree-vect-patterns.c
> +++ b/gcc/tree-vect-patterns.c
> @@ -5120,20 +5120,12 @@ vect_determine_precisions (vec_info *vinfo)
>else
>  {
>bb_vec_info bb_vinfo = as_a  (vinfo);
> -  gimple_stmt_iterator si = bb_vinfo->region_end;
> -  gimple *stmt;
> -  do
> +  for (gimple *stmt: *bb_vinfo)
>   {
> -   if (!gsi_stmt (si))
> - si = gsi_last_bb (bb_vinfo->bb);
> -   else
> - gsi_prev ();
> -   stmt = gsi_stmt (si);
> stmt_vec_info stmt_info = vinfo->lookup_stmt (stmt);
> if (stmt_info && STMT_VINFO_VECTORIZABLE (stmt_info))
>   vect_determine_stmt_precisions (vinfo, stmt_info);
>   }
> -  while (stmt != gsi_stmt (bb_vinfo->region_begin));
>  }
>  }

This loop wants a reverse iterator: it starts at the end and walks
backwards.  That's important because vect_determine_stmt_precisions
acts based on information recorded about later uses.

> @@ -5492,10 +5484,8 @@ vect_pattern_recog (vec_info *vinfo)
>else
>  {
>bb_vec_info bb_vinfo = as_a  (vinfo);
> -  for (si = bb_vinfo->region_begin;
> -gsi_stmt (si) != gsi_stmt (bb_vinfo->region_end); gsi_next ())
> +  for (gimple *stmt: *bb_vinfo)
>   {
> -   gimple *stmt = gsi_stmt (si);
> stmt_vec_info stmt_info = bb_vinfo->lookup_stmt (stmt);
> if (!stmt_info || !STMT_VINFO_VECTORIZABLE (stmt_info))
>   continue;

Very minor, but I think it's more usual to have a space both sides of
the ":".  (That's also the formatting used by libstdc++-v3, and ties in
nicely with the formatting of infix operators.)  Same for the others.

> diff --git a/gcc/tree-vect-stmts.c b/gcc/tree-vect-stmts.c
> index cdd6f6c5e5d..766598862d4 100644
> --- a/gcc/tree-vect-stmts.c
> +++ b/gcc/tree-vect-stmts.c
> @@ -1342,7 +1342,7 @@ vect_init_vector_1 (vec_info *vinfo, stmt_vec_info 
> stmt_vinfo, gimple *new_stmt,
>else
> {
>bb_vec_info bb_vinfo = dyn_cast  (vinfo);
> -   gimple_stmt_iterator gsi_region_begin = bb_vinfo->region_begin;
> +   gimple_stmt_iterator gsi_region_begin = bb_vinfo->begin ().gsi;
> gsi_insert_before (_region_begin, new_stmt, GSI_SAME_STMT);
> }
>  }

Feels like this kind-of breaks the abstraction a bit.

Would it make sense instead to add the operators to gimple_stmt_iterator
itself and just make const_iterator a typedef of that?  We could then
reuse this work for BB iterators, etc.

> diff --git a/gcc/tree-vectorizer.h b/gcc/tree-vectorizer.h
> index 6c830ad09f4..8f80a7d1bce 100644
> --- a/gcc/tree-vectorizer.h
> +++ b/gcc/tree-vectorizer.h
> @@ -787,12 +787,46 @@ loop_vec_info_for_loop (class loop *loop)
>  typedef class _bb_vec_info : public vec_info
>  {
>  public:
> +  struct const_iterator
> +  {
> +const_iterator (gimple_stmt_iterator _gsi): gsi (_gsi)
> +{
> +}

Again very minor, but I think the conventions say that this should
be defined on one line, like the later operator* is.  Space before
":" here too.

Thanks,
Richard


Re: [PATCH] avoid false positives due to compute_objsize (PR 95353)

2020-06-12 Thread Christophe Lyon via Gcc-patches
Hi,


On Thu, 11 Jun 2020 at 22:37, Rainer Orth  wrote:
>
> Hi Martin,
>
> > The compute_objsize() function started out as a thin wrapper around
> > compute_builtin_object_size(), but over time developed its own
> > features to compensate for the other function's limitations (such
> > as its inability to work with ranges).  The interaction of these
> > features and the limitations has started to become increasingly
> > problematic as the former function is used in more contexts.
> >
> > A complete "fix" for all the problems (as well as some other
> > limitations) that I'm working on will be more extensive and won't
> > be appropriate for backports.  Until then, the attached patch
> > cleans up the extensions compute_objsize() has accumulated over
> > the years to avoid a class of false positives.
> >
> > To make the warnings issued based on the results of the function
> > easier to understand and fix, the patch also adds an informative
> > message to many instances of -Wstringop-overflow to point to
> > the object to which the warning refers.  This is especially
> > helpful when the object is referenced by a series of pointer
> > operations.
> >
> > Tested by boostrapping on x86_64-linux and building Binutils/GDB,
> > Glibc, and the Linux kernel with no new warnings.
> >
> > Besides applying it to trunk I'm looking to backport the fix to
> > GCC 10.
>
> it seems you were over-eager in removing xfail's from
> gcc.dg/builtin-stringop-chk-5.c: on both Solaris/SPARC and x86 (32-bit
> only) I see
>
> +FAIL: gcc.dg/builtin-stringop-chk-5.c (test for excess errors)
> +FAIL: gcc.dg/builtin-stringop-chk-5.c memcpy into allocated (test for 
> warnings, line 136)
> +FAIL: gcc.dg/builtin-stringop-chk-5.c memcpy into allocated (test for 
> warnings, line 139)
> +FAIL: gcc.dg/builtin-stringop-chk-5.c memcpy into allocated (test for 
> warnings, line 142)
> +FAIL: gcc.dg/builtin-stringop-chk-5.c memcpy into allocated (test for 
> warnings, line 145)
> +FAIL: gcc.dg/builtin-stringop-chk-5.c memcpy into allocated (test for 
> warnings, line 148)
> +FAIL: gcc.dg/builtin-stringop-chk-5.c memcpy into allocated (test for 
> warnings, line 151)
>
> Excess errors:
> /vol/gcc/src/hg/master/local/gcc/testsuite/gcc.dg/builtin-stringop-chk-5.c:136:3:
>  warning: 'memset' writing 4 bytes into a region of size 1 overflows the 
> destination [-Wstringop-overflow=]
> /vol/gcc/src/hg/master/local/gcc/testsuite/gcc.dg/builtin-stringop-chk-5.c:139:3:
>  warning: 'memset' writing 4 bytes into a region of size 1 overflows the 
> destination [-Wstringop-overflow=]
> /vol/gcc/src/hg/master/local/gcc/testsuite/gcc.dg/builtin-stringop-chk-5.c:142:3:
>  warning: 'memset' writing 3 bytes into a region of size 1 overflows the 
> destination [-Wstringop-overflow=]
> /vol/gcc/src/hg/master/local/gcc/testsuite/gcc.dg/builtin-stringop-chk-5.c:145:3:
>  warning: 'memset' writing 3 bytes into a region of size 1 overflows the 
> destination [-Wstringop-overflow=]
> /vol/gcc/src/hg/master/local/gcc/testsuite/gcc.dg/builtin-stringop-chk-5.c:148:3:
>  warning: 'memset' writing 2 bytes into a region of size 1 overflows the 
> destination [-Wstringop-overflow=]
> /vol/gcc/src/hg/master/local/gcc/testsuite/gcc.dg/builtin-stringop-chk-5.c:151:3:
>  warning: 'memset' writing 2 bytes into a region of size 1 overflows the 
> destination [-Wstringop-overflow=]
>

I see the same error messages on arm.

Christophe


> Rainer
>
> --
> -
> Rainer Orth, Center for Biotechnology, Bielefeld University


[PATCH] Linux/i386: Remove SUBTARGET_FRAME_POINTER_REQUIRED

2020-06-12 Thread H.J. Lu via Gcc-patches
On Thu, Jun 11, 2020 at 8:24 PM Jeff Law  wrote:
>
> On Sat, 2020-05-02 at 04:55 -0700, H.J. Lu wrote:
> > Currently patchable area is at the wrong place.  It is placed immediately
> > after function label, before both .cfi_startproc and ENDBR.  This patch
> > adds UNSPECV_PATCHABLE_AREA for pseudo patchable area instruction and
> > changes ENDBR insertion pass to also insert patchable area instruction.
> > TARGET_ASM_PRINT_PATCHABLE_FUNCTION_ENTRY is defined to avoid placing
> > patchable area before .cfi_startproc and ENDBR.
> >
> > OK for master?
> >
> > Thanks.
> >
> > H.J.
> > ---
> > gcc/
> >
> >   PR target/93492
> >   * config/i386/i386-features.c (rest_of_insert_endbranch):
> >   Renamed to ...
> >   (rest_of_insert_endbr_and_patchable_area): Change return type
> >   to void. Add need_endbr and patchable_area_size arguments.
> >   Don't call timevar_push nor timevar_pop.  Replace
> >   endbr_queued_at_entrance with insn_queued_at_entrance.  Insert
> >   UNSPECV_PATCHABLE_AREA for patchable area.
> >   (pass_data_insert_endbranch): Renamed to ...
> >   (pass_data_insert_endbr_and_patchable_area): This.  Change
> >   pass name to endbr_and_patchable_area.
> >   (pass_insert_endbranch): Renamed to ...
> >   (pass_insert_endbr_and_patchable_area): This.  Add need_endbr
> >   and patchable_area_size;.
> >   (pass_insert_endbr_and_patchable_area::gate): Set and check
> >   need_endbr and patchable_area_size.
> >   (pass_insert_endbr_and_patchable_area::execute): Call
> >   timevar_push and timevar_pop.  Pass need_endbr and
> >   patchable_area_size to rest_of_insert_endbr_and_patchable_area.
> >   (make_pass_insert_endbranch): Renamed to ...
> >   (make_pass_insert_endbr_and_patchable_area): This.
> >   * config/i386/i386-passes.def: Replace pass_insert_endbranch
> >   with pass_insert_endbr_and_patchable_area.
> >   * config/i386/i386-protos.h (ix86_output_patchable_area): New.
> >   (make_pass_insert_endbranch): Renamed to ...
> >   (make_pass_insert_endbr_and_patchable_area): This.
> >   * config/i386/i386.c (ix86_asm_output_function_label): Set
> >   function_label_emitted to true.
> >   (ix86_print_patchable_function_entry): New function.
> >   (ix86_output_patchable_area): Likewise.
> >   (x86_function_profiler): Replace endbr_queued_at_entrance with
> >   insn_queued_at_entrance.  Generate ENDBR only for TYPE_ENDBR.
> >   Call ix86_output_patchable_area to generate patchable area if
> >   needed.
> >   (TARGET_ASM_PRINT_PATCHABLE_FUNCTION_ENTRY): New.
> >   * i386.h (queued_insn_type): New.
> >   (machine_function): Add function_label_emitted.  Replace
> >   endbr_queued_at_entrance with insn_queued_at_entrance.
> >   * config/i386/i386.md (UNSPECV_PATCHABLE_AREA): New.
> >   (patchable_area): New.
> >
> > gcc/testsuite/
> >
> >   PR target/93492
> >   * gcc.target/i386/pr93492-1.c: New test.
> >   * gcc.target/i386/pr93492-2.c: Likewise.
> >   * gcc.target/i386/pr93492-3.c: Likewise.
> >   * gcc.target/i386/pr93492-4.c: Likewise.
> >   * gcc.target/i386/pr93492-5.c: Likewise.
> OK
> jeff
> >

My patch triggered a latent x86 backend bug.   This patch fixes
it.  OK for master?

Thanks.

-- 
H.J.
From 0a5ebc4daad8533271406a4713059c19ebc76f56 Mon Sep 17 00:00:00 2001
From: "H.J. Lu" 
Date: Fri, 12 Jun 2020 05:44:59 -0700
Subject: [PATCH] Linux/i386: Remove SUBTARGET_FRAME_POINTER_REQUIRED

config/i386/gnu-user.h has

 #define SUBTARGET_FRAME_POINTER_REQUIRED crtl->profile

ix86_frame_pointer_required() has

  /* Several x86 os'es need a frame pointer for other reasons,
 usually pertaining to setjmp.  */
  if (SUBTARGET_FRAME_POINTER_REQUIRED)
return true;
...

  if (crtl->profile && !flag_fentry)
return true;

A frame pointer is needed only for -pg, not for -mfentry -pg.  Remove
SUBTARGET_FRAME_POINTER_REQUIRED from gnu-user.h to make i386 GCC behave
the same as x86-64 GCC.  This fixes

FAIL: gcc.target/i386/pr93492-3.c scan-assembler \t.cfi_startproc\n\tendbr(32|64)\n.*.LPFE1:\n\tnop\n1:\tcall\t__fentry__\n\tret\n
FAIL: gcc.target/i386/pr93492-5.c scan-assembler \t.cfi_startproc\n.*.LPFE1:\n\tnop\n1:\tcall\t__fentry__\n\tret\n

on Linux/i386.

	PR target/95655
	* config/i386/gnu-user.h (SUBTARGET_FRAME_POINTER_REQUIRED):
	Removed.
	* config/i386/i386.c (ix86_frame_pointer_required): Update
	comments.
---
 gcc/config/i386/gnu-user.h | 6 --
 gcc/config/i386/i386.c | 2 ++
 2 files changed, 2 insertions(+), 6 deletions(-)

diff --git a/gcc/config/i386/gnu-user.h b/gcc/config/i386/gnu-user.h
index ae4aa844f02..6ec5a114270 100644
--- a/gcc/config/i386/gnu-user.h
+++ b/gcc/config/i386/gnu-user.h
@@ -39,12 +39,6 @@ along with GCC; see the file COPYING3.  If not see
 #undef MCOUNT_NAME
 #define MCOUNT_NAME "mcount"
 
-/* The GLIBC version of mcount for the x86 assumes that there is a
-   frame, so we 

Re: [PATCH] vectorizer: add _bb_vec_info::const_iterator

2020-06-12 Thread Martin Liška

On 6/12/20 1:43 PM, Richard Sandiford wrote:

Martin Liška  writes:

On 6/12/20 12:46 PM, Richard Sandiford wrote:

Martin Liška  writes:

Hello.

I'm working one extension of SLP which will allow to vectorize multiple
BBs. This is a first step where I abstract _bb_vec_info::region_begin and
_bb_vec_info::region end by providing an iterator.


Nice.


diff --git a/gcc/tree-vectorizer.h b/gcc/tree-vectorizer.h
index 6c830ad09f4..542d49402d2 100644
--- a/gcc/tree-vectorizer.h
+++ b/gcc/tree-vectorizer.h
@@ -787,12 +787,46 @@ loop_vec_info_for_loop (class loop *loop)
typedef class _bb_vec_info : public vec_info
{
public:
+  struct const_iterator
+  {
+const_iterator (gimple_stmt_iterator _gsi): gsi (_gsi)
+{
+}
+
+const_iterator &
+operator++ (int)
+{
+  gsi_next (); return *this;
+}


Isn't this really operator++()?


It is, but post-increment ++ operators have one integer argument (so that
one can distinguish them from pre-increment operators:
https://en.cppreference.com/w/cpp/language/operator_incdec)


Sure, but what I mean by:


I.e. it returns a reference to the
modified iterator instead of the value at the original iterator.


is that the above implements the semantics of a preincrement, not a
postincrement, so it should be operator++() rather than operator++(int).


Ah, ok, I've got it.



In other words, the function (rightly) implements “++it” rather than “it++”.

With that fixed, it seems like a range-based for loop should work.


Yes, it works. The syntax is really neat:

for (gimple *stmt: *bb_vinfo)

I've tested vect.exp and i386.exp. May I install the patch after proper testing?

Thanks,
Martin



Thanks,
Richard



>From 977c96f27cbb6e6423c2546837ab50371df5f9d9 Mon Sep 17 00:00:00 2001
From: Martin Liska 
Date: Thu, 11 Jun 2020 13:25:40 +0200
Subject: [PATCH] vectorizer: add _bb_vec_info::const_iterator

gcc/ChangeLog:

	* tree-vect-patterns.c (vect_determine_precisions): Use the
	iterator.
	(vect_pattern_recog): Likewise.
	* tree-vect-slp.c (_bb_vec_info::_bb_vec_info): Likewise.
	(_bb_vec_info::~_bb_vec_info): Likewise.
	(vect_slp_check_for_constructors): Likewise.
	* tree-vect-stmts.c (vect_init_vector_1): Likewise.
	* tree-vectorizer.h: Add the new iterator and all related functions.
---
 gcc/tree-vect-patterns.c | 14 ++
 gcc/tree-vect-slp.c  | 28 ++--
 gcc/tree-vect-stmts.c|  2 +-
 gcc/tree-vectorizer.h| 38 --
 4 files changed, 49 insertions(+), 33 deletions(-)

diff --git a/gcc/tree-vect-patterns.c b/gcc/tree-vect-patterns.c
index 636ad59c001..eac372e6abc 100644
--- a/gcc/tree-vect-patterns.c
+++ b/gcc/tree-vect-patterns.c
@@ -5120,20 +5120,12 @@ vect_determine_precisions (vec_info *vinfo)
   else
 {
   bb_vec_info bb_vinfo = as_a  (vinfo);
-  gimple_stmt_iterator si = bb_vinfo->region_end;
-  gimple *stmt;
-  do
+  for (gimple *stmt: *bb_vinfo)
 	{
-	  if (!gsi_stmt (si))
-	si = gsi_last_bb (bb_vinfo->bb);
-	  else
-	gsi_prev ();
-	  stmt = gsi_stmt (si);
 	  stmt_vec_info stmt_info = vinfo->lookup_stmt (stmt);
 	  if (stmt_info && STMT_VINFO_VECTORIZABLE (stmt_info))
 	vect_determine_stmt_precisions (vinfo, stmt_info);
 	}
-  while (stmt != gsi_stmt (bb_vinfo->region_begin));
 }
 }
 
@@ -5492,10 +5484,8 @@ vect_pattern_recog (vec_info *vinfo)
   else
 {
   bb_vec_info bb_vinfo = as_a  (vinfo);
-  for (si = bb_vinfo->region_begin;
-	   gsi_stmt (si) != gsi_stmt (bb_vinfo->region_end); gsi_next ())
+  for (gimple *stmt: *bb_vinfo)
 	{
-	  gimple *stmt = gsi_stmt (si);
 	  stmt_vec_info stmt_info = bb_vinfo->lookup_stmt (stmt);
 	  if (!stmt_info || !STMT_VINFO_VECTORIZABLE (stmt_info))
 	continue;
diff --git a/gcc/tree-vect-slp.c b/gcc/tree-vect-slp.c
index 303410c2fc4..8646d7f77ab 100644
--- a/gcc/tree-vect-slp.c
+++ b/gcc/tree-vect-slp.c
@@ -2551,15 +2551,11 @@ _bb_vec_info::_bb_vec_info (gimple_stmt_iterator region_begin_in,
 			vec_info_shared *shared)
   : vec_info (vec_info::bb, init_cost (NULL), shared),
 bb (gsi_bb (region_begin_in)),
-region_begin (region_begin_in),
-region_end (region_end_in)
+m_region_begin (region_begin_in),
+m_region_end (region_end_in)
 {
-  gimple_stmt_iterator gsi;
-
-  for (gsi = region_begin; gsi_stmt (gsi) != gsi_stmt (region_end);
-   gsi_next ())
+  for (gimple *stmt: *this)
 {
-  gimple *stmt = gsi_stmt (gsi);
   gimple_set_uid (stmt, 0);
   if (is_gimple_debug (stmt))
 	continue;
@@ -2575,10 +2571,9 @@ _bb_vec_info::_bb_vec_info (gimple_stmt_iterator region_begin_in,
 
 _bb_vec_info::~_bb_vec_info ()
 {
-  for (gimple_stmt_iterator si = region_begin;
-   gsi_stmt (si) != gsi_stmt (region_end); gsi_next ())
+  for (gimple *stmt: *this)
 /* Reset region marker.  */
-gimple_set_uid (gsi_stmt (si), -1);
+gimple_set_uid (stmt, -1);
 
   bb->aux = NULL;
 }
@@ -3012,16 +3007,13 @@ 

Re: [PATCH] tsan: Add param to disable func-entry-exit instrumentation

2020-06-12 Thread Marco Elver via Gcc-patches
On Fri, 12 Jun 2020 at 12:29, Jakub Jelinek  wrote:
>
> On Fri, Jun 12, 2020 at 09:21:59AM +0200, Marco Elver wrote:
> > Adds param tsan-instrument-func-entry-exit, which controls if
> > __tsan_func_{entry,exit} calls should be emitted or not. The default
> > behaviour is to emit the calls.
>
> If you want that, I wonder if the spots you've chosen are the best ones.
> E.g. shouldn't
>   if (sanitize_flags_p (SANITIZE_THREAD))
> {
>   gcall *call = gimple_build_call_internal (IFN_TSAN_FUNC_EXIT, 0);
> ...
> in gimplify.c have this && param_tsan_instrument_func_entry_exit, so that
> we don't waste a call or several in every function when we are going to dump
> them all?

Yes, makes sense. Thanks for pointing it out! Done in v2.

> And in tsan.c, perhaps instead of changing instrument_gimple twice change:
> fentry_exit_instrument |= instrument_gimple ();
> to:
> fentry_exit_instrument
>   |= (instrument_gimple ()
>   && param_tsan_instrument_func_entry_exit);
> ?

Yeah, I was wondering where the best place is. I chose
instrument_gimple() because it's the inner-most function controlling
if func-entry-exit instrumentation is emitted. But I suppose that
function won't be used elsewhere, so your suggestion is simpler. Done
in v2.

> > gcc/ChangeLog:
> >
> >   * params.opt: Add --param=tsan-instrument-func-entry-exit=.
> >   * tsan.c (instrument_gimple): Make return value if
> > func entry and exit  should be instrumented dependent on
> > param.
>
> No tab + 2 spaces please, the further lines should be just tab indented.
> And s/  / /.

Done for v2.

Thanks,
-- Marco


Re: [PATCH] vectorizer: add _bb_vec_info::const_iterator

2020-06-12 Thread Richard Sandiford
Martin Liška  writes:
> On 6/12/20 12:46 PM, Richard Sandiford wrote:
>> Martin Liška  writes:
>>> Hello.
>>>
>>> I'm working one extension of SLP which will allow to vectorize multiple
>>> BBs. This is a first step where I abstract _bb_vec_info::region_begin and
>>> _bb_vec_info::region end by providing an iterator.
>> 
>> Nice.
>> 
>>> diff --git a/gcc/tree-vectorizer.h b/gcc/tree-vectorizer.h
>>> index 6c830ad09f4..542d49402d2 100644
>>> --- a/gcc/tree-vectorizer.h
>>> +++ b/gcc/tree-vectorizer.h
>>> @@ -787,12 +787,46 @@ loop_vec_info_for_loop (class loop *loop)
>>>typedef class _bb_vec_info : public vec_info
>>>{
>>>public:
>>> +  struct const_iterator
>>> +  {
>>> +const_iterator (gimple_stmt_iterator _gsi): gsi (_gsi)
>>> +{
>>> +}
>>> +
>>> +const_iterator &
>>> +operator++ (int)
>>> +{
>>> +  gsi_next (); return *this;
>>> +}
>> 
>> Isn't this really operator++()?
>
> It is, but post-increment ++ operators have one integer argument (so that
> one can distinguish them from pre-increment operators:
> https://en.cppreference.com/w/cpp/language/operator_incdec)

Sure, but what I mean by:

>> I.e. it returns a reference to the
>> modified iterator instead of the value at the original iterator.

is that the above implements the semantics of a preincrement, not a
postincrement, so it should be operator++() rather than operator++(int).

In other words, the function (rightly) implements “++it” rather than “it++”.

With that fixed, it seems like a range-based for loop should work.

Thanks,
Richard


Re: [PATCH] vectorizer: add _bb_vec_info::const_iterator

2020-06-12 Thread Martin Liška

On 6/12/20 12:46 PM, Richard Sandiford wrote:

Martin Liška  writes:

Hello.

I'm working one extension of SLP which will allow to vectorize multiple
BBs. This is a first step where I abstract _bb_vec_info::region_begin and
_bb_vec_info::region end by providing an iterator.


Nice.


diff --git a/gcc/tree-vectorizer.h b/gcc/tree-vectorizer.h
index 6c830ad09f4..542d49402d2 100644
--- a/gcc/tree-vectorizer.h
+++ b/gcc/tree-vectorizer.h
@@ -787,12 +787,46 @@ loop_vec_info_for_loop (class loop *loop)
   typedef class _bb_vec_info : public vec_info
   {
   public:
+  struct const_iterator
+  {
+const_iterator (gimple_stmt_iterator _gsi): gsi (_gsi)
+{
+}
+
+const_iterator &
+operator++ (int)
+{
+  gsi_next (); return *this;
+}


Isn't this really operator++()?


It is, but post-increment ++ operators have one integer argument (so that
one can distinguish them from pre-increment operators:
https://en.cppreference.com/w/cpp/language/operator_incdec)

I was also quite surprised about that.


 I.e. it returns a reference to the
modified iterator instead of the value at the original iterator.

With that change, is there any reason we can't use a range-based for
loop instead of:

   for (_bb_vec_info::const_iterator it = begin (); it != end (); it++)


/home/marxin/Programming/gcc/gcc/tree-vect-patterns.c: In function ‘void 
vect_determine_precisions(vec_info*)’:
/home/marxin/Programming/gcc/gcc/tree-vect-patterns.c:5124:31: error: no 
‘operator++(int)’ declared for postfix ‘++’ [-fpermissive]
 5124 | it != bb_vinfo->end (); it++)
  | ~~^~

There's slightly modified patch (one places is rewritten to classical iterator 
loop).

Martin

Martin



etc.?

Thanks,
Richard



>From 9e1a01e2e3a2075cf5ac2b2edb3fa969b198d342 Mon Sep 17 00:00:00 2001
From: Martin Liska 
Date: Thu, 11 Jun 2020 13:25:40 +0200
Subject: [PATCH] vectorizer: add _bb_vec_info::const_iterator

gcc/ChangeLog:

	* tree-vect-patterns.c (vect_determine_precisions): Use the
	iterator.
	(vect_pattern_recog): Likewise.
	* tree-vect-slp.c (_bb_vec_info::_bb_vec_info): Likewise.
	(_bb_vec_info::~_bb_vec_info): Likewise.
	(vect_slp_check_for_constructors): Likewise.
	* tree-vect-stmts.c (vect_init_vector_1): Likewise.
	* tree-vectorizer.h: Add the new iterator and all related functions.
---
 gcc/tree-vect-patterns.c | 18 ++
 gcc/tree-vect-slp.c  | 24 +---
 gcc/tree-vect-stmts.c|  2 +-
 gcc/tree-vectorizer.h| 38 --
 4 files changed, 52 insertions(+), 30 deletions(-)

diff --git a/gcc/tree-vect-patterns.c b/gcc/tree-vect-patterns.c
index 636ad59c001..d194826f132 100644
--- a/gcc/tree-vect-patterns.c
+++ b/gcc/tree-vect-patterns.c
@@ -5120,20 +5120,14 @@ vect_determine_precisions (vec_info *vinfo)
   else
 {
   bb_vec_info bb_vinfo = as_a  (vinfo);
-  gimple_stmt_iterator si = bb_vinfo->region_end;
-  gimple *stmt;
-  do
+  for (_bb_vec_info::const_iterator it = bb_vinfo->begin ();
+	   it != bb_vinfo->end (); it++)
 	{
-	  if (!gsi_stmt (si))
-	si = gsi_last_bb (bb_vinfo->bb);
-	  else
-	gsi_prev ();
-	  stmt = gsi_stmt (si);
+	  gimple *stmt = *it;
 	  stmt_vec_info stmt_info = vinfo->lookup_stmt (stmt);
 	  if (stmt_info && STMT_VINFO_VECTORIZABLE (stmt_info))
 	vect_determine_stmt_precisions (vinfo, stmt_info);
 	}
-  while (stmt != gsi_stmt (bb_vinfo->region_begin));
 }
 }
 
@@ -5492,10 +5486,10 @@ vect_pattern_recog (vec_info *vinfo)
   else
 {
   bb_vec_info bb_vinfo = as_a  (vinfo);
-  for (si = bb_vinfo->region_begin;
-	   gsi_stmt (si) != gsi_stmt (bb_vinfo->region_end); gsi_next ())
+  for (_bb_vec_info::const_iterator it = bb_vinfo->begin ();
+	   it != bb_vinfo->end (); it++)
 	{
-	  gimple *stmt = gsi_stmt (si);
+	  gimple *stmt = *it;
 	  stmt_vec_info stmt_info = bb_vinfo->lookup_stmt (stmt);
 	  if (!stmt_info || !STMT_VINFO_VECTORIZABLE (stmt_info))
 	continue;
diff --git a/gcc/tree-vect-slp.c b/gcc/tree-vect-slp.c
index 303410c2fc4..5a2dc71f0cd 100644
--- a/gcc/tree-vect-slp.c
+++ b/gcc/tree-vect-slp.c
@@ -2551,15 +2551,12 @@ _bb_vec_info::_bb_vec_info (gimple_stmt_iterator region_begin_in,
 			vec_info_shared *shared)
   : vec_info (vec_info::bb, init_cost (NULL), shared),
 bb (gsi_bb (region_begin_in)),
-region_begin (region_begin_in),
-region_end (region_end_in)
+m_region_begin (region_begin_in),
+m_region_end (region_end_in)
 {
-  gimple_stmt_iterator gsi;
-
-  for (gsi = region_begin; gsi_stmt (gsi) != gsi_stmt (region_end);
-   gsi_next ())
+  for (_bb_vec_info::const_iterator it = begin (); it != end (); it++)
 {
-  gimple *stmt = gsi_stmt (gsi);
+  gimple *stmt = *it;
   gimple_set_uid (stmt, 0);
   if (is_gimple_debug (stmt))
 	continue;
@@ -2575,10 +2572,9 @@ _bb_vec_info::_bb_vec_info (gimple_stmt_iterator region_begin_in,
 
 _bb_vec_info::~_bb_vec_info ()
 {
-  for 

[PATCH] testcase for shared DR alignment

2020-06-12 Thread Richard Biener
This adds a reduced C testcase from libgomp.fortran/examples-4/target-1.f90
and libgomp.fortran/examples-4/target_data-1.f90 FAILs, showing a case
of SLP instance stmt sharing that affects the shared dataref alignment
info.

2020-06-12  Richard Biener  

* gcc.dg/vect/bb-slp-44.c: New testcase.
---
 gcc/testsuite/gcc.dg/vect/bb-slp-44.c | 41 +++
 1 file changed, 41 insertions(+)
 create mode 100644 gcc/testsuite/gcc.dg/vect/bb-slp-44.c

diff --git a/gcc/testsuite/gcc.dg/vect/bb-slp-44.c 
b/gcc/testsuite/gcc.dg/vect/bb-slp-44.c
new file mode 100644
index 000..dfa0a5eaaab
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/vect/bb-slp-44.c
@@ -0,0 +1,41 @@
+/* { dg-do run } */
+
+typedef struct {
+unsigned long a;
+unsigned long b;
+unsigned long c;
+} data_o;
+typedef struct {
+unsigned long c;
+unsigned long gap1;
+unsigned long b;
+unsigned long gap2;
+unsigned long a;
+unsigned long x;
+} data_i;
+
+volatile unsigned long gx;
+void __attribute__((noipa))
+bar(unsigned long x)
+{
+  gx = x;
+}
+
+void __attribute__((noipa))
+foo(data_o *o, data_i *i)
+{
+  o->a = i->a;
+  o->b = i->b;
+  o->c = i->c;
+  bar (i->x);
+}
+
+int main()
+{
+  unsigned long data[9];
+  if ((__UINTPTR_TYPE__)data & 15 != 0)
+foo ((data_o *)[6], (data_i *)data);
+  else
+foo ((data_o *)data, (data_i *)[3]);
+  return 0;
+}
-- 
2.26.2


Re: [PATCH] vectorizer: add _bb_vec_info::const_iterator

2020-06-12 Thread Richard Sandiford
Martin Liška  writes:
> Hello.
>
> I'm working one extension of SLP which will allow to vectorize multiple
> BBs. This is a first step where I abstract _bb_vec_info::region_begin and
> _bb_vec_info::region end by providing an iterator.

Nice.

> diff --git a/gcc/tree-vectorizer.h b/gcc/tree-vectorizer.h
> index 6c830ad09f4..542d49402d2 100644
> --- a/gcc/tree-vectorizer.h
> +++ b/gcc/tree-vectorizer.h
> @@ -787,12 +787,46 @@ loop_vec_info_for_loop (class loop *loop)
>   typedef class _bb_vec_info : public vec_info
>   {
>   public:
> +  struct const_iterator
> +  {
> +const_iterator (gimple_stmt_iterator _gsi): gsi (_gsi)
> +{
> +}
> +
> +const_iterator &
> +operator++ (int)
> +{
> +  gsi_next (); return *this;
> +}

Isn't this really operator++()?  I.e. it returns a reference to the
modified iterator instead of the value at the original iterator.

With that change, is there any reason we can't use a range-based for
loop instead of:

  for (_bb_vec_info::const_iterator it = begin (); it != end (); it++)

etc.?

Thanks,
Richard


Re: [PATCH PR95570] vect: ICE: Segmentation fault in vect_loop_versioning

2020-06-12 Thread Richard Sandiford
"Yangfei (Felix)"  writes:
> +2020-06-12  Felix Yang  
> +
> +   PR tree-optimization/95570
> +   * tree-vect-data-refs.c (vect_relevant_for_alignment_p): New function.
> +   (vect_verify_datarefs_alignment): Call it to filter out data 
> references
> +   in the loop whose alignment is irrelevant.
> +   (vect_get_peeling_costs_all_drs): Likewise.
> +   (vect_peeling_supportable): Likewise.
> +   (vect_enhance_data_refs_alignment): Likewise.
>
> gcc/testsuite/
>
> +2020-06-12  Felix Yang  
> +
> +   PR tree-optimization/95570
> +   * gcc.dg/vect/pr95570.c: New test.

Pushed to master, thanks.

Richard


Re: [PATCH] tsan: Add param to disable func-entry-exit instrumentation

2020-06-12 Thread Jakub Jelinek via Gcc-patches
On Fri, Jun 12, 2020 at 09:21:59AM +0200, Marco Elver wrote:
> Adds param tsan-instrument-func-entry-exit, which controls if
> __tsan_func_{entry,exit} calls should be emitted or not. The default
> behaviour is to emit the calls.

If you want that, I wonder if the spots you've chosen are the best ones.
E.g. shouldn't
  if (sanitize_flags_p (SANITIZE_THREAD))
{
  gcall *call = gimple_build_call_internal (IFN_TSAN_FUNC_EXIT, 0);
...
in gimplify.c have this && param_tsan_instrument_func_entry_exit, so that
we don't waste a call or several in every function when we are going to dump
them all?
And in tsan.c, perhaps instead of changing instrument_gimple twice change:
fentry_exit_instrument |= instrument_gimple ();
to:
fentry_exit_instrument
  |= (instrument_gimple ()
  && param_tsan_instrument_func_entry_exit);
?

> gcc/ChangeLog:
> 
>   * params.opt: Add --param=tsan-instrument-func-entry-exit=.
>   * tsan.c (instrument_gimple): Make return value if
> func entry and exit  should be instrumented dependent on
> param.

No tab + 2 spaces please, the further lines should be just tab indented.
And s/  / /.

Jakub



Re: [PATCH] tsan: Add param to disable func-entry-exit instrumentation

2020-06-12 Thread Martin Liška

On 6/12/20 9:21 AM, Marco Elver wrote:

Adds param tsan-instrument-func-entry-exit, which controls if
__tsan_func_{entry,exit} calls should be emitted or not. The default
behaviour is to emit the calls.


I support the patch.
What about Jakub?

Martin


Re: [Patch][RFC] openmp: ensure variables in offload table are streamed out (PRs 94848 + 95551)

2020-06-12 Thread Thomas Schwinge
Hi!

On 2020-06-09T16:11:03+0200, Jakub Jelinek via Gcc-patches 
 wrote:
> On Tue, Jun 09, 2020 at 04:02:19PM +0200, Tobias Burnus wrote:
>> It turned out that this patch fails with LTO and partitions,
>> causing fails at runtime such as
>>   libgomp: Duplicate node
>> via libgomp/splay-tree.c's splay_tree_insert.
>>
>> In the test case, the problem occurred for functions - namely
>> main._omp_fn.* on the host.
>> If the code is run in LTO context, the filtering-out should
>> have already happen via the stream-out/stream-in and hence no
>> additional check is needed for omp_finish_file.
>
> Was this caught in the testsuite

I saw it show up as:

PASS: 
libgomp.oacc-c/../libgomp.oacc-c-c++-common/data-clauses-kernels-ipa-pta.c 
-DACC_DEVICE_TYPE_nvidia=1 -DACC_MEM_SHARED=0 -foffload=nvptx-none  -O0  (test 
for excess errors)
[-PASS:-]{+WARNING: program timed out.+}
{+FAIL:+} 
libgomp.oacc-c/../libgomp.oacc-c-c++-common/data-clauses-kernels-ipa-pta.c 
-DACC_DEVICE_TYPE_nvidia=1 -DACC_MEM_SHARED=0 -foffload=nvptx-none  -O0  
execution test
PASS: 
libgomp.oacc-c/../libgomp.oacc-c-c++-common/data-clauses-kernels-ipa-pta.c 
-DACC_DEVICE_TYPE_nvidia=1 -DACC_MEM_SHARED=0 -foffload=nvptx-none  -O2  (test 
for excess errors)
[-PASS:-]{+WARNING: program timed out.+}
{+FAIL:+} 
libgomp.oacc-c/../libgomp.oacc-c-c++-common/data-clauses-kernels-ipa-pta.c 
-DACC_DEVICE_TYPE_nvidia=1 -DACC_MEM_SHARED=0 -foffload=nvptx-none  -O2  
execution test

PASS: 
libgomp.oacc-c/../libgomp.oacc-c-c++-common/data-clauses-parallel-ipa-pta.c 
-DACC_DEVICE_TYPE_nvidia=1 -DACC_MEM_SHARED=0 -foffload=nvptx-none  -O0  (test 
for excess errors)
[-PASS:-]{+WARNING: program timed out.+}
{+FAIL:+} 
libgomp.oacc-c/../libgomp.oacc-c-c++-common/data-clauses-parallel-ipa-pta.c 
-DACC_DEVICE_TYPE_nvidia=1 -DACC_MEM_SHARED=0 -foffload=nvptx-none  -O0  
execution test
PASS: 
libgomp.oacc-c/../libgomp.oacc-c-c++-common/data-clauses-parallel-ipa-pta.c 
-DACC_DEVICE_TYPE_nvidia=1 -DACC_MEM_SHARED=0 -foffload=nvptx-none  -O2  (test 
for excess errors)
[-PASS:-]{+WARNING: program timed out.+}
{+FAIL:+} 
libgomp.oacc-c/../libgomp.oacc-c-c++-common/data-clauses-parallel-ipa-pta.c 
-DACC_DEVICE_TYPE_nvidia=1 -DACC_MEM_SHARED=0 -foffload=nvptx-none  -O2  
execution test

Same for C++.

Not sure if that constitutes sufficient testsuite coverage.

> do you have some short testcase
> that could be used in the testsuite?

Can we do some LTO-compile-time tree scanning?


Grüße
 Thomas
-
Mentor Graphics (Deutschland) GmbH, Arnulfstraße 201, 80634 München / Germany
Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Alexander 
Walter


[PATCH] Use SLP_TREE_VECTYPE consistently, get rid of STMT_VINFO_NUM_SLP_USES

2020-06-12 Thread Richard Biener
The following gets rid of the restriction in BB vectorization
where we needed to ensure underlying stmts vector types agree
for all uses in all SLP instances.  That's done by recording
the vector type for SLP nodes in all cases and using that
when analyzing/code-generating by means of adjusting STMT_VINFO_VECTYPE
for participating stmts around analysis/transform calls.

As this gets rid of the last user of STMT_VINFO_NUM_SLP_USES the
patch removes that as well.

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

Richard.

2020-06-12  Richard Biener  

* tree-vectorizer.h (_stmt_vec_info::num_slp_uses): Remove.
(STMT_VINFO_NUM_SLP_USES): Likewise.
(vect_free_slp_instance): Adjust.
(vect_slp_push_vectype): New.
(vect_slp_pop_vectype): Likewise.
* tree-vect-data-refs.c
(vect_slp_analyze_and_verify_instance_alignment): Push/pop
vectype around analysis.
* tree-vect-loop.c (vect_transform_loop): Adjust.
* tree-vect-slp.c (vect_free_slp_tree): Remove STMT_VINFO_NUM_SLP_USES
updating.
(vect_create_new_slp_node): Likewise.
(vect_free_slp_instance): Adjust.
(vect_update_shared_vectype): Remove.
(vect_build_slp_tree_1): Do not set STMT_VINFO_VECTYPE but
the passed in *vectype parameter.
(vect_build_slp_tree_2): Set SLP_TREE_VECTYPE from what
vect_build_slp_tree_1 computed.
(slp_copy_subtree): Do not update STMT_VINFO_NUM_SLP_USES.
(vect_attempt_slp_rearrange_stmts): Adjust.
(vect_analyze_slp_instance): Likewise.
(vect_analyze_slp): Likewise.
(vect_slp_push_vectype): New.
(vect_slp_pop_vectype): Likewise.
(vect_slp_analyze_node_operations_1): Push/pop vectype
around analysis.
(vect_schedule_slp_instance): Likewise.
(vect_slp_analyze_operations): Adjust.
(vect_slp_analyze_bb_1): Likewise.
* tree-vect-stmts.c (vect_is_simple_use): Take the vector type
from SLP_TREE_VECTYPE.
* tree-vectorizer.c (vec_info::~vec_info): Adjust.
---
 gcc/tree-vect-data-refs.c |  22 +++--
 gcc/tree-vect-loop.c  |   4 +-
 gcc/tree-vect-slp.c   | 176 --
 gcc/tree-vect-stmts.c |  12 +--
 gcc/tree-vectorizer.c |   2 +-
 gcc/tree-vectorizer.h |   8 +-
 6 files changed, 104 insertions(+), 120 deletions(-)

diff --git a/gcc/tree-vect-data-refs.c b/gcc/tree-vect-data-refs.c
index 39d5a1b554c..17da2da10a1 100644
--- a/gcc/tree-vect-data-refs.c
+++ b/gcc/tree-vect-data-refs.c
@@ -2466,15 +2466,25 @@ vect_slp_analyze_and_verify_instance_alignment 
(vec_info *vinfo,
 
   slp_tree node;
   unsigned i;
+  auto_vec saved_vectypes;
   FOR_EACH_VEC_ELT (SLP_INSTANCE_LOADS (instance), i, node)
-if (! vect_slp_analyze_and_verify_node_alignment (vinfo, node))
-  return false;
+{
+  vect_slp_push_vectype (node, _vectypes);
+  bool res = vect_slp_analyze_and_verify_node_alignment (vinfo, node);
+  vect_slp_pop_vectype (node, _vectypes);
+  if (! res)
+   return false;
+}
 
   node = SLP_INSTANCE_TREE (instance);
-  if (STMT_VINFO_DATA_REF (SLP_TREE_REPRESENTATIVE (node))
-  && ! vect_slp_analyze_and_verify_node_alignment
-(vinfo, SLP_INSTANCE_TREE (instance)))
-return false;
+  if (STMT_VINFO_DATA_REF (SLP_TREE_REPRESENTATIVE (node)))
+{
+  vect_slp_push_vectype (node, _vectypes);
+  bool res = vect_slp_analyze_and_verify_node_alignment (vinfo, node);
+  vect_slp_pop_vectype (node, _vectypes);
+  if (! res)
+   return false;
+}
 
   return true;
 }
diff --git a/gcc/tree-vect-loop.c b/gcc/tree-vect-loop.c
index f4d47e05bd4..e03bc9c8928 100644
--- a/gcc/tree-vect-loop.c
+++ b/gcc/tree-vect-loop.c
@@ -2328,7 +2328,7 @@ again:
   LOOP_VINFO_VECT_FACTOR (loop_vinfo) = saved_vectorization_factor;
   /* Free the SLP instances.  */
   FOR_EACH_VEC_ELT (LOOP_VINFO_SLP_INSTANCES (loop_vinfo), j, instance)
-vect_free_slp_instance (instance, false);
+vect_free_slp_instance (instance);
   LOOP_VINFO_SLP_INSTANCES (loop_vinfo).release ();
   /* Reset SLP type to loop_vect on all stmts.  */
   for (i = 0; i < LOOP_VINFO_LOOP (loop_vinfo)->num_nodes; ++i)
@@ -8827,7 +8827,7 @@ vect_transform_loop (loop_vec_info loop_vinfo, gimple 
*loop_vectorized_call)
  won't work.  */
   slp_instance instance;
   FOR_EACH_VEC_ELT (LOOP_VINFO_SLP_INSTANCES (loop_vinfo), i, instance)
-vect_free_slp_instance (instance, true);
+vect_free_slp_instance (instance);
   LOOP_VINFO_SLP_INSTANCES (loop_vinfo).release ();
   /* Clear-up safelen field since its value is invalid after vectorization
  since vectorized loop can have loop-carried dependencies.  */
diff --git a/gcc/tree-vect-slp.c b/gcc/tree-vect-slp.c
index 303410c2fc4..986c2cc37ac 100644
--- a/gcc/tree-vect-slp.c
+++ b/gcc/tree-vect-slp.c
@@ -84,7 +84,7 @@ _slp_tree::~_slp_tree ()
made a final decision not to 

[PATCH] fix vectorizable_condition ICE with EXTRACT_LAST_REDUCTION

2020-06-12 Thread Richard Biener
The previous reorg missed a guard around the else clause access.

Committed as obvious.

2020-06-12  Richard Biener  

PR tree-optimization/95633
* tree-vect-stmts.c (vectorizable_condition): Properly
guard the vec_else_clause access with EXTRACT_LAST_REDUCTION.
---
 gcc/tree-vect-stmts.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/gcc/tree-vect-stmts.c b/gcc/tree-vect-stmts.c
index cdd6f6c5e5d..cf2d979fea1 100644
--- a/gcc/tree-vect-stmts.c
+++ b/gcc/tree-vect-stmts.c
@@ -9925,7 +9925,8 @@ vectorizable_condition (vec_info *vinfo,
   FOR_EACH_VEC_ELT (vec_oprnds0, i, vec_cond_lhs)
 {
   vec_then_clause = vec_oprnds2[i];
-  vec_else_clause = vec_oprnds3[i];
+  if (reduction_type != EXTRACT_LAST_REDUCTION)
+   vec_else_clause = vec_oprnds3[i];
 
   if (swap_cond_operands)
std::swap (vec_then_clause, vec_else_clause);
-- 
2.16.4


[PATCH] tsan: Add param to disable func-entry-exit instrumentation

2020-06-12 Thread Marco Elver via Gcc-patches
Adds param tsan-instrument-func-entry-exit, which controls if
__tsan_func_{entry,exit} calls should be emitted or not. The default
behaviour is to emit the calls.

This may be required by alternative race detection runtimes. One such
runtime is the Kernel Concurrency Sanitizer (KCSAN):

https://github.com/google/ktsan/wiki/KCSAN

After this change, GCC should satisfy all requirements for KCSAN:

https://lore.kernel.org/lkml/20200515150338.190344-7-el...@google.com/

gcc/ChangeLog:

* params.opt: Add --param=tsan-instrument-func-entry-exit=.
* tsan.c (instrument_gimple): Make return value if
  func entry and exit  should be instrumented dependent on
  param.

gcc/testsuite/ChangeLog:

* c-c++-common/tsan/func_entry_exit.c: New test.
* c-c++-common/tsan/func_entry_exit_disabled.c: New test.
---
 gcc/params.opt|  4 +++
 .../c-c++-common/tsan/func_entry_exit.c   | 28 +++
 .../tsan/func_entry_exit_disabled.c   | 28 +++
 gcc/tsan.c|  4 +--
 4 files changed, 62 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/c-c++-common/tsan/func_entry_exit.c
 create mode 100644 gcc/testsuite/c-c++-common/tsan/func_entry_exit_disabled.c

diff --git a/gcc/params.opt b/gcc/params.opt
index 9b564bb046c..e29a44e7712 100644
--- a/gcc/params.opt
+++ b/gcc/params.opt
@@ -912,6 +912,10 @@ Set the maximum number of instructions executed in 
parallel in reassociated tree
 Common Joined UInteger Var(param_tsan_distinguish_volatile) IntegerRange(0, 1) 
Param
 Emit special instrumentation for accesses to volatiles.
 
+-param=tsan-instrument-func-entry-exit=
+Common Joined UInteger Var(param_tsan_instrument_func_entry_exit) Init(1) 
IntegerRange(0, 1) Param
+Emit instrumentation calls to __tsan_func_entry() and __tsan_func_exit().
+
 -param=uninit-control-dep-attempts=
 Common Joined UInteger Var(param_uninit_control_dep_attempts) Init(1000) 
IntegerRange(1, 65536) Param Optimization
 Maximum number of nested calls to search for control dependencies during 
uninitialized variable analysis.
diff --git a/gcc/testsuite/c-c++-common/tsan/func_entry_exit.c 
b/gcc/testsuite/c-c++-common/tsan/func_entry_exit.c
new file mode 100644
index 000..5bb524c73ae
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/tsan/func_entry_exit.c
@@ -0,0 +1,28 @@
+/* { dg-do compile } */
+/* { dg-options "-fdump-tree-optimized" } */
+
+int x;
+
+__attribute__((noinline))
+void fn1(void)
+{
+  x++;
+}
+
+__attribute__((noinline))
+void fn2(void)
+{
+  fn1();
+}
+
+__attribute__((noinline))
+int main(int argc, char *argv[])
+{
+  fn1();
+  fn2();
+  return 0;
+}
+
+// { dg-final { scan-tree-dump-times "__tsan_func_entry" 3 "optimized" } }
+// { dg-final { scan-tree-dump-times "__tsan_func_exit" 3 "optimized" } }
+// { dg-final { scan-tree-dump "__tsan_write" "optimized" } }
diff --git a/gcc/testsuite/c-c++-common/tsan/func_entry_exit_disabled.c 
b/gcc/testsuite/c-c++-common/tsan/func_entry_exit_disabled.c
new file mode 100644
index 000..b7e0d9d1019
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/tsan/func_entry_exit_disabled.c
@@ -0,0 +1,28 @@
+/* { dg-do compile } */
+/* { dg-options "--param=tsan-instrument-func-entry-exit=0 
-fdump-tree-optimized" } */
+
+int x;
+
+__attribute__((noinline))
+void fn1(void)
+{
+  x++;
+}
+
+__attribute__((noinline))
+void fn2(void)
+{
+  fn1();
+}
+
+__attribute__((noinline))
+int main(int argc, char *argv[])
+{
+  fn1();
+  fn2();
+  return 0;
+}
+
+// { dg-final { scan-tree-dump-not "__tsan_func_entry" "optimized" } }
+// { dg-final { scan-tree-dump-not "__tsan_func_exit" "optimized" } }
+// { dg-final { scan-tree-dump "__tsan_write" "optimized" } }
diff --git a/gcc/tsan.c b/gcc/tsan.c
index 447acccfafd..02625a952c3 100644
--- a/gcc/tsan.c
+++ b/gcc/tsan.c
@@ -718,7 +718,7 @@ instrument_gimple (gimple_stmt_iterator *gsi)
   gimple_call_set_tail (as_a  (stmt), false);
   if (gimple_call_builtin_p (stmt, BUILT_IN_NORMAL))
instrument_builtin_call (gsi);
-  return true;
+  return param_tsan_instrument_func_entry_exit;
 }
   else if (is_gimple_assign (stmt)
   && !gimple_clobber_p (stmt))
@@ -734,7 +734,7 @@ instrument_gimple (gimple_stmt_iterator *gsi)
  instrumented = instrument_expr (*gsi, rhs, false);
}
 }
-  return instrumented;
+  return param_tsan_instrument_func_entry_exit && instrumented;
 }
 
 /* Replace TSAN_FUNC_EXIT internal call with function exit tsan builtin.  */
-- 
2.27.0.290.gba653c62da-goog



[committed] libstdc++: Improve tests for std::atomic_flag

2020-06-12 Thread Jonathan Wakely via Gcc-patches
The tests for clear() and test_and_set() didn't cover all cases.

* testsuite/29_atomics/atomic_flag/clear/1.cc: Also test clear()
when the value is currently set.
* testsuite/29_atomics/atomic_flag/test_and_set/explicit.cc:
Actually check the return value.
* testsuite/29_atomics/atomic_flag/test_and_set/implicit.cc:
Likewise.

Tested powerpc64le-linux and x86_64-linux, committed to master.

commit e784f98027dbd5cdc46712751dcfba8278eb7fa9
Author: Jonathan Wakely 
Date:   Fri Jun 12 10:33:37 2020 +0100

libstdc++: Improve tests for std::atomic_flag

The tests for clear() and test_and_set() didn't cover all cases.

* testsuite/29_atomics/atomic_flag/clear/1.cc: Also test clear()
when the value is currently set.
* testsuite/29_atomics/atomic_flag/test_and_set/explicit.cc:
Actually check the return value.
* testsuite/29_atomics/atomic_flag/test_and_set/implicit.cc:
Likewise.

diff --git a/libstdc++-v3/testsuite/29_atomics/atomic_flag/clear/1.cc 
b/libstdc++-v3/testsuite/29_atomics/atomic_flag/clear/1.cc
index 30d9075e372..ed5d11a5292 100644
--- a/libstdc++-v3/testsuite/29_atomics/atomic_flag/clear/1.cc
+++ b/libstdc++-v3/testsuite/29_atomics/atomic_flag/clear/1.cc
@@ -25,9 +25,9 @@ int main()
 {
   std::atomic_flag f = ATOMIC_FLAG_INIT;
 
-  f.clear(); // set to false
+  f.clear();   // set to false
+  VERIFY( false == f.test_and_set() ); // return true
+  VERIFY( true == f.test_and_set() );  // return true
+  f.clear();   // set to false
   VERIFY( false == f.test_and_set() ); // return previous false, set to true
-  VERIFY( true == f.test_and_set() ); // return true
-
-  return 0;
 }
diff --git 
a/libstdc++-v3/testsuite/29_atomics/atomic_flag/test_and_set/explicit.cc 
b/libstdc++-v3/testsuite/29_atomics/atomic_flag/test_and_set/explicit.cc
index 5d6dbcc98a2..1934854d7f7 100644
--- a/libstdc++-v3/testsuite/29_atomics/atomic_flag/test_and_set/explicit.cc
+++ b/libstdc++-v3/testsuite/29_atomics/atomic_flag/test_and_set/explicit.cc
@@ -19,14 +19,13 @@
 // .
 
 #include 
+#include 
 
 int main()
 {
   using namespace std;
   atomic_flag af = ATOMIC_FLAG_INIT;
 
-  if (!af.test_and_set(memory_order_acquire))
-af.clear(memory_order_release);
-
-  return 0;
+  VERIFY( ! af.test_and_set(memory_order_acquire) );
+  VERIFY( af.test_and_set(memory_order_acquire) );
 }
diff --git 
a/libstdc++-v3/testsuite/29_atomics/atomic_flag/test_and_set/implicit.cc 
b/libstdc++-v3/testsuite/29_atomics/atomic_flag/test_and_set/implicit.cc
index 8e1284cd299..1934854d7f7 100644
--- a/libstdc++-v3/testsuite/29_atomics/atomic_flag/test_and_set/implicit.cc
+++ b/libstdc++-v3/testsuite/29_atomics/atomic_flag/test_and_set/implicit.cc
@@ -19,14 +19,13 @@
 // .
 
 #include 
+#include 
 
 int main()
 {
   using namespace std;
   atomic_flag af = ATOMIC_FLAG_INIT;
 
-  if (!af.test_and_set())
-af.clear();
-
-  return 0;
+  VERIFY( ! af.test_and_set(memory_order_acquire) );
+  VERIFY( af.test_and_set(memory_order_acquire) );
 }


Re: std::atomic_flag::test

2020-06-12 Thread Jonathan Wakely via Gcc-patches

On 11/05/20 09:11 +0100, Jonathan Wakely wrote:

On 08/05/20 17:05 +0200, Ulrich Drepper via Libstdc++ wrote:

This is not yet implemented.  Here is a patch.

2020-05-08  Ulrich Drepper  

  * include/bits/atomic_base.h (atomic_flag): Implement test
memeber function.
  * include/std/version: Define __cpp_lib_atomic_flag_test.
  * testsuite/29_atomics/atomic_flag/test/explicit.cc: New file.
  * testsuite/29_atomics/atomic_flag/test/implicit.cc: New file.



libatomic does not have a function 'test' so I implemented it with
__atomic_load (which takes care of memory ordering) and then compare
with the set-value.

The code generated at least for x86-64 looks good, it's a
straight-forward load, nothing else.


Thanks, looks good for master.


The tests weren't running by default, and the new members weren't const.

Fixed like so, tested powerpc64le-linux, committed to master.


commit 17412a74c531a21595311df5428f26552e82dfa8
Author: Jonathan Wakely 
Date:   Fri Jun 12 10:22:05 2020 +0100

libstdc++: Make std::atomic_flag::test members const

Also fix the tests so they run without an explicit -std=gnu++2a in the
RUNTESTFLAGS, and test the new function on const-qualified objects.

* include/bits/atomic_base.h (atomic_flag::test): Add missing
const qualifiers.
* testsuite/29_atomics/atomic_flag/test/explicit.cc: Add
dg-options and verify results of test function.
* testsuite/29_atomics/atomic_flag/test/implicit.cc: Likewise.

diff --git a/libstdc++-v3/include/bits/atomic_base.h b/libstdc++-v3/include/bits/atomic_base.h
index 01f77a0f372..ebcfeb4d51a 100644
--- a/libstdc++-v3/include/bits/atomic_base.h
+++ b/libstdc++-v3/include/bits/atomic_base.h
@@ -212,7 +212,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 #define __cpp_lib_atomic_flag_test 201907L
 
 _GLIBCXX_ALWAYS_INLINE bool
-test(memory_order __m = memory_order_seq_cst) noexcept
+test(memory_order __m = memory_order_seq_cst) const noexcept
 {
   __atomic_flag_data_type __v;
   __atomic_load(&_M_i, &__v, int(__m));
@@ -220,7 +220,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 }
 
 _GLIBCXX_ALWAYS_INLINE bool
-test(memory_order __m = memory_order_seq_cst) volatile noexcept
+test(memory_order __m = memory_order_seq_cst) const volatile noexcept
 {
   __atomic_flag_data_type __v;
   __atomic_load(&_M_i, &__v, int(__m));
diff --git a/libstdc++-v3/testsuite/29_atomics/atomic_flag/test/explicit.cc b/libstdc++-v3/testsuite/29_atomics/atomic_flag/test/explicit.cc
index 539656ba583..4f2a10d6d40 100644
--- a/libstdc++-v3/testsuite/29_atomics/atomic_flag/test/explicit.cc
+++ b/libstdc++-v3/testsuite/29_atomics/atomic_flag/test/explicit.cc
@@ -1,3 +1,4 @@
+// { dg-options "-std=gnu++2a" }
 // { dg-do run { target c++2a } }
 // { dg-require-thread-fence "" }
 
@@ -19,14 +20,21 @@
 // .
 
 #include 
+#include 
 
 int main()
 {
   using namespace std;
-  atomic_flag af = ATOMIC_FLAG_INIT;
 
-  if (af.test(memory_order_acquire))
-af.clear(memory_order_release);
+  atomic_flag af0 = ATOMIC_FLAG_INIT;
+  VERIFY( ! af0.test(memory_order_acquire) );
 
-  return 0;
+  atomic_flag af{true};
+  const atomic_flag& caf = af;
+
+  VERIFY( af.test(memory_order_acquire) );
+  VERIFY( caf.test(memory_order_acquire) );
+  af.clear(memory_order_release);
+  VERIFY( ! af.test(memory_order_acquire) );
+  VERIFY( ! caf.test(memory_order_acquire) );
 }
diff --git a/libstdc++-v3/testsuite/29_atomics/atomic_flag/test/implicit.cc b/libstdc++-v3/testsuite/29_atomics/atomic_flag/test/implicit.cc
index 11d29ac0b9e..3889f32b98a 100644
--- a/libstdc++-v3/testsuite/29_atomics/atomic_flag/test/implicit.cc
+++ b/libstdc++-v3/testsuite/29_atomics/atomic_flag/test/implicit.cc
@@ -1,3 +1,4 @@
+// { dg-options "-std=gnu++2a" }
 // { dg-do run { target c++2a } }
 // { dg-require-thread-fence "" }
 
@@ -19,14 +20,21 @@
 // .
 
 #include 
+#include 
 
 int main()
 {
   using namespace std;
-  atomic_flag af = ATOMIC_FLAG_INIT;
 
-  if (af.test())
-af.clear();
+  atomic_flag af0 = ATOMIC_FLAG_INIT;
+  VERIFY( ! af0.test(memory_order_acquire) );
 
-  return 0;
+  atomic_flag af{true};
+  const atomic_flag& caf = af;
+
+  VERIFY( af.test() );
+  VERIFY( caf.test() );
+  af.clear();
+  VERIFY( ! af.test() );
+  VERIFY( ! caf.test() );
 }


Re: [stage1][PATCH] Lower VEC_COND_EXPR into internal functions.

2020-06-12 Thread Richard Biener via Gcc-patches
On Thu, Jun 11, 2020 at 10:52 AM Martin Liška  wrote:
>
> On 6/9/20 3:42 PM, Richard Biener wrote:
> > I think we need to fix that before merging.
>
> There's updated version of the patch that should handle the EH properly.
>
> Patch can bootstrap on x86_64-linux-gnu and survives regression tests.
>
> Ready to be installed?

I think it would be better to avoid creating of a new edge and removing the old
by simply moving the condition stmt to the normal outgoing edge.  Thus in
expand_vector_condition do

   if (lookup_stmt_eh_lp (stmt) != 0)
 {
maybe_clean_or_replace_eh_stmt (stmt, assign);
gsi_remove (gsi, false);
edge_iterator ei;
edge e;
FOR_EACH_EDGE (e, ei, gimple_bb (assign)->succs)
   if (e->flags & EDGE_EH)
 break;
if (e)
  {
 gsi_remove (gsi, false);
 gsi_insert_on_edge_immediate (e, stmt);
  }
else
   gsi_remove (gsi, true);
 }

a twist is probably the following which shows how we wrongly
make 'res' available in the catch block.  The above would
break (your variant as well) since SSA form is broken afterwards.
This of course solves itself when we not start with the broken
IL in the first place.  We could also try to "solve" this in the
SSA renamer, but then I'm not sure if gimplification doesn't
already break it.

typedef double v2df __attribute__((vector_size(16)));

v2df foo (v2df a, v2df b, v2df c, v2df d)
{
 v2df res;
  try
  {
 res = a < b ? c : d;
return res; // replace with gcc_unreachable () for more twists
}
catch (...)
{
return res;
}
}

So ... how far are you with enforcing a split VEC_COND_EXPR?
Thus can we avoid the above completely (even as intermediate
state)?

Thanks,
Richard.

> Thanks,
> Martin


Re: [PATCH] guard against calls with fewer arguments than the function type implies (PR 95581)

2020-06-12 Thread Richard Biener via Gcc-patches
On Fri, Jun 12, 2020 at 2:31 AM Segher Boessenkool
 wrote:
>
> On Tue, Jun 09, 2020 at 09:51:12AM -0600, Martin Sebor wrote:
> > >I think the backend declaration is wrong, the function only takes
> > >a void * argument and returns a long.
> >
> > Thanks.  In his comment on the bug Segher (CC'd) points to
> > the internals manual that documents the function:
> >
> > https://gcc.gnu.org/git/?p=gcc.git;a=blob;f=gcc/target.def;h=07059a87caf7cc0237d583124b476ee45ea41ed5;hb=HEAD#l1744
> >
> > (By the way, thanks for the pointer!)
> >
> > If I read it right, ihe function f in
> > the TARGET_VECTORIZE_BUILTIN_MASK_FOR_LOAD documentation is
> > __builtin_altivec_mask_for_load.  Although the manual isn't
> > unequivocal about this but it does suggest the address addr
> > the function is given as an argument should be the first
> > (and presumably only) argument.  This matches the call in
> > the IL where the first argument is a pointer, but not
> > the function's signature.
> >
> > I think the middle end needs to be able to rely on built-in
> > function types when processing calls: i.e., the types and
> > numbers of actual arguments in the calls need to match those
> > of the built-in function type.  Otherwise it would have to
> > validate every call against the function signature and avoid
> > treating it as a built-in if it doesn't match.  There are
> > parts of the middle end that do that for library built-ins
> > (because they can be declared in a program with mismatched
> > signatures) but as we have seen it's error-prone.  I don't
> > think it would be helpful to try to extend this approach to
> > internal built-ins.
> >
> > So I agree that the real problem is the declaration of
> > the built-in.
>
> The problem is that this altivec builtin cannot implement the generic
> builtin directly.  It should *not* be changed, we *do* need to keep
> this builtin as-is.  We just cannot forward the generic builtin to it
> like this.
>
> Why did this work before, and not anymore?  That sounds like a missing
> or broken test?

It "worked" before because GIMPLE IL checking is not strict here
because of too many existing "bugs" like this.  Well, quite a few
years ago at least.

Richard.

> Thanks,
>
>
> Segher


Re: [PATCH] rs6000: skip debug info statements

2020-06-12 Thread Richard Biener via Gcc-patches
On Thu, Jun 11, 2020 at 9:04 PM Segher Boessenkool
 wrote:
>
> Hi!
>
> On Thu, Jun 11, 2020 at 01:49:57PM +0200, Martin Liška wrote:
> > Since stmt_vec_info is not generated for debug info statements, these needs
> > to
> > be skipped in rs6000_density_test.
>
> >   PR target/95627
> >   * config/rs6000/rs6000.c (rs6000_density_test): Skip debug
> >   statements.
>
> > diff --git a/gcc/config/rs6000/rs6000.c b/gcc/config/rs6000/rs6000.c
> > index 0bbd06ad1de..00daf979856 100644
> > --- a/gcc/config/rs6000/rs6000.c
> > +++ b/gcc/config/rs6000/rs6000.c
> > @@ -4987,6 +4987,9 @@ rs6000_density_test (rs6000_cost_data *data)
> >for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next ())
> >   {
> > gimple *stmt = gsi_stmt (gsi);
> > +   if (is_gimple_debug (stmt))
> > +   continue;
>
> Yes, this is fine for trunk (with the indent fixed), thanks!
>
> Or you could use gsi_next_nondebug?  That is a bit neater.  Either way
> is okay.

Also need to adjust gsi_start_bb then, of course.

>
> Thanks!
>
>
> Segher


[Ada] Implement AI12-0369

2020-06-12 Thread Pierre-Marie de Rodat
AI12-0369 relaxes the rules for the Static_Barriers and Pure_Barriers
restrictions so that subcomponents of a protected object can be named
(subject to some restrictions) in a barrier expression. Note that one
effect of this is to undo a change that was made recently for AI12-0290.

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

2020-06-12  Steve Baird  

gcc/ada/

* sem_util.ads, sem_util.adb: Define 3 new Boolean-valued
functions - Statically_Denotes_Entity,
Statically_Denotes_Object, and Statically_Names_Object. The
first two were taken from sem_attr.adb. The term "statically
names" is defined in the Ada RM and the new function
Statically_Names_Object is intended to reflect that definition,
or more precisely, as described in a comment in the code, to
reflect the expected future definition of that term.
* sem_attr.adb: Delete functions Statically_Denotes_Object and
Statically_Denotes_Entity; these two functions have been moved
to package Sem_Util. Replace call to Statically_Denotes_Object
with a call to Statically_Names_Object as per AI12-0217 (a
binding interpretation, so no Ada_Version check).
* exp_ch9.adb (Expand_Entry_Barrier.Is_Simple_Barrier): Change
name of function (it was previously Is_Simple_Barrier_Name)
because the function should return True in the case of a static
expression; implement this requirement.  Change function to
include a call to Statically_Names_Object so that, for Ada_2020
and later, it will return True for appropriate subcomponent
names.
(Expand_Entry_Barrier.Is_Pure_Barrier): Handle
N_Indexed_Component and N_Selected_Component cases by calling
Statically_Names_Object.
(Expand_Entry_Barrier): Reorganize to treat Simple_Barriers and
Pure_Barriers more uniformly.  Prevent cascaded errors.--- gcc/ada/exp_ch9.adb
+++ gcc/ada/exp_ch9.adb
@@ -5961,12 +5961,12 @@ package body Exp_Ch9 is
   --  If so, barrier may not be properly synchronized.
 
   function Is_Pure_Barrier (N : Node_Id) return Traverse_Result;
-  --  Check whether N follows the Pure_Barriers restriction. Return OK if
+  --  Check whether N meets the Pure_Barriers restriction. Return OK if
   --  so.
 
-  function Is_Simple_Barrier_Name (N : Node_Id) return Boolean;
-  --  Check whether entity name N denotes a component of the protected
-  --  object. This is used to check the Simple_Barrier restriction.
+  function Is_Simple_Barrier (N : Node_Id) return Boolean;
+  --  Check whether N meets the Simple_Barriers restriction. Return OK if
+  --  so.
 
   --
   -- Is_Global_Entity --
@@ -6018,14 +6018,25 @@ package body Exp_Ch9 is
   procedure Check_Unprotected_Barrier is
 new Traverse_Proc (Is_Global_Entity);
 
-  
-  -- Is_Simple_Barrier_Name --
-  
+  ---
+  -- Is_Simple_Barrier --
+  ---
 
-  function Is_Simple_Barrier_Name (N : Node_Id) return Boolean is
+  function Is_Simple_Barrier (N : Node_Id) return Boolean is
  Renamed : Node_Id;
 
   begin
+ if Is_Static_Expression (N) then
+return True;
+ elsif Ada_Version >= Ada_2020
+   and then Nkind_In (N, N_Selected_Component, N_Indexed_Component)
+   and then Statically_Names_Object (N)
+ then
+--  Restriction relaxed in Ada2020 to allow statically named
+--  subcomponents.
+return Is_Simple_Barrier (Prefix (N));
+ end if;
+
  --  Check if the name is a component of the protected object. If
  --  the expander is active, the component has been transformed into a
  --  renaming of _object.all.component. Original_Node is needed in case
@@ -6048,10 +6059,12 @@ package body Exp_Ch9 is
   Present (Renamed)
 and then Nkind (Renamed) = N_Selected_Component
 and then Chars (Prefix (Prefix (Renamed))) = Name_uObject;
+ elsif not Is_Entity_Name (N) then
+return False;
  else
 return Is_Protected_Component (Entity (N));
  end if;
-  end Is_Simple_Barrier_Name;
+  end Is_Simple_Barrier;
 
   -
   -- Is_Pure_Barrier --
@@ -6092,7 +6105,7 @@ package body Exp_Ch9 is
  return Skip;
 
   when E_Variable =>
- if Is_Simple_Barrier_Name (N) then
+ if Is_Simple_Barrier (N) then
 return Skip;
  end if;
 
@@ -6137,6 +6150,13 @@ package body Exp_Ch9 is
 =>
return OK;
 
+when N_Indexed_Component | N_Selected_Component =>
+   if Statically_Names_Object (N) then
+  

[Ada] Improve code generated for assignment of dynamic record aggregates

2020-06-12 Thread Pierre-Marie de Rodat
This mainly improves the code generated for the assignment of dynamic
record aggregates, which was always going through a temporary if the
target of the assignment was not a simple identifier (this is not the
case for dynamic array aggregates).  This also extends a little the
set of acceptable components of the aggregates in such a case.

This also ensures that a temporary is never created if an aggregate
is used as the expression of an allocator.

This finally streamlines a little the handling of the assignment of
qualified array aggregates.

No functional changes.

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

2020-06-12  Eric Botcazou  

gcc/ada/

* exp_aggr.adb: Add with and use clauses for Sem_Mech.
(Get_Base_Object): New function to get the base object of a node.
(In_Place_Assign_OK): Add Target_Object parameter.  Deal with a
qualified expression on entry.  Remove short-circuit for array
aggregates with a single "others" choice.  Do not look into the
components of the aggregate if the parent is an allocator.
(Check_Component): Add T_OK parameter and rewrite.
(Safe_Component): Invoke Check_Component with T_OK set to False.
(Convert_To_Assignments): Try to use an in-place assignment for
any target; for that, call Get_Base_Object on the target and pass
the result to In_Place_Assign_OK.
(Expand_Array_Aggregate): Use Parent_Kind and Parent_Node more
consistently.  For an assignment, call Get_Base_Object on the
target and pass the result to In_Place_Assign_OK.--- gcc/ada/exp_aggr.adb
+++ gcc/ada/exp_aggr.adb
@@ -53,6 +53,7 @@ with Sem_Aggr; use Sem_Aggr;
 with Sem_Aux;  use Sem_Aux;
 with Sem_Ch3;  use Sem_Ch3;
 with Sem_Eval; use Sem_Eval;
+with Sem_Mech; use Sem_Mech;
 with Sem_Res;  use Sem_Res;
 with Sem_Util; use Sem_Util;
 with Sinfo;use Sinfo;
@@ -86,6 +87,11 @@ package body Exp_Aggr is
procedure Expand_Delta_Array_Aggregate  (N : Node_Id; Deltas : List_Id);
procedure Expand_Delta_Record_Aggregate (N : Node_Id; Deltas : List_Id);
 
+   function Get_Base_Object (N : Node_Id) return Entity_Id;
+   --  Return the base object, i.e. the outermost prefix object, that N refers
+   --  to statically, or Empty if it cannot be determined. The assumption is
+   --  that all dereferences are explicit in the tree rooted at N.
+
function Has_Default_Init_Comps (N : Node_Id) return Boolean;
--  N is an aggregate (record or array). Checks the presence of default
--  initialization (<>) in any component (Ada 2005: AI-287).
@@ -217,7 +223,9 @@ package body Exp_Aggr is
--  defaults. An aggregate for a type with mutable components must be
--  expanded into individual assignments.
 
-   function In_Place_Assign_OK (N : Node_Id) return Boolean;
+   function In_Place_Assign_OK
+ (N : Node_Id;
+  Target_Object : Entity_Id := Empty) return Boolean;
--  Predicate to determine whether an aggregate assignment can be done in
--  place, because none of the new values can depend on the components of
--  the target of the assignment.
@@ -4122,23 +4130,40 @@ package body Exp_Aggr is
-- In_Place_Assign_OK --

 
-   function In_Place_Assign_OK (N : Node_Id) return Boolean is
+   function In_Place_Assign_OK
+ (N : Node_Id;
+  Target_Object : Entity_Id := Empty) return Boolean
+   is
   Is_Array : constant Boolean := Is_Array_Type (Etype (N));
 
-  Aggr_In : Node_Id;
-  Aggr_Lo : Node_Id;
-  Aggr_Hi : Node_Id;
-  Obj_In  : Node_Id;
-  Obj_Lo  : Node_Id;
-  Obj_Hi  : Node_Id;
+  Aggr_In : Node_Id;
+  Aggr_Lo : Node_Id;
+  Aggr_Hi : Node_Id;
+  Obj_In  : Node_Id;
+  Obj_Lo  : Node_Id;
+  Obj_Hi  : Node_Id;
+  Parent_Kind : Node_Kind;
+  Parent_Node : Node_Id;
 
   function Safe_Aggregate (Aggr : Node_Id) return Boolean;
   --  Check recursively that each component of a (sub)aggregate does not
   --  depend on the variable being assigned to.
 
   function Safe_Component (Expr : Node_Id) return Boolean;
-  --  Verify that an expression cannot depend on the variable being
-  --  assigned to. Room for improvement here (but less than before).
+  --  Verify that an expression cannot depend on the target being assigned
+  --  to. Return true for compile-time known values, stand-alone objects,
+  --  parameters passed by copy, calls to functions that return by copy,
+  --  selected components thereof only if the aggregate's type is an array,
+  --  indexed components and slices thereof only if the aggregate's type is
+  --  a record, and simple expressions involving only these as operands.
+  --  This is OK whatever the target because, for a component to overlap
+  --  with the target, it must be either a direct reference to a component
+  --  of the target, in which case 

[Ada] Fix anonymous-to-named access type implicit conversion legality checking

2020-06-12 Thread Pierre-Marie de Rodat
There are some cases where an explicit type conversion from an anonymous
access type to a named access type is legal but an implicit conversion
is not. Ada RM 8.6 requires that for such an implicit conversion (but
not for an explicit conversion), the operand of the conversion "shall
denote a view with an accessibility level for which the statically
deeper relationship applies". The previous code which appears to have
been intended to implement this test was brief, straightforward, and
completely wrong; it could produce errors in either direction (i.e.,
accepting what should be rejected and rejecting what should be
accepted).

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

2020-06-12  Steve Baird  

gcc/ada/

* sem_res.adb (Valid_Conversion): The simpler cases of
violations of the aforementioned 8.6 rule are already handled
correctly. These include cases where the operand of the type
conversion is an access parameter or a stand-alone object of an
anonymous access type. Add code to detect violations where the
operand of the type conversion is an access discriminant whose
accessibility level is tied to one of the other simpler cases.
This is implemented in a new function,
Valid_Conversion.Is_Discrim_Of_Bad_Access_Conversion_Argument,
which is called in place of the previous test.--- gcc/ada/sem_res.adb
+++ gcc/ada/sem_res.adb
@@ -12482,6 +12482,18 @@ package body Sem_Res is
   --  are not rechecked because type visbility may lead to spurious errors,
   --  but conversions in an actual for a formal object must be checked.
 
+  function Is_Discrim_Of_Bad_Access_Conversion_Argument
+(Expr : Node_Id) return Boolean;
+  --  Implicit anonymous-to-named access type conversions are not allowed
+  --  if the "statically deeper than" relationship does not apply to the
+  --  type of the conversion operand. See RM 8.6(28.1) and AARM 8.6(28.d).
+  --  We deal with most such cases elsewhere so that we can emit more
+  --  specific error messages (e.g., if the operand is an access parameter
+  --  or a saooaaat (stand-alone object of an anonymous access type)), but
+  --  here is where we catch the case where the operand is an access
+  --  discriminant selected from a dereference of another such "bad"
+  --  conversion argument.
+
   function Valid_Tagged_Conversion
 (Target_Type : Entity_Id;
  Opnd_Type   : Entity_Id) return Boolean;
@@ -12584,6 +12596,74 @@ package body Sem_Res is
  end if;
   end In_Instance_Code;
 
+  --
+  -- Is_Discrim_Of_Bad_Access_Conversion_Argument --
+  --
+
+  function Is_Discrim_Of_Bad_Access_Conversion_Argument
+(Expr : Node_Id) return Boolean
+  is
+ Exp_Type : Entity_Id := Base_Type (Etype (Expr));
+ pragma Assert (Is_Access_Type (Exp_Type));
+
+ Associated_Node : Node_Id;
+ Deref_Prefix : Node_Id;
+  begin
+ if not Is_Anonymous_Access_Type (Exp_Type) then
+return False;
+ end if;
+
+ pragma Assert (Is_Itype (Exp_Type));
+ Associated_Node := Associated_Node_For_Itype (Exp_Type);
+
+ if Nkind (Associated_Node) /= N_Discriminant_Specification then
+return False; -- not the type of an access discriminant
+ end if;
+
+ --  return False if Expr not of form .all.Some_Component
+
+ if (Nkind (Expr) /= N_Selected_Component)
+   or else (Nkind (Prefix (Expr)) /= N_Explicit_Dereference)
+ then
+--  conditional expressions, declare expressions ???
+return False;
+ end if;
+
+ Deref_Prefix := Prefix (Prefix (Expr));
+ Exp_Type := Base_Type (Etype (Deref_Prefix));
+
+ --  The "statically deeper relationship" does not apply
+ --  to generic formal access types, so a prefix of such
+ --  a type is a "bad" prefix.
+
+ if Is_Generic_Formal (Exp_Type) then
+return True;
+
+ --  The "statically deeper relationship" does apply to
+ --  any other named access type.
+
+ elsif not Is_Anonymous_Access_Type (Exp_Type) then
+return False;
+ end if;
+
+ pragma Assert (Is_Itype (Exp_Type));
+ Associated_Node := Associated_Node_For_Itype (Exp_Type);
+
+ --  The "statically deeper relationship" applies to some
+ --  anonymous access types and not to others. Return
+ --  True for the cases where it does not apply. Also check
+ --  recursively for the
+ -- .all.Access_Discrim.all.Access_Discrim case,
+ --  where the correct result depends on .
+
+ return Nkind_In (Associated_Node,
+   N_Procedure_Specification, -- access parameter
+   N_Function_Specification,  -- 

[Ada] Alphabetic ordering for name and pragmas

2020-06-12 Thread Pierre-Marie de Rodat
Identifiers in the snames template file are ordered either logically or
alphabetically, but the Test_Case identifier was clearly out-of-order.
Likewise for pragmas. Cleanup before adding a new aspect; semantics in
unaffected.

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

2020-06-12  Piotr Trojanek  

gcc/ada/

* par-prag.adb: Fix ordering.
* snames.ads-tmpl (Name_Test_Case, Pragma_Test_Case): Likewise.
* sem_prag.adb (Sig_Flags): Likewise.--- gcc/ada/par-prag.adb
+++ gcc/ada/par-prag.adb
@@ -1350,21 +1350,21 @@ begin
  | Pragma_Convention
  | Pragma_Deadline_Floor
  | Pragma_Debug_Policy
- | Pragma_Depends
- | Pragma_Detect_Blocking
  | Pragma_Default_Initial_Condition
  | Pragma_Default_Scalar_Storage_Order
  | Pragma_Default_Storage_Pool
+ | Pragma_Depends
+ | Pragma_Detect_Blocking
  | Pragma_Disable_Atomic_Synchronization
  | Pragma_Discard_Names
  | Pragma_Dispatching_Domain
  | Pragma_Effective_Reads
  | Pragma_Effective_Writes
- | Pragma_Eliminate
  | Pragma_Elaborate
  | Pragma_Elaborate_All
  | Pragma_Elaborate_Body
  | Pragma_Elaboration_Checks
+ | Pragma_Eliminate
  | Pragma_Enable_Atomic_Synchronization
  | Pragma_Export
  | Pragma_Export_Function
@@ -1376,8 +1376,8 @@ begin
  | Pragma_Extensions_Visible
  | Pragma_External
  | Pragma_External_Name_Casing
- | Pragma_Favor_Top_Level
  | Pragma_Fast_Math
+ | Pragma_Favor_Top_Level
  | Pragma_Finalize_Storage_Only
  | Pragma_Ghost
  | Pragma_Global
@@ -1402,8 +1402,8 @@ begin
  | Pragma_Interface
  | Pragma_Interface_Name
  | Pragma_Interrupt_Handler
- | Pragma_Interrupt_State
  | Pragma_Interrupt_Priority
+ | Pragma_Interrupt_State
  | Pragma_Invariant
  | Pragma_Keep_Names
  | Pragma_License
@@ -1437,9 +1437,9 @@ begin
  | Pragma_No_Tagged_Streams
  | Pragma_Normalize_Scalars
  | Pragma_Obsolescent
- | Pragma_Ordered
  | Pragma_Optimize
  | Pragma_Optimize_Alignment
+ | Pragma_Ordered
  | Pragma_Overflow_Mode
  | Pragma_Overriding_Renamings
  | Pragma_Pack
@@ -1469,6 +1469,8 @@ begin
  | Pragma_Pure
  | Pragma_Pure_Function
  | Pragma_Queuing_Policy
+ | Pragma_Rational
+ | Pragma_Ravenscar
  | Pragma_Refined_Depends
  | Pragma_Refined_Global
  | Pragma_Refined_Post
@@ -1477,10 +1479,8 @@ begin
  | Pragma_Remote_Access_Type
  | Pragma_Remote_Call_Interface
  | Pragma_Remote_Types
- | Pragma_Restricted_Run_Time
- | Pragma_Rational
- | Pragma_Ravenscar
  | Pragma_Rename_Pragma
+ | Pragma_Restricted_Run_Time
  | Pragma_Reviewable
  | Pragma_Secondary_Stack_Size
  | Pragma_Share_Generic
@@ -1490,9 +1490,9 @@ begin
  | Pragma_Short_Descriptors
  | Pragma_Simple_Storage_Pool_Type
  | Pragma_SPARK_Mode
+ | Pragma_Static_Elaboration_Desired
  | Pragma_Storage_Size
  | Pragma_Storage_Unit
- | Pragma_Static_Elaboration_Desired
  | Pragma_Stream_Convert
  | Pragma_Subtitle
  | Pragma_Suppress
@@ -1522,12 +1522,12 @@ begin
  | Pragma_Unsuppress
  | Pragma_Unused
  | Pragma_Use_VADS_Size
+ | Pragma_Validity_Checks
  | Pragma_Volatile
  | Pragma_Volatile_Components
  | Pragma_Volatile_Full_Access
  | Pragma_Volatile_Function
  | Pragma_Weak_External
- | Pragma_Validity_Checks
   =>
  null;
 

--- gcc/ada/sem_prag.adb
+++ gcc/ada/sem_prag.adb
@@ -30876,11 +30876,11 @@ package body Sem_Prag is
   Pragma_Deadline_Floor => -1,
   Pragma_Debug  => -1,
   Pragma_Debug_Policy   =>  0,
-  Pragma_Detect_Blocking=>  0,
   Pragma_Default_Initial_Condition  => -1,
   Pragma_Default_Scalar_Storage_Order   =>  0,
   Pragma_Default_Storage_Pool   =>  0,
   Pragma_Depends=> -1,
+  Pragma_Detect_Blocking=>  0,
   Pragma_Disable_Atomic_Synchronization =>  0,
   Pragma_Discard_Names  =>  0,
   Pragma_Dispatching_Domain => -1,
@@ -30902,9 +30902,9 @@ package body Sem_Prag is
   Pragma_Extensions_Allowed =>  0,
   Pragma_Extensions_Visible =>  0,
   Pragma_External   => -1,
-  Pragma_Favor_Top_Level=>  0,
   Pragma_External_Name_Casing   =>  0,
   Pragma_Fast_Math  =>  0,
+  Pragma_Favor_Top_Level=> 

[Ada] Fix handling of Ada 83 OUT parameter rule

2020-06-12 Thread Pierre-Marie de Rodat
The current code was climbing the tree manually assuming that an array
attribute (e.g. 'First) would appear immediately, which isn't the case
for e.g. a selected component expression.

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

2020-06-12  Arnaud Charlet  

gcc/ada/

* sem_res.adb (Resolve_Entity_Name): Fix handling of expressions
containing array attributes wrt Ada 83 detection.--- gcc/ada/sem_res.adb
+++ gcc/ada/sem_res.adb
@@ -7370,6 +7370,10 @@ package body Sem_Res is
   --  Determine whether node Context denotes an assignment statement or an
   --  object declaration whose expression is node Expr.
 
+  function Is_Attribute_Expression (Expr : Node_Id) return Boolean;
+  --  Determine whether Expr is part of an N_Attribute_Reference
+  --  expression.
+
   
   -- Is_Assignment_Or_Object_Expression --
   
@@ -7412,6 +7416,24 @@ package body Sem_Res is
  end if;
   end Is_Assignment_Or_Object_Expression;
 
+  -
+  -- Is_Attribute_Expression --
+  -
+
+  function Is_Attribute_Expression (Expr : Node_Id) return Boolean is
+ N : Node_Id := Expr;
+  begin
+ while Present (N) loop
+if Nkind (N) = N_Attribute_Reference then
+   return True;
+end if;
+
+N := Parent (N);
+ end loop;
+
+ return False;
+  end Is_Attribute_Expression;
+
   --  Local variables
 
   E   : constant Entity_Id := Entity (N);
@@ -7482,8 +7504,8 @@ package body Sem_Res is
   --  array types (i.e. bounds and length) are legal.
 
   elsif Ekind (E) = E_Out_Parameter
-and then (Nkind (Parent (N)) /= N_Attribute_Reference
-   or else Is_Scalar_Type (Etype (E)))
+and then (Is_Scalar_Type (Etype (E))
+   or else not Is_Attribute_Expression (Parent (N)))
 
 and then (Nkind (Parent (N)) in N_Op
or else Nkind (Parent (N)) = N_Explicit_Dereference



[Ada] AI12-0074 View conversions and out parameters passed by copy

2020-06-12 Thread Pierre-Marie de Rodat
This Ada 202x AI makes illegal some cases of out parameters whose type
has a Default_Value aspect.

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

2020-06-12  Arnaud Charlet  

gcc/ada/

* sem_res.adb (Resolve_Actuals): Check for AI12-0074.--- gcc/ada/sem_res.adb
+++ gcc/ada/sem_res.adb
@@ -4010,69 +4010,94 @@ package body Sem_Res is
   and then not Is_Class_Wide_Type (Etype (Expression (A)))
   and then not Is_Interface (Etype (A))
 then
-   if Ekind (F) = E_In_Out_Parameter
- and then Is_Array_Type (Etype (F))
-   then
-  --  In a view conversion, the conversion must be legal in
-  --  both directions, and thus both component types must be
-  --  aliased, or neither (4.6 (8)).
-
-  --  The extra rule in 4.6 (24.9.2) seems unduly restrictive:
-  --  the privacy requirement should not apply to generic
-  --  types, and should be checked in an instance. ARG query
-  --  is in order ???
-
-  if Has_Aliased_Components (Etype (Expression (A))) /=
- Has_Aliased_Components (Etype (F))
+   declare
+  Expr_Typ : constant Entity_Id := Etype (Expression (A));
+   begin
+  if Ekind (F) = E_In_Out_Parameter
+and then Is_Array_Type (Etype (F))
   then
- Error_Msg_N
-   ("both component types in a view conversion must be"
- & " aliased, or neither", A);
+ --  In a view conversion, the conversion must be legal in
+ --  both directions, and thus both component types must be
+ --  aliased, or neither (4.6 (8)).
 
-  --  Comment here??? what set of cases???
+ --  The extra rule in 4.6 (24.9.2) seems unduly
+ --  restrictive: the privacy requirement should not apply
+ --  to generic types, and should be checked in an
+ --  instance. ARG query is in order ???
 
-  elsif
- not Same_Ancestor (Etype (F), Etype (Expression (A)))
-  then
- --  Check view conv between unrelated by ref array types
-
- if Is_By_Reference_Type (Etype (F))
-or else Is_By_Reference_Type (Etype (Expression (A)))
+ if Has_Aliased_Components (Expr_Typ) /=
+Has_Aliased_Components (Etype (F))
  then
 Error_Msg_N
-  ("view conversion between unrelated by reference "
-   & "array types not allowed (\'A'I-00246)", A);
-
- --  In Ada 2005 mode, check view conversion component
- --  type cannot be private, tagged, or volatile. Note
- --  that we only apply this to source conversions. The
- --  generated code can contain conversions which are
- --  not subject to this test, and we cannot extract the
- --  component type in such cases since it is not present.
-
- elsif Comes_From_Source (A)
-   and then Ada_Version >= Ada_2005
- then
-declare
-   Comp_Type : constant Entity_Id :=
- Component_Type
-   (Etype (Expression (A)));
-begin
-   if (Is_Private_Type (Comp_Type)
- and then not Is_Generic_Type (Comp_Type))
- or else Is_Tagged_Type (Comp_Type)
- or else Is_Volatile (Comp_Type)
-   then
-  Error_Msg_N
-("component type of a view conversion cannot"
-   & " be private, tagged, or volatile"
-   & " (RM 4.6 (24))",
-   Expression (A));
-   end if;
-end;
+  ("both component types in a view conversion must be"
+& " aliased, or neither", A);
+
+ --  Comment here??? what set of cases???
+
+ elsif not Same_Ancestor (Etype (F), Expr_Typ) then
+--  Check view conv between unrelated by ref array
+--  types.
+
+if Is_By_Reference_Type (Etype (F))
+   or else Is_By_Reference_Type (Expr_Typ)
+then
+   

[Ada] Fix handling of subprograms declared in a protected body

2020-06-12 Thread Pierre-Marie de Rodat
Such subprograms are not protected and have convention Intrinsic to
ensure that their 'Access isn't taken as per RM 6.3.1(10/2).

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

2020-06-12  Arnaud Charlet  

gcc/ada/

* exp_ch6.adb (Expand_N_Subprogram_Declaration): Do nothing for
a subprogram declared in a protected body.
* exp_ch9.ads, exp_ch9.adb
(Build_Private_Protected_Declaration): Moved to sem_ch6.adb.
(Expand_N_Protected_Body): Do nothing for a subprogram declared
in a protected body.
* sem_ch6.adb (Build_Internal_Protected_Declaration): Moved from
exp_ch9.adb and renamed and fixed to ensure in particular that
such subprograms have convention Intrinsic and have no protected
version.
(Analyze_Subprogram_Body_Helper): Call
Build_Internal_Protected_Declaration.
(Move_Pragmas): Moved up and merged with the more general
version from Build_Private_Protected_Declaration. We only want
to copy selected pragmas, most pragmas are not suitable for a
copy on the spec.--- gcc/ada/exp_ch6.adb
+++ gcc/ada/exp_ch6.adb
@@ -6346,19 +6346,6 @@ package body Exp_Ch6 is
 Analyze (Prot_Decl);
 Freeze_Before (N, Prot_Id);
 Set_Protected_Body_Subprogram (Subp, Prot_Id);
-
---  Create protected operation as well. Even though the operation
---  is only accessible within the body, it is possible to make it
---  available outside of the protected object by using 'Access to
---  provide a callback, so build protected version in all cases.
-
-Prot_Decl :=
-  Make_Subprogram_Declaration (Loc,
-Specification =>
-  Build_Protected_Sub_Specification (N, Scop, Protected_Mode));
-Insert_Before (Prot_Bod, Prot_Decl);
-Analyze (Prot_Decl);
-
 Pop_Scope;
  end if;
 

--- gcc/ada/exp_ch9.adb
+++ gcc/ada/exp_ch9.adb
@@ -23,7 +23,6 @@
 --  --
 --
 
-with Aspects;  use Aspects;
 with Atree;use Atree;
 with Einfo;use Einfo;
 with Elists;   use Elists;
@@ -56,7 +55,6 @@ with Sem_Ch11; use Sem_Ch11;
 with Sem_Ch13; use Sem_Ch13;
 with Sem_Elab; use Sem_Elab;
 with Sem_Eval; use Sem_Eval;
-with Sem_Prag; use Sem_Prag;
 with Sem_Res;  use Sem_Res;
 with Sem_Util; use Sem_Util;
 with Sinfo;use Sinfo;
@@ -3491,177 +3489,6 @@ package body Exp_Ch9 is
   Set_Master_Id (Ptr_Typ, Master_Id);
end Build_Master_Renaming;
 
-   -
-   -- Build_Private_Protected_Declaration --
-   -
-
-   function Build_Private_Protected_Declaration
- (N : Node_Id) return Entity_Id
-   is
-  procedure Analyze_Pragmas (From : Node_Id);
-  --  Analyze all pragmas which follow arbitrary node From
-
-  procedure Move_Pragmas (From : Node_Id; To : Node_Id);
-  --  Find all suitable source pragmas at the top of subprogram body From's
-  --  declarations and insert them after arbitrary node To.
-  --
-  --  Very similar to Move_Pragmas in sem_ch6 ???
-
-  -
-  -- Analyze_Pragmas --
-  -
-
-  procedure Analyze_Pragmas (From : Node_Id) is
- Decl : Node_Id;
-
-  begin
- Decl := Next (From);
- while Present (Decl) loop
-if Nkind (Decl) = N_Pragma then
-   Analyze_Pragma (Decl);
-
---  No candidate pragmas are available for analysis
-
-else
-   exit;
-end if;
-
-Next (Decl);
- end loop;
-  end Analyze_Pragmas;
-
-  --
-  -- Move_Pragmas --
-  --
-
-  procedure Move_Pragmas (From : Node_Id; To : Node_Id) is
- Decl   : Node_Id;
- Insert_Nod : Node_Id;
- Next_Decl  : Node_Id;
-
-  begin
- pragma Assert (Nkind (From) = N_Subprogram_Body);
-
- --  The pragmas are moved in an order-preserving fashion
-
- Insert_Nod := To;
-
- --  Inspect the declarations of the subprogram body and relocate all
- --  candidate pragmas.
-
- Decl := First (Declarations (From));
- while Present (Decl) loop
-
---  Preserve the following declaration for iteration purposes, due
---  to possible relocation of a pragma.
-
-Next_Decl := Next (Decl);
-
---  We add an exception here for Unreferenced pragmas since the
---  internally generated spec gets analyzed within
---  Build_Private_Protected_Declaration and will lead to spurious
---  warnings due to the way references are checked.
-
-if Nkind (Decl) = N_Pragma
-  and 

[Ada] Don't correct socket timeout on Windows Server 2019

2020-06-12 Thread Pierre-Marie de Rodat
Windows Server 2019 do not need 500ms socket timeout correction. The
problem is that Windows API recommended function
IsWindowsVersionOrGreater is not comparing the build part which is only
difference between Windows 2016 and 2019 servers.

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

2020-06-12  Dmitriy Anisimkov  

gcc/ada/

* socket.c (__gnat_minus_500ms): Use GetVersionEx to detect
Windows Server version.
* libgnat/g-sothco.ads (Minus_500ms_Windows_Timeout): Remade to
Boolean constant.
* libgnat/g-socket.adb (Set_Socket_Option): Use
Minus_500ms_Windows_Timeout constant instead of function call.--- gcc/ada/libgnat/g-socket.adb
+++ gcc/ada/libgnat/g-socket.adb
@@ -2722,7 +2722,7 @@ package body GNAT.Sockets is
--  Old windows versions actual timeout is 500 ms + the given
--  value (unless it is 0).
 
-   if Minus_500ms_Windows_Timeout /= 0 then
+   if Minus_500ms_Windows_Timeout then
   if U4 > 500 then
  U4 := U4 - 500;
 

--- gcc/ada/libgnat/g-sothco.ads
+++ gcc/ada/libgnat/g-sothco.ads
@@ -451,12 +451,19 @@ package GNAT.Sockets.Thin_Common is
renames Short_To_Network;
--  Symmetric operation
 
-   function Minus_500ms_Windows_Timeout return C.int;
+   Minus_500ms_Windows_Timeout : constant Boolean;
--  Microsoft Windows desktop older then 8.0 and Microsoft Windows Server
--  older than 2019 need timeout correction for 500 milliseconds. This
-   --  routine returns 1 for such versions.
+   --  constant is True for such versions.
 
 private
+
+   function Get_Minus_500ms_Timeout return C.int
+ with Import, Convention => C, External_Name => "__gnat_minus_500ms";
+
+   Minus_500ms_Windows_Timeout : constant Boolean :=
+   Get_Minus_500ms_Timeout /= 0;
+
pragma Import (C, Get_Socket_From_Set, "__gnat_get_socket_from_set");
pragma Import (C, Is_Socket_In_Set, "__gnat_is_socket_in_set");
pragma Import (C, Last_Socket_In_Set, "__gnat_last_socket_in_set");
@@ -488,6 +495,4 @@ private
pragma Import (C, Hostent_H_Length,   "__gnat_hostent_h_length");
pragma Import (C, Hostent_H_Addr, "__gnat_hostent_h_addr");
 
-   pragma Import (C, Minus_500ms_Windows_Timeout, "__gnat_minus_500ms");
-
 end GNAT.Sockets.Thin_Common;

--- gcc/ada/socket.c
+++ gcc/ada/socket.c
@@ -801,14 +801,26 @@ const char * __gnat_gai_strerror(int errcode) {
 
 int __gnat_minus_500ms() {
 #if defined (_WIN32)
-  // Windows 8.0 and newer do not need 500 millisecond socket timeout
-  // correction.
-  // We do not know the Windows server version without socket timeout
-  // correction for now. When we know, we can add the call for
-  // IsWindowsVersionOrGreater(10, 0, ) into condition.
-  return !IsWindows8OrGreater() || IsWindowsServer();
+  // Windows Server 2019 and Windows 8.0 do not need 500 millisecond socket
+  // timeout correction.
+  if (IsWindowsServer()) {
+OSVERSIONINFO osvi;
+ZeroMemory(, sizeof(OSVERSIONINFO));
+osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
+// Documentation proposes to use IsWindowsVersionOrGreater(10, 0, 17763)
+// but it does not compare by the build number (last parameter). See
+// regression test for RC03-012 in fixedbugs, there are some code to
+// investigate Windows version API behavior.
+GetVersionEx();
+return osvi.dwMajorVersion < 10
+|| osvi.dwMajorVersion == 10
+&& osvi.dwMinorVersion == 0
+&& osvi.dwBuildNumber < 17763;
+  } else {
+return !IsWindows8OrGreater();
+  }
 #else
-   return 0;
+  return 0;
 #endif
 }
 



[Ada] Bump secondary stack alignment factor in full runtimes

2020-06-12 Thread Pierre-Marie de Rodat
Use Standard'Maximum_Alignment * 2 unconditionally to accommodate
possible requirements by user code compiled with specific cpu/arch
options such as -mavx on x86 targets, which Gigi assumes the SS can
handle.

Such options influence what Standard'Maximum_Alignment returns and are
typically not used when s-secsta is compiled for the runtime.

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

2020-06-12  Olivier Hainque  

gcc/ada/

* libgnat/s-secsta.ads (Memory_Alignment): New constant, memory
alignment for chunks and allocated blocks. Initialize to
Standard'Maximum_Alignment * 2.
(Chunk_Memory): Use it.
* libgnat/s-secsta.adb (Round_Up): Likewise.--- gcc/ada/libgnat/s-secsta.adb
+++ gcc/ada/libgnat/s-secsta.adb
@@ -564,7 +564,7 @@ package body System.Secondary_Stack is
   --
 
   function Round_Up (Size : Storage_Count) return Memory_Size is
- Algn_MS : constant Memory_Size := Standard'Maximum_Alignment;
+ Algn_MS : constant Memory_Size := Memory_Alignment;
  Size_MS : constant Memory_Size := Memory_Size (Size);
 
   begin

--- gcc/ada/libgnat/s-secsta.ads
+++ gcc/ada/libgnat/s-secsta.ads
@@ -261,10 +261,23 @@ private
subtype Memory_Index is Memory_Size;
--  Index into the memory storage of a single chunk
 
+   Memory_Alignment : constant := Standard'Maximum_Alignment * 2;
+   --  The memory alignment we will want to honor on every allocation.
+   --
+   --  At this stage, gigi assumes we can accomodate any alignment requirement
+   --  there might be on the data type for which the memory gets allocated (see
+   --  build_call_alloc_dealloc).
+   --
+   --  The multiplication factor is intended to account for requirements
+   --  by user code compiled with specific arch/cpu options such as -mavx
+   --  on X86[_64] targets, which Standard'Maximum_Alignment doesn't convey
+   --  without such compilation options. * 4 would actually be needed to
+   --  support -mavx512f on X86, but this would incur more annoying memory
+   --  consumption overheads.
+
type Chunk_Memory is array (Memory_Size range <>) of SSE.Storage_Element;
-   for Chunk_Memory'Alignment use Standard'Maximum_Alignment;
-   --  The memory storage of a single chunk. It utilizes maximum alignment in
-   --  order to guarantee efficient operations.
+   for Chunk_Memory'Alignment use Memory_Alignment;
+   --  The memory storage of a single chunk
 
--
-- SS_Chunk --



[Ada] ACATS 4.1Q - CDD2A04 - RLS not followed

2020-06-12 Thread Pierre-Marie de Rodat
The required level of support for elementary streaming includes support
for 24 bits elements, which is added here.

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

2020-06-12  Arnaud Charlet  

gcc/ada/

* exp_strm.adb (Build_Elementary_Input_Call): Add support for 24
bits elementary types.
* rtsfind.ads: Add 24 bits integer streaming routines.
* sem_ch13.adb (Analyze_Attribute_Definition_Clause
[Attribute_Stream_Size]): Add support for 24 bits elementary
types.
* libgnat/s-stratt.ads, libgnat/s-stratt.adb,
libgnat/s-stratt__xdr.adb: Add support for signed and unsigned
24 bits integers.--- gcc/ada/exp_strm.adb
+++ gcc/ada/exp_strm.adb
@@ -569,6 +569,9 @@ package body Exp_Strm is
  elsif P_Size <= Standard_Short_Integer_Size then
 Lib_RE := RE_I_SI;
 
+ elsif P_Size = 24 then
+Lib_RE := RE_I_I24;
+
  elsif P_Size <= Standard_Integer_Size then
 Lib_RE := RE_I_I;
 
@@ -597,6 +600,9 @@ package body Exp_Strm is
  elsif P_Size <= Standard_Short_Integer_Size then
 Lib_RE := RE_I_SU;
 
+ elsif P_Size = 24 then
+Lib_RE := RE_I_U24;
+
  elsif P_Size <= Standard_Integer_Size then
 Lib_RE := RE_I_U;
 
@@ -798,6 +804,8 @@ package body Exp_Strm is
 Lib_RE := RE_W_SSI;
  elsif P_Size <= Standard_Short_Integer_Size then
 Lib_RE := RE_W_SI;
+ elsif P_Size = 24 then
+Lib_RE := RE_W_I24;
  elsif P_Size <= Standard_Integer_Size then
 Lib_RE := RE_W_I;
  elsif P_Size <= Standard_Long_Integer_Size then
@@ -822,6 +830,8 @@ package body Exp_Strm is
 Lib_RE := RE_W_SSU;
  elsif P_Size <= Standard_Short_Integer_Size then
 Lib_RE := RE_W_SU;
+ elsif P_Size = 24 then
+Lib_RE := RE_W_U24;
  elsif P_Size <= Standard_Integer_Size then
 Lib_RE := RE_W_U;
  elsif P_Size <= Standard_Long_Integer_Size then

--- gcc/ada/libgnat/s-stratt.adb
+++ gcc/ada/libgnat/s-stratt.adb
@@ -59,6 +59,7 @@ package body System.Stream_Attributes is
subtype S_C   is SEA (1 .. (Character'Size+ SU - 1) / SU);
subtype S_F   is SEA (1 .. (Float'Size+ SU - 1) / SU);
subtype S_I   is SEA (1 .. (Integer'Size  + SU - 1) / SU);
+   subtype S_I24 is SEA (1 .. (Integer_24'Size   + SU - 1) / SU);
subtype S_LF  is SEA (1 .. (Long_Float'Size   + SU - 1) / SU);
subtype S_LI  is SEA (1 .. (Long_Integer'Size + SU - 1) / SU);
subtype S_LLF is SEA (1 .. (Long_Long_Float'Size  + SU - 1) / SU);
@@ -71,6 +72,7 @@ package body System.Stream_Attributes is
subtype S_SSU is SEA (1 .. (UST.Short_Short_Unsigned'Size + SU - 1) / SU);
subtype S_SU  is SEA (1 .. (UST.Short_Unsigned'Size   + SU - 1) / SU);
subtype S_U   is SEA (1 .. (UST.Unsigned'Size + SU - 1) / SU);
+   subtype S_U24 is SEA (1 .. (Unsigned_24'Size  + SU - 1) / SU);
subtype S_WC  is SEA (1 .. (Wide_Character'Size   + SU - 1) / SU);
subtype S_WWC is SEA (1 .. (Wide_Wide_Character'Size  + SU - 1) / SU);
 
@@ -80,6 +82,7 @@ package body System.Stream_Attributes is
function From_AS  is new UC (Thin_Pointer, S_AS);
function From_F   is new UC (Float,S_F);
function From_I   is new UC (Integer,  S_I);
+   function From_I24 is new UC (Integer_24,   S_I24);
function From_LF  is new UC (Long_Float,   S_LF);
function From_LI  is new UC (Long_Integer, S_LI);
function From_LLF is new UC (Long_Long_Float,  S_LLF);
@@ -92,6 +95,7 @@ package body System.Stream_Attributes is
function From_SSU is new UC (UST.Short_Short_Unsigned, S_SSU);
function From_SU  is new UC (UST.Short_Unsigned,   S_SU);
function From_U   is new UC (UST.Unsigned, S_U);
+   function From_U24 is new UC (Unsigned_24,  S_U24);
function From_WC  is new UC (Wide_Character,   S_WC);
function From_WWC is new UC (Wide_Wide_Character,  S_WWC);
 
@@ -101,6 +105,7 @@ package body System.Stream_Attributes is
function To_AS  is new UC (S_AS,  Thin_Pointer);
function To_F   is new UC (S_F,   Float);
function To_I   is new UC (S_I,   Integer);
+   function To_I24 is new UC (S_I24, Integer_24);
function To_LF  is new UC (S_LF,  Long_Float);
function To_LI  is new UC (S_LI,  Long_Integer);
function To_LLF is new UC (S_LLF, Long_Long_Float);
@@ -113,6 +118,7 @@ package body System.Stream_Attributes is
function To_SSU is new UC (S_SSU, UST.Short_Short_Unsigned);
function To_SU  is new UC (S_SU,  UST.Short_Unsigned);
function To_U   is new UC (S_U,   UST.Unsigned);
+   function To_U24 is new UC (S_U24, Unsigned_24);
function To_WC  is new UC (S_WC,  

[Ada] Remove redundant iterations in checks for overlapping actuals

2020-06-12 Thread Pierre-Marie de Rodat
We were detecting overlapping actuals in a call like "Proc (A, B, C)"
using two loops that iterated over all parameters, so we were examining
9 pairs:

  A-A, A-B, A-C
  B-A, B-B, B-C
  C-A, C-B, C-C

Now the outer loop iterates over all parameters, while the inner loop
always starts from the next parameter, so we are examining just those
pairs:

  ___, A-B, A-C
  ___, ___, B-C
  ___, ___, ___

which gives the same messages but the code is faster (and cleaner).

Also, there was a yet another loop with a comment "Find matching
actual", which was always assigning Act with Act2 and Form with Form2.
This loop is now entirely removed. Again, messages are the same messages
but the code is faster (and cleaner).

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

2020-06-12  Piotr Trojanek  

gcc/ada/

* sem_warn.adb (Warn_On_Overlapping_Actuals): Simplify.--- gcc/ada/sem_warn.adb
+++ gcc/ada/sem_warn.adb
@@ -3750,12 +3750,10 @@ package body Sem_Warn is
 null;
 
  else
-Form2 := First_Formal (Subp);
-Act2  := First_Actual (N);
+Form2 := Next_Formal (Form1);
+Act2  := Next_Actual (Act1);
 while Present (Form2) and then Present (Act2) loop
-   if Form1 /= Form2
- and then Refer_Same_Object (Act1, Act2)
-   then
+   if Refer_Same_Object (Act1, Act2) then
   if Is_Generic_Type (Etype (Act2)) then
  return;
   end if;
@@ -3847,71 +3845,55 @@ package body Sem_Warn is
   or else Error_To_Warning
   or else Warn_Only;
 
-declare
-   Act  : Node_Id;
-   Form : Entity_Id;
-
-begin
-   --  Find matching actual
-
-   Act  := First_Actual (N);
-   Form := First_Formal (Subp);
-   while Act /= Act2 loop
-  Next_Formal (Form);
-  Next_Actual (Act);
-   end loop;
-
-   if Is_Elementary_Type (Etype (Act1))
- and then Ekind (Form2) = E_In_Parameter
-   then
-  null;  --  No real aliasing
-
-   elsif Is_Elementary_Type (Etype (Act2))
- and then Ekind (Form2) = E_In_Parameter
-   then
-  null;  --  Ditto
+if Is_Elementary_Type (Etype (Act1))
+  and then Ekind (Form2) = E_In_Parameter
+then
+   null;  --  No real aliasing
 
-   --  If the call was written in prefix notation, and
-   --  thus its prefix before rewriting was a selected
-   --  component, count only visible actuals in call.
+elsif Is_Elementary_Type (Etype (Act2))
+  and then Ekind (Form2) = E_In_Parameter
+then
+   null;  --  Ditto
 
-   elsif Is_Entity_Name (First_Actual (N))
- and then Nkind (Original_Node (N)) = Nkind (N)
- and then Nkind (Name (Original_Node (N))) =
-   N_Selected_Component
- and then
-   Is_Entity_Name
- (Prefix (Name (Original_Node (N
- and then
-   Entity (Prefix (Name (Original_Node (N =
- Entity (First_Actual (N))
-   then
-  if Act1 = First_Actual (N) then
- Error_Msg_FE
-   ("<<`IN OUT` prefix overlaps with "
-& "actual for&", Act1, Form);
+--  If the call was written in prefix notation, and
+--  thus its prefix before rewriting was a selected
+--  component, count only visible actuals in call.
 
-  else
- --  For greater clarity, give name of formal
-
- Error_Msg_Node_2 := Form;
- Error_Msg_FE
-   ("<

[Ada] Implement AI12-0175 Preelaborable packages with address clauses

2020-06-12 Thread Pierre-Marie de Rodat
This implements the AI under the -gnat2020 switch, which extends the
set of calls that can be made during the elaboration of library units
subject to the aspect/pragma Preelaborate, beyond the existing ones
to static functions.  Calls to certain functions that are essentially
unchecked conversions are now allowed.

This makes it possible to portably write address clauses of the form:

  for Var'Address use System.Storage_Elements.To_Address (...);

in preelaborated library units, provided that the actual parameter
passed to the To_Address function is itself preelaborable.

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

2020-06-12  Eric Botcazou  

gcc/ada/

* rtsfind.ads (RTU_Id): Add System_Address_To_Access_Conversions.
* sem_elab.adb (Elaboration_Phase_Active): Alphabetize.
(Finalize_All_Data_Structures): Likewise.
(Error_Preelaborated_Call): New procedure.
(Build_Call_Marker): Set Is_Preelaborable_Call flag in marker.
(Build_Access_Marker): Likewise.
(Build_Subprogram_Invocation): Likewise.
(Build_Task_Activation): Likewise.
(Check_Preelaborated_Call): Return when the call is preelaborable.
Call Error_Preelaborated_Call to give the error otherwise.
(Check_Elab_Call): Likewise.
* sem_util.adb (Is_Preelaborable_Function): New predicate.
(Is_Non_Preelaborable_Construct.Visit): Recurse on the
Explicit_Actual_Parameter field of N_Parameter_Association.
(Is_Non_Preelaborable_Construct.Visit_Subexpression): In Ada 2020,
for a call to a preelaborable function, visit the parameter list;
otherwise, raise Non_Preelaborable exception.
(Is_Preelaborable_Construct): Likewise, but recursively check the
parameters instead and return false upon failure, otherwise true.
* sinfo.ads (Is_Preelaborable_Call): New flag in call marker nodes.
(Is_Preelaborable_Call): New inline function.
(Set_Is_Preelaborable_Call): New inline procedure.
* sinfo.adb (Is_Preelaborable_Call): New inline function.
(Set_Is_Preelaborable_Call): New inline procedure.--- gcc/ada/rtsfind.ads
+++ gcc/ada/rtsfind.ads
@@ -173,6 +173,7 @@ package Rtsfind is
   --  Children of System
 
   System_Address_Image,
+  System_Address_To_Access_Conversions,
   System_Arith_64,
   System_AST_Handling,
   System_Assertions,

--- gcc/ada/sem_elab.adb
+++ gcc/ada/sem_elab.adb
@@ -1952,6 +1952,18 @@ package body Sem_Elab is
pragma Inline (Compilation_Unit);
--  Return the N_Compilation_Unit node of unit Unit_Id
 
+   function Elaboration_Phase_Active return Boolean;
+   pragma Inline (Elaboration_Phase_Active);
+   --  Determine whether the elaboration phase of the compilation has started
+
+   procedure Error_Preelaborated_Call (N : Node_Id);
+   --  Give an error or warning for a non-static/non-preelaborable call in a
+   --  preelaborated unit.
+
+   procedure Finalize_All_Data_Structures;
+   pragma Inline (Finalize_All_Data_Structures);
+   --  Destroy all internal data structures
+
function Find_Enclosing_Instance (N : Node_Id) return Node_Id;
pragma Inline (Find_Enclosing_Instance);
--  Find the declaration or body of the nearest expanded instance which
@@ -1972,14 +1984,6 @@ package body Sem_Elab is
--  Return the type of subprogram Subp_Id's first formal parameter. If the
--  subprogram lacks formal parameters, return Empty.
 
-   function Elaboration_Phase_Active return Boolean;
-   pragma Inline (Elaboration_Phase_Active);
-   --  Determine whether the elaboration phase of the compilation has started
-
-   procedure Finalize_All_Data_Structures;
-   pragma Inline (Finalize_All_Data_Structures);
-   --  Destroy all internal data structures
-
function Has_Body (Pack_Decl : Node_Id) return Boolean;
pragma Inline (Has_Body);
--  Determine whether package declaration Pack_Decl has a corresponding body
@@ -3745,6 +3749,15 @@ package body Sem_Elab is
   Set_Is_SPARK_Mode_On_Node (Marker, Is_SPARK_Mode_On_Node (N));
   Set_Target(Marker, Subp_Id);
 
+  --  Ada 2020 (AI12-0175): Calls to certain functions that are essentially
+  --  unchecked conversions are preelaborable.
+
+  if Ada_Version >= Ada_2020 then
+ Set_Is_Preelaborable_Call (Marker, Is_Preelaborable_Construct (N));
+  else
+ Set_Is_Preelaborable_Call (Marker, False);
+  end if;
+
   --  The marker is inserted prior to the original call. This placement has
   --  several desirable effects:
 
@@ -4878,6 +4891,8 @@ package body Sem_Elab is
(Marker, Elaboration_Checks_OK (Attr_Rep));
 Set_Is_Elaboration_Warnings_OK_Node
(Marker, Elaboration_Warnings_OK (Attr_Rep));
+Set_Is_Preelaborable_Call
+   (Marker, False);
 Set_Is_Source_Call
(Marker, Comes_From_Source 

[Ada] Compiler locks up with -gnatX and formal subprogram with aspects

2020-06-12 Thread Pierre-Marie de Rodat
This patch fixes  an infinite loop in the compiler on an instantiation
that includes formal packages and formal subprograms with aspect
specifications (but no pre- or postconditions), when compiling with
-gnatX.

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

2020-06-12  Ed Schonberg  

gcc/ada/

* sem_ch12.adb (Find_Matching_Actual): Add guard on search loops
to detect a compilation error when using a compiler built
without assertions.
(Instantiate_Formal_Subprogram): Create a new subprogram name
for the actual only if formal has contract aspects and expansion
is enabled.--- gcc/ada/sem_ch12.adb
+++ gcc/ada/sem_ch12.adb
@@ -10403,7 +10403,9 @@ package body Sem_Ch12 is
 =>
Formal_Ent := Defining_Identifier (F);
 
-   while Chars (Act) /= Chars (Formal_Ent) loop
+   while Present (Act)
+ and then Chars (Act) /= Chars (Formal_Ent)
+   loop
   Next_Entity (Act);
end loop;
 
@@ -10414,7 +10416,9 @@ package body Sem_Ch12 is
 =>
Formal_Ent := Defining_Entity (F);
 
-   while Chars (Act) /= Chars (Formal_Ent) loop
+   while Present (Act)
+ and then Chars (Act) /= Chars (Formal_Ent)
+   loop
   Next_Entity (Act);
end loop;
 
@@ -10934,13 +10938,16 @@ package body Sem_Ch12 is
   --  Create new entity for the actual (New_Copy_Tree does not), and
   --  indicate that it is an actual.
 
-  --  If the actual is not an entity and the formal includes aspect
-  --  specifications for contracts, we create an internal name for
-  --  the renaming declaration. The constructed wrapper contains a
-  --  call to the entity in the renaming.
+  --  If the actual is not an entity (i.e. an attribute reference)
+  --  and the formal includes aspect specifications for contracts,
+  --  we create an internal name for the renaming declaration. The
+  --  constructed wrapper contains a call to the entity in the renaming.
+  --  This is an expansion activity, as is the wrapper creation.
 
   if Ada_Version >= Ada_2020
-and then Present (Aspect_Specifications (Analyzed_Formal))
+and then Has_Contracts (Analyzed_Formal)
+and then not Is_Entity_Name (Actual)
+and then Expander_Active
   then
  New_Subp := Make_Temporary (Sloc (Actual), 'S');
  Set_Defining_Unit_Name (New_Spec, New_Subp);



[Ada] Reuse Is_Entry where possible

2020-06-12 Thread Pierre-Marie de Rodat
Replace a low-level membership test "Ekind_In (Id, E_Entry,
E_Entry_Family)" with a high-level "Is_Entry (Id)", which is more
readable. Semantics stays the same.

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

2020-06-12  Piotr Trojanek  

gcc/ada/

* contracts.adb, einfo.adb, sem_ch4.adb, sem_ch6.adb,
sem_res.adb, sem_util.adb: Replace Ekind_In with Is_Entry.--- gcc/ada/contracts.adb
+++ gcc/ada/contracts.adb
@@ -562,8 +562,7 @@ package body Contracts is
   --  Save the SPARK_Mode-related data to restore on exit
 
   Skip_Assert_Exprs : constant Boolean :=
-Ekind_In (Subp_Id, E_Entry, E_Entry_Family)
-  and then not GNATprove_Mode;
+Is_Entry (Subp_Id) and then not GNATprove_Mode;
 
   Depends  : Node_Id := Empty;
   Global   : Node_Id := Empty;

--- gcc/ada/einfo.adb
+++ gcc/ada/einfo.adb
@@ -1299,7 +1299,7 @@ package body Einfo is
 
function Contract_Wrapper (Id : E) return E is
begin
-  pragma Assert (Ekind_In (Id, E_Entry, E_Entry_Family));
+  pragma Assert (Is_Entry (Id));
   return Node25 (Id);
end Contract_Wrapper;
 
@@ -1709,8 +1709,7 @@ package body Einfo is
function Has_Out_Or_In_Out_Parameter (Id : E) return B is
begin
   pragma Assert
-(Ekind_In (Id, E_Entry, E_Entry_Family)
-  or else Is_Subprogram_Or_Generic_Subprogram (Id));
+(Is_Entry (Id) or else Is_Subprogram_Or_Generic_Subprogram (Id));
   return Flag110 (Id);
end Has_Out_Or_In_Out_Parameter;
 
@@ -4159,7 +4158,7 @@ package body Einfo is
 
procedure Set_Contract_Wrapper (Id : E; V : E) is
begin
-  pragma Assert (Ekind_In (Id, E_Entry, E_Entry_Family));
+  pragma Assert (Is_Entry (Id));
   Set_Node25 (Id, V);
end Set_Contract_Wrapper;
 

--- gcc/ada/sem_ch4.adb
+++ gcc/ada/sem_ch4.adb
@@ -4989,7 +4989,7 @@ package body Sem_Ch4 is
  then
 if Is_Task_Type (Prefix_Type)
   and then Present (Entity (Sel))
-  and then Ekind_In (Entity (Sel), E_Entry, E_Entry_Family)
+  and then Is_Entry (Entity (Sel))
 then
null;
 

--- gcc/ada/sem_ch6.adb
+++ gcc/ada/sem_ch6.adb
@@ -12259,7 +12259,7 @@ package body Sem_Ch6 is
   --  point of the call.
 
   if Out_Present (Spec) then
- if Ekind_In (Id, E_Entry, E_Entry_Family)
+ if Is_Entry (Id)
or else Is_Subprogram_Or_Generic_Subprogram (Id)
  then
 Set_Has_Out_Or_In_Out_Parameter (Id, True);

--- gcc/ada/sem_res.adb
+++ gcc/ada/sem_res.adb
@@ -6098,8 +6098,7 @@ package body Sem_Res is
   --  can be an arbitrary expression with special resolution rules.
 
   elsif Nkind_In (Subp, N_Selected_Component, N_Indexed_Component)
-or else (Is_Entity_Name (Subp)
-  and then Ekind_In (Entity (Subp), E_Entry, E_Entry_Family))
+or else (Is_Entity_Name (Subp) and then Is_Entry (Entity (Subp)))
   then
  Resolve_Entry_Call (N, Typ);
 
@@ -7937,7 +7936,7 @@ package body Sem_Res is
  end;
   end if;
 
-  if Ekind_In (Nam, E_Entry, E_Entry_Family)
+  if Is_Entry (Nam)
 and then Present (Contract_Wrapper (Nam))
 and then Current_Scope /= Contract_Wrapper (Nam)
   then
@@ -8008,7 +8007,7 @@ package body Sem_Res is
 
   Generate_Reference (Nam, Entry_Name, 's');
 
-  if Ekind_In (Nam, E_Entry, E_Entry_Family) then
+  if Is_Entry (Nam) then
  Check_Potentially_Blocking_Operation (N);
   end if;
 

--- gcc/ada/sem_util.adb
+++ gcc/ada/sem_util.adb
@@ -9139,7 +9139,7 @@ package body Sem_Util is
  if Msg_Index <= Msg_Last - 10
and then Msg (Msg_Index .. Msg_Index + 9) = "subprogram"
  then
-if Ekind_In (Id, E_Entry, E_Entry_Family) then
+if Is_Entry (Id) then
Res (Res_Index .. Res_Index + 4) := "entry";
Res_Index := Res_Index + 5;
 
@@ -15417,7 +15417,7 @@ package body Sem_Util is
function Is_Entry_Body (Id : Entity_Id) return Boolean is
begin
   return
-Ekind_In (Id, E_Entry, E_Entry_Family)
+Is_Entry (Id)
   and then Nkind (Unit_Declaration_Node (Id)) = N_Entry_Body;
end Is_Entry_Body;
 
@@ -15428,7 +15428,7 @@ package body Sem_Util is
function Is_Entry_Declaration (Id : Entity_Id) return Boolean is
begin
   return
-Ekind_In (Id, E_Entry, E_Entry_Family)
+Is_Entry (Id)
   and then Nkind (Unit_Declaration_Node (Id)) = N_Entry_Declaration;
end Is_Entry_Declaration;
 



[Ada] Detect overlapping actuals in entry calls

2020-06-12 Thread Pierre-Marie de Rodat
For subprograms we call Warn_On_Overlapping_Actuals in Resolve_Call;
however, for protected entries we didn't call it at all, because
Resolve_Call was executing Resolve_Entry_Call and returning early. As a
result, we didn't detect overlapping actuals in entry calls. Now we do.

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

2020-06-12  Piotr Trojanek  

gcc/ada/

* sem_res.adb (Resolve_Entry_Call): Add call to
Warn_On_Overlapping_Actuals.--- gcc/ada/sem_res.adb
+++ gcc/ada/sem_res.adb
@@ -8090,6 +8090,13 @@ package body Sem_Res is
   then
  Establish_Transient_Scope (N, Manage_Sec_Stack => True);
   end if;
+
+  --  Now we know that this is not a call to a function that returns an
+  --  array type; moreover, we know the name of the called entry. Detect
+  --  overlapping actuals, just like for a subprogram call.
+
+  Warn_On_Overlapping_Actuals (Nam, N);
+
end Resolve_Entry_Call;
 
-



[Ada] Compiler crash on instance with overloaded actual and aspects

2020-06-12 Thread Pierre-Marie de Rodat
This patch fixes a crash in the compiler when handling an instantiation
with a formal subprogram that carries an aspect specification, when the
actual in the instantiation is an overloaded name.

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

2020-06-12  Ed Schonberg  

gcc/ada/

* sem_ch12.adb (Has_Contracts): New predicate to check whether a
formal subprogram carries an aspect specification for a pre- or
postcondition.
(Build_Subprogram_Wrappers): If actual is overloaded, create a
new name to be used in call inside wrapper body. This names
carries the interpretations of the actual, and is resolved when
the body is analyzed.
(Build_Subprogram_Body_Wrapper): Use this generated name in
call.
(Build_Subprogram_Decl_Wrapper): Build profile of wrapper from
the profile of formal, and reset type entities for subsequent
analysis.--- gcc/ada/sem_ch12.adb
+++ gcc/ada/sem_ch12.adb
@@ -496,8 +496,7 @@ package body Sem_Ch12 is
--  On return, the node N has been rewritten with the actual body.
 
function Build_Subprogram_Decl_Wrapper
- (Formal_Subp : Entity_Id;
-  Actual_Subp : Entity_Id) return Node_Id;
+ (Formal_Subp : Entity_Id) return Node_Id;
--  Ada 2020 allows formal subprograms to carry pre/postconditions.
--  At the point of instantiation these contracts apply to uses of
--  the actual subprogram. This is implemented by creating wrapper
@@ -508,7 +507,7 @@ package body Sem_Ch12 is
 
function Build_Subprogram_Body_Wrapper
  (Formal_Subp : Entity_Id;
-  Actual_Subp : Entity_Id) return Node_Id;
+  Actual_Name : Node_Id) return Node_Id;
--  The body of the wrapper is a call to the actual, with the generated
--  pre/postconditon checks added.
 
@@ -668,6 +667,10 @@ package body Sem_Ch12 is
--  Traverse the Exchanged_Views list to see if a type was private
--  and has already been flipped during this phase of instantiation.
 
+   function Has_Contracts (Decl : Node_Id) return Boolean;
+   --  Determine whether a formal subprogram has a Pre- or Postcondition,
+   --  in which case a subprogram wrapper has to be built for the actual.
+
procedure Hide_Current_Scope;
--  When instantiating a generic child unit, the parent context must be
--  present, but the instance and all entities that may be generated
@@ -1165,18 +1168,38 @@ package body Sem_Ch12 is
Defining_Unit_Name (Specification (Analyzed_Formal));
  Aspect_Spec : Node_Id;
  Decl_Node   : Node_Id;
- Ent : Entity_Id;
+ Actual_Name : Node_Id;
 
   begin
  --  Create declaration for wrapper subprogram
+ --  The actual can be overloaded, in which case it will be
+ --  resolved when the call in the wrapper body is analyzed.
+ --  We attach the possible interpretations of the actual to
+ --  the name to be used in the call in the wrapper body.
 
  if Is_Entity_Name (Match) then
-Ent := Entity (Match);
+Actual_Name := New_Occurrence_Of (Entity (Match), Sloc (Match));
+
+if Is_Overloaded (Match) then
+   Save_Interps (Match, Actual_Name);
+end if;
+
  else
-Ent := Defining_Entity (Last (Assoc_List));
+--  Use renaming declaration created when analyzing actual.
+--  This may be incomplete if there are several formal
+--  subprograms whose actual is an attribute ???
+
+declare
+   Renaming_Decl : constant Node_Id := Last (Assoc_List);
+
+begin
+   Actual_Name := New_Occurrence_Of
+ (Defining_Entity (Renaming_Decl), Sloc (Match));
+   Set_Etype (Actual_Name, Get_Instance_Of (Etype (Formal)));
+end;
  end if;
 
- Decl_Node := Build_Subprogram_Decl_Wrapper (Formal, Ent);
+ Decl_Node := Build_Subprogram_Decl_Wrapper (Formal);
 
  --  Transfer aspect specifications from formal subprogram to wrapper
 
@@ -1196,7 +1219,8 @@ package body Sem_Ch12 is
  --  The subprogram may be called in the analysis of subsequent
  --  actuals.
 
- Append_To (Assoc_List, Build_Subprogram_Body_Wrapper (Formal, Ent));
+ Append_To (Assoc_List,
+Build_Subprogram_Body_Wrapper (Formal, Actual_Name));
   end Build_Subprogram_Wrappers;
 
   
@@ -1865,7 +1889,7 @@ package body Sem_Ch12 is
  --  for it. This is an expansion activity that cannot
  --  take place e.g. within an enclosing generic unit.
 
- if Present (Aspect_Specifications (Analyzed_Formal))
+ if Has_Contracts (Analyzed_Formal)
and then Expander_Active
  then
 Build_Subprogram_Wrappers;
@@ 

[Ada] Simplify getting discriminant value from a list of constraints

2020-06-12 Thread Pierre-Marie de Rodat
Routine Get_Discr_Value takes a name of a discriminant, not its entity,
so its parameter should be a Node_Id, not an Entity_Id. Also, fix typo
in its comment and refactor repeated calls in the body. Semantics is
unaffected.

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

2020-06-12  Piotr Trojanek  

gcc/ada/

* sem_ch3.adb (Get_Discr_Value): Cleanup.--- gcc/ada/sem_ch3.adb
+++ gcc/ada/sem_ch3.adb
@@ -13112,8 +13112,8 @@ package body Sem_Ch3 is
   function Is_Discriminant (Expr : Node_Id) return Boolean;
   --  Returns True if Expr is a discriminant
 
-  function Get_Discr_Value (Discrim : Entity_Id) return Node_Id;
-  --  Find the value of discriminant Discrim in Constraint
+  function Get_Discr_Value (Discr_Expr : Node_Id) return Node_Id;
+  --  Find the value of a discriminant named by Discr_Expr in Constraints
 
   ---
   -- Build_Constrained_Access_Type --
@@ -13335,7 +13335,11 @@ package body Sem_Ch3 is
   -- Get_Discr_Value --
   -
 
-  function Get_Discr_Value (Discrim : Entity_Id) return Node_Id is
+  function Get_Discr_Value (Discr_Expr : Node_Id) return Node_Id is
+ Discr_Id : constant Entity_Id := Entity (Discr_Expr);
+ --  Entity of a discriminant that appear as a standalone expression in
+ --  the constraint of a component.
+
  D : Entity_Id;
  E : Elmt_Id;
 
@@ -13351,9 +13355,9 @@ package body Sem_Ch3 is
  E := First_Elmt (Constraints);
 
  while Present (D) loop
-if D = Entity (Discrim)
-  or else D = CR_Discriminant (Entity (Discrim))
-  or else Corresponding_Discriminant (D) = Entity (Discrim)
+if D = Discr_Id
+  or else D = CR_Discriminant (Discr_Id)
+  or else Corresponding_Discriminant (D) = Discr_Id
 then
return Node (E);
 end if;
@@ -13373,12 +13377,12 @@ package body Sem_Ch3 is
  --  be present when the component is a discriminated task type?
 
  if Is_Derived_Type (Typ)
-   and then Scope (Entity (Discrim)) = Etype (Typ)
+   and then Scope (Discr_Id) = Etype (Typ)
  then
 D := First_Discriminant (Etype (Typ));
 E := First_Elmt (Constraints);
 while Present (D) loop
-   if D = Entity (Discrim) then
+   if D = Discr_Id then
   return Node (E);
end if;
 



[Ada] Remove suppression for overlapping actuals in internal units

2020-06-12 Thread Pierre-Marie de Rodat
Detection of overlapping actuals was suppressed for internal units,
because we were getting spurious warnings on container units. Now this
suppression has no effect (most likely because ignore parameters of
generic types).

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

2020-06-12  Piotr Trojanek  

gcc/ada/

* sem_warn.adb (Warn_On_Overlapping_Actuals): Remove suppression
for internal units.--- gcc/ada/sem_warn.adb
+++ gcc/ada/sem_warn.adb
@@ -3727,19 +3727,13 @@ package body Sem_Warn is
   --  overlapping parameters that are record types or array types.
 
   --  It is also worthwhile to warn on overlaps of composite objects when
-  --  only one of the formals is (in)-out.  Note that the RM rule above is
+  --  only one of the formals is (in)-out. Note that the RM rule above is
   --  a legality rule. We choose to implement this check as a warning to
-  --  avoid major incompatibilities with legacy code. We exclude internal
-  --  sources from the warning, because subprograms in Container libraries
-  --  would be affected by the warning.
+  --  avoid major incompatibilities with legacy code.
 
   --  Note also that the rule in 6.4.1 (6.17/3), introduced by AI12-0324,
   --  is potentially more expensive to verify, and is not yet implemented.
 
-  if Is_Internal_Unit (Current_Sem_Unit) then
- return;
-  end if;
-
   Form1 := First_Formal (Subp);
   Act1  := First_Actual (N);
   while Present (Form1) and then Present (Act1) loop



[Ada] Diagnose illegal overriding indicators in protected bodies

2020-06-12 Thread Pierre-Marie de Rodat
This patch adds checks to reject illegal overriding indicators that
appear on subprogram declarations in protected bodies, where such
a subprogram cannot override any operation. Fixes ACATS test B831006.

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

2020-06-12  Ed Schonberg  

gcc/ada/

* sem_ch6.adb (Check_Overriding_Indicatior): Reject an
overriding indicator on a subprogram declared within a protected
body.--- gcc/ada/sem_ch6.adb
+++ gcc/ada/sem_ch6.adb
@@ -6515,6 +6515,19 @@ package body Sem_Ch6 is
  return;
   end if;
 
+  --  An overriding indication is illegal on a subprogram declared
+  --  in a protected body, where there is no operation to override.
+
+  if (Must_Override (Spec) or else Must_Not_Override (Spec))
+and then Is_List_Member (Decl)
+and then Present (Parent (List_Containing (Decl)))
+and then Nkind (Parent (List_Containing (Decl))) = N_Protected_Body
+  then
+ Error_Msg_N
+   ("illegal overriding indication in protected body", Decl);
+ return;
+  end if;
+
   --  The overriding operation is type conformant with the overridden one,
   --  but the names of the formals are not required to match. If the names
   --  appear permuted in the overriding operation, this is a possible



[Ada] ACATS 4.2Q - BDD2007

2020-06-12 Thread Pierre-Marie de Rodat
This acats test shows that we are not checking 13.1(9.2/5) for
representation aspects, now fixed.

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

2020-06-12  Arnaud Charlet  

gcc/ada/

* aspects.ads (Is_Representation_Aspect): New array.
* sem_ch13.adb (Analyze_Aspect_Specifications): Check
13.1(9.2/5) for representation aspects.

gcc/testsuite/

* gnat.dg/rep_clause8.adb: Update error location.--- gcc/ada/aspects.ads
+++ gcc/ada/aspects.ads
@@ -425,6 +425,134 @@ package Aspects is
   Boolean_Aspects   => Optional_Expression,
   Library_Unit_Aspects  => Optional_Expression);
 
+   --  The following array indicates what aspects are representation aspects
+
+   Is_Representation_Aspect : constant array (Aspect_Id) of Boolean :=
+ (No_Aspect   => False,
+  Aspect_Abstract_State   => False,
+  Aspect_Address  => True,
+  Aspect_Alignment=> True,
+  Aspect_Annotate => False,
+  Aspect_Async_Readers=> False,
+  Aspect_Async_Writers=> False,
+  Aspect_Attach_Handler   => False,
+  Aspect_Bit_Order=> True,
+  Aspect_Component_Size   => True,
+  Aspect_Constant_After_Elaboration   => False,
+  Aspect_Constant_Indexing=> False,
+  Aspect_Contract_Cases   => False,
+  Aspect_Convention   => True,
+  Aspect_CPU  => False,
+  Aspect_Default_Component_Value  => False,
+  Aspect_Default_Initial_Condition=> False,
+  Aspect_Default_Iterator => False,
+  Aspect_Default_Storage_Pool => True,
+  Aspect_Default_Value=> False,
+  Aspect_Depends  => False,
+  Aspect_Dimension=> False,
+  Aspect_Dimension_System => False,
+  Aspect_Dispatching_Domain   => False,
+  Aspect_Dynamic_Predicate=> False,
+  Aspect_Effective_Reads  => False,
+  Aspect_Effective_Writes => False,
+  Aspect_Extensions_Visible   => False,
+  Aspect_External_Name=> False,
+  Aspect_External_Tag => False,
+  Aspect_Ghost=> False,
+  Aspect_Global   => False,
+  Aspect_Implicit_Dereference => False,
+  Aspect_Initial_Condition=> False,
+  Aspect_Initializes  => False,
+  Aspect_Input=> False,
+  Aspect_Interrupt_Priority   => False,
+  Aspect_Invariant=> False,
+  Aspect_Iterable => False,
+  Aspect_Iterator_Element => False,
+  Aspect_Link_Name=> True,
+  Aspect_Linker_Section   => True,
+  Aspect_Machine_Radix=> True,
+  Aspect_Max_Entry_Queue_Depth=> False,
+  Aspect_Max_Entry_Queue_Length   => False,
+  Aspect_Max_Queue_Length => False,
+  Aspect_No_Caching   => False,
+  Aspect_Object_Size  => True,
+  Aspect_Obsolescent  => False,
+  Aspect_Output   => False,
+  Aspect_Part_Of  => False,
+  Aspect_Post => False,
+  Aspect_Postcondition=> False,
+  Aspect_Pre  => False,
+  Aspect_Precondition => False,
+  Aspect_Predicate=> False,
+  Aspect_Predicate_Failure=> False,
+  Aspect_Priority => False,
+  Aspect_Put_Image=> False,
+  Aspect_Read => False,
+  Aspect_Refined_Depends  => False,
+  Aspect_Refined_Global   => False,
+  Aspect_Refined_Post => False,
+  Aspect_Refined_State=> False,
+  Aspect_Relative_Deadline=> False,
+  Aspect_Scalar_Storage_Order => True,
+  Aspect_Secondary_Stack_Size => True,
+  Aspect_Simple_Storage_Pool  => True,
+  Aspect_Size => True,
+  Aspect_Small=> True,
+  Aspect_SPARK_Mode   => False,
+  Aspect_Static_Predicate => False,
+  Aspect_Storage_Pool => True,
+  Aspect_Storage_Size => True,
+  Aspect_Stream_Size  => True,
+  Aspect_Suppress => False,
+  Aspect_Synchronization  => False,
+  Aspect_Test_Case=> False,
+  Aspect_Type_Invariant   => False,
+  

[Ada] Small cleanup in handling of Ada 2012 implicit dereferences

2020-06-12 Thread Pierre-Marie de Rodat
This aligns the handling of Ada 2012 implicit dereferences in the
Is_OK_Variable_For_Out_Formal predicate wih that in Is_Variable,
and removes unreachable code as a result.

This also makes more use of the Get_Reference_Discriminant helper
function to retrieve the reference discriminant of a type.

No functional changes.

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

2020-06-12  Eric Botcazou  

gcc/ada/

* sem_ch4.adb (Try_Container_Indexing): Replace call to
First_Discriminant by Get_Reference_Discriminant to get the
reference discriminant.
* sem_ch13.adb (Check_Indexing_Functions): Likewise.
* sem_ch5.adb (Preanalyze_Range): Call Get_Reference_Discriminant
to get the reference discriminant.
* sem_util.adb (Is_OK_Variable_For_Out_Formal): Treat all
Ada 2012 implicit dereferences in only one place.
(Is_Variable): Minor tweak.--- gcc/ada/sem_ch13.adb
+++ gcc/ada/sem_ch13.adb
@@ -4759,9 +4759,10 @@ package body Sem_Ch13 is
end if;
 
 else
-   if  Has_Implicit_Dereference (Ret_Type)
+   if Has_Implicit_Dereference (Ret_Type)
  and then not
-   Is_Access_Constant (Etype (First_Discriminant (Ret_Type)))
+   Is_Access_Constant
+ (Etype (Get_Reference_Discriminant (Ret_Type)))
then
   Illegal_Indexing
 ("constant indexing must return an access to constant");

--- gcc/ada/sem_ch4.adb
+++ gcc/ada/sem_ch4.adb
@@ -8097,7 +8097,8 @@ package body Sem_Ch4 is
  --  as such and retry.
 
  if Has_Implicit_Dereference (Pref_Typ) then
-Build_Explicit_Dereference (Prefix, First_Discriminant (Pref_Typ));
+Build_Explicit_Dereference
+  (Prefix, Get_Reference_Discriminant (Pref_Typ));
 return Try_Container_Indexing (N, Prefix, Exprs);
 
  --  Otherwise this is definitely not container indexing

--- gcc/ada/sem_ch5.adb
+++ gcc/ada/sem_ch5.adb
@@ -4375,21 +4375,8 @@ package body Sem_Ch5 is
  --  visible in the loop.
 
  elsif Has_Implicit_Dereference (Etype (R_Copy)) then
-declare
-   Disc : Entity_Id;
-
-begin
-   Disc := First_Discriminant (Typ);
-   while Present (Disc) loop
-  if Has_Implicit_Dereference (Disc) then
- Build_Explicit_Dereference (R_Copy, Disc);
- exit;
-  end if;
-
-  Next_Discriminant (Disc);
-   end loop;
-end;
-
+Build_Explicit_Dereference
+  (R_Copy, Get_Reference_Discriminant (Etype (R_Copy)));
  end if;
   end if;
 

--- gcc/ada/sem_util.adb
+++ gcc/ada/sem_util.adb
@@ -16915,10 +16915,9 @@ package body Sem_Util is
   --  check whether the context requires an access_to_variable type.
 
   elsif Nkind (AV) = N_Explicit_Dereference
-and then Ada_Version >= Ada_2012
-and then Nkind (Original_Node (AV)) = N_Indexed_Component
 and then Present (Etype (Original_Node (AV)))
 and then Has_Implicit_Dereference (Etype (Original_Node (AV)))
+and then Ada_Version >= Ada_2012
   then
  return not Is_Access_Constant (Etype (Prefix (AV)));
 
@@ -16976,28 +16975,7 @@ package body Sem_Util is
   --  but we still want to allow the conversion if it converts a variable).
 
   elsif Is_Rewrite_Substitution (AV) then
-
- --  In Ada 2012, the explicit dereference may be a rewritten call to a
- --  Reference function.
-
- if Ada_Version >= Ada_2012
-   and then Nkind (Original_Node (AV)) = N_Function_Call
-   and then
- Has_Implicit_Dereference (Etype (Name (Original_Node (AV
- then
-
---  Check that this is not a constant reference.
-
-return not Is_Access_Constant (Etype (Prefix (AV)));
-
- elsif Has_Implicit_Dereference (Etype (Original_Node (AV))) then
-return
-  not Is_Access_Constant (Etype
-(Get_Reference_Discriminant (Etype (Original_Node (AV);
-
- else
-return Is_OK_Variable_For_Out_Formal (Original_Node (AV));
- end if;
+ return Is_OK_Variable_For_Out_Formal (Original_Node (AV));
 
   --  All other non-variables are rejected
 
@@ -18792,14 +18770,14 @@ package body Sem_Util is
or else
  Is_Variable_Prefix (Original_Node (Prefix (N)));
 
-  --  in Ada 2012, the dereference may have been added for a type with
-  --  a declared implicit dereference aspect. Check that it is not an
-  --  access to constant.
+  --  Generalized indexing operations are rewritten as explicit
+  --  dereferences, and it is only during resolution that we can
+  --  check whether the context requires an 

[Ada] Put_Image attribute

2020-06-12 Thread Pierre-Marie de Rodat
Enable Put_Image for types that don't cause regressions (which is most
types).

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

2020-06-12  Bob Duff  

gcc/ada/

* debug.adb: Remove usage of -gnatd_z.
* exp_attr.adb, exp_put_image.ads, exp_put_image.adb: Clean up
the enable/disable code. If Put_Image is disabled for a type,
systematically call the "unknown" version.  Improve comments.
Consolidate workarounds.  Remove usage of -gnatd_z.--- gcc/ada/debug.adb
+++ gcc/ada/debug.adb
@@ -170,7 +170,7 @@ package body Debug is
--  d_w
--  d_x
--  d_y
-   --  d_z  Enable Put_Image
+   --  d_z
 
--  d_A  Stop generation of ALI file
--  d_B
@@ -993,9 +993,6 @@ package body Debug is
--   a call to routine Ada.Synchronous_Task_Control.Suspend_Until_True
--   or Ada.Synchronous_Barriers.Wait_For_Release.
 
-   --  d_z  The Put_Image attribute is a work in progress, and is disabled by
-   --   default. This enables it.
-
--  d_A  Do not generate ALI files by setting Opt.Disable_ALI_File.
 
--  d_F  The compiler encodes the full path from an invocation construct to

--- gcc/ada/exp_attr.adb
+++ gcc/ada/exp_attr.adb
@@ -5463,7 +5463,9 @@ package body Exp_Attr is
 return;
  end if;
 
- --  If there is a TSS for Put_Image, just call it
+ --  If there is a TSS for Put_Image, just call it. This is true for
+ --  tagged types (if enabled) and if there is a user-specified
+ --  Put_Image.
 
  Pname := TSS (U_Type, TSS_Put_Image);
  if No (Pname) then
@@ -5478,10 +5480,17 @@ package body Exp_Attr is
  end if;
 
  if No (Pname) then
+--  If Put_Image is disabled, call the "unknown" version
+
+if not Enable_Put_Image (U_Type) then
+   Rewrite (N, Build_Unknown_Put_Image_Call (N));
+   Analyze (N);
+   return;
+
 --  For elementary types, we call the routine in System.Put_Images
 --  directly.
 
-if Is_Elementary_Type (U_Type) then
+elsif Is_Elementary_Type (U_Type) then
Rewrite (N, Build_Elementary_Put_Image_Call (N));
Analyze (N);
return;
@@ -5535,7 +5544,7 @@ package body Exp_Attr is
Analyze (N);
return;
 
---  All other record type cases, including protected records
+--  All other record type cases
 
 else
pragma Assert (Is_Record_Type (U_Type));

--- gcc/ada/exp_put_image.adb
+++ gcc/ada/exp_put_image.adb
@@ -24,7 +24,6 @@
 --
 
 with Atree;use Atree;
-with Debug;use Debug;
 with Einfo;use Einfo;
 with Exp_Tss;  use Exp_Tss;
 with Exp_Util;
@@ -341,9 +340,6 @@ package body Exp_Put_Image is
  --
  --  Note that this is putting a leading space for reals.
 
- --  ???Work around the fact that Put_Image doesn't work for private
- --  types whose full type is real.
-
  if Is_Real_Type (U_Type) then
 return Build_Unknown_Put_Image_Call (N);
  end if;
@@ -620,9 +616,7 @@ package body Exp_Put_Image is
   procedure Append_Component_Attr (Clist : List_Id; C : Entity_Id) is
  Component_Typ : constant Entity_Id := Put_Image_Base_Type (Etype (C));
   begin
- if Ekind (C) /= E_Void
-   and then Enable_Put_Image (Component_Typ)
- then
+ if Ekind (C) /= E_Void then
 Append_To (Clist,
   Make_Attribute_Reference (Loc,
 Prefix => New_Occurrence_Of (Component_Typ, Loc),
@@ -819,12 +813,8 @@ package body Exp_Put_Image is
-- Enable_Put_Image --
--
 
-   function Enable_Put_Image (T : Entity_Id) return Boolean is
+   function Enable_Put_Image (Typ : Entity_Id) return Boolean is
begin
-  if not Debug_Flag_Underscore_Z then -- True to disable for all types
- return False;
-  end if;
-
   --  There's a bit of a chicken problem. The compiler is likely to
   --  have trouble if we refer to the Put_Image of Sink itself, because
   --  Sink is part of the parameter profile:
@@ -840,12 +830,20 @@ package body Exp_Put_Image is
   --  scalar types are expanded inline. We certainly want to be able to use
   --  Integer'Put_Image, for example.
 
-  --  ???Work around a bug: Put_Image does not work for Remote_Types.
-  --  We check the containing package, rather than the type itself, because
-  --  we want to include types in the private part of a Remote_Types
-  --  package.
+  --  ???Temporarily disable to work around bugs:
+  --
+  --  Put_Image does not work for Remote_Types. We check the containing
+  --  package, rather than the type itself, because we want to include
+  --  types in the private part of 

Re: [PATCH] wwwdocs: Document devel/omp/gcc-10 branch

2020-06-12 Thread Thomas Schwinge
Hi Kwok!

On 2020-06-10T17:23:58+0100, Kwok Cheung Yeung  wrote:
> On 10/06/2020 4:15 pm, Tobias Burnus wrote:
>> On 6/10/20 3:34 PM, Kwok Cheung Yeung wrote:
>>> This patch updates the previous entry on the website for devel/omp/gcc-9 to
>>> refer to the new branch instead. This removes references to the old branch, 
>>> as
>>> new development should occur on the newer branch.
>>
>> Can you move the old entry to "Inactive Development Branches" instead?
>
> The inactive development branches are sorted alphabetically except for the
> openacc-gcc-*-branch entries, which are grouped with the gomp*-branch entries.
> Would it be better to place devel/omp/gcc-9 alphabetically (in which case it
> will go between debuglocus and dwarf4)

For obvious reasons, very most of all items on this list of inactive
development branches pre-date the Git conversion, which is when we added
the convention that shared development branches go into the 'devel/'
namespace.  So the current list does not reflect that current practice,
so given old practice, the 'devel/omp/gcc-9' etc. branches wouldn't sort
into 'd' but into 'o'.

> or by topic (in which case it should
> probably go after openacc-gcc-9-branch)?

By topic makes most sense to me.  And, 'devel/omp/gcc-9' definitively
should group right next to 'openacc-gcc-9-branch', as it began as a
direct translation of the latter.

For historical reasons, I have a (at least slight) preference to keep all
these branches right after the 'gomp-4_0-branch' -- where it all began.
This is a history chapter, after all.

And anyway, changing any of that would be a separate thing from simply
documenting the new 'devel/omp/gcc-10' branch, and retiring the
'devel/omp/gcc-9' branch.


Grüße
 Thomas
-
Mentor Graphics (Deutschland) GmbH, Arnulfstraße 201, 80634 München / Germany
Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Alexander 
Walter


[Ada] Implement AI12-0269 No_Return for functions

2020-06-12 Thread Pierre-Marie de Rodat
This implements the AI under the -gnat2020 switch, which extends the
Ada 2005 No_Return aspect/pragma to functions and generic functions.
As explained in the AI, functions subject to this aspect/pragma must
still have a return statement, but it must be of a specific form.

This also fixes the implementation of AI95-0414, whereby a procedure
overriding a No_Return dispatching procedure must also be No_Return,
but which has effectively led to the impossibility of overriding any
No_Return dispatching procedure.

This finally makes error messages about No_Return subprograms more
consistent in the semantic analyzer.

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

2020-06-12  Eric Botcazou  

gcc/ada/

* einfo.ads (No_Return): Document it for all subprograms.
* einfo.adb (Set_No_Return): Adjust assertion accordingly.
* sem_ch3.adb (Check_Abstract_Overriding): Implement the
check prescribed by RM 6.5.1(6/2) here instead of...
(Derive_Subprogram): Adjust comment accordingly.
* sem_disp.adb (Override_Dispatching_Operation): ...here.
Remove superfluous return statement.
* sem_ch6.adb (Check_No_Return_Expression): New procedure.
(Analyze_Function_Return): Call it to implement the check
prescribed by AI12-0269 for simple return statements of
No_Return functions, and also checks extended statements.
(Analyze_Return_Statement): Only give an error on a return
statement in No_Return procedures.  Use idiomatic form.
* sem_ch8.adb (Analyze_Subprogram_Renaming): Adjust error
message for No_Return renaming subprogram.
* sem_prag.adb (Analyze_Pragma) : Accept
it on functions and generic functions in Ada 2020.--- gcc/ada/einfo.adb
+++ gcc/ada/einfo.adb
@@ -6180,8 +6180,7 @@ package body Einfo is
 
procedure Set_No_Return (Id : E; V : B := True) is
begin
-  pragma Assert
-(V = False or else Ekind_In (Id, E_Procedure, E_Generic_Procedure));
+  pragma Assert (Is_Subprogram (Id) or else Is_Generic_Subprogram (Id));
   Set_Flag113 (Id, V);
end Set_No_Return;
 

--- gcc/ada/einfo.ads
+++ gcc/ada/einfo.ads
@@ -3720,8 +3720,8 @@ package Einfo is
 --   pragma No_Component_Reordering applies.
 
 --No_Return (Flag113)
---   Defined in all entities. Always false except in the case of procedures
---   and generic procedures for which a pragma No_Return is given.
+--   Defined in all entities. Set for subprograms and generic subprograms
+--   to which a valid aspect or pragma No_Return applies.
 
 --No_Strict_Aliasing (Flag136) [base type only]
 --   Defined in access types. Set to direct the backend to avoid any

--- gcc/ada/sem_ch3.adb
+++ gcc/ada/sem_ch3.adb
@@ -10868,6 +10868,20 @@ package body Sem_Ch3 is
 end if;
  end if;
 
+ --  Ada 2005 (AI95-0414) and Ada 2020 (AI12-0269): Diagnose failure to
+ --  match No_Return in parent, but do it unconditionally in Ada 95 too
+ --  for procedures, since this is our pragma.
+
+ if Present (Overridden_Operation (Subp))
+   and then No_Return (Overridden_Operation (Subp))
+   and then not No_Return (Subp)
+ then
+Error_Msg_N ("overriding subprogram & must be No_Return", Subp);
+Error_Msg_N
+  ("\since overridden subprogram is No_Return (RM 6.5.1(6/2))",
+   Subp);
+ end if;
+
  --  If the operation is a wrapper for a synchronized primitive, it
  --  may be called indirectly through a dispatching select. We assume
  --  that it will be referenced elsewhere indirectly, and suppress
@@ -15450,9 +15464,9 @@ package body Sem_Ch3 is
   end if;
 
   --  No_Return must be inherited properly. If this is overridden in the
-  --  case of a dispatching operation, then a check is made in Sem_Disp
-  --  that the overriding operation is also No_Return (no such check is
-  --  required for the case of non-dispatching operation.
+  --  case of a dispatching operation, then the check is made later in
+  --  Check_Abstract_Overriding that the overriding operation is also
+  --  No_Return (no such check is required for the nondispatching case).
 
   Set_No_Return (New_Subp, No_Return (Parent_Subp));
 

--- gcc/ada/sem_ch6.adb
+++ gcc/ada/sem_ch6.adb
@@ -676,6 +676,10 @@ package body Sem_Ch6 is
   R_Type : constant Entity_Id := Etype (Scope_Id);
   --  Function result subtype
 
+  procedure Check_No_Return_Expression (Return_Expr : Node_Id);
+  --  Ada 2020: Check that the return expression in a No_Return function
+  --  meets the conditions specified by RM 6.5.1(5.1/5).
+
   procedure Check_Return_Construct_Accessibility (Return_Stmt : Node_Id);
   --  Apply legality rule of 6.5 (5.9) to the access discriminants of an
   --  aggregate in a return statement.
@@ -684,6 +688,34 @@ package body 

[Ada] Ada2020: update Big_Numbers.* specs

2020-06-12 Thread Pierre-Marie de Rodat
This patch updates the Put_Image facilities in the Big_Numbers packages
to match the actual implementation of Put_Image.

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

2020-06-12  Bob Duff  

gcc/ada/

* libgnat/a-nbnbin.adb, libgnat/a-nbnbin.ads,
libgnat/a-nbnbin__gmp.adb, libgnat/a-nbnbre.adb,
libgnat/a-nbnbre.ads: Update Put_Image, and uncomment the aspect
specification.  Add pragmas Ada_2020.
* libgnat/a-stouut.ads, libgnat/a-stteou.ads: Add Preelaborate,
because the Big_Numbers packages have Preelaborate, and now
depend on these Text_Output packages.--- gcc/ada/libgnat/a-nbnbin.adb
+++ gcc/ada/libgnat/a-nbnbin.adb
@@ -29,8 +29,10 @@
 --  --
 --
 
+pragma Ada_2020;
+
 with Ada.Unchecked_Deallocation;
-with Ada.Characters.Conversions; use Ada.Characters.Conversions;
+with Ada.Strings.Text_Output.Utils;
 
 with Interfaces; use Interfaces;
 
@@ -290,11 +292,12 @@ package body Ada.Numerics.Big_Numbers.Big_Integers is
-- Put_Image --
---
 
-   procedure Put_Image
- (Stream : not null access Ada.Streams.Root_Stream_Type'Class;
-  Arg: Big_Integer) is
+   procedure Put_Image (S : in out Sink'Class; V : Big_Integer) is
+  --  This is implemented in terms of To_String. It might be more elegant
+  --  and more efficient to do it the other way around, but this is the
+  --  most expedient implementation for now.
begin
-  Wide_Wide_String'Write (Stream, To_Wide_Wide_String (To_String (Arg)));
+  Strings.Text_Output.Utils.Put_UTF_8 (S, To_String (V));
end Put_Image;
 
-

--- gcc/ada/libgnat/a-nbnbin.ads
+++ gcc/ada/libgnat/a-nbnbin.ads
@@ -13,7 +13,9 @@
 --  --
 --
 
-with Ada.Streams;
+pragma Ada_2020;
+
+with Ada.Strings.Text_Output; use Ada.Strings.Text_Output;
 
 private with Ada.Finalization;
 private with System;
@@ -24,9 +26,9 @@ private with System;
 package Ada.Numerics.Big_Numbers.Big_Integers
   with Preelaborate
 is
-   type Big_Integer is private;
-   --  with Integer_Literal => From_String,
-   --   Put_Image => Put_Image;
+   type Big_Integer is private with
+   --  Integer_Literal => From_String,
+ Put_Image => Put_Image;
 
function Is_Valid (Arg : Big_Integer) return Boolean
  with Convention => Intrinsic;
@@ -95,9 +97,7 @@ is
 
function From_String (Arg : String) return Big_Integer;
 
-   procedure Put_Image
- (Stream : not null access Ada.Streams.Root_Stream_Type'Class;
-  Arg: Big_Integer);
+   procedure Put_Image (S : in out Sink'Class; V : Big_Integer);
 
function "+" (L : Big_Integer) return Big_Integer;
 

--- gcc/ada/libgnat/a-nbnbin__gmp.adb
+++ gcc/ada/libgnat/a-nbnbin__gmp.adb
@@ -31,11 +31,13 @@
 
 --  This is the GMP version of this package
 
+pragma Ada_2020;
+
 with Ada.Unchecked_Conversion;
 with Ada.Unchecked_Deallocation;
 with Interfaces.C;   use Interfaces.C;
 with Interfaces.C.Strings;   use Interfaces.C.Strings;
-with Ada.Characters.Conversions; use Ada.Characters.Conversions;
+with Ada.Strings.Text_Output.Utils;
 with Ada.Characters.Handling;use Ada.Characters.Handling;
 
 package body Ada.Numerics.Big_Numbers.Big_Integers is
@@ -403,11 +405,12 @@ package body Ada.Numerics.Big_Numbers.Big_Integers is
-- Put_Image --
---
 
-   procedure Put_Image
- (Stream : not null access Ada.Streams.Root_Stream_Type'Class;
-  Arg: Big_Integer) is
+   procedure Put_Image (S : in out Sink'Class; V : Big_Real) is
+  --  This is implemented in terms of To_String. It might be more elegant
+  --  and more efficient to do it the other way around, but this is the
+  --  most expedient implementation for now.
begin
-  Wide_Wide_String'Write (Stream, To_Wide_Wide_String (To_String (Arg)));
+  Strings.Text_Output.Utils.Put_UTF_8 (S, To_String (V));
end Put_Image;
 
-

--- gcc/ada/libgnat/a-nbnbre.adb
+++ gcc/ada/libgnat/a-nbnbre.adb
@@ -31,7 +31,9 @@
 
 --  This is the default version of this package, based on Big_Integers only.
 
-with Ada.Characters.Conversions; use Ada.Characters.Conversions;
+pragma Ada_2020;
+
+with Ada.Strings.Text_Output.Utils;
 
 package body Ada.Numerics.Big_Numbers.Big_Reals is
 
@@ -399,11 +401,12 @@ package body Ada.Numerics.Big_Numbers.Big_Reals is
-- Put_Image --
---
 
-   procedure Put_Image
- (Stream : not null access Ada.Streams.Root_Stream_Type'Class;
-  Arg: Big_Real) is
+   procedure Put_Image (S : in out Sink'Class; V : Big_Real) is
+  --  This is implemented in terms of To_String. It might be more elegant
+  --  and more efficient to do it the other way around, but this is the

Re: [patch] Fix ICE in verify_sra_access_forest

2020-06-12 Thread Richard Biener via Gcc-patches
On Thu, Jun 11, 2020 at 5:24 PM Eric Botcazou  wrote:
>
> > I am not very good at reasoning about reverse storage order stuff but
> > can it ever happen that this reverse is not the same as racc->reverse?
> >
> > In order for that to happen, we'd have to have an assignment (folded
> > memcpy?) between two aggregates in the original code that, at the same
> > offset within the aggregates, have single field structures with
> > different storage orders.  If that has undefined behavior (even for
> > folded memcpy), I guess I am fine with the patch (but I cannot approve
> > it).  If not, I'd add a condition that racc->reverse is the same as
> > TYPE_REVERSE_STORAGE_ORDER(lacc->type) to the if guarding all of this.
>
> You cannot do an assignment between aggregates with opposite storage order,
> that's rejected by the compiler (both in C and Ada); generally speaking, such
> types are not compatible, even if they have the same underlying structure.
> We also block SRA when there is a VIEW_CONVERT_EXPR messing with the storage
> order, see calls to storage_order_barrier_p.  And folding a memcpy between
> them should be invalid too (see e.g. the ongoing discussion with Richard in an
> earlier thread).  So my understanding is that you don't need the condition.

The patch probably fixes only part of the issues with SRA and rev-storage.
I see in build_ref_for_model:

  /* The flag will be set on the record type.  */
  REF_REVERSE_STORAGE_ORDER (t) = 0;

for the case there was a COMPONENT_REF, so this is for the case where
the model did not have that?  Based on your assertion above can we
derive TYPE_REVERSE_STORAGE_ORDER from the passed in racc
and thus set the flag correctly in build_ref_for_model instead?

Thanks,
Richard.

> --
> Eric Botcazou


Re: [PATCH 2/2] Tune memcpy and memset for Zen cores.

2020-06-12 Thread Martin Liška

PING^2

On 6/3/20 11:14 AM, Martin Liška wrote:

On 6/1/20 1:40 PM, Martin Liška wrote:

Adding Honza as Uros recommended him for a review.


@Honza asked me personally to remind him this patch ;)

Martin




Re: [PATCH] Optimize multiplication for V8QI,V16QI,V32QI under TARGET_AVX512BW [target/95488]

2020-06-12 Thread Hongtao Liu via Gcc-patches
Thanks for the review.

On Fri, Jun 12, 2020 at 11:28 AM Jeff Law  wrote:
>
> On Fri, 2020-06-05 at 13:46 +0800, Hongtao Liu via Gcc-patches wrote:
> > Hi:
> >
> > +/* Optimize vector MUL generation for V8QI, V16QI and V32QI
> > +   under TARGET_AVX512BW. i.e. for v16qi a * b, it has
> > +
> > +   vpmovzxbw ymm2, xmm0
> > +   vpmovzxbw ymm3, xmm1
> > +   vpmullw   ymm4, ymm2, ymm3
> > +   vpmovwb   xmm0, ymm4
> > +
> > +   it would take less instructions than ix86_expand_vecop_qihi.
> > +   Return true if success.  */
> >
> >   Bootstrap is ok, regression test on i386/x86-64 backend is ok.
> >
> > gcc/ChangeLog:
> > PR target/95488
> > * config/i386/i386-expand.c (ix86_expand_vecmul_qihi): New
> > function.
> > * config/i386/i386-protos.h (ix86_expand_vecmul_qihi): Declare.
> > * config/i386/sse.md (mul3): Drop mask_name since
> > there's no real vector char multiplication instruction with
> > mask. Also optimize it under TARGET_AVX512BW.
> > (mulv8qi3): New expander.
> >
> > gcc/testsuite/ChangeLog:
> > * gcc.target/i386/avx512bw-pr95488-1.c: New test.
> > * gcc.target/i386/avx512bw-pr95488-2.c: Ditto.
> > * gcc.target/i386/avx512vl-pr95488-1.c: Ditto.
> > * gcc.target/i386/avx512vl-pr95488-2.c: Ditto.
> >
> OK
> jeff
>


-- 
BR,
Hongtao


[PATCH] vectorizer: add _bb_vec_info::const_iterator

2020-06-12 Thread Martin Liška

Hello.

I'm working one extension of SLP which will allow to vectorize multiple
BBs. This is a first step where I abstract _bb_vec_info::region_begin and
_bb_vec_info::region end by providing an iterator.

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

Ready to be installed?
Thanks,
Martin

gcc/ChangeLog:

* tree-vect-patterns.c (vect_determine_precisions): Use the
iterator.
(vect_pattern_recog): Likewise.
* tree-vect-slp.c (_bb_vec_info::_bb_vec_info): Likewise.
(_bb_vec_info::~_bb_vec_info): Likewise.
(vect_slp_check_for_constructors): Likewise.
* tree-vect-stmts.c (vect_init_vector_1): Likewise.
* tree-vectorizer.h: Add the new iterator and all related functions.
---
 gcc/tree-vect-patterns.c | 10 +-
 gcc/tree-vect-slp.c  | 24 +---
 gcc/tree-vect-stmts.c|  2 +-
 gcc/tree-vectorizer.h| 38 --
 4 files changed, 51 insertions(+), 23 deletions(-)

diff --git a/gcc/tree-vect-patterns.c b/gcc/tree-vect-patterns.c
index 636ad59c001..4c5a791522c 100644
--- a/gcc/tree-vect-patterns.c
+++ b/gcc/tree-vect-patterns.c
@@ -5120,7 +5120,7 @@ vect_determine_precisions (vec_info *vinfo)
   else
 {
   bb_vec_info bb_vinfo = as_a  (vinfo);
-  gimple_stmt_iterator si = bb_vinfo->region_end;
+  gimple_stmt_iterator si = bb_vinfo->end ().gsi;
   gimple *stmt;
   do
{
@@ -5133,7 +5133,7 @@ vect_determine_precisions (vec_info *vinfo)
  if (stmt_info && STMT_VINFO_VECTORIZABLE (stmt_info))
vect_determine_stmt_precisions (vinfo, stmt_info);
}
-  while (stmt != gsi_stmt (bb_vinfo->region_begin));
+  while (stmt != *bb_vinfo->begin ());
 }
 }
 
@@ -5492,10 +5492,10 @@ vect_pattern_recog (vec_info *vinfo)

   else
 {
   bb_vec_info bb_vinfo = as_a  (vinfo);
-  for (si = bb_vinfo->region_begin;
-  gsi_stmt (si) != gsi_stmt (bb_vinfo->region_end); gsi_next ())
+  for (_bb_vec_info::const_iterator it = bb_vinfo->begin ();
+  it != bb_vinfo->end (); it++)
{
- gimple *stmt = gsi_stmt (si);
+ gimple *stmt = *it;
  stmt_vec_info stmt_info = bb_vinfo->lookup_stmt (stmt);
  if (!stmt_info || !STMT_VINFO_VECTORIZABLE (stmt_info))
continue;
diff --git a/gcc/tree-vect-slp.c b/gcc/tree-vect-slp.c
index 303410c2fc4..5a2dc71f0cd 100644
--- a/gcc/tree-vect-slp.c
+++ b/gcc/tree-vect-slp.c
@@ -2551,15 +2551,12 @@ _bb_vec_info::_bb_vec_info (gimple_stmt_iterator 
region_begin_in,
vec_info_shared *shared)
   : vec_info (vec_info::bb, init_cost (NULL), shared),
 bb (gsi_bb (region_begin_in)),
-region_begin (region_begin_in),
-region_end (region_end_in)
+m_region_begin (region_begin_in),
+m_region_end (region_end_in)
 {
-  gimple_stmt_iterator gsi;
-
-  for (gsi = region_begin; gsi_stmt (gsi) != gsi_stmt (region_end);
-   gsi_next ())
+  for (_bb_vec_info::const_iterator it = begin (); it != end (); it++)
 {
-  gimple *stmt = gsi_stmt (gsi);
+  gimple *stmt = *it;
   gimple_set_uid (stmt, 0);
   if (is_gimple_debug (stmt))
continue;
@@ -2575,10 +2572,9 @@ _bb_vec_info::_bb_vec_info (gimple_stmt_iterator 
region_begin_in,
 
 _bb_vec_info::~_bb_vec_info ()

 {
-  for (gimple_stmt_iterator si = region_begin;
-   gsi_stmt (si) != gsi_stmt (region_end); gsi_next ())
+  for (_bb_vec_info::const_iterator it = begin (); it != end (); it++)
 /* Reset region marker.  */
-gimple_set_uid (gsi_stmt (si), -1);
+gimple_set_uid (*it, -1);
 
   bb->aux = NULL;

 }
@@ -3012,12 +3008,10 @@ vect_bb_vectorization_profitable_p (bb_vec_info 
bb_vinfo)
 static void
 vect_slp_check_for_constructors (bb_vec_info bb_vinfo)
 {
-  gimple_stmt_iterator gsi;
-
-  for (gsi = bb_vinfo->region_begin;
-   gsi_stmt (gsi) != gsi_stmt (bb_vinfo->region_end); gsi_next ())
+  for (_bb_vec_info::const_iterator it = bb_vinfo->begin ();
+   it != bb_vinfo->end (); it++)
 {
-  gassign *stmt = dyn_cast  (gsi_stmt (gsi));
+  gassign *stmt = dyn_cast  (*it);
   if (!stmt || gimple_assign_rhs_code (stmt) != CONSTRUCTOR)
continue;
 
diff --git a/gcc/tree-vect-stmts.c b/gcc/tree-vect-stmts.c

index cdd6f6c5e5d..766598862d4 100644
--- a/gcc/tree-vect-stmts.c
+++ b/gcc/tree-vect-stmts.c
@@ -1342,7 +1342,7 @@ vect_init_vector_1 (vec_info *vinfo, stmt_vec_info 
stmt_vinfo, gimple *new_stmt,
   else
{
   bb_vec_info bb_vinfo = dyn_cast  (vinfo);
- gimple_stmt_iterator gsi_region_begin = bb_vinfo->region_begin;
+ gimple_stmt_iterator gsi_region_begin = bb_vinfo->begin ().gsi;
  gsi_insert_before (_region_begin, new_stmt, GSI_SAME_STMT);
}
 }
diff --git a/gcc/tree-vectorizer.h b/gcc/tree-vectorizer.h
index 6c830ad09f4..542d49402d2 100644
--- a/gcc/tree-vectorizer.h
+++ b/gcc/tree-vectorizer.h
@@ -787,12 +787,46 

Re: (patch] Optimize assignment to volatile aggregate variable

2020-06-12 Thread Richard Biener via Gcc-patches
On Thu, Jun 11, 2020 at 1:52 PM Eric Botcazou  wrote:
>
> Hi,
>
> gimplify_modify_expr_rhs has an optimization whereby the assignment to an
> aggregate variable from a read-only object with a DECL_INITIAL is optimized
> into the direct assignment of the DECL_INITIAL, provided that no temporary is
> created in the process.
>
> The optimization is blocked if the read-only object is volatile, which is OK
> as per the semantics of volatile, but also if the target variable is volatile,
> on the grounds that the modified assignment might end up being done on a per
> field basis, which is also OK.  But this latter restriction is enforced a
> priori and there are cases where the modified assignment would be OK, for
> example if there is only one field or the DECL_INITIAL is equivalent to the
> empty CONSTRUCTOR, i.e. all zeros.
>
> So, in the latter case, the patch changes gimplify_modify_expr_rhs to ask
> gimplify_init_constructor whether the assignment would be done as a block,
> which is easy because gimplify_init_constructor knows that it must create a
> temporary if the LHS is volatile and this would not be the case, so it's just
> a matter of completing the NOTIFY_TEMP_CREATION mechanism for this case.
>
> Tested on x86-64/Linux, OK for the mainline?

OK.

Richard.

>
> 2020-06-11  Eric Botcazou  
>
> * gimplify.c (gimplify_init_constructor) : Declare new
> ENSURE_SINGLE_ACCESS constant and move variables down.  If it is true
> and all elements are zero, then always clear.  Return GS_ERROR if a
> temporary would be created for it and NOTIFY_TEMP_CREATION is set.
> (gimplify_modify_expr_rhs) : If the target is volatile but
> the type is aggregate non-addressable, ask gimplify_init_constructor
> whether it can generate a single access to the target.
>
>
> 2020-06-11  Eric Botcazou  
>
> * gnat.dg/aggr30.adb[sb]: New test.
>
> --
> Eric Botcazou


PING: Discussion about the medium code model in aarch64

2020-06-12 Thread bule
Hi,

I reported a PR in gcc Bugzilla about the medium code model in aarch64. A 
solution is proposed and some discussion has been posted.

The details of the discussion can be found here : 
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95285

Wilco suggest me to make a PIC 48-bit code model by making a new relocation 
type "high32_47" combined with ADRP instruction,  which I think is feasible and 
more efficient than my solution. But this kind of relocation hasn't been 
defined in arm's ABI. Meanwhile he also doubt the necessity of the medium or 
large-pic code model.

My solution, on the other hand, only use exiting relocation types 
R__MOVW_PREL_G0-3, which is also how llvm solve similar problems. Although 
it is less efficient, but currently more easier to implement. For the necessity 
concern, because I need to optimize CESM in my work, I happened need to use 
this kind of large-pic code model. The abstracted test case is also provided in 
the bug report.

I would very much like to know what is your opinion on this issue.

Which solution you think is more appropriate for current situation? 

And regarding the necessity problem, I admit it is not a critical issue. But 
some application in HPC field do need this code model. 
Personally, I think it doesn't hurt for us to upstream a prototype first for 
customer to use it. Later if arm have an official document regarding this code 
model, we can then make a standard model.
What's you opinion regarding this necessity problem?

Thanks a lot.

Regards,
Bu Le (Bruce)




Re: [PATCH PR95199] vect: Remove extra variable created for memory reference

2020-06-12 Thread Richard Sandiford
"zhoukaipeng (A)"  writes:
> Hi,
>
> This is a fix for pr95199.
> In vectorization, vinfo->ivexpr_map is supposed to catch those "IV base 
> and/or step expressions".  Just call cse_and_gimplify_to_preheader to handle 
> gathering/scattering to avoid the extra variable.
>
> Bootstrap and tested on aarch64/x86_64 Linux platform. No new regression 
> witnessed.
>
> Is it ok?
>
> Thanks,
> Kaipeng Zhou
>
> From 12cf9b362576735e4c584c48cd6db3d2b0f2e14b Mon Sep 17 00:00:00 2001
> From: Kaipeng Zhou 
> Date: Fri, 12 Jun 2020 00:54:15 +0800
> Subject: [PATCH] vect: Remove extra variable created for memory reference in
>  loop vectorization.
>
> Vectorization create two copies of the same IV and IVOPTs does not perform
> CSE.  But vinfo->ivexpr_map is supposed to catch those "IV base and/or step
> expressions".  Just call cse_and_gimplify_to_preheader to handle
> gathering/scattering to avoid the extra variable.
>
> 2020-06-12  Bin Cheng 
>   Kaipeng Zhou  
>
>   PR tree-optimization/95199
>   * tree-vect-stmts.c: Use CSE map to catch the IV step and eliminate
>   extra variable.
>
> 2020-06-12  Bin Cheng 
>   Kaipeng Zhou  
>
>   PR tree-optimization/95199
>   * gcc.dg/vect/pr95199.c: New test.
> ---
>  gcc/ChangeLog   |  7 +++
>  gcc/testsuite/ChangeLog |  6 ++
>  gcc/testsuite/gcc.dg/vect/pr95199.c | 17 +
>  gcc/tree-vect-stmts.c   |  1 +
>  4 files changed, 31 insertions(+)
>  create mode 100644 gcc/testsuite/gcc.dg/vect/pr95199.c
>
> diff --git a/gcc/ChangeLog b/gcc/ChangeLog
> index c92582df7fe..753d70fc94b 100644
> --- a/gcc/ChangeLog
> +++ b/gcc/ChangeLog
> @@ -1,3 +1,10 @@
> +2020-06-12  Bin Cheng 
> + Kaipeng Zhou  
> +
> + PR tree-optimization/95199
> + * tree-vect-stmts.c: Use CSE map to catch the IV step and eliminate
> + extra variable.
> +
>  2020-06-08  Tobias Burnus  
>  
>   PR lto/94848
> diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
> index 60d9ecca3ed..a27dd3fa072 100644
> --- a/gcc/testsuite/ChangeLog
> +++ b/gcc/testsuite/ChangeLog
> @@ -1,3 +1,9 @@
> +2020-06-12  Bin Cheng 
> + Kaipeng Zhou  
> +
> + PR tree-optimization/95199
> + * gcc.dg/vect/pr95199.c: New test.
> +
>  2020-06-08  Harald Anlauf  
>  
>   PR fortran/95195
> diff --git a/gcc/testsuite/gcc.dg/vect/pr95199.c 
> b/gcc/testsuite/gcc.dg/vect/pr95199.c
> new file mode 100644
> index 000..ec201feaec8
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/vect/pr95199.c
> @@ -0,0 +1,17 @@
> +/* { dg-do compile { target aarch64-*-* } } */
> +/* { dg-options "-O3 -march=armv8.2-a+fp+sve" } */
> +
> +void
> +foo (double *a, double *b, double m, int inc_x, int inc_y)
> +{
> +  int ix = 0, iy = 0;
> +  for (int i = 0; i < 1000; ++i)
> +{
> +  a[ix] += m * b[iy];
> +  ix += inc_x;
> +  iy += inc_y;
> +}
> +  return ;
> +}
> +
> +/* { dg-final { scan-assembler-times "add" 12 } } */

For asm tests, it's probably better to put this in aarch64/sve instead.
The scan-assembler should be a bit more precise though, since just
"add" could catch filenames like /homd/ladd/gcc.  E.g. maybe it would
be clearer to make the regexp match the register operands too.  (In that
case it's better to quote the regexp with {…} rather than "…", to reduce
the number of backslashes.)

> diff --git a/gcc/tree-vect-stmts.c b/gcc/tree-vect-stmts.c
> index b24b0fe4304..26a2b143b01 100644
> --- a/gcc/tree-vect-stmts.c
> +++ b/gcc/tree-vect-stmts.c
> @@ -2969,6 +2969,7 @@ vect_get_strided_load_store_ops (stmt_vec_info 
> stmt_info,
>tree bump = size_binop (MULT_EXPR,
> fold_convert (sizetype, unshare_expr (DR_STEP (dr))),
> size_int (TYPE_VECTOR_SUBPARTS (vectype)));
> +  bump = cse_and_gimplify_to_preheader (loop_vinfo, bump);
>*dataref_bump = force_gimple_operand (bump, , true, NULL_TREE);
>if (stmts)
>  gsi_insert_seq_on_edge_immediate (loop_preheader_edge (loop), stmts);

Agree it's good to do this, but using cse_and_gimplify_to_preheader
makes the force_gimple_operand and gsi_insert_seq_on_edge_immediate
redundant.

I guess we might as well do the same thing for “*vec_offset” too.

Thanks,
Richard


Re: [PATCH] middle-end: Optimize (A)^(B) to (A^B) in simplify_rtx.

2020-06-12 Thread Richard Sandiford
"Roger Sayle"  writes:
> diff --git a/gcc/simplify-rtx.c b/gcc/simplify-rtx.c
> index 28c2dc6..ccf5f6d 100644
> --- a/gcc/simplify-rtx.c
> +++ b/gcc/simplify-rtx.c
> @@ -3128,6 +3128,17 @@ simplify_binary_operation_1 (enum rtx_code code, 
> machine_mode mode,
>mode);
>}
>  
> +  /* Convert (xor (and A C) (and B C)) into (and (xor A B) C).  */
> +  if (GET_CODE (op0) == AND 
> +   && GET_CODE (op1) == AND
> +   && rtx_equal_p (XEXP (op0, 1), XEXP (op1, 1))
> +   && ! side_effects_p (XEXP (op0, 1)))
> + return simplify_gen_binary (AND, mode,
> + simplify_gen_binary (XOR, mode,
> +  XEXP (op0, 0),
> +  XEXP (op1, 0)),
> + XEXP (op0, 1));
> +
>/* Convert (xor (and A B) B) to (and (not A) B).  The latter may
>correspond to a machine insn or result in further simplifications
>if B is a constant.  */

Looks good, but I guess we might as well add the corresponding
(ior (and …) (and …)) and (and (and …) (and …)) rules at the
same time.  E.g. maybe have a new subfunction for logical ops that
is shared by all of AND, IOR and XOR.  In the case of AND, this ought
to have precedence over simplify_associative_operation.

No separate testcase is fine, but maybe it'd be worth adding some
selftests to simplify_rtx_c_tests.

Hope this isn't the best being the enemy of the good…

Thanks,
Richard


Re: [PATCH 3/5] gthr-vxworks.c: add include of taskLib.h

2020-06-12 Thread Olivier Hainque
Hi Rasmus,

(switched from gcc to gcc-patches list)

> On 26 May 2020, at 16:52, Rasmus Villemoes  wrote:
> 
> Fix
> 
> gcc-src/libgcc/config/gthr-vxworks.c:65:7: warning: implicit declaration of 
> function 'taskDelay'; did you mean 'sysDelay'? 
> [-Wimplicit-function-declaration]
>   65 |   taskDelay (1);

> --- a/libgcc/config/gthr-vxworks.c
> +++ b/libgcc/config/gthr-vxworks.c
> @@ -33,6 +33,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  
> If not, see
> #if defined(__GTHREADS)
> 
> #include 
> +#include 
> 
> #ifndef __RTP__
> # include 

Ok (with a ChangeLog),

Thanks,

Olivier



ping**(5./7.) [patch, fortran] Fix memory leak on deallocation

2020-06-12 Thread Thomas König




In the meantime, here is a patch which fixes a regression I introduced
when fixing a regression with a memory leak.  The important thing
here is to realize that we do not need to finalize (and deallocate)
multiple times for the same expression and the same component
in the same namespace.  It might cause code size regressions, but
better big code than wrong code...

This is a regression all the way down to gcc 8.  OK for all affected
branches?


Ping?

Unless there are any objections, I would commit this to master
on Sunday.

Regards

Thomas


[PATCH PR95199] vect: Remove extra variable created for memory reference

2020-06-12 Thread zhoukaipeng (A)
Hi,

This is a fix for pr95199.
In vectorization, vinfo->ivexpr_map is supposed to catch those "IV base and/or 
step expressions".  Just call cse_and_gimplify_to_preheader to handle 
gathering/scattering to avoid the extra variable.

Bootstrap and tested on aarch64/x86_64 Linux platform. No new regression 
witnessed.

Is it ok?

Thanks,
Kaipeng Zhou


0001-vect-Remove-extra-variable-created-for-memory-refere.patch
Description: 0001-vect-Remove-extra-variable-created-for-memory-refere.patch