Re: PING^1: V2 [PATCH] i386: Insert ENDBR for NOTE_INSN_DELETED_LABEL only if needed

2019-05-27 Thread Uros Bizjak
On Tue, May 21, 2019 at 11:48 PM H.J. Lu  wrote:
>
> On Sat, Feb 16, 2019 at 7:02 AM H.J. Lu  wrote:
> >
> > On Thu, Feb 14, 2019 at 08:13:32PM -0800, H.J. Lu wrote:
> > > NOTE_INSN_DELETED_LABEL is used to mark what used to be a 'code_label',
> > > but was not used for other purposes than taking its address and was
> > > transformed to mark that no code jumps to it.  NOTE_INSN_DELETED_LABEL
> > > is generated only in 3 places:
> > >
> > > 1. When delete_insn sees an unused label which is an explicit label in
> > > the input source code or its address is taken, it turns the label into
> > > a NOTE_INSN_DELETED_LABEL note.
> > > 2. When rtl_tidy_fallthru_edge deletes a tablejump, it turns the
> > > tablejump into a NOTE_INSN_DELETED_LABEL note.
> > > 3. ix86_init_large_pic_reg creats a NOTE_INSN_DELETED_LABEL note, .L2,
> > > to initialize large model PIC register:
> > >
> > > L2:
> > >   movabsq $_GLOBAL_OFFSET_TABLE_-.L2, %r11
> > >   leaq.L2(%rip), %rax
> > >   movabsq $val@GOT, %rdx
> > >   addq%r11, %rax
> > >
> > > Among of them, ENDBR is needed only when the label address is taken.
> > > rest_of_insert_endbranch has
> > >
> > >   if ((LABEL_P (insn) && LABEL_PRESERVE_P (insn))
> > >   || (NOTE_P (insn)
> > >   && NOTE_KIND (insn) == NOTE_INSN_DELETED_LABEL))
> > > /* TODO.  Check /s bit also.  */
> > > {
> > >   cet_eb = gen_nop_endbr ();
> > >   emit_insn_after (cet_eb, insn);
> > >   continue;
> > > }
> > >
> > > For NOTE_INSN_DELETED_LABEL, we should check if forced_labels to see
> > > if its address is taken.  Also ix86_init_large_pic_reg shouldn't set
> > > LABEL_PRESERVE_P (in_struct) since NOTE_INSN_DELETED_LABEL is suffcient
> > > to keep the label.
> > >
> > > gcc/
> > >
> > >   PR target/89355
> > >   * config/i386/i386.c (rest_of_insert_endbranch): Check
> > >   forced_labels to see if the address of NOTE_INSN_DELETED_LABEL
> > >   is taken.
> > >   (ix86_init_large_pic_reg): Don't set LABEL_PRESERVE_P.
> > >
> >
> > Here is the updated patch.  We should check LABEL_PRESERVE_P on
> > NOTE_INSN_DELETED_LABEL to see if its address is taken.
> >
> > OK for trunk?
> >
> > Thanks.
> >
> > H.J.
> > ---
> > NOTE_INSN_DELETED_LABEL is used to mark what used to be a 'code_label',
> > but was not used for other purposes than taking its address and was
> > transformed to mark that no code jumps to it.  Since LABEL_PRESERVE_P is
> > true only if the label address was taken, check LABEL_PRESERVE_P before
> > inserting ENDBR.
> >
> > 2019-02-15  H.J. Lu  
> > Hongtao Liu  
> >
> > gcc/
> >
> > PR target/89355
> > * config/i386/i386.c (rest_of_insert_endbranch): LABEL_PRESERVE_P
> > to see if the address of NOTE_INSN_DELETED_LABEL is taken.
> > (ix86_init_large_pic_reg): Don't set LABEL_PRESERVE_P.
> >
> > gcc/testsuite/
> >
> > PR target/89355
> > * gcc.target/i386/cet-label-3.c: New test.
> > * gcc.target/i386/cet-label-4.c: Likewise.
> > * gcc.target/i386/cet-label-5.c: Likewise.
>
> PING:
>
> https://gcc.gnu.org/ml/gcc-patches/2019-02/msg01327.html

This patch goes deep into RTL details, so IMO RTL expert (Jeff ?)
should approve it.

Uros.


Re: Add GCC support to ENQCMD.

2019-05-27 Thread Hongtao Liu
On Fri, May 24, 2019 at 3:51 PM Uros Bizjak  wrote:
>
> On Fri, May 24, 2019 at 9:43 AM Uros Bizjak  wrote:
> >
> > On Fri, May 24, 2019 at 7:16 AM Hongtao Liu  wrote:
> > >
> > > Hi Uros and all:
> > >   This patch is about to enable support for ENQCMD(Enqueue Command)
> > > which will be in Willow Cove.
> > >   There are two instructions for ENQCMD: ENQCMD and ENQCMDS. More
> > > details please refer to
> > > https://software.intel.com/sites/default/files/managed/c5/15/architecture-instruction-set-extensions-programming-reference.pdf
> > >
> > >   Bootstrap is ok, and no regressions for i386/x86-64 testsuite.
> > >
> > > gcc/ChangeLog
> > > 2019-01-23  Xuepeng Guo  
> > >
> > > * common/config/i386/i386-common.c
> > > (OPTION_MASK_ISA_ENQCMD_SET,
> > > OPTION_MASK_ISA_ENQCMD_UNSET): New macros.
> > > (ix86_handle_option): Handle -menqcmd.
> > > * config.gcc (enqcmdintrin.h): New header file.
> > > * config/i386/cpuid.h (bit_ENQCMD): New bit.
> > > * config/i386/driver-i386.c (host_detect_local_cpu): Handle
> > > -menqcmd.
> > > * config/i386/i386-builtin-types.def ((INT, PVOID, PCVOID)): 
> > > New
> > > function type.
> > > * config/i386/i386-builtin.def (__builtin_ia32_enqcmd,
> > > __builtin_ia32_enqcmds): New builtins.
> > > * config/i386/i386-c.c (__ENQCMD__): New macro.
> > > * config/i386/i386-option.c (ix86_target_string): Add
> > > -menqcmd.
> > > (ix86_valid_target_attribute_inner_p): Likewise.
> > > * config/i386/i386-expand.c
> > > (ix86_expand_builtin): Expand IX86_BUILTIN_ENQCMD and
> > > IX86_BUILTIN_ENQCMDS.
> > > * config/i386/i386.h (TARGET_ENQCMD): New.
> > > * config/i386/i386.md (UNSPECV_ENQCMD, UNSPECV_ENQCMDS): New.
> > > (@enqcmd_): New insn pattern.
> > > (movdir64b_): Parameterize to enable share expansion 
> > > code
> > > with ENQCMD in function ix86_expand_builtin.
> > > * config/i386/i386.opt: Add -menqcmd.
> > > * config/i386/immintrin.h: Include enqcmdintrin.h.
> > > * config/i386/enqcmdintrin.h: New intrinsic file.
> > > * doc/invoke.texi: Add -menqcmd.
> > >
> > > gcc/testsuite/ChangeLog
> > >
> > > 2019-01-23  Xuepeng Guo  
> > >
> > > * gcc.target/i386/enqcmd.c: New test.
> > > * gcc.target/i386/enqcmds.c: Likewise.
> > > * g++.dg/other/i386-2.C: Add -menqcmd.
> > > * g++.dg/other/i386-3.C: Likewise.
> > > * gcc.target/i386/sse-12.c: Likewise.
> > > * gcc.target/i386/sse-13.c: Likewise.
> > > * gcc.target/i386/sse-14.c: Likewise.
> > > * gcc.target/i386/sse-23.c: Likewise.
> >
> > OK for mainline with a small fix below.
> >
> > Thanks,
> > Uros.
> >
> > @@ -20321,7 +20325,7 @@
> >"movdiri\t{%1, %0|%0, %1}"
> >[(set_attr "type" "other")])
> >
> > -(define_insn "movdir64b_"
> > +(define_insn "@movdir64b"
> >[(unspec_volatile:XI [(match_operand:P 0 "register_operand" "r")
> >   (match_operand:XI 1 "memory_operand")]
> > UNSPECV_MOVDIR64B)]
> >
> > No need to remove the underscore in the above name.
>
> +  emit_insn (gen_movdir64b (GET_MODE (op0), op0, op1));
>
> You can just use Pmode instead of GET_MODE here ...
>
> +  if (fcode == IX86_BUILTIN_ENQCMD)
> +pat = gen_enqcmd (UNSPECV_ENQCMD, GET_MODE (op0), op0, op1);
>
> ... here ...
>
> +  else
> +pat = gen_enqcmd (UNSPECV_ENQCMDS, GET_MODE (op0), op0, op1);
>
> ... and here.

Thanks a lot.

Committed.
https://gcc.gnu.org/viewcvs/gcc?view=revision&revision=271678
-- 
BR,
Hongtao


Re: [RFC][PR88838][SVE] Use 32-bit WHILELO in LP64 mode

2019-05-27 Thread Kugan Vivekanandarajah
Hi Richard,

Thanks for the review.

On Sat, 25 May 2019 at 19:41, Richard Sandiford
 wrote:
>
> Kugan Vivekanandarajah  writes:
> > diff --git a/gcc/tree-vect-loop-manip.c b/gcc/tree-vect-loop-manip.c
> > index 77d3dac..d6452a1 100644
> > --- a/gcc/tree-vect-loop-manip.c
> > +++ b/gcc/tree-vect-loop-manip.c
> > @@ -418,7 +418,20 @@ vect_set_loop_masks_directly (struct loop *loop, 
> > loop_vec_info loop_vinfo,
> >tree mask_type = rgm->mask_type;
> >unsigned int nscalars_per_iter = rgm->max_nscalars_per_iter;
> >poly_uint64 nscalars_per_mask = TYPE_VECTOR_SUBPARTS (mask_type);
> > -
> > +  bool convert = false;
> > +  tree iv_type = NULL_TREE;
> > +
> > +  /* If the compare_type is not with Pmode size, we will create an IV with
> > + Pmode size with truncated use (i.e. converted to the correct type).
> > + This is because using Pmode allows ivopts to reuse the IV for indices
> > + (in the loads and store).  */
> > +  if (known_lt (GET_MODE_BITSIZE (TYPE_MODE (compare_type)),
> > + GET_MODE_BITSIZE (Pmode)))
> > +{
> > +  iv_type = build_nonstandard_integer_type (GET_MODE_BITSIZE (Pmode),
> > + true);
> > +  convert = true;
> > +}
> >/* Calculate the maximum number of scalar values that the rgroup
> >   handles in total, the number that it handles for each iteration
> >   of the vector loop, and the number that it should skip during the
> > @@ -444,12 +457,43 @@ vect_set_loop_masks_directly (struct loop *loop, 
> > loop_vec_info loop_vinfo,
> >   processed.  */
> >tree index_before_incr, index_after_incr;
> >gimple_stmt_iterator incr_gsi;
> > +  gimple_stmt_iterator incr_gsi2;
> >bool insert_after;
> > -  tree zero_index = build_int_cst (compare_type, 0);
> > +  tree zero_index;
> >standard_iv_increment_position (loop, &incr_gsi, &insert_after);
> > -  create_iv (zero_index, nscalars_step, NULL_TREE, loop, &incr_gsi,
> > -  insert_after, &index_before_incr, &index_after_incr);
> >
> > +  if (convert)
> > +{
> > +  /* If we are creating IV of Pmode type and converting.  */
> > +  zero_index = build_int_cst (iv_type, 0);
> > +  tree step = build_int_cst (iv_type,
> > +  LOOP_VINFO_VECT_FACTOR (loop_vinfo));
> > +  /* Creating IV of Pmode type.  */
> > +  create_iv (zero_index, step, NULL_TREE, loop, &incr_gsi,
> > +  insert_after, &index_before_incr, &index_after_incr);
> > +  /* Create truncated index_before and after increament.  */
> > +  tree index_before_incr_trunc = make_ssa_name (compare_type);
> > +  tree index_after_incr_trunc = make_ssa_name (compare_type);
> > +  gimple *incr_before_stmt = gimple_build_assign 
> > (index_before_incr_trunc,
> > +   NOP_EXPR,
> > +   index_before_incr);
> > +  gimple *incr_after_stmt = gimple_build_assign 
> > (index_after_incr_trunc,
> > +  NOP_EXPR,
> > +  index_after_incr);
> > +  incr_gsi2 = incr_gsi;
> > +  gsi_insert_before (&incr_gsi2, incr_before_stmt, GSI_NEW_STMT);
> > +  gsi_insert_after (&incr_gsi, incr_after_stmt, GSI_NEW_STMT);
> > +  index_before_incr = index_before_incr_trunc;
> > +  index_after_incr = index_after_incr_trunc;
> > +  zero_index = build_int_cst (compare_type, 0);
> > +}
> > +  else
> > +{
> > +  /* If the IV is of Pmode compare_type, no convertion needed.  */
> > +  zero_index = build_int_cst (compare_type, 0);
> > +  create_iv (zero_index, nscalars_step, NULL_TREE, loop, &incr_gsi,
> > +  insert_after, &index_before_incr, &index_after_incr);
> > +}
> >tree test_index, test_limit, first_limit;
> >gimple_stmt_iterator *test_gsi;
> >if (might_wrap_p)
>
> Instead of hard-coding Pmode as a special case here, I think we should
> record the IV type in vect_verify_full_masking in addition to the comparison
> type.  (With the IV type always being at least as wide as the comparison
> type.)
Ok.

>
> > diff --git a/gcc/tree-vect-loop.c b/gcc/tree-vect-loop.c
> > index bd81193..2769c86 100644
> > --- a/gcc/tree-vect-loop.c
> > +++ b/gcc/tree-vect-loop.c
> > @@ -1035,6 +1035,30 @@ vect_verify_full_masking (loop_vec_info loop_vinfo)
> >/* Find a scalar mode for which WHILE_ULT is supported.  */
> >opt_scalar_int_mode cmp_mode_iter;
> >tree cmp_type = NULL_TREE;
> > +  tree niters_type = TREE_TYPE (LOOP_VINFO_NITERS (loop_vinfo));
> > +  tree niters_skip = LOOP_VINFO_MASK_SKIP_NITERS (loop_vinfo);
> > +  unsigned HOST_WIDE_INT max_vf = vect_max_vf (loop_vinfo);
> > +  widest_int iv_limit;
> > +  bool known_max_iters = max_loop_iterations (loop, &iv_limit);
> > +  if (known_max_iters)
> > +{
> > +  if (niters_skip)
> > + {
> > +   /* Add the maximum

[committed] Add lastprivate(conditional:) support for the sections construct

2019-05-27 Thread Jakub Jelinek
Hi!

This adds support for the sections construct, similarly to the worksharing loop
construct only supported when not combined with parallel for now.

Bootstrapped/regtested on x86_64-linux and i686-linux, committed to trunk.

2019-05-27  Jakub Jelinek  

* gimplify.c (gimplify_scan_omp_clauses): Allow lastprivate conditional
on sections construct.
* omp-low.c (lower_lastprivate_conditional_clauses): Handle sections
construct.
(lower_omp_sections): Handle lastprivate conditional.
(lower_omp_1) : Handle sections construct with
lastprivate_conditional_map.
* omp-expand.c (expand_omp_sections): Handle lastprivate conditional.
libgomp/
* testsuite/libgomp.c-c++-common/lastprivate_conditional_4.c: New test.

--- gcc/gimplify.c.jj   2019-05-24 23:30:35.925880550 +0200
+++ gcc/gimplify.c  2019-05-27 16:00:23.476677962 +0200
@@ -8143,7 +8143,7 @@ gimplify_scan_omp_clauses (tree *list_p,
}
  if (OMP_CLAUSE_LASTPRIVATE_CONDITIONAL (c))
{
- if (code == OMP_FOR)
+ if (code == OMP_FOR || code == OMP_SECTIONS)
flags |= GOVD_LASTPRIVATE_CONDITIONAL;
  else
{
--- gcc/omp-low.c.jj2019-05-27 15:49:29.055288052 +0200
+++ gcc/omp-low.c   2019-05-27 17:21:20.260557994 +0200
@@ -5370,7 +5370,6 @@ lower_rec_input_clauses (tree clauses, g
 static void
 lower_lastprivate_conditional_clauses (tree *clauses, omp_context *ctx)
 {
-  struct omp_for_data fd;
   tree iter_type = NULL_TREE;
   tree cond_ptr = NULL_TREE;
   tree iter_var = NULL_TREE;
@@ -5380,8 +5379,15 @@ lower_lastprivate_conditional_clauses (t
   {
if (iter_type == NULL)
  {
-   omp_extract_for_data (as_a  (ctx->stmt), &fd, NULL);
-   iter_type = unsigned_type_for (fd.iter_type);
+   if (gimple_code (ctx->stmt) == GIMPLE_OMP_FOR)
+ {
+   struct omp_for_data fd;
+   omp_extract_for_data (as_a  (ctx->stmt), &fd,
+ NULL);
+   iter_type = unsigned_type_for (fd.iter_type);
+ }
+   else if (gimple_code (ctx->stmt) == GIMPLE_OMP_SECTIONS)
+ iter_type = unsigned_type_node;
cond_ptr = create_tmp_var_raw (build_pointer_type (iter_type));
DECL_CONTEXT (cond_ptr) = current_function_decl;
DECL_SEEN_IN_BIND_EXPR_P (cond_ptr) = 1;
@@ -6739,7 +6745,7 @@ lower_omp_sections (gimple_stmt_iterator
   gomp_sections *stmt;
   gimple *t;
   gbind *new_stmt, *bind;
-  gimple_seq ilist, dlist, olist, tred_dlist = NULL, new_body;
+  gimple_seq ilist, dlist, olist, tred_dlist = NULL, clist = NULL, new_body;
 
   stmt = as_a  (gsi_stmt (*gsi_p));
 
@@ -6771,6 +6777,12 @@ lower_omp_sections (gimple_stmt_iterator
   lower_rec_input_clauses (gimple_omp_sections_clauses (stmt),
   &ilist, &dlist, ctx, NULL);
 
+  control = create_tmp_var (unsigned_type_node, ".section");
+  gimple_omp_sections_set_control (stmt, control);
+
+  tree *clauses_ptr = gimple_omp_sections_clauses_ptr (stmt);
+  lower_lastprivate_conditional_clauses (clauses_ptr, ctx);
+
   new_body = gimple_omp_body (stmt);
   gimple_omp_set_body (stmt, NULL);
   tgsi = gsi_start (new_body);
@@ -6792,7 +6804,7 @@ lower_omp_sections (gimple_stmt_iterator
{
  gimple_seq l = NULL;
  lower_lastprivate_clauses (gimple_omp_sections_clauses (stmt), NULL,
-NULL, &l, NULL, ctx);
+&ilist, &l, &clist, ctx);
  gsi_insert_seq_after (&tgsi, l, GSI_CONTINUE_LINKING);
  gimple_omp_section_set_last (sec_start);
}
@@ -6806,7 +6818,17 @@ lower_omp_sections (gimple_stmt_iterator
 
   olist = NULL;
   lower_reduction_clauses (gimple_omp_sections_clauses (stmt), &olist,
-  NULL, ctx);
+  &clist, ctx);
+  if (clist)
+{
+  tree fndecl = builtin_decl_explicit (BUILT_IN_GOMP_ATOMIC_START);
+  gcall *g = gimple_build_call (fndecl, 0);
+  gimple_seq_add_stmt (&olist, g);
+  gimple_seq_add_seq (&olist, clist);
+  fndecl = builtin_decl_explicit (BUILT_IN_GOMP_ATOMIC_END);
+  g = gimple_build_call (fndecl, 0);
+  gimple_seq_add_stmt (&olist, g);
+}
 
   block = make_node (BLOCK);
   new_stmt = gimple_build_bind (NULL, NULL, block);
@@ -6824,9 +6846,7 @@ lower_omp_sections (gimple_stmt_iterator
   gimple_seq_add_stmt (&new_body, gimple_build_omp_sections_switch ());
   gimple_seq_add_stmt (&new_body, bind);
 
-  control = create_tmp_var (unsigned_type_node, ".section");
   t = gimple_build_omp_continue (control, control);
-  gimple_omp_sections_set_control (stmt, control);
   gimple_seq_add_stmt (&new_body, t);
 
   gimple_seq_add_seq (&new_body, olist);
@@ -10640,8 +10660,11 @@ lower_omp_1 (gimple_stmt_iterator *gsi_p
  if (DECL_P (lhs))
if (tree *v = u

[committed] Fix up lastprivate(conditional:) handling when assignment is nested inside critical, taskgroup or ordered construct

2019-05-27 Thread Jakub Jelinek
Hi!

The store to the lastprivate(conditional:) private variable could be nested
inside some other construct, the following patch deals with that.

Bootstrapped/regtested on x86_64-linux and i686-linux, committed to trunk.

2019-05-27  Jakub Jelinek  

* omp-low.c (lower_omp_1) : Look through ordered,
critical, taskgroup and section regions when looking for a region
with non-NULL lastprivate_conditional_map.

* testsuite/libgomp.c-c++-common/lastprivate-conditional-3.c: New test.

--- gcc/omp-low.c.jj2019-05-24 23:30:35.927880518 +0200
+++ gcc/omp-low.c   2019-05-27 15:33:10.855156534 +0200
@@ -10627,14 +10627,21 @@ lower_omp_1 (gimple_stmt_iterator *gsi_p
   goto regimplify;
 
 case GIMPLE_ASSIGN:
-  if (ctx && ctx->lastprivate_conditional_map)
+  for (omp_context *up = ctx; up; up = up->outer)
{
+ if (gimple_code (up->stmt) == GIMPLE_OMP_ORDERED
+ || gimple_code (up->stmt) == GIMPLE_OMP_CRITICAL
+ || gimple_code (up->stmt) == GIMPLE_OMP_TASKGROUP
+ || gimple_code (up->stmt) == GIMPLE_OMP_SECTION)
+   continue;
+ else if (!up->lastprivate_conditional_map)
+   break;
  tree lhs = get_base_address (gimple_assign_lhs (stmt));
  if (DECL_P (lhs))
-   if (tree *v = ctx->lastprivate_conditional_map->get (lhs))
+   if (tree *v = up->lastprivate_conditional_map->get (lhs))
  {
tree clauses
- = gimple_omp_for_clauses (as_a  (ctx->stmt));
+ = gimple_omp_for_clauses (as_a  (up->stmt));
tree c = omp_find_clause (clauses, OMP_CLAUSE__CONDTEMP_);
c = omp_find_clause (OMP_CLAUSE_CHAIN (c),
 OMP_CLAUSE__CONDTEMP_);
--- libgomp/testsuite/libgomp.c-c++-common/lastprivate-conditional-3.c.jj   
2019-05-27 15:35:43.549678080 +0200
+++ libgomp/testsuite/libgomp.c-c++-common/lastprivate-conditional-3.c  
2019-05-27 15:47:44.180988373 +0200
@@ -0,0 +1,57 @@
+/* { dg-do run } */
+/* { dg-require-effective-target tls_runtime } */
+/* { dg-additional-options "-std=gnu99" {target c } } */
+
+#include 
+#include 
+
+int r, s, u, v, t;
+int *x;
+
+void
+foo (int *a)
+{
+  int i;
+  long long j;
+  #pragma omp for lastprivate (conditional: u, x) ordered
+  for (i = 15; i < 64; i++)
+{
+  #pragma omp critical
+  {
+   if ((a[i] % 5) == 3)
+ u = i;
+  }
+  #pragma omp ordered
+  {
+   if ((a[i] % 7) == 2)
+ x = &a[i];
+  }
+}
+  #pragma omp for lastprivate (conditional: v) reduction (+:r, s) schedule 
(nonmonotonic: static) reduction (task, +: t)
+  for (i = -3; i < 119; i += 2)
+{
+  ++s;
+  #pragma omp taskgroup
+  {
+   #pragma omp task in_reduction (+: t)
+ ++t;
+   if ((a[i + 4] % 11) == 9)
+ v = i;
+   else
+ ++r;
+  }
+}
+}
+
+int
+main ()
+{
+  int a[128], i;
+  for (i = 0; i < 128; i++)
+a[i] = i;
+  #pragma omp parallel
+  foo (a);
+  if (u != 63 || v != 115 || x != &a[58] || r != 55 || s != 61 || t != 61)
+abort ();
+  return 0;
+}

Jakub


Re: Make possible 'scan-tree-dump' of 'lower_omp_target' mapping kinds

2019-05-27 Thread Thomas Schwinge
Hi!

I'm highly annoyed that we're wasting a lot of time arguing about such a
minor item.

On Mon, 27 May 2019 21:29:13 +0200, Jakub Jelinek  wrote:
> On Mon, May 27, 2019 at 09:05:06PM +0200, Thomas Schwinge wrote:
> > > The arrays are emitted in the *.omplower dump, so I think it is much 
> > > better
> > > to scan-tree-dump their content
> > 
> > That's not feasible in the general case.
> 
> Why?  The arrays have easily parseable names (.omp_data_kinds.N), then they
> have an initializer and you can easily write a regexp to say match 3
> occurences of the firstprivate int kind constant in there.

Given the test case that's part of my patch, we get:

$ grep -F omp_data_kinds < lower_omp_target-mappings-1.c.007t.omplower
  .omp_data_kinds.15[0] = D.2509;
  .omp_data_kinds.15[1] = 781;
  .omp_data_kinds.15[2] = 525;
  #pragma omp target num_teams(1) thread_limit(0) 
map(from:*vla.1[0] [len: _18]) map(firstprivate:vla [pointer assign, bias: 0]) 
firstprivate(D.2437) firstprivate(argc) [child fn: main._omp_fn.0 
(.omp_data_arr.13, .omp_data_sizes.14, .omp_data_kinds.15)]
  .omp_data_kinds.15 = {CLOBBER};
#pragma omp target num_teams(1) thread_limit(0) 
map(from:argc [len: 4]) map(tofrom:*vla.1 [len: D.2440]) map(firstprivate:vla 
[pointer assign, bias: 0]) map(alloc:MEM[(char *)argv] [len: 0]) 
map(firstprivate:argv [pointer assign, bias: 0]) [child fn: main._omp_fn.1 
(.omp_data_arr.18, .omp_data_sizes.19, .omp_data_kinds.20)]
#pragma omp target num_teams(1) thread_limit(0) 
is_device_ptr(argv) map(tofrom:*vla.1 [len: D.2440]) map(firstprivate:vla 
[pointer assign, bias: 0]) firstprivate(argc) [child fn: main._omp_fn.2 
(.omp_data_arr.25, .omp_data_sizes.26, .omp_data_kinds.27)]

So that doesn't even display all the arrays.  (The (default) 'static'
ones appear only in the next, 'lower', dump.)

What OMP construct does '.omp_data_kinds.15' relate to?  I can't tell
(what number each one gets), so can have just one per file?

What is 'D.2509'?  I can't follow/scan for that.

The values '781', '525' contain the alignment encoded, which may vary per
GCC target configuration, making it clumsy to scan for.

Etc.

(Why do I even have to explain this to you -- you must aleady before have
come across such dumps, and their peculiarities?)

With my patch, we can instead have:

// { dg-final { scan-tree-dump-times {(?n)^Mapping 
\[.*lower_omp_target-mappings-1.c:8:9\] main\._omp_fn\.0 \[0\] '\*vla.1\[0\]': 
kind = 2/15, size = .*, align = 1$} 1 omplower } }
// { dg-final { scan-tree-dump-times {(?n)^Mapping 
\[.*lower_omp_target-mappings-1.c:8:9\] main\._omp_fn\.0 \[1\] '.*': kind = 13, 
size = 0, align = 4$} 1 omplower { target { ! { c++ && lp64 } } } } }
// { dg-final { scan-tree-dump-times {(?n)^Mapping 
\[.*lower_omp_target-mappings-1.c:8:9\] main\._omp_fn\.0 \[1\] '.*': kind = 13, 
size = 0, align = 8$} 1 omplower { target { c++ && lp64 } } } }
// { dg-final { scan-tree-dump-times {(?n)^Mapping 
\[.*lower_omp_target-mappings-1.c:8:9\] main\._omp_fn\.0 \[2\] 'argc': kind = 
13, size = 0, align = 4$} 1 omplower } }

> > > if for whatever reason adding a runtime
> > > testcase isn't sufficient
> > 
> > Why should I have an execution test for something that should really be
> > verified at the compiler side, at compile time?  And, for example, an
> 
> Generally a runtime test can check all compilation phases, linking, runtime,
> while what looks like a unit test only tests a small portion of that.

I don't understand what you're intending to explain here.

> > > over adding further printouts and matching that.
> > 
> > I had assumed that you'd noticed that a lot of compiler passes are
> > dumping stuff that can then be scanned for.  Are you insisting that GCC's
> 
> Usually the detailed messages in the dump print why certain changes are
> done, or other information that is not readily available in the dump
> already.

So we must not do something new/useful, because it's... new?

> I'm not convinced what you are doing brings anything that isn't
> there already.

Aha.

Why exactly are you objecting that the compiler produces useful
intermediate dumps, understandable my machine and human?


Grüße
 Thomas


[committed] Fix libgomp lastprivate conditional handling on some strict alignment targets (PR libgomp/90641)

2019-05-27 Thread Jakub Jelinek
Hi!

While on x86_64-linux as well as i686-linux inline_ordered_team_ids
array is long long aligned, on other targets like sparc solaris it is not
due to different sizes of mutexes/pointer locks.  The following patch makes
sure that the memory used for lastprivate conditional is always long long
aligned.

Bootstrapped/regtested on x86_64-linux and i686-linux, additionally Rainer
has kindly tested it on sparc-sun-solaris, committed to trunk.

2019-05-27  Jakub Jelinek  

PR libgomp/90641
* work.c (gomp_init_work_share): Instead of aligning final ordered
value to multiples of long long alignment, align to that the
first part (ordered team ids) and if inline_ordered_team_ids
is not on a long long alignment boundary within the structure,
use __alignof__ (long long) - 1 pad size always.
* loop.c (GOMP_loop_start): Fix *mem computation if
inline_ordered_team_ids is not aligned on long long alignment boundary
within the structure.
* loop-ull.c (GOMP_loop_ull_start): Likewise.
* sections.c (GOMP_sections2_start): Likewise.

--- libgomp/work.c.jj   2019-01-01 12:38:37.703653396 +0100
+++ libgomp/work.c  2019-05-27 13:49:04.513336631 +0200
@@ -110,9 +110,12 @@ gomp_init_work_share (struct gomp_work_s
 
   if (__builtin_expect (ordered != 1, 0))
{
- ordered += nthreads * sizeof (*ws->ordered_team_ids) - 1;
- ordered = ordered + __alignof__ (long long) - 1;
- ordered &= ~(__alignof__ (long long) - 1);
+ size_t o = nthreads * sizeof (*ws->ordered_team_ids);
+ o += __alignof__ (long long) - 1;
+ if ((offsetof (struct gomp_work_share, inline_ordered_team_ids)
+  & (__alignof__ (long long) - 1)) == 0)
+   o &= ~(__alignof__ (long long) - 1);
+ ordered += o - 1;
}
   else
ordered = nthreads * sizeof (*ws->ordered_team_ids);
--- libgomp/loop.c.jj   2019-01-01 12:38:37.514656497 +0100
+++ libgomp/loop.c  2019-05-27 14:12:10.355836249 +0200
@@ -267,14 +267,17 @@ GOMP_loop_start (long start, long end, l
   if (mem)
{
  uintptr_t size = (uintptr_t) *mem;
+#define INLINE_ORDERED_TEAM_IDS_OFF \
+  ((offsetof (struct gomp_work_share, inline_ordered_team_ids) \
++ __alignof__ (long long) - 1) & ~(__alignof__ (long long) - 1))
  if (size > (sizeof (struct gomp_work_share)
- - offsetof (struct gomp_work_share,
- inline_ordered_team_ids)))
-   thr->ts.work_share->ordered_team_ids
- = gomp_malloc_cleared (size);
+ - INLINE_ORDERED_TEAM_IDS_OFF))
+   *mem
+ = (void *) (thr->ts.work_share->ordered_team_ids
+ = gomp_malloc_cleared (size));
  else
-   memset (thr->ts.work_share->ordered_team_ids, '\0', size);
- *mem = (void *) thr->ts.work_share->ordered_team_ids;
+   *mem = memset (((char *) thr->ts.work_share)
+  + INLINE_ORDERED_TEAM_IDS_OFF, '\0', size);
}
   gomp_work_share_init_done ();
 }
@@ -287,7 +290,18 @@ GOMP_loop_start (long start, long end, l
  first_reductions);
}
   if (mem)
-   *mem = (void *) thr->ts.work_share->ordered_team_ids;
+   {
+ if ((offsetof (struct gomp_work_share, inline_ordered_team_ids)
+  & (__alignof__ (long long) - 1)) == 0)
+   *mem = (void *) thr->ts.work_share->ordered_team_ids;
+ else
+   {
+ uintptr_t p = (uintptr_t) thr->ts.work_share->ordered_team_ids;
+ p += __alignof__ (long long) - 1;
+ p &= ~(__alignof__ (long long) - 1);
+ *mem = (void *) p;
+   }
+   }
 }
 
   if (!istart)
--- libgomp/loop_ull.c.jj   2019-01-01 12:38:37.893650279 +0100
+++ libgomp/loop_ull.c  2019-05-27 14:58:23.140888183 +0200
@@ -266,14 +266,17 @@ GOMP_loop_ull_start (bool up, gomp_ull s
   if (mem)
{
  uintptr_t size = (uintptr_t) *mem;
+#define INLINE_ORDERED_TEAM_IDS_OFF \
+  ((offsetof (struct gomp_work_share, inline_ordered_team_ids) \
++ __alignof__ (long long) - 1) & ~(__alignof__ (long long) - 1))
  if (size > (sizeof (struct gomp_work_share)
- - offsetof (struct gomp_work_share,
- inline_ordered_team_ids)))
-   thr->ts.work_share->ordered_team_ids
- = gomp_malloc_cleared (size);
+ - INLINE_ORDERED_TEAM_IDS_OFF))
+   *mem
+ = (void *) (thr->ts.work_share->ordered_team_ids
+ = gomp_malloc_cleared (size));
  else
-   memset (thr->ts.work_share->ordered_team_ids, '\0', size);
- *mem = (void *) thr->ts.work_share->ordered_team_ids;
+   *mem = memset (((char *) thr->ts.work_share)
+   

[C/C++ PATCH] Reject __builtin_{add,sub,mul}_overflow with pointer to const integer as last arg (PR c/90628)

2019-05-27 Thread Jakub Jelinek
Hi!

As the testcase shows, we are silently accepting writes into const
variables, because the type generic builtins don't have a prototype.

Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for
trunk?

2019-05-27  Jakub Jelinek  

PR c/90628
* c-common.c (check_builtin_function_arguments)
: Diagnose pointer to const qualified integer
as last argument.

* c-c++-common/builtin-arith-overflow-3.c: New test.

--- gcc/c-family/c-common.c.jj  2019-05-21 16:16:48.068973678 +0200
+++ gcc/c-family/c-common.c 2019-05-27 10:46:25.525968739 +0200
@@ -5995,6 +5995,13 @@ check_builtin_function_arguments (locati
"has pointer to boolean type", fndecl);
  return false;
}
+ else if (TYPE_READONLY (TREE_TYPE (TREE_TYPE (args[2]
+   {
+ error_at (ARG_LOCATION (2), "argument 3 in call to function %qE "
+   "has pointer type to % qualified integer",
+   fndecl);
+ return false;
+   }
  return true;
}
   return false;
--- gcc/testsuite/c-c++-common/builtin-arith-overflow-3.c.jj2019-05-27 
10:51:46.829710217 +0200
+++ gcc/testsuite/c-c++-common/builtin-arith-overflow-3.c   2019-05-27 
10:53:10.972330933 +0200
@@ -0,0 +1,42 @@
+/* PR c/90628 */
+/* { dg-do compile } */
+
+const int a = 1, b = 2, c = 3;
+const long d = 4, e = 5, f = 6;
+const long long g = 7, h = 8, i = 9;
+
+void
+f1 ()
+{
+  __builtin_add_overflow (a, b, &c);   /* { dg-error "argument 3 in call to 
function '__builtin_add_overflow' has pointer type to 'const' qualified 
integer" } */
+}
+
+void
+f2 ()
+{
+  __builtin_sub_overflow (d, e, &f);   /* { dg-error "argument 3 in call to 
function '__builtin_sub_overflow' has pointer type to 'const' qualified 
integer" } */
+}
+
+void
+f3 ()
+{
+  __builtin_mul_overflow (g, h, &i);   /* { dg-error "argument 3 in call to 
function '__builtin_mul_overflow' has pointer type to 'const' qualified 
integer" } */
+}
+
+void
+f4 ()
+{
+  __builtin_sadd_overflow (a, b, &c);  /* { dg-warning "passing argument 3 of 
'__builtin_sadd_overflow' discards 'const' qualifier from pointer target type" 
"" { target c } } */
+}  /* { dg-error "invalid conversion from 'const int\\*' to 'int\\*'" "" { 
target c++ } .-1 } */
+
+void
+f5 ()
+{
+  __builtin_ssubl_overflow (d, e, &f); /* { dg-warning "passing argument 3 of 
'__builtin_ssubl_overflow' discards 'const' qualifier from pointer target type" 
"" { target c } } */
+}  /* { dg-error "invalid conversion from 'const long int\\*' to 'long 
int\\*'" "" { target c++ } .-1 } */
+
+void
+f6 ()
+{
+  __builtin_smulll_overflow (g, h, &i);/* { dg-warning "passing 
argument 3 of '__builtin_smulll_overflow' discards 'const' qualifier from 
pointer target type" "" { target c } } */
+}  /* { dg-error "invalid conversion from 'const long long int\\*' to 
'long long int\\*'" "" { target c++ } .-1 } */

Jakub


Re: Hashtable comment cleanups & renamings

2019-05-27 Thread François Dumont
I had miss some occurences of __bucket_hint to replace with 
__bucket_count_hint so here is a new version.


Ok to commit with the simple ChangeLog entry below ?


On 5/21/19 7:42 AM, François Dumont wrote:

Here is a simplified form.

    Rename variables and cleanup comments.
    * include/bits/hashtable_policy.h
    * include/bits/hashtable.h

Ok to commit ?

François

On 5/17/19 10:24 PM, Jonathan Wakely wrote:

On 17/05/19 18:19 +0200, François Dumont wrote:

Hi

    I got tired of '__n' being used in _Hashtable for many different 
purposes: node, bucket, bucket count, bucket hint. It makes the code 
difficult to read. This code makes sure that __n is a node except is 
some very limited use cases where the method name is clear enough to 
tell what __n means.


    So I'd like to commit this patch which only change that and some 
comments before moving forward to more serious stuff. The only code 
change is a use of auto return type on _M_allocate_node.


    My main concern is the ChangeLog entry. Is the following entry ok ?

    Rename variables and cleanup comments.
    * include/bits/hashtable_policy.h
    * include/bits/hashtable.h

    Tested under Linux x86_64 (even if it can't be otherwise)

François




@@ -350,24 +347,24 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
  _M_base_alloc() { return *this; }

  __bucket_type*
-  _M_allocate_buckets(size_type __n)
+  _M_allocate_buckets(size_type __bkt_count)


This is a much more helpful name, thanks.


@@ -439,30 +436,31 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
  { }

  explicit
-  _Hashtable(size_type __n,
+  _Hashtable(size_type __bkt_hint,


This seems less helpful. Would __num_bkts_hint be clearer?
Or for consistency, __bkt_count_hint?


@@ -1415,9 +1414,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
    -> iterator
    {
  __hash_code __code = this->_M_hash_code(__k);
-  std::size_t __n = _M_bucket_index(__k, __code);
-  __node_type* __p = _M_find_node(__n, __k, __code);
-  return __p ? iterator(__p) : end();
+  std::size_t __bkt = _M_bucket_index(__k, __code);
+  __node_type* __n = _M_find_node(__bkt, __k, __code);
+  return __n ? iterator(__n) : end();


Is __n really an improvement over __p here?

If you're changing it, __node or __ptr might be an improvement, but
changing __p to __n seems like unnecessary churn.

I'm not convinced that __n is a big enough improvement over __p to
bother changing dozens of lines, for not much benefit. All those
changes will make it slower to use git blame to track down when thigns
changed, and will make it harder to review diffs between trunk and
older branches.



@@ -1479,17 +1478,17 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
    -> pair
    {
  __hash_code __code = this->_M_hash_code(__k);
-  std::size_t __n = _M_bucket_index(__k, __code);
-  __node_type* __p = _M_find_node(__n, __k, __code);
+  std::size_t __bkt = _M_bucket_index(__k, __code);
+  __node_type* __n = _M_find_node(__bkt, __k, __code);

-  if (__p)
+  if (__n)
{
-  __node_type* __p1 = __p->_M_next();
-  while (__p1 && _M_bucket_index(__p1) == __n
- && this->_M_equals(__k, __code, __p1))
-    __p1 = __p1->_M_next();
+  __node_type* __n1 = __n->_M_next();


__p1 is not a good name, but __n1 is no better.

At least with __p the second pointer could be __q, which is a fairly
idiomatic pairing of letters :-)

How about __first and __last? Or __n and __next?  Even __n1 and __n2
seems better than __n and __n1. Those pointers end up being used for
the 'first' and 'second' members of a pair, so __n1 and __n2 makes
more sense than setting 'first' from __n and 'second' from __n1.

But I don't feel strongly about it, so if it's just me who dislikes
__n and __n1 then it doesn't matter.

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

index a4d2a97f4f3..bb2e7b762ff 100644
--- a/libstdc++-v3/include/bits/hashtable_policy.h
+++ b/libstdc++-v3/include/bits/hashtable_policy.h
@@ -181,7 +181,7 @@ namespace __detail
   *  @tparam _Cache_hash_code  Boolean value. True if the value of
   *  the hash function is stored along with the value. This is a
   *  time-space tradeoff.  Storing it may improve lookup speed by
-   *  reducing the number of times we need to call the _Equal
+   *  reducing the number of times we need to call the _Hash


Doesn't it reduce both?

In _M_equals we don't bother calling the _Equal predicate if the
cached hash code doesn't match the one for the key we're comparing.







diff --git a/libstdc++-v3/include/bits/hashtable.h b/libstdc++-v3/include/bits/hashtable.h
index ab24b5bb537..33711ea4573 100644
--- a/libstdc++-v3/include/bits/hashtable.h
+++ b/libstdc++-v3/include/bits/hashtable.h
@@ -253,7 +253,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 	_Equal, _H1, _H2, _Hash,
 	_RehashPolicy, _Traits>;
 
-  using __reuse_or_alloc_node_type =
+  using __reuse_or_alloc_node_gen_t =
 

Re: Make possible 'scan-tree-dump' of 'lower_omp_target' mapping kinds

2019-05-27 Thread Jakub Jelinek
On Mon, May 27, 2019 at 09:05:06PM +0200, Thomas Schwinge wrote:
> > The arrays are emitted in the *.omplower dump, so I think it is much better
> > to scan-tree-dump their content
> 
> That's not feasible in the general case.

Why?  The arrays have easily parseable names (.omp_data_kinds.N), then they
have an initializer and you can easily write a regexp to say match 3
occurences of the firstprivate int kind constant in there.

> > if for whatever reason adding a runtime
> > testcase isn't sufficient
> 
> Why should I have an execution test for something that should really be
> verified at the compiler side, at compile time?  And, for example, an

Generally a runtime test can check all compilation phases, linking, runtime,
while what looks like a unit test only tests a small portion of that.
> 
> > over adding further printouts and matching that.
> 
> I had assumed that you'd noticed that a lot of compiler passes are
> dumping stuff that can then be scanned for.  Are you insisting that GCC's

Usually the detailed messages in the dump print why certain changes are
done, or other information that is not readily available in the dump
already.  I'm not convinced what you are doing brings anything that isn't
there already.

Jakub


gotools patch committed: Only chmod check-go-dir if it exists

2019-05-27 Thread Ian Lance Taylor
This patch tweaks the gotools Makefile to only chmod check-go-dir if
it exists.  This avoids a pointless error message in a fresh build.
Bootstrapped and ran gotools tests on x86_64-pc-linux-gnu.  Committed
to mainline.

Ian

2019-05-27  Ian Lance Taylor  

* Makefile.am (check-go-tool): Only chmod check-go-dir if it
exists.
* Makefile.in: Regenerate.
Index: Makefile.am
===
--- Makefile.am (revision 271666)
+++ Makefile.am (working copy)
@@ -207,7 +207,7 @@ ECHO_ENV = PATH=`echo $(abs_builddir):$$
 
 # check-go-tool runs `go test cmd/go` in our environment.
 check-go-tool: go$(EXEEXT) $(noinst_PROGRAMS) check-head check-gccgo check-gcc
-   -chmod -R u+w check-go-dir
+   if test -d check-go-dir; then chmod -R u+w check-go-dir; fi
rm -rf check-go-dir cmd_go-testlog
$(MKDIR_P) check-go-dir/src/cmd/go
cp $(cmdsrcdir)/go/*.go check-go-dir/src/cmd/go/


Re: Make possible 'scan-tree-dump' of 'lower_omp_target' mapping kinds

2019-05-27 Thread Thomas Schwinge
Hi!

On Mon, 27 May 2019 18:51:22 +0200, Jakub Jelinek  wrote:
> On Sun, May 26, 2019 at 06:46:19PM +0200, Thomas Schwinge wrote:
> > To establish some suitable testsuite coverage for a task that I'm working
> > on, I need to do 'scan-tree-dump' of 'lower_omp_target' mapping kinds.
> > Is the attached OK?
> > 
> > Any suggestions about whether/how to restrict the (effective?) targets
> > this gets run for, because no doubt there are target-specific bits at
> > least in the alignment chosen.  The attached test case passes for
> > x86_64-pc-linux-gnu with '--target_board=unix\{,-m32,-mx32\}'.  (I didn't
> > verify the mappings generated, but just documented the status quo.)
> 
> The arrays are emitted in the *.omplower dump, so I think it is much better
> to scan-tree-dump their content

That's not feasible in the general case.

> if for whatever reason adding a runtime
> testcase isn't sufficient

Why should I have an execution test for something that should really be
verified at the compiler side, at compile time?  And, for example, an
execution test cannot detect if a 'GOMP_MAP_FIRSTPRIVATE_INT' is being
used (instead of something else).

> over adding further printouts and matching that.

I had assumed that you'd noticed that a lot of compiler passes are
dumping stuff that can then be scanned for.  Are you insisting that GCC's
OMP code must be complex and unmaintainable?


Current version of that patch is attached: changed to generally print
'kind' first, and don't print non-existing 'align' for
'OMP_CLAUSE_USE_DEVICE_PTR', 'OMP_CLAUSE_IS_DEVICE_PTR'.

If approving this patch, please respond with "Reviewed-by: NAME "
so that your effort will be recorded in the commit log, see
.


Grüße
 Thomas


>From 30a64c6cf7b8096f27836c62f434eb4bc0ebe966 Mon Sep 17 00:00:00 2001
From: Thomas Schwinge 
Date: Mon, 27 May 2019 18:21:15 +0200
Subject: [PATCH] Make possible 'scan-tree-dump' of 'lower_omp_target' mapping
 kinds

	gcc/
	* omp-low.c (lower_omp_target): Dump mapping kinds.
	gcc/testsuite/
	* c-c++-common/gomp/lower_omp_target-mappings-1.c: New file.
---
 gcc/omp-low.c | 102 +++---
 .../gomp/lower_omp_target-mappings-1.c|  50 +
 2 files changed, 136 insertions(+), 16 deletions(-)
 create mode 100644 gcc/testsuite/c-c++-common/gomp/lower_omp_target-mappings-1.c

diff --git a/gcc/omp-low.c b/gcc/omp-low.c
index faab5d384280..bbeac7f61846 100644
--- a/gcc/omp-low.c
+++ b/gcc/omp-low.c
@@ -9218,15 +9218,23 @@ lower_omp_taskreg (gimple_stmt_iterator *gsi_p, omp_context *ctx)
 static void
 lower_omp_target (gimple_stmt_iterator *gsi_p, omp_context *ctx)
 {
+  pretty_printer pp;
   tree clauses;
   tree child_fn, t, c;
   gomp_target *stmt = as_a  (gsi_stmt (*gsi_p));
   gbind *tgt_bind, *bind, *dep_bind = NULL;
   gimple_seq tgt_body, olist, ilist, fplist, new_body;
   location_t loc = gimple_location (stmt);
+  const char *loc_str = NULL;
   bool offloaded, data_region;
   unsigned int map_cnt = 0;
 
+  if (dump_file && (dump_flags & TDF_DETAILS))
+{
+  dump_location (&pp, loc);
+  loc_str = pp_formatted_text (&pp);
+}
+
   offloaded = is_gimple_omp_offloaded (stmt);
   switch (gimple_omp_target_kind (stmt))
 {
@@ -9687,7 +9695,8 @@ lower_omp_target (gimple_stmt_iterator *gsi_p, omp_context *ctx)
 	if (TREE_CODE (s) != INTEGER_CST)
 	  TREE_STATIC (TREE_VEC_ELT (t, 1)) = 0;
 
-	unsigned HOST_WIDE_INT tkind, tkind_zero;
+	unsigned HOST_WIDE_INT tkind, tkind_align;
+	unsigned HOST_WIDE_INT tkind_zero, tkind_zero_align;
 	switch (OMP_CLAUSE_CODE (c))
 	  {
 	  case OMP_CLAUSE_MAP:
@@ -9743,25 +9752,43 @@ lower_omp_target (gimple_stmt_iterator *gsi_p, omp_context *ctx)
  < (HOST_WIDE_INT_C (1U) << talign_shift));
 	gcc_checking_assert (tkind_zero
  < (HOST_WIDE_INT_C (1U) << talign_shift));
-	talign = ceil_log2 (talign);
-	tkind |= talign << talign_shift;
-	tkind_zero |= talign << talign_shift;
-	gcc_checking_assert (tkind
+	{
+	  unsigned int talign2 = ceil_log2 (talign);
+	  tkind_align = tkind | (talign2 << talign_shift);
+	  tkind_zero_align = tkind_zero | (talign2 << talign_shift);
+	}
+	gcc_checking_assert (tkind_align
  <= tree_to_uhwi (TYPE_MAX_VALUE (tkind_type)));
-	gcc_checking_assert (tkind_zero
+	gcc_checking_assert (tkind_zero_align
  <= tree_to_uhwi (TYPE_MAX_VALUE (tkind_type)));
-	if (tkind == tkind_zero)
-	  x = build_int_cstu (tkind_type, tkind);
+	if (tkind_align == tkind_zero_align)
+	  x = build_int_cstu (tkind_type, tkind_align);
 	else
 	  {
 		TREE_STATIC (TREE_VEC_ELT (t, 2)) = 0;
 		x = build3 (COND_EXPR, tkind_type,
 			fold_build2 (EQ_EXPR, boolean_type_node,
 	 unshare_expr (s), size_zero_node),
-			build_int_cstu (tkind_type, tkind_zero),
-			build_int_cstu (tkind_type, tkind));
+			build_int_cstu (tkind_type, tkind_zero_align),
+	

[PATCH, i386]: Use generic gen_{add2,add3,sub2,sub3}_insn functions instead of ix86_gen_* global indirect functions

2019-05-27 Thread Uros Bizjak
... instead of ix86_gen_* global indirect functions to genreate Pmode
add and sub functions. Finally, the patch removes all ix86_gen_*
global indirect functions.

No functional changes.

2019-05-27  Uroš Bizjak  

* config/i386/i386.c (ix86_gen_add3): Remove indirect function.
(*ix86_gen_sub3): Ditto.
(*ix86_gen_sub3_carry): Ditto.
(*ix86_gen_one_cmpl2): Ditto.
(*ix86_gen_andsp): Ditto.
(ix86_init_large_pic_reg): Use gen_add2_insn instead of ix86_gen_add3.
(gen_and2_insn): New static function.
(ix86_expand_prologue): Use gen_and2_insn instead of ix86_gen_andsp.
Use gen_add3_insn instead of ix86_gen_add3.
(ix86_expand_split_stack_prologue): Use gen_add2_insn
instead of ix86_gen_add3.
(legitimize_tls_address): Use gen_add2_insn instead of ix86_gen_add3.
Use gen_sub3_insn instead of ix86_gen_sub3.
* config/i386-expand.c (ix86_split_long_move): Use gen_add2_insn
instead of ix86_gen_add3.
(ix86_expand_strlensi_unroll_1): Use gen_add2_insn instead of
ix86_gen_add3.  Use gen_sub3_insn instead of ix86_gen_sub3.
(construct_plt_address): Use gen_add2_insn instead of ix86_gen_add3.
* config/i386/i386-options.c (ix86_option_override_internal):
Do not initialize ix86_gen_add3, ix86_gen_sub3, ix86_gen_sub3_carry,
ix86_gen_one_cmpl2 and ix86_gen_andsp.

Bootstrapped and regression tested on x86_64-linux-gnu {,-m32}.

Committed to mainline SVN.

Uros.
diff --git a/gcc/config/i386/i386-expand.c b/gcc/config/i386/i386-expand.c
index 06ed1078ca46..9f9069a5fb96 100644
--- a/gcc/config/i386/i386-expand.c
+++ b/gcc/config/i386/i386-expand.c
@@ -5380,8 +5380,7 @@ ix86_split_long_move (rtx operands[])
  if (nparts == 3)
{
  if (TARGET_128BIT_LONG_DOUBLE && mode == XFmode)
-emit_insn (ix86_gen_add3 (stack_pointer_rtx,
- stack_pointer_rtx, GEN_INT (-4)));
+emit_insn (gen_add2_insn (stack_pointer_rtx, GEN_INT (-4)));
  emit_move_insn (part[0][2], part[1][2]);
}
  else if (nparts == 4)
@@ -7789,7 +7788,7 @@ ix86_expand_strlensi_unroll_1 (rtx out, rtx src, rtx 
align_rtx)
   QImode, 1, end_0_label);
 
   /* Increment the address.  */
-  emit_insn (ix86_gen_add3 (out, out, const1_rtx));
+  emit_insn (gen_add2_insn (out, const1_rtx));
 
   /* Not needed with an alignment of 2 */
   if (align != 2)
@@ -7799,7 +7798,7 @@ ix86_expand_strlensi_unroll_1 (rtx out, rtx src, rtx 
align_rtx)
  emit_cmp_and_jump_insns (mem, const0_rtx, EQ, NULL, QImode, 1,
   end_0_label);
 
- emit_insn (ix86_gen_add3 (out, out, const1_rtx));
+ emit_insn (gen_add2_insn (out, const1_rtx));
 
  emit_label (align_3_label);
}
@@ -7807,7 +7806,7 @@ ix86_expand_strlensi_unroll_1 (rtx out, rtx src, rtx 
align_rtx)
   emit_cmp_and_jump_insns (mem, const0_rtx, EQ, NULL, QImode, 1,
   end_0_label);
 
-  emit_insn (ix86_gen_add3 (out, out, const1_rtx));
+  emit_insn (gen_add2_insn (out, const1_rtx));
 }
 
   /* Generate loop to check 4 bytes at a time.  It is not a good idea to
@@ -7817,7 +7816,7 @@ ix86_expand_strlensi_unroll_1 (rtx out, rtx src, rtx 
align_rtx)
 
   mem = change_address (src, SImode, out);
   emit_move_insn (scratch, mem);
-  emit_insn (ix86_gen_add3 (out, out, GEN_INT (4)));
+  emit_insn (gen_add2_insn (out, GEN_INT (4)));
 
   /* This formula yields a nonzero result iff one of the bytes is zero.
  This saves three branches inside loop and many cycles.  */
@@ -7871,7 +7870,7 @@ ix86_expand_strlensi_unroll_1 (rtx out, rtx src, rtx 
align_rtx)
 
/* Not in the first two.  Move two bytes forward.  */
emit_insn (gen_lshrsi3 (tmpreg, tmpreg, GEN_INT (16)));
-   emit_insn (ix86_gen_add3 (out, out, const2_rtx));
+   emit_insn (gen_add2_insn (out, const2_rtx));
 
emit_label (end_2_label);
 
@@ -7882,7 +7881,7 @@ ix86_expand_strlensi_unroll_1 (rtx out, rtx src, rtx 
align_rtx)
   emit_insn (gen_addqi3_cconly_overflow (tmpreg, tmpreg));
   tmp = gen_rtx_REG (CCmode, FLAGS_REG);
   cmp = gen_rtx_LTU (VOIDmode, tmp, const0_rtx);
-  emit_insn (ix86_gen_sub3_carry (out, out, GEN_INT (3), tmp, cmp));
+  emit_insn (gen_sub3_carry (Pmode, out, out, GEN_INT (3), tmp, cmp));
 
   emit_label (end_0_label);
 }
@@ -7915,7 +7914,7 @@ if (TARGET_UNROLL_STRLEN
   /* strlensi_unroll_1 returns the address of the zero at the end of
 the string, like memchr(), so compute the length by subtracting
 the start address.  */
-  emit_insn (ix86_gen_sub3 (out, out, addr));
+  emit_insn (gen_sub2_insn (out, addr));
   return true;
 }
   else
@@ -7938,7 +7937,7 @@ construct_plt_address (rtx symbol)
   unspec = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, symbol), UNSPEC_PLTOFF);
 
   emit_move_insn (tmp, gen_rtx_CONST (Pmode, unspec));
-  emit_insn (ix8

[PATCH] rs6000: Fix sanitizer build (PR90639)

2019-05-27 Thread Segher Boessenkool
The assembler code needs to say it uses AltiVec instructions.

Tested on powerpc64-linux {-m32,-m64} and on powerpc64le-linux.
Committing to trunk.


2019-05-27  Segher Boessenkool  

libsanitizer/
PR target/90639
* tsan/tsan_rtl_ppc64.S: Add ".machine altivec".

---
 libsanitizer/tsan/tsan_rtl_ppc64.S | 1 +
 1 file changed, 1 insertion(+)

diff --git a/libsanitizer/tsan/tsan_rtl_ppc64.S 
b/libsanitizer/tsan/tsan_rtl_ppc64.S
index 8285e21..9e533a7 100644
--- a/libsanitizer/tsan/tsan_rtl_ppc64.S
+++ b/libsanitizer/tsan/tsan_rtl_ppc64.S
@@ -1,5 +1,6 @@
 #include "tsan_ppc_regs.h"
 
+.machine altivec
 .section .text
 .hidden __tsan_setjmp
 .globl _setjmp
-- 
1.8.3.1



Re: [PATCH,RFC 0/3] Support for CTF in GCC

2019-05-27 Thread Indu Bhagat

Hi Michael,

On 05/24/2019 06:04 AM, Michael Matz wrote:

Hello,

On Thu, 23 May 2019, Indu Bhagat wrote:


OK.  So I wonder how difficult it is to emit CTF by walking dwarf2outs own
data structures?  That is, in my view CTF should be emitted by
dwarf2out_early_finish ()  (which is also the point LTO type/decl debug
is generated from).  It would be nice to avoid extra bookkeeping data
structures
for CTF since those of DWARF should include all necessary information
already.

CTF format has some characteristics which make it necessary to "pre-process"
the generated CTF data before asm'ing out into a section. E.g. few cases of
why "pre-processing" CTF is required before asm'ing out :
  1. CTF types do need to be emitted in "some" order :
 CTF types can have references to other CTF types. This consequently
 implies
 that the referenced type must appear BEFORE the referring type.
  2. CTF preamble holds offsets to the various subsections - function info,
 variables, data types and CTF string table. To calculate the offsets, the
 compiler needs to know the size in bytes of these sub-sections.  CTF
 representation for some types like structures, functions, enums have
 variable length of bytes trailing them (depending on the defintion of the
 type).
  3. CTF variable entries need to be placed in the order of the names.

Because of some of these "features" of the CTF format, the compiler does
need to do a transition from runtime CTF generated data --> CTF binary
data format for a clean and readable code.

Sure, but this whole process could still be triggered from within
dwarf2out_early_finish, by walking the DWARF tree (instead of getting fed
types and decls via hooks) and generating the appropriate CTF data
structures.  (It's just a possibility, it might end up uglier that using
GCC trees)


I think not only is the code messier, but it's also wasted effort if user only
wants to generate CTF.


Imagine a world where debug hooks wouldn't exist (which is where we would
like to end up in a far away future), how would you then add CTF debug
info to the compiler (assuming it already emits DWARF)?  You would hook
yourself either into the DWARF routines that currently are fed the
entities or you would hook yourself into somewhere late in the pipeline
where the DWARF debug info is complete and you would generate CTF from
that.


So, I think the needs are different enough to vouch for an implementation
segregated from dwarf* codebase.

Of course.  We are merely discussing of where the triggering of processing
starts: debug hooks, or something like:

dwarf2out_early_finish() {
   ...
   if (ctf)
 ctf_emit();
}

(and then in addition if the current DWARF info would be the source of CTF
info, or if it'd be whatever the compiler gives you as trees)

The thing is, with debug hooks you'd have to invent a scheme of stacking
hooks on top of each other (because we want to generate DWARF and CTF from
the same compilation).  That seems like a wasted effort when our wish is
for the hooks to go away alltogether.


When the debug hooks go away, the functionality can be folded in. Much like
above, the ctf proposed implementation will do :

ctf_early_global_decl (tree decl)
{
  ctf_decl (decl);

  real_debug_hooks->early_global_decl (decl);
}

These ctf_* debug hooks wrappers are as lean as shown above.

I do understand now that if debug hooks are destined to go away, all the
implementation which wraps debug hooks (go dump hooks, vms debug hooks,
and now the proposed ctf debug hooks) will need some merging. But to generate
CTF, I think working on type or decl instead of DWARF dies to is a better
implementation because if user wants only CTF, no DWARF trees need to be
created.

This way we keep DWARF and CTF generation independent of each other (as the
user may want either one of these or both).


Ciao,
Michael.




Re: Make possible 'scan-tree-dump' of 'lower_omp_target' mapping kinds

2019-05-27 Thread Jakub Jelinek
On Sun, May 26, 2019 at 06:46:19PM +0200, Thomas Schwinge wrote:
> To establish some suitable testsuite coverage for a task that I'm working
> on, I need to do 'scan-tree-dump' of 'lower_omp_target' mapping kinds.
> Is the attached OK?
> 
> Any suggestions about whether/how to restrict the (effective?) targets
> this gets run for, because no doubt there are target-specific bits at
> least in the alignment chosen.  The attached test case passes for
> x86_64-pc-linux-gnu with '--target_board=unix\{,-m32,-mx32\}'.  (I didn't
> verify the mappings generated, but just documented the status quo.)

The arrays are emitted in the *.omplower dump, so I think it is much better
to scan-tree-dump their content if for whatever reason adding a runtime
testcase isn't sufficient over adding further printouts and matching that.

Jakub


Re: [gomp] Add langhook, so that Fortran can privatize variables by reference

2019-05-27 Thread Jakub Jelinek
On Sun, May 26, 2019 at 07:43:04PM +0200, Thomas Schwinge wrote:
> On Tue, 18 Oct 2005 03:01:40 -0400, Jakub Jelinek  wrote:
> > --- gcc/omp-low.c.jj2005-10-15 12:00:06.0 +0200
> > +++ gcc/omp-low.c   2005-10-18 08:46:23.0 +0200
> > @@ -126,7 +126,7 @@ is_variable_sized (tree expr)
> >  static inline bool
> >  is_reference (tree decl)
> >  {
> > -  return TREE_CODE (TREE_TYPE (decl)) == REFERENCE_TYPE;
> > +  return lang_hooks.decls.omp_privatize_by_reference (decl);
> >  }
> 
> With the same implementation, this function nowadays is known as
> 'omp_is_reference' ('gcc/omp-general.c'), and is used in 'omp-*' files
> only.  The gimplifier directly calls
> 'lang_hooks.decls.omp_privatize_by_reference'.
> 
> Will it be OK to commit the obvious patch to get rid of the
> 'omp_is_reference' function?  Whenever I see it used in 'omp-*' files, I

No, omp_is_reference (something) is certainly more readable from
lang_hooks.decls.omp_privatize_by_reference (something), which is quite
long and would cause major issues in formatting etc.

What advantage do you see in removing that?

> wonder and have to look up what special things it might be doing -- but
> it actually isn't.
> 
>   gcc/
> * omp-general.c (omp_is_reference): Don't define.  Adjust all users.

Jakub


[PATCH, i386]: Define STACK_SIZE_MODE

2019-05-27 Thread Uros Bizjak
STACK_SIZE_MODE should be defined together with "allocate_stack" named pattern.

2019-05-27  Uroš Bizjak  

* config/i386/i386.h (STACK_SIZE_MODE): Define.

Bootstrapped and regression tested on x86_64-linux-gnu {,-m32}.

Committed to mainline SVN.

Uros.
Index: config/i386/i386.h
===
--- config/i386/i386.h  (revision 271662)
+++ config/i386/i386.h  (revision 271663)
@@ -1947,6 +1947,10 @@
 #define STACK_SAVEAREA_MODE(LEVEL) \
   ((LEVEL) == SAVE_NONLOCAL ? (TARGET_64BIT ? TImode : DImode) : Pmode)
 
+/* Specify the machine_mode of the size increment
+   operand of an 'allocate_stack' named pattern.  */
+#define STACK_SIZE_MODE Pmode
+
 /* A C expression whose value is zero if pointers that need to be extended
from being `POINTER_SIZE' bits wide to `Pmode' are sign-extended and
greater then zero if they are zero-extended and less then zero if the


Re: Simplify more EXACT_DIV_EXPR comparisons

2019-05-27 Thread Aldy Hernandez




I don't know if there's the -Walloca pass would benefit from merging
with any of the others or vice versa, but superficially it seems like
it might be worth thinking about integrating the -Walloc-larger-than
warnings into the -Walloca pass, if only to keep similar functionality
in the same place.


My original code was in the VRP pass and I can't remember whether it was
you or Jeff that suggested a separate pass so we'd stop polluting VRP
with everything but the kitchen sink.


Specifically for VRP the reason is I'd like to see it go away...


You're preaching to the choir here :).

Aldy


Re: [patch] Fix ICE in resolve_args_picking_1 with -gsplit-dwarf

2019-05-27 Thread Richard Biener
On Mon, May 27, 2019 at 10:32 AM Eric Botcazou  wrote:
>
> The function simply doesn't handle the new location expression opcodes coming
> from DebugFission (https://gcc.gnu.org/wiki/DebugFission).  Fixed by making it
> handle them like DW_OP_addr and DW_OP_const*.
>
> OK for mainline and the active branches (it's a regression from GCC 5)?

OK.

>
> 2019-05-27  Eric Botcazou  
>
> * dwarf2out.c (resolve_args_picking_1): Deal with DW_OP_GNU_addr_index
> and DW_OP_GNU_const_index opcodes.
>
>
> 2019-05-27  Eric Botcazou  
>
> * gnat.dg/specs/array4.ads: New test.
>
> --
> Eric Botcazou


Re: Simplify more EXACT_DIV_EXPR comparisons

2019-05-27 Thread Richard Biener
On Mon, May 27, 2019 at 3:09 PM Aldy Hernandez  wrote:
>
>
>
> On 5/21/19 5:53 AM, Richard Biener wrote:
> > On Tue, May 21, 2019 at 4:13 AM Martin Sebor  wrote:
> >>
> >> On 5/20/19 3:16 AM, Richard Biener wrote:
> >>> On Mon, May 20, 2019 at 10:16 AM Marc Glisse  wrote:
> 
>  On Mon, 20 May 2019, Richard Biener wrote:
> 
> > On Sun, May 19, 2019 at 6:16 PM Marc Glisse  
> > wrote:
> >>
> >> Hello,
> >>
> >> 2 pieces:
> >>
> >> - the first one handles the case where the denominator is negative. It
> >> doesn't happen often with exact_div, so I don't handle it everywhere, 
> >> but
> >> this one looked trivial
> >>
> >> - handle the case where a pointer difference is cast to an unsigned 
> >> type
> >> before being compared to a constant (I hit this in std::vector). With 
> >> some
> >> range info we could probably handle some non-constant cases as well...
> >>
> >> The second piece breaks Walloca-13.c (-Walloca-larger-than=100 -O2)
> >>
> >> void f (void*);
> >> void g (int *p, int *q)
> >> {
> >>  __SIZE_TYPE__ n = (__SIZE_TYPE__)(p - q);
> >>  if (n < 100)
> >>f (__builtin_alloca (n));
> >> }
> >>
> >> At the time of walloca2, we have
> >>
> >>  _1 = p_5(D) - q_6(D);
> >>  # RANGE [-2305843009213693952, 2305843009213693951]
> >>  _2 = _1 /[ex] 4;
> >>  # RANGE ~[2305843009213693952, 16140901064495857663]
> >>  n_7 = (long unsigned intD.10) _2;
> >>  _11 = (long unsigned intD.10) _1;
> >>  if (_11 <= 396)
> >> [...]
> >>  _3 = allocaD.1059 (n_7);
> >>
> >> and warn.
> >
> > That's indeed to complicated relation of _11 to n_7 for
> > VRP predicate discovery.
> >
> >> However, DOM3 later produces
> >>
> >>  _1 = p_5(D) - q_6(D);
> >>  _11 = (long unsigned intD.10) _1;
> >>  if (_11 <= 396)
> >
> > while _11 vs. _1 works fine.
> >
> >> [...]
> >>  # RANGE [0, 99] NONZERO 127
> >>  _2 = _1 /[ex] 4;
> >>  # RANGE [0, 99] NONZERO 127
> >>  n_7 = (long unsigned intD.10) _2;
> >>  _3 = allocaD.1059 (n_7);
> >>
> >> so I am tempted to say that the walloca2 pass is too early, xfail the
> >> testcase and file an issue...
> >
> > Hmm, there's a DOM pass before walloca2 already and moving
> > walloca2 after loop opts doesn't look like the best thing to do?
> > I suppose it's not DOM but sinking that does the important transform
> > here?  That is,
> >
> > Index: gcc/passes.def
> > ===
> > --- gcc/passes.def  (revision 271395)
> > +++ gcc/passes.def  (working copy)
> > @@ -241,9 +241,9 @@ along with GCC; see the file COPYING3.
> > NEXT_PASS (pass_optimize_bswap);
> > NEXT_PASS (pass_laddress);
> > NEXT_PASS (pass_lim);
> > -  NEXT_PASS (pass_walloca, false);
> > NEXT_PASS (pass_pre);
> > NEXT_PASS (pass_sink_code);
> > +  NEXT_PASS (pass_walloca, false);
> > NEXT_PASS (pass_sancov);
> > NEXT_PASS (pass_asan);
> > NEXT_PASS (pass_tsan);
> >
> > fixes it?
> 
>  I will check, but I don't think walloca uses any kind of on-demand VRP, 
>  so
>  we still need some pass to update the ranges after sinking, which doesn't
>  seem to happen until the next DOM pass.
> >>>
> >>> Oh, ok...  Aldy, why's this a separate pass anyways?  I think similar
> >>> other warnigns are emitted from RTL expansion?  So maybe we can
> >>> indeed move the pass towards warn_restrict or late_warn_uninit.
> >>
> >> I thought there was a preference to add new middle-end warnings
> >> into passes of their own rather than into existing passes.  Is
> >> that not so (either in general or in this specific case)?
> >
> > The preference was to add them not into optimization passes.  But
> > of course having 10+ warning passes, each going over the whole IL
> > is excessive.  Also each of the locally computing ranges or so.
> >
> > Given the simplicity of Walloca I wonder why it's not part of another
> > warning pass - since it's about tracking "sizes" again there are plenty
> > that fit ;)
> >
> >>   From my POV, the main (only?) benefit of putting warnings in their
> >> own passes is modularity.  Are there any others?
> >>
> >> The biggest drawback I see is that it makes it hard to then share
> >> data across multiple passes.  The sharing can help not just
> >> warnings (reduce both false positive and false negative rates) but
> >> also optimization.  That's why I'm merging the strlen and sprintf
> >> passes, and want to eventually also look into merging
> >> the -Wstringop-overflow warnings there (also emitted just before
> >> RTL expansion.  Did I miss any downsides?
> >
>

Re: Teach same_types_for_tbaa to structurally compare arrays, pointers and vectors

2019-05-27 Thread Jan Hubicka
Hi,
this is minimal version of patch adding just the pointer compare.
Bootstrapped/regtested x86_64-linux, makes sense? :)

Honza

* tree-ssa-alias.c (same_type_for_tbaa): Return 1 if types
same as pointers.

Index: tree-ssa-alias.c
===
--- tree-ssa-alias.c(revision 271599)
+++ tree-ssa-alias.c(working copy)
@@ -787,6 +787,10 @@ same_type_for_tbaa (tree type1, tree typ
   type1 = TYPE_MAIN_VARIANT (type1);
   type2 = TYPE_MAIN_VARIANT (type2);
 
+  /* Handle common case.  */
+  if (type1 == type2)
+return 1;
+
   /* If we would have to do structural comparison bail out.  */
   if (TYPE_STRUCTURAL_EQUALITY_P (type1)
   || TYPE_STRUCTURAL_EQUALITY_P (type2))


Patch ping (was Re: [C++ PATCH] P1091R3 - Extending structured bindings to be more like var decls)

2019-05-27 Thread Jakub Jelinek
Hi!

On Mon, May 20, 2019 at 11:44:18PM +0200, Jakub Jelinek wrote:
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
> 
> 2019-05-20  Jakub Jelinek  
> 
>   P1091R3 - Extending structured bindings to be more like var decls
>   P1381R1 - Reference capture of structured bindings
>   * decl.c (cp_maybe_mangle_decomp): Handle TREE_STATIC decls even at
>   function scope.
>   (cp_finish_decomp): Copy over various decl properties from decl to
>   v[i] in the tuple case.
>   (grokdeclarator): Allow static, thread_local and __thread for C++2a
>   and use pedwarn instead of error for older standard revisions.
>   Make other structured binding diagnostic messages more i18n friendly.
> 
>   * g++.dg/cpp1z/decomp3.C (test): For static, expect only warning
>   instead of error and only for c++17_down.  Add a thread_local test.
>   (z2): Add a __thread test.
>   * g++.dg/cpp2a/decomp1.C: New test.
>   * g++.dg/cpp2a/decomp1-aux.cc: New file.
>   * g++.dg/cpp2a/decomp2.C: New test.
>   * g++.dg/cpp2a/decomp3.C: New test.

I'd like to ping this patch.

Thanks.

Jakub


Re: [PATCH] Fix PR88440, enable mem* detection at -O[2s]

2019-05-27 Thread Christophe Lyon
On Mon, 27 May 2019 at 09:26, Richard Biener  wrote:
>
> On Mon, 27 May 2019, Christophe Lyon wrote:
>
> > On Thu, 23 May 2019 at 13:32, Richard Biener  wrote:
> > >
> > > On Wed, 22 May 2019, Richard Biener wrote:
> > >
> > > >
> > > > This enables -ftree-loop-distribute-patterns at -O[2s] and also
> > > > arranges cold loops to be still processed but for pattern
> > > > recognition to save code-size.
> > > >
> > > > Bootstrap and regtest running on x86_64-unknown-linux-gnu.
> > > >
> > > > Martin has done extensive compile-time testing on SPEC
> > > > identifying only a single regression I'll have a look into.
> > >
> > > The reason for the compile-time regression is the complexity
> > > heuristic in LRA no longer choosing "simple" algorithms and
> > > the LIVE problem in particular being awfully slow.
> > >
> > > Unsurprisingly testing has also revealed loads of testsuite
> > > fallout which I deal with in the patch as committed below.
> > > Sorry for any further fallout on other targets (which I do
> > > expect).
> > >
> >
> > Hi 
> > Richard,http://people.linaro.org/~christophe.lyon/cross-validation/gcc/trunk/271588/report-build-info.html
> >
> > Indeed git bisect pointed me to this commit when checking
> > the regressions on arm & aarch64 reported at:
> > http://people.linaro.org/~christophe.lyon/cross-validation/gcc/trunk/271588/report-build-info.html
> >
> > Since I'm a bit later in reporting, I'm not sure you've fixed them already?
> > (I didn't notice follow-ups)
> > Looking at this patch, it seems adding -fno-tree-loop-distribute-patterns to
> > dg-options is the standard way of fixing the regressions?
>
> Yes.  As I wrote above I did expect some target specific fallout and
> hoped target maintainers would fix that.
>

OK, I've committed the attached patch as r271662.

Christophe

> Richard.
>
> > Christophe
> >
> > > Bootstrapped and tested on x86_64-unknown-linux-gnu, applied.
> > >
> > > Richard.
> > >
> > > 2019-05-23  Richard Biener  
> > >
> > > PR tree-optimization/88440
> > > * opts.c (default_options_table): Enable 
> > > -ftree-loop-distribute-patterns
> > > at -O[2s]+.
> > > * tree-loop-distribution.c (generate_memset_builtin): Fold the
> > > generated call.
> > > (generate_memcpy_builtin): Likewise.
> > > (distribute_loop): Pass in whether to only distribute patterns.
> > > (prepare_perfect_loop_nest): Also allow size optimization.
> > > (pass_loop_distribution::execute): When optimizing a loop
> > > nest for size allow pattern replacement.
> > >
> > > * gcc.dg/tree-ssa/ldist-37.c: New testcase.
> > > * gcc.dg/tree-ssa/ldist-38.c: Likewise.
> > > * gcc.dg/vect/vect.exp: Add -fno-tree-loop-distribute-patterns.
> > > * gcc.dg/tree-ssa/ldist-37.c: Adjust.
> > > * gcc.dg/tree-ssa/ldist-38.c: Likewise.
> > > * g++.dg/tree-ssa/pr78847.C: Likewise.
> > > * gcc.dg/autopar/pr39500-1.c: Likewise.
> > > * gcc.dg/autopar/reduc-1char.c: Likewise.
> > > * gcc.dg/autopar/reduc-7.c: Likewise.
> > > * gcc.dg/tree-ssa/ivopts-lt-2.c: Likewise.
> > > * gcc.dg/tree-ssa/ivopts-lt.c: Likewise.
> > > * gcc.dg/tree-ssa/predcom-dse-1.c: Likewise.
> > > * gcc.dg/tree-ssa/predcom-dse-2.c: Likewise.
> > > * gcc.dg/tree-ssa/predcom-dse-3.c: Likewise.
> > > * gcc.dg/tree-ssa/predcom-dse-4.c: Likewise.
> > > * gcc.dg/tree-ssa/prefetch-7.c: Likewise.
> > > * gcc.dg/tree-ssa/prefetch-8.c: Likewise.
> > > * gcc.dg/tree-ssa/prefetch-9.c: Likewise.
> > > * gcc.dg/tree-ssa/scev-11.c: Likewise.
> > > * gcc.dg/vect/costmodel/i386/costmodel-vect-31.c: Likewise.
> > > * gcc.dg/vect/costmodel/i386/costmodel-vect-33.c: Likewise.
> > > * gcc.dg/vect/costmodel/x86_64/costmodel-vect-31.c: Likewise.
> > > * gcc.dg/vect/costmodel/x86_64/costmodel-vect-33.c: Likewise.
> > > * gcc.target/i386/pr30970.c: Likewise.
> > > * gcc.target/i386/vect-double-1.c: Likewise.
> > > * gcc.target/i386/vect-double-2.c: Likewise.
> > > * gcc.dg/tree-ssa/gen-vect-2.c: Likewise.
> > > * gcc.dg/tree-ssa/gen-vect-26.c: Likewise.
> > > * gcc.dg/tree-ssa/gen-vect-28.c: Likewise.
> > > * gcc.dg/tree-ssa/gen-vect-32.c: Likewise.
> > > * gfortran.dg/vect/vect-5.f90: Likewise.
> > > * gfortran.dg/vect/vect-8.f90: Likewise.
> > >
> > > Index: gcc/opts.c
> > > ===
> > > --- gcc/opts.c  (revision 271513)
> > > +++ gcc/opts.c  (working copy)
> > > @@ -550,7 +550,7 @@ static const struct default_options defa
> > >  { OPT_LEVELS_3_PLUS, OPT_fpredictive_commoning, NULL, 1 },
> > >  { OPT_LEVELS_3_PLUS, OPT_fsplit_loops, NULL, 1 },
> > >  { OPT_LEVELS_3_PLUS, OPT_fsplit_paths, NULL, 1 },
> > > -{ OPT_LEVELS_3_PLUS, OPT_ftree_loop_distribute_patterns, NULL, 1 }

Re: Simplify more EXACT_DIV_EXPR comparisons

2019-05-27 Thread Aldy Hernandez




On 5/21/19 5:53 AM, Richard Biener wrote:

On Tue, May 21, 2019 at 4:13 AM Martin Sebor  wrote:


On 5/20/19 3:16 AM, Richard Biener wrote:

On Mon, May 20, 2019 at 10:16 AM Marc Glisse  wrote:


On Mon, 20 May 2019, Richard Biener wrote:


On Sun, May 19, 2019 at 6:16 PM Marc Glisse  wrote:


Hello,

2 pieces:

- the first one handles the case where the denominator is negative. It
doesn't happen often with exact_div, so I don't handle it everywhere, but
this one looked trivial

- handle the case where a pointer difference is cast to an unsigned type
before being compared to a constant (I hit this in std::vector). With some
range info we could probably handle some non-constant cases as well...

The second piece breaks Walloca-13.c (-Walloca-larger-than=100 -O2)

void f (void*);
void g (int *p, int *q)
{
 __SIZE_TYPE__ n = (__SIZE_TYPE__)(p - q);
 if (n < 100)
   f (__builtin_alloca (n));
}

At the time of walloca2, we have

 _1 = p_5(D) - q_6(D);
 # RANGE [-2305843009213693952, 2305843009213693951]
 _2 = _1 /[ex] 4;
 # RANGE ~[2305843009213693952, 16140901064495857663]
 n_7 = (long unsigned intD.10) _2;
 _11 = (long unsigned intD.10) _1;
 if (_11 <= 396)
[...]
 _3 = allocaD.1059 (n_7);

and warn.


That's indeed to complicated relation of _11 to n_7 for
VRP predicate discovery.


However, DOM3 later produces

 _1 = p_5(D) - q_6(D);
 _11 = (long unsigned intD.10) _1;
 if (_11 <= 396)


while _11 vs. _1 works fine.


[...]
 # RANGE [0, 99] NONZERO 127
 _2 = _1 /[ex] 4;
 # RANGE [0, 99] NONZERO 127
 n_7 = (long unsigned intD.10) _2;
 _3 = allocaD.1059 (n_7);

so I am tempted to say that the walloca2 pass is too early, xfail the
testcase and file an issue...


Hmm, there's a DOM pass before walloca2 already and moving
walloca2 after loop opts doesn't look like the best thing to do?
I suppose it's not DOM but sinking that does the important transform
here?  That is,

Index: gcc/passes.def
===
--- gcc/passes.def  (revision 271395)
+++ gcc/passes.def  (working copy)
@@ -241,9 +241,9 @@ along with GCC; see the file COPYING3.
NEXT_PASS (pass_optimize_bswap);
NEXT_PASS (pass_laddress);
NEXT_PASS (pass_lim);
-  NEXT_PASS (pass_walloca, false);
NEXT_PASS (pass_pre);
NEXT_PASS (pass_sink_code);
+  NEXT_PASS (pass_walloca, false);
NEXT_PASS (pass_sancov);
NEXT_PASS (pass_asan);
NEXT_PASS (pass_tsan);

fixes it?


I will check, but I don't think walloca uses any kind of on-demand VRP, so
we still need some pass to update the ranges after sinking, which doesn't
seem to happen until the next DOM pass.


Oh, ok...  Aldy, why's this a separate pass anyways?  I think similar
other warnigns are emitted from RTL expansion?  So maybe we can
indeed move the pass towards warn_restrict or late_warn_uninit.


I thought there was a preference to add new middle-end warnings
into passes of their own rather than into existing passes.  Is
that not so (either in general or in this specific case)?


The preference was to add them not into optimization passes.  But
of course having 10+ warning passes, each going over the whole IL
is excessive.  Also each of the locally computing ranges or so.

Given the simplicity of Walloca I wonder why it's not part of another
warning pass - since it's about tracking "sizes" again there are plenty
that fit ;)


  From my POV, the main (only?) benefit of putting warnings in their
own passes is modularity.  Are there any others?

The biggest drawback I see is that it makes it hard to then share
data across multiple passes.  The sharing can help not just
warnings (reduce both false positive and false negative rates) but
also optimization.  That's why I'm merging the strlen and sprintf
passes, and want to eventually also look into merging
the -Wstringop-overflow warnings there (also emitted just before
RTL expansion.  Did I miss any downsides?


When things fit together they are fine to merge obviously.

One may not like -Warray-bounds inside VRP but it really "fits".

OTOH making a warning part of an optimization pass naturally
limits its effect to when the specific optimization is enabled.
In theory it's possible to do -Warray-bounds at -O0 - we are in
SSA form after all - but of course you don't want to enable VRP at -O0.


I don't know if there's the -Walloca pass would benefit from merging
with any of the others or vice versa, but superficially it seems like
it might be worth thinking about integrating the -Walloc-larger-than
warnings into the -Walloca pass, if only to keep similar functionality
in the same place.


My original code was in the VRP pass and I can't remember whether it was 
you or Jeff that suggested a separate pass so we'd stop polluting VRP 
with everything but the kitchen sink.


Aldy


Re: [PATCH] Handle loop fields in IPA ICF (PR ipa/90555).

2019-05-27 Thread Jakub Jelinek
On Mon, May 27, 2019 at 02:18:37PM +0200, Martin Liška wrote:
> +/* Compare loop information for basic blocks BB1 and BB2.  */
> +
> +bool
> +func_checker::compare_loops (basic_block bb1, basic_block bb2)
> +{
> +  if ((bb1->loop_father == NULL) != (bb2->loop_father == NULL))
> +return return_false ();
> +
> +  struct loop *l1 = bb1->loop_father;
> +  struct loop *l2 = bb2->loop_father;

Perhaps also
  if ((bb1 == l1->header) != (bb2 == l2->header))
return return_false_with_msg ("header");
  if ((bb1 == l1->latch) != (bb2 == l2->latch))
return return_false_with_msg ("latch");
too?

BTW, unrelated to this patch, what does ICF do if e.g. SSA_NAME_PTR_INFO
or SSA_NAME_RANGE_INFO is different between otherwise identical functions?
Say one having early
  if (arg > 10)
__builtin_unreachable ();
and another one
  if (arg > - 10)
__builtin_unreachable ();
both optimized away into SSA_NAME_RANGE_INFO of the argument before IPA (or
do we optimize that away only after IPA?).

Jakub


Re: [PATCH] Handle loop fields in IPA ICF (PR ipa/90555).

2019-05-27 Thread Martin Liška
On 5/24/19 11:37 AM, Richard Biener wrote:
> On Fri, May 24, 2019 at 10:08 AM Jakub Jelinek  wrote:
>>
>> On Fri, May 24, 2019 at 09:48:03AM +0200, Martin Liška wrote:
>>> gcc/ChangeLog:
>>>
>>> 2019-05-23  Martin Liska  
>>>
>>>   PR ipa/90555
>>>   * ipa-icf-gimple.c (func_checker::compare_loops): New function.
>>>   * ipa-icf-gimple.h (func_checker::compare_loops): Likewise.
>>>   * ipa-icf.c (sem_function::equals_private): Use compare_loops.
>>>
>>> gcc/testsuite/ChangeLog:
>>>
>>> 2019-05-23  Martin Liska  
>>>
>>>   PR ipa/90555
>>>   * gcc.dg/ipa/pr90555.c: New test.
>>
>>> @@ -605,6 +606,45 @@ func_checker::compare_variable_decl (tree t1, tree t2)
>>>return return_with_debug (ret);
>>>  }
>>>
>>> +/* Compare significant loop information.  */
>>> +bool
>>> +func_checker::compare_loops (void)
>>> +{
>>> +  struct loop *loop;
>>> +
>>> +  auto_vec  loops1;
>>> +  auto_vec  loops2;
>>> +
>>> +  FOR_EACH_LOOP_FN (DECL_STRUCT_FUNCTION (m_source_func_decl), loop, 0)
>>> +loops1.safe_push (loop);
>>> +
>>> +  FOR_EACH_LOOP_FN (DECL_STRUCT_FUNCTION (m_target_func_decl), loop, 0)
>>> +loops2.safe_push (loop);
>>> +
>>> +  gcc_assert (loops1.length () == loops2.length ());
>>> +
>>> +  for (unsigned i = 0; i < loops1.length (); i++)
>>
>> I wonder how likely/unlikely it is that the loops will be ordered the same
>> by the iterators.  If they are the same always, then perhaps it would be
>> better to avoid the temporary vectors, and just do one FOR_EACH_LOOP_FN
>> with another manual loop_iterator use in sync with that.
>> If it isn't guaranteed they are ordered the same, then I think we need to
>> match the loops by the corresponding loop header and perhaps also verify
>> loop latch and other basic blocks in the loop?
> 
> In fact I wouldn't even compare loops this way but compare loop
> paris when I run across two equal basic-blocks that are loop
> headers (bb->loop_father == bb->loop_father->header).

That's definitely nicer.

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

Ready to be installed?
Thanks,
Martin

> 
>>> +{
>>> +  struct loop *l1 = loops1[i];
>>> +  struct loop *l2 = loops2[i];
>>> +  if (l1->simdlen != l2->simdlen)
>>> + return return_false_with_msg ("simdlen");
>>> +  if (l1->safelen != l2->safelen)
>>> + return return_false_with_msg ("safelen");
>>> +  if (l1->can_be_parallel != l2->can_be_parallel)
>>> + return return_false_with_msg ("can_be_parallel");
>>> +  if (l1->dont_vectorize != l2->dont_vectorize)
>>> + return return_false_with_msg ("dont_vectorize");
>>> +  if (l1->force_vectorize != l2->force_vectorize)
>>> + return return_false_with_msg ("force_vectorize");
>>> +  if (l1->unroll != l2->unroll)
>>> + return return_false_with_msg ("unroll");
>>> +  if (!compare_variable_decl (l1->simduid, l2->simduid))
>>> + return return_false_with_msg ("simduid");
>>
>> The above looks reasonable if we are guaranteed we are talking about a loop
>> corresponding between the two functions.
>>
>>> --- /dev/null
>>> +++ b/gcc/testsuite/gcc.dg/ipa/pr90555.c
>>> @@ -0,0 +1,67 @@
>>> +/* { dg-do compile } */
>>> +/* { dg-options "-fopenmp-simd -O2 -mavx512f -fdump-ipa-icf" } */
>>> +/* { dg-do compile { target i?86-*-* x86_64-*-* } } */
>>
>> Please don't use two dg-do compile directives, drop the first line,
>> move the third line to first one.
>>
>> Jakub

>From 306cab10e8ef918b25321132aa75d9400f7de247 Mon Sep 17 00:00:00 2001
From: Martin Liska 
Date: Thu, 23 May 2019 12:47:11 +0200
Subject: [PATCH] Handle loop fields in IPA ICF (PR ipa/90555).

gcc/ChangeLog:

2019-05-23  Martin Liska  

	PR ipa/90555
	* ipa-icf-gimple.c (func_checker::compare_loops): New function.
	* ipa-icf-gimple.h (func_checker::compare_loops): Likewise.
	(func_checker::compare_bb): Call compare_loops.

gcc/testsuite/ChangeLog:

2019-05-23  Martin Liska  

	PR ipa/90555
	* gcc.dg/ipa/pr90555.c: New test.
---
 gcc/ipa-icf-gimple.c   | 31 ++
 gcc/ipa-icf-gimple.h   |  3 ++
 gcc/testsuite/gcc.dg/ipa/pr90555.c | 67 ++
 3 files changed, 101 insertions(+)
 create mode 100644 gcc/testsuite/gcc.dg/ipa/pr90555.c

diff --git a/gcc/ipa-icf-gimple.c b/gcc/ipa-icf-gimple.c
index 25284936bc3..92b1813ec6c 100644
--- a/gcc/ipa-icf-gimple.c
+++ b/gcc/ipa-icf-gimple.c
@@ -37,6 +37,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "ipa-utils.h"
 #include "tree-eh.h"
 #include "builtins.h"
+#include "cfgloop.h"
 
 #include "ipa-icf-gimple.h"
 
@@ -605,6 +606,33 @@ func_checker::compare_variable_decl (tree t1, tree t2)
   return return_with_debug (ret);
 }
 
+/* Compare loop information for basic blocks BB1 and BB2.  */
+
+bool
+func_checker::compare_loops (basic_block bb1, basic_block bb2)
+{
+  if ((bb1->loop_father == NULL) != (bb2->loop_father == NULL))
+return return_false ();
+
+  struct loop *l1 = bb1->loop_father;
+  struct

[Ada] Silence useless -Wuninitialized warning

2019-05-27 Thread Eric Botcazou
This silences a warning issued for the call to the initialization procedure of 
a record type on a misaligned component of another record type.

Tested on x86_64-suse-linux, applied on the mainline and 9 branch.


2019-05-27  Eric Botcazou  

* gcc-interface/trans.c (Call_to_gnu): Do not initialize the temporary
created out of addressability concerns if it's for the _Init parameter
of an initialization procedure.

-- 
Eric BotcazouIndex: gcc-interface/trans.c
===
--- gcc-interface/trans.c	(revision 271658)
+++ gcc-interface/trans.c	(working copy)
@@ -5313,13 +5313,23 @@ Call_to_gnu (Node_Id gnat_node, tree *gn
 	  /* Create an explicit temporary holding the copy.  */
 	  if (atomic_p)
 	gnu_name = build_atomic_load (gnu_name, sync);
-	  gnu_temp
-	= create_init_temporary ("A", gnu_name, &gnu_stmt, gnat_actual);
 
-	  /* But initialize it on the fly like for an implicit temporary as
-	 we aren't necessarily having a statement list.  */
-	  gnu_name = build_compound_expr (TREE_TYPE (gnu_name), gnu_stmt,
-	  gnu_temp);
+	  /* Do not initialize it for the _Init parameter of an initialization
+	 procedure since no data is meant to be passed in.  */
+	  if (Ekind (gnat_formal) == E_Out_Parameter
+	  && Is_Entity_Name (Name (gnat_node))
+	  && Is_Init_Proc (Entity (Name (gnat_node
+	gnu_name = gnu_temp = create_temporary ("A", TREE_TYPE (gnu_name));
+
+	  /* Initialize it on the fly like for an implicit temporary in the
+	 other cases, as we don't necessarily have a statement list.  */
+	  else
+	{
+	  gnu_temp = create_init_temporary ("A", gnu_name, &gnu_stmt,
+		gnat_actual);
+	  gnu_name = build_compound_expr (TREE_TYPE (gnu_name), gnu_stmt,
+	  gnu_temp);
+	}
 
 	  /* Set up to move the copy back to the original if needed.  */
 	  if (!in_param)


[Ada] Add support for __builtin_expect and friends

2019-05-27 Thread Eric Botcazou
This adds support for __builtin_expect as well as __builtin_[un]likely in Ada.

Tested on x86_64-suse-linux, applied on the mainline.


2019-05-27  Eric Botcazou  

* gcc-interface/ada-builtin-types.def: New file.
* gcc-interface/ada-builtins.def: Likewise.
* gcc-interface/ada-tree.h (BUILT_IN_LIKELY): New macro.
(BUILT_IN_UNLIKELY): Likewise.
* gcc-interface/trans.c (independent_iterations_p): Initialize the
auto-vector to 16 elements.
(Call_to_gnu): Remove local variable and change the vector of actual
parameters to an auto-vector.  Do not convert actual parameters to
the argument type for front-end built-in functions.  Add support for
front-end built-in functions.
(build_noreturn_cond): Use internal instead of built-in function.
* gcc-interface/utils.c (c_builtin_type): Include ada-builtin-types.def
(install_builtin_function_types): Likewise.
(install_builtin_functions): Include ada-builtins.def first.


2019-05-27  Eric Botcazou  

* gnat.dg/expect2.adb: New test.
* gnat.dg/expect2_pkg.ads: New helper.

-- 
Eric BotcazouIndex: gcc-interface/ada-builtin-types.def
===
--- gcc-interface/ada-builtin-types.def	(nonexistent)
+++ gcc-interface/ada-builtin-types.def	(revision 336464)
@@ -0,0 +1,25 @@
+/* This file contains the type definitions for the builtins exclusively
+   used in the GNU Ada compiler.
+
+   Copyright (C) 2019 Free Software Foundation, Inc.
+
+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
+.  */
+
+/* See builtin-types.def for details.  */
+
+DEF_FUNCTION_TYPE_1 (BT_FN_BOOL_BOOL, BT_BOOL, BT_BOOL)
+DEF_FUNCTION_TYPE_2 (BT_FN_BOOL_BOOL_BOOL, BT_BOOL, BT_BOOL, BT_BOOL)
Index: gcc-interface/ada-builtins.def
===
--- gcc-interface/ada-builtins.def	(nonexistent)
+++ gcc-interface/ada-builtins.def	(revision 336464)
@@ -0,0 +1,30 @@
+/* This file contains the definitions for the builtins exclusively used
+   in the GNU Ada compiler.
+
+   Copyright (C) 2019 Free Software Foundation, Inc.
+
+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
+.  */
+
+/* Before including this file, you should define a macro:
+
+ DEF_ADA_BUILTIN (ENUM, NAME, TYPE, ATTRS)
+
+   See builtins.def for details.  */
+
+DEF_ADA_BUILTIN(BUILT_IN_EXPECT, "expect", BT_FN_BOOL_BOOL_BOOL, ATTR_CONST_NOTHROW_LEAF_LIST)
+DEF_ADA_BUILTIN(BUILT_IN_LIKELY, "likely", BT_FN_BOOL_BOOL, ATTR_CONST_NOTHROW_LEAF_LIST)
+DEF_ADA_BUILTIN(BUILT_IN_UNLIKELY, "unlikely", BT_FN_BOOL_BOOL, ATTR_CONST_NOTHROW_LEAF_LIST)
Index: gcc-interface/ada-tree.h
===
--- gcc-interface/ada-tree.h	(revision 336463)
+++ gcc-interface/ada-tree.h	(revision 336464)
@@ -6,7 +6,7 @@
  *  *
  *  C Header File   *
  *  *
- *  Copyright (C) 1992-2018, Free Software Foundation, Inc. *
+ *  Copyright (C) 1992-2019, Free Software Foundation, Inc. *
  *  *
  * GNAT is free software;  you can  redistribute it  and/or modify it under *
  * terms of the  GNU General Public License as published  by the Free Soft- *
@@ -582,3 +582,8 @@ do {		   \
 
 #define EXIT_STMT_COND(NODE) TREE_OPERAND_CHECK_CODE (NODE, EXIT_STMT, 0)
 #define EXIT_STMT_LABEL(NODE)TREE_OPERAND_CHECK_CODE (NODE, EXIT_STMT, 1)
+
+/* Small kludge to be able to define Ada built-in functions locally.
+   We overload them o

Remove pre-Solaris 11/SPARC unwinding support

2019-05-27 Thread Rainer Orth
One of the last remnants of Solaris 10 (and 9)/SPARC support is the
libgcc unwinder.

To get rid of unused cruft, I've taken a full clone of the Solaris 11
support repository, checked out every since version of 32 and 64-bit
libc.so.1 and checked if the patters looked for in sol2-unwind.h are
present.

* As expected, the 64-bit __sighndlr pattern is present everywhere, as
  is the Solaris 11 cuh_pattern.  However, neither the Solaris 10
  cuh_pattern nor the Solaris 9 one can be found, while both are present
  in the respective versions of libc/libthread.

* In the 32-bit case, __sighndlr is identical everywhere again, and the
  Solaris 11 cuh_pattern is found in most versions of libc.  Unlike the
  64-bit case, the Solaris 10 cuh_pattern is also found in the Solaris
  11 Express (snv_151) versions of libc.  While this in itself doesn't
  matter (I won't be supporting a 9-year old beta version of Solaris 11
  these days), it might be that this is still present in OpenSolaris
  derivatives since snv_147 was the last open version.  So I checked
  Tribblix m20.6, the only known Illumos derivative with SPARC support.
  However, when I looked at 32-bit libc from Tribblix m20.6, I found
  none of the patterns in sol2-unwind.h (neither any of the 64-bit ones
  in the 64-bit libc).  I have to assume that Peter Tribble switched to
  using gcc for his builds.

So all pre-Solaris 11 patterns can go since there's no way that they can
be found on a Solaris 11 system: there's no static libc.a anymore since
Solaris 10 and the system-call interface between libc and kernel changed
so much in Solaris 11 that a local copy of Solaris 10 libc.so.1 wouldn't
work at all on Solaris 11.

Bootstrapped without regressions on sparc-sun-solaris2.11 (Solaris 11.3,
11.4, and 11.5).  I'm going to install the patch in a day or two unless
someone finds fault with my reasoning.

Rainer

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


2019-05-25  Rainer Orth  

* config/sparc/sol2-unwind.h [__arch64__] (sparc64_is_sighandler):
Remove Solaris 9 and 10 support.
(sparc_is_sighandler): Remove Solaris 9 and 10 support.

# HG changeset patch
# Parent  a471ac842743a60d92dc3c029ee68c655bb00142
Remove pre-Solaris 11/SPARC unwinding support

diff --git a/libgcc/config/sparc/sol2-unwind.h b/libgcc/config/sparc/sol2-unwind.h
--- a/libgcc/config/sparc/sol2-unwind.h
+++ b/libgcc/config/sparc/sol2-unwind.h
@@ -67,51 +67,7 @@ sparc64_is_sighandler (unsigned int *pc,
 	   libc.so.1:
 
 	   : mov  %i1, %o1
-	   : call __sighndlr
-
-	   This is the same setup as for Solaris 10, see below.  */
-	*nframes = 3;
-
-  else if (cuh_pattern == 0xd25fa7ef)
-	{
-	  /* This matches the call_user_handler pattern in Solaris 10
-	 libc.so.1:
-
-	 : ldx  [ %fp + 0x7ef ], %o1
-	 : call __sighndlr
-
-	 There are 2 cases so we look for the return address of the
-	 caller's caller frame in order to do more pattern matching.  */
-	  unsigned long sah_address = *(unsigned long *)(cfa + 176 + 15*8);
-
-  if (sah_address && *(unsigned int *)(sah_address - 4) == 0x92100019)
-	/* We need to move up three frames:
-
-			<-- context->cfa
-		__sighndlr
-		call_user_handler
-		sigacthandler
-		  */
-	*nframes = 3;
-	  else
-	/* The sigacthandler frame isn't present in the chain.
-	   We need to move up two frames:
-
-			<-- context->cfa
-		__sighndlr
-		call_user_handler
-		  */
-	*nframes = 2;
-	}
-
-  else if (cuh_pattern == 0x9410001a || cuh_pattern == 0x9410001b)
-	/* This matches the call_user_handler pattern in Solaris 9
-	   libthread.so.1:
-
-	   : mov  %i2, %o2
-	   : call  __sighndlr
-
-	   This is the same setup as for Solaris 10, see above.  */
+	   : call __sighndlr  */
 	*nframes = 3;
 
   return 1;
@@ -184,51 +140,7 @@ sparc_is_sighandler (unsigned int *pc, v
 	   libc.so.1:
 
 	   : mov  %i1, %o1
-	   : call __sighndlr
-
-	   This is the same setup as for Solaris 10, see below.  */
-	*nframes = 3;
-
-  else if (cuh_pattern == 0xd407a04c)
-	{
-	  /* This matches the call_user_handler pattern in Solaris 10
-	 libc.so.1:
-
-	 : ld  [ %fp + 0x4c ], %o2
-	 : call __sighndlr
-
-	 There are 2 cases so we look for the return address of the
-	 caller's caller frame in order to do more pattern matching.  */
-	  unsigned int sah_address = *(unsigned int *)(cfa + 96 + 15*4);
-
-  if (sah_address && *(unsigned int *)(sah_address - 4) == 0x92100019)
-	/* We need to move up three frames:
-
-			<-- context->cfa
-		__sighndlr
-		call_user_handler
-		sigacthandler
-		  */
-	*nframes = 3;
-	  else
-	/* The sigacthandler frame isn't present in the chain.
-	   We need to move up two frames:
-
-			<-- context->cfa
-		__sighndlr
-		call_user_handler
-		  */
-	*nframes = 2;
-	}
-
-  else if (cuh_pattern == 0x94100

[Ada] Fix minor warning issue

2019-05-27 Thread Eric Botcazou
Tested on x86_64-suse-linux, applied on the mainline, 9 and 8 branches.


2019-05-27  Eric Botcazou  

* gcc-interface/utils.c (maybe_pad_type): Issue the warning for the
specific case of component types preferably.

-- 
Eric Botcazou
Index: gcc-interface/utils.c
===
--- gcc-interface/utils.c	(revision 271528)
+++ gcc-interface/utils.c	(working copy)
@@ -1530,14 +1530,14 @@ built:
 	 generated for some other corresponding source entity.  */
   if (Comes_From_Source (gnat_entity))
 	{
-	  if (Present (gnat_error_node))
-	post_error_ne_tree ("{^ }bits of & unused?",
-gnat_error_node, gnat_entity,
-size_diffop (size, orig_size));
-	  else if (is_component_type)
+	  if (is_component_type)
 	post_error_ne_tree ("component of& padded{ by ^ bits}?",
 gnat_entity, gnat_entity,
 size_diffop (size, orig_size));
+	  else if (Present (gnat_error_node))
+	post_error_ne_tree ("{^ }bits of & unused?",
+gnat_error_node, gnat_entity,
+size_diffop (size, orig_size));
 	}
 }
 


[Ada] Do not generate dangling references to bounds

2019-05-27 Thread Eric Botcazou
This prevents gigi from generating dangling references to the bounds of an 
aliased parameter of an unconstrained array type.  This cannot happen in 
strict Ada but you can bypass the rules by means of 'Unchecked_Access.

Tested on x86_64-suse-linux, applied on the mainline and 9 branch.


2019-05-27  Eric Botcazou  

* gcc-interface/trans.c (Identifier_to_gnu): Minor tweaks.
(gnat_to_gnu): Do not convert the result if it is a reference to an
unconstrained array used as the prefix of an attribute reference that
requires an lvalue.


2019-05-27  Eric Botcazou  

* gnat.dg/aliased2.adb: New test.

-- 
Eric BotcazouIndex: gcc-interface/trans.c
===
--- gcc-interface/trans.c	(revision 271650)
+++ gcc-interface/trans.c	(working copy)
@@ -1110,11 +1110,12 @@ Identifier_to_gnu (Node_Id gnat_node, tr
 }
   else
 {
-  /* We want to use the Actual_Subtype if it has already been elaborated,
-	 otherwise the Etype.  Avoid using Actual_Subtype for packed arrays to
-	 simplify things.  */
+  /* We use the Actual_Subtype only if it has already been elaborated,
+	 as we may be invoked precisely during its elaboration, otherwise
+	 the Etype.  Avoid using it for packed arrays to simplify things.  */
   if ((Ekind (gnat_entity) == E_Constant
-	   || Ekind (gnat_entity) == E_Variable || Is_Formal (gnat_entity))
+	   || Ekind (gnat_entity) == E_Variable
+	   || Is_Formal (gnat_entity))
 	  && !(Is_Array_Type (Etype (gnat_entity))
 	   && Present (Packed_Array_Impl_Type (Etype (gnat_entity
 	  && Present (Actual_Subtype (gnat_entity))
@@ -8685,7 +8686,11 @@ gnat_to_gnu (Node_Id gnat_node)
 	  declaration, return the result unmodified because we want to use the
 	  return slot optimization in this case.
 
-   5. Finally, if the type of the result is already correct.  */
+   5. If this is a reference to an unconstrained array which is used as the
+	  prefix of an attribute reference that requires an lvalue, return the
+	  result unmodified because we want return the original bounds.
+
+   6. Finally, if the type of the result is already correct.  */
 
   if (Present (Parent (gnat_node))
   && (lhs_or_actual_p (gnat_node)
@@ -8734,13 +8739,19 @@ gnat_to_gnu (Node_Id gnat_node)
   else if (gnu_result == error_mark_node || gnu_result_type == void_type_node)
 gnu_result = error_mark_node;
 
-  else if (Present (Parent (gnat_node))
+  else if (TREE_CODE (gnu_result) == CALL_EXPR
+	   && Present (Parent (gnat_node))
 	   && (Nkind (Parent (gnat_node)) == N_Object_Declaration
 	   || Nkind (Parent (gnat_node)) == N_Object_Renaming_Declaration)
-	   && TREE_CODE (gnu_result) == CALL_EXPR
 	   && return_type_with_variable_size_p (TREE_TYPE (gnu_result)))
 ;
 
+  else if (TREE_CODE (gnu_result) == UNCONSTRAINED_ARRAY_REF
+	   && Present (Parent (gnat_node))
+	   && Nkind (Parent (gnat_node)) == N_Attribute_Reference
+	   && lvalue_required_for_attribute_p (Parent (gnat_node)))
+;
+
   else if (TREE_TYPE (gnu_result) != gnu_result_type)
 gnu_result = convert (gnu_result_type, gnu_result);
 
-- { dg-do run }

procedure Aliased2 is

  type Rec is record
Data : access constant String;
  end record;

  function Get (S : aliased String) return Rec is
R : Rec := (Data => S'Unchecked_Access);
  begin
return R;
  end;

  S : aliased String := "Hello";

  R : Rec := Get (S);

begin
  if R.Data'Length /= S'Length then
raise Program_Error;
  end if;
end;


[v3 PATCH] basic_string spurious use of a default constructible allocator - LWG2788

2019-05-27 Thread Nina Dinka Ranns
Tested on Linux x86_64
basic_string spurious use of a default constructible allocator - LWG2788

2019-05-27  Nina Dinka Ranns  
basic_string spurious use of a default constructible allocator - LWG2788
* bits/basic_string.tcc:
(_M_replace_dispatch()): string temporary now constructed with
the current allocator
* testsuite/21_strings/basic_string/allocator/char/lwg2788.cc: New
* testsuite/21_strings/basic_string/allocator/wchar_t/lwg2788.cc: New
Index: libstdc++-v3/include/bits/basic_string.tcc
===
--- libstdc++-v3/include/bits/basic_string.tcc	(revision 271509)
+++ libstdc++-v3/include/bits/basic_string.tcc	(working copy)
@@ -381,7 +381,9 @@
 			  _InputIterator __k1, _InputIterator __k2,
 			  std::__false_type)
   {
-	const basic_string __s(__k1, __k2);
+// _GLIBCXX_RESOLVE_LIB_DEFECTS
+// 2788. unintentionally require a default constructible allocator
+	const basic_string __s(__k1, __k2, this->get_allocator());
 	const size_type __n1 = __i2 - __i1;
 	return _M_replace(__i1 - begin(), __n1, __s._M_data(),
 			  __s.size());
Index: libstdc++-v3/testsuite/20_util/nonesuch/nonesuch.cc
===
--- libstdc++-v3/testsuite/20_util/nonesuch/nonesuch.cc	(revision 271509)
+++ libstdc++-v3/testsuite/20_util/nonesuch/nonesuch.cc	(nonexistent)
@@ -1,39 +0,0 @@
-// 2019-05-14  Nina Dinka Ranns  
-// Copyright (C) 2019 Free Software Foundation, Inc.
-//
-// This file is part of the GNU ISO C++ Library.  This library is free
-// software; you can redistribute it and/or modify it under the
-// terms of the GNU General Public License as published by the
-// Free Software Foundation; either version 3, or (at your option)
-// any later version.
-
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-// GNU General Public License for more details.
-
-// You should have received a copy of the GNU General Public License along
-// with this library; see the file COPYING3.  If not see
-// .
-
-// { dg-do compile { target c++14 } }
-
-#include 
-// Example taken from LWG2960
-
-using std::__nonesuch;
-struct such {};
-void f(const such&){};
-void f(const std::__nonesuch&);
-
-int main(){
- static_assert(!std::is_default_constructible<__nonesuch>::value,
-		 "__nonesuch is default constructible");
- static_assert(!std::is_copy_constructible<__nonesuch>::value,
-		 "__nonesuch is copy constructible");
- static_assert(!std::is_assignable<__nonesuch, __nonesuch>::value,
-		 "__nonesuch is assignable");
- static_assert(!std::is_destructible<__nonesuch>::value,
-		 "__nonesuch is destructible");
- f({});
-}
Index: libstdc++-v3/testsuite/21_strings/basic_string/allocator/char/lwg2788.cc
===
--- libstdc++-v3/testsuite/21_strings/basic_string/allocator/char/lwg2788.cc	(nonexistent)
+++ libstdc++-v3/testsuite/21_strings/basic_string/allocator/char/lwg2788.cc	(working copy)
@@ -0,0 +1,84 @@
+//{ dg-do run { target c++11 } }
+
+// 2019-05-27  Nina Dinka Ranns  
+//
+// Copyright (C) 2015-2019 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+ 
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+ 
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3.  If not see
+// .
+
+#include 
+#include 
+
+using C = char;
+using traits = std::char_traits;
+int constructCount = 0;
+
+static void resetCounter()
+{
+ constructCount = 0;
+}
+
+template 
+struct TestAllocator
+{
+  typedef Tp value_type;
+  using size_type = unsigned;
+
+  TestAllocator() noexcept { constructCount++; }
+
+  template 
+  TestAllocator(const TestAllocator&) {}
+
+  Tp *allocate(std::size_t n)
+  { return std::allocator().allocate(n); }
+
+  void deallocate(Tp *p, std::size_t n)
+  { std::allocator().deallocate(p, n); }
+
+};
+
+template 
+bool operator==(const TestAllocator&, const TestAllocator&)
+{ return true; }
+template 
+bool operator!=(const TestAllocator&, const TestAllocator&)
+{ return false; }
+
+void test01()
+{
+  typedef TestAllocator alloc_type;
+  typedef std::basic_string test_type;
+  test_type v1{alloc_type()};
+  std::string v2{"some_content"};
+
+  resetCounter();
+  v1.assign(v2.begi

[Ada] Fix internal error on limited view of incomplete type

2019-05-27 Thread Eric Botcazou
This fixes an ICE on a package whose spec has a limited_with clause of another 
package, whose body has a with clause of the same other package and uses a 
type which is first declared as incomplete in this other package.

Tested on x86_64-suse-linux, applied on the mainline and 9 branch.


2019-05-27  Eric Botcazou  

* gcc-interface/trans.c (Gigi_Types_Compatible): New predicate.
(Identifier_to_gnu): Use it to assert that the type of the identifier
and that of its entity are compatible for gigi.  Rename a couple of
local variables and separate the processing of the result type.


2019-05-27  Eric Botcazou  

* gnat.dg/limited_with7.ad[sb]: New test.
* gnat.dg/limited_with7_pkg.ads: New helper.

-- 
Eric Botcazoulimited with Limited_With7_Pkg;

package Limited_With7 is

   procedure Proc (R : out Limited_With7_Pkg.Rec);

end Limited_With7;
-- { dg-do compile }

with Limited_With7_Pkg; use Limited_With7_Pkg;

package body Limited_With7 is

   procedure Proc (R : out Limited_With7_Pkg.Rec) is
   begin
  R.I := 0;
   end;

end Limited_With7;
package Limited_With7_Pkg is

   type Rec;

   type Rec is record
  I : Integer;
   end record;

end Limited_With7_Pkg;
Index: gcc-interface/trans.c
===
--- gcc-interface/trans.c	(revision 271647)
+++ gcc-interface/trans.c	(working copy)
@@ -1021,6 +1021,42 @@ fold_constant_decl_in_expr (tree exp)
   gcc_unreachable ();
 }
 
+/* Return true if TYPE and DEF_TYPE are compatible GNAT types for Gigi.  */
+
+static bool
+Gigi_Types_Compatible (Entity_Id type, Entity_Id def_type)
+{
+  /* The trivial case.  */
+  if (type == def_type)
+return true;
+
+  /* A class-wide type is equivalent to a subtype of itself.  */
+  if (Is_Class_Wide_Type (type))
+return true;
+
+  /* A packed array type is compatible with its implementation type.  */
+  if (Is_Packed (def_type) && type == Packed_Array_Impl_Type (def_type))
+return true;
+
+  /* If both types are Itypes, one may be a copy of the other.  */
+  if (Is_Itype (def_type) && Is_Itype (type))
+return true;
+
+  /* If the type is incomplete and comes from a limited context, then also
+ consider its non-limited view.  */
+  if (Is_Incomplete_Type (def_type)
+  && From_Limited_With (def_type)
+  && Present (Non_Limited_View (def_type)))
+return Gigi_Types_Compatible (type, Non_Limited_View (def_type));
+
+  /* If the type is incomplete/private, then also consider its full view.  */
+  if (Is_Incomplete_Or_Private_Type (def_type)
+  && Present (Full_View (def_type)))
+return Gigi_Types_Compatible (type, Full_View (def_type));
+
+  return false;
+}
+
 /* Subroutine of gnat_to_gnu to translate gnat_node, an N_Identifier,
to a GCC tree, which is returned.  GNU_RESULT_TYPE_P is a pointer
to where we should place the result type.  */
@@ -1028,55 +1064,31 @@ fold_constant_decl_in_expr (tree exp)
 static tree
 Identifier_to_gnu (Node_Id gnat_node, tree *gnu_result_type_p)
 {
-  Node_Id gnat_temp, gnat_temp_type;
-  tree gnu_result, gnu_result_type;
-
-  /* Whether we should require an lvalue for GNAT_NODE.  Needed in
- specific circumstances only, so evaluated lazily.  < 0 means
- unknown, > 0 means known true, 0 means known false.  */
-  int require_lvalue = -1;
-
+  /* The entity of GNAT_NODE and its type.  */
+  Node_Id gnat_entity = (Nkind (gnat_node) == N_Defining_Identifier
+			 || Nkind (gnat_node) == N_Defining_Operator_Symbol)
+			? gnat_node : Entity (gnat_node);
+  Node_Id gnat_entity_type = Etype (gnat_entity);
   /* If GNAT_NODE is a constant, whether we should use the initialization
  value instead of the constant entity, typically for scalars with an
  address clause when the parent doesn't require an lvalue.  */
   bool use_constant_initializer = false;
+  /* Whether we should require an lvalue for GNAT_NODE.  Needed in
+ specific circumstances only, so evaluated lazily.  < 0 means
+ unknown, > 0 means known true, 0 means known false.  */
+  int require_lvalue = -1;
+  Node_Id gnat_result_type;
+  tree gnu_result, gnu_result_type;
 
   /* If the Etype of this node is not the same as that of the Entity, then
  something went wrong, probably in generic instantiation.  However, this
  does not apply to types.  Since we sometime have strange Ekind's, just
- do this test for objects.  Moreover, if the Etype of the Entity is private
- or incomplete coming from a limited context, the Etype of the N_Identifier
- is allowed to be the full/non-limited view and we also consider a packed
- array type to be the same as the original type.  Similarly, a CW type is
- equivalent to a subtype of itself.  Finally, if the types are Itypes, one
- may be a copy of the other, which is also legal.  */
-  gnat_temp = ((Nkind (gnat_node) == N_Defining_Identifier
-		|| Nkind (gnat_node) == N_Defining_Operator_Symbol)
-	   ? gnat_

[PATCH] Fix PR90637

2019-05-27 Thread Richard Biener


The following fixes GIMPLE stmt sinking to not sink a stmt into a loop.
It actually chooses the correct basic-block to sink to but just
ignores that when computing the stmt iterator to sink to...

Bootstrap and regtest running on x86_64-unknown-linux-gnu.

Richard.

2019-05-27  Richard Biener  

PR tree-optimization/90637
* tree-ssa-sink.c (statement_sink_location): Honor the
computed sink location for single-uses.

* gcc.dg/gomp/pr90637.c: New testcase.

Index: gcc/tree-ssa-sink.c
===
--- gcc/tree-ssa-sink.c (revision 271644)
+++ gcc/tree-ssa-sink.c (working copy)
@@ -439,7 +439,10 @@ statement_sink_location (gimple *stmt, b
  if (sinkbb == frombb)
return false;
 
- *togsi = gsi_for_stmt (use);
+ if (sinkbb == gimple_bb (use))
+   *togsi = gsi_for_stmt (use);
+ else
+   *togsi = gsi_after_labels (sinkbb);
 
  return true;
}
Index: gcc/testsuite/gcc.dg/gomp/pr90637.c
===
--- gcc/testsuite/gcc.dg/gomp/pr90637.c (nonexistent)
+++ gcc/testsuite/gcc.dg/gomp/pr90637.c (working copy)
@@ -0,0 +1,14 @@
+/* PR tree-optimization/90637 */
+/* { dg-do compile } */
+/* { dg-options "-fopenmp -O1 --param sink-frequency-threshold=90" } */
+
+int v;
+
+void
+foo (int c)
+{
+  int i;
+#pragma omp for simd if (c) lastprivate (v) schedule (static, 16)
+  for (i = 0; i < 64; ++i)
+v = i;
+}


[PATCH] Fix PR90610

2019-05-27 Thread Richard Biener


Another mistake in the vec_perm -> bit_insert change.

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

Richard.

2019-05-27  Richard Biener  

PR middle-end/90610
* match.pd (vec_perm): Avoid clobbering op0 when not generating
a bit-insert.

Index: gcc/match.pd
===
--- gcc/match.pd(revision 271644)
+++ gcc/match.pd(working copy)
@@ -5453,8 +5453,8 @@ (define_operator_list COND_TERNARY
   first vector we only can insert the first elt from
   the first vector.  */
at = 0;
-   ins = fold_read_from_vector (cop0, 0);
-   op0 = op1;
+   if ((ins = fold_read_from_vector (cop0, 0)))
+ op0 = op1;
  }
else
  {


[Ada] Fix spurious error on unchecked conversion to misaligned type

2019-05-27 Thread Eric Botcazou
This is a regression present on the mainline, 9 and 8 branches.  The compiler 
issues a spurious error on the result of an unchecked conversion used as an 
actual In parameter in a subprogram call, if the destination type is a scalar 
type subject to a clause which gives an alignment lower than the natural one.

Tested on x86_64-suse-linux, applied on the mainline, 9 and 8 branches.


2019-05-27  Eric Botcazou  

* gcc-interface/trans.c (Call_to_gnu): Use the unpadded type when
putting back an intermediate conversion the type of the actuals.


2019-05-27  Eric Botcazou  

* gnat.dg/unchecked_convert13.adb: New test.

-- 
Eric BotcazouIndex: gcc-interface/trans.c
===
--- gcc-interface/trans.c	(revision 336034)
+++ gcc-interface/trans.c	(revision 336035)
@@ -5354,7 +5354,7 @@ Call_to_gnu (Node_Id gnat_node, tree *gn
 	 since the parent is a procedure call, so put it back here.  Note that
 	 we might have a dummy type here if the actual is the dereference of a
 	 pointer to it, but that's OK if the formal is passed by reference.  */
-  tree gnu_actual_type = gnat_to_gnu_type (Etype (gnat_actual));
+  tree gnu_actual_type = get_unpadded_type (Etype (gnat_actual));
   if (TYPE_IS_DUMMY_P (gnu_actual_type))
 	gcc_assert (is_true_formal_parm && DECL_BY_REF_P (gnu_formal));
   else if (suppress_type_conversion
-- { dg-do compile }

with Ada.Unchecked_Conversion;

procedure Unchecked_Convert13 is

  type B16_T is mod 2 ** 16;
  for B16_T'Size use 16;
  for B16_T'Alignment use 1;

  type Rec_T is record
A : Short_Integer;
  end record;
  for Rec_T use record
A at 0 range 0 .. 15;
  end record;
  for Rec_T'Size use 16;

  Rec : constant Rec_T := (A => 0);

  function Rec_To_B16 is new Ada.Unchecked_Conversion (Rec_T, B16_T);

  procedure Nested (B16 : B16_T) is
  begin
null;
  end;

begin
  Nested (Rec_To_B16 (Rec));
end;


[AArch64] [SVE] PR88837 - Poor vector construction code in VL-specific mode

2019-05-27 Thread Prathamesh Kulkarni
Hi,
The attached patch tries to improve initialization for fixed-length
SVE vector and it's algorithm is described in comments for
aarch64_sve_expand_vector_init() in the patch, with help from Richard
Sandiford. I verified tests added in the patch pass with qemu and am
trying to run bootstrap+test on patch in qemu.
Does the patch look OK ?

Thanks,
Prathamesh
2019-05-27  Prathamesh Kulkarni  
Richard Sandiford  

* vector-builder.h (vector_builder::count_dups): New method.
* config/aarch64/aarch64-protos.h (aarch64_expand_sve_vector_init):
Declare prototype.
* config/aarch64/aarch64/sve.md (aarch64_sve_rev64): Use @.
(vec_init): New pattern.
* config/aarch64/aarch64.c (emit_insr): New function.
(aarch64_sve_expand_vector_init_handle_trailing_constants): Likewise.
(aarch64_sve_expand_vector_init_insert_elems): Likewise.
(aarch64_sve_expand_vector_init_handle_trailing_same_elem): Likewise.
(aarch64_sve_expand_vector_init): Define two overloaded functions.

testsuite/
* gcc.target/aarch64/sve/init_1.c: New test.
* gcc.target/aarch64/sve/init_1_run.c: Likewise.
* gcc.target/aarch64/sve/init_2.c: Likewise.
* gcc.target/aarch64/sve/init_2_run.c: Likewise.
* gcc.target/aarch64/sve/init_3.c: Likewise.
* gcc.target/aarch64/sve/init_3_run.c: Likewise.
* gcc.target/aarch64/sve/init_4.c: Likewise.
* gcc.target/aarch64/sve/init_4_run.c: Likewise.
* gcc.target/aarch64/sve/init_5.c: Likewise.
* gcc.target/aarch64/sve/init_5_run.c: Likewise.
* gcc.target/aarch64/sve/init_6.c: Likewise.
* gcc.target/aarch64/sve/init_6_run.c: Likewise.
* gcc.target/aarch64/sve/init_7.c: Likewise.
* gcc.target/aarch64/sve/init_7_run.c: Likewise.
* gcc.target/aarch64/sve/init_8.c: Likewise.
* gcc.target/aarch64/sve/init_8_run.c: Likewise.
* gcc.target/aarch64/sve/init_9.c: Likewise.
* gcc.target/aarch64/sve/init_9_run.c: Likewise.
* gcc.target/aarch64/sve/init_10.c: Likewise.
* gcc.target/aarch64/sve/init_10_run.c: Likewise.
* gcc.target/aarch64/sve/init_11.c: Likewise.
* gcc.target/aarch64/sve/init_11_run.c: Likewise.
* gcc.target/aarch64/sve/init_12.c: Likewise.
* gcc.target/aarch64/sve/init_12_run.c: Likewise.

diff --git a/gcc/config/aarch64/aarch64-protos.h 
b/gcc/config/aarch64/aarch64-protos.h
index b6c0d0a8eb6..f82728ed2d3 100644
--- a/gcc/config/aarch64/aarch64-protos.h
+++ b/gcc/config/aarch64/aarch64-protos.h
@@ -515,6 +515,7 @@ bool aarch64_maybe_expand_sve_subreg_move (rtx, rtx);
 void aarch64_split_sve_subreg_move (rtx, rtx, rtx);
 void aarch64_expand_prologue (void);
 void aarch64_expand_vector_init (rtx, rtx);
+void aarch64_sve_expand_vector_init (rtx, rtx);
 void aarch64_init_cumulative_args (CUMULATIVE_ARGS *, const_tree, rtx,
   const_tree, unsigned);
 void aarch64_init_expanders (void);
diff --git a/gcc/config/aarch64/aarch64-sve.md 
b/gcc/config/aarch64/aarch64-sve.md
index b9cb1fae98c..a4e0014eb3d 100644
--- a/gcc/config/aarch64/aarch64-sve.md
+++ b/gcc/config/aarch64/aarch64-sve.md
@@ -863,7 +863,7 @@
   "revb\t%0.h, %1/m, %2.h"
 )
 
-(define_insn "*aarch64_sve_rev"
+(define_insn "@aarch64_sve_rev"
   [(set (match_operand:SVE_ALL 0 "register_operand" "=w")
(unspec:SVE_ALL [(match_operand:SVE_ALL 1 "register_operand" "w")]
UNSPEC_REV))]
@@ -3207,3 +3207,15 @@
 DONE;
   }
 )
+
+;; Standard pattern name vec_init.
+
+(define_expand "vec_init"
+  [(match_operand:SVE_ALL 0 "register_operand" "")
+(match_operand 1 "" "")]
+  "TARGET_SVE"
+  {
+aarch64_sve_expand_vector_init (operands[0], operands[1]);
+DONE;
+  }
+)
diff --git a/gcc/config/aarch64/aarch64.c b/gcc/config/aarch64/aarch64.c
index 83453d03095..8967e02524e 100644
--- a/gcc/config/aarch64/aarch64.c
+++ b/gcc/config/aarch64/aarch64.c
@@ -15244,6 +15244,261 @@ aarch64_expand_vector_init (rtx target, rtx vals)
 }
 }
 
+/* Emit RTL corresponding to:
+   insr TARGET, ELEM.  */
+
+static void
+emit_insr (rtx target, rtx elem)
+{
+  machine_mode mode = GET_MODE (target);
+  scalar_mode elem_mode = GET_MODE_INNER (mode);
+  elem = force_reg (elem_mode, elem);
+
+  insn_code icode = optab_handler (vec_shl_insert_optab, mode);
+  gcc_assert (icode != CODE_FOR_nothing);
+  emit_insn (GEN_FCN (icode) (target, target, elem));
+}
+
+/* Subroutine of aarch64_sve_expand_vector_init for handling
+   trailing constants.
+   This function works as follows:
+   (a) Create a new vector consisting of trailing constants.
+   (b) Initialize TARGET with the constant vector using emit_move_insn.
+   (c) Insert remaining elements in TARGET using insr.
+   NELTS is the total number of elements in original vector while
+
+   ??? The heuristic used is to do above only if number of constants
+   is at least half the total number of ele

[Ada] Improve code generated for Left_Rotate from Interfaces

2019-05-27 Thread Eric Botcazou
This tweaks the GENERIC code emitted by gigi for the Left_Rotate routine from  
the Interfaces package so as to expose more optimization opportunities.

Tested on x86_64-suse-linux, applied on the mainline.


2019-05-27  Eric Botcazou  

* gcc-interface/trans.c (gnat_to_gnu) : Convert the
count to the unsigned version of its base type before proceeding.

-- 
Eric BotcazouIndex: gcc-interface/trans.c
===
--- gcc-interface/trans.c	(revision 271528)
+++ gcc-interface/trans.c	(working copy)
@@ -7422,7 +7422,7 @@ gnat_to_gnu (Node_Id gnat_node)
 	enum tree_code code = gnu_codes[kind];
 	bool ignore_lhs_overflow = false;
 	location_t saved_location = input_location;
-	tree gnu_type;
+	tree gnu_type, gnu_max_shift = NULL_TREE;
 
 	/* Fix operations set up for boolean types in GNU_CODES above.  */
 	if (Is_Modular_Integer_Type (Underlying_Type (Etype (gnat_node
@@ -7445,6 +7445,17 @@ gnat_to_gnu (Node_Id gnat_node)
 	gnu_rhs = gnat_to_gnu (Right_Opnd (gnat_node));
 	gnu_type = gnu_result_type = get_unpadded_type (Etype (gnat_node));
 
+	/* If this is a shift, take the count as unsigned since that is what
+	   most machines do and will generate simpler adjustments below.  */
+	if (IN (kind, N_Op_Shift))
+	  {
+	tree gnu_count_type
+	  = gnat_unsigned_type_for (get_base_type (TREE_TYPE (gnu_rhs)));
+	gnu_rhs = convert (gnu_count_type, gnu_rhs);
+	gnu_max_shift
+	  = convert (TREE_TYPE (gnu_rhs), TYPE_SIZE (gnu_type));
+	  }
+
 	/* Pending generic support for efficient vector logical operations in
 	   GCC, convert vectors to their representative array type view and
 	   fallthrough.  */
@@ -7468,25 +7479,20 @@ gnat_to_gnu (Node_Id gnat_node)
 
 	/* If this is a shift whose count is not guaranteed to be correct,
 	   we need to adjust the shift count.  */
-	if (IN (kind, N_Op_Shift) && !Shift_Count_OK (gnat_node))
-	  {
-	tree gnu_count_type = get_base_type (TREE_TYPE (gnu_rhs));
-	tree gnu_max_shift
-	  = convert (gnu_count_type, TYPE_SIZE (gnu_type));
-
-	if (kind == N_Op_Rotate_Left || kind == N_Op_Rotate_Right)
-	  gnu_rhs = build_binary_op (TRUNC_MOD_EXPR, gnu_count_type,
-	 gnu_rhs, gnu_max_shift);
-	else if (kind == N_Op_Shift_Right_Arithmetic)
-	  gnu_rhs
-		= build_binary_op
-		  (MIN_EXPR, gnu_count_type,
-		   build_binary_op (MINUS_EXPR,
-gnu_count_type,
-gnu_max_shift,
-build_int_cst (gnu_count_type, 1)),
-		   gnu_rhs);
-	  }
+	if ((kind == N_Op_Rotate_Left || kind == N_Op_Rotate_Right)
+	&& !Shift_Count_OK (gnat_node))
+	  gnu_rhs = build_binary_op (TRUNC_MOD_EXPR, TREE_TYPE (gnu_rhs),
+ gnu_rhs, gnu_max_shift);
+	else if (kind == N_Op_Shift_Right_Arithmetic
+		 && !Shift_Count_OK (gnat_node))
+	  gnu_rhs
+	= build_binary_op (MIN_EXPR, TREE_TYPE (gnu_rhs),
+			   build_binary_op (MINUS_EXPR,
+		TREE_TYPE (gnu_rhs),
+		gnu_max_shift,
+		build_int_cst
+		(TREE_TYPE (gnu_rhs), 1)),
+			   gnu_rhs);
 
 	/* For right shifts, the type says what kind of shift to do,
 	   so we may need to choose a different type.  In this case,
@@ -7533,18 +7539,15 @@ gnat_to_gnu (Node_Id gnat_node)
 
 	/* If this is a logical shift with the shift count not verified,
 	   we must return zero if it is too large.  We cannot compensate
-	   above in this case.  */
+	   beforehand in this case.  */
 	if ((kind == N_Op_Shift_Left || kind == N_Op_Shift_Right)
 	&& !Shift_Count_OK (gnat_node))
 	  gnu_result
-	= build_cond_expr
-	  (gnu_type,
-	   build_binary_op (GE_EXPR, boolean_type_node,
-gnu_rhs,
-convert (TREE_TYPE (gnu_rhs),
-	 TYPE_SIZE (gnu_type))),
-	   build_int_cst (gnu_type, 0),
-	   gnu_result);
+	= build_cond_expr (gnu_type,
+			   build_binary_op (GE_EXPR, boolean_type_node,
+		gnu_rhs, gnu_max_shift),
+			   build_int_cst (gnu_type, 0),
+			   gnu_result);
   }
   break;
 


[wwwdocs] readings.html - opengroup.org has moved to https

2019-05-27 Thread Gerald Pfeifer
...so we should update our link, too.

Committed.

Gerald

Index: readings.html
===
RCS file: /cvs/gcc/wwwdocs/htdocs/readings.html,v
retrieving revision 1.312
diff -u -r1.312 readings.html
--- readings.html   26 May 2019 19:39:47 -  1.312
+++ readings.html   26 May 2019 21:02:40 -
@@ -642,7 +642,7 @@
   Robert Morgan (1998) "Building an Optimizing Compiler".
   300pp. ISBN: 1-8-179-X.
 
-  http://www.opengroup.org/";>The Open Group has quite a bit
+  https://www.opengroup.org/";>The Open Group has quite a bit
   on http://pubs.opengroup.org/onlinepubs/009695399/toc.htm";>POSIX
   and friends.
   


[PATCH v4] Use builtin sort instead of shell sort

2019-05-27 Thread Émeric Dupont
v4: Handling wildcard files correctly

Some build environments and configuration options may lead to the make
variable PLUGIN_HEADERS being too long to be passed as parameters to the
shell `echo` command, leading to a "write error" message when making the
target install-plugin.

The following patch fixes this issue by using the [Make $(sort list)][1]
function instead to remove duplicates from the list of headers. There is
no functional change, the value assigned to the shell variable is the
same.

Tested in production on x86 and armv7 cross-compilation toolchains.
- The length of the headers variable goes from 8+ chars to 7500+

Tested with make bootstrap and make check on host-x86_64-pc-linux-gnu
- make bootstrap successful
- make check fails even before the patch is applied

WARNING: program timed out.
FAIL: libgomp.c/../libgomp.c-c++-common/cancel-parallel-1.c execution 
test
...
make[4]: *** [Makefile:479: check-DEJAGNU] Error 1

2019-04-15  Emeric Dupont  

* Makefile.in: Use builtin sort instead of shell sort

Signed-off-by: Emeric Dupont 

[1]: 
https://www.gnu.org/software/make/manual/html_node/Text-Functions.html#index-sorting-words
---
 gcc/Makefile.in | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/Makefile.in b/gcc/Makefile.in
index d186d71c91e..79b32fffa8f 100644
--- a/gcc/Makefile.in
+++ b/gcc/Makefile.in
@@ -3538,7 +3538,7 @@ install-plugin: installdirs lang.install-plugin 
s-header-vars install-gengtype
 # We keep the directory structure for files in config or c-family and .def
 # files. All other files are flattened to a single directory.
 $(mkinstalldirs) $(DESTDIR)$(plugin_includedir)
-headers=`echo $(PLUGIN_HEADERS) $$(cd $(srcdir); echo *.h *.def) | tr ' ' 
'\012' | sort -u`; \
+headers="$(sort $(PLUGIN_HEADERS) $(patsubst $(srcdir)/%,%,$(wildcard 
$(srcdir)/*.h $(srcdir)/*.def)))"; \
 srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/&/g'`; \
 for file in $$headers; do \
   if [ -f $$file ] ; then \
--
2.21.0




TriaGnoSys GmbH, Registergericht: München HRB 141647, Vat.: DE 813396184 
Geschäftsführer: Núria Riera Díaz, Peter Lewalter


[patch] Fix ICE in resolve_args_picking_1 with -gsplit-dwarf

2019-05-27 Thread Eric Botcazou
The function simply doesn't handle the new location expression opcodes coming 
from DebugFission (https://gcc.gnu.org/wiki/DebugFission).  Fixed by making it 
handle them like DW_OP_addr and DW_OP_const*.

OK for mainline and the active branches (it's a regression from GCC 5)?


2019-05-27  Eric Botcazou  

* dwarf2out.c (resolve_args_picking_1): Deal with DW_OP_GNU_addr_index
and DW_OP_GNU_const_index opcodes.


2019-05-27  Eric Botcazou  

* gnat.dg/specs/array4.ads: New test.

-- 
Eric BotcazouIndex: dwarf2out.c
===
--- dwarf2out.c	(revision 271106)
+++ dwarf2out.c	(working copy)
@@ -17906,6 +17906,8 @@ resolve_args_picking_1 (dw_loc_descr_ref
 	case DW_OP_push_object_address:
 	case DW_OP_call_frame_cfa:
 	case DW_OP_GNU_variable_value:
+	case DW_OP_GNU_addr_index:
+	case DW_OP_GNU_const_index:
 	  ++frame_offset_;
 	  break;
 
-- { dg-do compile }
-- { dg-skip-if "missing -gsplit-dwarf support" { *-*-darwin* } }
-- { dg-options "-gsplit-dwarf" }

package Array4 is

  type Arr1 is array (Positive range <>) of Boolean;

  Size : Positive := 20;

  type Rec is record
A : Arr1 (1 .. Size);
  end record;

  type Arr2 is array (Positive range <>) of Rec;

end Array4;


Re: Teach same_types_for_tbaa to structurally compare arrays, pointers and vectors

2019-05-27 Thread Jan Hubicka
> The way you do it above seeing struct X p will end up comparing
> 'struct X' but that doesn't really have any say on whether we
> can apply TBAA to the outermost pointer type which, if used as a base,
> cannot be subsetted by components anyway.

We remove pointers in pairs so seeing
struct X p
struct Y q
we will end up saying that these pointers are same if struct X and Y are
same (which we will do by pointer type) or if we can not decide (one of
them is void).

Non-LTO code returns 0 in the second case, but I think that could be
considered unsafe when mixing K&R and ansi-C code.
> 
> So - why's anything besides treating all structurally equivalent
> non-composite types as the same sensible here (and not waste of time)?

I think you are right that with current implementation it should not
make difference.  I want eventually to disambiguate

struct foo {struct bar *a;} ptr1;
struct foobar **ptr2;

ptr1->a and *ptr2;

Here we will currently punt on comparing different pointer types.
With structural compare we will end up to base&offset because we would
consider struct foobar * and struct bar * as same types (they are both
incomplete in LTO now).

Same_types_for_tbaa does not need to form equivalences and if we unwind
pointers&arrays to types mathing odr_comparable_p (i.e. we have two
accesses originating from C++ code), we can disambiguate incompete
pointers based on mangled name of types they point to.  I have
incremental patch for that (which futher improves disambiguations to
about 8000).
> 
> I realize this is mostly my mess but if we try to "enhance" things
> we need to make it clearer what we want...
> 
> Maybe even commonize more code paths (the path TBAA stuff is really
> replicated in at least two places IIRC).

Yep, I am trying to understand what we need to do here and clean things
up.

I guess we could handle few independent issues
1) if it is safe to return 1 for types that compare as equivalent as
   pointers (currently we return -1 if canonical types are not defined).
   This seems to handle a most common case
2) decide what to do about pointers
3) decide what to do about arrays
4) decide what to do about ODR 
5) see how much we can merge with alias set & canonical type
computation.

I would propose first just add
 if (type1 == type2)
reutrn 1;
and I will do bit deeper look at the pointers next and produce also some
testcases.

Honza
> 
> Richard.
> 
> > Honza
> > > 
> > > > +  else
> > > > +   {
> > > > + if (POINTER_TYPE_P (type1) != POINTER_TYPE_P (type2))
> > > > +   return 0;
> > > > + return in_ptr ? 1 : -1;
> > > > +   }
> > > > +
> > > > +  if (type1 == type2)
> > > > +return in_array ? -1 : 1;
> > > > +}
> > > >  
> > > >/* Compare the canonical types.  */
> > > >if (TYPE_CANONICAL (type1) == TYPE_CANONICAL (type2))
> > > > -return 1;
> > > > +return in_array ? -1 : 1;
> > > >  
> > > >/* ??? Array types are not properly unified in all cases as we have
> > > >   spurious changes in the index types for example.  Removing this
> > > >   causes all sorts of problems with the Fortran frontend.  */
> > > >if (TREE_CODE (type1) == ARRAY_TYPE
> > > >&& TREE_CODE (type2) == ARRAY_TYPE)
> > > > -return -1;
> > > > +return in_ptr ? 1 : -1;
> > > >  
> > > >/* ??? In Ada, an lvalue of an unconstrained type can be used to 
> > > > access an
> > > >   object of one of its constrained subtypes, e.g. when a function 
> > > > with an
> > > > @@ -770,7 +858,7 @@ same_type_for_tbaa (tree type1, tree typ
> > > >   not (e.g. type and subtypes can have different modes).  So, in 
> > > > the end,
> > > >   they are only guaranteed to have the same alias set.  */
> > > >if (get_alias_set (type1) == get_alias_set (type2))
> > > > -return -1;
> > > > +return in_ptr ? 1 : -1;
> > > >  
> > > >/* The types are known to be not equal.  */
> > > >return 0;
> > > > 
> > > 
> > > -- 
> > > Richard Biener 
> > > SUSE Linux GmbH, Maxfeldstrasse 5, 90409 Nuernberg, Germany;
> > > GF: Felix Imendörffer, Mary Higgins, Sri Rasiah; HRB 21284 (AG Nürnberg)
> > 
> > 
> 
> -- 
> Richard Biener 
> SUSE Linux GmbH, Maxfeldstrasse 5, 90409 Nuernberg, Germany;
> GF: Felix Imendörffer, Mary Higgins, Sri Rasiah; HRB 21284 (AG Nürnberg)



Re: [PATCH v3] Use builtin sort instead of shell sort

2019-05-27 Thread Émeric Dupont
The 20.04.2019 09:23, Andreas Schwab wrote:
>On Apr 20 2019, Émeric Dupont  wrote:
>> diff --git a/gcc/Makefile.in b/gcc/Makefile.in
>> index d186d71c91e..3196e774a26 100644
>> --- a/gcc/Makefile.in
>> +++ b/gcc/Makefile.in
>> @@ -3538,7 +3538,7 @@ install-plugin: installdirs lang.install-plugin 
>> s-header-vars install-gengtype
>>  # We keep the directory structure for files in config or c-family and .def
>>  # files. All other files are flattened to a single directory.
>>  $(mkinstalldirs) $(DESTDIR)$(plugin_includedir)
>> -headers=`echo $(PLUGIN_HEADERS) $$(cd $(srcdir); echo *.h *.def) | tr ' ' 
>> '\012' | sort -u`; \
>> +headers=$(sort $(PLUGIN_HEADERS) $$(cd $(srcdir); echo *.h *.def)); \
>
>This sorts the words $(PLUGIN_HEADERS) '$(cd' $(srcdir); echo '*.h'
>'*.def)' and produces a command line that doesn't make sense.
>
Thanks for pointing this out! I will provide an updated patch as soon as
I made sure the unwanted mail footer disappears (Sorry it took so long,
it had to go through the legal department first.)



--
Emeric Dupont
Zodiac Inflight Innovations
P +49815388678207
Argelsrieder Feld, 22 - 82234 Wessling
www.safran-aerosystems.com



TriaGnoSys GmbH, Registergericht: München HRB 141647, Vat.: DE 813396184 
Geschäftsführer: Núria Riera Díaz, Peter Lewalter


[PATCH] Fix PR90615

2019-05-27 Thread Richard Biener


Committed.

Richard.

2019-05-27  Richard Biener  

PR testsuite/90615
* gcc.dg/vect/costmodel/ppc/costmodel-vect-31b.c: Add
-fno-tree-loop-distribute-patterns.
* gcc.dg/vect/costmodel/ppc/costmodel-vect-33.c: Likewise.
* gcc.dg/vect/costmodel/ppc/costmodel-vect-76a.c: Likewise.
* gcc.dg/vect/costmodel/ppc/costmodel-vect-76b.c: Likewise.
* gcc.dg/vect/costmodel/ppc/costmodel-vect-76c.c: Likewise.
* gcc.target/powerpc/vsx-vectorize-1.c: Likewise.

Index: gcc/testsuite/gcc.dg/vect/costmodel/ppc/costmodel-vect-31b.c
===
--- gcc/testsuite/gcc.dg/vect/costmodel/ppc/costmodel-vect-31b.c
(revision 271644)
+++ gcc/testsuite/gcc.dg/vect/costmodel/ppc/costmodel-vect-31b.c
(working copy)
@@ -1,4 +1,5 @@
 /* { dg-require-effective-target vect_int } */
+/* { dg-additional-options "-fno-tree-loop-distribute-patterns" } */
 
 #include 
 #include "../../tree-vect.h"
Index: gcc/testsuite/gcc.dg/vect/costmodel/ppc/costmodel-vect-33.c
===
--- gcc/testsuite/gcc.dg/vect/costmodel/ppc/costmodel-vect-33.c (revision 
271644)
+++ gcc/testsuite/gcc.dg/vect/costmodel/ppc/costmodel-vect-33.c (working copy)
@@ -1,5 +1,6 @@
 /* { dg-do compile } */
 /* { dg-require-effective-target vect_int } */
+/* { dg-additional-options "-fno-tree-loop-distribute-patterns" } */
 
 #include 
 #include "../../tree-vect.h"
Index: gcc/testsuite/gcc.dg/vect/costmodel/ppc/costmodel-vect-76a.c
===
--- gcc/testsuite/gcc.dg/vect/costmodel/ppc/costmodel-vect-76a.c
(revision 271644)
+++ gcc/testsuite/gcc.dg/vect/costmodel/ppc/costmodel-vect-76a.c
(working copy)
@@ -1,4 +1,5 @@
 /* { dg-require-effective-target vect_int } */
+/* { dg-additional-options "-fno-tree-loop-distribute-patterns" } */
 
 #include 
 #include "../../tree-vect.h"
Index: gcc/testsuite/gcc.dg/vect/costmodel/ppc/costmodel-vect-76b.c
===
--- gcc/testsuite/gcc.dg/vect/costmodel/ppc/costmodel-vect-76b.c
(revision 271644)
+++ gcc/testsuite/gcc.dg/vect/costmodel/ppc/costmodel-vect-76b.c
(working copy)
@@ -1,4 +1,5 @@
 /* { dg-require-effective-target vect_int } */
+/* { dg-additional-options "-fno-tree-loop-distribute-patterns" } */
 
 #include 
 #include "../../tree-vect.h"
Index: gcc/testsuite/gcc.dg/vect/costmodel/ppc/costmodel-vect-76c.c
===
--- gcc/testsuite/gcc.dg/vect/costmodel/ppc/costmodel-vect-76c.c
(revision 271644)
+++ gcc/testsuite/gcc.dg/vect/costmodel/ppc/costmodel-vect-76c.c
(working copy)
@@ -1,4 +1,5 @@
 /* { dg-require-effective-target vect_int } */
+/* { dg-additional-options "-fno-tree-loop-distribute-patterns" } */
 
 #include 
 #include "../../tree-vect.h"
Index: gcc/testsuite/gcc.target/powerpc/vsx-vectorize-1.c
===
--- gcc/testsuite/gcc.target/powerpc/vsx-vectorize-1.c  (revision 271644)
+++ gcc/testsuite/gcc.target/powerpc/vsx-vectorize-1.c  (working copy)
@@ -1,7 +1,7 @@
 /* { dg-do compile { target { powerpc*-*-* && lp64 } } } */
 /* { dg-skip-if "" { powerpc*-*-darwin* } } */
 /* { dg-require-effective-target powerpc_vsx_ok } */
-/* { dg-options "-mdejagnu-cpu=power7 -O2 -ftree-vectorize 
-fno-vect-cost-model -fdump-tree-vect-details" } */
+/* { dg-options "-mdejagnu-cpu=power7 -O2 -ftree-vectorize 
-fno-tree-loop-distribute-patterns -fno-vect-cost-model 
-fdump-tree-vect-details" } */
 
 /* Taken from vect/vect-align-1.c.  */
 #include 


Re: [PATCH] Fix PR88440, enable mem* detection at -O[2s]

2019-05-27 Thread Richard Biener
On Mon, 27 May 2019, Christophe Lyon wrote:

> On Thu, 23 May 2019 at 13:32, Richard Biener  wrote:
> >
> > On Wed, 22 May 2019, Richard Biener wrote:
> >
> > >
> > > This enables -ftree-loop-distribute-patterns at -O[2s] and also
> > > arranges cold loops to be still processed but for pattern
> > > recognition to save code-size.
> > >
> > > Bootstrap and regtest running on x86_64-unknown-linux-gnu.
> > >
> > > Martin has done extensive compile-time testing on SPEC
> > > identifying only a single regression I'll have a look into.
> >
> > The reason for the compile-time regression is the complexity
> > heuristic in LRA no longer choosing "simple" algorithms and
> > the LIVE problem in particular being awfully slow.
> >
> > Unsurprisingly testing has also revealed loads of testsuite
> > fallout which I deal with in the patch as committed below.
> > Sorry for any further fallout on other targets (which I do
> > expect).
> >
> 
> Hi 
> Richard,http://people.linaro.org/~christophe.lyon/cross-validation/gcc/trunk/271588/report-build-info.html
> 
> Indeed git bisect pointed me to this commit when checking
> the regressions on arm & aarch64 reported at:
> http://people.linaro.org/~christophe.lyon/cross-validation/gcc/trunk/271588/report-build-info.html
> 
> Since I'm a bit later in reporting, I'm not sure you've fixed them already?
> (I didn't notice follow-ups)
> Looking at this patch, it seems adding -fno-tree-loop-distribute-patterns to
> dg-options is the standard way of fixing the regressions?

Yes.  As I wrote above I did expect some target specific fallout and
hoped target maintainers would fix that.

Richard.

> Christophe
> 
> > Bootstrapped and tested on x86_64-unknown-linux-gnu, applied.
> >
> > Richard.
> >
> > 2019-05-23  Richard Biener  
> >
> > PR tree-optimization/88440
> > * opts.c (default_options_table): Enable 
> > -ftree-loop-distribute-patterns
> > at -O[2s]+.
> > * tree-loop-distribution.c (generate_memset_builtin): Fold the
> > generated call.
> > (generate_memcpy_builtin): Likewise.
> > (distribute_loop): Pass in whether to only distribute patterns.
> > (prepare_perfect_loop_nest): Also allow size optimization.
> > (pass_loop_distribution::execute): When optimizing a loop
> > nest for size allow pattern replacement.
> >
> > * gcc.dg/tree-ssa/ldist-37.c: New testcase.
> > * gcc.dg/tree-ssa/ldist-38.c: Likewise.
> > * gcc.dg/vect/vect.exp: Add -fno-tree-loop-distribute-patterns.
> > * gcc.dg/tree-ssa/ldist-37.c: Adjust.
> > * gcc.dg/tree-ssa/ldist-38.c: Likewise.
> > * g++.dg/tree-ssa/pr78847.C: Likewise.
> > * gcc.dg/autopar/pr39500-1.c: Likewise.
> > * gcc.dg/autopar/reduc-1char.c: Likewise.
> > * gcc.dg/autopar/reduc-7.c: Likewise.
> > * gcc.dg/tree-ssa/ivopts-lt-2.c: Likewise.
> > * gcc.dg/tree-ssa/ivopts-lt.c: Likewise.
> > * gcc.dg/tree-ssa/predcom-dse-1.c: Likewise.
> > * gcc.dg/tree-ssa/predcom-dse-2.c: Likewise.
> > * gcc.dg/tree-ssa/predcom-dse-3.c: Likewise.
> > * gcc.dg/tree-ssa/predcom-dse-4.c: Likewise.
> > * gcc.dg/tree-ssa/prefetch-7.c: Likewise.
> > * gcc.dg/tree-ssa/prefetch-8.c: Likewise.
> > * gcc.dg/tree-ssa/prefetch-9.c: Likewise.
> > * gcc.dg/tree-ssa/scev-11.c: Likewise.
> > * gcc.dg/vect/costmodel/i386/costmodel-vect-31.c: Likewise.
> > * gcc.dg/vect/costmodel/i386/costmodel-vect-33.c: Likewise.
> > * gcc.dg/vect/costmodel/x86_64/costmodel-vect-31.c: Likewise.
> > * gcc.dg/vect/costmodel/x86_64/costmodel-vect-33.c: Likewise.
> > * gcc.target/i386/pr30970.c: Likewise.
> > * gcc.target/i386/vect-double-1.c: Likewise.
> > * gcc.target/i386/vect-double-2.c: Likewise.
> > * gcc.dg/tree-ssa/gen-vect-2.c: Likewise.
> > * gcc.dg/tree-ssa/gen-vect-26.c: Likewise.
> > * gcc.dg/tree-ssa/gen-vect-28.c: Likewise.
> > * gcc.dg/tree-ssa/gen-vect-32.c: Likewise.
> > * gfortran.dg/vect/vect-5.f90: Likewise.
> > * gfortran.dg/vect/vect-8.f90: Likewise.
> >
> > Index: gcc/opts.c
> > ===
> > --- gcc/opts.c  (revision 271513)
> > +++ gcc/opts.c  (working copy)
> > @@ -550,7 +550,7 @@ static const struct default_options defa
> >  { OPT_LEVELS_3_PLUS, OPT_fpredictive_commoning, NULL, 1 },
> >  { OPT_LEVELS_3_PLUS, OPT_fsplit_loops, NULL, 1 },
> >  { OPT_LEVELS_3_PLUS, OPT_fsplit_paths, NULL, 1 },
> > -{ OPT_LEVELS_3_PLUS, OPT_ftree_loop_distribute_patterns, NULL, 1 },
> > +{ OPT_LEVELS_2_PLUS, OPT_ftree_loop_distribute_patterns, NULL, 1 },
> >  { OPT_LEVELS_3_PLUS, OPT_ftree_loop_distribution, NULL, 1 },
> >  { OPT_LEVELS_3_PLUS, OPT_ftree_loop_vectorize, NULL, 1 },
> >  { OPT_LEVELS_3_PLUS, OPT_ftree_partial_pre, NULL, 1 },
> > Index: gcc/testsuite/g++.dg/tree-ssa/

Re: [PATCH] PR c/86407 - Add option to ignore fndecl attributes on function pointers

2019-05-27 Thread Richard Biener
On Sat, 25 May 2019, Alex Henrie wrote:

> On Sat, May 25, 2019 at 12:34 AM Richard Biener  wrote:
> >
> > On May 24, 2019 5:49:38 PM GMT+02:00, Alex Henrie  
> > wrote:
> > >As far as I can tell, "fndecl" is a misnomer: these attributes are
> > >more accurately called "function definition attributes", i.e.
> > >attributes that affect the assembly code of the function but do not
> > >affect its calling convention.
> >
> > Yes. The others are attributes also applicable to function types to 
> > properly support attributed indirect calls.
> 
> I'm happy to rename ix86_handle_fndecl_attribute to
> ix86_handle_fndef_attribute then. Should I do that in this patch or a
> separate patch?

I don't see this fixes anything.  It's pretty well-know that attributes
affecting call semantics have to be accepted both at type and decl
position and that they should be added to the type attributes.
Attributes that only affect code generation for the function itself
should be added to decl attributes and do not necessarily need to
be accepted in type position.


Re: Teach same_types_for_tbaa to structurally compare arrays, pointers and vectors

2019-05-27 Thread Richard Biener
On Fri, 24 May 2019, Jan Hubicka wrote:

> > > so about 5 times increase of alias_components_refs_p disambiguations.
> > 
> > Note the number of queries also changes so it's "somewhat" comparing
> > apples and oranges (possibly the alias walk doesn't have to give up
> > and thus we walk more and do more queries).
> 
> Yep, I know. If you disambiguate you may increase number of queries
> overall because oracles walks further or decrease because tings get
> optimized out.
> 
> It is however relatively useful to check if patch is doing something :)
> 
> > > +  /* If same_type_for_tbaa returns true we make an assumption that 
> > > pointers to
> > > + TYPE1 and TYPE2 can either point to same copy of the type or 
> > > completely
> > > + different.
> > > +
> > > + This is not necessarily true for arrays where overlap can be partial
> > > + as in gcc.dg/torture/alias-2.c.  So we can only prove that arrays 
> > > are
> > > + disjoint becuase they are derived from different types but we can 
> > > not
> > > + prove they are same.
> > > +
> > > + On the other hand for pointers we can always consider them to be 
> > > same
> > > + unless we can prove that pointed-to types are different.
> > 
> > What about different address-spaces and/or pointer sizes?
> > 
> > > + So normally return values are
> > > +   0  if types are known to be different
> > > +   1  if types are same and there is no partial overlap
> > > +   -1 otherwise.
> > > +
> > > + However if comparing two pointers return values are
> > > +   0  if pointed to types are known to be different
> > > +   1  otherwise (because partial overlaps do not happen).
> > 
> > Doesn't this apply to all non-composite types?  (the "partial overlaps
> > do not happen"?)
> 
> I think we should have TYPE_CANONICAL defined on those so the comparsion
> should follow the usual way.
> > 
> > > + If comparing array or vector to other type return values are
> > > +   0  if types array/vector are derived from are known to be 
> > > different
> > > +   -1 otherwise (to watch for partial overlaps).  */
> > > +
> > > +  bool in_ptr = false;
> > > +  bool in_array = false;
> > > +
> > > +  if (type1 == type2)
> > > +return 1;
> > > +
> > > +  /* Do structural comparsion for types that have no canonical types in 
> > > LTO.  */
> > > +  while (TYPE_STRUCTURAL_EQUALITY_P (type1)
> > > +  || TYPE_STRUCTURAL_EQUALITY_P (type2))
> > > +{
> > > +  /* Pointer types are same if they point to same types.  */
> > > +  if (POINTER_TYPE_P (type1) && POINTER_TYPE_P (type2))
> > > + {
> > > +   type1 = TYPE_MAIN_VARIANT (TREE_TYPE (type1));
> > > +   type2 = TYPE_MAIN_VARIANT (TREE_TYPE (type2));
> > > +   if (!in_array)
> > > + in_ptr = true;
> > 
> > Don't you run into unrelated types when visiting pointed-to types
> > here?  Why would we care for the pointed-to type anwyways?
> 
> What do you mean by unrelated type here?
> > 
> > That is, the loop should just handle composite types
> > and after it compare non-composite types with
> > types_compatible_p for example?  Maybe even do that change
> > independently.
> 
> It would probably give more 1s and less 0s which would, in turn, make
> aliasing_component_refs to apply range check (which will return 1)
> instead of concluding that access paths are disjoint.
> 
> Why do you think this is better than looking up the pointed-to type
> and comparing that one?

The way you do it above seeing struct X p will end up comparing
'struct X' but that doesn't really have any say on whether we
can apply TBAA to the outermost pointer type which, if used as a base,
cannot be subsetted by components anyway.

So - why's anything besides treating all structurally equivalent
non-composite types as the same sensible here (and not waste of time)?

> > 
> > > + }
> > > +  /* Peel out arrays and vector to compare inner types.  */
> > > +  else if ((TREE_CODE (type1) == ARRAY_TYPE
> > > + || TREE_CODE (type1) == VECTOR_TYPE)
> > > +&& TYPE_STRUCTURAL_EQUALITY_P (type1))
> > > + {
> > > +   type1 = TYPE_MAIN_VARIANT (TREE_TYPE (type1));
> > > +   if (!in_ptr)
> > > + in_array = true;
> > > + }
> > > +  else if ((TREE_CODE (type2) == ARRAY_TYPE
> > > + || TREE_CODE (type2) == VECTOR_TYPE)
> > > +&& TYPE_STRUCTURAL_EQUALITY_P (type2))
> > > + {
> > > +   type2 = TYPE_MAIN_VARIANT (TREE_TYPE (type2));
> > > +   if (!in_ptr)
> > > + in_array = true;
> > > + }
> > 
> > I don't think it works like this, peeling arrays/vectors from
> > types individually instead of in lock-step?
> 
> The intention here is behave similarly to get_alias_set and handle
> declare arrays/vectors to be the same as the type they are derived from
> + dissabling the assumption about non-existence of partial overlaps.

But this will cause us to use path based disambiguation for, say
a[i][j].b vs. (*p)[k].b, no?

I think we need to clarify what the comparison r