Re: [PATCH] improve performance of std::allocator::deallocate

2019-03-06 Thread Jonathan Wakely

On 06/03/19 02:43 +, Pádraig Brady wrote:



On 02/26/2019 04:23 PM, Padraig Brady wrote:



Note jemalloc >= 5.1 is required to fix a bug with 0 sizes.

How serious is the bug? What are the symptoms?


I've updated the commit summary to say it's a crash.
Arguably that's better than mem corruption.


It looks like 5.1.0 is less than a year old, so older versions are
presumably still in wide use.

We could potentially workaround it by making
new_allocator::allocate(0) call ::operator new(1) when
__cpp_sized_deallocation is defined, and deallocate(p, 0) call
::operator delete(p, 1). Obviously I'd prefer not to do that, because
the default operator new already has an equivalent check, and only
programs linking to jemalloc require the workaround.


Right the jemalloc fix was released May 2018.
It would be great to avoid the extra workarounds.
Given this would be released about a year after the jemalloc fix was
released,
and that this would only manifest upon program rebuild,
I would be inclined to not add any workarounds.
For reference tcmalloc and glibc malloc were seen to work fine with this.


Actually the jemalloc issue will only be fixed with the release of 5.2
(a few weeks away).
I've updated the commit message in the attached accordingly.


Hmm, I'm a bit nervous about making a change that will cause crashes
unless using an unreleased version (I know it will be released by the
time GCC 9.1 is released, but some people might upgrade GCC without
upgrading jemalloc).

On the other hand, zero sized allocations should be rare in practice.



Re: [PATCH] backport r268834 from mainline to gcc-7-branch

2019-03-06 Thread Segher Boessenkool
On Wed, Mar 06, 2019 at 01:49:54AM -0600, luo...@linux.vnet.ibm.com wrote:
> From: Xiong Hu Luo 
> 
> Backport r268834 of "Add support for the vec_sbox_be, vec_cipher_be etc."
> from mainline to gcc-8-branch.
> 
> Regression-tested on Linux POWER8 LE.  Backport patch for gcc-8-branch
> already got approved and commited.  OK for gcc-7-branch?

Okay.  Thanks!


Segher


> gcc/ChangeLog:
> 2019-03-05  Xiong Hu Luo  
> 
>   Backport of r268834 from mainline to gcc-7-branch.
>   2019-02-13  Xiong Hu Luo  
> 
>   * config/rs6000/altivec.h (vec_sbox_be, vec_cipher_be,
>   vec_cipherlast_be, vec_ncipher_be, vec_ncipherlast_be): New #defines.
>   * config/rs6000/crypto.md (CR_vqdi): New define_mode_iterator.
>   (crypto_vsbox_, crypto__): New define_insns.
>   * config/rs6000/rs6000-builtin.def (VSBOX_BE): New BU_CRYPTO_1.
>   (VCIPHER_BE, VCIPHERLAST_BE, VNCIPHER_BE, VNCIPHERLAST_BE):
>   New BU_CRYPTO_2.
>   * config/rs6000/rs6000.c (builtin_function_type)
>  CRYPTO_BUILTIN_VCIPHERLAST_BE, CRYPTO_BUILTIN_VNCIPHER_BE,
>   CRYPTO_BUILTIN_VNCIPHERLAST_BE>: New switch options.
>   * doc/extend.texi (vec_sbox_be, vec_cipher_be, vec_cipherlast_be,
>   vec_ncipher_be, vec_ncipherlast_be): New builtin functions.
> 
> gcc/testsuite/ChangeLog:
> 2019-03-05  Xiong Hu Luo  
> 
>   Backport of r268834 from mainline to gcc-7-branch.
>   2019-01-23  Xiong Hu Luo  
> 
>   * gcc.target/powerpc/crypto-builtin-1.c
>   (crypto1_be, crypto2_be, crypto3_be, crypto4_be, crypto5_be):
>   New testcases.


Re: [PATCH] Mention logical-op-non-short-circuit param in gcc/doc/invoke.texi.

2019-03-06 Thread Martin Liška
On 3/5/19 5:01 PM, Jakub Jelinek wrote:
> On Tue, Mar 05, 2019 at 04:53:54PM +0100, Martin Liška wrote:
>> Hi.
>>
>> The param was added by Jakub. Should I mention it in invoke.texi?
> 
> It is meant solely for the testsuite, so I wouldn't document it.
> But if others disagree, I'm not strongly opposed to that, but we then should
> say so in the documentation.

Ah, I see. Then let me suggest patch that will ignore the option
in contrib/check-params-in-docs.py script?

Martin

> 
>> 2019-03-05  Martin Liska  
>>
>>  * doc/invoke.texi: Mention logical-op-non-short-circuit
>>  param.
>> ---
>>  gcc/doc/invoke.texi | 3 +++
>>  1 file changed, 3 insertions(+)
>>
>>
> 
>> diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
>> index df0883f2fc9..d9be34da077 100644
>> --- a/gcc/doc/invoke.texi
>> +++ b/gcc/doc/invoke.texi
>> @@ -12044,6 +12044,9 @@ considered for SLP vectorization.
>>  @item avoid-fma-max-bits
>>  Maximum number of bits for which we avoid creating FMAs.
>>  
>> +@item logical-op-non-short-circuit
>> +True if a non-short-circuit operation is optimal.
>> +
>>  @item sms-loop-average-count-threshold
>>  A threshold on the average loop count considered by the swing modulo 
>> scheduler.
>>  
>>
> 
> 
>   Jakub
> 

>From 97ab8910d4a6c546cedece49880fce1a85ace1df Mon Sep 17 00:00:00 2001
From: marxin 
Date: Wed, 6 Mar 2019 10:16:54 +0100
Subject: [PATCH] Ignore a param in check-params-in-docs.py

contrib/ChangeLog:

2019-03-06  Martin Liska  

	* check-params-in-docs.py: Ignore a param.
---
 contrib/check-params-in-docs.py | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/contrib/check-params-in-docs.py b/contrib/check-params-in-docs.py
index eb36f4b8654..6cff090dc4c 100755
--- a/contrib/check-params-in-docs.py
+++ b/contrib/check-params-in-docs.py
@@ -39,6 +39,7 @@ parser.add_argument('params_output')
 
 args = parser.parse_args()
 
+ignored = set(['logical-op-non-short-circuit'])
 params = {}
 
 for line in open(args.params_output).readlines():
@@ -56,8 +57,8 @@ token = '@item '
 texi = [x[len(token):] for x in texi if x.startswith(token)]
 sorted_texi = sorted(texi)
 
-texi_set = set(texi)
-params_set = set(params.keys())
+texi_set = set(texi) - ignored
+params_set = set(params.keys()) - ignored
 
 extra = texi_set - params_set
 if len(extra):
-- 
2.21.0



Re: [PATCH] improve performance of std::allocator::deallocate

2019-03-06 Thread Pádraig Brady
On 03/06/2019 12:50 AM, Jonathan Wakely wrote:
> On 06/03/19 02:43 +, Pádraig Brady wrote:
>>
>>
>> On 02/26/2019 04:23 PM, Padraig Brady wrote:
>>>
 Note jemalloc >= 5.1 is required to fix a bug with 0 sizes.

 How serious is the bug? What are the symptoms?

>>> I've updated the commit summary to say it's a crash.
>>> Arguably that's better than mem corruption.
>>>
 It looks like 5.1.0 is less than a year old, so older versions are
 presumably still in wide use.

 We could potentially workaround it by making
 new_allocator::allocate(0) call ::operator new(1) when
 __cpp_sized_deallocation is defined, and deallocate(p, 0) call
 ::operator delete(p, 1). Obviously I'd prefer not to do that, because
 the default operator new already has an equivalent check, and only
 programs linking to jemalloc require the workaround.

>>> Right the jemalloc fix was released May 2018.
>>> It would be great to avoid the extra workarounds.
>>> Given this would be released about a year after the jemalloc fix was
>>> released,
>>> and that this would only manifest upon program rebuild,
>>> I would be inclined to not add any workarounds.
>>> For reference tcmalloc and glibc malloc were seen to work fine with
>>> this.
>>
>> Actually the jemalloc issue will only be fixed with the release of 5.2
>> (a few weeks away).
>> I've updated the commit message in the attached accordingly.
>
> Hmm, I'm a bit nervous about making a change that will cause crashes
> unless using an unreleased version (I know it will be released by the
> time GCC 9.1 is released, but some people might upgrade GCC without
> upgrading jemalloc).
Yes it's not ideal. It does make it a lot less risky that one has to
rebuild programs to get the new functionality, so existing programs
will be unaffected. Also -fsized-deallocation is only enabled by
default on gcc with -std >= c++14.
>
> On the other hand, zero sized allocations should be rare in practice.
Yes they were rare in testing here

So programs _rebuilt_ against the following would need to update
to jemalloc 5.2:

  zero sized allocs, jemalloc<5.2, c++>=14, GCC>=9.1

Hopefully that's a small enough set.

thanks,
Pádraig


Re: [PATCH] Mention logical-op-non-short-circuit param in gcc/doc/invoke.texi.

2019-03-06 Thread Jakub Jelinek
On Wed, Mar 06, 2019 at 10:18:22AM +0100, Martin Liška wrote:
> On 3/5/19 5:01 PM, Jakub Jelinek wrote:
> > On Tue, Mar 05, 2019 at 04:53:54PM +0100, Martin Liška wrote:
> >> Hi.
> >>
> >> The param was added by Jakub. Should I mention it in invoke.texi?
> > 
> > It is meant solely for the testsuite, so I wouldn't document it.
> > But if others disagree, I'm not strongly opposed to that, but we then should
> > say so in the documentation.
> 
> Ah, I see. Then let me suggest patch that will ignore the option
> in contrib/check-params-in-docs.py script?

LGTM.

Jakub


Re: [v3 PATCH, RFC] Rewrite variant. Also PR libstdc++/85517

2019-03-06 Thread Jonathan Wakely

On 05/03/19 23:27 +0200, Ville Voutilainen wrote:

On Mon, 4 Mar 2019 at 01:43, Ville Voutilainen
 wrote:


On Mon, 4 Mar 2019 at 01:26, Ville Voutilainen
 wrote:
> I consider variant to no longer be in the state of sin after this.

Sigh, except for the places where it self-destructs or placement-news
over things that it shouldn't. That's hopefully
the next bit that I'll rectify, Real Soon Now.


Here we go. Variant, go forth and sin no more. Tested locally on
linux-x64, will run the full suite
on linux-ppc64. OK for trunk if tests pass?

2019-03-05  Ville Voutilainen  

   Rewrite variant.
   Also PR libstdc++/85517
   * include/std/variant (__do_visit): New.
   (__variant_cast): Likewise.
   (__variant_cookie): Likewise.
   (__erased_*): Remove.
   (_Variant_storage::_S_vtable): Likewise.
   (_Variant_storage::__M_reset_impl): Adjust to use __do_visit.
   (_Variant_storage::__M_reset): Adjust.
   (__variant_construct): New.
   (_Copy_ctor_base(const _Copy_ctor_base&)): Adjust to use
   __variant_construct.
   (_Move_ctor_base(_Move_ctor_base&&)): Likewise.
   (_Move_ctor_base::__M_destructive_copy): New.
   (_Move_ctor_base::__M_destructive_move): Adjust to use
   __variant_construct.
   (_Copy_assign_base::operator=): Adjust to use __do_visit.
   (_Copy_assign_alias): Adjust to check both copy assignment
   and copy construction for triviality.
   (_Move_assign_base::operator=): Adjust to use __do_visit.
   (_Multi_array): Add support for visitors that accept and return
   a __variant_cookie.
   (__gen_vtable_impl::_S_apply_all_alts): Likewise.
   (__gen_vtable_impl::_S_apply_single_alt): Likewise.
   (__gen_vtable_impl::__element_by_index_or_cookie): New. Generate
   a __variant_cookie temporary for a variant that is valueless and..
   (__gen_vtable_impl::__visit_invoke): ..adjust here.
   (__gen_vtable::_Array_type): Conditionally make space for
   the __variant_cookie visitor case.
   (__variant_construct_by_index): New.
   (get_if): Adjust to use std::addressof.
   (relops): Adjust to use __do_visit.
   (variant): Add __variant_cast and __variant_construct_by_index
   as friends.
   (variant::emplace): Use _M_reset() and __variant_construct_by_index
   instead of self-destruction.
   (variant::swap): Adjust to use __do_visit.
   (visit): Reimplement in terms of __do_visit.
   (__variant_hash_call_base_impl::operator()): Adjust to use __do_visit.
   * testsuite/20_util/variant/compile.cc: Adjust.
   * testsuite/20_util/variant/run.cc: Likewise.



diff --git a/libstdc++-v3/include/std/variant b/libstdc++-v3/include/std/variant
index 89deb14..5138599 100644
--- a/libstdc++-v3/include/std/variant
+++ b/libstdc++-v3/include/std/variant
@@ -138,6 +138,21 @@ namespace __variant
constexpr variant_alternative_t<_Np, variant<_Types...>> const&&
get(const variant<_Types...>&&);

+  template
+constexpr decltype(auto)
+__do_visit(_Visitor&& __visitor, _Variants&&... __variants);
+
+  template 
+decltype(auto) __variant_cast(_Tp&& __rhs)
+{
+  if constexpr (is_const_v>)
+return static_cast&>(__rhs);
+  else if constexpr (is_rvalue_reference_v<_Tp&&>)


I know what this is doing, but it still looks a little odd to ask if
T&& is an rvalue-reference.

Would it be clearer to structure this as:

 if constexpr (is_lvalue_reference_v<_Tp>)
   {
 if constexpr (is_const_v>)
   return static_cast&>(__rhs);
 else
   return static_cast&>(__rhs);
   }
 else
   return static_cast&&>(__rhs);

?


+  template
+void __variant_construct(_Tp&& __lhs, _Up&& __rhs)
+{
+  __lhs._M_index = __rhs._M_index;
+  __do_visit([](auto&& __this_mem, auto&& __rhs_mem) mutable
+-> __detail::__variant::__variant_cookie
+{
+ using _Type = remove_reference_t;
+ if constexpr (is_same_v<__remove_cvref_t,
+ remove_cv_t<_Type>>
+   && !is_same_v<_Type, __variant_cookie>)
+   ::new (std::addressof(__this_mem))


Is there any way that this can find the wrong operator new?

Even if it can't, saying ::new ((void*)std::addressof(__this_mem))
would avoid having to think about that question again in future.

Therre are a few other new expressions where that applies too (several
of them already there before your patch).


@@ -869,6 +926,15 @@ namespace __variant
} // namespace __variant
} // namespace __detail

+  template
+void __variant_construct_by_index(_Variant& __v, _Args&&... __args)
+{
+  __v._M_index = _Np;
+  auto&& __storage = __detail::__variant::__get<_Np>(__v);
+  ::new (&__storage) remove_reference_t


This one definitely needs to be cast to void* and needs to use
addressof (or __addressof), otherwise ...

struct X {
 ~X() { } // not trivially copyable
 X* operator&() { puts("First problem"); return this; }
};

void* operator new(std::size_t, X*)
{
 puts("second problem");
 abort();
}

int main()
{
 std::variant  v;
 v.e

Re: [PATCH] improve performance of std::allocator::deallocate

2019-03-06 Thread Jonathan Wakely

On 06/03/19 09:20 +, Pádraig Brady wrote:

On 03/06/2019 12:50 AM, Jonathan Wakely wrote:

On 06/03/19 02:43 +, Pádraig Brady wrote:



On 02/26/2019 04:23 PM, Padraig Brady wrote:



Note jemalloc >= 5.1 is required to fix a bug with 0 sizes.

How serious is the bug? What are the symptoms?


I've updated the commit summary to say it's a crash.
Arguably that's better than mem corruption.


It looks like 5.1.0 is less than a year old, so older versions are
presumably still in wide use.

We could potentially workaround it by making
new_allocator::allocate(0) call ::operator new(1) when
__cpp_sized_deallocation is defined, and deallocate(p, 0) call
::operator delete(p, 1). Obviously I'd prefer not to do that, because
the default operator new already has an equivalent check, and only
programs linking to jemalloc require the workaround.


Right the jemalloc fix was released May 2018.
It would be great to avoid the extra workarounds.
Given this would be released about a year after the jemalloc fix was
released,
and that this would only manifest upon program rebuild,
I would be inclined to not add any workarounds.
For reference tcmalloc and glibc malloc were seen to work fine with
this.


Actually the jemalloc issue will only be fixed with the release of 5.2
(a few weeks away).
I've updated the commit message in the attached accordingly.


Hmm, I'm a bit nervous about making a change that will cause crashes
unless using an unreleased version (I know it will be released by the
time GCC 9.1 is released, but some people might upgrade GCC without
upgrading jemalloc).

Yes it's not ideal. It does make it a lot less risky that one has to
rebuild programs to get the new functionality, so existing programs
will be unaffected. Also -fsized-deallocation is only enabled by
default on gcc with -std >= c++14.


The default is -std=gnu++14 so it's enabled unless you explicitly
choose an older dialect or add -fno-sized-deallocation.


On the other hand, zero sized allocations should be rare in practice.

Yes they were rare in testing here

So programs _rebuilt_ against the following would need to update
to jemalloc 5.2:

 zero sized allocs, jemalloc<5.2, c++>=14, GCC>=9.1

Hopefully that's a small enough set.


Which versions of jemalloc replace operator delete(void*, size_t) ?

Was that something new in 5.0 or did older versions already provide a
replacement for the sized operator delete?

If it was introduced in 5.0 then there won't be a problem for 3.x and
4.x because they'll use the default definition from libstdc++ which
just calls ::operator delete(p).

How complicated is the fix to prevent the crashes? Would it be
feasible for distros to backport that fix? I see that RHEL8 has
jemalloc 5.0.1 for example, but if the fix could be backported to that
release then it's less of a problem.




Re: [v3 PATCH, RFC] Rewrite variant. Also PR libstdc++/85517

2019-03-06 Thread Ville Voutilainen
On Wed, 6 Mar 2019 at 11:33, Jonathan Wakely  wrote:
> >+  else if constexpr (is_rvalue_reference_v<_Tp&&>)
>
> I know what this is doing, but it still looks a little odd to ask if
> T&& is an rvalue-reference.
>
> Would it be clearer to structure this as:
>
>   if constexpr (is_lvalue_reference_v<_Tp>)
> {
>   if constexpr (is_const_v>)
> return static_cast&>(__rhs);
>   else
> return static_cast&>(__rhs);
> }
>   else
> return static_cast&&>(__rhs);
>
> ?
> >+  ::new (std::addressof(__this_mem))
>
> Is there any way that this can find the wrong operator new?
>
> Even if it can't, saying ::new ((void*)std::addressof(__this_mem))
> would avoid having to think about that question again in future.
>
> Therre are a few other new expressions where that applies too (several
> of them already there before your patch).
> >+  ::new (&__storage) remove_reference_t
>
> This one definitely needs to be cast to void* and needs to use
> addressof (or __addressof), otherwise ...


Sure thing; an incremental diff attached.
diff --git a/libstdc++-v3/include/std/variant b/libstdc++-v3/include/std/variant
index 5138599..4d81ceb 100644
--- a/libstdc++-v3/include/std/variant
+++ b/libstdc++-v3/include/std/variant
@@ -145,12 +145,15 @@ namespace __variant
   template 
 decltype(auto) __variant_cast(_Tp&& __rhs)
 {
-  if constexpr (is_const_v>)
-return static_cast&>(__rhs);
-  else if constexpr (is_rvalue_reference_v<_Tp&&>)
-return static_cast&&>(__rhs);
+  if constexpr (is_lvalue_reference_v<_Tp>)
+	{
+	  if constexpr (is_const_v>)
+			 return static_cast&>(__rhs);
+	  else
+	return static_cast&>(__rhs);
+	}
   else
-return static_cast&>(__rhs);
+return static_cast&&>(__rhs);
 }
 
 namespace __detail
@@ -212,7 +215,8 @@ namespace __variant
 {
   template
   constexpr _Uninitialized(in_place_index_t<0>, _Args&&... __args)
-  { ::new (&_M_storage) _Type(std::forward<_Args>(__args)...); }
+  { ::new ((void*)std::addressof(_M_storage))
+	  _Type(std::forward<_Args>(__args)...); }
 
   const _Type& _M_get() const &
   { return *_M_storage._M_ptr(); }
@@ -427,7 +431,7 @@ namespace __variant
 	  if constexpr (is_same_v<__remove_cvref_t,
 			  remove_cv_t<_Type>>
 			&& !is_same_v<_Type, __variant_cookie>)
-	::new (std::addressof(__this_mem))
+	::new ((void*)std::addressof(__this_mem))
 	  _Type(std::forward(__rhs_mem));
 	  return {};
 	}, __variant_cast<_Types...>(__lhs),
@@ -931,8 +935,9 @@ namespace __variant
 {
   __v._M_index = _Np;
   auto&& __storage = __detail::__variant::__get<_Np>(__v);
-  ::new (&__storage) remove_reference_t
-(std::forward<_Args>(__args)...);
+  ::new ((void*)std::addressof(__storage))
+remove_reference_t
+	  (std::forward<_Args>(__args)...);
 }
 
   template


Re: [v3 PATCH, RFC] Rewrite variant. Also PR libstdc++/85517

2019-03-06 Thread Ville Voutilainen
On Wed, 6 Mar 2019 at 11:56, Ville Voutilainen
 wrote:
> > This one definitely needs to be cast to void* and needs to use
> > addressof (or __addressof), otherwise ...
>
>
> Sure thing; an incremental diff attached.

And here's the whole shebang.
diff --git a/libstdc++-v3/include/std/variant b/libstdc++-v3/include/std/variant
index 89deb14..4d81ceb 100644
--- a/libstdc++-v3/include/std/variant
+++ b/libstdc++-v3/include/std/variant
@@ -138,6 +138,24 @@ namespace __variant
 constexpr variant_alternative_t<_Np, variant<_Types...>> const&&
 get(const variant<_Types...>&&);
 
+  template
+constexpr decltype(auto)
+__do_visit(_Visitor&& __visitor, _Variants&&... __variants);
+
+  template 
+decltype(auto) __variant_cast(_Tp&& __rhs)
+{
+  if constexpr (is_lvalue_reference_v<_Tp>)
+	{
+	  if constexpr (is_const_v>)
+			 return static_cast&>(__rhs);
+	  else
+	return static_cast&>(__rhs);
+	}
+  else
+return static_cast&&>(__rhs);
+}
+
 namespace __detail
 {
 namespace __variant
@@ -155,6 +173,9 @@ namespace __variant
   std::integral_constant
 	? 0 : __index_of_v<_Tp, _Rest...> + 1> {};
 
+  // used for raw visitation
+  struct __variant_cookie {};
+
   // _Uninitialized is guaranteed to be a literal type, even if T is not.
   // We have to do this, because [basic.types]p10.5.3 (n4606) is not implemented
   // yet. When it's implemented, _Uninitialized can be changed to the alias
@@ -194,7 +215,8 @@ namespace __variant
 {
   template
   constexpr _Uninitialized(in_place_index_t<0>, _Args&&... __args)
-  { ::new (&_M_storage) _Type(std::forward<_Args>(__args)...); }
+  { ::new ((void*)std::addressof(_M_storage))
+	  _Type(std::forward<_Args>(__args)...); }
 
   const _Type& _M_get() const &
   { return *_M_storage._M_ptr(); }
@@ -236,63 +258,6 @@ namespace __variant
 			  std::forward<_Variant>(__v)._M_u);
 }
 
-  // Various functions as "vtable" entries, where those vtables are used by
-  // polymorphic operations.
-  template
-void
-__erased_ctor(void* __lhs, void* __rhs)
-{
-  using _Type = remove_reference_t<_Lhs>;
-  ::new (__lhs) _Type(__variant::__ref_cast<_Rhs>(__rhs));
-}
-
-  template
-void
-__erased_dtor(_Variant&& __v)
-{ std::_Destroy(std::__addressof(__variant::__get<_Np>(__v))); }
-
-  template
-void
-__erased_assign(void* __lhs, void* __rhs)
-{
-  __variant::__ref_cast<_Lhs>(__lhs) = __variant::__ref_cast<_Rhs>(__rhs);
-}
-
-  template
-void
-__erased_swap(void* __lhs, void* __rhs)
-{
-  using std::swap;
-  swap(__variant::__ref_cast<_Lhs>(__lhs),
-	   __variant::__ref_cast<_Rhs>(__rhs));
-}
-
-#define _VARIANT_RELATION_FUNCTION_TEMPLATE(__OP, __NAME) \
-  template \
-constexpr bool \
-__erased_##__NAME(const _Variant& __lhs, const _Variant& __rhs) \
-{ \
-  return __variant::__get<_Np>(std::forward<_Variant>(__lhs)) \
-	  __OP __variant::__get<_Np>(std::forward<_Variant>(__rhs)); \
-}
-
-  _VARIANT_RELATION_FUNCTION_TEMPLATE(<, less)
-  _VARIANT_RELATION_FUNCTION_TEMPLATE(<=, less_equal)
-  _VARIANT_RELATION_FUNCTION_TEMPLATE(==, equal)
-  _VARIANT_RELATION_FUNCTION_TEMPLATE(!=, not_equal)
-  _VARIANT_RELATION_FUNCTION_TEMPLATE(>=, greater_equal)
-  _VARIANT_RELATION_FUNCTION_TEMPLATE(>, greater)
-
-#undef _VARIANT_RELATION_FUNCTION_TEMPLATE
-
-  template
-size_t
-__erased_hash(void* __t)
-{
-  return std::hash<__remove_cvref_t<_Tp>>{}(
-	  __variant::__ref_cast<_Tp>(__t));
-}
-
   template
 struct _Traits
 {
@@ -369,9 +334,6 @@ namespace __variant
   template
 struct _Variant_storage
 {
-  template
-	static constexpr void (*_S_vtable[])(const _Variant_storage&) =
-	{ &__erased_dtor... };
 
   constexpr _Variant_storage() : _M_index(variant_npos) { }
 
@@ -381,16 +343,21 @@ namespace __variant
 	_M_index(_Np)
 	{ }
 
-  template
-	constexpr void _M_reset_impl(std::index_sequence<__indices...>)
-	{
-	  if (_M_index != __index_type(variant_npos))
-	_S_vtable<__indices...>[_M_index](*this);
+  constexpr void _M_reset_impl()
+  {
+	__do_visit([](auto&& __this_mem) mutable
+		   -> __detail::__variant::__variant_cookie
+	  {
+	if constexpr (!is_same_v,
+			  __variant_cookie>)
+	  std::_Destroy(std::__addressof(__this_mem));
+	return {};
+	  }, __variant_cast<_Types...>(*this));
 	}
 
   void _M_reset()
   {
-	_M_reset_impl(std::index_sequence_for<_Types...>{});
+	_M_reset_impl();
 	_M_index = variant_npos;
   }
 
@@ -453,6 +420,24 @@ namespace __variant
 using _Variant_storage_alias =
 	_Variant_storage<_Traits<_Types...>::_S_trivial_dtor, _Types...>;
 
+  template
+void __variant_construct(_Tp&& __lhs, _Up&& __rhs)
+{
+  __lhs._M_index = __rhs._M_index;
+  __do_visit([](auto&& __this_mem, auto&& __rhs_mem) mutable
+		 -> __detail::__variant::__variant_cookie
+{
+	  using _Type = remove_reference_t;
+	

Re: [PATCH] Significantly speed up verifiers for a cgraph_node with many clones.

2019-03-06 Thread Martin Liška
@Honza: PING^1

On 2/22/19 11:59 AM, Martin Liška wrote:
> Hi.
> 
> The patch makes a significant verifier speed up in a project that
> has a dtor for which we create ~70.000 clones.
> 
> Patch can bootstrap on x86_64-linux-gnu and survives regression tests.
> 
> Ready to be installed?
> Thanks,
> Martin
> 
> gcc/ChangeLog:
> 
> 2019-02-22  Martin Liska  
> 
>   * cgraph.c (cgraph_node::verify_node): Verify with a neighbour
>   which is equivalent to searching for this in clones chain.
>   * symtab.c (symtab_node::verify_base): Similarly compare ASM
>   names with a neighbour and special case first node in a chain.
> ---
>  gcc/cgraph.c | 14 +++---
>  gcc/symtab.c | 39 +++
>  2 files changed, 30 insertions(+), 23 deletions(-)
> 
> 



Re: [PATCH, stage1] Construct ipa_reduced_postorder always for overwritable (PR ipa/89009).

2019-03-06 Thread Martin Liška
@Honza: PING^1

On 2/20/19 10:10 AM, Martin Liška wrote:
> On 2/19/19 2:25 PM, Martin Jambor wrote:
>> Hi,
>>
>> On Tue, Feb 19 2019, Martin Liška wrote:
>>> On 2/14/19 11:19 AM, Jan Hubicka wrote:

>>
>> ...
>>
 Next stage1 we should also teach the callback to ignore edges of calls
 that are not being optimized.
>>>
>>> I'm sending patch for that.
>>
>> ...
>>
>>> gcc/ChangeLog:
>>>
>>> 2019-02-19  Martin Liska  
>>>
>>> * ipa-cp.c (ignore_edge_p): New function.
>>> (build_toporder_info): Use it.
>>> * ipa-inline.c (ignore_edge_p): New function/
>>> (inline_small_functions): Use it.
>>> * ipa-pure-const.c (ignore_edge_for_nothrow):
>>> Verify opt_for_fn for caller and callee.
>>> (ignore_edge_for_pure_const): Likewise.
>>> * ipa-reference.c (ignore_edge_p): Extend to check
>>> for opt_for_fn.
>>> * ipa-utils.c (searchc): Refactor.
>>> * ipa-utils.h: Fix coding style.
>>> ---
>>>  gcc/ipa-cp.c | 18 +-
>>>  gcc/ipa-inline.c | 12 +++-
>>>  gcc/ipa-pure-const.c | 17 -
>>>  gcc/ipa-reference.c  | 13 ++---
>>>  gcc/ipa-utils.c  |  3 +--
>>>  gcc/ipa-utils.h  |  2 --
>>>  6 files changed, 51 insertions(+), 14 deletions(-)
>>>
>>> diff --git a/gcc/ipa-cp.c b/gcc/ipa-cp.c
>>> index 442d5c63eff..004b3a34b1c 100644
>>> --- a/gcc/ipa-cp.c
>>> +++ b/gcc/ipa-cp.c
>>> @@ -806,6 +806,21 @@ public:
>>>{}
>>>  };
>>>  
>>> +/* Skip edges from and to nodes without ipa_cp enabled.
>>> +   Ignore not available symbols.  */
>>> +
>>> +static bool
>>> +ignore_edge_p (cgraph_edge *e)
>>> +{
>>> +  enum availability avail;
>>> +  e->callee->function_or_virtual_thunk_symbol (&avail, e->caller);
>>
>> Can't the return value of this call be directly fed...
>>
>>> +
>>> +  return (avail <= AVAIL_INTERPOSABLE
>>> + || !opt_for_fn (e->caller->decl, flag_ipa_cp)
>>> + || !opt_for_fn (e->callee->function_symbol ()->decl,
>>
>> ...here instead of calling function_symbol... which does not look
>> through thunks which IMHO you want, even if only for consistency.
> 
> Yes, I like it.
> 
> There's a new version of the patch I've just tested.
> 
> Martin
> 
>>
>> Otherwise, it the IPA-CP bits obviously look good,
>>
>> Martin
>>
> 



Re: A bug in vrp_meet?

2019-03-06 Thread Richard Biener
On Tue, Mar 5, 2019 at 10:36 PM Jeff Law  wrote:
>
> On 3/5/19 7:44 AM, Richard Biener wrote:
>
> > So fixing it properly with also re-optimize_stmt those stmts so we'd CSE
> > the MAX_EXPR introduced by folding makes it somewhat ugly.
> >
> > Bootstrapped on x86_64-unknown-linux-gnu, testing in progress.
> >
> > Any ideas how to make it less so?  I can split out making optimize_stmt
> > take a gsi * btw, in case that's a more obvious change and it makes the
> > patch a little smaller.
> >
> > Richard.
> >
> > 2019-03-05  Richard Biener  
> >
> > PR tree-optimization/89595
> > * tree-ssa-dom.c (dom_opt_dom_walker::optimize_stmt): Take
> > stmt iterator as reference, take boolean output parameter to
> > indicate whether the stmt was removed and thus the iterator
> > already advanced.
> > (dom_opt_dom_walker::before_dom_children): Re-iterate over
> > stmts created by folding.
> >
> > * gcc.dg/torture/pr89595.c: New testcase.
> >
>
> Well, all the real logic changs are in the before_dom_children method.
> The bits in optimize_stmt are trivial enough to effectively ignore.
>
> I don't see a better way to discover and process statements that are
> created in the bowels of fold_stmt.

I'm not entirely happy so I created the following alternative which
is a bit larger and slower due to the pre-pass clearing the visited flag
but is IMHO easier to follow.  I guess there's plenty of TLC opportunity
here but then I also hope to retire the VN parts of DOM in favor
of the non-iterating RPO-VN code...

So - I'd lean to this variant even though it has the extra loop over stmts,
would you agree?

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

Richard.

2019-03-06  Richard Biener  

PR tree-optimization/89595
* tree-ssa-dom.c (dom_opt_dom_walker::optimize_stmt): Take
stmt iterator as reference, take boolean output parameter to
indicate whether the stmt was removed and thus the iterator
already advanced.
(dom_opt_dom_walker::before_dom_children): Re-iterate over
stmts created by folding.

* gcc.dg/torture/pr89595.c: New testcase.


fix-pr89595-2
Description: Binary data


Re: [v3 PATCH, RFC] Rewrite variant. Also PR libstdc++/85517

2019-03-06 Thread Jonathan Wakely

On 06/03/19 11:56 +0200, Ville Voutilainen wrote:

On Wed, 6 Mar 2019 at 11:33, Jonathan Wakely  wrote:

>+  else if constexpr (is_rvalue_reference_v<_Tp&&>)

I know what this is doing, but it still looks a little odd to ask if
T&& is an rvalue-reference.

Would it be clearer to structure this as:

  if constexpr (is_lvalue_reference_v<_Tp>)
{
  if constexpr (is_const_v>)
return static_cast&>(__rhs);
  else
return static_cast&>(__rhs);
}
  else
return static_cast&&>(__rhs);

?
>+  ::new (std::addressof(__this_mem))

Is there any way that this can find the wrong operator new?

Even if it can't, saying ::new ((void*)std::addressof(__this_mem))
would avoid having to think about that question again in future.

Therre are a few other new expressions where that applies too (several
of them already there before your patch).
>+  ::new (&__storage) remove_reference_t

This one definitely needs to be cast to void* and needs to use
addressof (or __addressof), otherwise ...



Sure thing; an incremental diff attached.



diff --git a/libstdc++-v3/include/std/variant b/libstdc++-v3/include/std/variant
index 5138599..4d81ceb 100644
--- a/libstdc++-v3/include/std/variant
+++ b/libstdc++-v3/include/std/variant
@@ -145,12 +145,15 @@ namespace __variant
  template 
decltype(auto) __variant_cast(_Tp&& __rhs)
{
-  if constexpr (is_const_v>)
-return static_cast&>(__rhs);
-  else if constexpr (is_rvalue_reference_v<_Tp&&>)
-return static_cast&&>(__rhs);
+  if constexpr (is_lvalue_reference_v<_Tp>)


As you mentioned on IRC, this also seems a bit odd ("why would it be
an lvalue reference?"), but such is the way of forwarding references
... they're not very intuitable. I think I have a weak preference for
doing it this way, so thanks for the change.


+   {
+ if constexpr (is_const_v>)
+return static_cast&>(__rhs);


Too many TABs here.


+ else
+   return static_cast&>(__rhs);
+   }
  else
-return static_cast&>(__rhs);
+return static_cast&&>(__rhs);
}

namespace __detail
@@ -212,7 +215,8 @@ namespace __variant
{
  template
  constexpr _Uninitialized(in_place_index_t<0>, _Args&&... __args)
-  { ::new (&_M_storage) _Type(std::forward<_Args>(__args)...); }
+  { ::new ((void*)std::addressof(_M_storage))
+ _Type(std::forward<_Args>(__args)...); }


Now that it doesn't fit in a single line, please put the braces on
separate lines:

 {
   ::new ((void*)std::addressof(_M_storage))
  _Type(std::forward<_Args>(__args)...);
 }

Otherwise looks great, OK for trunk with those whitespace tweaks.
Thanks for doing this!




[PATCH] Extend Arm interrupt attribute

2019-03-06 Thread Alexander Fedotov
This is quite common mistake when SVC is used as parameter for
interrupt attribute instead of SWI. Since gcc doesn't warn the
developer and treats this as undefined I propose following patch.


0001-Allow-SVC-as-a-parameter-of-intterupt-attribute.patch
Description: Binary data


Re: [PATCH] Adjust gcc.dg/uninit-pred-8_b.c (PR89551)

2019-03-06 Thread Richard Biener
On Mon, 4 Mar 2019, Richard Biener wrote:

> 
> The CFG cleanup change made us remove an extra forwarder which somehow
> makes VRP jump threading go berzerk.  Fortunately only on
> logical-op-non-short-circuit=0 targets so the easy way to fix the
> testcase is to force that our way.
> 
> Tested on powerpc64le-linux-gnu and x86_64-linux-gnu.
> 
> I'll hold off applying this for a bit in case Jeff wants to
> analyze why/how we're doing extra jump threading just because
> of the lack of that extra forwarder...

r269416.

Richard.

> 2019-03-04  Richard Biener  
> 
>   PR testsuite/89551
>   * gcc.dg/uninit-pred-8_b.c: Force logical-op-non-short-circuit
>   the way that makes the testcase PASS.
> 
> Index: gcc/testsuite/gcc.dg/uninit-pred-8_b.c
> ===
> --- gcc/testsuite/gcc.dg/uninit-pred-8_b.c(revision 269361)
> +++ gcc/testsuite/gcc.dg/uninit-pred-8_b.c(working copy)
> @@ -1,6 +1,7 @@
> -
>  /* { dg-do compile } */
> -/* { dg-options "-Wuninitialized -O2" } */
> +/* ???  Jump threading makes a mess of the logical-op-non-short-circuit=0 
> case
> +   so force it our way.  */
> +/* { dg-options "-Wuninitialized -O2 --param logical-op-non-short-circuit=1" 
> } */
>  
>  int g;
>  void bar();
> 


[PATCH 0/5][ARC] Fix failing tests and use newer macros.

2019-03-06 Thread Claudiu Zissulescu
Hi,

Please find a set of 5 patches as this:

  [ARC] Introduce ADJUST_REG_ALLOC_ORDER.
This patch just cleans the old way of changing the register allocation 
order and uses a gcc macro specially made for this task.

  [ARC] Enable code density frame option for elf targets.
The compress instruction for frame are there for a while, but they are 
not enabled by default when using Os, just do it.

  [ARC] Define TARGET_HAVE_SPECULATION_SAFE_VALUE.
New macro fixes a dejagnu failure.

  [ARC] Fix tst_movb pattern.
Fixes dejagnu failure.

  [ARC] Refactor deprecated macros.
Old macros replaced with their newer equivalent.


Thanks,
Claudiu

 gcc/config/arc/arc-protos.h |   3 +-
 gcc/config/arc/arc.c| 101 ++--
 gcc/config/arc/arc.h|  44 ++--
 gcc/config/arc/arc.md   |  24 -
 gcc/config/arc/arc.opt  |   2 +-
 gcc/config/arc/elf.h|   4 ++
 gcc/config/arc/linux.h  |   4 ++
 7 files changed, 99 insertions(+), 83 deletions(-)

-- 
2.20.1



[PATCH 3/5] [ARC] Define TARGET_HAVE_SPECULATION_SAFE_VALUE.

2019-03-06 Thread Claudiu Zissulescu
-xx-xx  Claudiu Zissulescu  

* config/arc/arc.c (TARGET_HAVE_SPECULATION_SAFE_VALUE): Define.
---
 gcc/config/arc/arc.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/gcc/config/arc/arc.c b/gcc/config/arc/arc.c
index 9e086477027..a3a013e90e1 100644
--- a/gcc/config/arc/arc.c
+++ b/gcc/config/arc/arc.c
@@ -11440,6 +11440,9 @@ arc_adjust_reg_alloc_order (void)
 #undef TARGET_ASM_TRAMPOLINE_TEMPLATE
 #define TARGET_ASM_TRAMPOLINE_TEMPLATE arc_asm_trampoline_template
 
+#undef TARGET_HAVE_SPECULATION_SAFE_VALUE
+#define TARGET_HAVE_SPECULATION_SAFE_VALUE speculation_safe_value_not_needed
+
 struct gcc_target targetm = TARGET_INITIALIZER;
 
 #include "gt-arc.h"
-- 
2.20.1



[PATCH 4/5] [ARC] Fix tst_movb pattern.

2019-03-06 Thread Claudiu Zissulescu
-xx-xx  Claudiu Zissulescu  

* config/arc/arc.md (tst_movb): Fix constraint.
---
 gcc/config/arc/arc.md | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/gcc/config/arc/arc.md b/gcc/config/arc/arc.md
index c64a7fdb653..1e64331f397 100644
--- a/gcc/config/arc/arc.md
+++ b/gcc/config/arc/arc.md
@@ -958,10 +958,10 @@ core_3, archs4x, archs4xd, archs4xd_slow"
  (match_operand 0 "cc_register" "")
  (match_operator 4 "zn_compare_operator"
[(and:SI
- (match_operand:SI 1 "register_operand"  "%Rcq,Rcq, c,  c,  c,  c,Rrq, 
 3,  c")
+ (match_operand:SI 1 "register_operand"  "%Rcq,Rcq, c,  c,  c,  
c,Rrq,Rrq,  c")
  (match_operand:SI 2 "nonmemory_operand"  
"Rcq,C0p,cI,C1p,Ccp,Chs,Cbf,Cbf,???Cal"))
(const_int 0)]))
-   (clobber (match_scratch:SI 3 "=X,X,X,X,X,X,Rrq,Rrq,c"))]
+   (clobber (match_scratch:SI 3 "=X,X,X,X,X,X,Rrq,1,c"))]
   "TARGET_NPS_BITOPS"
   "movb.f.cl %3,%1,%p2,%p2,%s2"
   "TARGET_NPS_BITOPS && reload_completed
-- 
2.20.1



[PATCH 5/5] [ARC] Refactor deprecated macros.

2019-03-06 Thread Claudiu Zissulescu
-xx-xx  Claudiu Zissulescu  

* config/arc/arc-protos.h (arc_register_move_cost): Remove.
* config/arc/arc.c (arc_register_move_cost): Re-purpose it to
implement target hook.
(arc_memory_move_cost): New function.
(TARGET_REGISTER_MOVE_COST): Define.
(TARGET_MEMORY_MOVE_COST): Likewise.
* config/arc/arc.h (REGISTER_MOVE_COST): Remove.
(MEMORY_MOVE_COST): Likewise.
---
 gcc/config/arc/arc-protos.h |  2 --
 gcc/config/arc/arc.c| 26 --
 gcc/config/arc/arc.h| 11 ---
 3 files changed, 24 insertions(+), 15 deletions(-)

diff --git a/gcc/config/arc/arc-protos.h b/gcc/config/arc/arc-protos.h
index 8f0f197f14a..ac0de6b2874 100644
--- a/gcc/config/arc/arc-protos.h
+++ b/gcc/config/arc/arc-protos.h
@@ -68,8 +68,6 @@ extern bool arc_is_shortcall_p (rtx);
 extern bool valid_brcc_with_delay_p (rtx *);
 extern bool arc_ccfsm_cond_exec_p (void);
 struct secondary_reload_info;
-extern int arc_register_move_cost (machine_mode, enum reg_class,
-  enum reg_class);
 extern rtx disi_highpart (rtx);
 extern int arc_adjust_insn_length (rtx_insn *, int, bool);
 extern int arc_corereg_hazard (rtx, rtx);
diff --git a/gcc/config/arc/arc.c b/gcc/config/arc/arc.c
index a3a013e90e1..50977704c45 100644
--- a/gcc/config/arc/arc.c
+++ b/gcc/config/arc/arc.c
@@ -8686,9 +8686,11 @@ arc_preserve_reload_p (rtx in)
  && !((INTVAL (XEXP (in, 1)) & 511)));
 }
 
-int
+/* Implement TARGET_REGISTER_MOVE_COST.  */
+
+static int
 arc_register_move_cost (machine_mode,
-   enum reg_class from_class, enum reg_class to_class)
+   reg_class_t from_class, reg_class_t to_class)
 {
   /* Force an attempt to 'mov Dy,Dx' to spill.  */
   if ((TARGET_ARC700 || TARGET_EM) && TARGET_DPFP
@@ -11428,6 +11430,20 @@ arc_adjust_reg_alloc_order (void)
 memcpy (reg_alloc_order, size_alloc_order, sizeof (size_alloc_order));
 }
 
+/* Implement TARGET_MEMORY_MOVE_COST.  */
+
+static int
+arc_memory_move_cost (machine_mode mode,
+ reg_class_t rclass ATTRIBUTE_UNUSED,
+ bool in ATTRIBUTE_UNUSED)
+{
+  if ((GET_MODE_SIZE (mode) <= UNITS_PER_WORD)
+  || ((GET_MODE_SIZE (mode) <= UNITS_PER_WORD * 2) && TARGET_LL64))
+return 6;
+
+  return (2 * GET_MODE_SIZE (mode));
+}
+
 #undef TARGET_USE_ANCHORS_FOR_SYMBOL_P
 #define TARGET_USE_ANCHORS_FOR_SYMBOL_P arc_use_anchors_for_symbol_p
 
@@ -11443,6 +11459,12 @@ arc_adjust_reg_alloc_order (void)
 #undef TARGET_HAVE_SPECULATION_SAFE_VALUE
 #define TARGET_HAVE_SPECULATION_SAFE_VALUE speculation_safe_value_not_needed
 
+#undef TARGET_REGISTER_MOVE_COST
+#define TARGET_REGISTER_MOVE_COST arc_register_move_cost
+
+#undef TARGET_MEMORY_MOVE_COST
+#define TARGET_MEMORY_MOVE_COST arc_memory_move_cost
+
 struct gcc_target targetm = TARGET_INITIALIZER;
 
 #include "gt-arc.h"
diff --git a/gcc/config/arc/arc.h b/gcc/config/arc/arc.h
index 90420a9d474..46ca2dde413 100644
--- a/gcc/config/arc/arc.h
+++ b/gcc/config/arc/arc.h
@@ -925,17 +925,6 @@ arc_select_cc_mode (OP, X, Y)
 
 /* Costs.  */
 
-/* Compute extra cost of moving data between one register class
-   and another.  */
-#define REGISTER_MOVE_COST(MODE, CLASS, TO_CLASS) \
-   arc_register_move_cost ((MODE), (CLASS), (TO_CLASS))
-
-/* Compute the cost of moving data between registers and memory.  */
-/* Memory is 3 times as expensive as registers.
-   ??? Is that the right way to look at it?  */
-#define MEMORY_MOVE_COST(MODE,CLASS,IN) \
-(GET_MODE_SIZE (MODE) <= UNITS_PER_WORD ? 6 : 12)
-
 /* The cost of a branch insn.  */
 /* ??? What's the right value here?  Branches are certainly more
expensive than reg->reg moves.  */
-- 
2.20.1



[PATCH 2/5] [ARC] Enable code density frame option for elf targets.

2019-03-06 Thread Claudiu Zissulescu
-xx-xx  Claudiu Zissulescu  

* config/arc/arc.opt (mcode-density-frame): Get the inital value
from TARGET_CODE_DENSITY_FRAME_DEFAULT.
* config/arc/elf.h (TARGET_CODE_DENSITY_FRAME_DEFAULT): Define it
to 1.
* config/arc/linux.h (TARGET_CODE_DENSITY_FRAME_DEFAULT): Define
it to 0.
---
 gcc/config/arc/arc.c   |  5 -
 gcc/config/arc/arc.md  | 20 ++--
 gcc/config/arc/arc.opt |  2 +-
 gcc/config/arc/elf.h   |  4 
 gcc/config/arc/linux.h |  4 
 5 files changed, 23 insertions(+), 12 deletions(-)

diff --git a/gcc/config/arc/arc.c b/gcc/config/arc/arc.c
index 0b18e677735..9e086477027 100644
--- a/gcc/config/arc/arc.c
+++ b/gcc/config/arc/arc.c
@@ -1292,6 +1292,9 @@ arc_override_options (void)
   if (arc_size_opt_level == 3)
 optimize_size = 1;
 
+  if (TARGET_V2 && optimize_size && (ATTRIBUTE_PCS == 2))
+TARGET_CODE_DENSITY_FRAME = 1;
+
   if (flag_pic)
 {
   /* If we had SDATA enabled, still don't use GP when pic is
@@ -3188,7 +3191,7 @@ arc_save_callee_enter (unsigned int gmask,
   reg = gen_rtx_SET (stack_pointer_rtx,
 plus_constant (Pmode,
stack_pointer_rtx,
-   nregs * UNITS_PER_WORD));
+   -nregs * UNITS_PER_WORD));
   RTX_FRAME_RELATED_P (reg) = 1;
   XVECEXP (insn, 0, indx++) = reg;
   off = nregs * UNITS_PER_WORD;
diff --git a/gcc/config/arc/arc.md b/gcc/config/arc/arc.md
index 54d073107a8..c64a7fdb653 100644
--- a/gcc/config/arc/arc.md
+++ b/gcc/config/arc/arc.md
@@ -6442,7 +6442,7 @@ core_3, archs4x, archs4xd, archs4xd_slow"
 (plus:SI (reg:SI SP_REG)
  (match_operand 1 "immediate_operand" "")))
(set (mem:SI (plus:SI (reg:SI SP_REG)
- (match_dup 1)))
+ (match_operand 2 "immediate_operand" 
"")))
 (reg:SI 13))])]
   "TARGET_CODE_DENSITY"
   {
@@ -6450,14 +6450,14 @@ core_3, archs4x, archs4xd, archs4xd_slow"
rtx tmp = XVECEXP (operands[0], 0, len - 1);
if (MEM_P (XEXP (tmp, 0)))
  {
-  operands[2] = XEXP (tmp, 1);
-  return "enter_s\\t{r13-%2} ; sp=sp-%1";
+  operands[3] = XEXP (tmp, 1);
+  return "enter_s\\t{r13-%3} ; sp=sp+(%1)";
  }
else
  {
   tmp = XVECEXP (operands[0], 0, len - 3);
-  operands[2] = XEXP (tmp, 1);
-  return "enter_s\\t{r13-%2, fp} ; sp=sp-%1";
+  operands[3] = XEXP (tmp, 1);
+  return "enter_s\\t{r13-%3, fp} ; sp=sp+(%1)";
  }
   }
   [(set_attr "type" "call_no_delay_slot")
@@ -6469,7 +6469,7 @@ core_3, archs4x, archs4xd, archs4xd_slow"
 (plus:SI (reg:SI SP_REG)
  (match_operand 1 "immediate_operand" "")))
(set (mem:SI (plus:SI (reg:SI SP_REG)
- (match_dup 1)))
+ (match_operand 2 "immediate_operand" 
"")))
 (reg:SI RETURN_ADDR_REGNUM))])]
   "TARGET_CODE_DENSITY"
   {
@@ -6477,14 +6477,14 @@ core_3, archs4x, archs4xd, archs4xd_slow"
rtx tmp = XVECEXP (operands[0], 0, len - 1);
if (MEM_P (XEXP (tmp, 0)))
  {
-  operands[2] = XEXP (tmp, 1);
-  return "enter_s\\t{r13-%2, blink} ; sp=sp-%1";
+  operands[3] = XEXP (tmp, 1);
+  return "enter_s\\t{r13-%3, blink} ; sp=sp+(%1)";
  }
else
  {
   tmp = XVECEXP (operands[0], 0, len - 3);
-  operands[2] = XEXP (tmp, 1);
-  return "enter_s\\t{r13-%2, fp, blink} ; sp=sp-%1";
+  operands[3] = XEXP (tmp, 1);
+  return "enter_s\\t{r13-%3, fp, blink} ; sp=sp+(%1)";
  }
   }
   [(set_attr "type" "call_no_delay_slot")
diff --git a/gcc/config/arc/arc.opt b/gcc/config/arc/arc.opt
index a5271cbbceb..567df30951f 100644
--- a/gcc/config/arc/arc.opt
+++ b/gcc/config/arc/arc.opt
@@ -537,5 +537,5 @@ Target Report Var(TARGET_BRANCH_INDEX) 
Init(DEFAULT_BRANCH_INDEX)
 Enable use of BI/BIH instructions when available.
 
 mcode-density-frame
-Target Report Var(TARGET_CODE_DENSITY_FRAME)
+Target Report Var(TARGET_CODE_DENSITY_FRAME) 
Init(TARGET_CODE_DENSITY_FRAME_DEFAULT)
 Enable ENTER_S and LEAVE_S opcodes for ARCv2.
diff --git a/gcc/config/arc/elf.h b/gcc/config/arc/elf.h
index 8f9bec05606..651741f3342 100644
--- a/gcc/config/arc/elf.h
+++ b/gcc/config/arc/elf.h
@@ -98,3 +98,7 @@ along with GCC; see the file COPYING3.  If not see
   fixed_regs[GP_REG] = 0;  \
   arc_regno_reg_class[GP_REG] = GENERAL_REGS;  \
 }
+
+/* Enter/Leave ops are default on for elf targets.  */
+#undef TARGET_CODE_DENSITY_FRAME_DEFAULT
+#define TARGET_CODE_DENSITY_FRAME_DEFAULT 0
diff --git a/gcc/config/arc/linux.h b/gcc/config/arc/linux.h
index 6c8a7b46296..270ca907d87 100644
--- a/gcc/config/arc/linux.h
+++ b/gcc/config/arc/linux.h
@@ -133,3 +1

[PATCH 1/5] [ARC] Introduce ADJUST_REG_ALLOC_ORDER.

2019-03-06 Thread Claudiu Zissulescu
The ARC port is changing the allocation order in the
arc_conditional_register_usage function, but this is not the proper
way. Thus, we employ ADJUST_REG_ALLOC_ORDER hook for this task.

gcc/
-xx-xx  Claudiu Zissulescu  

* config/arc/arc-protos.h (arc_adjust_reg_alloc_order): Declare.
* config/arc/arc.c (arc_conditional_register_usage): Remove all
reg_alloc_order references.
(size_alloc_order): Define.
(arc_adjust_reg_alloc_order): New function.
* config/arc/arc.h (REG_ALLOC_ORDER): Proper define the register
order.
(ADJUST_REG_ALLOC_ORDER): Define.
(HONOR_REG_ALLOC_ORDER): Likewise.
---
 gcc/config/arc/arc-protos.h |  1 +
 gcc/config/arc/arc.c| 67 +++--
 gcc/config/arc/arc.h| 33 ++
 3 files changed, 47 insertions(+), 54 deletions(-)

diff --git a/gcc/config/arc/arc-protos.h b/gcc/config/arc/arc-protos.h
index 1362b41f101..8f0f197f14a 100644
--- a/gcc/config/arc/arc-protos.h
+++ b/gcc/config/arc/arc-protos.h
@@ -47,6 +47,7 @@ extern unsigned int arc_compute_function_type (struct 
function *);
 extern bool arc_is_uncached_mem_p (rtx);
 extern bool gen_operands_ldd_std (rtx *operands, bool load, bool commute);
 extern bool arc_check_multi (rtx, bool);
+extern void arc_adjust_reg_alloc_order (void);
 #endif /* RTX_CODE */
 
 extern unsigned int arc_compute_frame_size (int);
diff --git a/gcc/config/arc/arc.c b/gcc/config/arc/arc.c
index 9938a774d91..0b18e677735 100644
--- a/gcc/config/arc/arc.c
+++ b/gcc/config/arc/arc.c
@@ -1807,54 +1807,6 @@ arc_conditional_register_usage (void)
warning (0, "multiply option implies r%d is fixed", regno);
   fixed_regs [regno] = call_used_regs[regno] = 1;
 }
-  if (TARGET_Q_CLASS)
-{
-  if (optimize_size)
-   {
- reg_alloc_order[0] = 0;
- reg_alloc_order[1] = 1;
- reg_alloc_order[2] = 2;
- reg_alloc_order[3] = 3;
- reg_alloc_order[4] = 12;
- reg_alloc_order[5] = 13;
- reg_alloc_order[6] = 14;
- reg_alloc_order[7] = 15;
- reg_alloc_order[8] = 4;
- reg_alloc_order[9] = 5;
- reg_alloc_order[10] = 6;
- reg_alloc_order[11] = 7;
- reg_alloc_order[12] = 8;
- reg_alloc_order[13] = 9;
- reg_alloc_order[14] = 10;
- reg_alloc_order[15] = 11;
-   }
-  else
-   {
- reg_alloc_order[2] = 12;
- reg_alloc_order[3] = 13;
- reg_alloc_order[4] = 14;
- reg_alloc_order[5] = 15;
- reg_alloc_order[6] = 1;
- reg_alloc_order[7] = 0;
- reg_alloc_order[8] = 4;
- reg_alloc_order[9] = 5;
- reg_alloc_order[10] = 6;
- reg_alloc_order[11] = 7;
- reg_alloc_order[12] = 8;
- reg_alloc_order[13] = 9;
- reg_alloc_order[14] = 10;
- reg_alloc_order[15] = 11;
-   }
-}
-  if (TARGET_SIMD_SET)
-{
-  int i;
-  for (i = ARC_FIRST_SIMD_VR_REG; i <= ARC_LAST_SIMD_VR_REG; i++)
-   reg_alloc_order [i] = i;
-  for (i = ARC_FIRST_SIMD_DMA_CONFIG_REG;
-  i <= ARC_LAST_SIMD_DMA_CONFIG_REG; i++)
-   reg_alloc_order [i] = i;
-}
 
   /* Reduced configuration: don't use r4-r9, r16-r25.  */
   if (TARGET_RF16)
@@ -11454,6 +11406,25 @@ gen_operands_ldd_std (rtx *operands, bool load, bool 
commute)
   return false;
 }
 
+/* This order of allocation is used when we compile for size.  It
+   allocates first the registers which are most probably to end up in
+   a short instruction.  */
+static const int size_alloc_order[] =
+{
+ 0, 1, 2, 3, 12, 13, 14, 15,
+ 4, 5, 6, 7, 8, 9, 10, 11
+};
+
+/* Adjust register allocation order when compiling for size.  */
+void
+arc_adjust_reg_alloc_order (void)
+{
+  const int arc_default_alloc_order[] = REG_ALLOC_ORDER;
+  memcpy (reg_alloc_order, arc_default_alloc_order, sizeof (reg_alloc_order));
+  if (optimize_size)
+memcpy (reg_alloc_order, size_alloc_order, sizeof (size_alloc_order));
+}
+
 #undef TARGET_USE_ANCHORS_FOR_SYMBOL_P
 #define TARGET_USE_ANCHORS_FOR_SYMBOL_P arc_use_anchors_for_symbol_p
 
diff --git a/gcc/config/arc/arc.h b/gcc/config/arc/arc.h
index fbe71278346..90420a9d474 100644
--- a/gcc/config/arc/arc.h
+++ b/gcc/config/arc/arc.h
@@ -361,7 +361,6 @@ if (GET_MODE_CLASS (MODE) == MODE_INT   \
 
By default, the extension registers are not available.  */
 /* Present implementations only have VR0-VR23 only.  */
-/* ??? FIXME: r27 and r31 should not be fixed registers.  */
 #define FIXED_REGISTERS \
 { 0, 0, 0, 0, 0, 0, 0, 0,  \
   0, 0, 0, 0, 0, 0, 0, 0,  \
@@ -422,12 +421,34 @@ if (GET_MODE_CLASS (MODE) == MODE_INT \
 /* If defined, an initializer for a vector of integers, containing the
numbers of hard registers in the order in which GCC should
prefer to use them (from most preferred to least).  */
-#define REG_ALLOC_ORDER \
-{ 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 0, 1,  

[wwwdocs] Document recent libstdc++ changes

2019-03-06 Thread Jonathan Wakely

Committed to CVS.


Index: htdocs/gcc-9/changes.html
===
RCS file: /cvs/gcc/wwwdocs/htdocs/gcc-9/changes.html,v
retrieving revision 1.49
diff -u -r1.49 changes.html
--- htdocs/gcc-9/changes.html	28 Feb 2019 21:49:05 -	1.49
+++ htdocs/gcc-9/changes.html	6 Mar 2019 10:20:44 -
@@ -213,15 +213,35 @@
 
 Runtime Library (libstdc++)
 
+  Improved experimental support for C++17,
+  including .
+  
   Improved experimental support for C++2a,
-  including type traits std::remove_cvref,
-  std::is_nothrow_convertible, and
-  std::type_identity,
-  and headers  and .
+  including:
+  
+  Type traits std::remove_cvref,
+std::unwrap_reference, std::unwrap_decay_ref,
+std::is_nothrow_convertible, and
+std::type_identity;.
+  Headers  and
+.
+  Uniform container erasure (std::erase_if).
+  contains member of maps and sets.
+  String prefix and suffix checking (starts_with,
+ends_with).
+  Functions std::midpoint and lerp for
+interpolation.
+  Uses-allocator construction utilities.
+  std::pmr::polymorphic_allocator.
+  Library support for char8_t type.
+  Destroying delete.
+  std::is_constant_evaluated() function.
+  
   
   Support for opening file streams with wide character paths on Windows
   Incomplete support for the C++17 Filesystem library and the Filesystem
   TS on Windows.
+  Incomplete, experimental support for the Networking TS.
 
 
 D


[PATCH] Cherry pick libsanitizer r355488 (PR sanitizer/88684).

2019-03-06 Thread Martin Liška
Hi.

The patch is a cherry pick from libsanitizer.

Patch can bootstrap on x86_64-linux-gnu and survives regression tests.
I'm going to install the patch.

Thanks,
Martin

libsanitizer/ChangeLog:

2019-03-06  Martin Liska  

PR sanitizer/88684
* sanitizer_common/sanitizer_platform.h (defined): Cherry pick.
(SANITIZER_NON_UNIQUE_TYPEINFO): Likewise.
* ubsan/ubsan_type_hash_itanium.cc (isDerivedFromAtOffset):
Likewise.
---
 libsanitizer/sanitizer_common/sanitizer_platform.h | 6 +++---
 libsanitizer/ubsan/ubsan_type_hash_itanium.cc  | 1 +
 2 files changed, 4 insertions(+), 3 deletions(-)


diff --git a/libsanitizer/sanitizer_common/sanitizer_platform.h b/libsanitizer/sanitizer_common/sanitizer_platform.h
index 352b374e177..192667989f4 100644
--- a/libsanitizer/sanitizer_common/sanitizer_platform.h
+++ b/libsanitizer/sanitizer_common/sanitizer_platform.h
@@ -290,10 +290,10 @@
 # define MSC_PREREQ(version) 0
 #endif
 
-#if defined(__arm64__) && SANITIZER_IOS
-# define SANITIZER_NON_UNIQUE_TYPEINFO 1
-#else
+#if SANITIZER_MAC && !(defined(__arm64__) && SANITIZER_IOS)
 # define SANITIZER_NON_UNIQUE_TYPEINFO 0
+#else
+# define SANITIZER_NON_UNIQUE_TYPEINFO 1
 #endif
 
 // On linux, some architectures had an ABI transition from 64-bit long double
diff --git a/libsanitizer/ubsan/ubsan_type_hash_itanium.cc b/libsanitizer/ubsan/ubsan_type_hash_itanium.cc
index 9df316e14be..bff78887396 100644
--- a/libsanitizer/ubsan/ubsan_type_hash_itanium.cc
+++ b/libsanitizer/ubsan/ubsan_type_hash_itanium.cc
@@ -117,6 +117,7 @@ static bool isDerivedFromAtOffset(const abi::__class_type_info *Derived,
   sptr Offset) {
   if (Derived->__type_name == Base->__type_name ||
   (SANITIZER_NON_UNIQUE_TYPEINFO &&
+   Derived->__type_name[0] != '*' &&
!internal_strcmp(Derived->__type_name, Base->__type_name)))
 return Offset == 0;
 



RE: [PATCH] [ARC] Fix logic set UNALIGNED_ACCESS

2019-03-06 Thread Claudiu Zissulescu
Pushed. Thank you Andrew for your review.

//Claudiu

From: Andrew Burgess [andrew.burg...@embecosm.com]
Sent: Friday, March 01, 2019 11:07 AM
To: Vineet Gupta
Cc: gcc-patches@gcc.gnu.org; Claudiu Zissulescu; 
linux-snps-...@lists.infradead.org; Claudiu Zissulescu
Subject: Re: [PATCH] [ARC] Fix logic set UNALIGNED_ACCESS

* Vineet Gupta  [2019-02-28 10:04:24 -0800]:

> From: Claudiu Zissulescu 
>
> gcc/
> -xx-xx  Claudiu Zissulescu  
>
>   * config/arc/arc-c.def (__ARC_UNALIGNED__): Set it on
>   unaligned_access variable.
>   * config/arc/arc.c (arc_override_options): Set unaligned access
>   default on for HS CPUs.
>   * config/arc/arc.h (STRICT_ALIGNMENT): Fix logic.

This looks good.

Thanks,
Andrew


>
> Signed-off-by: Vineet Gupta 
> ---
>  gcc/config/arc/arc-c.def | 2 +-
>  gcc/config/arc/arc.c | 4 
>  gcc/config/arc/arc.h | 2 +-
>  3 files changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/gcc/config/arc/arc-c.def b/gcc/config/arc/arc-c.def
> index 9c0ba2c9c294..9472b48aa7bc 100644
> --- a/gcc/config/arc/arc-c.def
> +++ b/gcc/config/arc/arc-c.def
> @@ -29,7 +29,7 @@ ARC_C_DEF ("__ARC_MUL64__", TARGET_MUL64_SET)
>  ARC_C_DEF ("__ARC_MUL32BY16__", TARGET_MULMAC_32BY16_SET)
>  ARC_C_DEF ("__ARC_SIMD__",   TARGET_SIMD_SET)
>  ARC_C_DEF ("__ARC_RF16__",   TARGET_RF16)
> -ARC_C_DEF ("__ARC_UNALIGNED__", !STRICT_ALIGNMENT)
> +ARC_C_DEF ("__ARC_UNALIGNED__", unaligned_access)
>
>  ARC_C_DEF ("__ARC_BARREL_SHIFTER__", TARGET_BARREL_SHIFTER)
>
> diff --git a/gcc/config/arc/arc.c b/gcc/config/arc/arc.c
> index de2c8d5df9cf..3b8c29981b9a 100644
> --- a/gcc/config/arc/arc.c
> +++ b/gcc/config/arc/arc.c
> @@ -1313,6 +1313,10 @@ arc_override_options (void)
>if (TARGET_LONG_CALLS_SET)
>  target_flags &= ~MASK_MILLICODE_THUNK_SET;
>
> +  /* Set unaligned to all HS cpus.  */
> +  if (!global_options_set.x_unaligned_access && TARGET_HS)
> +unaligned_access = 1;
> +
>/* These need to be done at start up.  It's convenient to do them here.  */
>arc_init ();
>  }
> diff --git a/gcc/config/arc/arc.h b/gcc/config/arc/arc.h
> index 12b4b62bba7b..894eb3946000 100644
> --- a/gcc/config/arc/arc.h
> +++ b/gcc/config/arc/arc.h
> @@ -285,7 +285,7 @@ if (GET_MODE_CLASS (MODE) == MODE_INT \
>  /* On the ARC the lower address bits are masked to 0 as necessary.  The chip
> won't croak when given an unaligned address, but the insn will still fail
> to produce the correct result.  */
> -#define STRICT_ALIGNMENT (!unaligned_access && !TARGET_HS)
> +#define STRICT_ALIGNMENT (!unaligned_access)
>
>  /* Layout of source language data types.  */
>
> --
> 2.7.4
>


Re: [PATCH, wwwdocs] Mention -march=armv8.5-a and other new command line options for AArch64 and Arm for GCC 9

2019-03-06 Thread Sudakshina Das
Pinging and adding Gerald to the CC list.

On 22/02/2019 10:45, Sudakshina Das wrote:
> Hi
> 
> This patch documents the addition of the new Armv8.5-A and corresponding 
> extensions in the gcc-9/changes.html.
> As per https://gcc.gnu.org/about.html, I have used W3 Validator.
> Is this ok for cvs?
> 
> Thanks
> Sudi



[PATCH] Constexpr in std::pointer_traits (P1006R1)

2019-03-06 Thread Jonathan Wakely

* include/bits/ptr_traits.h [C++20] (pointer_traits::pointer_to):
Add constexpr.
* testsuite/20_util/pointer_traits/pointer_to_constexpr.cc: New test.

Tested powerpc64le-linux, committed to trunk.


commit 8125740feaa7aa66589d0922992b9bf1065e1699
Author: Jonathan Wakely 
Date:   Wed Mar 6 10:45:02 2019 +

Constexpr in std::pointer_traits (P1006R1)

* include/bits/ptr_traits.h [C++20] 
(pointer_traits::pointer_to):
Add constexpr.
* testsuite/20_util/pointer_traits/pointer_to_constexpr.cc: New 
test.

diff --git a/libstdc++-v3/include/bits/ptr_traits.h 
b/libstdc++-v3/include/bits/ptr_traits.h
index 76355863852..c90a35080f1 100644
--- a/libstdc++-v3/include/bits/ptr_traits.h
+++ b/libstdc++-v3/include/bits/ptr_traits.h
@@ -137,7 +137,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
*  @param  __r  A reference to an object of type @c element_type
*  @return @c addressof(__r)
   */
-  static pointer
+  static _GLIBCXX20_CONSTEXPR pointer
   pointer_to(__make_not_void& __r) noexcept
   { return std::addressof(__r); }
 };
diff --git 
a/libstdc++-v3/testsuite/20_util/pointer_traits/pointer_to_constexpr.cc 
b/libstdc++-v3/testsuite/20_util/pointer_traits/pointer_to_constexpr.cc
new file mode 100644
index 000..ed4f2157adc
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/pointer_traits/pointer_to_constexpr.cc
@@ -0,0 +1,27 @@
+// 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 "-std=gnu++2a" }
+// { dg-do compile { target c++2a } }
+
+#include 
+
+int i = 0;
+static_assert( std::pointer_traits::pointer_to(i) == &i );
+
+struct X { } x;
+static_assert( std::pointer_traits::pointer_to(x) == &x );


[PATCH] Add C++20 Traits for [Un]bounded Arrays (P1357R1)

2019-03-06 Thread Jonathan Wakely

 * include/std/type_traits [C++20] (is_bounded_array)
 (is_unbounded_array, is_bounded_array_v, is_unbounded_array_v):
 Define.
 * testsuite/20_util/is_bounded_array/requirements/
 explicit_instantiation.cc: New test.
 * testsuite/20_util/is_bounded_array/requirements/typedefs.cc: New
 test.
 * testsuite/20_util/is_bounded_array/value.cc: New test.
 * testsuite/20_util/is_unbounded_array/requirements/
 explicit_instantiation.cc: New test.
 * testsuite/20_util/is_unbounded_array/requirements/typedefs.cc: New
 * test.
 * testsuite/20_util/is_unbounded_array/value.cc: New test.

Tested powerpc64le-linux, committed to trunk.


commit 091647557c4f6d6972c4098cd8dd8ca953d339d1
Author: Jonathan Wakely 
Date:   Wed Mar 6 11:59:02 2019 +

Add C++20 Traits for [Un]bounded Arrays (P1357R1)

 * include/std/type_traits [C++20] (is_bounded_array)
 (is_unbounded_array, is_bounded_array_v, is_unbounded_array_v):
 Define.
 * testsuite/20_util/is_bounded_array/requirements/
 explicit_instantiation.cc: New test.
 * testsuite/20_util/is_bounded_array/requirements/typedefs.cc: New
 test.
 * testsuite/20_util/is_bounded_array/value.cc: New test.
 * testsuite/20_util/is_unbounded_array/requirements/
 explicit_instantiation.cc: New test.
 * testsuite/20_util/is_unbounded_array/requirements/typedefs.cc: 
New
 * test.
 * testsuite/20_util/is_unbounded_array/value.cc: New test.

diff --git a/libstdc++-v3/include/std/type_traits 
b/libstdc++-v3/include/std/type_traits
index 977ca0e1350..a1161d50399 100644
--- a/libstdc++-v3/include/std/type_traits
+++ b/libstdc++-v3/include/std/type_traits
@@ -3074,6 +3074,26 @@ template 
   template
 using unwrap_ref_decay_t = typename unwrap_ref_decay<_Tp>::type;
 
+  /// True for a type that is an array of known bound.
+  template
+struct is_bounded_array
+: public __is_array_known_bounds<_Tp>
+{ };
+
+  /// True for a type that is an array of unknown bound.
+  template
+struct is_unbounded_array
+: public __is_array_unknown_bounds<_Tp>
+{ };
+
+  template
+inline constexpr bool is_bounded_array_v
+  = is_bounded_array<_Tp>::value;
+
+  template
+inline constexpr bool is_unbounded_array_v
+  = is_unbounded_array<_Tp>::value;
+
 #ifdef _GLIBCXX_HAVE_BUILTIN_IS_CONSTANT_EVALUATED
 
 #define __cpp_lib_is_constant_evaluated 201811L
diff --git 
a/libstdc++-v3/testsuite/20_util/is_bounded_array/requirements/explicit_instantiation.cc
 
b/libstdc++-v3/testsuite/20_util/is_bounded_array/requirements/explicit_instantiation.cc
new file mode 100644
index 000..d7417a9f26c
--- /dev/null
+++ 
b/libstdc++-v3/testsuite/20_util/is_bounded_array/requirements/explicit_instantiation.cc
@@ -0,0 +1,29 @@
+// { dg-options "-std=gnu++2a" }
+// { dg-do compile { target c++2a } }
+
+// 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
+// .
+
+// NB: This file is for testing type_traits with NO OTHER INCLUDES.
+
+#include 
+
+namespace std
+{
+  typedef short test_type;
+  template struct is_bounded_array;
+}
diff --git 
a/libstdc++-v3/testsuite/20_util/is_bounded_array/requirements/typedefs.cc 
b/libstdc++-v3/testsuite/20_util/is_bounded_array/requirements/typedefs.cc
new file mode 100644
index 000..abe430a6554
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/is_bounded_array/requirements/typedefs.cc
@@ -0,0 +1,33 @@
+// { dg-options "-std=gnu++2a" }
+// { dg-do compile { target c++2a } }
+
+// 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 

[PATCH] Add L suffix to __cpp_lib_char8_t value

2019-03-06 Thread Jonathan Wakely

* include/bits/c++config.h (_cpp_lib_char8_t): Add L suffix to
constant.
* testsuite/experimental/feat-char8_t.cc: Likewise.

Tested powerpc64le-linux, committed to trunk.

commit 959e5191a2e9628bedb38439842331658dbc4a58
Author: Jonathan Wakely 
Date:   Wed Mar 6 12:02:47 2019 +

Add L suffix to __cpp_lib_char8_t value

* include/bits/c++config.h (_cpp_lib_char8_t): Add L suffix to
constant.
* testsuite/experimental/feat-char8_t.cc: Likewise.

diff --git a/libstdc++-v3/include/bits/c++config 
b/libstdc++-v3/include/bits/c++config
index 9993f4b1998..c785bf84c1b 100644
--- a/libstdc++-v3/include/bits/c++config
+++ b/libstdc++-v3/include/bits/c++config
@@ -633,7 +633,7 @@ namespace std
 # endif
 #endif
 #ifdef _GLIBCXX_USE_CHAR8_T
-# define __cpp_lib_char8_t 201811
+# define __cpp_lib_char8_t 201811L
 #endif
 
 /* Define if __float128 is supported on this host. */
diff --git a/libstdc++-v3/testsuite/experimental/feat-char8_t.cc 
b/libstdc++-v3/testsuite/experimental/feat-char8_t.cc
index 4384f98da34..e843604266c 100644
--- a/libstdc++-v3/testsuite/experimental/feat-char8_t.cc
+++ b/libstdc++-v3/testsuite/experimental/feat-char8_t.cc
@@ -12,6 +12,6 @@
 
 #ifndef  __cpp_lib_char8_t
 #  error "__cpp_lib_char8_t"
-#elif  __cpp_lib_char8_t != 201811
-#  error "__cpp_lib_char8_t != 201811"
+#elif  __cpp_lib_char8_t != 201811L
+#  error "__cpp_lib_char8_t != 201811L"
 #endif


[PR 88235] Relax cgraph_node::clone_of_p to also look through former clones

2019-03-06 Thread Martin Jambor
Hi,

PR 88235 is a cgraph verification failure which is a false positive.
The problem is that after thunk expansion which is done as a part of
thunk inlining the verifier is no longer able to detect that a call
graph edge callee points to a clone of the destination of the now
expanded thunk in the decl of the corresponding gimple statement.

Fixed in a way agreed on with Honza in bugzilla, we simply add a way to
detect former (expanded) thunks, I understand this is already done
by devirtualization in a similar way too, and use that information in
the verifier.

Passed bootstrap and testing on x86_64-linux, OK for trunk?  OK for
gcc-7-branch and gcc-8-branch too if a backport is straightforward (I
have not tried yet) and it passes testing there too?

Thanks,

Martin


2019-03-05  Martin Jambor  

PR ipa/88235
* cgraph.h (cgraph_node): New inline method former_thunk_p.
* cgraph.c (cgraph_node::dump): Dump a note if node is a former thunk.
(clone_of_p): Treat expanded thunks like thunks, be optimistic if they
have multiple callees.  At the end check if declarations match as
opposed to cgraph_nodes.

testsuite/
* g++.dg/ipa/pr88235.C: New test.
---
 gcc/cgraph.c   | 15 ++--
 gcc/cgraph.h   | 14 
 gcc/testsuite/g++.dg/ipa/pr88235.C | 55 ++
 3 files changed, 81 insertions(+), 3 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/ipa/pr88235.C

diff --git a/gcc/cgraph.c b/gcc/cgraph.c
index de82316d4b1..e5f5a98a0c0 100644
--- a/gcc/cgraph.c
+++ b/gcc/cgraph.c
@@ -2109,6 +2109,8 @@ cgraph_node::dump (FILE *f)
   (int)thunk.indirect_offset,
   (int)thunk.virtual_offset_p);
 }
+  else if (former_thunk_p ())
+fprintf (f, "  Former thunk");
   if (alias && thunk.alias
   && DECL_P (thunk.alias))
 {
@@ -2963,7 +2965,9 @@ cgraph_node::collect_callers (void)
   return redirect_callers;
 }
 
-/* Return TRUE if NODE2 a clone of NODE or is equivalent to it.  */
+
+/* Return TRUE if NODE2 a clone of NODE or is equivalent to it.  Return
+   optimistically true if this cannot be determined.  */
 
 static bool
 clone_of_p (cgraph_node *node, cgraph_node *node2)
@@ -2975,12 +2979,17 @@ clone_of_p (cgraph_node *node, cgraph_node *node2)
   /* There are no virtual clones of thunks so check former_clone_of or if we
  might have skipped thunks because this adjustments are no longer
  necessary.  */
-  while (node->thunk.thunk_p)
+  while (node->thunk.thunk_p || node->former_thunk_p ())
 {
   if (node2->former_clone_of == node->decl)
return true;
   if (!node->thunk.this_adjusting)
return false;
+  /* In case of instrumented expanded thunks, which can have multiple calls
+in them, we do not know how to continue and just have to be
+optimistic.  */
+  if (node->callees->next_callee)
+   return true;
   node = node->callees->callee->ultimate_alias_target ();
   skipped_thunk = true;
 }
@@ -2996,7 +3005,7 @@ clone_of_p (cgraph_node *node, cgraph_node *node2)
return false;
 }
 
-  while (node != node2 && node2)
+  while (node2 && node->decl != node2->decl)
 node2 = node2->clone_of;
   return node2 != NULL;
 }
diff --git a/gcc/cgraph.h b/gcc/cgraph.h
index c294602d762..9a19d83fffb 100644
--- a/gcc/cgraph.h
+++ b/gcc/cgraph.h
@@ -1283,6 +1283,9 @@ public:
  Note that at WPA stage, the function body may not be present in memory.  
*/
   inline bool has_gimple_body_p (void);
 
+  /* Return true if this node represents a former, i.e. an expanded, thunk.  */
+  inline bool former_thunk_p (void);
+
   /* Return true if function should be optimized for size.  */
   bool optimize_for_size_p (void);
 
@@ -2921,6 +2924,17 @@ cgraph_node::has_gimple_body_p (void)
   return definition && !thunk.thunk_p && !alias;
 }
 
+/* Return true if this node represents a former, i.e. an expanded, thunk.  */
+
+inline bool
+cgraph_node::former_thunk_p (void)
+{
+  return (!thunk.thunk_p
+ && (thunk.fixed_offset
+ || thunk.virtual_offset_p
+ || thunk.indirect_offset));
+}
+
 /* Walk all functions with body defined.  */
 #define FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) \
for ((node) = symtab->first_function_with_gimple_body (); (node); \
diff --git a/gcc/testsuite/g++.dg/ipa/pr88235.C 
b/gcc/testsuite/g++.dg/ipa/pr88235.C
new file mode 100644
index 000..29f3252b828
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ipa/pr88235.C
@@ -0,0 +1,55 @@
+// { dg-do compile }
+// { dg-options "-O1 -fdevirtualize -finline-small-functions -fipa-cp 
-fipa-cp-clone --param ipa-cp-eval-threshold=125 --param 
max-inline-insns-single=4" }
+
+extern "C" int printf (const char *, ...);
+enum E { vf_request, vf_event } want;
+
+int errs = 0;
+
+class ivResource {
+public:
+  virtual ~ivResource () { }
+};
+
+class ivHandler   : public ivResource   {
+public:
+  virtual void

Re: [PATCH] Add C++20 Traits for [Un]bounded Arrays (P1357R1)

2019-03-06 Thread Jonathan Wakely

On 06/03/19 12:13 +, Jonathan Wakely wrote:

 * include/std/type_traits [C++20] (is_bounded_array)
 (is_unbounded_array, is_bounded_array_v, is_unbounded_array_v):
 Define.
 * testsuite/20_util/is_bounded_array/requirements/
 explicit_instantiation.cc: New test.
 * testsuite/20_util/is_bounded_array/requirements/typedefs.cc: New
 test.
 * testsuite/20_util/is_bounded_array/value.cc: New test.
 * testsuite/20_util/is_unbounded_array/requirements/
 explicit_instantiation.cc: New test.
 * testsuite/20_util/is_unbounded_array/requirements/typedefs.cc: New
 * test.
 * testsuite/20_util/is_unbounded_array/value.cc: New test.


I forgot the feature test macro. I'll commit this after testing ...

commit 1d2785fd303eaf89daea9aff31d6164e75ff7e22
Author: Jonathan Wakely 
Date:   Wed Mar 6 12:28:00 2019 +

Add feature test macro for bounded array traits

* include/std/type_traits (__cpp_lib_bounded_array_traits): Define.
* include/std/version (__cpp_lib_bounded_array_traits): Likewise.
* testsuite/20_util/is_bounded_array/value.cc: Check for macro.
* testsuite/20_util/is_unbounded_array/value.cc: Likewise.

diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits
index a1161d50399..c3cb67a457d 100644
--- a/libstdc++-v3/include/std/type_traits
+++ b/libstdc++-v3/include/std/type_traits
@@ -3074,6 +3074,8 @@ template 
   template
 using unwrap_ref_decay_t = typename unwrap_ref_decay<_Tp>::type;
 
+#define __cpp_lib_bounded_array_traits 201902L
+
   /// True for a type that is an array of known bound.
   template
 struct is_bounded_array
diff --git a/libstdc++-v3/include/std/version b/libstdc++-v3/include/std/version
index 785e8966dbf..668b477e24d 100644
--- a/libstdc++-v3/include/std/version
+++ b/libstdc++-v3/include/std/version
@@ -148,6 +148,7 @@
 
 #if __cplusplus > 201703L
 // c++2a
+#define __cpp_lib_bounded_array_traits 201902L
 #if __cpp_impl_destroying_delete
 # define __cpp_lib_destroying_delete 201806L
 #endif
diff --git a/libstdc++-v3/testsuite/20_util/is_bounded_array/value.cc b/libstdc++-v3/testsuite/20_util/is_bounded_array/value.cc
index 9f37d36e532..47ecae8ca05 100644
--- a/libstdc++-v3/testsuite/20_util/is_bounded_array/value.cc
+++ b/libstdc++-v3/testsuite/20_util/is_bounded_array/value.cc
@@ -21,6 +21,12 @@
 #include 
 #include 
 
+#ifndef __cpp_lib_bounded_array_traits
+# error "Feature test macro for is_bounded_array is missing"
+#elif __cpp_lib_bounded_array_traits < 201902L
+# error "Feature test macro for is_bounded_array has wrong value"
+#endif
+
 void test01()
 {
   using std::is_bounded_array;
diff --git a/libstdc++-v3/testsuite/20_util/is_unbounded_array/value.cc b/libstdc++-v3/testsuite/20_util/is_unbounded_array/value.cc
index 28a77b21da2..19fb0524cd8 100644
--- a/libstdc++-v3/testsuite/20_util/is_unbounded_array/value.cc
+++ b/libstdc++-v3/testsuite/20_util/is_unbounded_array/value.cc
@@ -21,6 +21,12 @@
 #include 
 #include 
 
+#ifndef __cpp_lib_bounded_array_traits
+# error "Feature test macro for is_unbounded_array is missing"
+#elif __cpp_lib_bounded_array_traits < 201902L
+# error "Feature test macro for is_unbounded_array has wrong value"
+#endif
+
 void test01()
 {
   using std::is_unbounded_array;


Re: V3 [PATCH] Optimize vector constructor

2019-03-06 Thread Richard Biener
On Wed, Mar 6, 2019 at 8:46 AM H.J. Lu  wrote:
>
> On Tue, Mar 5, 2019 at 1:46 AM H.J. Lu  wrote:
> >
> > On Mon, Mar 04, 2019 at 12:55:04PM +0100, Richard Biener wrote:
> > > On Sun, Mar 3, 2019 at 10:13 PM H.J. Lu  wrote:
> > > >
> > > > On Sun, Mar 03, 2019 at 06:40:09AM -0800, Andrew Pinski wrote:
> > > > > )
> > > > > ,On Sun, Mar 3, 2019 at 6:32 AM H.J. Lu  wrote:
> > > > > >
> > > > > > For vector init constructor:
> > > > > >
> > > > > > ---
> > > > > > typedef float __v4sf __attribute__ ((__vector_size__ (16)));
> > > > > >
> > > > > > __v4sf
> > > > > > foo (__v4sf x, float f)
> > > > > > {
> > > > > >   __v4sf y = { f, x[1], x[2], x[3] };
> > > > > >   return y;
> > > > > > }
> > > > > > ---
> > > > > >
> > > > > > we can optimize vector init constructor with vector copy or permute
> > > > > > followed by a single scalar insert:
> >
> > > and you want to advance to the _1 = BIT_INSERT_EXPR here.  The easiest way
> > > is to emit a new stmt for _2 = copy ...; and do the set_rhs with the
> > > BIT_INSERT_EXPR.
> >
> > Thanks for BIT_INSERT_EXPR suggestion.  I am testing this patch.
> >
> >
> > H.J.
> > ---
> > We can optimize vector constructor with vector copy or permute followed
> > by a single scalar insert:
> >
> >   __v4sf y;
> >   __v4sf D.1930;
> >   float _1;
> >   float _2;
> >   float _3;
> >
> >:
> >   _1 = BIT_FIELD_REF ;
> >   _2 = BIT_FIELD_REF ;
> >   _3 = BIT_FIELD_REF ;
> >   y_6 = {f_5(D), _3, _2, _1};
> >   return y_6;
> >
> > with
> >
> >  __v4sf y;
> >   __v4sf D.1930;
> >   float _1;
> >   float _2;
> >   float _3;
> >   vector(4) float _8;
> >
> >:
> >   _1 = BIT_FIELD_REF ;
> >   _2 = BIT_FIELD_REF ;
> >   _3 = BIT_FIELD_REF ;
> >   _8 = x_9(D);
> >   y_6 = BIT_INSERT_EXPR ;
> >   return y_6;
> >
> > gcc/
> >
> > PR tree-optimization/88828
> > * tree-ssa-forwprop.c (simplify_vector_constructor): Optimize
> > vector init constructor with vector copy or permute followed
> > by a single scalar insert.
> >
> > gcc/testsuite/
> >
> > PR tree-optimization/88828
> > * gcc.target/i386/pr88828-1a.c: New test.
> > * gcc.target/i386/pr88828-2b.c: Likewise.
> > * gcc.target/i386/pr88828-2.c: Likewise.
> > * gcc.target/i386/pr88828-3a.c: Likewise.
> > * gcc.target/i386/pr88828-3b.c: Likewise.
> > * gcc.target/i386/pr88828-3c.c: Likewise.
> > * gcc.target/i386/pr88828-3d.c: Likewise.
> > * gcc.target/i386/pr88828-4a.c: Likewise.
> > * gcc.target/i386/pr88828-4b.c: Likewise.
> > * gcc.target/i386/pr88828-5a.c: Likewise.
> > * gcc.target/i386/pr88828-5b.c: Likewise.
> > * gcc.target/i386/pr88828-6a.c: Likewise.
> > * gcc.target/i386/pr88828-6b.c: Likewise.
>
> Here is the updated patch with run-time tests.

-  if (TREE_CODE (elt->value) != SSA_NAME)
+  if (TREE_CODE (ce->value) != SSA_NAME)
return false;

hmm, so it doesn't allow { 0, v[1], v[2], v[3] }?  I think the single
scalar value can be a constant as well.

   if (!def_stmt)
-   return false;
+   {
+ if (gimple_nop_p (SSA_NAME_DEF_STMT (ce->value)))

if (SSA_NAME_IS_DEFAULT_DEF (ce->value))

+   {

also you seem to disallow

  { i + 1, v[1], v[2], v[3] }

because get_prop_source_stmt will return the definition computing
i + 1 in this case and your code will be skipped?

I think you can simplify the code by treating scalar_element != NULL
as nscalars == 1 and eliding nscalars.

-  if (conv_code == ERROR_MARK)
+  if (conv_code == ERROR_MARK && !insert)
gimple_assign_set_rhs_with_ops (gsi, VEC_PERM_EXPR, orig[0],
orig[1], op2);
   else
@@ -2148,10 +2198,25 @@ simplify_vector_constructor (gimple_stmt_iterator *gsi)
   VEC_PERM_EXPR, orig[0], orig[1], op2);
  orig[0] = gimple_assign_lhs (perm);
  gsi_insert_before (gsi, perm, GSI_SAME_STMT);
- gimple_assign_set_rhs_with_ops (gsi, conv_code, orig[0],
+ gimple_assign_set_rhs_with_ops (gsi,
+ (conv_code != ERROR_MARK
+  ? conv_code
+  : NOP_EXPR),
+ orig[0],
  NULL_TREE, NULL_TREE);

I believe you should elide the last stmt for conv_code == ERROR_MARK,
that is, why did you need to add the && !insert check in the guarding condition
(this path should already do the correct thing?).  Note that in all
cases it looks
that with conv_code != ERROR_MARK you may end up doing a float->int
or int->float conversion on a value it wasn't done on before which might
raise exceptions?  That is, do we need to make sure we permute a
value we already do convert into the place we're going to insert to?

+  if (insert)
+{
+  /* Generate a single scalar insert.  */
+  tree var = make_ssa_nam

Re: libgo patch committed: Update to final Go 1.12 release

2019-03-06 Thread Uros Bizjak
On Tue, Mar 5, 2019 at 9:50 PM Ian Lance Taylor  wrote:
>
> On Tue, Mar 5, 2019 at 1:02 AM Uros Bizjak  wrote:
> >
> > > I've committed this patch to update to the final Go 1.12 release.
> > > Bootstrapped and ran Go testsuite on x86_64-pc-linux-gnu.  Committed
> > > to mainline.
> >
> > This patch introduced following failure in CentOS 5.11:
> >
> > syscall_linux_test.go:381:11: error: reference to undefined field or
> > method 'Flags'
> >   381 |  return st.Flags&syscall.MS_NOSUID != 0
> >   |   ^
> > FAIL: syscall
>
> Thanks.  Should be fixed by this patch, tested on x86_64-pc-linux-gnu,
> committed to mainline.

Attached patchlet is also needed to create correct sysinfo.go.

Tested on CentOS 5.11.

Uros.
diff --git a/libgo/mksysinfo.sh b/libgo/mksysinfo.sh
index e0ae30f..56a6546 100755
--- a/libgo/mksysinfo.sh
+++ b/libgo/mksysinfo.sh
@@ -1119,7 +1119,7 @@ if ! echo "$statfs" | grep f_flags; then
   statfs=`echo "$statfs" | sed -e 's/f_spare \[4+1\]\([^ ;]*\)/f_flags \1; 
f_spare [3+1]\1/'`
 fi
 if test "$statfs" != ""; then
-  grep '^type _statfs64 ' gen-sysinfo.go
+  echo $statfs
 else
   grep '^type _statfs ' gen-sysinfo.go
 fi | sed -e 's/type _statfs64/type Statfs_t/' \


[PATCH, libobjc]: Avoid "DFmode" redefinition warning

2019-03-06 Thread Uros Bizjak
The attached patch removes

/space/homedirs/uros/gcc-svn/trunk/libobjc/encoding.c:84: warning:
"DFmode" redefined
   84 | #define DFmode  _C_DBL
  |
In file included from ../.././gcc/tm.h:36,
 from /space/homedirs/uros/gcc-svn/trunk/libobjc/encoding.c:37:
../.././gcc/insn-modes.h:210: note: this is the location of the
previous definition
  210 | #define DFmode (scalar_float_mode
((scalar_float_mode::from_int) E_DFmode))
  |

warning.

2019-03-06  Uroš Bizjak  

* encoding.c (DFmode): #undef before #define.

Bootstrapped on x86_64-linux-gnu {,-m32}.

OK for mainline?

Uros.
diff --git a/libobjc/encoding.c b/libobjc/encoding.c
index adac546..ef34fc8 100644
--- a/libobjc/encoding.c
+++ b/libobjc/encoding.c
@@ -81,6 +81,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If 
not, see
 #define DECL_MODE(TYPE) *(TYPE)
 #define TYPE_MODE(TYPE) *(TYPE)
 
+#undef  DFmode
 #define DFmode  _C_DBL
 
 #define strip_array_types(TYPE)  ({const char *_field = (TYPE); \


Re: [PATCH, libobjc]: Avoid "DFmode" redefinition warning

2019-03-06 Thread Jakub Jelinek
On Wed, Mar 06, 2019 at 02:45:23PM +0100, Uros Bizjak wrote:
> The attached patch removes
> 
> /space/homedirs/uros/gcc-svn/trunk/libobjc/encoding.c:84: warning:
> "DFmode" redefined
>84 | #define DFmode  _C_DBL
>   |
> In file included from ../.././gcc/tm.h:36,
>  from 
> /space/homedirs/uros/gcc-svn/trunk/libobjc/encoding.c:37:
> ../.././gcc/insn-modes.h:210: note: this is the location of the
> previous definition
>   210 | #define DFmode (scalar_float_mode
> ((scalar_float_mode::from_int) E_DFmode))
>   |
> 
> warning.
> 
> 2019-03-06  Uroš Bizjak  
> 
> * encoding.c (DFmode): #undef before #define.
> 
> Bootstrapped on x86_64-linux-gnu {,-m32}.
> 
> OK for mainline?

Ok, thanks.

Jakub


Re: libgo patch committed: Update to final Go 1.12 release

2019-03-06 Thread Ian Lance Taylor
On Wed, Mar 6, 2019 at 5:39 AM Uros Bizjak  wrote:
>
> On Tue, Mar 5, 2019 at 9:50 PM Ian Lance Taylor  wrote:
> >
> > On Tue, Mar 5, 2019 at 1:02 AM Uros Bizjak  wrote:
> > >
> > > > I've committed this patch to update to the final Go 1.12 release.
> > > > Bootstrapped and ran Go testsuite on x86_64-pc-linux-gnu.  Committed
> > > > to mainline.
> > >
> > > This patch introduced following failure in CentOS 5.11:
> > >
> > > syscall_linux_test.go:381:11: error: reference to undefined field or
> > > method 'Flags'
> > >   381 |  return st.Flags&syscall.MS_NOSUID != 0
> > >   |   ^
> > > FAIL: syscall
> >
> > Thanks.  Should be fixed by this patch, tested on x86_64-pc-linux-gnu,
> > committed to mainline.
>
> Attached patchlet is also needed to create correct sysinfo.go.
>
> Tested on CentOS 5.11.

Bother, I don't know what I was thinking.  I think this patch is a bit
better.  Could you test whether it works for you?  Thanks.

Ian
diff --git a/libgo/mksysinfo.sh b/libgo/mksysinfo.sh
index e0ae30f6..418ba2cf 100755
--- a/libgo/mksysinfo.sh
+++ b/libgo/mksysinfo.sh
@@ -1115,14 +1115,13 @@ grep '^const _FALLOC_' gen-sysinfo.go |
 # Prefer largefile variant if available.
 # CentOS 5 does not have f_flags, so pull from f_spare.
 statfs=`grep '^type _statfs64 ' gen-sysinfo.go || true`
+if test "$statfs" == ""; then
+  statfs=`grep '^type _statfs ' gen-sysinfo.go || true`
+fi
 if ! echo "$statfs" | grep f_flags; then
   statfs=`echo "$statfs" | sed -e 's/f_spare \[4+1\]\([^ ;]*\)/f_flags \1; 
f_spare [3+1]\1/'`
 fi
-if test "$statfs" != ""; then
-  grep '^type _statfs64 ' gen-sysinfo.go
-else
-  grep '^type _statfs ' gen-sysinfo.go
-fi | sed -e 's/type _statfs64/type Statfs_t/' \
+echo "$statfs" | sed -e 's/type _statfs64/type Statfs_t/' \
 -e 's/type _statfs/type Statfs_t/' \
 -e 's/f_type/Type/' \
 -e 's/f_bsize/Bsize/' \


Re: libgo patch committed: Update to final Go 1.12 release

2019-03-06 Thread Uros Bizjak
On Wed, Mar 6, 2019 at 2:49 PM Ian Lance Taylor  wrote:
>
> On Wed, Mar 6, 2019 at 5:39 AM Uros Bizjak  wrote:
> >
> > On Tue, Mar 5, 2019 at 9:50 PM Ian Lance Taylor  wrote:
> > >
> > > On Tue, Mar 5, 2019 at 1:02 AM Uros Bizjak  wrote:
> > > >
> > > > > I've committed this patch to update to the final Go 1.12 release.
> > > > > Bootstrapped and ran Go testsuite on x86_64-pc-linux-gnu.  Committed
> > > > > to mainline.
> > > >
> > > > This patch introduced following failure in CentOS 5.11:
> > > >
> > > > syscall_linux_test.go:381:11: error: reference to undefined field or
> > > > method 'Flags'
> > > >   381 |  return st.Flags&syscall.MS_NOSUID != 0
> > > >   |   ^
> > > > FAIL: syscall
> > >
> > > Thanks.  Should be fixed by this patch, tested on x86_64-pc-linux-gnu,
> > > committed to mainline.
> >
> > Attached patchlet is also needed to create correct sysinfo.go.
> >
> > Tested on CentOS 5.11.
>
> Bother, I don't know what I was thinking.  I think this patch is a bit
> better.  Could you test whether it works for you?  Thanks.

Yes, this patch works for me on CentOS 5.11.

Thanks,
Uros.


Re: libgo patch committed: Update to final Go 1.12 release

2019-03-06 Thread Ian Lance Taylor
On Wed, Mar 6, 2019 at 6:08 AM Uros Bizjak  wrote:
>
> On Wed, Mar 6, 2019 at 2:49 PM Ian Lance Taylor  wrote:
> >
> > On Wed, Mar 6, 2019 at 5:39 AM Uros Bizjak  wrote:
> > >
> > > On Tue, Mar 5, 2019 at 9:50 PM Ian Lance Taylor  wrote:
> > > >
> > > > On Tue, Mar 5, 2019 at 1:02 AM Uros Bizjak  wrote:
> > > > >
> > > > > > I've committed this patch to update to the final Go 1.12 release.
> > > > > > Bootstrapped and ran Go testsuite on x86_64-pc-linux-gnu.  Committed
> > > > > > to mainline.
> > > > >
> > > > > This patch introduced following failure in CentOS 5.11:
> > > > >
> > > > > syscall_linux_test.go:381:11: error: reference to undefined field or
> > > > > method 'Flags'
> > > > >   381 |  return st.Flags&syscall.MS_NOSUID != 0
> > > > >   |   ^
> > > > > FAIL: syscall
> > > >
> > > > Thanks.  Should be fixed by this patch, tested on x86_64-pc-linux-gnu,
> > > > committed to mainline.
> > >
> > > Attached patchlet is also needed to create correct sysinfo.go.
> > >
> > > Tested on CentOS 5.11.
> >
> > Bother, I don't know what I was thinking.  I think this patch is a bit
> > better.  Could you test whether it works for you?  Thanks.
>
> Yes, this patch works for me on CentOS 5.11.

Thanks.  Committed to mainline.

Ian


Re: [PATCH, asmcons] Fix PR rtl-optimization/89313: ICE in process_alt_operands, at lra-constraints.c:2962

2019-03-06 Thread Segher Boessenkool
Hi Peter,

On Wed, Feb 20, 2019 at 09:19:58PM -0600, Peter Bergner wrote:
> PR89313 exposes a bug in the asmcons pass where it replaces input operands
> with matching constraints with their associated output operands, as well as
> all other uses of its pseudo registers.  This is normally fine.  However, if
> the matched output operand is marked as early clobber, then we cannot replace
> the uses of 'input' that do not have matching constraints, since they by
> definition conflict with the early clobber output operand and could be
> clobbered if assigned to the same register as the output operand.
> 
> The patch below fixes the bug by only doing the input pseudo replacement
> if the output operand is not early clobber or the input operand is known
> to be a matching constraint.
> 
> This passed bootstrap and regression testing with no regressions on
> both x86_64-linux and powerpc64le-linux.  Ok for mainline?

Looks fine to me, but I cannot approve it of course.  Some trivial
comments:

> +/* If CONSTRAINT is a matching constraint, then return its number.
> +   Otherwise, return -1.  */
> +
> +static int
> +matching_constraint_num (const char *constraint)
> +{
> +  int match;
> +
> +  if (*constraint == '%')
> +constraint++;
> +
> +  switch (*constraint)
> +{
> +case '0': case '1': case '2': case '3': case '4':
> +case '5': case '6': case '7': case '8': case '9':
> +  {
> + char *end;
> + match = strtoul (constraint, &end, 10);
> + if (end == constraint)
> +   match = -1;

This condition is always false, because we have at least one digit.

> + break;
> +  }
> +
> +default:
> +  match = -1;
> +  break;
> +}
> +  return match;
> +}

Which means you can write it as just

static int
matching_constraint_num (const char *constraint)
{
  if (*constraint == '%')
constraint++;

  if (IN_RANGE (*constraint, '0', '9'))
return strtoul (constraint, NULL, 10);

  return -1;
}


Segher


Re: [PATCH, asmcons] Fix PR rtl-optimization/89313: ICE in process_alt_operands, at lra-constraints.c:2962

2019-03-06 Thread Peter Bergner
On 3/6/19 8:47 AM, Segher Boessenkool wrote:
> Which means you can write it as just
> 
> static int
> matching_constraint_num (const char *constraint)
> {
>   if (*constraint == '%')
> constraint++;
> 
>   if (IN_RANGE (*constraint, '0', '9'))
> return strtoul (constraint, NULL, 10);
> 
>   return -1;
> }

Ok, changed.  Thanks!


Peter



Re: [C++ PATCH] Allow value initialization of classes with flexible array member (PR c++/87148)

2019-03-06 Thread Jason Merrill

On 3/5/19 5:23 PM, Jakub Jelinek wrote:

Hi!

In this PR, Jonathan argues that we should accept value initialization of
classes with flexible array member.

The following patch does that.  Bootstrapped/regtested on x86_64-linux
and i686-linux, ok for trunk?


OK.

Jason



Re: C++ PATCH for c++/87378 - bogus -Wredundant-move warning

2019-03-06 Thread Jason Merrill

On 3/5/19 4:53 PM, Marek Polacek wrote:

On Tue, Mar 05, 2019 at 03:50:30PM -0500, Jason Merrill wrote:

On 3/4/19 7:17 PM, Marek Polacek wrote:

This patch fixes a bogus -Wredundant-move warning.  In the test in the PR
the std::move call isn't redundant; the testcase won't actually compile
without that call, as per the resolution of bug 87150.

Before this patch, we'd issue the redundant-move warning anytime
treat_lvalue_as_rvalue_p is true for a std::move's argument.  But we also
need to make sure that convert_for_initialization works even without the
std::move call, if not, it's not redundant.


Indeed.


Trouble arises when the argument is const.  Then it might be the case that
the implicit rvalue fails because it uses a const copy constructor, or
that the type of the returned object and the type of the selected ctor's
parameter aren't the same.


So this is the case where std::move is redundant because doing overload
resolution on the lvalue would select the same constructor?  I'm not sure
that's worth warning about, especially in templates where we don't know
anything about the return type.


Yes, it's about:

struct T {
   T(const T&);
   T(T&&);
};

T
f(const T t)
{
   return t; // uses const T&
   return std::move (t); // also uses const T&
}

I'm fine with dropping the warning in this (IMO fairly obscure) case; I
certainly didn't have this in mind when adding the warning.

So the patch can be simplified to the following:

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


OK.


2019-03-05  Marek Polacek  

PR c++/87378 - bogus -Wredundant-move warning.
* typeck.c (maybe_warn_pessimizing_move): See if the maybe-rvalue
overload resolution would actually succeed.

* g++.dg/cpp0x/Wredundant-move1.C (fn4): Drop dg-warning.
* g++.dg/cpp0x/Wredundant-move7.C: New test.

diff --git gcc/cp/typeck.c gcc/cp/typeck.c
index 1bf9ad88141..43ff3d63abd 100644
--- gcc/cp/typeck.c
+++ gcc/cp/typeck.c
@@ -9429,10 +9429,24 @@ maybe_warn_pessimizing_move (tree retval, tree functype)
 do maybe-rvalue overload resolution even without std::move.  */
  else if (treat_lvalue_as_rvalue_p (arg, /*parm_ok*/true))
{
- auto_diagnostic_group d;
- if (warning_at (loc, OPT_Wredundant_move,
- "redundant move in return statement"))
-   inform (loc, "remove % call");
+ /* Make sure that the overload resolution would actually succeed
+if we removed the std::move call.  */
+ tree t = convert_for_initialization (NULL_TREE, functype,
+  move (arg),
+  (LOOKUP_NORMAL
+   | LOOKUP_ONLYCONVERTING
+   | LOOKUP_PREFER_RVALUE),
+  ICR_RETURN, NULL_TREE, 0,
+  tf_none);
+ /* If this worked, implicit rvalue would work, so the call to
+std::move is redundant.  */
+ if (t != error_mark_node)
+   {
+ auto_diagnostic_group d;
+ if (warning_at (loc, OPT_Wredundant_move,
+ "redundant move in return statement"))
+   inform (loc, "remove % call");
+   }
}
}
  }
diff --git gcc/testsuite/g++.dg/cpp0x/Wredundant-move1.C 
gcc/testsuite/g++.dg/cpp0x/Wredundant-move1.C
index 5d4a25dbc3b..e70f3cde625 100644
--- gcc/testsuite/g++.dg/cpp0x/Wredundant-move1.C
+++ gcc/testsuite/g++.dg/cpp0x/Wredundant-move1.C
@@ -59,7 +59,8 @@ T
  fn4 (const T t)
  {
// t is const: will decay into copy despite std::move, so it's redundant.
-  return std::move (t); // { dg-warning "redundant move in return statement" }
+  // We used to warn about this, but no longer since c++/87378.
+  return std::move (t);
  }
  
  int

diff --git gcc/testsuite/g++.dg/cpp0x/Wredundant-move7.C 
gcc/testsuite/g++.dg/cpp0x/Wredundant-move7.C
new file mode 100644
index 000..015d7c4f7a4
--- /dev/null
+++ gcc/testsuite/g++.dg/cpp0x/Wredundant-move7.C
@@ -0,0 +1,59 @@
+// PR c++/87378
+// { dg-do compile { target c++11 } }
+// { dg-options "-Wredundant-move" }
+
+// Define std::move.
+namespace std {
+  template
+struct remove_reference
+{ typedef _Tp   type; };
+
+  template
+struct remove_reference<_Tp&>
+{ typedef _Tp   type; };
+
+  template
+struct remove_reference<_Tp&&>
+{ typedef _Tp   type; };
+
+  template
+constexpr typename std::remove_reference<_Tp>::type&&
+move(_Tp&& __t) noexcept
+{ return static_cast::type&&>(__t); }
+}
+
+struct S1 { S1(S1 &&); };
+struct S2 : S1 {};
+
+S1
+f (S2 s)
+{
+  return std::move(s); // { dg-bogus "redundant move in return statement" }
+}
+
+struct R1 {
+  R1(R1 &&);
+  R1(const R1 &&);
+

Re: [PATCH, asmcons] Fix PR rtl-optimization/89313: ICE in process_alt_operands, at lra-constraints.c:2962

2019-03-06 Thread Peter Bergner
On 3/6/19 8:56 AM, Peter Bergner wrote:
> On 3/6/19 8:47 AM, Segher Boessenkool wrote:
>> Which means you can write it as just
>>
>> static int
>> matching_constraint_num (const char *constraint)
>> {
>>   if (*constraint == '%')
>> constraint++;
>>
>>   if (IN_RANGE (*constraint, '0', '9'))
>> return strtoul (constraint, NULL, 10);
>>
>>   return -1;
>> }
> 
> Ok, changed.  Thanks!

...and re-bootstrapping and regtesting were clean with that change.

Peter





Re: [PATCH] Fix up --enable-checking=fold (PR middle-end/89503)

2019-03-06 Thread Martin Sebor

On 3/1/19 2:11 AM, Jakub Jelinek wrote:

On Fri, Mar 01, 2019 at 09:49:03AM +0100, Richard Biener wrote:

On Fri, 1 Mar 2019, Jakub Jelinek wrote:

Some of the builtin folding sets TREE_NO_WARNING flags, which triggers as
--enable-checking=fold errors.  I think we should allow setting of
TREE_NO_WARNING flag when folding, so this patch arranges that.

Tested on:
../configure --enable-languages=c,c++,fortran --enable-checking=fold 
--disable-bootstrap
make -jN && make -jN -k check
No extra FAILs compared to normal regtest.  Ok for trunk?


Hmm, I guess it's OK though for EXPR_P I think we may want the
TREE_NO_WARNING setter to unshare the tree?  Because IIRC it is
exactly because of tree sharing that we do this kind of checking?


Maybe, I just wonder if it wouldn't be too expensive.
These TREE_NO_WARNING sets are typically on arguments of builtin functions
so we'd need to unshare the argument (shallow copy) as well as the whole
builtin.  Some spots (usually older) in builtins.c do create new trees,
but some TREE_NO_WARNING setting is hidden even in APIs like c_strlen
which actually doesn't return the argument.  Plus, many of those functions
that set it are used both during expansion (where supposedly we don't care
about modifying in place) and folding.  What a mess?

So, do you prefer to drop this patch, or just take the  || EXPR_P (expr)
part away from it and let Martin (who has added pretty much all of these
TREE_NO_WARNING) fix it later?


I read through this thread but I'm not sure I understand the problem
(or really the tree sharing business -- different GIMPLE statements
sharing the same tree node?)

Is the problem here that the checking computes a checksum of the bits
in a tree node before folding and compares it to a checksum after
folding and setting the NO_WARNING bit in between causes the checking
to fail?

If that's accurate, if this patch is not the right fix, what would be?

Martin


c_strlen is probably the oldest with this
issue and most likely very hard to change; the thing is, it is usually used
during expansion and we heavily rely in that case that it modifies it
in-place and thus doesn't warn multiple times.  Just use it also in
fold_builtin_strlen :(.


2019-03-01  Jakub Jelinek  

PR middle-end/89503
* fold-const.c (fold_checksum_tree): Ignore TREE_NO_WARNING bit
on DECL_P and EXPR_P.


Jakub





Re: [PATCH] Fix up --enable-checking=fold (PR middle-end/89503)

2019-03-06 Thread Jakub Jelinek
On Wed, Mar 06, 2019 at 10:15:33AM -0700, Martin Sebor wrote:
> I read through this thread but I'm not sure I understand the problem
> (or really the tree sharing business -- different GIMPLE statements
> sharing the same tree node?)
> 
> Is the problem here that the checking computes a checksum of the bits
> in a tree node before folding and compares it to a checksum after
> folding and setting the NO_WARNING bit in between causes the checking
> to fail?
> 
> If that's accurate, if this patch is not the right fix, what would be?

The --enable-checking=fold is an attempt to find bugs in fold and friends.
Unlike the gimplifier, which is destructive on the trees passed to it (and
that is why e.g. function bodies are unshared before being passed to the
gimplifier), fold is invoked often by the FE and trees can be heavily shared
at that point, so if fold modifies the arguments passed to it rather than
creating new trees, it could modify some other tree in the same (or another)
function.  fold_checksum_tree has some exceptions on what is allowed to
change, e.g. the various caches of types etc.
My patch has treated the TREE_NO_WARNING flag similarly to that, as an
exception, but Richard expressed the opinion that perhaps that is not the
right thing and we should instead unshare trees containing it if we want to
set TREE_NO_WARNING.  That would mean either don't warn from within the
folder (e.g. warn during gimplification or gimple-fold instead), or unshare.

Jakub


[C++ PATCH] PR c++/89576 - if constexpr of lambda capture.

2019-03-06 Thread Jason Merrill
Now that we're doing implicit lambda capture in templates, we see x here as
the lambda capture.  maybe_convert_cond was doing nothing in a template, so
we never called mark_rvalue_use on x.  As part of the broad move toward
doing more processing of non-dependent expressions, let's do this
conversion.

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

* semantics.c (maybe_convert_cond): Do convert a non-dependent
condition in a template.
* typeck.c (condition_conversion): Handle being called in a
template.
---
 gcc/cp/semantics.c  |  4 ++--
 gcc/cp/typeck.c |  9 -
 gcc/testsuite/g++.dg/cpp1z/constexpr-if15.C |  2 +-
 gcc/testsuite/g++.dg/cpp1z/constexpr-if28.C | 11 +++
 gcc/cp/ChangeLog|  8 
 5 files changed, 26 insertions(+), 8 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/cpp1z/constexpr-if28.C

diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index c03e4ef247c..2573b77f6d6 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -646,10 +646,10 @@ maybe_convert_cond (tree cond)
 return NULL_TREE;
 
   /* Wait until we instantiate templates before doing conversion.  */
-  if (processing_template_decl)
+  if (type_dependent_expression_p (cond))
 return cond;
 
-  if (warn_sequence_point)
+  if (warn_sequence_point && !processing_template_decl)
 verify_sequence_points (cond);
 
   /* Do the conversion.  */
diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c
index 1bf9ad88141..8367497b539 100644
--- a/gcc/cp/typeck.c
+++ b/gcc/cp/typeck.c
@@ -5867,18 +5867,17 @@ cp_truthvalue_conversion (tree expr)
 return c_common_truthvalue_conversion (input_location, expr);
 }
 
-/* Just like cp_truthvalue_conversion, but we want a CLEANUP_POINT_EXPR.  */
+/* Just like cp_truthvalue_conversion, but we want a CLEANUP_POINT_EXPR.  This
+   is a low-level function; most callers should use maybe_convert_cond.  */
 
 tree
 condition_conversion (tree expr)
 {
   tree t;
-  /* Anything that might happen in a template should go through
- maybe_convert_cond.  */
-  gcc_assert (!processing_template_decl);
   t = perform_implicit_conversion_flags (boolean_type_node, expr,
 tf_warning_or_error, LOOKUP_NORMAL);
-  t = fold_build_cleanup_point_expr (boolean_type_node, t);
+  if (!processing_template_decl)
+t = fold_build_cleanup_point_expr (boolean_type_node, t);
   return t;
 }
 
diff --git a/gcc/testsuite/g++.dg/cpp1z/constexpr-if15.C 
b/gcc/testsuite/g++.dg/cpp1z/constexpr-if15.C
index 1dd8beab89c..49c7b7abb63 100644
--- a/gcc/testsuite/g++.dg/cpp1z/constexpr-if15.C
+++ b/gcc/testsuite/g++.dg/cpp1z/constexpr-if15.C
@@ -7,5 +7,5 @@ constexpr int foo (int) { return 2; }
 template 
 void a()
 {
-  if constexpr(foo) { };
+  if constexpr(foo) { };   // { dg-error "overloaded" }
 }
diff --git a/gcc/testsuite/g++.dg/cpp1z/constexpr-if28.C 
b/gcc/testsuite/g++.dg/cpp1z/constexpr-if28.C
new file mode 100644
index 000..8bfde6c1bdb
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1z/constexpr-if28.C
@@ -0,0 +1,11 @@
+// PR c++/89576
+// { dg-do compile { target c++17 } }
+
+template 
+void foo()
+{
+constexpr int x = 0;
+[&] {
+if constexpr (x) {}
+};
+}
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index d2cb7fd1132..f889b253f5a 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,11 @@
+2019-03-06  Jason Merrill  
+
+   PR c++/89576 - if constexpr of lambda capture.
+   * semantics.c (maybe_convert_cond): Do convert a non-dependent
+   condition in a template.
+   * typeck.c (condition_conversion): Handle being called in a
+   template.
+
 2019-03-05  Jason Merrill  
 
* class.c (is_really_empty_class): Add ignore_vptr parm.

base-commit: ad0ce1a5e76e19a5222cb0a529a245d8a7991114
-- 
2.20.1



[patch, fortran] Fix PR 66089, ICE (plus wrong code) in dependency handling

2019-03-06 Thread Thomas Koenig

Hello world,

the attached patch fixes a 7/8/9 regression where dependency checking
was for class arrays and a scalar value was mishandled when the
dependency happened in an elemental function.

There was an ICE for the test case which is handled by
fixing up the class refs in gfc_walk_variable_expr.
Once this was gone, a wrong-code issue appeared which was fixed
by the part in gfc_scalar_elemental_arg_saved_as_reference
(is that the longest function name in gfortran?).

Regression-tested. OK for all affected branches?

Regards

Thomas

2019-03-06  Thomas Koenig  

PR fortran/66089
* trans-array.c (gfc_scalar_elemental_arg_saved_as_reference):
Return false if a scalar tempoary is needed.
(gfc_walk_variable_expr): Fix up class refs.

2019-03-06  Thomas Koenig  

PR fortran/66089
* gfortran.dg/dependency_53.f90: New test.
Index: trans-array.c
===
--- trans-array.c	(Revision 269260)
+++ trans-array.c	(Arbeitskopie)
@@ -2699,6 +2699,9 @@ gfc_scalar_elemental_arg_saved_as_reference (gfc_s
   if (ss_info->type != GFC_SS_REFERENCE)
 return false;
 
+  if (ss_info->data.scalar.needs_temporary)
+return false;
+
   /* If the actual argument can be absent (in other words, it can
  be a NULL reference), don't try to evaluate it; pass instead
  the reference directly.  */
@@ -10515,6 +10518,8 @@ gfc_walk_variable_expr (gfc_ss * ss, gfc_expr * ex
 {
   gfc_ref *ref;
 
+  gfc_fix_class_refs (expr);
+
   for (ref = expr->ref; ref; ref = ref->next)
 if (ref->type == REF_ARRAY && ref->u.ar.type != AR_ELEMENT)
   break;
! { dg-do run }
! PR fortran/66089 - used to ICE and, after that ICE was fixed,
! gave wrong results.
  type :: t
integer :: c
  end type t

  class(t), dimension(:), allocatable :: b,c

  allocate (b(5), source=t(7))
  allocate(c(5), source=t(13))
  c = plus(c(1), b)
  if (any(c%c /= 20)) call abort
  c = t(13)
  c = plus(b, c(1))
  if (any(c%c /= 20)) call abort
contains

  elemental function plus(lhs, rhs)
class(t), intent(in) :: lhs, rhs
type(t) :: plus
plus%c = lhs%c + rhs%c
  end function plus

end


[C++ PATCH] PR c++/89381 - implicit copy and using-declaration.

2019-03-06 Thread Jason Merrill
Here the used base::operator= gets into the list of foo's bindings for
operator=, but it shouldn't make the copy ctor deleted.

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

* class.c (classtype_has_move_assign_or_move_ctor_p): Don't consider
op= brought in by a using-declaration.
---
 gcc/cp/class.c  |  4 ++-
 gcc/testsuite/g++.dg/cpp0x/implicit16.C | 37 +
 gcc/cp/ChangeLog|  4 +++
 3 files changed, 44 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/g++.dg/cpp0x/implicit16.C

diff --git a/gcc/cp/class.c b/gcc/cp/class.c
index 0d4d35bd690..a70a852424e 100644
--- a/gcc/cp/class.c
+++ b/gcc/cp/class.c
@@ -5220,7 +5220,9 @@ classtype_has_move_assign_or_move_ctor_p (tree t, bool 
user_p)
 for (ovl_iterator iter (get_class_binding_direct
(t, assign_op_identifier));
 iter; ++iter)
-  if ((!user_p || !DECL_ARTIFICIAL (*iter)) && move_fn_p (*iter))
+  if ((!user_p || !DECL_ARTIFICIAL (*iter))
+ && DECL_CONTEXT (*iter) == t
+ && move_fn_p (*iter))
return true;
   
   return false;
diff --git a/gcc/testsuite/g++.dg/cpp0x/implicit16.C 
b/gcc/testsuite/g++.dg/cpp0x/implicit16.C
new file mode 100644
index 000..229f2b4cd81
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/implicit16.C
@@ -0,0 +1,37 @@
+// PR c++/89381
+// { dg-do compile { target c++11 } }
+
+template
+struct base
+{
+  base() { }
+  base(const base&) { }
+  base(base&&) { }
+  base& operator=(const base&) { return *this; }
+  base& operator=(base&&) { return *this; }
+};
+
+struct foo : base
+{
+using base::base;
+using base::operator=;
+};
+
+//using workaround = decltype(foo{*static_cast(0)});
+
+struct bar
+{
+bar& operator=(foo ve)
+{
+value = ve;
+return *this;
+}
+
+foo value;
+};
+
+int main()
+{
+foo a;
+foo b{a};
+}
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index a076fa9a255..848859e955e 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,5 +1,9 @@
 2019-03-06  Jason Merrill  
 
+   PR c++/89381 - implicit copy and using-declaration.
+   * class.c (classtype_has_move_assign_or_move_ctor_p): Don't consider
+   op= brought in by a using-declaration.
+
PR c++/89576 - if constexpr of lambda capture.
* semantics.c (maybe_convert_cond): Do convert a non-dependent
condition in a template.

base-commit: 02daf5d2ca0cd851d93e4d7299a95013cb405497
-- 
2.20.1



Re: [PR fortran/71203, patch] - ICE on zero-length arrays or substrings

2019-03-06 Thread Harald Anlauf
Committed as rev.269444 to trunk, rev.269445 to 8-branch.

Thanks for the review!

Harald

On 03/06/19 00:07, Thomas Koenig wrote:
> Hi Harald,
> 
>> To the reviewer: I am not 100% sure that my solution is correct, but it
>> solves the issues reported and regtests cleanly on x86_64-pc-linux-gnu.
>>
>> OK for trunk?  Backports?
> 
> I don't see how adding the charlen to the current namespace can hurt,
> so I think this is OK.
> 
> Regarding backports:  I don't think we need to backport every bug fix
> if does not fix a regression.  (Officially, we are not even
> supposed to fix non-regressions on trunk at this point, but in practice
> this means that we should take care not to introduce risky patches.
> gfortran is not release critical, so we are free to break our own
> compiler without holding up all of gcc).
> 
> Regards
> 
> Thomas
> 



PING [PATCH] correct handling of offsets in bounds warnings (PR 89350)

2019-03-06 Thread Martin Sebor

Ping: https://gcc.gnu.org/ml/gcc-patches/2019-02/msg02029.html

(This is marked as a P1 regression.)

On 2/26/19 6:32 PM, Martin Sebor wrote:

Please disregard the original patch and consider the attached
version instead.

On 2/26/19 5:03 PM, Martin Sebor wrote:

The false positive in PR89350 is due to -Wstringop-overflow
trusting that the sizetype offset in POINTER_PLUS_EXPR means
the offset is, in fact, unsigned.  Avoiding the false positive
in the cases when this isn't so is trivial but comes at a cost
of false negatives.  Avoiding those will, I expect, require
enhancing the compute_builtin_object_size() function and that
seems risky at this stage so I would like to defer that until
stage 1.  Except in the instance of memset, the false positives
also aren't too serious because the same problem is also
diagnosed by the -Warray-bounds warning in the wrestrict pass.
Unfortunately, the wrestrict pass only handles copy functions
and not memset.

With that as background, the attached patch avoids
the -Wstringop-overflow false positive by disabling the warning
for offsets whose lower bound is positive and upper bound negative.
To avoid the false negatives for memset the patch lets the wrestrict
pass handle the function (for the bounds checking only).  While
testing this I noticed that the wrestrict pass makes the same
assumption about offsets, so it too is susceptible to similar
false positives.  The rest of the patch corrects this problem
n the wrestrict pass.  Because the pass doesn't depend on
the compute_builtin_object_size() function as much as
-Wstringop-overflow, the fix does not cause false positives (at
least none that I came across).

Tested on x86_64-linux.

Martin






Re: [PATCH] Fix -gdwarf-5 -gsplit-dwarf ICEs (PR debug/89498)

2019-03-06 Thread Jakub Jelinek
On Tue, Mar 05, 2019 at 04:06:59PM -0500, Jason Merrill wrote:
> > Assuming output_view_list_offset is correct, the following patch adjusts
> > size_of_die/value_format accordingly.
> 
> I would guess that omitting the handling from output_view_list_offset was an
> oversight in the view work.  Alex, which is right? :)

I had further look today.  Alex has added multiple modes, with
-gvariable-location-views=incompat5 the location view stuff is emitted
directly into the .debug_loclist section as part of the sequence, like:
.uleb128 0  # DW_AT_location (*.LLST0)
...
.section.debug_loclists.dwo,"e",@progbits
.long   .Ldebug_loc3-.Ldebug_loc2   # Length of Location Lists
.Ldebug_loc2:
.value  0x5 # DWARF version number
.byte   0x8 # Address Size
.byte   0   # Segment Size
.long   0x3 # Offset Entry Count
.Ldebug_loc0:
.long   .LLST0-.Ldebug_loc0
.long   .LLST1-.Ldebug_loc0
.long   .LLST2-.Ldebug_loc0
.LLST0:
.byte   0x9 # DW_LLE_view_pair
.uleb128 0  # Location view begin
.uleb128 .LVU6  # Location view end
.byte   0x3 # DW_LLE_startx_length (*.LLST0)
.uleb128 0x2# Location list range start index (*.LVL0)
.uleb128 .LVL1-.LVL0# Location list length (*.LLST0)
.uleb128 0x1# Location expression size
.byte   0x61# DW_OP_reg17
...
.byte   0   # DW_LLE_end_of_list (*.LLST0)
and in this case we don't ICE, the DW_AT_GNU_locviews attributes aren't
emitted at all.
With just -gvariable-location-views -gdwarf-5 -gsplit-dwarf (and the patch
I've posted so that it doesn't ICE):
.uleb128 0  # DW_AT_location (*.LLST0)
.long   .LVUS0-.Ldebug_loc0 # DW_AT_GNU_locviews
...
.section.debug_loclists.dwo,"e",@progbits
.long   .Ldebug_loc3-.Ldebug_loc2   # Length of Location Lists
.Ldebug_loc2:
.value  0x5 # DWARF version number
.byte   0x8 # Address Size
.byte   0   # Segment Size
.long   0x3 # Offset Entry Count
.Ldebug_loc0:
.long   .LLST0-.Ldebug_loc0
.long   .LLST1-.Ldebug_loc0
.long   .LLST2-.Ldebug_loc0
.LVUS0:
.uleb128 0  # View list begin (*.LVUS0)
.uleb128 .LVU6  # View list end (*.LVUS0)
.uleb128 .LVU6  # View list begin (*.LVUS0)
.uleb128 0  # View list end (*.LVUS0)
.LLST0:
.byte   0x3 # DW_LLE_startx_length (*.LLST0)
.uleb128 0x2# Location list range start index (*.LVL0)
.uleb128 .LVL1-.LVL0# Location list length (*.LLST0)
.uleb128 0x1# Location expression size
.byte   0x61# DW_OP_reg17
.byte   0x3 # DW_LLE_startx_length (*.LLST0)
.uleb128 0  # Location list range start index (*.LVL1)
.uleb128 .LFE0-.LVL1# Location list length (*.LLST0)
.uleb128 0x6# Location expression size
.byte   0xa3# DW_OP_entry_value
.uleb128 0x3
.byte   0xa5# DW_OP_regval_type
.uleb128 0x11
.uleb128 0x19
.byte   0x9f# DW_OP_stack_value
.byte   0   # DW_LLE_end_of_list (*.LLST0)
In order to use DW_FORM_loclistx .uleb128 for the DW_AT_GNU_locviews,
we'd need to emit .long .LVUS0-.Ldebug_loc0 etc. next to the
.LLST0-.Ldebug_loc0 in the section offsets table at .Ldebug_loc0,
but I'd expect debug info consumers to assume that anything listed
in the offset table is actually a valid DW_LLE_* sequence, which is not the
case for the .LVUS* labels.

Note the
.long   .LVUS0-.Ldebug_loc0 # DW_AT_GNU_locviews
looks weird, at least with the patch it is given DW_FORM_sec_offset, but
because it is a difference between .LVUS0-.Ldebug_loc0, it is actually not a
sec offset.  Shall it use a different form in that case?

Alex?

Jakub


Re: [PATCH] improve performance of std::allocator::deallocate

2019-03-06 Thread Pádraig Brady



On 03/06/2019 01:44 AM, Jonathan Wakely wrote:
> On 06/03/19 09:20 +, Pádraig Brady wrote:
>> On 03/06/2019 12:50 AM, Jonathan Wakely wrote:
>>> On 06/03/19 02:43 +, Pádraig Brady wrote:


 On 02/26/2019 04:23 PM, Padraig Brady wrote:
>
>> Note jemalloc >= 5.1 is required to fix a bug with 0 sizes.
>>
>> How serious is the bug? What are the symptoms?
>>
> I've updated the commit summary to say it's a crash.
> Arguably that's better than mem corruption.
>
>> It looks like 5.1.0 is less than a year old, so older versions are
>> presumably still in wide use.
>>
>> We could potentially workaround it by making
>> new_allocator::allocate(0) call ::operator new(1) when
>> __cpp_sized_deallocation is defined, and deallocate(p, 0) call
>> ::operator delete(p, 1). Obviously I'd prefer not to do that,
>> because
>> the default operator new already has an equivalent check, and only
>> programs linking to jemalloc require the workaround.
>>
> Right the jemalloc fix was released May 2018.
> It would be great to avoid the extra workarounds.
> Given this would be released about a year after the jemalloc fix was
> released,
> and that this would only manifest upon program rebuild,
> I would be inclined to not add any workarounds.
> For reference tcmalloc and glibc malloc were seen to work fine with
> this.

 Actually the jemalloc issue will only be fixed with the release of 5.2
 (a few weeks away).
 I've updated the commit message in the attached accordingly.
>>>
>>> Hmm, I'm a bit nervous about making a change that will cause crashes
>>> unless using an unreleased version (I know it will be released by the
>>> time GCC 9.1 is released, but some people might upgrade GCC without
>>> upgrading jemalloc).
>> Yes it's not ideal. It does make it a lot less risky that one has to
>> rebuild programs to get the new functionality, so existing programs
>> will be unaffected. Also -fsized-deallocation is only enabled by
>> default on gcc with -std >= c++14.
>
> The default is -std=gnu++14 so it's enabled unless you explicitly
> choose an older dialect or add -fno-sized-deallocation.
Good point :)
>
>>> On the other hand, zero sized allocations should be rare in practice.
>> Yes they were rare in testing here
>>
>> So programs _rebuilt_ against the following would need to update
>> to jemalloc 5.2:
>>
>>  zero sized allocs, jemalloc<5.2, c++>=14, GCC>=9.1
>>
>> Hopefully that's a small enough set.
>
> Which versions of jemalloc replace operator delete(void*, size_t) ?
>
> Was that something new in 5.0 or did older versions already provide a
> replacement for the sized operator delete?
>
> If it was introduced in 5.0 then there won't be a problem for 3.x and
> 4.x because they'll use the default definition from libstdc++ which
> just calls ::operator delete(p).
Again very good point. The replacements were only added in 5.0:
https://github.com/jemalloc/jemalloc/commit/2319152d
>
> How complicated is the fix to prevent the crashes? Would it be
> feasible for distros to backport that fix? I see that RHEL8 has
> jemalloc 5.0.1 for example, but if the fix could be backported to that
> release then it's less of a problem.
The patch set is simple enough:
https://github.com/jemalloc/jemalloc/pull/1341/commits

cheers,
Pádraig.


[C++ PATCH] Toplevel asm volatile (PR c++/89585)

2019-03-06 Thread Jakub Jelinek
Hi!

The following patch tries to improve diagnostics of toplevel asm qualifiers
in C++ by actually parsing them and complaining if they appear at toplevel,
instead of just emitting a parse error that ( is expected, e.g. some
versions of Qt do use toplevel asm volatile and apparently the Qt code is
copied into lots of various projects.

In addition to that, it mentions in the documentation that qualifiers are
not allowed at toplevel asm statements; apparently our documentation at
least from r220506 for GCC 5 says that at toplevel Basic Asm needs to be
used and for Basic Asm lists volatile qualifier as optional and its behavior
(that it is ignored for Basic Asm).  Makes me wonder if we don't want to
keep accepting/ignoring volatile at toplevel for both C and C++ instead of
rejecting it (and rejecting just the other qualifiers).  Thoughts on this?

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

Attached is an untested backport of this patch to 8.4, which does allow
asm volatile at toplevel, so that we don't break in 8.4 what has been
accepted in 8.2.  Ok if it passes bootstrap/regtest there?

2019-03-07  Jakub Jelinek  

PR c++/89585
* doc/extend.texi (Basic Asm): Document qualifiers are not allowed
at toplevel.

* parser.c (cp_parser_asm_definition): Parse asm qualifiers even
at toplevel, but diagnose them.

* g++.dg/asm-qual-3.C: Adjust expected diagnostics.

--- gcc/doc/extend.texi.jj  2019-02-26 21:35:26.782115737 +0100
+++ gcc/doc/extend.texi 2019-03-06 10:23:14.894032621 +0100
@@ -9064,6 +9064,8 @@ outside of C functions, you must use bas
 You can use this technique to emit assembler directives,
 define assembly language macros that can be invoked elsewhere in the file,
 or write entire functions in assembly language.
+Basic @code{asm} statements outside of functions may not use any
+qualifiers.
 
 @item
 Functions declared
--- gcc/cp/parser.c.jj  2019-03-05 09:39:18.850146559 +0100
+++ gcc/cp/parser.c 2019-03-06 19:41:27.861895296 +0100
@@ -19766,8 +19766,9 @@ cp_parser_asm_definition (cp_parser* par
   location_t volatile_loc = UNKNOWN_LOCATION;
   location_t inline_loc = UNKNOWN_LOCATION;
   location_t goto_loc = UNKNOWN_LOCATION;
+  location_t first_loc = UNKNOWN_LOCATION;
 
-  if (cp_parser_allow_gnu_extensions_p (parser) && parser->in_function_body)
+  if (cp_parser_allow_gnu_extensions_p (parser))
 for (;;)
   {
cp_token *token = cp_lexer_peek_token (parser->lexer);
@@ -19782,6 +19783,8 @@ cp_parser_asm_definition (cp_parser* par
  }
else
  volatile_loc = loc;
+   if (!first_loc)
+ first_loc = loc;
cp_lexer_consume_token (parser->lexer);
continue;
 
@@ -19793,6 +19796,8 @@ cp_parser_asm_definition (cp_parser* par
  }
else
  inline_loc = loc;
+   if (!first_loc)
+ first_loc = loc;
cp_lexer_consume_token (parser->lexer);
continue;
 
@@ -19804,6 +19809,8 @@ cp_parser_asm_definition (cp_parser* par
  }
else
  goto_loc = loc;
+   if (!first_loc)
+ first_loc = loc;
cp_lexer_consume_token (parser->lexer);
continue;
 
@@ -19823,6 +19830,12 @@ cp_parser_asm_definition (cp_parser* par
   bool inline_p = (inline_loc != UNKNOWN_LOCATION);
   bool goto_p = (goto_loc != UNKNOWN_LOCATION);
 
+  if (!parser->in_function_body && (volatile_p || inline_p || goto_p))
+{
+  error_at (first_loc, "asm qualifier outside of function body");
+  volatile_p = inline_p = goto_p = false;
+}
+
   /* Look for the opening `('.  */
   if (!cp_parser_require (parser, CPP_OPEN_PAREN, RT_OPEN_PAREN))
 return;
--- gcc/testsuite/g++.dg/asm-qual-3.C.jj2018-12-20 08:50:27.234484465 
+0100
+++ gcc/testsuite/g++.dg/asm-qual-3.C   2019-03-06 19:40:20.932993605 +0100
@@ -2,11 +2,11 @@
 // { dg-do compile }
 // { dg-options "-std=gnu++98" }
 
-asm const ("");// { dg-error {expected '\(' before 'const'} }
-asm volatile (""); // { dg-error {expected '\(' before 'volatile'} }
+asm const ("");// { dg-error {'const' is not an asm qualifier} }
+asm volatile (""); // { dg-error {asm qualifier outside of function body} }
 asm restrict (""); // { dg-error {expected '\(' before 'restrict'} }
-asm inline ("");   // { dg-error {expected '\(' before 'inline'} }
-asm goto (""); // { dg-error {expected '\(' before 'goto'} }
+asm inline ("");   // { dg-error {asm qualifier outside of function body} }
+asm goto (""); // { dg-error {asm qualifier outside of function body} }
 
 // There are many other things wrong with this code, so:
 // { dg-excess-errors "" }

Jakub
2019-03-07  Jakub Jelinek  

PR c++/89585
* parser.c (cp_parser_asm_definition): Parse asm qualifiers even
at toplevel, but diagnose them.

* g++.dg/asm-qual-3.C: Adjust expected diag

[PATCH] Add missing avx512fintrin.h intrinsics (PR target/89602)

2019-03-06 Thread Jakub Jelinek
Hi!

The following patch adds vmovss/vmovsd masked intrinsics.
On
#include 
__m128 f1 (__m128 w, __mmask8 u, const float *p) { return _mm_mask_load_ss (w, 
u, p); }
__m128 f2 (__mmask8 u, const float *p) { return _mm_maskz_load_ss (u, p); }
__m128d f3 (__m128d w, __mmask8 u, const double *p) { return _mm_mask_load_sd 
(w, u, p); }
__m128d f4 (__mmask8 u, const double *p) { return _mm_maskz_load_sd (u, p); }
__m128 f5 (__m128 w, __mmask8 u, __m128 a, __m128 b) { return _mm_mask_move_ss 
(w, u, a, b); }
__m128 f6 (__mmask8 u, __m128 a, __m128 b) { return _mm_maskz_move_ss (u, a, 
b); }
__m128d f7 (__m128d w, __mmask8 u, __m128d a, __m128d b) { return 
_mm_mask_move_sd (w, u, a, b); }
__m128d f8 (__mmask8 u, __m128d a, __m128d b) { return _mm_maskz_move_sd (u, a, 
b); }
void f9 (float *p, __mmask8 u, __m128 a) { _mm_mask_store_ss (p, u, a); }
void f10 (double *p, __mmask8 u, __m128d a) { _mm_mask_store_sd (p, u, a); }
it generates the same assembly with -O2 -mavx512f as icc 19 or clang trunk.
It mostly does a good job also when the mask is constant, on the above
testcase with u arguments replaced with 1 I get:
f1: vmovss (%rsi), %xmm0
f2: vmovss (%rsi), %xmm0
f3: vmovq (%rsi), %xmm0
f4: movzbl .LC0(%rip), %eax; kmovw %eax, %k1; vmovsd (%rsi), %xmm0{%k1}{z}
f5: vmovss %xmm2, %xmm1, %xmm0
f6: vmovss %xmm1, %xmm0, %xmm0
f7: vmovsd %xmm2, %xmm1, %xmm0
f8: vmovsd %xmm1, %xmm0, %xmm0
f9: vmovss %xmm0, (%rdi)
f10: vmovlpd %xmm0, (%rdi)
Except for f4 that looks reasonable to me (and as tested in the testsuite
works too), for f4 guess either we need to improve simplify-rtx.c or add
some pattern for the combiner.  Can handle that as follow-up.
When instead using 0 mask, I get:
f1: kxorw %k1, %k1, %k1; vmovss (%rsi), %xmm0{%k1}
f2: vxorps %xmm0, %xmm0, %xmm0
f3: kxorw %k1, %k1, %k1; vmovsd (%rsi), %xmm0{%k1}
f4: vxorpd %xmm0, %xmm0, %xmm0
f5: vmovss %xmm0, %xmm1, %xmm0
f6: kxorw %k1, %k1, %k1; vmovss %xmm1, %xmm0, %xmm0{%k1}{z}
f7: vmovsd %xmm0, %xmm1, %xmm0
f8: kxorw %k1, %k1, %k1; vmovsd %xmm1, %xmm0, %xmm0{%k1}{z}
f9: nothing
f10: nothing
which looks good to me.  For f1/f3/f6/f8, I really have no idea if there is
some single insn that could do that kind of operation.  This is also tested
at runtime in the testsuite.

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

2019-03-07  Jakub Jelinek  

PR target/89602
* config/i386/sse.md (avx512f_mov_mask,
*avx512f_load_mask, avx512f_store_mask): New define_insns.
(avx512f_load_mask): New define_expand.
* config/i386/i386-builtin.def (__builtin_ia32_loadsd_mask,
__builtin_ia32_loadss_mask, __builtin_ia32_storesd_mask,
__builtin_ia32_storess_mask, __builtin_ia32_movesd_mask,
__builtin_ia32_movess_mask): New builtins.
* config/i386/avx512fintrin.h (_mm_mask_load_ss, _mm_maskz_load_ss,
_mm_mask_load_sd, _mm_maskz_load_sd, _mm_mask_move_ss,
_mm_maskz_move_ss, _mm_mask_move_sd, _mm_maskz_move_sd,
_mm_mask_store_ss, _mm_mask_store_sd): New intrinsics.

* gcc.target/i386/avx512f-vmovss-1.c: New test.
* gcc.target/i386/avx512f-vmovss-2.c: New test.
* gcc.target/i386/avx512f-vmovss-3.c: New test.
* gcc.target/i386/avx512f-vmovsd-1.c: New test.
* gcc.target/i386/avx512f-vmovsd-2.c: New test.
* gcc.target/i386/avx512f-vmovsd-3.c: New test.

--- gcc/config/i386/sse.md.jj   2019-02-20 23:40:17.119140235 +0100
+++ gcc/config/i386/sse.md  2019-03-06 19:15:12.379749161 +0100
@@ -1151,6 +1151,67 @@ (define_insn "_load_mask"
(set_attr "memory" "none,load")
(set_attr "mode" "")])
 
+(define_insn "avx512f_mov_mask"
+  [(set (match_operand:VF_128 0 "register_operand" "=v")
+   (vec_merge:VF_128
+ (vec_merge:VF_128
+   (match_operand:VF_128 2 "register_operand" "v")
+   (match_operand:VF_128 3 "nonimm_or_0_operand" "0C")
+   (match_operand:QI 4 "register_operand" "Yk"))
+ (match_operand:VF_128 1 "register_operand" "v")
+ (const_int 1)))]
+  "TARGET_AVX512F"
+  "vmov\t{%2, %1, %0%{%4%}%N3|%0%{%4%}%N3, %1, %2}"
+  [(set_attr "type" "ssemov")
+   (set_attr "prefix" "evex")
+   (set_attr "mode" "")])
+
+(define_expand "avx512f_load_mask"
+  [(set (match_operand: 0 "register_operand")
+   (vec_merge:
+ (vec_merge:
+   (vec_duplicate:
+ (match_operand:MODEF 1 "memory_operand"))
+   (match_operand: 2 "nonimm_or_0_operand")
+   (match_operand:QI 3 "nonmemory_operand"))
+ (match_dup 4)
+ (const_int 1)))]
+  "TARGET_AVX512F"
+  "operands[4] = CONST0_RTX (mode);")
+
+(define_insn "*avx512f_load_mask"
+  [(set (match_operand: 0 "register_operand" "=v")
+   (vec_merge:
+ (vec_merge:
+   (vec_duplicate:
+ (match_operand:MODEF 1 "memory_operand" "m"))
+   (match_operand: 2 "nonimm_or_0_operand" "0C")
+   (match_operand:QI 3 "nonmemory_operand" "Yk"))
+ (match_operand: 

Test message, please ignore

2019-03-06 Thread Ian Lance Taylor
My e-mail is not going out and I don't know why.  Just testing.  Sorry.

Ian


Go patch committed: avoid emitting type conversion in Array_type::do_export

2019-03-06 Thread Ian Lance Taylor
I have committed a Go frontend patch by Than McIntosh that fixes
Array_type::do_export to not emit a type conversion, by fetching the
constant value and exporting that.  This fixes Go issue 30628.
Bootstrapped and ran Go testsuite on x86_64-pc-linux-gnu.  Committed
to mainline.

Unfortunately it appears that I cannot attach the patch to this e-mail
message, because every attempt to do so causes my e-mail to be blocked
by GMail.  I have no idea why.  So if you want to see the actual
diffs, please see
https://gcc.gnu.org/viewcvs/gcc?view=revision&revision=269443 .

Ian


Re: [C++ PATCH] Toplevel asm volatile (PR c++/89585)

2019-03-06 Thread Jason Merrill
On Wed, Mar 6, 2019 at 6:39 PM Jakub Jelinek  wrote:
>
> The following patch tries to improve diagnostics of toplevel asm qualifiers
> in C++ by actually parsing them and complaining if they appear at toplevel,
> instead of just emitting a parse error that ( is expected, e.g. some
> versions of Qt do use toplevel asm volatile and apparently the Qt code is
> copied into lots of various projects.
>
> In addition to that, it mentions in the documentation that qualifiers are
> not allowed at toplevel asm statements; apparently our documentation at
> least from r220506 for GCC 5 says that at toplevel Basic Asm needs to be
> used and for Basic Asm lists volatile qualifier as optional and its behavior
> (that it is ignored for Basic Asm).  Makes me wonder if we don't want to
> keep accepting/ignoring volatile at toplevel for both C and C++ instead of
> rejecting it (and rejecting just the other qualifiers).  Thoughts on this?

That seems reasonable.  Or using warning or permerror instead of error.

> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
>
> Attached is an untested backport of this patch to 8.4, which does allow
> asm volatile at toplevel, so that we don't break in 8.4 what has been
> accepted in 8.2.  Ok if it passes bootstrap/regtest there?

Both OK.

Jason


Go patch committed: Set TREE_PUBLIC for only-inline functions

2019-03-06 Thread Ian Lance Taylor
This patch to the Go frontend sets TREE_PUBLIC for only-inline
functions.  This fixes GCC PR 89227.  Bootstrapped and ran Go tests on
x86_64-pc-linux-gnu and ppc64le-linux-gnu.  Committed to mainline.

Ian


2019-03-06  Ian Lance Taylor  

PR go/89227
* go-gcc.cc (Gcc_backend::function): Set TREE_PUBLIC for an
only-inline function.
Index: go-gcc.cc
===
--- go-gcc.cc   (revision 269196)
+++ go-gcc.cc   (working copy)
@@ -3101,6 +3101,7 @@ Gcc_backend::function(Btype* fntype, con
 resolve_unique_section(decl, 0, 1);
   if ((flags & function_only_inline) != 0)
 {
+  TREE_PUBLIC (decl) = 1;
   DECL_EXTERNAL(decl) = 1;
   DECL_DECLARED_INLINE_P(decl) = 1;
 }


V4 [PATCH] Optimize vector constructor

2019-03-06 Thread H.J. Lu
On Wed, Mar 6, 2019 at 8:33 PM Richard Biener
 wrote:
>
> On Wed, Mar 6, 2019 at 8:46 AM H.J. Lu  wrote:
> >
> > On Tue, Mar 5, 2019 at 1:46 AM H.J. Lu  wrote:
> > >
> > > On Mon, Mar 04, 2019 at 12:55:04PM +0100, Richard Biener wrote:
> > > > On Sun, Mar 3, 2019 at 10:13 PM H.J. Lu  wrote:
> > > > >
> > > > > On Sun, Mar 03, 2019 at 06:40:09AM -0800, Andrew Pinski wrote:
> > > > > > )
> > > > > > ,On Sun, Mar 3, 2019 at 6:32 AM H.J. Lu  wrote:
> > > > > > >
> > > > > > > For vector init constructor:
> > > > > > >
> > > > > > > ---
> > > > > > > typedef float __v4sf __attribute__ ((__vector_size__ (16)));
> > > > > > >
> > > > > > > __v4sf
> > > > > > > foo (__v4sf x, float f)
> > > > > > > {
> > > > > > >   __v4sf y = { f, x[1], x[2], x[3] };
> > > > > > >   return y;
> > > > > > > }
> > > > > > > ---
> > > > > > >
> > > > > > > we can optimize vector init constructor with vector copy or 
> > > > > > > permute
> > > > > > > followed by a single scalar insert:
> > >
> > > > and you want to advance to the _1 = BIT_INSERT_EXPR here.  The easiest 
> > > > way
> > > > is to emit a new stmt for _2 = copy ...; and do the set_rhs with the
> > > > BIT_INSERT_EXPR.
> > >
> > > Thanks for BIT_INSERT_EXPR suggestion.  I am testing this patch.
> > >
> > >
> > > H.J.
> > > ---
> > > We can optimize vector constructor with vector copy or permute followed
> > > by a single scalar insert:
> > >
> > >   __v4sf y;
> > >   __v4sf D.1930;
> > >   float _1;
> > >   float _2;
> > >   float _3;
> > >
> > >:
> > >   _1 = BIT_FIELD_REF ;
> > >   _2 = BIT_FIELD_REF ;
> > >   _3 = BIT_FIELD_REF ;
> > >   y_6 = {f_5(D), _3, _2, _1};
> > >   return y_6;
> > >
> > > with
> > >
> > >  __v4sf y;
> > >   __v4sf D.1930;
> > >   float _1;
> > >   float _2;
> > >   float _3;
> > >   vector(4) float _8;
> > >
> > >:
> > >   _1 = BIT_FIELD_REF ;
> > >   _2 = BIT_FIELD_REF ;
> > >   _3 = BIT_FIELD_REF ;
> > >   _8 = x_9(D);
> > >   y_6 = BIT_INSERT_EXPR ;
> > >   return y_6;
> > >
> > > gcc/
> > >
> > > PR tree-optimization/88828
> > > * tree-ssa-forwprop.c (simplify_vector_constructor): Optimize
> > > vector init constructor with vector copy or permute followed
> > > by a single scalar insert.
> > >
> > > gcc/testsuite/
> > >
> > > PR tree-optimization/88828
> > > * gcc.target/i386/pr88828-1a.c: New test.
> > > * gcc.target/i386/pr88828-2b.c: Likewise.
> > > * gcc.target/i386/pr88828-2.c: Likewise.
> > > * gcc.target/i386/pr88828-3a.c: Likewise.
> > > * gcc.target/i386/pr88828-3b.c: Likewise.
> > > * gcc.target/i386/pr88828-3c.c: Likewise.
> > > * gcc.target/i386/pr88828-3d.c: Likewise.
> > > * gcc.target/i386/pr88828-4a.c: Likewise.
> > > * gcc.target/i386/pr88828-4b.c: Likewise.
> > > * gcc.target/i386/pr88828-5a.c: Likewise.
> > > * gcc.target/i386/pr88828-5b.c: Likewise.
> > > * gcc.target/i386/pr88828-6a.c: Likewise.
> > > * gcc.target/i386/pr88828-6b.c: Likewise.
> >
> > Here is the updated patch with run-time tests.
>
> -  if (TREE_CODE (elt->value) != SSA_NAME)
> +  if (TREE_CODE (ce->value) != SSA_NAME)
> return false;
>
> hmm, so it doesn't allow { 0, v[1], v[2], v[3] }?  I think the single
> scalar value can be a constant as well.

Fixed.

>if (!def_stmt)
> -   return false;
> +   {
> + if (gimple_nop_p (SSA_NAME_DEF_STMT (ce->value)))
>
> if (SSA_NAME_IS_DEFAULT_DEF (ce->value))
>
> +   {
>
> also you seem to disallow
>
>   { i + 1, v[1], v[2], v[3] }

Fixed by

 if (code != BIT_FIELD_REF)
{
  /* Only allow one scalar insert.  */
  if (nscalars != 0)
return false;

  nscalars = 1;
  insert = true;
  scalar_idx = i;
  sel.quick_push (i);
  scalar_element = ce->value;
  continue;
}

> because get_prop_source_stmt will return the definition computing
> i + 1 in this case and your code will be skipped?
>
> I think you can simplify the code by treating scalar_element != NULL
> as nscalars == 1 and eliding nscalars.

It works only if

TYPE_VECTOR_SUBPARTS (type).to_constant ()  == (nscalars + nvectors)

We need to check both nscalars and nvectors.  Elide nscalar
check doesn't help much here.

> -  if (conv_code == ERROR_MARK)
> +  if (conv_code == ERROR_MARK && !insert)
> gimple_assign_set_rhs_with_ops (gsi, VEC_PERM_EXPR, orig[0],
> orig[1], op2);
>else
> @@ -2148,10 +2198,25 @@ simplify_vector_constructor (gimple_stmt_iterator 
> *gsi)
>VEC_PERM_EXPR, orig[0], orig[1], op2);
>   orig[0] = gimple_assign_lhs (perm);
>   gsi_insert_before (gsi, perm, GSI_SAME_STMT);
> - gimple_assign_set_rhs_with_ops (gsi, conv_code, orig[0],
> + gimple_assign_set_rhs_with_ops (gsi,
> + (conv_cod

Re: [PATCH] Add missing avx512fintrin.h intrinsics (PR target/89602)

2019-03-06 Thread Uros Bizjak
On Thu, Mar 7, 2019 at 12:49 AM Jakub Jelinek  wrote:
>
> Hi!
>
> The following patch adds vmovss/vmovsd masked intrinsics.
> On
> #include 
> __m128 f1 (__m128 w, __mmask8 u, const float *p) { return _mm_mask_load_ss 
> (w, u, p); }
> __m128 f2 (__mmask8 u, const float *p) { return _mm_maskz_load_ss (u, p); }
> __m128d f3 (__m128d w, __mmask8 u, const double *p) { return _mm_mask_load_sd 
> (w, u, p); }
> __m128d f4 (__mmask8 u, const double *p) { return _mm_maskz_load_sd (u, p); }
> __m128 f5 (__m128 w, __mmask8 u, __m128 a, __m128 b) { return 
> _mm_mask_move_ss (w, u, a, b); }
> __m128 f6 (__mmask8 u, __m128 a, __m128 b) { return _mm_maskz_move_ss (u, a, 
> b); }
> __m128d f7 (__m128d w, __mmask8 u, __m128d a, __m128d b) { return 
> _mm_mask_move_sd (w, u, a, b); }
> __m128d f8 (__mmask8 u, __m128d a, __m128d b) { return _mm_maskz_move_sd (u, 
> a, b); }
> void f9 (float *p, __mmask8 u, __m128 a) { _mm_mask_store_ss (p, u, a); }
> void f10 (double *p, __mmask8 u, __m128d a) { _mm_mask_store_sd (p, u, a); }
> it generates the same assembly with -O2 -mavx512f as icc 19 or clang trunk.
> It mostly does a good job also when the mask is constant, on the above
> testcase with u arguments replaced with 1 I get:
> f1: vmovss (%rsi), %xmm0
> f2: vmovss (%rsi), %xmm0
> f3: vmovq (%rsi), %xmm0
> f4: movzbl .LC0(%rip), %eax; kmovw %eax, %k1; vmovsd (%rsi), %xmm0{%k1}{z}
> f5: vmovss %xmm2, %xmm1, %xmm0
> f6: vmovss %xmm1, %xmm0, %xmm0
> f7: vmovsd %xmm2, %xmm1, %xmm0
> f8: vmovsd %xmm1, %xmm0, %xmm0
> f9: vmovss %xmm0, (%rdi)
> f10: vmovlpd %xmm0, (%rdi)
> Except for f4 that looks reasonable to me (and as tested in the testsuite
> works too), for f4 guess either we need to improve simplify-rtx.c or add
> some pattern for the combiner.  Can handle that as follow-up.
> When instead using 0 mask, I get:
> f1: kxorw %k1, %k1, %k1; vmovss (%rsi), %xmm0{%k1}
> f2: vxorps %xmm0, %xmm0, %xmm0
> f3: kxorw %k1, %k1, %k1; vmovsd (%rsi), %xmm0{%k1}
> f4: vxorpd %xmm0, %xmm0, %xmm0
> f5: vmovss %xmm0, %xmm1, %xmm0
> f6: kxorw %k1, %k1, %k1; vmovss %xmm1, %xmm0, %xmm0{%k1}{z}
> f7: vmovsd %xmm0, %xmm1, %xmm0
> f8: kxorw %k1, %k1, %k1; vmovsd %xmm1, %xmm0, %xmm0{%k1}{z}
> f9: nothing
> f10: nothing
> which looks good to me.  For f1/f3/f6/f8, I really have no idea if there is
> some single insn that could do that kind of operation.  This is also tested
> at runtime in the testsuite.
>
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
>
> 2019-03-07  Jakub Jelinek  
>
> PR target/89602
> * config/i386/sse.md (avx512f_mov_mask,
> *avx512f_load_mask, avx512f_store_mask): New define_insns.
> (avx512f_load_mask): New define_expand.
> * config/i386/i386-builtin.def (__builtin_ia32_loadsd_mask,
> __builtin_ia32_loadss_mask, __builtin_ia32_storesd_mask,
> __builtin_ia32_storess_mask, __builtin_ia32_movesd_mask,
> __builtin_ia32_movess_mask): New builtins.
> * config/i386/avx512fintrin.h (_mm_mask_load_ss, _mm_maskz_load_ss,
> _mm_mask_load_sd, _mm_maskz_load_sd, _mm_mask_move_ss,
> _mm_maskz_move_ss, _mm_mask_move_sd, _mm_maskz_move_sd,
> _mm_mask_store_ss, _mm_mask_store_sd): New intrinsics.
>
> * gcc.target/i386/avx512f-vmovss-1.c: New test.
> * gcc.target/i386/avx512f-vmovss-2.c: New test.
> * gcc.target/i386/avx512f-vmovss-3.c: New test.
> * gcc.target/i386/avx512f-vmovsd-1.c: New test.
> * gcc.target/i386/avx512f-vmovsd-2.c: New test.
> * gcc.target/i386/avx512f-vmovsd-3.c: New test.
>
> --- gcc/config/i386/sse.md.jj   2019-02-20 23:40:17.119140235 +0100
> +++ gcc/config/i386/sse.md  2019-03-06 19:15:12.379749161 +0100
> @@ -1151,6 +1151,67 @@ (define_insn "_load_mask"
> (set_attr "memory" "none,load")
> (set_attr "mode" "")])
>
> +(define_insn "avx512f_mov_mask"
> +  [(set (match_operand:VF_128 0 "register_operand" "=v")
> +   (vec_merge:VF_128
> + (vec_merge:VF_128
> +   (match_operand:VF_128 2 "register_operand" "v")
> +   (match_operand:VF_128 3 "nonimm_or_0_operand" "0C")
> +   (match_operand:QI 4 "register_operand" "Yk"))
> + (match_operand:VF_128 1 "register_operand" "v")
> + (const_int 1)))]
> +  "TARGET_AVX512F"
> +  "vmov\t{%2, %1, %0%{%4%}%N3|%0%{%4%}%N3, %1, %2}"
> +  [(set_attr "type" "ssemov")
> +   (set_attr "prefix" "evex")
> +   (set_attr "mode" "")])
> +
> +(define_expand "avx512f_load_mask"
> +  [(set (match_operand: 0 "register_operand")
> +   (vec_merge:
> + (vec_merge:
> +   (vec_duplicate:
> + (match_operand:MODEF 1 "memory_operand"))
> +   (match_operand: 2 "nonimm_or_0_operand")
> +   (match_operand:QI 3 "nonmemory_operand"))
> + (match_dup 4)
> + (const_int 1)))]
> +  "TARGET_AVX512F"
> +  "operands[4] = CONST0_RTX (mode);")
> +
> +(define_insn "*avx512f_load_mask"
> +  [(set (match_operand: 0 "register_operand" "=v")
>