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

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

Hi.
Thanks for the review. See the comments below.
I attached the updated patch.

On Thu, Oct 15, 2020 at 05:52:33PM -0400, David Malcolm wrote:

On Thu, 2020-10-15 at 13:39 -0400, Antoni Boucher wrote:

Thanks. I updated the patch with these changes.


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


2020-09-1  Antoni Boucher  

gcc/jit/
PR target/96889
* docs/topics/compatibility.rst (LIBGCCJIT_ABI_14): New ABI tag.


15 now.


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


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


Is there any way to run that locally to check the format automatically?




* libgccjit.h


Likewise.


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


15 now.



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


[...]



diff --git a/gcc/jit/docs/topics/functions.rst 
b/gcc/jit/docs/topics/functions.rst
index eb40d64010e..9819c28cda2 100644
--- a/gcc/jit/docs/topics/functions.rst
+++ b/gcc/jit/docs/topics/functions.rst
@@ -171,6 +171,16 @@ Functions
underlying string, so it is valid to pass in a pointer to an on-stack
buffer.

+.. function::  size_t \
+   gcc_jit_function_get_param_count (gcc_jit_function *func)
+
+   Get the number of parameters of the function.
+
+.. function::  gcc_jit_type \*
+   gcc_jit_function_get_return_type (gcc_jit_function *func)
+
+   Get the return type of the function.
+


The documentation part of the patch is incomplete: it hasn't been
updated to add all the new entrypoints.


Indeed, I wanted some feedback before I write the documentation. I'll 
write it soon.



Also, the return type of gcc_jit_function_get_param_count is
inconsistent (size_t above, but ssize_t below).



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


Can't you use dyn_cast_struct for this?


We could, but wouldn't that be inconvenient for the user to call 
gcc_jit_type_unqualified every time they want to call a function such as 
gcc_jit_type_is_struct?
(I don't mind if you prefer to make the call to gcc_jit_type_unqualified 
explicit in user code.)



Or is this about looking through decorated_type? e.g. for const and
volatile variants?

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


The purpose is to be able to get information about the fields of the 
struct, if the type is a struct.





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


Likewise, can't you use dyn_cast_vector_type for this?


Same as for is_struct().


   virtual bool has_known_size () const { return true; }

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


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


   bool is_void () const FINAL OVERRIDE { return m_kind == GCC_JIT_TYPE_VOID; }

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


Likewise.



@@ -655,6 +661,7 @@ public:
   bool 

Re: [PATCH 1/9, revised] PowerPC: Map long double built-in functions if IEEE 128-bit long double.

2020-10-16 Thread Segher Boessenkool
On Fri, Oct 09, 2020 at 12:35:44AM -0400, Michael Meissner wrote:
> This patch is revised from the first version of the patch posted.

In the future, please send a NEW series, in a NEW thread, when you have
a new series.  I was waiting for a new series (because you needed
changes), and I missed that you posted it in the old thread.

If you do not want to because the patches are independent (and not
actually a series), you can send them as independent patches as well
(and that is easier to handle, independent things become much more
obviously independent!)

> Normally the mapping is done in the math.h and stdio.h files.  However, not
> everybody uses these files, which means we also need to change the external
> name for the built-in function within the compiler.

Because those are *not* defined in those headers.  So those headers are
completely irrelevant to this.

> --- a/gcc/config/rs6000/rs6000.c
> +++ b/gcc/config/rs6000/rs6000.c
> @@ -26897,56 +26897,156 @@ rs6000_globalize_decl_name (FILE * stream, tree 
> decl)
> library before you can switch the real*16 type at compile time.
>  
> We use the TARGET_MANGLE_DECL_ASSEMBLER_NAME hook to change this name.  We
> -   only do this if the default is that long double is IBM extended double, 
> and
> -   the user asked for IEEE 128-bit.  */
> +   only do this transformation if the __float128 type is enabled.  This
> +   prevents us from doing the transformation on older 32-bit ports that might
> +   have enabled using IEEE 128-bit floating point as the default long double
> +   type.  */

But that is just as broken then?

> + default:
> +   break;

Please don't invert the natural order, leave the default at the bottom.
Just like you should not write "0 == x".

> + case BUILT_IN_NEXTTOWARD:
> +   newname = "__nexttoward_to_ieee128";
> +   break;
> +
> + case BUILT_IN_NEXTTOWARDF:
> +   newname = "__nexttowardf_to_ieee128";
> +   break;

Why the "_to_" in those?  How irregular.

> + case BUILT_IN_SCALBL:
> +   newname = "__scalbnieee128";
> +   break;

Should that be __scalbieee128?

> +  /* Update the __builtin_*printf && __builtin_*scanf functions.  */
> +  if (!newname)
> + {
> +   const size_t printf_len = sizeof ("printf") - 1;

The "const" here has no function; the compiler *knows* this is a
constant number.

Please use strlen, and no - 1.

> +   if (len >= printf_len
> +   && strcmp (name + len - printf_len, "printf") == 0)

Thew first test is unnecessary.

> + {
> +   char *name2 = (char *) alloca (len + 1 + printf_extra);
> +   strcpy (name2, "__");
> +   memcpy (name2 + 2, name, len);
> +   strcpy (name2 + 2 + len, "ieee128");
> +   newname = (const char *) name2;
> + }

Maybe just use asprintf and simplify all of this massively?  It's not
like a malloc here or there will be measurably slower (if it was, you
need to do all of this differently anyway, with some caching etc.)

> +   /* See if the function passes a IEEE 128-bit floating point 
> type
> +  or complex type.  */
> +   FOREACH_FUNCTION_ARGS (type, arg, args_iter)
>   {
> -   uses_ieee128_p = true;
> -   break;
> +   machine_mode arg_mode = TYPE_MODE (arg);
> +   if (arg_mode == TFmode || arg_mode == TCmode)
> + {
> +   uses_ieee128_p = true;
> +   break;
> + }

I don't see why TFmode would mean it is IEEE?  TFmode can be IBM128 as
well?


Segher


Re: [patch, fortran] Partial fix for PR97454, declarations of some library functions

2020-10-16 Thread Thomas Koenig via Gcc-patches

I wrote:


Regression-tested. OK for trunk?


I will remove this part

-   When an actual argument list is provided, skip the absent arguments.
+   When an actual argument list is provided, skip the absent arguments
+   unless copy_type is true.
To be used together with gfc_se->ignore_optional.  */

(which was true for an intermediate version of the patch)
before committing.

Regards

Thomas


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

2020-10-16 Thread Thomas Koenig via Gcc-patches

Hello Harald,


*ping*



OK for master / 10-branch?


OK for both (with a suitable waiting period).

Best regards

Thomas


[patch, fortran] Partial fix for PR97454, declarations of some library functions

2020-10-16 Thread Thomas Koenig via Gcc-patches

Hello world,

here's a patch which corrects some wrong declarations (and fixes
the segfault for FINDLOC on Darwin ARM).

Regression-tested. OK for trunk?

Best regards

Thomas

Correct decls for functions which do not pass actual arguments.

A wrong decl for findloc caused segfaults at runtime on
Darwin for ARM; however, this is only a symptom of a larger
disease: The declarations for our library functions are often
inconsistent.  This patch solves that problem for the functions
specifically for the functions for which we do not pass optional
arguments, i.e. findloc and (min|max)loc.

It works by saving the symbols of the specific functions in
gfc_intrinsic_namespace and by generating the formal argument
lists from the actual argument lists.  Because symbols are
re-used, so are the backend decls.

gcc/fortran/ChangeLog:

PR fortran/97454
* gfortran.h (gfc_symbol): Add pass_as_value flag.
(gfc_copy_formal_args_intr): Add optional argument
copy_type.
(gfc_get_intrinsic_function_symbol): Add prototype.
(gfc_find_intrinsic_symbol): Add prototype.
* intrinsic.c (gfc_get_intrinsic_function_symbol): New function.
(gfc_find_intrinsic_symbol): New function.
* symbol.c (gfc_copy_formal_args_intr): Add argument. Handle case
where the type needs to be copied from the actual argument.
* trans-intrinsic.c (remove_empty_actual_arguments): New function.
(specific_intrinsic_symbol): New function.
(gfc_conv_intrinsic_funcall): Use it.
(strip_kind_from_actual): Adjust so that the expression pointer
is set to NULL.
(gfc_conv_intrinsic_minmaxloc): Likewise.
(gfc_conv_intrinsic_minmaxval): Adjust removal of dim.
* trans-types.c (gfc_sym_type): If sym->pass_as_value is set, do
not pass by reference.
diff --git a/gcc/fortran/gfortran.h b/gcc/fortran/gfortran.h
index d0cea838444..37fed61a679 100644
--- a/gcc/fortran/gfortran.h
+++ b/gcc/fortran/gfortran.h
@@ -1664,6 +1664,9 @@ typedef struct gfc_symbol
   /* Set if the dummy argument of a procedure could be an array despite
  being called with a scalar actual argument. */
   unsigned maybe_array:1;
+  /* Set if this should be passed by value, but is not a VALUE argument
+ according to the Fortran standard.  */
+  unsigned pass_as_value:1;
 
   int refs;
   struct gfc_namespace *ns;	/* namespace containing this symbol */
@@ -3239,7 +3242,7 @@ bool gfc_type_is_extension_of (gfc_symbol *, gfc_symbol *);
 bool gfc_type_compatible (gfc_typespec *, gfc_typespec *);
 
 void gfc_copy_formal_args_intr (gfc_symbol *, gfc_intrinsic_sym *,
-gfc_actual_arglist *);
+gfc_actual_arglist *, bool copy_type = false);
 
 void gfc_free_finalizer (gfc_finalizer *el); /* Needed in resolve.c, too  */
 
@@ -3264,6 +3267,8 @@ void gfc_intrinsic_done_1 (void);
 
 char gfc_type_letter (bt, bool logical_equals_int = false);
 gfc_symbol * gfc_get_intrinsic_sub_symbol (const char *);
+gfc_symbol *gfc_get_intrinsic_function_symbol (gfc_expr *);
+gfc_symbol *gfc_find_intrinsic_symbol (gfc_expr *);
 bool gfc_convert_type (gfc_expr *, gfc_typespec *, int);
 bool gfc_convert_type_warn (gfc_expr *, gfc_typespec *, int, int,
 			bool array = false);
diff --git a/gcc/fortran/intrinsic.c b/gcc/fortran/intrinsic.c
index ef33587a774..938a2f3606b 100644
--- a/gcc/fortran/intrinsic.c
+++ b/gcc/fortran/intrinsic.c
@@ -122,6 +122,43 @@ gfc_get_intrinsic_sub_symbol (const char *name)
   return sym;
 }
 
+/* Get a symbol for a resolved function, with its special name.  The
+   actual argument list needs to be set by the caller.  */
+
+gfc_symbol *
+gfc_get_intrinsic_function_symbol (gfc_expr *expr)
+{
+  gfc_symbol *sym;
+
+  gfc_get_symbol (expr->value.function.name, gfc_intrinsic_namespace, );
+  sym->attr.external = 1;
+  sym->attr.function = 1;
+  sym->attr.always_explicit = 1;
+  sym->attr.proc = PROC_INTRINSIC;
+  sym->attr.flavor = FL_PROCEDURE;
+  sym->result = sym;
+  if (expr->rank > 0)
+{
+  sym->attr.dimension = 1;
+  sym->as = gfc_get_array_spec ();
+  sym->as->type = AS_ASSUMED_SHAPE;
+  sym->as->rank = expr->rank;
+}
+  return sym;
+}
+
+/* Find a symbol for a resolved intrinsic procedure, return NULL if
+   not found.  */
+
+gfc_symbol *
+gfc_find_intrinsic_symbol (gfc_expr *expr)
+{
+  gfc_symbol *sym;
+  gfc_find_symbol (expr->value.function.name, gfc_intrinsic_namespace,
+		   0, );
+  return sym;
+}
+
 
 /* Return a pointer to the name of a conversion function given two
typespecs.  */
diff --git a/gcc/fortran/symbol.c b/gcc/fortran/symbol.c
index df1e8965daa..a112c813124 100644
--- a/gcc/fortran/symbol.c
+++ b/gcc/fortran/symbol.c
@@ -4645,12 +4645,13 @@ add_proc_interface (gfc_symbol *sym, ifsrc source, gfc_formal_arglist *formal)
declaration statement (see match_proc_decl()) to create the formal
args based on the args of a given named interface.
 
-   When an actual argument list is provided, 

Re: [PATCH 0/9] PowerPC: Patches to enable changing the long double default to IEEE 128-bit on little endian PowerPC 64-bit Linux systems

2020-10-16 Thread Segher Boessenkool
On Thu, Sep 24, 2020 at 04:20:36PM -0400, Michael Meissner wrote:
> This series of 9 patches is an attempt to gather together all of the patches
> that are needed to be able to configure and build a little endian 64-bit
> PowerPC Linux GCC compiler where the defualt long double format uses the IEEE
> 128-bit representation.
> 
> I have created an IBM vendor branch that includes these patches (along the
> other outstanding patches that I have for IEEE 128-bit min/max/cmove on
> power10, and power10 PCREL_OPT support):
> 
>   vendors/ibm/ieee-longdouble-001
> 
> You will need a new enough GLIBC in order to do this configuration.

What happens if you glibc is older, and you try?


Segher


[PATCH] Don't display ranges for dead ssa-names.

2020-10-16 Thread Andrew MacLeod via Gcc-patches
AS Jakub  observed in an earlier testcase (97325),  when EVRP dumps the 
known SSA_RANGES, it isn't expecting names to be deleted that it could 
not delete, so it wasn't checking.


With the hybrid model, ranger sometimes deletes things that EVRP 
calculated a range for, and the resulting dump was confusing


 _1: short unsigned int VARYING
 _2: int [0, 65535]
 _3: int [-65535, 0]
 : int [0, 32]
 : long long unsigned int [0, 0]
 c_6(D): long long unsigned int VARYING
 : long long unsigned int [0, 32]

Now we just check if then name is valid before dumping.

Bootstrapped on x86_64-pc-linux-gnu,  no regressions, pushed.
2020-10-16  Andrew MacLeod  

	* vr-values.c (dump_all_value_ranges): Only dump names which are
	still active.


diff --git a/gcc/vr-values.c b/gcc/vr-values.c
index da0b249278b..e917704d9bb 100644
--- a/gcc/vr-values.c
+++ b/gcc/vr-values.c
@@ -1999,7 +1999,7 @@ vr_values::dump_all_value_ranges (FILE *file)
 
   for (i = 0; i < num_vr_values; i++)
 {
-  if (vr_value[i])
+  if (vr_value[i] && ssa_name (i))
 	{
 	  print_generic_expr (file, ssa_name (i));
 	  fprintf (file, ": ");


[PATCH] pointer_plus [0, 0] + const folding

2020-10-16 Thread Andrew MacLeod via Gcc-patches
In order to match evrp behaviour, adjust POINTER_PLUS_EXPR processing to 
handle a zero constant plus something to return the something.

ie

[0, 0]  + CONST    will now return [CONST, CONST] instead of the 
previous behaviour of [1, +INF].



Bootstrapped on x86_64-pc-linux-gnu, no regressions, pushed.

Andrew
2020-10-16  Andrew MacLeod  

	* range-op.cc (pointer_plus_operator::wi_fold): Make pointer_plus
	[0, 0] + const return a [const, const] range.


diff --git a/gcc/range-op.cc b/gcc/range-op.cc
index 6108de367ad..9df08a61289 100644
--- a/gcc/range-op.cc
+++ b/gcc/range-op.cc
@@ -3063,6 +3063,14 @@ pointer_plus_operator::wi_fold (irange , tree type,
 const wide_int _lb,
 const wide_int _ub) const
 {
+  // Check for [0,0] + const, and simply return the const.
+  if (lh_lb == 0 && lh_ub == 0 && rh_lb == rh_ub)
+{
+  tree val = wide_int_to_tree (type, rh_lb);
+  r.set (val, val);
+  return;
+}
+
   // For pointer types, we are really only interested in asserting
   // whether the expression evaluates to non-NULL.
   //


[PATCH] Don't invoke range_of_expr multiple times.

2020-10-16 Thread Andrew MacLeod via Gcc-patches
In the hybrid folder, range_of_stmt and range_on_edge invoke the same 
routines in both evrp_folder and ranger_folder and compare results.


In implementing hybrid folder, I inherited it from evrp_folder since 
EVRP has a few pre-and post statement things to do.


when the hybdrid folder calls evrp_folder::range_on_edge (or stmt) the 
evrp folder simple invokes range_of_expr() for evaluation.
Because I inherited from evrp_folder, this actually calls 
hybrid_folder::range_of_expr(), which in turns invokes both evrp_folder 
AND ranger on the query.


This was not my intention, and results in additional ranger queries 
without any context.    Instead, the calls should be made directly to 
evrp_folder::range_of_expr.



Bootstrapped on x86_64-pc-linux-gnu,  no regressions, pushed.

Andrew
2020-10-16  Andrew MacLeod  

	* gimple-ssa-evrp.c (hybrid_folder::value_on_edge): Call
	evrp_folder::value_of_expr directly.
	(hybrid_folder::value_of_stmt): Ditto.


diff --git a/gcc/gimple-ssa-evrp.c b/gcc/gimple-ssa-evrp.c
index 7688e4aa4bd..309cdd94c21 100644
--- a/gcc/gimple-ssa-evrp.c
+++ b/gcc/gimple-ssa-evrp.c
@@ -239,7 +239,9 @@ hybrid_folder::value_of_expr (tree op, gimple *stmt)
 tree
 hybrid_folder::value_on_edge (edge e, tree op)
 {
-  tree evrp_ret = evrp_folder::value_on_edge (e, op);
+  // Call evrp::value_of_expr directly.  Otherwise another dual call is made
+  // via hybrid_folder::value_of_expr, but without an edge.
+  tree evrp_ret = evrp_folder::value_of_expr (op, NULL);
   tree ranger_ret = m_ranger->value_on_edge (e, op);
   return choose_value (evrp_ret, ranger_ret);
 }
@@ -247,7 +249,14 @@ hybrid_folder::value_on_edge (edge e, tree op)
 tree
 hybrid_folder::value_of_stmt (gimple *stmt, tree op) 
 {
-  tree evrp_ret = evrp_folder::value_of_stmt (stmt, op);
+  // Call evrp::value_of_expr directly.  Otherwise another dual call is made
+  // via hybrid_folder::value_of_expr, but without a stmt.
+  tree evrp_ret;
+  if (op)
+evrp_ret = evrp_folder::value_of_expr (op, NULL);
+  else
+evrp_ret = NULL_TREE;
+
   tree ranger_ret = m_ranger->value_of_stmt (stmt, op);
   return choose_value (evrp_ret, ranger_ret);
 }


[PATCH] Don't assert on a negative shift.

2020-10-16 Thread Andrew MacLeod via Gcc-patches
We were asserting that the shifts should not be negative, instead, just 
return false indicating we can't tell anything about operand1 from the 
result.


Bootstrapped on x86_64-pc-linux-gnu,  no regressions, pushed.

Andrew


2020-10-16  Andrew Macleod  

	PR tree-optimization/97462
	gcc/
	* range-op.cc (operator_lshift::op1_range): Don't trap on negative
	shifts.
	gcc/testsuite/
	 * gcc.dg/pr97462.c: New file.


diff --git a/gcc/range-op.cc b/gcc/range-op.cc
index 6108de367ad..0efa00186e8 100644
--- a/gcc/range-op.cc
+++ b/gcc/range-op.cc
@@ -1577,7 +1577,8 @@ operator_lshift::op1_range (irange ,
   if (op2.singleton_p (_amount))
 {
   wide_int shift = wi::to_wide (shift_amount);
-  gcc_checking_assert (wi::gt_p (shift, 0, SIGNED));
+  if (wi::lt_p (shift, 0, SIGNED))
+	return false;
 
   // Work completely in unsigned mode to start.
   tree utype = type;
diff --git a/gcc/testsuite/gcc.dg/pr97462.c b/gcc/testsuite/gcc.dg/pr97462.c
new file mode 100644
index 000..52c0533c98e
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr97462.c
@@ -0,0 +1,10 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -w" } */
+
+int a, b;
+
+void d ()
+{
+  a << ~0 && b;
+  b = a;
+}


[PATCH] cplxlower: Avoid a transform when looking at a default definition

2020-10-16 Thread Martin Jambor
Hi,

in PR 97456, IPA-SRA triggers a bug in tree-complex.c where it
converts:

 
   a$_M_value_21 = COMPLEX_EXPR ;

(where ISRA.18 is IPA-SRA created PARM_DECL with DECL_IGNORED_P set,
which is why it only happens with IPA-SRA) into:

  
a$_M_value_21 = COMPLEX_EXPR ;

i.e. it replaces two uses of the parameter default-def with two
uninitialized default-defs of a new variable - all in hope to produce
code with better debug info.

This patch fixes it by avoiding the transform when the SSA_NAME to be
replaced is a default definition.  Bootstrapped and tested on
x86_64-linux.  OK for trunk and the gcc-10 branch?

Thanks,

Martin


gcc/ChangeLog:

2020-10-16  Martin Jambor  

PR tree-optimization/97456
* tree-complex.c (set_component_ssa_name): Do not replace ignored decl
default definitions with new component vars.  Reorder if conditions.

gcc/testsuite/ChangeLog:

2020-10-16  Martin Jambor  

PR tree-optimization/97456
* gcc.dg/tree-ssa/pr97456.c: New test.
---
 gcc/testsuite/gcc.dg/tree-ssa/pr97456.c | 40 +
 gcc/tree-complex.c  |  6 ++--
 2 files changed, 44 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr97456.c

diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr97456.c 
b/gcc/testsuite/gcc.dg/tree-ssa/pr97456.c
new file mode 100644
index 000..5171c9b4577
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/pr97456.c
@@ -0,0 +1,40 @@
+/* { dg-do run } */
+/* { dg-options "-O2 -fwhole-program" } */
+
+
+float val2 = 1.710780f;
+float val3;
+volatile float vf;
+
+int __attribute__((noipa))
+get_bool (void)
+{
+  return 1;
+}
+
+int __attribute__((noinline))
+wrong (float *pos)
+{
+  _Complex float a;
+
+  __real__ a = *pos;
+  __imag__ a = *pos;
+
+  _Complex float b = 0 + 0i;
+
+  b = b + a;
+
+  if (b == 0.0f)
+return 1;
+
+  vf = __imag__ b;
+  return 0;
+}
+
+int main(int argc, char **argv) {
+  float val = get_bool () == 1 ? val2 : val3;
+
+  if ((wrong(), wrong()))
+__builtin_abort ();
+  return 0;
+}
diff --git a/gcc/tree-complex.c b/gcc/tree-complex.c
index 2e54bbb917c..71ad7c18523 100644
--- a/gcc/tree-complex.c
+++ b/gcc/tree-complex.c
@@ -570,8 +570,10 @@ set_component_ssa_name (tree ssa_name, bool imag_p, tree 
value)
   /* Replace an anonymous base value with the variable from cvc_lookup.
 This should result in better debug info.  */
   if (SSA_NAME_VAR (ssa_name)
- && (!SSA_NAME_VAR (value) || DECL_IGNORED_P (SSA_NAME_VAR (value)))
- && !DECL_IGNORED_P (SSA_NAME_VAR (ssa_name)))
+ && !DECL_IGNORED_P (SSA_NAME_VAR (ssa_name))
+ && (!SSA_NAME_VAR (value)
+ || (DECL_IGNORED_P (SSA_NAME_VAR (value))
+ && !SSA_NAME_IS_DEFAULT_DEF (value
{
  comp = get_component_var (SSA_NAME_VAR (ssa_name), imag_p);
  replace_ssa_name_symbol (value, comp);
-- 
2.28.0



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

2020-10-16 Thread Ed Smith-Rowland via Gcc-patches

On 10/15/20 7:21 PM, Jonathan Wakely wrote:

Ed,

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

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

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


Jonathan,

Go ahead and remove that header. Sorry for the noise.

Ed




Re: [PATCH] Check for working assembler --gdwarf-[45] options

2020-10-16 Thread H.J. Lu via Gcc-patches
On Fri, Oct 16, 2020 at 11:17 AM Jakub Jelinek  wrote:
>
> On Fri, Oct 16, 2020 at 10:58:34AM -0700, H.J. Lu wrote:
> > Don't set HAVE_AS_GDWARF_5_DEBUG_FLAG nor HAVE_AS_WORKING_DWARF_4_FLAG
> > if there is an extra assembly input file in debug info generated by
> > --gdwarf-5/--gdwarf-4:
> >
> > https://sourceware.org/bugzilla/show_bug.cgi?id=25878
> > https://sourceware.org/bugzilla/show_bug.cgi?id=26740
> >
> > Also replace success with dwarf4_success in the 32-bit --gdwarf-4 check.
> >
> > OK for master?
> >
> >   PR bootstrap/97451
> >   * configure.ac (HAVE_AS_GDWARF_5_DEBUG_FLAG): Don't define if
> >   there is an extra assembly input file in debug info.
> >   (HAVE_AS_WORKING_DWARF_4_FLAG): Likewise.  Replace success with
> >   dwarf4_success in the 32-bit --gdwarf-4 check.
> >   * configure: Regenerated.
>
> The HAVE_AS_GDWARF_5_DEBUG_FLAG macro should be solely about whether
> -gdwarf-5 can be passed to as, nothing else.  That is because it is not only
> used to decide if we can pass -gdwarf-5 to as for assembly of e.g. *.c
> compilation, but also if we can pass it to as when gcc driver is invoked on
> *.s and *.S.  And in that case the problems with -gdwarf-N having unwanted
> effects on assembly with compiler generated .debug_info etc. sections.
> don't really matter.
>
> The HAVE_AS_WORKING_DWARF_4_FLAG perhaps could be renamed to
> ...DWARF_N_FLAG, it is meant to check for whether we can safely pass the
> option also for *.c etc. compilation when we emit debug info sections by the
> compiler.
>
> For that, the question is, are all the issues already fixed on the binutils
> trunk?  As in, do I get identical object files e.g. for -gdwarf-2

Not yet.  This patch:

https://sourceware.org/pipermail/binutils/2020-October/113744.html

is needed for binutils master branch.  BTW, binutils 2.35 and 2.35.1 are
broken.

> compilation no matter whether the compiler passes -gdwarf-2 to gas or not
> (assuming dwarf 2 is the default in gas) when compiling various *.c/*.C
> files?  Ditto for modified gas that would default to other .debug_line
> versions and corresponding gcc -gdwarf-N flag and passing vs. not passing
> that -gdwarf-N to gas?
>
> The hope is that -gdwarf-N to gas would have two functions:
> 1) if the assembly doesn't contain .debug* sections/.file/.loc directives,
>emit debug info (mainly .debug_line) for the assembler file in order to
>be able to debug those
> 2) if the assembly does contain .debug* sections/.file/.loc directives,
>only change the version of the .debug_line generated for the .file/.loc
>directives, but nothing else; keep all .debug* sections but .debug_line
>as is


-- 
H.J.


[r11-3966 Regression] FAIL: gcc.dg/vect/slp-21.c scan-tree-dump-times vect "vectorizing stmts using SLP" 2 on Linux/x86_64

2020-10-16 Thread sunil.k.pandey via Gcc-patches
On Linux/x86_64,

429ad0bb0d3dc77e44f95620341da4938d49168e is the first bad commit
commit 429ad0bb0d3dc77e44f95620341da4938d49168e
Author: Richard Biener 
Date:   Thu Oct 15 11:55:53 2020 +0200

tree-optimization/97428 - split SLP groups for loop vectorization

caused

FAIL: gcc.dg/vect/slp-11b.c -flto -ffat-lto-objects  scan-tree-dump-times vect 
"vectorizing stmts using SLP" 0
FAIL: gcc.dg/vect/slp-11b.c scan-tree-dump-times vect "vectorizing stmts using 
SLP" 0
FAIL: gcc.dg/vect/slp-21.c -flto -ffat-lto-objects  scan-tree-dump-times vect 
"vectorizing stmts using SLP" 2
FAIL: gcc.dg/vect/slp-21.c scan-tree-dump-times vect "vectorizing stmts using 
SLP" 2

with GCC configured with

Configured with: ../../gcc/configure 
--prefix=/local/skpandey/gccwork/toolwork/gcc-bisect-master/master/r11-3966/usr 
--enable-clocale=gnu --with-system-zlib --with-demangler-in-ld 
--with-fpmath=sse --enable-languages=c,c++,fortran --enable-cet --without-isl 
--enable-libmpx x86_64-linux --disable-bootstrap

To reproduce:

$ cd {build_dir}/gcc && make check RUNTESTFLAGS="vect.exp=gcc.dg/vect/slp-11b.c 
--target_board='unix{-m32\ -march=cascadelake}'"
$ cd {build_dir}/gcc && make check RUNTESTFLAGS="vect.exp=gcc.dg/vect/slp-11b.c 
--target_board='unix{-m64\ -march=cascadelake}'"
$ cd {build_dir}/gcc && make check RUNTESTFLAGS="vect.exp=gcc.dg/vect/slp-21.c 
--target_board='unix{-m32\ -march=cascadelake}'"
$ cd {build_dir}/gcc && make check RUNTESTFLAGS="vect.exp=gcc.dg/vect/slp-21.c 
--target_board='unix{-m64\ -march=cascadelake}'"

(Please do not reply to this email, for question about this report, contact me 
at skpgkp2 at gmail dot com)


Re: [PATCH] Check for working assembler --gdwarf-[45] options

2020-10-16 Thread Jakub Jelinek via Gcc-patches
On Fri, Oct 16, 2020 at 10:58:34AM -0700, H.J. Lu wrote:
> Don't set HAVE_AS_GDWARF_5_DEBUG_FLAG nor HAVE_AS_WORKING_DWARF_4_FLAG
> if there is an extra assembly input file in debug info generated by
> --gdwarf-5/--gdwarf-4:
> 
> https://sourceware.org/bugzilla/show_bug.cgi?id=25878
> https://sourceware.org/bugzilla/show_bug.cgi?id=26740
> 
> Also replace success with dwarf4_success in the 32-bit --gdwarf-4 check.
> 
> OK for master?
> 
>   PR bootstrap/97451
>   * configure.ac (HAVE_AS_GDWARF_5_DEBUG_FLAG): Don't define if
>   there is an extra assembly input file in debug info.
>   (HAVE_AS_WORKING_DWARF_4_FLAG): Likewise.  Replace success with
>   dwarf4_success in the 32-bit --gdwarf-4 check.
>   * configure: Regenerated.

The HAVE_AS_GDWARF_5_DEBUG_FLAG macro should be solely about whether
-gdwarf-5 can be passed to as, nothing else.  That is because it is not only
used to decide if we can pass -gdwarf-5 to as for assembly of e.g. *.c
compilation, but also if we can pass it to as when gcc driver is invoked on
*.s and *.S.  And in that case the problems with -gdwarf-N having unwanted
effects on assembly with compiler generated .debug_info etc. sections.
don't really matter.

The HAVE_AS_WORKING_DWARF_4_FLAG perhaps could be renamed to
...DWARF_N_FLAG, it is meant to check for whether we can safely pass the
option also for *.c etc. compilation when we emit debug info sections by the
compiler.

For that, the question is, are all the issues already fixed on the binutils
trunk?  As in, do I get identical object files e.g. for -gdwarf-2
compilation no matter whether the compiler passes -gdwarf-2 to gas or not
(assuming dwarf 2 is the default in gas) when compiling various *.c/*.C
files?  Ditto for modified gas that would default to other .debug_line
versions and corresponding gcc -gdwarf-N flag and passing vs. not passing
that -gdwarf-N to gas?

The hope is that -gdwarf-N to gas would have two functions:
1) if the assembly doesn't contain .debug* sections/.file/.loc directives,
   emit debug info (mainly .debug_line) for the assembler file in order to
   be able to debug those
2) if the assembly does contain .debug* sections/.file/.loc directives,
   only change the version of the .debug_line generated for the .file/.loc
   directives, but nothing else; keep all .debug* sections but .debug_line
   as is

Jakub



[PATCH] Check for working assembler --gdwarf-[45] options

2020-10-16 Thread H.J. Lu via Gcc-patches
Don't set HAVE_AS_GDWARF_5_DEBUG_FLAG nor HAVE_AS_WORKING_DWARF_4_FLAG
if there is an extra assembly input file in debug info generated by
--gdwarf-5/--gdwarf-4:

https://sourceware.org/bugzilla/show_bug.cgi?id=25878
https://sourceware.org/bugzilla/show_bug.cgi?id=26740

Also replace success with dwarf4_success in the 32-bit --gdwarf-4 check.

OK for master?

PR bootstrap/97451
* configure.ac (HAVE_AS_GDWARF_5_DEBUG_FLAG): Don't define if
there is an extra assembly input file in debug info.
(HAVE_AS_WORKING_DWARF_4_FLAG): Likewise.  Replace success with
dwarf4_success in the 32-bit --gdwarf-4 check.
* configure: Regenerated.
---
 gcc/configure| 114 ---
 gcc/configure.ac |  70 ++---
 2 files changed, 172 insertions(+), 12 deletions(-)

diff --git a/gcc/configure b/gcc/configure
index abff47d30eb..d63c2331157 100755
--- a/gcc/configure
+++ b/gcc/configure
@@ -28475,6 +28475,7 @@ $as_echo "#define HAVE_AS_GDWARF2_DEBUG_FLAG 1" 
>>confdefs.h
 fi
 
 
+ dwarf5_success=no
  { $as_echo "$as_me:${as_lineno-$LINENO}: checking assembler for --gdwarf-5 
option" >&5
 $as_echo_n "checking assembler for --gdwarf-5 option... " >&6; }
 if ${gcc_cv_as_gdwarf_5_flag+:} false; then :
@@ -28506,9 +28507,7 @@ fi
 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $gcc_cv_as_gdwarf_5_flag" >&5
 $as_echo "$gcc_cv_as_gdwarf_5_flag" >&6; }
 if test $gcc_cv_as_gdwarf_5_flag = yes; then
-
-$as_echo "#define HAVE_AS_GDWARF_5_DEBUG_FLAG 1" >>confdefs.h
-
+  dwarf5_success=yes
 fi
 
 
@@ -28701,7 +28700,7 @@ fi
 { $as_echo "$as_me:${as_lineno-$LINENO}: result: 
$gcc_cv_as_debug_line_32_flag" >&5
 $as_echo "$gcc_cv_as_debug_line_32_flag" >&6; }
 if test $gcc_cv_as_debug_line_32_flag = yes; then
-  success=yes
+  dwarf4_success=yes
 fi
 
else
@@ -28741,6 +28740,7 @@ fi
 
fi
if test $dwarf4_success = yes; then
+ dwarf4_success=no
  { $as_echo "$as_me:${as_lineno-$LINENO}: checking assembler for 
--gdwarf-4 not refusing compiler generated .debug_line" >&5
 $as_echo_n "checking assembler for --gdwarf-4 not refusing compiler generated 
.debug_line... " >&6; }
 if ${gcc_cv_as_dwarf_4_debug_line_flag+:} false; then :
@@ -28772,9 +28772,7 @@ fi
 { $as_echo "$as_me:${as_lineno-$LINENO}: result: 
$gcc_cv_as_dwarf_4_debug_line_flag" >&5
 $as_echo "$gcc_cv_as_dwarf_4_debug_line_flag" >&6; }
 if test $gcc_cv_as_dwarf_4_debug_line_flag = yes; then
-
-$as_echo "#define HAVE_AS_WORKING_DWARF_4_FLAG 1" >>confdefs.h
-
+  dwarf4_success=yes
 fi
 
  break
@@ -28785,6 +28783,108 @@ fi
dwarf4_line_sz=5
  done
 
+ conftest_s="\
+   .text
+   .globl  foo
+   .type   foo, %function
+foo:
+   $insn
+   .size   foo, .-foo
+   .file   0 \"foo.c\"
+"
+ if test $dwarf5_success = yes; then
+   dwarf5_success=no
+   { $as_echo "$as_me:${as_lineno-$LINENO}: checking assembler for working 
--gdwarf-5 option" >&5
+$as_echo_n "checking assembler for working --gdwarf-5 option... " >&6; }
+if ${gcc_cv_as_working_gdwarf_5_flag+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  gcc_cv_as_working_gdwarf_5_flag=no
+  if test x$gcc_cv_as != x; then
+$as_echo "$conftest_s" > conftest.s
+if { ac_try='$gcc_cv_as $gcc_cv_as_flags --gdwarf-5 -o conftest.o 
conftest.s >&5'
+  { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; }
+then
+ if test x$gcc_cv_readelf != x \
+&& $gcc_cv_readelf -w conftest.o 2>&1 \
+   | grep conftest.s > /dev/null 2>&1; then
+   dwarf5_success=no
+  else
+   dwarf5_success=yes
+  fi
+  else
+  echo "configure: failed program was" >&5
+  cat conftest.s >&5
+fi
+rm -f conftest.o conftest.s
+  fi
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: 
$gcc_cv_as_working_gdwarf_5_flag" >&5
+$as_echo "$gcc_cv_as_working_gdwarf_5_flag" >&6; }
+
+
+   if test $dwarf5_success = yes; then
+
+$as_echo "#define HAVE_AS_GDWARF_5_DEBUG_FLAG 1" >>confdefs.h
+
+   fi
+ fi
+
+ conftest_s="\
+   .text
+   .globl  foo
+   .type   foo, %function
+foo:
+   $insn
+   .size   foo, .-foo
+   .file   1 \"foo.c\"
+"
+ if test $dwarf4_success = yes; then
+   dwarf4_success=no
+   { $as_echo "$as_me:${as_lineno-$LINENO}: checking assembler for working 
--gdwarf-4 option" >&5
+$as_echo_n "checking assembler for working --gdwarf-4 option... " >&6; }
+if ${gcc_cv_as_working_gdwarf_4_flag+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  gcc_cv_as_working_gdwarf_4_flag=no
+  if test x$gcc_cv_as != x; then
+$as_echo "$conftest_s" > conftest.s
+if { ac_try='$gcc_cv_as $gcc_cv_as_flags --gdwarf-4 -o conftest.o 
conftest.s >&5'
+  { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  $as_echo 

c++: Fix nullptr deref [pr97460[

2020-10-16 Thread Nathan Sidwell

My changes to friend handling meant that there are now cases where a
friend doesn't get a lang-specific object.  So we need to check there
is one before looking inside it.

PR c++/97460
gcc/cp/
* pt.c (push_template_decl): Check DECL_LANG_SPECIFIC in friend
case.
gcc/testsuite/
* g++.dg/template/pr97460.C: New.

pushing to trunk

nathan
--
Nathan Sidwell
diff --git c/gcc/cp/pt.c w/gcc/cp/pt.c
index 2a9a8fafaca..dc664ec3798 100644
--- c/gcc/cp/pt.c
+++ w/gcc/cp/pt.c
@@ -5877,7 +5877,8 @@ push_template_decl (tree decl, bool is_friend)
   || TREE_CODE (ctx) == FUNCTION_DECL
   || (CLASS_TYPE_P (ctx) && TYPE_BEING_DEFINED (ctx))
   || (TREE_CODE (decl) == TYPE_DECL && LAMBDA_TYPE_P (TREE_TYPE (decl)))
-  || (is_friend && !DECL_TEMPLATE_INFO (decl)))
+  || (is_friend && !(DECL_LANG_SPECIFIC (decl)
+			 && DECL_TEMPLATE_INFO (decl
 {
   if (DECL_LANG_SPECIFIC (decl)
 	  && DECL_TEMPLATE_INFO (decl)
diff --git c/gcc/testsuite/g++.dg/template/pr97460.C w/gcc/testsuite/g++.dg/template/pr97460.C
new file mode 100644
index 000..6dea4898997
--- /dev/null
+++ w/gcc/testsuite/g++.dg/template/pr97460.C
@@ -0,0 +1,9 @@
+// PR 97460
+// ICE, null dereference
+
+class io_context {
+  template  class basic_executor_type;
+};
+template  class io_context::basic_executor_type {
+  template  friend class basic_executor_type;
+};


c++: Fix null deref at EOF [PR96258]

2020-10-16 Thread Nathan Sidwell

cp_parser_declaration peeks at 1 or 2 tokens, when I changed it not to
peek past EOF, I set the second token to NULL.  But there are paths
through the function that just look at the second token.  Fixed by
setting that token to EOF rather than NULL in this case.

PR c++/96258
gcc/cp/
* parser.c (cp_parser_declaration): Make token2 point to EOF if
token1 was EOF.
gcc/testsuite/
* g++.dg/parse/pr96258.C: New.

pushing to trunk

nathan
--
Nathan Sidwell
diff --git c/gcc/cp/parser.c w/gcc/cp/parser.c
index 592ce95b571..7ec7d42773c 100644
--- c/gcc/cp/parser.c
+++ w/gcc/cp/parser.c
@@ -13497,10 +13497,8 @@ cp_parser_declaration (cp_parser* parser)
 
   /* Try to figure out what kind of declaration is present.  */
   cp_token *token1 = cp_lexer_peek_token (parser->lexer);
-  cp_token *token2 = NULL;
-
-  if (token1->type != CPP_EOF)
-token2 = cp_lexer_peek_nth_token (parser->lexer, 2);
+  cp_token *token2 = (token1->type == CPP_EOF
+		  ? token1 : cp_lexer_peek_nth_token (parser->lexer, 2));
 
   /* Get the high-water mark for the DECLARATOR_OBSTACK.  */
   void *p = obstack_alloc (_obstack, 0);
diff --git c/gcc/testsuite/g++.dg/parse/pr96258.C w/gcc/testsuite/g++.dg/parse/pr96258.C
new file mode 100644
index 000..1b642e1fc38
--- /dev/null
+++ w/gcc/testsuite/g++.dg/parse/pr96258.C
@@ -0,0 +1,5 @@
+// { dg-additional-options -fopenmp }
+// { dg-require-effective-target fopenmp } 
+#pragma omp declare simd // { dg-error "not immediately followed by" }
+
+// { dg-error "-:expected unqualified-id" "" { target *-*-* } .+1 }


[patch] vxworks; Fix the vx_crtstuff handling of kernel/rtp variations

2020-10-16 Thread Olivier Hainque
Hello,

The VxWorks ports come with specific crtstuff objects to cope
with the variety of possible means to load code on a target, as
kernel modules or RTPS (Real Time Processes).

Compilation of those objects is currently explicitly replicated
for the two modes, through t-vxcrtstuff:

  EXTRA_PARTS += vx_crtbegin-kernel.o vx_crtbegin-rtp.o vx_crtend.o

... where the difference between "-kernel" and "-rtp" is to pass -mrtp
in the compilation options.

But the ports that support RTPs already achieve that distinction
through the multilib mechanism, so we end up with nonsensical 
object sets like:

 ./lib/gcc/powerpc-wrs-vxworks7r2/10.2.1/mrtp/vx_crtbegin-rtp.o
 ./lib/gcc/powerpc-wrs-vxworks7r2/10.2.1/mrtp/vx_crtend.o
 ./lib/gcc/powerpc-wrs-vxworks7r2/10.2.1/mrtp/vx_crtbegin-kernel.o
 ./lib/gcc/powerpc-wrs-vxworks7r2/10.2.1/vx_crtbegin-rtp.o
 ./lib/gcc/powerpc-wrs-vxworks7r2/10.2.1/vx_crtend.o
 ./lib/gcc/powerpc-wrs-vxworks7r2/10.2.1/vx_crtbegin-kernel.o

This patch just removes the bogus explicit distinction and
leaves it all to the multilib circuitry.

Tested by verifying that our gcc-10 based toolchain behave as
intended after the change, both for VxWorks 6.9 and 7.2, and by
a sanity check build of mainline for VxWorks 6.9.

Olivier

2020-10-15  Olivier Hainque  

libgcc/
* config/t-vxcrtstuff: Remove the -kernel/-rtp specialization.

gcc/
* config/vxworks.h (VX_CRTBEGIN_SPEC): Likewise.

diff --git a/gcc/config/vxworks.h b/gcc/config/vxworks.h
index d3c417e7f5ae..5b1538085e9e 100644
--- a/gcc/config/vxworks.h
+++ b/gcc/config/vxworks.h
@@ -158,8 +158,7 @@ along with GCC; see the file COPYING3.  If not see
 /* Setup the crtstuff begin/end we might need for dwarf EH registration.  */
 
 #if !defined(CONFIG_SJLJ_EXCEPTIONS) && DWARF2_UNWIND_INFO
-#define VX_CRTBEGIN_SPEC \
- "%{!mrtp:vx_crtbegin-kernel.o%s} %{mrtp:vx_crtbegin-rtp.o%s}"
+#define VX_CRTBEGIN_SPEC "vx_crtbegin.o%s"
 #define VX_CRTEND_SPEC "-l:vx_crtend.o"
 #else
 #define VX_CRTBEGIN_SPEC ""
diff --git a/libgcc/config/t-vxcrtstuff b/libgcc/config/t-vxcrtstuff
index 96b728525e04..ef64951c9038 100644
--- a/libgcc/config/t-vxcrtstuff
+++ b/libgcc/config/t-vxcrtstuff
@@ -1,12 +1,12 @@
-# crtbegin/crtend for VxWorks (DKM or RTP)
+# crtbegin/crtend for VxWorks
 
-vx_crtbegin-kernel.o: $(srcdir)/config/vxcrtstuff.c
+vx_crtbegin.o: $(srcdir)/config/vxcrtstuff.c
$(crt_compile) $(CRTSTUFF_T_CFLAGS) -DCRT_BEGIN -c $<
 
-vx_crtbegin-rtp.o: $(srcdir)/config/vxcrtstuff.c
-   $(crt_compile) $(CRTSTUFF_T_CFLAGS) -DCRT_BEGIN -c $< -mrtp
-
 vx_crtend.o: $(srcdir)/config/vxcrtstuff.c
$(crt_compile) $(CRTSTUFF_T_CFLAGS) -DCRT_END -c $<
 
-EXTRA_PARTS += vx_crtbegin-kernel.o vx_crtbegin-rtp.o vx_crtend.o
+# We do pretty different things for kernel vs rtp modes, all
+# controlled thanks to __RTP__ and (optional) multilibs.
+
+EXTRA_PARTS += vx_crtbegin.o vx_crtend.o


[PATCH] c++: Deducing type from initializer_list [PR93107]

2020-10-16 Thread Marek Polacek via Gcc-patches
In this testcase we weren't able to deduce b's type:

  template void Task() { }
  auto b = {  };

because resolve_nondeduced_context doesn't iterate on the {}'s elements.
So make sure to look into {} too.  We don't need to handle nested {}
here.

We could either tweak resolve_nondeduced_context to handle CONSTRUCTORs
or add a _ctor version, but then resolve_nondeduced_context_or_error
would need some changes too -- it'd have to check the result of a call
to r_n_c for each element.

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

gcc/cp/ChangeLog:

PR c++/93107
* pt.c (do_auto_deduction): Call resolve_nondeduced_context for
the elements of a { } list.

gcc/testsuite/ChangeLog:

PR c++/93107
* g++.dg/cpp0x/initlist-deduce3.C: New test.
---
 gcc/cp/pt.c   |  6 -
 gcc/testsuite/g++.dg/cpp0x/initlist-deduce3.C | 22 +++
 2 files changed, 27 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/g++.dg/cpp0x/initlist-deduce3.C

diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 2a9a8fafaca..b7e8a47bde8 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -29240,7 +29240,11 @@ do_auto_deduction (tree type, tree init, tree 
auto_node,
   if (type == error_mark_node)
 return error_mark_node;
 
-  init = resolve_nondeduced_context (init, complain);
+  if (BRACE_ENCLOSED_INITIALIZER_P (init))
+for (constructor_elt  : *CONSTRUCTOR_ELTS (init))
+  elt.value = resolve_nondeduced_context (elt.value, complain);
+  else
+init = resolve_nondeduced_context (init, complain);
 
   if (context == adc_decomp_type
   && auto_node == type
diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist-deduce3.C 
b/gcc/testsuite/g++.dg/cpp0x/initlist-deduce3.C
new file mode 100644
index 000..b8417d7bf0c
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/initlist-deduce3.C
@@ -0,0 +1,22 @@
+// PR c++/93107
+// { dg-do compile { target c++11 } }
+
+using size_t = decltype(sizeof 0);
+
+namespace std {
+  template struct initializer_list {
+const T *ptr;
+size_t n;
+initializer_list(const T*, size_t);
+  };
+}
+
+template
+void Task() {}
+
+auto a = ;
+auto b = {  };
+auto e{  };
+auto f = { ,  };
+std::initializer_list c = {  };
+auto d = { static_cast() };

base-commit: 1e8e49f135c814bd268289609dd0aea305ed546e
-- 
2.26.2



Ping #2: [PATCH 0/9] PowerPC: Patches to enable changing the long double default to IEEE 128-bit on little endian PowerPC 64-bit Linux systems

2020-10-16 Thread Michael Meissner via Gcc-patches
Ping (#2) the following 9 patches to add support for building a GCC toolchain
where the default long double is IEEE 128-bit floating point instead of the IBM
extended double floating point.

The first patch was revised with input from Joesph Myers.  I will list that
patch in this list.  Most of these patches are independent of each other, so if
there are problems with some of the patches, please look at the other patches
after that patch:

Patch #1: Map built-in long double functions to an alternate name if long
double is IEEE 128-bit.
https://gcc.gnu.org/pipermail/gcc-patches/2020-October/555855.html

Patch #2: Update error messages about mixing __float128 and __ibm128 to deal
with long double being IEEE 128-bit:
https://gcc.gnu.org/pipermail/gcc-patches/2020-September/554767.html

Patch #3: Rework libgcc 128-bit floating point conversion support:
https://gcc.gnu.org/pipermail/gcc-patches/2020-September/554768.html

Patch #4: Add support in libgcc to convert between IEEE 128-bit and the three
Decimal types:
https://gcc.gnu.org/pipermail/gcc-patches/2020-September/554770.html

Patch #5: Fix some tests that break if long double is IEEE 128-bit:
https://gcc.gnu.org/pipermail/gcc-patches/2020-September/554772.html

Patch #6: Map the 'q' built-ins to 'l' built-ins if long double is IEEE
128-bit:
https://gcc.gnu.org/pipermail/gcc-patches/2020-September/554773.html

Patch #7: Update the power10 built-in functions for IEEE 128-bit support to
support long double if long double is IEEE 128-bit:
https://gcc.gnu.org/pipermail/gcc-patches/2020-September/554774.html

Patch #8: Change tests that use an explicit '__ieee128' keywork to use the
keyword we document ('__float128'):
https://gcc.gnu.org/pipermail/gcc-patches/2020-September/554775.html

Patch #9: If long double is IEEE 128-bit, use the pack_ibm128 built-in instead
of the pack_longdouble built-in in libgcc:
https://gcc.gnu.org/pipermail/gcc-patches/2020-September/554776.html

-- 
Michael Meissner, IBM
IBM, M/S 2506R, 550 King Street, Littleton, MA 01460-6245, USA
email: meiss...@linux.ibm.com, phone: +1 (978) 899-4797


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

2020-10-16 Thread Martin Liška

Hello.

There's another version of the patch that should be based on what
I discussed with Richi and Jakub:

- the first patch introduces a new option -fbit-tests that analogue to 
-fjump-tables
  and will control the new if-to-switch conversion pass

- the second patch adds the pass
- I share code with tree-ssa-reassoc.c (range_entry and init_range_entry)
- a local discovery phase is run first
- later than these local BBs are chained into a candidate list for the 
conversion

I'm also sending transformed chains for 'make all-host' (620 transformations).
Patch can bootstrap on x86_64-linux-gnu and survives regression tests.

Thoughts?
Thanks,
Martin
>From 69b043dfe5a741ca5b0d9536a0b59b1d5066d47f Mon Sep 17 00:00:00 2001
From: Martin Liska 
Date: Fri, 28 Aug 2020 10:26:13 +0200
Subject: [PATCH 2/2] Add if-chain to switch conversion pass.

gcc/ChangeLog:

	PR tree-optimization/14799
	PR ipa/88702
	* Makefile.in: Add gimple-if-to-switch.o.
	* dbgcnt.def (DEBUG_COUNTER): Add new debug counter.
	* passes.def: Include new pass_if_to_switch pass.
	* timevar.def (TV_TREE_IF_TO_SWITCH): New timevar.
	* tree-pass.h (make_pass_if_to_switch): New.
	* tree-ssa-reassoc.c (struct operand_entry): Move to the header.
	(dump_range_entry): Move to header file.
	(debug_range_entry): Likewise.
	(no_side_effect_bb): Make it global.
	* tree-switch-conversion.h (simple_cluster::simple_cluster):
	Add inline for couple of functions in order to prevent error
	about multiple defined symbols.
	* gimple-if-to-switch.cc: New file.
	* tree-ssa-reassoc.h: New file.

gcc/testsuite/ChangeLog:

	PR tree-optimization/14799
	PR ipa/88702
	* gcc.dg/tree-ssa/pr96480.c: Disable if-to-switch conversion.
	* gcc.dg/tree-ssa/reassoc-32.c: Likewise.
	* g++.dg/tree-ssa/if-to-switch-1.C: New test.
	* gcc.dg/tree-ssa/if-to-switch-1.c: New test.
	* gcc.dg/tree-ssa/if-to-switch-2.c: New test.
	* gcc.dg/tree-ssa/if-to-switch-3.c: New test.
	* gcc.dg/tree-ssa/if-to-switch-4.c: New test.
	* gcc.dg/tree-ssa/if-to-switch-5.c: New test.
	* gcc.dg/tree-ssa/if-to-switch-6.c: New test.
	* gcc.dg/tree-ssa/if-to-switch-7.c: New test.
	* gcc.dg/tree-ssa/if-to-switch-8.c: New test.
---
 gcc/Makefile.in   |   1 +
 gcc/dbgcnt.def|   1 +
 gcc/gimple-if-to-switch.cc| 565 ++
 gcc/passes.def|   1 +
 .../g++.dg/tree-ssa/if-to-switch-1.C  |  25 +
 .../gcc.dg/tree-ssa/if-to-switch-1.c  |  35 ++
 .../gcc.dg/tree-ssa/if-to-switch-2.c  |  11 +
 .../gcc.dg/tree-ssa/if-to-switch-3.c  |  11 +
 .../gcc.dg/tree-ssa/if-to-switch-4.c  |  36 ++
 .../gcc.dg/tree-ssa/if-to-switch-5.c  |  12 +
 .../gcc.dg/tree-ssa/if-to-switch-6.c  |  42 ++
 .../gcc.dg/tree-ssa/if-to-switch-7.c  |  25 +
 .../gcc.dg/tree-ssa/if-to-switch-8.c  |  27 +
 gcc/testsuite/gcc.dg/tree-ssa/pr96480.c   |   2 +-
 gcc/testsuite/gcc.dg/tree-ssa/reassoc-32.c|   2 +-
 gcc/timevar.def   |   1 +
 gcc/tree-pass.h   |   1 +
 gcc/tree-ssa-reassoc.c|  27 +-
 gcc/tree-ssa-reassoc.h|  48 ++
 gcc/tree-switch-conversion.h  |  24 +-
 20 files changed, 865 insertions(+), 32 deletions(-)
 create mode 100644 gcc/gimple-if-to-switch.cc
 create mode 100644 gcc/testsuite/g++.dg/tree-ssa/if-to-switch-1.C
 create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/if-to-switch-1.c
 create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/if-to-switch-2.c
 create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/if-to-switch-3.c
 create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/if-to-switch-4.c
 create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/if-to-switch-5.c
 create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/if-to-switch-6.c
 create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/if-to-switch-7.c
 create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/if-to-switch-8.c
 create mode 100644 gcc/tree-ssa-reassoc.h

diff --git a/gcc/Makefile.in b/gcc/Makefile.in
index 5a8fb0d7612..c7ecda54df2 100644
--- a/gcc/Makefile.in
+++ b/gcc/Makefile.in
@@ -1361,6 +1361,7 @@ OBJS = \
 	gimple-array-bounds.o \
 	gimple-builder.o \
 	gimple-expr.o \
+	gimple-if-to-switch.o \
 	gimple-iterator.o \
 	gimple-fold.o \
 	gimple-laddress.o \
diff --git a/gcc/dbgcnt.def b/gcc/dbgcnt.def
index 07946a85ecc..c8d41065a94 100644
--- a/gcc/dbgcnt.def
+++ b/gcc/dbgcnt.def
@@ -170,6 +170,7 @@ DEBUG_COUNTER (if_after_combine)
 DEBUG_COUNTER (if_after_reload)
 DEBUG_COUNTER (if_conversion)
 DEBUG_COUNTER (if_conversion_tree)
+DEBUG_COUNTER (if_to_switch)
 DEBUG_COUNTER (ipa_cp_bits)
 DEBUG_COUNTER (ipa_mod_ref)
 DEBUG_COUNTER (ipa_sra_params)
diff --git a/gcc/gimple-if-to-switch.cc b/gcc/gimple-if-to-switch.cc
new file mode 100644
index 000..25ef45175a7
--- /dev/null
+++ b/gcc/gimple-if-to-switch.cc
@@ -0,0 +1,565 @@
+/* If-elseif-else to switch conversion pass
+   Copyright (C) 

RE: [PATCH][GCC] arm: Fix the warning -mcpu=cortex-m55 conflicting with -march=armv8.1-m.main (pr97327).

2020-10-16 Thread Kyrylo Tkachov via Gcc-patches



> -Original Message-
> From: Srinath Parvathaneni 
> Sent: 16 October 2020 14:21
> To: gcc-patches@gcc.gnu.org
> Cc: Kyrylo Tkachov 
> Subject: [PATCH][GCC] arm: Fix the warning -mcpu=cortex-m55 conflicting
> with -march=armv8.1-m.main (pr97327).
> 
> Hello,
> 
> This patch fixes (PR97327) the warning -mcpu=cortex-m55 conflicts with -
> march=armv8.1-m.main
> for -mfloat-abi=soft by adding the isa_bit_mve_float to clearing FP bit list.
> 
> The following combination are fixed with this patch:
> $ cat bug.c
> int main(){
> return 0;
> }
> 
> $ arm-none-eabi-gcc -mcpu=cortex-m55 -mfloat-abi=soft bug.c -c
> $ arm-none-eabi-gcc -mcpu=cortex-m55 -mfloat-abi=soft -march=armv8.1-
> m.main+mve bug.c -c
> 
> Before this patch for above combinations:
> cc1: warning: switch '-mcpu=cortex-m55' conflicts with '-march=armv8.1-
> m.main' switch
> 
> After this patch for above combinations no warning/errors.
> 
> Regression tested on arm-none-eabi and found no regressions.
> 
> Ok for master? Ok for GCC-10 branch?

Ok for master and for the branch next week if testing shows no problem.
Thanks,
Kyrill

> 
> Regards,
> Srinath.
> 
> gcc/ChangeLog:
> 
> 2020-10-16  Srinath Parvathaneni  
> 
>   PR target/97327
>   * config/arm/arm.c (fp_bitlist): Add isa_bit_mve_float to FP bits
> array.
> 
> gcc/testsuite/ChangeLog:
> 
>   PR target/97327
>   * gcc.target/arm/mve/intrinsics/pr97327.c: New test.
> 
> 
> ### Attachment also inlined for ease of reply
> ###
> 
> 
> diff --git a/gcc/config/arm/arm.c b/gcc/config/arm/arm.c
> index
> 0b8c5fa074d32e9ced107d1917323479c19d4c4e..dfadaca6fdfe16cfd5b6531
> ae8564d01063bbe77 100644
> --- a/gcc/config/arm/arm.c
> +++ b/gcc/config/arm/arm.c
> @@ -3429,8 +3429,9 @@ arm_option_override (void)
>  {
>static const enum isa_feature fpu_bitlist_internal[]
>  = { ISA_ALL_FPU_INTERNAL, isa_nobit };
> +  /* isa_bit_mve_float is also part of FP bit list for arch v8.1-m.main.  */
>static const enum isa_feature fp_bitlist[]
> -= { ISA_ALL_FP, isa_nobit };
> += { ISA_ALL_FP, isa_bit_mve_float, isa_nobit };
>static const enum isa_feature quirk_bitlist[] = { ISA_ALL_QUIRKS, 
> isa_nobit};
>cl_target_option opts;
> 
> diff --git a/gcc/testsuite/gcc.target/arm/mve/intrinsics/pr97327.c
> b/gcc/testsuite/gcc.target/arm/mve/intrinsics/pr97327.c
> new file mode 100644
> index
> ..8f6d36063811607623048
> c0a95920b29e43f4c39
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/arm/mve/intrinsics/pr97327.c
> @@ -0,0 +1,8 @@
> +/* { dg-require-effective-target arm_v8_1m_mve_fp_ok } */
> +/* { dg-skip-if "Incompatible float ABI" { *-*-* } { "-mfloat-abi=hard" } { 
> "" } }
> */
> +/* { dg-additional-options "-mcpu=cortex-m55 -mfloat-abi=soft -
> mfpu=auto -Werror" } */
> +
> +int main ()
> +{
> +  return 0;
> +}



[PATCH][GCC] arm: Fix the warning -mcpu=cortex-m55 conflicting with -march=armv8.1-m.main (pr97327).

2020-10-16 Thread Srinath Parvathaneni via Gcc-patches
Hello,

This patch fixes (PR97327) the warning -mcpu=cortex-m55 conflicts with 
-march=armv8.1-m.main
for -mfloat-abi=soft by adding the isa_bit_mve_float to clearing FP bit list.

The following combination are fixed with this patch:
$ cat bug.c
int main(){
return 0;
}

$ arm-none-eabi-gcc -mcpu=cortex-m55 -mfloat-abi=soft bug.c -c
$ arm-none-eabi-gcc -mcpu=cortex-m55 -mfloat-abi=soft -march=armv8.1-m.main+mve 
bug.c -c

Before this patch for above combinations:
cc1: warning: switch '-mcpu=cortex-m55' conflicts with '-march=armv8.1-m.main' 
switch

After this patch for above combinations no warning/errors.

Regression tested on arm-none-eabi and found no regressions.

Ok for master? Ok for GCC-10 branch?

Regards,
Srinath.

gcc/ChangeLog:

2020-10-16  Srinath Parvathaneni  

PR target/97327
* config/arm/arm.c (fp_bitlist): Add isa_bit_mve_float to FP bits array.

gcc/testsuite/ChangeLog:

PR target/97327
* gcc.target/arm/mve/intrinsics/pr97327.c: New test.


### Attachment also inlined for ease of reply###


diff --git a/gcc/config/arm/arm.c b/gcc/config/arm/arm.c
index 
0b8c5fa074d32e9ced107d1917323479c19d4c4e..dfadaca6fdfe16cfd5b6531ae8564d01063bbe77
 100644
--- a/gcc/config/arm/arm.c
+++ b/gcc/config/arm/arm.c
@@ -3429,8 +3429,9 @@ arm_option_override (void)
 {
   static const enum isa_feature fpu_bitlist_internal[]
 = { ISA_ALL_FPU_INTERNAL, isa_nobit };
+  /* isa_bit_mve_float is also part of FP bit list for arch v8.1-m.main.  */
   static const enum isa_feature fp_bitlist[]
-= { ISA_ALL_FP, isa_nobit };
+= { ISA_ALL_FP, isa_bit_mve_float, isa_nobit };
   static const enum isa_feature quirk_bitlist[] = { ISA_ALL_QUIRKS, isa_nobit};
   cl_target_option opts;
 
diff --git a/gcc/testsuite/gcc.target/arm/mve/intrinsics/pr97327.c 
b/gcc/testsuite/gcc.target/arm/mve/intrinsics/pr97327.c
new file mode 100644
index 
..8f6d36063811607623048c0a95920b29e43f4c39
--- /dev/null
+++ b/gcc/testsuite/gcc.target/arm/mve/intrinsics/pr97327.c
@@ -0,0 +1,8 @@
+/* { dg-require-effective-target arm_v8_1m_mve_fp_ok } */
+/* { dg-skip-if "Incompatible float ABI" { *-*-* } { "-mfloat-abi=hard" } { "" 
} } */
+/* { dg-additional-options "-mcpu=cortex-m55 -mfloat-abi=soft -mfpu=auto 
-Werror" } */
+
+int main ()
+{
+  return 0;
+}

diff --git a/gcc/config/arm/arm.c b/gcc/config/arm/arm.c
index 
0b8c5fa074d32e9ced107d1917323479c19d4c4e..dfadaca6fdfe16cfd5b6531ae8564d01063bbe77
 100644
--- a/gcc/config/arm/arm.c
+++ b/gcc/config/arm/arm.c
@@ -3429,8 +3429,9 @@ arm_option_override (void)
 {
   static const enum isa_feature fpu_bitlist_internal[]
 = { ISA_ALL_FPU_INTERNAL, isa_nobit };
+  /* isa_bit_mve_float is also part of FP bit list for arch v8.1-m.main.  */
   static const enum isa_feature fp_bitlist[]
-= { ISA_ALL_FP, isa_nobit };
+= { ISA_ALL_FP, isa_bit_mve_float, isa_nobit };
   static const enum isa_feature quirk_bitlist[] = { ISA_ALL_QUIRKS, isa_nobit};
   cl_target_option opts;
 
diff --git a/gcc/testsuite/gcc.target/arm/mve/intrinsics/pr97327.c 
b/gcc/testsuite/gcc.target/arm/mve/intrinsics/pr97327.c
new file mode 100644
index 
..8f6d36063811607623048c0a95920b29e43f4c39
--- /dev/null
+++ b/gcc/testsuite/gcc.target/arm/mve/intrinsics/pr97327.c
@@ -0,0 +1,8 @@
+/* { dg-require-effective-target arm_v8_1m_mve_fp_ok } */
+/* { dg-skip-if "Incompatible float ABI" { *-*-* } { "-mfloat-abi=hard" } { "" 
} } */
+/* { dg-additional-options "-mcpu=cortex-m55 -mfloat-abi=soft -mfpu=auto 
-Werror" } */
+
+int main ()
+{
+  return 0;
+}



[PATCH] Adjust BB vectorization SLP build heuristics

2020-10-16 Thread Richard Biener
This changes SLP def gathering to not fail due to mismatched
def type but instead demote the def to external.  This allows the
new testcase to be vectorized in full (with GCC 10 it is not
vectorized at all and with current trunk we vectorize only the
store).  This is important since with BB vectorization being
applied to bigger pieces of code the chance that we mix
internal and external defs for an operand that should end up
treated as external (built from scalars) increases.

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

2020-10-16  Richard Biener  

* tree-vect-slp.c (vect_get_and_check_slp_defs): For BB
vectorization swap operands only if it helps, demote mismatches to
external.

* gcc.dg/vect/bb-slp-53.c: New testcase.
---
 gcc/testsuite/gcc.dg/vect/bb-slp-53.c | 20 +
 gcc/tree-vect-slp.c   | 31 +--
 2 files changed, 45 insertions(+), 6 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/vect/bb-slp-53.c

diff --git a/gcc/testsuite/gcc.dg/vect/bb-slp-53.c 
b/gcc/testsuite/gcc.dg/vect/bb-slp-53.c
new file mode 100644
index 000..f3b5f317444
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/vect/bb-slp-53.c
@@ -0,0 +1,20 @@
+/* { dg-do compile } */
+/* { dg-require-effective-target vect_double } */
+
+double a[2], b[2];
+
+void foo(double x, double y)
+{
+  double breakme1 = y + 3.;
+  double a1 = b[1] + 2.;
+  double breakme0 = x;
+  double a0 = b[0] + 1.;
+  a[0] = a0 * breakme0;
+  a[1] = a1 * breakme1;
+}
+
+/* We should vectorize the SLP opportunity starting from the
+   grouped store to a[] including the load from b[] at the
+   leaf even though the multiplication requires another
+   vector invariant to be built.  */
+/* { dg-final { scan-tree-dump "transform load" "slp2" } } */
diff --git a/gcc/tree-vect-slp.c b/gcc/tree-vect-slp.c
index cfb79e2651f..c3e6d67067c 100644
--- a/gcc/tree-vect-slp.c
+++ b/gcc/tree-vect-slp.c
@@ -564,8 +564,15 @@ vect_get_and_check_slp_defs (vec_info *vinfo, unsigned 
char swap,
  != (oprnd_info->first_dt != vect_reduction_def
{
  /* Try swapping operands if we got a mismatch.  For BB
-vectorization only in case that will improve things.  */
- if (i == commutative_op && !swapped)
+vectorization only in case it will clearly improve things.  */
+ if (i == commutative_op && !swapped
+ && (!is_a  (vinfo)
+ || (!vect_def_types_match ((*oprnds_info)[i+1]->first_dt,
+dts[i+1])
+ && (vect_def_types_match (oprnd_info->first_dt,
+   dts[i+1])
+ || vect_def_types_match
+  ((*oprnds_info)[i+1]->first_dt, dts[i])
{
  if (dump_enabled_p ())
dump_printf_loc (MSG_NOTE, vect_location,
@@ -579,10 +586,22 @@ vect_get_and_check_slp_defs (vec_info *vinfo, unsigned 
char swap,
  continue;
}
 
- if (dump_enabled_p ())
-   dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
-"Build SLP failed: different types\n");
- return 1;
+ if (is_a  (vinfo))
+   {
+ /* Now for commutative ops we should see whether we can
+make the other operand matching.  */
+ if (dump_enabled_p ())
+   dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
+"treating operand as external\n");
+ oprnd_info->first_dt = dt = vect_external_def;
+   }
+ else
+   {
+ if (dump_enabled_p ())
+   dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
+"Build SLP failed: different types\n");
+ return 1;
+   }
}
 
   /* Make sure to demote the overall operand to external.  */
-- 
2.26.2


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

2020-10-16 Thread Richard Biener
On Thu, 15 Oct 2020, guojiufu wrote:

> Hi,
> 
> I just had a check on below patch for PR66552.
> https://gcc.gnu.org/pipermail/gcc-patches/2020-February/540930.html
> It seems this patch works fine now. This patch fixes PR66552 which
> request to optimizes (x shift (n mod C)) to
> (x shift (n bit_and (C - 1))) when C is a constant and power of two.
> 
> As tests, bootstrap and regtests pass on ppc64le. Is it ok for trunk?

OK.

Thanks,
Richard.

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

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


GCC 11.0.0 Status Report (2020-10-16), Stage 1 ends Nov 15th

2020-10-16 Thread Richard Biener


Status
==

GCC trunk which eventually will become GCC 11 is still open for general
development.  Stage 1 will end on the end of Sunday, Nov 15th 2020
at which point we will transition into Stage 3 which allows for general
bugfixing.

We have accumulated quite a number of regressions, a lot of the
untriaged and eventually stale.  Please help in cleaning up.


Quality Data


Priority  #   Change from last report
---   ---
P1   33   +  33
P2  256   +  35
P3   74   +  47
P4  185   +  12
P5   24   +   2
---   ---
Total P1-P3 363   + 121
Total   572   + 135


Previous Report
===

https://gcc.gnu.org/pipermail/gcc/2020-April/000505.html


RE: [PATCH][GCC-10 backport] arm: [MVE] Remove illegal intrinsics (PR target/96914)

2020-10-16 Thread Kyrylo Tkachov via Gcc-patches



> -Original Message-
> From: Srinath Parvathaneni 
> Sent: 16 October 2020 12:45
> To: gcc-patches@gcc.gnu.org
> Cc: Kyrylo Tkachov 
> Subject: [PATCH][GCC-10 backport] arm: [MVE] Remove illegal intrinsics (PR
> target/96914)
> 
> Hello,
> 
> Applied cleanly, Ok for backporting this patch to GCC-10?

Ok.
Thanks,
Kyrill

> 
> A few MVE intrinsics had an unsigned variant implement while they are
> supported by the hardware.  This patch removes them:
> __arm_vqrdmlashq_n_u8
> __arm_vqrdmlahq_n_u8
> __arm_vqdmlahq_n_u8
> __arm_vqrdmlashq_n_u16
> __arm_vqrdmlahq_n_u16
> __arm_vqdmlahq_n_u16
> __arm_vqrdmlashq_n_u32
> __arm_vqrdmlahq_n_u32
> __arm_vqdmlahq_n_u32
> __arm_vmlaldavaxq_p_u32
> __arm_vmlaldavaxq_p_u16
> 
> 2020-10-08  Christophe Lyon  
> 
>   gcc/
>   PR target/96914
>   * config/arm/arm_mve.h (vqrdmlashq_n_u8, vqrdmlashq_n_u16)
>   (vqrdmlashq_n_u32, vqrdmlahq_n_u8, vqrdmlahq_n_u16)
>   (vqrdmlahq_n_u32, vqdmlahq_n_u8, vqdmlahq_n_u16,
> vqdmlahq_n_u32)
>   (vmlaldavaxq_p_u16, vmlaldavaxq_p_u32): Remove.
>   * config/arm/arm_mve_builtins.def (vqrdmlashq_n_u,
> vqrdmlahq_n_u)
>   (vqdmlahq_n_u, vmlaldavaxq_p_u): Remove.
>   * config/arm/unspecs.md (VQDMLAHQ_N_U, VQRDMLAHQ_N_U)
>   (VQRDMLASHQ_N_U)
>   (VMLALDAVAXQ_P_U): Remove unspecs.
>   * config/arm/iterators.md (VQDMLAHQ_N_U, VQRDMLAHQ_N_U)
>   (VQRDMLASHQ_N_U, VMLALDAVAXQ_P_U): Remove attributes.
>   (VQDMLAHQ_N, VQRDMLAHQ_N, VQRDMLASHQ_N,
> VMLALDAVAXQ_P): Remove
>   unsigned variants from iterators.
>   * config/arm/mve.md (mve_vqdmlahq_n_)
>   (mve_vqrdmlahq_n_)
>   (mve_vqrdmlashq_n_,
> mve_vmlaldavaxq_p_):
>   Update comment.
> 
>   gcc/testsuite/
>   PR target/96914
>   * gcc.target/arm/mve/intrinsics/vmlaldavaxq_p_u16.c: Remove.
>   * gcc.target/arm/mve/intrinsics/vmlaldavaxq_p_u32.c: Remove.
>   * gcc.target/arm/mve/intrinsics/vqdmlahq_n_u16.c: Remove.
>   * gcc.target/arm/mve/intrinsics/vqdmlahq_n_u32.c: Remove.
>   * gcc.target/arm/mve/intrinsics/vqdmlahq_n_u8.c: Remove.
>   * gcc.target/arm/mve/intrinsics/vqrdmlahq_n_u16.c: Remove.
>   * gcc.target/arm/mve/intrinsics/vqrdmlahq_n_u32.c: Remove.
>   * gcc.target/arm/mve/intrinsics/vqrdmlahq_n_u8.c: Remove.
>   * gcc.target/arm/mve/intrinsics/vqrdmlashq_n_u16.c: Remove.
>   * gcc.target/arm/mve/intrinsics/vqrdmlashq_n_u32.c: Remove.
>   * gcc.target/arm/mve/intrinsics/vqrdmlashq_n_u8.c: Remove.
> 
> (cherry picked from commit 237f12da4124b91503646b099a8282aa6b251ef9)
> 
> 
> ### Attachment also inlined for ease of reply
> ###
> 
> 
> diff --git a/gcc/config/arm/arm_mve.h b/gcc/config/arm/arm_mve.h
> index
> 424a5ae84623569c9feafae78107933cb1de5744..f0de29477abd9a1474eaaf0
> 28aa9a6ea57b58142 100644
> --- a/gcc/config/arm/arm_mve.h
> +++ b/gcc/config/arm/arm_mve.h
> @@ -1236,9 +1236,6 @@
>  #define vpselq_u8(__a, __b, __p) __arm_vpselq_u8(__a, __b, __p)
>  #define vpselq_s8(__a, __b, __p) __arm_vpselq_s8(__a, __b, __p)
>  #define vrev64q_m_u8(__inactive, __a, __p)
> __arm_vrev64q_m_u8(__inactive, __a, __p)
> -#define vqrdmlashq_n_u8(__a, __b, __c) __arm_vqrdmlashq_n_u8(__a, __b,
> __c)
> -#define vqrdmlahq_n_u8(__a, __b, __c) __arm_vqrdmlahq_n_u8(__a, __b,
> __c)
> -#define vqdmlahq_n_u8(__a, __b, __c) __arm_vqdmlahq_n_u8(__a, __b,
> __c)
>  #define vmvnq_m_u8(__inactive, __a, __p) __arm_vmvnq_m_u8(__inactive,
> __a, __p)
>  #define vmlasq_n_u8(__a, __b, __c) __arm_vmlasq_n_u8(__a, __b, __c)
>  #define vmlaq_n_u8(__a, __b, __c) __arm_vmlaq_n_u8(__a, __b, __c)
> @@ -1322,9 +1319,6 @@
>  #define vpselq_u16(__a, __b, __p) __arm_vpselq_u16(__a, __b, __p)
>  #define vpselq_s16(__a, __b, __p) __arm_vpselq_s16(__a, __b, __p)
>  #define vrev64q_m_u16(__inactive, __a, __p)
> __arm_vrev64q_m_u16(__inactive, __a, __p)
> -#define vqrdmlashq_n_u16(__a, __b, __c) __arm_vqrdmlashq_n_u16(__a,
> __b, __c)
> -#define vqrdmlahq_n_u16(__a, __b, __c) __arm_vqrdmlahq_n_u16(__a, __b,
> __c)
> -#define vqdmlahq_n_u16(__a, __b, __c) __arm_vqdmlahq_n_u16(__a, __b,
> __c)
>  #define vmvnq_m_u16(__inactive, __a, __p)
> __arm_vmvnq_m_u16(__inactive, __a, __p)
>  #define vmlasq_n_u16(__a, __b, __c) __arm_vmlasq_n_u16(__a, __b, __c)
>  #define vmlaq_n_u16(__a, __b, __c) __arm_vmlaq_n_u16(__a, __b, __c)
> @@ -1408,9 +1402,6 @@
>  #define vpselq_u32(__a, __b, __p) __arm_vpselq_u32(__a, __b, __p)
>  #define vpselq_s32(__a, __b, __p) __arm_vpselq_s32(__a, __b, __p)
>  #define vrev64q_m_u32(__inactive, __a, __p)
> __arm_vrev64q_m_u32(__inactive, __a, __p)
> -#define vqrdmlashq_n_u32(__a, __b, __c) __arm_vqrdmlashq_n_u32(__a,
> __b, __c)
> -#define vqrdmlahq_n_u32(__a, __b, __c) __arm_vqrdmlahq_n_u32(__a, __b,
> __c)
> -#define vqdmlahq_n_u32(__a, __b, __c) __arm_vqdmlahq_n_u32(__a, __b,
> __c)
>  #define vmvnq_m_u32(__inactive, __a, __p)
> __arm_vmvnq_m_u32(__inactive, __a, __p)
>  #define vmlasq_n_u32(__a, __b, __c) __arm_vmlasq_n_u32(__a, __b, __c)
>  

RE: [PATCH][GCC-10 backport] arm: [MVE] Add missing __arm_vcvtnq_u32_f32 intrinsic (PR 96914)

2020-10-16 Thread Kyrylo Tkachov via Gcc-patches



> -Original Message-
> From: Srinath Parvathaneni 
> Sent: 16 October 2020 12:45
> To: gcc-patches@gcc.gnu.org
> Cc: Kyrylo Tkachov 
> Subject: [PATCH][GCC-10 backport] arm: [MVE] Add missing
> __arm_vcvtnq_u32_f32 intrinsic (PR 96914)
> 
> Hello,
> 
> Applied cleanly, Ok for backporting this patch to GCC-10?

Ok.
Thanks,
Kyrill

> 
> __arm_vcvtnq_u32_f32 was missing from arm_mve.h, although the s32_f32
> and
> [su]16_f16 versions were present.
> 
> This patch adds the missing version and testcase, which are
> cut-and-paste from the other versions.
> 
> 2020-10-08  Christophe Lyon  
> 
>   gcc/
>   PR target/96914
>   * config/arm/arm_mve.h (__arm_vcvtnq_u32_f32): New.
> 
>   gcc/testsuite/
>   PR target/96914
>   * gcc.target/arm/mve/intrinsics/vcvtnq_u32_f32.c: New test.
> 
> (cherry picked from commit 5a448362da6133c3b16ffdb0c795b657af7fa5a4)
> 
> 
> ### Attachment also inlined for ease of reply
> ###
> 
> 
> diff --git a/gcc/config/arm/arm_mve.h b/gcc/config/arm/arm_mve.h
> index
> f0de29477abd9a1474eaaf028aa9a6ea57b58142..6c0d1e2e634a32196eb310
> 79166a7733dcd3a4b6 100644
> --- a/gcc/config/arm/arm_mve.h
> +++ b/gcc/config/arm/arm_mve.h
> @@ -645,6 +645,7 @@
>  #define vcvtpq_u16_f16(__a) __arm_vcvtpq_u16_f16(__a)
>  #define vcvtpq_u32_f32(__a) __arm_vcvtpq_u32_f32(__a)
>  #define vcvtnq_u16_f16(__a) __arm_vcvtnq_u16_f16(__a)
> +#define vcvtnq_u32_f32(__a) __arm_vcvtnq_u32_f32(__a)
>  #define vcvtmq_u16_f16(__a) __arm_vcvtmq_u16_f16(__a)
>  #define vcvtmq_u32_f32(__a) __arm_vcvtmq_u32_f32(__a)
>  #define vcvtaq_u16_f16(__a) __arm_vcvtaq_u16_f16(__a)
> @@ -16966,6 +16967,13 @@ __arm_vcvtnq_u16_f16 (float16x8_t __a)
>return __builtin_mve_vcvtnq_uv8hi (__a);
>  }
> 
> +__extension__ extern __inline uint32x4_t
> +__attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
> +__arm_vcvtnq_u32_f32 (float32x4_t __a)
> +{
> +  return __builtin_mve_vcvtnq_uv4si (__a);
> +}
> +
>  __extension__ extern __inline uint16x8_t
>  __attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
>  __arm_vcvtmq_u16_f16 (float16x8_t __a)
> diff --git a/gcc/testsuite/gcc.target/arm/mve/intrinsics/vcvtnq_u32_f32.c
> b/gcc/testsuite/gcc.target/arm/mve/intrinsics/vcvtnq_u32_f32.c
> new file mode 100644
> index
> ..b6d5eb904931438571599
> 95d78f53df8ced0c667
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/arm/mve/intrinsics/vcvtnq_u32_f32.c
> @@ -0,0 +1,13 @@
> +/* { dg-require-effective-target arm_v8_1m_mve_fp_ok } */
> +/* { dg-add-options arm_v8_1m_mve_fp } */
> +/* { dg-additional-options "-O2" } */
> +
> +#include "arm_mve.h"
> +
> +uint32x4_t
> +foo (float32x4_t a)
> +{
> +  return vcvtnq_u32_f32 (a);
> +}
> +
> +/* { dg-final { scan-assembler "vcvtn.u32.f32"  }  } */



RE: [PATCH][GCC-10 backport] arm: [MVE] Add vqdmlashq intrinsics (PR target/96914)

2020-10-16 Thread Kyrylo Tkachov via Gcc-patches



> -Original Message-
> From: Srinath Parvathaneni 
> Sent: 16 October 2020 12:45
> To: gcc-patches@gcc.gnu.org
> Cc: Kyrylo Tkachov 
> Subject: [PATCH][GCC-10 backport] arm: [MVE] Add vqdmlashq intrinsics (PR
> target/96914)
> 
> Hello,
> 
> Applied cleanly, Ok for backporting this patch to GCC-10?

Ok.
Thanks,
Kyrill

> 
> This patch adds:
> vqdmlashq_m_n_s16
> vqdmlashq_m_n_s32
> vqdmlashq_m_n_s8
> vqdmlashq_n_s16
> vqdmlashq_n_s32
> vqdmlashq_n_s8
> 
> 2020-10-08  Christophe Lyon  
> 
>   gcc/
>   PR target/96914
>   * config/arm/arm_mve.h (vqdmlashq, vqdmlashq_m): Define.
>   * config/arm/arm_mve_builtins.def (vqdmlashq_n_s)
>   (vqdmlashq_m_n_s,): New.
>   * config/arm/unspecs.md (VQDMLASHQ_N_S, VQDMLASHQ_M_N_S):
> New
>   unspecs.
>   * config/arm/iterators.md (VQDMLASHQ_N_S,
> VQDMLASHQ_M_N_S): New
>   attributes.
>   (VQDMLASHQ_N): New iterator.
>   * config/arm/mve.md (mve_vqdmlashq_n_, mve_vqdmlashq_m_n_s):
> New
>   patterns.
> 
>   gcc/testsuite/
>   PR target/96914
>   * gcc.target/arm/mve/intrinsics/vqdmlashq_m_n_s16.c: New test.
>   * gcc.target/arm/mve/intrinsics/vqdmlashq_m_n_s32.c: New test.
>   * gcc.target/arm/mve/intrinsics/vqdmlashq_m_n_s8.c: New test.
>   * gcc.target/arm/mve/intrinsics/vqdmlashq_n_s16.c: New test.
>   * gcc.target/arm/mve/intrinsics/vqdmlashq_n_s32.c: New test.
>   * gcc.target/arm/mve/intrinsics/vqdmlashq_n_s8.c: New test.
> 
> (cherry picked from commit afb198ee3729c29c8e681aedc656f55f4afe4053)
> 
> 
> ### Attachment also inlined for ease of reply
> ###
> 
> 
> diff --git a/gcc/config/arm/arm_mve.h b/gcc/config/arm/arm_mve.h
> index
> 02dd216cb6039c20dbeda0c2ee1ca7ee8cb77549..424a5ae84623569c9feafa
> e78107933cb1de5744 100644
> --- a/gcc/config/arm/arm_mve.h
> +++ b/gcc/config/arm/arm_mve.h
> @@ -141,6 +141,7 @@
>  #define vrev64q_m(__inactive, __a, __p) __arm_vrev64q_m(__inactive, __a,
> __p)
>  #define vqrdmlashq(__a, __b, __c) __arm_vqrdmlashq(__a, __b, __c)
>  #define vqrdmlahq(__a, __b, __c) __arm_vqrdmlahq(__a, __b, __c)
> +#define vqdmlashq(__a, __b, __c) __arm_vqdmlashq(__a, __b, __c)
>  #define vqdmlahq(__a, __b, __c) __arm_vqdmlahq(__a, __b, __c)
>  #define vmvnq_m(__inactive, __a, __p) __arm_vmvnq_m(__inactive, __a,
> __p)
>  #define vmlasq(__a, __b, __c) __arm_vmlasq(__a, __b, __c)
> @@ -260,6 +261,7 @@
>  #define vorrq_m(__inactive, __a, __b, __p) __arm_vorrq_m(__inactive, __a,
> __b, __p)
>  #define vqaddq_m(__inactive, __a, __b, __p) __arm_vqaddq_m(__inactive,
> __a, __b, __p)
>  #define vqdmladhq_m(__inactive, __a, __b, __p)
> __arm_vqdmladhq_m(__inactive, __a, __b, __p)
> +#define vqdmlashq_m(__a, __b, __c, __p) __arm_vqdmlashq_m(__a, __b,
> __c, __p)
>  #define vqdmladhxq_m(__inactive, __a, __b, __p)
> __arm_vqdmladhxq_m(__inactive, __a, __b, __p)
>  #define vqdmlahq_m(__a, __b, __c, __p) __arm_vqdmlahq_m(__a, __b, __c,
> __p)
>  #define vqdmlsdhq_m(__inactive, __a, __b, __p)
> __arm_vqdmlsdhq_m(__inactive, __a, __b, __p)
> @@ -1306,6 +1308,7 @@
>  #define vqdmlsdhxq_s8(__inactive, __a, __b)
> __arm_vqdmlsdhxq_s8(__inactive, __a, __b)
>  #define vqdmlsdhq_s8(__inactive, __a, __b)
> __arm_vqdmlsdhq_s8(__inactive, __a, __b)
>  #define vqdmlahq_n_s8(__a, __b, __c) __arm_vqdmlahq_n_s8(__a, __b, __c)
> +#define vqdmlashq_n_s8(__a, __b, __c) __arm_vqdmlashq_n_s8(__a, __b,
> __c)
>  #define vqdmladhxq_s8(__inactive, __a, __b)
> __arm_vqdmladhxq_s8(__inactive, __a, __b)
>  #define vqdmladhq_s8(__inactive, __a, __b)
> __arm_vqdmladhq_s8(__inactive, __a, __b)
>  #define vmlsdavaxq_s8(__a, __b, __c) __arm_vmlsdavaxq_s8(__a, __b, __c)
> @@ -1390,6 +1393,7 @@
>  #define vqrdmladhq_s16(__inactive, __a, __b)
> __arm_vqrdmladhq_s16(__inactive, __a, __b)
>  #define vqdmlsdhxq_s16(__inactive, __a, __b)
> __arm_vqdmlsdhxq_s16(__inactive, __a, __b)
>  #define vqdmlsdhq_s16(__inactive, __a, __b)
> __arm_vqdmlsdhq_s16(__inactive, __a, __b)
> +#define vqdmlashq_n_s16(__a, __b, __c) __arm_vqdmlashq_n_s16(__a,
> __b, __c)
>  #define vqdmlahq_n_s16(__a, __b, __c) __arm_vqdmlahq_n_s16(__a, __b,
> __c)
>  #define vqdmladhxq_s16(__inactive, __a, __b)
> __arm_vqdmladhxq_s16(__inactive, __a, __b)
>  #define vqdmladhq_s16(__inactive, __a, __b)
> __arm_vqdmladhq_s16(__inactive, __a, __b)
> @@ -1475,6 +1479,7 @@
>  #define vqrdmladhq_s32(__inactive, __a, __b)
> __arm_vqrdmladhq_s32(__inactive, __a, __b)
>  #define vqdmlsdhxq_s32(__inactive, __a, __b)
> __arm_vqdmlsdhxq_s32(__inactive, __a, __b)
>  #define vqdmlsdhq_s32(__inactive, __a, __b)
> __arm_vqdmlsdhq_s32(__inactive, __a, __b)
> +#define vqdmlashq_n_s32(__a, __b, __c) __arm_vqdmlashq_n_s32(__a,
> __b, __c)
>  #define vqdmlahq_n_s32(__a, __b, __c) __arm_vqdmlahq_n_s32(__a, __b,
> __c)
>  #define vqdmladhxq_s32(__inactive, __a, __b)
> __arm_vqdmladhxq_s32(__inactive, __a, __b)
>  #define vqdmladhq_s32(__inactive, __a, __b)
> __arm_vqdmladhq_s32(__inactive, __a, __b)
> @@ -1901,6 +1906,9 @@
>  #define 

[PATCH][GCC-10 backport] arm: [MVE] Remove illegal intrinsics (PR target/96914)

2020-10-16 Thread Srinath Parvathaneni via Gcc-patches
Hello,

Applied cleanly, Ok for backporting this patch to GCC-10?

A few MVE intrinsics had an unsigned variant implement while they are
supported by the hardware.  This patch removes them:
__arm_vqrdmlashq_n_u8
__arm_vqrdmlahq_n_u8
__arm_vqdmlahq_n_u8
__arm_vqrdmlashq_n_u16
__arm_vqrdmlahq_n_u16
__arm_vqdmlahq_n_u16
__arm_vqrdmlashq_n_u32
__arm_vqrdmlahq_n_u32
__arm_vqdmlahq_n_u32
__arm_vmlaldavaxq_p_u32
__arm_vmlaldavaxq_p_u16

2020-10-08  Christophe Lyon  

gcc/
PR target/96914
* config/arm/arm_mve.h (vqrdmlashq_n_u8, vqrdmlashq_n_u16)
(vqrdmlashq_n_u32, vqrdmlahq_n_u8, vqrdmlahq_n_u16)
(vqrdmlahq_n_u32, vqdmlahq_n_u8, vqdmlahq_n_u16, vqdmlahq_n_u32)
(vmlaldavaxq_p_u16, vmlaldavaxq_p_u32): Remove.
* config/arm/arm_mve_builtins.def (vqrdmlashq_n_u, vqrdmlahq_n_u)
(vqdmlahq_n_u, vmlaldavaxq_p_u): Remove.
* config/arm/unspecs.md (VQDMLAHQ_N_U, VQRDMLAHQ_N_U)
(VQRDMLASHQ_N_U)
(VMLALDAVAXQ_P_U): Remove unspecs.
* config/arm/iterators.md (VQDMLAHQ_N_U, VQRDMLAHQ_N_U)
(VQRDMLASHQ_N_U, VMLALDAVAXQ_P_U): Remove attributes.
(VQDMLAHQ_N, VQRDMLAHQ_N, VQRDMLASHQ_N, VMLALDAVAXQ_P): Remove
unsigned variants from iterators.
* config/arm/mve.md (mve_vqdmlahq_n_)
(mve_vqrdmlahq_n_)
(mve_vqrdmlashq_n_, mve_vmlaldavaxq_p_):
Update comment.

gcc/testsuite/
PR target/96914
* gcc.target/arm/mve/intrinsics/vmlaldavaxq_p_u16.c: Remove.
* gcc.target/arm/mve/intrinsics/vmlaldavaxq_p_u32.c: Remove.
* gcc.target/arm/mve/intrinsics/vqdmlahq_n_u16.c: Remove.
* gcc.target/arm/mve/intrinsics/vqdmlahq_n_u32.c: Remove.
* gcc.target/arm/mve/intrinsics/vqdmlahq_n_u8.c: Remove.
* gcc.target/arm/mve/intrinsics/vqrdmlahq_n_u16.c: Remove.
* gcc.target/arm/mve/intrinsics/vqrdmlahq_n_u32.c: Remove.
* gcc.target/arm/mve/intrinsics/vqrdmlahq_n_u8.c: Remove.
* gcc.target/arm/mve/intrinsics/vqrdmlashq_n_u16.c: Remove.
* gcc.target/arm/mve/intrinsics/vqrdmlashq_n_u32.c: Remove.
* gcc.target/arm/mve/intrinsics/vqrdmlashq_n_u8.c: Remove.

(cherry picked from commit 237f12da4124b91503646b099a8282aa6b251ef9)


### Attachment also inlined for ease of reply###


diff --git a/gcc/config/arm/arm_mve.h b/gcc/config/arm/arm_mve.h
index 
424a5ae84623569c9feafae78107933cb1de5744..f0de29477abd9a1474eaaf028aa9a6ea57b58142
 100644
--- a/gcc/config/arm/arm_mve.h
+++ b/gcc/config/arm/arm_mve.h
@@ -1236,9 +1236,6 @@
 #define vpselq_u8(__a, __b, __p) __arm_vpselq_u8(__a, __b, __p)
 #define vpselq_s8(__a, __b, __p) __arm_vpselq_s8(__a, __b, __p)
 #define vrev64q_m_u8(__inactive, __a, __p) __arm_vrev64q_m_u8(__inactive, __a, 
__p)
-#define vqrdmlashq_n_u8(__a, __b, __c) __arm_vqrdmlashq_n_u8(__a, __b, __c)
-#define vqrdmlahq_n_u8(__a, __b, __c) __arm_vqrdmlahq_n_u8(__a, __b, __c)
-#define vqdmlahq_n_u8(__a, __b, __c) __arm_vqdmlahq_n_u8(__a, __b, __c)
 #define vmvnq_m_u8(__inactive, __a, __p) __arm_vmvnq_m_u8(__inactive, __a, __p)
 #define vmlasq_n_u8(__a, __b, __c) __arm_vmlasq_n_u8(__a, __b, __c)
 #define vmlaq_n_u8(__a, __b, __c) __arm_vmlaq_n_u8(__a, __b, __c)
@@ -1322,9 +1319,6 @@
 #define vpselq_u16(__a, __b, __p) __arm_vpselq_u16(__a, __b, __p)
 #define vpselq_s16(__a, __b, __p) __arm_vpselq_s16(__a, __b, __p)
 #define vrev64q_m_u16(__inactive, __a, __p) __arm_vrev64q_m_u16(__inactive, 
__a, __p)
-#define vqrdmlashq_n_u16(__a, __b, __c) __arm_vqrdmlashq_n_u16(__a, __b, __c)
-#define vqrdmlahq_n_u16(__a, __b, __c) __arm_vqrdmlahq_n_u16(__a, __b, __c)
-#define vqdmlahq_n_u16(__a, __b, __c) __arm_vqdmlahq_n_u16(__a, __b, __c)
 #define vmvnq_m_u16(__inactive, __a, __p) __arm_vmvnq_m_u16(__inactive, __a, 
__p)
 #define vmlasq_n_u16(__a, __b, __c) __arm_vmlasq_n_u16(__a, __b, __c)
 #define vmlaq_n_u16(__a, __b, __c) __arm_vmlaq_n_u16(__a, __b, __c)
@@ -1408,9 +1402,6 @@
 #define vpselq_u32(__a, __b, __p) __arm_vpselq_u32(__a, __b, __p)
 #define vpselq_s32(__a, __b, __p) __arm_vpselq_s32(__a, __b, __p)
 #define vrev64q_m_u32(__inactive, __a, __p) __arm_vrev64q_m_u32(__inactive, 
__a, __p)
-#define vqrdmlashq_n_u32(__a, __b, __c) __arm_vqrdmlashq_n_u32(__a, __b, __c)
-#define vqrdmlahq_n_u32(__a, __b, __c) __arm_vqrdmlahq_n_u32(__a, __b, __c)
-#define vqdmlahq_n_u32(__a, __b, __c) __arm_vqdmlahq_n_u32(__a, __b, __c)
 #define vmvnq_m_u32(__inactive, __a, __p) __arm_vmvnq_m_u32(__inactive, __a, 
__p)
 #define vmlasq_n_u32(__a, __b, __c) __arm_vmlasq_n_u32(__a, __b, __c)
 #define vmlaq_n_u32(__a, __b, __c) __arm_vmlaq_n_u32(__a, __b, __c)
@@ -2032,8 +2023,6 @@
 #define vmlaldavaq_p_u16(__a, __b, __c, __p) __arm_vmlaldavaq_p_u16(__a, __b, 
__c, __p)
 #define vmlaldavaxq_p_s32(__a, __b, __c, __p) __arm_vmlaldavaxq_p_s32(__a, 
__b, __c, __p)
 #define vmlaldavaxq_p_s16(__a, __b, __c, __p) __arm_vmlaldavaxq_p_s16(__a, 
__b, __c, __p)
-#define vmlaldavaxq_p_u32(__a, __b, __c, __p) 

[PATCH][GCC-10 backport] arm: [MVE] Add vqdmlashq intrinsics (PR target/96914)

2020-10-16 Thread Srinath Parvathaneni via Gcc-patches
Hello,

Applied cleanly, Ok for backporting this patch to GCC-10?

This patch adds:
vqdmlashq_m_n_s16
vqdmlashq_m_n_s32
vqdmlashq_m_n_s8
vqdmlashq_n_s16
vqdmlashq_n_s32
vqdmlashq_n_s8

2020-10-08  Christophe Lyon  

gcc/
PR target/96914
* config/arm/arm_mve.h (vqdmlashq, vqdmlashq_m): Define.
* config/arm/arm_mve_builtins.def (vqdmlashq_n_s)
(vqdmlashq_m_n_s,): New.
* config/arm/unspecs.md (VQDMLASHQ_N_S, VQDMLASHQ_M_N_S): New
unspecs.
* config/arm/iterators.md (VQDMLASHQ_N_S, VQDMLASHQ_M_N_S): New
attributes.
(VQDMLASHQ_N): New iterator.
* config/arm/mve.md (mve_vqdmlashq_n_, mve_vqdmlashq_m_n_s): New
patterns.

gcc/testsuite/
PR target/96914
* gcc.target/arm/mve/intrinsics/vqdmlashq_m_n_s16.c: New test.
* gcc.target/arm/mve/intrinsics/vqdmlashq_m_n_s32.c: New test.
* gcc.target/arm/mve/intrinsics/vqdmlashq_m_n_s8.c: New test.
* gcc.target/arm/mve/intrinsics/vqdmlashq_n_s16.c: New test.
* gcc.target/arm/mve/intrinsics/vqdmlashq_n_s32.c: New test.
* gcc.target/arm/mve/intrinsics/vqdmlashq_n_s8.c: New test.

(cherry picked from commit afb198ee3729c29c8e681aedc656f55f4afe4053)


### Attachment also inlined for ease of reply###


diff --git a/gcc/config/arm/arm_mve.h b/gcc/config/arm/arm_mve.h
index 
02dd216cb6039c20dbeda0c2ee1ca7ee8cb77549..424a5ae84623569c9feafae78107933cb1de5744
 100644
--- a/gcc/config/arm/arm_mve.h
+++ b/gcc/config/arm/arm_mve.h
@@ -141,6 +141,7 @@
 #define vrev64q_m(__inactive, __a, __p) __arm_vrev64q_m(__inactive, __a, __p)
 #define vqrdmlashq(__a, __b, __c) __arm_vqrdmlashq(__a, __b, __c)
 #define vqrdmlahq(__a, __b, __c) __arm_vqrdmlahq(__a, __b, __c)
+#define vqdmlashq(__a, __b, __c) __arm_vqdmlashq(__a, __b, __c)
 #define vqdmlahq(__a, __b, __c) __arm_vqdmlahq(__a, __b, __c)
 #define vmvnq_m(__inactive, __a, __p) __arm_vmvnq_m(__inactive, __a, __p)
 #define vmlasq(__a, __b, __c) __arm_vmlasq(__a, __b, __c)
@@ -260,6 +261,7 @@
 #define vorrq_m(__inactive, __a, __b, __p) __arm_vorrq_m(__inactive, __a, __b, 
__p)
 #define vqaddq_m(__inactive, __a, __b, __p) __arm_vqaddq_m(__inactive, __a, 
__b, __p)
 #define vqdmladhq_m(__inactive, __a, __b, __p) __arm_vqdmladhq_m(__inactive, 
__a, __b, __p)
+#define vqdmlashq_m(__a, __b, __c, __p) __arm_vqdmlashq_m(__a, __b, __c, __p)
 #define vqdmladhxq_m(__inactive, __a, __b, __p) __arm_vqdmladhxq_m(__inactive, 
__a, __b, __p)
 #define vqdmlahq_m(__a, __b, __c, __p) __arm_vqdmlahq_m(__a, __b, __c, __p)
 #define vqdmlsdhq_m(__inactive, __a, __b, __p) __arm_vqdmlsdhq_m(__inactive, 
__a, __b, __p)
@@ -1306,6 +1308,7 @@
 #define vqdmlsdhxq_s8(__inactive, __a, __b) __arm_vqdmlsdhxq_s8(__inactive, 
__a, __b)
 #define vqdmlsdhq_s8(__inactive, __a, __b) __arm_vqdmlsdhq_s8(__inactive, __a, 
__b)
 #define vqdmlahq_n_s8(__a, __b, __c) __arm_vqdmlahq_n_s8(__a, __b, __c)
+#define vqdmlashq_n_s8(__a, __b, __c) __arm_vqdmlashq_n_s8(__a, __b, __c)
 #define vqdmladhxq_s8(__inactive, __a, __b) __arm_vqdmladhxq_s8(__inactive, 
__a, __b)
 #define vqdmladhq_s8(__inactive, __a, __b) __arm_vqdmladhq_s8(__inactive, __a, 
__b)
 #define vmlsdavaxq_s8(__a, __b, __c) __arm_vmlsdavaxq_s8(__a, __b, __c)
@@ -1390,6 +1393,7 @@
 #define vqrdmladhq_s16(__inactive, __a, __b) __arm_vqrdmladhq_s16(__inactive, 
__a, __b)
 #define vqdmlsdhxq_s16(__inactive, __a, __b) __arm_vqdmlsdhxq_s16(__inactive, 
__a, __b)
 #define vqdmlsdhq_s16(__inactive, __a, __b) __arm_vqdmlsdhq_s16(__inactive, 
__a, __b)
+#define vqdmlashq_n_s16(__a, __b, __c) __arm_vqdmlashq_n_s16(__a, __b, __c)
 #define vqdmlahq_n_s16(__a, __b, __c) __arm_vqdmlahq_n_s16(__a, __b, __c)
 #define vqdmladhxq_s16(__inactive, __a, __b) __arm_vqdmladhxq_s16(__inactive, 
__a, __b)
 #define vqdmladhq_s16(__inactive, __a, __b) __arm_vqdmladhq_s16(__inactive, 
__a, __b)
@@ -1475,6 +1479,7 @@
 #define vqrdmladhq_s32(__inactive, __a, __b) __arm_vqrdmladhq_s32(__inactive, 
__a, __b)
 #define vqdmlsdhxq_s32(__inactive, __a, __b) __arm_vqdmlsdhxq_s32(__inactive, 
__a, __b)
 #define vqdmlsdhq_s32(__inactive, __a, __b) __arm_vqdmlsdhq_s32(__inactive, 
__a, __b)
+#define vqdmlashq_n_s32(__a, __b, __c) __arm_vqdmlashq_n_s32(__a, __b, __c)
 #define vqdmlahq_n_s32(__a, __b, __c) __arm_vqdmlahq_n_s32(__a, __b, __c)
 #define vqdmladhxq_s32(__inactive, __a, __b) __arm_vqdmladhxq_s32(__inactive, 
__a, __b)
 #define vqdmladhq_s32(__inactive, __a, __b) __arm_vqdmladhq_s32(__inactive, 
__a, __b)
@@ -1901,6 +1906,9 @@
 #define vqdmladhxq_m_s8(__inactive, __a, __b, __p) 
__arm_vqdmladhxq_m_s8(__inactive, __a, __b, __p)
 #define vqdmladhxq_m_s32(__inactive, __a, __b, __p) 
__arm_vqdmladhxq_m_s32(__inactive, __a, __b, __p)
 #define vqdmladhxq_m_s16(__inactive, __a, __b, __p) 
__arm_vqdmladhxq_m_s16(__inactive, __a, __b, __p)
+#define vqdmlashq_m_n_s8(__a, __b, __c, __p) __arm_vqdmlashq_m_n_s8(__a, __b, 
__c, __p)
+#define vqdmlashq_m_n_s32(__a, __b, __c, __p) 

[PATCH][GCC-10 backport] arm: [MVE] Add missing __arm_vcvtnq_u32_f32 intrinsic (PR 96914)

2020-10-16 Thread Srinath Parvathaneni via Gcc-patches
Hello,

Applied cleanly, Ok for backporting this patch to GCC-10?

__arm_vcvtnq_u32_f32 was missing from arm_mve.h, although the s32_f32 and
[su]16_f16 versions were present.

This patch adds the missing version and testcase, which are
cut-and-paste from the other versions.

2020-10-08  Christophe Lyon  

gcc/
PR target/96914
* config/arm/arm_mve.h (__arm_vcvtnq_u32_f32): New.

gcc/testsuite/
PR target/96914
* gcc.target/arm/mve/intrinsics/vcvtnq_u32_f32.c: New test.

(cherry picked from commit 5a448362da6133c3b16ffdb0c795b657af7fa5a4)


### Attachment also inlined for ease of reply###


diff --git a/gcc/config/arm/arm_mve.h b/gcc/config/arm/arm_mve.h
index 
f0de29477abd9a1474eaaf028aa9a6ea57b58142..6c0d1e2e634a32196eb31079166a7733dcd3a4b6
 100644
--- a/gcc/config/arm/arm_mve.h
+++ b/gcc/config/arm/arm_mve.h
@@ -645,6 +645,7 @@
 #define vcvtpq_u16_f16(__a) __arm_vcvtpq_u16_f16(__a)
 #define vcvtpq_u32_f32(__a) __arm_vcvtpq_u32_f32(__a)
 #define vcvtnq_u16_f16(__a) __arm_vcvtnq_u16_f16(__a)
+#define vcvtnq_u32_f32(__a) __arm_vcvtnq_u32_f32(__a)
 #define vcvtmq_u16_f16(__a) __arm_vcvtmq_u16_f16(__a)
 #define vcvtmq_u32_f32(__a) __arm_vcvtmq_u32_f32(__a)
 #define vcvtaq_u16_f16(__a) __arm_vcvtaq_u16_f16(__a)
@@ -16966,6 +16967,13 @@ __arm_vcvtnq_u16_f16 (float16x8_t __a)
   return __builtin_mve_vcvtnq_uv8hi (__a);
 }
 
+__extension__ extern __inline uint32x4_t
+__attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
+__arm_vcvtnq_u32_f32 (float32x4_t __a)
+{
+  return __builtin_mve_vcvtnq_uv4si (__a);
+}
+
 __extension__ extern __inline uint16x8_t
 __attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
 __arm_vcvtmq_u16_f16 (float16x8_t __a)
diff --git a/gcc/testsuite/gcc.target/arm/mve/intrinsics/vcvtnq_u32_f32.c 
b/gcc/testsuite/gcc.target/arm/mve/intrinsics/vcvtnq_u32_f32.c
new file mode 100644
index 
..b6d5eb90493143857159995d78f53df8ced0c667
--- /dev/null
+++ b/gcc/testsuite/gcc.target/arm/mve/intrinsics/vcvtnq_u32_f32.c
@@ -0,0 +1,13 @@
+/* { dg-require-effective-target arm_v8_1m_mve_fp_ok } */
+/* { dg-add-options arm_v8_1m_mve_fp } */
+/* { dg-additional-options "-O2" } */
+
+#include "arm_mve.h"
+
+uint32x4_t
+foo (float32x4_t a)
+{
+  return vcvtnq_u32_f32 (a);
+}
+
+/* { dg-final { scan-assembler "vcvtn.u32.f32"  }  } */

diff --git a/gcc/config/arm/arm_mve.h b/gcc/config/arm/arm_mve.h
index 
f0de29477abd9a1474eaaf028aa9a6ea57b58142..6c0d1e2e634a32196eb31079166a7733dcd3a4b6
 100644
--- a/gcc/config/arm/arm_mve.h
+++ b/gcc/config/arm/arm_mve.h
@@ -645,6 +645,7 @@
 #define vcvtpq_u16_f16(__a) __arm_vcvtpq_u16_f16(__a)
 #define vcvtpq_u32_f32(__a) __arm_vcvtpq_u32_f32(__a)
 #define vcvtnq_u16_f16(__a) __arm_vcvtnq_u16_f16(__a)
+#define vcvtnq_u32_f32(__a) __arm_vcvtnq_u32_f32(__a)
 #define vcvtmq_u16_f16(__a) __arm_vcvtmq_u16_f16(__a)
 #define vcvtmq_u32_f32(__a) __arm_vcvtmq_u32_f32(__a)
 #define vcvtaq_u16_f16(__a) __arm_vcvtaq_u16_f16(__a)
@@ -16966,6 +16967,13 @@ __arm_vcvtnq_u16_f16 (float16x8_t __a)
   return __builtin_mve_vcvtnq_uv8hi (__a);
 }
 
+__extension__ extern __inline uint32x4_t
+__attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
+__arm_vcvtnq_u32_f32 (float32x4_t __a)
+{
+  return __builtin_mve_vcvtnq_uv4si (__a);
+}
+
 __extension__ extern __inline uint16x8_t
 __attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
 __arm_vcvtmq_u16_f16 (float16x8_t __a)
diff --git a/gcc/testsuite/gcc.target/arm/mve/intrinsics/vcvtnq_u32_f32.c 
b/gcc/testsuite/gcc.target/arm/mve/intrinsics/vcvtnq_u32_f32.c
new file mode 100644
index 
..b6d5eb90493143857159995d78f53df8ced0c667
--- /dev/null
+++ b/gcc/testsuite/gcc.target/arm/mve/intrinsics/vcvtnq_u32_f32.c
@@ -0,0 +1,13 @@
+/* { dg-require-effective-target arm_v8_1m_mve_fp_ok } */
+/* { dg-add-options arm_v8_1m_mve_fp } */
+/* { dg-additional-options "-O2" } */
+
+#include "arm_mve.h"
+
+uint32x4_t
+foo (float32x4_t a)
+{
+  return vcvtnq_u32_f32 (a);
+}
+
+/* { dg-final { scan-assembler "vcvtn.u32.f32"  }  } */



[PATCH][COMMITTED][GCC-10 backport] arm: Fix wrong code generated for mve scatter store with writeback intrinsics with -O2 (PR97271).

2020-10-16 Thread Srinath Parvathaneni via Gcc-patches
This patch fixes (PR97271) the wrong code-gen for mve scatter store with 
writeback intrinsics with -O2.

$cat bug.c
void
foo (uint32x4_t * addr, const int offset, int32x4_t value)
{
  vstrwq_scatter_base_wb_s32 (addr, 8, value);
}

$ arm-none-eabi-gcc  bug.c -S -O2 -march=armv8.1-m.main+mve -mfloat-abi=hard -o 
-
Without this patch:
...
foo:
vldrw.32q3, [r0]
vstrw.u32   q0, [q3, #8]!  ---> (A)
vldr.64 d4, .L3
vldr.64 d5, .L3+8
vldrw.32q3, [r0]
vstrw.u32   q2, [q3, #8]!  ---> (B)
bx  lr
...

With this patch:
...
foo:
vldrw.32q3, [r0]
vstrw.u32   q0, [q3, #8]!  --> (C)
vstrw.32q3, [r0]
bx  lr
...

Without this patch 2 vstrw assembly instructions (A and B) are generated for 
vstrwq_scatter_base_wb_s32
intrinsic where as fix generates only one vstrw assembly instruction (C).

Patch backport approved here 
https://gcc.gnu.org/pipermail/gcc-patches/2020-October/556373.html

gcc/ChangeLog:

2020-10-06  Srinath Parvathaneni  

PR target/97271
* config/arm/arm-builtins.c (arm_strsbwbs_qualifiers): Modify array.
(arm_strsbwbu_qualifiers): Likewise.
(arm_strsbwbs_p_qualifiers): Likewise.
(arm_strsbwbu_p_qualifiers): Likewise.
* config/arm/arm_mve.h (__arm_vstrdq_scatter_base_wb_s64): Modify
function definition.
(__arm_vstrdq_scatter_base_wb_u64): Likewise.
(__arm_vstrdq_scatter_base_wb_p_s64): Likewise.
(__arm_vstrdq_scatter_base_wb_p_u64): Likewise.
(__arm_vstrwq_scatter_base_wb_p_s32): Likewise.
(__arm_vstrwq_scatter_base_wb_p_u32): Likewise.
(__arm_vstrwq_scatter_base_wb_s32): Likewise.
(__arm_vstrwq_scatter_base_wb_u32): Likewise.
(__arm_vstrwq_scatter_base_wb_f32): Likewise.
(__arm_vstrwq_scatter_base_wb_p_f32): Likewise.
* config/arm/arm_mve_builtins.def (vstrwq_scatter_base_wb_add_u): Remove
expansion for the builtin.
(vstrwq_scatter_base_wb_add_s): Likewise.
(vstrwq_scatter_base_wb_add_f): Likewise.
(vstrdq_scatter_base_wb_add_u): Likewise.
(vstrdq_scatter_base_wb_add_s): Likewise.
(vstrwq_scatter_base_wb_p_add_u): Likewise.
(vstrwq_scatter_base_wb_p_add_s): Likewise.
(vstrwq_scatter_base_wb_p_add_f): Likewise.
(vstrdq_scatter_base_wb_p_add_u): Likewise.
(vstrdq_scatter_base_wb_p_add_s): Likewise.
* config/arm/mve.md (mve_vstrwq_scatter_base_wb_v4si): Remove
expand.
(mve_vstrwq_scatter_base_wb_add_v4si): Likewise.
(mve_vstrwq_scatter_base_wb_v4si_insn): Rename pattern to ...
(mve_vstrwq_scatter_base_wb_v4si): This.
(mve_vstrwq_scatter_base_wb_p_v4si): Remove expand.
(mve_vstrwq_scatter_base_wb_p_add_v4si): Likewise.
(mve_vstrwq_scatter_base_wb_p_v4si_insn): Rename pattern to ...
(mve_vstrwq_scatter_base_wb_p_v4si): This.
(mve_vstrwq_scatter_base_wb_fv4sf): Remove expand.
(mve_vstrwq_scatter_base_wb_add_fv4sf): Likewise.
(mve_vstrwq_scatter_base_wb_fv4sf_insn): Rename pattern to ...
(mve_vstrwq_scatter_base_wb_fv4sf): This.
(mve_vstrwq_scatter_base_wb_p_fv4sf): Remove expand.
(mve_vstrwq_scatter_base_wb_p_add_fv4sf): Likewise.
(mve_vstrwq_scatter_base_wb_p_fv4sf_insn): Rename pattern to ...
(mve_vstrwq_scatter_base_wb_p_fv4sf): This.
(mve_vstrdq_scatter_base_wb_v2di): Remove expand.
(mve_vstrdq_scatter_base_wb_add_v2di): Likewise.
(mve_vstrdq_scatter_base_wb_v2di_insn): Rename pattern to ...
(mve_vstrdq_scatter_base_wb_v2di): This.
(mve_vstrdq_scatter_base_wb_p_v2di): Remove expand.
(mve_vstrdq_scatter_base_wb_p_add_v2di): Likewise.
(mve_vstrdq_scatter_base_wb_p_v2di_insn): Rename pattern to ...
(mve_vstrdq_scatter_base_wb_p_v2di): This.

gcc/testsuite/ChangeLog:

PR target/97271
* gcc.target/arm/mve/intrinsics/vstrdq_scatter_base_wb_p_s64.c: Modify.
* gcc.target/arm/mve/intrinsics/vstrdq_scatter_base_wb_p_u64.c:
Likewise.
* gcc.target/arm/mve/intrinsics/vstrdq_scatter_base_wb_s64.c: Likewise.
* gcc.target/arm/mve/intrinsics/vstrdq_scatter_base_wb_u64.c: Likewise.
* gcc.target/arm/mve/intrinsics/vstrwq_scatter_base_wb_f32.c: Likewise.
* gcc.target/arm/mve/intrinsics/vstrwq_scatter_base_wb_p_f32.c:
Likewise.
* gcc.target/arm/mve/intrinsics/vstrwq_scatter_base_wb_p_s32.c:
Likewise.
* gcc.target/arm/mve/intrinsics/vstrwq_scatter_base_wb_p_u32.c:
Likewise.
* gcc.target/arm/mve/intrinsics/vstrwq_scatter_base_wb_s32.c: Likewise.
* gcc.target/arm/mve/intrinsics/vstrwq_scatter_base_wb_u32.c: Likewise.

(cherry picked from commit 377535881166969dba43794f298170978d797ef6)


### Attachment also inlined for ease of reply###



Re: New modref/ipa_modref optimization passes

2020-10-16 Thread Richard Biener
On Fri, 16 Oct 2020, Richard Biener wrote:

> On Fri, 16 Oct 2020, Richard Biener wrote:
> 
> > On Fri, 16 Oct 2020, Jan Hubicka wrote:
> > 
> > > Hi,
> > > I am slowly getting finished with the fn spec changes on trunk and then
> > > would like to proceed with modref.  Sadly  still get the assumed_type
> > > failuere and in addition to that:
> > > FAIL: gfortran.dg/finalize_25.f90   -O2  execution test
> > > FAIL: gfortran.dg/finalize_25.f90   -O3 -fomit-frame-pointer 
> > > -funroll-loops -fpeel-loops -ftracer -finline-functions  execution test
> > > FAIL: gfortran.dg/finalize_25.f90   -O3 -g  execution test
> > > FAIL: gfortran.dg/finalize_25.f90   -Os  execution test
> > > WARNING: gfortran.dg/pdt_14.f03   -O2  execution test program timed out.
> > > FAIL: gfortran.dg/pdt_14.f03   -O2  execution test
> > > WARNING: gfortran.dg/pdt_14.f03   -O3 -fomit-frame-pointer -funroll-loops 
> > > -fpeel-loops -ftracer -finline-functions  execution test
> > > program timed out.
> > > FAIL: gfortran.dg/pdt_14.f03   -O3 -fomit-frame-pointer -funroll-loops 
> > > -fpeel-loops -ftracer -finline-functions  execution test
> > > WARNING: gfortran.dg/pdt_14.f03   -O3 -g  execution test program timed 
> > > out.
> > > FAIL: gfortran.dg/pdt_14.f03   -O3 -g  execution test
> > > WARNING: gfortran.dg/pdt_14.f03   -Os  execution test program timed out.
> > > FAIL: gfortran.dg/pdt_14.f03   -Os  execution test
> > > 
> > > I wonder if there is any chance to get Fortran FE fixed here?
> > 
> > OK, I'll try doing a little surgery in the FE today, coming up with
> > a little refactoring and a fix along your original one that allows
> > for a better one by FE folks.
> 
> So I've sent a refactoring patch improving the tree building code.
> 
> But now trying to fix the actual issue with the idea to perform
> accesses indirectly via a descriptor with dim[] type I see that
> the coarray 'token' field is appended to descriptors conditional
> on -fcoarray and that this field makes the dim[] array no longer
> trailing - which means the offset of the 'token' field depends
> on the rank of the array.
> 
> The dim[] field is even optional when dim + codimen == 0 and that
> case indeed happens (ah, via get_scalar_to_descriptor_type).
> So much for re-using this combo ;)
> 
> I suppose we can compensate for this by dynamically computing the
> offset of the 'token' field but then it's not obvious to me
> where the total 'rank' is stored inside the descriptor or how
> the 'token' field is accessed for assumed-shape arrays - the
> current method by simple field chaining definitely won't work.
> 
> Anyway, I'll try to deal with all this by just adjusting the TBAA
> type but not the access type leaving that alone.
> 
> IMHO the cleanest way would be to swap the CAF token field and
> the dim[] field (which is an ABI change for -fcoarray)

OK, so I tried

diff --git a/gcc/fortran/trans-array.c b/gcc/fortran/trans-array.c
index f30a2f75701..29381f6756e 100644
--- a/gcc/fortran/trans-array.c
+++ b/gcc/fortran/trans-array.c
@@ -142,6 +142,17 @@ gfc_get_descriptor_field (tree desc, unsigned 
field_idx)
   tree field = gfc_advance_chain (TYPE_FIELDS (type), field_idx);
   gcc_assert (field != NULL_TREE);
 
+  /* We need to use a consistent descriptor type across all accesses
+ which should be possible by indirectly accessing the descriptor
+ via a type with a trailing flexible array dim[] member if there
+ were not the CAF token field after it.  So for now ensure correct
+ TBAA behavior by explicitely specifying a common TBAA type - any
+ descriptor-like type is OK here.  */
+  tree tbaa_type
+= build_pointer_type (gfc_get_array_descriptor_base (4, 2, false));
+  desc = fold_build2_loc (input_location, MEM_REF, type,
+ build_fold_addr_expr_loc (input_location, desc),
+ build_int_cst (tbaa_type, 0));
   return fold_build3_loc (input_location, COMPONENT_REF, TREE_TYPE 
(field),
  desc, field, NULL_TREE);
 }

which first reveals two spots missed by the sent refactoring and
second exposes the fact that we use aggregate copies to copy
array descritors or aggregates with array descriptor typed fields.
There's currently no way to assign a custom TBAA type to aggregate
fields which means that the only choice is to fix things at the
above central place is using alias-set zero (and hoping for
the embedded/aggregate copied places to match up).  In the end
this means that the optimal approach is to adjust only those
accesses where we do not know the actual descriptor type but
I expect those to be spread out?  Eventually those cases
could be identified above?

Meanwhile the refactoring patch still applies of course,
amended by adjustments to gfc_conv_descriptor_data_addr
and gfc_conv_descriptor_data_set.

Unfortunately punning the descriptor like above causes
numerous testsuite FAILs due to orignal dump scannings no
longer matching :/  So I'm hoping for a hint as to how to

Re: Handle POINTER_PLUS_EXPR in jump functions

2020-10-16 Thread Jan Hubicka
> > > 
> > > 2020-10-15  Jakub Jelinek  
> > > 
> > >   * gcc.dg/ipa/modref-1.c: Remove space between param offset: and number
> > >   in scan-ipa-dump.
> > >   (b): Declare return type to void.
> > >   (main): Declare return type to int.  Change c to array of 3 chars.
> > >   * gcc.dg/tree-ssa/modref-4.c: Remove space between param offset: and
> > >   number in scan-ipa-dump.  Use modref1 instead of modref2.
> > >   (b): Declare return type to void.
> > >   (main): Declare return type to int.  Change c to array of 3 chars.
> > Sorry for that - I had fixed versions of the testcases but must have
> > mixed the up.   I will look at the reutrn 0 case.
> 
> Note that even if it optimized as much as it ever could, return 0 is not the
> correct value, while c[0] is unmodified and the optimization
> correctly proves that it isn't and optimizes it into 0, c[2] is modified -
> it is changed from 0 to 1.  Perhaps you meant c[4]={0,1,0,0}; and check
> if c[0]+c[3] is optimized into 0?
Yep, I was trying to check that both offset and size are correctly
determined.  I applied the folowing:

* gcc.dg/tree-ssa/modref-4.c: Fix return test.

diff --git a/gcc/testsuite/gcc.dg/tree-ssa/modref-4.c 
b/gcc/testsuite/gcc.dg/tree-ssa/modref-4.c
index 97fe5307a1c..3ac217bafb8 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/modref-4.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/modref-4.c
@@ -15,9 +15,9 @@ void b(char *ptr)
 
 int main()
 {
-  char c[3]={0,1,0};
+  char c[4]={0,1,2,0};
   b(c);
-  return c[0]+c[2];
+  return c[0]+c[3];
 }
 /* Check that both param offsets are determined correctly and the computation
is optimized out.  */


RE: [PATCH][GCC] arm: Fix wrong code generated for mve scatter store with writeback intrinsics with -O2 (PR97271).

2020-10-16 Thread Kyrylo Tkachov via Gcc-patches



> -Original Message-
> From: Srinath Parvathaneni 
> Sent: 07 October 2020 07:14
> To: gcc-patches@gcc.gnu.org
> Cc: Kyrylo Tkachov 
> Subject: [PATCH][GCC] arm: Fix wrong code generated for mve scatter store
> with writeback intrinsics with -O2 (PR97271).
> 
> Hello,
> 
> This patch fixes (PR97271) the wrong code-gen for mve scatter store with
> writeback intrinsics with -O2.
> 
> $cat bug.c
> #include "arm_mve.h"
> void
> foo (uint32x4_t * addr, const int offset, int32x4_t value)
> {
>   vstrwq_scatter_base_wb_s32 (addr, 8, value);
> }
> 
> $ arm-none-eabi-gcc  bug.c -S -O2 -march=armv8.1-m.main+mve -mfloat-
> abi=hard -o -
> Without this patch:
> ...
> foo:
>   vldrw.32q3, [r0]
>   vstrw.u32   q0, [q3, #8]!  ---> (A)
>   vldr.64 d4, .L3
>   vldr.64 d5, .L3+8
>   vldrw.32q3, [r0]
>   vstrw.u32   q2, [q3, #8]!  ---> (B)
>   bx  lr
> ...
> 
> With this patch:
> ...
> foo:
>   vldrw.32q3, [r0]
>   vstrw.u32   q0, [q3, #8]!  --> (C)
>   vstrw.32q3, [r0]
>   bx  lr
> ...
> 
> Without this patch 2 vstrw assembly instructions (A and B) are generated for
> vstrwq_scatter_base_wb_s32
> intrinsic where as fix generates only one vstrw assembly instruction (C).
> 
> Bootstrapped on arm-none-linux-gnueabihf and regression tested on arm-
> none-eabi and found no regressions.
> 
> Ok for master? Ok for GCC-10 branch?

Ok for both.
Thanks,
Kyrill

> 
> Regards,
> Srinath.
> 
> gcc/ChangeLog:
> 
> 2020-10-06  Srinath Parvathaneni  
> 
>   PR target/97291
>   * config/arm/arm-builtins.c (arm_strsbwbs_qualifiers): Modify array.
>   (arm_strsbwbu_qualifiers): Likewise.
>   (arm_strsbwbs_p_qualifiers): Likewise.
>   (arm_strsbwbu_p_qualifiers): Likewise.
>   * config/arm/arm_mve.h (__arm_vstrdq_scatter_base_wb_s64):
> Modify
>   function definition.
>   (__arm_vstrdq_scatter_base_wb_u64): Likewise.
>   (__arm_vstrdq_scatter_base_wb_p_s64): Likewise.
>   (__arm_vstrdq_scatter_base_wb_p_u64): Likewise.
>   (__arm_vstrwq_scatter_base_wb_p_s32): Likewise.
>   (__arm_vstrwq_scatter_base_wb_p_u32): Likewise.
>   (__arm_vstrwq_scatter_base_wb_s32): Likewise.
>   (__arm_vstrwq_scatter_base_wb_u32): Likewise.
>   (__arm_vstrwq_scatter_base_wb_f32): Likewise.
>   (__arm_vstrwq_scatter_base_wb_p_f32): Likewise.
>   * config/arm/arm_mve_builtins.def
> (vstrwq_scatter_base_wb_add_u): Remove
>   expansion for the builtin.
>   (vstrwq_scatter_base_wb_add_s): Likewise.
>   (vstrwq_scatter_base_wb_add_f): Likewise.
>   (vstrdq_scatter_base_wb_add_u): Likewise.
>   (vstrdq_scatter_base_wb_add_s): Likewise.
>   (vstrwq_scatter_base_wb_p_add_u): Likewise.
>   (vstrwq_scatter_base_wb_p_add_s): Likewise.
>   (vstrwq_scatter_base_wb_p_add_f): Likewise.
>   (vstrdq_scatter_base_wb_p_add_u): Likewise.
>   (vstrdq_scatter_base_wb_p_add_s): Likewise.
>   * config/arm/mve.md (mve_vstrwq_scatter_base_wb_v4si):
> Remove
>   expand.
>   (mve_vstrwq_scatter_base_wb_add_v4si): Likewise.
>   (mve_vstrwq_scatter_base_wb_v4si_insn): Rename pattern
> to ...
>   (mve_vstrwq_scatter_base_wb_v4si): This.
>   (mve_vstrwq_scatter_base_wb_p_v4si): Remove expand.
>   (mve_vstrwq_scatter_base_wb_p_add_v4si): Likewise.
>   (mve_vstrwq_scatter_base_wb_p_v4si_insn): Rename pattern
> to ...
>   (mve_vstrwq_scatter_base_wb_p_v4si): This.
>   (mve_vstrwq_scatter_base_wb_fv4sf): Remove expand.
>   (mve_vstrwq_scatter_base_wb_add_fv4sf): Likewise.
>   (mve_vstrwq_scatter_base_wb_fv4sf_insn): Rename pattern to ...
>   (mve_vstrwq_scatter_base_wb_fv4sf): This.
>   (mve_vstrwq_scatter_base_wb_p_fv4sf): Remove expand.
>   (mve_vstrwq_scatter_base_wb_p_add_fv4sf): Likewise.
>   (mve_vstrwq_scatter_base_wb_p_fv4sf_insn): Rename pattern to ...
>   (mve_vstrwq_scatter_base_wb_p_fv4sf): This.
>   (mve_vstrdq_scatter_base_wb_v2di): Remove expand.
>   (mve_vstrdq_scatter_base_wb_add_v2di): Likewise.
>   (mve_vstrdq_scatter_base_wb_v2di_insn): Rename pattern
> to ...
>   (mve_vstrdq_scatter_base_wb_v2di): This.
>   (mve_vstrdq_scatter_base_wb_p_v2di): Remove expand.
>   (mve_vstrdq_scatter_base_wb_p_add_v2di): Likewise.
>   (mve_vstrdq_scatter_base_wb_p_v2di_insn): Rename pattern
> to ...
>   (mve_vstrdq_scatter_base_wb_p_v2di): This.
> 
> gcc/testsuite/ChangeLog:
> 
>   PR target/97291
>   * gcc.target/arm/mve/intrinsics/vstrdq_scatter_base_wb_p_s64.c:
> Modify.
>   * gcc.target/arm/mve/intrinsics/vstrdq_scatter_base_wb_p_u64.c:
>   Likewise.
>   * gcc.target/arm/mve/intrinsics/vstrdq_scatter_base_wb_s64.c:
> Likewise.
>   * gcc.target/arm/mve/intrinsics/vstrdq_scatter_base_wb_u64.c:
> Likewise.
>   * gcc.target/arm/mve/intrinsics/vstrwq_scatter_base_wb_f32.c:
> Likewise.
>   * gcc.target/arm/mve/intrinsics/vstrwq_scatter_base_wb_p_f32.c:
>   

RE: [PATCH][GCC-10 backport] arm: Add +nomve and +nomve.fp options to -mcpu=cortex-m55.

2020-10-16 Thread Kyrylo Tkachov via Gcc-patches



> -Original Message-
> From: Srinath Parvathaneni 
> Sent: 06 October 2020 15:32
> To: gcc-patches@gcc.gnu.org
> Cc: Kyrylo Tkachov 
> Subject: [PATCH][GCC-10 backport] arm: Add +nomve and +nomve.fp
> options to -mcpu=cortex-m55.
> 
> Backport of Joe's patch wit no changes.
> 
> This patch rearranges feature bits for MVE and FP to implement the
> following flags for -mcpu=cortex-m55.
> 
>   - +nomve:equivalent to armv8.1-m.main+fp.dp+dsp.
>   - +nomve.fp: equivalent to armv8.1-m.main+mve+fp.dp (+dsp is implied by
> +mve).
>   - +nofp: equivalent to armv8.1-m.main+mve (+dsp is implied by +mve).
>   - +nodsp:equivalent to armv8.1-m.main+fp.dp.
> 
> Combinations of the above:
> 
>   - +nomve+nofp: equivalent to armv8.1-m.main+dsp.
>   - +nodsp+nofp: equivalent to armv8.1-m.main.
> 
> Due to MVE and FP sharing vfp_base, some new syntax was required in the
> CPU
> description to implement the concept of 'implied bits'. These are non-named
> features added to the ISA late, depending on whether one or more features
> which
> depend on them are present. This means vfp_base can be present when only
> one of
> MVE and FP is removed, but absent when both are removed.
> 
> Ok for GCC-10 branch?

Ok.
Thanks,
Kyrill

> 
> gcc/ChangeLog:
> 
> 2020-07-31  Joe Ramsay  
> 
>   * config/arm/arm-cpus.in:
>   (ALL_FPU_INTERNAL): Remove vfp_base.
>   (VFPv2): Remove vfp_base.
>   (MVE): Remove vfp_base.
>   (vfp_base): Redefine as implied bit dependent on MVE or FP
>   (cortex-m55): Add flags to disable MVE, MVE FP, FP and DSP
> extensions.
>   * config/arm/arm.c (arm_configure_build_target): Add implied bits
> to ISA.
>   * config/arm/parsecpu.awk:
>   (gen_isa): Print implied bits and their dependencies to ISA header.
>   (gen_data): Add parsing for implied feature bits.
> 
> gcc/testsuite/ChangeLog:
> 
>   * gcc.target/arm/cortex-m55-nodsp-flag-hard.c: New test.
>   * gcc.target/arm/cortex-m55-nodsp-flag-softfp.c: New test.
>   * gcc.target/arm/cortex-m55-nodsp-nofp-flag-softfp.c: New test.
>   * gcc.target/arm/cortex-m55-nofp-flag-hard.c: New test.
>   * gcc.target/arm/cortex-m55-nofp-flag-softfp.c: New test.
>   * gcc.target/arm/cortex-m55-nofp-nomve-flag-softfp.c: New test.
>   * gcc.target/arm/cortex-m55-nomve-flag-hard.c: New test.
>   * gcc.target/arm/cortex-m55-nomve-flag-softfp.c: New test.
>   * gcc.target/arm/cortex-m55-nomve.fp-flag-hard.c: New test.
>   * gcc.target/arm/cortex-m55-nomve.fp-flag-softfp.c: New test.
>   * gcc.target/arm/multilib.exp: Add tests for -mcpu=cortex-m55.
> 
> (cherry picked from commit 3e8fb15a8cfd0e62dd474af9f536863392ed7572)
> 
> 
> ### Attachment also inlined for ease of reply
> ###
> 
> 
> diff --git a/gcc/config/arm/arm-cpus.in b/gcc/config/arm/arm-cpus.in
> index
> d609113e969d69505bc2f1b13fab8b1dfd622472..db0b93f6bb74f6ddf42636c
> aa0d9a3db38692982 100644
> --- a/gcc/config/arm/arm-cpus.in
> +++ b/gcc/config/arm/arm-cpus.in
> @@ -135,10 +135,6 @@ define feature armv8_1m_main
>  # Floating point and Neon extensions.
>  # VFPv1 is not supported in GCC.
> 
> -# This feature bit is enabled for all VFP, MVE and
> -# MVE with floating point extensions.
> -define feature vfp_base
> -
>  # Vector floating point v2.
>  define feature vfpv2
> 
> @@ -251,7 +247,7 @@ define fgroup ALL_SIMD
>   ALL_SIMD_INTERNAL ALL_SIMD_EXTERNAL
> 
>  # List of all FPU bits to strip out if -mfpu is used to override the
>  # default.  fp16 is deliberately missing from this list.
> -define fgroup ALL_FPU_INTERNAL   vfp_base vfpv2 vfpv3 vfpv4 fpv5
> fp16conv fp_dbl ALL_SIMD_INTERNAL
> +define fgroup ALL_FPU_INTERNAL   vfpv2 vfpv3 vfpv4 fpv5 fp16conv
> fp_dbl ALL_SIMD_INTERNAL
>  # Similarly, but including fp16 and other extensions that aren't part of
>  # -mfpu support.
>  define fgroup ALL_FPU_EXTERNAL fp16 bf16
> @@ -296,11 +292,11 @@ define fgroup ARMv8r  ARMv8a
>  define fgroup ARMv8_1m_main ARMv8m_main armv8_1m_main
> 
>  # Useful combinations.
> -define fgroup VFPv2  vfp_base vfpv2
> +define fgroup VFPv2  vfpv2
>  define fgroup VFPv3  VFPv2 vfpv3
>  define fgroup VFPv4  VFPv3 vfpv4 fp16conv
>  define fgroup FPv5   VFPv4 fpv5
> -define fgroup MVE  mve vfp_base armv7em
> +define fgroup MVE  mve armv7em
>  define fgroup MVE_FP   MVE FPv5 fp16 mve_float
> 
>  define fgroup FP_DBL fp_dbl
> @@ -310,6 +306,18 @@ define fgroup NEON   FP_D32 neon
>  define fgroup CRYPTO NEON crypto
>  define fgroup DOTPRODNEON dotprod
> 
> +# Implied feature bits.  These are for non-named features shared between
> fgroups.
> +# Shared feature f belonging to fgroups A and B will be erroneously
> removed if:
> +# A and B are enabled by default AND A is disabled by a removal flag.
> +# To ensure that f is retained, we must add such bits to the ISA after
> +# processing the removal flags.  This is implemented by 'implied bits':
> +# define implied  []+
> +# This 

Re: libstdc++: Fix visitor return type diagnostics [PR97499]

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

On 16/10/20 10:26 +0300, Ville Voutilainen via Libstdc++ wrote:

Tested on Linux-PPC64. I haven't tested this with clang yet,
Jonathan, can you help with that? The previous implementation
indeed made an if-constexpr branch invalid for all instantiations
of that branch, this one doesn't - now we have just a dependent static_assert
which is well-formed for correct visitors and ill-formed for incorrect
visitors.


All I checked is that  can now be included using -std=c++17,
but that works with Clang.

OK for trunk, thanks.



[PATCH] c++: Diagnose constexpr delete [] new int; and delete new int[N]; [PR95808]

2020-10-16 Thread Jakub Jelinek via Gcc-patches
Hi!

This patch diagnoses delete [] new int; and delete new int[1]; in constexpr
contexts by remembering
IDENTIFIER_OVL_OP_FLAGS (DECL_NAME (fun)) & OVL_OP_FLAG_VEC
from the operator new and checking it at operator delete time.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2020-10-16  Jakub Jelinek  

PR c++/95808
* cp-tree.h (enum cp_tree_index): Add CPTI_HEAP_VEC_UNINIT_IDENTIFIER
and CPTI_HEAP_VEC_IDENTIFIER.
(heap_vec_uninit_identifier, heap_vec_identifier): Define.
* decl.c (initialize_predefined_identifiers): Initialize those
identifiers.
* constexpr.c (cxx_eval_call_expression): Reject array allocations
deallocated with non-array deallocation or non-array allocations
deallocated with array deallocation.
(non_const_var_error): Handle heap_vec_uninit_identifier and
heap_vec_identifier too.
(cxx_eval_constant_expression): Handle also heap_vec_uninit_identifier
and in that case during initialization replace it with
heap_vec_identifier.
(find_heap_var_refs): Handle heap_vec_uninit_identifier and
heap_vec_identifier too.

* g++.dg/cpp2a/constexpr-new15.C: New test.

--- gcc/cp/cp-tree.h.jj 2020-10-14 22:05:19.274858485 +0200
+++ gcc/cp/cp-tree.h2020-10-15 16:29:12.136899207 +0200
@@ -178,6 +178,8 @@ enum cp_tree_index
 CPTI_HEAP_UNINIT_IDENTIFIER,
 CPTI_HEAP_IDENTIFIER,
 CPTI_HEAP_DELETED_IDENTIFIER,
+CPTI_HEAP_VEC_UNINIT_IDENTIFIER,
+CPTI_HEAP_VEC_IDENTIFIER,
 
 CPTI_LANG_NAME_C,
 CPTI_LANG_NAME_CPLUSPLUS,
@@ -322,6 +324,8 @@ extern GTY(()) tree cp_global_trees[CPTI
 #define heap_uninit_identifier 
cp_global_trees[CPTI_HEAP_UNINIT_IDENTIFIER]
 #define heap_identifier
cp_global_trees[CPTI_HEAP_IDENTIFIER]
 #define heap_deleted_identifier
cp_global_trees[CPTI_HEAP_DELETED_IDENTIFIER]
+#define heap_vec_uninit_identifier 
cp_global_trees[CPTI_HEAP_VEC_UNINIT_IDENTIFIER]
+#define heap_vec_identifier
cp_global_trees[CPTI_HEAP_VEC_IDENTIFIER]
 #define lang_name_ccp_global_trees[CPTI_LANG_NAME_C]
 #define lang_name_cplusplus
cp_global_trees[CPTI_LANG_NAME_CPLUSPLUS]
 
--- gcc/cp/decl.c.jj2020-10-14 22:05:19.293858210 +0200
+++ gcc/cp/decl.c   2020-10-15 16:30:05.690125490 +0200
@@ -4242,6 +4242,8 @@ initialize_predefined_identifiers (void)
 {"heap uninit", _uninit_identifier, cik_normal},
 {"heap ", _identifier, cik_normal},
 {"heap deleted", _deleted_identifier, cik_normal},
+{"heap [] uninit", _vec_uninit_identifier, cik_normal},
+{"heap []", _vec_identifier, cik_normal},
 {NULL, NULL, cik_normal}
   };
 
--- gcc/cp/constexpr.c.jj   2020-10-01 11:16:36.390959542 +0200
+++ gcc/cp/constexpr.c  2020-10-15 17:02:31.036021476 +0200
@@ -2288,7 +2288,11 @@ cxx_eval_call_expression (const constexp
{
  tree type = build_array_type_nelts (char_type_node,
  tree_to_uhwi (arg0));
- tree var = build_decl (loc, VAR_DECL, heap_uninit_identifier,
+ tree var = build_decl (loc, VAR_DECL,
+(IDENTIFIER_OVL_OP_FLAGS (DECL_NAME (fun))
+ & OVL_OP_FLAG_VEC)
+? heap_vec_uninit_identifier
+: heap_uninit_identifier,
 type);
  DECL_ARTIFICIAL (var) = 1;
  TREE_STATIC (var) = 1;
@@ -2306,6 +2310,42 @@ cxx_eval_call_expression (const constexp
  if (DECL_NAME (var) == heap_uninit_identifier
  || DECL_NAME (var) == heap_identifier)
{
+ if (IDENTIFIER_OVL_OP_FLAGS (DECL_NAME (fun))
+ & OVL_OP_FLAG_VEC)
+   {
+ if (!ctx->quiet)
+   {
+ error_at (loc, "array deallocation of object "
+"allocated with non-array "
+"allocation");
+ inform (DECL_SOURCE_LOCATION (var),
+ "allocation performed here");
+   }
+ *non_constant_p = true;
+ return t;
+   }
+ DECL_NAME (var) = heap_deleted_identifier;
+ ctx->global->values.remove (var);
+ ctx->global->heap_dealloc_count++;
+ return void_node;
+   }
+ else if (DECL_NAME (var) == heap_vec_uninit_identifier
+  || DECL_NAME (var) == heap_vec_identifier)
+   {
+ if ((IDENTIFIER_OVL_OP_FLAGS 

[patch] vxworks: refactor VX_ENTER/LEAVE_TLS_DTOR

2020-10-16 Thread Olivier Hainque
Hello,

This is a minor update of the change proposed by
Rasmus at

  https://gcc.gnu.org/pipermail/gcc/2020-May/232632.html

to help builds on vxWorks 5.

This variant refactors the code area a bit based on the
observation that __gthread_enter/leave_tls_dtor_context is
actually only relevant to VxWorks 6 at this stage.

Tested by verifying that our vx 6.9 and 7.2 toolchains
are still buildable and functional after the change.

Olivier

2020-10-15  Rasmus Villemoes  
Olivier Hainque  
  
libgcc/
* config/gthr-vxworks-tls.c (VX_ENTER_TLS_DTOR): Nil
except on VxWorks 6.

diff --git a/libgcc/config/gthr-vxworks-tls.c b/libgcc/config/gthr-vxworks-tls.c
index fac25e305a01..8987e55c35ac 100644
--- a/libgcc/config/gthr-vxworks-tls.c
+++ b/libgcc/config/gthr-vxworks-tls.c
@@ -94,7 +94,9 @@ static int self_owner;
 static volatile int delete_hook_installed;
 
 /* TLS data access internal API.  A straight __thread variable starting with
-   VxWorks 7, a pointer returned by kernel provided routines otherwise.  */
+   VxWorks 7, a pointer returned by kernel provided routines otherwise.  And
+   on VxWorks 6, the kernel expects us to notify entry/exit of regions
+   handling such variables by calls to kernel provided __gthread routines.  */
 
 #if _VXWORKS_MAJOR_GE(7)
 
@@ -103,23 +105,29 @@ static __thread struct tls_data *__gthread_tls_data;
 #define VX_GET_TLS_DATA() __gthread_tls_data
 #define VX_SET_TLS_DATA(x) __gthread_tls_data = (x)
 
-#define VX_ENTER_TLS_DTOR()
-#define VX_LEAVE_TLS_DTOR()
-
 #else
 
 extern void *__gthread_get_tls_data (void);
 extern void __gthread_set_tls_data (void *data);
 
-extern void __gthread_enter_tls_dtor_context (void);
-extern void __gthread_leave_tls_dtor_context (void);
-
 #define VX_GET_TLS_DATA() __gthread_get_tls_data()
 #define VX_SET_TLS_DATA(x) __gthread_set_tls_data(x)
 
+#endif
+
+#ifdef _VXWORKS_MAJOR_EQ(6)
+
+extern void __gthread_enter_tls_dtor_context (void);
+extern void __gthread_leave_tls_dtor_context (void);
+
 #define VX_ENTER_TLS_DTOR() __gthread_enter_tls_dtor_context ()
 #define VX_LEAVE_TLS_DTOR() __gthread_leave_tls_dtor_context ()
 
+#else
+
+#define VX_ENTER_TLS_DTOR()
+#define VX_LEAVE_TLS_DTOR()
+
 #endif
 
 /* This is a global structure which records all of the active keys.


[PATCH] RISC-V: Extend syntax for the multilib-generator

2020-10-16 Thread Kito Cheng
 - Support expansion operator (*) in the multilib config string.

 - Motivation of this patch is reduce the complexity when we deal multilib with
   sub-extension, expand the combinations by hand would be very painful and
   error prone, no one deserve to experience this[1] again!

[1] 
https://github.com/sifive/freedom-tools/blob/f4d7facafb27d16125768c90ff1790c674e4be7a/Makefile#L348

gcc/ChangeLog:

* config/riscv/multilib-generator: Add TODO, import itertools
and functools.reduce.
Handle expantion operator.
(LONG_EXT_PREFIXES): New.
(arch_canonicalize): Update comment and improve python3
debuggability/compatibility.
(add_underline_prefix): New.
(_expand_combination): Ditto.
(unique): Ditto.
(expand_combination): Ditto.
---
 gcc/config/riscv/multilib-generator | 109 ++--
 1 file changed, 102 insertions(+), 7 deletions(-)

diff --git a/gcc/config/riscv/multilib-generator 
b/gcc/config/riscv/multilib-generator
index ade3e6e97725..d31e52bccd61 100755
--- a/gcc/config/riscv/multilib-generator
+++ b/gcc/config/riscv/multilib-generator
@@ -22,14 +22,26 @@
 
 # Each argument to this script is of the form
 #  ---
-# For example,
+# Example 1:
 #  rv32imafd-ilp32d-rv32g-c,v
 # means that, in addition to rv32imafd, these configurations can also use the
 # rv32imafd-ilp32d libraries: rv32imafdc, rv32imafdv, rv32g, rv32gc, rv32gv
+#
+# Example 2:
+#  rv32imafd-ilp32d--c*b
+# means that, in addition to rv32imafd, these configurations can also use the
+# rv32imafd-ilp32d libraries: rv32imafd-ilp32dc, rv32imafd-ilp32db,
+# rv32imafd-ilp32dcb
 
 from __future__ import print_function
 import sys
 import collections
+import itertools
+from functools import reduce
+
+#
+# TODO: Add test for this script.
+#
 
 arches = collections.OrderedDict()
 abis = collections.OrderedDict()
@@ -37,6 +49,7 @@ required = []
 reuse = []
 
 canonical_order = "mafdgqlcbjtpvn"
+LONG_EXT_PREFIXES = ['z', 's', 'h', 'x']
 
 #
 # IMPLIED_EXT(ext) -> implied extension list.
@@ -59,14 +72,13 @@ def arch_canonicalize(arch):
   # TODO: Support extension version.
   new_arch = ""
   if arch[:5] in ['rv32e', 'rv32i', 'rv32g', 'rv64i', 'rv64g']:
-# TODO: We should expand g to imadzifencei once we support newer spec.
+# TODO: We should expand g to imad_zifencei once we support newer spec.
 new_arch = arch[:5].replace("g", "imafd")
   else:
 raise Exception("Unexpected arch: `%s`" % arch[:5])
 
   # Find any Z, S, H or X
-  long_ext_prefixes = ['z', 's', 'h', 'x']
-  long_ext_prefixes_idx = map(lambda x: arch.find(x), long_ext_prefixes)
+  long_ext_prefixes_idx = map(lambda x: arch.find(x), LONG_EXT_PREFIXES)
 
   # Filter out any non-existent index.
   long_ext_prefixes_idx = list(filter(lambda x: x != -1, 
long_ext_prefixes_idx))
@@ -93,7 +105,7 @@ def arch_canonicalize(arch):
   std_exts += list(filter(lambda x:len(x) == 1, long_exts))
 
   # Multi-letter extension must be in lexicographic order.
-  long_exts = sorted(filter(lambda x:len(x) != 1, long_exts))
+  long_exts = list(sorted(filter(lambda x:len(x) != 1, long_exts)))
 
   # Put extensions in canonical order.
   for ext in canonical_order:
@@ -112,6 +124,85 @@ def arch_canonicalize(arch):
 new_arch += "_" + "_".join(long_exts)
   return new_arch
 
+#
+# add underline for each multi-char extensions.
+# e.g. ["a", "zfh"] -> ["a", "_zfh"]
+#
+def add_underline_prefix(ext):
+  for long_ext_prefix in LONG_EXT_PREFIXES:
+if ext.startswith(long_ext_prefix):
+  return "_" + ext
+
+  return ext
+
+#
+# Handle expansion operation.
+#
+# e.g. "a*b" -> [("a",), ("b",), ("a", "b")]
+#  "a"   -> [("a",)]
+#
+def _expand_combination(ext):
+  exts = list(ext.split("*"))
+
+  # No need to expand if there is no `*`.
+  if len(exts) == 1:
+return [(exts[0],)]
+
+  # Add underline to every extension.
+  # e.g.
+  #  _b * zvamo => _b * _zvamo
+  exts = list(map(lambda x: '_' + x, exts))
+
+  # Generate combination!
+  ext_combs = []
+  for comb_len in range(1, len(exts)+1):
+for ext_comb in itertools.combinations(exts, comb_len):
+  ext_combs.append(ext_comb)
+
+  return ext_combs
+
+#
+# Input a list and drop duplicated entry.
+# e.g.
+#   ["a", "b", "ab", "a"] -> ["a", "b", "ab"]
+#
+def unique(x):
+  #
+  # Drop duplicated entry.
+  # Convert list to set and then convert back to list.
+  #
+  # Add sorted to prevent non-deterministic results in different env.
+  #
+  return list(sorted(list(set(x
+
+#
+# Expand EXT string if there is any expansion operator (*).
+# e.g.
+#   "a*b,c" -> ["a", "b", "ab", "c"]
+#
+def expand_combination(ext):
+  ext = list(filter(None, ext.split(',')))
+
+  # Expand combination for EXT, got lots of list.
+  # e.g.
+  #   a * b => [[("a",), ("b",)], [("a", "b")]]
+  ext_combs = list(map(_expand_combination, ext))
+
+  # Then fold to single list.
+  # e.g.
+  #   [[("a",), ("b",)], [("a", "b")]] => [("a",), 

Re: New modref/ipa_modref optimization passes

2020-10-16 Thread Richard Biener
On Fri, 16 Oct 2020, Richard Biener wrote:

> On Fri, 16 Oct 2020, Jan Hubicka wrote:
> 
> > Hi,
> > I am slowly getting finished with the fn spec changes on trunk and then
> > would like to proceed with modref.  Sadly  still get the assumed_type
> > failuere and in addition to that:
> > FAIL: gfortran.dg/finalize_25.f90   -O2  execution test
> > FAIL: gfortran.dg/finalize_25.f90   -O3 -fomit-frame-pointer -funroll-loops 
> > -fpeel-loops -ftracer -finline-functions  execution test
> > FAIL: gfortran.dg/finalize_25.f90   -O3 -g  execution test
> > FAIL: gfortran.dg/finalize_25.f90   -Os  execution test
> > WARNING: gfortran.dg/pdt_14.f03   -O2  execution test program timed out.
> > FAIL: gfortran.dg/pdt_14.f03   -O2  execution test
> > WARNING: gfortran.dg/pdt_14.f03   -O3 -fomit-frame-pointer -funroll-loops 
> > -fpeel-loops -ftracer -finline-functions  execution test
> > program timed out.
> > FAIL: gfortran.dg/pdt_14.f03   -O3 -fomit-frame-pointer -funroll-loops 
> > -fpeel-loops -ftracer -finline-functions  execution test
> > WARNING: gfortran.dg/pdt_14.f03   -O3 -g  execution test program timed out.
> > FAIL: gfortran.dg/pdt_14.f03   -O3 -g  execution test
> > WARNING: gfortran.dg/pdt_14.f03   -Os  execution test program timed out.
> > FAIL: gfortran.dg/pdt_14.f03   -Os  execution test
> > 
> > I wonder if there is any chance to get Fortran FE fixed here?
> 
> OK, I'll try doing a little surgery in the FE today, coming up with
> a little refactoring and a fix along your original one that allows
> for a better one by FE folks.

So I've sent a refactoring patch improving the tree building code.

But now trying to fix the actual issue with the idea to perform
accesses indirectly via a descriptor with dim[] type I see that
the coarray 'token' field is appended to descriptors conditional
on -fcoarray and that this field makes the dim[] array no longer
trailing - which means the offset of the 'token' field depends
on the rank of the array.

The dim[] field is even optional when dim + codimen == 0 and that
case indeed happens (ah, via get_scalar_to_descriptor_type).
So much for re-using this combo ;)

I suppose we can compensate for this by dynamically computing the
offset of the 'token' field but then it's not obvious to me
where the total 'rank' is stored inside the descriptor or how
the 'token' field is accessed for assumed-shape arrays - the
current method by simple field chaining definitely won't work.

Anyway, I'll try to deal with all this by just adjusting the TBAA
type but not the access type leaving that alone.

IMHO the cleanest way would be to swap the CAF token field and
the dim[] field (which is an ABI change for -fcoarray)

Richard.


[PATCH] RISC-V: Add configure option: --with-multilib-config to flexible config multi-lib settings.

2020-10-16 Thread Kito Cheng
 - Able to configure complex multi-lib rule in configure time, without modify
   any in-tree source.

 - I was consider to implmenet this into `--with-multilib-list` option,
   but I am not sure who will using that with riscv*-*-elf*, so I decide to
   using another option name for that.

 - --with-multilib-config will pass arguments to multilib-generator, and
   then using the generated multi-lib config file to build the toolchain.

  e.g. Build riscv gcc, default arch/abi is rv64gc/lp64, and build multilib
   for rv32imafd/ilp32 and rv32i/ilp32; rv32ic/ilp32 will reuse
   rv32i/ilp32.
$ /configure \
   --target=riscv64-elf \
   --with-arch=rv64gc --with-abi=lp64 \
   --with-multilib-config=rv32i-ilp32--c;rv32imafd-ilp32--

gcc/ChangeLog:

* config.gcc (riscv*-*-*): Handle --with-multilib-config.
* configure: Regen.
* configure.ac: Add --with-multilib-config.
* config/riscv/multilib-generator: Exit when parsing arch string error.
* config/riscv/t-withmultilib-config: New.
* doc/install.texi: Document --with-multilib-config.
---
 gcc/config.gcc | 32 ++
 gcc/config/riscv/multilib-generator|  9 +++-
 gcc/config/riscv/t-withmultilib-config |  2 ++
 gcc/configure  | 15 ++--
 gcc/configure.ac   |  5 
 gcc/doc/install.texi   | 30 
 6 files changed, 85 insertions(+), 8 deletions(-)
 create mode 100644 gcc/config/riscv/t-withmultilib-config

diff --git a/gcc/config.gcc b/gcc/config.gcc
index b79c544c9fa4..bfd34db0a4f3 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -2436,11 +2436,13 @@ riscv*-*-elf* | riscv*-*-rtems*)
  tmake_file="${tmake_file} riscv/t-rtems"
  ;;
*)
- case "x${enable_multilib}" in
- xno) ;;
- xyes) tmake_file="${tmake_file} riscv/t-elf-multilib" ;;
- *) echo "Unknown value for enable_multilib"; exit 1
- esac
+ if test "x${with_multilib_config}" == xdefault; then
+ case "x${enable_multilib}" in
+ xno) ;;
+ xyes) tmake_file="${tmake_file} riscv/t-elf-multilib" ;;
+ *) echo "Unknown value for enable_multilib"; exit 1
+ esac
+ fi
esac
tmake_file="${tmake_file} riscv/t-riscv"
gnu_ld=yes
@@ -4575,6 +4577,26 @@ case "${target}" in
exit 1
;;
esac
+   # Handle --with-multilib-config.
+   case "${target}" in
+   riscv*-*-elf*)
+   if test "x${with_multilib_config}" != xdefault; then
+   if ${srcdir}/config/riscv/multilib-generator \
+   `echo ${with_multilib_config} | sed 
's/;/ /g'`\
+   > t-multilib-config;
+   then
+   tmake_file="${tmake_file} 
riscv/t-withmultilib-config"
+   else
+   echo "invalid option for 
--with-multilib-config" 1>&2
+   exit 1
+   fi
+   fi
+   ;;
+   *)
+   echo "--with-multilib-config= is not supported for 
${target}, only supported for riscv*-*-elf*" 1>&2
+   exit 1
+   ;;
+   esac
 
# Handle --with-multilib-list.
if test "x${with_multilib_list}" != xdefault; then
diff --git a/gcc/config/riscv/multilib-generator 
b/gcc/config/riscv/multilib-generator
index f444d0ebc746..9bc3a8fbb1f4 100755
--- a/gcc/config/riscv/multilib-generator
+++ b/gcc/config/riscv/multilib-generator
@@ -103,7 +103,14 @@ def arch_canonicalize(arch):
   return new_arch
 
 for cfg in sys.argv[1:]:
-  (arch, abi, extra, ext) = cfg.split('-')
+  try:
+(arch, abi, extra, ext) = cfg.split('-')
+  except:
+print ("Invalid configure string %s, ---\n"
+   " and  can be empty, "
+   "e.g. rv32imafd-ilp32--" % cfg)
+sys.exit(1)
+
   arch = arch_canonicalize (arch)
   arches[arch] = 1
   abis[abi] = 1
diff --git a/gcc/config/riscv/t-withmultilib-config 
b/gcc/config/riscv/t-withmultilib-config
new file mode 100644
index ..1a35cc0bc655
--- /dev/null
+++ b/gcc/config/riscv/t-withmultilib-config
@@ -0,0 +1,2 @@
+# t-multilib-config will generated in build folder by configure script.
+include t-multilib-config
diff --git a/gcc/configure b/gcc/configure
index abff47d30eb9..eab70192bf46 100755
--- a/gcc/configure
+++ b/gcc/configure
@@ -972,6 +972,7 @@ with_documentation_root_url
 with_changes_root_url
 enable_languages
 with_multilib_list
+with_multilib_config
 with_zstd
 with_zstd_include
 with_zstd_lib
@@ -1811,6 

Re: [RISC-V] Add support for AddressSanitizer on RISC-V GCC

2020-10-16 Thread Martin Liška

On 10/16/20 9:45 AM, Kito Cheng wrote:

I think it would be helpful! thanks!


Hello.

I've just installed the patches to master.

Martin


Re: [PATCH] PR target/96307: Fix KASAN option checking.

2020-10-16 Thread Martin Liška

On 10/16/20 9:41 AM, Kito Cheng wrote:

I think it is still useful for other targets which are not supporting 
libsanitizer yet, so in this patch I also moved related testcases from 
gcc.target to gcc.dg.


All right, I can't approve the patch, but I support it.

Martin


[committed] RISC-V: Handle implied extension in multilib-generator

2020-10-16 Thread Kito Cheng
 - -march has handle implied extension for a while, so I think
   multilib-generator should handle this well too.

 - Currently only add rule for D imply F.

gcc/ChangeLog:

* config/riscv/multilib-generator (IMPLIED_EXT): New.
(arch_canonicalize): Update comment and handle implied extensions.
---
 gcc/config/riscv/multilib-generator | 24 
 1 file changed, 20 insertions(+), 4 deletions(-)

diff --git a/gcc/config/riscv/multilib-generator 
b/gcc/config/riscv/multilib-generator
index 8f4df183db21..f444d0ebc746 100755
--- a/gcc/config/riscv/multilib-generator
+++ b/gcc/config/riscv/multilib-generator
@@ -38,8 +38,14 @@ reuse = []
 
 canonical_order = "mafdgqlcbjtpvn"
 
+#
+# IMPLIED_EXT(ext) -> implied extension list.
+#
+IMPLIED_EXT = {
+  "d" : ["f"],
+}
+
 def arch_canonicalize(arch):
-  # TODO: Support implied extensions, e.g. D implied F in latest spec.
   # TODO: Support extension version.
   new_arch = ""
   if arch[:5] in ['rv32e', 'rv32i', 'rv32g', 'rv64i', 'rv64g']:
@@ -57,14 +63,24 @@ def arch_canonicalize(arch):
   if long_ext_prefixes_idx:
 first_long_ext_idx = min(long_ext_prefixes_idx)
 long_exts = arch[first_long_ext_idx:].split("_")
-std_exts = arch[5:first_long_ext_idx]
+std_exts = list(arch[5:first_long_ext_idx])
   else:
 long_exts = []
-std_exts = arch[5:]
+std_exts = list(arch[5:])
+
+  #
+  # Handle implied extensions.
+  #
+  for ext in std_exts + long_exts:
+if ext in IMPLIED_EXT:
+  implied_exts = IMPLIED_EXT[ext]
+  for implied_ext in implied_exts:
+if implied_ext not in std_exts + long_exts:
+  long_exts.append(implied_ext)
 
   # Single letter extension might appear in the long_exts list,
   # becasue we just append extensions list to the arch string.
-  std_exts += "".join(filter(lambda x:len(x) == 1, long_exts))
+  std_exts += list(filter(lambda x:len(x) == 1, long_exts))
 
   # Multi-letter extension must be in lexicographic order.
   long_exts = sorted(filter(lambda x:len(x) != 1, long_exts))
-- 
2.28.0



Re: GCC 9 backports

2020-10-16 Thread Martin Liška

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

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

There are 2 more I've just tested.

Martin


and one more.

Martin


Adding one more.

Martin
>From afcdd7b8ff51a7df885dc3fdf38be566a4c1fdbf Mon Sep 17 00:00:00 2001
From: Martin Liska 
Date: Thu, 15 Oct 2020 14:57:31 +0200
Subject: [PATCH] IPA: compare VRP types.

gcc/ChangeLog:

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

gcc/testsuite/ChangeLog:

	PR ipa/97404
	* gcc.c-torture/execute/pr97404.c: New test.

(cherry picked from commit a86623902767122c71c7229150a8b8a79cbb3673)
---
 gcc/ipa-prop.c|  3 +-
 gcc/testsuite/gcc.c-torture/execute/pr97404.c | 28 +++
 2 files changed, 30 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gcc.c-torture/execute/pr97404.c

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



Re: GCC 10 backports

2020-10-16 Thread Martin Liška

On 10/7/20 2:03 PM, Martin Liška wrote:

On 10/1/20 9:18 PM, Martin Liška wrote:

I'm going to install the following 3 tested backports.

Martin


One more patch that I've tested.

Martin


Adding one more.

Martin
>From afcdd7b8ff51a7df885dc3fdf38be566a4c1fdbf Mon Sep 17 00:00:00 2001
From: Martin Liska 
Date: Thu, 15 Oct 2020 14:57:31 +0200
Subject: [PATCH] IPA: compare VRP types.

gcc/ChangeLog:

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

gcc/testsuite/ChangeLog:

	PR ipa/97404
	* gcc.c-torture/execute/pr97404.c: New test.

(cherry picked from commit a86623902767122c71c7229150a8b8a79cbb3673)
---
 gcc/ipa-prop.c|  3 +-
 gcc/testsuite/gcc.c-torture/execute/pr97404.c | 28 +++
 2 files changed, 30 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gcc.c-torture/execute/pr97404.c

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



[PATCH] Refactor array descriptor field access

2020-10-16 Thread Richard Biener
This refactors the array descriptor component access tree building
to commonize code into new helpers to provide a single place to
fix correctness issues with respect to TBAA.

The only interesting part is the gfc_conv_descriptor_data_get change
to drop broken special-casing of REFERENCE_TYPE desc which, when hit,
would build invalid GENERIC trees, missing an INDIRECT_REF before
subsetting the descriptor with a COMPONENT_REF.

Tested on x86_64-unknown-linux-gnu, full bootstrap / test running.

OK for trunk?

Thanks,
Richard.

2020-10-16  Richard Biener  

gcc/fortran/ChangeLog:
* trans-array.c (gfc_get_descriptor_field): New helper.
(gfc_conv_descriptor_data_get): Use it - drop strange
REFERENCE_TYPE handling and make sure we don't trigger it.
(gfc_conv_descriptor_offset): Use gfc_get_descriptor_field.
(gfc_conv_descriptor_dtype): Likewise.
(gfc_conv_descriptor_span): Likewise.
(gfc_get_descriptor_dimension): Likewise.
(gfc_conv_descriptor_token): Likewise.
(gfc_conv_descriptor_subfield): New helper.
(gfc_conv_descriptor_stride): Use it.
(gfc_conv_descriptor_lbound): Likewise.
(gfc_conv_descriptor_ubound): Likewise.
---
 gcc/fortran/trans-array.c | 158 +-
 1 file changed, 52 insertions(+), 106 deletions(-)

diff --git a/gcc/fortran/trans-array.c b/gcc/fortran/trans-array.c
index 998d4d4ed9b..f30a2f75701 100644
--- a/gcc/fortran/trans-array.c
+++ b/gcc/fortran/trans-array.c
@@ -133,28 +133,31 @@ gfc_array_dataptr_type (tree desc)
 #define LBOUND_SUBFIELD 1
 #define UBOUND_SUBFIELD 2
 
+static tree
+gfc_get_descriptor_field (tree desc, unsigned field_idx)
+{
+  tree type = TREE_TYPE (desc);
+  gcc_assert (GFC_DESCRIPTOR_TYPE_P (type));
+
+  tree field = gfc_advance_chain (TYPE_FIELDS (type), field_idx);
+  gcc_assert (field != NULL_TREE);
+
+  return fold_build3_loc (input_location, COMPONENT_REF, TREE_TYPE (field),
+ desc, field, NULL_TREE);
+}
+
 /* This provides READ-ONLY access to the data field.  The field itself
doesn't have the proper type.  */
 
 tree
 gfc_conv_descriptor_data_get (tree desc)
 {
-  tree field, type, t;
-
-  type = TREE_TYPE (desc);
+  tree type = TREE_TYPE (desc);
   if (TREE_CODE (type) == REFERENCE_TYPE)
-type = TREE_TYPE (type);
-
-  gcc_assert (GFC_DESCRIPTOR_TYPE_P (type));
-
-  field = TYPE_FIELDS (type);
-  gcc_assert (DATA_FIELD == 0);
-
-  t = fold_build3_loc (input_location, COMPONENT_REF, TREE_TYPE (field), desc,
-  field, NULL_TREE);
-  t = fold_convert (GFC_TYPE_ARRAY_DATAPTR_TYPE (type), t);
+gcc_unreachable ();
 
-  return t;
+  tree field = gfc_get_descriptor_field (desc, DATA_FIELD);
+  return fold_convert (GFC_TYPE_ARRAY_DATAPTR_TYPE (type), field);
 }
 
 /* This provides WRITE access to the data field.
@@ -204,17 +207,9 @@ gfc_conv_descriptor_data_addr (tree desc)
 static tree
 gfc_conv_descriptor_offset (tree desc)
 {
-  tree type;
-  tree field;
-
-  type = TREE_TYPE (desc);
-  gcc_assert (GFC_DESCRIPTOR_TYPE_P (type));
-
-  field = gfc_advance_chain (TYPE_FIELDS (type), OFFSET_FIELD);
-  gcc_assert (field != NULL_TREE && TREE_TYPE (field) == gfc_array_index_type);
-
-  return fold_build3_loc (input_location, COMPONENT_REF, TREE_TYPE (field),
- desc, field, NULL_TREE);
+  tree field = gfc_get_descriptor_field (desc, OFFSET_FIELD);
+  gcc_assert (TREE_TYPE (field) == gfc_array_index_type);
+  return field;
 }
 
 tree
@@ -235,34 +230,17 @@ gfc_conv_descriptor_offset_set (stmtblock_t *block, tree 
desc,
 tree
 gfc_conv_descriptor_dtype (tree desc)
 {
-  tree field;
-  tree type;
-
-  type = TREE_TYPE (desc);
-  gcc_assert (GFC_DESCRIPTOR_TYPE_P (type));
-
-  field = gfc_advance_chain (TYPE_FIELDS (type), DTYPE_FIELD);
-  gcc_assert (field != NULL_TREE
- && TREE_TYPE (field) == get_dtype_type_node ());
-
-  return fold_build3_loc (input_location, COMPONENT_REF, TREE_TYPE (field),
- desc, field, NULL_TREE);
+  tree field = gfc_get_descriptor_field (desc, DTYPE_FIELD);
+  gcc_assert (TREE_TYPE (field) == get_dtype_type_node ());
+  return field;
 }
 
 static tree
 gfc_conv_descriptor_span (tree desc)
 {
-  tree type;
-  tree field;
-
-  type = TREE_TYPE (desc);
-  gcc_assert (GFC_DESCRIPTOR_TYPE_P (type));
-
-  field = gfc_advance_chain (TYPE_FIELDS (type), SPAN_FIELD);
-  gcc_assert (field != NULL_TREE && TREE_TYPE (field) == gfc_array_index_type);
-
-  return fold_build3_loc (input_location, COMPONENT_REF, TREE_TYPE (field),
- desc, field, NULL_TREE);
+  tree field = gfc_get_descriptor_field (desc, SPAN_FIELD);
+  gcc_assert (TREE_TYPE (field) == gfc_array_index_type);
+  return field;
 }
 
 tree
@@ -328,22 +306,13 @@ gfc_conv_descriptor_attribute (tree desc)
  dtype, tmp, NULL_TREE);
 }
 
-
 tree
 gfc_get_descriptor_dimension (tree desc)
 {
-  tree type, field;
-
-  type = 

Re: [PATCH] ipa-inline: Improve growth accumulation for recursive calls

2020-10-16 Thread Xionghu Luo via Gcc-patches



On 2020/9/12 01:36, Tamar Christina wrote:
> Hi Martin,
> 
>>
>> can you please confirm that the difference between these two is all due to
>> the last option -fno-inline-functions-called-once ?  Is LTo necessary?  
>> I.e., can
>> you run the benchmark also built with the branch compiler and -mcpu=native
>> -Ofast -fomit-frame-pointer -fno-inline-functions-called-once ?
>>
> 
> Done, see below.
> 
>>> +--+--
>> +--+--+--+
>>> | Branch   | -mcpu=native -Ofast -fomit-frame-pointer -flto
>> | -24% |  |  |
>>> +--+--
>> +--+--+--+
>>> | Branch   | -mcpu=native -Ofast -fomit-frame-pointer
>> | -26% |  |  |
>>> +--+--
>> +--+--+--+
>>
>>>
>>> (Hopefully the table shows up correct)
>>
>> it does show OK for me, thanks.
>>
>>>
>>> It looks like your patch definitely does improve the basic cases. So
>>> there's not much difference between lto and non-lto anymore and it's
>> much Better than GCC 10. However it still contains the regression introduced
>> by Honza's changes.
>>
>> I assume these are rates, not times, so negative means bad.  But do I
>> understand it correctly that you're comparing against GCC 10 with the two
>> parameters set to rather special values?  Because your table seems to
>> indicate that even for you, the branch is faster than GCC 10 with just -
>> mcpu=native -Ofast -fomit-frame-pointer.
> 
> Yes these are indeed rates, and indeed I am comparing against the same options
> we used to get the fastest rates on before which is the two parameters and
> the inline flag.
> 
>>
>> So is the problem that the best obtainable run-time, even with obscure
>> options, from the branch is slower than the best obtainable run-time from
>> GCC 10?
>>
> 
> Yeah that's the problem, when we compare the two we're still behind.
> 
> I've done the additional two runs
> 
> +--+--+--+
> | Compiler | Flags
>   
>   | diff GCC 10  |
> +--+--+--+
> | GCC 10   | -mcpu=native -Ofast -fomit-frame-pointer -flto --param 
> ipa-cp-eval-threshold=1 --param   ipa-cp-unit-growth=80 
> -fno-inline-functions-called-once |  |
> +--+--+--+
> | GCC 10   | -mcpu=native -Ofast -fomit-frame-pointer 
>   
>   | -44% |
> +--+--+--+
> | GCC 10   | -mcpu=native -Ofast -fomit-frame-pointer -flto   
>   
>   | -36% |
> +--+--+--+
> | GCC 11   | -mcpu=native -Ofast -fomit-frame-pointer -flto --param 
> ipa-cp-eval-threshold=1 --param   ipa-cp-unit-growth=80 
> -fno-inline-functions-called-once | -12% |
> +--+--+--+
> | Branch   | -mcpu=native -Ofast -fomit-frame-pointer -flto --param 
> ipa-cp-eval-threshold=1 --param   ipa-cp-unit-growth=80   
> | -22% |
> +--+--+--+
> | Branch   | -mcpu=native -Ofast -fomit-frame-pointer -flto --param 
> ipa-cp-eval-threshold=1 --param   ipa-cp-unit-growth=80 
> -fno-inline-functions-called-once | -12% |
> 

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

2020-10-16 Thread Christophe Lyon via Gcc-patches
On Thu, 15 Oct 2020 at 20:10, Andrea Corallo  wrote:
>
> Hi Christophe,
>
> I've spotted two very minors.
>
> Christophe Lyon via Gcc-patches  writes:
>
> [...]
>
> > +/* For vceqq_p64, we rely on vceq_p64 for each of the two elements.  */
> > +__extension__ extern __inline uint64x2_t
> > +__attribute__  ((__always_inline__, __gnu_inline__, __artificial__))
> > +vceqq_p64 (poly64x2_t __a, poly64x2_t __b)
> > +{
> > +  poly64_t __high_a = vget_high_p64 (__a);
> > +  poly64_t __high_b = vget_high_p64 (__b);
> > +  uint64x1_t __high = vceq_p64(__high_a, __high_b);
> ^^^
>space

Thanks for catching this, I'll fix it before committing if the rest is approved.

Christophe

> > +
> > +  poly64_t __low_a = vget_low_p64 (__a);
> > +  poly64_t __low_b = vget_low_p64 (__b);
> > +  uint64x1_t __low = vceq_p64(__low_a, __low_b);
>
> Same
>
> > +  return vcombine_u64 (__low, __high);
> > +}
> > +
> > +__extension__ extern __inline uint64x2_t
> > +__attribute__  ((__always_inline__, __gnu_inline__, __artificial__))
> > +vceqzq_p64 (poly64x2_t __a)
> > +{
> > +  poly64x2_t __b = vreinterpretq_p64_u32 (vdupq_n_u32 (0));
> > +  return vceqq_p64 (__a, __b);
> > +}
>
> Thanks
>
>   Andrea


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

2020-10-16 Thread Christophe Lyon via Gcc-patches
On Thu, 15 Oct 2020 at 20:10, Andrea Corallo  wrote:
>
> Hi Christophe,
>
> I've spotted two very minors.
>
> Christophe Lyon via Gcc-patches  writes:
>
> [...]
>
> > +/* For vceqq_p64, we rely on vceq_p64 for each of the two elements.  */
> > +__extension__ extern __inline uint64x2_t
> > +__attribute__  ((__always_inline__, __gnu_inline__, __artificial__))
> > +vceqq_p64 (poly64x2_t __a, poly64x2_t __b)
> > +{
> > +  poly64_t __high_a = vget_high_p64 (__a);
> > +  poly64_t __high_b = vget_high_p64 (__b);
> > +  uint64x1_t __high = vceq_p64(__high_a, __high_b);
> ^^^
>space
> > +
> > +  poly64_t __low_a = vget_low_p64 (__a);
> > +  poly64_t __low_b = vget_low_p64 (__b);
> > +  uint64x1_t __low = vceq_p64(__low_a, __low_b);
>
> Same
>
> > +  return vcombine_u64 (__low, __high);
> > +}
> > +
> > +__extension__ extern __inline uint64x2_t
> > +__attribute__  ((__always_inline__, __gnu_inline__, __artificial__))
> > +vceqzq_p64 (poly64x2_t __a)
> > +{
> > +  poly64x2_t __b = vreinterpretq_p64_u32 (vdupq_n_u32 (0));
> > +  return vceqq_p64 (__a, __b);
> > +}
>
> Thanks
>
>   Andrea


[PATCH] Refactor vect_get_and_check_slp_defs some more

2020-10-16 Thread Richard Biener
This refactors vect_get_and_check_slp_defs so that the ops and def_stmts
arrays are filled for all stmts and operands even when we signal failure.
This allows later changes for BB vectorization SLP discovery heuristics.

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

2020-10-16  Richard Biener  

* tree-vect-slp.c (vect_get_and_check_slp_defs): First analyze
all operands and fill in the def_stmts and ops entries.
(vect_def_types_match): New helper.
---
 gcc/tree-vect-slp.c | 141 ++--
 1 file changed, 82 insertions(+), 59 deletions(-)

diff --git a/gcc/tree-vect-slp.c b/gcc/tree-vect-slp.c
index 8037b27cddd..cfb79e2651f 100644
--- a/gcc/tree-vect-slp.c
+++ b/gcc/tree-vect-slp.c
@@ -356,6 +356,16 @@ can_duplicate_and_interleave_p (vec_info *vinfo, unsigned 
int count,
 }
 }
 
+/* Return true if DTA and DTB match.  */
+
+static bool
+vect_def_types_match (enum vect_def_type dta, enum vect_def_type dtb)
+{
+  return (dta == dtb
+ || ((dta == vect_external_def || dta == vect_constant_def)
+ && (dtb == vect_external_def || dtb == vect_constant_def)));
+}
+
 /* Get the defs for the rhs of STMT (collect them in OPRNDS_INFO), check that
they are of a valid type and that they match the defs of the first stmt of
the SLP group (stored in OPRNDS_INFO).  This function tries to match stmts
@@ -421,9 +431,9 @@ vect_get_and_check_slp_defs (vec_info *vinfo, unsigned char 
swap,
 
   bool swapped = (swap != 0);
   gcc_assert (!swapped || first_op_cond);
+  enum vect_def_type *dts = XALLOCAVEC (enum vect_def_type, number_of_oprnds);
   for (i = 0; i < number_of_oprnds; i++)
 {
-again:
   if (first_op_cond)
{
  /* Map indicating how operands of cond_expr should be swapped.  */
@@ -444,7 +454,7 @@ again:
   oprnd_info = (*oprnds_info)[i];
 
   stmt_vec_info def_stmt_info;
-  if (!vect_is_simple_use (oprnd, vinfo, , _stmt_info))
+  if (!vect_is_simple_use (oprnd, vinfo, [i], _stmt_info))
{
  if (dump_enabled_p ())
dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
@@ -457,9 +467,13 @@ again:
   if (def_stmt_info && is_pattern_stmt_p (def_stmt_info))
oprnd_info->any_pattern = true;
 
-  tree type = TREE_TYPE (oprnd);
+  oprnd_info->def_stmts.quick_push (def_stmt_info);
+  oprnd_info->ops.quick_push (oprnd);
+
   if (first)
{
+ tree type = TREE_TYPE (oprnd);
+ dt = dts[i];
  if ((dt == vect_constant_def
   || dt == vect_external_def)
  && !GET_MODE_SIZE (vinfo->vector_mode).is_constant ()
@@ -480,14 +494,48 @@ again:
  && REDUC_GROUP_FIRST_ELEMENT (stmt_info)
  && (int)i == STMT_VINFO_REDUC_IDX (stmt_info)
  && def_stmt_info)
-   dt = vect_reduction_def;
+   dts[i] = dt = vect_reduction_def;
+
+ /* Check the types of the definition.  */
+ switch (dt)
+   {
+   case vect_external_def:
+   case vect_constant_def:
+   case vect_internal_def:
+   case vect_reduction_def:
+   case vect_induction_def:
+ break;
+
+   default:
+ /* FORNOW: Not supported.  */
+ if (dump_enabled_p ())
+   dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
+"Build SLP failed: illegal type of def %T\n",
+oprnd);
+ return -1;
+   }
+
  oprnd_info->first_dt = dt;
  oprnd_info->first_op_type = type;
}
-  else
-   {
+}
+  if (first)
+return 0;
+
+  /* Now match the operand definition types to that of the first stmt.  */
+  for (i = 0; i < number_of_oprnds;)
+{
+  oprnd_info = (*oprnds_info)[i];
+  dt = dts[i];
+  stmt_vec_info def_stmt_info = oprnd_info->def_stmts[stmt_num];
+  oprnd = oprnd_info->ops[stmt_num];
+  tree type = TREE_TYPE (oprnd);
+
  if (!types_compatible_p (oprnd_info->first_op_type, type))
{
+ gcc_assert ((i != commutative_op
+  && (commutative_op == -1U
+  || i != commutative_op + 1)));
  if (dump_enabled_p ())
dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
 "Build SLP failed: different operand types\n");
@@ -499,18 +547,14 @@ again:
 types for reduction chains: the first stmt must be a
 vect_reduction_def (a phi node), and the rest
 end in the reduction chain.  */
- if ((oprnd_info->first_dt != dt
+ if ((!vect_def_types_match (oprnd_info->first_dt, dt)
   && !(oprnd_info->first_dt == vect_reduction_def
&& !STMT_VINFO_DATA_REF (stmt_info)
&& REDUC_GROUP_FIRST_ELEMENT (stmt_info)
&& 

Re: New modref/ipa_modref optimization passes

2020-10-16 Thread Richard Biener
On Fri, 16 Oct 2020, Jan Hubicka wrote:

> Hi,
> I am slowly getting finished with the fn spec changes on trunk and then
> would like to proceed with modref.  Sadly  still get the assumed_type
> failuere and in addition to that:
> FAIL: gfortran.dg/finalize_25.f90   -O2  execution test
> FAIL: gfortran.dg/finalize_25.f90   -O3 -fomit-frame-pointer -funroll-loops 
> -fpeel-loops -ftracer -finline-functions  execution test
> FAIL: gfortran.dg/finalize_25.f90   -O3 -g  execution test
> FAIL: gfortran.dg/finalize_25.f90   -Os  execution test
> WARNING: gfortran.dg/pdt_14.f03   -O2  execution test program timed out.
> FAIL: gfortran.dg/pdt_14.f03   -O2  execution test
> WARNING: gfortran.dg/pdt_14.f03   -O3 -fomit-frame-pointer -funroll-loops 
> -fpeel-loops -ftracer -finline-functions  execution test
> program timed out.
> FAIL: gfortran.dg/pdt_14.f03   -O3 -fomit-frame-pointer -funroll-loops 
> -fpeel-loops -ftracer -finline-functions  execution test
> WARNING: gfortran.dg/pdt_14.f03   -O3 -g  execution test program timed out.
> FAIL: gfortran.dg/pdt_14.f03   -O3 -g  execution test
> WARNING: gfortran.dg/pdt_14.f03   -Os  execution test program timed out.
> FAIL: gfortran.dg/pdt_14.f03   -Os  execution test
> 
> I wonder if there is any chance to get Fortran FE fixed here?

OK, I'll try doing a little surgery in the FE today, coming up with
a little refactoring and a fix along your original one that allows
for a better one by FE folks.

Richard.


Re: New modref/ipa_modref optimization passes

2020-10-16 Thread Jan Hubicka
Hi,
I am slowly getting finished with the fn spec changes on trunk and then
would like to proceed with modref.  Sadly  still get the assumed_type
failuere and in addition to that:
FAIL: gfortran.dg/finalize_25.f90   -O2  execution test
FAIL: gfortran.dg/finalize_25.f90   -O3 -fomit-frame-pointer -funroll-loops 
-fpeel-loops -ftracer -finline-functions  execution test
FAIL: gfortran.dg/finalize_25.f90   -O3 -g  execution test
FAIL: gfortran.dg/finalize_25.f90   -Os  execution test
WARNING: gfortran.dg/pdt_14.f03   -O2  execution test program timed out.
FAIL: gfortran.dg/pdt_14.f03   -O2  execution test
WARNING: gfortran.dg/pdt_14.f03   -O3 -fomit-frame-pointer -funroll-loops 
-fpeel-loops -ftracer -finline-functions  execution test
program timed out.
FAIL: gfortran.dg/pdt_14.f03   -O3 -fomit-frame-pointer -funroll-loops 
-fpeel-loops -ftracer -finline-functions  execution test
WARNING: gfortran.dg/pdt_14.f03   -O3 -g  execution test program timed out.
FAIL: gfortran.dg/pdt_14.f03   -O3 -g  execution test
WARNING: gfortran.dg/pdt_14.f03   -Os  execution test program timed out.
FAIL: gfortran.dg/pdt_14.f03   -Os  execution test

I wonder if there is any chance to get Fortran FE fixed here?

Honza


Re: [RISC-V] Add support for AddressSanitizer on RISC-V GCC

2020-10-16 Thread Kito Cheng via Gcc-patches
Hi Martin:

> I can do it earlier if it helps for the integration and testing purpose?

I think it would be helpful! thanks!

On Fri, Oct 16, 2020 at 3:33 PM Martin Liška  wrote:
>
> On 8/19/20 11:25 AM, Kito Cheng via Gcc-patches wrote:
> > Could you update that for RV32, and this patch will be pending until
> > LLVM accepts the libsanitizer part.
>
> Hello.
>
> I've noticed that the libsanitizer part was accepted to LLVM. I'm planning to 
> do
> a merge upstream (for libsanitizer) and was planning to do so in 3 weeks.
>
> I can do it earlier if it helps for the integration and testing purpose?
>
> Thoughts?
> Thanks,
> Martin


Re: [PATCH] PR target/96307: Fix KASAN option checking.

2020-10-16 Thread Kito Cheng
Hi Martin:

I think it is still useful for other targets which are not supporting
libsanitizer yet, so in this patch I also moved related testcases from
gcc.target to gcc.dg.

On Fri, Oct 16, 2020 at 3:34 PM Martin Liška  wrote:

> Hello.
>
> I'm expecting a support for libsanitizer for RISC-V happening soon.
> Having that, will we still need this patch?
>
> Thanks,
> Martin
>


[Ada] Implement expansion of CUDA_Execute pragma

2020-10-16 Thread Pierre-Marie de Rodat
This commit implements expansion of the CUDA_Execute pragma.
CUDA_Execute must result in multiple calls to the runtime API: calls to
the hidden functions CUDA.Push_Call_Configuration and
CUDA.Pop_Call_Configuration but also to CUDA.Launch_Kernel. Calling
these functions requires putting arguments of CUDA_Execute in specific
data structures and thus requires a declare block to hold these
temporary datastructures.

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

gcc/ada/

* elists.ads (New_Elmt_List): New functions.
* elists.adb (New_Elmt_List): New functions.
* exp_prag.adb: Add dependency on Elists.
(Expand_Pragma_CUDA_Execute): New function.
(Expand_N_Pragma): Add call to Expand_Pragma_CUDA_Execute.
* rtsfind.ads: Add CUDA.Internal, CUDA.Runtime, System.C
packages and RE_Push_Call_Configuration,
RE_Pop_Call_Configuration, RE_Launch_Kernel, RO_IC_Unsigned,
RO_IC_Unsigned_Long_Long entities.
* rtsfind.adb: Extend Interfaces_Descendant to include
Interfaces_C.diff --git a/gcc/ada/elists.adb b/gcc/ada/elists.adb
--- a/gcc/ada/elists.adb
+++ b/gcc/ada/elists.adb
@@ -373,6 +373,64 @@ package body Elists is
   return Elists.Last;
end New_Elmt_List;
 
+   ---
+   -- New_Elmt_List --
+   ---
+
+   function New_Elmt_List (Elmt1 : Node_Or_Entity_Id)
+ return Elist_Id
+   is
+  L : constant Elist_Id := New_Elmt_List;
+   begin
+  Append_Elmt (Elmt1, L);
+  return L;
+   end New_Elmt_List;
+
+   ---
+   -- New_Elmt_List --
+   ---
+
+   function New_Elmt_List
+ (Elmt1 : Node_Or_Entity_Id;
+  Elmt2 : Node_Or_Entity_Id) return Elist_Id
+   is
+  L : constant Elist_Id := New_Elmt_List (Elmt1);
+   begin
+  Append_Elmt (Elmt2, L);
+  return L;
+   end New_Elmt_List;
+
+   ---
+   -- New_Elmt_List --
+   ---
+
+   function New_Elmt_List
+ (Elmt1 : Node_Or_Entity_Id;
+  Elmt2 : Node_Or_Entity_Id;
+  Elmt3 : Node_Or_Entity_Id) return Elist_Id
+   is
+  L : constant Elist_Id := New_Elmt_List (Elmt1, Elmt2);
+   begin
+  Append_Elmt (Elmt3, L);
+  return L;
+   end New_Elmt_List;
+
+   ---
+   -- New_Elmt_List --
+   ---
+
+   function New_Elmt_List
+ (Elmt1 : Node_Or_Entity_Id;
+  Elmt2 : Node_Or_Entity_Id;
+  Elmt3 : Node_Or_Entity_Id;
+  Elmt4 : Node_Or_Entity_Id) return Elist_Id
+   is
+  L : constant Elist_Id := New_Elmt_List (Elmt1, Elmt2, Elmt3);
+   begin
+  Append_Elmt (Elmt4, L);
+  return L;
+   end New_Elmt_List;
+
---
-- Next_Elmt --
---


diff --git a/gcc/ada/elists.ads b/gcc/ada/elists.ads
--- a/gcc/ada/elists.ads
+++ b/gcc/ada/elists.ads
@@ -90,6 +90,21 @@ package Elists is
--  a field in some other node which points to an element list where the
--  list is then subsequently filled in using Append calls.
 
+   function New_Elmt_List (Elmt1 : Node_Or_Entity_Id) return Elist_Id;
+   function New_Elmt_List
+ (Elmt1 : Node_Or_Entity_Id;
+  Elmt2 : Node_Or_Entity_Id) return Elist_Id;
+   function New_Elmt_List
+ (Elmt1 : Node_Or_Entity_Id;
+  Elmt2 : Node_Or_Entity_Id;
+  Elmt3 : Node_Or_Entity_Id) return Elist_Id;
+   function New_Elmt_List
+ (Elmt1 : Node_Or_Entity_Id;
+  Elmt2 : Node_Or_Entity_Id;
+  Elmt3 : Node_Or_Entity_Id;
+  Elmt4 : Node_Or_Entity_Id) return Elist_Id;
+   --  Create a new element list containing the given arguments.
+
function First_Elmt (List : Elist_Id) return Elmt_Id;
pragma Inline (First_Elmt);
--  Obtains the first element of the given element list or, if the list has


diff --git a/gcc/ada/exp_prag.adb b/gcc/ada/exp_prag.adb
--- a/gcc/ada/exp_prag.adb
+++ b/gcc/ada/exp_prag.adb
@@ -28,6 +28,7 @@ with Casing;   use Casing;
 with Checks;   use Checks;
 with Debug;use Debug;
 with Einfo;use Einfo;
+with Elists;   use Elists;
 with Errout;   use Errout;
 with Exp_Ch11; use Exp_Ch11;
 with Exp_Util; use Exp_Util;
@@ -67,6 +68,7 @@ package body Exp_Prag is
procedure Expand_Pragma_Abort_Defer (N : Node_Id);
procedure Expand_Pragma_Check   (N : Node_Id);
procedure Expand_Pragma_Common_Object   (N : Node_Id);
+   procedure Expand_Pragma_CUDA_Execute(N : Node_Id);
procedure Expand_Pragma_Import_Or_Interface (N : Node_Id);
procedure Expand_Pragma_Inspection_Point(N : Node_Id);
procedure Expand_Pragma_Interrupt_Priority  (N : Node_Id);
@@ -156,6 +158,9 @@ package body Exp_Prag is
  when Pragma_Common_Object =>
 Expand_Pragma_Common_Object (N);
 
+ when Pragma_CUDA_Execute =>
+Expand_Pragma_CUDA_Execute (N);
+
  when Pragma_Import =>
 Expand_Pragma_Import_Or_Interface (N);
 
@@ -614,6 +619,474 @@ package body Exp_Prag is
   

[Ada] Preelaborate rules not fully enforced

2020-10-16 Thread Pierre-Marie de Rodat
In particular RM10.2.1(8) states:

5 An elaborable construct is preelaborable unless its elaboration
performs any of the following actions:

...

8 The evaluation of a primary that is a name of an object, unless
the name is a static expression, or statically denotes a
discriminant of an enclosing type.

which isn't enforced in the case of an object referenced in a range, as
in:

   S : String (1 .. X);

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

gcc/ada/

* sem_cat.adb (Is_Primary): Handle N_Range properly.diff --git a/gcc/ada/sem_cat.adb b/gcc/ada/sem_cat.adb
--- a/gcc/ada/sem_cat.adb
+++ b/gcc/ada/sem_cat.adb
@@ -2121,6 +2121,7 @@ package body Sem_Cat is
| N_Index_Or_Discriminant_Constraint
| N_Membership_Test
| N_Op
+   | N_Range
 =>
return True;
 




[Ada] Clean up in system.ads dependencies during compiler build

2020-10-16 Thread Pierre-Marie de Rodat
Having system.ads in libgnat can cause various kinds of inconsistencies,
so we move it to gcc-interface.

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

gcc/ada/

* gcc-interface/Make-lang.in: Update dependencies on system.ads,
add gnatbind switch -t to avoid timestamp inconsistencies during
build.
* libgnat/system.ads: Move...
* gcc-interface/system.ads: ... here.diff --git a/gcc/ada/gcc-interface/Make-lang.in b/gcc/ada/gcc-interface/Make-lang.in
--- a/gcc/ada/gcc-interface/Make-lang.in
+++ b/gcc/ada/gcc-interface/Make-lang.in
@@ -68,7 +68,7 @@ ALL_ADAFLAGS = \
   $(CFLAGS) $(ADA_CFLAGS) $(ADAFLAGS) $(CHECKING_ADAFLAGS) $(WARN_ADAFLAGS)
 FORCE_DEBUG_ADAFLAGS = -g
 ADA_CFLAGS =
-ADA_INCLUDES = -nostdinc -I- -I. -Iada/generated -Iada -I$(srcdir)/ada -I$(srcdir)/ada/gcc-interface -Iada/libgnat -I$(srcdir)/ada/libgnat
+ADA_INCLUDES = -nostdinc -I- -I. -Iada/generated -Iada -Iada/gcc-interface -I$(srcdir)/ada -I$(srcdir)/ada/gcc-interface -Iada/libgnat -I$(srcdir)/ada/libgnat
 GNATLIBFLAGS= -W -Wall -gnatpg -nostdinc
 GNATLIBCFLAGS= -g -O2 $(TCFLAGS)
 ADA_INCLUDE_DIR = $(libsubdir)/adainclude
@@ -469,7 +469,7 @@ GNAT_ADA_OBJS =	\
  ada/stylesw.o	\
  ada/switch-c.o	\
  ada/switch.o	\
- ada/libgnat/system.o	\
+ ada/gcc-interface/system.o	\
  ada/table.o	\
  ada/targparm.o	\
  ada/tbuild.o	\
@@ -627,7 +627,7 @@ GNATBIND_OBJS = \
  ada/stylesw.o\
  ada/switch-b.o   \
  ada/switch.o \
- ada/libgnat/system.o \
+ ada/gcc-interface/system.o \
  ada/table.o  \
  ada/targext.o\
  ada/targparm.o   \
@@ -1038,8 +1038,9 @@ ada/sdefault.o : ada/libgnat/ada.ads ada/libgnat/a-except.ads ada/libgnat/a-uncc
ada/libgnat/s-exctab.ads ada/libgnat/s-memory.ads ada/libgnat/s-os_lib.ads ada/libgnat/s-parame.ads \
ada/libgnat/s-stalib.ads ada/libgnat/s-strops.ads ada/libgnat/s-sopco3.ads ada/libgnat/s-sopco4.ads \
ada/libgnat/s-sopco5.ads ada/libgnat/s-string.ads ada/libgnat/s-traent.ads ada/libgnat/s-unstyp.ads \
-   ada/libgnat/s-wchcon.ads ada/libgnat/system.ads ada/table.adb ada/table.ads \
-   ada/types.ads ada/libgnat/unchdeal.ads ada/libgnat/unchconv.ads
+   ada/libgnat/s-wchcon.ads ada/table.adb ada/table.ads \
+   ada/types.ads ada/libgnat/unchdeal.ads ada/libgnat/unchconv.ads \
+   ada/gcc-interface/system.ads
 
 # Special flags - see gcc-interface/Makefile.in for the template.
 


diff --git /dev/null b/gcc/ada/gcc-interface/system.ads
new file mode 100644
--- /dev/null
+++ b/gcc/ada/gcc-interface/system.ads
@@ -0,0 +1,184 @@
+--
+--  --
+--GNAT RUN-TIME COMPONENTS  --
+--  --
+--   S Y S T E M--
+--  --
+-- S p e c  --
+--(Compiler Version)--
+--  --
+--  Copyright (C) 1992-2020, Free Software Foundation, Inc. --
+--  --
+-- This specification is derived from the Ada Reference Manual for use with --
+-- GNAT. The copyright notice above, and the license provisions that follow --
+-- apply solely to the  contents of the part following the private keyword. --
+--  --
+-- 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- --
+-- ware  Foundation;  either version 3,  or (at your option) any later ver- --
+-- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
+-- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
+-- or FITNESS FOR A PARTICULAR PURPOSE. --
+--  --
+-- As a special exception under Section 7 of GPL version 3, you are granted --
+-- additional permissions described in the GCC Runtime Library Exception,   --
+-- version 3.1, as published by the Free Software Foundation.   --
+--  --
+-- You should have received a copy of the GNU General Public License and--
+-- a copy of the GCC Runtime Library Exception along with this program; --
+-- see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see--
+-- .  --
+--

[Ada] Legal actual type with inherited discriminants rejected in instantiation

2020-10-16 Thread Pierre-Marie de Rodat
When determining the legality of a generic parameter association
for a formal type derived from a type that imposes a discriminant
constraint, the compiler was incorrectly concluding that an actual
type that inherits the constraint of the formal's parent type was
not compatible with the formal type (due to not recognizing the
constraints as statically matching). The comparison of constraints
was not taking into account the possibility of inherited constraints
and the fact that the compiler makes a copy of the parent type's
constraint. The fix is to traverse the chain of ancestors to locate
the nearest explicit constraint from which a constraint may be
inherited.

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

gcc/ada/

* sem_eval.adb (Subtypes_Statically_Match): Retrieve
discriminant constraints from the two types via new function
Original_Discriminant_Constraint rather than
Discriminant_Constraint.
(Original_Discriminant_Constraint): New function to locate the
nearest explicit discriminant constraint associated with a type
that may possibly have inherited a constraint from an ancestor
type.diff --git a/gcc/ada/sem_eval.adb b/gcc/ada/sem_eval.adb
--- a/gcc/ada/sem_eval.adb
+++ b/gcc/ada/sem_eval.adb
@@ -6554,8 +6554,65 @@ package body Sem_Eval is
  end if;
 
  declare
-DL1 : constant Elist_Id := Discriminant_Constraint (T1);
-DL2 : constant Elist_Id := Discriminant_Constraint (T2);
+
+function Original_Discriminant_Constraint
+  (Typ : Entity_Id) return Elist_Id;
+--  Returns Typ's discriminant constraint, or if the constraint
+--  is inherited from an ancestor type, then climbs the parent
+--  types to locate and return the constraint farthest up the
+--  parent chain that Typ's constraint is ultimately inherited
+--  from (stopping before a parent that doesn't impose a constraint
+--  or a parent that has new discriminants). This ensures a proper
+--  result from the equality comparison of Elist_Ids below (as
+--  otherwise, derived types that inherit constraints may appear
+--  to be unequal, because each level of derivation can have its
+--  own copy of the constraint).
+
+function Original_Discriminant_Constraint
+  (Typ : Entity_Id) return Elist_Id
+is
+begin
+   if not Has_Discriminants (Typ) then
+  return No_Elist;
+
+   --  If Typ is not a derived type, then directly return the
+   --  its constraint.
+
+   elsif not Is_Derived_Type (Typ) then
+  return Discriminant_Constraint (Typ);
+
+   --  If the parent type doesn't have discriminants, doesn't
+   --  have a constraint, or has new discriminants, then stop
+   --  and return Typ's constraint.
+
+   elsif not Has_Discriminants (Etype (Typ))
+
+ --  No constraint on the parent type
+
+ or else not Present (Discriminant_Constraint (Etype (Typ)))
+ or else Is_Empty_Elmt_List
+   (Discriminant_Constraint (Etype (Typ)))
+
+ --  The parent type defines new discriminants
+
+ or else
+   (Is_Base_Type (Etype (Typ))
+ and then Present (Discriminant_Specifications
+ (Parent (Etype (Typ)
+   then
+  return Discriminant_Constraint (Typ);
+
+   --  Otherwise, make a recursive call on the parent type
+
+   else
+  return Original_Discriminant_Constraint (Etype (Typ));
+   end if;
+end Original_Discriminant_Constraint;
+
+--  Local variables
+
+DL1 : constant Elist_Id := Original_Discriminant_Constraint (T1);
+DL2 : constant Elist_Id := Original_Discriminant_Constraint (T2);
 
 DA1 : Elmt_Id;
 DA2 : Elmt_Id;




[Ada] Attribute Img on derived types

2020-10-16 Thread Pierre-Marie de Rodat
Refinement of previous patch: the root type must be used for the image
of enumeration types, because the literal map is attached to the root
type even when derivations are present.
Fixes several ACATS and fixedbugs regressions involving 'Image.

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

gcc/ada/

*  exp_imgv.adb (Expand_Image_Attribute):  Refine previous patch
to use root type (and not base type) on enumeration types.diff --git a/gcc/ada/exp_imgv.adb b/gcc/ada/exp_imgv.adb
--- a/gcc/ada/exp_imgv.adb
+++ b/gcc/ada/exp_imgv.adb
@@ -481,9 +481,15 @@ package body Exp_Imgv is
 
   --  Ada 2020 allows 'Image on private types, so fetch the underlying
   --  type to obtain the structure of the type. We use the base type,
-  --  not the root type, to handle properly derived types.
+  --  not the root type, to handle properly derived types, but we use
+  --  the root type for enumeration types, because the literal map is
+  --  attached to the root. Should be inherited ???
 
-  Rtyp := Underlying_Type (Base_Type (Ptyp));
+  if Is_Enumeration_Type (Ptyp) then
+ Rtyp := Underlying_Type (Root_Type (Ptyp));
+  else
+ Rtyp := Underlying_Type (Base_Type (Ptyp));
+  end if;
 
   --  Enable speed-optimized expansion of user-defined enumeration types
   --  if we are compiling with optimizations enabled and enumeration type




[Ada] Avoid premature finalization of a function result

2020-10-16 Thread Pierre-Marie de Rodat
When a (simple) return statement in a function that returns a class-wide
result type returns a call to a function that returns a specific
result type, do not finalize that function result before returning it.

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

gcc/ada/

* exp_util.adb (Is_Related_To_Func_Return): Cope with the case
where the FE introduces a type conversion.diff --git a/gcc/ada/exp_util.adb b/gcc/ada/exp_util.adb
--- a/gcc/ada/exp_util.adb
+++ b/gcc/ada/exp_util.adb
@@ -8740,9 +8740,14 @@ package body Exp_Util is
function Is_Related_To_Func_Return (Id : Entity_Id) return Boolean is
   Expr : constant Node_Id := Related_Expression (Id);
begin
+  --  In the case of a function with a class-wide result that returns
+  --  a call to a function with a specific result, we introduce a
+  --  type conversion for the return expression. We do not want that
+  --  type conversion to influence the result of this function.
+
   return
 Present (Expr)
-  and then Nkind (Expr) = N_Explicit_Dereference
+  and then Nkind (Unqual_Conv (Expr)) = N_Explicit_Dereference
   and then Nkind (Parent (Expr)) = N_Simple_Return_Statement;
end Is_Related_To_Func_Return;
 




[Ada] Improvements to implementation of Ada_2020 attribute Reduce

2020-10-16 Thread Pierre-Marie de Rodat
AI12-0262 indicates that the reducer in an attribute reference
'Reduce must be either a binary function with same types for parameters
and result, or else a procedure with an in_out parameter that serves
as an accumulator. The function case includes attributes that are
themselves funxtions: the only two that match the type requirements
are 'Min and 'Max. This patch implements these two additional cases.

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

gcc/ada/

* sem_attr.adb (Min_Max): Handle the case where attribute
name (qualified by required type) appears as the reducer of a
'Reduce attribute reference.
(Resolve_Attribute) : Handle properly the presence of a
procedure or an attribute reference Min/Max as a reducer.
* exp_attr.adb (Expand_Attribute_Reference) : New
subprogram Build_Stat, to construct the combining statement
which appears in the generated loop for Reduce, and which is
either a function call when the reducer is a function or an
attribute, or a procedure call when reducer is an appropriate
procedure.  BuilD_Stat is used both when the prefix of 'Reduce
is a value sequence and when it is an objectdiff --git a/gcc/ada/exp_attr.adb b/gcc/ada/exp_attr.adb
--- a/gcc/ada/exp_attr.adb
+++ b/gcc/ada/exp_attr.adb
@@ -5619,40 +5619,101 @@ package body Exp_Attr is
 E2  : constant Node_Id := Next (E1);
 Bnn : constant Entity_Id := Make_Temporary (Loc, 'B', N);
 Typ : constant Entity_Id := Etype (N);
+
 New_Loop : Node_Id;
+Stat: Node_Id;
+
+function Build_Stat (Comp : Node_Id) return Node_Id;
+--  The reducer can be a function, a procedure whose first
+--  parameter is in-out, or an attribute that is a function,
+--  which (for now) can only be Min/Max. This subprogram
+--  builds the corresponding computation for the generated loop.
+
+
+-- Build_Stat --
+
+
+function Build_Stat (Comp : Node_Id) return Node_Id is
+begin
+   if Nkind (E1) = N_Attribute_Reference then
+  Stat :=  Make_Assignment_Statement (Loc,
+ Name => New_Occurrence_Of (Bnn, Loc),
+ Expression => Make_Attribute_Reference (Loc,
+   Attribute_Name => Attribute_Name (E1),
+   Prefix => New_Copy (Prefix (E1)),
+   Expressions => New_List (
+ New_Occurrence_Of (Bnn, Loc),
+ Comp)));
+
+   elsif Ekind (Entity (E1)) = E_Procedure then
+  Stat := Make_Procedure_Call_Statement (Loc,
+Name => New_Occurrence_Of (Entity (E1), Loc),
+   Parameter_Associations => New_List (
+ New_Occurrence_Of (Bnn, Loc),
+ Comp));
+   else
+  Stat :=  Make_Assignment_Statement (Loc,
+ Name => New_Occurrence_Of (Bnn, Loc),
+ Expression => Make_Function_Call (Loc,
+   Name => New_Occurrence_Of (Entity (E1), Loc),
+   Parameter_Associations => New_List (
+ New_Occurrence_Of (Bnn, Loc),
+ Comp)));
+   end if;
+
+   return Stat;
+end Build_Stat;
 
  --  If the prefix is an aggregate, its unique component is an
  --  Iterated_Element, and we create a loop out of its iterator.
+ --  The iterated_component_Association is parsed as a loop
+ --  parameter specification with "in" or as a container
+ --  iterator with "of".
 
  begin
 if Nkind (Prefix (N)) = N_Aggregate then
declare
   Stream  : constant Node_Id :=
   First (Component_Associations (Prefix (N)));
-  Id  : constant Node_Id := Defining_Identifier (Stream);
   Expr: constant Node_Id := Expression (Stream);
-  Ch  : constant Node_Id :=
-  First (Discrete_Choices (Stream));
+  Id  : constant Node_Id := Defining_Identifier (Stream);
+  It_Spec : constant Node_Id :=
+ Iterator_Specification (Stream);
+  Ch  : Node_Id;
+  Iter: Node_Id;
+
begin
-  New_Loop := Make_Loop_Statement (Loc,
-Iteration_Scheme =>
+  --  Iteration may be given by an element iterator:
+
+  if Nkind (Stream) = 

[Ada] Remove non-ASCII character

2020-10-16 Thread Pierre-Marie de Rodat
This is the first step in supporting [...] notation for aggregates in
-gnatX mode.

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

gcc/ada/

* libgnat/a-numeri.ads: Remove the greek letter.diff --git a/gcc/ada/libgnat/a-numeri.ads b/gcc/ada/libgnat/a-numeri.ads
--- a/gcc/ada/libgnat/a-numeri.ads
+++ b/gcc/ada/libgnat/a-numeri.ads
@@ -21,10 +21,13 @@ package Ada.Numerics is
Pi : constant :=
   3.14159_26535_89793_23846_26433_83279_50288_41971_69399_37511;
 
-   ["03C0"] : constant := Pi;
+   --  ["03C0"] : constant := Pi;
--  This is the Greek letter Pi (for Ada 2005 AI-388). Note that it is
--  conforming to have this constant present even in Ada 95 mode, as there
--  is no way for a normal mode Ada 95 program to reference this identifier.
+   --  ???This is removed for now, because nobody uses it, and it causes
+   --  trouble for tools other than the compiler. If people want to use the
+   --  Greek letter in their programs, they can easily define it themselves.
 
e : constant :=
  2.71828_18284_59045_23536_02874_71352_66249_77572_47093_69996;




[Ada] Ada2020: parsing of qualified exprs with new agg syntax

2020-10-16 Thread Pierre-Marie de Rodat
This patch allows parsing of qualified expressions of the form

T'[...]

where [...] is a new syntax for aggregate in Ada 2020.

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

gcc/ada/

* par-ch4.adb (P_Name): Allow Tok_Left_Bracket in two places to
call P_Qualified_Expression. We don't need to modify other
places that call P_Qualified_Expression, because a
qualified_expression is a name in Ada 2012 and higher, so P_Name
is the right place.  The parser already parses aggregates with
brackets; we just need to allow that in qualified expressions.diff --git a/gcc/ada/par-ch4.adb b/gcc/ada/par-ch4.adb
--- a/gcc/ada/par-ch4.adb
+++ b/gcc/ada/par-ch4.adb
@@ -281,9 +281,10 @@ package body Ch4 is
  goto Scan_Name_Extension;
   end if;
 
-  --  We have scanned out a qualified simple name, check for name extension
-  --  Note that we know there is no dot here at this stage, so the only
-  --  possible cases of name extension are apostrophe and left paren.
+  --  We have scanned out a qualified simple name, check for name
+  --  extension.  Note that we know there is no dot here at this stage,
+  --  so the only possible cases of name extension are apostrophe followed
+  --  by '(' or '['.
 
   if Token = Tok_Apostrophe then
  Save_Scan_State (Scan_State); -- at apostrophe
@@ -291,7 +292,9 @@ package body Ch4 is
 
  --  Qualified expression in Ada 2012 mode (treated as a name)
 
- if Ada_Version >= Ada_2012 and then Token = Tok_Left_Paren then
+ if Ada_Version >= Ada_2012
+   and then Token in Tok_Left_Paren | Tok_Left_Bracket
+ then
 goto Scan_Name_Extension_Apostrophe;
 
  --  If left paren not in Ada 2012, then it is not part of the name,
@@ -445,7 +448,9 @@ package body Ch4 is
  begin
 --  Check for qualified expression case in Ada 2012 mode
 
-if Ada_Version >= Ada_2012 and then Token = Tok_Left_Paren then
+if Ada_Version >= Ada_2012
+  and then Token in Tok_Left_Paren | Tok_Left_Bracket
+then
Name_Node := P_Qualified_Expression (Name_Node);
goto Scan_Name_Extension;
 




[Ada] Relax too strong assertions

2020-10-16 Thread Pierre-Marie de Rodat
Recent changes exposed that some assertions were too strong, now
relaxed.

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

gcc/ada/

* scil_ll.adb, sem_scil.adb: Update assertions.diff --git a/gcc/ada/scil_ll.adb b/gcc/ada/scil_ll.adb
--- a/gcc/ada/scil_ll.adb
+++ b/gcc/ada/scil_ll.adb
@@ -122,7 +122,7 @@ package body SCIL_LL is
 when N_SCIL_Membership_Test =>
pragma Assert
  (Nkind (N) in N_Identifier | N_And_Then | N_Or_Else |
-   N_Expression_With_Actions);
+   N_Expression_With_Actions | N_Function_Call);
null;
 
 when others =>


diff --git a/gcc/ada/sem_scil.adb b/gcc/ada/sem_scil.adb
--- a/gcc/ada/sem_scil.adb
+++ b/gcc/ada/sem_scil.adb
@@ -135,7 +135,7 @@ package body Sem_SCIL is
 pragma Assert
   (Nkind (N) in
  N_Identifier | N_And_Then | N_Or_Else |
- N_Expression_With_Actions
+ N_Expression_With_Actions | N_Function_Call
   and then Etype (N) = Standard_Boolean);
 
 --  Check the entity identifier of the associated tagged type (that




[Ada] Attribute Img on derived types

2020-10-16 Thread Pierre-Marie de Rodat
This patch fixes the handling of the Ada_2020 attribute Img when applied
to derived types. If the type is private it is necessary to retrieve a
non-private description of the type structure, by using an underlying
view (which crosses the privacy boundary). The underlying view is that
of the base type of the object, but not its root type, which might
ignore components of a type extension and produce spurious type errors.

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

gcc/ada/

*  exp_imgv.adb (Expand_Image_Attribute): Use the base type
instead of the root type when type of object is private. Remove
Ada_2020 guard, because it has been checked during prior
analysis. Use Underlying_Type in all cases, as it is a no-op on
types that are not private.diff --git a/gcc/ada/exp_imgv.adb b/gcc/ada/exp_imgv.adb
--- a/gcc/ada/exp_imgv.adb
+++ b/gcc/ada/exp_imgv.adb
@@ -479,14 +479,11 @@ package body Exp_Imgv is
 
   Ptyp := Entity (Pref);
 
-  --  Ada 2020 allows 'Image on private types, so we need to fetch the
-  --  underlying type.
+  --  Ada 2020 allows 'Image on private types, so fetch the underlying
+  --  type to obtain the structure of the type. We use the base type,
+  --  not the root type, to handle properly derived types.
 
-  if Ada_Version >= Ada_2020 then
- Rtyp := Underlying_Type (Root_Type (Ptyp));
-  else
- Rtyp := Root_Type (Ptyp);
-  end if;
+  Rtyp := Underlying_Type (Base_Type (Ptyp));
 
   --  Enable speed-optimized expansion of user-defined enumeration types
   --  if we are compiling with optimizations enabled and enumeration type
@@ -657,9 +654,10 @@ package body Exp_Imgv is
 T : Entity_Id;
  begin
 --  In Ada 2020 we need the underlying type here, because 'Image is
---  allowed on private types.
+--  allowed on private types. We have already checked the version
+--  when resolving the attribute.
 
-if Ada_Version >= Ada_2020 then
+if Is_Private_Type (Ptyp) then
T := Rtyp;
 else
T := Ptyp;
@@ -683,9 +681,7 @@ package body Exp_Imgv is
  declare
 Conv : Node_Id;
  begin
-if Ada_Version >= Ada_2020
-  and then Is_Private_Type (Etype (Expr))
-then
+if Is_Private_Type (Etype (Expr)) then
if Is_Fixed_Point_Type (Rtyp) then
   Conv := Convert_To (Tent, OK_Convert_To (Rtyp, Expr));
else




[Ada] Detect qualified type names for AI12-0027

2020-10-16 Thread Pierre-Marie de Rodat
Type in a view conversion can be both qualified and unqualified.

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

gcc/ada/

* sem_util.adb (Is_View_Conversion): Detect qualified types.
* sem_util.ads (Is_Actual_In_Out_Parameter): Fix style in
comment.diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb
--- a/gcc/ada/sem_util.adb
+++ b/gcc/ada/sem_util.adb
@@ -19641,7 +19641,7 @@ package body Sem_Util is
function Is_View_Conversion (N : Node_Id) return Boolean is
begin
   if Nkind (N) = N_Type_Conversion
-and then Nkind (Unqual_Conv (N)) = N_Identifier
+and then Nkind (Unqual_Conv (N)) in N_Expanded_Name | N_Identifier
   then
  if Is_Tagged_Type (Etype (N))
and then Is_Tagged_Type (Etype (Unqual_Conv (N)))


diff --git a/gcc/ada/sem_util.ads b/gcc/ada/sem_util.ads
--- a/gcc/ada/sem_util.ads
+++ b/gcc/ada/sem_util.ads
@@ -1598,7 +1598,7 @@ package Sem_Util is
 
function Is_Actual_In_Out_Parameter (N : Node_Id) return Boolean;
--  Determines if N is an actual parameter of in-out mode in a subprogram
-   --  call
+   --  call.
 
function Is_Actual_Out_Parameter (N : Node_Id) return Boolean;
--  Determines if N is an actual parameter of out mode in a subprogram call




[Ada] Constants no longer synchronised if they are access-to-variable

2020-10-16 Thread Pierre-Marie de Rodat
Implement changes in SPARK RM 9(1): previously an object was
'synchronized' if it was a constant, now constants are only synchronized
if they are not of an access-to-variable type.

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

gcc/ada/

* sem_util.ads, sem_util.adb (Is_Access_Variable): New function.
(Is_Synchronized_Object): Call new function when determining if
a constant can be regarded as synchronized.diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb
--- a/gcc/ada/sem_util.adb
+++ b/gcc/ada/sem_util.adb
@@ -14337,6 +14337,16 @@ package body Sem_Util is
   return Nkind (Par) in N_Subprogram_Call;
end Is_Anonymous_Access_Actual;
 
+   
+   -- Is_Access_Variable --
+   
+
+   function Is_Access_Variable (E : Entity_Id) return Boolean is
+   begin
+  return Is_Access_Object_Type (E)
+and then not Is_Access_Constant (E);
+   end Is_Access_Variable;
+
-
-- Is_Actual_Out_Parameter --
-
@@ -19149,9 +19159,12 @@ package body Sem_Util is
  then
 return True;
 
- --  A constant is a synchronized object by default
+ --  A constant is a synchronized object by default, unless its type is
+ --  access-to-variable type.
 
- elsif Ekind (Id) = E_Constant then
+ elsif Ekind (Id) = E_Constant
+   and then not Is_Access_Variable (Etype (Id))
+ then
 return True;
 
  --  A variable is a synchronized object if it is subject to pragma


diff --git a/gcc/ada/sem_util.ads b/gcc/ada/sem_util.ads
--- a/gcc/ada/sem_util.ads
+++ b/gcc/ada/sem_util.ads
@@ -1596,6 +1596,9 @@ package Sem_Util is
--  True if E is the constructed wrapper for an access_to_subprogram
--  type with Pre/Postconditions.
 
+   function Is_Access_Variable (E : Entity_Id) return Boolean;
+   --  Determines if type E is an access-to-variable
+
function Is_Actual_In_Out_Parameter (N : Node_Id) return Boolean;
--  Determines if N is an actual parameter of in-out mode in a subprogram
--  call.
@@ -2166,7 +2169,7 @@ package Sem_Util is
--  such, the object must be
--* Of a type that yields a synchronized object
--* An atomic object with enabled Async_Writers
-   --* A constant
+   --* A constant not of access-to-variable type
--* A variable subject to pragma Constant_After_Elaboration
 
function Is_Synchronized_Tagged_Type (E : Entity_Id) return Boolean;




[Ada] Ada2020: AI12-0129 Make protected objects more protecting

2020-10-16 Thread Pierre-Marie de Rodat
A Boolean aspect Exclusive_Functions is added to the language to change
the semantic of protected functions to use a R/W lock instead of a Read
lock.

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

gcc/ada/

* aspects.ads, snames.ads-tmpl: Add support for
Exclusive_Functions aspect.
* sem_ch13.adb (Analyze_Aspect_Specifications): Ditto.
* exp_ch9.adb (Build_Protected_Subprogram_Body): Take aspect
Exclusive_Functions into account.diff --git a/gcc/ada/aspects.ads b/gcc/ada/aspects.ads
--- a/gcc/ada/aspects.ads
+++ b/gcc/ada/aspects.ads
@@ -190,6 +190,7 @@ package Aspects is
   Aspect_Disable_Controlled,-- GNAT
   Aspect_Discard_Names,
   Aspect_CUDA_Global,   -- GNAT
+  Aspect_Exclusive_Functions,
   Aspect_Export,
   Aspect_Favor_Top_Level,   -- GNAT
   Aspect_Independent,
@@ -472,6 +473,7 @@ package Aspects is
   Aspect_Dynamic_Predicate=> False,
   Aspect_Effective_Reads  => False,
   Aspect_Effective_Writes => False,
+  Aspect_Exclusive_Functions  => False,
   Aspect_Extensions_Visible   => False,
   Aspect_External_Name=> False,
   Aspect_External_Tag => False,
@@ -619,6 +621,7 @@ package Aspects is
   Aspect_Effective_Reads  => Name_Effective_Reads,
   Aspect_Effective_Writes => Name_Effective_Writes,
   Aspect_Elaborate_Body   => Name_Elaborate_Body,
+  Aspect_Exclusive_Functions  => Name_Exclusive_Functions,
   Aspect_Export   => Name_Export,
   Aspect_Extensions_Visible   => Name_Extensions_Visible,
   Aspect_External_Name=> Name_External_Name,
@@ -851,6 +854,7 @@ package Aspects is
   Aspect_Dispatching_Domain   => Always_Delay,
   Aspect_Dynamic_Predicate=> Always_Delay,
   Aspect_Elaborate_Body   => Always_Delay,
+  Aspect_Exclusive_Functions  => Always_Delay,
   Aspect_External_Name=> Always_Delay,
   Aspect_External_Tag => Always_Delay,
   Aspect_Favor_Top_Level  => Always_Delay,


diff --git a/gcc/ada/exp_ch9.adb b/gcc/ada/exp_ch9.adb
--- a/gcc/ada/exp_ch9.adb
+++ b/gcc/ada/exp_ch9.adb
@@ -24,6 +24,7 @@
 --
 
 with Atree;use Atree;
+with Aspects;  use Aspects;
 with Checks;   use Checks;
 with Einfo;use Einfo;
 with Elists;   use Elists;
@@ -4089,8 +4090,17 @@ package body Exp_Ch9 is
 Parameter_Associations => Uactuals));
  end if;
 
- Lock_Kind := RE_Lock_Read_Only;
-
+ if Has_Aspect (Pid, Aspect_Exclusive_Functions)
+   and then
+ (No (Find_Value_Of_Aspect (Pid, Aspect_Exclusive_Functions))
+   or else
+ Is_True (Static_Boolean (Find_Value_Of_Aspect
+   (Pid, Aspect_Exclusive_Functions
+ then
+Lock_Kind := RE_Lock;
+ else
+Lock_Kind := RE_Lock_Read_Only;
+ end if;
   else
  Unprot_Call :=
Make_Procedure_Call_Statement (Loc,


diff --git a/gcc/ada/sem_ch13.adb b/gcc/ada/sem_ch13.adb
--- a/gcc/ada/sem_ch13.adb
+++ b/gcc/ada/sem_ch13.adb
@@ -4397,14 +4397,16 @@ package body Sem_Ch13 is
  if Ekind (E) /= E_Protected_Type then
 Error_Msg_Name_1 := Nam;
 Error_Msg_N
-  ("aspect % only applies to a protected object",
+  ("aspect % only applies to a protected type " &
+   "or object",
Aspect);
 
  else
 --  Set the Uses_Lock_Free flag to True if there is no
 --  expression or if the expression is True. The
 --  evaluation of this aspect should be delayed to the
---  freeze point (why???)
+--  freeze point if we wanted to handle the corner case
+--  of "true" or "false" being redefined.
 
 if No (Expr)
   or else Is_True (Static_Boolean (Expr))
@@ -4426,6 +4428,19 @@ package body Sem_Ch13 is
  Analyze_Aspect_Disable_Controlled;
  goto Continue;
 
+  --  Ada 202x (AI12-0129): Exclusive_Functions
+
+  elsif A_Id = Aspect_Exclusive_Functions then
+ if Ekind (E) /= E_Protected_Type then
+Error_Msg_Name_1 := Nam;
+Error_Msg_N
+  ("aspect % only applies to a protected type " &
+   "or object",
+   Aspect);
+

[Ada] Finalization of uninitialized object with build in place call

2020-10-16 Thread Pierre-Marie de Rodat
In some cases combining a build in place function call returning a
controlled object, part of another procedure call, if the function call
raises an exception before executing the extended return statement, the
caller would attempt to finalize the build in place result which has not
been initialized yet.

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

gcc/ada/

* exp_ch6.adb (Make_Build_In_Place_Call_In_Object_Declaration):
Call Set_BIP_Initialization_Call systematically.
* exp_ch7.adb (Process_Transient_In_Scope): Take
BIP_Initialization_Call into account to decide where to insert
the Hook.diff --git a/gcc/ada/exp_ch6.adb b/gcc/ada/exp_ch6.adb
--- a/gcc/ada/exp_ch6.adb
+++ b/gcc/ada/exp_ch6.adb
@@ -9593,7 +9593,7 @@ package body Exp_Ch6 is
  --  which prompted the generation of the transient block. To resolve
  --  this scenario, store the build-in-place call.
 
- if Scope_Is_Transient and then Node_To_Be_Wrapped = Obj_Decl then
+ if Scope_Is_Transient then
 Set_BIP_Initialization_Call (Obj_Def_Id, Res_Decl);
  end if;
 


diff --git a/gcc/ada/exp_ch7.adb b/gcc/ada/exp_ch7.adb
--- a/gcc/ada/exp_ch7.adb
+++ b/gcc/ada/exp_ch7.adb
@@ -5668,10 +5668,18 @@ package body Exp_Ch7 is
--  
--Hook := Obj_Id'Unrestricted_Access;
 
-   if Ekind (Obj_Id) in E_Constant | E_Variable
- and then Present (Last_Aggregate_Assignment (Obj_Id))
-   then
-  Hook_Insert := Last_Aggregate_Assignment (Obj_Id);
+   --  Similarly if we have a build in place call: we must
+   --  initialize Hook only after the call has happened, otherwise
+   --  Obj_Id will not be initialized yet.
+
+   if Ekind (Obj_Id) in E_Constant | E_Variable then
+  if Present (Last_Aggregate_Assignment (Obj_Id)) then
+ Hook_Insert := Last_Aggregate_Assignment (Obj_Id);
+  elsif Present (BIP_Initialization_Call (Obj_Id)) then
+ Hook_Insert := BIP_Initialization_Call (Obj_Id);
+  else
+ Hook_Insert := Obj_Decl;
+  end if;
 
--  Otherwise the hook seizes the related object immediately
 




[Ada] Add Max_Integer_Size attribute and couple of helper functions

2020-10-16 Thread Pierre-Marie de Rodat
This introduces a new attribute Max_Integer_Size that can only be
applied to Standard and yields the size of the largest supported integer
type for the target.  It is primarily intended to implement
System.{Min,Max}_Int.

This also implements a couple of internal helper functions in the
compiler to return an appropriate integer type for a given size and
signedness.

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

gcc/ada/

* doc/gnat_rm/implementation_defined_attributes.rst: Document the
new Max_Integer_Size attribute.
* gnat_rm.texi: Regenerate.
* exp_attr.adb (Get_Integer_Type): Call Small_Integer_Type_For.
(Expand_N_Attribute_Reference) : Replace selection
code with call to Integer_Type_For.
: Likewise.
: Likewise.
: Likewise.
: Raise Program_Error.
* exp_ch3.adb (Expand_Freeze_Enumeration_Type): Replace selection
code with call to Integer_Type_For.
(Simple_Init_Initialize_Scalars_Type): Use Long_Long_Unsigned and
System_Max_Integer_Size to size the largest integer type.
* exp_pakd.adb (Compute_Linear_Subscript): Minor tweak.
(Create_Packed_Array_Impl_Type): Use Small_Integer_Type_For.
* exp_util.ads (Integer_Type_For): New function.
(Small_Integer_Type_For): Likewise.
* exp_util.adb (Adjust_Condition): Use Integer_Type_For.
(Component_May_Be_Bit_Aligned): Use System_Max_Integer_Size.
(Integer_Type_For): New function.
(Small_Integer_Type_For): Likewise.
(Matching_Standard_Type): Use Small_Integer_Type_For.
(Needs_Constant_Address): Replace 64 with System_Max_Integer_Size.
* freeze.adb (Set_Small_Size): Likewise.
(Size_Known): Likewise.
(Check_Suspicious_Modulus): Likewise.
(Check_Large_Modular_Array): Likewise.
(Freeze_Entity): Likewise.
* layout.adb (Layout_Type): Likewise.
* sem_aggr.adb: Add with and use clauses for Ttypes.
(Resolve_Aggregate): Replace 64 with System_Max_Integer_Size.
* sem_attr.ads (Attribute_Impl_Def): Add Attribute_Max_Integer_Size.
* sem_attr.adb (Analyze_Attribute) : New
(Eval_Attribute): Likewise.
* sem_ch13.adb (Adjust_Record_For_Reverse_Bit_Order): Change max
scalar size to System_Max_Integer_Size.
(Check_Array_Type): Replace 64 with System_Max_Integer_Size and
remove superfluous test.
(OK_Component): Likewise.
* sem_ch5.adb: Add with and use clauses for Ttypes.
(Analyze_Assignment): Replace 64 with System_Max_Integer_Size.
* snames.ads-tmpl (Name_Max_Integer_Size): New attribute name.
(Attribute_Id): Add Attribute_Max_Integer_Size.
* ttypes.ads (System_Max_Integer_Size): New constant.

patch.diff.gz
Description: application/gzip


[Ada] Remove support for -gnatP and pragma Polling

2020-10-16 Thread Pierre-Marie de Rodat
This switch has never been very useful nor used in practice, so remove
the associated code complexity.

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

gcc/ada/

* Makefile.rtl, gnat1drv.adb, expander.adb
doc/gnat_rm/implementation_defined_pragmas.rst,
doc/gnat_ugn/building_executable_programs_with_gnat.rst,
doc/gnat_ugn/the_gnat_compilation_model.rst, exp_ch5.ads,
exp_ch5.adb, exp_ch6.adb, exp_ch7.adb, exp_util.adb,
exp_util.ads, libgnarl/s-osinte__aix.adb,
libgnarl/s-osinte__android.adb, libgnarl/s-osinte__darwin.adb,
libgnarl/s-osinte__gnu.adb, libgnarl/s-osinte__hpux-dce.adb,
libgnarl/s-osinte__lynxos178.adb, libgnarl/s-osinte__posix.adb,
libgnarl/s-osinte__qnx.adb, libgnarl/s-osinte__rtems.adb,
libgnarl/s-osinte__solaris.adb, libgnarl/s-osinte__vxworks.adb,
libgnarl/s-osinte__x32.adb, libgnarl/s-solita.adb,
libgnarl/s-taasde.adb, libgnarl/s-taprob.adb,
libgnarl/s-taprop__dummy.adb, libgnarl/s-taprop__hpux-dce.adb,
libgnarl/s-taprop__linux.adb, libgnarl/s-taprop__mingw.adb,
libgnarl/s-taprop__posix.adb, libgnarl/s-taprop__qnx.adb,
libgnarl/s-taprop__solaris.adb, libgnarl/s-taprop__vxworks.adb,
libgnarl/s-tarest.adb, libgnarl/s-tasini.adb,
libgnarl/s-taskin.adb, libgnarl/s-taspri__dummy.ads,
libgnarl/s-taspri__hpux-dce.ads, libgnarl/s-taspri__lynxos.ads,
libgnarl/s-taspri__mingw.ads,
libgnarl/s-taspri__posix-noaltstack.ads,
libgnarl/s-taspri__posix.ads, libgnarl/s-taspri__solaris.ads,
libgnarl/s-taspri__vxworks.ads, libgnarl/s-tassta.adb,
libgnarl/s-tasuti.adb, libgnarl/s-tposen.adb,
libgnat/a-except.adb, libgnat/a-except.ads,
libgnat/s-dwalin.adb, libgnat/s-dwalin.ads,
libgnat/s-mastop.ads, libgnat/s-soflin.adb,
libgnat/s-stalib.adb, libgnat/s-stalib.ads,
libgnat/s-stchop.adb, libgnat/s-stchop.ads,
libgnat/s-stchop__limit.ads, libgnat/s-traceb.ads,
libgnat/s-traent.adb, libgnat/s-traent.ads,
libgnat/s-trasym.adb, libgnat/s-trasym.ads,
libgnat/s-trasym__dwarf.adb, opt.adb, opt.ads, par-prag.adb,
sem_prag.adb, snames.ads-tmpl, switch-c.adb, targparm.adb,
targparm.ads, usage.adb: Remove support for -gnatP and pragma
Polling.
* gnat_ugn.texi: Regenerate.
* libgnat/a-excpol.adb, libgnat/a-excpol__abort.adb: Removed.

patch.diff.gz
Description: application/gzip


[Ada] Unique itypes names for unconstrained array object declaration

2020-10-16 Thread Pierre-Marie de Rodat
An unconstrained array object declaration might require two itypes: for
object definition and for its initial value. Their names do not matter
for the frontend, but GNATprove requires all types to have unique names
(except private/full views).

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

gcc/ada/

* sem_ch3.adb (Array_Type_Declaration): Create itype with unique
name.diff --git a/gcc/ada/sem_ch3.adb b/gcc/ada/sem_ch3.adb
--- a/gcc/ada/sem_ch3.adb
+++ b/gcc/ada/sem_ch3.adb
@@ -6141,7 +6141,12 @@ package body Sem_Ch3 is
   --  Constrained array case
 
   if No (T) then
- T := Create_Itype (E_Void, P, Related_Id, 'T');
+ --  We might be creating more than one itype with the same Related_Id,
+ --  e.g. for an array object definition and its initial value. Give
+ --  them unique suffixes, because GNATprove require distinct types to
+ --  have different names.
+
+ T := Create_Itype (E_Void, P, Related_Id, 'T', Suffix_Index => -1);
   end if;
 
   if Nkind (Def) = N_Constrained_Array_Definition then




[Ada] Use new Max_Integer_Size attribute in system.ads files

2020-10-16 Thread Pierre-Marie de Rodat
This replaces the use of Long_Long_Integer by Standard'Max_Integer_Size
in the definition of Min_Int, Max_Int and Max_Binary_Modulus.

No functional changes.

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

gcc/ada/

* libgnat/system-aix.ads: Likewise.
* libgnat/system-darwin-arm.ads: Likewise.
* libgnat/system-darwin-ppc.ads: Likewise.
* libgnat/system-darwin-x86.ads: Likewise.
* libgnat/system-djgpp.ads: Likewise.
* libgnat/system-dragonfly-x86_64.ads: Likewise.
* libgnat/system-freebsd.ads: Likewise.
* libgnat/system-hpux-ia64.ads: Likewise.
* libgnat/system-hpux.ads: Likewise.
* libgnat/system-linux-alpha.ads: Likewise.
* libgnat/system-linux-arm.ads: Likewise.
* libgnat/system-linux-hppa.ads: Likewise.
* libgnat/system-linux-ia64.ads: Likewise.
* libgnat/system-linux-m68k.ads: Likewise.
* libgnat/system-linux-mips.ads: Likewise.
* libgnat/system-linux-ppc.ads: Likewise.
* libgnat/system-linux-riscv.ads: Likewise.
* libgnat/system-linux-s390.ads: Likewise.
* libgnat/system-linux-sh4.ads: Likewise.
* libgnat/system-linux-sparc.ads: Likewise.
* libgnat/system-linux-x86.ads: Likewise.
* libgnat/system-lynxos178-ppc.ads: Likewise.
* libgnat/system-lynxos178-x86.ads: Likewise.
* libgnat/system-mingw.ads: Likewise.
* libgnat/system-qnx-aarch64.ads: Likewise.
* libgnat/system-rtems.ads: Likewise.
* libgnat/system-solaris-sparc.ads: Likewise.
* libgnat/system-solaris-x86.ads: Likewise.
* libgnat/system-vxworks-arm-rtp-smp.ads: Likewise.
* libgnat/system-vxworks-arm-rtp.ads: Likewise.
* libgnat/system-vxworks-arm.ads: Likewise.
* libgnat/system-vxworks-e500-kernel.ads: Likewise.
* libgnat/system-vxworks-e500-rtp-smp.ads: Likewise.
* libgnat/system-vxworks-e500-rtp.ads: Likewise.
* libgnat/system-vxworks-e500-vthread.ads: Likewise.
* libgnat/system-vxworks-ppc-kernel.ads: Likewise.
* libgnat/system-vxworks-ppc-ravenscar.ads: Likewise.
* libgnat/system-vxworks-ppc-rtp-smp.ads: Likewise.
* libgnat/system-vxworks-ppc-rtp.ads: Likewise.
* libgnat/system-vxworks-ppc-vthread.ads: Likewise.
* libgnat/system-vxworks-ppc.ads: Likewise.
* libgnat/system-vxworks-x86-kernel.ads: Likewise.
* libgnat/system-vxworks-x86-rtp-smp.ads: Likewise.
* libgnat/system-vxworks-x86-rtp.ads: Likewise.
* libgnat/system-vxworks-x86-vthread.ads: Likewise.
* libgnat/system-vxworks-x86.ads: Likewise.
* libgnat/system-vxworks7-aarch64-rtp-smp.ads: Likewise.
* libgnat/system-vxworks7-aarch64.ads: Likewise.
* libgnat/system-vxworks7-arm-rtp-smp.ads: Likewise.
* libgnat/system-vxworks7-arm.ads: Likewise.
* libgnat/system-vxworks7-e500-kernel.ads: Likewise.
* libgnat/system-vxworks7-e500-rtp-smp.ads: Likewise.
* libgnat/system-vxworks7-e500-rtp.ads: Likewise.
* libgnat/system-vxworks7-ppc-kernel.ads: Likewise.
* libgnat/system-vxworks7-ppc-rtp-smp.ads: Likewise.
* libgnat/system-vxworks7-ppc-rtp.ads: Likewise.
* libgnat/system-vxworks7-ppc64-kernel.ads: Likewise.
* libgnat/system-vxworks7-ppc64-rtp-smp.ads: Likewise.
* libgnat/system-vxworks7-x86-kernel.ads: Likewise.
* libgnat/system-vxworks7-x86-rtp-smp.ads: Likewise.
* libgnat/system-vxworks7-x86-rtp.ads: Likewise.
* libgnat/system-vxworks7-x86_64-kernel.ads: Likewise.
* libgnat/system-vxworks7-x86_64-rtp-smp.ads: Likewise.

patch.diff.gz
Description: application/gzip


[Ada] Spurious visibility error on Declare_Expression with renames

2020-10-16 Thread Pierre-Marie de Rodat
The compiler rejects a declare expression whose declarations are only
object renaming declarations, when the expression references those
local objects.

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

gcc/ada/

* sem_res.adb (Resolve_Declare_Expression): Retrieve the created
block entity that is the scope of the local declarations, from
either a local object declaration or an object renaming
declaration. The block entity does not have an explicit
declaration, but appears as the scope of all locally declared
objects.diff --git a/gcc/ada/sem_res.adb b/gcc/ada/sem_res.adb
--- a/gcc/ada/sem_res.adb
+++ b/gcc/ada/sem_res.adb
@@ -7441,11 +7441,14 @@ package body Sem_Res is
   --  Install the scope created for local declarations, if
   --  any. The syntax allows a Declare_Expression with no
   --  declarations, in analogy with block statements.
+  --  Note that that scope has no explicit declaration, but
+  --  appears as the scope of all entities declared therein.
 
   Decl := First (Actions (N));
 
   while Present (Decl) loop
- exit when Nkind (Decl) = N_Object_Declaration;
+ exit when Nkind (Decl)
+ in N_Object_Declaration | N_Object_Renaming_Declaration;
  Next (Decl);
   end loop;
 




[Ada] Reduce use of primary stack on string concatenation

2020-10-16 Thread Pierre-Marie de Rodat
Always using the primary stack when concatenating arrays can lead to a
very large stack usage. To alleviate this, if the current scope is
already using the secondary stack, then allocate the temporary object on
the secondary stack as well.

For the time being, this is for string concatenation, since using it
with e.g. controlled objects can lead to missing finalization and
memory leaks.

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

gcc/ada/

* exp_ch4.adb (Expand_Concatenate): Allocate result of string
concatenation on secondary stack when relevant.diff --git a/gcc/ada/exp_ch4.adb b/gcc/ada/exp_ch4.adb
--- a/gcc/ada/exp_ch4.adb
+++ b/gcc/ada/exp_ch4.adb
@@ -2963,12 +2963,13 @@ package body Exp_Ch4 is
 
   --  Local Declarations
 
-  Opnd_Typ : Entity_Id;
-  Ent  : Entity_Id;
-  Len  : Uint;
-  J: Nat;
-  Clen : Node_Id;
-  Set  : Boolean;
+  Opnd_Typ   : Entity_Id;
+  Subtyp_Ind : Entity_Id;
+  Ent: Entity_Id;
+  Len: Uint;
+  J  : Nat;
+  Clen   : Node_Id;
+  Set: Boolean;
 
--  Start of processing for Expand_Concatenate
 
@@ -3441,28 +3442,95 @@ package body Exp_Ch4 is
   --  Initialize_Scalars is enabled. Also since this is the actual result
   --  entity, we make sure we have debug information for the result.
 
+  Subtyp_Ind :=
+Make_Subtype_Indication (Loc,
+  Subtype_Mark => New_Occurrence_Of (Atyp, Loc),
+  Constraint   =>
+Make_Index_Or_Discriminant_Constraint (Loc,
+  Constraints => New_List (
+Make_Range (Loc,
+  Low_Bound  => Low_Bound,
+  High_Bound => High_Bound;
+
   Ent := Make_Temporary (Loc, 'S');
   Set_Is_Internal   (Ent);
   Set_Debug_Info_Needed (Ent);
 
-  --  If the bound is statically known to be out of range, we do not want
-  --  to abort, we want a warning and a runtime constraint error. Note that
-  --  we have arranged that the result will not be treated as a static
-  --  constant, so we won't get an illegality during this insertion.
+  --  If we are concatenating strings and the current scope already uses
+  --  the secondary stack, allocate the resulting string also on the
+  --  secondary stack to avoid putting too much pressure on the primary
+  --  stack.
+  --  Don't do this if -gnatd.h is set, as this will break the wrapping of
+  --  Cnode in an Expression_With_Actions, see Expand_N_Op_Concat.
 
-  Insert_Action (Cnode,
-Make_Object_Declaration (Loc,
-  Defining_Identifier => Ent,
-  Object_Definition   =>
-Make_Subtype_Indication (Loc,
-  Subtype_Mark => New_Occurrence_Of (Atyp, Loc),
-  Constraint   =>
-Make_Index_Or_Discriminant_Constraint (Loc,
-  Constraints => New_List (
-Make_Range (Loc,
-  Low_Bound  => Low_Bound,
-  High_Bound => High_Bound),
-Suppress => All_Checks);
+  if Atyp = Standard_String
+and then Uses_Sec_Stack (Current_Scope)
+and then RTE_Available (RE_SS_Pool)
+and then not Debug_Flag_Dot_H
+  then
+ --  Generate:
+ -- subtype Axx is ...;
+ -- type Ayy is access Axx;
+ -- Rxx : Ayy := new  [storage_pool = ss_pool];
+ -- Sxx :  renames Rxx.all;
+
+ declare
+Alloc   : Node_Id;
+ConstrT : constant Entity_Id := Make_Temporary (Loc, 'A');
+Acc_Typ : constant Entity_Id := Make_Temporary (Loc, 'A');
+Temp: Entity_Id;
+
+ begin
+Insert_Action (Cnode,
+  Make_Subtype_Declaration (Loc,
+Defining_Identifier => ConstrT,
+Subtype_Indication  => Subtyp_Ind),
+  Suppress => All_Checks);
+Freeze_Itype (ConstrT, Cnode);
+
+Insert_Action (Cnode,
+  Make_Full_Type_Declaration (Loc,
+Defining_Identifier => Acc_Typ,
+Type_Definition =>
+  Make_Access_To_Object_Definition (Loc,
+Subtype_Indication => New_Occurrence_Of (ConstrT, Loc))),
+  Suppress => All_Checks);
+Alloc :=
+  Make_Allocator (Loc,
+Expression => New_Occurrence_Of (ConstrT, Loc));
+Set_Storage_Pool (Alloc, RTE (RE_SS_Pool));
+Set_Procedure_To_Call (Alloc, RTE (RE_SS_Allocate));
+
+Temp := Make_Temporary (Loc, 'R', Alloc);
+Insert_Action (Cnode,
+  Make_Object_Declaration (Loc,
+Defining_Identifier => Temp,
+Object_Definition   => New_Occurrence_Of (Acc_Typ, Loc),
+Expression  => Alloc),
+  Suppress => All_Checks);
+
+

[Ada] SPARK: update for effectively volatile types and objects

2020-10-16 Thread Pierre-Marie de Rodat
SPARK Reference Manual has been updated to allow the use of volatile
types and objects without Async_Writers or Effective_Reads in more
places, as these references are not considered as external effects.

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

gcc/ada/

* sem_prag.adb (Analyze_Global_In_Decl_Part): Update check to
reject volatile object for reading.
* sem_res.adb (Resolve_Actuals, Resolve_Entity_Name): Update
check to reject volatile object for reading.
* sem_util.adb, sem_util.ads
(Check_Nonvolatile_Function_Profile,
Has_Effectively_Volatile_Profile): Detect use of volatile object
for reading.
(Has_Enabled_Property): Accept constants as well.
(Is_Effectively_Volatile_For_Reading): New function based on
existing Is_Effectively_Volatile.
(Is_Effectively_Volatile_Object_For_Reading): Adapted from the
existing Is_Effectively_Volatile_Object, using a shared
implementation in Is_Effectively_Volatile_Object_Shared.diff --git a/gcc/ada/sem_prag.adb b/gcc/ada/sem_prag.adb
--- a/gcc/ada/sem_prag.adb
+++ b/gcc/ada/sem_prag.adb
@@ -2467,10 +2467,11 @@ package body Sem_Prag is
 
elsif SPARK_Mode = On
  and then Ekind (Item_Id) = E_Variable
- and then Is_Effectively_Volatile (Item_Id)
+ and then Is_Effectively_Volatile_For_Reading (Item_Id)
then
-  --  An effectively volatile object cannot appear as a global
-  --  item of a nonvolatile function (SPARK RM 7.1.3(8)).
+  --  An effectively volatile object for reading cannot appear
+  --  as a global item of a nonvolatile function (SPARK RM
+  --  7.1.3(8)).
 
   if Ekind (Spec_Id) in E_Function | E_Generic_Function
 and then not Is_Volatile_Function (Spec_Id)


diff --git a/gcc/ada/sem_res.adb b/gcc/ada/sem_res.adb
--- a/gcc/ada/sem_res.adb
+++ b/gcc/ada/sem_res.adb
@@ -3428,7 +3428,7 @@ package body Sem_Res is
 
   procedure Flag_Effectively_Volatile_Objects (Expr : Node_Id);
   --  Emit an error concerning the illegal usage of an effectively volatile
-  --  object in interfering context (SPARK RM 7.1.3(10)).
+  --  object for reading in interfering context (SPARK RM 7.1.3(10)).
 
   procedure Insert_Default;
   --  If the actual is missing in a call, insert in the actuals list
@@ -3687,7 +3687,7 @@ package body Sem_Res is
   procedure Flag_Effectively_Volatile_Objects (Expr : Node_Id) is
  function Flag_Object (N : Node_Id) return Traverse_Result;
  --  Determine whether arbitrary node N denotes an effectively volatile
- --  object and if it does, emit an error.
+ --  object for reading and if it does, emit an error.
 
  -
  -- Flag_Object --
@@ -3707,9 +3707,7 @@ package body Sem_Res is
Id := Entity (N);
 
if Is_Object (Id)
- and then Is_Effectively_Volatile (Id)
- and then (Async_Writers_Enabled (Id)
-or else Effective_Reads_Enabled (Id))
+ and then Is_Effectively_Volatile_For_Reading (Id)
then
   Error_Msg_N
 ("volatile object cannot appear in this context (SPARK "
@@ -4876,17 +4874,17 @@ package body Sem_Res is
 
 if SPARK_Mode = On and then Comes_From_Source (A) then
 
-   --  An effectively volatile object may act as an actual when the
-   --  corresponding formal is of a non-scalar effectively volatile
-   --  type (SPARK RM 7.1.3(10)).
+   --  An effectively volatile object for reading may act as an
+   --  actual when the corresponding formal is of a non-scalar
+   --  effectively volatile type for reading (SPARK RM 7.1.3(10)).
 
if not Is_Scalar_Type (Etype (F))
- and then Is_Effectively_Volatile (Etype (F))
+ and then Is_Effectively_Volatile_For_Reading (Etype (F))
then
   null;
 
-   --  An effectively volatile object may act as an actual in a
-   --  call to an instance of Unchecked_Conversion.
+   --  An effectively volatile object for reading may act as an
+   --  actual in a call to an instance of Unchecked_Conversion.
--  (SPARK RM 7.1.3(10)).
 
elsif Is_Unchecked_Conversion_Instance (Nam) then
@@ -4894,18 +4892,18 @@ package body Sem_Res is
 
--  The actual denotes an object
 
-   elsif Is_Effectively_Volatile_Object (A) then
+   elsif Is_Effectively_Volatile_Object_For_Reading (A) then
   Error_Msg_N
 ("volatile object cannot act as actual in a call (SPARK "
 

[Ada] GNAT-LLVM unnesting issues in elaboration code

2020-10-16 Thread Pierre-Marie de Rodat
There are cases involving limited class-wide allocators with an
aggregate that result in if-statements in library-level elaboration
code, where parts of the if-statement can contain a nested subprogram at
the outer level of the statement lists, and the subprogram can make
up-level references to objects also declared at the outer statement
level. When Unnest_Subprogram_Mode is enabled, such statement lists are
now wrapped in a procedure body within the if-statement, in a manner
similar to other statements containing nested subprograms (such as block
and loop statements). The possibility of the need for deeper unnesting
within if-statements is also handled here, as well as the situation of
procedures nested within exception handlers of a block statement.

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

gcc/ada/

* exp_ch7.adb (Check_Unnesting_In_Decls_Or_Stmts): In the case
of an if-statement, call Unnest_If_Statement to determine
whether there are nested subprograms in any of the statement
lists of the "if" parts that require a wrapping procedure to
handle possible up-level refeferences.
(Unnest_Block): Call Check_Unnesting_In_Handlers to do unnesting
of subprograms in exception handlers of the block statement.
(Unnest_If_Statement): New procedure to traverse the parts of an
if-statement and create wrapper procedures as needed to
encapsulate nested subprograms that may make up-level
references.
(Check_Stmts_For_Subp_Unnesting): New support procedure in
Unnest_If_Statement to traverse a statement list looking for
top-level subprogram bodies that require wrapping inside a
procedure (via Unnest_Statement_List) as well as possibly having
other statements (block, loop, if) that may themselves require
an unnesting transformation (via
Check_Unnesting_In_Decls_Or_Stmts).
(Unnest_Statement_List): New support procedure to traverse the
statements of a statement list that contains subprogram bodies
at the top level and replace the statement list with a wrapper
procedure body encapsulating the statements and a call to the
procedure.diff --git a/gcc/ada/exp_ch7.adb b/gcc/ada/exp_ch7.adb
--- a/gcc/ada/exp_ch7.adb
+++ b/gcc/ada/exp_ch7.adb
@@ -398,6 +398,31 @@ package body Exp_Ch7 is
--  actions or secondary-stack management, in which case the nested
--  subprogram is a finalizer.
 
+   procedure Unnest_If_Statement (If_Stmt : Node_Id);
+   --  The separate statement lists associated with an if-statement (then part,
+   --  elsif parts, else part) may require unnesting if they directly contain
+   --  a subprogram body that references up-level objects. Each statement list
+   --  is traversed to locate such subprogram bodies, and if a part's statement
+   --  list contains a body, then the list is replaced with a new procedure
+   --  containing the part's statements followed by a call to the procedure.
+   --  Furthermore, any nested blocks, loops, or if statements will also be
+   --  traversed to determine the need for further unnesting transformations.
+
+   procedure Unnest_Statement_List (Stmts : in out List_Id);
+   --  A list of statements that directly contains a subprogram at its outer
+   --  level, that may reference objects declared in that same statement list,
+   --  is rewritten as a procedure containing the statement list Stmts (which
+   --  includes any such objects as well as the nested subprogram), followed by
+   --  a call to the new procedure, and Stmts becomes the list containing the
+   --  procedure and the call. This ensures that Unnest_Subprogram will later
+   --  properly handle up-level references from the nested subprogram to
+   --  objects declared earlier in statement list, by creating an activation
+   --  record and passing it to the nested subprogram. This procedure also
+   --  resets the Scope of objects declared in the statement list, as well as
+   --  the Scope of the nested subprogram, to refer to the new procedure.
+   --  Also, the new procedure is marked Has_Nested_Subprogram, so this should
+   --  only be called when known that the statement list contains a subprogram.
+
procedure Unnest_Loop (Loop_Stmt : Node_Id);
--  Top-level Loops that contain nested subprograms with up-level references
--  need to have activation records. We do this by rewriting the loop as a
@@ -4233,6 +4258,17 @@ package body Exp_Ch7 is
 then
Unnest_Block (Decl_Or_Stmt);
 
+--  If-statements may contain subprogram bodies at the outer level
+--  of their statement lists, and the subprograms may make up-level
+--  references (such as to objects declared in the same statement
+--  list). Unlike block and loop cases, however, we don't have an
+--  entity on which to test the Contains_Subprogram flag, so
+  

Re: Extend builtin fnspecs

2020-10-16 Thread Jan Hubicka
> > @@ -122,7 +201,8 @@ public:
> >  unsigned int idx = arg_idx (i);
> >  gcc_checking_assert (arg_specified_p (i));
> >  return str[idx] == 'w' || str[idx] == 'W'
> > -  || str[idx] == 'R' || str[idx] == 'r';
> > +  || str[idx] == 'r' || str[idx] == 'R'
> > +  || str[idx] == 'o' || str[idx] == 'o';
> 
> Did you mean 
> 
>   || str[idx] == 'o' || str[idx] == 'O';
> 
> here?
Yes, thank you!  It is a lot of ascii-art that is easy to get wrong :(
I also re-checked the new specs and noticed wrong return value of
mempcpy.  Here is updated patch I am re-testing.

2020-10-16  Jan Hubicka  

* attr-fnspec.h: Update toplevel comment.
(attr_fnspec::attr_fnspec): New constructor.
(attr_fnspec::arg_read_p,
attr_fnspec::arg_written_p,
attr_fnspec::arg_access_size_given_by_arg_p,
attr_fnspec::arg_single_access_p
attr_fnspec::loads_known_p
attr_fnspec::stores_known_p,
attr_fnspec::clobbers_errno_p): New member functions.
(gimple_call_fnspec): Declare.
(builtin_fnspec): Declare.
* builtins.c: Include attr-fnspec.h
(builtin_fnspec): New function.
* builtins.def (BUILT_IN_MEMCPY): Do not specify RET1 fnspec.
(BUILT_IN_MEMMOVE): Do not specify RET1 fnspec.
(BUILT_IN_MEMSET): Do not specify RET1 fnspec.
(BUILT_IN_STRCAT): Do not specify RET1 fnspec.
(BUILT_IN_STRCPY): Do not specify RET1 fnspec.
(BUILT_IN_STRNCAT): Do not specify RET1 fnspec.
(BUILT_IN_STRNCPY): Do not specify RET1 fnspec.
(BUILT_IN_MEMCPY_CHK): Do not specify RET1 fnspec.
(BUILT_IN_MEMMOVE_CHK): Do not specify RET1 fnspec.
(BUILT_IN_MEMSET_CHK): Do not specify RET1 fnspec.
(BUILT_IN_STRCAT_CHK): Do not specify RET1 fnspec.
(BUILT_IN_STRCPY_CHK): Do not specify RET1 fnspec.
(BUILT_IN_STRNCAT_CHK): Do not specify RET1 fnspec.
(BUILT_IN_STRNCPY_CHK): Do not specify RET1 fnspec.
* gimple.c (gimple_call_fnspec): Return attr_fnspec.
(gimple_call_arg_flags): Update.
(gimple_call_return_flags): Update.
* tree-ssa-alias.c (check_fnspec): New function.
(ref_maybe_used_by_call_p_1): Use fnspec for builtin handling.
(call_may_clobber_ref_p_1): Likewise.
(attr_fnspec::verify): Update verifier.
* calls.c (decl_fnspec): New function.
(decl_return_flags): Use it.

diff --git a/gcc/attr-fnspec.h b/gcc/attr-fnspec.h
index d38b84a969e..c9421a60095 100644
--- a/gcc/attr-fnspec.h
+++ b/gcc/attr-fnspec.h
@@ -27,11 +27,19 @@
  '.'   specifies that nothing is known.
character 1  specifies additional function properties
  ' 'specifies that nothing is known
+ 'p' or 'P' specifies that function is pure except for described side
+   effects.
+ 'c' or 'C' specifies that function is const except for described side
+   effects.
+ 'b'   specifies that functions is a memory barrier.
+   The uppercase letter in addition specifies that function clobbers errno.
 
character 2+2i specifies properties of argument number i as follows:
  'x' or 'X' specifies that parameter is unused.
  'r' or 'R' specifies that the memory pointed to by the parameter is only
read and does not escape
+ 'o' or 'O' specifies that the memory pointed to by the parameter is only
+   written and does not escape
  'w' or 'W' specifies that the memory pointed to by the parameter does not
escape
  '.'   specifies that nothing is known.
@@ -42,6 +50,10 @@
character 3+2i specifies additional properties of argument number i
as follows:
  ' 'nothing is known
+ 't'   the size of value written/read corresponds to the size of
+   of the pointed-to type of the argument type
+ '1'...'9'  the size of value written/read is given by the specified
+   argument
  */
 
 #ifndef ATTR_FNSPEC_H
@@ -72,6 +84,12 @@ public:
 if (flag_checking)
   verify ();
   }
+  attr_fnspec (const char *str)
+  : str (str), len (strlen (str))
+  {
+if (flag_checking)
+  verify ();
+  }
   attr_fnspec (const_tree identifier)
   : str (TREE_STRING_POINTER (identifier)),
 len (TREE_STRING_LENGTH (identifier))
@@ -79,6 +97,17 @@ public:
 if (flag_checking)
   verify ();
   }
+  attr_fnspec ()
+  : str (NULL), len (0)
+  {
+  }
+
+  /* Return true if fn spec is known.  */
+  bool
+  known_p ()
+  {
+return len;
+  }
 
   /* Return true if arg I is specified.  */
   bool
@@ -94,7 +123,7 @@ public:
   {
 unsigned int idx = arg_idx (i);
 gcc_checking_assert (arg_specified_p (i));
-return str[idx] == 'R' || str[idx] == 'W';
+return str[idx] == 'R' || str[idx] == 'O' || str[idx] == 'W';
   }
 
   /* True if argument is used.  */
@@ -115,6 +144,56 @@ public:
 return str[idx] == 'r' || str[idx] == 'R';
   }
 
+  /* True if 

Re: [PATCH] PR target/96307: Fix KASAN option checking.

2020-10-16 Thread Martin Liška

Hello.

I'm expecting a support for libsanitizer for RISC-V happening soon.
Having that, will we still need this patch?

Thanks,
Martin


Re: [RISC-V] Add support for AddressSanitizer on RISC-V GCC

2020-10-16 Thread Martin Liška

On 8/19/20 11:25 AM, Kito Cheng via Gcc-patches wrote:

Could you update that for RV32, and this patch will be pending until
LLVM accepts the libsanitizer part.


Hello.

I've noticed that the libsanitizer part was accepted to LLVM. I'm planning to do
a merge upstream (for libsanitizer) and was planning to do so in 3 weeks.

I can do it earlier if it helps for the integration and testing purpose?

Thoughts?
Thanks,
Martin


libstdc++: Fix visitor return type diagnostics [PR97499]

2020-10-16 Thread Ville Voutilainen via Gcc-patches
Tested on Linux-PPC64. I haven't tested this with clang yet,
Jonathan, can you help with that? The previous implementation
indeed made an if-constexpr branch invalid for all instantiations
of that branch, this one doesn't - now we have just a dependent static_assert
which is well-formed for correct visitors and ill-formed for incorrect
visitors.

2020-10-16  Ville Voutilainen  

PR libstdc++/97449
* include/std/variant
(__gen_vtable_impl<>::_S_apply_single_alt):
Diagnose visitor return type mismatches here..
(__gen_vtable_impl::_S_apply):
..not here.
diff --git a/libstdc++-v3/include/std/variant b/libstdc++-v3/include/std/variant
index a29c5bf513b..17f8bcd638b 100644
--- a/libstdc++-v3/include/std/variant
+++ b/libstdc++-v3/include/std/variant
@@ -960,9 +960,13 @@ namespace __variant
 	}
 	  else
 	{
-	  __element = __gen_vtable_impl<
+	  auto __tmp_element = __gen_vtable_impl<
 		remove_reference_t,
 		std::index_sequence<__indices..., __index>>::_S_apply();
+	  static_assert(is_same_v<_Tp, decltype(__tmp_element)>,
+			"std::visit requires the visitor to have the same "
+			"return type for all alternatives of a variant");
+	  __element = __tmp_element;
 	}
 	}
 };
@@ -1026,10 +1030,8 @@ namespace __variant
 std::declval<_Variants>()...))>;
 	if constexpr (__visit_ret_type_mismatch)
 	  {
-		static_assert(!__visit_ret_type_mismatch,
-		  "std::visit requires the visitor to have the same "
-		  "return type for all alternatives of a variant");
-		return __nonesuch{};
+		struct __cannot_match {};
+		return __cannot_match{};
 	  }
 	else
 	  return _Array_type{&__visit_invoke};