Re: GCC 8 backports

2019-01-03 Thread Martin Liška
On 1/2/19 12:50 PM, Jan Hubicka wrote:
>>
>> Honza, in order to make the test working I would need to backport
>> r267495. Is it a good idea?
> 
> Yes, my apologies for the mistake! I should stop looking for failures
> via grep and use test_summary consistently since I tend to miss
> unresolved tests.  Old habits are hard to change.
> 
> Honza
>>
>> Thanks,
>> Martin

Hi.

So there's a backport of 3 patches that fix the test-case.
Tested and bootstrapped on x86_64-linux-gnu, I'm going
to install the patches.

Martin
>From 5fd0285a53b7caee98625472adc44cb101bd4873 Mon Sep 17 00:00:00 2001
From: jakub 
Date: Wed, 2 Jan 2019 09:25:59 +
Subject: [PATCH 3/3] Backport r267507

gcc/testsuite/ChangeLog:

2019-01-02  Jakub Jelinek  

	PR ipa/88561
	* g++.dg/tree-prof/devirt.C: Expect _ZThn16 only for lp64 and llp64
	targets and expect _ZThn8 for ilp32 targets.
---
 gcc/testsuite/g++.dg/tree-prof/devirt.C | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/gcc/testsuite/g++.dg/tree-prof/devirt.C b/gcc/testsuite/g++.dg/tree-prof/devirt.C
index 7d6797dd226..3de5dbcf688 100644
--- a/gcc/testsuite/g++.dg/tree-prof/devirt.C
+++ b/gcc/testsuite/g++.dg/tree-prof/devirt.C
@@ -1,4 +1,6 @@
+/* PR ipa/88561 */
 /* { dg-options "-O3 -fdump-tree-dom3-details" } */
+
 struct nsISupports
 {
   virtual int QueryInterface (const int &aIID, void **aInstancePtr) = 0;
@@ -119,5 +121,6 @@ main ()
 __builtin_abort ();
 }
 
-/* { dg-final-use-not-autofdo { scan-tree-dump-times "folding virtual function call to virtual unsigned int mozPersonalDictionary::_ZThn16" 1 "dom3" } } */
+/* { dg-final-use-not-autofdo { scan-tree-dump-times "folding virtual function call to virtual unsigned int mozPersonalDictionary::_ZThn16" 1 "dom3" { target { lp64 || llp64 } } } } */
+/* { dg-final-use-not-autofdo { scan-tree-dump-times "folding virtual function call to virtual unsigned int mozPersonalDictionary::_ZThn8" 1 "dom3" { target ilp32 } } } */
 /* { dg-final-use-not-autofdo { scan-tree-dump-times "folding virtual function call to virtual unsigned int mozPersonalDictionary::AddRef" 1 "dom3" } } */
-- 
2.20.1

>From f3a455cffaee5ac5af2ac188e08c51f3a662491a Mon Sep 17 00:00:00 2001
From: marxin 
Date: Wed, 2 Jan 2019 12:54:23 +0100
Subject: [PATCH 2/3] Backport r267495

gcc/ChangeLog:

2019-01-01  Jan Hubicka  

	* coverage.c (get_coverage_counts): Use current_function_decl.
	* profile.c (read_thunk_profile): New function.
	(branch_prob): Add THUNK parameter.
	* tree-profile.c (tree_profiling): Handle thunks.
	* value-prof.c (init_node_map): Handle thunks.
	* value-prof.h (branch_prob): Upate prototype.
	(read_thunk_profile): Declare.

gcc/testsuite/ChangeLog:

2019-01-01  Jan Hubicka  

	* g++.dg/tree-prof/devirt.C: Update testcase.
---
 gcc/coverage.c  |   2 +-
 gcc/profile.c   | 250 ++--
 gcc/testsuite/g++.dg/tree-prof/devirt.C |   4 +-
 gcc/tree-profile.c  |  28 ++-
 gcc/value-prof.c|   2 +-
 gcc/value-prof.h|   3 +-
 6 files changed, 177 insertions(+), 112 deletions(-)

diff --git a/gcc/coverage.c b/gcc/coverage.c
index 75628b1748f..592d3dcef84 100644
--- a/gcc/coverage.c
+++ b/gcc/coverage.c
@@ -368,7 +368,7 @@ get_coverage_counts (unsigned counter, unsigned expected,
   else
 {
   gcc_assert (coverage_node_map_initialized_p ());
-  elt.ident = cgraph_node::get (cfun->decl)->profile_id;
+  elt.ident = cgraph_node::get (current_function_decl)->profile_id;
 }
   elt.ctr = counter;
   entry = counts_hash->find (&elt);
diff --git a/gcc/profile.c b/gcc/profile.c
index 6fde0fd29d1..eb9f7d52668 100644
--- a/gcc/profile.c
+++ b/gcc/profile.c
@@ -977,6 +977,25 @@ compare_freqs (const void *p1, const void *p2)
   return e2->dest->index - e1->dest->index;
 }
 
+/* Only read execution count for thunks.  */
+
+void
+read_thunk_profile (struct cgraph_node *node)
+{
+  tree old = current_function_decl;
+  current_function_decl = node->decl;
+  gcov_type *counts = get_coverage_counts (GCOV_COUNTER_ARCS, 1, 0, 0, NULL);
+  if (counts)
+{
+  node->callees->count = node->count
+	 = profile_count::from_gcov_type (counts[0]);
+  free (counts);
+}
+  current_function_decl = old;
+  return;
+}
+
+
 /* Instrument and/or analyze program behavior based on program the CFG.
 
This function creates a representation of the control flow graph (of
@@ -997,7 +1016,7 @@ compare_freqs (const void *p1, const void *p2)
Main entry point of this file.  */
 
 void
-branch_prob (void)
+branch_prob (bool thunk)
 {
   basic_block bb;
   unsigned i;
@@ -1012,118 +1031,121 @@ branch_prob (void)
   flow_call_edges_add (NULL);
   add_noreturn_fake_exit_edges ();
 
-  /* We can't handle cyclic regions constructed using abnormal edges.
- To avoid these we replace every source of abnormal edge by a fake
- edge from entry node and every destination by fake edge to exit.
- This keeps g

Re: [Patch 3/4][Aarch64] v2: Implement Aarch64 SIMD ABI

2019-01-03 Thread Richard Sandiford
Steve Ellcey  writes:
> Here is an update of this patch.  I believe I addressed all of the
> issues you raised.  Thanks for the new target.def description, it
> seems much clearer than mine.  I did a full build and test on x86 as
> well as aarch64 to make sure that architectures that do not define
> TARGET_REMOVE_EXTRA_CALL_PRESERVED_REGS build correctly.
>
> Steve Ellcey
> sell...@marvell.com
>
>
> 2019-01-02  Steve Ellcey  
>
>   * config/aarch64/aarch64.c (aarch64_simd_call_p): New function.
>   (aarch64_remove_extra_call_preserved_regs): New function.
>   (TARGET_REMOVE_EXTRA_CALL_PRESERVED_REGS): New macro.
>   * doc/tm.texi.in (TARGET_REMOVE_EXTRA_CALL_PRESERVED_REGS): New hook.
>   * final.c (get_call_reg_set_usage): Call new hook.
>   * target.def (remove_extra_call_preserved_regs): New hook.
>   * targhooks.c (default_remove_extra_call_preserved_regs): New function.
>   * targhooks.h (default_remove_extra_call_preserved_regs): New function.

OK, thanks.

Richard


Re: [nvptx] vector length patch series -- openacc parts

2019-01-03 Thread Tom de Vries
On 18-12-18 00:52, Tom de Vries wrote:
> On 14-12-18 20:58, Tom de Vries wrote:
> 
>> 0003-openacc-Add-target-hook-TARGET_GOACC_ADJUST_PARALLEL.patch
> 

Hi Thomas,

ping. OK for trunk?

Thanks,
- Tom


[PATCH] genattrtab bit-rot, and if_then_else in values

2019-01-03 Thread Alan Modra
This patch started off just by adding if_then_else support in
write_attr_value to be able to write a saner expression for powerpc
tls_gdld_nomark length. (*)  Then I noticed bit-rot in functions used
to calculate insn_default_length, insn_min_length, and length_unit_log
(which are used by the shorten_branches pass).  These functions
don't handle a const_int length value and return an "unknown" status
that isn't used, or in the case of or_attr_value, doesn't need to be
used.  min_attr_value also attempts to return INT_MAX for the
unhandled rtl case, but this can get lost in recursive calls.  I fixed
that problem by returning INT_MIN instead, and translating that to
INT_MAX in the only caller of min_attr_value.

Bootstrapped and regression tested powerpc64le-linux and x86_64-linux.
OK to apply?

* genattrtab.c (max_attr_value, min_attr_value, or_attr_value):
Delete "unknownp" parameter.  Adjust callers.  Handle
CONST_INT and PLUS.
(min_attr_value): Return INT_MIN for unhandled rtl case..
(min_fn): ..and translate to INT_MAX here.
(write_length_unit_log): Modify to cope without "unknown".
(write_attr_value): Handle IF_THEN_ELSE.

*) I want to use something like the following in a fix for PR88614.

   (set (attr "length")
 (plus (if_then_else (match_test "TARGET_CMODEL != CMODEL_SMALL")
 (const_int 8)
 (const_int 4))
   (plus (if_then_else (match_test "GET_CODE (operands[1]) != 
SYMBOL_REF")
   (plus (if_then_else (match_test 
"!rs6000_speculate_indirect_jumps")
   (const_int 4)
   (const_int 0))
 (if_then_else (match_test "DEFAULT_ABI == 
ABI_AIX")
   (const_int 4)
   (const_int 0)))
   (const_int 0))
 (if_then_else (match_test "DEFAULT_ABI != ABI_V4")
   (const_int 8)
   (const_int 4)

diff --git a/gcc/genattrtab.c b/gcc/genattrtab.c
index 2cd04cdb06f..c86b3587cd9 100644
--- a/gcc/genattrtab.c
+++ b/gcc/genattrtab.c
@@ -266,9 +266,9 @@ static int compares_alternatives_p (rtx);
 static void make_internal_attr (const char *, rtx, int);
 static void insert_insn_ent(struct attr_value *, struct insn_ent *);
 static void walk_attr_value   (rtx);
-static int max_attr_value (rtx, int*);
-static int min_attr_value (rtx, int*);
-static int or_attr_value  (rtx, int*);
+static int max_attr_value (rtx);
+static int min_attr_value (rtx);
+static int or_attr_value  (rtx);
 static rtx simplify_test_exp  (rtx, int, int);
 static rtx simplify_test_exp_in_temp (rtx, int, int);
 static rtx copy_rtx_unchanging(rtx);
@@ -1550,15 +1550,16 @@ one_fn (rtx exp ATTRIBUTE_UNUSED)
 static rtx
 max_fn (rtx exp)
 {
-  int unknown;
-  return make_numeric_value (max_attr_value (exp, &unknown));
+  return make_numeric_value (max_attr_value (exp));
 }
 
 static rtx
 min_fn (rtx exp)
 {
-  int unknown;
-  return make_numeric_value (min_attr_value (exp, &unknown));
+  int val = min_attr_value (exp);
+  if (val < 0)
+val = INT_MAX;
+  return make_numeric_value (val);
 }
 
 static void
@@ -1568,24 +1569,20 @@ write_length_unit_log (FILE *outf)
   struct attr_value *av;
   struct insn_ent *ie;
   unsigned int length_unit_log, length_or;
-  int unknown = 0;
 
+  length_or = ~0;
   if (length_attr)
 {
-  length_or = or_attr_value (length_attr->default_val->value, &unknown);
+  length_or = or_attr_value (length_attr->default_val->value);
   for (av = length_attr->first_value; av; av = av->next)
for (ie = av->first_insn; ie; ie = ie->next)
- length_or |= or_attr_value (av->value, &unknown);
+ length_or |= or_attr_value (av->value);
 }
 
-  if (length_attr == NULL || unknown)
-length_unit_log = 0;
-  else
-{
-  length_or = ~length_or;
-  for (length_unit_log = 0; length_or & 1; length_or >>= 1)
-   length_unit_log++;
-}
+  length_or = ~length_or;
+  for (length_unit_log = 0; length_or & 1; length_or >>= 1)
+length_unit_log++;
+
   fprintf (outf, "EXPORTED_CONST int length_unit_log = %u;\n", 
length_unit_log);
 }
 
@@ -3753,11 +3750,11 @@ write_test_expr (FILE *outf, rtx exp, unsigned int 
attrs_cached, int flags,
   return attrs_cached;
 }
 
-/* Given an attribute value, return the maximum CONST_STRING argument
-   encountered.  Set *UNKNOWNP and return INT_MAX if the value is unknown.  */
+/* Given an attribute value, return the maximum CONST_INT or CONST_STRING
+   argument encountered.  Return INT_MAX if the value is unknown.  */
 
 static int
-max_attr_value (rtx exp, int *unknownp)
+max_attr_value (rtx exp)
 {
   int current_max;
   in

Re: [Fortran, test case, committed] Test case for PR 48543

2019-01-03 Thread Jakub Jelinek
On Wed, Jan 02, 2019 at 04:31:49PM +0100, Thomas Koenig wrote:
> Hell world,
> 
> somebody fixed PR 48543 for us, so I have committed the
> attached test case as obvious and closed the PR.  Thanks
> to however did this!

Nobody actually fixed this and the testcase fails e.g. on i686-linux.
The reason why you don't see the 'Supercalifragilis' string on x86_64
is that the expansion decides to emit the memcpy of the first string
using move_by_pieces and it emits:
movaps  .LC3(%rip), %xmm0
movb$115, 29(%rsp)
...
movups  %xmm0, 13(%rsp)
...
.LC3:
.quad   7809632571816441171
.quad   7596562564204619369
so the Supercalifragilis is there, but not in a greppable form.
The above two numbers are in hex
0x6c61637265707553
0x696c696761726669
where you can already see the ascii characters.

The reason why the middle-end doesn't and can't do anything about these is
that the Fortran FE is representing those to the middle-end as
zero-terminated strings.  For those it can only do tail merging, but even
that is deferred to the linker, which does this for SHF_MERGE | SHF_STRINGS
sections.  So, e.g. C "foobar" can be merged with "blahblahfoobar", by
replacing relocations against "foobar" with "blahblahfoobar" + 8.

Fortran doesn't have zero terminated strings, so the FE could do arbitrary
substring merging if it processes all functions e.g. through FE
optimizations before actually handing them over to the middle-end (at which
point it would turn them into zero terminated strings).
The linker doesn't offer anything that could help here though, so it would
still be limited to single TU only.  Another question is how to implement it
efficiently.  For tail merging ld.bfd or ld.gold has an algorithm, but for
the general substring merging, would you e.g. use a hash table hashed by
each 4? consecutive characters to filter out strings that are certainly not
containing that substring (plus length check), and then use say Boyer-Moore
algorithm to search for the substrings in the strings that could contain it.
Perhaps also hash table based on each present character for shorter strings.
Another thing is that it should be independent of the order in which it is
looked up, so if you first enter "foo" and then "foobar", it should still
point "foo" to "foobar" + 3.  And, you might consider even partial overlaps,
like if the source refers to "foobar" and "barbaz", you could emit
"foobarbaz" and point "barbaz" at "foobarbaz" + 3.
Another thing to consider is string alignment, some targets make sure string
constants have higher alignment so that e.g. memcpy etc. from those can be
vectorized or implemented efficiently using aligned multi-byte reads/stores,
by doing arbitrary string merging more strings might be not aligned.

In any case, IMHO the test should be removed or XFAILed for now.

> 2019-01-02  Thomas Koenig  
> 
>   PR fortran/48543
>   * gfortran.dg/const_chararacter_merge.f90: New test.

> ! { dg-do compile }
> ! { dg-options "-Os" }
> ! PR 48543
> program main
>   character(len=17) :: a
>   character(len=34) :: b
>   a = 'Supercalifragilis'
>   b = 'Supercalifragilisticexpialidocious'
>   print *,a," ",b
> end program main
> ! { dg-final { scan-assembler-times "Supercalifragilis" 1 } }


Jakub


[PATCH] Add __builtin_convertvector support (PR c++/85052)

2019-01-03 Thread Jakub Jelinek
Hi!

The following patch adds support for the __builtin_convertvector builtin.
C casts on generic vectors are just reinterpretation of the bits (i.e. a
VCE), this builtin allows to cast int/unsigned elements to float or vice
versa or promote/demote them.  doc/ change is missing, will write it soon.

The builtin appeared in I think clang 3.4 and is apparently in real-world
use as e.g. Honza reported.  The first argument is an expression with vector
type, the second argument is a vector type (similarly e.g. to va_arg), to
which the first argument should be converted.  Both vector types need to
have the same number of elements.

I've implemented same element size (thus also whole vector size) conversions
efficiently - signed to unsigned and vice versa or same vector type just
using a VCE, for e.g. int <-> float or long long <-> double using
appropriate optab, possibly repeated multiple times for very large vectors.
For everything there is a fallback to lower __builtin_convertvector (x, t)
as { (__typeof (t[0])) x[0], (__typeof (t[1])) x[1], ... }.

What isn't implemented efficiently (yet) are the narrowing or widening
conversions; the optabs we have are meant for same size vectors, so
for the packing we have 2 arguments that we pack into 1, for unpacking we
have those lo/hi variants, but in this case at least for the most common
vectors we have just one argument and want result with the same number of
elements.  The AVX* different vector size instructions is the thing that
does this most efficiently, of course for large generic vectors we can
easily use these optabs.  Shall we go for e.g. trying to pack the argument
and all zeros dummy operand and pick the low half of the result vector,
or pick the low and high halves of the argument and use a half sized vector
operations, or both?

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

2019-01-03  Jakub Jelinek  

PR c++/85052
* tree-vect-generic.c (expand_vector_piecewise): Add defaulted
ret_type argument, if non-NULL, use that in preference to type
for the result type.
(expand_vector_parallel): Formatting fix.
(do_vec_conversion, expand_vector_conversion): New functions.
(expand_vector_operations_1): Call expand_vector_conversion
for VEC_CONVERT ifn calls.
* internal-fn.def (VEC_CONVERT): New internal function.
* internal-fn.c (expand_VEC_CONVERT): New function.
* fold-const-call.c (fold_const_vec_convert): New function.
(fold_const_call): Use it for CFN_VEC_CONVERT.
c-family/
* c-common.h (enum rid): Add RID_BUILTIN_CONVERTVECTOR.
(c_build_vec_convert): Declare.
* c-common.c (c_build_vec_convert): New function.
c/
* c-parser.c (c_parser_postfix_expression): Parse
__builtin_convertvector.
cp/
* cp-tree.h (cp_build_vec_convert): Declare.
* parser.c (cp_parser_postfix_expression): Parse
__builtin_convertvector.
* constexpr.c: Include fold-const-call.h.
(cxx_eval_internal_function): Handle IFN_VEC_CONVERT.
(potential_constant_expression_1): Likewise.
* semantics.c (cp_build_vec_convert): New function.
* pt.c (tsubst_copy_and_build): Handle CALL_EXPR to
IFN_VEC_CONVERT.
testsuite/
* c-c++-common/builtin-convertvector-1.c: New test.
* c-c++-common/torture/builtin-convertvector-1.c: New test.
* g++.dg/ext/builtin-convertvector-1.C: New test.
* g++.dg/cpp0x/constexpr-builtin4.C: New test.

--- gcc/tree-vect-generic.c.jj  2019-01-01 12:37:17.084976148 +0100
+++ gcc/tree-vect-generic.c 2019-01-02 17:51:28.012876543 +0100
@@ -267,7 +267,8 @@ do_negate (gimple_stmt_iterator *gsi, tr
 static tree
 expand_vector_piecewise (gimple_stmt_iterator *gsi, elem_op_func f,
 tree type, tree inner_type,
-tree a, tree b, enum tree_code code)
+tree a, tree b, enum tree_code code,
+tree ret_type = NULL_TREE)
 {
   vec *v;
   tree part_width = TYPE_SIZE (inner_type);
@@ -278,23 +279,27 @@ expand_vector_piecewise (gimple_stmt_ite
   int i;
   location_t loc = gimple_location (gsi_stmt (*gsi));
 
-  if (types_compatible_p (gimple_expr_type (gsi_stmt (*gsi)), type))
+  if (ret_type
+  || types_compatible_p (gimple_expr_type (gsi_stmt (*gsi)), type))
 warning_at (loc, OPT_Wvector_operation_performance,
"vector operation will be expanded piecewise");
   else
 warning_at (loc, OPT_Wvector_operation_performance,
"vector operation will be expanded in parallel");
 
+  if (!ret_type)
+ret_type = type;
   vec_alloc (v, (nunits + delta - 1) / delta);
   for (i = 0; i < nunits;
i += delta, index = int_const_binop (PLUS_EXPR, index, part_width))
 {
-  tree result = f (gsi, inner_type, a, b, index, part_width, code, type);
+  tree result = f (gsi, inner_type, a, b, index, part_width

[PATCH] Avoid sizetype in .debug_pubtypes (PR debug/88644)

2019-01-03 Thread Jakub Jelinek
Hi!

Some time ago I've changed modified_type_die, so that it doesn't emit
the internal "sizetype" type as DW_TAG_base_type, but instead emits the
underlying type (e.g. "long unsigned int" or whatever the target has).
This PR complains that when .debug_pubtypes is emitted, we still refer to it
through "sizetype" name, and the "sizetype" .debug_pubtypes entry points to
a DW_TAG_base_type with "long unsigned int" name (or similar).

The following patch makes sure it doesn't appear even in .debug_pubtypes.

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

2019-01-03  Jakub Jelinek  

PR debug/88644
* dwarf2out.c (modified_type_die): If type is equal to sizetype,
change it to qualified_type.

* gcc.dg/debug/dwarf2/pr88644.c: New test.
* gcc.dg/debug/dwarf2/pr80263.c: Remove darwin hack.

2019-01-03  Iain Sandoe  

* gcc.dg/pubtypes-2.c: Adjust expected pubtypes length.
* gcc.dg/pubtypes-3.c: Likewise.
* gcc.dg/pubtypes-4.c: Likewise.

--- gcc/dwarf2out.c.jj  2019-01-01 12:37:16.113992080 +0100
+++ gcc/dwarf2out.c 2019-01-02 20:07:48.591193291 +0100
@@ -13152,6 +13152,8 @@ modified_type_die (tree type, int cv_qua
   && TYPE_PRECISION (sizetype) == TYPE_PRECISION (size_type_node)
   && TYPE_UNSIGNED (sizetype) == TYPE_UNSIGNED (size_type_node))
qualified_type = size_type_node;
+  if (type == sizetype)
+   type = qualified_type;
 }
 
   /* If we do, then we can just use its DIE, if it exists.  */
--- gcc/testsuite/gcc.dg/debug/dwarf2/pr88644.c.jj  2019-01-02 
20:12:53.284261470 +0100
+++ gcc/testsuite/gcc.dg/debug/dwarf2/pr88644.c 2019-01-02 20:13:24.238760419 
+0100
@@ -0,0 +1,7 @@
+/* PR debug/88644 */
+/* { dg-do compile } */
+/* { dg-options "-gdwarf-4 -dA -gpubnames" } */
+
+char array[1];
+
+/* { dg-final { scan-assembler-not {\msizetype} } } */
--- gcc/testsuite/gcc.dg/debug/dwarf2/pr80263.c.jj  2018-08-26 
22:41:31.095644328 +0200
+++ gcc/testsuite/gcc.dg/debug/dwarf2/pr80263.c 2019-01-02 20:13:03.779091593 
+0100
@@ -1,8 +1,6 @@
 /* PR debug/80263 */
 /* { dg-do compile } */
 /* { dg-options "-g -dA" } */
-/* Darwin emits pubnames/types by default - suppress this for the test. */
-/* { dg-additional-options "-gno-pubnames" { target *-*-darwin* } }  */
 
 char array[1];
 
--- gcc/testsuite/gcc.dg/pubtypes-2.c.jj2017-06-19 10:39:09.583276388 
+0200
+++ gcc/testsuite/gcc.dg/pubtypes-2.c   2019-01-02 22:05:30.933780939 +0100
@@ -2,7 +2,7 @@
 /* { dg-options "-O0 -gdwarf-2 -dA" } */
 /* { dg-skip-if "Unmatchable assembly" { mmix-*-* } } */
 /* { dg-final { scan-assembler "__debug_pubtypes" } } */
-/* { dg-final { scan-assembler "long+\[ \t\]+0x13b+\[ \t\]+\[#;]+\[ \t\]+Pub 
Info Length" } } */
+/* { dg-final { scan-assembler "long+\[ \t\]+0x12e+\[ \t\]+\[#;]+\[ \t\]+Pub 
Info Length" } } */
 /* { dg-final { scan-assembler "used_struct0\"+\[ \t\]+\[#;]+\[ 
\t\]+external name" } } */
 /* { dg-final { scan-assembler-not "unused_struct0\"+\[ \t\]+\[#;]+\[ 
\t\]+external name" } } */
 
--- gcc/testsuite/gcc.dg/pubtypes-3.c.jj2017-06-19 10:39:09.725274700 
+0200
+++ gcc/testsuite/gcc.dg/pubtypes-3.c   2019-01-02 22:03:53.044367518 +0100
@@ -2,7 +2,7 @@
 /* { dg-options "-O0 -gdwarf-2 -dA" } */
 /* { dg-skip-if "Unmatchable assembly" { mmix-*-* } } */
 /* { dg-final { scan-assembler "__debug_pubtypes" } } */
-/* { dg-final { scan-assembler "long+\[ \t\]+0x13b+\[ \t\]+\[#;]+\[ \t\]+Pub 
Info Length" } } */
+/* { dg-final { scan-assembler "long+\[ \t\]+0x12e+\[ \t\]+\[#;]+\[ \t\]+Pub 
Info Length" } } */
 /* { dg-final { scan-assembler "used_struct0\"+\[ \t\]+\[#;]+\[ 
\t\]+external name" } } */
 /* { dg-final { scan-assembler-not "unused_struct0\"+\[ \t\]+\[#;]+\[ 
\t\]+external name" } } */
 /* { dg-final { scan-assembler-not "\"list_name_type0\"+\[ \t\]+\[#;]+\[ 
\t\]+external name" } } */
--- gcc/testsuite/gcc.dg/pubtypes-4.c.jj2017-06-19 10:39:09.434278158 
+0200
+++ gcc/testsuite/gcc.dg/pubtypes-4.c   2019-01-02 22:03:53.044367518 +0100
@@ -2,7 +2,7 @@
 /* { dg-options "-O0 -gdwarf-2 -dA" } */
 /* { dg-skip-if "Unmatchable assembly" { mmix-*-* } } */
 /* { dg-final { scan-assembler "__debug_pubtypes" } } */
-/* { dg-final { scan-assembler "long+\[ \t\]+0x172+\[ \t\]+\[#;]+\[ \t\]+Pub 
Info Length" } } */
+/* { dg-final { scan-assembler "long+\[ \t\]+0x165+\[ \t\]+\[#;]+\[ \t\]+Pub 
Info Length" } } */
 /* { dg-final { scan-assembler "used_struct0\"+\[ \t\]+\[#;]+\[ 
\t\]+external name" } } */
 /* { dg-final { scan-assembler-not "unused_struct0\"+\[ \t\]+\[#;]+\[ 
\t\]+external name" } } */
 /* { dg-final { scan-assembler "\"list_name_type0\"+\[ \t\]+\[#;]+\[ 
\t\]+external name" } } */

Jakub


Fix profile merging for thunks

2019-01-03 Thread Jan Hubicka
Hi,
testing of Firefox has uncovered an ICE which I introduced by the patch
to fix profile of thunks.  The problem is that ipa_merge_profile may try
to merge profile of thunks and end up with attempting to touch their
gimple body.

This patch implements merging of profile of thunks and I also added
aliases because these also have no body and merging can happen.

Bootstrapped/regtested x86_64-linux, comitted.

* ipa-utils.c (scale_ipa_profile_for_fn): Break out from ...
(ipa_merge_profiles): ... here; do not ICE on thunks and aliases.
Index: ipa-utils.c
===
--- ipa-utils.c (revision 267499)
+++ ipa-utils.c (working copy)
@@ -375,6 +375,20 @@ get_base_var (tree t)
   return t;
 }
 
+/* Scale function of calls in NODE by ratio ORIG_COUNT/NODE->count.  */
+
+void
+scale_ipa_profile_for_fn (struct cgraph_node *node, profile_count orig_count)
+{
+  profile_count to = node->count;
+  profile_count::adjust_for_ipa_scaling (&to, &orig_count);
+  struct cgraph_edge *e;
+  
+  for (e = node->callees; e; e = e->next_callee)
+e->count = e->count.apply_scale (to, orig_count);
+  for (e = node->indirect_calls; e; e = e->next_callee)
+e->count = e->count.apply_scale (to, orig_count);
+}
 
 /* SRC and DST are going to be merged.  Take SRC's profile and merge it into
DST so it is not going to be lost.  Possibly destroy SRC's body on the way
@@ -424,6 +438,14 @@ ipa_merge_profiles (struct cgraph_node *
   else 
 dst->count = src->count.ipa ();
 
+  /* First handle functions with no gimple body.  */
+  if (dst->thunk.thunk_p || dst->alias
+  || src->thunk.thunk_p || src->alias)
+{
+  scale_ipa_profile_for_fn (dst, orig_count);
+  return;
+}
+
   /* This is ugly.  We need to get both function bodies into memory.
  If declaration is merged, we need to duplicate it to be able
  to load body that is being replaced.  This makes symbol table
@@ -652,16 +674,7 @@ ipa_merge_profiles (struct cgraph_node *
   /* We can't update CFG profile, but we can scale IPA profile. CFG
  will be scaled according to dst->count after IPA passes.  */
   else
-{
-  profile_count to = dst->count;
-  profile_count::adjust_for_ipa_scaling (&to, &orig_count);
-  struct cgraph_edge *e;
-  
-  for (e = dst->callees; e; e = e->next_callee)
-   e->count = e->count.apply_scale (to, orig_count);
-  for (e = dst->indirect_calls; e; e = e->next_callee)
-   e->count = e->count.apply_scale (to, orig_count);
-}
+scale_ipa_profile_for_fn (dst, orig_count);
   src->decl = oldsrcdecl;
 }
 


Re: [PATCH] Add __builtin_convertvector support (PR c++/85052)

2019-01-03 Thread Marc Glisse

On Thu, 3 Jan 2019, Jakub Jelinek wrote:


The following patch adds support for the __builtin_convertvector builtin.
C casts on generic vectors are just reinterpretation of the bits (i.e. a
VCE), this builtin allows to cast int/unsigned elements to float or vice
versa or promote/demote them.  doc/ change is missing, will write it soon.

The builtin appeared in I think clang 3.4 and is apparently in real-world
use as e.g. Honza reported.  The first argument is an expression with vector
type, the second argument is a vector type (similarly e.g. to va_arg), to
which the first argument should be converted.  Both vector types need to
have the same number of elements.

I've implemented same element size (thus also whole vector size) conversions
efficiently - signed to unsigned and vice versa or same vector type just
using a VCE, for e.g. int <-> float or long long <-> double using
appropriate optab, possibly repeated multiple times for very large vectors.


Hello,

IIUC, you only lower __builtin_convertvector to VCE or FLOAT_EXPR or 
whatever in tree-vect-generic. That seems quite late. At least for the 
"easy" same-size case, I think we should do it early (gimplification?), 
before we start optimizing, without checking if it is supported by the 
target (generic lowering can fix that up later). Of course that can be 
changed later, getting the basic functionality comes first.


(while you are writing the doc patch: tree.def and generic.texi do not say 
anything about using FLOAT_EXPR on a vector)


--
Marc Glisse


[RFC/PATCH] gcc.c: access does not work in new msvcr for nul file

2019-01-03 Thread Johannes Pfau
Hello list,

I'm currently adding D support to the MinGW targets. As the libphobos
upstream only targets newer msvcr runtime libraries, I tried building
GCC against libmsvcr120. When doing that, the build fails when building 
s-selftest-c++:

/home/jpfau/mingw-gcc-trunk/x86_64-trunk-win32-seh-rt_v6/build/gcc-trunk/./gcc/xgcc
 \

-B/home/jpfau/mingw-gcc-trunk/x86_64-trunk-win32-seh-rt_v6/build/gcc-trunk/./gcc/
 \
-xc++ -nostdinc nul -S -o nul 
-fself-test=../../../../src/gcc-trunk/gcc/testsuite/selftests
xgcc.exe: error: nul: Invalid argument
xgcc.exe: warning: '-x c' after last input file has no effect
xgcc.exe: fatal error: no input files
compilation terminated.
make[2]: *** [../../../../src/gcc-trunk/gcc/cp/Make-lang.in:178: 
s-selftest-c++] Error 1

Debugging shows that the access function used to check
if the input files exist has different behavior in newer msvcr libraries:
It does return proper results for the 'nul' file in the old msvcrt.dll
but in newer libraries it returns EINVAL for the nul file.

I can think of at least two possible solutions:
1) Manually strcmp the input to find nul files. As far as I know there
   are many paths which count as nul files on windows, so it might be
   difficult to actually properly support all valid paths.
2) Use the windows API to check if the file exists.

A RFC patch for 2) is attached. I guess we don't want such platform
specific code in GCC, so any recommendation how to proceed? Should
this be placed in libiberty as a generic
int file_exists(const char *path, **error) instead?

Best regards,
Johannes

---
 gcc/gcc.c | 22 --
 1 file changed, 20 insertions(+), 2 deletions(-)

diff --git a/gcc/gcc.c b/gcc/gcc.c
index 955a08cc8e8..674313facf1 100644
--- a/gcc/gcc.c
+++ b/gcc/gcc.c
@@ -45,6 +45,10 @@ compilation is specified by a string called a "spec".  */
 #include "filenames.h"
 #include "spellcheck.h"
 
+#ifdef _WIN32
+#include 
+#endif
+
 
 
 /* Manage the manipulation of env vars.
@@ -4552,12 +4556,26 @@ process_command (unsigned int decoded_options_count,
  else
fname = xstrdup (arg);
 
-  if (strcmp (fname, "-") != 0 && access (fname, F_OK) < 0)
+#ifdef _WIN32
+ // _access does not work for the nul file on newer msvc versions
+ if (strcmp (fname, "-") != 0 && GetFileAttributes(fname) == 
INVALID_FILE_ATTRIBUTES)
+   {
+ bool resp = fname[0] == '@'
+ && GetFileAttributes(fname + 1) == INVALID_FILE_ATTRIBUTES;
+
+ char error_msg[256] = "\0";
+ FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), 
0,
+   (LPSTR)&error_msg, 256, NULL);
+ error ("%s: %s", fname + resp, error_msg);
+   }
+#else
+ if (strcmp (fname, "-") != 0 && access (fname, F_OK) < 0)
{
  bool resp = fname[0] == '@' && access (fname + 1, F_OK) < 0;
  error ("%s: %m", fname + resp);
}
-  else
+#endif
+ else
add_infile (arg, spec_lang);
 
   free (fname);
-- 
2.19.2



Re: [PATCH] Avoid sizetype in .debug_pubtypes (PR debug/88644)

2019-01-03 Thread Richard Biener
On Thu, 3 Jan 2019, Jakub Jelinek wrote:

> Hi!
> 
> Some time ago I've changed modified_type_die, so that it doesn't emit
> the internal "sizetype" type as DW_TAG_base_type, but instead emits the
> underlying type (e.g. "long unsigned int" or whatever the target has).
> This PR complains that when .debug_pubtypes is emitted, we still refer to it
> through "sizetype" name, and the "sizetype" .debug_pubtypes entry points to
> a DW_TAG_base_type with "long unsigned int" name (or similar).
> 
> The following patch makes sure it doesn't appear even in .debug_pubtypes.
> 
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

OK.

> 2019-01-03  Jakub Jelinek  
> 
>   PR debug/88644
>   * dwarf2out.c (modified_type_die): If type is equal to sizetype,
>   change it to qualified_type.
> 
>   * gcc.dg/debug/dwarf2/pr88644.c: New test.
>   * gcc.dg/debug/dwarf2/pr80263.c: Remove darwin hack.
> 
> 2019-01-03  Iain Sandoe  
> 
>   * gcc.dg/pubtypes-2.c: Adjust expected pubtypes length.
>   * gcc.dg/pubtypes-3.c: Likewise.
>   * gcc.dg/pubtypes-4.c: Likewise.
> 
> --- gcc/dwarf2out.c.jj2019-01-01 12:37:16.113992080 +0100
> +++ gcc/dwarf2out.c   2019-01-02 20:07:48.591193291 +0100
> @@ -13152,6 +13152,8 @@ modified_type_die (tree type, int cv_qua
>  && TYPE_PRECISION (sizetype) == TYPE_PRECISION (size_type_node)
>  && TYPE_UNSIGNED (sizetype) == TYPE_UNSIGNED (size_type_node))
>   qualified_type = size_type_node;
> +  if (type == sizetype)
> + type = qualified_type;
>  }
>  
>/* If we do, then we can just use its DIE, if it exists.  */
> --- gcc/testsuite/gcc.dg/debug/dwarf2/pr88644.c.jj2019-01-02 
> 20:12:53.284261470 +0100
> +++ gcc/testsuite/gcc.dg/debug/dwarf2/pr88644.c   2019-01-02 
> 20:13:24.238760419 +0100
> @@ -0,0 +1,7 @@
> +/* PR debug/88644 */
> +/* { dg-do compile } */
> +/* { dg-options "-gdwarf-4 -dA -gpubnames" } */
> +
> +char array[1];
> +
> +/* { dg-final { scan-assembler-not {\msizetype} } } */
> --- gcc/testsuite/gcc.dg/debug/dwarf2/pr80263.c.jj2018-08-26 
> 22:41:31.095644328 +0200
> +++ gcc/testsuite/gcc.dg/debug/dwarf2/pr80263.c   2019-01-02 
> 20:13:03.779091593 +0100
> @@ -1,8 +1,6 @@
>  /* PR debug/80263 */
>  /* { dg-do compile } */
>  /* { dg-options "-g -dA" } */
> -/* Darwin emits pubnames/types by default - suppress this for the test. */
> -/* { dg-additional-options "-gno-pubnames" { target *-*-darwin* } }  */
>  
>  char array[1];
>  
> --- gcc/testsuite/gcc.dg/pubtypes-2.c.jj  2017-06-19 10:39:09.583276388 
> +0200
> +++ gcc/testsuite/gcc.dg/pubtypes-2.c 2019-01-02 22:05:30.933780939 +0100
> @@ -2,7 +2,7 @@
>  /* { dg-options "-O0 -gdwarf-2 -dA" } */
>  /* { dg-skip-if "Unmatchable assembly" { mmix-*-* } } */
>  /* { dg-final { scan-assembler "__debug_pubtypes" } } */
> -/* { dg-final { scan-assembler "long+\[ \t\]+0x13b+\[ \t\]+\[#;]+\[ \t\]+Pub 
> Info Length" } } */
> +/* { dg-final { scan-assembler "long+\[ \t\]+0x12e+\[ \t\]+\[#;]+\[ \t\]+Pub 
> Info Length" } } */
>  /* { dg-final { scan-assembler "used_struct0\"+\[ \t\]+\[#;]+\[ 
> \t\]+external name" } } */
>  /* { dg-final { scan-assembler-not "unused_struct0\"+\[ \t\]+\[#;]+\[ 
> \t\]+external name" } } */
>  
> --- gcc/testsuite/gcc.dg/pubtypes-3.c.jj  2017-06-19 10:39:09.725274700 
> +0200
> +++ gcc/testsuite/gcc.dg/pubtypes-3.c 2019-01-02 22:03:53.044367518 +0100
> @@ -2,7 +2,7 @@
>  /* { dg-options "-O0 -gdwarf-2 -dA" } */
>  /* { dg-skip-if "Unmatchable assembly" { mmix-*-* } } */
>  /* { dg-final { scan-assembler "__debug_pubtypes" } } */
> -/* { dg-final { scan-assembler "long+\[ \t\]+0x13b+\[ \t\]+\[#;]+\[ \t\]+Pub 
> Info Length" } } */
> +/* { dg-final { scan-assembler "long+\[ \t\]+0x12e+\[ \t\]+\[#;]+\[ \t\]+Pub 
> Info Length" } } */
>  /* { dg-final { scan-assembler "used_struct0\"+\[ \t\]+\[#;]+\[ 
> \t\]+external name" } } */
>  /* { dg-final { scan-assembler-not "unused_struct0\"+\[ \t\]+\[#;]+\[ 
> \t\]+external name" } } */
>  /* { dg-final { scan-assembler-not "\"list_name_type0\"+\[ \t\]+\[#;]+\[ 
> \t\]+external name" } } */
> --- gcc/testsuite/gcc.dg/pubtypes-4.c.jj  2017-06-19 10:39:09.434278158 
> +0200
> +++ gcc/testsuite/gcc.dg/pubtypes-4.c 2019-01-02 22:03:53.044367518 +0100
> @@ -2,7 +2,7 @@
>  /* { dg-options "-O0 -gdwarf-2 -dA" } */
>  /* { dg-skip-if "Unmatchable assembly" { mmix-*-* } } */
>  /* { dg-final { scan-assembler "__debug_pubtypes" } } */
> -/* { dg-final { scan-assembler "long+\[ \t\]+0x172+\[ \t\]+\[#;]+\[ \t\]+Pub 
> Info Length" } } */
> +/* { dg-final { scan-assembler "long+\[ \t\]+0x165+\[ \t\]+\[#;]+\[ \t\]+Pub 
> Info Length" } } */
>  /* { dg-final { scan-assembler "used_struct0\"+\[ \t\]+\[#;]+\[ 
> \t\]+external name" } } */
>  /* { dg-final { scan-assembler-not "unused_struct0\"+\[ \t\]+\[#;]+\[ 
> \t\]+external name" } } */
>  /* { dg-final { scan-assembler "\"list_name_type0\"+\[ \t\]+\[#;]+\[ 
> \t\]+external n

Re: [PATCH] Add __builtin_convertvector support (PR c++/85052)

2019-01-03 Thread Jakub Jelinek
On Thu, Jan 03, 2019 at 11:48:12AM +0100, Marc Glisse wrote:
> > The following patch adds support for the __builtin_convertvector builtin.
> > C casts on generic vectors are just reinterpretation of the bits (i.e. a
> > VCE), this builtin allows to cast int/unsigned elements to float or vice
> > versa or promote/demote them.  doc/ change is missing, will write it soon.
> > 
> > The builtin appeared in I think clang 3.4 and is apparently in real-world
> > use as e.g. Honza reported.  The first argument is an expression with vector
> > type, the second argument is a vector type (similarly e.g. to va_arg), to
> > which the first argument should be converted.  Both vector types need to
> > have the same number of elements.
> > 
> > I've implemented same element size (thus also whole vector size) conversions
> > efficiently - signed to unsigned and vice versa or same vector type just
> > using a VCE, for e.g. int <-> float or long long <-> double using
> > appropriate optab, possibly repeated multiple times for very large vectors.
> 
> IIUC, you only lower __builtin_convertvector to VCE or FLOAT_EXPR or
> whatever in tree-vect-generic. That seems quite late. At least for the
> "easy" same-size case, I think we should do it early (gimplification?),

No, it must not be done at gimplification time, think about OpenMP/OpenACC
offloading, the target before IPA optimizations might not be the target
after them, while they have to agree on ABI issues, the optabs definitely
can be and are different and these optabs originally added for the
vectorizer are something that doesn't have a fallback, whatever introduces
it into the IL is responsible for verification it is supported.

It could be done in some post-IPA pass, perhaps by just calling from
somewhere else the tree-vect-generic.c function added in the patch, maybe
with a special argument that would do it only for the single op cases and
not for the others.

That said, not sure if e.g. using an opaque builtin for the conversion that
supportable_convert_operation sometimes uses is better over this ifn.
What exact optimization opportunities you are looking for if it is lowered
earlier?  I have the VECTOR_CST folding in place...

> before we start optimizing, without checking if it is supported by the
> target (generic lowering can fix that up later). Of course that can be
> changed later, getting the basic functionality comes first.

Jakub


Re: [PATCH] Add __builtin_convertvector support (PR c++/85052)

2019-01-03 Thread Richard Biener
On Thu, 3 Jan 2019, Jakub Jelinek wrote:

> Hi!
> 
> The following patch adds support for the __builtin_convertvector builtin.
> C casts on generic vectors are just reinterpretation of the bits (i.e. a
> VCE), this builtin allows to cast int/unsigned elements to float or vice
> versa or promote/demote them.  doc/ change is missing, will write it soon.
> 
> The builtin appeared in I think clang 3.4 and is apparently in real-world
> use as e.g. Honza reported.  The first argument is an expression with vector
> type, the second argument is a vector type (similarly e.g. to va_arg), to
> which the first argument should be converted.  Both vector types need to
> have the same number of elements.
> 
> I've implemented same element size (thus also whole vector size) conversions
> efficiently - signed to unsigned and vice versa or same vector type just
> using a VCE, for e.g. int <-> float or long long <-> double using
> appropriate optab, possibly repeated multiple times for very large vectors.
> For everything there is a fallback to lower __builtin_convertvector (x, t)
> as { (__typeof (t[0])) x[0], (__typeof (t[1])) x[1], ... }.
> 
> What isn't implemented efficiently (yet) are the narrowing or widening
> conversions; the optabs we have are meant for same size vectors, so
> for the packing we have 2 arguments that we pack into 1, for unpacking we
> have those lo/hi variants, but in this case at least for the most common
> vectors we have just one argument and want result with the same number of
> elements.  The AVX* different vector size instructions is the thing that
> does this most efficiently, of course for large generic vectors we can
> easily use these optabs.  Shall we go for e.g. trying to pack the argument
> and all zeros dummy operand and pick the low half of the result vector,
> or pick the low and high halves of the argument and use a half sized vector
> operations, or both?

I guess it depends on target capabilities - I think
__builtin_convertvector is a bit "misdesigned" for pack/unpack.  You
also have to consider a v2di to v2qi conversion which requires
several unpack steps.  Does the clang documentation given any
hints how to "efficiently" use __builtin_convertvector for
packing/unpacking without exposing too much of the target architecture?

But yes, for unpacking you'd use a series of vec_unpack_*_lo_expr
with padded input (padded with "don't care" if we had that, on
RTL we'd use a paradoxical subreg, on GIMPLE we _might_ consider
allowing VCE of different size?  Or simply allow half-size input
operands to vec_unpack_*_lo where that expands to paradoxical
subregs (a bit difficult for the optab query I guess).

For packing you'd use a series of vec_pack_* on argument split
to two halves via BIT_FIELD_REF.

What does clang do for testcases that request promotion/demotion?

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

do_vec_conversion needs a comment.  Overall the patch (with its
existing features) looks OK to me.

As of Marcs comments I agree that vector lowering happens quite late.
It might be for example useful to lower before vectorization (or
any loop optimization) so that un-handled generic vector code can be
eventually vectorized differently.  But that's sth to investigate for
GCC 10.

Giving FE maintainers a chance to comment, so no overall ACK yet.

Thanks,
Richard.

> 2019-01-03  Jakub Jelinek  
> 
>   PR c++/85052
>   * tree-vect-generic.c (expand_vector_piecewise): Add defaulted
>   ret_type argument, if non-NULL, use that in preference to type
>   for the result type.
>   (expand_vector_parallel): Formatting fix.
>   (do_vec_conversion, expand_vector_conversion): New functions.
>   (expand_vector_operations_1): Call expand_vector_conversion
>   for VEC_CONVERT ifn calls.
>   * internal-fn.def (VEC_CONVERT): New internal function.
>   * internal-fn.c (expand_VEC_CONVERT): New function.
>   * fold-const-call.c (fold_const_vec_convert): New function.
>   (fold_const_call): Use it for CFN_VEC_CONVERT.
> c-family/
>   * c-common.h (enum rid): Add RID_BUILTIN_CONVERTVECTOR.
>   (c_build_vec_convert): Declare.
>   * c-common.c (c_build_vec_convert): New function.
> c/
>   * c-parser.c (c_parser_postfix_expression): Parse
>   __builtin_convertvector.
> cp/
>   * cp-tree.h (cp_build_vec_convert): Declare.
>   * parser.c (cp_parser_postfix_expression): Parse
>   __builtin_convertvector.
>   * constexpr.c: Include fold-const-call.h.
>   (cxx_eval_internal_function): Handle IFN_VEC_CONVERT.
>   (potential_constant_expression_1): Likewise.
>   * semantics.c (cp_build_vec_convert): New function.
>   * pt.c (tsubst_copy_and_build): Handle CALL_EXPR to
>   IFN_VEC_CONVERT.
> testsuite/
>   * c-c++-common/builtin-convertvector-1.c: New test.
>   * c-c++-common/torture/builtin-convertvector-1.c: New test.
>   * g++.dg/ext/builtin-convertvector-1.C: New test.
> 

[build] Update config.guess, config.sub (PR target/88535)

2019-01-03 Thread Rainer Orth
I've just updated config.guess and config.sub to the current upstream
versions.  This was prompted by PR target/88535 where on Solaris/SPARC
config.guess didn't return the 64-bit configure triplet when a 64-bit
compiler is used, unlike Solaris/x86.  This ultimately lead to a
comparison failure.  config.guess handling of Solaris/SPARC and x86 is
now in sync again.

Tested with running toplevel configure on i386-pc-solaris2.10 (to check
that the older Solaris 10 tools don't have problems with newer shell
features in config.guess) and sparc-sun-solaris2.11, both with a 32-bit
and 64-bit compiler.  As expected, the only differences were the changed
configure triplets in the 64-bit Solaris/SPARC case.

Installed on mainline.

Rainer

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


2019-01-03  Rainer Orth  

PR target/88535
* config.guess: Import upstream version 2019-01-03.
* config.sub: Import upstream version 2019-01-01.

# HG changeset patch
# Parent  4ed79698a5ae949ce2162cfae86c50d1b449bc32
Update config.guess, config.sub (PR target/88535)

diff --git a/config.guess b/config.guess
--- a/config.guess
+++ b/config.guess
@@ -1,8 +1,8 @@
 #! /bin/sh
 # Attempt to guess a canonical system name.
-#   Copyright 1992-2018 Free Software Foundation, Inc.
+#   Copyright 1992-2019 Free Software Foundation, Inc.
 
-timestamp='2018-06-26'
+timestamp='2019-01-03'
 
 # This file is free software; you can redistribute it and/or modify it
 # under the terms of the GNU General Public License as published by
@@ -50,7 +50,7 @@ version="\
 GNU config.guess ($timestamp)
 
 Originally written by Per Bothner.
-Copyright 1992-2018 Free Software Foundation, Inc.
+Copyright 1992-2019 Free Software Foundation, Inc.
 
 This is free software; see the source for copying conditions.  There is NO
 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
@@ -84,8 +84,6 @@ if test $# != 0; then
   exit 1
 fi
 
-trap 'exit 1' 1 2 15
-
 # CC_FOR_BUILD -- compiler used by this script. Note that the use of a
 # compiler to aid in system detection is discouraged as it requires
 # temporary files to be created and, as you can see below, it is a
@@ -96,34 +94,38 @@ trap 'exit 1' 1 2 15
 
 # Portable tmp directory creation inspired by the Autoconf team.
 
-set_cc_for_build='
-trap "exitcode=\$?; (rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null) && exit \$exitcode" 0 ;
-trap "rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null; exit 1" 1 2 13 15 ;
-: ${TMPDIR=/tmp} ;
- { tmp=`(umask 077 && mktemp -d "$TMPDIR/cgXX") 2>/dev/null` && test -n "$tmp" && test -d "$tmp" ; } ||
- { test -n "$RANDOM" && tmp=$TMPDIR/cg$$-$RANDOM && (umask 077 && mkdir $tmp) ; } ||
- { tmp=$TMPDIR/cg-$$ && (umask 077 && mkdir $tmp) && echo "Warning: creating insecure temp directory" >&2 ; } ||
- { echo "$me: cannot create a temporary directory in $TMPDIR" >&2 ; exit 1 ; } ;
-dummy=$tmp/dummy ;
-tmpfiles="$dummy.c $dummy.o $dummy.rel $dummy" ;
-case ${CC_FOR_BUILD-},${HOST_CC-},${CC-} in
- ,,)echo "int x;" > "$dummy.c" ;
-	for c in cc gcc c89 c99 ; do
-	  if ($c -c -o "$dummy.o" "$dummy.c") >/dev/null 2>&1 ; then
-	 CC_FOR_BUILD="$c"; break ;
-	  fi ;
-	done ;
-	if test x"$CC_FOR_BUILD" = x ; then
-	  CC_FOR_BUILD=no_compiler_found ;
-	fi
-	;;
- ,,*)   CC_FOR_BUILD=$CC ;;
- ,*,*)  CC_FOR_BUILD=$HOST_CC ;;
-esac ; set_cc_for_build= ;'
+tmp=
+# shellcheck disable=SC2172
+trap 'test -z "$tmp" || rm -fr "$tmp"' 0 1 2 13 15
+
+set_cc_for_build() {
+: "${TMPDIR=/tmp}"
+# shellcheck disable=SC2039
+{ tmp=`(umask 077 && mktemp -d "$TMPDIR/cgXX") 2>/dev/null` && test -n "$tmp" && test -d "$tmp" ; } ||
+	{ test -n "$RANDOM" && tmp=$TMPDIR/cg$$-$RANDOM && (umask 077 && mkdir "$tmp" 2>/dev/null) ; } ||
+	{ tmp=$TMPDIR/cg-$$ && (umask 077 && mkdir "$tmp" 2>/dev/null) && echo "Warning: creating insecure temp directory" >&2 ; } ||
+	{ echo "$me: cannot create a temporary directory in $TMPDIR" >&2 ; exit 1 ; }
+dummy=$tmp/dummy
+case ${CC_FOR_BUILD-},${HOST_CC-},${CC-} in
+	,,)echo "int x;" > "$dummy.c"
+	   for driver in cc gcc c89 c99 ; do
+		   if ($driver -c -o "$dummy.o" "$dummy.c") >/dev/null 2>&1 ; then
+		   CC_FOR_BUILD="$driver"
+		   break
+		   fi
+	   done
+	   if test x"$CC_FOR_BUILD" = x ; then
+		   CC_FOR_BUILD=no_compiler_found
+	   fi
+	   ;;
+	,,*)   CC_FOR_BUILD=$CC ;;
+	,*,*)  CC_FOR_BUILD=$HOST_CC ;;
+esac
+}
 
 # This is needed to find uname on a Pyramid OSx when run in the BSD universe.
 # (gh...@noc.rutgers.edu 1994-08-24)
-if (test -f /.attbin/uname) >/dev/null 2>&1 ; then
+if test -f /.attbin/uname ; then
 	PATH=$PATH:/.attbin ; export PATH
 fi
 
@@ -138,7 +140,7 @@ Linux|GNU|GNU/*)
 	# We could probably try harder.
 	LIBC=gnu
 
-	eval "$set_cc_for_build"
+	set_cc_for_build
 	cat <<-EOF > "$dummy.c"
 	#include 
 	#if defined(__UCLIBC__)
@@ -199

Re: [PATCH 4/4][libbacktrace] Add tests for unused formats

2019-01-03 Thread Iain Sandoe


> On 2 Jan 2019, at 13:26, Iain Sandoe  wrote:
> 
> 
>> On 2 Jan 2019, at 13:20, Rainer Orth  wrote:
>> 
>> Gerald Pfeifer  writes:
>> 
>>> 

>>> 
>>> I believe that in addition to FreeBSD this probably also fails on
>>> Solaris and Darwin.
>> 
>> I cannot test Darwin right now,
> 
> I have builds running on a number of versions, will take a look 
> - is it missing a “macho_xx.c” implementation, anyway ?

(on darwin17 / macOS 10.13)

make check-target-libbacktrace 

fails for me at trunk r267505 with:

/src-local/gcc-trunk/libbacktrace/elf.c:144:2: error: #error "Unknown 
BACKTRACE_ELF_SIZE"
  144 | #error "Unknown BACKTRACE_ELF_SIZE"
  |  ^

So, it looks like there’s some configury-fixing/implementation work needed for 
Darwin.
Iain



Re: [PATCH] Add __builtin_convertvector support (PR c++/85052)

2019-01-03 Thread Jakub Jelinek
On Thu, Jan 03, 2019 at 12:16:31PM +0100, Richard Biener wrote:
> I guess it depends on target capabilities - I think
> __builtin_convertvector is a bit "misdesigned" for pack/unpack.  You
> also have to consider a v2di to v2qi conversion which requires

I'm aware of that, I know supportable_{widening,narrowing}_conversion in the
vectorizer handles those, but they are vectorizer specific and written for
the model vectorizer uses.  In any case, I wanted to have something correct
first (i.e. the scalar ops fallback in there) and then improve what I can,
and start with the 2x narrowing and widening first and only when that works
go further.

> several unpack steps.  Does the clang documentation given any
> hints how to "efficiently" use __builtin_convertvector for
> packing/unpacking without exposing too much of the target architecture?

The clang documentation is completely useless here, trying e.g.
typedef signed char v16qi __attribute__((vector_size (16 * sizeof (signed 
char;
typedef int v16si __attribute__((vector_size (16 * sizeof (int;

void
foo (v16si *x, v16qi *y)
{
  *y = __builtin_convertvector (*x, v16qi);
}

void
bar (v16qi *x, v16si *y)
{
  *y = __builtin_convertvector (*x, v16si);
}

with clang -O2 -mavx512{bw,vl,dq} shows efficient:
vmovdqa64   (%rdi), %zmm0
vpmovdb %zmm0, (%rsi)
and
vpmovsxbd   (%rdi), %zmm0
vmovdqa64   %zmm0, (%rsi)
With -O2 -mavx2 bar is:
vpmovsxbd   (%rdi), %ymm0
vpmovsxbd   8(%rdi), %ymm1
vmovdqa %ymm1, 32(%rsi)
vmovdqa %ymm0, (%rsi)
which is what would be emitted for v8[qs]i twice, and foo is:
vmovdqa (%rdi), %ymm0
vmovdqa 32(%rdi), %ymm1
vmovdqa .LCPI0_0(%rip), %ymm2   # ymm2 = 
[0,1,4,5,8,9,12,13,8,9,12,13,12,13,14,15,16,17,20,21,24,25,28,29,24,25,28,29,28,29,30,31]
vpshufb %ymm2, %ymm1, %ymm1
vpermq  $232, %ymm1, %ymm1  # ymm1 = ymm1[0,2,2,3]
vmovdqa .LCPI0_1(%rip), %xmm3   # xmm3 = 
<0,2,4,6,8,10,12,14,u,u,u,u,u,u,u,u>
vpshufb %xmm3, %xmm1, %xmm1
vpshufb %ymm2, %ymm0, %ymm0
vpermq  $232, %ymm0, %ymm0  # ymm0 = ymm0[0,2,2,3]
vpshufb %xmm3, %xmm0, %xmm0
vpunpcklqdq %xmm1, %xmm0, %xmm0 # xmm0 = xmm0[0],xmm1[0]
vmovdqa %xmm0, (%rsi)
which looks quite complicated to me.  I would think we could emit e.g. what
we emit for:
typedef signed char v16qi __attribute__((vector_size (16 * sizeof (signed 
char;
typedef signed char v32qi __attribute__((vector_size (32 * sizeof (signed 
char;

void
baz (v32qi *x, v16qi *y)
{
  v32qi z = __builtin_shuffle (x[0], x[1], (v32qi) { 0, 4, 8, 12, 16, 20, 24, 
28, 32, 36, 40, 44, 48, 52, 56, 60,
 0, 4, 8, 12, 16, 20, 24, 
28, 32, 36, 40, 44, 48, 52, 56, 60 });
  v16qi u;
  __builtin_memcpy (&u, &z, sizeof (u));
  *y = u;
}
which is with gcc trunk:
vmovdqa (%rdi), %ymm0
vmovdqa 32(%rdi), %ymm1
vpshufb .LC0(%rip), %ymm0, %ymm0
vpshufb .LC1(%rip), %ymm1, %ymm1
vpermq  $78, %ymm0, %ymm3
vpermq  $78, %ymm1, %ymm2
vpor%ymm3, %ymm0, %ymm0
vpor%ymm2, %ymm1, %ymm1
vpor%ymm1, %ymm0, %ymm0
vmovaps %xmm0, (%rsi)
although really the upper half is a don't care (so a properly implemented
__builtin_shufflevector might be handy too, with
__builtin_shufflevector (x[0], x[1], 0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 
44, 48, 52, 56, 60,
 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 
-1, -1, -1, -1, -1, -1);
).

> > Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
> 
> do_vec_conversion needs a comment.  Overall the patch (with its

Will add one (though do_unop/do_binop don't have one either) and add
documentation.

> existing features) looks OK to me.
> 
> As of Marcs comments I agree that vector lowering happens quite late.
> It might be for example useful to lower before vectorization (or
> any loop optimization) so that un-handled generic vector code can be
> eventually vectorized differently.  But that's sth to investigate for
> GCC 10.
> 
> Giving FE maintainers a chance to comment, so no overall ACK yet.

Ok.

Jakub


[PATCH] Fix PR85574

2019-01-03 Thread Richard Biener


The following rectifies a change during hash-map intruction which
changed the uncprop operand_equal_p based hash to a pointer-based
hash_map.  That assumes pointer equality between constants which
does not hold since different (but compatible) typed constants
can appear in the IL.  For SSA names the equivalence holds, of course.

Fixing this should increase the number of eliminated const-copies
on edges during out-of-SSA.  It also happens to fix the LTO
bootstrap miscompare of cc1 and friends, but I can't really
explain that.

[LTO] bootstrapped and tested on x86_64-unknown-linux-gnu, applied
to trunk.

Richard.

2019-01-03  Jan Hubicka  

PR tree-optimization/85574
* tree-ssa-uncprop.c (struct equiv_hash_elt): Remove unused
structure.
(struct ssa_equip_hash_traits): Declare.
(val_ssa_equiv): Use custom hash traits using operand_equal_p.

Index: gcc/tree-ssa-uncprop.c
===
--- gcc/tree-ssa-uncprop.c  (revision 267549)
+++ gcc/tree-ssa-uncprop.c  (working copy)
@@ -268,21 +268,24 @@ associate_equivalences_with_edges (void)
so with each value we have a list of SSA_NAMEs that have the
same value.  */
 
-
-/* Main structure for recording equivalences into our hash table.  */
-struct equiv_hash_elt
-{
-  /* The value/key of this entry.  */
-  tree value;
-
-  /* List of SSA_NAMEs which have the same value/key.  */
-  vec equivalences;
+/* Traits for the hash_map to record the value to SSA name equivalences
+   mapping.  */
+struct ssa_equip_hash_traits : default_hash_traits 
+{
+  static inline hashval_t hash (value_type value)
+{ return iterative_hash_expr (value, 0); }
+  static inline bool equal (value_type existing, value_type candidate)
+{ return operand_equal_p (existing, candidate, 0); }
 };
 
+typedef hash_map,
+simple_hashmap_traits  > > val_ssa_equiv_t;
+
 /* Global hash table implementing a mapping from invariant values
to a list of SSA_NAMEs which have the same value.  We might be
able to reuse tree-vn for this code.  */
-static hash_map > *val_ssa_equiv;
+val_ssa_equiv_t *val_ssa_equiv;
 
 static void uncprop_into_successor_phis (basic_block);
 
@@ -476,7 +479,7 @@ pass_uncprop::execute (function *fun)
   associate_equivalences_with_edges ();
 
   /* Create our global data structures.  */
-  val_ssa_equiv = new hash_map > (1024);
+  val_ssa_equiv = new val_ssa_equiv_t (1024);
 
   /* We're going to do a dominator walk, so ensure that we have
  dominance information.  */


Re: [RFC/PATCH] gcc.c: access does not work in new msvcr for nul file

2019-01-03 Thread Alexander Monakov
On Thu, 3 Jan 2019, Johannes Pfau wrote:
> 
> Debugging shows that the access function used to check
> if the input files exist has different behavior in newer msvcr libraries:
> It does return proper results for the 'nul' file in the old msvcrt.dll
> but in newer libraries it returns EINVAL for the nul file.

I would recommend to consult with MinGW-W64 maintainers first: it may be
appropriate to handle this in mingw's wrapper for the access function.
In any case, they should be informed about this weird regression.

Cheers.
Alexander


Re: [Fortran, test case, committed] Test case for PR 48543

2019-01-03 Thread Thomas Koenig

Hi Jakub,


In any case, IMHO the test should be removed or XFAILed for now.


thanks for your explanations. I have removed the test case.

Regards

Thomas


Re: [PATCH] genattrtab bit-rot, and if_then_else in values

2019-01-03 Thread Richard Sandiford
Alan Modra  writes:
> +case PLUS:
> +  current_or = or_attr_value (XEXP (exp, 0));
> +  if (current_or != -1)
> + {
> +   int n = current_or;
> +   current_or = or_attr_value (XEXP (exp, 1));
> +   if (current_or != -1)
> + current_or += n;
> + }
> +  break;

This doesn't look right.  Doing the same for IOR and |= would be OK
in principle, but write_attr_value doesn't handle IOR yet.

OK with the above dropped, thanks.

Richard

PS. current write_attr_value doesn't seem to handle operator precedence
properly, but that's orthogonal.


Re: [PATCH 4/4][libbacktrace] Add tests for unused formats

2019-01-03 Thread Tom de Vries
On 02-01-19 14:20, Rainer Orth wrote:
> Unfortunately, libbacktrace is one of those libraries that don't produce
> Dejagnu-style .sum and .log files, so test failures are buried in the
> make check output and very easily overlooked.

FTR, I've filed PR88002 - "libbacktrace and libiberty tests don't use
dejagnu" for that ( https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88002 ).

Thanks,
- Tom


Re: [PATCH] Add __builtin_convertvector support (PR c++/85052)

2019-01-03 Thread Richard Sandiford
Jakub Jelinek  writes:
> +  /* Can't use get_compute_type here, as supportable_convert_operation
> +  doesn't necessarily use an optab and needs two arguments.  */
> +  tree vector_compute_type
> + = type_for_widest_vector_mode (TREE_TYPE (arg_type), mov_optab);
> +  unsigned HOST_WIDE_INT nelts;
> +  if (vector_compute_type
> +   && VECTOR_MODE_P (TYPE_MODE (vector_compute_type))
> +   && subparts_gt (arg_type, vector_compute_type)
> +   && TYPE_VECTOR_SUBPARTS (vector_compute_type).is_constant (&nelts))
> + {
> +   while (nelts > 1)
> + {
> +   tree ret1_type = build_vector_type (TREE_TYPE (ret_type), nelts);
> +   tree arg1_type = build_vector_type (TREE_TYPE (arg_type), nelts);
> +   if (supportable_convert_operation (code, ret1_type, arg1_type,
> +  &decl, &code1))
> + {
> +   new_rhs = expand_vector_piecewise (gsi, do_vec_conversion,
> +  ret_type, arg1_type, arg,
> +  decl, code1);
> +   g = gimple_build_assign (lhs, new_rhs);
> +   gsi_replace (gsi, g, false);
> +   return;
> + }
> +   nelts = nelts / 2;
> + }
> + }

I think for this it would be better to use:

  if (vector_compute_type
  && VECTOR_MODE_P (TYPE_MODE (vector_compute_type))
  && subparts_gt (arg_type, vector_compute_type))
{
  unsigned HOST_WIDE_INT nelts = constant_lower_bound
(TYPE_VECTOR_SUBPARTS (vector_compute_type));

since the loop is self-checking.

E.g. this will make the Advanced SIMD handling on AArch64 the same
regardless of whether SVE is also enabled.

Thanks,
Richard


Re: [PATCH] Fix PR85574

2019-01-03 Thread Richard Sandiford
Richard Biener  writes:
> The following rectifies a change during hash-map intruction which
> changed the uncprop operand_equal_p based hash to a pointer-based
> hash_map.  That assumes pointer equality between constants which
> does not hold since different (but compatible) typed constants
> can appear in the IL.  For SSA names the equivalence holds, of course.
>
> Fixing this should increase the number of eliminated const-copies
> on edges during out-of-SSA.  It also happens to fix the LTO
> bootstrap miscompare of cc1 and friends, but I can't really
> explain that.
>
> [LTO] bootstrapped and tested on x86_64-unknown-linux-gnu, applied
> to trunk.
>
> Richard.
>
> 2019-01-03  Jan Hubicka  
>
>   PR tree-optimization/85574
>   * tree-ssa-uncprop.c (struct equiv_hash_elt): Remove unused
>   structure.
>   (struct ssa_equip_hash_traits): Declare.
>   (val_ssa_equiv): Use custom hash traits using operand_equal_p.
>
> Index: gcc/tree-ssa-uncprop.c
> ===
> --- gcc/tree-ssa-uncprop.c(revision 267549)
> +++ gcc/tree-ssa-uncprop.c(working copy)
> @@ -268,21 +268,24 @@ associate_equivalences_with_edges (void)
> so with each value we have a list of SSA_NAMEs that have the
> same value.  */
>  
> -
> -/* Main structure for recording equivalences into our hash table.  */
> -struct equiv_hash_elt
> -{
> -  /* The value/key of this entry.  */
> -  tree value;
> -
> -  /* List of SSA_NAMEs which have the same value/key.  */
> -  vec equivalences;
> +/* Traits for the hash_map to record the value to SSA name equivalences
> +   mapping.  */
> +struct ssa_equip_hash_traits : default_hash_traits 
> +{
> +  static inline hashval_t hash (value_type value)
> +{ return iterative_hash_expr (value, 0); }
> +  static inline bool equal (value_type existing, value_type candidate)
> +{ return operand_equal_p (existing, candidate, 0); }
>  };

FWIW, this is a dup of tree_operand_hash.

Thanks,
Richard

> +typedef hash_map,
> +  simple_hashmap_traits  + auto_vec  > > val_ssa_equiv_t;
> +
>  /* Global hash table implementing a mapping from invariant values
> to a list of SSA_NAMEs which have the same value.  We might be
> able to reuse tree-vn for this code.  */
> -static hash_map > *val_ssa_equiv;
> +val_ssa_equiv_t *val_ssa_equiv;
>  
>  static void uncprop_into_successor_phis (basic_block);
>  
> @@ -476,7 +479,7 @@ pass_uncprop::execute (function *fun)
>associate_equivalences_with_edges ();
>  
>/* Create our global data structures.  */
> -  val_ssa_equiv = new hash_map > (1024);
> +  val_ssa_equiv = new val_ssa_equiv_t (1024);
>  
>/* We're going to do a dominator walk, so ensure that we have
>   dominance information.  */


[testsuite] Fix gcc.dg/debug/dwarf2/inline5.c with Solaris as (PR debug/87451)

2019-01-03 Thread Rainer Orth
gcc.dg/debug/dwarf2/inline5.c currently FAILs with Solaris as (both
sparc and x86):

FAIL: gcc.dg/debug/dwarf2/inline5.c scan-assembler-not (DIE 
(0x([0-9a-f]*)) DW_TAG_lexical_block)[^#/!]*[#/!] 
[^(].*DW_TAG_lexical_block)[^#/!x]*x1[^#/!]*[#/!] DW_AT_abstract_origin
FAIL: gcc.dg/debug/dwarf2/inline5.c scan-assembler-times 
DW_TAG_lexical_block)[^#/!]*[#/!] (DIE (0x[0-9a-f]*) 
DW_TAG_variable 1

The first failure seems to be caused because .* performs multiline
matches by default in Tcl; tightening it to [^\n]* avoids the problem.

The second failures happens because Solaris as doesn't support .uleb128,
so we get e.g.

.byte   0xc / uleb128 0xc; (DIE (0x19f) DW_TAG_lexical_block)
.byte   0xd / uleb128 0xd; (DIE (0x1a0) DW_TAG_variable)

instead of

.uleb128 0xc/ (DIE (0xad) DW_TAG_lexical_block)
.uleb128 0xd/ (DIE (0xae) DW_TAG_variable)

To fix this, the patch allows for additional non-comment text before (DIE.

Tested on i386-pc-solaris2.11, sparc-sun-solaris2.11, and
x86_64-pc-linux-gnu.  Ok for mainline?

Rainer

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


2019-01-03  Rainer Orth  

PR debug/87451
* gcc.dg/debug/dwarf2/inline5.c: Allow for non-comment before
"(DIE (0x[0-9a-f]*) DW_TAG_variable".
Avoid multiline matches.

# HG changeset patch
# Parent  9265ca22ad184b53589ea032b85a14f545ba564a
Fix gcc.dg/debug/dwarf2/inline5.c with Solaris as (PR debug/87451)

diff --git a/gcc/testsuite/gcc.dg/debug/dwarf2/inline5.c b/gcc/testsuite/gcc.dg/debug/dwarf2/inline5.c
--- a/gcc/testsuite/gcc.dg/debug/dwarf2/inline5.c
+++ b/gcc/testsuite/gcc.dg/debug/dwarf2/inline5.c
@@ -5,12 +5,12 @@
 /* { dg-do compile } */
 /* { dg-final { scan-assembler-times "DW_TAG_inlined_subroutine" 2 } } */
 /* { dg-final { scan-assembler-times "DW_TAG_lexical_block\\)\[^#/!\]*\[#/!\] DW_AT_abstract_origin" 2 } } */
-/* { dg-final { scan-assembler-times "DW_TAG_lexical_block\\)\[^#/!\]*\[#/!\] \\(DIE \\(0x\[0-9a-f\]*\\) DW_TAG_variable" 1 } } */
+/* { dg-final { scan-assembler-times "DW_TAG_lexical_block\\)\[^#/!\]*\[#/!\] \[^#/!\]*\\(DIE \\(0x\[0-9a-f\]*\\) DW_TAG_variable" 1 } } */
 /* We do not know which is output first so look for both invalid abstract
origins on the lexical blocks (knowing that the abstract instance has
no attribute following the DW_TAG_lexical_block.  */
-/* { dg-final { scan-assembler-not "\\(DIE \\(0x(\[0-9a-f\]*)\\) DW_TAG_lexical_block\\)\[^#/!\]*\[#/!\] \[^(\].*DW_TAG_lexical_block\\)\[^#/!x\]*x\\1\[^#/!\]*\[#/!\] DW_AT_abstract_origin" } } */
-/* { dg-final { scan-assembler-not "DW_TAG_lexical_block\\)\[^#/!x\]*x(\[0-9a-f\]*)\[^#/!\]*\[#/!\] DW_AT_abstract_origin.*\\(DIE \\(0x\\1\\) DW_TAG_lexical_block\\)\[^#/!\]*\[#/!\] DW_AT" } } */
+/* { dg-final { scan-assembler-not "\\(DIE \\(0x(\[0-9a-f\]*)\\) DW_TAG_lexical_block\\)\[^#/!\]*\[#/!\] \[^(\]\[^\\n\]*DW_TAG_lexical_block\\)\[^#/!x\]*x\\1\[^#/!\]*\[#/!\] DW_AT_abstract_origin" } } */
+/* { dg-final { scan-assembler-not "DW_TAG_lexical_block\\)\[^#/!x\]*x(\[0-9a-f\]*)\[^#/!\]*\[#/!\] DW_AT_abstract_origin\[^\\n\]*\\(DIE \\(0x\\1\\) DW_TAG_lexical_block\\)\[^#/!\]*\[#/!\] DW_AT" } } */
 
 int foo (int i)
 {


[PATCH] PR85574 - add gcc/lto$(exeext) to files compared

2019-01-03 Thread Richard Biener


This makes sure we do not regress PR85574 and thus that when
doing LTO bootstrap the generated binaries do not differ from
stage2 to stage3.  Note we indepenently verify the object
files which contain just LTO bytecode do not differ (besides
differences in the LTO options sections).

This has the chance of breaking on some targets given we've
never compared binaries before but just object files.

Still it's an invariant we'd like to hold, so hopefully it
works out.

Bootstrapped on x86_64-unknown-linux-gnu, LTO bootstrapped on
x86_64-unknown-linux-gnu.

OK for trunk?

Note I picked just gcc/lto1 as a binary that will surely be
available when doing LTO bootstrap rather than also compare
all $(exeext) found in stageN-gcc/ (build/gen* are for example
also LTO compiled).  The explicit list could also be amended
of course.

Thanks,
Richard.

2019-01-03  Richard Biener  

PR bootstrap/85574
* Makefile.tpl (compare target): Also compare extra-compare
files.
* Makefile.in: Regenerate.

config/
* bootstrap-lto.mk (extra-compare): Set to gcc/lto1$(exeext).

Index: Makefile.in
===
--- Makefile.in (revision 267551)
+++ Makefile.in (working copy)
@@ -53850,7 +53850,7 @@ compare:
 sed=`echo stage3 | sed 's,^stage,,;s,.,.,g'`; \
files=`find stage3-* -name "*$(objext)" -print | \
 sed -n s,^stage$$sed-,,p`; \
-   for file in $${files}; do \
+   for file in $${files} ${extra-compare}; do \
  f1=$$r/stage2-$$file; f2=$$r/stage3-$$file; \
  if test ! -f $$f1; then continue; fi; \
  $(do-compare) > /dev/null 2>&1; \
@@ -54248,7 +54248,7 @@ compare3:
 sed=`echo stage4 | sed 's,^stage,,;s,.,.,g'`; \
files=`find stage4-* -name "*$(objext)" -print | \
 sed -n s,^stage$$sed-,,p`; \
-   for file in $${files}; do \
+   for file in $${files} ${extra-compare}; do \
  f1=$$r/stage3-$$file; f2=$$r/stage4-$$file; \
  if test ! -f $$f1; then continue; fi; \
  $(do-compare3) > /dev/null 2>&1; \
Index: Makefile.tpl
===
--- Makefile.tpl(revision 267551)
+++ Makefile.tpl(working copy)
@@ -1675,7 +1675,7 @@ do-clean: clean-stage[+id+]
 sed=`echo stage[+id+] | sed 's,^stage,,;s,.,.,g'`; \
files=`find stage[+id+]-* -name "*$(objext)" -print | \
 sed -n s,^stage$$sed-,,p`; \
-   for file in $${files}; do \
+   for file in $${files} ${extra-compare}; do \
  f1=$$r/stage[+prev+]-$$file; f2=$$r/stage[+id+]-$$file; \
  if test ! -f $$f1; then continue; fi; \
  $(do-[+compare-target+]) > /dev/null 2>&1; \
Index: config/bootstrap-lto.mk
===
--- config/bootstrap-lto.mk (revision 267551)
+++ config/bootstrap-lto.mk (working copy)
@@ -15,3 +15,4 @@ LTO_EXPORTS = AR="$(LTO_AR)"; export AR;
 LTO_FLAGS_TO_PASS = AR="$(LTO_AR)" RANLIB="$(LTO_RANLIB)"
 
 do-compare = $(SHELL) $(srcdir)/contrib/compare-lto $$f1 $$f2
+extra-compare = gcc/lto1$(exeext)


Re: [PATCH] Fix PR85574

2019-01-03 Thread Richard Biener
On Thu, 3 Jan 2019, Richard Sandiford wrote:

> Richard Biener  writes:
> > The following rectifies a change during hash-map intruction which
> > changed the uncprop operand_equal_p based hash to a pointer-based
> > hash_map.  That assumes pointer equality between constants which
> > does not hold since different (but compatible) typed constants
> > can appear in the IL.  For SSA names the equivalence holds, of course.
> >
> > Fixing this should increase the number of eliminated const-copies
> > on edges during out-of-SSA.  It also happens to fix the LTO
> > bootstrap miscompare of cc1 and friends, but I can't really
> > explain that.
> >
> > [LTO] bootstrapped and tested on x86_64-unknown-linux-gnu, applied
> > to trunk.
> >
> > Richard.
> >
> > 2019-01-03  Jan Hubicka  
> >
> > PR tree-optimization/85574
> > * tree-ssa-uncprop.c (struct equiv_hash_elt): Remove unused
> > structure.
> > (struct ssa_equip_hash_traits): Declare.
> > (val_ssa_equiv): Use custom hash traits using operand_equal_p.
> >
> > Index: gcc/tree-ssa-uncprop.c
> > ===
> > --- gcc/tree-ssa-uncprop.c  (revision 267549)
> > +++ gcc/tree-ssa-uncprop.c  (working copy)
> > @@ -268,21 +268,24 @@ associate_equivalences_with_edges (void)
> > so with each value we have a list of SSA_NAMEs that have the
> > same value.  */
> >  
> > -
> > -/* Main structure for recording equivalences into our hash table.  */
> > -struct equiv_hash_elt
> > -{
> > -  /* The value/key of this entry.  */
> > -  tree value;
> > -
> > -  /* List of SSA_NAMEs which have the same value/key.  */
> > -  vec equivalences;
> > +/* Traits for the hash_map to record the value to SSA name equivalences
> > +   mapping.  */
> > +struct ssa_equip_hash_traits : default_hash_traits 
> > +{
> > +  static inline hashval_t hash (value_type value)
> > +{ return iterative_hash_expr (value, 0); }
> > +  static inline bool equal (value_type existing, value_type candidate)
> > +{ return operand_equal_p (existing, candidate, 0); }
> >  };
> 
> FWIW, this is a dup of tree_operand_hash.

Indeed.  Testing patch to do the obvious replacement.

Richard.

> Thanks,
> Richard
> 
> > +typedef hash_map,
> > +simple_hashmap_traits  > +   auto_vec  > > val_ssa_equiv_t;
> > +
> >  /* Global hash table implementing a mapping from invariant values
> > to a list of SSA_NAMEs which have the same value.  We might be
> > able to reuse tree-vn for this code.  */
> > -static hash_map > *val_ssa_equiv;
> > +val_ssa_equiv_t *val_ssa_equiv;
> >  
> >  static void uncprop_into_successor_phis (basic_block);
> >  
> > @@ -476,7 +479,7 @@ pass_uncprop::execute (function *fun)
> >associate_equivalences_with_edges ();
> >  
> >/* Create our global data structures.  */
> > -  val_ssa_equiv = new hash_map > (1024);
> > +  val_ssa_equiv = new val_ssa_equiv_t (1024);
> >  
> >/* We're going to do a dominator walk, so ensure that we have
> >   dominance information.  */
> 
> 

-- 
Richard Biener 
SUSE LINUX GmbH, GF: Felix Imendoerffer, Jane Smithard, Graham Norton, HRB 
21284 (AG Nuernberg)


Re: [testsuite] Fix gcc.dg/debug/dwarf2/inline5.c with Solaris as (PR debug/87451)

2019-01-03 Thread Richard Biener
On Thu, 3 Jan 2019, Rainer Orth wrote:

> gcc.dg/debug/dwarf2/inline5.c currently FAILs with Solaris as (both
> sparc and x86):
> 
> FAIL: gcc.dg/debug/dwarf2/inline5.c scan-assembler-not (DIE 
> (0x([0-9a-f]*)) DW_TAG_lexical_block)[^#/!]*[#/!] 
> [^(].*DW_TAG_lexical_block)[^#/!x]*x1[^#/!]*[#/!] 
> DW_AT_abstract_origin
> FAIL: gcc.dg/debug/dwarf2/inline5.c scan-assembler-times 
> DW_TAG_lexical_block)[^#/!]*[#/!] (DIE (0x[0-9a-f]*) 
> DW_TAG_variable 1
> 
> The first failure seems to be caused because .* performs multiline
> matches by default in Tcl; tightening it to [^\n]* avoids the problem.

Hmm, but the matches are supposed to match multiple lines...  how
does it fail for you?

> The second failures happens because Solaris as doesn't support .uleb128,
> so we get e.g.
> 
>   .byte   0xc / uleb128 0xc; (DIE (0x19f) DW_TAG_lexical_block)
>   .byte   0xd / uleb128 0xd; (DIE (0x1a0) DW_TAG_variable)
> 
> instead of
> 
>   .uleb128 0xc/ (DIE (0xad) DW_TAG_lexical_block)
>   .uleb128 0xd/ (DIE (0xae) DW_TAG_variable)
> 
> To fix this, the patch allows for additional non-comment text before (DIE.
> 
> Tested on i386-pc-solaris2.11, sparc-sun-solaris2.11, and
> x86_64-pc-linux-gnu.  Ok for mainline?


Re: [PATCH] genattrtab bit-rot, and if_then_else in values

2019-01-03 Thread Alan Modra
On Thu, Jan 03, 2019 at 12:41:52PM +, Richard Sandiford wrote:
> Alan Modra  writes:
> > +case PLUS:
> > +  current_or = or_attr_value (XEXP (exp, 0));
> > +  if (current_or != -1)
> > +   {
> > + int n = current_or;
> > + current_or = or_attr_value (XEXP (exp, 1));
> > + if (current_or != -1)
> > +   current_or += n;
> > +   }
> > +  break;
> 
> This doesn't look right.  Doing the same for IOR and |= would be OK
> in principle, but write_attr_value doesn't handle IOR yet.

>From what I can see, or_attr_value is used to find the largest power
of two that divides all attr length values for a given insn.  So what
should be done for PLUS in an attr length value expression?  I can't
simply ignore it as then or_attr_value will return -1 and we'll
calculate length_unit_log as 0 on powerpc when it ought to be 2.
That might matter some time in the future.

If the operands of PLUS are assumed to be insn lengths (reasonable,
since you're likely to use PLUS to sum the machine insn lengths of a
pattern that conditionally emits multiple machine insns), then it
might be better to replace "current_or += n" above with
"current_or |= n".  That would be correct for a length expression of
(plus (if_then_else (condA) (const_int 4) (const_int 0))
  (if_then_else (condB) (const_int 8) (const_int 4)))
where any answer from or_attr_value that has 3 lsbs of 100b is
sufficently correct.  If I keep "+=" then we'd get the wrong answer in
this particular example.  However "|=" is wrong if someone is playing
games and writes a silly expression like
(plus (const_int 1) (const_int 3))
since the length is always 4.

> OK with the above dropped, thanks.

Maybe this instead?

case PLUS:
  current_or = or_attr_value (XEXP (exp, 0));
  current_or |= or_attr_value (XEXP (exp, 1));
  break;

> Richard
> 
> PS. current write_attr_value doesn't seem to handle operator precedence
> properly, but that's orthogonal.

I hadn't noticed that, but yes that is another problem.  I also didn't
implement MINUS, MULT, DIV and MOD in max_attr_value, min_attr_value
and or_attr_value even though write_attr_value handles those cases.

-- 
Alan Modra
Australia Development Lab, IBM


Re: [testsuite] Fix gcc.dg/debug/dwarf2/inline5.c with Solaris as (PR debug/87451)

2019-01-03 Thread Rainer Orth
Hi Richard,

> On Thu, 3 Jan 2019, Rainer Orth wrote:
>
>> gcc.dg/debug/dwarf2/inline5.c currently FAILs with Solaris as (both
>> sparc and x86):
>> 
>> FAIL: gcc.dg/debug/dwarf2/inline5.c scan-assembler-not (DIE
>> (0x([0-9a-f]*)) DW_TAG_lexical_block)[^#/!]*[#/!]
>> [^(].*DW_TAG_lexical_block)[^#/!x]*x1[^#/!]*[#/!]
>> DW_AT_abstract_origin
>> FAIL: gcc.dg/debug/dwarf2/inline5.c scan-assembler-times
>> DW_TAG_lexical_block)[^#/!]*[#/!] (DIE (0x[0-9a-f]*)
>> DW_TAG_variable 1
>> 
>> The first failure seems to be caused because .* performs multiline
>> matches by default in Tcl; tightening it to [^\n]* avoids the problem.
>
> Hmm, but the matches are supposed to match multiple lines...  how
> does it fail for you?

it matches all of

(DIE (0x19f) DW_TAG_lexical_block)
.byte   0xd / uleb128 0xd; (DIE (0x1a0) DW_TAG_variable)
.ascii "j"  / DW_AT_name
.byte   0x1 / DW_AT_decl_file 
(/vol/gcc/src/hg/trunk/local/gcc/testsuite/gcc.dg/debug/dwarf2/inline5.c)
.byte   0x12/ DW_AT_decl_line
.byte   0x14/ DW_AT_decl_column
.long   0x17f   / DW_AT_type
.byte   0   / end of children of DIE 0x19f
.byte   0   / end of children of DIE 0x184
.byte   0xe / uleb128 0xe; (DIE (0x1ac) DW_TAG_subprogram)
.long   0x184   / DW_AT_abstract_origin
.long   .LFB0   / DW_AT_low_pc
.long   .LFE0-.LFB0 / DW_AT_high_pc
.byte   0x1 / uleb128 0x1; DW_AT_frame_base
.byte   0x9c/ DW_OP_call_frame_cfa
/ DW_AT_GNU_all_call_sites
.byte   0xf / uleb128 0xf; (DIE (0x1bb) DW_TAG_formal_parameter)
.long   0x195   / DW_AT_abstract_origin
.byte   0x2 / uleb128 0x2; DW_AT_location
.byte   0x91/ DW_OP_fbreg
.byte   0   / sleb128 0
.byte   0x6 / uleb128 0x6; (DIE (0x1c3) DW_TAG_lexical_block)
.long   0x19f   / DW_AT_abstract_origin

while with gas there's instead

.uleb128 0xc/ (DIE (0xad) DW_TAG_lexical_block)
.uleb128 0xd/ (DIE (0xae) DW_TAG_variable)
.ascii "j\0"/ DW_AT_name
.byte   0x1 / DW_AT_decl_file 
(/vol/gcc/src/hg/trunk/local/gcc/testsuite/gcc.dg/debug/dwarf2/inline5.c)

i.e. the pattern doesn't match with gas due to the [^(] while with as we
have uleb128 first which does match, producing the failure (which shows
that that part of my patch is wrong).

Rainer

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


[committed][nvptx] Eliminate changed local var in nvptx_goacc_validate_dims

2019-01-03 Thread Tom de Vries
Hi,

The TARGET_GOACC_VALIDATE_DIMS hook requires an implementation to return a bool
indicating whether the dims parameter has changed.

Factor nvptx_goacc_validate_dims_1 out of nvptx_goacc_validate_dims, and
calculate the return value in nvptx_goacc_validate_dims.

Committed to trunk.

Thanks,
- Tom

[nvptx] Eliminate changed local var in nvptx_goacc_validate_dims

2019-01-03  Tom de Vries  

* config/nvptx/nvptx.c (nvptx_goacc_validate_dims_1): New function,
factored out of ...
(nvptx_goacc_validate_dims): ... here.

---
 gcc/config/nvptx/nvptx.c | 38 ++
 1 file changed, 26 insertions(+), 12 deletions(-)

diff --git a/gcc/config/nvptx/nvptx.c b/gcc/config/nvptx/nvptx.c
index f4095ff5f55..39cf2c7b22a 100644
--- a/gcc/config/nvptx/nvptx.c
+++ b/gcc/config/nvptx/nvptx.c
@@ -5188,15 +5188,12 @@ nvptx_simt_vf ()
   return PTX_WARP_SIZE;
 }
 
-/* Validate compute dimensions of an OpenACC offload or routine, fill
-   in non-unity defaults.  FN_LEVEL indicates the level at which a
-   routine might spawn a loop.  It is negative for non-routines.  If
-   DECL is null, we are validating the default dimensions.  */
+/* As nvptx_goacc_validate_dims, but does not return bool to indicate whether
+   DIMS has changed.  */
 
-static bool
-nvptx_goacc_validate_dims (tree decl, int dims[], int fn_level)
+static void
+nvptx_goacc_validate_dims_1 (tree decl, int dims[], int fn_level)
 {
-  bool changed = false;
   bool oacc_default_dims_p = false;
   bool oacc_min_dims_p = false;
   bool offload_region_p = false;
@@ -5255,7 +5252,6 @@ nvptx_goacc_validate_dims (tree decl, int dims[], int 
fn_level)
   dims[GOMP_DIM_VECTOR] = fn_level > GOMP_DIM_VECTOR ? 1 : 0;
   dims[GOMP_DIM_WORKER] = fn_level > GOMP_DIM_WORKER ? 1 : 0;
   dims[GOMP_DIM_GANG] = fn_level > GOMP_DIM_GANG ? 1 : 0;
-  changed = true;
 }
 
   /* The vector size must be 32, unless this is a SEQ routine.  */
@@ -5272,7 +5268,6 @@ nvptx_goacc_validate_dims (tree decl, int dims[], int 
fn_level)
: G_("using vector_length (%d), ignoring runtime setting"),
PTX_VECTOR_LENGTH, dims[GOMP_DIM_VECTOR]);
   dims[GOMP_DIM_VECTOR] = PTX_VECTOR_LENGTH;
-  changed = true;
 }
 
   /* Check the num workers is not too large.  */
@@ -5282,7 +5277,6 @@ nvptx_goacc_validate_dims (tree decl, int dims[], int 
fn_level)
  "using num_workers (%d), ignoring %d",
  PTX_WORKER_LENGTH, dims[GOMP_DIM_WORKER]);
   dims[GOMP_DIM_WORKER] = PTX_WORKER_LENGTH;
-  changed = true;
 }
 
   if (oacc_default_dims_p || oacc_min_dims_p)
@@ -5292,10 +5286,30 @@ nvptx_goacc_validate_dims (tree decl, int dims[], int 
fn_level)
dims[GOMP_DIM_WORKER] = PTX_DEFAULT_RUNTIME_DIM;
   if (dims[GOMP_DIM_GANG] < 0)
dims[GOMP_DIM_GANG] = PTX_DEFAULT_RUNTIME_DIM;
-  changed = true;
 }
+}
+
+/* Validate compute dimensions of an OpenACC offload or routine, fill
+   in non-unity defaults.  FN_LEVEL indicates the level at which a
+   routine might spawn a loop.  It is negative for non-routines.  If
+   DECL is null, we are validating the default dimensions.  */
+
+static bool
+nvptx_goacc_validate_dims (tree decl, int dims[], int fn_level)
+{
+  int old_dims[GOMP_DIM_MAX];
+  unsigned int i;
 
-  return changed;
+  for (i = 0; i < GOMP_DIM_MAX; ++i)
+old_dims[i] = dims[i];
+
+  nvptx_goacc_validate_dims_1 (decl, dims, fn_level);
+
+  for (i = 0; i < GOMP_DIM_MAX; ++i)
+if (old_dims[i] != dims[i])
+  return true;
+
+  return false;
 }
 
 /* Return maximum dimension size, or zero for unbounded.  */


[committed][nvptx] Add early-out cases in nvptx_goacc_validate_dims

2019-01-03 Thread Tom de Vries
Hi,

Add early-out cases for for oacc_min_dims_p and routine_p in
nvptx_goacc_validate_dims, allowing simplification of the rest of the
function.

Committed to trunk.

Thanks,
- Tom

[nvptx] Add early-out cases in nvptx_goacc_validate_dims

2019-01-03  Tom de Vries  

* config/nvptx/nvptx.c (nvptx_goacc_validate_dims_1): Add early-out
cases for oacc_min_dims_p and routine_p.  Add asserts for
oacc_default_dims_p and offload_region_p.

---
 gcc/config/nvptx/nvptx.c | 62 ++--
 1 file changed, 50 insertions(+), 12 deletions(-)

diff --git a/gcc/config/nvptx/nvptx.c b/gcc/config/nvptx/nvptx.c
index 39cf2c7b22a..8cb58341c23 100644
--- a/gcc/config/nvptx/nvptx.c
+++ b/gcc/config/nvptx/nvptx.c
@@ -5254,19 +5254,57 @@ nvptx_goacc_validate_dims_1 (tree decl, int dims[], int 
fn_level)
   dims[GOMP_DIM_GANG] = fn_level > GOMP_DIM_GANG ? 1 : 0;
 }
 
-  /* The vector size must be 32, unless this is a SEQ routine.  */
-  if ((offload_region_p || oacc_default_dims_p
-   || (routine_p && !routine_seq_p))
-  && dims[GOMP_DIM_VECTOR] >= 0
+  if (oacc_min_dims_p)
+{
+  gcc_assert (dims[GOMP_DIM_VECTOR] == 1);
+  gcc_assert (dims[GOMP_DIM_WORKER] == 1);
+  gcc_assert (dims[GOMP_DIM_GANG] == 1);
+
+  dims[GOMP_DIM_VECTOR] = PTX_WARP_SIZE;
+  return;
+}
+
+  if (routine_p)
+{
+  if (!routine_seq_p)
+   dims[GOMP_DIM_VECTOR] = PTX_WARP_SIZE;
+
+  return;
+}
+
+  if (oacc_default_dims_p)
+{
+  /* -1  : not set
+ 0  : set at runtime, f.i. -fopenacc-dims=-
+ >= 1: set at compile time, f.i. -fopenacc-dims=1.  */
+  gcc_assert (dims[GOMP_DIM_VECTOR] >= -1);
+  gcc_assert (dims[GOMP_DIM_WORKER] >= -1);
+  gcc_assert (dims[GOMP_DIM_GANG] >= -1);
+
+  /* But -fopenacc-dims=- is not yet supported on trunk.  */
+  gcc_assert (dims[GOMP_DIM_VECTOR] != 0);
+  gcc_assert (dims[GOMP_DIM_WORKER] != 0);
+  gcc_assert (dims[GOMP_DIM_GANG] != 0);
+}
+
+  if (offload_region_p)
+{
+  /* -1   : not set
+ 0   : set using variable, f.i. num_gangs (n)
+ >= 1: set using constant, f.i. num_gangs (1).  */
+  gcc_assert (dims[GOMP_DIM_VECTOR] >= -1);
+  gcc_assert (dims[GOMP_DIM_WORKER] >= -1);
+  gcc_assert (dims[GOMP_DIM_GANG] >= -1);
+}
+
+  if (dims[GOMP_DIM_VECTOR] >= 0
   && dims[GOMP_DIM_VECTOR] != PTX_VECTOR_LENGTH)
 {
-  if ((offload_region_p || oacc_default_dims_p)
- && dims[GOMP_DIM_VECTOR] >= 0)
-   warning_at (decl ? DECL_SOURCE_LOCATION (decl) : UNKNOWN_LOCATION, 0,
-   dims[GOMP_DIM_VECTOR]
-   ? G_("using vector_length (%d), ignoring %d")
-   : G_("using vector_length (%d), ignoring runtime setting"),
-   PTX_VECTOR_LENGTH, dims[GOMP_DIM_VECTOR]);
+  warning_at (decl ? DECL_SOURCE_LOCATION (decl) : UNKNOWN_LOCATION, 0,
+ dims[GOMP_DIM_VECTOR]
+ ? G_("using vector_length (%d), ignoring %d")
+ : G_("using vector_length (%d), ignoring runtime setting"),
+ PTX_VECTOR_LENGTH, dims[GOMP_DIM_VECTOR]);
   dims[GOMP_DIM_VECTOR] = PTX_VECTOR_LENGTH;
 }
 
@@ -5279,7 +5317,7 @@ nvptx_goacc_validate_dims_1 (tree decl, int dims[], int 
fn_level)
   dims[GOMP_DIM_WORKER] = PTX_WORKER_LENGTH;
 }
 
-  if (oacc_default_dims_p || oacc_min_dims_p)
+  if (oacc_default_dims_p)
 {
   dims[GOMP_DIM_VECTOR] = PTX_VECTOR_LENGTH;
   if (dims[GOMP_DIM_WORKER] < 0)


Re: Fix profile merging for thunks

2019-01-03 Thread Jan Hubicka
Hi,
since Martin in meantime backported the fix for thunk profiling which
trigers the merging bug, I also bacported the patch into GCC 8
as follows.

Bootstrapped/regtested x86_64-linux and tested on Firefox build.

2019-01-03  Jan Hubicka  

* ipa-utils.c (scale_ipa_profile_for_fn): Break out from ...
(ipa_merge_profiles): ... here; do not ICE on thunks and aliases.

Index: ipa-utils.c
===
--- ipa-utils.c (revision 267549)
+++ ipa-utils.c (working copy)
@@ -375,6 +375,20 @@ get_base_var (tree t)
   return t;
 }
 
+/* Scale function of calls in NODE by ratio ORIG_COUNT/NODE->count.  */
+
+void
+scale_ipa_profile_for_fn (struct cgraph_node *node, profile_count orig_count)
+{
+  profile_count to = node->count;
+  profile_count::adjust_for_ipa_scaling (&to, &orig_count);
+  struct cgraph_edge *e;
+  
+  for (e = node->callees; e; e = e->next_callee)
+e->count = e->count.apply_scale (to, orig_count);
+  for (e = node->indirect_calls; e; e = e->next_callee)
+e->count = e->count.apply_scale (to, orig_count);
+}
 
 /* SRC and DST are going to be merged.  Take SRC's profile and merge it into
DST so it is not going to be lost.  Possibly destroy SRC's body on the way
@@ -392,6 +406,7 @@ ipa_merge_profiles (struct cgraph_node *
   if (!src->definition
   || !dst->definition)
 return;
+
   if (src->frequency < dst->frequency)
 src->frequency = dst->frequency;
 
@@ -402,6 +417,10 @@ ipa_merge_profiles (struct cgraph_node *
   if (src->profile_id && !dst->profile_id)
 dst->profile_id = src->profile_id;
 
+  /* Merging zero profile to dst is no-op.  */
+  if (src->count.ipa () == profile_count::zero ())
+return;
+
   /* FIXME when we merge in unknown profile, we ought to set counts as
  unsafe.  */
   if (!src->count.initialized_p ()
@@ -412,11 +431,21 @@ ipa_merge_profiles (struct cgraph_node *
   fprintf (symtab->dump_file, "Merging profiles of %s to %s\n",
   src->dump_name (), dst->dump_name ());
 }
+  profile_count orig_count = dst->count;
+
   if (dst->count.initialized_p () && dst->count.ipa () == dst->count)
 dst->count += src->count.ipa ();
   else 
 dst->count = src->count.ipa ();
 
+  /* First handle functions with no gimple body.  */
+  if (dst->thunk.thunk_p || dst->alias
+  || src->thunk.thunk_p || src->alias)
+{
+  scale_ipa_profile_for_fn (dst, orig_count);
+  return;
+}
+
   /* This is ugly.  We need to get both function bodies into memory.
  If declaration is merged, we need to duplicate it to be able
  to load body that is being replaced.  This makes symbol table
@@ -641,7 +670,10 @@ ipa_merge_profiles (struct cgraph_node *
 src->release_body ();
   ipa_update_overall_fn_summary (dst);
 }
-  /* TODO: if there is no match, we can scale up.  */
+  /* We can't update CFG profile, but we can scale IPA profile. CFG
+ will be scaled according to dst->count after IPA passes.  */
+  else
+scale_ipa_profile_for_fn (dst, orig_count);
   src->decl = oldsrcdecl;
 }
 


Re: [nvptx] vector length patch series

2019-01-03 Thread Tom de Vries
On 14-12-18 20:58, Tom de Vries wrote:
> 0007-nvptx-consolidate-offloaded-function-attributes-into.patch


> diff --git a/gcc/config/nvptx/nvptx.c b/gcc/config/nvptx/nvptx.c
> index a3169febbb4..dcfa57d10ca 100644
> --- a/gcc/config/nvptx/nvptx.c
> +++ b/gcc/config/nvptx/nvptx.c
> @@ -2872,6 +2872,17 @@ nvptx_reorg_uniform_simt ()
>  }
>  }
>  
> +/* Offloading function attributes.  */
> +
> +struct offload_attrs
> +{
> +  unsigned mask;
> +  int num_gangs;
> +  int num_workers;
> +  int vector_length;
> +  int max_workers;
> +};
> +

I like the idea of factoring out the extraction of information from the
function attributes.  But max_workers is something derived from that
information, so it doesn't seem proper to add it here.

>  /* Loop structure of the function.  The entire function is described as
> a NULL loop.  */
>  
> @@ -4569,6 +4580,56 @@ nvptx_neuter_pars (parallel *par, unsigned modes, 
> unsigned outer)
>  nvptx_neuter_pars (par->next, modes, outer);
>  }
>  
> +static void
> +populate_offload_attrs (offload_attrs *oa)
> +{
> +  tree attr = oacc_get_fn_attrib (current_function_decl);
> +  tree dims = TREE_VALUE (attr);
> +  unsigned ix;
> +
> +  oa->mask = 0;
> +
> +  for (ix = 0; ix != GOMP_DIM_MAX; ix++, dims = TREE_CHAIN (dims))
> +{
> +  tree t = TREE_VALUE (dims);
> +  int size = (t == NULL_TREE) ? 0 : TREE_INT_CST_LOW (t);

This is very strange.  Why do we represent 'TREE_VALUE (dims) ==
NULL_TREE' with '0' (which means determined at runtime)? In
oacc_validate_dims we use -1 for this, which means 'not set'.

> +  tree allowed = TREE_PURPOSE (dims);
> +
> +  if (size != 1 && !(allowed && integer_zerop (allowed)))
> +   oa->mask |= GOMP_DIM_MASK (ix);
> +
> +  switch (ix)
> +   {
> +   case GOMP_DIM_GANG:
> + oa->num_gangs = size;
> + break;
> +
> +   case GOMP_DIM_WORKER:
> + oa->num_workers = size;
> + break;
> +
> +   case GOMP_DIM_VECTOR:
> + oa->vector_length = size;
> + break;
> +   }
> +}
> +

> +  if (oa->vector_length == 0)
> +{
> +  /* FIXME: Need a more graceful way to handle large vector
> +lengths in OpenACC routines.  */
> +  if (!lookup_attribute ("omp target entrypoint",
> +DECL_ATTRIBUTES (current_function_decl)))
> +   oa->vector_length = PTX_WARP_SIZE;
> +  else
> +   oa->vector_length = PTX_VECTOR_LENGTH;
> +}

The case that 'oa->vector_length == 0' is triggered by calling
populate_offload_attrs from nvptx_adjust_parallelism, which is called
before oacc_validate_dims has updated the function attributes.

This kludge is trying to resolve a circular dependency: after calling
oacc_validate_dims and updating the function attributes, we know the
chosen vector length, which is necessary for nvptx_adjust_parallelism,
which influences the used_mask given as parameter to ... oacc_validate_dims.

The way the kludge tries to cut this circular dependency is by
replicating setting of default dimensions (designed to be done in
nvptx_goacc_validate_dims) here in populate_offload_attrs.

In the counter-proposed nvptx_adjust_parallelism (
https://gcc.gnu.org/ml/gcc-patches/2018-12/msg01619.html ), we cut the
circular dependency in a different way: by reusing
nvptx_goacc_validate_dims in nvptx_adjust_parallelism.

So, we can assume oa->vector_length > 0 here, and declare this dead code.

> +  if (oa->num_workers == 0)
> +oa->max_workers = PTX_CTA_SIZE / oa->vector_length;
> +  else
> +oa->max_workers = oa->num_workers;
> +}
> +

I moved this bit to the patch introducing nvptx_mach_max_workers.

>  #if WORKAROUND_PTXJIT_BUG_2
>  /* Variant of pc_set that only requires JUMP_P (INSN) if STRICT.  This 
> variant
> is needed in the nvptx target because the branches generated for
> @@ -4750,27 +4811,19 @@ nvptx_reorg (void)
>  {
>/* If we determined this mask before RTL expansion, we could
>  elide emission of some levels of forks and joins.  */
> -  unsigned mask = 0;
> -  tree dims = TREE_VALUE (attr);
> -  unsigned ix;
> +  offload_attrs oa;
>  
> -  for (ix = 0; ix != GOMP_DIM_MAX; ix++, dims = TREE_CHAIN (dims))
> -   {
> - int size = TREE_INT_CST_LOW (TREE_VALUE (dims));
> - tree allowed = TREE_PURPOSE (dims);
> +  populate_offload_attrs (&oa);
>  
> - if (size != 1 && !(allowed && integer_zerop (allowed)))
> -   mask |= GOMP_DIM_MASK (ix);
> -   }
>/* If there is worker neutering, there must be vector
>  neutering.  Otherwise the hardware will fail.  */
> -  gcc_assert (!(mask & GOMP_DIM_MASK (GOMP_DIM_WORKER))
> - || (mask & GOMP_DIM_MASK (GOMP_DIM_VECTOR)));
> +  gcc_assert (!(oa.mask & GOMP_DIM_MASK (GOMP_DIM_WORKER))
> + || (oa.mask & GOMP_DIM_MASK (GOMP_DIM_VECTOR)));
>  
>/* Discover & process partitioned regions.  */
>parallel *pars = nvptx_d

Re: [nvptx] vector length patch series

2019-01-03 Thread Tom de Vries
On 14-12-18 20:58, Tom de Vries wrote:
> 0012-nvptx-Add-axis_dim.patch

> diff --git a/gcc/config/nvptx/nvptx.c b/gcc/config/nvptx/nvptx.c
> index 74a0d4b04d9..02ecf12bd84 100644
> --- a/gcc/config/nvptx/nvptx.c
> +++ b/gcc/config/nvptx/nvptx.c
> @@ -2885,6 +2885,23 @@ struct offload_attrs
>int max_workers;
>  };
>  
> +/* Define entries for cfun->machine->axis_dim.  */
> +
> +#define MACH_VECTOR_LENGTH 0
> +#define MACH_MAX_WORKERS 1
> +
> +static int ATTRIBUTE_UNUSED
> +nvptx_mach_max_workers ()
> +{
> +  return cfun->machine->axis_dim[MACH_MAX_WORKERS];
> +}
> +
> +static int ATTRIBUTE_UNUSED
> +nvptx_mach_vector_length ()
> +{
> +  return cfun->machine->axis_dim[MACH_VECTOR_LENGTH];
> +}
> +
>  /* Loop structure of the function.  The entire function is described as
> a NULL loop.  */
>  
> @@ -4832,6 +4849,9 @@ nvptx_reorg (void)
>  
>populate_offload_attrs (&oa);
>  
> +  cfun->machine->axis_dim[MACH_VECTOR_LENGTH] = oa.vector_length;
> +  cfun->machine->axis_dim[MACH_MAX_WORKERS] = oa.max_workers;
> +

This initialization here is done during pass_machine_reorg , but the
data is needed earlier, making it necessary there to call
populate_offload_attrs again, instead of using
nvptx_mach_vector_length/nvptx_mach_max_workers.

I've made the initialization lazy, which fixes that problem.

>/* If there is worker neutering, there must be vector
>  neutering.  Otherwise the hardware will fail.  */
>gcc_assert (!(oa.mask & GOMP_DIM_MASK (GOMP_DIM_WORKER))
> diff --git a/gcc/config/nvptx/nvptx.h b/gcc/config/nvptx/nvptx.h
> index a2fe8b68b22..4059691a609 100644
> --- a/gcc/config/nvptx/nvptx.h
> +++ b/gcc/config/nvptx/nvptx.h
> @@ -218,6 +218,8 @@ struct GTY(()) machine_function
>int return_mode; /* Return mode of current fn.
>   (machine_mode not defined yet.) */
>rtx axis_predicate[2]; /* Neutering predicates.  */
> +  int axis_dim[2]; /* Maximum number of threads on each axis, dim[0] is
> + vector_length, dim[1] is num_workers.  */
>rtx unisimt_master; /* 'Master lane index' for -muniform-simt.  */
>rtx unisimt_predicate; /* Predicate for -muniform-simt.  */
>rtx unisimt_location; /* Mask location for -muniform-simt.  */
> -- 
> 2.17.2

Committed as attached.

Thanks,
- Tom
[nvptx] Add nvptx_mach_vector_length, nvptx_mach_max_workers

The vector length and maximum number of workers are known compile-time.  Make
these easily available during code generation via new functions.

2019-01-03  Tom de Vries  

	* config/nvptx/nvptx.c (MACH_VECTOR_LENGTH, MACH_MAX_WORKERS): Define.
	(init_axis_dim, nvptx_mach_max_workers, nvptx_mach_vector_length): New
	function.
	* config/nvptx/nvptx.h (struct machine_function): Add axis_dims.

---
 gcc/config/nvptx/nvptx.c | 41 +
 gcc/config/nvptx/nvptx.h |  3 +++
 2 files changed, 44 insertions(+)

diff --git a/gcc/config/nvptx/nvptx.c b/gcc/config/nvptx/nvptx.c
index f527429ce2d..52cbac957ce 100644
--- a/gcc/config/nvptx/nvptx.c
+++ b/gcc/config/nvptx/nvptx.c
@@ -2883,6 +2883,47 @@ struct offload_attrs
   int vector_length;
 };
 
+/* Define entries for cfun->machine->axis_dim.  */
+
+#define MACH_VECTOR_LENGTH 0
+#define MACH_MAX_WORKERS 1
+
+static void populate_offload_attrs (offload_attrs *oa);
+
+static void
+init_axis_dim (void)
+{
+  offload_attrs oa;
+  int max_workers;
+
+  populate_offload_attrs (&oa);
+
+  if (oa.num_workers == 0)
+max_workers = PTX_CTA_SIZE / oa.vector_length;
+  else
+max_workers = oa.num_workers;
+
+  cfun->machine->axis_dim[MACH_VECTOR_LENGTH] = oa.vector_length;
+  cfun->machine->axis_dim[MACH_MAX_WORKERS] = max_workers;
+  cfun->machine->axis_dim_init_p = true;
+}
+
+static int ATTRIBUTE_UNUSED
+nvptx_mach_max_workers ()
+{
+  if (!cfun->machine->axis_dim_init_p)
+init_axis_dim ();
+  return cfun->machine->axis_dim[MACH_MAX_WORKERS];
+}
+
+static int ATTRIBUTE_UNUSED
+nvptx_mach_vector_length ()
+{
+  if (!cfun->machine->axis_dim_init_p)
+init_axis_dim ();
+  return cfun->machine->axis_dim[MACH_VECTOR_LENGTH];
+}
+
 /* Loop structure of the function.  The entire function is described as
a NULL loop.  */
 
diff --git a/gcc/config/nvptx/nvptx.h b/gcc/config/nvptx/nvptx.h
index a2fe8b68b22..cb4404504c5 100644
--- a/gcc/config/nvptx/nvptx.h
+++ b/gcc/config/nvptx/nvptx.h
@@ -218,6 +218,9 @@ struct GTY(()) machine_function
   int return_mode; /* Return mode of current fn.
 		  (machine_mode not defined yet.) */
   rtx axis_predicate[2]; /* Neutering predicates.  */
+  int axis_dim[2]; /* Maximum number of threads on each axis, dim[0] is
+		  vector_length, dim[1] is num_workers.  */
+  bool axis_dim_init_p;
   rtx unisimt_master; /* 'Master lane index' for -muniform-simt.  */
   rtx unisimt_predicate; /* Predicate for -muniform-simt.  */
   rtx unisimt_location; /* Mask location for -muniform-simt.  */


Re: [nvptx] vector length patch series

2019-01-03 Thread Tom de Vries
On 14-12-18 20:58, Tom de Vries wrote:
> 0016-nvptx-Add-vector_length-128-testcases.patch


> * testsuite/libgomp.oacc-c-c++-common/vred2d-128.c: New test. 
> 
> * testsuite/libgomp.oacc-fortran/gemm.f90: New test.  
> 
> * testsuite/libgomp.oacc-c-c++-common/vector-length-128-10.c: New 
> test.   

These test-cases fail at the point that they're introduced in the patch
series, which is not a good idea.

> * testsuite/libgomp.oacc-c-c++-common/vector-length-128-1.c: New 
> test.
> * testsuite/libgomp.oacc-c-c++-common/vector-length-128-3.c: New 
> test.

These test-cases could have been committed as obvious.

Committed last two as attached.

Thanks,
- Tom
[nvptx] Add vector_length 128 testcases

Add a couple of test-cases using vector length 128, while checking that we
override to vector length 32.

2018-12-17  Tom de Vries  

	* testsuite/libgomp.oacc-c-c++-common/vector-length-128-1.c: New test.
	* testsuite/libgomp.oacc-c-c++-common/vector-length-128-3.c: New test.

---
 .../vector-length-128-1.c  | 39 
 .../vector-length-128-3.c  | 42 ++
 2 files changed, 81 insertions(+)

diff --git a/libgomp/testsuite/libgomp.oacc-c-c++-common/vector-length-128-1.c b/libgomp/testsuite/libgomp.oacc-c-c++-common/vector-length-128-1.c
new file mode 100644
index 000..fab5b0d25d1
--- /dev/null
+++ b/libgomp/testsuite/libgomp.oacc-c-c++-common/vector-length-128-1.c
@@ -0,0 +1,39 @@
+/* { dg-do run { target openacc_nvidia_accel_selected } } */
+/* { dg-additional-options "-foffload=-fdump-tree-oaccdevlow" } */
+/* { dg-set-target-env-var "GOMP_DEBUG" "1" } */
+
+#include 
+
+#define N 1024
+
+unsigned int a[N];
+unsigned int b[N];
+unsigned int c[N];
+unsigned int n = N;
+
+int
+main (void)
+{
+  for (unsigned int i = 0; i < n; ++i)
+{
+  a[i] = i % 3;
+  b[i] = i % 5;
+}
+
+#pragma acc parallel vector_length (128) copyin (a,b) copyout (c)
+  {
+#pragma acc loop vector
+for (unsigned int i = 0; i < n; i++)
+  c[i] = a[i] + b[i];
+  }
+
+  for (unsigned int i = 0; i < n; ++i)
+if (c[i] != (i % 3) + (i % 5))
+  abort ();
+
+  return 0;
+}
+/* { dg-prune-output "using vector_length \\(32\\), ignoring 128" } */
+
+/* { dg-final { scan-offload-tree-dump "__attribute__\\(\\(oacc function \\(1, 1, 32\\)" "oaccdevlow" } } */
+/* { dg-output "nvptx_exec: kernel main\\\$_omp_fn\\\$0: launch gangs=1, workers=1, vectors=32" } */
diff --git a/libgomp/testsuite/libgomp.oacc-c-c++-common/vector-length-128-3.c b/libgomp/testsuite/libgomp.oacc-c-c++-common/vector-length-128-3.c
new file mode 100644
index 000..c403e74658b
--- /dev/null
+++ b/libgomp/testsuite/libgomp.oacc-c-c++-common/vector-length-128-3.c
@@ -0,0 +1,42 @@
+/* { dg-do run { target openacc_nvidia_accel_selected } } */
+/* { dg-additional-options "-foffload=-fdump-tree-oaccdevlow" } */
+/* We default to warp size 32 for the vector length, so the GOMP_OPENACC_DIM has
+   no effect.  */
+/* { dg-set-target-env-var "GOMP_OPENACC_DIM" "-:-:128" } */
+/* { dg-set-target-env-var "GOMP_DEBUG" "1" } */
+
+
+#include 
+
+#define N 1024
+
+unsigned int a[N];
+unsigned int b[N];
+unsigned int c[N];
+unsigned int n = N;
+
+int
+main (void)
+{
+  for (unsigned int i = 0; i < n; ++i)
+{
+  a[i] = i % 3;
+  b[i] = i % 5;
+}
+
+#pragma acc parallel copyin (a,b) copyout (c)
+  {
+#pragma acc loop vector
+for (unsigned int i = 0; i < n; i++)
+  c[i] = a[i] + b[i];
+  }
+
+  for (unsigned int i = 0; i < n; ++i)
+if (c[i] != (i % 3) + (i % 5))
+  abort ();
+
+  return 0;
+}
+
+/* { dg-final { scan-offload-tree-dump "__attribute__\\(\\(oacc function \\(1, 1, 32\\)" "oaccdevlow" } } */
+/* { dg-output "nvptx_exec: kernel main\\\$_omp_fn\\\$0: launch gangs=1, workers=1, vectors=32" } */


Re: [PATCH] Add __builtin_convertvector support (PR c++/85052)

2019-01-03 Thread Martin Sebor

+/* Build a VEC_CONVERT ifn for __builtin_convertvector builtin.  */


Can you please document the function arguments and explain how they
are used?


+
+tree
+c_build_vec_convert (location_t loc1, tree expr, location_t loc2, tree type,
+bool complain)
+{
+  if (error_operand_p (type))
+return error_mark_node;
+  if (error_operand_p (expr))
+return error_mark_node;
+
+  if (!VECTOR_INTEGER_TYPE_P (TREE_TYPE (expr))
+  && !VECTOR_FLOAT_TYPE_P (TREE_TYPE (expr)))
+{
+  if (complain)
+   error_at (loc1, "%<__builtin_convertvector%> first argument must "
+   "be an integer or floating vector");
+  return error_mark_node;
+}
+
+  if (!VECTOR_INTEGER_TYPE_P (type) && !VECTOR_FLOAT_TYPE_P (type))
+{
+  if (complain)
+   error_at (loc2, "%<__builtin_convertvector%> second argument must "
+   "be an integer or floating vector type");
+  return error_mark_node;
+}
+
+  if (maybe_ne (TYPE_VECTOR_SUBPARTS (TREE_TYPE (expr)),
+   TYPE_VECTOR_SUBPARTS (type)))
+{
+  if (complain)
+   error_at (loc1, "%<__builtin_convertvector%> number of elements "
+   "of the first argument vector and the second argument "
+   "vector type should be the same");
+  return error_mark_node;
+}


Just a few wording suggestions for the errors:

1) for the first two errors consider using a single message
   parameterized on the argument number to reduce translation effort
   (both styles are in use but the more concise form seems preferable
   to me)
2) in the last error use "must" instead of "should" as in the first
   two ("must" is imperative rather than just suggestive)
3) consider simplifying the third message to "%<...%> argument
   vectors must have the same size" (or "the same number of
   elements") along the same lines as in c_build_vec_perm_expr.


+
+  if ((TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (expr)))
+   == TYPE_MAIN_VARIANT (TREE_TYPE (type)))
+  || (VECTOR_INTEGER_TYPE_P (TREE_TYPE (expr))
+ && VECTOR_INTEGER_TYPE_P (type)
+ && (TYPE_PRECISION (TREE_TYPE (TREE_TYPE (expr)))
+ == TYPE_PRECISION (TREE_TYPE (type)
+return build1_loc (loc1, VIEW_CONVERT_EXPR, type, expr);


The conditional above is very difficult to read, and without
a comment explaining its purpose, difficult to understand.
Introducing named temporaries for the repetitive subexpressions
would help with the readability (not just here but in rest of
the function as well).  A comment explaining what the conditional
handles would help with the latter.


+
+  bool wrap = true;
+  bool maybe_const = false;
+  tree ret;


Moving maybe_const to the conditional block where it's used and ret
to the point of its initialization just after that block would improve
readability.


+  if (!c_dialect_cxx ())
+{
+  /* Avoid C_MAYBE_CONST_EXPRs inside of VEC_CONVERT argument.  */
+  expr = c_fully_fold (expr, false, &maybe_const);
+  wrap &= maybe_const;
+}
+
+  ret = build_call_expr_internal_loc (loc1, IFN_VEC_CONVERT, type, 1, expr);
+
+  if (!wrap)
+ret = c_wrap_maybe_const (ret, true);
+
+  return ret;
  }


Martin


Re: [PATCH] genattrtab bit-rot, and if_then_else in values

2019-01-03 Thread Richard Sandiford
Alan Modra  writes:
> On Thu, Jan 03, 2019 at 12:41:52PM +, Richard Sandiford wrote:
>> Alan Modra  writes:
>> > +case PLUS:
>> > +  current_or = or_attr_value (XEXP (exp, 0));
>> > +  if (current_or != -1)
>> > +  {
>> > +int n = current_or;
>> > +current_or = or_attr_value (XEXP (exp, 1));
>> > +if (current_or != -1)
>> > +  current_or += n;
>> > +  }
>> > +  break;
>> 
>> This doesn't look right.  Doing the same for IOR and |= would be OK
>> in principle, but write_attr_value doesn't handle IOR yet.
>
> From what I can see, or_attr_value is used to find the largest power
> of two that divides all attr length values for a given insn.  So what
> should be done for PLUS in an attr length value expression?  I can't
> simply ignore it as then or_attr_value will return -1 and we'll
> calculate length_unit_log as 0 on powerpc when it ought to be 2.
> That might matter some time in the future.

Ah, OK.

> If the operands of PLUS are assumed to be insn lengths (reasonable,
> since you're likely to use PLUS to sum the machine insn lengths of a
> pattern that conditionally emits multiple machine insns), then it
> might be better to replace "current_or += n" above with
> "current_or |= n".  That would be correct for a length expression of
>   (plus (if_then_else (condA) (const_int 4) (const_int 0))
> (if_then_else (condB) (const_int 8) (const_int 4)))
> where any answer from or_attr_value that has 3 lsbs of 100b is
> sufficently correct.  If I keep "+=" then we'd get the wrong answer in
> this particular example.  However "|=" is wrong if someone is playing
> games and writes a silly expression like
>   (plus (const_int 1) (const_int 3))
> since the length is always 4.
>
>> OK with the above dropped, thanks.
>
> Maybe this instead?
>
> case PLUS:
>   current_or = or_attr_value (XEXP (exp, 0));
>   current_or |= or_attr_value (XEXP (exp, 1));
>   break;

This still seems risky and isn't what the name and function comment
imply.  Maybe we should replace or_attr_value with something like
floor_log2_attr_value or attr_value_alignment?

Thanks,
Richard


Re: [PATCH] Add __builtin_convertvector support (PR c++/85052)

2019-01-03 Thread Marc Glisse

On Thu, 3 Jan 2019, Jakub Jelinek wrote:


On Thu, Jan 03, 2019 at 11:48:12AM +0100, Marc Glisse wrote:

The following patch adds support for the __builtin_convertvector builtin.
C casts on generic vectors are just reinterpretation of the bits (i.e. a
VCE), this builtin allows to cast int/unsigned elements to float or vice
versa or promote/demote them.  doc/ change is missing, will write it soon.

The builtin appeared in I think clang 3.4 and is apparently in real-world
use as e.g. Honza reported.  The first argument is an expression with vector
type, the second argument is a vector type (similarly e.g. to va_arg), to
which the first argument should be converted.  Both vector types need to
have the same number of elements.

I've implemented same element size (thus also whole vector size) conversions
efficiently - signed to unsigned and vice versa or same vector type just
using a VCE, for e.g. int <-> float or long long <-> double using
appropriate optab, possibly repeated multiple times for very large vectors.


IIUC, you only lower __builtin_convertvector to VCE or FLOAT_EXPR or
whatever in tree-vect-generic. That seems quite late. At least for the
"easy" same-size case, I think we should do it early (gimplification?),


No, it must not be done at gimplification time, think about OpenMP/OpenACC
offloading, the target before IPA optimizations might not be the target
after them, while they have to agree on ABI issues, the optabs definitely
can be and are different and these optabs originally added for the
vectorizer are something that doesn't have a fallback, whatever introduces
it into the IL is responsible for verification it is supported.


Ah, I was missing this. And I don't see why we should keep it that way. As 
long as the vectorizer was the only producer, it made sense not to have a 
fallback, it was not needed. But now that we are talking of having the 
user produce it almost directly, it would make sense for it to behave like 
other vector operations (say PLUS_EXPR).



That said, not sure if e.g. using an opaque builtin for the conversion that
supportable_convert_operation sometimes uses is better over this ifn.
What exact optimization opportunities you are looking for if it is lowered
earlier?  I have the VECTOR_CST folding in place...


I don't know, any kind of optimization we currently do on scalars... For 
conversions between integers and floats, that seems to be very limited, 
maybe combine consecutive casts in rare cases. For sign changes, we have a 
number of transformations in match.pd that are fine with an intermediate 
cast that only changes the sign (I even introduced nop_convert to handle 
vectors at the same time). I guess we could handle this IFN as well. It is 
just that having 2 ways to express the same thing tends to cause code 
duplication.


On the other hand, for narrowing/widening conversions, keeping it as one 
stmt with your ifn may be more convenient to optimize than a large mess of 
VEC_UNPACK_FLOAT_HI_EXPR and friends. Again I am thinking more of match.pd 
type of transformation, nothing that looks at the target.


--
Marc Glisse


Re: [PATCH] genattrtab bit-rot, and if_then_else in values

2019-01-03 Thread Richard Sandiford
Richard Sandiford  writes:
> Alan Modra  writes:
>> If the operands of PLUS are assumed to be insn lengths (reasonable,
>> since you're likely to use PLUS to sum the machine insn lengths of a
>> pattern that conditionally emits multiple machine insns), then it
>> might be better to replace "current_or += n" above with
>> "current_or |= n".  That would be correct for a length expression of
>>  (plus (if_then_else (condA) (const_int 4) (const_int 0))
>>(if_then_else (condB) (const_int 8) (const_int 4)))
>> where any answer from or_attr_value that has 3 lsbs of 100b is
>> sufficently correct.  If I keep "+=" then we'd get the wrong answer in
>> this particular example.  However "|=" is wrong if someone is playing
>> games and writes a silly expression like
>>  (plus (const_int 1) (const_int 3))
>> since the length is always 4.
>>
>>> OK with the above dropped, thanks.
>>
>> Maybe this instead?
>>
>> case PLUS:
>>   current_or = or_attr_value (XEXP (exp, 0));
>>   current_or |= or_attr_value (XEXP (exp, 1));
>>   break;
>
> This still seems risky and isn't what the name and function comment
> imply.  Maybe we should replace or_attr_value with something like
> floor_log2_attr_value or attr_value_alignment?

Er, forget floor_log2_attr_value :-)  First day back, etc. etc.


[PATCH] PR libstdc++/88607 replace or remove unnecessary UTF-8 characters

2019-01-03 Thread Jonathan Wakely

There are a number of UTF-8 characters in comments which add no value
and can be replaced with ASCII equivalents, or removed entirely for the
section sign (U+00A7).

PR libstdc++/88607
* include/bits/forward_list.h: Replace UTF-8 "ligature fi" character.
* include/debug/forward_list: Likewise.
* include/experimental/bits/shared_ptr.h: Remove UTF-8 "section sign"
character.
* include/experimental/chrono: Likewise.
* include/experimental/functional: Likewise.
* include/experimental/ratio: Likewise.
* include/experimental/system_error: Likewise.
* include/experimental/tuple: Likewise.
* include/experimental/type_traits: Likewise.
* include/parallel/workstealing.h: Replace UTF-8 "en dash" character.
* include/parallel/multiseq_selection.h: Likewise.

Tested powerpc64-linux, committed to trunk.

commit 5b93c250295edf46bc7e69b64fb4304e2ade4a1d
Author: Jonathan Wakely 
Date:   Thu Jan 3 20:22:30 2019 +

PR libstdc++/88607 replace or remove unnecessary UTF-8 characters

There are a number of UTF-8 characters in comments which add no value
and can be replaced with ASCII equivalents, or removed entirely for the
section sign (U+00A7).

PR libstdc++/88607
* include/bits/forward_list.h: Replace UTF-8 "ligature fi" 
character.
* include/debug/forward_list: Likewise.
* include/experimental/bits/shared_ptr.h: Remove UTF-8 "section 
sign"
character.
* include/experimental/chrono: Likewise.
* include/experimental/functional: Likewise.
* include/experimental/ratio: Likewise.
* include/experimental/system_error: Likewise.
* include/experimental/tuple: Likewise.
* include/experimental/type_traits: Likewise.
* include/parallel/workstealing.h: Replace UTF-8 "en dash" 
character.
* include/parallel/multiseq_selection.h: Likewise.

diff --git a/libstdc++-v3/include/bits/forward_list.h 
b/libstdc++-v3/include/bits/forward_list.h
index 1ccad5f6f21..4741c43376c 100644
--- a/libstdc++-v3/include/bits/forward_list.h
+++ b/libstdc++-v3/include/bits/forward_list.h
@@ -809,7 +809,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
return *__front->_M_valptr();
   }
 
-  // 23.3.4.5 modifiers:
+  // 23.3.4.5 modifiers:
 
   /**
*  @brief  Constructs object in %forward_list at the front of the
diff --git a/libstdc++-v3/include/debug/forward_list 
b/libstdc++-v3/include/debug/forward_list
index 1af792c9798..e30b09e 100644
--- a/libstdc++-v3/include/debug/forward_list
+++ b/libstdc++-v3/include/debug/forward_list
@@ -369,7 +369,7 @@ namespace __debug
return _Base::front();
   }
 
-  // modifiers:
+  // modifiers:
 
   using _Base::emplace_front;
   using _Base::push_front;
diff --git a/libstdc++-v3/include/experimental/bits/shared_ptr.h 
b/libstdc++-v3/include/experimental/bits/shared_ptr.h
index 01962f2c07a..65df4dd7e3b 100644
--- a/libstdc++-v3/include/experimental/bits/shared_ptr.h
+++ b/libstdc++-v3/include/experimental/bits/shared_ptr.h
@@ -157,10 +157,10 @@ inline namespace fundamentals_v2
   constexpr shared_ptr(nullptr_t __p)
   : _Base_type(__p) { }
 
-  // C++14 §20.8.2.2
+  // C++14 20.8.2.2
   ~shared_ptr() = default;
 
-  // C++14 §20.8.2.3
+  // C++14 20.8.2.3
   shared_ptr& operator=(const shared_ptr&) noexcept = default;
 
   template 
@@ -204,7 +204,7 @@ inline namespace fundamentals_v2
  return *this;
}
 
-  // C++14 §20.8.2.2.4
+  // C++14 20.8.2.2.4
   // swap & reset
   // 8.2.1.2 shared_ptr observers
   // in __shared_ptr
@@ -255,7 +255,7 @@ inline namespace fundamentals_v2
{ }
 };
 
-  // C++14 §20.8.2.2.7 //DOING
+  // C++14 20.8.2.2.7
   template
 bool operator==(const shared_ptr<_Tp1>& __a,
const shared_ptr<_Tp2>& __b) noexcept
@@ -368,7 +368,7 @@ inline namespace fundamentals_v2
 operator>=(nullptr_t, const shared_ptr<_Tp>& __a) noexcept
 { return !(nullptr < __a); }
 
-  // C++14 §20.8.2.2.8
+  // C++14 20.8.2.2.8
   template
 inline void
 swap(shared_ptr<_Tp>& __a, shared_ptr<_Tp>& __b) noexcept
@@ -409,7 +409,7 @@ inline namespace fundamentals_v2
   return shared_ptr<_Tp>(__r, reinterpret_cast<__elem_t*>(__r.get()));
 }
 
-  // C++14 §20.8.2.3
+  // C++14 20.8.2.3
   template
 class weak_ptr : public __weak_ptr<_Tp>
 {
@@ -474,19 +474,19 @@ inline namespace fundamentals_v2
friend class enable_shared_from_this<_Tp>;
 };
 
-  // C++14 §20.8.2.3.6
+  // C++14 20.8.2.3.6
   template
 inline void
 swap(weak_ptr<_Tp>& __a, weak_ptr<_Tp>& __b) noexcept
 { __a.swap(__b); }
 
-  /// C++14 §20.8.2.2.10
+  /// C++14 20.8.2.2.10
   template
 inline _Del*
 get_deleter(const shared_ptr<_Tp>& __p) noexcept
 { return std::g

[PATCH] PR libstdc++/88681 export missing symbols

2019-01-03 Thread Jonathan Wakely

These new facet functions were added to GCC 5.1 but the versions for the
old std::string ABI were never exported from the shared library.

PR libstdc++/88681
* config/abi/pre/gnu.ver: Add missing exports.
* testsuite/22_locale/collate_byname/88681.cc: New test.
* testsuite/22_locale/time_get/get/char/88681.cc: New test.
* testsuite/22_locale/time_get/get/wchar_t/88681.cc: New test.

Tested x86_64-linux and powerpc64-linux, committed to trunk.

Target maintainers, please don't regenerate your baseline-symbols.txt
files yet as there are more new symbols to be added over the next day
or two.


commit 493cfc957f344091a28eef80c2c8f851cca26fb5
Author: Jonathan Wakely 
Date:   Thu Jan 3 19:38:39 2019 +

PR libstdc++/88681 export missing symbols

These new facet functions were added to GCC 5.1 but the versions for the
old std::string ABI were never exported from the shared library.

PR libstdc++/88681
* config/abi/pre/gnu.ver: Add missing exports.
* testsuite/22_locale/collate_byname/88681.cc: New test.
* testsuite/22_locale/time_get/get/char/88681.cc: New test.
* testsuite/22_locale/time_get/get/wchar_t/88681.cc: New test.

diff --git a/libstdc++-v3/config/abi/pre/gnu.ver 
b/libstdc++-v3/config/abi/pre/gnu.ver
index 42697afc30f..de3c87abf15 100644
--- a/libstdc++-v3/config/abi/pre/gnu.ver
+++ b/libstdc++-v3/config/abi/pre/gnu.ver
@@ -2069,6 +2069,9 @@ GLIBCXX_3.4.26 {
 _ZNSt3pmr28unsynchronized_pool_resource11do_allocateE[jmy][jmy];
 _ZNSt3pmr28unsynchronized_pool_resource13do_deallocateEPv[jmy][jmy];
 
+_ZNSt14collate_bynameI[cw]EC[12]ERKSs[jmy];
+
_ZNKSt8time_getI[cw]St19istreambuf_iteratorI[cw]St11char_traitsI[cw]EEE3getES3_S3_RSt8ios_baseRSt12_Ios_IostateP2tmcc;
+
 } GLIBCXX_3.4.25;
 
 # Symbols in the support library (libsupc++) have their own tag.
diff --git a/libstdc++-v3/testsuite/22_locale/collate_byname/88681.cc 
b/libstdc++-v3/testsuite/22_locale/collate_byname/88681.cc
new file mode 100644
index 000..863319dc82c
--- /dev/null
+++ b/libstdc++-v3/testsuite/22_locale/collate_byname/88681.cc
@@ -0,0 +1,48 @@
+// Copyright (C) 2019 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3.  If not see
+// .
+
+// { dg-options "-fno-inline" }
+// { dg-do link { target c++11 } }
+
+#undef _GLIBCXX_USE_CXX11_ABI
+#define _GLIBCXX_USE_CXX11_ABI 0
+#include 
+#include 
+
+std::string s = "C";
+
+template
+struct facet : std::collate_byname
+{
+  facet() : std::collate_byname(s) { }
+};
+
+void
+test01()
+{
+  facet c;
+
+#ifdef _GLIBCXX_USE_WCHAR_T
+  facet w;
+#endif
+}
+
+int
+main()
+{
+  test01();
+}
diff --git a/libstdc++-v3/testsuite/22_locale/time_get/get/char/88681.cc 
b/libstdc++-v3/testsuite/22_locale/time_get/get/char/88681.cc
new file mode 100644
index 000..5365871409f
--- /dev/null
+++ b/libstdc++-v3/testsuite/22_locale/time_get/get/char/88681.cc
@@ -0,0 +1,51 @@
+// Copyright (C) 2019 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3.  If not see
+// .
+
+// { dg-options "-fno-inline" }
+// { dg-do link { target c++11 } }
+
+#undef _GLIBCXX_USE_CXX11_ABI
+#define _GLIBCXX_USE_CXX11_ABI 0
+#include 
+#include 
+
+using C = char;
+
+void
+test01()
+{
+  using namespace std;
+
+  locale loc_c = locale::classic();
+
+  basic_istringstream iss;
+  iss.imbue(loc_c);
+  const time_get& tget = use_facet>(iss.getloc());
+  typedef istreambuf_iterator iter;
+  const iter end;
+
+  tm time;
+  ios_base::iostate err = ios_base::badbit;
+
+  tget.get(iter(iss), end, iss, err, &time, 'Y');
+}
+
+int
+main()
+{
+  test01();
+}
d

Re: [PATCH] PR libstdc++/88607 replace or remove unnecessary UTF-8 characters

2019-01-03 Thread Jonathan Wakely

On 03/01/19 20:38 +, Jonathan Wakely wrote:

There are a number of UTF-8 characters in comments which add no value
and can be replaced with ASCII equivalents, or removed entirely for the
section sign (U+00A7).

PR libstdc++/88607
* include/bits/forward_list.h: Replace UTF-8 "ligature fi" character.
* include/debug/forward_list: Likewise.
* include/experimental/bits/shared_ptr.h: Remove UTF-8 "section sign"
character.
* include/experimental/chrono: Likewise.
* include/experimental/functional: Likewise.
* include/experimental/ratio: Likewise.
* include/experimental/system_error: Likewise.
* include/experimental/tuple: Likewise.
* include/experimental/type_traits: Likewise.
* include/parallel/workstealing.h: Replace UTF-8 "en dash" character.
* include/parallel/multiseq_selection.h: Likewise.


This replaces some more non-ASCII characters.

Tested powerpc64-linux, committed to trunk.

commit e539e235bc31bfe1011ad3cd5df14d827f387c33
Author: Jonathan Wakely 
Date:   Thu Jan 3 21:56:50 2019 +

PR libstdc++/88607 replace some more UTF-8 characters

2019-01-03  Jonathan Wakely  
Jakub Jelinek  

PR libstdc++/88607
* include/experimental/memory: Replace UTF-8 quote characters.
* include/std/future: Replace UTF-8 "em dash" characters.

diff --git a/libstdc++-v3/include/experimental/memory b/libstdc++-v3/include/experimental/memory
index 955f83072b9..b8faeb23eef 100644
--- a/libstdc++-v3/include/experimental/memory
+++ b/libstdc++-v3/include/experimental/memory
@@ -63,12 +63,12 @@ inline namespace fundamentals_v2
   using __reference = add_lvalue_reference_t<_Tp>; // exposition-only
 
   // 3.2.2, observer_ptr constructors
-  // default c’tor
+  // default c'tor
   constexpr observer_ptr() noexcept
   : __t()
   { }
 
-  // pointer-accepting c’tors
+  // pointer-accepting c'tors
   constexpr observer_ptr(nullptr_t) noexcept
   : __t()
   { }
@@ -77,7 +77,7 @@ inline namespace fundamentals_v2
   : __t(__p)
   { }
 
-  // copying c’tors (in addition to compiler-generated copy c’tor)
+  // copying c'tors (in addition to compiler-generated copy c'tor)
   template ::type, __pointer
diff --git a/libstdc++-v3/include/std/future b/libstdc++-v3/include/std/future
index 2b60c58f3bc..6cafde5ee6a 100644
--- a/libstdc++-v3/include/std/future
+++ b/libstdc++-v3/include/std/future
@@ -1629,11 +1629,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 //
 // [futures.async]:
 //
-// — a call to a waiting function on an asynchronous return object that
+// - a call to a waiting function on an asynchronous return object that
 // shares the shared state created by this async call shall block until
 // the associated thread has completed, as if joined, or else time out.
 //
-// — the associated thread completion synchronizes with the return from
+// - the associated thread completion synchronizes with the return from
 // the first function that successfully detects the ready status of the
 // shared state or with the return from the last function that releases
 // the shared state, whichever happens first.


Re: [PATCH] attribute copy, leaf, weakref and -Wmisisng-attributes (PR 88546)

2019-01-03 Thread Martin Sebor

Ping: https://gcc.gnu.org/ml/gcc-patches/2018-12/msg01616.html

(The first sentence in the second paragraph below should have
read "...independently of the question whether leaf should be
accepted on extern declarations.")

On 12/21/18 4:50 PM, Martin Sebor wrote:

The first revision of the patch was missing a test and didn't
completely or completely correctly handle attribute noreturn.
Attached is an update with the test included and the omission
and bug fixed.

I think it makes sense to consider the patch independently of
the question whether weakrefs should be extern.  That change can
be made separately, with only minor tweaks to the attribute copy
handling and the warning.  None of the other fixes in this patch
(precipitated by more thorough testing) should be affected by it.

Martin

On 12/20/18 8:45 PM, Martin Sebor wrote:

The enhancement to detect mismatched attributes between function
aliases and their targets triggers (expected) warnings in GCC
builds due to aliases being declared with fewer attributes than
their targets.

Using attribute copy as recommended to copy the attributes from
the target to the alias triggers another warning, this time due
to applying attribute leaf to static functions (the attribute
only applies to extern functions).  This is due to an oversight
in both the handler for attribute copy and in
the -Wmissing-attributes warning.

In addition, the copy attribute handler doesn't account for C11
_Noreturn and C++ throw() specifications, both of which set
the corresponding tree bits but don't attach the synonymous
attribute to it.  This also leads to warnings in GCC builds
(in libgfortran).

The attached patch corrects all of these problems: the attribute
copy handler to avoid copying attribute leaf to declarations of
static functions, and to set the noreturn and nonthrow bits, and
the missing attribute warning to avoid triggering for static
weakref aliases whose targets are decorated wiwth attribute leaf.

With this patch, GCC should build with no -Wmissing-attributes
warnings.

Tested on x86_64-linux.

Martin






Re: [PATCH] attribute copy, leaf, weakref and -Wmisisng-attributes (PR 88546)

2019-01-03 Thread Martin Sebor

Ping: https://gcc.gnu.org/ml/gcc-patches/2018-12/msg01616.html

(The first sentence in the second paragraph below should have
read "...independently of the question whether leaf should be
accepted on extern declarations.")

On 12/21/18 4:50 PM, Martin Sebor wrote:

The first revision of the patch was missing a test and didn't
completely or completely correctly handle attribute noreturn.
Attached is an update with the test included and the omission
and bug fixed.

I think it makes sense to consider the patch independently of
the question whether weakrefs should be extern.  That change can
be made separately, with only minor tweaks to the attribute copy
handling and the warning.  None of the other fixes in this patch
(precipitated by more thorough testing) should be affected by it.

Martin

On 12/20/18 8:45 PM, Martin Sebor wrote:

The enhancement to detect mismatched attributes between function
aliases and their targets triggers (expected) warnings in GCC
builds due to aliases being declared with fewer attributes than
their targets.

Using attribute copy as recommended to copy the attributes from
the target to the alias triggers another warning, this time due
to applying attribute leaf to static functions (the attribute
only applies to extern functions).  This is due to an oversight
in both the handler for attribute copy and in
the -Wmissing-attributes warning.

In addition, the copy attribute handler doesn't account for C11
_Noreturn and C++ throw() specifications, both of which set
the corresponding tree bits but don't attach the synonymous
attribute to it.  This also leads to warnings in GCC builds
(in libgfortran).

The attached patch corrects all of these problems: the attribute
copy handler to avoid copying attribute leaf to declarations of
static functions, and to set the noreturn and nonthrow bits, and
the missing attribute warning to avoid triggering for static
weakref aliases whose targets are decorated wiwth attribute leaf.

With this patch, GCC should build with no -Wmissing-attributes
warnings.

Tested on x86_64-linux.

Martin






PING #2 [PATCH] accept all C integer types in function parameters referenced by alloc_align (PR 88363)

2019-01-03 Thread Martin Sebor

Ping: https://gcc.gnu.org/ml/gcc-patches/2018-12/msg00740.html

On 12/18/18 2:42 PM, Martin Sebor wrote:

On 12/11/18 4:19 PM, Jason Merrill wrote:

On 12/11/18 6:08 PM, Martin Sebor wrote:

On 12/11/18 3:52 PM, Marek Polacek wrote:

On Tue, Dec 11, 2018 at 03:46:37PM -0700, Martin Sebor wrote:

On 12/11/18 1:47 PM, Jakub Jelinek wrote:

On Tue, Dec 11, 2018 at 01:36:58PM -0700, Martin Sebor wrote:

Attached is an updated version of the patch that restores
the original behavior for the positional argument validation
(i.e., prior to r266195) for integral types except bool as
discussed.


I thought Jason wanted to also warn for scoped enums in C++.


I missed that.  It seems needlessly restrictive to me to reject
the preferred kind of an enum when ordinary enums are accepted.
Jason, can you confirm that you really want a warning for B
below when there is none for A (GCC 8 doesn't complain about
either, Clang complains about both, ICC about neither when
using alloc_size -- it doesn't understand alloc_align):

   enum A { /* ... */ };
   __attribute__ ((alloc_align (1))) void* f (A);

   enum class B { /* ... */ };
   __attribute__ ((alloc_align (1))) void* g (B);

The only use case I can think of for enums is in APIs that try
to restrict the available choices of alignment to those of
the enumerators.  In that use case, I would expect it to make
no difference whether the enum is ordinary or the scoped kind.


The reason was that C++ scoped enumerations don't implicitly convert to
integral types.


I'm not sure we're talking about the same thing.  There is no
conversion in the use case I described, the attribute argument
just refers to the function parameter, and the function is called
with an argument of the enumerated type of the parameter.  Like
this:

   enum class Alignment { a4 = 4, a8 = 8 };

   __attribute__ ((alloc_align (1))) void*
   aligned_alloc (Alignment, size_t);

   void *p = aligned_alloc (Alignment::a8, 32);

My question is: if we think it makes sense to accept this use
case with ordinary enums why would we not want to make it possible
with scoped enums?  People tend to think of the latter as preferable
over the former.


OK, I suppose it's reasonable to allow scoped enums as well.


Are there any other suggestions for changes or should I take
this as an approval to commit the updated patch?

https://gcc.gnu.org/ml/gcc-patches/2018-12/msg00740.html

Martin




Re: [PATCH] Don't run ident tests on powerpc-darwin

2019-01-03 Thread Mike Stump
On Jan 2, 2019, at 5:39 AM, Rainer Orth  wrote:
> 
> It's on the brink, I'd say.  The effective-keyword form is shorter and
> more descriptive and can be extended to more targets way more easily.
> Checking 2018-12 testresults, I find failures of the ident-*.c tests on
> hppa2.0w-hp-hpux11.11 and powerpc-ibm-aix7.2.0.0.  If those were to be
> handled as well, I'd strongly prefer the effective-keyword variant
> rather than adding more and more targets to the individual tests.

For a completely different thought, we can compare to a fine grain feature 
database that dejagnu or the running program can probe and adjust for...

#ifdef __has_feature(directive_ident)
#endif

then, this is directly populated from the port's #define, and the duplication 
is gone.  I think I like this direction.  Let maintenance, faster port time, 
higher quality port, and testing less noisy in general.

Re: [Fortran, test case, committed] Test case for PR 48543

2019-01-03 Thread Jakub Jelinek
On Thu, Jan 03, 2019 at 01:36:30PM +0100, Thomas Koenig wrote:
> Hi Jakub,
> 
> > In any case, IMHO the test should be removed or XFAILed for now.
> 
> thanks for your explanations. I have removed the test case.

You've actually removed a different testcase (which was working fine),
while the ChangeLog says const_character_merge.f90 has been removed,
you've removed merge_char_const.f90.

Jakub


PING [PATCH] handle expressions in __builtin_has_attribute (PR 88383)

2019-01-03 Thread Martin Sebor

Ping: https://gcc.gnu.org/ml/gcc-patches/2018-12/msg00337.html

On 12/20/18 7:51 PM, Martin Sebor wrote:

Jeff, did this and the rest of the discussion answer your question
and if so, is the patch okay to commit?

   https://gcc.gnu.org/ml/gcc-patches/2018-12/msg00337.html

Martin

On 12/13/18 12:48 PM, Martin Sebor wrote:

On 12/13/18 12:20 PM, Martin Sebor wrote:

On 12/13/18 11:59 AM, Jeff Law wrote:

On 12/5/18 8:55 PM, Martin Sebor wrote:

The __builtin_has_attribute function fails with an ICE when
its first argument is an expression such as INDIRECT_REF, or
many others.  The code simply assumes it's either a type or
a decl.  The attached patch corrects this oversight.

While testing the fix I also noticed the C++ front end expects
the first operand to be a unary expression, which causes most
other kinds of expressions to be rejected.  The patch fixes
that as well.

Finally, while testing the fix even more I realized that
the built-in considers the underlying array itself in ARRAY_REF
expressions rather than its type, which leads to inconsistent
results for overaligned arrays (it's the array itself that's
overaligned, not its elements).  So I fixed that too and
adjusted the one test designed to verify this.

Tested on x86_64-linux.

Martin

gcc-88383.diff

PR c/88383 - ICE calling __builtin_has_attribute on a reference

gcc/c-family/ChangeLog:

PR c/88383
* c-attribs.c (validate_attribute): Handle expressions.
(has_attribute): Handle types referenced by expressions.
Avoid considering array attributes in ARRAY_REF expressions .

gcc/cp/ChangeLog:

PR c/88383
* parser.c (cp_parser_has_attribute_expression): Handle assignment
expressions.

gcc/testsuite/ChangeLog:

PR c/88383
* c-c++-common/builtin-has-attribute-4.c: Adjust expectations.
* c-c++-common/builtin-has-attribute-6.c: New test.
Well, the high level question here is do we want to support this 
builtin

on expressions at all.  Generally attributes apply to types and decls,
not expressions.

Clearly we shouldn't fault, but my first inclination is that the
attribute applies to types or decls, not expressions.  In that case we
should just be issuing an error.

I could be convinced otherwise, so if you think we should support
passing expressions to this builtin, make your case.


The support is necessary in order to determine the attributes
in expressions such as:

   struct S { __attribute__ ((packed)) int a[32]; };

   extern struct S s;

   _Static_assert (__builtin_has_attribute (s.a, packed));


An example involving types might be a better one:

   typedef __attribute__ ((may_alias)) int* BadInt;

   void f (BadInt *p)
   {
 _Static_assert (__builtin_has_attribute (*p, may_alias));
   }

Martin






[PATCH] Add __builtin_convertvector support (PR c++/85052, take 2)

2019-01-03 Thread Jakub Jelinek
On Thu, Jan 03, 2019 at 06:32:44PM +0100, Marc Glisse wrote:
> > That said, not sure if e.g. using an opaque builtin for the conversion that
> > supportable_convert_operation sometimes uses is better over this ifn.
> > What exact optimization opportunities you are looking for if it is lowered
> > earlier?  I have the VECTOR_CST folding in place...
> 
> I don't know, any kind of optimization we currently do on scalars... For
> conversions between integers and floats, that seems to be very limited,
> maybe combine consecutive casts in rare cases. For sign changes, we have a
> number of transformations in match.pd that are fine with an intermediate
> cast that only changes the sign (I even introduced nop_convert to handle
> vectors at the same time). I guess we could handle this IFN as well. It is

For the sign only changes (non-narrowing/widening), the FE is already
emitting a VIEW_CONVERT_EXPR instead of the IFN.

Anyway, here is an updated version of the patch, that:
1) has doc/extend.texi changes
2) adds the missing function comment
3) has the tweak suggested by Richard Sandiford
4) has implemented 2x narrowing and 2x widening vector support, haven't done
the multi cvt cases yet though

Bootstrapped/regtested on x86_64-linux and i686-linux.

2019-01-03  Jakub Jelinek  

PR c++/85052
* tree-vect-generic.c: Include insn-config.h and recog.h.
(expand_vector_piecewise): Add defaulted ret_type argument,
if non-NULL, use that in preference to type for the result type.
(expand_vector_parallel): Formatting fix.
(do_vec_conversion, do_vec_narrowing_conversion,
expand_vector_conversion): New functions.
(expand_vector_operations_1): Call expand_vector_conversion
for VEC_CONVERT ifn calls.
* internal-fn.def (VEC_CONVERT): New internal function.
* internal-fn.c (expand_VEC_CONVERT): New function.
* fold-const-call.c (fold_const_vec_convert): New function.
(fold_const_call): Use it for CFN_VEC_CONVERT.
* doc/extend.texi (__builtin_convertvector): Document.
c-family/
* c-common.h (enum rid): Add RID_BUILTIN_CONVERTVECTOR.
(c_build_vec_convert): Declare.
* c-common.c (c_build_vec_convert): New function.
c/
* c-parser.c (c_parser_postfix_expression): Parse
__builtin_convertvector.
cp/
* cp-tree.h (cp_build_vec_convert): Declare.
* parser.c (cp_parser_postfix_expression): Parse
__builtin_convertvector.
* constexpr.c: Include fold-const-call.h.
(cxx_eval_internal_function): Handle IFN_VEC_CONVERT.
(potential_constant_expression_1): Likewise.
* semantics.c (cp_build_vec_convert): New function.
* pt.c (tsubst_copy_and_build): Handle CALL_EXPR to
IFN_VEC_CONVERT.
testsuite/
* c-c++-common/builtin-convertvector-1.c: New test.
* c-c++-common/torture/builtin-convertvector-1.c: New test.
* g++.dg/ext/builtin-convertvector-1.C: New test.
* g++.dg/cpp0x/constexpr-builtin4.C: New test.

--- gcc/tree-vect-generic.c.jj  2019-01-02 20:48:25.880725772 +0100
+++ gcc/tree-vect-generic.c 2019-01-03 17:45:43.005459518 +0100
@@ -39,6 +39,8 @@ along with GCC; see the file COPYING3.
 #include "tree-cfg.h"
 #include "tree-vector-builder.h"
 #include "vec-perm-indices.h"
+#include "insn-config.h"
+#include "recog.h" /* FIXME: for insn_data */
 
 
 static void expand_vector_operations_1 (gimple_stmt_iterator *);
@@ -267,7 +269,8 @@ do_negate (gimple_stmt_iterator *gsi, tr
 static tree
 expand_vector_piecewise (gimple_stmt_iterator *gsi, elem_op_func f,
 tree type, tree inner_type,
-tree a, tree b, enum tree_code code)
+tree a, tree b, enum tree_code code,
+tree ret_type = NULL_TREE)
 {
   vec *v;
   tree part_width = TYPE_SIZE (inner_type);
@@ -278,23 +281,27 @@ expand_vector_piecewise (gimple_stmt_ite
   int i;
   location_t loc = gimple_location (gsi_stmt (*gsi));
 
-  if (types_compatible_p (gimple_expr_type (gsi_stmt (*gsi)), type))
+  if (ret_type
+  || types_compatible_p (gimple_expr_type (gsi_stmt (*gsi)), type))
 warning_at (loc, OPT_Wvector_operation_performance,
"vector operation will be expanded piecewise");
   else
 warning_at (loc, OPT_Wvector_operation_performance,
"vector operation will be expanded in parallel");
 
+  if (!ret_type)
+ret_type = type;
   vec_alloc (v, (nunits + delta - 1) / delta);
   for (i = 0; i < nunits;
i += delta, index = int_const_binop (PLUS_EXPR, index, part_width))
 {
-  tree result = f (gsi, inner_type, a, b, index, part_width, code, type);
+  tree result = f (gsi, inner_type, a, b, index, part_width, code,
+  ret_type);
   constructor_elt ce = {NULL_TREE, result};
   v->quick_push (ce);
 }
 
-  return build_constructor (type, v);
+  return build_

[PATCH] Tweak dwarf2out const_ok_for_output* (PR debug/88635)

2019-01-03 Thread Jakub Jelinek
Hi!

The following testcase FAILs on 8.x branch, went latent later on on the
trunk and I suppose Alex' i386.c ix86_const_not_ok_for_debug_p change would
have prevented it too.

The problem is in what the comment in const_ok_for_output* says, we don't do
sufficient checking of what kind of expressions we accept inside of CONST
and we could have there something that the assembler doesn't really like.
In particular, in the testcase we ended up with
(const:P (minus:P (const_int -2) (unspec [(symbol_ref ...)] UNSPEC_GOTOFF)))
and as doesn't like -2-.LC0@gotoff.

We already have some hacks in there, like punt on NOT or NEG.  The following
patch extends it, by requiring that the CONST doesn't contain e.g. .LC0 + .LC1
or any kind of labels in the second operand of MINUS (which is like
negation).  In theory, we could allow .LC0 - .LC1 if both labels are in the
same section, but the patch tries to be safe.

After writing the patch, I've noticed Alex made ix86_const_not_ok_for_debug_p
changes, but I think they aren't enough, they will still fail on e.g. all the 
cases
where there are SYMBOL_REFs rather than UNSPECs involved, and on the other
side it disallows 16+.LC0@gotoff which happens quite often.

If const_ok_for_output rejects the whole CONST, there is already code to try
to split it up into smaller expressions, so e.g. that .LC0 - .LC1 would be
emitted then as DW_OP_addr .LC0 DW_OP_addr .LC1 DW_OP_minus, this patch
extends it so that it can handle the UNSPECs that way as well, so the above
would be DW_OP_const1s 0xff DW_OP_addr .LC0@gotoff DW_OP_minus.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk and
without the i386.c part after a while for 8.x?

2019-01-03  Jakub Jelinek  

PR debug/88635
* dwarf2out.c (const_ok_for_output_1): Reject MINUS that contains
SYMBOL_REF, CODE_LABEL or UNSPEC in subexpressions of second argument.
Reject PLUS that contains SYMBOL_REF, CODE_LABEL or UNSPEC in
subexpressions of both operands.
(mem_loc_descriptor): Handle UNSPEC if target hook acks it and all the
subrtxes are CONSTANT_P.
* config/i386/i386.c (ix86_const_not_ok_for_debug_p): Revert
2018-11-09 changes.

* gcc.dg/debug/dwarf2/pr88635.c: New test.

--- gcc/dwarf2out.c.jj  2019-01-03 12:04:45.720730572 +0100
+++ gcc/dwarf2out.c 2019-01-03 14:35:02.897782400 +0100
@@ -14464,6 +14464,41 @@ const_ok_for_output_1 (rtx rtl)
 case NOT:
 case NEG:
   return false;
+case PLUS:
+  {
+   /* Make sure SYMBOL_REFs/UNSPECs are at most in one of the
+  operands.  */
+   subrtx_var_iterator::array_type array;
+   bool first = false;
+   FOR_EACH_SUBRTX_VAR (iter, array, XEXP (rtl, 0), ALL)
+ if (SYMBOL_REF_P (*iter)
+ || LABEL_P (*iter)
+ || GET_CODE (*iter) == UNSPEC)
+   {
+ first = true;
+ break;
+   }
+   if (!first)
+ return true;
+   FOR_EACH_SUBRTX_VAR (iter, array, XEXP (rtl, 1), ALL)
+ if (SYMBOL_REF_P (*iter)
+ || LABEL_P (*iter)
+ || GET_CODE (*iter) == UNSPEC)
+   return false;
+   return true;
+  }
+case MINUS:
+  {
+   /* Disallow negation of SYMBOL_REFs or UNSPECs when they
+  appear in the second operand of MINUS.  */
+   subrtx_var_iterator::array_type array;
+   FOR_EACH_SUBRTX_VAR (iter, array, XEXP (rtl, 1), ALL)
+ if (SYMBOL_REF_P (*iter)
+ || LABEL_P (*iter)
+ || GET_CODE (*iter) == UNSPEC)
+   return false;
+   return true;
+  }
 default:
   return true;
 }
@@ -15607,6 +15642,7 @@ mem_loc_descriptor (rtx rtl, machine_mod
 pool.  */
 case CONST:
 case SYMBOL_REF:
+case UNSPEC:
   if (!is_a  (mode, &int_mode)
  || (GET_MODE_SIZE (int_mode) > DWARF2_ADDR_SIZE
 #ifdef POINTERS_EXTEND_UNSIGNED
@@ -15614,6 +15650,30 @@ mem_loc_descriptor (rtx rtl, machine_mod
 #endif
  ))
break;
+
+  if (GET_CODE (rtl) == UNSPEC)
+   {
+ /* If delegitimize_address couldn't do anything with the UNSPEC, we
+can't express it in the debug info.  This can happen e.g. with some
+TLS UNSPECs.  Allow UNSPECs formerly from CONST that the backend
+approves.  */
+ bool not_ok = false;
+ subrtx_var_iterator::array_type array;
+ FOR_EACH_SUBRTX_VAR (iter, array, rtl, ALL)
+   if ((*iter != rtl && !CONSTANT_P (*iter))
+   || !const_ok_for_output_1 (*iter))
+ {
+   not_ok = true;
+   break;
+ }
+
+ if (not_ok)
+   break;
+
+ rtl = gen_rtx_CONST (GET_MODE (rtl), rtl);
+ goto symref;
+   }
+
   if (GET_CODE (rtl) == SYMBOL_REF
  && SYMBOL_REF_TLS_MODEL (rtl) != TLS_MODEL_NONE)
{
@@ -16282,7 +16342,6 @@ mem_loc_descriptor (rtx rtl, machine_m

Re: [PATCH] PR libstdc++/88607 replace or remove unnecessary UTF-8 characters

2019-01-03 Thread Jonathan Wakely

On 03/01/19 22:07 +, Jonathan Wakely wrote:

On 03/01/19 20:38 +, Jonathan Wakely wrote:

There are a number of UTF-8 characters in comments which add no value
and can be replaced with ASCII equivalents, or removed entirely for the
section sign (U+00A7).

PR libstdc++/88607
* include/bits/forward_list.h: Replace UTF-8 "ligature fi" character.
* include/debug/forward_list: Likewise.
* include/experimental/bits/shared_ptr.h: Remove UTF-8 "section sign"
character.
* include/experimental/chrono: Likewise.
* include/experimental/functional: Likewise.
* include/experimental/ratio: Likewise.
* include/experimental/system_error: Likewise.
* include/experimental/tuple: Likewise.
* include/experimental/type_traits: Likewise.
* include/parallel/workstealing.h: Replace UTF-8 "en dash" character.
* include/parallel/multiseq_selection.h: Likewise.


This replaces some more non-ASCII characters.

Tested powerpc64-linux, committed to trunk.


The tests added by this patch would probably be a good idea, but I'm
not sure if -finput-charset=ascii works for all targets.


commit 53a31b41d06059fdaf1f09fd66f5d9e219246759
Author: Jonathan Wakely 
Date:   Thu Jan 3 22:18:14 2019 +

PR libstdc++/88607 add tests using -finput-charset=ascii

This verifies that the  header can be compiled with ASCII
as the input character set.

PR libstdc++/88607
* testsuite/17_intro/headers/c++1998/charset.cc: New test.
* testsuite/17_intro/headers/c++2011/charset.cc: New test.
* testsuite/17_intro/headers/c++2014/charset.cc: New test.
* testsuite/17_intro/headers/c++2017/charset.cc: New test.
* testsuite/17_intro/headers/c++2020/charset.cc: New test.

diff --git a/libstdc++-v3/testsuite/17_intro/headers/c++1998/charset.cc b/libstdc++-v3/testsuite/17_intro/headers/c++1998/charset.cc
new file mode 100644
index 000..864c64ef831
--- /dev/null
+++ b/libstdc++-v3/testsuite/17_intro/headers/c++1998/charset.cc
@@ -0,0 +1,4 @@
+// { dg-options "-finput-charset=ascii" }
+// { dg-do compile }
+
+#include 
diff --git a/libstdc++-v3/testsuite/17_intro/headers/c++2011/charset.cc b/libstdc++-v3/testsuite/17_intro/headers/c++2011/charset.cc
new file mode 100644
index 000..864c64ef831
--- /dev/null
+++ b/libstdc++-v3/testsuite/17_intro/headers/c++2011/charset.cc
@@ -0,0 +1,4 @@
+// { dg-options "-finput-charset=ascii" }
+// { dg-do compile }
+
+#include 
diff --git a/libstdc++-v3/testsuite/17_intro/headers/c++2014/charset.cc b/libstdc++-v3/testsuite/17_intro/headers/c++2014/charset.cc
new file mode 100644
index 000..864c64ef831
--- /dev/null
+++ b/libstdc++-v3/testsuite/17_intro/headers/c++2014/charset.cc
@@ -0,0 +1,4 @@
+// { dg-options "-finput-charset=ascii" }
+// { dg-do compile }
+
+#include 
diff --git a/libstdc++-v3/testsuite/17_intro/headers/c++2017/charset.cc b/libstdc++-v3/testsuite/17_intro/headers/c++2017/charset.cc
new file mode 100644
index 000..864c64ef831
--- /dev/null
+++ b/libstdc++-v3/testsuite/17_intro/headers/c++2017/charset.cc
@@ -0,0 +1,4 @@
+// { dg-options "-finput-charset=ascii" }
+// { dg-do compile }
+
+#include 
diff --git a/libstdc++-v3/testsuite/17_intro/headers/c++2020/charset.cc b/libstdc++-v3/testsuite/17_intro/headers/c++2020/charset.cc
new file mode 100644
index 000..864c64ef831
--- /dev/null
+++ b/libstdc++-v3/testsuite/17_intro/headers/c++2020/charset.cc
@@ -0,0 +1,4 @@
+// { dg-options "-finput-charset=ascii" }
+// { dg-do compile }
+
+#include 


[PATCH] Fix -fsanitize=address with > 32 byte aligned vars (PR sanitizer/88619)

2019-01-03 Thread Jakub Jelinek
Hi!

The prev_offset we push into the vector is supposed to be the end of
the red zone for the variable, it needs to be ASAN_MIN_RED_ZONE_SIZE
aligned, but by aligning it more we can end up with red zone with negative
size.  E.g. on the testcase, we have initial frame_offset -8 (because of
-fstack-protector guard), we align it to -32 first (required that the
start and end of the var block is 32 byte aligned (4 byte aligned in shadow
memory)).  The first variable needs 64 byte alignment, but is just 4 bytes,
so the next after
  offset = alloc_stack_frame_space (size, alignment);
we end up with frame_offset (== offset) -64 and the start of red zone is
after that 4 byte variable, i.e. at -60.  But the align_base tweak from
-32 with 64 byte alignment gives -64.

Now, the stack vars are sorted first by large vs. small alignment (not
relevant to x86), then by size and only afterwards by alignment, so similar
problems could appear if we have some large variable followed by > 32 byte
aligned very small variable.

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

2019-01-03  Jakub Jelinek  

PR sanitizer/88619
* cfgexpand.c (expand_stack_vars): Only align prev_offset to
ASAN_MIN_RED_ZONE_SIZE, not to maximum of that and alignb.

* c-c++-common/asan/pr88619.c: New test.

--- gcc/cfgexpand.c.jj  2019-01-01 12:37:17.328972145 +0100
+++ gcc/cfgexpand.c 2019-01-03 14:11:16.209366858 +0100
@@ -1130,7 +1130,7 @@ expand_stack_vars (bool (*pred) (size_t)
  prev_offset = frame_offset.to_constant ();
}
  prev_offset = align_base (prev_offset,
-   MAX (alignb, ASAN_MIN_RED_ZONE_SIZE),
+   ASAN_MIN_RED_ZONE_SIZE,
!FRAME_GROWS_DOWNWARD);
  tree repr_decl = NULL_TREE;
  unsigned HOST_WIDE_INT size
--- gcc/testsuite/c-c++-common/asan/pr88619.c.jj2019-01-03 
14:16:00.779659964 +0100
+++ gcc/testsuite/c-c++-common/asan/pr88619.c   2019-01-03 14:15:40.568994254 
+0100
@@ -0,0 +1,14 @@
+/* PR sanitizer/88619 */
+/* { dg-do compile { target fstack_protector } } */
+/* { dg-options "-fstack-protector-strong -fsanitize=address" } */
+
+typedef int A __attribute__((aligned (64)));
+
+int
+main ()
+{
+  A b;
+  int *p = &b;
+  *(p - 1) = 123;
+  __builtin_alloca (b);
+}

Jakub


[PATCH] Fix expansion ICE with call returning VL structure (PR middle-end/82564, PR target/88620)

2019-01-03 Thread Jakub Jelinek
Hi!

The following testcases ICE on x86_64 and other targets.

The problem is that a function with nested functions returning VLA
structures is inlined (or versioned) so that the variable sizes become
constant, but we still have a MEM_REF[(struct S *) &D.1234] = fn ();
where the D.1234 variable has fixed non-BLKmode size, but struct S is
still a VLA type.  Furthermore, D.1234 isn't marked as addressable,
because it is only accessed through such MEM_REFs.  Because of that
mem_ref_refers_to_non_mem_p is true and we take a different
expand_assignment path from normal VLA return expansion and try to create
the VLA structure temporary, which ICEs obviously.

The following patch fixes that by using a MEM temporary for this rare case.

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

2019-01-03  Jakub Jelinek  

PR middle-end/82564
PR target/88620
* expr.c (expand_assignment): For calls returning VLA structures
if to_rtx is not a MEM, force it into a stack temporary.

* gcc.dg/nested-func-12.c: New test.
* gcc.c-torture/compile/pr82564.c: New test.

--- gcc/expr.c.jj   2019-01-01 12:37:16.751981612 +0100
+++ gcc/expr.c  2019-01-03 19:17:25.882346422 +0100
@@ -5254,6 +5254,21 @@ expand_assignment (tree to, tree from, b
  emit_move_insn (XEXP (to_rtx, 1), read_complex_part (temp, true));
}
}
+  /* For calls to functions returning variable length structures, if TO_RTX
+is not a MEM, go through a MEM because we must not create temporaries
+of the VLA type.  */
+  else if (!MEM_P (to_rtx)
+  && TREE_CODE (from) == CALL_EXPR
+  && COMPLETE_TYPE_P (TREE_TYPE (from))
+  && TREE_CODE (TYPE_SIZE (TREE_TYPE (from))) != INTEGER_CST)
+   {
+ rtx temp = assign_stack_temp (GET_MODE (to_rtx),
+   GET_MODE_SIZE (GET_MODE (to_rtx)));
+ result = store_field (temp, bitsize, bitpos, bitregion_start,
+   bitregion_end, mode1, from, get_alias_set (to),
+   nontemporal, reversep);
+ emit_move_insn (to_rtx, temp);
+   }
   else
{
  if (MEM_P (to_rtx))
--- gcc/testsuite/gcc.dg/nested-func-12.c.jj2019-01-03 19:25:46.466084209 
+0100
+++ gcc/testsuite/gcc.dg/nested-func-12.c   2019-01-03 19:25:38.181220942 
+0100
@@ -0,0 +1,48 @@
+/* PR target/88620 */
+/* { dg-do run } */
+/* { dg-options "-Ofast --param ipa-cp-eval-threshold=0 
-fno-guess-branch-probability -fno-inline-small-functions" } */
+/* { dg-require-effective-target alloca } */
+
+void
+foo (int n)
+{
+  struct S { int a[n]; };
+
+  struct S
+  fn (void)
+  {
+struct S s;
+s.a[0] = 42;
+return s;
+  }
+
+  auto struct S
+  fn2 (void)
+  {
+return fn ();
+  }
+
+  struct S x;
+  fn ();
+  fn2 ();
+  x = fn ();
+
+  if (x.a[0] != 42)
+__builtin_abort ();
+
+  if (fn ().a[0] != 42)
+__builtin_abort ();
+
+  __typeof__ (fn ()) *p = &x;
+  if (p->a[0] != 42)
+__builtin_abort ();
+
+  if (fn2 ().a[0] != 42)
+__builtin_abort ();
+}
+
+int
+main (void)
+{
+  foo (1);
+}
--- gcc/testsuite/gcc.c-torture/compile/pr82564.c.jj2019-01-03 
19:22:36.763215290 +0100
+++ gcc/testsuite/gcc.c-torture/compile/pr82564.c   2019-01-03 
19:24:44.607105204 +0100
@@ -0,0 +1,15 @@
+/* PR middle-end/82564 */
+/* { dg-require-effective-target alloca } */
+
+int
+main ()
+{
+  int t = 8, i;
+  typedef struct { char v[t]; } B; 
+  B a, b;
+  B __attribute__ ((noinline)) f () { return b; }
+  for (i = 0; i < 8; i++)
+b.v[i] = i;
+  a = f ();
+  return 0;
+}

Jakub


[PATCH] Fix ICE in x86 DIVMOD libfunc expansion (PR target/88594)

2019-01-03 Thread Jakub Jelinek
Hi!

The following testcase ICEs, because during DIVMOD discovery a is still not
known to be a constant (otherwise we wouldn't create a DIVMOD), but later on
before expansion it is replaced with 17 and ix86_expand_divmod_libfunc
calls emit_library_call_value with GET_MODE (op1) as the mode for the
argument, which is thus VOIDmode, while we want to say that even when the
argument is VOIDmode, the argument is TImode.

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

2019-01-03  Jakub Jelinek  

PR target/88594
* config/i386/i386.c (ix86_expand_divmod_libfunc): Use mode instead
of GET_MODE (opN) as modes of the libcall arguments.

* gcc.dg/pr88594.c: New test.

--- gcc/config/i386/i386.c.jj   2019-01-03 14:32:43.050093691 +0100
+++ gcc/config/i386/i386.c  2019-01-03 20:15:11.351392235 +0100
@@ -51002,9 +51002,7 @@ ix86_expand_divmod_libfunc (rtx libfunc,
   rtx rem = assign_386_stack_local (mode, SLOT_TEMP);
 
   rtx quot = emit_library_call_value (libfunc, NULL_RTX, LCT_NORMAL,
- mode,
- op0, GET_MODE (op0),
- op1, GET_MODE (op1),
+ mode, op0, mode, op1, mode,
  XEXP (rem, 0), Pmode);
   *quot_p = quot;
   *rem_p = rem;
--- gcc/testsuite/gcc.dg/pr88594.c.jj   2019-01-03 20:29:58.177819386 +0100
+++ gcc/testsuite/gcc.dg/pr88594.c  2019-01-03 20:29:34.209213935 +0100
@@ -0,0 +1,16 @@
+/* PR target/88594 */
+/* { dg-do compile { target int128 } } */
+/* { dg-options "-O2 -fno-tree-dominator-opts -fno-tree-forwprop 
-fno-tree-vrp" } */
+
+__int128
+foo (__int128 x, __int128 *y)
+{
+  int a;
+  __int128 z, r;
+  for (a = 0; a < 17; ++a)
+;
+  z = x / a;
+  r = x % a;
+  *y = z;
+  return r;
+}

Jakub


[PATCH] Disable gdb pagination temporarily in gdbinit.in

2019-01-03 Thread Jakub Jelinek
Hi!

After upgrading gdb recently gdb ./cc1 etc. asks me to
--Type  for more, q to quit, c to continue without paging--
on start, because the stuff it prints by default + all the
File tree.h will be skipped when stepping.
File is-a.h will be skipped when stepping.
File line-map.h will be skipped when stepping.
File timevar.h will be skipped when stepping.
Function rtx_expr_list::next will be skipped when stepping.
Function rtx_expr_list::element will be skipped when stepping.
Function rtx_insn_list::next will be skipped when stepping.
Function rtx_insn_list::insn will be skipped when stepping.
Function rtx_sequence::len will be skipped when stepping.
Function rtx_sequence::element will be skipped when stepping.
Function rtx_sequence::insn will be skipped when stepping.
Function INSN_UID will be skipped when stepping.
Function PREV_INSN will be skipped when stepping.
Function SET_PREV_INSN will be skipped when stepping.
Function NEXT_INSN will be skipped when stepping.
Function SET_NEXT_INSN will be skipped when stepping.
Function BLOCK_FOR_INSN will be skipped when stepping.
Function PATTERN will be skipped when stepping.
Function INSN_LOCATION will be skipped when stepping.
Function INSN_HAS_LOCATION will be skipped when stepping.
Function JUMP_LABEL_AS_INSN will be skipped when stepping.

lines don't fit into my 41 line terminal anymore.  The following patch
temporarily switches pagination off when printing all those skipped when
stepping messages and restores it back afterwards.

It uses python, but it seems we already unconditionally add to .gdbinit
python import sys; sys.path.append('../../gcc'); import gdbhooks
so I'd hope we don't regress with this anywhere.

Even better would be to tell gdb not to print the skip messages, but it
doesn't have such a support right now.

Tested on x86_64-linux, ok for trunk?

2019-01-03  Jakub Jelinek  

* gdbinit.in: Turn off pagination for the skip commands, restore
it to previous state afterwards.

--- gcc/gdbinit.in.jj   2019-01-01 12:37:17.890962924 +0100
+++ gcc/gdbinit.in  2019-01-03 21:41:44.649355028 +0100
@@ -219,6 +219,11 @@ macro define __null 0
 macro define input_line expand_location(input_location).line
 macro define input_filename expand_location(input_location).file
 
+# Remember previous pagination status and turn it off, so that
+# the messages for skip commands don't require pagination.
+python __gcc_prev_pagination=gdb.parameter("pagination")
+set pagination off
+
 # Gracefully handle aborts in functions used from gdb.
 set unwindonsignal on
 
@@ -276,3 +281,6 @@ skip PATTERN
 skip INSN_LOCATION
 skip INSN_HAS_LOCATION
 skip JUMP_LABEL_AS_INSN
+
+# Restore pagination to the previous state.
+python if __gcc_prev_pagination: gdb.execute("set pagination on")

Jakub


Re: [PATCH 4/4][libbacktrace] Add tests for unused formats

2019-01-03 Thread Ian Lance Taylor via gcc-patches
On Thu, Jan 3, 2019 at 3:49 AM Iain Sandoe  wrote:
>
> > On 2 Jan 2019, at 13:26, Iain Sandoe  wrote:
> >
> >
> >> On 2 Jan 2019, at 13:20, Rainer Orth  wrote:
> >>
> >> Gerald Pfeifer  writes:
> >>
> >>>
> 
> >>>
> >>> I believe that in addition to FreeBSD this probably also fails on
> >>> Solaris and Darwin.
> >>
> >> I cannot test Darwin right now,
> >
> > I have builds running on a number of versions, will take a look
> > - is it missing a “macho_xx.c” implementation, anyway ?
>
> (on darwin17 / macOS 10.13)
>
> make check-target-libbacktrace
>
> fails for me at trunk r267505 with:
>
> /src-local/gcc-trunk/libbacktrace/elf.c:144:2: error: #error "Unknown 
> BACKTRACE_ELF_SIZE"
>   144 | #error "Unknown BACKTRACE_ELF_SIZE"
>   |  ^
>
> So, it looks like there’s some configury-fixing/implementation work needed 
> for Darwin.

Someone needs to write a macho.c that roughly corresponds to the
existing elf.c, pecoff.c, and xcoff.c.

Ian


Re: [PATCH] genattrtab bit-rot, and if_then_else in values

2019-01-03 Thread Alan Modra
On Thu, Jan 03, 2019 at 07:03:59PM +, Richard Sandiford wrote:
> Richard Sandiford  writes:
> > This still seems risky and isn't what the name and function comment

OK, how about this delta from the previous patch to ameliorate the
maintenance risk?

diff --git a/gcc/genattrtab.c b/gcc/genattrtab.c
index c86b3587cd9..2a81445a160 100644
--- a/gcc/genattrtab.c
+++ b/gcc/genattrtab.c
@@ -3750,8 +3750,9 @@ write_test_expr (FILE *outf, rtx exp, unsigned int 
attrs_cached, int flags,
   return attrs_cached;
 }
 
-/* Given an attribute value, return the maximum CONST_INT or CONST_STRING
-   argument encountered.  Return INT_MAX if the value is unknown.  */
+/* Given an attribute value expression, return the maximum value that
+   might be evaluated assuming all conditionals are independent.
+   Return INT_MAX if the value can't be calculated by this function.  */
 
 static int
 max_attr_value (rtx exp)
@@ -3805,8 +3806,9 @@ max_attr_value (rtx exp)
   return current_max;
 }
 
-/* Given an attribute value, return the minimum CONST_INT or CONST_STRING
-   argument encountered.  Return INT_MIN if the value is unknown.  */
+/* Given an attribute value expression, return the minimum value that
+   might be evaluated assuming all conditionals are independent.
+   Return INT_MIN if the value can't be calculated by this function.  */
 
 static int
 min_attr_value (rtx exp)
@@ -3860,9 +3862,18 @@ min_attr_value (rtx exp)
   return current_min;
 }
 
-/* Given an attribute value, return the result of ORing together all
-   CONST_INT or CONST_STRING arguments encountered.  Return -1 if the
-   numeric value is not known.  */
+/* Given an attribute value expression, return the result of ORing
+   together all CONST_INT or CONST_STRING arguments encountered in the
+   value parts of the expression.  (ie. excluding those that might be
+   found in condition expressions of COND or IF_THEN_ELSE.)  Note that
+   this isn't the same as the OR of all possible evaluations of the
+   expression, but is sufficient for the current use of this function
+   in calculating the largest power of two that divides insn lengths.
+   ie.  We are calculating a property of the underlying machine
+   instructions emitted by gcc.  In particular this implementation
+   assumes conditionals are independent and that the operands of a
+   PLUS are multiples of the underlying machine instruction length.
+   Returns -1 if the value can't be calculated by this function.  */
 
 static int
 or_attr_value (rtx exp)
@@ -3882,13 +3893,7 @@ or_attr_value (rtx exp)
 
 case PLUS:
   current_or = or_attr_value (XEXP (exp, 0));
-  if (current_or != -1)
-   {
- int n = current_or;
- current_or = or_attr_value (XEXP (exp, 1));
- if (current_or != -1)
-   current_or += n;
-   }
+  current_or |= or_attr_value (XEXP (exp, 1));
   break;
 
 case COND:


[committed] avoid null dereference in maybe_warn_nonstring_arg (PR 88659)

2019-01-03 Thread Martin Sebor

The attached patch avoids dereferencing a null pointer in
maybe_warn_nonstring_arg reported to cause an ICE in pr88659.
Committed in r267569 after bootstrapping and regtesting on
x86_64-linux.

Martin
gcc/ChangeLog:

	PR tree-optimization/88659
* calls.c (maybe_warn_nonstring_arg): Avoid assuming maxlen is set.

gcc/testsuite/ChangeLog:

	PR tree-optimization/88659
* gcc.dg/Wstringop-truncation-6.c: New test.

Index: gcc/calls.c
===
--- gcc/calls.c	(revision 267568)
+++ gcc/calls.c	(working copy)
@@ -1681,7 +1681,7 @@ maybe_warn_nonstring_arg (tree fndecl, tree exp)
 	  bndrng[1] = maxlen;
 	  bound = void_type_node;
 	}
-  else
+  else if (maxlen)
 	{
 	  /* Replace the bound on the operation with the upper bound
 	 of the length of the string if the latter is smaller.  */
Index: gcc/testsuite/gcc.dg/Wstringop-truncation-6.c
===
--- gcc/testsuite/gcc.dg/Wstringop-truncation-6.c	(nonexistent)
+++ gcc/testsuite/gcc.dg/Wstringop-truncation-6.c	(working copy)
@@ -0,0 +1,42 @@
+/* PR tree-optimization/88659 - ICE in maybe_warn_nonstring_arg
+   { dg-do compile }
+   { dg-options "-O0 -Wall" }  */
+
+const char a[5] = "1234";
+
+int cst_idx_cst_bnd (void)
+{
+  return __builtin_strnlen (&a[1], 0);
+}
+
+int var_idx_cst_bnd (void)
+{
+  int i = 1;
+  return __builtin_strnlen (&a[i], 0);
+}
+
+int phi_idx_cst_bnd (int i)
+{
+  return __builtin_strnlen (&a[i ? 1 : 2], 0);
+}
+
+int unk_idx_cst_bnd (int i)
+{
+  return __builtin_strnlen (&a[i], 0);
+}
+
+int cst_idx_var_bnd (void)
+{
+  int n = 0;
+  return __builtin_strnlen (&a[1], n);
+}
+
+int cst_idx_phi_bnd (int n)
+{
+  return __builtin_strnlen (&a[1], n ? 1 : 2);
+}
+
+int cst_idx_unk_bnd (int n)
+{
+  return __builtin_strnlen (&a[1], n);
+}


[doc patch] fix minor typos in -Wmemset-transposed-args

2019-01-03 Thread Martin Sebor

The attached patch corrects a couple of minor typos in the description
of -Wmemset-transposed-args.  It also tweaks the text a bit for better
readability.

Martin
gcc/ChangeLog:

	* invoke.texi (-Wmemset-transposed-args): Fix typos, adjust wording.

Index: gcc/doc/invoke.texi
===
--- gcc/doc/invoke.texi	(revision 267568)
+++ gcc/doc/invoke.texi	(working copy)
@@ -6958,14 +6958,15 @@ the element size.  This warning is enabled by @opt
 @item -Wmemset-transposed-args
 @opindex Wmemset-transposed-args
 @opindex Wno-memset-transposed-args
-Warn for suspicious calls to the @code{memset} built-in function, if the
-second argument is not zero and the third argument is zero.  This warns e.g.@:
-about @code{memset (buf, sizeof buf, 0)} where most probably
-@code{memset (buf, 0, sizeof buf)} was meant instead.  The diagnostics
-is only emitted if the third argument is literal zero.  If it is some
-expression that is folded to zero, a cast of zero to some type, etc., 
-it is far less likely that the user has mistakenly exchanged the arguments 
-and no warning is emitted.  This warning is enabled by @option{-Wall}.
+Warn for suspicious calls to the @code{memset} built-in function where
+the second argument is not zero and the third argument is zero.  For
+example, the call @code{memset (buf, sizeof buf, 0)} is diagnosed because
+@code{memset (buf, 0, sizeof buf)} was meant instead.  The diagnostic
+is only emitted if the third argument is a literal zero.  Otherwise, if
+it is an expression that is folded to zero, or a cast of zero to some
+type, it is far less likely that the arguments have been mistakenly
+transposed and no warning is emitted.  This warning is enabled
+by @option{-Wall}.
 
 @item -Waddress
 @opindex Waddress


Re: [PATCH] Fix ICE in x86 DIVMOD libfunc expansion (PR target/88594)

2019-01-03 Thread Uros Bizjak
On Fri, Jan 4, 2019 at 12:00 AM Jakub Jelinek  wrote:
>
> Hi!
>
> The following testcase ICEs, because during DIVMOD discovery a is still not
> known to be a constant (otherwise we wouldn't create a DIVMOD), but later on
> before expansion it is replaced with 17 and ix86_expand_divmod_libfunc
> calls emit_library_call_value with GET_MODE (op1) as the mode for the
> argument, which is thus VOIDmode, while we want to say that even when the
> argument is VOIDmode, the argument is TImode.
>
> Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for
> trunk?
>
> 2019-01-03  Jakub Jelinek  
>
> PR target/88594
> * config/i386/i386.c (ix86_expand_divmod_libfunc): Use mode instead
> of GET_MODE (opN) as modes of the libcall arguments.
>
> * gcc.dg/pr88594.c: New test.

OK for trunk and release branches.

Thanks,
Uros.

> --- gcc/config/i386/i386.c.jj   2019-01-03 14:32:43.050093691 +0100
> +++ gcc/config/i386/i386.c  2019-01-03 20:15:11.351392235 +0100
> @@ -51002,9 +51002,7 @@ ix86_expand_divmod_libfunc (rtx libfunc,
>rtx rem = assign_386_stack_local (mode, SLOT_TEMP);
>
>rtx quot = emit_library_call_value (libfunc, NULL_RTX, LCT_NORMAL,
> - mode,
> - op0, GET_MODE (op0),
> - op1, GET_MODE (op1),
> + mode, op0, mode, op1, mode,
>   XEXP (rem, 0), Pmode);
>*quot_p = quot;
>*rem_p = rem;
> --- gcc/testsuite/gcc.dg/pr88594.c.jj   2019-01-03 20:29:58.177819386 +0100
> +++ gcc/testsuite/gcc.dg/pr88594.c  2019-01-03 20:29:34.209213935 +0100
> @@ -0,0 +1,16 @@
> +/* PR target/88594 */
> +/* { dg-do compile { target int128 } } */
> +/* { dg-options "-O2 -fno-tree-dominator-opts -fno-tree-forwprop 
> -fno-tree-vrp" } */
> +
> +__int128
> +foo (__int128 x, __int128 *y)
> +{
> +  int a;
> +  __int128 z, r;
> +  for (a = 0; a < 17; ++a)
> +;
> +  z = x / a;
> +  r = x % a;
> +  *y = z;
> +  return r;
> +}
>
> Jakub