Re: [PATCH 1/3, v2] rs6000: Add base support and types for defining MMA built-ins.

2020-06-19 Thread Segher Boessenkool
On Fri, Jun 19, 2020 at 02:43:36PM -0500, Peter Bergner wrote:
> Heh, now I'm not so sure after reading the comment before the test. :-)
> Mike added this code.
> 
> Mike, it looks like you explicitly added XImode here, even though we
> will never generate XImode uses.  Is there some code somewhere that
> requires an integer mode and it's associated partial integer mode to
> have the same registers and if they don't, something won't work right?
> Meaning, is there some reason I shouldn't remove the XImode use here?
> 
> Ditto for OImode and PImode.

If you need to keep it, please add a comment explaining why?


Segher


Re: [PATCH] Handle TYPE_PACK_EXPANSION in cxx_incomplete_type_diagnostic

2020-06-19 Thread Jason Merrill via Gcc-patches

On 6/19/20 2:39 PM, Nicholas Krause wrote:

This fixs the PR95672 by adding the missing TYPE_PACK_EXPANSION case in
cxx_incomplete_type_diagnostic in order to avoid ICES on diagnosing
incomplete template pack expansion cases.
Signed-off-by: Nicholas Krause 

Changelog:
*cp/type2ck.c: Add missing case TYPE_PACK_EXPANSION for diagnosticing


The filename is misspelled here; git gcc-verify would catch that for you.

"diagnosing".


incomplete parameter pack expansion in cxx_incomplete_type_diagnostic
in order to avoid ICEing here.



---
  gcc/cp/typeck2.c | 5 +
  1 file changed, 5 insertions(+)

diff --git a/gcc/cp/typeck2.c b/gcc/cp/typeck2.c
index 5fd3b82..dc5bd5e 100644
--- a/gcc/cp/typeck2.c
+++ b/gcc/cp/typeck2.c
@@ -552,6 +552,11 @@ cxx_incomplete_type_diagnostic (location_t loc, const_tree 
value,
   TYPE_NAME (type));
break;
  
+case TYPE_PACK_EXPANSION:

+ emit_diagnostic(diag_kind, loc, 0,


Space before (.


+"invalid expansion of template expansion parameter %qT",


Let's just say "invalid use of pack expansion", there's no parameter here.


+ PACK_EXPANSION_PATTERN(type));


Space before (.


+  break;


Blank line after break.


  case TYPENAME_TYPE:
  case DECLTYPE_TYPE:
emit_diagnostic (diag_kind, loc, 0,



You also need to include the testcase in your patch.

Thanks,
Jason



[PATCH] simplify-rtx: Two easy pieces.

2020-06-19 Thread Roger Sayle

My recent patch to add scalar integer simplification unit tests to 
simplify_rtx_c_tests
identified two "trivial" corner cases that could be improved in simplify-rtx.c.
I don't believe that either case can currently be triggered from GCC current
front-end/back-end combinations, but hopefully the reviewer agrees these
changes are simple/safe enough.

Although it makes no sense to ever see a BImode ROTATE, the current ordering
of transformations in simplify_binary_operation_1 converts (rotate:bi (reg:bi) 
0) to
(rotatert:bi (reg:bi) 1), which then doesn't get simplified away.  Rather than 
teach
the middle-end that any hypothetical ROTATE or ROTATERT of a BImode value is a
no-op, a more realistic invariant is that any rotate by const0_rtx is already 
canonical.

Optimizing "parity of parity" matches the tree constant folding transformation 
pending
review.  Alas, the only mentions of PARITY in GCC's official backend machine 
descriptions
are in expanders, so the middle-end's RTL optimizers never see a PARITY to 
simplify.
A test can be added to test_scalar_int_ops once that patch is reviewed/approved.

This patch has been tested with "make bootstrap" and "make -k check"
on x86_64-pc-linux-gnu with no regressions.


2020-06-19  Roger Sayle  

* simplify-rtx.c (simplify_unary_operation_1): Simplify
(parity (parity x)) as (parity x), i.e. PARITY is idempotent.
(simplify_binary_operation_1): Don't canonicalize rotations
by zero bits, these get simplified away.


Thanks in advance,
Roger
--
Roger Sayle
NextMove Software
Cambridge, UK

diff --git a/gcc/simplify-rtx.c b/gcc/simplify-rtx.c
index 28c2dc6..b856b02 100644
--- a/gcc/simplify-rtx.c
+++ b/gcc/simplify-rtx.c
@@ -1391,6 +1391,10 @@ simplify_unary_operation_1 (enum rtx_code code, 
machine_mode mode, rtx op)
   GET_MODE (XEXP (op, 0)));
  break;
 
+   case PARITY:
+ /* (parity (parity x)) -> parity (x).  */
+ return op;
+
default:
  break;
}
@@ -3649,7 +3653,8 @@ simplify_binary_operation_1 (enum rtx_code code, 
machine_mode mode,
   if (CONST_INT_P (trueop1)
  && IN_RANGE (INTVAL (trueop1),
   GET_MODE_UNIT_PRECISION (mode) / 2 + (code == ROTATE),
-  GET_MODE_UNIT_PRECISION (mode) - 1))
+  GET_MODE_UNIT_PRECISION (mode) - 1)
+ && trueop1 != CONST0_RTX (mode))
{
  int new_amount = GET_MODE_UNIT_PRECISION (mode) - INTVAL (trueop1);
  rtx new_amount_rtx = gen_int_shift_amount (mode, new_amount);


Re: [PATCH 1/3, v2] rs6000: Add base support and types for defining MMA built-ins.

2020-06-19 Thread Peter Bergner via Gcc-patches
On 6/19/20 2:33 PM, Peter Bergner wrote:
> On 6/19/20 1:12 PM, Segher Boessenkool wrote:
>> On Fri, Jun 19, 2020 at 11:47:35AM -0500, Peter Bergner wrote:
 Why are OImode and XImode handled here?

>  static bool
>  rs6000_modes_tieable_p (machine_mode mode1, machine_mode mode2)
>  {
>>>
>>> Do you mean why *aren't* they handled in rs6000_modes_tieable_p?
>>
>> No, this is a comment about the stuff above my comment, so
>>
>>> +  /* MMA accumulator modes need FPR registers divisible by 4.  We need to 
>>> allow
>>> + XImode to have the same registers as PXImode, even though we do not 
>>> enable
>>> + the move pattern for XImode.  */
>>> +  if (mode == PXImode || mode == XImode)
>>> +return (TARGET_MMA && FP_REGNO_P (regno) && (regno & 3) == 0);

Heh, now I'm not so sure after reading the comment before the test. :-)
Mike added this code.

Mike, it looks like you explicitly added XImode here, even though we
will never generate XImode uses.  Is there some code somewhere that
requires an integer mode and it's associated partial integer mode to
have the same registers and if they don't, something won't work right?
Meaning, is there some reason I shouldn't remove the XImode use here?

Ditto for OImode and PImode.

Peter




Re: [PATCH 1/3, v2] rs6000: Add base support and types for defining MMA built-ins.

2020-06-19 Thread Peter Bergner via Gcc-patches
On 6/19/20 1:12 PM, Segher Boessenkool wrote:
> On Fri, Jun 19, 2020 at 11:47:35AM -0500, Peter Bergner wrote:
>>> Why are OImode and XImode handled here?
>>>
  static bool
  rs6000_modes_tieable_p (machine_mode mode1, machine_mode mode2)
  {
>>
>> Do you mean why *aren't* they handled in rs6000_modes_tieable_p?
> 
> No, this is a comment about the stuff above my comment, so
> 
>> +  /* MMA accumulator modes need FPR registers divisible by 4.  We need to 
>> allow
>> + XImode to have the same registers as PXImode, even though we do not 
>> enable
>> + the move pattern for XImode.  */
>> +  if (mode == PXImode || mode == XImode)
>> +return (TARGET_MMA && FP_REGNO_P (regno)
>> +&& (regno & 3) == 0);
> 
> and the one with
> 
>> +  if (mode == POImode || mode == OImode)
> 
> before it.

Ah, ok.  Yeah, I think that was an oversight and we shouldn't need those.
I'll remove them.



>>> Same for the CCFP one here.
>>
>> Mike added those.  I guess I thought they were needed.  Mike?
>> If they're not needed for MMA, I'll remove them from this patch
>> and they be submitted in a separate patch if they are needed for
>> something else.
> 
> You can keep them, it's compiler debug only, but the changelog should
> mention it (it looks like an accident now, which maybe it was ;-) )

Ok, I'll add a changelog entry for them then...unless Mike comes back
before my testing is done and says we don't need them at all.

Peter





[committed] libstdc++: Fix some -Wsystem-headers warnings (PR 95765)

2020-06-19 Thread Jonathan Wakely via Gcc-patches
PR libstdc++/95765
* include/bits/stl_algobase.h (__size_to_integer(float))
(__size_to_integer(double), __size_to_integer(long double))
(__size_to_integer(__float128)): Cast return type explicitly.
* include/bits/stl_uninitialized.h (__uninitialized_default_1):
Remove unused typedef.

Tested powerpc64le-linux, committed to master.


commit 5b6215083bd6a3e10dd142e1c5d4fab011d6f074
Author: Jonathan Wakely 
Date:   Fri Jun 19 18:15:15 2020 +0100

libstdc++: Fix some -Wsystem-headers warnings (PR 95765)

PR libstdc++/95765
* include/bits/stl_algobase.h (__size_to_integer(float))
(__size_to_integer(double), __size_to_integer(long double))
(__size_to_integer(__float128)): Cast return type explicitly.
* include/bits/stl_uninitialized.h 
(__uninitialized_default_1):
Remove unused typedef.

diff --git a/libstdc++-v3/include/bits/stl_algobase.h 
b/libstdc++-v3/include/bits/stl_algobase.h
index 41dd740d34a..4fc8850d707 100644
--- a/libstdc++-v3/include/bits/stl_algobase.h
+++ b/libstdc++-v3/include/bits/stl_algobase.h
@@ -1039,14 +1039,14 @@ _GLIBCXX_END_NAMESPACE_CONTAINER
 #endif
 
   inline _GLIBCXX_CONSTEXPR long long
-  __size_to_integer(float __n) { return __n; }
+  __size_to_integer(float __n) { return (long long)__n; }
   inline _GLIBCXX_CONSTEXPR long long
-  __size_to_integer(double __n) { return __n; }
+  __size_to_integer(double __n) { return (long long)__n; }
   inline _GLIBCXX_CONSTEXPR long long
-  __size_to_integer(long double __n) { return __n; }
+  __size_to_integer(long double __n) { return (long long)__n; }
 #if !defined(__STRICT_ANSI__) && defined(_GLIBCXX_USE_FLOAT128)
   inline _GLIBCXX_CONSTEXPR long long
-  __size_to_integer(__float128 __n) { return __n; }
+  __size_to_integer(__float128 __n) { return (long long)__n; }
 #endif
 
   template
diff --git a/libstdc++-v3/include/bits/stl_uninitialized.h 
b/libstdc++-v3/include/bits/stl_uninitialized.h
index b5248fd49ea..a3ccb72078b 100644
--- a/libstdc++-v3/include/bits/stl_uninitialized.h
+++ b/libstdc++-v3/include/bits/stl_uninitialized.h
@@ -553,9 +553,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 static void
 __uninit_default(_ForwardIterator __first, _ForwardIterator __last)
 {
- typedef typename iterator_traits<_ForwardIterator>::value_type
-   _ValueType;
-
  if (__first == __last)
return;
 


[PATCH] Handle TYPE_PACK_EXPANSION in cxx_incomplete_type_diagnostic

2020-06-19 Thread Nicholas Krause via Gcc-patches
This fixs the PR95672 by adding the missing TYPE_PACK_EXPANSION case in
cxx_incomplete_type_diagnostic in order to avoid ICES on diagnosing
incomplete template pack expansion cases.
Signed-off-by: Nicholas Krause 

Changelog:
*cp/type2ck.c: Add missing case TYPE_PACK_EXPANSION for diagnosticing
incomplete parameter pack expansion in cxx_incomplete_type_diagnostic
in order to avoid ICEing here.
---
 gcc/cp/typeck2.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/gcc/cp/typeck2.c b/gcc/cp/typeck2.c
index 5fd3b82..dc5bd5e 100644
--- a/gcc/cp/typeck2.c
+++ b/gcc/cp/typeck2.c
@@ -552,6 +552,11 @@ cxx_incomplete_type_diagnostic (location_t loc, const_tree 
value,
   TYPE_NAME (type));
   break;
 
+case TYPE_PACK_EXPANSION:
+ emit_diagnostic(diag_kind, loc, 0,
+"invalid expansion of template expansion parameter %qT",
+ PACK_EXPANSION_PATTERN(type));
+  break;
 case TYPENAME_TYPE:
 case DECLTYPE_TYPE:
   emit_diagnostic (diag_kind, loc, 0,
-- 
1.8.3.1



Re: [PATCH 1/3, v2] rs6000: Add base support and types for defining MMA built-ins.

2020-06-19 Thread Segher Boessenkool
Hi!

On Fri, Jun 19, 2020 at 11:47:35AM -0500, Peter Bergner wrote:
> >>(define_mode_iterator RELOAD): Add POI and PXI.
> > 
> > Why POI and PXI, but not OI and XI?
> 
> We don't have an enabled XI or OI move pattern, so I don't think
> we'll ever see those modes at all in rtl.

Yeah good point.  And the OI/XI move expanders are probably enough to
diagnose that if ever it does go wrong.

> >> +;; Define a disabled OImode move pattern, so we can use POImode.
> >> +(define_expand "movoi"
> >> +  [(set (match_operand:OI 0 "nonimmediate_operand")
> >> +  (match_operand:OI 1 "input_operand"))]
> >> +  "0"
> >> +{
> >> +  gcc_unreachable ();
> >> +})
> > 
> > So dirty, I love it :-)
> 
> Heh, credit to Mike on this one.

Thanks Mike :-)

> > Why are OImode and XImode handled here?
> > 
> >>  static bool
> >>  rs6000_modes_tieable_p (machine_mode mode1, machine_mode mode2)
> >>  {
> 
> Do you mean why *aren't* they handled in rs6000_modes_tieable_p?

No, this is a comment about the stuff above my comment, so

> +  /* MMA accumulator modes need FPR registers divisible by 4.  We need to 
> allow
> + XImode to have the same registers as PXImode, even though we do not 
> enable
> + the move pattern for XImode.  */
> +  if (mode == PXImode || mode == XImode)
> +return (TARGET_MMA && FP_REGNO_P (regno)
> + && (regno & 3) == 0);

and the one with

> +  if (mode == POImode || mode == OImode)

before it.

> Ok, changed.  Let me know if you want me to also add OImode and XImode
> there too.

No, not handling those anywhere is fine, but let's be consistent then :-)

> > Well, it is debug info only, so not really interesting, but heh.
> > 
> >> @@ -2220,9 +2243,14 @@ rs6000_debug_reg_global (void)
> >>  V2DFmode,
> >>  V8SFmode,
> >>  V4DFmode,
> >> +OImode,
> >> +XImode,
> >> +POImode,
> >> +PXImode,
> >>  CCmode,
> >>  CCUNSmode,
> >>  CCEQmode,
> >> +CCFPmode,
> >>};
> > 
> > Same for the CCFP one here.
> 
> Mike added those.  I guess I thought they were needed.  Mike?
> If they're not needed for MMA, I'll remove them from this patch
> and they be submitted in a separate patch if they are needed for
> something else.

You can keep them, it's compiler debug only, but the changelog should
mention it (it looks like an accident now, which maybe it was ;-) )


Segher


Re: [PATCH 2/3, v2] rs6000: Add MMA built-in function definitions

2020-06-19 Thread Peter Bergner via Gcc-patches
On 6/19/20 11:45 AM, Segher Boessenkool wrote:
> On Thu, Jun 18, 2020 at 03:45:17PM -0500, Peter Bergner wrote:
>> +;; Return 1 if this operand is valid for a MMA assemble accumulator insn.
>> +(define_special_predicate "mma_input_operand"
>> +  (match_test "(mode == PXImode
>> +&& (GET_MODE (op) == V16QImode)
>> +&& (vsx_register_operand (op, GET_MODE (op)) || MEM_P (op)))"))
> 
> Maybe the name could be better, then?  "mma_assemble_input_operand"?

Yes, that's a better name.  Changed.


>> +  else if ((fnmask & RS6000_BTM_FUTURE) != 0)
>> +error ("%qs requires the %qs option", name, "-mcpu=future");
> 
> In the future, please send such pieces in a separate patch?

Ok.  I'm actually surprised this wasn't added as part of the
initial -mcpu=future patch that went in a while ago.



>> @@ -9944,7 +9944,8 @@ rs6000_emit_move (rtx dest, rtx source, machine_mode 
>> mode)
>>  
>>  case E_POImode:
>>  case E_PXImode:
>> -  if (CONSTANT_P (operands[1]))
>> +  if (CONSTANT_P (operands[1])
>> +  && INTVAL (operands[1]) != 0)
>>  error ("%qs is an opaque type, and you can't set it to other values.",
>> (mode == POImode) ? "__vector_pair" : "__vector_quad");
> 
> Put that condition on just one line please?  CONSTANT_P might not be
> good enough if you want do use INTVAL btw, CONST_INT_P is clearer and/or
> more correct.

Ok, I'll make those changes.



>> +(define_insn_and_split "*mma_assemble_acc"
>> +  [(set (match_operand:PXI 0 "fpr_reg_operand" "=d")
>> +(unspec:PXI [(match_operand:PXI 1 "mma_input_operand" "mwa")
>> + (match_operand:PXI 2 "mma_input_operand" "mwa")
>> + (match_operand:PXI 3 "mma_input_operand" "mwa")
>> + (match_operand:PXI 4 "mma_input_operand" "mwa")]
>> + UNSPEC_MMA_ASSEMBLE_ACC))]
> 
> I would expect all those four last match_operand to be :V16QI, so why
> does it use this strange mode?

Must be a cut/paste error and probably why we saw mode == PXImode
in the mma_input_operand predicate.  I'll change that and the
predicate and retest.  Thanks for pointing that out!


> Anyway, okay for trunk.  Thanks!  Thanks to all who worked on this, it
> was a painful trip getting to here.

Thanks for the review!

Peter




Re: [PATCH 3/3, v2] rs6000: Add testsuite test cases for MMA built-ins.

2020-06-19 Thread Segher Boessenkool
Hi!

On Thu, Jun 18, 2020 at 03:46:31PM -0500, Peter Bergner wrote:
> +/* { dg-final { scan-assembler-times {\mlxv\M} 40 } } */
> +/* { dg-final { scan-assembler-times {\mlxvp\M} 12 } } */
> +/* { dg-final { scan-assembler-times {\mstxvp\M} 40 } } */
> +/* { dg-final { scan-assembler-times {\mxxmfacc\M} 20 } } */
> +/* { dg-final { scan-assembler-times {\mxxmtacc\M} 6 } } */
> +/* { dg-final { scan-assembler-times {\mxvbf16ger2\M} 1 } } */
> +/* { dg-final { scan-assembler-times {\mxvbf16ger2nn\M} 1 } } */
> +/* { dg-final { scan-assembler-times {\mxvbf16ger2np\M} 1 } } */
> +/* { dg-final { scan-assembler-times {\mxvbf16ger2pn\M} 1 } } */
> +/* { dg-final { scan-assembler-times {\mxvbf16ger2pp\M} 1 } } */
> +/* { dg-final { scan-assembler-times {\mxvf16ger2\M} 1 } } */
> +/* { dg-final { scan-assembler-times {\mxvf16ger2nn\M} 1 } } */
> +/* { dg-final { scan-assembler-times {\mxvf16ger2np\M} 1 } } */
> +/* { dg-final { scan-assembler-times {\mxvf16ger2pn\M} 1 } } */
> +/* { dg-final { scan-assembler-times {\mxvf16ger2pp\M} 1 } } */
> +/* { dg-final { scan-assembler-times {\mxvf32ger\M} 1 } } */
> +/* { dg-final { scan-assembler-times {\mxvf32gernn\M} 1 } } */
> +/* { dg-final { scan-assembler-times {\mxvf32gernp\M} 1 } } */
> +/* { dg-final { scan-assembler-times {\mxvf32gerpn\M} 1 } } */
> +/* { dg-final { scan-assembler-times {\mxvf32gerpp\M} 1 } } */
> +/* { dg-final { scan-assembler-times {\mxvi16ger2\M} 1 } } */
> +/* { dg-final { scan-assembler-times {\mxvi16ger2pp\M} 1 } } */
> +/* { dg-final { scan-assembler-times {\mxvi16ger2s\M} 1 } } */
> +/* { dg-final { scan-assembler-times {\mxvi16ger2spp\M} 1 } } */
> +/* { dg-final { scan-assembler-times {\mxvi4ger8\M} 1 } } */
> +/* { dg-final { scan-assembler-times {\mxvi4ger8pp\M} 1 } } */
> +/* { dg-final { scan-assembler-times {\mxvi8ger4\M} 1 } } */
> +/* { dg-final { scan-assembler-times {\mxvi8ger4pp\M} 1 } } */
> +/* { dg-final { scan-assembler-times {\mxvi8ger4spp\M} 1 } } */
> +/* { dg-final { scan-assembler-times {\mpmxvbf16ger2\M} 1 } } */
> +/* { dg-final { scan-assembler-times {\mpmxvbf16ger2nn\M} 1 } } */
> +/* { dg-final { scan-assembler-times {\mpmxvbf16ger2np\M} 1 } } */
> +/* { dg-final { scan-assembler-times {\mpmxvbf16ger2pn\M} 1 } } */
> +/* { dg-final { scan-assembler-times {\mpmxvbf16ger2pp\M} 1 } } */
> +/* { dg-final { scan-assembler-times {\mpmxvf16ger2\M} 1 } } */
> +/* { dg-final { scan-assembler-times {\mpmxvf16ger2nn\M} 1 } } */
> +/* { dg-final { scan-assembler-times {\mpmxvf16ger2np\M} 1 } } */
> +/* { dg-final { scan-assembler-times {\mpmxvf16ger2pn\M} 1 } } */
> +/* { dg-final { scan-assembler-times {\mpmxvf16ger2pp\M} 1 } } */
> +/* { dg-final { scan-assembler-times {\mpmxvf32ger\M} 1 } } */
> +/* { dg-final { scan-assembler-times {\mpmxvf32gernn\M} 1 } } */
> +/* { dg-final { scan-assembler-times {\mpmxvf32gernp\M} 1 } } */
> +/* { dg-final { scan-assembler-times {\mpmxvf32gerpn\M} 1 } } */
> +/* { dg-final { scan-assembler-times {\mpmxvf32gerpp\M} 1 } } */
> +/* { dg-final { scan-assembler-times {\mpmxvi16ger2\M} 1 } } */
> +/* { dg-final { scan-assembler-times {\mpmxvi16ger2pp\M} 1 } } */
> +/* { dg-final { scan-assembler-times {\mpmxvi16ger2s\M} 1 } } */
> +/* { dg-final { scan-assembler-times {\mpmxvi16ger2spp\M} 1 } } */
> +/* { dg-final { scan-assembler-times {\mpmxvi4ger8\M} 1 } } */
> +/* { dg-final { scan-assembler-times {\mpmxvi4ger8pp\M} 1 } } */
> +/* { dg-final { scan-assembler-times {\mpmxvi8ger4\M} 1 } } */
> +/* { dg-final { scan-assembler-times {\mpmxvi8ger4pp\M} 1 } } */
> +/* { dg-final { scan-assembler-times {\mpmxvi8ger4spp\M} 1 } } */

Nowhere does it say how many of which insns are expected in which of the
twenty-odd functions, so this can become a maintenance nightmare.  If
anything ever changes, and it will be *your* nightmare anyway ;-)

Okay for trunk.  Thanks!


Segher


Re: [PATCH 1/3, v2] rs6000: Add base support and types for defining MMA built-ins.

2020-06-19 Thread Peter Bergner via Gcc-patches
On 6/18/20 6:44 PM, Segher Boessenkool wrote:
>>  (rs6000_builtin_mask_calculate): Add support for RS6000_BTM_MMA
>>  and RS6000_BTM_FUTURE.
> The latter is already there?

Oops, yes.  I'll remove it.



>>  * config/rs6000/rs6000.md (define_attr "isa"): Add mma.
> 
> Is this ever useful?  Please leave it out if not.  The "isa" things
> are only for when some insn alternatives are available only one some
> configurations and not others (not for when the whole pattern is not
> valid).

I think I added it back when we had a "pair" isa attribute and I
think I thought I needed it then.  I think you are correct that
we don't need it now.  I'll remove it.



>>  (define_mode_iterator RELOAD): Add POI and PXI.
> 
> Why POI and PXI, but not OI and XI?

We don't have an enabled XI or OI move pattern, so I don't think
we'll ever see those modes at all in rtl.




>>  Include mma.md.
> 
> That looks to be about RELOAD, the way it is placed.  Maybe put it as
> the very first thing for this file, in the changelog?

Yo mean rewrite it like the following?
...
* config/rs6000/rs6000.md: Include mma.md.
(define_attr "isa"): Add mma.
(define_attr "enabled"): Handle mma.
(define_mode_iterator RELOAD): Add POI and PXI.
...

...or do you mean move the rs6000.md entry to be the first entry in the 
ChangeLog?



>> +;; cause byte swapping issues on litte-endian systems.  We don't need
>> +;; the XImode and OImode move patterns for actual code generation,
>> +;; therefor, we define the XImode and OImode move patterns, but we
>> +;; disable their use with a "false" condition flag.
> 
> "therefore".

Fixed.


>> +;; Define a disabled OImode move pattern, so we can use POImode.
>> +(define_expand "movoi"
>> +  [(set (match_operand:OI 0 "nonimmediate_operand")
>> +(match_operand:OI 1 "input_operand"))]
>> +  "0"
>> +{
>> +  gcc_unreachable ();
>> +})
> 
> So dirty, I love it :-)

Heh, credit to Mike on this one.




>> +(define_insn_and_split "*movpoi"
>> +  [(set (match_operand:POI 0 "nonimmediate_operand" "=wa,m,wa")
>> +(match_operand:POI 1 "input_operand""m,wa,wa"))]
> 
> Don't use tabs other than at the start of the line, please (or *maybe*
> in tables).

Fixed.  I just replaced it with one space to match the *movpxi pattern.



>> +;; Special pattern to prevent DSE from generating an internal error if it
>> +;; notices a structure copy that it wants to eliminate.  This generates 
>> pretty
>> +;; bad code, but at least it doesn't die.
>> +(define_insn_and_split "truncpoidi2"
> 
> Could you say *why*/*how* it prevents the ICE here?

This was added by Mike.  I didn't debug the issue.  Mike, do you have
some verbiage we could add here?




>> +  [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
>> +(truncate:DI (match_operand:POI 1 "gpc_reg_operand" "wa")))]
>> +  "TARGET_MMA"
>> +  "#"
>> +  "&& reload_completed"
>> +  [(set (match_dup 0)
>> +(vec_select:DI (match_dup 2)
>> +   (parallel [(match_dup 3)])))]
>> +{
>> +  unsigned r = reg_or_subregno (operands[1]) + !BYTES_BIG_ENDIAN;
> 
> Don't + booleans please (use ?: instead).
> 
>> +  operands[2] = gen_rtx_REG (V2DImode, r);
>> +  operands[3] = BYTES_BIG_ENDIAN ? const1_rtx : const0_rtx;
>> +})
> 
> So maybe just do an  if (BYTES_BIG_ENDIAN)  even, the arms simplify a
> bit then.

Like so?

  if (BYTES_BIG_ENDIAN)
{
  operands[2] = gen_rtx_REG (V2DImode, reg_or_subregno (operands[1]));
  operands[3] = const1_rtx;
}
  else
{
  operands[2] = gen_rtx_REG (V2DImode, reg_or_subregno (operands[1]) + 1);
  operands[3] = const0_rtx;
}





>> +;; Vector quad support.  PXImode is only defined for floating point 
>> registers.
> 
> Rephrase this?  A mode is defined without referring to registers at
> all ;-)  "PXImode can only live in FPRs", something like that?

Ok, I changed it to that.  I assume you want the same thing changed for POImode
too, so I modified its comment to "POImode can only live in VSRs.".



>> +  /* Vector pair modes need even/odd VSX register pairs.  Only allow vector
>> + registers.  We need to allow OImode to have the same registers as 
>> POImode,
>> + even though we do not enable the move pattern for OImode.  */
>> +  if (mode == POImode || mode == OImode)
>> +return (TARGET_MMA && VSX_REGNO_P (regno)
>> +&& (regno & 1) == 0);
> 
> Put it all one one line?
> 
>> +  /* MMA accumulator modes need FPR registers divisible by 4.  We need to 
>> allow
>> + XImode to have the same registers as PXImode, even though we do not 
>> enable
>> + the move pattern for XImode.  */
>> +  if (mode == PXImode || mode == XImode)
>> +return (TARGET_MMA && FP_REGNO_P (regno)
>> +&& (regno & 3) == 0);
> 
> Likewise.

Done.




> Why are OImode and XImode handled here?
> 
>>  static bool
>>  rs6000_modes_tieable_p (machine_mode mode1, machine_mode mode2)
>>  {

Do you mean why *aren't* they handled in 

Re: [PATCH 2/3, v2] rs6000: Add MMA built-in function definitions

2020-06-19 Thread Segher Boessenkool
Hi!

On Thu, Jun 18, 2020 at 03:45:17PM -0500, Peter Bergner wrote:
> +;; Return 1 if this operand is valid for a MMA assemble accumulator insn.
> +(define_special_predicate "mma_input_operand"
> +  (match_test "(mode == PXImode
> + && (GET_MODE (op) == V16QImode)
> + && (vsx_register_operand (op, GET_MODE (op)) || MEM_P (op)))"))

Maybe the name could be better, then?  "mma_assemble_input_operand"?

I don't see how mode is PXI but GET_MODE (op) is V16QI.  The actual
register is V16QI, but then it is used as if it was a PXI?  Is there no
better way to do this?  It certainly needs a comment, and a more specific
name, if you keep this like this.

> +BU_MMA_6 (PMXVI16GER2SPP,   "pmxvi16ger2spp",   QUAD, mma_pmxvi16ger2spp)

(I didn't check the large table, I'll just hope you did -- check against
the ISA and the builtins docs, etc. :-) )

> +  else if ((fnmask & RS6000_BTM_FUTURE) != 0)
> +error ("%qs requires the %qs option", name, "-mcpu=future");

In the future, please send such pieces in a separate patch?

> @@ -9944,7 +9944,8 @@ rs6000_emit_move (rtx dest, rtx source, machine_mode 
> mode)
>  
>  case E_POImode:
>  case E_PXImode:
> -  if (CONSTANT_P (operands[1]))
> +  if (CONSTANT_P (operands[1])
> +   && INTVAL (operands[1]) != 0)
>   error ("%qs is an opaque type, and you can't set it to other values.",
>  (mode == POImode) ? "__vector_pair" : "__vector_quad");

Put that condition on just one line please?  CONSTANT_P might not be
good enough if you want do use INTVAL btw, CONST_INT_P is clearer and/or
more correct.

> +(define_insn_and_split "*mma_assemble_acc"
> +  [(set (match_operand:PXI 0 "fpr_reg_operand" "=d")
> + (unspec:PXI [(match_operand:PXI 1 "mma_input_operand" "mwa")
> +  (match_operand:PXI 2 "mma_input_operand" "mwa")
> +  (match_operand:PXI 3 "mma_input_operand" "mwa")
> +  (match_operand:PXI 4 "mma_input_operand" "mwa")]
> +  UNSPEC_MMA_ASSEMBLE_ACC))]

I would expect all those four last match_operand to be :V16QI, so why
does it use this strange mode?

In general, many of the MMA insns play loose and fast with the modes.
This probably works fine, since everything is unspec, but eww :-)

Anyway, okay for trunk.  Thanks!  Thanks to all who worked on this, it
was a painful trip getting to here.


Segher


[pushed] c++: Allow defaulted comparison outside class.

2020-06-19 Thread Jason Merrill via Gcc-patches
Implementing P2085, another refinement to the operator<=> specification from
the Prague meeting.  It was deemed desirable to be able to have a non-inline
defaulted definition of a comparison operator just like you can with other
defaulted functions.

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

gcc/cp/ChangeLog:

* method.c (early_check_defaulted_comparison): Allow defaulting
comparison outside class.  Complain if non-member operator isn't a
friend.

gcc/testsuite/ChangeLog:

* g++.dg/cpp2a/spaceship-friend1.C: New test.
* g++.dg/cpp2a/spaceship-err4.C: Adjust diagnostic.
---
 gcc/cp/method.c   | 38 +--
 gcc/testsuite/g++.dg/cpp2a/spaceship-err4.C   |  6 +--
 .../g++.dg/cpp2a/spaceship-friend1.C  | 26 +
 3 files changed, 48 insertions(+), 22 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/cpp2a/spaceship-friend1.C

diff --git a/gcc/cp/method.c b/gcc/cp/method.c
index b23764b3d54..2a98907bfa1 100644
--- a/gcc/cp/method.c
+++ b/gcc/cp/method.c
@@ -1102,17 +1102,6 @@ early_check_defaulted_comparison (tree fn)
   return false;
 }
 
-  if (!ctx)
-{
-  if (DECL_OVERLOADED_OPERATOR_IS (fn, SPACESHIP_EXPR))
-   error_at (loc, "three-way comparison operator can only be defaulted "
- "in a class definition");
-  else
-   error_at (loc, "equality comparison operator can only be defaulted "
- "in a class definition");
-  return false;
-}
-
   if (!DECL_OVERLOADED_OPERATOR_IS (fn, SPACESHIP_EXPR)
   && !same_type_p (TREE_TYPE (TREE_TYPE (fn)), boolean_type_node))
 {
@@ -1146,16 +1135,27 @@ early_check_defaulted_comparison (tree fn)
   for (; parmnode != void_list_node; parmnode = TREE_CHAIN (parmnode))
 {
   tree parmtype = TREE_VALUE (parmnode);
-  if (same_type_p (parmtype, ctx))
+  if (CLASS_TYPE_P (parmtype))
saw_byval = true;
-  else if (TREE_CODE (parmtype) != REFERENCE_TYPE
-  || TYPE_REF_IS_RVALUE (parmtype)
-  || TYPE_QUALS (TREE_TYPE (parmtype)) != TYPE_QUAL_CONST
-  || !(same_type_ignoring_top_level_qualifiers_p
-   (TREE_TYPE (parmtype), ctx)))
-   saw_bad = true;
+  else if (TREE_CODE (parmtype) == REFERENCE_TYPE
+  && !TYPE_REF_IS_RVALUE (parmtype)
+  && TYPE_QUALS (TREE_TYPE (parmtype)) == TYPE_QUAL_CONST)
+   {
+ saw_byref = true;
+ parmtype = TREE_TYPE (parmtype);
+   }
   else
-   saw_byref = true;
+   saw_bad = true;
+
+  if (!saw_bad && !ctx)
+   {
+ /* Defaulted outside the class body.  */
+ ctx = TYPE_MAIN_VARIANT (parmtype);
+ if (!is_friend (ctx, fn))
+   error_at (loc, "defaulted %qD is not a friend of %qT", fn, ctx);
+   }
+  else if (!same_type_ignoring_top_level_qualifiers_p (parmtype, ctx))
+   saw_bad = true;
 }
 
   if (saw_bad || (saw_byval && saw_byref))
diff --git a/gcc/testsuite/g++.dg/cpp2a/spaceship-err4.C 
b/gcc/testsuite/g++.dg/cpp2a/spaceship-err4.C
index b044914bbfc..a39e5069957 100644
--- a/gcc/testsuite/g++.dg/cpp2a/spaceship-err4.C
+++ b/gcc/testsuite/g++.dg/cpp2a/spaceship-err4.C
@@ -2,6 +2,6 @@
 // { dg-do compile { target c++20 } }
 
 struct B {};
-bool operator!=(const B&, const B&) = default; // { dg-error "equality 
comparison operator can only be defaulted in a class definition" }
-bool operator==(const B&, const B&) = default; // { dg-error "equality 
comparison operator can only be defaulted in a class definition" }
-bool operator<=>(const B&, const B&) = default; // { dg-error "three-way 
comparison operator can only be defaulted in a class definition" }
+bool operator!=(const B&, const B&) = default; // { dg-error "not a friend" }
+bool operator==(const B&, const B&) = default; // { dg-error "not a friend" }
+bool operator<=>(const B&, const B&) = default; // { dg-error "not a friend" }
diff --git a/gcc/testsuite/g++.dg/cpp2a/spaceship-friend1.C 
b/gcc/testsuite/g++.dg/cpp2a/spaceship-friend1.C
new file mode 100644
index 000..24bbc74a2d1
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/spaceship-friend1.C
@@ -0,0 +1,26 @@
+// P2085, separate definition of defaulted comparisons
+// { dg-do compile { target c++20 } }
+
+namespace X {
+
+  struct A {
+int i;
+friend constexpr bool operator==(const A&,const A&);
+  };
+
+  inline constexpr bool operator==(const A&,const A&)=default;
+
+  static_assert (A() == A());
+
+}
+
+namespace Y {
+
+  struct A {
+int i;
+// friend bool operator==(const A&,const A&);
+  };
+
+  inline bool operator==(const A&,const A&)=default; // { dg-error "not a 
friend" }
+
+}

base-commit: 4cea81adabd7660838ebb3e59e8d28f820a3b789
-- 
2.18.1



Re: [Patch] amdgcn: Silence compile warnings

2020-06-19 Thread Andrew Stubbs

On 19/06/2020 17:00, Tobias Burnus wrote:

OK for mainline?


OK, thank you.

Andrew


Re: drop -aux{dir,base}, revamp -dump{dir,base}

2020-06-19 Thread Tobias Burnus

On 6/19/20 11:53 AM, Alexandre Oliva wrote:


Here's an incremental patch, on top of the one you kindly tested the
other day (thanks!), that attempts to introduce per-offload-target dump
name variation.

Could you possibly give it a spin with the offloading targets you've
got?


Done; nvptx compiled but for AMDGCN I got a compile error:
in one function 'argv_obstack' was lacking a 'cc_' prefix ('cc_argv_obstack'),
see attached patch (vs. mainline, not vs. either of your patches).

And there is an (unfixed) warning:
config/gcn/mkoffload.c:535:9: warning: unused variable 'dumpbase'

I additionally did run the test case manually → files.log for the
produced files.

Unfortunately, running the testsuite fails now with a tcl error:

ERROR: libgomp.oacc-c/../libgomp.oacc-c-c++-common/nvptx-merged-loop.c 
-DACC_DEVICE_TYPE_nvidia=1 -DACC_MEM_SHARED=0 -foffload=nvptx-none  -O2 : error executing 
dg-final: unknown or ambiguous subcommand "set": must be args, body, class, 
cmdcount, commands, complete, coroutine, default, errorstack, exists, frame, functions, 
globals, hostname, level, library, loaded, locals, nameofexecutable, object, patchlevel, 
procs, script, sharedlibextension, tclversion, or vars

Thanks,

Tobias

-
Mentor Graphics (Deutschland) GmbH, Arnulfstraße 201, 80634 München / Germany
Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Alexander 
Walter
-rw-r--r-- 1 tburnus dem  1579 Jun 19 08:17 nvptx-merged-loop.i
-rw-r--r-- 1 tburnus dem 10273 Jun 19 08:17 nvptx-merged-loop.s
-rw-r--r-- 1 tburnus dem  6992 Jun 19 08:17 nvptx-merged-loop.o
-rw-r--r-- 1 tburnus dem 2 Jun 19 08:17 nvptx-merged-loop.res
-rw-r--r-- 1 tburnus dem99 Jun 19 08:17 nvptx-merged-loop.lto_wrapper_args
-rw-r--r-- 1 tburnus dem  1443 Jun 19 08:17 nvptx-merged-loop.xnvptx-none.mkoffload.s
-rw-r--r-- 1 tburnus dem  1345 Jun 19 08:17 nvptx-merged-loop.xnvptx-none.mkoffload.o
-rw-r--r-- 1 tburnus dem 17060 Jun 19 08:17 nvptx-merged-loop.xnvptx-none.mkoffload.309r.mach
-rw-r--r-- 1 tburnus dem  1346 Jun 19 08:17 nvptx-merged-loop.xnvptx-none.mkoffload
-rw-r--r-- 1 tburnus dem  3002 Jun 19 08:17 nvptx-merged-loop.xnvptx-none.c
-rw-r--r-- 1 tburnus dem  3120 Jun 19 08:17 nvptx-merged-loop.xnvptx-none.i
-rw-r--r-- 1 tburnus dem  3227 Jun 19 08:17 nvptx-merged-loop.xnvptx-none.s
-rw-r--r-- 1 tburnus dem  4072 Jun 19 08:17 nvptx-merged-loop.xnvptx-none.o
-rwxr-xr-x 1 tburnus dem 17872 Jun 19 08:17 nvptx-merged-loop.exe

plus in /tmp:
-rw---  1 tburnus  dem   24 Jun 19 08:17 cctrysFw.ofldlist
-rw---  1 tburnus  dem  405 Jun 19 08:17 cclbqtZz
-rw---  1 tburnus  dem  290 Jun 19 08:17 ccKK2E3z
-rw---  1 tburnus  dem   22 Jun 19 08:17 ccEw89Sz
-rw---  1 tburnus  dem   44 Jun 19 08:17 ccFqM78R
-rw---  1 tburnus  dem  167 Jun 19 08:17 ccdiqRyS
-rw---  1 tburnus  dem 1648 Jun 19 08:17 ccjfEpIS.crtoffloadtable.o

And for AMDGCN:
-rw-r--r--  1 tburnus dem1517 Jun 19 08:25 nvptx-merged-loop.i
-rw-r--r--  1 tburnus dem   10227 Jun 19 08:25 nvptx-merged-loop.s
-rw-r--r--  1 tburnus dem6944 Jun 19 08:25 nvptx-merged-loop.o
-rw-r--r--  1 tburnus dem   2 Jun 19 08:25 nvptx-merged-loop.res
-rw-r--r--  1 tburnus dem  99 Jun 19 08:25 nvptx-merged-loop.lto_wrapper_args
-rw-r--r--  1 tburnus dem   10999 Jun 19 08:25 nvptx-merged-loop.xamdgcn-amdhsa.mkoffload.310r.mach
-rw-r--r--  1 tburnus dem2843 Jun 19 08:25 nvptx-merged-loop.xamdgcn-amdhsa.mkoffload.1.s
-rw-r--r--  1 tburnus dem2551 Jun 19 08:25 nvptx-merged-loop.xamdgcn-amdhsa.mkoffload.2.s
-rwxr-xr-x  1 tburnus dem   10248 Jun 19 08:25 nvptx-merged-loop.xamdgcn-amdhsa.mkoffload.hsaco
-rw-r--r--  1 tburnus dem   43672 Jun 19 08:25 nvptx-merged-loop.xamdgcn-amdhsa.c
-rw-r--r--  1 tburnus dem   67626 Jun 19 08:25 nvptx-merged-loop.xamdgcn-amdhsa.i
-rw-r--r--  1 tburnus dem   97925 Jun 19 08:25 nvptx-merged-loop.xamdgcn-amdhsa.s
drwxr-xr-x  7 tburnus dem   12288 Jun 19 08:25 .
-rw-r--r--  1 tburnus dem   13144 Jun 19 08:25 nvptx-merged-loop.xamdgcn-amdhsa.o
-rwxr-xr-x  1 tburnus dem   28152 Jun 19 08:25 nvptx-merged-loop.exe
diff --git a/gcc/config/gcn/mkoffload.c b/gcc/config/gcn/mkoffload.c
index 4a99d70..818e98c 100644
--- a/gcc/config/gcn/mkoffload.c
+++ b/gcc/config/gcn/mkoffload.c
@@ -41,6 +41,7 @@ static const char *gcn_s1_name;
 static const char *gcn_s2_name;
 static const char *gcn_o_name;
 static const char *gcn_cfile_name;
+static const char *gcn_dumpbase;
 
 enum offload_abi offload_abi = OFFLOAD_ABI_UNSET;
 
@@ -496,6 +497,12 @@ compile_native (const char *infile, const char *outfile, const char *compiler)
 obstack_ptr_grow (_obstack, "-save-temps");
   if (verbose)
 obstack_ptr_grow (_obstack, "-v");
+  obstack_ptr_grow (_obstack, "-dumpdir");
+  obstack_ptr_grow (_obstack, "");
+  obstack_ptr_grow (_obstack, "-dumpbase");
+  obstack_ptr_grow (_obstack, gcn_dumpbase);
+  obstack_ptr_grow (_obstack, "-dumpbase-ext");
+  obstack_ptr_grow 

[Patch] amdgcn: Silence compile warnings

2020-06-19 Thread Tobias Burnus

OK for mainline?

Tobias

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

gcc/ChangeLog:

	* config/gcn/gcn.c (gcn_related_vector_mode): Add ARG_UNUSED.
	(output_file_start): Use const 'char *'.

diff --git a/gcc/config/gcn/gcn.c b/gcc/config/gcn/gcn.c
index fff0e8c..b6ff0bb 100644
--- a/gcc/config/gcn/gcn.c
+++ b/gcc/config/gcn/gcn.c
@@ -4038,8 +4038,8 @@ gcn_vectorize_preferred_simd_mode (scalar_mode mode)
In particular, we do *not* want to match vector bit-size.  */
 
 static opt_machine_mode
-gcn_related_vector_mode (machine_mode vector_mode, scalar_mode element_mode,
-			 poly_uint64 nunits)
+gcn_related_vector_mode (machine_mode ARG_UNUSED (vector_mode),
+			 scalar_mode element_mode, poly_uint64 nunits)
 {
   if (known_ne (nunits, 0U) && known_ne (nunits, 64U))
 return VOIDmode;
@@ -4937,7 +4937,7 @@ gcn_fixup_accel_lto_options (tree fndecl)
 static void
 output_file_start (void)
 {
-  char *cpu;
+  const char *cpu;
   switch (gcn_arch)
 {
 case PROCESSOR_FIJI: cpu = "gfx803"; break;


Re: [PATCH] RISC-V: Fix compilation failed for frflags builtin in C++ mode

2020-06-19 Thread Jason Merrill via Gcc-patches

On 6/19/20 3:08 AM, Kito Cheng wrote:

   - g++ will complain too few arguments for frflags builtin like bellow
 message:

 error: too few arguments to function 'unsigned int 
__builtin_riscv_frflags(void)'

   - However it's no arguments needed, it because we declare the function
 type with VOID arguments, that seems like require a VOID argument
 in the c++ front-end when GCC tried to resolve the function.


Yes, G++ expects a parameter list to end with void_list_node 
specifically, not any TREE_LIST with void_type_node.



gcc/ChangeLog

* config/riscv/riscv-builtins.c (RISCV_FTYPE_NAME0): New.
(RISCV_FTYPE_ATYPES0): New.
(riscv_builtins): Using RISCV_USI_FTYPE for frflags.
* config/riscv/riscv-ftypes.def: Remove VOID argument.


You should also be able to remove


#define RISCV_ATYPE_VOID void_type_node


OK with that change.

Jason



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

2020-06-19 Thread Alex Coplan
> -Original Message-
> From: Gcc-patches  On Behalf Of Przemyslaw
> Wirkus
> Sent: 19 June 2020 15:06
> To: Richard Biener 
> Cc: gcc-patches@gcc.gnu.org; Marc Glisse 
> Subject: RE: [PATCH][GCC]: Fix for PR94880: Failure to recognize andn pattern
> 
> > From: Richard Biener 
> > Subject: Re: [PATCH][GCC]: Fix for PR94880: Failure to recognize andn
> > pattern
> 
> Snip...
> 
> > The patch is OK.
> 
> I do not have write access yet. Can I ask someone to push my patch to
> master please ?

Pushed to master (e0bfe016712ace877dd5b057bc1eb06e3c307623).

Thanks,
Alex

> 
> Thanks in advance,
> Przemyslaw


[wwwdocs] Fix typo in docs for Git write access

2020-06-19 Thread Jonathan Wakely via Gcc-patches
Committed to wwwdocs.


commit 2b70f89ff4df991b32d3680f56485470ec978bc6
Author: Jonathan Wakely 
Date:   Fri Jun 19 16:06:05 2020 +0100

Fix typo in docs for Git write access

diff --git a/htdocs/gitwrite.html b/htdocs/gitwrite.html
index 36bb1a20..5332e2f5 100644
--- a/htdocs/gitwrite.html
+++ b/htdocs/gitwrite.html
@@ -516,7 +516,7 @@ check the branch out locally.  You can do that afterwards 
with
 
 
 will set up a branch called topic on the server and a
-  local branch called me/topic that tracks it.  The banch
+  local branch called me/topic that tracks it.  The branch
   can then be pushed using:
 
 


[committed] libstdc++: Remove redundant std:: qualification

2020-06-19 Thread Jonathan Wakely via Gcc-patches
* include/bits/stl_pair.h (_Index_tuple): Remove redundant
namespace qualification.
(pair::pair(tuple<>&, tuple<>&, _Index_tuple, _Index_tuple)):
Likewise.
* include/std/tuple (_Head_base, _Tuple_impl, tuple_size)
(tuple_element, __get_helper, get, __make_tuple_impl)
(__make_1st_indices, __tuple_concater)
(pair::pair(tuple<>&, tuple<>&, _Index_tuple, _Index_tuple)):
Likewise.
* include/std/utility (tuple_element, __is_tuple_like_impl)
(tuple_size, __pair_get, get): Likewise.

Tested powerpc64l-linux, committed to master.


commit a7a3932e4b698f205273cfa78c7aa8ab6840542a
Author: Jonathan Wakely 
Date:   Fri Jun 19 15:02:54 2020 +0100

libstdc++: Remove redundant std:: qualification

* include/bits/stl_pair.h (_Index_tuple): Remove redundant
namespace qualification.
(pair::pair(tuple<>&, tuple<>&, _Index_tuple, _Index_tuple)):
Likewise.
* include/std/tuple (_Head_base, _Tuple_impl, tuple_size)
(tuple_element, __get_helper, get, __make_tuple_impl)
(__make_1st_indices, __tuple_concater)
(pair::pair(tuple<>&, tuple<>&, _Index_tuple, _Index_tuple)):
Likewise.
* include/std/utility (tuple_element, __is_tuple_like_impl)
(tuple_size, __pair_get, get): Likewise.

diff --git a/libstdc++-v3/include/bits/stl_pair.h 
b/libstdc++-v3/include/bits/stl_pair.h
index 491c599076e..e5669d5d7ae 100644
--- a/libstdc++-v3/include/bits/stl_pair.h
+++ b/libstdc++-v3/include/bits/stl_pair.h
@@ -89,7 +89,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   template
 class tuple;
 
-  template
+  template
 struct _Index_tuple;
 
   // Concept utility functions, reused in conditionally-explicit
@@ -446,11 +446,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   }
 
 private:
-  template
+  template
_GLIBCXX20_CONSTEXPR
 pair(tuple<_Args1...>&, tuple<_Args2...>&,
- _Index_tuple<_Indexes1...>, _Index_tuple<_Indexes2...>);
+_Index_tuple<_Indexes1...>, _Index_tuple<_Indexes2...>);
 #endif // C++11
 };
 
diff --git a/libstdc++-v3/include/std/tuple b/libstdc++-v3/include/std/tuple
index db4872d3a52..726ad0aabbb 100644
--- a/libstdc++-v3/include/std/tuple
+++ b/libstdc++-v3/include/std/tuple
@@ -69,11 +69,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 = typename conditional<__is_final(_Tp), false_type,
   __is_empty_non_tuple<_Tp>>::type;
 
-  template::value>
 struct _Head_base;
 
-  template
+  template
 struct _Head_base<_Idx, _Head, true>
 : public _Head
 {
@@ -120,7 +120,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   _M_head(const _Head_base& __b) noexcept { return __b; }
 };
 
-  template
+  template
 struct _Head_base<_Idx, _Head, false>
 {
   constexpr _Head_base()
@@ -179,7 +179,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* point in the hierarchy; we use it to implement a constant-time
* get() operation.
*/
-  template
+  template
 struct _Tuple_impl;
 
   /**
@@ -187,12 +187,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* and derive from a @c Tuple_impl containing the remaining elements
* (which contains the @c Tail).
*/
-  template
+  template
 struct _Tuple_impl<_Idx, _Head, _Tail...>
 : public _Tuple_impl<_Idx + 1, _Tail...>,
   private _Head_base<_Idx, _Head>
 {
-  template friend class _Tuple_impl;
+  template friend class _Tuple_impl;
 
   typedef _Tuple_impl<_Idx + 1, _Tail...> _Inherited;
   typedef _Head_base<_Idx, _Head> _Base;
@@ -337,11 +337,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 };
 
   // Basis case of inheritance recursion.
-  template
+  template
 struct _Tuple_impl<_Idx, _Head>
 : private _Head_base<_Idx, _Head>
 {
-  template friend class _Tuple_impl;
+  template friend class _Tuple_impl;
 
   typedef _Head_base<_Idx, _Head> _Base;
 
@@ -1244,7 +1244,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   /// class tuple_size
   template
 struct tuple_size>
-: public integral_constant { };
+: public integral_constant { };
 
 #if __cplusplus > 201402L
   template 
@@ -1255,7 +1255,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* Recursive case for tuple_element: strip off the first element in
* the tuple and retrieve the (i-1)th element of the remaining tuple.
*/
-  template
+  template
 struct tuple_element<__i, tuple<_Head, _Tail...> >
 : tuple_element<__i - 1, tuple<_Tail...> > { };
 
@@ -1278,30 +1278,30 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
  "tuple index is in range");
 };
 
-  template
+  template
 constexpr _Head&
 __get_helper(_Tuple_impl<__i, _Head, _Tail...>& __t) noexcept
 { return _Tuple_impl<__i, _Head, _Tail...>::_M_head(__t); }
 
-  template
+  template
 constexpr const _Head&
 __get_helper(const _Tuple_impl<__i, _Head, _Tail...>& __t) noexcept
 { return 

[PATCH] Handle SLP_TREE_LANE_PERMUTATION in scalar costing

2020-06-19 Thread Richard Biener
This properly handles a lane permutation in scalar costing.
For the current only use this doesn't matter much but with
permutes that change the number of lanes it will eventually
ICE.

Bootstrapped and tested on x86_64-unknown-linux-gnu, applied.

Richard,

2020-06-19  Richard Biener  

* tree-vect-slp.c (vect_bb_slp_scalar_cost): Adjust
for lane permutations.
---
 gcc/tree-vect-slp.c | 17 -
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/gcc/tree-vect-slp.c b/gcc/tree-vect-slp.c
index 84b97270cd1..5c169f37022 100644
--- a/gcc/tree-vect-slp.c
+++ b/gcc/tree-vect-slp.c
@@ -2969,7 +2969,22 @@ vect_bb_slp_scalar_cost (vec_info *vinfo,
{
  /* Do not directly pass LIFE to the recursive call, copy it to
 confine changes in the callee to the current child/subtree.  */
- subtree_life.safe_splice (*life);
+ if (SLP_TREE_CODE (node) == VEC_PERM_EXPR)
+   {
+ subtree_life.safe_grow_cleared (SLP_TREE_LANES (child));
+ for (unsigned j = 0;
+  j < SLP_TREE_LANE_PERMUTATION (node).length (); ++j)
+   {
+ auto perm = SLP_TREE_LANE_PERMUTATION (node)[j];
+ if (perm.first == i)
+   subtree_life[perm.second] = (*life)[j];
+   }
+   }
+ else
+   {
+ gcc_assert (SLP_TREE_LANES (node) == SLP_TREE_LANES (child));
+ subtree_life.safe_splice (*life);
+   }
  vect_bb_slp_scalar_cost (vinfo, child, _life, cost_vec,
   visited);
  subtree_life.truncate (0);
-- 
2.25.1


[committed] libstdc++: Define all std::function members inline

2020-06-19 Thread Jonathan Wakely via Gcc-patches
* include/bits/std_function.h (function): Define all member
functions inline.

There doesn't seem to be a good reason for these to be non-inline.

Tested powerpc64le-linux, committed to master.


commit abed8b56b92b103275e6871b689862c0495b761b
Author: Jonathan Wakely 
Date:   Fri Jun 19 14:37:52 2020 +0100

libstdc++: Define all std::function members inline

* include/bits/std_function.h (function): Define all member
functions inline.

diff --git a/libstdc++-v3/include/bits/std_function.h 
b/libstdc++-v3/include/bits/std_function.h
index e2bf9b91850..fa65885d1de 100644
--- a/libstdc++-v3/include/bits/std_function.h
+++ b/libstdc++-v3/include/bits/std_function.h
@@ -345,7 +345,16 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
*  The newly-created %function contains a copy of the target of @a
*  __x (if it has one).
*/
-  function(const function& __x);
+  function(const function& __x)
+  : _Function_base()
+  {
+   if (static_cast(__x))
+ {
+   __x._M_manager(_M_functor, __x._M_functor, __clone_functor);
+   _M_invoker = __x._M_invoker;
+   _M_manager = __x._M_manager;
+ }
+  }
 
   /**
*  @brief %Function move constructor.
@@ -354,10 +363,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
*  The newly-created %function contains the target of @a __x
*  (if it has one).
*/
-  function(function&& __x) noexcept : _Function_base()
-  {
-   __x.swap(*this);
-  }
+  function(function&& __x) noexcept
+  : _Function_base()
+  { __x.swap(*this); }
 
   /**
*  @brief Builds a %function that targets a copy of the incoming
@@ -378,7 +386,18 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   template>, void>,
   typename = _Requires<_Callable<_Functor>, void>>
-   function(_Functor);
+   function(_Functor __f)
+   : _Function_base()
+   {
+ typedef _Function_handler<_Res(_ArgTypes...), _Functor> _My_handler;
+
+ if (_My_handler::_M_not_empty_function(__f))
+   {
+ _My_handler::_M_init_functor(_M_functor, std::move(__f));
+ _M_invoker = &_My_handler::_M_invoke;
+ _M_manager = &_My_handler::_M_manager;
+   }
+   }
 
   /**
*  @brief %Function assignment operator.
@@ -508,7 +527,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
*  The function call operator invokes the target function object
*  stored by @c this.
*/
-  _Res operator()(_ArgTypes... __args) const;
+  _Res
+  operator()(_ArgTypes... __args) const
+  {
+   if (_M_empty())
+ __throw_bad_function_call();
+   return _M_invoker(_M_functor, std::forward<_ArgTypes>(__args)...);
+  }
 
 #if __cpp_rtti
   // [3.7.2.5] function target access
@@ -521,7 +546,18 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
*
*  This function will not throw an %exception.
*/
-  const type_info& target_type() const noexcept;
+  const type_info&
+  target_type() const noexcept
+  {
+   if (_M_manager)
+ {
+   _Any_data __typeinfo_result;
+   _M_manager(__typeinfo_result, _M_functor, __get_type_info);
+   return *__typeinfo_result._M_access();
+ }
+   else
+ return typeid(void);
+  }
 
   /**
*  @brief Access the stored target function object.
@@ -534,9 +570,28 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
*
* @{
*/
-  template   _Functor* target() noexcept;
+  template
+   _Functor*
+   target() noexcept
+   {
+ const function* __const_this = this;
+ const _Functor* __func = __const_this->template target<_Functor>();
+ return const_cast<_Functor*>(__func);
+   }
 
-  template const _Functor* target() const noexcept;
+  template
+   const _Functor*
+   target() const noexcept
+   {
+ if (typeid(_Functor) == target_type() && _M_manager)
+   {
+ _Any_data __ptr;
+ _M_manager(__ptr, _M_functor, __get_functor_ptr);
+ return __ptr._M_access();
+   }
+ else
+   return nullptr;
+   }
   // @}
 #endif
 
@@ -582,90 +637,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 function(_Functor) -> function<_Signature>;
 #endif
 
-  // Out-of-line member definitions.
-  template
-function<_Res(_ArgTypes...)>::
-function(const function& __x)
-: _Function_base()
-{
-  if (static_cast(__x))
-   {
- __x._M_manager(_M_functor, __x._M_functor, __clone_functor);
- _M_invoker = __x._M_invoker;
- _M_manager = __x._M_manager;
-   }
-}
-
-  template
-template
-  function<_Res(_ArgTypes...)>::
-  function(_Functor __f)
-  : _Function_base()
-  {
-   typedef _Function_handler<_Res(_ArgTypes...), _Functor> _My_handler;
-
-   if 

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

2020-06-19 Thread Przemyslaw Wirkus
> From: Richard Biener 
> Subject: Re: [PATCH][GCC]: Fix for PR94880: Failure to recognize andn
> pattern

Snip...

> The patch is OK.

I do not have write access yet. Can I ask someone to push my patch to
master please ?

Thanks in advance, 
Przemyslaw

> Thanks,
> Richard.
> 
> > > On Fri, 19 Jun 2020, Przemyslaw Wirkus wrote:
> > >
> > > > Hi all,
> > > >
> > > > Pattern "(x | y) - y" can be optimized to simple "(x & ~y)" andn 
> > > > pattern.
> > > >
> > > > Bootstrapped and tested on aarch64-none-linux-gnu.
> > > >
> > > > OK for master ?
> > > >
> > > > Cheers,
> > > > Przemyslaw
> > > >
> > > > gcc/ChangeLog:
> > > >
> > > > PR tree-optimization/94880
> > > > * match.pd (A | B) - B -> (A & ~B): New simplification.
> > > >
> > > > gcc/testsuite/ChangeLog:
> > > >
> > > > PR tree-optimization/94880
> > > > * gcc.dg/tree-ssa/pr94880.c: New Test.
> > > >
> > > >
> > >
> > > --
> > > Marc Glisse
> >
> > --
> > Przemyslaw


[PATCH] Split load permutation

2020-06-19 Thread Richard Biener


This splits SLP load nodes with load permutation into a SLP
load node (with load "permutation" removing gaps) and a
lane permutation node.  The first and foremost goal of this
is to be able to have a single SLP node for each load group
so we can start making decisions about how to vectorize
them factoring in all loads of that group.  The second
goal is to eventually be able to optimize permutations by
pushing them down where they can be combined from multiple
children to the output.  We do have one very special case
handled by vect_attempt_slp_rearrange_stmts doing it all
the way down for reductions that are associative.

For example for

  l1 = a[0]; l2 = a[1];
  b[0] = l1; b[1] = l2;
  c[0] = l2; c[1] = l1;

wecan avoid generating loads twice.  For

  l1 = a[0]; l2 = a[1]; l3 = a[2];
  b[0] = l1; b[1] = l2;
 c[0] = l2; c[1] = l3;

we will have a SLP load node with three lanes plus
two lane permutation nodes selecting two lanes each.  In
a loop context this will cause a VF of two and three
loads per vectorized loop iteration (plus two permutes)
while previously we used a VF of one with two loads
and no permutation per loop iteration.  In the new
scheme the number of loads is less but we pay with
permutes and a higher VF.

There is (bad) interaction with determining of the vectorization
factor which for BB vectorization causes missed vectorizations
because the "load parts of a dataref group directly" optimization
is not (yet) reflected in the SLP graph.

There is (bad) interaction with CTOR vectorization since we now
get confused about where to insert vectorized stmts when combining
two previously distinct SLP graphs.

My immediate focus is on the SSA verification FAILs but the
other part points at a missing piece in this - a "pass"
that "optimizes" the SLP graph with respect to permutations
and loads, ultimatively for example deciding between using
interleaving schemes, scalar loads, "SLP" + permutation,
load-lanes, etc.;  This is also the thing that blocks
SLP only (apart from teaching the few pieces that cannot do SLP
to do SLP).

I'm posting this mostly to make people think how it fits
their future development and architecture features.

And of course to see whether there are already made up ideas
how to structure such "optimization".

Thanks,
Richard.

PS: patch doesn't bootstrap, it ICEs during libgfortran build.
C vect.exp FAILs are

FAIL: gcc.dg/vect/pr59354.c (internal compiler error)
FAIL: gcc.dg/vect/pr88903-2.c (internal compiler error)
FAIL: gcc.dg/vect/vect-alias-check-10.c (internal compiler error)
FAIL: gcc.dg/vect/vect-alias-check-11.c (internal compiler error)
FAIL: gcc.dg/vect/vect-alias-check-12.c (internal compiler error)
FAIL: gcc.dg/vect/slp-23.c scan-tree-dump-times vect "vectorizing stmts using 
SLP" 2
FAIL: gcc.dg/vect/slp-43.c (internal compiler error)
FAIL: gcc.dg/vect/bb-slp-19.c scan-tree-dump-times slp2 "basic block 
vectorized" 1
FAIL: gcc.dg/vect/bb-slp-29.c scan-tree-dump-times slp1 "basic block 
vectorized" 1
FAIL: gcc.dg/vect/bb-slp-pr78205.c scan-tree-dump-times slp2 "basic block 
vectorized" 1
FAIL: gcc.dg/vect/bb-slp-pr78205.c scan-tree-dump-times slp2 "BB vectorization 
with gaps at the end of a load is not supported" 1
FAIL: gcc.dg/vect/bb-slp-subgroups-2.c (internal compiler error)
FAIL: gcc.dg/vect/bb-slp-subgroups-3.c (internal compiler error)

* tree-vectorizer.h (vect_get_place_in_interleaving_chain):
Add flag paramter defaulted to true.
* tree-vect-slp.c (vect_get_place_in_interleaving_chain):
Imlement alternate mode not counting gaps.
(vect_build_slp_tree_2): Split load nodes into load and
lane permutation.
(vect_attempt_slp_rearrange_stmts): Pass in the unroll
factor to consider.
(calculate_unrolling_factor): New function.
(vect_analyze_slp_instance): Adjust.
(vect_analyze_slp): Nail down the unroll factor before
optimizing permutations in SLP reductions.
(vect_make_slp_decision): Remove determining unroll
factor here.
(vect_schedule_slp_instance): Adjust where we emit vectorized
stmts.
---
 gcc/tree-vect-slp.c   | 246 +-
 gcc/tree-vectorizer.h |   3 +-
 2 files changed, 199 insertions(+), 50 deletions(-)

diff --git a/gcc/tree-vect-slp.c b/gcc/tree-vect-slp.c
index 5c169f37022..68b0750db44 100644
--- a/gcc/tree-vect-slp.c
+++ b/gcc/tree-vect-slp.c
@@ -244,7 +244,8 @@ vect_contains_pattern_stmt_p (vec stmts)
 
 int
 vect_get_place_in_interleaving_chain (stmt_vec_info stmt_info,
- stmt_vec_info first_stmt_info)
+ stmt_vec_info first_stmt_info,
+ bool add_gaps)
 {
   stmt_vec_info next_stmt_info = first_stmt_info;
   int result = 0;
@@ -258,7 +259,7 @@ vect_get_place_in_interleaving_chain (stmt_vec_info 
stmt_info,
return result;
   next_stmt_info = 

[PATCH wwwdocs] gcc-11/changes: Document TSAN changes

2020-06-19 Thread Marco Elver via Gcc-patches
Document TSAN changes to support alternative runtimes, such as KCSAN.
---
 htdocs/gcc-11/changes.html | 15 +++
 1 file changed, 15 insertions(+)

diff --git a/htdocs/gcc-11/changes.html b/htdocs/gcc-11/changes.html
index 9dba1e14..dc22f216 100644
--- a/htdocs/gcc-11/changes.html
+++ b/htdocs/gcc-11/changes.html
@@ -46,6 +46,21 @@ a work-in-progress.
 
 General Improvements
 
+
+  
+https://github.com/google/sanitizers/wiki/ThreadSanitizerCppManual;>
+ThreadSanitizer improvements to support alternative runtimes and
+environments. The https://www.kernel.org/doc/html/latest/dev-tools/kcsan.html;>
+Linux Kernel Concurrency Sanitizer (KCSAN) is now supported.
+
+  Add --param tsan-distinguish-volatile to optionally emit
+  instrumentation distinguishing volatile accesses.
+  Add --param tsan-instrument-func-entry-exit to 
optionally
+  control if function entries and exits should be instrumented.
+
+  
+
+
 
 New Languages and Language specific improvements
 
-- 
2.27.0.111.gc72c7da667-goog



Re: std::includes performance tweak

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

On 19/06/20 12:17 +0100, Jonathan Wakely wrote:

On 19/06/20 12:49 +0200, Marc Glisse wrote:
Anyway, while I blame the compiler for not generating very good code 
with the current implementation, I believe the change can be seen as 
a simplification and should be pushed to master. It regtests fine.


2020-06-20  Marc Glisse  

* include/bits/stl_algo.h (__includes): Simplify the code.

(as with the patch for std::optional, I still haven't worked on my 
ssh key issue and cannot currently push)


Thanks, I'll take care of it (and the std::optional one which I still
haven't done).


Pushed to master as r11-1554 465520e3eb45d83ad18394aa537150bfa6bdf117

Thanks again.



Re: std::optional defaut constructor

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

On 04/06/20 14:46 +0100, Jonathan Wakely wrote:

On 04/06/20 00:50 +0200, Marc Glisse wrote:

(I don't currently have a setup that would enable me to commit anything. I'll
try to fix it eventually, but likely not so soon)


Ah, I missed this bit. I'll take care of it for you.

If it's due to the Git conversion let me know if it's something I can
help with off-list.



diff --git a/libstdc++-v3/include/std/optional 
b/libstdc++-v3/include/std/optional
index 37c2ba7a025..e84ba28a806 100644
--- a/libstdc++-v3/include/std/optional
+++ b/libstdc++-v3/include/std/optional
@@ -688,7 +688,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   public:
 using value_type = _Tp;

-  constexpr optional() = default;
+  constexpr optional() noexcept { }

 constexpr optional(nullopt_t) noexcept { }




Committed to master as r11-1552 bafd12cb22e83b7da8946873513a897e48e2900f




[PATCH] Handle SLP_TREE_LANE_PERMUTATION in scalar costing

2020-06-19 Thread Richard Biener
This properly handles a lane permutation in scalar costing.
For the current only use this doesn't matter much but with
permutes that change the number of lanes it will eventually
ICE.

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

2020-06-19  Richard Biener  

* tree-vect-slp.c (vect_bb_slp_scalar_cost): Adjust
for lane permutations.
---
 gcc/tree-vect-slp.c | 17 -
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/gcc/tree-vect-slp.c b/gcc/tree-vect-slp.c
index 84b97270cd1..5c169f37022 100644
--- a/gcc/tree-vect-slp.c
+++ b/gcc/tree-vect-slp.c
@@ -2969,7 +2969,22 @@ vect_bb_slp_scalar_cost (vec_info *vinfo,
{
  /* Do not directly pass LIFE to the recursive call, copy it to
 confine changes in the callee to the current child/subtree.  */
- subtree_life.safe_splice (*life);
+ if (SLP_TREE_CODE (node) == VEC_PERM_EXPR)
+   {
+ subtree_life.safe_grow_cleared (SLP_TREE_LANES (child));
+ for (unsigned j = 0;
+  j < SLP_TREE_LANE_PERMUTATION (node).length (); ++j)
+   {
+ auto perm = SLP_TREE_LANE_PERMUTATION (node)[j];
+ if (perm.first == i)
+   subtree_life[perm.second] = (*life)[j];
+   }
+   }
+ else
+   {
+ gcc_assert (SLP_TREE_LANES (node) == SLP_TREE_LANES (child));
+ subtree_life.safe_splice (*life);
+   }
  vect_bb_slp_scalar_cost (vinfo, child, _life, cost_vec,
   visited);
  subtree_life.truncate (0);
-- 
2.25.1


[PATCH] tree-optimization/95761 - fix vector insertion place compute

2020-06-19 Thread Richard Biener
I missed that indeed SLP permutation code generation can end up
refering to a non-last vectorized stmt in the last SLP_TREE_VEC_STMTS
element as optimization.  So walk them all.

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

2020-06-19  Richard Biener  

PR tree-optimization/95761
* tree-vect-slp.c (vect_schedule_slp_instance): Walk all
vectorized stmts for finding the last one.

* gcc.dg/torture/pr95761.c: New testcase.
---
 gcc/testsuite/gcc.dg/torture/pr95761.c | 25 +
 gcc/tree-vect-slp.c| 15 +--
 2 files changed, 34 insertions(+), 6 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/torture/pr95761.c

diff --git a/gcc/testsuite/gcc.dg/torture/pr95761.c 
b/gcc/testsuite/gcc.dg/torture/pr95761.c
new file mode 100644
index 000..65ee0fc1c11
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr95761.c
@@ -0,0 +1,25 @@
+/* { dg-do compile } */
+
+typedef int a[10];
+typedef struct {
+  a b;
+  a c;
+  a d;
+  a e;
+} f;
+f g;
+int *j;
+void k() {
+  for (;;) {
+a l;
+j[0] = g.b[0];
+int *h = g.d;
+int i = 0;
+for (; i < 10; i++)
+  h[i] = l[0] - g.e[0];
+h = g.e;
+i = 0;
+for (; i < 10; i++)
+  h[i] = l[1] + g.e[i];
+  }
+}
diff --git a/gcc/tree-vect-slp.c b/gcc/tree-vect-slp.c
index e33b42fbc68..c9ec77b4a97 100644
--- a/gcc/tree-vect-slp.c
+++ b/gcc/tree-vect-slp.c
@@ -4207,7 +4207,6 @@ vect_schedule_slp_instance (vec_info *vinfo,
 {
   /* Or if we do not have 1:1 matching scalar stmts emit after the
 children vectorized defs.  */
-  gimple *last_in_child;
   gimple *last_stmt = NULL;
   FOR_EACH_VEC_ELT (SLP_TREE_CHILDREN (node), i, child)
/* ???  With only external defs the following breaks.  Note
@@ -4216,11 +4215,15 @@ vect_schedule_slp_instance (vec_info *vinfo,
if (SLP_TREE_DEF_TYPE (child) == vect_internal_def)
  {
/* We are emitting all vectorized stmts in the same place and
-  the last one is the last.  */
-   last_in_child = SLP_TREE_VEC_STMTS (child).last ();
-   if (!last_stmt
-   || vect_stmt_dominates_stmt_p (last_stmt, last_in_child))
- last_stmt = last_in_child;
+  the last one is the last.
+  ???  Unless we have a load permutation applied and that
+  figures to re-use an earlier generated load.  */
+   unsigned j;
+   gimple *vstmt;
+   FOR_EACH_VEC_ELT (SLP_TREE_VEC_STMTS (child), j, vstmt)
+ if (!last_stmt
+ || vect_stmt_dominates_stmt_p (last_stmt, vstmt))
+   last_stmt = vstmt;
  }
   if (is_a  (last_stmt))
si = gsi_after_labels (gimple_bb (last_stmt));
-- 
2.26.2


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

2020-06-19 Thread Richard Biener via Gcc-patches
On Fri, Jun 19, 2020 at 12:37 PM Przemyslaw Wirkus
 wrote:
>
>
> On Fri, Jun 19 2020 Marc Glisse wrote:
> > (not a reviewer)
> >
> > It looks fine to me. Do we already handle the related (x|y)^y and (x|y)&~y ?
>
> These are already in match.pd:
>
> /* (X | Y) ^ X -> Y & ~ X*/
> /* (x | y) & ~x -> y & ~x */

The patch is OK.

Thanks,
Richard.

> > On Fri, 19 Jun 2020, Przemyslaw Wirkus wrote:
> >
> > > Hi all,
> > >
> > > Pattern "(x | y) - y" can be optimized to simple "(x & ~y)" andn pattern.
> > >
> > > Bootstrapped and tested on aarch64-none-linux-gnu.
> > >
> > > OK for master ?
> > >
> > > Cheers,
> > > Przemyslaw
> > >
> > > gcc/ChangeLog:
> > >
> > > PR tree-optimization/94880
> > > * match.pd (A | B) - B -> (A & ~B): New simplification.
> > >
> > > gcc/testsuite/ChangeLog:
> > >
> > > PR tree-optimization/94880
> > > * gcc.dg/tree-ssa/pr94880.c: New Test.
> > >
> > >
> >
> > --
> > Marc Glisse
>
> --
> Przemyslaw


Re: std::includes performance tweak

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

On 19/06/20 12:49 +0200, Marc Glisse wrote:

Hello,

I am proposing a small tweak to the implementation of __includes, 
which in my application saves 20% of the running time. I noticed it 
because using range-v3 was giving unexpected performance gains.


The unified diff is attached, but let me first show a more readable 
context diff.


*** /tmp/zzm2NX_stl_algo.h  2020-06-19 10:48:58.702634366 +0200
--- libstdc++-v3/include/bits/stl_algo.h2020-06-18 23:16:06.183427245 
+0200
***
*** 2783,2797 
   _Compare __comp)
 {
   while (__first1 != __last1 && __first2 != __last2)
!   if (__comp(__first2, __first1))
! return false;
!   else if (__comp(__first1, __first2))
! ++__first1;
!   else
! {
!   ++__first1;
++__first2;
! }

   return __first2 == __last2;
 }
--- 2783,2795 
   _Compare __comp)
 {
   while (__first1 != __last1 && __first2 != __last2)
!   {
! if (__comp(__first2, __first1))
!   return false;
! if (!__comp(__first1, __first2))
++__first2;
! ++__first1;
!   }

   return __first2 == __last2;
 }

As you can see, it isn't much change. Some of the gain comes from 
pulling the 2 calls ++__first1 out of the condition so there is just 
one call. And most of the gain comes from replacing the resulting


if (__comp(__first1, __first2))
 ;
else
 ++__first2;

with

if (!__comp(__first1, __first2))
 ++__first2;

I was very surprised that the code ended up being so different for 
such a change, and I still don't really understand where the extra 
time is going...


Anyway, while I blame the compiler for not generating very good code 
with the current implementation, I believe the change can be seen as a 
simplification and should be pushed to master. It regtests fine.


2020-06-20  Marc Glisse  

* include/bits/stl_algo.h (__includes): Simplify the code.

(as with the patch for std::optional, I still haven't worked on my ssh 
key issue and cannot currently push)


Thanks, I'll take care of it (and the std::optional one which I still
haven't done).




std::includes performance tweak

2020-06-19 Thread Marc Glisse

Hello,

I am proposing a small tweak to the implementation of __includes, which in 
my application saves 20% of the running time. I noticed it because using 
range-v3 was giving unexpected performance gains.


The unified diff is attached, but let me first show a more readable 
context diff.


*** /tmp/zzm2NX_stl_algo.h  2020-06-19 10:48:58.702634366 +0200
--- libstdc++-v3/include/bits/stl_algo.h2020-06-18 23:16:06.183427245 
+0200
***
*** 2783,2797 
   _Compare __comp)
  {
while (__first1 != __last1 && __first2 != __last2)
!   if (__comp(__first2, __first1))
! return false;
!   else if (__comp(__first1, __first2))
! ++__first1;
!   else
! {
!   ++__first1;
++__first2;
! }

return __first2 == __last2;
  }
--- 2783,2795 
   _Compare __comp)
  {
while (__first1 != __last1 && __first2 != __last2)
!   {
! if (__comp(__first2, __first1))
!   return false;
! if (!__comp(__first1, __first2))
++__first2;
! ++__first1;
!   }

return __first2 == __last2;
  }

As you can see, it isn't much change. Some of the gain comes from pulling 
the 2 calls ++__first1 out of the condition so there is just one call. And 
most of the gain comes from replacing the resulting


if (__comp(__first1, __first2))
  ;
else
  ++__first2;

with

if (!__comp(__first1, __first2))
  ++__first2;

I was very surprised that the code ended up being so different for such a 
change, and I still don't really understand where the extra time is 
going...


Anyway, while I blame the compiler for not generating very good code with 
the current implementation, I believe the change can be seen as a 
simplification and should be pushed to master. It regtests fine.


2020-06-20  Marc Glisse  

* include/bits/stl_algo.h (__includes): Simplify the code.

(as with the patch for std::optional, I still haven't worked on my ssh key 
issue and cannot currently push)


--
Marc Glissediff --git a/libstdc++-v3/include/bits/stl_algo.h b/libstdc++-v3/include/bits/stl_algo.h
index fd6edd0d5f4..550a15f2b3b 100644
--- a/libstdc++-v3/include/bits/stl_algo.h
+++ b/libstdc++-v3/include/bits/stl_algo.h
@@ -2783,15 +2783,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 	   _Compare __comp)
 {
   while (__first1 != __last1 && __first2 != __last2)
-	if (__comp(__first2, __first1))
-	  return false;
-	else if (__comp(__first1, __first2))
-	  ++__first1;
-	else
-	  {
-	++__first1;
+	{
+	  if (__comp(__first2, __first1))
+	return false;
+	  if (!__comp(__first1, __first2))
 	++__first2;
-	  }
+	  ++__first1;
+	}
 
   return __first2 == __last2;
 }


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

2020-06-19 Thread Przemyslaw Wirkus


On Fri, Jun 19 2020 Marc Glisse wrote:
> (not a reviewer)
> 
> It looks fine to me. Do we already handle the related (x|y)^y and (x|y)&~y ?

These are already in match.pd: 

/* (X | Y) ^ X -> Y & ~ X*/
/* (x | y) & ~x -> y & ~x */

> On Fri, 19 Jun 2020, Przemyslaw Wirkus wrote:
> 
> > Hi all,
> >
> > Pattern "(x | y) - y" can be optimized to simple "(x & ~y)" andn pattern.
> >
> > Bootstrapped and tested on aarch64-none-linux-gnu.
> >
> > OK for master ?
> >
> > Cheers,
> > Przemyslaw
> >
> > gcc/ChangeLog:
> >
> > PR tree-optimization/94880
> > * match.pd (A | B) - B -> (A & ~B): New simplification.
> >
> > gcc/testsuite/ChangeLog:
> >
> > PR tree-optimization/94880
> > * gcc.dg/tree-ssa/pr94880.c: New Test.
> >
> >
> 
> --
> Marc Glisse

-- 
Przemyslaw


Re: [PATCH] RISC-V: Fix compilation failed for frflags builtin in C++ mode

2020-06-19 Thread Kito Cheng via Gcc-patches
Oh I missed the -mabi in testcase, v2 patch attached, same as V1 but
add -mabi flag to testcase.

On Fri, Jun 19, 2020 at 3:08 PM Kito Cheng  wrote:
>
>   - g++ will complain too few arguments for frflags builtin like bellow
> message:
>
> error: too few arguments to function 'unsigned int 
> __builtin_riscv_frflags(void)'
>
>   - However it's no arguments needed, it because we declare the function
> type with VOID arguments, that seems like require a VOID argument
> in the c++ front-end when GCC tried to resolve the function.
>
> gcc/ChangeLog
>
> * config/riscv/riscv-builtins.c (RISCV_FTYPE_NAME0): New.
> (RISCV_FTYPE_ATYPES0): New.
> (riscv_builtins): Using RISCV_USI_FTYPE for frflags.
> * config/riscv/riscv-ftypes.def: Remove VOID argument.
>
> gcc/testsuite/ChangeLog
>
> * g++.target/riscv/frflags.C: New.
> ---
>  gcc/config/riscv/riscv-builtins.c| 5 -
>  gcc/config/riscv/riscv-ftypes.def| 2 +-
>  gcc/testsuite/g++.target/riscv/frflags.C | 7 +++
>  3 files changed, 12 insertions(+), 2 deletions(-)
>  create mode 100644 gcc/testsuite/g++.target/riscv/frflags.C
>
> diff --git a/gcc/config/riscv/riscv-builtins.c 
> b/gcc/config/riscv/riscv-builtins.c
> index a45108e03557..bc959389c76c 100644
> --- a/gcc/config/riscv/riscv-builtins.c
> +++ b/gcc/config/riscv/riscv-builtins.c
> @@ -38,6 +38,7 @@ along with GCC; see the file COPYING3.  If not see
>  #include "langhooks.h"
>
>  /* Macros to create an enumeration identifier for a function prototype.  */
> +#define RISCV_FTYPE_NAME0(A) RISCV_##A##_FTYPE
>  #define RISCV_FTYPE_NAME1(A, B) RISCV_##A##_FTYPE_##B
>
>  /* Classifies the prototype of a built-in function.  */
> @@ -121,11 +122,13 @@ AVAIL (hard_float, TARGET_HARD_FLOAT)
>
>  /* RISCV_FTYPE_ATYPESN takes N RISCV_FTYPES-like type codes and lists
> their associated RISCV_ATYPEs.  */
> +#define RISCV_FTYPE_ATYPES0(A) \
> +  RISCV_ATYPE_##A
>  #define RISCV_FTYPE_ATYPES1(A, B) \
>RISCV_ATYPE_##A, RISCV_ATYPE_##B
>
>  static const struct riscv_builtin_description riscv_builtins[] = {
> -  DIRECT_BUILTIN (frflags, RISCV_USI_FTYPE_VOID, hard_float),
> +  DIRECT_BUILTIN (frflags, RISCV_USI_FTYPE, hard_float),
>DIRECT_NO_TARGET_BUILTIN (fsflags, RISCV_VOID_FTYPE_USI, hard_float)
>  };
>
> diff --git a/gcc/config/riscv/riscv-ftypes.def 
> b/gcc/config/riscv/riscv-ftypes.def
> index 5edeb481a72d..1c6bc4e9dce1 100644
> --- a/gcc/config/riscv/riscv-ftypes.def
> +++ b/gcc/config/riscv/riscv-ftypes.def
> @@ -26,5 +26,5 @@ along with GCC; see the file COPYING3.  If not see
>LIST contains the return-type code followed by the codes for each
>  argument type.  */
>
> -DEF_RISCV_FTYPE (1, (USI, VOID))
> +DEF_RISCV_FTYPE (0, (USI))
>  DEF_RISCV_FTYPE (1, (VOID, USI))
> diff --git a/gcc/testsuite/g++.target/riscv/frflags.C 
> b/gcc/testsuite/g++.target/riscv/frflags.C
> new file mode 100644
> index ..be0bd4db01c3
> --- /dev/null
> +++ b/gcc/testsuite/g++.target/riscv/frflags.C
> @@ -0,0 +1,7 @@
> +/* { dg-options "-O2 -march=rv32if" } */
> +/* { dg-do compile } */
> +
> +int f()
> +{
> +  return __builtin_riscv_frflags();
> +}
> --
> 2.27.0
>
From 6a84ffed89eb8c2a42ccbc29b93df996d0e5d6c9 Mon Sep 17 00:00:00 2001
From: Kito Cheng 
Date: Fri, 19 Jun 2020 14:07:39 +0800
Subject: [PATCH] RISC-V: Fix compilation failed for frflags builtin in C++
 mode

  - g++ will complain too few arguments for frflags builtin like bellow
message:

error: too few arguments to function 'unsigned int __builtin_riscv_frflags(void)'

  - However it's no arguments needed, it because we declare the function
type with VOID arguments, that seems like require a VOID argument
in the c++ front-end when GCC tried to resolve the function.

gcc/ChangeLog

	* config/riscv/riscv-builtins.c (RISCV_FTYPE_NAME0): New.
	(RISCV_FTYPE_ATYPES0): New.
	(riscv_builtins): Using RISCV_USI_FTYPE for frflags.
	* config/riscv/riscv-ftypes.def: Remove VOID argument.

gcc/testsuite/ChangeLog

	* g++.target/riscv/frflags.C: New.
---
 gcc/config/riscv/riscv-builtins.c| 5 -
 gcc/config/riscv/riscv-ftypes.def| 2 +-
 gcc/testsuite/g++.target/riscv/frflags.C | 7 +++
 3 files changed, 12 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/g++.target/riscv/frflags.C

diff --git a/gcc/config/riscv/riscv-builtins.c b/gcc/config/riscv/riscv-builtins.c
index a45108e03557..bc959389c76c 100644
--- a/gcc/config/riscv/riscv-builtins.c
+++ b/gcc/config/riscv/riscv-builtins.c
@@ -38,6 +38,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "langhooks.h"
 
 /* Macros to create an enumeration identifier for a function prototype.  */
+#define RISCV_FTYPE_NAME0(A) RISCV_##A##_FTYPE
 #define RISCV_FTYPE_NAME1(A, B) RISCV_##A##_FTYPE_##B
 
 /* Classifies the prototype of a built-in function.  */
@@ -121,11 +122,13 @@ AVAIL (hard_float, TARGET_HARD_FLOAT)
 
 /* RISCV_FTYPE_ATYPESN takes N RISCV_FTYPES-like type 

Re: drop -aux{dir,base}, revamp -dump{dir,base}

2020-06-19 Thread Alexandre Oliva
On Jun 18, 2020, Tobias Burnus  wrote:

> Thus, without the offload_target prefix, they would dump into the same file!

Here's an incremental patch, on top of the one you kindly tested the
other day (thanks!), that attempts to introduce per-offload-target dump
name variation.

Could you possibly give it a spin with the offloading targets you've
got?

Thanks in advance,


introduce per-offload-target dumpbase

From: Alexandre Oliva 


---
 gcc/lto-wrapper.c |5 +---
 gcc/testsuite/lib/scanoffload.exp |   45 +
 gcc/testsuite/lib/scanoffloadrtl.exp  |   41 +++---
 gcc/testsuite/lib/scanoffloadtree.exp |   41 +++---
 libgomp/testsuite/lib/libgomp-dg.exp  |8 --
 libgomp/testsuite/lib/libgomp.exp |1 +
 6 files changed, 89 insertions(+), 52 deletions(-)
 create mode 100644 gcc/testsuite/lib/scanoffload.exp

diff --git a/gcc/lto-wrapper.c b/gcc/lto-wrapper.c
index e990961..939a83a 100644
--- a/gcc/lto-wrapper.c
+++ b/gcc/lto-wrapper.c
@@ -854,10 +854,7 @@ compile_offload_image (const char *target, const char 
*compiler_path,
 "could not find %s in %s (consider using %<-B%>)",
 suffix + 1, compiler_path);
 
-  /* ??? We should probably use the TARGET name instead of "target"
- here, so as to create different file names for different offload
- targets.  */
-  dumpbase = concat (dumppfx, "target", NULL);
+  dumpbase = concat (dumppfx, "x", target, NULL);
 
   /* Generate temporary output file name.  */
   if (save_temps)
diff --git a/gcc/testsuite/lib/scanoffload.exp 
b/gcc/testsuite/lib/scanoffload.exp
new file mode 100644
index ..cbf9fcb
--- /dev/null
+++ b/gcc/testsuite/lib/scanoffload.exp
@@ -0,0 +1,45 @@
+#   Copyright (C) 2020 Free Software Foundation, Inc.
+
+# This program 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 of the License, or
+# (at your option) any later version.
+# 
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License
+# along with GCC; see the file COPYING3.  If not see
+# .
+
+# Utility for scanning offloading dump output, used by libgomp.exp.
+
+# Format an offload dump suffix given the offload target name in
+# OFFTGT and any suffix, probably empty, in SUFFIX.
+proc scoff-format { offtgt suffix } {
+return ".x$offtgt.mkoffload$suffix"
+}
+
+# Wrapper for scan procs.
+# Argument 0 is the index of the argument to replace when calling
+# argument 1 with the remaining arguments.  Use end-1 or end or so.
+proc scoff { args } {
+set idx [lindex $args 0]
+set prc [lindex $args 1]
+set args [lreplace $args 0 1]
+
+global offload_target
+if [info set offload_target] {
+   set target $offload_target
+   if { "$target" != "disable" } {
+   eval $prc [lreplace $args $idx $idx "[scoff-format $target [lindex 
$args $idx]]"]
+   }
+} else {
+   global offload_targets
+   foreach target [split $offload_targets ","] {
+   eval $prc [lreplace $args $idx $idx "[scoff-format $target [lindex 
$args $idx]]"]
+   }
+}
+}
diff --git a/gcc/testsuite/lib/scanoffloadrtl.exp 
b/gcc/testsuite/lib/scanoffloadrtl.exp
index e792450..be457f7 100644
--- a/gcc/testsuite/lib/scanoffloadrtl.exp
+++ b/gcc/testsuite/lib/scanoffloadrtl.exp
@@ -18,6 +18,7 @@
 # libgomp.exp.
 
 load_lib scandump.exp
+load_lib scanoffload.exp
 
 # Utility for scanning compiler result, invoked via dg-final.
 # Call pass if pattern is present, otherwise fail.
@@ -36,12 +37,12 @@ proc scan-offload-rtl-dump { args } {
return
 }
 if { [llength $args] >= 3 } {
-   scan-dump "offload-rtl" [lindex $args 0] \
-   "\[0-9\]\[0-9\]\[0-9]r.[lindex $args 1]" ".target.mkoffload" \
+   scoff end-1 scan-dump "offload-rtl" [lindex $args 0] \
+   "\[0-9\]\[0-9\]\[0-9]r.[lindex $args 1]" "" \
[lindex $args 2]
 } else {
-   scan-dump "offload-rtl" [lindex $args 0] \
-   "\[0-9\]\[0-9\]\[0-9]r.[lindex $args 1]" ".target.mkoffload"
+   scoff end scan-dump "offload-rtl" [lindex $args 0] \
+   "\[0-9\]\[0-9\]\[0-9]r.[lindex $args 1]" ""
 }
 }
 
@@ -61,12 +62,12 @@ proc scan-offload-rtl-dump-times { args } {
return
 }
 if { [llength $args] >= 4 } {
-   scan-dump-times "offload-rtl" [lindex $args 0] [lindex $args 1] \
-   "\[0-9\]\[0-9\]\[0-9]r.[lindex $args 2]" ".target.mkoffload" \
+   scoff end-1 scan-dump-times "offload-rtl" [lindex $args 0] \
+   [lindex $args 1] 

[PATCH] RISC-V: Normalize arch string in driver time

2020-06-19 Thread Kito Cheng
 - Normalize arch string would help the multi-lib handling, e.g. rv64gc and
   rv64g_c are both valid and same arch, but latter one would confuse
   the detection of multi-lib, earlier normalize can resolve this issue.

gcc/ChangeLog:

* config/riscv/riscv.h (DRIVER_SELF_SPECS): New.
---
 gcc/config/riscv/riscv.h | 4 
 1 file changed, 4 insertions(+)

diff --git a/gcc/config/riscv/riscv.h b/gcc/config/riscv/riscv.h
index 6119e6350620..1f2fe7e10e05 100644
--- a/gcc/config/riscv/riscv.h
+++ b/gcc/config/riscv/riscv.h
@@ -68,6 +68,10 @@ extern const char *riscv_expand_arch (int argc, const char 
**argv);
 %{mabi=*} \
 %(subtarget_asm_spec)"
 
+#undef DRIVER_SELF_SPECS
+#define DRIVER_SELF_SPECS \
+"%{march=*:-march=%:riscv_expand_arch(%*)}"
+
 #define TARGET_DEFAULT_CMODEL CM_MEDLOW
 
 #define LOCAL_LABEL_PREFIX "."
-- 
2.27.0



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

2020-06-19 Thread Marc Glisse

(not a reviewer)

It looks fine to me. Do we already handle the related (x|y)^y and (x|y)&~y ?

On Fri, 19 Jun 2020, Przemyslaw Wirkus wrote:


Hi all,

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

Bootstrapped and tested on aarch64-none-linux-gnu.

OK for master ?

Cheers,
Przemyslaw

gcc/ChangeLog:

PR tree-optimization/94880
* match.pd (A | B) - B -> (A & ~B): New simplification.

gcc/testsuite/ChangeLog:

PR tree-optimization/94880
* gcc.dg/tree-ssa/pr94880.c: New Test.




--
Marc Glisse


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

2020-06-19 Thread Przemyslaw Wirkus
Hi all,

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

Bootstrapped and tested on aarch64-none-linux-gnu.

OK for master ?

Cheers,
Przemyslaw

gcc/ChangeLog:

PR tree-optimization/94880
* match.pd (A | B) - B -> (A & ~B): New simplification.

gcc/testsuite/ChangeLog:

PR tree-optimization/94880
* gcc.dg/tree-ssa/pr94880.c: New Test.

diff --git a/gcc/match.pd b/gcc/match.pd
index 
33ee1a920bf4a036cc5fdb3c96b38b52765bdefb..10bf33d8cb215dfb0f54cb0ad02ad0af9d9dea7b
 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -1109,6 +1109,11 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
   && !TYPE_SATURATING (type))
   (bit_ior @0 @1)))
 
+/* (x | y) - y -> (x & ~y) */
+(simplify
+ (minus (bit_ior:cs @0 @1) @1)
+ (bit_and @0 (bit_not @1)))
+
 /* (x | y) - (x ^ y) -> x & y */
 (simplify
  (minus (bit_ior @0 @1) (bit_xor @0 @1))
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr94880.c 
b/gcc/testsuite/gcc.dg/tree-ssa/pr94880.c
new file mode 100644
index 
..f72166181479d43762423e7e153ee1832760cad0
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/pr94880.c
@@ -0,0 +1,29 @@
+/* PR tree-optimization/94786 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+/* { dg-final { scan-tree-dump-times "= ~\[xy\]_" 4 "optimized" } } */
+/* { dg-final { scan-tree-dump-times " & \[xy\]_" 4 "optimized" } } */
+
+unsigned
+foo_u(unsigned x, unsigned y)
+{
+  return (x | y) - y;
+}
+
+int
+foo_i(int x, int y)
+{
+  return (x | y) - y;
+}
+
+unsigned long long
+foo_ull(unsigned long long x, unsigned long long y)
+{
+  return (x | y) - y;
+}
+
+long long
+foo_ll(long long x, long long y)
+{
+  return (x | y) - y;
+}


[Ada] Further cleanup in constraint checking code for allocators

2020-06-19 Thread Pierre-Marie de Rodat
There is a second case where Expand_N_Assignment_Statement was applying
range checks for allocators and it is also obsolete.

No functional changes.

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

2020-06-19  Eric Botcazou  

gcc/ada/

* exp_ch5.adb (Expand_N_Assignment_Statement): Do not apply
range checks to allocators here.--- gcc/ada/exp_ch5.adb
+++ gcc/ada/exp_ch5.adb
@@ -2448,16 +2448,6 @@ package body Exp_Ch5 is
Apply_Length_Check (Rhs, Etype (Lhs));
 end if;
  end if;
-
-  --  Apply range check for access type case
-
-  elsif Is_Access_Type (Etype (Lhs))
-and then Nkind (Rhs) = N_Allocator
-and then Nkind (Expression (Rhs)) = N_Qualified_Expression
-  then
- Analyze_And_Resolve (Expression (Rhs));
- Apply_Range_Check
-   (Expression (Rhs), Designated_Type (Etype (Lhs)));
   end if;
 
   --  Ada 2005 (AI-231): Generate the run-time check



[Ada] Crash on compiling project with multiple subunits per file

2020-06-19 Thread Pierre-Marie de Rodat
This patch fixes the compiler whereby a project with manually specified
Naming for subunits such that several of the subunits exist in the same
file as the unit they are defined in.

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

2020-06-19  Justin Squirek  

gcc/ada/

* lib.adb (Check_Same_Extended_Unit): Add check to determine if
the body for the subunits exist in the same file as their
specifications.--- gcc/ada/lib.adb
+++ gcc/ada/lib.adb
@@ -362,6 +362,12 @@ package body Lib is
  --  Step 2: Check subunits. If a subunit is instantiated, follow the
  --  instantiation chain rather than the stub chain.
 
+ --  Note that we must handle the case where the subunit exists in the
+ --  same body as the main unit (which may happen when Naming gets
+ --  manually specified within a project file or through tools like
+ --  gprname). Otherwise, we will have an infinite loop jumping around
+ --  the same file.
+
  Unit1 := Unit (Cunit (Unum1));
  Unit2 := Unit (Cunit (Unum2));
  Inst1 := Instantiation (Sind1);
@@ -384,21 +390,35 @@ package body Lib is
   Length_Of_Name (Unit_Name (Unum2))
then
   Sloc2 := Sloc (Corresponding_Stub (Unit2));
-  Unum2 := Get_Source_Unit (Sloc2);
-  goto Continue;
 
+  if Unum2 /= Get_Source_Unit (Sloc2) then
+ Unum2 := Get_Source_Unit (Sloc2);
+ goto Continue;
+  else
+ null; --  Unum2 already designates the correct unit
+  end if;
else
   Sloc1 := Sloc (Corresponding_Stub (Unit1));
-  Unum1 := Get_Source_Unit (Sloc1);
-  goto Continue;
+
+  if Unum1 /= Get_Source_Unit (Sloc1) then
+ Unum1 := Get_Source_Unit (Sloc1);
+ goto Continue;
+  else
+ null; --  Unum1 already designates the correct unit
+  end if;
end if;
 
 --  Sloc1 in subunit, Sloc2 not
 
 else
Sloc1 := Sloc (Corresponding_Stub (Unit1));
-   Unum1 := Get_Source_Unit (Sloc1);
-   goto Continue;
+
+   if Unum1 /= Get_Source_Unit (Sloc1) then
+  Unum1 := Get_Source_Unit (Sloc1);
+  goto Continue;
+   else
+  null; --  Unum1 already designates the correct unit
+   end if;
 end if;
 
  --  Sloc2 in subunit, Sloc1 not
@@ -408,8 +428,13 @@ package body Lib is
and then Inst2 = No_Location
  then
 Sloc2 := Sloc (Corresponding_Stub (Unit2));
-Unum2 := Get_Source_Unit (Sloc2);
-goto Continue;
+
+if Unum2 /= Get_Source_Unit (Sloc2) then
+   Unum2 := Get_Source_Unit (Sloc2);
+   goto Continue;
+else
+   null; --  Unum2 already designates the correct unit
+end if;
  end if;
 
  --  Step 3: Check instances. The two locations may yield a common



[Ada] AI12-0293-1 Remove pragma Assert

2020-06-19 Thread Pierre-Marie de Rodat
...and replace it with an explicit check, so it is enabled whether or
not assertions are enabled.

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

2020-06-19  Bob Duff  

gcc/ada/

* libgnat/a-ststbo.adb (Write): Replace pragma Assert with "if
... raise Constraint_Error".--- gcc/ada/libgnat/a-ststbo.adb
+++ gcc/ada/libgnat/a-ststbo.adb
@@ -79,16 +79,19 @@ package body Ada.Streams.Storage.Bounded is
overriding procedure Write
  (Stream : in out Stream_Type; Item : Stream_Element_Array)
is
-  pragma Assert
-(Element_Count (Stream) + Item'Length <= Stream.Max_Elements
-   or else (raise Constraint_Error));
-  --  That is a precondition in the RM
-
-  New_Count : constant Stream_Element_Count :=
-Element_Count (Stream) + Item'Length;
begin
-  Stream.Elements (Element_Count (Stream) + 1 .. New_Count) := Item;
-  Stream.Count := New_Count;
+  if Element_Count (Stream) + Item'Length > Stream.Max_Elements then
+ --  That is a precondition in the RM
+ raise Constraint_Error;
+  end if;
+
+  declare
+ New_Count : constant Stream_Element_Count :=
+   Element_Count (Stream) + Item'Length;
+  begin
+ Stream.Elements (Element_Count (Stream) + 1 .. New_Count) := Item;
+ Stream.Count := New_Count;
+  end;
end Write;
 
---



[Ada] Deal with enumeration types with very large size

2020-06-19 Thread Pierre-Marie de Rodat
It is permitted to put very large size clauses on enumeration types
so we need to deal with them in Get_Integer_Type.

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

2020-06-19  Eric Botcazou  

gcc/ada/

* exp_attr.adb (Get_Integer_Type): Return the largest supported
unsigned integer type if need be.--- gcc/ada/exp_attr.adb
+++ gcc/ada/exp_attr.adb
@@ -1766,7 +1766,7 @@ package body Exp_Attr is
 Int_Typ := Standard_Unsigned;
 
  else
-raise Program_Error;
+Int_Typ := Standard_Long_Long_Unsigned;
  end if;
 
  return Int_Typ;



[Ada] Attempt to hide public entities in nested instance bodies

2020-06-19 Thread Pierre-Marie de Rodat
The procedure Hide_Public_Entities is responsible for (conservatively)
attempting to hide entities that have been previously made public by
the semantic analyzer in package bodies.  But it effectively does not
run on nested instance bodies because instantiations are still pending
by the time the encloding body is analyzed, so the change explicitly
allows this case in the caller Analyze_Package_Body_Helper.

The change also slightly improves the algorithm for nested instance
specs and more clearly separates the cases of objects and subprograms.

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

2020-06-19  Eric Botcazou  

gcc/ada/

* sem_ch7.adb (Hide_Public_Entities): Split handling of objects
and subprograms, and do not reject the latter upfront in nested
instance specs if there are no referencer subprograms at all.
(Analyze_Package_Body_Helper): Also call Hide_Public_Entities on
nested generic instances.--- gcc/ada/sem_ch7.adb
+++ gcc/ada/sem_ch7.adb
@@ -462,17 +462,11 @@ package body Sem_Ch7 is
 
--  Exceptions, objects and renamings do not need to be public
--  if they are not followed by a construct which can reference
-   --  and export them. Likewise for subprograms but we work harder
-   --  for them to see whether they are referenced on an individual
-   --  basis by looking into the table of referenced subprograms.
-   --  But we cannot say anything for entities declared in nested
-   --  instances because instantiations are not done yet so the
-   --  bodies are not visible and could contain references to them.
+   --  and export them.
+
elsif Nkind_In (Decl, N_Exception_Declaration,
  N_Object_Declaration,
- N_Object_Renaming_Declaration,
- N_Subprogram_Declaration,
- N_Subprogram_Renaming_Declaration)
+ N_Object_Renaming_Declaration)
then
   Decl_Id := Defining_Entity (Decl);
 
@@ -480,11 +474,32 @@ package body Sem_Ch7 is
 and then not Is_Imported (Decl_Id)
 and then not Is_Exported (Decl_Id)
 and then No (Interface_Name (Decl_Id))
-and then
-  ((Nkind (Decl) /= N_Subprogram_Declaration
- and then not Has_Referencer_Of_Non_Subprograms)
-or else (Nkind (Decl) = N_Subprogram_Declaration
-  and then not Subprogram_Table.Get (Decl_Id)))
+and then not Has_Referencer_Of_Non_Subprograms
+  then
+ Set_Is_Public (Decl_Id, False);
+  end if;
+
+   --  Likewise for subprograms and renamings, but we work harder
+   --  for them to see whether they are referenced on an individual
+   --  basis by looking into the table of referenced subprograms.
+
+   elsif Nkind_In (Decl, N_Subprogram_Declaration,
+ N_Subprogram_Renaming_Declaration)
+   then
+  Decl_Id := Defining_Entity (Decl);
+
+  --  We cannot say anything for subprograms declared in nested
+  --  instances because instantiations are not done yet so the
+  --  bodies are not visible and could contain references to
+  --  them, except if we still have no subprograms at all which
+  --  are referenced by an inlined body.
+
+  if (not In_Nested_Instance
+   or else not Subprogram_Table.Get_First)
+and then not Is_Imported (Decl_Id)
+and then not Is_Exported (Decl_Id)
+and then No (Interface_Name (Decl_Id))
+and then not Subprogram_Table.Get (Decl_Id)
   then
  Set_Is_Public (Decl_Id, False);
   end if;
@@ -1081,9 +1096,13 @@ package body Sem_Ch7 is
   --unit, especially subprograms.
 
   --  This is done only for top-level library packages or child units as
-  --  the algorithm does a top-down traversal of the package body.
+  --  the algorithm does a top-down traversal of the package body. This is
+  --  also done for instances because instantiations are still pending by
+  --  the time the enclosing package body is analyzed.
 
-  if (Scope (Spec_Id) = Standard_Standard or else Is_Child_Unit (Spec_Id))
+  if (Scope (Spec_Id) = Standard_Standard
+   or else Is_Child_Unit (Spec_Id)
+   or else Is_Generic_Instance (Spec_Id))
 and then not Is_Generic_Unit (Spec_Id)
   then
  Hide_Public_Entities 

[Ada] Reject junk expressions in attribute Update

2020-06-19 Thread Pierre-Marie de Rodat
Attribute Update only makes sense with named component associations. The
positional component associations were silently ignored by both
analysis, resolution and expansion; now they are rejected as illegal.

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

2020-06-19  Piotr Trojanek  

gcc/ada/

* sem_attr.adb (Analyze_Attribute): Reject illegal positional
component associations; fix syntax in comment about named
component associations.--- gcc/ada/sem_attr.adb
+++ gcc/ada/sem_attr.adb
@@ -6836,7 +6836,7 @@ package body Sem_Attr is
 --  Verify the consistency of types when the current component is
 --  part of a miltiple component update.
 
---Comp_1, ..., Comp_N => 
+--Comp_1 | ... | Comp_N => 
 
 if Present (Etype (Comp)) then
Base_Typ := Base_Type (Etype (Comp));
@@ -6877,6 +6877,11 @@ package body Sem_Attr is
 
  elsif Nkind (E1) /= N_Aggregate then
 Error_Attr ("attribute % requires component association list", N);
+
+ elsif Present (Expressions (E1)) then
+Error_Attr ("attribute % requires named component associations",
+First (Expressions (E1)));
+
  end if;
 
  --  Inspect the update aggregate, looking at all the associations and



[Ada] Fix check for bounds in aggregate expansion of allocator

2020-06-19 Thread Pierre-Marie de Rodat
The predicate function In_Place_Assign_OK is responsible for finding
out whether the in-place assignment of an aggregate is possible; for
array aggregates, it checks among other things whether sliding will
occur during the assignment.

But, in an allocator context, it does so by comparing the bounds of
the aggregate with those of the qualified expression surrounding it.
Now Constraint_Error is already guaranteed to be raised if they do
not match, so there is no point in doing it and the check must be
made against the bounds of the designated type instead.

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

2020-06-19  Eric Botcazou  

gcc/ada/

* exp_aggr.adb (In_Place_Assign_OK): In an allocator context,
check the bounds of an array aggregate against those of the
designated type, except if the latter is unconstrained.--- gcc/ada/exp_aggr.adb
+++ gcc/ada/exp_aggr.adb
@@ -4429,15 +4429,26 @@ package body Exp_Aggr is
   then
  Aggr_In := First_Index (Etype (N));
 
+ --  Context is an assignment
+
  if Parent_Kind = N_Assignment_Statement then
 Obj_In := First_Index (Etype (Name (Parent_Node)));
 
- else
---  Context is an allocator. Check bounds of aggregate against
---  given type in qualified expression.
+ --  Context is an allocator. Check the bounds of the aggregate against
+ --  those of the designated type, except in the case where the type is
+ --  unconstrained (and then we can directly return true, see below).
+
+ else pragma Assert (Parent_Kind = N_Allocator);
+declare
+   Desig_Typ : constant Entity_Id :=
+ Designated_Type (Etype (Parent_Node));
+begin
+   if not Is_Constrained (Desig_Typ) then
+  return True;
+   end if;
 
-pragma Assert (Parent_Kind = N_Allocator);
-Obj_In := First_Index (Etype (Entity (Subtype_Mark (Parent (N);
+   Obj_In := First_Index (Desig_Typ);
+end;
  end if;
 
  while Present (Aggr_In) loop



[Ada] Fix internal error on component of class-wide parameter in instance body

2020-06-19 Thread Pierre-Marie de Rodat
This fixes a Program_Error raised by Analyze_Selected_Component because
it didn't manage to find the proper selector for a selected component
applied to a parameter of class-wide type in an instance body.

The problem is that the tagged type is derived in the private part of
the generic spec from a private tagged type declared in a parent unit,
but this second tagged type is never referenced in the generic body,
so the mechanism implemented to restore the proper views in instances
does not work in this case.

Analyze_Selected_Component already has a specific countermeasure for
tagged types in instance bodies so this extends its usage to this case.

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

2020-06-19  Eric Botcazou  

gcc/ada/

* sem_ch4.adb (Analyze_Selected_Component): In an instance body,
also invoke Find_Component_In_Instance on the parent subtype of
a derived tagged type immediately visible.  Remove obsolete case.--- gcc/ada/sem_ch4.adb
+++ gcc/ada/sem_ch4.adb
@@ -5268,25 +5268,21 @@ package body Sem_Ch4 is
   end loop;
 
--  Another special case: the type is an extension of a private
-   --  type T, is an actual in an instance, and we are in the body
-   --  of the instance, so the generic body had a full view of the
-   --  type declaration for T or of some ancestor that defines the
-   --  component in question.
+   --  type T, either is an actual in an instance or is immediately
+   --  visible, and we are in the body of the instance, which means
+   --  the generic body had a full view of the type declaration for
+   --  T or some ancestor that defines the component in question.
+   --  This happens because Is_Visible_Component returned False on
+   --  this component, as T or the ancestor is still private since
+   --  the Has_Private_View mechanism is bypassed because T or the
+   --  ancestor is not directly referenced in the generic body.
 
elsif Is_Derived_Type (Type_To_Use)
- and then Used_As_Generic_Actual (Type_To_Use)
+ and then (Used_As_Generic_Actual (Type_To_Use)
+or else Is_Immediately_Visible (Type_To_Use))
  and then In_Instance_Body
then
   Find_Component_In_Instance (Parent_Subtype (Type_To_Use));
-
-   --  In ASIS mode the generic parent type may be absent. Examine
-   --  the parent type directly for a component that may have been
-   --  visible in a parent generic unit.
-   --  ??? Revisit now that ASIS mode is gone
-
-   elsif Is_Derived_Type (Prefix_Type) then
-  Par := Etype (Prefix_Type);
-  Find_Component_In_Instance (Par);
end if;
 end;
 



[Ada] Spurious error on private type in ghost expression function

2020-06-19 Thread Pierre-Marie de Rodat
The compiler rejects an expression function declared in a generic
package with Ghost aspect, when the expression of the function includes
a reference to a private type declared outside of the package, whose
full view has not yet been analyzed, and the Ghost mode is Ignore.

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

2020-06-19  Ed Schonberg  

gcc/ada/

* sem_ch6.adb (Analyze_Expression_Function): Do not indicate
that the function has a completion if it appears within a Ghost
generic package.--- gcc/ada/sem_ch6.adb
+++ gcc/ada/sem_ch6.adb
@@ -499,9 +499,14 @@ package body Sem_Ch6 is
  --  Within a generic preanalyze the original expression for name
  --  capture. The body is also generated but plays no role in
  --  this because it is not part of the original source.
+ --  If this is an ignored Ghost entity, analysis of the generated
+ --  body is needed to hide external references (as is done in
+ --  Analyze_Subprogram_Body) after which the the subprogram profile
+ --  can be frozen, which is needed to expand calls to such an ignored
+ --  Ghost subprogram.
 
  if Inside_A_Generic then
-Set_Has_Completion (Def_Id);
+Set_Has_Completion (Def_Id, not Is_Ignored_Ghost_Entity (Def_Id));
 Push_Scope (Def_Id);
 Install_Formals (Def_Id);
 Preanalyze_Spec_Expression (Expr, Etype (Def_Id));



[Ada] Fix small fallout of previous change for Analyze_Selected_Component

2020-06-19 Thread Pierre-Marie de Rodat
The removal of the obsolete code path originally implemented for ASIS
has exposed a latent issue for components of discriminated tagged types
in instance bodies: Is_Visible_Component can wrongly return false for
them even though the ancestor type is perfectly visible in the instance.

No functional changes.

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

2020-06-19  Eric Botcazou  

gcc/ada/

* sem_ch3.adb (Is_Visible_Component): Reason only on the private
status of the original type in an instance body.--- gcc/ada/sem_ch3.adb
+++ gcc/ada/sem_ch3.adb
@@ -18864,7 +18864,9 @@ package body Sem_Ch3 is
   --  a component in a sibling package that is inherited from a visible
   --  component of a type in an ancestor package; the component in the
   --  sibling package should not be visible even though the component it
-  --  inherited from is visible). This does not apply however in the case
+  --  inherited from is visible), but instance bodies are not subject to
+  --  this second case since they have the Has_Private_View mechanism to
+  --  ensure proper visibility. This does not apply however in the case
   --  where the scope of the type is a private child unit, or when the
   --  parent comes from a local package in which the ancestor is currently
   --  visible. The latter suppression of visibility is needed for cases
@@ -18874,7 +18876,8 @@ package body Sem_Ch3 is
 or else
   (not Is_Private_Descendant (Type_Scope)
 and then not In_Open_Scopes (Type_Scope)
-and then Has_Private_Declaration (Original_Type))
+and then Has_Private_Declaration (Original_Type)
+and then not In_Instance_Body)
   then
  --  If the type derives from an entity in a formal package, there
  --  are no additional visible components.



[Ada] Spurious condition warning on type conversion in return

2020-06-19 Thread Pierre-Marie de Rodat
This patch fixes the compiler whereby a conversion to Interfaces.C.Bool
within a return statement may cause a spurious "condition always X"
warning.

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

2020-06-19  Justin Squirek  

gcc/ada/

* sem_warn.adb (Warn_On_Known_Condition): Add general sanity
check that asserts the original source node being checked
contains an entity. If not, it could be the result of special
case expansion for type conversions.--- gcc/ada/sem_warn.adb
+++ gcc/ada/sem_warn.adb
@@ -3520,6 +3520,7 @@ package body Sem_Warn is
   if Constant_Condition_Warnings
 and then Is_Known_Branch
 and then Comes_From_Source (Orig)
+and then Nkind (Orig) in N_Has_Entity
 and then not In_Instance
   then
  --  Don't warn if comparison of result of attribute against a constant



[Ada] Small cleanup in Apply_Range_Check implementation

2020-06-19 Thread Pierre-Marie de Rodat
The procedure Apply_Range_Check is the only caller of the procedure
Apply_Selected_Range_Checks and always passes Do_Static as False,
which means that the True path is unreachable in the latter, so this
change merges the latter in the former.

Moveover, it adds a new parameter Insert_Node to Apply_Range_Check
with the same semantics as other similar routines, namely that it
gives the insertion point of the checks if not Empty. This makes it
possible for Analyze_Subtype_Declaration to call it in the array
case too (it already calls it in the scalar case) instead of using
the awkward Get_Range_Checks/Insert_Range_Checks interface.

No functional changes.

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

2020-06-19  Eric Botcazou  

gcc/ada/

* checks.ads (Apply_Static_Length_Check): Move up.
(Apply_Range_Check): Add parameter Insert_Node.
* checks.adb (Apply_Selected_Range_Checks): Merge into...
(Apply_Range_Check): ...this.  Add parameter Insert_Node,
pass it as Warn_Node to Selected_Range_Checks and use it
as insertion point for the checks.
* sem_ch3.adb (Analyze_Subtype_Declaration): Rewrite block
dealing with the range checks for the subtype indication.
Use local variable and call Apply_Range_Check in both cases.--- gcc/ada/checks.adb
+++ gcc/ada/checks.adb
@@ -240,16 +240,6 @@ package body Checks is
--  described for the above routines. The Do_Static flag indicates that
--  only a static check is to be done.
 
-   procedure Apply_Selected_Range_Checks
- (Expr   : Node_Id;
-  Target_Typ : Entity_Id;
-  Source_Typ : Entity_Id;
-  Do_Static  : Boolean);
-   --  This is the subprogram that does all the work for Apply_Range_Check.
-   --  Expr, Target_Typ and Source_Typ are as described for the above
-   --  routine. The Do_Static flag indicates that only a static check is
-   --  to be done.
-
procedure Compute_Range_For_Arithmetic_Op
  (Op   : Node_Kind;
   Lo_Left  : Uint;
@@ -364,8 +354,8 @@ package body Checks is
   Target_Typ : Entity_Id;
   Source_Typ : Entity_Id;
   Warn_Node  : Node_Id) return Check_Result;
-   --  Like Apply_Selected_Range_Checks, except it doesn't modify anything,
-   --  just returns a list of nodes as described in the spec of this package
+   --  Like Apply_Range_Checks, except it doesn't modify anything, just
+   --  returns a list of nodes as described in the spec of this package
--  for the Range_Check function.
 
--
@@ -2910,13 +2900,107 @@ package body Checks is
---
 
procedure Apply_Range_Check
- (Expr   : Node_Id;
-  Target_Typ : Entity_Id;
-  Source_Typ : Entity_Id := Empty)
+ (Expr: Node_Id;
+  Target_Typ  : Entity_Id;
+  Source_Typ  : Entity_Id := Empty;
+  Insert_Node : Node_Id   := Empty)
is
+  Checks_On : constant Boolean :=
+not Index_Checks_Suppressed (Target_Typ)
+  or else
+not Range_Checks_Suppressed (Target_Typ);
+
+  Loc : constant Source_Ptr := Sloc (Expr);
+
+  Cond : Node_Id;
+  R_Cno: Node_Id;
+  R_Result : Check_Result;
+
begin
-  Apply_Selected_Range_Checks
-(Expr, Target_Typ, Source_Typ, Do_Static => False);
+  --  Only apply checks when generating code. In GNATprove mode, we do not
+  --  apply the checks, but we still call Selected_Range_Checks to possibly
+  --  issue errors on SPARK code when a run-time error can be detected at
+  --  compile time.
+
+  if not GNATprove_Mode then
+ if not Expander_Active or not Checks_On then
+return;
+ end if;
+  end if;
+
+  R_Result :=
+Selected_Range_Checks (Expr, Target_Typ, Source_Typ, Insert_Node);
+
+  if GNATprove_Mode then
+ return;
+  end if;
+
+  for J in 1 .. 2 loop
+ R_Cno := R_Result (J);
+ exit when No (R_Cno);
+
+ --  The range check requires runtime evaluation. Depending on what its
+ --  triggering condition is, the check may be converted into a compile
+ --  time constraint check.
+
+ if Nkind (R_Cno) = N_Raise_Constraint_Error
+   and then Present (Condition (R_Cno))
+ then
+Cond := Condition (R_Cno);
+
+--  Insert the range check before the related context. Note that
+--  this action analyses the triggering condition.
+
+if Present (Insert_Node) then
+   Insert_Action (Insert_Node, R_Cno);
+else
+   Insert_Action (Expr, R_Cno);
+end if;
+
+--  The triggering condition evaluates to True, the range check
+--  can be converted into a compile time constraint check.
+
+if Is_Entity_Name (Cond)
+  and then Entity (Cond) = Standard_True
+then
+   --  

[Ada] Fix small fallout of previous change for allocator

2020-06-19 Thread Pierre-Marie de Rodat
Resolve_Qualified_Expression propagates the type of the operand into
the node itself if the original type of the node is unconstrained,
but this is not needed for an allocator and might be problematic,
e.g. for the CCG compiler which expects unconstrained array types.

No functional changes.

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

2020-06-19  Eric Botcazou  

gcc/ada/

* sem_res.adb (Resolve_Qualified_Expression): Do not override the
type of the node when it is unconstrained if it is for an allocator.--- gcc/ada/sem_res.adb
+++ gcc/ada/sem_res.adb
@@ -10161,10 +10161,12 @@ package body Sem_Res is
 
   --  If the target type is unconstrained, then we reset the type of the
   --  result from the type of the expression. For other cases, the actual
-  --  subtype of the expression is the target type.
+  --  subtype of the expression is the target type. But we avoid doing it
+  --  for an allocator since this is not needed and might be problematic.
 
   if Is_Composite_Type (Target_Typ)
 and then not Is_Constrained (Target_Typ)
+and then Nkind (Parent (N)) /= N_Allocator
   then
  Set_Etype (N, Etype (Expr));
   end if;



[Ada] Style checks on invalid UTF character cause crash

2020-06-19 Thread Pierre-Marie de Rodat
This patch fixes the compiler whereby style checks for extranious
whitespace (under the flag -gnatyb) may crash the compiler when a
manually specified UTF character is present directly before such an
extranious whitespace.

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

2020-06-19  Justin Squirek  

gcc/ada/

* widechar.adb, widechar.ads (Skip_Wide): Catch validity check
failure when skipping over characters, and update comment to
reflect Skip_Wide's usage in error printing.--- gcc/ada/widechar.adb
+++ gcc/ada/widechar.adb
@@ -203,7 +203,16 @@ package body Widechar is
--  Start of processing for Skip_Wide
 
begin
-  Discard := WC_Skip (Skip_Char, Wide_Character_Encoding_Method);
+  --  Capture invalid wide characters errors since we are going to discard
+  --  the result anyway. We just want to move past it.
+
+  begin
+ Discard := WC_Skip (Skip_Char, Wide_Character_Encoding_Method);
+  exception
+ when Constraint_Error =>
+null;
+  end;
+
   Wide_Char_Byte_Count := Wide_Char_Byte_Count + Nat (P - P_Init - 1);
end Skip_Wide;
 
@@ -235,7 +244,16 @@ package body Widechar is
--  Start of processing for Skip_Wide
 
begin
-  Discard := WC_Skip (Skip_Char, Wide_Character_Encoding_Method);
+  --  Capture invalid wide characters errors since we are going to discard
+  --  the result anyway. We just want to move past it.
+
+  begin
+ Discard := WC_Skip (Skip_Char, Wide_Character_Encoding_Method);
+  exception
+ when Constraint_Error =>
+null;
+  end;
+
   Wide_Char_Byte_Count := Wide_Char_Byte_Count + Nat (P - P_Init - 1);
end Skip_Wide;
 

--- gcc/ada/widechar.ads
+++ gcc/ada/widechar.ads
@@ -81,9 +81,7 @@ package Widechar is
--  On entry, S (P) points to an ESC character for a wide character escape
--  sequence or to an upper half character if the encoding method uses the
--  upper bit, or to a left bracket if the brackets encoding method is in
-   --  use. On exit, P is bumped past the wide character sequence. No error
-   --  checking is done, since this is only used on escape sequences generated
-   --  by Set_Wide, which are known to be correct.
+   --  use. On exit, P is bumped past the wide character sequence.
 
procedure Skip_Wide (S : Source_Buffer_Ptr; P : in out Source_Ptr);
--  Similar to the above procedure, but operates on a source buffer



[Ada] AI12-0366 Changes to Big_Integer and Big_Real

2020-06-19 Thread Pierre-Marie de Rodat
This AI changes the API to move the validity checks to a subtype
Valid_Big_Integer/Real with a dynamic predicate.

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

2020-06-19  Arnaud Charlet  

gcc/ada/

* libgnat/a-nbnbin.adb, libgnat/a-nbnbin.ads,
libgnat/a-nbnbin__gmp.adb, libgnat/a-nbnbre.adb,
libgnat/a-nbnbre.ads: Update spec according to AI12-0366.

patch.diff.gz
Description: application/gzip


[Ada] Plug small loophole in implementation of AI12-0100

2020-06-19 Thread Pierre-Marie de Rodat
The qualified expressions present in allocators use a specific circuitry
during type resolution and, therefore, escape the new static predicate
check required by AI12-0100 and present in Resolve_Qualified_Expression.

This removes the specific circuitry, as well as makes small adjustments
to Resolve_Qualified_Expression needed in allocator contexts.

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

2020-06-19  Eric Botcazou  

gcc/ada/

* sem_res.adb (Resolve_Allocator): Call Resolve_Qualified_Expression
on the qualified expression, if any, instead of doing an incomplete
type resolution manually.
(Resolve_Qualified_Expression): Apply predicate check to operand.--- gcc/ada/sem_res.adb
+++ gcc/ada/sem_res.adb
@@ -5133,8 +5133,9 @@ package body Sem_Res is
   ("class-wide allocator not allowed for this access type", N);
  end if;
 
- Resolve (Expression (E), Etype (E));
- Check_Non_Static_Context (Expression (E));
+ --  Do a full resolution to apply constraint and predicate checks
+
+ Resolve_Qualified_Expression (E, Etype (E));
  Check_Unset_Reference (Expression (E));
 
  --  Allocators generated by the build-in-place expansion mechanism
@@ -5168,16 +5169,6 @@ package body Sem_Res is
 end if;
  end if;
 
- --  A qualified expression requires an exact match of the type. Class-
- --  wide matching is not allowed.
-
- if (Is_Class_Wide_Type (Etype (Expression (E)))
-  or else Is_Class_Wide_Type (Etype (E)))
-   and then Base_Type (Etype (Expression (E))) /= Base_Type (Etype (E))
- then
-Wrong_Type (Expression (E), Etype (E));
- end if;
-
  --  Calls to build-in-place functions are not currently supported in
  --  allocators for access types associated with a simple storage pool.
  --  Supporting such allocators may require passing additional implicit
@@ -10199,7 +10190,7 @@ package body Sem_Res is
 
   if Has_Predicates (Target_Typ) then
  Check_Expression_Against_Static_Predicate
-   (N, Target_Typ, Static_Failure_Is_Error => True);
+   (Expr, Target_Typ, Static_Failure_Is_Error => True);
   end if;
end Resolve_Qualified_Expression;
 



[Ada] Remove second warning for convention C_Variadic_n

2020-06-19 Thread Pierre-Marie de Rodat
It turns out that there are legitimate cases now flagged by the warning.

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

2020-06-19  Eric Botcazou  

gcc/ada/

* sem_prag.adb (Process_Convention): Revert previous change.--- gcc/ada/sem_prag.adb
+++ gcc/ada/sem_prag.adb
@@ -8304,7 +8304,8 @@ package body Sem_Prag is
  ("??C_Variadic_0 cannot be used for an 'I'S'O C function",
   Get_Pragma_Arg (Arg2));
 
---  Now check the number of parameters of the subprogram
+--  Now check the number of parameters of the subprogram and give
+--  an error if it is lower than n.
 
 elsif Present (Subp) then
declare
@@ -8323,21 +8324,11 @@ package body Sem_Prag is
  Next_Formal (Formal);
   end loop;
 
-  --  Error out if the number of parameters is lower than n
-
   if Count < Minimum then
  Error_Msg_Uint_1 := UI_From_Int (Minimum);
  Error_Pragma_Arg
("argument of pragma% must have at least"
 & "^ parameters", Arg2);
-
-  --  But warn if it is exactly n because this is useless
-
-  elsif Count = Minimum then
- Error_Msg_Uint_1 := UI_From_Int (Minimum + 1);
- Error_Msg_N
-   ("??subprogram should have at least ^ parameters",
-Get_Pragma_Arg (Arg2));
   end if;
end;
 end if;



[Ada] universal_access equality and 'Access attributes

2020-06-19 Thread Pierre-Marie de Rodat
For any object Foo, Foo'Access can never be passed as a parameter of a
call to the equality op for Universal_Access, so add this check and do
some code cleanup on recent changes at the same time.

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

2020-06-19  Arnaud Charlet  

gcc/ada/

* sem_ch4.adb (Find_Equality_Types.Check_Access_Attribute): New.
(Find_Equality_Types): Move universal_access related checks at
the end of the processing and add call to
Check_Access_Attribute.--- gcc/ada/sem_ch4.adb
+++ gcc/ada/sem_ch4.adb
@@ -6540,12 +6540,24 @@ package body Sem_Ch4 is
   Op_Id : Entity_Id;
   N : Node_Id)
is
-  Index : Interp_Index := 0;
-  It: Interp;
-  Found : Boolean := False;
-  I_F   : Interp_Index;
-  T_F   : Entity_Id;
-  Scop  : Entity_Id := Empty;
+  Index   : Interp_Index := 0;
+  It  : Interp;
+  Found   : Boolean := False;
+  Is_Universal_Access : Boolean := False;
+  I_F : Interp_Index;
+  T_F : Entity_Id;
+  Scop: Entity_Id := Empty;
+
+  procedure Check_Access_Attribute (N : Node_Id);
+  --  For any object, '[Unchecked_]Access of such object can never be
+  --  passed as a parameter of a call to the Universal_Access equality
+  --  operator.
+  --  This is because the expected type for Obj'Access in a call to
+  --  the Standard."=" operator whose formals are of type
+  --  Universal_Access is Universal_Integer, and Universal_Access
+  --  doesn't have a designated type. For more detail see RM 6.4.1(3)
+  --  and 3.10.2.
+  --  This procedure assumes that the context is a universal_access.
 
   function Check_Access_Object_Types
 (N : Node_Id; Typ : Entity_Id) return Boolean;
@@ -6574,6 +6586,23 @@ package body Sem_Ch4 is
   --  and an error can be emitted now, after trying to disambiguate, i.e.
   --  applying preference rules.
 
+  
+  -- Check_Access_Attribute --
+  
+
+  procedure Check_Access_Attribute (N : Node_Id) is
+  begin
+ if Nkind (N) = N_Attribute_Reference
+   and then Nam_In (Attribute_Name (N),
+Name_Access,
+Name_Unchecked_Access)
+ then
+Error_Msg_N
+  ("access attribute cannot be used as actual for "
+   & "universal_access equality", N);
+ end if;
+  end Check_Access_Attribute;
+
   ---
   -- Check_Access_Object_Types --
   ---
@@ -6867,14 +6896,6 @@ package body Sem_Ch4 is
and then (not Universal_Access
   or else Check_Access_Object_Types (R, T1))
  then
-if Universal_Access
-  and then Is_Access_Subprogram_Type (T1)
-  and then Nkind (L) /= N_Null
-  and then Nkind (R) /= N_Null
-then
-   Check_Compatible_Profiles (R, T1);
-end if;
-
 if Found
   and then Base_Type (T1) /= Base_Type (T_F)
 then
@@ -6887,12 +6908,14 @@ package body Sem_Ch4 is
 
else
   T_F := It.Typ;
+  Is_Universal_Access := Universal_Access;
end if;
 
 else
Found := True;
T_F   := T1;
I_F   := Index;
+   Is_Universal_Access := Universal_Access;
 end if;
 
 if not Analyzed (L) then
@@ -6947,6 +6970,18 @@ package body Sem_Ch4 is
 Get_Next_Interp (Index, It);
  end loop;
   end if;
+
+  if Is_Universal_Access then
+ if Is_Access_Subprogram_Type (Etype (L))
+   and then Nkind (L) /= N_Null
+   and then Nkind (R) /= N_Null
+ then
+Check_Compatible_Profiles (R, Etype (L));
+ end if;
+
+ Check_Access_Attribute (R);
+ Check_Access_Attribute (L);
+  end if;
end Find_Equality_Types;
 
-



[Ada] Decorate record delta aggregate for GNATprove

2020-06-19 Thread Pierre-Marie de Rodat
For a record delta aggregate like "(X with delta C => 1)" the component
choice identifier "C" had empty Entity and Etype fields.

For GNAT this was fine, because it expands delta aggregates into
assignments using component names alone; for GNATprove this was
troublesome, because it keeps delta aggregates unexpanded and would have
to re-discover the missing fields by itself.

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

2020-06-19  Piotr Trojanek  

gcc/ada/

* sem_aggr.adb (Resolve_Delta_Record_Aggregate): Modify a nested
Get_Component_Type routine to return a component and not just
its type; use this routine to decorate the identifier within the
delta aggregate.--- gcc/ada/sem_aggr.adb
+++ gcc/ada/sem_aggr.adb
@@ -2762,9 +2762,9 @@ package body Sem_Aggr is
   --  part, verify that it is within the same variant as that of previous
   --  specified variant components of the delta.
 
-  function Get_Component_Type (Nam : Node_Id) return Entity_Id;
-  --  Locate component with a given name and return its type. If none found
-  --  report error.
+  function Get_Component (Nam : Node_Id) return Entity_Id;
+  --  Locate component with a given name and return it. If none found then
+  --  report error and return Empty.
 
   function Nested_In (V1 : Node_Id; V2 : Node_Id) return Boolean;
   --  Determine whether variant V1 is within variant V2
@@ -2828,11 +2828,11 @@ package body Sem_Aggr is
  end if;
   end Check_Variant;
 
-  
-  -- Get_Component_Type --
-  
+  ---
+  -- Get_Component --
+  ---
 
-  function Get_Component_Type (Nam : Node_Id) return Entity_Id is
+  function Get_Component (Nam : Node_Id) return Entity_Id is
  Comp : Entity_Id;
 
   begin
@@ -2843,15 +2843,15 @@ package body Sem_Aggr is
   Error_Msg_N ("delta cannot apply to discriminant", Nam);
end if;
 
-   return Etype (Comp);
+   return Comp;
 end if;
 
 Next_Entity (Comp);
  end loop;
 
  Error_Msg_NE ("type& has no component with this name", Nam, Typ);
- return Any_Type;
-  end Get_Component_Type;
+ return Empty;
+  end Get_Component;
 
   ---
   -- Nested_In --
@@ -2898,6 +2898,7 @@ package body Sem_Aggr is
 
   Assoc : Node_Id;
   Choice: Node_Id;
+  Comp  : Entity_Id;
   Comp_Type : Entity_Id := Empty; -- init to avoid warning
 
--  Start of processing for Resolve_Delta_Record_Aggregate
@@ -2909,10 +2910,21 @@ package body Sem_Aggr is
   while Present (Assoc) loop
  Choice := First (Choice_List (Assoc));
  while Present (Choice) loop
-Comp_Type := Get_Component_Type (Choice);
+Comp := Get_Component (Choice);
 
-if Comp_Type /= Any_Type then
+if Present (Comp) then
Check_Variant (Choice);
+
+   Comp_Type := Etype (Comp);
+
+   --  Decorate the component reference by setting its entity and
+   --  type, as otherwise backends like GNATprove would have to
+   --  rediscover this information by themselves.
+
+   Set_Entity (Choice, Comp);
+   Set_Etype  (Choice, Comp_Type);
+else
+   Comp_Type := Any_Type;
 end if;
 
 Next (Choice);



[Ada] Fix validity checking for class-wide objects

2020-06-19 Thread Pierre-Marie de Rodat
When applying 'Valid_Scalars attribute to a class-wide object (either
explicitly or as a result of a command line switch like -gnateV), we
must strip away type privacy.

Note: this is just a minimal fix to avoid a crash. Attribute
'Valid_Scalars is not really working as expected on tagged types,
especially with private derivations and type extensions.

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

2020-06-19  Piotr Trojanek  

gcc/ada/

* exp_attr.adb (Build_Record_VS_Func): Strip privacy and type
derivation from the root type when 'Valid_Scalars is applied to
a class-wide type.--- gcc/ada/exp_attr.adb
+++ gcc/ada/exp_attr.adb
@@ -737,7 +737,7 @@ package body Exp_Attr is
   --  Use the root type when dealing with a class-wide type
 
   if Is_Class_Wide_Type (Typ) then
- Typ := Root_Type (Typ);
+ Typ := Validated_View (Root_Type (Typ));
   end if;
 
   Typ_Decl := Declaration_Node (Typ);



[Ada] Add comments about attribute 'Valid_Scalars on private tagged types

2020-06-19 Thread Pierre-Marie de Rodat
Attribute 'Valid_Scalars on private tagged types doesn't work as it
should on private tagged types. Fix most likely needs to modify three
routines.  This patch document the problem with a ??? comment.

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

2020-06-19  Piotr Trojanek  

gcc/ada/

* exp_attr.adb (Expand_N_Attribute_Reference): Add comment.
* sem_attr.adb (Analyze_Attribute): Add ??? comment.
* sem_util.ads (Valid_Scalars): This routine is only used for
'Valid_Scalars and not for 'Valid.--- gcc/ada/exp_attr.adb
+++ gcc/ada/exp_attr.adb
@@ -7094,7 +7094,8 @@ package body Exp_Attr is
 
  Expr := Empty;
 
- --  Attribute 'Valid_Scalars is not supported on private tagged types
+ --  Attribute 'Valid_Scalars is not supported on private tagged types;
+ --  see a detailed explanation where this attribute is analyzed.
 
  if Is_Private_Type (Ptyp) and then Is_Tagged_Type (Ptyp) then
 null;

--- gcc/ada/sem_attr.adb
+++ gcc/ada/sem_attr.adb
@@ -7016,6 +7016,10 @@ package body Sem_Attr is
--  types due to a code generation issue. Is_Visible_Component
--  does not allow for a component of a private tagged type to
--  be successfully retrieved.
+   --  ??? This attribute should simply ignore type privacy
+   --  (see Validated_View). It should examine components of the
+   --  tagged type extensions (if any) and recursively examine
+   --  'Valid_Scalars of the parent's type (if any).
 
--  Do not use Error_Attr_P because this bypasses any subsequent
--  processing and leaves the attribute with type Any_Type. This

--- gcc/ada/sem_util.ads
+++ gcc/ada/sem_util.ads
@@ -3050,10 +3050,10 @@ package Sem_Util is
--  conversions, and unchecked conversions.
 
function Validated_View (Typ : Entity_Id) return Entity_Id;
-   --  Obtain the "validated view" of arbitrary type Typ which is suitable
-   --  for verification by attributes 'Valid and 'Valid_Scalars. This view
-   --  is the type itself or its full view while stripping away concurrency,
-   --  derivations, and privacy.
+   --  Obtain the "validated view" of arbitrary type Typ which is suitable for
+   --  verification by attributes 'Valid_Scalars. This view is the type itself
+   --  or its full view while stripping away concurrency, derivations, and
+   --  privacy.
 
function Visible_Ancestors (Typ : Entity_Id) return Elist_Id;
--  [Ada 2012:AI-0125-1]: Collect all the visible parents and progenitors



[Ada] Simplify processing of 'Valid_Scalars on array types

2020-06-19 Thread Pierre-Marie de Rodat
When calling routine Build_Array_VS_Func that expands attribute
Valid_Scalars on array objects we tested Scalar_Part_Present on the
array's component type. This was unnecessary, because
Build_Array_VS_Func is only called after checking Scalar_Part_Present on
the array's type, which internally Scalar_Part_Present on the array's
component type.

This patch is a cleanup only; semantics is unaffected.

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

2020-06-19  Piotr Trojanek  

gcc/ada/

* exp_attr.adb (Expand_N_Attribute_Reference): Do not call
Scalar_Part_Present on the array component's type.
(Build_Array_VS_Func): Remove Comp_Typ parameter, because it can
be easily computed from the Array_Top parameter *and redundant
parameters are confusing and error-prone).--- gcc/ada/exp_attr.adb
+++ gcc/ada/exp_attr.adb
@@ -79,8 +79,7 @@ package body Exp_Attr is
function Build_Array_VS_Func
  (Attr   : Node_Id;
   Formal_Typ : Entity_Id;
-  Array_Typ  : Entity_Id;
-  Comp_Typ   : Entity_Id) return Entity_Id;
+  Array_Typ  : Entity_Id) return Entity_Id;
--  Validate the components of an array type by means of a function. Return
--  the entity of the validation function. The parameters are as follows:
--
@@ -91,8 +90,6 @@ package body Exp_Attr is
--  parameter.
--
--* Array_Typ - the array type whose components are to be validated
-   --
-   --* Comp_Typ - the component type of the array
 
function Build_Disp_Get_Task_Id_Call (Actual : Node_Id) return Node_Id;
--  Build a call to Disp_Get_Task_Id, passing Actual as actual parameter
@@ -237,10 +234,11 @@ package body Exp_Attr is
function Build_Array_VS_Func
  (Attr   : Node_Id;
   Formal_Typ : Entity_Id;
-  Array_Typ  : Entity_Id;
-  Comp_Typ   : Entity_Id) return Entity_Id
+  Array_Typ  : Entity_Id) return Entity_Id
is
-  Loc : constant Source_Ptr := Sloc (Attr);
+  Loc  : constant Source_Ptr := Sloc (Attr);
+  Comp_Typ : constant Entity_Id :=
+Validated_View (Component_Type (Array_Typ));
 
   function Validate_Component
 (Obj_Id  : Entity_Id;
@@ -7088,9 +7086,8 @@ package body Exp_Attr is
   ---
 
   when Attribute_Valid_Scalars => Valid_Scalars : declare
- Val_Typ  : constant Entity_Id := Validated_View (Ptyp);
- Comp_Typ : Entity_Id;
- Expr : Node_Id;
+ Val_Typ : constant Entity_Id := Validated_View (Ptyp);
+ Expr: Node_Id;
 
   begin
  --  Assume that the prefix does not need validation
@@ -7130,21 +7127,16 @@ package body Exp_Attr is
  --  dimensions of the array while checking individual components.
 
  elsif Is_Array_Type (Val_Typ) then
-Comp_Typ := Validated_View (Component_Type (Val_Typ));
-
-if Scalar_Part_Present (Comp_Typ) then
-   Expr :=
- Make_Function_Call (Loc,
-   Name   =>
- New_Occurrence_Of
-   (Build_Array_VS_Func
- (Attr   => N,
-  Formal_Typ => Ptyp,
-  Array_Typ  => Val_Typ,
-  Comp_Typ   => Comp_Typ),
-   Loc),
-   Parameter_Associations => New_List (Pref));
-end if;
+Expr :=
+  Make_Function_Call (Loc,
+Name   =>
+  New_Occurrence_Of
+(Build_Array_VS_Func
+  (Attr   => N,
+   Formal_Typ => Ptyp,
+   Array_Typ  => Val_Typ),
+Loc),
+Parameter_Associations => New_List (Pref));
 
  --  Validate the scalar components, discriminants of a record type by
  --  examining the structure of a record type.



[Ada] Fix validity checks on attribute 'Old prefix

2020-06-19 Thread Pierre-Marie de Rodat
Validity checks for 'Old prefixes (enabled by the -gnatVo switch) are
now executed when the 'Old prefix is evaluated, i.e. at the very
beginning of a subprogram and not when evaluating the postcondition.

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

2020-06-19  Piotr Trojanek  

gcc/ada/

* exp_attr.adb (Expand_N_Attribute_Reference): Call Ensure_Valid
on the expression of an object declaration that captures the
value of 'Old prefix.--- gcc/ada/exp_attr.adb
+++ gcc/ada/exp_attr.adb
@@ -4587,6 +4587,7 @@ package body Exp_Attr is
  Typ : constant Entity_Id := Etype (N);
  CW_Temp : Entity_Id;
  CW_Typ  : Entity_Id;
+ Decl: Node_Id;
  Ins_Nod : Node_Id;
  Subp: Node_Id;
  Temp: Entity_Id;
@@ -4685,13 +4686,15 @@ package body Exp_Attr is
 CW_Temp := Make_Temporary (Loc, 'T');
 CW_Typ  := Class_Wide_Type (Typ);
 
-Insert_Before_And_Analyze (Ins_Nod,
+Decl :=
   Make_Object_Declaration (Loc,
 Defining_Identifier => CW_Temp,
 Constant_Present=> True,
 Object_Definition   => New_Occurrence_Of (CW_Typ, Loc),
 Expression  =>
-  Convert_To (CW_Typ, Relocate_Node (Pref;
+  Convert_To (CW_Typ, Relocate_Node (Pref)));
+
+Insert_Before_And_Analyze (Ins_Nod, Decl);
 
 --  Generate:
 --Temp : Typ renames Typ (CW_Temp);
@@ -4709,12 +4712,15 @@ package body Exp_Attr is
 --  Generate:
 --Temp : constant Typ := Pref;
 
-Insert_Before_And_Analyze (Ins_Nod,
+Decl :=
   Make_Object_Declaration (Loc,
 Defining_Identifier => Temp,
 Constant_Present=> True,
 Object_Definition   => New_Occurrence_Of (Typ, Loc),
-Expression  => Relocate_Node (Pref)));
+Expression  => Relocate_Node (Pref));
+
+Insert_Before_And_Analyze (Ins_Nod, Decl);
+
  end if;
 
  if Present (Subp) then
@@ -4726,7 +4732,7 @@ package body Exp_Attr is
  --  to reflect the new placement of the prefix.
 
  if Validity_Checks_On and then Validity_Check_Operands then
-Ensure_Valid (Pref);
+Ensure_Valid (Expression (Decl));
  end if;
 
  Rewrite (N, New_Occurrence_Of (Temp, Loc));



[Ada] Remove repeated testing of Check_Validity_Of_Parameters

2020-06-19 Thread Pierre-Marie de Rodat
Routine Apply_Parameter_Validity_Checks is only called when flag
Check_Validity_Of_Parameters is true, so repeated testing of this flag
within that routine itself was unnecessary.

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

2020-06-19  Piotr Trojanek  

gcc/ada/

* checks.adb (Apply_Parameter_Validity_Checks): Remove testing
of Check_Validity_Of_Parameters for every formal parameter and
function result.--- gcc/ada/checks.adb
+++ gcc/ada/checks.adb
@@ -2679,8 +2679,8 @@ package body Checks is
 
   if not Comes_From_Source (Subp)
 
- --  Do not process formal subprograms because the corresponding actual
- --  will receive the proper checks when the instance is analyzed.
+--  Do not process formal subprograms because the corresponding actual
+--  will receive the proper checks when the instance is analyzed.
 
 or else Is_Formal_Subprogram (Subp)
 
@@ -2723,14 +2723,12 @@ package body Checks is
  --mode IN OUT - Pre, Post => Formal'Valid[_Scalars]
  --modeOUT -  Post => Formal'Valid[_Scalars]
 
- if Check_Validity_Of_Parameters then
-if Ekind_In (Formal, E_In_Parameter, E_In_Out_Parameter) then
-   Add_Validity_Check (Formal, Name_Precondition, False);
-end if;
+ if Ekind_In (Formal, E_In_Parameter, E_In_Out_Parameter) then
+Add_Validity_Check (Formal, Name_Precondition, False);
+ end if;
 
-if Ekind_In (Formal, E_In_Out_Parameter, E_Out_Parameter) then
-   Add_Validity_Check (Formal, Name_Postcondition, False);
-end if;
+ if Ekind_In (Formal, E_In_Out_Parameter, E_Out_Parameter) then
+Add_Validity_Check (Formal, Name_Postcondition, False);
  end if;
 
  Next_Formal (Formal);
@@ -2740,7 +2738,7 @@ package body Checks is
 
   --Post => Subp'Result'Valid[_Scalars]
 
-  if Check_Validity_Of_Parameters and then Ekind (Subp) = E_Function then
+  if Ekind (Subp) = E_Function then
  Add_Validity_Check (Subp, Name_Postcondition, True);
   end if;
end Apply_Parameter_Validity_Checks;



[PATCH] Fortran : ICE in resolve_fl_procedure PR95708

2020-06-19 Thread Mark Eggleston

Please find attached a fix for PR95708.

OK for commit and backport?

Commit message:

Fortran  : ICE in resolve_fl_procedure PR95708

Now issues an error "Intrinsic procedure 'num_images' not
allowed in PROCEDURE" instead of an ICE.

2020-06-19  Steven G. Kargl  

gcc/fortran/

    PR fortran/PR95708
    * intrinsic.c (add_functions): Replace CLASS_INQUIRY with
    CLASS_TRANSFORMATIONAL for intrinsic num_images.
    (make_generic): Replace ACTUAL_NO with ACTUAL_YES for
    intrinsic team_number.

2020-06-19  Mark Eggleston 

gcc/testsuite/

    PR fortran/95708
    * gfortran.dg/pr95708.f90: New test.

--
https://www.codethink.co.uk/privacy.html

>From c5d89e71478d7c022370992dfd7e42dc2b82040a Mon Sep 17 00:00:00 2001
From: Mark Eggleston 
Date: Thu, 18 Jun 2020 13:42:58 +0100
Subject: [PATCH] Fortran  : ICE in resolve_fl_procedure PR95708

Now issues an error "Intrinsic procedure 'num_images' not
allowed in PROCEDURE" instead of an ICE.

2020-06-19  Steven G. Kargl  

gcc/fortran/

	PR fortran/PR95708
	* intrinsic.c (add_functions): Replace CLASS_INQUIRY with
	CLASS_TRANSFORMATIONAL for intrinsic num_images.
	(make_generic): Replace ACTUAL_NO with ACTUAL_YES for
	intrinsic team_number.

2020-06-19  Mark Eggleston  

gcc/testsuite/

	PR fortran/95708
	* gfortran.dg/pr95708.f90: New test.
---
 gcc/fortran/intrinsic.c   | 6 +++---
 gcc/fortran/resolve.c | 1 +
 gcc/testsuite/gfortran.dg/pr95708.f90 | 6 ++
 3 files changed, 10 insertions(+), 3 deletions(-)
 create mode 100644 gcc/testsuite/gfortran.dg/pr95708.f90

diff --git a/gcc/fortran/intrinsic.c b/gcc/fortran/intrinsic.c
index 17f5efc6566..f2f743a2721 100644
--- a/gcc/fortran/intrinsic.c
+++ b/gcc/fortran/intrinsic.c
@@ -2733,8 +2733,8 @@ add_functions (void)
 
   make_generic ("null", GFC_ISYM_NULL, GFC_STD_F95);
 
-  add_sym_2 ("num_images", GFC_ISYM_NUM_IMAGES, CLASS_INQUIRY, ACTUAL_NO,
-	 BT_INTEGER, di, GFC_STD_F2008,
+  add_sym_2 ("num_images", GFC_ISYM_NUM_IMAGES, CLASS_TRANSFORMATIONAL,
+	 ACTUAL_NO, BT_INTEGER, di, GFC_STD_F2008,
 	 gfc_check_num_images, gfc_simplify_num_images, NULL,
 	 dist, BT_INTEGER, di, OPTIONAL,
 	 failed, BT_LOGICAL, dl, OPTIONAL);
@@ -3174,7 +3174,7 @@ add_functions (void)
   make_generic ("tanh", GFC_ISYM_TANH, GFC_STD_F77);
 
   add_sym_1 ("team_number", GFC_ISYM_TEAM_NUMBER, CLASS_TRANSFORMATIONAL,
-	 ACTUAL_YES, BT_INTEGER, di, GFC_STD_F2018,
+	 ACTUAL_NO, BT_INTEGER, di, GFC_STD_F2018,
 	 gfc_check_team_number, NULL, gfc_resolve_team_number,
 	 team, BT_DERIVED, di, OPTIONAL);
 
diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c
index aaee5eb6b9b..c53b312f7ed 100644
--- a/gcc/fortran/resolve.c
+++ b/gcc/fortran/resolve.c
@@ -12999,6 +12999,7 @@ resolve_fl_procedure (gfc_symbol *sym, int mp_flag)
 	{
 	  if (arg->sym
 	  && arg->sym->ts.type == BT_DERIVED
+	  && arg->sym->ts.u.derived
 	  && !arg->sym->ts.u.derived->attr.use_assoc
 	  && !gfc_check_symbol_access (arg->sym->ts.u.derived)
 	  && !gfc_notify_std (GFC_STD_F2003, "%qs is of a PRIVATE type "
diff --git a/gcc/testsuite/gfortran.dg/pr95708.f90 b/gcc/testsuite/gfortran.dg/pr95708.f90
new file mode 100644
index 000..32bd324ce15
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr95708.f90
@@ -0,0 +1,6 @@
+! { dg-do compile }
+!
+
+program test
+  procedure(team_num) :: g ! { dg-error "must be explicit" }
+end program
-- 
2.11.0



[PATCH] RISC-V: Fix compilation failed for frflags builtin in C++ mode

2020-06-19 Thread Kito Cheng
  - g++ will complain too few arguments for frflags builtin like bellow
message:

error: too few arguments to function 'unsigned int 
__builtin_riscv_frflags(void)'

  - However it's no arguments needed, it because we declare the function
type with VOID arguments, that seems like require a VOID argument
in the c++ front-end when GCC tried to resolve the function.

gcc/ChangeLog

* config/riscv/riscv-builtins.c (RISCV_FTYPE_NAME0): New.
(RISCV_FTYPE_ATYPES0): New.
(riscv_builtins): Using RISCV_USI_FTYPE for frflags.
* config/riscv/riscv-ftypes.def: Remove VOID argument.

gcc/testsuite/ChangeLog

* g++.target/riscv/frflags.C: New.
---
 gcc/config/riscv/riscv-builtins.c| 5 -
 gcc/config/riscv/riscv-ftypes.def| 2 +-
 gcc/testsuite/g++.target/riscv/frflags.C | 7 +++
 3 files changed, 12 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/g++.target/riscv/frflags.C

diff --git a/gcc/config/riscv/riscv-builtins.c 
b/gcc/config/riscv/riscv-builtins.c
index a45108e03557..bc959389c76c 100644
--- a/gcc/config/riscv/riscv-builtins.c
+++ b/gcc/config/riscv/riscv-builtins.c
@@ -38,6 +38,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "langhooks.h"
 
 /* Macros to create an enumeration identifier for a function prototype.  */
+#define RISCV_FTYPE_NAME0(A) RISCV_##A##_FTYPE
 #define RISCV_FTYPE_NAME1(A, B) RISCV_##A##_FTYPE_##B
 
 /* Classifies the prototype of a built-in function.  */
@@ -121,11 +122,13 @@ AVAIL (hard_float, TARGET_HARD_FLOAT)
 
 /* RISCV_FTYPE_ATYPESN takes N RISCV_FTYPES-like type codes and lists
their associated RISCV_ATYPEs.  */
+#define RISCV_FTYPE_ATYPES0(A) \
+  RISCV_ATYPE_##A
 #define RISCV_FTYPE_ATYPES1(A, B) \
   RISCV_ATYPE_##A, RISCV_ATYPE_##B
 
 static const struct riscv_builtin_description riscv_builtins[] = {
-  DIRECT_BUILTIN (frflags, RISCV_USI_FTYPE_VOID, hard_float),
+  DIRECT_BUILTIN (frflags, RISCV_USI_FTYPE, hard_float),
   DIRECT_NO_TARGET_BUILTIN (fsflags, RISCV_VOID_FTYPE_USI, hard_float)
 };
 
diff --git a/gcc/config/riscv/riscv-ftypes.def 
b/gcc/config/riscv/riscv-ftypes.def
index 5edeb481a72d..1c6bc4e9dce1 100644
--- a/gcc/config/riscv/riscv-ftypes.def
+++ b/gcc/config/riscv/riscv-ftypes.def
@@ -26,5 +26,5 @@ along with GCC; see the file COPYING3.  If not see
   LIST contains the return-type code followed by the codes for each
 argument type.  */
 
-DEF_RISCV_FTYPE (1, (USI, VOID))
+DEF_RISCV_FTYPE (0, (USI))
 DEF_RISCV_FTYPE (1, (VOID, USI))
diff --git a/gcc/testsuite/g++.target/riscv/frflags.C 
b/gcc/testsuite/g++.target/riscv/frflags.C
new file mode 100644
index ..be0bd4db01c3
--- /dev/null
+++ b/gcc/testsuite/g++.target/riscv/frflags.C
@@ -0,0 +1,7 @@
+/* { dg-options "-O2 -march=rv32if" } */
+/* { dg-do compile } */
+
+int f()
+{
+  return __builtin_riscv_frflags();
+}
-- 
2.27.0