[PATCH GCC]Correct cand_chain and stmt_cand_map for copy/cast

2019-05-14 Thread bin.cheng
Hi,
I noticed that cand_chain (first_interp/next_interp) is not maintained correctly
in slsr_process_copy/slsr_process_cast (now slsr_process_copycast).  This one
fixes the issue, as well as records the "first" cand in stmt_cand_map.

Hi Bill, is this correct or I misunderstood the code? Bootstrap and test on 
x86_64.

Thanks,
bin

2019-05-15  Bin Cheng  

* gimple-ssa-strength-reduction.c (slsr_process_copycast): Record
information about next_interp and the first cand.

0003-Correct-cand_chain-and-cand_stmt_map-for-copy-cast.patch
Description: Binary data


[PATCH GCC]refactor process of copy and cast in slsr

2019-05-14 Thread bin.cheng
Hi,
I noticed that slsr_process_copy and slsr_process_cast are almost identical
and called only once.  This patch refactor the two functions into one.
For copies, it also passes lhs' type to creation of new cand assuming that
lhs, rhs and base_cand have the same/compatible type.  I will keep an eye
on this in case of any fallouts.

Bootstrap and test on x86_64.  Is it OK?

Thanks,
bin

2019-05-15  Bin Cheng  

* gimple-ssa-strength-reduction.c (slsr_process_cast): Refactor into
(slsr_process_copycast): ...this.
(slsr_process_copy): Delete.
(find_candidates_dom_walker::before_dom_children): Call the refactor
function slsr_process_copycast.

0002-Factor-slsr-process-of-copy-and-cast.patch
Description: Binary data


Re: [PATCH v2 2/3] Add predict_doloop_p target hook

2019-05-14 Thread Kewen.Lin
on 2019/5/15 上午11:34, Kewen.Lin wrote:
> 
> on 2019/5/15 上午10:40, Bin.Cheng wrote:
>> I wonder if you can factor out generic part into GIMPLE and leave
>> target hook as specific as possible?
>>
> 
> Good suggestion! Yes, most of the checks are common as you
> pointed out.  I hope the other targets won't have more
> customization needs excepting for that GIMPLE stmt hook
> check. 
> 
> I am thinking IVOPTs is a best place to factor to? Or 
> somewhere to put common GIMPLE query interface? 
> 

Or move it into targhooks.cpp as a possible base process 
of [target]_predict_doloop_p?   The target owner can
decide whether to use generic_predict_doloop_p in its 
own target hook.
It seems more flexible and allow them to have a new 
implementation for their own targets.  Like:

rs6000_predict_doloop_p:

if (generic_predict_doloop_p(loop))
...

special_target_predict_doloop_p:




Thanks,
Kewen

>>> +
>>> +  /* Similar to doloop_optimize, check whether iteration count too small
>>> + and not profitable.  */
>>> +  HOST_WIDE_INT est_niter = get_estimated_loop_iterations_int (loop);
>>> +  if (est_niter == -1)
>>> +est_niter = get_likely_max_loop_iterations_int (loop);
>>> +  if (est_niter >= 0 && est_niter < 3)
>> The only probably target dependent is the magic number 3 here.  After
>> moving all generic part to ivopts, we can use a macro for the moment,
>> and improve it as a parameter if there are more doloop targets.
> 
> The magic number 3 is from function doloop_optimize, not a
> target dependent value.  But thanks for your tips with 
> macro mechanism!
> 
> 
> Thanks,
> Kewen
> 
>> Overall most of above checks can be moved out of backend, leaving only
>> more specific target hook checking on gimple_stmt?  And even that can
>> be made generic to some extend.
>>
>> Thanks,
>> bin
> 



Re: [PATCH v2 3/3] Consider doloop cmp use in ivopts

2019-05-14 Thread Kewen.Lin
on 2019/5/14 下午3:26, Richard Biener wrote:
> On Tue, May 14, 2019 at 5:10 AM  wrote:
>>
>> From: Kewen Lin 
>>
>> Previous version link for background:
>> https://gcc.gnu.org/ml/gcc-patches/2019-04/msg00912.html
>>
>> Firstly, it's to call predict_doloop_p hook to check this
>> loop will be transformed to doloop or not, if yes, find
>> the expected comp iv use and its dependent original iv,
>> set the iv candidate as bind_cand of the group.
>> In following candidate selection process, we will bypass
>> the group with bind_cand, since we don't want to affect
>> global decision making for an iv use which will be
>> eliminated eventually.  At the time of iv candidate set
>> finalization, we will fill the cost pair for the group
>> with bind_cand.  If the bind_cand is already in the final
>> set, then just use it. Otherwise, we can check whether one
>> of existing final set is better and fill with that if so.
>>
>> Bootstrapped and regression testing passed on powerpc64le.
>>
>> Is it ok for trunk?
> 
> I wonder what prevents IVOPTs to consider a counter IV
> (eventually such candidate needs to be added if that's not
> already done) to be the most profitable variant w/o any
> of the other changes?  I guess that would be costing of
> the IV adjust plus branch which we would need to lower
> in case there's nothing inside the loop that would make
> later doloop transform fail?
> 
> Richard.
> 

If the question is for "w/o this patch", I think IVOPTs
can find counter IV as the most profitable one for the cmp
use in most time.  But the key issue is that it may stop
us to bring in more iv cands.  We have to add on iv cost
of new cand desirable for some iv use, it's probably more
than the cost of just using counter IV for the interest
use.  

If the question is for "w/i this patch", since we bypass
the doloop cmp use in candidate determination algorithm, 
it's possible that some other iv cands are preferred for 
the remaining uses rather than the counter IV. For example,
for some address type iv use, iv cand with memory based is
mostly better.


Thanks,
Kewen



[PATCH PR57534]Support strength reduction for MEM_REF in slur

2019-05-14 Thread bin.cheng
Hi,
As noted in PR57534 comment #33, SLSR currently doesn't strength reduce memory
references in reported cases, which conflicts with its comment at the beginning 
of file.
The main reason is in functions slsr_process_ref and restructure_reference which
rejects MEM_REF by handled_compoenent_p in the first place.  This patch 
identifies
and creates CAND_REF for MEM_REF by restructuring base/offset.

Note the patch only affects cases with multiple reducible MEM_REF.

Also note, with this patch, [base + cst_offset] addressing mode would be 
generally
preferred.  I need to adjust three existing tests:
* gcc.dg/tree-ssa/isolate-5.c
* gcc.dg/tree-ssa/ssa-hoist-4.c
Though address computation is reduced out of memory reference, the generated 
assembly is not worsened.

* gcc.dg/tree-ssa/slsr-3.c
The generated assembly has two more instructions:
<   movslq  %edx, %rcx
<   movl(%rsi,%rcx,4), %r9d
<   leaq0(,%rcx,4), %rax
<   leal2(%r9), %r8d
<   movl%r8d, (%rdi,%rcx,4)
<   movl4(%rsi,%rax), %ecx
<   addl$2, %ecx
<   movl%ecx, 4(%rdi,%rax)
<   movl8(%rsi,%rax), %ecx
<   addl$2, %ecx
<   movl%ecx, 8(%rdi,%rax)
<   movl12(%rsi,%rax), %ecx
<   addl$2, %ecx
<   movl%ecx, 12(%rdi,%rax)
---
>   movslq  %edx, %rax
>   salq$2, %rax
>   addq%rax, %rsi
>   addq%rax, %rdi
>   movl(%rsi), %eax
>   addl$2, %eax
>   movl%eax, (%rdi)
>   movl4(%rsi), %eax
>   addl$2, %eax
>   movl%eax, 4(%rdi)
>   movl8(%rsi), %eax
>   addl$2, %eax
>   movl%eax, 8(%rdi)
>   movl12(%rsi), %eax
>   addl$2, %eax
>   movl%eax, 12(%rdi)

Seems to me this is not deteriorating and "salq" can be saved by two forward 
propagation.

Bootstrap and test on x86_64, any comments?

Thanks,
bin

2019-05-15  Bin Cheng  

PR tree-optimization/57534
* gimple-ssa-strength-reduction.c (restructure_base_offset): New.
(restructure_reference): Call restructure_base_offset when offset is
NULL.
(slsr_process_ref): Handle MEM_REF.

2018-05-15  Bin Cheng  

PR tree-optimization/57534
* gcc.dg/tree-ssa/pr57534.c: New test.
* gcc.dg/tree-ssa/isolate-5.c: Adjust checking strings.
* gcc.dg/tree-ssa/slsr-3.c: Ditto.
* gcc.dg/tree-ssa/ssa-hoist-4.c: Ditto.

0001-pr57534.patch
Description: Binary data


[PATCH] Refactor away an obsolete is_unsigned distinction in is_value_included_in

2019-05-14 Thread Vladislav Ivanishin
Hi!

This is just a clean-up.  During the course of past refactorings, the
then and else branches of `if (is_unsigned)` in is_value_included_in()
became semantically equivalent and almost textually identical.  This
patch removes the conditional altogether.

Regtested and bootstrapped with `BOOT_CFLAGS="-O
-Wno-error=maybe-uninitialized -Wuninitialized"` on x86_64-pc-linux-gnu.

OK for trunk?

gcc/Changelog:

* tree-ssa-uninit.c (is_value_included_in): remove is_unsigned and merge
semantically equivalent branches (left over after prior refactorings).
---
 gcc/tree-ssa-uninit.c | 31 ++-
 1 file changed, 6 insertions(+), 25 deletions(-)

diff --git a/gcc/tree-ssa-uninit.c b/gcc/tree-ssa-uninit.c
index 831587854c6..7362e374dea 100644
--- a/gcc/tree-ssa-uninit.c
+++ b/gcc/tree-ssa-uninit.c
@@ -1017,45 +1017,26 @@ static bool
 is_value_included_in (tree val, tree boundary, enum tree_code cmpc)
 {
   bool inverted = false;
-  bool is_unsigned;
   bool result;
 
   /* Only handle integer constant here.  */
   if (TREE_CODE (val) != INTEGER_CST || TREE_CODE (boundary) != INTEGER_CST)
 return true;
 
-  is_unsigned = TYPE_UNSIGNED (TREE_TYPE (val));
-
   if (cmpc == GE_EXPR || cmpc == GT_EXPR || cmpc == NE_EXPR)
 {
   cmpc = invert_tree_comparison (cmpc, false);
   inverted = true;
 }
 
-  if (is_unsigned)
-{
-  if (cmpc == EQ_EXPR)
-	result = tree_int_cst_equal (val, boundary);
-  else if (cmpc == LT_EXPR)
-	result = tree_int_cst_lt (val, boundary);
-  else
-	{
-	  gcc_assert (cmpc == LE_EXPR);
-	  result = tree_int_cst_le (val, boundary);
-	}
-}
+  if (cmpc == EQ_EXPR)
+result = tree_int_cst_equal (val, boundary);
+  else if (cmpc == LT_EXPR)
+result = tree_int_cst_lt (val, boundary);
   else
 {
-  if (cmpc == EQ_EXPR)
-	result = tree_int_cst_equal (val, boundary);
-  else if (cmpc == LT_EXPR)
-	result = tree_int_cst_lt (val, boundary);
-  else
-	{
-	  gcc_assert (cmpc == LE_EXPR);
-	  result = (tree_int_cst_equal (val, boundary)
-		|| tree_int_cst_lt (val, boundary));
-	}
+  gcc_assert (cmpc == LE_EXPR);
+  result = tree_int_cst_le (val, boundary);
 }
 
   if (inverted)
-- 
2.21.0


-- 
Vlad


Re: [PATCH v2 2/3] Add predict_doloop_p target hook

2019-05-14 Thread Kewen.Lin


on 2019/5/15 上午10:40, Bin.Cheng wrote:
> I wonder if you can factor out generic part into GIMPLE and leave
> target hook as specific as possible?
> 

Good suggestion! Yes, most of the checks are common as you
pointed out.  I hope the other targets won't have more
customization needs excepting for that GIMPLE stmt hook
check. 

I am thinking IVOPTs is a best place to factor to? Or 
somewhere to put common GIMPLE query interface? 

>> +
>> +  /* Similar to doloop_optimize, check whether iteration count too small
>> + and not profitable.  */
>> +  HOST_WIDE_INT est_niter = get_estimated_loop_iterations_int (loop);
>> +  if (est_niter == -1)
>> +est_niter = get_likely_max_loop_iterations_int (loop);
>> +  if (est_niter >= 0 && est_niter < 3)
> The only probably target dependent is the magic number 3 here.  After
> moving all generic part to ivopts, we can use a macro for the moment,
> and improve it as a parameter if there are more doloop targets.

The magic number 3 is from function doloop_optimize, not a
target dependent value.  But thanks for your tips with 
macro mechanism!


Thanks,
Kewen

> Overall most of above checks can be moved out of backend, leaving only
> more specific target hook checking on gimple_stmt?  And even that can
> be made generic to some extend.
> 
> Thanks,
> bin



New Documents For(gcc-patches@gcc.gnu.org)Your Shipment (Shipping SF Electronic Invoice Notification)

2019-05-14 Thread SF Express

\0Ae6Cv84�7AN30�1F�D0[A2b37�1A `A8Y7D gcc-patches@gcc.gnu.org 
a1F�22`A8�09bE9�7AN30�1F�D0N3A`A8cD0O9Bv84e36m3Eg0DRA1002 
`A8u33�F7v84u35[50SD1y68]F2b10R9F_00Q77�01SD1y68�E6`C5Y82N0B�1A 
SD1y68NE3x01�1A019093877133873SD1y68SF7x01�1A5123338323SD1y68�D1�9D�1A639.9Q43 
S05T2Bv84�D0S55SF7�1A   `A8SEFNE5pB9QFBNE5N0B�FEcA5N0B�7Du35[50SD1y68002  
1001N0B�7DPDFh3C_0Fu35[50SD1y68 2001N0B�7DJPGh3C_0Fu35[50SD1y68 
|FB~DF�AE{B1�0C�F7RFFVDEY0D002Y82g09�00l42�0C�F7�54|FBe36m3ET58b16[A2g0D�0C�22�22�

Re: [PATCH v2 2/3] Add predict_doloop_p target hook

2019-05-14 Thread Kewen.Lin
on 2019/5/14 下午3:24, Richard Biener wrote:> 
> Most of the rs6000 target hook checks look general
> (can we compute niter, etc.), IVOPTs would have a hard
> time adding a counter IV w/o being able to compute niters.

Do you mean to reuse them?

Yes, IVOPTs has already checked niter.  At the initial 
version of this patch, I tried to pass more parameters
for this hook, but IMHO it looks not elegant.  In future,
if this hook is called in other places, it may require
others to construct the required parameters.  

number_of_latch_executions uses the cache way, it should
not cost much to get the niter.  For the estimated niter
counts, I don't think IVOPTs also checks it.

> Likewise IVOPTs should already consider (does it?) costs
> of invariant computations (the niter computation).
> 

I did check the computation_cost in IVOPTs, but I found
it can not be reused directly for doloop cost check.  So
I had to refactor the prepare_decl_rtl part.  It's 
possible to hack the IVOPTs code to get what we want, 
but it seems too hacky.


> That leaves the CTR invalidation checks which makes
> me wonder if the hook shouldn't be one working on
> a stmt, like stmt_precludes_doloop_p?
> 

This sounds like a better name instead of 
invalid_insn_for_doloop_p.  :)


Thanks,
Kewen

> Richard.
> 



[PATCH 2/2] aarch64 back-end changes

2019-05-14 Thread kugan . vivekanandarajah
From: Kugan Vivekanandarajah 

gcc/ChangeLog:

2019-05-15  Kugan Vivekanandarajah  

PR target/88834
* config/aarch64/aarch64.c (aarch64_classify_address): Relax
allow_reg_index_p.

gcc/testsuite/ChangeLog:

2019-05-15  Kugan Vivekanandarajah  

PR target/88834
* gcc.target/aarch64/pr88834.c: New test.
* gcc.target/aarch64/sve/struct_vect_1.c: Adjust.
* gcc.target/aarch64/sve/struct_vect_14.c: Likewise.
* gcc.target/aarch64/sve/struct_vect_15.c: Likewise.
* gcc.target/aarch64/sve/struct_vect_16.c: Likewise.
* gcc.target/aarch64/sve/struct_vect_17.c: Likewise.
* gcc.target/aarch64/sve/struct_vect_7.c: Likewise.

Change-Id: I840d08dc89a845b3913204228bae1bed40601d07
---
 gcc/config/aarch64/aarch64.c  |  2 +-
 gcc/testsuite/gcc.target/aarch64/pr88834.c| 15 +++
 gcc/testsuite/gcc.target/aarch64/sve/struct_vect_1.c  |  8 
 gcc/testsuite/gcc.target/aarch64/sve/struct_vect_14.c |  8 
 gcc/testsuite/gcc.target/aarch64/sve/struct_vect_15.c |  8 
 gcc/testsuite/gcc.target/aarch64/sve/struct_vect_16.c |  8 
 gcc/testsuite/gcc.target/aarch64/sve/struct_vect_17.c |  8 
 gcc/testsuite/gcc.target/aarch64/sve/struct_vect_7.c  |  8 
 8 files changed, 40 insertions(+), 25 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/aarch64/pr88834.c

diff --git a/gcc/config/aarch64/aarch64.c b/gcc/config/aarch64/aarch64.c
index 1f90467..34292eb 100644
--- a/gcc/config/aarch64/aarch64.c
+++ b/gcc/config/aarch64/aarch64.c
@@ -6592,7 +6592,7 @@ aarch64_classify_address (struct aarch64_address_info 
*info,
   bool allow_reg_index_p = (!load_store_pair_p
&& (known_lt (GET_MODE_SIZE (mode), 16)
|| vec_flags == VEC_ADVSIMD
-   || vec_flags == VEC_SVE_DATA));
+   || vec_flags & VEC_SVE_DATA));
 
   /* For SVE, only accept [Rn], [Rn, Rm, LSL #shift] and
  [Rn, #offset, MUL VL].  */
diff --git a/gcc/testsuite/gcc.target/aarch64/pr88834.c 
b/gcc/testsuite/gcc.target/aarch64/pr88834.c
new file mode 100644
index 000..ea00967
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/pr88834.c
@@ -0,0 +1,15 @@
+/* { dg-do compile } */
+/* { dg-options "-S -O3 -march=armv8.2-a+sve" } */
+
+void
+f (int *restrict x, int *restrict y, int *restrict z, int n)
+{
+  for (int i = 0; i < n; i += 2)
+{
+  x[i] = y[i] + z[i];
+  x[i + 1] = y[i + 1] - z[i + 1];
+}
+}
+
+/* { dg-final { scan-assembler-times {\tld2w\t{z[0-9]+.s - z[0-9]+.s}, 
p[0-7]/z, \[x[0-9]+, x[0-9]+, lsl 2\]\n} 2 } } */
+/* { dg-final { scan-assembler-times {\tst2w\t{z[0-9]+.s - z[0-9]+.s}, p[0-7], 
\[x[0-9]+, x[0-9]+, lsl 2\]\n} 1 } } */
diff --git a/gcc/testsuite/gcc.target/aarch64/sve/struct_vect_1.c 
b/gcc/testsuite/gcc.target/aarch64/sve/struct_vect_1.c
index 6e3c889..918a581 100644
--- a/gcc/testsuite/gcc.target/aarch64/sve/struct_vect_1.c
+++ b/gcc/testsuite/gcc.target/aarch64/sve/struct_vect_1.c
@@ -83,9 +83,9 @@ NAME(g4) (TYPE *__restrict a, TYPE *__restrict b, TYPE 
*__restrict c,
 }
 }
 
-/* { dg-final { scan-assembler {\tld2b\t{z[0-9]+.b - z[0-9]+.b}, p[0-7]/z, 
\[x[0-9]+\]\n} } } */
+/* { dg-final { scan-assembler {\tld2b\t{z[0-9]+.b - z[0-9]+.b}, p[0-7]/z, 
\[x[0-9]+, x[0-9]+\]\n} } } */
 /* { dg-final { scan-assembler {\tld3b\t{z[0-9]+.b - z[0-9]+.b}, p[0-7]/z, 
\[x[0-9]+\]\n} } } */
-/* { dg-final { scan-assembler {\tld4b\t{z[0-9]+.b - z[0-9]+.b}, p[0-7]/z, 
\[x[0-9]+\]\n} } } */
-/* { dg-final { scan-assembler {\tst2b\t{z[0-9]+.b - z[0-9]+.b}, p[0-7], 
\[x[0-9]+\]\n} } } */
+/* { dg-final { scan-assembler {\tld4b\t{z[0-9]+.b - z[0-9]+.b}, p[0-7]/z, 
\[x[0-9]+, x[0-9]+\]\n} } } */
+/* { dg-final { scan-assembler {\tst2b\t{z[0-9]+.b - z[0-9]+.b}, p[0-7], 
\[x[0-9]+, x[0-9]+\]\n} } } */
 /* { dg-final { scan-assembler {\tst3b\t{z[0-9]+.b - z[0-9]+.b}, p[0-7], 
\[x[0-9]+\]\n} } } */
-/* { dg-final { scan-assembler {\tst4b\t{z[0-9]+.b - z[0-9]+.b}, p[0-7], 
\[x[0-9]+\]\n} } } */
+/* { dg-final { scan-assembler {\tst4b\t{z[0-9]+.b - z[0-9]+.b}, p[0-7], 
\[x[0-9]+, x[0-9]+\]\n} } } */
diff --git a/gcc/testsuite/gcc.target/aarch64/sve/struct_vect_14.c 
b/gcc/testsuite/gcc.target/aarch64/sve/struct_vect_14.c
index 45644b6..a16a79e 100644
--- a/gcc/testsuite/gcc.target/aarch64/sve/struct_vect_14.c
+++ b/gcc/testsuite/gcc.target/aarch64/sve/struct_vect_14.c
@@ -43,12 +43,12 @@
 #undef NAME
 #undef TYPE
 
-/* { dg-final { scan-assembler-times {\tld2b\t{z[0-9]+.b - z[0-9]+.b}, 
p[0-7]/z, \[x[0-9]+\]\n} 1 } } */
+/* { dg-final { scan-assembler-times {\tld2b\t{z[0-9]+.b - z[0-9]+.b}, 
p[0-7]/z, \[x[0-9]+, x[0-9]+\]\n} 1 } } */
 /* { dg-final { scan-assembler-times {\tld3b\t{z[0-9]+.b - z[0-9]+.b}, 
p[0-7]/z, \[x[0-9]+\]\n} 1 } } */
-/* { dg-final { scan-assembler-times {\tld4b\t{z[0-9]+.b - z[0-9]+.b}, 
p[0-7]/z, \[x[0-9]+\]\n} 1 } } */
-/* { dg-final { 

Re: [PATCH v2 2/3] Add predict_doloop_p target hook

2019-05-14 Thread Bin.Cheng
I wonder if you can factor out generic part into GIMPLE and leave
target hook as specific as possible?

On Tue, May 14, 2019 at 11:10 AM  wrote:
>
> From: Kewen Lin 
>
> Previous version link for background:
> https://gcc.gnu.org/ml/gcc-patches/2019-04/msg00912.html
>
> This hook is to predict whether one loop in gimple will
> be transformed to low-overhead loop later in RTL, and
> designed to be called in ivopts.
>
> "Since the low-overhead loop optimize transformation is
> based on RTL, some of those checks are hard to be imitated
> on gimple, so it's not possible to predict the current
> loop will be transformed exactly in middle-end.  But if we
> can have most loop predicted precisely, it would be helpful.
> It highly depends on target hook fine tuning. It's
> acceptable to have some loops which can be transformed to
> low-overhead loop but we don't catch.  But we should try
> our best to avoid to predict some loop as low-overhead loop
> but which isn't."
>
> Bootstrapped and regression testing passed on powerpc64le.
>
> Is it ok for trunk?
>
> gcc/ChangeLog
>
> 2019-05-13  Kewen Lin  
>
> PR middle-end/80791
> * target.def (predict_doloop_p): New hook.
> * targhooks.h (default_predict_doloop_p): New declaration.
> * targhooks.c (default_predict_doloop_p): New function.
> * doc/tm.texi.in (TARGET_PREDICT_DOLOOP_P): New hook.
> * doc/tm.texi: Regenerate.
> * config/rs6000/rs6000.c (invalid_insn_for_doloop_p): New function.
> (costly_iter_for_doloop_p): Likewise.
> (rs6000_predict_doloop_p): Likewise.
> (TARGET_PREDICT_DOLOOP_P): New macro.
>
> ---
>  gcc/config/rs6000/rs6000.c | 174 
> -
>  gcc/doc/tm.texi|   8 +++
>  gcc/doc/tm.texi.in |   2 +
>  gcc/target.def |   9 +++
>  gcc/targhooks.c|  13 
>  gcc/targhooks.h|   1 +
>  6 files changed, 206 insertions(+), 1 deletion(-)
>
> diff --git a/gcc/config/rs6000/rs6000.c b/gcc/config/rs6000/rs6000.c
> index a21f4f7..1c1c8eb 100644
> --- a/gcc/config/rs6000/rs6000.c
> +++ b/gcc/config/rs6000/rs6000.c
> @@ -83,6 +83,9 @@
>  #include "tree-ssa-propagate.h"
>  #include "tree-vrp.h"
>  #include "tree-ssanames.h"
> +#include "tree-ssa-loop-niter.h"
> +#include "tree-cfg.h"
> +#include "tree-scalar-evolution.h"
>
>  /* This file should be included last.  */
>  #include "target-def.h"
> @@ -1914,6 +1917,9 @@ static const struct attribute_spec 
> rs6000_attribute_table[] =
>  #undef TARGET_CAN_USE_DOLOOP_P
>  #define TARGET_CAN_USE_DOLOOP_P can_use_doloop_if_innermost
>
> +#undef TARGET_PREDICT_DOLOOP_P
> +#define TARGET_PREDICT_DOLOOP_P rs6000_predict_doloop_p
> +
>  #undef TARGET_ATOMIC_ASSIGN_EXPAND_FENV
>  #define TARGET_ATOMIC_ASSIGN_EXPAND_FENV rs6000_atomic_assign_expand_fenv
>
> @@ -39436,7 +39442,173 @@ rs6000_mangle_decl_assembler_name (tree decl, tree 
> id)
>return id;
>  }
>
> -
> +/* Check whether there are some instructions preventing doloop transformation
> +   inside loop body, mainly for instructions which are possible to kill CTR.
> +
> +   Return true if some invalid insn exits, otherwise return false.  */
> +
> +static bool
> +invalid_insn_for_doloop_p (struct loop *loop)
> +{
> +  basic_block *body = get_loop_body (loop);
> +  gimple_stmt_iterator gsi;
> +
> +  for (unsigned i = 0; i < loop->num_nodes; i++)
> +for (gsi = gsi_start_bb (body[i]); !gsi_end_p (gsi); gsi_next ())
The loops on bbs/stmts seem general and can be put in GIMPLE.  So a
target hook taking gimple_stmt parameter and returning if the stmt
blocks doloop is enough?

> +  {
> +   gimple *stmt = gsi_stmt (gsi);
> +   if (is_gimple_call (stmt) && !gimple_call_internal_p (stmt)
> +   && !is_inexpensive_builtin (gimple_call_fndecl (stmt)))
> + {
> +   if (dump_file && (dump_flags & TDF_DETAILS))
> + fprintf (dump_file,
> +  "predict doloop failure due to finding call.\n");
> +   return true;
> + }
> +   if (computed_goto_p (stmt))
> + {
> +   if (dump_file && (dump_flags & TDF_DETAILS))
> + fprintf (dump_file, "predict doloop failure due to"
> + "finding computed jump.\n");
> +   return true;
> + }
> +   /* TODO: Now this hook is expected to be called in ivopts, which is
> +  before switchlower1/switchlower2.  Checking for SWITCH at this 
> point
> +   will eliminate some good candidates.  But since there are only a few
> +   cases having _a_ switch statement in the innermost loop, it can be a 
> low
> +  priority enhancement.  */
> +
> +   if (gimple_code (stmt) == GIMPLE_SWITCH)
> + {
> +   if (dump_file && (dump_flags & TDF_DETAILS))
> + fprintf (dump_file,
> +  "predict doloop failure due to finding switch.\n");
> +   return true;
> + 

[PATCH 0/2] [RFC][PR88834]

2019-05-14 Thread kugan . vivekanandarajah
From: Kugan Vivekanandarajah 

In PR88834, IVOPT is not selecting the right addressing mode. Inorder to fix 
thix,
we need to add support to add IV uses for IFN_MASK_LOAD_LANES and 
IFN_MASK_STORE_LANES.
In addition, we also need to add IV candidate with scaled by the element or 
access size if
that is useful. Richard Sandiford has provided some feedback in the PR and I 
tried to
incoporate this in PATCH1.

PATCH 2 is the changes needed in aarch64 back in the testadjustments.

Bootstrap and regression testing for the current version is ongoing.

Thanks,
Kugan

Kugan Vivekanandarajah (2):
  Add support for IVOPT
  aarch64 back-end changes

 gcc/config/aarch64/aarch64.c   |  2 +-
 gcc/testsuite/gcc.target/aarch64/pr88834.c | 15 ++
 .../gcc.target/aarch64/sve/struct_vect_1.c |  8 +--
 .../gcc.target/aarch64/sve/struct_vect_14.c|  8 +--
 .../gcc.target/aarch64/sve/struct_vect_15.c|  8 +--
 .../gcc.target/aarch64/sve/struct_vect_16.c|  8 +--
 .../gcc.target/aarch64/sve/struct_vect_17.c|  8 +--
 .../gcc.target/aarch64/sve/struct_vect_7.c |  8 +--
 gcc/tree-ssa-loop-ivopts.c | 60 +-
 9 files changed, 99 insertions(+), 26 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/aarch64/pr88834.c

-- 
2.7.4



[PATCH 1/2] Add support for IVOPT

2019-05-14 Thread kugan . vivekanandarajah
From: Kugan Vivekanandarajah 

gcc/ChangeLog:

2019-05-15  Kugan Vivekanandarajah  

PR target/88834
* tree-ssa-loop-ivopts.c (get_mem_type_for_internal_fn): Handle
IFN_MASK_LOAD_LANES and IFN_MASK_STORE_LANES.
(find_interesting_uses_stmt): Likewise.
(get_alias_ptr_type_for_ptr_address): Likewise.
(add_iv_candidate_for_use): Add scaled index candidate if useful.

Change-Id: I8e8151fe2dde2845dedf38b090103694da6fc9d1
---
 gcc/tree-ssa-loop-ivopts.c | 60 +-
 1 file changed, 59 insertions(+), 1 deletion(-)

diff --git a/gcc/tree-ssa-loop-ivopts.c b/gcc/tree-ssa-loop-ivopts.c
index 9864b59..115a70c 100644
--- a/gcc/tree-ssa-loop-ivopts.c
+++ b/gcc/tree-ssa-loop-ivopts.c
@@ -2451,11 +2451,13 @@ get_mem_type_for_internal_fn (gcall *call, tree *op_p)
   switch (gimple_call_internal_fn (call))
 {
 case IFN_MASK_LOAD:
+case IFN_MASK_LOAD_LANES:
   if (op_p == gimple_call_arg_ptr (call, 0))
return TREE_TYPE (gimple_call_lhs (call));
   return NULL_TREE;
 
 case IFN_MASK_STORE:
+case IFN_MASK_STORE_LANES:
   if (op_p == gimple_call_arg_ptr (call, 0))
return TREE_TYPE (gimple_call_arg (call, 3));
   return NULL_TREE;
@@ -2545,7 +2547,7 @@ find_interesting_uses_stmt (struct ivopts_data *data, 
gimple *stmt)
  return;
}
 
-  /* TODO -- we should also handle address uses of type
+  /* TODO -- we should also handle all address uses of type
 
 memory = call (whatever);
 
@@ -2553,6 +2555,27 @@ find_interesting_uses_stmt (struct ivopts_data *data, 
gimple *stmt)
 
 call (memory).  */
 }
+  else if (is_gimple_call (stmt))
+{
+  gcall *call = dyn_cast  (stmt);
+  if (call
+ && gimple_call_internal_p (call)
+ && (gimple_call_internal_fn (call) == IFN_MASK_LOAD_LANES
+ || gimple_call_internal_fn (call) == IFN_MASK_STORE_LANES))
+   {
+ tree *arg = gimple_call_arg_ptr (call, 0);
+ struct iv *civ = get_iv (data, *arg);
+ tree mem_type = get_mem_type_for_internal_fn (call, arg);
+ if (civ && mem_type)
+   {
+ civ = alloc_iv (data, civ->base, civ->step);
+ record_group_use (data, arg, civ, stmt, USE_PTR_ADDRESS,
+   mem_type);
+ return;
+   }
+   }
+}
+
 
   if (gimple_code (stmt) == GIMPLE_PHI
   && gimple_bb (stmt) == data->current_loop->header)
@@ -3500,6 +3523,39 @@ add_iv_candidate_for_use (struct ivopts_data *data, 
struct iv_use *use)
 basetype = sizetype;
   record_common_cand (data, build_int_cst (basetype, 0), iv->step, use);
 
+  /* Compare the cost of an address with an unscaled index with the cost of
+an address with a scaled index and add candidate if useful. */
+  if (use != NULL && use->type == USE_PTR_ADDRESS)
+{
+  struct mem_address parts = {NULL_TREE, integer_one_node,
+ NULL_TREE, NULL_TREE, NULL_TREE};
+  poly_uint64 temp;
+  poly_int64 fact;
+  bool speed = optimize_loop_for_speed_p (data->current_loop);
+  poly_int64 poly_step = tree_to_poly_int64 (iv->step);
+  machine_mode mem_mode = TYPE_MODE (use->mem_type);
+  addr_space_t as = TYPE_ADDR_SPACE (TREE_TYPE (use->iv->base));
+
+  fact = GET_MODE_SIZE (GET_MODE_INNER (TYPE_MODE (use->mem_type)));
+  parts.index = integer_one_node;
+
+  if (fact.is_constant ()
+ && can_div_trunc_p (poly_step, fact, ))
+   {
+ /* Addressing mode "base + index".  */
+ rtx addr = addr_for_mem_ref (, as, false);
+ unsigned cost = address_cost (addr, mem_mode, as, speed);
+ tree step = wide_int_to_tree (sizetype,
+   exact_div (poly_step, fact));
+ parts.step = wide_int_to_tree (sizetype, fact);
+ /* Addressing mode "base + index << scale".  */
+ addr = addr_for_mem_ref (, as, false);
+ unsigned new_cost = address_cost (addr, mem_mode, as, speed);
+ if (new_cost < cost)
+   add_candidate (data, size_int (0), step, true, NULL);
+   }
+}
+
   /* Record common candidate with constant offset stripped in base.
  Like the use itself, we also add candidate directly for it.  */
   base = strip_offset (iv->base, );
@@ -7112,6 +7168,8 @@ get_alias_ptr_type_for_ptr_address (iv_use *use)
 {
 case IFN_MASK_LOAD:
 case IFN_MASK_STORE:
+case IFN_MASK_LOAD_LANES:
+case IFN_MASK_STORE_LANES:
   /* The second argument contains the correct alias type.  */
   gcc_assert (use->op_p = gimple_call_arg_ptr (call, 0));
   return TREE_TYPE (gimple_call_arg (call, 1));
-- 
2.7.4



Re: [PATCH v2 1/3] Move prepare_decl_rtl to expr.[ch] as extern

2019-05-14 Thread Kewen.Lin


on 2019/5/14 下午3:18, Richard Biener wrote:
> Hum.  The function is somewhat of a hack, trying to produce
> "reasonable" DECL_RTL, exposing it in expr.[ch] with this
> name is eventually misleading.  Also you fail to "outline"
> the most important part:
> 
>   FOR_EACH_VEC_ELT (decl_rtl_to_reset, i, obj)
> SET_DECL_RTL (obj, NULL_RTX);
> 
> which IMHO would warrant making this machinery a class
> with the above done in its destructor?
> 

Good suggestion!  In the IVOPTS implementation, it has one 
interface free_loop_data to clean up some data structures
including this decl_rtl_to_reset.  While for the use in 
"PATCH v2 2/3", we have to clean it artificially once 
expanding finishes.

It's better to make it as a class and ensure the clean of
the vector in its destructor.

> Maybe name the functions prepare_guessed_decl_rtl ()
> and the new class guessed_decl_rtl?
> 
OK.  Or "tmp" instead of "guessed"?


Thanks,
Kewen

> Now looking how you'll end up using this...
> 
> Richard.
> 



Re: [PATCH 12/12] fix diagnostic quoting/spelling issues in ObjC

2019-05-14 Thread Iain Sandoe
Hi Martin,

> On 14 May 2019, at 22:33, Martin Sebor  wrote:
> 
> The attached patch fixes quoting, spelling, and other formatting
> issues in diagnostics issued by the Objective C/C++ front-end and
> pointed out by the -Wformat-diag warning.

> 

The ObjC changes are OK.

It’s possible there might be a few more testsuite fails from this that are only
tested for the NeXT runtime; those can be picked up later (or if there’s no
hurry to apply this, I can stick it into a run in the next few days).

thanks
Iain



Re: [PATCH] Fix aarch64 exception handling (PR c++/59813)

2019-05-14 Thread Jakub Jelinek
On Tue, May 14, 2019 at 01:08:27PM -0600, Jeff Law wrote:
> > In https://gcc.gnu.org/ml/gcc-patches/2019-05/msg00484.html I've posted a
> > patch that would set it earlier (or it could be set during gimplification
> > and propagated during inlining, would need to be in cfun->calls_eh_return
> > instead of crtl->calls_eh_return) and then targets for which we do not want
> > to bother with it or where it is not beneficial to have tail calls in
> > functions that call __builtin_eh_return (as I said in the thread, e.g. on
> > x86_64-linux it is both smaller and faster), the targets which we expect to
> > fail currently or even have a proof of that can just punt.
> I would go with a patch that got the info set earlier and just punt in
> the generic code.  I just don't see this case as terribly important to
> optimize.

So like this?  Bootstrapped/regtested on x86_64-linux and i686-linux,
verified _Unwind_Resume_or_Rethrow no longer has a tail call.

2019-05-14  Jakub Jelinek  

PR c++/59813
PR target/90418
* function.h (struct function): Add calls_eh_return member.
* gimplify.c (gimplify_call_expr): Set cfun->calls_eh_return when
gimplifying __builtin_eh_return call.
* tree-inline.c (initialize_cfun): Copy calls_eh_return from src_cfun
to cfun.
(expand_call_inline): Or in src_cfun->calls_eh_return into
dst_cfun->calls_eh_return.
* tree-tailcall.c (suitable_for_tail_call_opt_p): Return false if
cfun->calls_eh_return.
* lto-streamer-in.c (input_struct_function_base): Read calls_eh_return.
* lto-streamer-out.c (output_struct_function_base): Write
calls_eh_return.

--- gcc/function.h.jj   2019-01-01 12:37:15.383004075 +0100
+++ gcc/function.h  2019-05-14 21:40:13.837715081 +0200
@@ -327,6 +327,9 @@ struct GTY(()) function {
  either as a subroutine or builtin.  */
   unsigned int calls_alloca : 1;
 
+  /* Nonzero if function being compiled can call __builtin_eh_return.  */
+  unsigned int calls_eh_return : 1;
+
   /* Nonzero if function being compiled receives nonlocal gotos
  from nested functions.  */
   unsigned int has_nonlocal_label : 1;
--- gcc/gimplify.c.jj   2019-05-03 15:22:07.416401170 +0200
+++ gcc/gimplify.c  2019-05-14 21:51:38.700288873 +0200
@@ -3297,6 +3297,10 @@ gimplify_call_expr (tree *expr_p, gimple
  break;
}
 
+  case BUILT_IN_EH_RETURN:
+   cfun->calls_eh_return = true;
+   break;
+
   default:
 ;
   }
--- gcc/tree-inline.c.jj2019-05-10 10:15:40.704283180 +0200
+++ gcc/tree-inline.c   2019-05-14 21:49:19.038617963 +0200
@@ -2662,6 +2662,7 @@ initialize_cfun (tree new_fndecl, tree c
   cfun->va_list_gpr_size = src_cfun->va_list_gpr_size;
   cfun->va_list_fpr_size = src_cfun->va_list_fpr_size;
   cfun->has_nonlocal_label = src_cfun->has_nonlocal_label;
+  cfun->calls_eh_return = src_cfun->calls_eh_return;
   cfun->stdarg = src_cfun->stdarg;
   cfun->after_inlining = src_cfun->after_inlining;
   cfun->can_throw_non_call_exceptions
@@ -4778,6 +4779,7 @@ expand_call_inline (basic_block bb, gimp
   src_properties = id->src_cfun->curr_properties & prop_mask;
   if (src_properties != prop_mask)
 dst_cfun->curr_properties &= src_properties | ~prop_mask;
+  dst_cfun->calls_eh_return |= id->src_cfun->calls_eh_return;
 
   gcc_assert (!id->src_cfun->after_inlining);
 
--- gcc/tree-tailcall.c.jj  2019-05-10 23:20:33.849768476 +0200
+++ gcc/tree-tailcall.c 2019-05-14 21:54:34.733353248 +0200
@@ -140,6 +140,7 @@ suitable_for_tail_opt_p (void)
 
   return true;
 }
+
 /* Returns false when the function is not suitable for tail call optimization
for some reason (e.g. if it takes variable number of arguments).
This test must pass in addition to suitable_for_tail_opt_p in order to make
@@ -168,6 +169,11 @@ suitable_for_tail_call_opt_p (void)
   if (cfun->calls_setjmp)
 return false;
 
+  /* Various targets don't handle tail calls correctly in functions
+ that call __builtin_eh_return.  */
+  if (cfun->calls_eh_return)
+return false;
+
   /* ??? It is OK if the argument of a function is taken in some cases,
  but not in all cases.  See PR15387 and PR19616.  Revisit for 4.1.  */
   for (param = DECL_ARGUMENTS (current_function_decl);
--- gcc/lto-streamer-in.c.jj2019-03-08 11:43:35.062317743 +0100
+++ gcc/lto-streamer-in.c   2019-05-14 21:41:48.900128559 +0200
@@ -1005,6 +1005,7 @@ input_struct_function_base (struct funct
   fn->has_forced_label_in_static = bp_unpack_value (, 1);
   fn->calls_alloca = bp_unpack_value (, 1);
   fn->calls_setjmp = bp_unpack_value (, 1);
+  fn->calls_eh_return = bp_unpack_value (, 1);
   fn->has_force_vectorize_loops = bp_unpack_value (, 1);
   fn->has_simduid_loops = bp_unpack_value (, 1);
   fn->va_list_fpr_size = bp_unpack_value (, 8);
--- gcc/lto-streamer-out.c.jj   2019-03-08 11:43:35.062317743 +0100
+++ gcc/lto-streamer-out.c  2019-05-14 21:42:05.262855481 

Re: [PATCH v2 2/3] Add predict_doloop_p target hook

2019-05-14 Thread Segher Boessenkool
On Tue, May 14, 2019 at 01:13:34PM -0600, Jeff Law wrote:
> Trying to guess what the target is going to do, then changing the
> structure of the loops in gimple based on that guess -- is that really a
> good idea.  It's fairly counter to many of the design goals around gimple.

That is exactly what ivopts does in the first place?  It tries to find
what ivs result in cheaper code, and it looks at a lot of target-specific
stuff for that (like available addressing modes and the cost to use those).

I think doloops fit perfectly well in that scheme.  This patch is not
radically changing anything.


Segher


[PATCH 3/3][DejaGNU] target: Wrap linker flags into `-largs'/`-margs' for Ada

2019-05-14 Thread Maciej W. Rozycki
Unrecognized `gnatmake' switches are not implicitly passed on to the 
linker, so just pasting board `ldflags' and any other linker flags 
verbatim into `add_flags' to use for the invocation line of `gnatmake' 
will make them ignored at best.

For example in a GCC test environment that has:

set_board_info ldflags 
"-Wl,-dynamic-linker,.../sysroot/lib/ld-linux-riscv64-lp64d.so.1 
-Wl,-rpath,.../sysroot/lib64/lp64d -Wl,-rpath,.../sysroot/usr/lib64/lp64d"

so that sysroot paths are correctly embedded with the binaries linked 
for use with the dynamic loader and shared library dependencies, the 
setting will be ignored for the GNAT test suite making all the execution 
tests fail, e.g.:

PASS: gnat.dg/abstract_with_anonymous_result.adb (test for excess errors)
spawn qemu-riscv64 ./abstract_with_anonymous_result.exe
/lib/ld-linux-riscv64-lp64d.so.1: No such file or directory
FAIL: gnat.dg/abstract_with_anonymous_result.adb execution test

For `gnatmake' to pass switches on to the linker the `-largs' switch has 
to be used, which affects all the switches that follow until a switch is
seen that changes the selection, like `-margs', which resets to the 
initial state of the switch interpretation machine.

Wrap linker flags into `-largs'/`-margs' for Ada then, carefully 
preserving the place these flags are placed within `add_flags', as 
surely someone will have depended on that, correcting test failures like 
above:

PASS: gnat.dg/abstract_with_anonymous_result.adb (test for excess errors)
spawn qemu-riscv64 ./abstract_with_anonymous_result.exe
PASS: gnat.dg/abstract_with_anonymous_result.adb execution test

* lib/target.exp (default_target_compile): Wrap linker flags into 
`-largs'/`-margs' for Ada.

Signed-off-by: Maciej W. Rozycki 
---
Hi,

 My WDC copyright paperwork has not been sorted with FSF yet, however I 
have not contributed to DejaGNU on behalf of WDC so far and I believe this 
change falls within the limit of roughly 15 lines to be considered legally 
insignificant given that:

"A regular series of repeated changes, such as renaming a symbol, is not
legally significant even if the symbol has to be renamed in many places."

 Please apply then; this does not rely on 2/3 in any way, as we ought to
handle Ada compilations correctly regardless of whether our caller does 
the right thing there.

  Maciej 
---
 lib/target.exp |   24 ++--
 1 file changed, 18 insertions(+), 6 deletions(-)

dejagnu-target-ada-ldflags.diff
Index: dejagnu/lib/target.exp
===
--- dejagnu.orig/lib/target.exp
+++ dejagnu/lib/target.exp
@@ -518,11 +518,12 @@ proc default_target_compile {source dest
 }
 
 if { $type eq "executable" } {
+   set extra_ldflags ""
if {[board_info $dest exists ldflags]} {
-   append add_flags " [board_info $dest ldflags]"
+   append extra_ldflags " [board_info $dest ldflags]"
}
if { $compiler_type eq "c++" } {
-   append add_flags " [g++_link_flags]"
+   append extra_ldflags " [g++_link_flags]"
}
if {[isnative]} {
# This is a lose.
@@ -530,16 +531,23 @@ proc default_target_compile {source dest
if { $tmp ne "" } {
if {[regexp ".*solaris2.*" $target_triplet]} {
# Solaris 2
-   append add_flags " -R$tool_root_dir/libstdc++"
+   append extra_ldflags " -R$tool_root_dir/libstdc++"
} elseif {[regexp ".*(osf|irix5|linux).*" $target_triplet]} {
# OSF/1 or IRIX 5
-   append add_flags " -Wl,-rpath,$tool_root_dir/libstdc++"
+   append extra_ldflags " -Wl,-rpath,$tool_root_dir/libstdc++"
} elseif {[regexp ".*hppa.*" $target_triplet]} {
# HP-UX
-   append add_flags " -Wl,-a,shared_archive"
+   append extra_ldflags " -Wl,-a,shared_archive"
}
}
}
+   if { $extra_ldflags ne "" } {
+   if { $compiler_type eq "ada" } {
+   append add_flags " -largs $extra_ldflags -margs"
+   } else {
+   append add_flags " $extra_ldflags"
+   }
+   }
 }
 
 if {![info exists ldscript]} {
@@ -561,7 +569,11 @@ proc default_target_compile {source dest
 }
 
 if { $type eq "executable" } {
-   append add_flags " $ldflags"
+   if { $compiler_type eq "ada" } {
+   append add_flags " -largs $ldflags -margs"
+   } else {
+   append add_flags " $ldflags"
+   }
foreach x $libs {
if {[file exists $x]} {
append source " $x"

[PATCH 2/3][GCC] GNAT/testsuite: Pass the `ada' option to target compilation

2019-05-14 Thread Maciej W. Rozycki
Pass the `ada' option to DejaGNU's `target_compile' procedure, which by 
default calls `default_target_compile', so that it arranges for an Ada 
compilation rather the default of C.  We set the compiler to `gnatmake' 
manually here, so that part of the logic in `default_target_compile' is 
not used, but it affects other settings, such as the use of `adaflags'.

gcc/testsuite/
* lib/gnat.exp (gnat_target_compile): Pass the `ada' option to 
`target_compile'.
---
Hi,

 Unfortunately I have exhausted the limit of changes I can make to GCC
without my WDC copyright paperwork sorted with FSF.  OK to apply once that
has been completed?

  Maciej
---
 gcc/testsuite/lib/gnat.exp |2 ++
 1 file changed, 2 insertions(+)

gcc-test-gnat-options-ada.diff
Index: gcc/gcc/testsuite/lib/gnat.exp
===
--- gcc.orig/gcc/testsuite/lib/gnat.exp
+++ gcc/gcc/testsuite/lib/gnat.exp
@@ -167,6 +167,8 @@ proc gnat_target_compile { source dest t
set options [concat "additional_flags=$TOOL_OPTIONS" $options]
 }
 
+set options [concat "{ada}" $options]
+
 return [target_compile $source $dest $type $options]
 }
 

[PATCH 1/3][GCC] gnatmake: Accept the `--sysroot=' GCC driver option

2019-05-14 Thread Maciej W. Rozycki
According to `gnatmake' documentation:

"Any uppercase or multi-character switch that is not a 'gnatmake' switch
is passed to 'gcc' (e.g., '-O', '-gnato,' etc.)"

however the `--sysroot=' switch is actually rejected:

gnatmake: invalid switch: --sysroot=...

likely because it is one of the very few GCC driver options that have a 
leading double dash and therefore we don't have a blanket fall-through 
for such switches that would satisfy what our documentation claims.

The option is actually shared between the compiler and the linker, so 
pass the switch to both build stages if requested, removing GNAT 
testsuite issues like:

gnatmake: invalid switch: --sysroot=.../sysroot
compiler exited with status 1
Executing on host: .../gcc/gnatclean -c -q -n ./abstract_with_anonymous_result  
 (timeout = 300)
spawn -ignore SIGHUP .../gcc/gnatclean -c -q -n ./abstract_with_anonymous_result
PASS: gnat.dg/abstract_with_anonymous_result.adb (test for excess errors)
UNRESOLVED: gnat.dg/abstract_with_anonymous_result.adb compilation failed to 
produce executable

in a test environment where `--with-build-sysroot=.../sysroot' has been 
used to build a cross-compiler.  Passing to the compilation stage only 
would lead to errors like:

.../bin/riscv64-linux-gnu-ld: cannot find crt1.o: No such file or directory
.../bin/riscv64-linux-gnu-ld: cannot find -lc
collect2: error: ld returned 1 exit status
gnatlink: error when calling .../gcc/xgcc
gnatmake: *** link failed.
compiler exited with status 1
Executing on host: .../gcc/gnatclean -c -q -n ./abstract_with_anonymous_result  
 (timeout = 300)
spawn -ignore SIGHUP .../gcc/gnatclean -c -q -n ./abstract_with_anonymous_result
./abstract_with_anonymous_result.ali
./abstract_with_anonymous_result.o
FAIL: gnat.dg/abstract_with_anonymous_result.adb (test for excess errors)
Excess errors:
.../bin/riscv64-linux-gnu-ld: cannot find crt1.o: No such file or directory
.../bin/riscv64-linux-gnu-ld: cannot find -lc
gnatlink: error when calling .../gcc/xgcc

UNRESOLVED: gnat.dg/abstract_with_anonymous_result.adb compilation failed to 
produce executable

instead.

gcc/ada/
* make.adb (Scan_Make_Arg): Also accept `--sysroot=' for the 
compiler and the linker.
---
Hi,

 I think treating `--sysroot=' like this makes sense, as otherwise it'd 
have to be specified twice, once with `-largs' and the second time 
optionally with `-cargs'.  It's consistent with how `--param=' is handled.
I'm not sure if this peculiarity should be mentioned in the manual; it 
surely is not for the existing `--param=' switch.

 Unfortunately I have exhausted the limit of changes I can make to GCC 
without my WDC copyright paperwork sorted with FSF.  OK to apply once that 
has been completed?

  Maciej
---
 gcc/ada/make.adb |4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

gcc-gnatmake-sysroot.diff
Index: gcc/gcc/ada/make.adb
===
--- gcc.orig/gcc/ada/make.adb
+++ gcc/gcc/ada/make.adb
@@ -4516,7 +4516,9 @@ package body Make is
end;
 end if;
 
- elsif Argv'Length >= 8 and then Argv (1 .. 8) = "--param=" then
+ elsif (Argv'Length >= 8 and then Argv (1 .. 8) = "--param=")
+   or (Argv'Length >= 10 and then Argv (1 .. 10) = "--sysroot=")
+ then
 Add_Switch (Argv, Compiler);
 Add_Switch (Argv, Linker);
 

[PATCH 0/3] GNAT test suite fixes for build sysroot

2019-05-14 Thread Maciej W. Rozycki
Hi,

 In the course of setting up GCC regression testing for the RISC-V target 
I have discovered that the GNAT test suite does not correctly respond to 
the test environment settings passed from the test harness in my setup and 
consequently no test case works correctly.

 In my particular setup `--with-build-sysroot=' has been used to configure 
GCC and also additional linker flags are defined in the target board so 
that adjusted paths are used for the dynamic loader and shared libraries 
to be found in the build sysroot at the test suite run time.  That plays 
well with most of the test suites included with GCC, but not the GNAT one.

 I have tracked down the cause to three issues spread across `gnatmake', 
the GNAT test driver and the DejaGNU target driver.  These issues are 
independent from each other, however all have to be addressed for the test 
suite to run, so I have decided to group them into a series despite that 
each of them can be applied separately, and the DejaGNU one goes to a 
separate project even.

 With them all in place I get these results with the `riscv64-linux-gnu'
target:

=== gnat Summary ===

# of expected passes2926
# of unexpected failures5
# of expected failures  23
# of unsupported tests  26

which I think are pretty good, especially compared to the original results 
without these changes:

=== gnat Summary ===

# of expected passes1580
# of unexpected failures133
# of unexpected successes   23
# of unresolved testcases   875
# of unsupported tests  26

 See individual change descriptions for details.

  Maciej

[PATCH 12/12] fix diagnostic quoting/spelling issues in ObjC

2019-05-14 Thread Martin Sebor

The attached patch fixes quoting, spelling, and other formatting
issues in diagnostics issued by the Objective C/C++ front-end and
pointed out by the -Wformat-diag warning.

Martin
gcc/objc/ChangeLog:

	* objc-act.c (objc_begin_catch_clause): Quote keywords and options
	in diagnostics.
	(objc_build_throw_stmt): Same.
	(objc_finish_message_expr): Same.
	(get_super_receiver): Same.
	* objc-next-runtime-abi-01.c (objc_next_runtime_abi_01_init): Spell
	out "less than" in English./
	* objc-next-runtime-abi-02.c (objc_next_runtime_abi_02_init): Spell
	out "greater" in English.

diff --git a/gcc/objc/objc-act.c b/gcc/objc/objc-act.c
index 5cf7205c23b..1eb2262b8ec 100644
--- a/gcc/objc/objc-act.c
+++ b/gcc/objc/objc-act.c
@@ -4208,13 +4208,13 @@ objc_begin_catch_clause (tree decl)
 }
   else if (!objc_type_valid_for_messaging (type, false))
 {
-  error ("@catch parameter is not a known Objective-C class type");
+  error ("%<@catch%> parameter is not a known Objective-C class type");
   type = error_mark_node;
 }
   else if (TYPE_HAS_OBJC_INFO (TREE_TYPE (type))
 	   && TYPE_OBJC_PROTOCOL_LIST (TREE_TYPE (type)))
 {
-  error ("@catch parameter cannot be protocol-qualified");
+  error ("%<@catch%> parameter cannot be protocol-qualified");
   type = error_mark_node;
 }
   else if (POINTER_TYPE_P (type) && objc_is_object_id (TREE_TYPE (type)))
@@ -4336,7 +4336,8 @@ objc_build_throw_stmt (location_t loc, tree throw_expr)
   if (cur_try_context == NULL
   || cur_try_context->current_catch == NULL)
 	{
-	  error_at (loc, "%<@throw%> (rethrow) used outside of a @catch block");
+	  error_at (loc,
+		"%<@throw%> (rethrow) used outside of a %<@catch%> block");
 	  return error_mark_node;
 	}
 
@@ -5411,7 +5412,8 @@ objc_finish_message_expr (tree receiver, tree sel_name, tree method_params,
 		 prototype.  Emit a warning, then keep going (this
 		 will use any method with a matching name, as if the
 		 receiver was of type 'Class').  */
-	  warning (0, "@interface of class %qE not found", class_tree);
+	  warning (0, "%<@interface%> of class %qE not found",
+		   class_tree);
 	}
 	}
   /* Handle `self' and `super'.  */
@@ -5545,7 +5547,7 @@ objc_finish_message_expr (tree receiver, tree sel_name, tree method_params,
 		 warning, either include an @interface for the
 		 class, or cast the receiver to 'id'.  Note that
 		 rtype is an IDENTIFIER_NODE at this point.  */
-		  warning (0, "@interface of class %qE not found", rtype);
+		  warning (0, "%<@interface%> of class %qE not found", rtype);
 		}
 	}
 
@@ -5628,11 +5630,9 @@ objc_finish_message_expr (tree receiver, tree sel_name, tree method_params,
   if (!warn_missing_methods)
 	{
 	  warning_at (input_location,
-		  0, "(Messages without a matching method signature");
-	  warning_at (input_location,
-		  0, "will be assumed to return % and accept");
-	  warning_at (input_location,
-		  0, "%<...%> as arguments.)");
+		  0, "(messages without a matching method signature "
+		  "will be assumed to return % and accept "
+		  "%<...%> as arguments)");
 	  warn_missing_methods = true;
 	}
 }
@@ -8848,7 +8848,7 @@ get_super_receiver (void)
 }
   else
 {
-  error ("[super ...] must appear in a method context");
+  error ("%<[super ...]%> must appear in a method context");
   return error_mark_node;
 }
 }
diff --git a/gcc/objc/objc-next-runtime-abi-01.c b/gcc/objc/objc-next-runtime-abi-01.c
index 77d2c374bc0..fa83e64b6a1 100644
--- a/gcc/objc/objc-next-runtime-abi-01.c
+++ b/gcc/objc/objc-next-runtime-abi-01.c
@@ -150,7 +150,8 @@ objc_next_runtime_abi_01_init (objc_runtime_hooks *rthooks)
 {
   warning_at (UNKNOWN_LOCATION, OPT_Wall,
 		"%<-fobjc-sjlj-exceptions%> is the only supported exceptions "
-		"system for %<-fnext-runtime%> with %<-fobjc-abi-version%> < 2");
+		"system for %<-fnext-runtime%> with %<-fobjc-abi-version%> "
+		"argument less than 2");
 }
 
   rthooks->initialize = next_runtime_01_initialize;
diff --git a/gcc/objc/objc-next-runtime-abi-02.c b/gcc/objc/objc-next-runtime-abi-02.c
index a2214195b2c..aa1cbde5010 100644
--- a/gcc/objc/objc-next-runtime-abi-02.c
+++ b/gcc/objc/objc-next-runtime-abi-02.c
@@ -241,8 +241,10 @@ objc_next_runtime_abi_02_init (objc_runtime_hooks *rthooks)
 
   if (flag_objc_exceptions && flag_objc_sjlj_exceptions)
 {
-  inform (UNKNOWN_LOCATION, "%<-fobjc-sjlj-exceptions%> is ignored for "
-"%<-fnext-runtime%> when %<-fobjc-abi-version%> >= 2");
+  inform (UNKNOWN_LOCATION,
+	  "%<-fobjc-sjlj-exceptions%> is ignored for "
+	  "%<-fnext-runtime%> when %<-fobjc-abi-version%> "
+	  "greater than 1");
   flag_objc_sjlj_exceptions = 0;
 }
 


[PATCH 11/12] fix diagnostic quoting/spelling issues in i386 back-end

2019-05-14 Thread Martin Sebor

The attached patch fixes quoting, spelling, and other formatting
issues in diagnostics issued by the i386 back-end and pointed out
by the -Wformat-diag warning.

Martin
gcc/ChangeLog:

	* config/i386/i386-expand.c (get_element_number): Quote keywords
	and other internal names in diagnostics.  Adjust other diagnostic
	formatting issues noted by -Wformat-diag.
	* config/i386/i386-features.c
	(ix86_mangle_function_version_assembler_name): Same.
	* config/i386/i386-options.c (ix86_handle_abi_attribute): Same.
	* config/i386/i386.c (ix86_function_type_abi): Same.
	(ix86_function_ms_hook_prologue): Same.
	(classify_argument): Same.
	(ix86_expand_prologue): Same.
	(ix86_md_asm_adjust): Same.
	(ix86_memmodel_check): Same.

diff --git a/gcc/config/i386/i386-expand.c b/gcc/config/i386/i386-expand.c
index a55d4923be4..f96f079ee30 100644
--- a/gcc/config/i386/i386-expand.c
+++ b/gcc/config/i386/i386-expand.c
@@ -10630,7 +10630,8 @@ get_element_number (tree vec_type, tree arg)
   if (!tree_fits_uhwi_p (arg)
   || (elt = tree_to_uhwi (arg), elt > max))
 {
-  error ("selector must be an integer constant in the range 0..%wi", max);
+  error ("selector must be an integer constant in the range "
+	 "[0, %wi]", max);
   return 0;
 }
 
diff --git a/gcc/config/i386/i386-features.c b/gcc/config/i386/i386-features.c
index 67f45d66c48..60a120f4df7 100644
--- a/gcc/config/i386/i386-features.c
+++ b/gcc/config/i386/i386-features.c
@@ -2447,7 +2447,7 @@ ix86_mangle_function_version_assembler_name (tree decl, tree id)
   && lookup_attribute ("gnu_inline",
 			   DECL_ATTRIBUTES (decl)))
 error_at (DECL_SOURCE_LOCATION (decl),
-	  "function versions cannot be marked as gnu_inline,"
+	  "function versions cannot be marked as %,"
 	  " bodies have to be generated");
 
   if (DECL_VIRTUAL_P (decl)
diff --git a/gcc/config/i386/i386-options.c b/gcc/config/i386/i386-options.c
index dec8352143c..7c8ddbee0f7 100644
--- a/gcc/config/i386/i386-options.c
+++ b/gcc/config/i386/i386-options.c
@@ -3462,7 +3462,8 @@ ix86_handle_abi_attribute (tree *node, tree name, tree, int,
 {
   if (lookup_attribute ("sysv_abi", TYPE_ATTRIBUTES (*node)))
 {
-	  error ("ms_abi and sysv_abi attributes are not compatible");
+	  error ("%qs and %qs attributes are not compatible",
+		 "ms_abi", "sysv_abi");
 	}
 
   return NULL_TREE;
@@ -3471,7 +3472,8 @@ ix86_handle_abi_attribute (tree *node, tree name, tree, int,
 {
   if (lookup_attribute ("ms_abi", TYPE_ATTRIBUTES (*node)))
 {
-	  error ("ms_abi and sysv_abi attributes are not compatible");
+	  error ("%qs and %qs attributes are not compatible",
+		 "ms_abi", "sysv_abi");
 	}
 
   return NULL_TREE;
diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
index cc0ae3fcfd3..93ed940eb9e 100644
--- a/gcc/config/i386/i386.c
+++ b/gcc/config/i386/i386.c
@@ -1525,7 +1525,7 @@ ix86_function_type_abi (const_tree fntype)
   static int warned;
   if (TARGET_X32 && !warned)
 	{
-	  error ("X32 does not support ms_abi attribute");
+	  error ("X32 does not support % attribute");
 	  warned = 1;
 	}
 
@@ -1559,7 +1559,8 @@ ix86_function_ms_hook_prologue (const_tree fn)
 {
   if (decl_function_context (fn) != NULL_TREE)
 	error_at (DECL_SOURCE_LOCATION (fn),
-		  "ms_hook_prologue is not compatible with nested function");
+		  "% attribute is not compatible "
+		  "with nested function");
   else
 return true;
 }
@@ -2266,7 +2267,7 @@ classify_argument (machine_mode mode, const_tree type,
 		{
 		  warned = true;
 		  inform (input_location,
-			  "the ABI of passing union with long double"
+			  "the ABI of passing union with %"
 			  " has changed in GCC 4.4");
 		}
 	  return 0;
@@ -2384,7 +2385,7 @@ classify_argument (machine_mode mode, const_tree type,
 	{
 	  warned = true;
 	  inform (input_location,
-		  "the ABI of passing structure with complex float"
+		  "the ABI of passing structure with %"
 		  " member has changed in GCC 4.4");
 	}
 	  classes[1] = X86_64_SSESF_CLASS;
@@ -7787,7 +7788,7 @@ ix86_expand_prologue (void)
   /* Check if profiling is active and we shall use profiling before
  prologue variant. If so sorry.  */
   if (crtl->profile && flag_fentry != 0)
-sorry ("ms_hook_prologue attribute isn%'t compatible "
+sorry ("% attribute is not compatible "
 	   "with %<-mfentry%> for 32-bit");
 
   /* In ix86_asm_output_function_label we emitted:
@@ -20651,7 +20652,7 @@ ix86_md_asm_adjust (vec , vec &/*inputs*/,
   con += 4;
   if (strchr (con, ',') != NULL)
 	{
-	  error ("alternatives not allowed in asm flag output");
+	  error ("alternatives not allowed in % flag output");
 	  continue;
 	}
 
@@ -20715,7 +20716,7 @@ ix86_md_asm_adjust (vec , vec &/*inputs*/,
 	}
   if (code == UNKNOWN)
 	{
-	  error ("unknown asm flag output %qs", constraints[i]);
+	  error ("unknown % flag output %qs", constraints[i]);
 

[PATCH 8/12] fix diagnostic quoting/spelling in the middle-end

2019-05-14 Thread Martin Sebor

The attached patch fixes quoting, spelling, and other formatting
issues in diagnostics issued from files in middle-end files and
pointed out by the -Wformat-diag warning.

Martin
gcc/ChangeLog:

	* builtins.c (expand_builtin_atomic_always_lock_free): Quote
	identifiers, keywords, operators, and types in diagnostics.  Correct
	quoting, spelling, and sentence capitalization issues.
	(expand_builtin_atomic_is_lock_free): Same.
	(fold_builtin_next_arg): Same.
	* cfgexpand.c (expand_one_var): Same.
	(tree_conflicts_with_clobbers_p): Same.
	(expand_asm_stmt): Same.
	(verify_loop_structure): Same.
	* cgraphunit.c (process_function_and_variable_attributes): Same.
	* collect-utils.c (collect_execute): Same.
	* collect2.c (maybe_run_lto_and_relink): Same.
	(is_lto_object_file): Same.
	(scan_prog_file): Same.
	* convert.c (convert_to_real_1): Same.
	* diagnostic-core.h (GCC_DIAG_STYLE): Adjust.
	(GCC_DIAG_RAW_STYLE): New macro.
	* dwarf2out.c (dwarf2out_begin_prologue): Same.
	* except.c (verify_eh_tree): Same.
	* gcc.c (execute): Same.
	(eval_spec_function): Same.
	(run_attempt): Same.
	(driver::set_up_specs): Same.
	(compare_debug_auxbase_opt_spec_function): Same.
	* gcov-tool.c (unlink_gcda_file): Same.
	(do_merge): Same.
	(do_rewrite): Same.
	* gcse.c (gcse_or_cprop_is_too_expensive): Same.
	* gimplify.c (gimplify_asm_expr): Same.
	(gimplify_adjust_omp_clauses): Same.
	* hsa-gen.c (gen_hsa_addr_insns): Same.
	(gen_hsa_insns_for_load): Same.
	(gen_hsa_cmp_insn_from_gimple): Same.
	(gen_hsa_insns_for_operation_assignment): Same.
	(gen_get_level): Same.
	(gen_hsa_alloca): Same.
	(omp_simple_builtin::generate): Same.
	(gen_hsa_atomic_for_builtin): Same.
	(gen_hsa_insns_for_call): Same.
	* input.c (dump_location_info): Same.
	* ipa-devirt.c (compare_virtual_tables): Same.
	* ira.c (ira_setup_eliminable_regset): Same.
	* lra-assigns.c (lra_assign): Same.
	* lra-constraints.c (lra_constraints): Same.
	* lto-streamer-in.c (lto_input_mode_table): Same.
	* lto-wrapper.c (get_options_from_collect_gcc_options): Same.
	(merge_and_complain): Same.
	(compile_offload_image): Same.
	(compile_images_for_offload_targets): Same.
	(debug_objcopy): Same.
	(run_gcc): Same.
	(main): Same.
	* opts.c (print_specific_help): Same.
	(parse_no_sanitize_attribute): Same.
	(print_help): Same.
	(handle_param): Same.
	* passes.c (opt_pass::clone): Same.
	* plugin.c (add_new_plugin): Same.
	(parse_plugin_arg_opt): Same.
	(try_init_one_plugin): Same.
	* pretty-print.h (GCC_DIAG_RAW_STYLE): Adjust.
	(GCC_DIAG_RAW_STYLE): New macro.
	* print-rtl.c (debug_bb_n_slim): Quote identifiers, keywords,
	operators, and types in diagnostics.  Correct quoting and spelling
	issues.
	* read-rtl-function.c (parse_edge_flag_token): Same.
	(function_reader::parse_enum_value): Same.
	* reg-stack.c (check_asm_stack_operands): Same.
	* regcprop.c (validate_value_data): Same.
	* sched-rgn.c (make_pass_sched_fusion): Same.
	* stmt.c (check_unique_operand_names): Same.
	* targhooks.c (default_target_option_pragma_parse): Same.
	* tlink.c (recompile_files): Same.
	* toplev.c (process_options): Same.
	(do_compile): Same.
	* trans-mem.c (diagnose_tm_1): Same.
	(ipa_tm_scan_irr_block): Same.
	(ipa_tm_diagnose_transaction): Same.
	* tree-cfg.c (verify_address): Same.  Use get_tree_code_name to
	format a tree code name in a diagnostic.
	(verify_types_in_gimple_min_lval): Same.
	(verify_types_in_gimple_reference): Same.
	(verify_gimple_call): Same.
	(verify_gimple_assign_unary): Same.
	(verify_gimple_assign_binary): Same.
	(verify_gimple_assign_ternary): Same.
	(verify_gimple_assign_single): Same.
	(verify_gimple_switch): Same.
	(verify_gimple_label): Same.
	(verify_gimple_phi): Same.
	(verify_gimple_in_seq): Same.
	(verify_eh_throw_stmt_node): Same.
	(collect_subblocks): Same.
	(gimple_verify_flow_info): Same.
	(do_warn_unused_result): Same.
	* tree-inline.c (expand_call_inline): Same.
	* tree-into-ssa.c (update_ssa): Same.
	* tree.c (tree_int_cst_elt_check_failed): Same.
	(tree_vec_elt_check_failed): Same.
	(omp_clause_operand_check_failed): Same.
	(verify_type_variant): Same.
	(verify_type): Same.
	* value-prof.c (verify_histograms): Same.
	* varasm.c (assemble_start_function): Same.

	* cfghooks.c: Disable -Wformat-diags.
	* cfgloop.c: Same.
	* cfgrtl.c: Same.
	* cgraph.c: Same.
	* diagnostic-show-locus.c: Same.
	* diagnostic.c: Same.
	* gimple-pretty-print.c: Same.
	* graph.c: Same.
	* symtab.c: Same.
	* tree-eh.c Same.
	* tree-pretty-print.c: Same.
	* tree-ssa.c: Same.

	* configure: Regenerate.
	* configure.ac (ACX_PROG_CXX_WARNING_OPTS): Add -Wno-error=format-diag.
	 (ACX_PROG_CC_WARNING_OPTS): Same.

gcc/lto/ChangeLog:

	* lto-dump.c (lto_main): Same.
	* lto.c (stream_out): Same.

diff --git a/gcc/builtins.c b/gcc/builtins.c
index d37d73fc4a0..0456a9ef646 100644
--- a/gcc/builtins.c
+++ b/gcc/builtins.c
@@ -6784,7 +6784,7 @@ expand_builtin_atomic_always_lock_free (tree exp)
 
   if (TREE_CODE (arg0) != INTEGER_CST)
 {
-  error ("non-constant argument 1 to 

[PATCH 10/12] fix diagnostic quoting/spelling in D

2019-05-14 Thread Martin Sebor

The attached patch fixes quoting, spelling, and other formatting
issues in diagnostics issued by the D front end and pointed out
by the -Wformat-diag warning.

Martin
gcc/d/ChangeLog:

	* d/d-builtins.cc (d_init_builtins): Quote keywords, operators,
	and types in diagnostics.
	* d/d-codegen.cc (get_array_length): Same.  Replace can't with cannot.
	* d/d-convert.cc (convert_expr): Same.
	* d/d-frontend.cc (getTypeInfoType): Quote an option name in
	a diagnostic.
	* d/d-lang.cc (d_handle_option): Same.
	(d_parse_file): Same.
	* d/decl.cc: Remove a trailing period from a diagnostic.
	* d/expr.cc: Use a directive for an apostrophe.
	* d/toir.cc: Quote keywords, operators, and types in diagnostics.
	* d/typeinfo.cc (build_typeinfo): Quote an option name in a diagnostic.

diff --git a/gcc/d/d-builtins.cc b/gcc/d/d-builtins.cc
index 3dbdafb492a..3ebee721a25 100644
--- a/gcc/d/d-builtins.cc
+++ b/gcc/d/d-builtins.cc
@@ -1117,7 +1117,7 @@ d_init_builtins (void)
   Type::tvalist = build_frontend_type (va_list_type_node);
   if (!Type::tvalist)
 {
-  error ("cannot represent built-in va_list type in D");
+  error ("cannot represent built-in % type in D");
   gcc_unreachable ();
 }
 
diff --git a/gcc/d/d-codegen.cc b/gcc/d/d-codegen.cc
index 2abff92fc88..1971064e334 100644
--- a/gcc/d/d-codegen.cc
+++ b/gcc/d/d-codegen.cc
@@ -316,7 +316,7 @@ get_array_length (tree exp, Type *type)
   return d_array_length (exp);
 
 default:
-  error ("can't determine the length of a %qs", type->toChars ());
+  error ("cannot determine the length of a %qs", type->toChars ());
   return error_mark_node;
 }
 }
diff --git a/gcc/d/d-convert.cc b/gcc/d/d-convert.cc
index e9aa457d852..b020eab902f 100644
--- a/gcc/d/d-convert.cc
+++ b/gcc/d/d-convert.cc
@@ -376,7 +376,7 @@ convert_expr (tree exp, Type *etype, Type *totype)
 	}
   else
 	{
-	  error ("can't convert a delegate expression to %qs",
+	  error ("cannot convert a delegate expression to %qs",
 		 totype->toChars ());
 	  return error_mark_node;
 	}
@@ -392,7 +392,7 @@ convert_expr (tree exp, Type *etype, Type *totype)
 	}
 	  else
 	{
-	  error ("can't convert struct %qs to %qs",
+	  error ("cannot convert struct %qs to %qs",
 		 etype->toChars (), totype->toChars ());
 	  return error_mark_node;
 	}
@@ -475,7 +475,7 @@ convert_expr (tree exp, Type *etype, Type *totype)
 
 	  if ((dim * esize) % tsize != 0)
 	{
-	  error ("cannot cast %qs to %qs since sizes don't line up",
+	  error ("cannot cast %qs to %qs since sizes do not line up",
 		 etype->toChars (), totype->toChars ());
 	  return error_mark_node;
 	}
diff --git a/gcc/d/d-frontend.cc b/gcc/d/d-frontend.cc
index ccd5f50130f..77b6f22d824 100644
--- a/gcc/d/d-frontend.cc
+++ b/gcc/d/d-frontend.cc
@@ -625,7 +625,7 @@ getTypeInfoType (Loc loc, Type *type, Scope *sc)
 	  if (!warned)
 	{
 	  error_at (make_location_t (loc),
-			"% cannot be used with -fno-rtti");
+			"% cannot be used with %<-fno-rtti%>");
 	  warned = 1;
 	}
 	}
diff --git a/gcc/d/d-lang.cc b/gcc/d/d-lang.cc
index 62a8ddd69b2..f23f719a2c3 100644
--- a/gcc/d/d-lang.cc
+++ b/gcc/d/d-lang.cc
@@ -449,7 +449,7 @@ d_handle_option (size_t scode, const char *arg, HOST_WIDE_INT value,
 	  break;
 	}
 
-  error ("bad argument for -fdebug %qs", arg);
+  error ("bad argument for %<-fdebug%>: %qs", arg);
   break;
 
 case OPT_fdoc:
@@ -497,7 +497,7 @@ d_handle_option (size_t scode, const char *arg, HOST_WIDE_INT value,
 case OPT_fmodule_file_:
   global.params.modFileAliasStrings->push (arg);
   if (!strchr (arg, '='))
-	error ("bad argument for -fmodule-file %qs", arg);
+	error ("bad argument for %<-fmodule-file%>: %qs", arg);
   break;
 
 case OPT_fmoduleinfo:
@@ -588,7 +588,7 @@ d_handle_option (size_t scode, const char *arg, HOST_WIDE_INT value,
 	  break;
 	}
 
-  error ("bad argument for -fversion %qs", arg);
+  error ("bad argument for %<-fversion%>: %qs", arg);
   break;
 
 case OPT_H:
@@ -1011,7 +1011,7 @@ d_parse_file (void)
   /* In this mode, the first file name is supposed to be a duplicate
  of one of the input files.  */
   if (d_option.fonly && strcmp (d_option.fonly, main_input_filename) != 0)
-error ("-fonly= argument is different from first input file name");
+error ("%<-fonly=%> argument is different from first input file name");
 
   for (size_t i = 0; i < num_in_fnames; i++)
 {
diff --git a/gcc/d/decl.cc b/gcc/d/decl.cc
index 49723649230..bcce245e59c 100644
--- a/gcc/d/decl.cc
+++ b/gcc/d/decl.cc
@@ -463,7 +463,7 @@ public:
 			fd2->toPrettyChars ());
 		inform (make_location_t (d->loc),
 			"use % to introduce base class "
-			"overload set.", fd->toChars (),
+			"overload set", fd->toChars (),
 			fd->parent->toChars (), fd->toChars ());
 		  }
 		else
diff --git a/gcc/d/expr.cc b/gcc/d/expr.cc
index 6497619e5fd..826c32a059f 100644
--- 

[PATCH 5/12] fix diagnostic quoting/spelling in c-family

2019-05-14 Thread Martin Sebor

The attached patch fixes quoting, spelling, and other formatting
issues in diagnostics issued from files in the c-family/ directory
and pointed out by the -Wformat-diag warning.

Martin
gcc/c-family/ChangeLog:

	* c-attribs.c (handle_no_sanitize_attribute): Quote identifiers,
	keywords, operators, and types in diagnostics.
	(handle_scalar_storage_order_attribute): Same.
	(handle_mode_attribute): Same.
	(handle_visibility_attribute): Same.
	(handle_assume_aligned_attribute): Same.
	(handle_no_split_stack_attribute): Same.
	* c-common.c (shorten_compare): Same.
	(c_common_truthvalue_conversion): Same.
	(cb_get_source_date_epoch): Same.
	* c-common.h (GCC_DIAG_STYLE): Adjust.
	(GCC_DIAG_RAW_STYLE): New macro.
	* c-lex.c (cb_def_pragma): Quote keywords, operators, and types
	in diagnostics.
	(interpret_float): Same.
	* c-omp.c (c_finish_omp_for): Same.
	* c-opts.c (c_common_post_options): Same.
	* c-pch.c (c_common_pch_pragma): Same.
	* c-pragma.c (pop_alignment): Same.
	(handle_pragma_pack): Same.
	(apply_pragma_weak): Same.
	(handle_pragma_weak): Same.
	(handle_pragma_scalar_storage_order): Same.
	(handle_pragma_redefine_extname): Same.
	(add_to_renaming_pragma_list): Same.
	(maybe_apply_renaming_pragma): Same.
	(push_visibility): Same.
	(handle_pragma_visibility): Same.
	(handle_pragma_optimize): Same.
	(handle_pragma_message): Same.
	* c-warn.c (warn_for_omitted_condop): Same.
	(lvalue_error): Same.

diff --git a/gcc/c-family/c-attribs.c b/gcc/c-family/c-attribs.c
index 93b210eed9c..60e5d851586 100644
--- a/gcc/c-family/c-attribs.c
+++ b/gcc/c-family/c-attribs.c
@@ -891,7 +891,7 @@ handle_no_sanitize_attribute (tree *node, tree name, tree args, int,
   tree id = TREE_VALUE (args);
   if (TREE_CODE (id) != STRING_CST)
 	{
-	  error ("no_sanitize argument not a string");
+	  error ("%qE argument not a string", name);
 	  return NULL_TREE;
 	}
 
@@ -1418,8 +1418,8 @@ handle_scalar_storage_order_attribute (tree *node, tree name, tree args,
 
   if (BYTES_BIG_ENDIAN != WORDS_BIG_ENDIAN)
 {
-  error ("scalar_storage_order is not supported because endianness "
-	"is not uniform");
+  error ("%qE attribute is not supported because endianness is not uniform",
+	 name);
   return NULL_TREE;
 }
 
@@ -1435,8 +1435,8 @@ handle_scalar_storage_order_attribute (tree *node, tree name, tree args,
 	reverse = BYTES_BIG_ENDIAN;
   else
 	{
-	  error ("scalar_storage_order argument must be one of \"big-endian\""
-		 " or \"little-endian\"");
+	  error ("attribute %qE argument must be one of %qs or %qs",
+		 name, "big-endian", "little-endian");
 	  return NULL_TREE;
 	}
 
@@ -1759,9 +1759,9 @@ handle_mode_attribute (tree *node, tree name, tree args,
 	case MODE_VECTOR_ACCUM:
 	case MODE_VECTOR_UACCUM:
 	  warning (OPT_Wattributes, "specifying vector types with "
-		   "__attribute__ ((mode)) is deprecated");
-	  warning (OPT_Wattributes,
-		   "use __attribute__ ((vector_size)) instead");
+		   "%<__attribute__ ((mode))%> is deprecated");
+	  inform (input_location,
+		  "use %<__attribute__ ((vector_size))%> instead");
 	  valid_mode = vector_mode_valid_p (mode);
 	  break;
 
@@ -2671,7 +2671,8 @@ handle_visibility_attribute (tree *node, tree name, tree args,
 vis = VISIBILITY_PROTECTED;
   else
 {
-  error ("visibility argument must be one of \"default\", \"hidden\", \"protected\" or \"internal\"");
+  error ("attribute %qE argument must be one of %qs, %qs, %qs, or %qs",
+	 name, "default", "hidden", "protected", "internal");
   vis = VISIBILITY_DEFAULT;
 }
 
@@ -2935,8 +2936,8 @@ handle_assume_aligned_attribute (tree *node, tree name, tree args, int,
 	  /* The misalignment specified by the second argument
 	 must be non-negative and less than the alignment.  */
 	  warning (OPT_Wattributes,
-		   "%qE attribute argument %E is not in the range [0, %E)",
-		   name, val, align);
+		   "%qE attribute argument %E is not in the range %s, %E%c",
+		   name, val, "[0", align, ')');
 	  *no_add_attrs = true;
 	  return NULL_TREE;
 	}
@@ -3985,13 +3986,13 @@ handle_no_split_stack_attribute (tree *node, tree name,
struct attribute_spec.handler.  */
 
 static tree
-handle_returns_nonnull_attribute (tree *node, tree, tree, int,
+handle_returns_nonnull_attribute (tree *node, tree name, tree, int,
   bool *no_add_attrs)
 {
   // Even without a prototype we still have a return type we can check.
   if (TREE_CODE (TREE_TYPE (*node)) != POINTER_TYPE)
 {
-  error ("returns_nonnull attribute on a function not returning a pointer");
+  error ("%qE attribute on a function not returning a pointer", name);
   *no_add_attrs = true;
 }
   return NULL_TREE;
diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c
index 3c2f7a9d1c7..4cb2082959a 100644
--- a/gcc/c-family/c-common.c
+++ b/gcc/c-family/c-common.c
@@ -3063,14 +3063,16 @@ shorten_compare (location_t loc, tree *op0_ptr, tree *op1_ptr,
 	case GE_EXPR:
 	  if (warn)
 		

[PATCH 6/12] fix diagnostic quoting/spelling in C++

2019-05-14 Thread Martin Sebor

The attached patch fixes quoting, spelling, and other formatting
issues in diagnostics issued by the C++ front-end and pointed out
by the -Wformat-diag warning.

Martin
gcc/cp/ChangeLog:

	* call.c (print_z_candidate): Wrap diagnostic text in a gettext
	macro.  Adjust.
	(print_z_candidates): Same.
	(build_conditional_expr_1): Quote keywords, operators, and types
	in diagnostics.
	(build_op_delete_call): Same.
	(maybe_print_user_conv_context): Wrap diagnostic text in a gettext
	macro.
	(convert_like_real): Same.
	(convert_arg_to_ellipsis): Quote keywords, operators, and types
	in diagnostics.
	(build_over_call): Same.
	(joust): Break up an overlong line.  Wrap diagnostic text in a gettext
	macro.
	* constexpr.c (cxx_eval_check_shift_p): Spell out >= in English.
	(cxx_eval_constant_expression): Quote keywords, operators, and types
	in diagnostics.
	(potential_constant_expression_1): Same.
	* cp-gimplify.c (cp_genericize_r): Same.
	* cp-tree.h (GCC_DIAG_STYLE): Adjust.
	(GCC_DIAG_RAW_STYLE): New macro.
	* cvt.c (maybe_warn_nodiscard): Quote keywords, operators, and types
	in diagnostics.
	(type_promotes_to): Same.
	* decl.c (check_previous_goto_1): Same.
	(check_goto): Same.
	(start_decl): Same.
	(cp_finish_decl): Avoid parenthesizing a sentence for consistency.
	(grok_op_properties): Quote keywords, operators, and types
	in diagnostics.
	* decl2.c (grokfield): Same.
	(coerce_delete_type): Same.
	* except.c (is_admissible_throw_operand_or_catch_parameter): Same.
	* friend.c (do_friend): Quote C++ tokens.
	* init.c (build_new_1): Quote keywords, operators, and types
	in diagnostics.
	(build_vec_delete_1): Same.
	(build_delete): Same.
	* lex.c (parse_strconst_pragma): Same.
	(handle_pragma_implementation): Same.
	(unqualified_fn_lookup_error): Same.
	* mangle.c (write_type): Same.
	* method.c (defaulted_late_check): Avoid two consecutive punctuators.
	* name-lookup.c (cp_binding_level_debug): Remove a trailing newline.
	(pop_everything): Same.
	* parser.c (cp_lexer_start_debugging): Quote a macro name.
	in a diagnostic
	(cp_lexer_stop_debugging): Same.
	(cp_parser_userdef_numeric_literal): Quote a C++ header name
	in a diagnostic.
	(cp_parser_nested_name_specifier_opt): Quote keywords, operators,
	and types in diagnostics.
	(cp_parser_question_colon_clause): Same.
	(cp_parser_asm_definition): Same.
	(cp_parser_init_declarator): Same.
	(cp_parser_template_declaration_after_parameters): Avoid capitalizing
	a sentence in a diagnostic.
	(cp_parser_omp_declare_reduction): Quote keywords, operators, and types
	in diagnostics.
	(cp_parser_transaction): Same.
	* pt.c (maybe_process_partial_specialization): Replace second call
	to permerror with inform for consistency with other uses.
	(expand_integer_pack): Quote keywords, operators, and types
	in diagnostics.
	* rtti.c (get_typeid): Quote keywords, operators, and types
	in diagnostics.
	(build_dynamic_cast_1): Same.
	* semantics.c (finish_asm_stmt): Same.
	(finish_label_decl): Same.
	(finish_bases): Same.
	(finish_offsetof): Same.
	(cp_check_omp_declare_reduction): Same.
	(finish_decltype_type): Same.
	* tree.c (handle_init_priority_attribute): Same.  Add detail
	to diagnostics.
	(maybe_warn_zero_as_null_pointer_constant): Same.
	* typeck.c (cp_build_binary_op): Quote keywords, operators, and types
	in diagnostics.
	(cp_build_unary_op): Same.
	(check_for_casting_away_constness): Same.
	(build_static_cast): Same.
	(build_const_cast_1): Same.
	(maybe_warn_about_returning_address_of_local): Same.
	(check_return_expr): Same.
	* typeck2.c (abstract_virtuals_error_sfinae): Same.
	(digest_init_r): Replace a tab with spaces in a diagnostic.
	(build_functional_cast): Quote keywords, operators, and types
	in diagnostics.

diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index 00cb3993471..c2f17dc3750 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -3603,7 +3603,7 @@ print_z_candidate (location_t loc, const char *msgstr,
 {
   const char *msg = (msgstr == NULL
 		 ? ""
-		 : ACONCAT ((msgstr, " ", NULL)));
+		 : ACONCAT ((_(msgstr), " ", NULL)));
   tree fn = candidate->fn;
   if (flag_new_inheriting_ctors)
 fn = strip_inheriting_ctors (fn);
@@ -3613,24 +3613,27 @@ print_z_candidate (location_t loc, const char *msgstr,
 {
   cloc = loc;
   if (candidate->num_convs == 3)
-	inform (cloc, "%s%<%D(%T, %T, %T)%> ", msg, fn,
+	inform (cloc, "%s%<%D(%T, %T, %T)%> %s", msg, fn,
 		candidate->convs[0]->type,
 		candidate->convs[1]->type,
-		candidate->convs[2]->type);
+		candidate->convs[2]->type,
+		"");
   else if (candidate->num_convs == 2)
-	inform (cloc, "%s%<%D(%T, %T)%> ", msg, fn,
+	inform (cloc, "%s%<%D(%T, %T)%> %s", msg, fn,
 		candidate->convs[0]->type,
-		candidate->convs[1]->type);
+		candidate->convs[1]->type,
+		"");
   else
-	inform (cloc, "%s%<%D(%T)%> ", msg, fn,
-		candidate->convs[0]->type);
+	inform (cloc, "%s%<%D(%T)%> %s", msg, fn,
+		candidate->convs[0]->type,
+		"");
 }
   else if (TYPE_P (fn))
-inform (cloc, "%s%qT ", 

[PATCH 7/12] fix diagnostic quoting/spelling in libgcc

2019-05-14 Thread Martin Sebor

The attached patch fixes quoting, spelling, and other formatting
issues in diagnostics issued from files in the libgcc directory
and pointed out by the -Wformat-diag warning.

Martin
libgcc/ChangeLog:

	* libgcov-util.c (read_gcda_file): Remove trailing newline.

diff --git a/libgcc/libgcov-util.c b/libgcc/libgcov-util.c
index ae0dd017204..62f4fe38233 100644
--- a/libgcc/libgcov-util.c
+++ b/libgcc/libgcov-util.c
@@ -332,7 +332,7 @@ read_gcda_file (const char *filename)
 {
   if (((mask & 0xff) != 0xff))
 {
-  warning (0, "%s:tag `%x' is invalid\n", filename, tag);
+  warning (0, "%s:tag %qx is invalid", filename, tag);
   break;
 }
   tag_depth--;
@@ -347,7 +347,7 @@ read_gcda_file (const char *filename)
   if (depth && depth < tag_depth)
 {
   if (!GCOV_TAG_IS_SUBTAG (tags[depth - 1], tag))
-warning (0, "%s:tag `%x' is incorrectly nested\n",
+warning (0, "%s:tag %qx is incorrectly nested",
  filename, tag);
 }
   depth = tag_depth;
@@ -362,18 +362,18 @@ read_gcda_file (const char *filename)
 
   actual_length = gcov_position () - base;
   if (actual_length > length)
-warning (0, "%s:record size mismatch %lu bytes overread\n",
+warning (0, "%s:record size mismatch %lu bytes overread",
  filename, actual_length - length);
   else if (length > actual_length)
-warning (0, "%s:record size mismatch %lu bytes unread\n",
+warning (0, "%s:record size mismatch %lu bytes unread",
  filename, length - actual_length);
}
 
   gcov_sync (base, length);
   if ((error = gcov_is_error ()))
 {
-  warning (0, error < 0 ? "%s:counter overflow at %lu\n" :
-  "%s:read error at %lu\n", filename,
+  warning (0, error < 0 ? "%s:counter overflow at %lu" :
+  "%s:read error at %lu", filename,
(long unsigned) gcov_position ());
   break;
 }


[PATCH 4/12] fix diagnostic quoting/spelling in the C front-end

2019-05-14 Thread Martin Sebor

The attached patch fixes quoting, spelling, and other formatting
issues in diagnostics issued by the C front-end and pointed out
by the -Wformat-diag warning.

Martin
gcc/c/ChangeLog:

	* c-decl.c (start_decl): Quote keywords, operators, and
	types in diagnostics.
	(finish_decl): Same.
	* c-parser.c (c_parser_asm_statement): Same.
	(c_parser_conditional_expression): Same.
	(c_parser_transaction_cancel): Same.
	* c-typeck.c (c_common_type): Same.
	(build_conditional_expr): Same.
	(digest_init): Same.
	(process_init_element): Same.
	(build_binary_op): Same.

diff --git a/gcc/c/c-decl.c b/gcc/c/c-decl.c
index c8e7cd01d9e..11c0a421432 100644
--- a/gcc/c/c-decl.c
+++ b/gcc/c/c-decl.c
@@ -4887,7 +4887,7 @@ start_decl (struct c_declarator *declarator, struct c_declspecs *declspecs,
 switch (TREE_CODE (decl))
   {
   case TYPE_DECL:
-	error ("typedef %qD is initialized (use __typeof__ instead)", decl);
+	error ("typedef %qD is initialized (use %<__typeof__%> instead)", decl);
 	initialized = false;
 	break;
 
@@ -5282,7 +5282,7 @@ finish_decl (tree decl, location_t init_loc, tree init,
 	  && VAR_P (decl)
 	  && !C_DECL_REGISTER (decl)
 	  && !TREE_STATIC (decl))
-	warning (0, "ignoring asm-specifier for non-static local "
+	warning (0, "ignoring %-specifier for non-static local "
 		 "variable %q+D", decl);
 	  else
 	set_user_assembler_name (decl, asmspec);
diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c
index 3aa85125cf1..e499a7c8beb 100644
--- a/gcc/c/c-parser.c
+++ b/gcc/c/c-parser.c
@@ -6401,7 +6401,7 @@ c_parser_asm_statement (c_parser *parser)
 	case RID_VOLATILE:
 	  if (volatile_loc)
 	{
-	  error_at (loc, "duplicate asm qualifier %qE", token->value);
+	  error_at (loc, "duplicate % qualifier %qE", token->value);
 	  inform (volatile_loc, "first seen here");
 	}
 	  else
@@ -6412,7 +6412,7 @@ c_parser_asm_statement (c_parser *parser)
 	case RID_INLINE:
 	  if (inline_loc)
 	{
-	  error_at (loc, "duplicate asm qualifier %qE", token->value);
+	  error_at (loc, "duplicate % qualifier %qE", token->value);
 	  inform (inline_loc, "first seen here");
 	}
 	  else
@@ -6423,7 +6423,7 @@ c_parser_asm_statement (c_parser *parser)
 	case RID_GOTO:
 	  if (goto_loc)
 	{
-	  error_at (loc, "duplicate asm qualifier %qE", token->value);
+	  error_at (loc, "duplicate % qualifier %qE", token->value);
 	  inform (goto_loc, "first seen here");
 	}
 	  else
@@ -6433,7 +6433,7 @@ c_parser_asm_statement (c_parser *parser)
 
 	case RID_CONST:
 	case RID_RESTRICT:
-	  error_at (loc, "%qE is not an asm qualifier", token->value);
+	  error_at (loc, "%qE is not an % qualifier", token->value);
 	  c_parser_consume_token (parser);
 	  continue;
 
@@ -6791,7 +6791,7 @@ c_parser_conditional_expression (c_parser *parser, struct c_expr *after,
 
   location_t middle_loc = c_parser_peek_token (parser)->location;
   pedwarn (middle_loc, OPT_Wpedantic,
-	   "ISO C forbids omitting the middle term of a ?: expression");
+	   "ISO C forbids omitting the middle term of a % expression");
   if (TREE_CODE (cond.value) == EXCESS_PRECISION_EXPR)
 	{
 	  eptype = TREE_TYPE (cond.value);
@@ -19825,8 +19825,8 @@ c_parser_transaction_cancel (c_parser *parser)
 	  && !is_tm_may_cancel_outer (current_function_decl))
 	{
 	  error_at (loc, "outer %<__transaction_cancel%> not "
-		"within outer %<__transaction_atomic%>");
-	  error_at (loc, "  or a % function");
+		"within outer %<__transaction_atomic%> or "
+		"a % function");
 	  goto ret_error;
 	}
 }
diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c
index 4e443754002..5eff040e85d 100644
--- a/gcc/c/c-typeck.c
+++ b/gcc/c/c-typeck.c
@@ -743,17 +743,18 @@ c_common_type (tree t1, tree t2)
 {
   if (code1 == VECTOR_TYPE || code2 == VECTOR_TYPE)
 	{
-	  error ("can%'t mix operands of decimal float and vector types");
+	  error ("cannot mix operands of decimal floating and vector types");
 	  return error_mark_node;
 	}
   if (code1 == COMPLEX_TYPE || code2 == COMPLEX_TYPE)
 	{
-	  error ("can%'t mix operands of decimal float and complex types");
+	  error ("cannot mix operands of decimal floating and complex types");
 	  return error_mark_node;
 	}
   if (code1 == REAL_TYPE && code2 == REAL_TYPE)
 	{
-	  error ("can%'t mix operands of decimal float and other float types");
+	  error ("cannot mix operands of decimal floating "
+		 "and other floating types");
 	  return error_mark_node;
 	}
 }
@@ -5253,13 +5254,13 @@ build_conditional_expr (location_t colon_loc, tree ifexp, bool ifexp_bcp,
 			/* OK */;
 		  else if (unsigned_op2)
 			warning_at (op1_loc, OPT_Wsign_compare,
-"operand of ?: changes signedness from "
+"operand of % changes signedness from "
 "%qT to %qT due to unsignedness of other "
 "operand", TREE_TYPE (orig_op1),
 TREE_TYPE (orig_op2));
 		  else
 			warning_at (op2_loc, 

[PATCH 3/12] fix diagnostic quoting/spelling in Brig

2019-05-14 Thread Martin Sebor

The attached patch fixes quoting, spelling, and other formatting
issues in diagnostics issued by the Brig front end and pointed
out by the -Wformat-diag warning.

Martin
gcc/brig/ChangeLog:

	* brigfrontend/brig-control-handler.cc
	(brig_directive_control_handler::operator): Remove trailing newline
	from a diagnostic.
	* brigfrontend/brig-module-handler.cc
	(brig_directive_module_handler::operator): Remove a duplicated space
	from a diagnostic.

diff --git a/gcc/brig/brigfrontend/brig-control-handler.cc b/gcc/brig/brigfrontend/brig-control-handler.cc
index 38039315c7c..4374c469a39 100644
--- a/gcc/brig/brigfrontend/brig-control-handler.cc
+++ b/gcc/brig/brigfrontend/brig-control-handler.cc
@@ -102,7 +102,7 @@ brig_directive_control_handler::operator () (const BrigBase *base)
   /* Unimplemented.  */
   break;
 default:
-  sorry ("Unsupported control directive %x.\n", inst->control);
+  sorry ("Unsupported control directive %x.", inst->control);
 }
   return base->byteCount;
 }
diff --git a/gcc/brig/brigfrontend/brig-module-handler.cc b/gcc/brig/brigfrontend/brig-module-handler.cc
index 58a65d65574..e1551b93812 100644
--- a/gcc/brig/brigfrontend/brig-module-handler.cc
+++ b/gcc/brig/brigfrontend/brig-module-handler.cc
@@ -28,10 +28,10 @@ brig_directive_module_handler::operator () (const BrigBase *base)
   const BrigDirectiveModule* mod = (const BrigDirectiveModule*)base;
   m_parent.m_module_name = m_parent.get_string (mod->name).substr (1);
   if (mod->hsailMajor != 1 || mod->hsailMinor != 0)
-fatal_error (UNKNOWN_LOCATION, PHSA_ERROR_PREFIX_INCOMPATIBLE_MODULE " "
+fatal_error (UNKNOWN_LOCATION, PHSA_ERROR_PREFIX_INCOMPATIBLE_MODULE
 		 "HSAIL version not supported. HSAIL 1.0 required.");
   if (mod->machineModel != BRIG_MACHINE_LARGE)
-fatal_error (UNKNOWN_LOCATION, PHSA_ERROR_PREFIX_INCOMPATIBLE_MODULE " "
+fatal_error (UNKNOWN_LOCATION, PHSA_ERROR_PREFIX_INCOMPATIBLE_MODULE
 		 "Only HSA 'large' machine model supported.");
   /* Do not check for the profile as the runtime conformance suite tests
  with 'full' profile BRIGs even though they don't use any full profile


[PATCH 1/12] implement -Wformat-diag to detect quoting and spelling issues in GCC diagnostics

2019-05-14 Thread Martin Sebor

The attached patch implements the -Wformat-diag warning to help find
quoting, spelling, and other formatting issues in diagnostics issued
by GCC.

Martin
gcc/c-family/ChangeLog:

	* c-common.h (GCC_DIAG_STYLE): Adjust.
	 (GCC_DIAG_RAW_STYLE): New macro.
	c-format.c (function_format_info::format_type): Adjust type.
	(function_format_info::is_raw): New member.
	(decode_format_type): Adjust signature.  Handle "raw" diag attributes.
	(decode_format_attr): Adjust call to decode_format_type.
	Avoid a redundant call to convert_format_name_to_system_name.
	Avoid abbreviating the word "arguments" in a diagnostic.
	(format_warning_substr): New function.
	(avoid_dollar_number): Quote dollar sign in a diagnostic.
	(finish_dollar_format_checking): Same.
	(check_format_info): Same.
	(struct baltoks_t): New.
	(maybe_diag_unbalanced_tokens, check_tokens, check_plain): New
	functions.
	(check_format_info_main): Call check_plain.  Use baltoks_t.  Call
	maybe_diag_unbalanced_tokens.
	(handle_format_attribute): Spell out the word "arguments" in
	a diagnostic.
	* c.opt (-Wformat-diag): New option.

gcc/testsuite/ChangeLog:

	* gcc.dg/format/gcc_diag-11.c: New test.

diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h
index 1cf2cae6395..9d067028416 100644
--- a/gcc/c-family/c-common.h
+++ b/gcc/c-family/c-common.h
@@ -39,7 +39,10 @@ framework extensions, you must include this file before diagnostic-core.h \
 never after.
 #endif
 #ifndef GCC_DIAG_STYLE
-#define GCC_DIAG_STYLE __gcc_cdiag__
+#  define GCC_DIAG_STYLE   __gcc_cdiag__
+#endif
+#ifndef GCC_DIAG_RAW_STYLE
+#  define GCC_DIAG_RAW_STYLE   __gcc_cdiag_raw__
 #endif
 #include "diagnostic-core.h"
 
diff --git a/gcc/c-family/c-format.c b/gcc/c-family/c-format.c
index a7f76c1c01d..372ab124661 100644
--- a/gcc/c-family/c-format.c
+++ b/gcc/c-family/c-format.c
@@ -52,7 +52,13 @@ enum format_type { printf_format_type, asm_fprintf_format_type,
 
 struct function_format_info
 {
-  int format_type;			/* type of format (printf, scanf, etc.) */
+  enum format_type format_type;		/* type of format (printf, scanf, etc.) */
+  /* IS_RAW is relevant only for GCC diagnostic format functions.
+ It is set for "raw" formatting functions like pp_printf that
+ are not intended to produce complete diagnostics according to
+ GCC guidelines, and clear for others like error and warning
+ whose format string is checked for proper quoting and spelling.  */
+  bool is_raw;
   unsigned HOST_WIDE_INT format_num;	/* number of format argument */
   unsigned HOST_WIDE_INT first_arg_num;	/* number of first arg (zero for varargs) */
 };
@@ -65,7 +71,7 @@ static GTY(()) tree locus;
 
 static bool decode_format_attr (const_tree, tree, tree, function_format_info *,
 bool);
-static int decode_format_type (const char *);
+static format_type decode_format_type (const char *, bool * = NULL);
 
 static bool check_format_string (const_tree argument,
  unsigned HOST_WIDE_INT format_num,
@@ -111,6 +117,32 @@ format_warning_at_char (location_t fmt_string_loc, tree format_string_cst,
   return warned;
 }
 
+
+/* Emit a warning as per format_warning_va, but construct the substring_loc
+   for the substring at offset (POS1, POS2 - 1) within a string constant
+   FORMAT_STRING_CST at FMT_STRING_LOC.  */
+
+ATTRIBUTE_GCC_DIAG (6,7)
+static bool
+format_warning_substr (location_t fmt_string_loc, tree format_string_cst,
+		   int pos1, int pos2, int opt, const char *gmsgid, ...)
+{
+  va_list ap;
+  va_start (ap, gmsgid);
+  tree string_type = TREE_TYPE (format_string_cst);
+
+  pos2 -= 1;
+
+  substring_loc fmt_loc (fmt_string_loc, string_type, pos1, pos1, pos2);
+  format_string_diagnostic_t diag (fmt_loc, NULL, UNKNOWN_LOCATION, NULL,
+   NULL);
+  bool warned = diag.emit_warning_va (opt, gmsgid, );
+  va_end (ap);
+
+  return warned;
+}
+
+
 /* Check that we have a pointer to a string suitable for use as a format.
The default is to check for a char type.
For objective-c dialects, this is extended to include references to string
@@ -320,10 +352,8 @@ decode_format_attr (const_tree fntype, tree atname, tree args,
 {
   const char *p = IDENTIFIER_POINTER (format_type_id);
 
-  p = convert_format_name_to_system_name (p);
+  info->format_type = decode_format_type (p, >is_raw);
 
-  info->format_type = decode_format_type (p);
-  
   if (!c_dialect_objc ()
 	   && info->format_type == gcc_objc_string_format_type)
 	{
@@ -359,7 +389,7 @@ decode_format_attr (const_tree fntype, tree atname, tree args,
   if (info->first_arg_num != 0 && info->first_arg_num <= info->format_num)
 {
   gcc_assert (!validated_p);
-  error ("format string argument follows the args to be formatted");
+  error ("format string argument follows the arguments to be formatted");
   return false;
 }
 
@@ -1067,27 +1097,55 @@ static void format_type_warning (const substring_loc _loc,
  char conversion_char);
 
 /* Decode a format type from a string, 

[PATCH 2/12] fix diagnostic quoting/spelling in ada

2019-05-14 Thread Martin Sebor

The attached patch fixes quoting, spelling, and other formatting
issues in diagnostics issued by the Ada front and pointed out by
the -Wformat-diag warning.

Martin
gcc/ada/ChangeLog:

	* gcc-interface/trans.c (check_inlining_for_nested_subprog): Quote
	reserved names.

diff --git a/gcc/ada/gcc-interface/trans.c b/gcc/ada/gcc-interface/trans.c
index 155cb4b27ab..932a54ca111 100644
--- a/gcc/ada/gcc-interface/trans.c
+++ b/gcc/ada/gcc-interface/trans.c
@@ -2024,12 +2024,13 @@ check_inlining_for_nested_subprog (tree fndecl)
 
   if (lookup_attribute ("always_inline", DECL_ATTRIBUTES (parent_decl)))
 	{
-	  error_at (loc1, "subprogram %q+F not marked Inline_Always", fndecl);
+	  error_at (loc1, "subprogram %q+F not marked %",
+		fndecl);
 	  error_at (loc2, "parent subprogram cannot be inlined");
 	}
   else
 	{
-	  warning_at (loc1, OPT_Winline, "subprogram %q+F not marked Inline",
+	  warning_at (loc1, OPT_Winline, "subprogram %q+F not marked %",
 		  fndecl);
 	  warning_at (loc2, OPT_Winline, "parent subprogram cannot be inlined");
 	}


Re: [C++ Patch] Consistently use OVL_P

2019-05-14 Thread Marek Polacek
On Tue, May 14, 2019 at 11:20:16PM +0200, Paolo Carlini wrote:
> Hi again,
> 
> On 14/05/19 21:21, Paolo Carlini wrote:
> > Hi,
> > 
> > On 14/05/19 21:05, Marek Polacek wrote:
> > > On Tue, May 14, 2019 at 03:01:35PM -0400, Nathan Sidwell wrote:
> > > > On 5/14/19 11:28 AM, Paolo Carlini wrote:
> > > > 
> > > > > another straightforward one sitting in my tree... Sanity checked on
> > > > > x86_64-linux.
> > > > I suspect many/all of the TREE_CODE (x) == TEMPLATE_DECL
> > > > (or DECL_FUNCTION_TEMPLATE_P) could also be elided -- we don't
> > > > have naked
> > > > function templates at that point, they're always wrapped in overloads.
> > > > Could you see if that's true?
> > > That's what I pointed out here
> > > 
> > > but I thought it might be better to do it as a follow-up.
> > 
> > Yeah, on the other hand, we can as well sort out this now: after all, I
> > like to spend time on this kind of work also in the hope that little
> > buglets or issues will then become more evident. Thus, I'm removing all
> > those checks for TEMPLATE_DECL and DECL_FUNCTION_TEMPLATE_P, let's see
> > what regression testing tells us. To be clear: I'm leaving
> > TEMPLATE_ID_EXPR (two of those) alone.
> 
> ... so the below passes testing on x86_64-linux. In fact, I think we are on
> a pretty safe ground, now at the beginning of Stage 1: if, over the next
> months we get a testcase which causes one of the 4 tightened gcc_assert to
> trip we'll comfortably deal with it.

Nice!

Just nits:

> Index: call.c
> ===
> --- call.c(revision 271166)
> +++ call.c(working copy)
> @@ -4383,9 +4383,7 @@ perform_overload_resolution (tree fn,
>*any_viable_p = true;
>  
>/* Check FN.  */
> -  gcc_assert (TREE_CODE (fn) == FUNCTION_DECL
> -   || TREE_CODE (fn) == TEMPLATE_DECL
> -   || TREE_CODE (fn) == OVERLOAD
> +  gcc_assert (OVL_P (fn)
> || TREE_CODE (fn) == TEMPLATE_ID_EXPR);

This can now fit on one line.

> Index: parser.c
> ===
> --- parser.c  (revision 271166)
> +++ parser.c  (working copy)
> @@ -16479,10 +16479,8 @@ cp_parser_template_id (cp_parser *parser,
>  {
>/* If it's not a class-template or a template-template, it should be
>a function-template.  */
> -  gcc_assert ((DECL_FUNCTION_TEMPLATE_P (templ)
> -|| TREE_CODE (templ) == OVERLOAD
> -|| TREE_CODE (templ) == FUNCTION_DECL
> -|| BASELINK_P (templ)));
> +  gcc_assert (OVL_P (templ)
> +   || BASELINK_P (templ));
  
Likewise.

> Index: search.c
> ===
> --- search.c  (revision 271166)
> +++ search.c  (working copy)
> @@ -1058,10 +1058,8 @@ build_baselink (tree binfo, tree access_binfo, tre
>  {
>tree baselink;
>  
> -  gcc_assert (TREE_CODE (functions) == FUNCTION_DECL
> -   || TREE_CODE (functions) == TEMPLATE_DECL
> -   || TREE_CODE (functions) == TEMPLATE_ID_EXPR
> -   || TREE_CODE (functions) == OVERLOAD);
> +  gcc_assert (OVL_P (functions)
> +   || TREE_CODE (functions) == TEMPLATE_ID_EXPR);

Likewise.

Marek


Re: [C++ Patch] Consistently use OVL_P

2019-05-14 Thread Paolo Carlini

Hi again,

On 14/05/19 21:21, Paolo Carlini wrote:

Hi,

On 14/05/19 21:05, Marek Polacek wrote:

On Tue, May 14, 2019 at 03:01:35PM -0400, Nathan Sidwell wrote:

On 5/14/19 11:28 AM, Paolo Carlini wrote:


another straightforward one sitting in my tree... Sanity checked on
x86_64-linux.

I suspect many/all of the TREE_CODE (x) == TEMPLATE_DECL
(or DECL_FUNCTION_TEMPLATE_P) could also be elided -- we don't have 
naked

function templates at that point, they're always wrapped in overloads.
Could you see if that's true?

That's what I pointed out here

but I thought it might be better to do it as a follow-up.


Yeah, on the other hand, we can as well sort out this now: after all, 
I like to spend time on this kind of work also in the hope that little 
buglets or issues will then become more evident. Thus, I'm removing 
all those checks for TEMPLATE_DECL and DECL_FUNCTION_TEMPLATE_P, let's 
see what regression testing tells us. To be clear: I'm leaving 
TEMPLATE_ID_EXPR (two of those) alone.


... so the below passes testing on x86_64-linux. In fact, I think we are 
on a pretty safe ground, now at the beginning of Stage 1: if, over the 
next months we get a testcase which causes one of the 4 tightened 
gcc_assert to trip we'll comfortably deal with it.


Thanks, Paolo.


Index: call.c
===
--- call.c  (revision 271166)
+++ call.c  (working copy)
@@ -4383,9 +4383,7 @@ perform_overload_resolution (tree fn,
   *any_viable_p = true;
 
   /* Check FN.  */
-  gcc_assert (TREE_CODE (fn) == FUNCTION_DECL
- || TREE_CODE (fn) == TEMPLATE_DECL
- || TREE_CODE (fn) == OVERLOAD
+  gcc_assert (OVL_P (fn)
  || TREE_CODE (fn) == TEMPLATE_ID_EXPR);
 
   if (TREE_CODE (fn) == TEMPLATE_ID_EXPR)
@@ -9605,9 +9603,7 @@ build_new_method_call_1 (tree instance, tree fns,
   fns = TREE_OPERAND (fns, 0);
   template_only = 1;
 }
-  gcc_assert (TREE_CODE (fns) == FUNCTION_DECL
- || TREE_CODE (fns) == TEMPLATE_DECL
- || TREE_CODE (fns) == OVERLOAD);
+  gcc_assert (OVL_P (fns));
   fn = OVL_FIRST (fns);
   name = DECL_NAME (fn);
 
Index: decl.c
===
--- decl.c  (revision 271166)
+++ decl.c  (working copy)
@@ -8918,9 +8918,7 @@ grokfndecl (tree ctype,
 the information in the TEMPLATE_ID_EXPR.  */
  SET_DECL_IMPLICIT_INSTANTIATION (decl);
 
- gcc_assert (identifier_p (fns)
- || TREE_CODE (fns) == OVERLOAD
- || TREE_CODE (fns) == FUNCTION_DECL);
+ gcc_assert (identifier_p (fns) || OVL_P (fns));
  DECL_TEMPLATE_INFO (decl) = build_template_info (fns, args);
 
  for (t = TYPE_ARG_TYPES (TREE_TYPE (decl)); t; t = TREE_CHAIN (t))
Index: mangle.c
===
--- mangle.c(revision 271166)
+++ mangle.c(working copy)
@@ -3278,8 +3278,7 @@ write_expression (tree expr)
 
/* Mangle a dependent name as the name, not whatever happens to
   be the first function in the overload set.  */
-   if ((TREE_CODE (fn) == FUNCTION_DECL
-|| TREE_CODE (fn) == OVERLOAD)
+   if (OVL_P (fn)
&& type_dependent_expression_p_push (expr))
  fn = OVL_NAME (fn);
 
Index: parser.c
===
--- parser.c(revision 271166)
+++ parser.c(working copy)
@@ -16479,10 +16479,8 @@ cp_parser_template_id (cp_parser *parser,
 {
   /* If it's not a class-template or a template-template, it should be
 a function-template.  */
-  gcc_assert ((DECL_FUNCTION_TEMPLATE_P (templ)
-  || TREE_CODE (templ) == OVERLOAD
-  || TREE_CODE (templ) == FUNCTION_DECL
-  || BASELINK_P (templ)));
+  gcc_assert (OVL_P (templ)
+ || BASELINK_P (templ));
 
   template_id = lookup_template_function (templ, arguments);
   if (TREE_CODE (template_id) == TEMPLATE_ID_EXPR)
Index: pt.c
===
--- pt.c(revision 271166)
+++ pt.c(working copy)
@@ -21193,8 +21193,7 @@ resolve_overloaded_unification (tree tparms,
   if (good != 1)
good = ok;
 }
-  else if (TREE_CODE (arg) != OVERLOAD
-  && TREE_CODE (arg) != FUNCTION_DECL)
+  else if (!OVL_P (arg))
 /* If ARG is, for example, "(0, )" then its type will be unknown
-- but the deduction does not succeed because the expression is
not just the function on its own.  */
@@ -25950,8 +25949,7 @@ type_dependent_expression_p (tree expression)
return true;
}
 
-  gcc_assert (TREE_CODE (expression) == OVERLOAD
- || TREE_CODE (expression) == 

[PATCH 0/12] detect quoting and punctuation problems in diagnostics

2019-05-14 Thread Martin Sebor

Near the end of every release a bunch of problem reports are
raised for various punctuation, quoting, and spelling issues
in GCC.  In GCC 9 a total 28 such issues were submitted.
A fair number of them are discovered as new or changed
diagnostics are being translated.  A checker was developed
to help find some of these as well many others by scanning
the gcc.pot file: contrib/check-internal-format-escaping.py.
The checker automates the process of finding these issues but
it doesn't prevent them.  Being external to GCC the checker
cannot easily distinguish between message strings that are
expected to be translated and those that aren't.

To help avoid introducing the most glaring subset of these
problems as early as possible while making it possible to
differentiate messages that are expected to conform from those
that need not, the attached patch adds a simple checker to GCC:
-Wformat-diag.  My goal is to improve consistency of messages
and relieve the burden at the end of each release both on
translators and those who then have to fix the problems.

The warning detects some of the following:

 *  unquoted operators consisting of two or more characters
(e.g., == or ?:)
 *  unquoted keywords, types, GCC built-ins and command line
options, or identifiers with underscores
 *  unquoted apostrophes and contractions like in can't
 *  informal abbreviations (arg or reg)
 *  unbalanced paired tokens (brackets, parentheses, or quotes)
 *  duplicate or trailing spaces (it allows multiple spaces at
the beginning of a diagnostic since that's used by the C++
front-end as an "indentation")
 *  unintended control characters
 *  inconsistent sentence capitalization

To avoid diagnosing direct calls to pretty-printer functions
that often format parts of the same diagnostic in multiple steps,
the solution introduces the "_raw__" suffix to the __gcc_diag__
attributes that the warning then uses to avoid checking those
calls.  Functions with the raw attributes aren't checked.

I tested the patch kit as a whole in an x86_64-linux build and
fixed all the issues it pointed out except for 43 instances of
the new warning in the Go front-end that I wasn't sure how best
to handle (I will follow up on that with Ian).  I also adjusted
the affected tests.

There were just a few issues specific to the i386 back-end but they
had an impact on 9 tests.  The impact of fixing the same kinds of
issues in other back-ends is likely to be similar.  Rather than
trying to do the clean up across all supported targets I think it's
better to handle the rest of the issues over time and with the help
of back end maintainers who can more easily verify that tests still
pass.  With than in mind, I have prevented the warning from causing
bootstrap failures. Once the cleanup is complete I expect to remove
this and include the new warning in -Werror.

Since a few files in GCC "misuse" the diagnostic machinery for
debugging output leading up to internal errors (instead of
calling a pp_xxx function) I suppressed the new warning in those
files via #pragma GCC diagnostic ignored "-Wformat-diag".  If we
agree that calling pp_format or some such is the way to go I can
work replacing those calls as a subsequent step.

The subset should cover the following bug reports (some already
resolved):

90176 - diagnostics should generally contain underscore only
inside quotes
90162 - exclamation mark in diagnostic!
90158 - aarch64: wrong quotation in diagnostics
90157 - aarch64: unnecessary abbreviation in diagnostic
90156 - add linter check suggesting to replace %<%s%> with %qs
90149 - diagnostics containing BIT_FIELD_REF don't conform to
diagnostics guideline
90121 - extra space in error message
90117 - Replace %<%s%> with %qs
90011 - [9 Regression] trailing space in diagnostic
79477 - Please write code more translator-friendly (unquoted options)
89936 - wrong punctuation in tree-profile.c (%<%s%>)

Although the changes are mechanical, since I made them all by hand
I broke up the patch into a series to make it easier to review:

[PATCH 1/12] implement -Wformat-diag to detect quoting and spelling
 issues in GCC diagnostics
[PATCH 2/12] fix diagnostic quoting/spelling in ada
[PATCH 3/12] fix diagnostic quoting/spelling in Brig
[PATCH 4/12] fix diagnostic quoting/spelling in the C front-end
[PATCH 5/12] fix diagnostic quoting/spelling in c-family
[PATCH 6/12] fix diagnostic quoting/spelling in C++
[PATCH 7/12] fix diagnostic quoting/spelling in libgcc
[PATCH 8/12] fix diagnostic quoting/spelling in the middle-end
[PATCH 9/12] adjust tests to quoting/spelling diagnostics fixes
[PATCH 10/12] fix diagnostic quoting/spelling in D
[PATCH 11/12] fix diagnostic quoting/spelling issues in i386 back-end
[PATCH 12/12] fix diagnostic quoting/spelling issues in ObjC

Martin


Re: [PATCH v2 2/3] Add predict_doloop_p target hook

2019-05-14 Thread Jeff Law
On 5/14/19 1:35 PM, Bill Schmidt wrote:
> On 5/14/19 2:13 PM, Jeff Law wrote:
>> On 5/13/19 9:09 PM, li...@linux.ibm.com wrote:
>>> From: Kewen Lin 
>>>
>>> Previous version link for background:
>>> https://gcc.gnu.org/ml/gcc-patches/2019-04/msg00912.html
>>>
>>> This hook is to predict whether one loop in gimple will
>>> be transformed to low-overhead loop later in RTL, and
>>> designed to be called in ivopts.
>>>
>>> "Since the low-overhead loop optimize transformation is
>>> based on RTL, some of those checks are hard to be imitated
>>> on gimple, so it's not possible to predict the current
>>> loop will be transformed exactly in middle-end.  But if we
>>> can have most loop predicted precisely, it would be helpful.
>>> It highly depends on target hook fine tuning. It's
>>> acceptable to have some loops which can be transformed to
>>> low-overhead loop but we don't catch.  But we should try
>>> our best to avoid to predict some loop as low-overhead loop
>>> but which isn't."
>>>
>>> Bootstrapped and regression testing passed on powerpc64le.
>>>
>>> Is it ok for trunk?
>>>
>>> gcc/ChangeLog
>>>
>>> 2019-05-13  Kewen Lin  
>>>
>>> PR middle-end/80791
>>> * target.def (predict_doloop_p): New hook.
>>> * targhooks.h (default_predict_doloop_p): New declaration.
>>> * targhooks.c (default_predict_doloop_p): New function.
>>> * doc/tm.texi.in (TARGET_PREDICT_DOLOOP_P): New hook.
>>> * doc/tm.texi: Regenerate.
>>> * config/rs6000/rs6000.c (invalid_insn_for_doloop_p): New function.
>>> (costly_iter_for_doloop_p): Likewise.
>>> (rs6000_predict_doloop_p): Likewise.
>>> (TARGET_PREDICT_DOLOOP_P): New macro.
>> Trying to guess what the target is going to do, then changing the
>> structure of the loops in gimple based on that guess -- is that really a
>> good idea.  It's fairly counter to many of the design goals around gimple.
> 
> Understood -- but incorrect selection of ivars has a heavily detrimental 
> effect.
> We have run into this problem many times on Power, where the cost model 
> wrongly
> takes into effect the cost of the compare that will be absorbed into the bdnz
> instruction.  Hot loops can end up 15-20% worse.  I don't see any reasonable
> alternative to a target hook with the present IVOPTS cost model.
I won't claim to know what the solution is here -- IVOPTS is certainly a
pain point and not just with low overhead looping constructs.

Of course we had similar problems when we did this on RTL even with
access to the low level costing information -- often the right choice
would depends on some factor external to the current loop.

In a perfect world we'd probably keep the current stuff as-is, then
lower a bit to expose addressing modes and some other target
dependencies in a lowered gimple.  But we're certainly not there.




jeff


Re: [Contrib PATCH] Add scripts to convert GCC repo from SVN to Git

2019-05-14 Thread Segher Boessenkool
On Tue, May 14, 2019 at 07:11:18PM +0300, Maxim Kuvyrkov wrote:
> This patch adds scripts to contrib/ to migrate full history of GCC's
> subversion repository to git.  My hope is that these scripts will
> finally allow GCC project to migrate to Git.

Thank you for doing this.

> The result of the conversion is at
> https://github.com/maxim-kuvyrkov/gcc/branches/all .  Branches with
> "@rev" suffixes represent branch points.  The conversion is still
> running, so not all branches may appear right away.

What exactly is a branch point here?  Why is it useful to have tags
at branch points?  Why did you make branches instead of tags?


Only very lightly tested so far, but it looks promising.


Segher


C++ PATCH to add test for c++/68918

2019-05-14 Thread Marek Polacek
We used to print errors, but since r236221 this compiles fine.  clang++ also
compiles it without errors.

Tested on x86_64-linux, applying to trunk.

2019-05-14  Marek Polacek  

PR c++/68918
* g++.dg/cpp0x/decltype71.C: New test.

diff --git gcc/testsuite/g++.dg/cpp0x/decltype71.C 
gcc/testsuite/g++.dg/cpp0x/decltype71.C
new file mode 100644
index 000..24c3abfba49
--- /dev/null
+++ gcc/testsuite/g++.dg/cpp0x/decltype71.C
@@ -0,0 +1,25 @@
+// PR c++/68918
+// { dg-do compile { target c++11 } }
+
+struct foo {
+static void a() {}
+
+auto b() const -> decltype( this->a() )
+{}
+
+template
+auto c() -> decltype( this->a() )
+{}
+
+template
+auto d() const -> decltype( a() )
+{}
+
+template
+auto e() const -> decltype( this->a() )
+{}
+};
+
+int main()
+{
+}


C++ PATCH to add test for c++/70156

2019-05-14 Thread Marek Polacek
This got fixed by r254461.

Tested on x86_64-linux, applying to trunk.

2019-05-14  Marek Polacek  

PR c++/70156
* g++.dg/init/static5.C: New test.

diff --git gcc/testsuite/g++.dg/init/static5.C 
gcc/testsuite/g++.dg/init/static5.C
new file mode 100644
index 000..4eaf787d0d4
--- /dev/null
+++ gcc/testsuite/g++.dg/init/static5.C
@@ -0,0 +1,9 @@
+// PR c++/70156
+// { dg-do compile { target c++11 } }
+
+template  struct A { int i; };
+struct B { int i; };
+struct C {
+static const A<0> a = { 0 }; // { dg-error ".constexpr. needed for 
in-class initialization of static data member" }
+static const B b = { 1 }; // { dg-error ".constexpr. needed for in-class 
initialization of static data member" }
+};


[PATCH, Darwin] Fix more PR82920

2019-05-14 Thread Iain Sandoe
Darwin doesn't support mx32, and some tests were
failing because it was trying to do them.  When we
disable this it turns out that quite a few tests 
requiring mx32 support were not guarded.

Tested on x86_64-linux-gnu (m32/m64) and x86_64-darwin12

applied to mainline.
Iain

gcc/

2019-05-14  Iain Sandoe  

PR target/82920
* config/i386/darwin.h (CC1_SPEC): Report -mx32 as an error for
Darwin.

gcc/testsuite/

2019-05-14  Iain Sandoe  

PR target/82920
* gcc.target/i386/cet-sjlj-6b.c: Require effective target x32.
* gcc.target/i386/pr52146.c: Likewise.
* gcc.target/i386/pr52698.c: Likewise.
* gcc.target/i386/pr52857-1.c: Likewise.
* gcc.target/i386/pr52857-2.c: Likewise.
* gcc.target/i386/pr52876.c: Likewise.
* gcc.target/i386/pr53698.c: Likewise.
* gcc.target/i386/pr54157.c: Likewise.
* gcc.target/i386/pr55049-1.c: Likewise.
* gcc.target/i386/pr55093.c: Likewise.
* gcc.target/i386/pr55116-1.c: Likewise.


pr82920-mx32-fails.diff
Description: Binary data


[PATCH] improve linter for diagnostics

2019-05-14 Thread Roland Illig
The linter in contrib/ checks all messages that the GCC user may see
whether they conform roughly to the GCC Guidelines for Diagnostics.

* contrib/check-internal-format-escaping.py: improve output of
the linter by providing short rationales for the warnings;
detect space before punctuation; temporarily disable the most
frequent diagnostics, in order to first focus on the ones that
can be fixed more quickly
Index: contrib/check-internal-format-escaping.py
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===
--- contrib/check-internal-format-escaping.py   (revision 
c7bf741f801cfbdf56bf1ee11a74ca0abe1e8c16)
+++ contrib/check-internal-format-escaping.py   (date 1557864788799)
@@ -41,18 +41,19 @@
  diagnostic_id: str, diagnostic: str, include_msgid=True):
 """
 To suppress a warning for a particular message,
-add a line "#, gcclint:ignore:{diagnostic_id}" to the message.
+add a comment "# gcclint:ignore:{diagnostic_id}" to the message.
 """
 
-if f'gcclint:ignore:{diagnostic_id}' in msg.flags:
+marker = f'gcclint:ignore:{diagnostic_id}'
+if marker in msg.comment:
 return
 
-seen_warnings[diagnostic] += 1
+seen_warnings[diagnostic_id] += 1
 
 if include_msgid:
-print(f'{location(msg)}: {diagnostic} in {repr(msg.msgid)}')
+print(f'{location(msg)}: {diagnostic} in {msg.msgid!r} [{marker}]')
 else:
-print(f'{location(msg)}: {diagnostic}')
+print(f'{location(msg)}: {diagnostic} [{marker}]')
 
 
 def lint_gcc_internal_format(msg: polib.POEntry):
@@ -68,6 +69,9 @@
 before = msgid[:m.start(0)]
 return before.count("%<") == before.count("%>")
 
+def find_outside_quotes(regex: str, s: str):
+return filter(outside_quotes, re.finditer(regex, s))
+
 def lint_matching_placeholders():
 """
 Warns when literal values in placeholders are not exactly equal
@@ -89,36 +93,31 @@
 in_msgstr = re.findall('%<[^%]+%>', msg.msgstr)
 
 if set(in_msgid) != set(in_msgstr):
-warn(msg,
- 'placeholder-mismatch',
+warn(msg, 'placeholder-mismatch',
  f'placeholder mismatch: msgid has {in_msgid}, '
  f'msgstr has {in_msgstr}',
  include_msgid=False)
 
 def lint_option_outside_quotes():
-for match in re.finditer(r'\S+', msgid):
+for match in find_outside_quotes(r'\S+', msgid):
 part = match.group()
-if not outside_quotes(match):
-continue
 
-if part.startswith('-'):
-if len(part) >= 2 and part[1].isalpha():
-if part == '-INF':
-continue
-
-warn(msg,
- 'option-outside-quotes',
- 'command line option outside %')
+if len(part) >= 2 and part[0] == '-' \
+and part[1].isalpha() and part != '-INF':
+warn(msg, 'option-outside-quotes',
+ 'command line options '
+ 'should be enclosed in %')
 
 if part.startswith('__builtin_'):
-warn(msg,
- 'builtin-outside-quotes',
- 'builtin function outside %')
+warn(msg, 'builtin-outside-quotes',
+ 'names of builtin functions '
+ 'should be enclosed in %')
 
 def lint_plain_apostrophe():
-for match in re.finditer("[^%]'", msgid):
-if outside_quotes(match):
-warn(msg, 'apostrophe', 'apostrophe without leading %')
+if any(find_outside_quotes("[^%]'", msgid)):
+warn(msg, 'apostrophe',
+ 'apostrophes should be written as %\' '
+ 'to make them typographically correct')
 
 def lint_space_before_quote():
 """
@@ -129,26 +128,45 @@
 
 for match in re.finditer("(.?[a-zA-Z0-9])%<", msgid):
 if match.group(1) != '%s':
-warn(msg,
- 'no-space-before-quote',
- '%< directly following a letter or digit')
+warn(msg, 'space-before-quote',
+ 'a letter or digit should not be '
+ 'directly followed by a %<')
+
+def lint_space_before_punctuation():
+"""
+In written English, there is no space before a colon.
+In text enclosed in % it's ok though.
+"""
+
+for match in find_outside_quotes(" [.,:;?]", msgid):
+warn(msg, 'space-before-punctuation',
+ f'there should be no space before punctuation '
+ f'{match.group()!r}')
 
 def lint_underscore_outside_quotes():
 """
 An underscore outside of quotes is used in several 

Re: [PATCH] Add __gnu_test::NullablePointer utility to testsuite

2019-05-14 Thread Jonathan Wakely

On 14/05/19 19:09 +0200, Daniel Krügler wrote:

Am Di., 14. Mai 2019 um 13:20 Uhr schrieb Jonathan Wakely :


* testsuite/20_util/allocator_traits/members/allocate_hint_nonpod.cc:
Use operator-> to access raw pointer member.
* testsuite/23_containers/vector/59829.cc: Likewise.
* testsuite/23_containers/vector/bool/80893.cc: Likewise.
* testsuite/libstdc++-prettyprinters/cxx11.cc: Use NullablePointer.
* testsuite/util/testsuite_allocator.h (NullablePointer): New utility
for tests.
(PointerBase, PointerBase_void): Derive from NullablePointer and use
its constructors and equality operators. Change converting
constructors to use operator-> to access private member of the other
pointer type.
(PointerBase_void::operator->()): Add, for access to private member.
(operator-(PointerBase, PointerBase)): Change to hidden friend.
(operator==(PointerBase, PointerBase)): Remove.
(operator!=(PointerBase, PointerBase)): Remove.

There are probably more places in the testsuite that could use
NullablePointer as a minimally-conforming type that meets the
Cpp17NullablePointer requirements, instead of defining a new type each
time one is needed.

Tested powerpc64le-linux, committed to trunk.



In the primary template of NullablePointer we have:

explicit operator bool() const noexcept { return value == nullptr; }

This is incorrect according to the NullablePointer requirements, it needs to be:

explicit operator bool() const noexcept { return value != nullptr; }


Argh! I changed that to test something and then didn't change it back
before committing.

It looks like we need a testsuite for our testsuite utilities.

Fixed with this patch, tested ppc64le-linux and committed to trunk.

Thanks for the diligent checks!


commit 5c5b3801911e4b47dd496ce024840d390b72023b
Author: Jonathan Wakely 
Date:   Tue May 14 20:45:53 2019 +0100

Fix NullablePointer test utility

* testsuite/util/testsuite_allocator.h (NullablePointer::operator bool):
Fix return value.

diff --git a/libstdc++-v3/testsuite/util/testsuite_allocator.h b/libstdc++-v3/testsuite/util/testsuite_allocator.h
index ac7dc8ee2c4..d817ac4e838 100644
--- a/libstdc++-v3/testsuite/util/testsuite_allocator.h
+++ b/libstdc++-v3/testsuite/util/testsuite_allocator.h
@@ -600,7 +600,7 @@ namespace __gnu_test
   NullablePointer() = default;
   NullablePointer(std::nullptr_t) noexcept : value() { }
 
-  explicit operator bool() const noexcept { return value == nullptr; }
+  explicit operator bool() const noexcept { return value != nullptr; }
 
   friend inline bool
   operator==(NullablePointer lhs, NullablePointer rhs) noexcept


Re: [PATCH v2 2/3] Add predict_doloop_p target hook

2019-05-14 Thread Bill Schmidt
On 5/14/19 2:13 PM, Jeff Law wrote:
> On 5/13/19 9:09 PM, li...@linux.ibm.com wrote:
>> From: Kewen Lin 
>>
>> Previous version link for background:
>> https://gcc.gnu.org/ml/gcc-patches/2019-04/msg00912.html
>>
>> This hook is to predict whether one loop in gimple will
>> be transformed to low-overhead loop later in RTL, and
>> designed to be called in ivopts.
>>
>> "Since the low-overhead loop optimize transformation is
>> based on RTL, some of those checks are hard to be imitated
>> on gimple, so it's not possible to predict the current
>> loop will be transformed exactly in middle-end.  But if we
>> can have most loop predicted precisely, it would be helpful.
>> It highly depends on target hook fine tuning. It's
>> acceptable to have some loops which can be transformed to
>> low-overhead loop but we don't catch.  But we should try
>> our best to avoid to predict some loop as low-overhead loop
>> but which isn't."
>>
>> Bootstrapped and regression testing passed on powerpc64le.
>>
>> Is it ok for trunk?
>>
>> gcc/ChangeLog
>>
>> 2019-05-13  Kewen Lin  
>>
>>  PR middle-end/80791
>>  * target.def (predict_doloop_p): New hook.
>>  * targhooks.h (default_predict_doloop_p): New declaration.
>>  * targhooks.c (default_predict_doloop_p): New function.
>>  * doc/tm.texi.in (TARGET_PREDICT_DOLOOP_P): New hook.
>>  * doc/tm.texi: Regenerate.
>>  * config/rs6000/rs6000.c (invalid_insn_for_doloop_p): New function.
>>  (costly_iter_for_doloop_p): Likewise.
>>  (rs6000_predict_doloop_p): Likewise.
>>  (TARGET_PREDICT_DOLOOP_P): New macro.
> Trying to guess what the target is going to do, then changing the
> structure of the loops in gimple based on that guess -- is that really a
> good idea.  It's fairly counter to many of the design goals around gimple.

Understood -- but incorrect selection of ivars has a heavily detrimental effect.
We have run into this problem many times on Power, where the cost model wrongly
takes into effect the cost of the compare that will be absorbed into the bdnz
instruction.  Hot loops can end up 15-20% worse.  I don't see any reasonable
alternative to a target hook with the present IVOPTS cost model.

Thanks,
Bill

> jeff
>



Re: [C++ Patch] Consistently use OVL_P

2019-05-14 Thread Paolo Carlini

Hi,

On 14/05/19 21:05, Marek Polacek wrote:

On Tue, May 14, 2019 at 03:01:35PM -0400, Nathan Sidwell wrote:

On 5/14/19 11:28 AM, Paolo Carlini wrote:


another straightforward one sitting in my tree... Sanity checked on
x86_64-linux.

I suspect many/all of the TREE_CODE (x) == TEMPLATE_DECL
(or DECL_FUNCTION_TEMPLATE_P) could also be elided -- we don't have naked
function templates at that point, they're always wrapped in overloads.
Could you see if that's true?

That's what I pointed out here

but I thought it might be better to do it as a follow-up.


Yeah, on the other hand, we can as well sort out this now: after all, I 
like to spend time on this kind of work also in the hope that little 
buglets or issues will then become more evident. Thus, I'm removing all 
those checks for TEMPLATE_DECL and DECL_FUNCTION_TEMPLATE_P, let's see 
what regression testing tells us. To be clear: I'm leaving 
TEMPLATE_ID_EXPR (two of those) alone.


Paolo.



Re: [PATCH v2 2/3] Add predict_doloop_p target hook

2019-05-14 Thread Jeff Law
On 5/13/19 9:09 PM, li...@linux.ibm.com wrote:
> From: Kewen Lin 
> 
> Previous version link for background:
> https://gcc.gnu.org/ml/gcc-patches/2019-04/msg00912.html
> 
> This hook is to predict whether one loop in gimple will
> be transformed to low-overhead loop later in RTL, and
> designed to be called in ivopts.
> 
> "Since the low-overhead loop optimize transformation is
> based on RTL, some of those checks are hard to be imitated
> on gimple, so it's not possible to predict the current
> loop will be transformed exactly in middle-end.  But if we
> can have most loop predicted precisely, it would be helpful.
> It highly depends on target hook fine tuning. It's
> acceptable to have some loops which can be transformed to
> low-overhead loop but we don't catch.  But we should try
> our best to avoid to predict some loop as low-overhead loop
> but which isn't."
> 
> Bootstrapped and regression testing passed on powerpc64le.
> 
> Is it ok for trunk?
> 
> gcc/ChangeLog
> 
> 2019-05-13  Kewen Lin  
> 
>   PR middle-end/80791
>   * target.def (predict_doloop_p): New hook.
>   * targhooks.h (default_predict_doloop_p): New declaration.
>   * targhooks.c (default_predict_doloop_p): New function.
>   * doc/tm.texi.in (TARGET_PREDICT_DOLOOP_P): New hook.
>   * doc/tm.texi: Regenerate.
>   * config/rs6000/rs6000.c (invalid_insn_for_doloop_p): New function.
>   (costly_iter_for_doloop_p): Likewise.
>   (rs6000_predict_doloop_p): Likewise.
>   (TARGET_PREDICT_DOLOOP_P): New macro.
Trying to guess what the target is going to do, then changing the
structure of the loops in gimple based on that guess -- is that really a
good idea.  It's fairly counter to many of the design goals around gimple.

jeff


Re: [PATCH] Fix aarch64 exception handling (PR c++/59813)

2019-05-14 Thread Jeff Law
On 5/13/19 4:51 PM, Jakub Jelinek wrote:
> On Mon, May 13, 2019 at 04:29:21PM -0600, Jeff Law wrote:
>>> That is a serious misunderstanding of what __builtin_eh_return does.
>>> For the most part, __builtin_eh_return works by forcing all call clobbered
>>> registers to stack, having that described in the unwind info and having the
>>> unwinding code modify that saved info when needed.  The adjustment of the
>>> stack is done only on approx. half of the targets where the destination
>>> stack pointer should be derived from CFA instead of being restored with the
>>> rest of the call saved registers.  You can't do this in assembly, it needs
>>> to be done in the same function that saves the state etc.
>> So why not just reject tail calls when we see __builtin_eh_return.  It's
>> not ideal, but that feels better than the currently posted hack.
> 
> The problem as has been said in this thread is that crtl->calls_eh_return
> flag is only set during expansion, so if it is tested when deciding if we
> should allow the tail call or not, it might be (and in the case of
> _Unwind_Resume_or_Rethrow it is) too late, because we first expand the call
> that could be tail call and only afterwards expand the __builtin_eh_return
> and set crtl->calls_eh_return.
> 
> In https://gcc.gnu.org/ml/gcc-patches/2019-05/msg00484.html I've posted a
> patch that would set it earlier (or it could be set during gimplification
> and propagated during inlining, would need to be in cfun->calls_eh_return
> instead of crtl->calls_eh_return) and then targets for which we do not want
> to bother with it or where it is not beneficial to have tail calls in
> functions that call __builtin_eh_return (as I said in the thread, e.g. on
> x86_64-linux it is both smaller and faster), the targets which we expect to
> fail currently or even have a proof of that can just punt.
I would go with a patch that got the info set earlier and just punt in
the generic code.  I just don't see this case as terribly important to
optimize.

jeff


Re: [C++ Patch] Consistently use OVL_P

2019-05-14 Thread Marek Polacek
On Tue, May 14, 2019 at 03:01:35PM -0400, Nathan Sidwell wrote:
> On 5/14/19 11:28 AM, Paolo Carlini wrote:
> 
> > another straightforward one sitting in my tree... Sanity checked on
> > x86_64-linux.
> 
> I suspect many/all of the TREE_CODE (x) == TEMPLATE_DECL
> (or DECL_FUNCTION_TEMPLATE_P) could also be elided -- we don't have naked
> function templates at that point, they're always wrapped in overloads.
> Could you see if that's true?

That's what I pointed out here

but I thought it might be better to do it as a follow-up.

Marek


Re: [C++ Patch] Consistently use OVL_P

2019-05-14 Thread Nathan Sidwell

On 5/14/19 11:28 AM, Paolo Carlini wrote:

another straightforward one sitting in my tree... Sanity checked on 
x86_64-linux.


I suspect many/all of the TREE_CODE (x) == TEMPLATE_DECL
(or DECL_FUNCTION_TEMPLATE_P) could also be elided -- we don't have 
naked function templates at that point, they're always wrapped in 
overloads.  Could you see if that's true?


nathan

--
Nathan Sidwell


Re: [PATCH] GCC 8 Backports for AIX

2019-05-14 Thread Segher Boessenkool
On Tue, May 14, 2019 at 09:42:58AM -0400, David Edelsohn wrote:
> I would like to backport two AIX-specific patches to GCC 8.  These
> both fix bugs that generate wrong code on AIX.
> 
> 1) XCOFF private read only data section
> 
> 2) Follow AIX ABI to not pass FP structures in FPRs.
> 
> These patches have been on trunk / GCC 9 for months.
> 
> Bootstrapped gcc-8-branch on powerpc-ibm-aix7.2.0.0.
> 
> Is this okay?

Sure!  For GCC 7 too, if you want?


Segher


> * xcoffout.h (xcoff_private_rodata_section_name): Declare.
> * xcoffout.c (xcoff_private_rodata_section_name): Define.
> * config/rs6000/rs6000.c (rs6000_xcoff_asm_init_sections): Create
> read_only_private_data_section using 
> xcoff_private_rodata_section_name.
> (rs6000_xcoff_file_start): Generate xcoff_private_rodata_section_name.
> 
> PR target/61976
> * config/rs6000/rs6000.c (rs6000_function_arg): Don't pass aggregates
> in FPRs on AIX. Ensure type is non-NULL.
> (rs6000_arg_partial_bytes): Same.


[PATCH] gcc: move assemble_start_function / assemble_end_function to output_mi_thunk

2019-05-14 Thread Max Filippov
Let backends call assemble_start_function after they have generated
thunk function body so that a constant pool could be output if it is
required. This may help backends to avoid implementing custom constant
loading code specifically for the MI thunk and reuse existing
functionality.

gcc/
2019-01-08  Max Filippov  

* cgraphunit.c (cgraph_node::expand_thunk): Remove
assemble_start_function and assemble_end_function calls.
* config/alpha/alpha.c (alpha_output_mi_thunk_osf): Call
assemble_start_function and assemble_end_function.
* config/arc/arc.c (arc_output_mi_thunk): Likewise.
* config/arm/arm.c (arm_output_mi_thunk): Likewise.
* config/bfin/bfin.c (bfin_output_mi_thunk): Likewise.
* config/c6x/c6x.c (c6x_output_mi_thunk): Likewise.
* config/cris/cris.c (cris_asm_output_mi_thunk): Likewise.
* config/csky/csky.c (csky_output_mi_thunk): Likewise.
* config/epiphany/epiphany.c (epiphany_output_mi_thunk): Likewise.
* config/frv/frv.c (frv_asm_output_mi_thunk): Likewise.
* config/i386/i386.c (x86_output_mi_thunk): Likewise.
* config/ia64/ia64.c (ia64_output_mi_thunk): Likewise.
* config/m68k/m68k.c (m68k_output_mi_thunk): Likewise.
* config/microblaze/microblaze.c (microblaze_asm_output_mi_thunk):
Likewise.
* config/mips/mips.c (mips_output_mi_thunk): Likewise.
* config/mmix/mmix.c (mmix_asm_output_mi_thunk): Likewise.
* config/mn10300/mn10300.c (mn10300_asm_output_mi_thunk): Likewise.
* config/nds32/nds32.c (nds32_asm_output_mi_thunk): Likewise.
* config/nios2/nios2.c (nios2_asm_output_mi_thunk): Likewise.
* config/or1k/or1k.c (or1k_output_mi_thunk): Likewise.
* config/pa/pa.c (pa_asm_output_mi_thunk): Likewise.
* config/riscv/riscv.c (riscv_output_mi_thunk): Likewise.
* config/rs6000/rs6000.c (rs6000_output_mi_thunk): Likewise.
* config/s390/s390.c (s390_output_mi_thunk): Likewise.
* config/sh/sh.c (sh_output_mi_thunk): Likewise.
* config/sparc/sparc.c (sparc_output_mi_thunk): Likewise.
* config/spu/spu.c (spu_output_mi_thunk): Likewise.
* config/stormy16/stormy16.c (xstormy16_asm_output_mi_thunk):
Likewise.
* config/tilegx/tilegx.c (tilegx_output_mi_thunk): Likewise.
* config/tilepro/tilepro.c (tilepro_asm_output_mi_thunk): Likewise.
* config/vax/vax.c (vax_output_mi_thunk): Likewise.
---

Bootstrapped/regtested on x86_64-pc-linux-gnu, no new regressions.

Build tested for the following targets:
alpha-linux-gnu, arc-elf, arm-linux-gnueabi, bfin-elf, c6x-elf, cris-elf,
csky-elf, epiphany-elf, frv-elf, ia64-elf, m68k-elf, microblaze-elf,
mips-elf, mmix-knuth-mmixware, mn10300-elf, nds32-elf, nios2-elf,
or1k-elf, parisc-elf, riscv-elf, ppc-elf, s390-linux-gnu, sh-elf,
sparc-elf, spu-elf, xstormy16-elf, tilegx-linux-gnu, tilepro-linux-gnu,
vax-linux-gnu

OK for trunk?

 gcc/cgraphunit.c   | 4 
 gcc/config/alpha/alpha.c   | 3 +++
 gcc/config/arc/arc.c   | 4 
 gcc/config/arm/arm.c   | 4 
 gcc/config/bfin/bfin.c | 3 +++
 gcc/config/c6x/c6x.c   | 3 +++
 gcc/config/cris/cris.c | 4 
 gcc/config/csky/csky.c | 3 +++
 gcc/config/epiphany/epiphany.c | 3 +++
 gcc/config/frv/frv.c   | 4 
 gcc/config/i386/i386.c | 5 -
 gcc/config/ia64/ia64.c | 3 +++
 gcc/config/m68k/m68k.c | 3 +++
 gcc/config/microblaze/microblaze.c | 3 +++
 gcc/config/mips/mips.c | 3 +++
 gcc/config/mmix/mmix.c | 6 +-
 gcc/config/mn10300/mn10300.c   | 3 +++
 gcc/config/nds32/nds32.c   | 3 +++
 gcc/config/nios2/nios2.c   | 3 +++
 gcc/config/or1k/or1k.c | 5 -
 gcc/config/pa/pa.c | 3 +++
 gcc/config/riscv/riscv.c   | 3 +++
 gcc/config/rs6000/rs6000.c | 3 +++
 gcc/config/s390/s390.c | 3 +++
 gcc/config/sh/sh.c | 3 +++
 gcc/config/sparc/sparc.c   | 3 +++
 gcc/config/spu/spu.c   | 3 +++
 gcc/config/stormy16/stormy16.c | 3 +++
 gcc/config/tilegx/tilegx.c | 3 +++
 gcc/config/tilepro/tilepro.c   | 3 +++
 gcc/config/vax/vax.c   | 4 
 31 files changed, 99 insertions(+), 7 deletions(-)

diff --git a/gcc/cgraphunit.c b/gcc/cgraphunit.c
index 8bfbd0bb12f3..325cefad8366 100644
--- a/gcc/cgraphunit.c
+++ b/gcc/cgraphunit.c
@@ -1790,7 +1790,6 @@ cgraph_node::expand_thunk (bool output_asm_thunks, bool 
force_gimple_thunk)
   && targetm.asm_out.can_output_mi_thunk (thunk_fndecl, fixed_offset,
  virtual_value, alias))
 {
-  const char *fnname;
   tree fn_block;
   tree restype = TREE_TYPE (TREE_TYPE (thunk_fndecl));
 
@@ -1814,7 +1813,6 @@ cgraph_node::expand_thunk (bool output_asm_thunks, bool 

Re: [DRIVER PATCH]: Nadger subprocess argv[0]

2019-05-14 Thread Martin Sebor

On 5/14/19 8:02 AM, Nathan Sidwell wrote:
This patch nadgers the driver's subprocess names to include the driver 
name. It results in more informative error messages.  For instance, 
rather than:


   >./xg++ -B./ frob.cc -c -fdump-tree-nope
   cc1plus: error: unrecognized command line option '-fdump-tree-nope'

we get:

   >./xg++ -B./ frob.cc -c -fdump-tree-nope
   xg++(cc1plus): error: unrecognized command line option 
'-fdump-tree-nope'


Thereby cluing the user into this being a compiler error.  (When this 
error is buried inside a build log, the poor user can be more confused 
as to what this cc1plus thing might be).


I achieve this by taking advantage of the subprocess spawning taking 
separate arguments for the program to exec, and the argv[0] value passed 
to that program.  Because subprocesses can use argv[0] to locate 
themselves I propagate the directory name, so that remains as before.


When using valgrind, this substitution is not performed, because 
valgrind relies on argv[0] being the program pathname.


The -v output is unaffected, as that is emitted before altering argv[0]. 
  argv[0] is also restored after spawning.


This then allows us to elide process_command's check of whether the 
input file exists.  That's optimizing for failure, but I suspect is 
desired merely to avoid an error of the form:

   cc1plus: fatal error: frob.cc: No such file or directory

As you can see process_command does some special handling for lto & 
@files, which is kind of icky and now goes away.  We get:

   xg++(cc1plus): fatal error: frob.cc: No such file or directory

Thoughts? Ok? Stupid idea?


It sounds like a nice little improvement to me.

The question of what's cc1 and cc1plus sometimes comes up on
message boards indicating that users new to GCC find these
errors at first confusing.  A common one is about:

  gcc: error trying to exec ‘cc1plus’: execvp: No such file or directory”

This one prints gcc but what's cc1plus and what's execvp?  After
an incomplete install, newbie users go looking for cc1plus (and
sometimes apparently even for excecvp). Improving these messages
will make GCC easier for newbies to use.

Just a nit about the output above: is no space after the driver
name and before the parenthesis.  To my eyes that looks a little
odd.  I would expect see one.

Martin


[PATCH 1/2] rs6000: New enum epilogue_type

2019-05-14 Thread Segher Boessenkool
We currently call rs6000_emit_epilogue with a boolean parameter saying
if this is for a sibcall.  We also need to create epilogues for
eh_return.  This isn't yet indicated directly: instead, we get an
eh_return epilogue if crtl->calls_eh_return and this is not a sibcall.

This patch changes things so there is a three-way enum argument.

What is called "normal" now can still actually be "eh_return".  The
rs6000_emit_epilogue function still uses an "int sibcall" variable
internally.

Tested on powerpc*-linux; committing to trunk.


Segher


2019-05-14  Segher Boessenkool  

* config/rs6000/rs6000-protos.h (rs6000_emit_epilogue): Change
arguments.
* config/rs6000/rs6000.c (rs6000_emit_epilogue): Change arguments.
* config/rs6000/rs6000.md (epilogue_type): New define_enum.
(sibcall_epilogue): Adjust.
(epilogue): Adjust.

---
 gcc/config/rs6000/rs6000-protos.h | 2 +-
 gcc/config/rs6000/rs6000.c| 3 ++-
 gcc/config/rs6000/rs6000.md   | 6 --
 3 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/gcc/config/rs6000/rs6000-protos.h 
b/gcc/config/rs6000/rs6000-protos.h
index 8466368..9718ada 100644
--- a/gcc/config/rs6000/rs6000-protos.h
+++ b/gcc/config/rs6000/rs6000-protos.h
@@ -190,7 +190,7 @@ extern alias_set_type get_TOC_alias_set (void);
 extern void rs6000_emit_prologue (void);
 extern void rs6000_emit_load_toc_table (int);
 extern unsigned int rs6000_dbx_register_number (unsigned int, unsigned int);
-extern void rs6000_emit_epilogue (int);
+extern void rs6000_emit_epilogue (enum epilogue_type);
 extern void rs6000_expand_split_stack_prologue (void);
 extern void rs6000_split_stack_space_check (rtx, rtx);
 extern void rs6000_emit_eh_reg_restore (rtx, rtx);
diff --git a/gcc/config/rs6000/rs6000.c b/gcc/config/rs6000/rs6000.c
index b886f58..2992ba5 100644
--- a/gcc/config/rs6000/rs6000.c
+++ b/gcc/config/rs6000/rs6000.c
@@ -27874,8 +27874,9 @@ emit_cfa_restores (rtx cfa_restores)
 /* Emit function epilogue as insns.  */
 
 void
-rs6000_emit_epilogue (int sibcall)
+rs6000_emit_epilogue (enum epilogue_type epilogue_type)
 {
+  int sibcall = (epilogue_type == EPILOGUE_TYPE_SIBCALL);
   rs6000_stack_t *info;
   int restoring_GPRs_inline;
   int restoring_FPRs_inline;
diff --git a/gcc/config/rs6000/rs6000.md b/gcc/config/rs6000/rs6000.md
index 8da7aba..c3181e7 100644
--- a/gcc/config/rs6000/rs6000.md
+++ b/gcc/config/rs6000/rs6000.md
@@ -174,6 +174,8 @@ (define_c_enum "unspecv"
UNSPECV_SPEC_BARRIER ; Speculation barrier
   ])
 
+; The three different kinds of epilogue.
+(define_enum "epilogue_type" [normal sibcall eh_return])
 
 ;; Define an insn type attribute.  This is used in function unit delay
 ;; computations.
@@ -10941,7 +10943,7 @@ (define_expand "sibcall_epilogue"
 {
   if (!TARGET_SCHED_PROLOG)
 emit_insn (gen_blockage ());
-  rs6000_emit_epilogue (TRUE);
+  rs6000_emit_epilogue (EPILOGUE_TYPE_SIBCALL);
   DONE;
 })
 
@@ -12881,7 +12883,7 @@ (define_expand "epilogue"
 {
   if (!TARGET_SCHED_PROLOG)
 emit_insn (gen_blockage ());
-  rs6000_emit_epilogue (FALSE);
+  rs6000_emit_epilogue (EPILOGUE_TYPE_NORMAL);
   DONE;
 })
 
-- 
1.8.3.1



[PATCH 2/2] rs6000: Make eh_set_lr_ a define_insn_and_split

2019-05-14 Thread Segher Boessenkool
2019-05-14  Segher Boessenkool  

* config/rs6000/rs6000.md (eh_set_lr_): Merge with following
define_split to become a define_insn_and_split.

---
 gcc/config/rs6000/rs6000.md | 11 +++
 1 file changed, 3 insertions(+), 8 deletions(-)

diff --git a/gcc/config/rs6000/rs6000.md b/gcc/config/rs6000/rs6000.md
index c3181e7..31fc90a 100644
--- a/gcc/config/rs6000/rs6000.md
+++ b/gcc/config/rs6000/rs6000.md
@@ -13099,16 +13099,11 @@ (define_expand "eh_return"
 })
 
 ; We can't expand this before we know where the link register is stored.
-(define_insn "eh_set_lr_"
-  [(unspec_volatile [(match_operand:P 0 "register_operand" "r")]
-   UNSPECV_EH_RR)
+(define_insn_and_split "eh_set_lr_"
+  [(unspec_volatile [(match_operand:P 0 "register_operand" "r")] UNSPECV_EH_RR)
(clobber (match_scratch:P 1 "="))]
   ""
-  "#")
-
-(define_split
-  [(unspec_volatile [(match_operand 0 "register_operand")] UNSPECV_EH_RR)
-   (clobber (match_scratch 1))]
+  "#"
   "reload_completed"
   [(const_int 0)]
 {
-- 
1.8.3.1



Re: [C++ Patch] Consistently use OVL_P

2019-05-14 Thread Marek Polacek
On Tue, May 14, 2019 at 05:28:09PM +0200, Paolo Carlini wrote:
> Hi,
> 
> another straightforward one sitting in my tree... Sanity checked on
> x86_64-linux.
> 
> Thanks, Paolo.
> 
> ///
> 

> 2019-05-14  Paolo Carlini  
> 
>   * call.c (perform_overload_resolution, build_new_method_call_1):
>   Use OVL_P.
>   * decl.c (grokfndecl): Likewise.
>   * mangle.c (write_expression): Likewise.
>   * parser.c (cp_parser_template_id): Likewise.
>   * pt.c (resolve_overloaded_unification, type_dependent_expression_p):
>   Likewise. 
>   * search.c (build_baselink): Likewise.
>   * tree.c (is_overloaded_fn, dependent_name, maybe_get_fns): Likewise.

Looks fine.

OVL_P says "TEMPLATE_DECLS are always wrapped in an OVERLOAD, so we don't need
to check them", but I wouldn't mess with that in a cleanup patch like this.

Marek


Re: [PATCH] Add __gnu_test::NullablePointer utility to testsuite

2019-05-14 Thread Daniel Krügler
Am Di., 14. Mai 2019 um 13:20 Uhr schrieb Jonathan Wakely :
>
> * testsuite/20_util/allocator_traits/members/allocate_hint_nonpod.cc:
> Use operator-> to access raw pointer member.
> * testsuite/23_containers/vector/59829.cc: Likewise.
> * testsuite/23_containers/vector/bool/80893.cc: Likewise.
> * testsuite/libstdc++-prettyprinters/cxx11.cc: Use NullablePointer.
> * testsuite/util/testsuite_allocator.h (NullablePointer): New utility
> for tests.
> (PointerBase, PointerBase_void): Derive from NullablePointer and use
> its constructors and equality operators. Change converting
> constructors to use operator-> to access private member of the other
> pointer type.
> (PointerBase_void::operator->()): Add, for access to private member.
> (operator-(PointerBase, PointerBase)): Change to hidden friend.
> (operator==(PointerBase, PointerBase)): Remove.
> (operator!=(PointerBase, PointerBase)): Remove.
>
> There are probably more places in the testsuite that could use
> NullablePointer as a minimally-conforming type that meets the
> Cpp17NullablePointer requirements, instead of defining a new type each
> time one is needed.
>
> Tested powerpc64le-linux, committed to trunk.
>

In the primary template of NullablePointer we have:

explicit operator bool() const noexcept { return value == nullptr; }

This is incorrect according to the NullablePointer requirements, it needs to be:

explicit operator bool() const noexcept { return value != nullptr; }

- Daniel


Re: New .md construct: define_insn_and_rewrite

2019-05-14 Thread Eric Botcazou
> This patch therefore adds a new construct called define_insn_and_rewrite.
> It's basically a define_insn_and_split with an implicit split pattern,
> obtained by copying the insn pattern and replacing match_operands with
> match_dups and match_operators with match_op_dups.

Isn't that what define_subst does in a different context?

> Any comments?  Suggestions for better names?

define_insn_and_subst?

-- 
Eric Botcazou


[PATCH] Add __raw_visit and __raw_idx_visit, use INVOKE

2019-05-14 Thread Jonathan Wakely

This change simplifies visitation for variants, by using INVOKE for
the visit form, and explicitly specifying the tag types for raw
visitation, instead of inferring them from the return types of the
lambda functions used as visitors.

* include/std/variant (__visit_with_index): Remove typedef.
(__deduce_visit_result): New tag type.
(__raw_visit, __raw_idx_visit): New helper functions for "raw"
visitation of possibly-valueless variants, forwarding to __do_visit
with the relevant tag type.
(_Variant_storage::_M_reset_impl): Use __raw_visit
and make lambda return void.
(__variant_construct): Likewise.
(_Copy_assign_base::operator=, _Move_assign_base::operator=): Use
__raw_idx_visit and make lambda return void.
(_Multi_array::__untag_result): Add metafunction to check the function
pointer type for a tag type that dictates the kind of visitation.
(_Multi_array<_Ret(*)(_Visitor, _Variants...), __first, __rest...>):
Use decltype(auto) instead of tagged function pointer type.
(__gen_vtable_impl): Remove bool non-type parameter and unused
_Variant_tuple parameter.
(__gen_vtable_impl::__visit_invoke_impl): Remove.
(__gen_vtable_impl::__do_visit_invoke): Remove.
(__gen_vtable_impl::__do_visit_invoke_r): Remove.
(__gen_vtable_impl::__visit_invoke): Use if-constexpr and __invoke_r
for the visit case, rather than dispatching to separate functions.
(_VARIANT_RELATION_FUNCTION_TEMPLATE): Use __raw_idx_visit and make
lambda return void.
(variant::swap): Likewise.
(__do_visit): Replace two non-type template parameters with a single
type parameter, so that the caller must specify the visitor's return
type (or one of the tag types).
(visit): Deduce a return type from the visitor and use the
__deduce_visit_result tag to enforce that all overloads return the
same type.
(visit): Call __do_visit with explicit result type.
(__variant_hash_call_base_impl::operator()): Use __raw_visit and make
lambda return void.

Tested powerpc64le-linux, committed to trunk.

commit 5fcf0c52fa1352fcef16850f1695a9aa5fb6afa7
Author: Jonathan Wakely 
Date:   Tue Apr 9 20:09:31 2019 +0100

Add __raw_visit and __raw_idx_visit, use INVOKE

This change simplifies visitation for variants, by using INVOKE for
the visit form, and explicitly specifying the tag types for raw
visitation, instead of inferring them from the return types of the
lambda functions used as visitors.

* include/std/variant (__visit_with_index): Remove typedef.
(__deduce_visit_result): New tag type.
(__raw_visit, __raw_idx_visit): New helper functions for "raw"
visitation of possibly-valueless variants, forwarding to __do_visit
with the relevant tag type.
(_Variant_storage::_M_reset_impl): Use __raw_visit
and make lambda return void.
(__variant_construct): Likewise.
(_Copy_assign_base::operator=, _Move_assign_base::operator=): Use
__raw_idx_visit and make lambda return void.
(_Multi_array::__untag_result): Add metafunction to check the 
function
pointer type for a tag type that dictates the kind of visitation.
(_Multi_array<_Ret(*)(_Visitor, _Variants...), __first, __rest...>):
Use decltype(auto) instead of tagged function pointer type.
(__gen_vtable_impl): Remove bool non-type parameter and unused
_Variant_tuple parameter.
(__gen_vtable_impl::__visit_invoke_impl): Remove.
(__gen_vtable_impl::__do_visit_invoke): Remove.
(__gen_vtable_impl::__do_visit_invoke_r): Remove.
(__gen_vtable_impl::__visit_invoke): Use if-constexpr and __invoke_r
for the visit case, rather than dispatching to separate 
functions.
(_VARIANT_RELATION_FUNCTION_TEMPLATE): Use __raw_idx_visit and make
lambda return void.
(variant::swap): Likewise.
(__do_visit): Replace two non-type template parameters with a single
type parameter, so that the caller must specify the visitor's return
type (or one of the tag types).
(visit): Deduce a return type from the visitor and use the
__deduce_visit_result tag to enforce that all overloads return the
same type.
(visit): Call __do_visit with explicit result type.
(__variant_hash_call_base_impl::operator()): Use __raw_visit and 
make
lambda return void.

diff --git a/libstdc++-v3/include/std/variant b/libstdc++-v3/include/std/variant
index d539df125bf..dc4bbb7f356 100644
--- a/libstdc++-v3/include/std/variant
+++ b/libstdc++-v3/include/std/variant
@@ -138,9 +138,7 @@ namespace __variant
 constexpr 

[PATCH, lto-plugin] Make the plugin more -save-temps friendly.

2019-05-14 Thread Iain Sandoe
Currently the lto plugin has a somewhat obscure incantation to get it to save 
its temp files, and at least one is not named in any sensible way for 
development examination.

This patch makes it follow the same approach as collect2. 

-save-temps causes the temp file to be named meaningfully, and for the relevant 
input files to be saved in CWD.
-v, —version causes the save actions to be output to stderr.

——

one can get this to happen by just putting -save-temps, -v on the regular link 
line or (for compatibility with the way the -debug flag works, by appending 
-plugin-opt=-save-temps, etc.

(the latter change might be a bit OTT, I was in two minds about deleting that 
part, but …)

tested on x86_64-linux-gnu.

OK for trunk?
Iain

lto-plugin/

* lto-plugin.c (exec_lto_wrapper): Make the wrapper
arguments filename more user-friendly.
(file_exists, maybe_unlink): New.
(cleanup_handler): Use maybe unlink to handle the
case when temps should be saved.
(process_option): Look for -v, —version, -save-temps.
(onload): Record the linker output file name.
Check for  -v, —version, -save-temps in GCC collect
options environment.



lto-plugin-save-temps.diff
Description: Binary data


[PATCH, i386]: Macroize DIVMOD patterns

2019-05-14 Thread Uros Bizjak
Recent work by Richard Sandiford [1] enabled the possibility to
macroize DIVMOD patterns in i386.md.

2019-05-14  Uroš Bizjak  

* config/i386/i386.md (any_div): New code iterator.
(paired_mod): New code attribute.
(sgnprefix): Handle DIV and UDIV RTXes.
(u): Ditto.
(divmod4): Macroize expander from divmod4
and udivmod4 patterns using any_div code iterator.
(divmod splitters): Macroize splitters using any_div code iterator.
(*udivmodsi4_pow2_zext_1): Use exactl_log2 in insn condition.
(*udivmodsi4_pow2_zext_2): Ditto.
(*divmod4_noext): Macroize insn from *divmod4_noext
and *udivmod4_noext patterns using any_div code iterator.
(*divmod4_noext_zext_1): Macroize insn from
*divmod4_noext_zext_1 and *udivmod4_noext_zext_1
patterns using any_div code iterator.
(*divmod4_noext_zext_2): Macroize insn from
*divmod4_noext_zext_2 and *udivmod4_noext_zext_2
patterns using any_div code iterator.
(divmodhiqi3): Macroize insn from divmodhiqi3 and
udivmodhiqi3 patterns using any_extend code iterator.

The patch also reorders DIVMOD patterns a bit.

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

Committed to mainline SVN.

[1] https://gcc.gnu.org/ml/gcc-patches/2019-05/msg00560.html

Uros.
diff --git a/gcc/config/i386/i386.md b/gcc/config/i386/i386.md
index edec0ab0386c..05411221197f 100644
--- a/gcc/config/i386/i386.md
+++ b/gcc/config/i386/i386.md
@@ -933,11 +933,12 @@
 (define_code_iterator any_extend [sign_extend zero_extend])
 
 ;; Prefix for insn menmonic.
-(define_code_attr sgnprefix [(sign_extend "i") (zero_extend "")])
-
+(define_code_attr sgnprefix [(sign_extend "i") (zero_extend "")
+(div "i") (udiv "")])
 ;; Prefix for define_insn
-(define_code_attr u [(sign_extend "") (zero_extend "u")])
 (define_code_attr s [(sign_extend "s") (zero_extend "u")])
+(define_code_attr u [(sign_extend "") (zero_extend "u")
+(div "") (udiv "u")])
 (define_code_attr u_bool [(sign_extend "false") (zero_extend "true")])
 
 ;; Used in signed and unsigned truncations.
@@ -7475,13 +7476,16 @@
 
 ;; Divmod instructions.
 
-(define_expand "divmod4"
+(define_code_iterator any_div [div udiv])
+(define_code_attr paired_mod [(div "mod") (udiv "umod")])
+
+(define_expand "divmod4"
   [(parallel [(set (match_operand:SWIM248 0 "register_operand")
-  (div:SWIM248
+  (any_div:SWIM248
 (match_operand:SWIM248 1 "register_operand")
 (match_operand:SWIM248 2 "nonimmediate_operand")))
  (set (match_operand:SWIM248 3 "register_operand")
-  (mod:SWIM248 (match_dup 1) (match_dup 2)))
+  (:SWIM248 (match_dup 1) (match_dup 2)))
  (clobber (reg:CC FLAGS_REG))])])
 
 ;; Split with 8bit unsigned divide:
@@ -7491,10 +7495,10 @@
 ;;use original integer divide
 (define_split
   [(set (match_operand:SWI48 0 "register_operand")
-   (div:SWI48 (match_operand:SWI48 2 "register_operand")
-   (match_operand:SWI48 3 "nonimmediate_operand")))
+   (any_div:SWI48 (match_operand:SWI48 2 "register_operand")
+  (match_operand:SWI48 3 "nonimmediate_operand")))
(set (match_operand:SWI48 1 "register_operand")
-   (mod:SWI48 (match_dup 2) (match_dup 3)))
+   (:SWI48 (match_dup 2) (match_dup 3)))
(clobber (reg:CC FLAGS_REG))]
   "TARGET_USE_8BIT_IDIV
&& TARGET_QIMODE_MATH
@@ -7506,12 +7510,13 @@
 (define_split
   [(set (match_operand:DI 0 "register_operand")
(zero_extend:DI
- (div:SI (match_operand:SI 2 "register_operand")
- (match_operand:SI 3 "nonimmediate_operand"
+ (any_div:SI (match_operand:SI 2 "register_operand")
+ (match_operand:SI 3 "nonimmediate_operand"
(set (match_operand:SI 1 "register_operand")
-   (mod:SI (match_dup 2) (match_dup 3)))
+   (:SI (match_dup 2) (match_dup 3)))
(clobber (reg:CC FLAGS_REG))]
-  "TARGET_USE_8BIT_IDIV
+  "TARGET_64BIT
+   && TARGET_USE_8BIT_IDIV
&& TARGET_QIMODE_MATH
&& can_create_pseudo_p ()
&& !optimize_insn_for_size_p ()"
@@ -7521,12 +7526,13 @@
 (define_split
   [(set (match_operand:DI 1 "register_operand")
(zero_extend:DI
- (mod:SI (match_operand:SI 2 "register_operand")
- (match_operand:SI 3 "nonimmediate_operand"
+ (:SI (match_operand:SI 2 "register_operand")
+  (match_operand:SI 3 "nonimmediate_operand"
(set (match_operand:SI 0 "register_operand")
-   (div:SI  (match_dup 2) (match_dup 3)))
+   (any_div:SI  (match_dup 2) (match_dup 3)))
(clobber (reg:CC FLAGS_REG))]
-  "TARGET_USE_8BIT_IDIV
+  "TARGET_64BIT
+   && TARGET_USE_8BIT_IDIV
&& TARGET_QIMODE_MATH
&& can_create_pseudo_p ()
&& !optimize_insn_for_size_p ()"
@@ -7568,6 +7574,28 @@
   [(set_attr "type" "multi")
(set_attr "mode" "")])
 

Re: [v3 PATCH] nonesuch is insufficiently useless (lwg2996)

2019-05-14 Thread Nina Dinka Ranns
That was fast :)
I’ll check the changelog for future reference.
Thanks,
Nina

On Tue, 14 May 2019 at 16:50, Jonathan Wakely  wrote:

> On 14/05/19 15:43 +0100, Nina Dinka Ranns wrote:
> >Tested on Linux x86_64
> >nonesuch is insufficiently useless (lwg2996)
> >
> >2019-05-14  Nina Dinka Ranns  
> >nonesuch is insufficiently useless (lwg2996)
> >* include/std/type_traits
> >struct __nonesuch: added private base class to make __nonesuch
> >not an aggregate and removed deleted default constructor
> >* include/bits/stl_pair.h:
> >struct __nonesuch_no_braces: Removed
> >(operator=(const pair&)): Use __nonesuch instead of
> >__nonesuch_no_braces.
> >(operator=(pair&&)): Likewise
> >* include/std/tuple
> >(operator=(const tuple&)): Use __nonesuch instead of
> >__nonesuch_no_braces.
> >(operator=(tuple&&)): Likewise
> >* include/experimental/type_traits
> > struct nonesuch: added private base class to make nonesuch
> >not an aggregate and removed deleted default constructor
> >* testsuite/20_util/nonesuch/nonesuch.cc: New
> >* testsuite/experimental/type_traits/nonesuch.cc: New
>
> Thanks!
>
> Tested and committed, again with some changelog edits, and some whitespace
> before the opening braces here ...
>
> >@@ -2769,8 +2769,8 @@
> >  __call_is_nothrow_<_Fn, _Args...>>::type
> > { };
> >
> >-  struct __nonesuch {
> >-__nonesuch() = delete;
> >+  struct __nonesuchbase{};
> >+  struct __nonesuch : private __nonesuchbase{
>
>
>


[Contrib PATCH] Add scripts to convert GCC repo from SVN to Git

2019-05-14 Thread Maxim Kuvyrkov
This patch adds scripts to contrib/ to migrate full history of GCC's subversion 
repository to git.  My hope is that these scripts will finally allow GCC 
project to migrate to Git.

The result of the conversion is at 
https://github.com/maxim-kuvyrkov/gcc/branches/all .  Branches with "@rev" 
suffixes represent branch points.  The conversion is still running, so not all 
branches may appear right away.

The scripts are not specific to GCC repo and are usable for other projects.  In 
particular, they should be able to convert downstream GCC svn repos.

The scripts convert svn history branch by branch.  They rely on git-svn on 
convert individual branches.  Git-svn is a good tool for converting individual 
branches.  It is, however, either very slow at converting the entire GCC repo, 
or goes into infinite loop.

There are 3 scripts:

- svn-git-repo.sh: top level script to convert entire repo or a part of it 
(e.g., branches/),
- svn-list-branches.sh: helper script to output branches and their parents in 
bottom-up order,
- svn-git-branch.sh: helper script to convert a single branch.

Whenever possible, svn-git-branch.sh uses existing git branches as caches.

What are your questions and comments?

The attached is cleaned up version, which hasn't been fully tested yet; typos 
and other silly mistakes are likely.  OK to commit after testing?

--
Maxim Kuvyrkov
www.linaro.org




0001-Contrib-SVN-Git-conversion-scripts.patch
Description: Binary data


Re: [PATCH] Add gdc support to macOS

2019-05-14 Thread Iain Buclaw
On Tue, 14 May 2019 at 17:05, ciel  wrote:
>
> Dear GCC team,
>
> I have succeeded to build gdc on macOS. I firstly submitted the patch
> to https://github.com/Homebrew/homebrew-core/pull/39712 but I was
> encouraged to submit to gcc team instead. So could you take a look at
> it?
>

Some of it looks on par with work I've already done on this port.

I don't think that the sections/osx.d module is the right way to go,
particularly if you want proper shared library support.

As for the name of the section, this should be handled by a D language
target hook.

I'll post patches for this soon once the rough edges have been sorted out.

Thanks,
--
Iain


Re: [v3 PATCH] nonesuch is insufficiently useless (lwg2996)

2019-05-14 Thread Jonathan Wakely

On 14/05/19 15:43 +0100, Nina Dinka Ranns wrote:

Tested on Linux x86_64
nonesuch is insufficiently useless (lwg2996)

2019-05-14  Nina Dinka Ranns  
   nonesuch is insufficiently useless (lwg2996)
   * include/std/type_traits
   struct __nonesuch: added private base class to make __nonesuch
not an aggregate and removed deleted default constructor
   * include/bits/stl_pair.h:
   struct __nonesuch_no_braces: Removed
   (operator=(const pair&)): Use __nonesuch instead of
__nonesuch_no_braces.
   (operator=(pair&&)): Likewise
   * include/std/tuple
   (operator=(const tuple&)): Use __nonesuch instead of
__nonesuch_no_braces.
   (operator=(tuple&&)): Likewise
   * include/experimental/type_traits
struct nonesuch: added private base class to make nonesuch
not an aggregate and removed deleted default constructor
   * testsuite/20_util/nonesuch/nonesuch.cc: New
   * testsuite/experimental/type_traits/nonesuch.cc: New


Thanks!

Tested and committed, again with some changelog edits, and some whitespace
before the opening braces here ...


@@ -2769,8 +2769,8 @@
 __call_is_nothrow_<_Fn, _Args...>>::type
{ };

-  struct __nonesuch {
-__nonesuch() = delete;
+  struct __nonesuchbase{};
+  struct __nonesuch : private __nonesuchbase{





[C++ Patch] Consistently use OVL_P

2019-05-14 Thread Paolo Carlini

Hi,

another straightforward one sitting in my tree... Sanity checked on 
x86_64-linux.


Thanks, Paolo.

///

2019-05-14  Paolo Carlini  

* call.c (perform_overload_resolution, build_new_method_call_1):
Use OVL_P.
* decl.c (grokfndecl): Likewise.
* mangle.c (write_expression): Likewise.
* parser.c (cp_parser_template_id): Likewise.
* pt.c (resolve_overloaded_unification, type_dependent_expression_p):
Likewise. 
* search.c (build_baselink): Likewise.
* tree.c (is_overloaded_fn, dependent_name, maybe_get_fns): Likewise.
Index: call.c
===
--- call.c  (revision 271166)
+++ call.c  (working copy)
@@ -4383,9 +4383,8 @@ perform_overload_resolution (tree fn,
   *any_viable_p = true;
 
   /* Check FN.  */
-  gcc_assert (TREE_CODE (fn) == FUNCTION_DECL
+  gcc_assert (OVL_P (fn)
  || TREE_CODE (fn) == TEMPLATE_DECL
- || TREE_CODE (fn) == OVERLOAD
  || TREE_CODE (fn) == TEMPLATE_ID_EXPR);
 
   if (TREE_CODE (fn) == TEMPLATE_ID_EXPR)
@@ -9605,9 +9604,8 @@ build_new_method_call_1 (tree instance, tree fns,
   fns = TREE_OPERAND (fns, 0);
   template_only = 1;
 }
-  gcc_assert (TREE_CODE (fns) == FUNCTION_DECL
- || TREE_CODE (fns) == TEMPLATE_DECL
- || TREE_CODE (fns) == OVERLOAD);
+  gcc_assert (OVL_P (fns)
+ || TREE_CODE (fns) == TEMPLATE_DECL);
   fn = OVL_FIRST (fns);
   name = DECL_NAME (fn);
 
Index: decl.c
===
--- decl.c  (revision 271166)
+++ decl.c  (working copy)
@@ -8918,9 +8918,7 @@ grokfndecl (tree ctype,
 the information in the TEMPLATE_ID_EXPR.  */
  SET_DECL_IMPLICIT_INSTANTIATION (decl);
 
- gcc_assert (identifier_p (fns)
- || TREE_CODE (fns) == OVERLOAD
- || TREE_CODE (fns) == FUNCTION_DECL);
+ gcc_assert (identifier_p (fns) || OVL_P (fns));
  DECL_TEMPLATE_INFO (decl) = build_template_info (fns, args);
 
  for (t = TYPE_ARG_TYPES (TREE_TYPE (decl)); t; t = TREE_CHAIN (t))
Index: mangle.c
===
--- mangle.c(revision 271166)
+++ mangle.c(working copy)
@@ -3278,8 +3278,7 @@ write_expression (tree expr)
 
/* Mangle a dependent name as the name, not whatever happens to
   be the first function in the overload set.  */
-   if ((TREE_CODE (fn) == FUNCTION_DECL
-|| TREE_CODE (fn) == OVERLOAD)
+   if (OVL_P (fn)
&& type_dependent_expression_p_push (expr))
  fn = OVL_NAME (fn);
 
Index: parser.c
===
--- parser.c(revision 271166)
+++ parser.c(working copy)
@@ -16479,10 +16479,9 @@ cp_parser_template_id (cp_parser *parser,
 {
   /* If it's not a class-template or a template-template, it should be
 a function-template.  */
-  gcc_assert ((DECL_FUNCTION_TEMPLATE_P (templ)
-  || TREE_CODE (templ) == OVERLOAD
-  || TREE_CODE (templ) == FUNCTION_DECL
-  || BASELINK_P (templ)));
+  gcc_assert (DECL_FUNCTION_TEMPLATE_P (templ)
+ || OVL_P (templ)
+ || BASELINK_P (templ));
 
   template_id = lookup_template_function (templ, arguments);
   if (TREE_CODE (template_id) == TEMPLATE_ID_EXPR)
Index: pt.c
===
--- pt.c(revision 271166)
+++ pt.c(working copy)
@@ -21193,8 +21193,7 @@ resolve_overloaded_unification (tree tparms,
   if (good != 1)
good = ok;
 }
-  else if (TREE_CODE (arg) != OVERLOAD
-  && TREE_CODE (arg) != FUNCTION_DECL)
+  else if (!OVL_P (arg))
 /* If ARG is, for example, "(0, )" then its type will be unknown
-- but the deduction does not succeed because the expression is
not just the function on its own.  */
@@ -25950,8 +25949,7 @@ type_dependent_expression_p (tree expression)
return true;
}
 
-  gcc_assert (TREE_CODE (expression) == OVERLOAD
- || TREE_CODE (expression) == FUNCTION_DECL);
+  gcc_assert (OVL_P (expression));
 
   for (lkp_iterator iter (expression); iter; ++iter)
if (type_dependent_expression_p (*iter))
Index: search.c
===
--- search.c(revision 271166)
+++ search.c(working copy)
@@ -1058,10 +1058,9 @@ build_baselink (tree binfo, tree access_binfo, tre
 {
   tree baselink;
 
-  gcc_assert (TREE_CODE (functions) == FUNCTION_DECL
+  gcc_assert (OVL_P (functions)
  || TREE_CODE (functions) == TEMPLATE_DECL
- || TREE_CODE (functions) == TEMPLATE_ID_EXPR
- || TREE_CODE (functions) == 

[PATCH] Use INVOKE in std::function, std::bind and std::packaged_task

2019-05-14 Thread Jonathan Wakely

As well as simpifying the code by removing duplication, this means that
we only need to touch std::__invoke_r if we need to implement changes to
INVOKE, such as those in P0932R0.

* include/bits/std_function.h (_Simple_type_wrapper): Remove.
(_Function_handler): Remove partial specializations for void return
types and pointers to member.
(_Function_handler::_M_manager): Adapt to removal of
_Simple_type_wrapper.
(_Function_handler::_M_invoke): Use __invoke_r instead of __invoke.
* include/std/functional (_Bind_result::__enable_if_void)
(_Bind_result::__disable_if_void): Remove sfinae helpers.
(_Bind_result::__call): Use __invoke_r and remove overloads for void
return types.
* include/std/future (__future_base::_Task_state::_M_run)
(__future_base::_Task_state::_M_run_delayed): Use __invoke_r and
change return type of lambda expressions.

Tested powerpc64le-linux, committed to trunk.


commit 251e0fb712bb801cae130f838e02ee697b97e73c
Author: Jonathan Wakely 
Date:   Tue Apr 9 20:07:33 2019 +0100

Use INVOKE in std::function, std::bind and std::packaged_task

As well as simpifying the code by removing duplication, this means that
we only need to touch std::__invoke_r if we need to implement changes to
INVOKE, such as those in P0932R0.

* include/bits/std_function.h (_Simple_type_wrapper): Remove.
(_Function_handler): Remove partial specializations for void return
types and pointers to member.
(_Function_handler::_M_manager): Adapt to removal of
_Simple_type_wrapper.
(_Function_handler::_M_invoke): Use __invoke_r instead of __invoke.
* include/std/functional (_Bind_result::__enable_if_void)
(_Bind_result::__disable_if_void): Remove sfinae helpers.
(_Bind_result::__call): Use __invoke_r and remove overloads for void
return types.
* include/std/future (__future_base::_Task_state::_M_run)
(__future_base::_Task_state::_M_run_delayed): Use __invoke_r and
change return type of lambda expressions.

diff --git a/libstdc++-v3/include/bits/std_function.h 
b/libstdc++-v3/include/bits/std_function.h
index b70ed564d11..5733bf5f3f9 100644
--- a/libstdc++-v3/include/bits/std_function.h
+++ b/libstdc++-v3/include/bits/std_function.h
@@ -109,21 +109,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 __destroy_functor
   };
 
-  // Simple type wrapper that helps avoid annoying const problems
-  // when casting between void pointers and pointers-to-pointers.
-  template
-struct _Simple_type_wrapper
-{
-  _Simple_type_wrapper(_Tp __value) : __value(__value) { }
-
-  _Tp __value;
-};
-
-  template
-struct __is_location_invariant<_Simple_type_wrapper<_Tp> >
-: __is_location_invariant<_Tp>
-{ };
-
   template
 class function;
 
@@ -278,56 +263,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 {
   typedef _Function_base::_Base_manager<_Functor> _Base;
 
-public:
-  static _Res
-  _M_invoke(const _Any_data& __functor, _ArgTypes&&... __args)
-  {
-   return (*_Base::_M_get_pointer(__functor))(
-   std::forward<_ArgTypes>(__args)...);
-  }
-};
-
-  template
-class _Function_handler
-: public _Function_base::_Base_manager<_Functor>
-{
-  typedef _Function_base::_Base_manager<_Functor> _Base;
-
- public:
-  static void
-  _M_invoke(const _Any_data& __functor, _ArgTypes&&... __args)
-  {
-   (*_Base::_M_get_pointer(__functor))(
-   std::forward<_ArgTypes>(__args)...);
-  }
-};
-
-  template
-class _Function_handler<_Res(_ArgTypes...), _Member _Class::*>
-: public _Function_handler
-{
-  typedef _Function_handler
-   _Base;
-
- public:
-  static _Res
-  _M_invoke(const _Any_data& __functor, _ArgTypes&&... __args)
-  {
-   return std::__invoke(_Base::_M_get_pointer(__functor)->__value,
-std::forward<_ArgTypes>(__args)...);
-  }
-};
-
-  template
-class _Function_handler
-: public _Function_base::_Base_manager<
-_Simple_type_wrapper< _Member _Class::* > >
-{
-  typedef _Member _Class::* _Functor;
-  typedef _Simple_type_wrapper<_Functor> _Wrapper;
-  typedef _Function_base::_Base_manager<_Wrapper> _Base;
-
 public:
   static bool
   _M_manager(_Any_data& __dest, const _Any_data& __source,
@@ -341,8 +276,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
break;
 #endif
  case __get_functor_ptr:
-   __dest._M_access<_Functor*>() =
- &_Base::_M_get_pointer(__source)->__value;
+   __dest._M_access<_Functor*>() = _Base::_M_get_pointer(__source);
break;
 
  default:
@@ -351,11 +285,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
return false;
   }
 
-  static void
+  

[PATCH] Define std::__invoke_r for INVOKE

2019-05-14 Thread Jonathan Wakely

* include/bits/invoke.h (__invoke_r): Define new function implementing
the INVOKE pseudo-function.
* testsuite/20_util/function_objects/invoke/1.cc: Add more tests.
* testsuite/20_util/function_objects/invoke/2.cc: New test.

Tested powerpc64le-linux, committed to trunk.

commit 2a1977fbb243b6551de42a434a316fb033580f79
Author: Jonathan Wakely 
Date:   Tue Apr 9 20:09:00 2019 +0100

Define std::__invoke_r for INVOKE

* include/bits/invoke.h (__invoke_r): Define new function 
implementing
the INVOKE pseudo-function.
* testsuite/20_util/function_objects/invoke/1.cc: Add more tests.
* testsuite/20_util/function_objects/invoke/2.cc: New test.

diff --git a/libstdc++-v3/include/bits/invoke.h 
b/libstdc++-v3/include/bits/invoke.h
index a5278a59f0c..59e22da84d4 100644
--- a/libstdc++-v3/include/bits/invoke.h
+++ b/libstdc++-v3/include/bits/invoke.h
@@ -96,6 +96,65 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
std::forward<_Args>(__args)...);
 }
 
+#if __cplusplus >= 201703L
+  // INVOKE: Invoke a callable object and convert the result to R.
+  template
+constexpr enable_if_t, _Res>
+__invoke_r(_Callable&& __fn, _Args&&... __args)
+noexcept(is_nothrow_invocable_r_v<_Res, _Callable, _Args...>)
+{
+  using __result = __invoke_result<_Callable, _Args...>;
+  using __type = typename __result::type;
+  using __tag = typename __result::__invoke_type;
+  if constexpr (is_void_v<_Res>)
+   std::__invoke_impl<__type>(__tag{}, std::forward<_Callable>(__fn),
+   std::forward<_Args>(__args)...);
+  else
+   return std::__invoke_impl<__type>(__tag{},
+ std::forward<_Callable>(__fn),
+ std::forward<_Args>(__args)...);
+}
+#else // C++11
+  template
+using __can_invoke_as_void = __enable_if_t<
+  __and_, __is_invocable<_Callable, _Args...>>::value,
+  _Res
+>;
+
+  template
+using __can_invoke_as_nonvoid = __enable_if_t<
+  __and_<__not_>,
+is_convertible::type,
+   _Res>
+  >::value,
+  _Res
+>;
+
+  // INVOKE: Invoke a callable object and convert the result to R.
+  template
+constexpr __can_invoke_as_nonvoid<_Res, _Callable, _Args...>
+__invoke_r(_Callable&& __fn, _Args&&... __args)
+{
+  using __result = __invoke_result<_Callable, _Args...>;
+  using __type = typename __result::type;
+  using __tag = typename __result::__invoke_type;
+  return std::__invoke_impl<__type>(__tag{}, std::forward<_Callable>(__fn),
+   std::forward<_Args>(__args)...);
+}
+
+  // INVOKE when R is cv void
+  template
+constexpr __can_invoke_as_void<_Res, _Callable, _Args...>
+__invoke_r(_Callable&& __fn, _Args&&... __args)
+{
+  using __result = __invoke_result<_Callable, _Args...>;
+  using __type = typename __result::type;
+  using __tag = typename __result::__invoke_type;
+  std::__invoke_impl<__type>(__tag{}, std::forward<_Callable>(__fn),
+std::forward<_Args>(__args)...);
+}
+#endif // C++11
+
 _GLIBCXX_END_NAMESPACE_VERSION
 } // namespace std
 
diff --git a/libstdc++-v3/testsuite/20_util/function_objects/invoke/1.cc 
b/libstdc++-v3/testsuite/20_util/function_objects/invoke/1.cc
index e6a4a2ac560..9af7b294130 100644
--- a/libstdc++-v3/testsuite/20_util/function_objects/invoke/1.cc
+++ b/libstdc++-v3/testsuite/20_util/function_objects/invoke/1.cc
@@ -24,7 +24,43 @@ struct abstract {
   void operator()() noexcept;
 };
 
-static_assert( noexcept(std::__invoke(std::declval())), "" );
+static_assert( noexcept(std::__invoke(std::declval())),
+"It should be possible to use abstract types with INVOKE" );
 #if __cpp_lib_invoke
-static_assert( noexcept(std::invoke(std::declval())), "" );
+// std::invoke is only defined since C++17.
+static_assert( noexcept(std::invoke(std::declval())),
+"It should be possible to use abstract types with INVOKE" );
+
+// The std::__invoke_r extension only has a noexcept-specifier for >= C++17.
+static_assert( noexcept(std::__invoke_r(std::declval())),
+"It should be possible to use abstract types with INVOKE" );
+#endif
+
+struct F {
+  void operator()() &;
+  void operator()() && noexcept;
+  int operator()(int);
+  double* operator()(int, int) noexcept;
+};
+struct D { D(void*); };
+
+static_assert( !noexcept(std::__invoke(std::declval())), "" );
+static_assert( noexcept(std::__invoke(std::declval())), "" );
+static_assert( !noexcept(std::__invoke(std::declval(), 1)), "" );
+static_assert( noexcept(std::__invoke(std::declval(), 1, 2)), "" );
+
+#if __cpp_lib_invoke
+static_assert( !noexcept(std::invoke(std::declval())), "" );
+static_assert( noexcept(std::invoke(std::declval())), "" );
+static_assert( 

Re: [PATCH][RFC] Come up with TARGET_HAS_FAST_MEMPCPY_ROUTINE (PR middle-end/90263).

2019-05-14 Thread Martin Sebor

On 5/14/19 8:55 AM, Martin Liška wrote:

On 5/13/19 3:07 PM, Jakub Jelinek wrote:

On Mon, May 13, 2019 at 12:14:37PM +0200, Martin Liška wrote:

On 5/10/19 11:21 AM, Jakub Jelinek wrote:

On Fri, May 10, 2019 at 11:04:12AM +0200, Martin Liška wrote:

--- a/gcc/config/i386/i386.h
+++ b/gcc/config/i386/i386.h
@@ -1906,6 +1906,9 @@ typedef struct ix86_args {
  
  #define CLEAR_RATIO(speed) ((speed) ? MIN (6, ix86_cost->move_ratio) : 2)
  
+/* C library provides fast implementation of mempcpy function.  */

+#define TARGET_HAS_FAST_MEMPCPY_ROUTINE 1
+


1) we shouldn't be adding further target macros, but target hooks


Done.


2) I don't think this is a property of the x86 target, but of x86 glibc,
so you should set it on x86 glibc only (i.e. i?86/x86_64 linux and hurd
when using glibc, not newlib, nor bionic/android, nor uclibc, nor musl)


I've implemented the in i386.c with DEFAULT_LIBC == LIBC_GLIBC. Hope it's 
correct?


No, that would be correct only in the rare SINGLE_LIBC configurations.
Either you can do
#ifdef OPTION_GLIBC
   return OPTION_GLIBC;
#else
   return false;
#endif
or define something in config/linux.h (or .[ch]) that you can then use in
i386.c.

Jakub



Hi.

You always have nice ideas. I'm sending updated patch which addresses both 
Jakub's
and Wilco's comments.



index 66cee075018..7bff5cbd313 100644
--- a/gcc/target.def
+++ b/gcc/target.def
@@ -5797,6 +5797,12 @@ DEFHOOK
  const char *, (void),
  hook_constcharptr_void_null)

+DEFHOOK
+(has_fast_mempcpy_routine,
+ "Return true if a target has a fast mempcpy routine.",
+ bool, (void),
+ hook_bool_void_false)
+

Not to be too nit-picky about the name but target.def refers to
functions rather than routines.  It also defines a hook called
libc_has_function with the obvious semantics so if there's
a chance that it could be useful to query whether another libc
function is "fast" I would suggest to consider defining the hook
correspondingly, i.e.,

  bool libc_has_fast_function (enum function_class)

and naming the macro similarly.

Martin


[PATCH] Add gdc support to macOS

2019-05-14 Thread ciel
Dear GCC team,

I have succeeded to build gdc on macOS. I firstly submitted the patch
to https://github.com/Homebrew/homebrew-core/pull/39712 but I was
encouraged to submit to gcc team instead. So could you take a look at
it?

Best Regards,
T. Yamada


gcc9-gdc.patch
Description: Binary data


libgo patch committed: Reduce profiling overhead

2019-05-14 Thread Ian Lance Taylor
This libgo patch by Than McIntosh revises the gccgo version of
memory/block/mutex profiling to reduce runtime overhead.  The main
change is to collect raw stack traces while the profile is on line,
then post-process the stacks just prior to the point where we are
ready to use the final product.  Memory profiling (at a very low
sampling rate) is enabled by default, and the overhead of the
symbolization / DWARF-reading from backtrace_full was slowing things
down relative to the main Go runtime.  Bootstrapped and ran Go
testsuite on x86_64-pc-linux-gnu.  Committed to mainline.

Ian
Index: gcc/go/gofrontend/MERGE
===
--- gcc/go/gofrontend/MERGE (revision 271135)
+++ gcc/go/gofrontend/MERGE (working copy)
@@ -1,4 +1,4 @@
-3f015e128bf6d1d9279f3d43e26f60f0927019cb
+6112f9b8fa9d57d2db8a709cc8b44a94d778d08a
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
Index: libgo/go/runtime/heapdump.go
===
--- libgo/go/runtime/heapdump.go(revision 270877)
+++ libgo/go/runtime/heapdump.go(working copy)
@@ -437,17 +437,15 @@ func dumpmemstats() {
dumpint(uint64(memstats.numgc))
 }
 
-func dumpmemprof_callback(b *bucket, nstk uintptr, pstk *location, size, 
allocs, frees uintptr) {
-   stk := (*[10]location)(unsafe.Pointer(pstk))
+func dumpmemprof_callback(b *bucket, nstk uintptr, pstk *uintptr, size, 
allocs, frees uintptr) {
+   stk := (*[10]uintptr)(unsafe.Pointer(pstk))
dumpint(tagMemProf)
dumpint(uint64(uintptr(unsafe.Pointer(b
dumpint(uint64(size))
dumpint(uint64(nstk))
for i := uintptr(0); i < nstk; i++ {
-   pc := stk[i].pc
-   fn := stk[i].function
-   file := stk[i].filename
-   line := stk[i].lineno
+   pc := stk[i]
+   fn, file, line, _ := funcfileline(pc, -1)
if fn == "" {
var buf [64]byte
n := len(buf)
Index: libgo/go/runtime/mgcmark.go
===
--- libgo/go/runtime/mgcmark.go (revision 270877)
+++ libgo/go/runtime/mgcmark.go (working copy)
@@ -1085,7 +1085,7 @@ func scanstackblockwithmap(pc, b0, n0 ui
span != nil && span.state != 
mSpanManual &&
(obj < span.base() || 
obj >= span.limit || span.state != mSpanInUse) {
print("runtime: found in object 
at *(", hex(b), "+", hex(i), ") = ", hex(obj), ", pc=", hex(pc), "\n")
-   name, file, line := 
funcfileline(pc, -1)
+   name, file, line, _ := 
funcfileline(pc, -1)
print(name, "\n", file, ":", 
line, "\n")
//gcDumpObject("object", b, i)
throw("found bad pointer in Go 
stack (incorrect use of unsafe or cgo?)")
Index: libgo/go/runtime/mprof.go
===
--- libgo/go/runtime/mprof.go   (revision 270877)
+++ libgo/go/runtime/mprof.go   (working copy)
@@ -24,6 +24,10 @@ const (
blockProfile
mutexProfile
 
+   // a profile bucket from one of the categories above whose stack
+   // trace has been fixed up / pruned.
+   prunedProfile
+
// size of bucket hash table
buckHashSize = 17
 
@@ -138,11 +142,13 @@ type blockRecord struct {
 }
 
 var (
-   mbuckets  *bucket // memory profile buckets
-   bbuckets  *bucket // blocking profile buckets
-   xbuckets  *bucket // mutex profile buckets
-   buckhash  *[17]*bucket
-   bucketmem uintptr
+   mbuckets*bucket // memory profile buckets
+   bbuckets*bucket // blocking profile buckets
+   xbuckets*bucket // mutex profile buckets
+   sbuckets*bucket // pre-symbolization profile buckets (stacks fixed 
up)
+   freebuckets *bucket // freelist of unused fixed up profile buckets
+   buckhash*[17]*bucket
+   bucketmem   uintptr
 
mProf struct {
// All fields in mProf are protected by proflock.
@@ -158,12 +164,35 @@ var (
 
 const mProfCycleWrap = uint32(len(memRecord{}.future)) * (2 << 24)
 
+// payloadOffset() returns a pointer into the part of a bucket
+// containing the profile payload (skips past the bucket struct itself
+// and then the stack trace).
+func payloadOffset(typ bucketType, nstk uintptr) uintptr {
+   if typ == prunedProfile {
+   // To allow reuse of prunedProfile buckets between different
+   // collections, allocate them with the max stack 

Re: [PATCH][RFC] Come up with TARGET_HAS_FAST_MEMPCPY_ROUTINE (PR middle-end/90263).

2019-05-14 Thread Martin Liška
On 5/13/19 3:07 PM, Jakub Jelinek wrote:
> On Mon, May 13, 2019 at 12:14:37PM +0200, Martin Liška wrote:
>> On 5/10/19 11:21 AM, Jakub Jelinek wrote:
>>> On Fri, May 10, 2019 at 11:04:12AM +0200, Martin Liška wrote:
 --- a/gcc/config/i386/i386.h
 +++ b/gcc/config/i386/i386.h
 @@ -1906,6 +1906,9 @@ typedef struct ix86_args {
  
  #define CLEAR_RATIO(speed) ((speed) ? MIN (6, ix86_cost->move_ratio) : 2)
  
 +/* C library provides fast implementation of mempcpy function.  */
 +#define TARGET_HAS_FAST_MEMPCPY_ROUTINE 1
 +
>>>
>>> 1) we shouldn't be adding further target macros, but target hooks
>>
>> Done.
>>
>>> 2) I don't think this is a property of the x86 target, but of x86 glibc,
>>>so you should set it on x86 glibc only (i.e. i?86/x86_64 linux and hurd
>>>when using glibc, not newlib, nor bionic/android, nor uclibc, nor musl)
>>
>> I've implemented the in i386.c with DEFAULT_LIBC == LIBC_GLIBC. Hope it's 
>> correct?
> 
> No, that would be correct only in the rare SINGLE_LIBC configurations.
> Either you can do
> #ifdef OPTION_GLIBC
>   return OPTION_GLIBC;
> #else
>   return false;
> #endif
> or define something in config/linux.h (or .[ch]) that you can then use in
> i386.c.
> 
>   Jakub
> 

Hi.

You always have nice ideas. I'm sending updated patch which addresses both 
Jakub's
and Wilco's comments.

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

Ready to be installed?
Thanks,
Martin
>From 0b056d6293feb70b3cd4a0cae5418d6bc8aa5491 Mon Sep 17 00:00:00 2001
From: marxin 
Date: Mon, 29 Apr 2019 13:46:25 +0200
Subject: [PATCH] Come up with has_fast_mempcpy_routine hook (PR
 middle-end/90263).

gcc/ChangeLog:

2019-05-13  Martin Liska  

	PR middle-end/90263
	* builtins.c (expand_builtin_memory_copy_args): When having a
	target with fast mempcpy implementation do now use memcpy.
	* config/i386/i386.c (glibc_has_fast_mempcpy_routine): New.
	(TARGET_HAS_FAST_MEMPCPY_ROUTINE): Likewise.
	* doc/tm.texi: Likewise.
	* doc/tm.texi.in: Likewise.
	* target.def: Likewise.
	* expr.c (emit_block_move_hints): Add 2 new arguments.
	* expr.h (emit_block_move_hints): Bail out when libcall
	to memcpy would be used.

gcc/testsuite/ChangeLog:

2019-05-13  Martin Liska  

	PR middle-end/90263
	* gcc.c-torture/compile/pr90263.c: New test.
	* lib/target-supports.exp: Add check_effective_target_glibc.
---
 gcc/builtins.c| 17 +++--
 gcc/config/i386/i386.c| 12 
 gcc/doc/tm.texi   |  4 
 gcc/doc/tm.texi.in|  2 ++
 gcc/expr.c| 13 -
 gcc/expr.h|  4 +++-
 gcc/target.def|  6 ++
 gcc/testsuite/gcc.c-torture/compile/pr90263.c | 10 ++
 gcc/testsuite/lib/target-supports.exp | 11 +++
 9 files changed, 75 insertions(+), 4 deletions(-)
 create mode 100644 gcc/testsuite/gcc.c-torture/compile/pr90263.c

diff --git a/gcc/builtins.c b/gcc/builtins.c
index d37d73fc4a0..06b19b62b43 100644
--- a/gcc/builtins.c
+++ b/gcc/builtins.c
@@ -3839,6 +3839,8 @@ expand_builtin_memory_copy_args (tree dest, tree src, tree len,
   unsigned HOST_WIDE_INT max_size;
   unsigned HOST_WIDE_INT probable_max_size;
 
+  bool is_move_done;
+
   /* If DEST is not a pointer type, call the normal function.  */
   if (dest_align == 0)
 return NULL_RTX;
@@ -3888,11 +3890,22 @@ expand_builtin_memory_copy_args (tree dest, tree src, tree len,
   if (CALL_EXPR_TAILCALL (exp)
   && (retmode == RETURN_BEGIN || target == const0_rtx))
 method = BLOCK_OP_TAILCALL;
-  if (retmode == RETURN_END && target != const0_rtx)
+  bool use_mempcpy_call = (targetm.has_fast_mempcpy_routine ()
+			   && retmode == RETURN_END
+			   && target != const0_rtx);
+  if (use_mempcpy_call)
 method = BLOCK_OP_NO_LIBCALL_RET;
   dest_addr = emit_block_move_hints (dest_mem, src_mem, len_rtx, method,
  expected_align, expected_size,
- min_size, max_size, probable_max_size);
+ min_size, max_size, probable_max_size,
+ use_mempcpy_call, _move_done);
+
+  /* Bail out when a mempcpy call would be expanded as libcall and when
+ we have a target that provides a fast implementation
+ of mempcpy routine.  */
+  if (!is_move_done)
+return NULL_RTX;
+
   if (dest_addr == pc_rtx)
 return NULL_RTX;
 
diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
index cc0ae3fcfd3..cf53bd91558 100644
--- a/gcc/config/i386/i386.c
+++ b/gcc/config/i386/i386.c
@@ -23056,6 +23056,18 @@ ix86_run_selftests (void)
 #define TARGET_GET_MULTILIB_ABI_NAME \
   ix86_get_multilib_abi_name
 
+static bool glibc_has_fast_mempcpy_routine (void)
+{
+#ifdef OPTION_GLIBC
+  return OPTION_GLIBC;
+#else
+  return false;
+#endif
+}
+
+#undef TARGET_HAS_FAST_MEMPCPY_ROUTINE
+#define TARGET_HAS_FAST_MEMPCPY_ROUTINE 

[v3 PATCH] nonesuch is insufficiently useless (lwg2996)

2019-05-14 Thread Nina Dinka Ranns
Tested on Linux x86_64
nonesuch is insufficiently useless (lwg2996)

2019-05-14  Nina Dinka Ranns  
nonesuch is insufficiently useless (lwg2996)
* include/std/type_traits
struct __nonesuch: added private base class to make __nonesuch
not an aggregate and removed deleted default constructor
* include/bits/stl_pair.h:
struct __nonesuch_no_braces: Removed
(operator=(const pair&)): Use __nonesuch instead of
__nonesuch_no_braces.
(operator=(pair&&)): Likewise
* include/std/tuple
(operator=(const tuple&)): Use __nonesuch instead of
__nonesuch_no_braces.
(operator=(tuple&&)): Likewise
* include/experimental/type_traits
 struct nonesuch: added private base class to make nonesuch
not an aggregate and removed deleted default constructor
* testsuite/20_util/nonesuch/nonesuch.cc: New
* testsuite/experimental/type_traits/nonesuch.cc: New
Index: libstdc++-v3/include/bits/stl_pair.h
===
--- libstdc++-v3/include/bits/stl_pair.h	(revision 270630)
+++ libstdc++-v3/include/bits/stl_pair.h	(working copy)
@@ -178,13 +178,6 @@
 	return false;
   }
   };
-
-  // PR libstdc++/79141, a utility type for preventing
-  // initialization of an argument of a disabled assignment
-  // operator from a pair of empty braces.
-  struct __nonesuch_no_braces : std::__nonesuch {
-explicit __nonesuch_no_braces(const __nonesuch&) = delete;
-  };
 #endif // C++11
 
   template class __pair_base
@@ -378,7 +371,7 @@
   operator=(typename conditional<
 		__and_,
 		   is_copy_assignable<_T2>>::value,
-		const pair&, const __nonesuch_no_braces&>::type __p)
+		const pair&, const __nonesuch&>::type __p)
   {
 	first = __p.first;
 	second = __p.second;
@@ -389,7 +382,7 @@
   operator=(typename conditional<
 		__and_,
 		   is_move_assignable<_T2>>::value,
-		pair&&, __nonesuch_no_braces&&>::type __p)
+		pair&&, __nonesuch&&>::type __p)
   noexcept(__and_,
 		  is_nothrow_move_assignable<_T2>>::value)
   {
Index: libstdc++-v3/include/experimental/type_traits
===
--- libstdc++-v3/include/experimental/type_traits	(revision 270630)
+++ libstdc++-v3/include/experimental/type_traits	(working copy)
@@ -226,9 +226,9 @@
 
 template using void_t = void;
 
-struct nonesuch
+struct __nonesuchbase{};
+struct nonesuch : private __nonesuchbase
 {
-  nonesuch() = delete;
   ~nonesuch() = delete;
   nonesuch(nonesuch const&) = delete;
   void operator=(nonesuch const&) = delete;
Index: libstdc++-v3/include/std/tuple
===
--- libstdc++-v3/include/std/tuple	(revision 270630)
+++ libstdc++-v3/include/std/tuple	(working copy)
@@ -816,7 +816,7 @@
   tuple&
   operator=(typename conditional<__assignable(),
  const tuple&,
- const __nonesuch_no_braces&>::type __in)
+ const __nonesuch&>::type __in)
   noexcept(__nothrow_assignable())
   {
 	this->_M_assign(__in);
@@ -826,7 +826,7 @@
   tuple&
   operator=(typename conditional<__assignable<_Elements...>(),
  tuple&&,
- __nonesuch_no_braces&&>::type __in)
+ __nonesuch&&>::type __in)
   noexcept(__nothrow_assignable<_Elements...>())
   {
 	this->_M_assign(std::move(__in));
@@ -1204,7 +1204,7 @@
   tuple&
   operator=(typename conditional<__assignable(),
  const tuple&,
- const __nonesuch_no_braces&>::type __in)
+ const __nonesuch&>::type __in)
   noexcept(__nothrow_assignable())
   {
 	this->_M_assign(__in);
@@ -1214,7 +1214,7 @@
   tuple&
   operator=(typename conditional<__assignable<_T1, _T2>(),
  tuple&&,
- __nonesuch_no_braces&&>::type __in)
+ __nonesuch&&>::type __in)
   noexcept(__nothrow_assignable<_T1, _T2>())
   {
 	this->_M_assign(std::move(__in));
Index: libstdc++-v3/include/std/type_traits
===
--- libstdc++-v3/include/std/type_traits	(revision 270630)
+++ libstdc++-v3/include/std/type_traits	(working copy)
@@ -2769,8 +2769,8 @@
  __call_is_nothrow_<_Fn, _Args...>>::type
 { };
 
-  struct __nonesuch {
-__nonesuch() = delete;
+  struct __nonesuchbase{};
+  struct __nonesuch : private __nonesuchbase{
 ~__nonesuch() = delete;
 __nonesuch(__nonesuch const&) = delete;
 void operator=(__nonesuch const&) = delete;
Index: libstdc++-v3/testsuite/20_util/nonesuch/nonesuch.cc
===
--- libstdc++-v3/testsuite/20_util/nonesuch/nonesuch.cc	(nonexistent)
+++ libstdc++-v3/testsuite/20_util/nonesuch/nonesuch.cc	(working copy)
@@ -0,0 +1,39 @@
+// 2019-05-14  Nina Dinka Ranns  
+// Copyright (C) 2019 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  

[PATCH] Add __is_nothrow_convertible to fix std::is_nothrow_invocable_r

2019-05-14 Thread Jonathan Wakely

The definition of is_nothrow_invocable in terms of is_convertible and
is_nothrow_constructible is incorrect, because a type could have an
explicit constructor that means is_nothrow_constructible is true, but
implicit conversions could use a different constructor that is
potentially-throwing.

Fix it by adding a C++11 version of C++20's is_nothrow_convertible that
only considers implicit conversions.

* include/std/type_traits (__is_nt_convertible_helper): Define it
unconditionally, not only for C++20.
(__is_nothrow_convertible): Define internal trait for use in C++11.
(__is_nt_invocable_impl: Fix by using __is_nothrow_convertible.
(is_invocable_r_v, is_nothrow_invocable_r_v): Add missing parameter.
* testsuite/20_util/is_nothrow_convertible/value_ext.cc: New test.
* testsuite/20_util/is_nothrow_convertible/value.cc: Check with type
that has nothrow explicit conversion but potentially-throwing implicit
conversion.
* testsuite/20_util/is_nothrow_invocable/value.cc: Likewise.
* testsuite/20_util/is_nothrow_invocable/value_ext.cc: Fix helper
function to only consider implicit conversions.
* testsuite/20_util/tuple/cons/noexcept_specs.cc: Add comment.

Tested powerpc64le-linux, committed to trunk.

commit e872e963111c865ac5a446703663bdc52990b938
Author: Jonathan Wakely 
Date:   Tue May 14 14:21:53 2019 +0100

Add __is_nothrow_convertible to fix std::is_nothrow_invocable_r

The definition of is_nothrow_invocable in terms of is_convertible and
is_nothrow_constructible is incorrect, because a type could have an
explicit constructor that means is_nothrow_constructible is true, but
implicit conversions could use a different constructor that is
potentially-throwing.

Fix it by adding a C++11 version of C++20's is_nothrow_convertible that
only considers implicit conversions.

* include/std/type_traits (__is_nt_convertible_helper): Define it
unconditionally, not only for C++20.
(__is_nothrow_convertible): Define internal trait for use in C++11.
(__is_nt_invocable_impl: Fix by using __is_nothrow_convertible.
(is_invocable_r_v, is_nothrow_invocable_r_v): Add missing parameter.
* testsuite/20_util/is_nothrow_convertible/value_ext.cc: New test.
* testsuite/20_util/is_nothrow_convertible/value.cc: Check with type
that has nothrow explicit conversion but potentially-throwing 
implicit
conversion.
* testsuite/20_util/is_nothrow_invocable/value.cc: Likewise.
* testsuite/20_util/is_nothrow_invocable/value_ext.cc: Fix helper
function to only consider implicit conversions.
* testsuite/20_util/tuple/cons/noexcept_specs.cc: Add comment.

diff --git a/libstdc++-v3/include/std/type_traits 
b/libstdc++-v3/include/std/type_traits
index ea733e7b7b2..f68d366269d 100644
--- a/libstdc++-v3/include/std/type_traits
+++ b/libstdc++-v3/include/std/type_traits
@@ -1378,7 +1378,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 : public __is_convertible_helper<_From, _To>::type
 { };
 
-#if __cplusplus > 201703L
 template, is_function<_To>,
 is_array<_To>>::value>
@@ -1393,7 +1392,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
static void __test_aux(_To1) noexcept;
 
   template
-   static bool_constant(std::declval<_From1>()))>
+   static
+   __bool_constant(std::declval<_From1>()))>
__test(int);
 
   template
@@ -1404,6 +1404,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   using type = decltype(__test<_From, _To>(0));
 };
 
+  // is_nothrow_convertible for C++11
+  template
+struct __is_nothrow_convertible
+: public __is_nt_convertible_helper<_From, _To>::type
+{ };
+
+#if __cplusplus > 201703L
   /// is_nothrow_convertible
   template
 struct is_nothrow_convertible
@@ -2831,8 +2838,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 struct __is_nt_invocable_impl<_Result, _Ret,
  __void_t>
 : __or_,
-   __and_,
-  is_nothrow_constructible<_Ret, typename _Result::type>>>
+   __is_nothrow_convertible>
 { };
 
   /// std::is_nothrow_invocable_r
@@ -2852,14 +2858,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   = is_nothrow_invocable<_Fn, _Args...>::value;
 
   /// std::is_invocable_r_v
-  template
+  template
 inline constexpr bool is_invocable_r_v
-  = is_invocable_r<_Fn, _Args...>::value;
+  = is_invocable_r<_Ret, _Fn, _Args...>::value;
 
   /// std::is_nothrow_invocable_r_v
-  template
+  template
 inline constexpr bool is_nothrow_invocable_r_v
-  = is_nothrow_invocable_r<_Fn, _Args...>::value;
+  = is_nothrow_invocable_r<_Ret, _Fn, _Args...>::value;
 #endif // C++17
 
 #if __cplusplus >= 201703L
diff --git a/libstdc++-v3/testsuite/20_util/is_nothrow_convertible/value.cc 

New .md construct: define_insn_and_rewrite

2019-05-14 Thread Richard Sandiford
Several SVE patterns need define_insn_and_splits that generate the
same insn_code, but with different operands.  That's probably a
niche requirement, but it's cropping up often enough on the ACLE
branch that I think it would be good to have a syntactic sugar for it.

This patch therefore adds a new construct called define_insn_and_rewrite.
It's basically a define_insn_and_split with an implicit split pattern,
obtained by copying the insn pattern and replacing match_operands with
match_dups and match_operators with match_op_dups.

Any comments?  Suggestions for better names?

Richard


2019-05-14  Richard Sandiford  

gcc/
* doc/md.texi: Document define_insn_and_rewrite.
* rtl.def (DEFINE_INSN_AND_REWRITE): New rtx code.
* gensupport.c (queue_elem): Update comment.
(replace_operands_with_dups): New function.
(gen_rewrite_sequence): Likewise.
(process_rtx): Handle DEFINE_INSN_AND_REWRITE.
* read-rtl.c (apply_subst_iterator): Likewise.
(add_condition_to_rtx, named_rtx_p): Likewise.
(rtx_reader::read_rtx_operand): Likewise.
* config/aarch64/aarch64-sve.md
(while_ult_cc): Rename to...
(*while_ult_cc): ...this and use
define_insn_and_rewrite.
(*cond__any): Turn into define_insn_and_rewrites.
Remove separate define_split.

Index: gcc/doc/md.texi
===
--- gcc/doc/md.texi 2019-05-12 12:27:15.753897237 +0100
+++ gcc/doc/md.texi 2019-05-14 15:06:14.496625455 +0100
@@ -8537,6 +8537,72 @@ functionality as two separate @code{defi
 patterns.  It exists for compactness, and as a maintenance tool to prevent
 having to ensure the two patterns' templates match.
 
+@findex define_insn_and_rewrite
+It is sometimes useful to have a @code{define_insn_and_split}
+in which the new instruction pattern replaces some of the operands but leaves
+the rest of the original pattern unchanged.  Doing this directly in a
+@code{define_insn_and_split} would require a sequence of
+@var{new-insn-pattern}s that repeats the fixed parts of the
+@var{insn-pattern}.  You can avoid this by using
+@code{define_insn_and_rewrite}, which automatically generates
+a new pattern based on the original one, but using any new
+operand values provided by the @var{preparation-statements}.
+The operands are otherwise identical:
+
+@smallexample
+(define_insn_and_rewrite
+  [@var{insn-pattern}]
+  "@var{condition}"
+  "@var{output-template}"
+  "@var{split-condition}"
+  "@var{preparation-statements}"
+  [@var{insn-attributes}])
+@end smallexample
+
+The split in a @code{define_insn_and_rewrite} is only intended
+to apply to existing instructions that match @var{insn-pattern}.
+The @var{split-condition} must therefore start with @code{&&},
+so that the split condition applies on top of @var{condition}.
+
+Here is an example from the SVE port, in which operand 1 is known
+to be equivalent to an all-true constant and isn't used by the
+output template:
+
+@smallexample
+(define_insn_and_rewrite "*while_ult_cc"
+  [(set (reg:CC CC_REGNUM)
+(compare:CC
+  (unspec:SI [(match_operand:PRED_ALL 1)
+  (unspec:PRED_ALL
+[(match_operand:GPI 2 "aarch64_reg_or_zero" "rZ")
+ (match_operand:GPI 3 "aarch64_reg_or_zero" "rZ")]
+UNSPEC_WHILE_LO)]
+ UNSPEC_PTEST_PTRUE)
+  (const_int 0)))
+   (set (match_operand:PRED_ALL 0 "register_operand" "=Upa")
+(unspec:PRED_ALL [(match_dup 2)
+  (match_dup 3)]
+ UNSPEC_WHILE_LO))]
+  "TARGET_SVE"
+  "whilelo\t%0., %2, %3"
+  ;; Force the compiler to drop the unused predicate operand, so that we
+  ;; don't have an unnecessary PTRUE.
+  "&& !CONSTANT_P (operands[1])"
+  @{
+operands[1] = CONSTM1_RTX (mode);
+  @}
+)
+@end smallexample
+
+The splitter in this case simply replaces operand 1 with the constant
+value that it is known to have.
+
+As with a @code{define_split} or @code{define_insn_and_split},
+the @var{preparation-statements} in a @code{define_insn_and_rewrite}
+can emit additional instructions before the new instruction.  They
+can also emit an entirely different sequence of instructions and use
+@code{DONE} to avoid emitting a new form of the original instruction.
+
 @end ifset
 @ifset INTERNALS
 @node Including Patterns
Index: gcc/rtl.def
===
--- gcc/rtl.def 2019-03-08 18:15:26.824777889 +
+++ gcc/rtl.def 2019-05-14 15:06:14.500625443 +0100
@@ -936,6 +936,12 @@ DEF_RTL_EXPR(DEFINE_SPLIT, "define_split
7: optionally, a vector of attributes for this insn.  */
 DEF_RTL_EXPR(DEFINE_INSN_AND_SPLIT, "define_insn_and_split", "sEsTsESV", 
RTX_EXTRA)
 
+/* A form of define_insn_and_split in which the split insn pattern (operand 5)
+   is determined automatically by replacing match_operands 

Re: [PATCH] PR90424 - lowpart vector set recognition

2019-05-14 Thread Richard Sandiford
Richard Biener  writes:
> On Tue, 14 May 2019, Richard Sandiford wrote:
>
>> Richard Biener  writes:
>> > The following makes SSA rewrite (update-address-taken) recognize
>> > sets of aligned sub-vectors in aligned position
>> > (v2qi into v16qi, but esp. v8qi into v16qi).  It uses the
>> > BIT_INSERT_EXPR support for this, enabling that for vector
>> > typed values.  This makes us turn for example
>> >
>> > typedef unsigned char v16qi __attribute__((vector_size(16)));
>> > v16qi load (const void *p)
>> > {
>> >   v16qi r;
>> >   __builtin_memcpy (, p, 8);
>> >   return r;
>> > }
>> >
>> > into the following
>> >
>> > load (const void * p)
>> > {
>> >   v16qi r;
>> >   long unsigned int _3;
>> >   v16qi _5;
>> >   vector(8) unsigned char _7;
>> >
>> >:
>> >   _3 = MEM[(char * {ref-all})p_2(D)];
>> >   _7 = VIEW_CONVERT_EXPR(_3);
>> >   r_9 = BIT_INSERT_EXPR ;
>> >   _5 = r_9;
>> >   return _5;
>> >
>> > this isn't yet nicely expanded since the BIT_INSERT_EXPR
>> > expansion simply goes through store_bit_field and there's
>> > no vector-mode vec_set.
>> >
>> > Similar as to the single-element insert SSA rewrite already
>> > handles the transform is conditional on the involved
>> > vector types having non-BLKmode.  This is somewhat bad
>> > since the transform is supposed to enable SSA optimizations
>> > by rewriting memory vectors into SSA form.  Since splitting
>> > of larger generic vectors happens very much later only
>> > this pessimizes their use.  But the BIT_INSERT_EXPR
>> > expansion doesn't cope with BLKmode entities (source or
>> > destination).
>> >
>> > Extending BIT_INSERT_EXPR this way seems natural given
>> > the support of CONSTRUCTORs with smaller vectors.
>> > BIT_FIELD_REF isn't particularly restricted so can be
>> > used to extract sub-vectors as well.
>> >
>> > Code generation is as bad as before (RTL expansion eventually
>> > spills) but SSA optimizations are enabled on less trivial
>> > testcases.
>> >
>> > Boostrap / regtest running on x86_64-unknown-linux-gnu.
>> >
>> > Comments?
>> >
>> > Richard.
>> >
>> > 2019-05-14  Richard Biener  
>> >
>> >PR tree-optimization/90424
>> >* tree-ssa.c (non_rewritable_lvalue_p): Handle inserts from
>> >aligned subvectors.
>> >(execute_update_addresses_taken): Likewise.
>> >* tree-cfg.c (verify_gimple_assign_ternary): Likewise.
>> >
>> >* g++.target/i386/pr90424-1.C: New testcase.
>> >* g++.target/i386/pr90424-2.C: Likewise.
>> >
>> > Index: gcc/tree-ssa.c
>> > ===
>> > --- gcc/tree-ssa.c (revision 271155)
>> > +++ gcc/tree-ssa.c (working copy)
>> > @@ -1521,14 +1521,28 @@ non_rewritable_lvalue_p (tree lhs)
>> >if (DECL_P (decl)
>> >  && VECTOR_TYPE_P (TREE_TYPE (decl))
>> >  && TYPE_MODE (TREE_TYPE (decl)) != BLKmode
>> > -&& operand_equal_p (TYPE_SIZE_UNIT (TREE_TYPE (lhs)),
>> > -TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (decl))), 0)
>> > +&& multiple_of_p (sizetype,
>> > +  TYPE_SIZE_UNIT (TREE_TYPE (decl)),
>> > +  TYPE_SIZE_UNIT (TREE_TYPE (lhs)))
>> >  && known_ge (mem_ref_offset (lhs), 0)
>> >  && known_gt (wi::to_poly_offset (TYPE_SIZE_UNIT (TREE_TYPE (decl))),
>> >   mem_ref_offset (lhs))
>> >  && multiple_of_p (sizetype, TREE_OPERAND (lhs, 1),
>> >TYPE_SIZE_UNIT (TREE_TYPE (lhs
>> > -  return false;
>> > +  {
>> > +if (operand_equal_p (TYPE_SIZE_UNIT (TREE_TYPE (lhs)),
>> > + TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (decl))),
>> > + 0))
>> > +  return false;
>> > +/* For sub-vector inserts the insert vector mode has to be
>> > +   supported.  */
>> > +tree vtype = build_vector_type
>> > +(TREE_TYPE (TREE_TYPE (decl)),
>> > + tree_to_uhwi (TYPE_SIZE (TREE_TYPE (lhs)))
>> > + / tree_to_uhwi (TYPE_SIZE (TREE_TYPE (TREE_TYPE (decl);
>> 
>> AFAICT nothing guarantees tree_fits_uhwi_p for the lhs, so this isn't
>> poly-int clean.  Is there a guarantee that lhs is a multiple of the
>> element size even for integers?  Or are we just relying on a vector
>> of 0 elements being rejected?
>
> That it is a multiple of the element size is tested indirectly by
>
>> > + && multiple_of_p (sizetype, 
>> > +   TYPE_SIZE_UNIT (TREE_TYPE (decl)),
>> > +   TYPE_SIZE_UNIT (TREE_TYPE (lhs)))
>
> given 'decl' has vector type.  That also guarantees non-zero size?

I was thinking of the case where the element size is still bigger
than lhs, so the division would end up being 0.  Maybe one of those
conditions indirectly prevents that though.

> But yes, I guess TYPE_SIZE_UNIT might be a poly-int.
>
>> Maybe something like:
>> 
>>tree elt_type = TREE_TYPE (TREE_TYPE (decl));
>>unsigned int elt_bits = tree_to_uhwi (TYPE_SIZE (elt_type));
>>poly_uint64 lhs_bits, nelts;
>>

Re: malloc cannot alias preexisting pointers

2019-05-14 Thread Marc Glisse

On Tue, 14 May 2019, Richard Biener wrote:


In princple PTA should know the aliasing cannot happen but possibly
the info is either lost or the IL is too obfuscated at the point it gets
computed.  (hello C++...)


We don't need much obfuscation for this, a simple C program

int g;
int*f(int**p){
   int*q=*p;
   int*r=__builtin_malloc(4);
   *q=1;
   *r=2;
   g=*q;
   return r;
}

gives

   q_4 = *p_3(D);
   r_6 = __builtin_malloc (4);
   *q_4 = 1;
   *r_6 = 2;
   _1 = *q_4;
   g = _1;
   return r_6;

where we clearly don't manage to prove that q and r don't alias.


We can probably improve this one in general from inside PTA
by treating escapes through return specially.  I wasn't looking
too closely at the C++ testcase but I simply assumed the
addition to ESCAPED happens through storing the malloc
result to memory that PTA cannot prove local.


Yes, that is indeed the case. I only wrote the version with return to 
simplify, but the vector testcase does store the malloc result in 
non-local memory, so handling return as a special case wouldn't help it.



So at ldist time I see

 # PT = null { D.47989 } (escaped, escaped heap)
 # ALIGN = 8, MISALIGN = 0
 # USE = nonlocal null { D.47989 } (escaped, escaped heap)
 # CLB = nonlocal null { D.47989 } (escaped, escaped heap)
 _27 = malloc (8192);

good.  The interesting loop is the following where the allocation PTA
is good and _4 intersect because they include ESCAPED.  This is
because _27 itself escapes and PTA not being flow-sensitive.  I don't
see an easy way to improve things here but dislike the stmt walking
very much.  That is, the proper solution is to re-write PTA in some way.


I am trying to imagine what that might look like. I imagine that instead
of having a single "escaped" set, we would have multiple escaped sets at
different points in the function (at most one per VDEF?). Then _4 would
only contain escaped3 while heap5 (*_27) only appears in escaped9 and
later? It may be tricky to keep a linear-ish complexity with anything more
powerful than the current PTA. I don't know what LLVM is doing, but they
seem to manage.


IIRC LLVM uses Steensgard analysis which is flow-sensitive but generally
less powerful.  We are using Andersen constraint-based analysis because
Steensgard was patented back in time (that patent has now expired).


In https://llvm.org/docs/AliasAnalysis.html they say that Steensgaard’s 
algorithm is flow-insensitive and context-insensitive, so it might not be 
it. They run about 5 different alias analysis engines and combine their 
results to disambiguate as much as they can.



One approach to make PTA "more" flow-sensitive is to partition the function
into regions (basically represent the function as a series of function calls
to its parts).

For the issue above there's the long-standing issue of splitting escapes
from function return from escapes to functions called to properly represent
local variable lifetime.

That said, your simpler patch still relies on up-to-date dominators, sth
not guaranteed or required previously.


Ah, dom_info_available_p does not mean that the available information is 
up-to-date? :-(



We might consider implementing a separate (region-based) analysis
adjusting/pruning points-to information with flow-sensitive knowlege.
This might even work when done from inside PTA as post-processing.


--
Marc Glisse


Re: [PATCH] PR90424 - lowpart vector set recognition

2019-05-14 Thread Richard Biener
On Tue, 14 May 2019, Richard Sandiford wrote:

> Richard Biener  writes:
> > The following makes SSA rewrite (update-address-taken) recognize
> > sets of aligned sub-vectors in aligned position
> > (v2qi into v16qi, but esp. v8qi into v16qi).  It uses the
> > BIT_INSERT_EXPR support for this, enabling that for vector
> > typed values.  This makes us turn for example
> >
> > typedef unsigned char v16qi __attribute__((vector_size(16)));
> > v16qi load (const void *p)
> > {
> >   v16qi r;
> >   __builtin_memcpy (, p, 8);
> >   return r;
> > }
> >
> > into the following
> >
> > load (const void * p)
> > {
> >   v16qi r;
> >   long unsigned int _3;
> >   v16qi _5;
> >   vector(8) unsigned char _7;
> >
> >:
> >   _3 = MEM[(char * {ref-all})p_2(D)];
> >   _7 = VIEW_CONVERT_EXPR(_3);
> >   r_9 = BIT_INSERT_EXPR ;
> >   _5 = r_9;
> >   return _5;
> >
> > this isn't yet nicely expanded since the BIT_INSERT_EXPR
> > expansion simply goes through store_bit_field and there's
> > no vector-mode vec_set.
> >
> > Similar as to the single-element insert SSA rewrite already
> > handles the transform is conditional on the involved
> > vector types having non-BLKmode.  This is somewhat bad
> > since the transform is supposed to enable SSA optimizations
> > by rewriting memory vectors into SSA form.  Since splitting
> > of larger generic vectors happens very much later only
> > this pessimizes their use.  But the BIT_INSERT_EXPR
> > expansion doesn't cope with BLKmode entities (source or
> > destination).
> >
> > Extending BIT_INSERT_EXPR this way seems natural given
> > the support of CONSTRUCTORs with smaller vectors.
> > BIT_FIELD_REF isn't particularly restricted so can be
> > used to extract sub-vectors as well.
> >
> > Code generation is as bad as before (RTL expansion eventually
> > spills) but SSA optimizations are enabled on less trivial
> > testcases.
> >
> > Boostrap / regtest running on x86_64-unknown-linux-gnu.
> >
> > Comments?
> >
> > Richard.
> >
> > 2019-05-14  Richard Biener  
> >
> > PR tree-optimization/90424
> > * tree-ssa.c (non_rewritable_lvalue_p): Handle inserts from
> > aligned subvectors.
> > (execute_update_addresses_taken): Likewise.
> > * tree-cfg.c (verify_gimple_assign_ternary): Likewise.
> >
> > * g++.target/i386/pr90424-1.C: New testcase.
> > * g++.target/i386/pr90424-2.C: Likewise.
> >
> > Index: gcc/tree-ssa.c
> > ===
> > --- gcc/tree-ssa.c  (revision 271155)
> > +++ gcc/tree-ssa.c  (working copy)
> > @@ -1521,14 +1521,28 @@ non_rewritable_lvalue_p (tree lhs)
> >if (DECL_P (decl)
> >   && VECTOR_TYPE_P (TREE_TYPE (decl))
> >   && TYPE_MODE (TREE_TYPE (decl)) != BLKmode
> > - && operand_equal_p (TYPE_SIZE_UNIT (TREE_TYPE (lhs)),
> > - TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (decl))), 0)
> > + && multiple_of_p (sizetype,
> > +   TYPE_SIZE_UNIT (TREE_TYPE (decl)),
> > +   TYPE_SIZE_UNIT (TREE_TYPE (lhs)))
> >   && known_ge (mem_ref_offset (lhs), 0)
> >   && known_gt (wi::to_poly_offset (TYPE_SIZE_UNIT (TREE_TYPE (decl))),
> >mem_ref_offset (lhs))
> >   && multiple_of_p (sizetype, TREE_OPERAND (lhs, 1),
> > TYPE_SIZE_UNIT (TREE_TYPE (lhs
> > -   return false;
> > +   {
> > + if (operand_equal_p (TYPE_SIZE_UNIT (TREE_TYPE (lhs)),
> > +  TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (decl))),
> > +  0))
> > +   return false;
> > + /* For sub-vector inserts the insert vector mode has to be
> > +supported.  */
> > + tree vtype = build_vector_type
> > + (TREE_TYPE (TREE_TYPE (decl)),
> > +  tree_to_uhwi (TYPE_SIZE (TREE_TYPE (lhs)))
> > +  / tree_to_uhwi (TYPE_SIZE (TREE_TYPE (TREE_TYPE (decl);
> 
> AFAICT nothing guarantees tree_fits_uhwi_p for the lhs, so this isn't
> poly-int clean.  Is there a guarantee that lhs is a multiple of the
> element size even for integers?  Or are we just relying on a vector
> of 0 elements being rejected?

That it is a multiple of the element size is tested indirectly by

> > + && multiple_of_p (sizetype, 
> > +   TYPE_SIZE_UNIT (TREE_TYPE (decl)),
> > +   TYPE_SIZE_UNIT (TREE_TYPE (lhs)))

given 'decl' has vector type.  That also guarantees non-zero size?

But yes, I guess TYPE_SIZE_UNIT might be a poly-int.

> Maybe something like:
> 
> tree elt_type = TREE_TYPE (TREE_TYPE (decl));
> unsigned int elt_bits = tree_to_uhwi (TYPE_SIZE (elt_type));
> poly_uint64 lhs_bits, nelts;
> if (poly_int_tree_p (TYPE_SIZE (TREE_TYPE (lhs)), _bits)
> && multiple_p (lhs_bits, elt_bits, ))
> {
> tree vtype = build_vector_type (elt_type, nelts);

This should work.

Of course it even more so makes duplicating all the bits in
two places ugly :/

I 

[DRIVER PATCH]: Nadger subprocess argv[0]

2019-05-14 Thread Nathan Sidwell
This patch nadgers the driver's subprocess names to include the driver 
name. It results in more informative error messages.  For instance, 
rather than:


  >./xg++ -B./ frob.cc -c -fdump-tree-nope
  cc1plus: error: unrecognized command line option '-fdump-tree-nope'

we get:

  >./xg++ -B./ frob.cc -c -fdump-tree-nope
  xg++(cc1plus): error: unrecognized command line option '-fdump-tree-nope'

Thereby cluing the user into this being a compiler error.  (When this 
error is buried inside a build log, the poor user can be more confused 
as to what this cc1plus thing might be).


I achieve this by taking advantage of the subprocess spawning taking 
separate arguments for the program to exec, and the argv[0] value passed 
to that program.  Because subprocesses can use argv[0] to locate 
themselves I propagate the directory name, so that remains as before.


When using valgrind, this substitution is not performed, because 
valgrind relies on argv[0] being the program pathname.


The -v output is unaffected, as that is emitted before altering argv[0]. 
 argv[0] is also restored after spawning.


This then allows us to elide process_command's check of whether the 
input file exists.  That's optimizing for failure, but I suspect is 
desired merely to avoid an error of the form:

  cc1plus: fatal error: frob.cc: No such file or directory

As you can see process_command does some special handling for lto & 
@files, which is kind of icky and now goes away.  We get:

  xg++(cc1plus): fatal error: frob.cc: No such file or directory

Thoughts? Ok? Stupid idea?

nathan

--
Nathan Sidwell
2019-05-14  Nathan Sidwell  

	* gcc.c (execute): Splice current executable name into spawned
	argv[0] for better subprocess diagnostics.
	(process_command): Do not check if input file exists.

	* lib/prune.exp (prune_gcc_output): Adjust collect regexps.

Index: gcc/gcc.c
===
--- gcc/gcc.c	(revision 271131)
+++ gcc/gcc.c	(working copy)
@@ -3206,6 +3206,48 @@ execute (void)
   int err;
   const char *string = commands[i].argv[0];
 
+  if (commands[i].argv == argbuf.address ())
+	{
+	  /* Munge argv[0], the one given in the exec'd command's
+	 argv, to include information about from whence it was
+	 spawned.  We preserve the directory component so the
+	 command can determine where it is, but not what it was
+	 called.  Thus its otherwise-unlocated errors specify
+	 something like 'g++(cc1plus)' rather than plain
+	 'cc1plus'.  Only do this if argv is the argbuf address,
+	 so as to not interfere with valgrind insertion.  */
+	  size_t slen = strlen (string);
+	  size_t plen = strlen (progname);
+	  size_t tlen = strlen (commands[i].prog);
+
+	  /* Remove the filename component from the path.  */
+	  while (slen && !IS_DIR_SEPARATOR (string[slen-1]))
+	slen--;
+	  char *ren = XNEWVEC (char, slen + plen + tlen + 3);
+	  size_t off = 0;
+
+	  /* Copy directory, including final dir separator.  */
+	  memcpy (ren + off, string, slen);
+	  off += slen;
+	  /* Append our progname.  */
+	  memcpy (ren + off, progname, plen);
+	  off += plen;
+
+	  ren[off++] = '(';
+
+	  /* Append the plain progname (lacking any os-specific
+	 suffix).  */
+	  memcpy (ren + off, commands[i].prog, tlen);
+	  off += tlen;
+
+	  ren[off++] = ')';
+
+	  /* And a NUL.  */
+	  ren[off++] = 0;
+
+	  commands[i].argv[0] = ren;
+	}
+
   errmsg = pex_run (pex,
 			((i + 1 == n_commands ? PEX_LAST : 0)
 			 | (string == commands[i].prog ? PEX_SEARCH : 0)),
@@ -3220,6 +3262,12 @@ execute (void)
 		   string, errmsg);
 	}
 
+  if (commands[i].argv[0] != string)
+	{
+	  free (const_cast  (commands[i].argv[0]));
+	  commands[i].argv[0] = string;
+	}
+
   if (i && string != commands[i].prog)
 	free (CONST_CAST (char *, string));
 }
@@ -4561,44 +4609,11 @@ process_command (unsigned int decoded_op
   if (decoded_options[j].opt_index == OPT_SPECIAL_input_file)
 	{
 	  const char *arg = decoded_options[j].arg;
-  const char *p = strrchr (arg, '@');
-  char *fname;
-	  long offset;
-	  int consumed;
 #ifdef HAVE_TARGET_OBJECT_SUFFIX
 	  arg = convert_filename (arg, 0, access (arg, F_OK));
 #endif
-	  /* For LTO static archive support we handle input file
-	 specifications that are composed of a filename and
-	 an offset like FNAME@OFFSET.  */
-	  if (p
-	  && p != arg
-	  && sscanf (p, "@%li%n", , ) >= 1
-	  && strlen (p) == (unsigned int)consumed)
-	{
-  fname = (char *)xmalloc (p - arg + 1);
-  memcpy (fname, arg, p - arg);
-  fname[p - arg] = '\0';
-	  /* Only accept non-stdin and existing FNAME parts, otherwise
-		 try with the full name.  */
-	  if (strcmp (fname, "-") == 0 || access (fname, F_OK) < 0)
-		{
-		  free (fname);
-		  fname = xstrdup (arg);
-		}
-	}
-	  else
-	fname = xstrdup (arg);
-
-  if (strcmp (fname, "-") != 0 && access 

[RFC, PATCH] Don't introduce useless edge splits unless in PRE

2019-05-14 Thread Vladislav Ivanishin
Hi!

The split_critical_edges() function has multiple uses and it seems, a
portion of its code was added to work only when called from tree-ssa-pre
but right now it is executed regardless of the caller.

The below patch survives bootstrap and regression testing on
x86_64-pc-linux-gnu.  Does it make sense?

>From d6d843653b82f277e780f19f2d2b3cc3125db8b5 Mon Sep 17 00:00:00 2001
From: Vladislav Ivanishin 
Date: Wed, 8 May 2019 20:29:34 +0300
Subject: [PATCH] Don't introduce useless edge splits unless in pre

gcc/Changelog:

* tree-cfg.h (split_critical_edges): Add in_pre_p parameter with default
value false to declaration.
* tree-cfg.c (split_critical_edges): Don't split non-critical edges if
in_pre_p is false.  Fix whitespace.
* tree-ssa-pre.c (pass_pre::execute): Pass in_pre_p = true to
split_critical_edges.
---
 gcc/tree-cfg.c | 14 --
 gcc/tree-cfg.h |  2 +-
 gcc/tree-ssa-pre.c |  2 +-
 3 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/gcc/tree-cfg.c b/gcc/tree-cfg.c
index 587408150fb..11683e63cd1 100644
--- a/gcc/tree-cfg.c
+++ b/gcc/tree-cfg.c
@@ -8870,10 +8870,11 @@ struct cfg_hooks gimple_cfg_hooks = {
 };
 
 
-/* Split all critical edges.  */
+/* Split all critical edges.  Split some extra edges to help PRE if IN_PRE_P is
+   true.  */
 
 unsigned int
-split_critical_edges (void)
+split_critical_edges (bool in_pre_p /* = false */)
 {
   basic_block bb;
   edge e;
@@ -8896,11 +8897,12 @@ split_critical_edges (void)
 	 end by control flow statements, such as RESX.
 	 Go ahead and split them too.  This matches the logic in
 	 gimple_find_edge_insert_loc.  */
-	  else if ((!single_pred_p (e->dest)
-	|| !gimple_seq_empty_p (phi_nodes (e->dest))
-		|| e->dest == EXIT_BLOCK_PTR_FOR_FN (cfun))
+	  else if (in_pre_p
+		   && (!single_pred_p (e->dest)
+		   || !gimple_seq_empty_p (phi_nodes (e->dest))
+		   || e->dest == EXIT_BLOCK_PTR_FOR_FN (cfun))
 		   && e->src != ENTRY_BLOCK_PTR_FOR_FN (cfun)
-	   && !(e->flags & EDGE_ABNORMAL))
+		   && !(e->flags & EDGE_ABNORMAL))
 	{
 	  gimple_stmt_iterator gsi;
 
diff --git a/gcc/tree-cfg.h b/gcc/tree-cfg.h
index 212f5ff5919..3fbf983b36a 100644
--- a/gcc/tree-cfg.h
+++ b/gcc/tree-cfg.h
@@ -105,7 +105,7 @@ extern void extract_true_false_edges_from_block (basic_block, edge *, edge *);
 extern tree find_case_label_for_value (const gswitch *switch_stmt, tree val);
 extern edge find_taken_edge_switch_expr (const gswitch *switch_stmt, tree val);
 extern unsigned int execute_fixup_cfg (void);
-extern unsigned int split_critical_edges (void);
+extern unsigned int split_critical_edges (bool in_pre_p = false);
 extern basic_block insert_cond_bb (basic_block, gimple *, gimple *,
    profile_probability);
 extern bool gimple_find_sub_bbs (gimple_seq, gimple_stmt_iterator *);
diff --git a/gcc/tree-ssa-pre.c b/gcc/tree-ssa-pre.c
index 09335faa6a9..2c3645b5301 100644
--- a/gcc/tree-ssa-pre.c
+++ b/gcc/tree-ssa-pre.c
@@ -4195,7 +4195,7 @@ pass_pre::execute (function *fun)
   /* This has to happen before VN runs because
  loop_optimizer_init may create new phis, etc.  */
   loop_optimizer_init (LOOPS_NORMAL);
-  split_critical_edges ();
+  split_critical_edges (/*in_pre_p=*/true);
   scev_initialize ();
   calculate_dominance_info (CDI_DOMINATORS);
 
-- 
2.21.0


If it does, then it uncovers what I think might be a latent bug in the
late uninit pass.

Without the patch, the crited pass inserts an empty basic block that
almost magically prevents the uninit pass from reporting a false
positive.

$ gcc -c -fdump-tree-all -fgimple -O -Wuninitialized gimple-fp-hfs.c

int __GIMPLE (ssa,startwith("uninit1"))
probe_hfsplus ()
{
  int D_1913;
  unsigned int ext_block_start;
  int ext;
  unsigned int _1;
  int _14;

  __BB(2):
  ext_7 = 0;
  goto __BB4;

  __BB(3):
  ext_block_start_11 = 1u;
  _1 = 0u;
  ext_13 = ext_4 + 1;
  goto __BB4;

  __BB(4,loop_header(1)):
  ext_block_start_2 = __PHI (__BB2: ext_block_start_8(D), __BB3: 
ext_block_start_11);
  ext_4 = __PHI (__BB2: 0, __BB3: ext_13);
  if (ext_4 <= 7)
goto __BB3;
  else
goto __BB5;

  __BB(5):
  ext_block_start_3 = __PHI (__BB4: ext_block_start_2);
  _14 = (int) ext_block_start_3;
  return _14;

}



(no warning)

--- gimple-fp-hfs.c.170t.veclower21
+++ gimple-fp-hfs.c.194t.crited1
@@ -24,10 +24,12 @@
   if (ext_4 <= 7)
 goto ; [INV]
   else
-goto ; [INV]
+goto ; [INV]
+
+   :

:
-  # ext_block_start_3 = PHI 
+  # ext_block_start_3 = PHI 
   _14 = (int) ext_block_start_3;
   return _14;

And with the patch, the useless bb 6 is not inserted and the following
is produced:

gimple-fp-hfs.c: In function 'probe_hfsplus':
gimple-fp-hfs.c:5:16: warning: 'ext_block_start' may be used uninitialized in 
this function [-Wmaybe-uninitialized]
5 |   unsigned int ext_block_start;
  |^~~

If this patch is OK, I'll try to fix the uninit pass next.

-- 

[PATCH] GCC 8 Backports for AIX

2019-05-14 Thread David Edelsohn
I would like to backport two AIX-specific patches to GCC 8.  These
both fix bugs that generate wrong code on AIX.

1) XCOFF private read only data section

2) Follow AIX ABI to not pass FP structures in FPRs.

These patches have been on trunk / GCC 9 for months.

Bootstrapped gcc-8-branch on powerpc-ibm-aix7.2.0.0.

Is this okay?

Thanks, David

* xcoffout.h (xcoff_private_rodata_section_name): Declare.
* xcoffout.c (xcoff_private_rodata_section_name): Define.
* config/rs6000/rs6000.c (rs6000_xcoff_asm_init_sections): Create
read_only_private_data_section using xcoff_private_rodata_section_name.
(rs6000_xcoff_file_start): Generate xcoff_private_rodata_section_name.

PR target/61976
* config/rs6000/rs6000.c (rs6000_function_arg): Don't pass aggregates
in FPRs on AIX. Ensure type is non-NULL.
(rs6000_arg_partial_bytes): Same.

Index: xcoffout.c
===
--- xcoffout.c  (revision 271131)
+++ xcoffout.c  (working copy)
@@ -64,6 +64,7 @@

 char *xcoff_bss_section_name;
 char *xcoff_private_data_section_name;
+char *xcoff_private_rodata_section_name;
 char *xcoff_tls_data_section_name;
 char *xcoff_tbss_section_name;
 char *xcoff_read_only_section_name;
Index: xcoffout.h
===
--- xcoffout.h  (revision 271131)
+++ xcoffout.h  (working copy)
@@ -127,6 +127,7 @@

 extern char *xcoff_bss_section_name;
 extern char *xcoff_private_data_section_name;
+extern char *xcoff_private_rodata_section_name;
 extern char *xcoff_tls_data_section_name;
 extern char *xcoff_tbss_section_name;
 extern char *xcoff_read_only_section_name;
Index: config/rs6000/rs6000.c
===
--- config/rs6000/rs6000.c  (revision 271131)
+++ config/rs6000/rs6000.c  (working copy)
@@ -12615,7 +12615,9 @@ rs6000_function_arg (cumulative_args_t cum_v, mach
   if (elt_mode == TDmode && (cum->fregno % 2) == 1)
cum->fregno++;

-  if (USE_FP_FOR_ARG_P (cum, elt_mode))
+  if (USE_FP_FOR_ARG_P (cum, elt_mode)
+ && !(TARGET_AIX && !TARGET_ELF
+  && type != NULL && AGGREGATE_TYPE_P (type)))
{
  rtx rvec[GP_ARG_NUM_REG + AGGR_ARG_NUM_REG + 1];
  rtx r, off;
@@ -12751,7 +12753,9 @@ rs6000_arg_partial_bytes (cumulative_args_t cum_v,

   align_words = rs6000_parm_start (mode, type, cum->words);

-  if (USE_FP_FOR_ARG_P (cum, elt_mode))
+  if (USE_FP_FOR_ARG_P (cum, elt_mode)
+  && !(TARGET_AIX && !TARGET_ELF
+  && type != NULL && AGGREGATE_TYPE_P (type)))
 {
   unsigned long n_fpreg = (GET_MODE_SIZE (elt_mode) + 7) >> 3;

@@ -34218,6 +34222,10 @@ rs6000_xcoff_asm_init_sections (void)
   rs6000_xcoff_output_readwrite_section_asm_op,
   _private_data_section_name);

+  read_only_private_data_section
+= get_unnamed_section (0, rs6000_xcoff_output_readonly_section_asm_op,
+  _private_rodata_section_name);
+
   tls_data_section
 = get_unnamed_section (SECTION_TLS,
   rs6000_xcoff_output_tls_section_asm_op,
@@ -34228,10 +34236,6 @@ rs6000_xcoff_asm_init_sections (void)
   rs6000_xcoff_output_tls_section_asm_op,
   _private_data_section_name);

-  read_only_private_data_section
-= get_unnamed_section (0, rs6000_xcoff_output_readonly_section_asm_op,
-  _private_data_section_name);
-
   toc_section
 = get_unnamed_section (0, rs6000_xcoff_output_toc_section_asm_op, NULL);

@@ -34412,6 +34416,8 @@ rs6000_xcoff_file_start (void)
   main_input_filename, ".bss_");
   rs6000_gen_section_name (_private_data_section_name,
   main_input_filename, ".rw_");
+  rs6000_gen_section_name (_private_rodata_section_name,
+  main_input_filename, ".rop_");
   rs6000_gen_section_name (_read_only_section_name,
   main_input_filename, ".ro_");
   rs6000_gen_section_name (_tls_data_section_name,


Re: [PATCH] PR90424 - lowpart vector set recognition

2019-05-14 Thread Richard Sandiford
Richard Biener  writes:
> The following makes SSA rewrite (update-address-taken) recognize
> sets of aligned sub-vectors in aligned position
> (v2qi into v16qi, but esp. v8qi into v16qi).  It uses the
> BIT_INSERT_EXPR support for this, enabling that for vector
> typed values.  This makes us turn for example
>
> typedef unsigned char v16qi __attribute__((vector_size(16)));
> v16qi load (const void *p)
> {
>   v16qi r;
>   __builtin_memcpy (, p, 8);
>   return r;
> }
>
> into the following
>
> load (const void * p)
> {
>   v16qi r;
>   long unsigned int _3;
>   v16qi _5;
>   vector(8) unsigned char _7;
>
>:
>   _3 = MEM[(char * {ref-all})p_2(D)];
>   _7 = VIEW_CONVERT_EXPR(_3);
>   r_9 = BIT_INSERT_EXPR ;
>   _5 = r_9;
>   return _5;
>
> this isn't yet nicely expanded since the BIT_INSERT_EXPR
> expansion simply goes through store_bit_field and there's
> no vector-mode vec_set.
>
> Similar as to the single-element insert SSA rewrite already
> handles the transform is conditional on the involved
> vector types having non-BLKmode.  This is somewhat bad
> since the transform is supposed to enable SSA optimizations
> by rewriting memory vectors into SSA form.  Since splitting
> of larger generic vectors happens very much later only
> this pessimizes their use.  But the BIT_INSERT_EXPR
> expansion doesn't cope with BLKmode entities (source or
> destination).
>
> Extending BIT_INSERT_EXPR this way seems natural given
> the support of CONSTRUCTORs with smaller vectors.
> BIT_FIELD_REF isn't particularly restricted so can be
> used to extract sub-vectors as well.
>
> Code generation is as bad as before (RTL expansion eventually
> spills) but SSA optimizations are enabled on less trivial
> testcases.
>
> Boostrap / regtest running on x86_64-unknown-linux-gnu.
>
> Comments?
>
> Richard.
>
> 2019-05-14  Richard Biener  
>
>   PR tree-optimization/90424
>   * tree-ssa.c (non_rewritable_lvalue_p): Handle inserts from
>   aligned subvectors.
>   (execute_update_addresses_taken): Likewise.
>   * tree-cfg.c (verify_gimple_assign_ternary): Likewise.
>
>   * g++.target/i386/pr90424-1.C: New testcase.
>   * g++.target/i386/pr90424-2.C: Likewise.
>
> Index: gcc/tree-ssa.c
> ===
> --- gcc/tree-ssa.c(revision 271155)
> +++ gcc/tree-ssa.c(working copy)
> @@ -1521,14 +1521,28 @@ non_rewritable_lvalue_p (tree lhs)
>if (DECL_P (decl)
> && VECTOR_TYPE_P (TREE_TYPE (decl))
> && TYPE_MODE (TREE_TYPE (decl)) != BLKmode
> -   && operand_equal_p (TYPE_SIZE_UNIT (TREE_TYPE (lhs)),
> -   TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (decl))), 0)
> +   && multiple_of_p (sizetype,
> + TYPE_SIZE_UNIT (TREE_TYPE (decl)),
> + TYPE_SIZE_UNIT (TREE_TYPE (lhs)))
> && known_ge (mem_ref_offset (lhs), 0)
> && known_gt (wi::to_poly_offset (TYPE_SIZE_UNIT (TREE_TYPE (decl))),
>  mem_ref_offset (lhs))
> && multiple_of_p (sizetype, TREE_OPERAND (lhs, 1),
>   TYPE_SIZE_UNIT (TREE_TYPE (lhs
> - return false;
> + {
> +   if (operand_equal_p (TYPE_SIZE_UNIT (TREE_TYPE (lhs)),
> +TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (decl))),
> +0))
> + return false;
> +   /* For sub-vector inserts the insert vector mode has to be
> +  supported.  */
> +   tree vtype = build_vector_type
> +   (TREE_TYPE (TREE_TYPE (decl)),
> +tree_to_uhwi (TYPE_SIZE (TREE_TYPE (lhs)))
> +/ tree_to_uhwi (TYPE_SIZE (TREE_TYPE (TREE_TYPE (decl);

AFAICT nothing guarantees tree_fits_uhwi_p for the lhs, so this isn't
poly-int clean.  Is there a guarantee that lhs is a multiple of the
element size even for integers?  Or are we just relying on a vector
of 0 elements being rejected?

Maybe something like:

  tree elt_type = TREE_TYPE (TREE_TYPE (decl));
  unsigned int elt_bits = tree_to_uhwi (TYPE_SIZE (elt_type));
  poly_uint64 lhs_bits, nelts;
  if (poly_int_tree_p (TYPE_SIZE (TREE_TYPE (lhs)), _bits)
  && multiple_p (lhs_bits, elt_bits, ))
{
  tree vtype = build_vector_type (elt_type, nelts);

?  

Thanks,
Richard


Re: [PATCH] Fix aarch64 exception handling (PR c++/59813)

2019-05-14 Thread Michael Matz
Hi,

On Tue, 14 May 2019, Jakub Jelinek wrote:

> In https://gcc.gnu.org/ml/gcc-patches/2019-05/msg00484.html I've posted 
> a patch that would set it earlier (or it could be set during 
> gimplification and propagated during inlining, would need to be in 
> cfun->calls_eh_return instead of crtl->calls_eh_return) and then targets 
> for which we do not want to bother with it or where it is not beneficial 
> to have tail calls in functions that call __builtin_eh_return (as I said 
> in the thread, e.g. on x86_64-linux it is both smaller and faster),

I really think you're over-obsessing with the optimization in this case. 
Given the general slowness of DWARF CFI interpretation (which always 
happens before eh_return) any optimization re tail-calls in any of 
_Unwind_RaiseException _Unwind_ForcedUnwind _Unwind_Resume or 
_Unwind_Resume_or_Rethrow (of which only the latter looks amenable) seems 
a bit silly.  Disable tail-calls whenever builtin_eh_return is seen in the 
gimplifier (in all four functions in the world!), and be done.


Ciao,
Michael.


[PATCH] PR90424 - lowpart vector set recognition

2019-05-14 Thread Richard Biener


The following makes SSA rewrite (update-address-taken) recognize
sets of aligned sub-vectors in aligned position
(v2qi into v16qi, but esp. v8qi into v16qi).  It uses the
BIT_INSERT_EXPR support for this, enabling that for vector
typed values.  This makes us turn for example

typedef unsigned char v16qi __attribute__((vector_size(16)));
v16qi load (const void *p)
{
  v16qi r;
  __builtin_memcpy (, p, 8);
  return r;
}

into the following

load (const void * p)
{
  v16qi r;
  long unsigned int _3;
  v16qi _5;
  vector(8) unsigned char _7;

   :
  _3 = MEM[(char * {ref-all})p_2(D)];
  _7 = VIEW_CONVERT_EXPR(_3);
  r_9 = BIT_INSERT_EXPR ;
  _5 = r_9;
  return _5;

this isn't yet nicely expanded since the BIT_INSERT_EXPR
expansion simply goes through store_bit_field and there's
no vector-mode vec_set.

Similar as to the single-element insert SSA rewrite already
handles the transform is conditional on the involved
vector types having non-BLKmode.  This is somewhat bad
since the transform is supposed to enable SSA optimizations
by rewriting memory vectors into SSA form.  Since splitting
of larger generic vectors happens very much later only
this pessimizes their use.  But the BIT_INSERT_EXPR
expansion doesn't cope with BLKmode entities (source or
destination).

Extending BIT_INSERT_EXPR this way seems natural given
the support of CONSTRUCTORs with smaller vectors.
BIT_FIELD_REF isn't particularly restricted so can be
used to extract sub-vectors as well.

Code generation is as bad as before (RTL expansion eventually
spills) but SSA optimizations are enabled on less trivial
testcases.

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

Comments?

Richard.

2019-05-14  Richard Biener  

PR tree-optimization/90424
* tree-ssa.c (non_rewritable_lvalue_p): Handle inserts from
aligned subvectors.
(execute_update_addresses_taken): Likewise.
* tree-cfg.c (verify_gimple_assign_ternary): Likewise.

* g++.target/i386/pr90424-1.C: New testcase.
* g++.target/i386/pr90424-2.C: Likewise.

Index: gcc/tree-ssa.c
===
--- gcc/tree-ssa.c  (revision 271155)
+++ gcc/tree-ssa.c  (working copy)
@@ -1521,14 +1521,28 @@ non_rewritable_lvalue_p (tree lhs)
   if (DECL_P (decl)
  && VECTOR_TYPE_P (TREE_TYPE (decl))
  && TYPE_MODE (TREE_TYPE (decl)) != BLKmode
- && operand_equal_p (TYPE_SIZE_UNIT (TREE_TYPE (lhs)),
- TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (decl))), 0)
+ && multiple_of_p (sizetype,
+   TYPE_SIZE_UNIT (TREE_TYPE (decl)),
+   TYPE_SIZE_UNIT (TREE_TYPE (lhs)))
  && known_ge (mem_ref_offset (lhs), 0)
  && known_gt (wi::to_poly_offset (TYPE_SIZE_UNIT (TREE_TYPE (decl))),
   mem_ref_offset (lhs))
  && multiple_of_p (sizetype, TREE_OPERAND (lhs, 1),
TYPE_SIZE_UNIT (TREE_TYPE (lhs
-   return false;
+   {
+ if (operand_equal_p (TYPE_SIZE_UNIT (TREE_TYPE (lhs)),
+  TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (decl))),
+  0))
+   return false;
+ /* For sub-vector inserts the insert vector mode has to be
+supported.  */
+ tree vtype = build_vector_type
+ (TREE_TYPE (TREE_TYPE (decl)),
+  tree_to_uhwi (TYPE_SIZE (TREE_TYPE (lhs)))
+  / tree_to_uhwi (TYPE_SIZE (TREE_TYPE (TREE_TYPE (decl);
+ if (TYPE_MODE (vtype) != BLKmode)
+   return false;
+   }
 }
 
   /* A vector-insert using a BIT_FIELD_REF is rewritable using
@@ -1866,9 +1880,9 @@ execute_update_addresses_taken (void)
&& bitmap_bit_p (suitable_for_renaming, DECL_UID (sym))
&& VECTOR_TYPE_P (TREE_TYPE (sym))
&& TYPE_MODE (TREE_TYPE (sym)) != BLKmode
-   && operand_equal_p (TYPE_SIZE_UNIT (TREE_TYPE (lhs)),
-   TYPE_SIZE_UNIT
- (TREE_TYPE (TREE_TYPE (sym))), 0)
+   && multiple_of_p (sizetype,
+ TYPE_SIZE_UNIT (TREE_TYPE (sym)),
+ TYPE_SIZE_UNIT (TREE_TYPE (lhs)))
&& tree_fits_uhwi_p (TREE_OPERAND (lhs, 1))
&& tree_int_cst_lt (TREE_OPERAND (lhs, 1),
TYPE_SIZE_UNIT (TREE_TYPE (sym)))
@@ -1879,7 +1893,16 @@ execute_update_addresses_taken (void)
if (! types_compatible_p (TREE_TYPE (val),
  TREE_TYPE (TREE_TYPE (sym
  {
-   tree tem = make_ssa_name (TREE_TYPE (TREE_TYPE (sym)));
+   tree temtype = TREE_TYPE (TREE_TYPE (sym));
+   if (!operand_equal_p 

[PATCH] Reduce header dependencies in

2019-05-14 Thread Jonathan Wakely

* include/std/iterator: Include  instead of  and
.

This makes  5kloc smaller!

Tested powerpc64le-linux, committed to trunk.

commit 32a8a4b2518030b683561d26ef64c301b46deb5a
Author: Jonathan Wakely 
Date:   Thu Feb 23 20:13:37 2017 +

Reduce header dependencies in 

* include/std/iterator: Include  instead of  and
.

diff --git a/libstdc++-v3/include/std/iterator 
b/libstdc++-v3/include/std/iterator
index 9d9e19c4c6b..28e7c65a9e5 100644
--- a/libstdc++-v3/include/std/iterator
+++ b/libstdc++-v3/include/std/iterator
@@ -61,8 +61,7 @@
 #include 
 #include 
 #include 
-#include 
-#include 
+#include 
 #include 
 #include 
 #include 


[PATCH][gimplefe] Add __VIEW_CONVERT parsing

2019-05-14 Thread Richard Biener


For vector testcases this is very much required (as others, coming).

It also seems to handle __VIEW_CONVERT in a component-reference
chain just fine though handling this wasn't the original intention.

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

Richard.

2019-05-14  Richard Biener  

* gimple-parser.c (c_parser_gimple_statement): Remove
questionable auto-promotion to VIEW_CONVERT_EXPR.
(c_parser_gimple_typespec): Split out from __MEM parsing.
(c_parser_gimple_postfix_expression): Handle __VIEW_CONVERT.
* tree-pretty-print.c (dump_generic_node): Dump VIEW_CONVERT_EXPR
as __VIEW_CONVERT with -gimple.

* gcc.dg/gimplefe-40.c: New testcase.

Index: gcc/c/gimple-parser.c
===
--- gcc/c/gimple-parser.c   (revision 271155)
+++ gcc/c/gimple-parser.c   (working copy)
@@ -724,14 +724,8 @@ c_parser_gimple_statement (gimple_parser
  && rhs.value != error_mark_node)
{
  enum tree_code code = NOP_EXPR;
- if (VECTOR_TYPE_P (TREE_TYPE (lhs.value)))
-   {
- code = VIEW_CONVERT_EXPR;
- rhs.value = build1 (VIEW_CONVERT_EXPR,
- TREE_TYPE (lhs.value), rhs.value);
-   }
- else if (FLOAT_TYPE_P (TREE_TYPE (lhs.value))
-  && ! FLOAT_TYPE_P (TREE_TYPE (rhs.value)))
+ if (FLOAT_TYPE_P (TREE_TYPE (lhs.value))
+ && ! FLOAT_TYPE_P (TREE_TYPE (rhs.value)))
code = FLOAT_EXPR;
  else if (! FLOAT_TYPE_P (TREE_TYPE (lhs.value))
   && FLOAT_TYPE_P (TREE_TYPE (rhs.value)))
@@ -1247,6 +1241,36 @@ c_parser_gimple_call_internal (gimple_pa
   return expr;
 }
 
+/* Parse '<' type [',' alignment] '>' and return a type on success
+   and NULL_TREE on error.  */
+
+static tree
+c_parser_gimple_typespec (gimple_parser )
+{
+  struct c_type_name *type_name = NULL;
+  tree alignment = NULL_TREE;
+  if (c_parser_require (parser, CPP_LESS, "expected %<<%>"))
+{
+  type_name = c_parser_type_name (parser);
+  /* Optional alignment.  */
+  if (c_parser_next_token_is (parser, CPP_COMMA))
+   {
+ c_parser_consume_token (parser);
+ alignment
+ = c_parser_gimple_postfix_expression (parser).value;
+   }
+  c_parser_skip_until_found (parser,
+CPP_GREATER, "expected %<>%>");
+}
+  if (!type_name)
+return NULL_TREE;
+  tree tem;
+  tree type = groktypename (type_name, , NULL);
+  if (alignment)
+type = build_aligned_type (type, tree_to_uhwi (alignment));
+  return type;
+}
+
 /* Parse gimple postfix expression.
 
gimple-postfix-expression:
@@ -1316,21 +1340,7 @@ c_parser_gimple_postfix_expression (gimp
   [ '+' number ] ')'  */
  location_t loc = c_parser_peek_token (parser)->location;
  c_parser_consume_token (parser);
- struct c_type_name *type_name = NULL;
- tree alignment = NULL_TREE;
- if (c_parser_require (parser, CPP_LESS, "expected %<<%>"))
-   {
- type_name = c_parser_type_name (parser);
- /* Optional alignment.  */
- if (c_parser_next_token_is (parser, CPP_COMMA))
-   {
- c_parser_consume_token (parser);
- alignment
-   = c_parser_gimple_postfix_expression (parser).value;
-   }
- c_parser_skip_until_found (parser,
-CPP_GREATER, "expected %<>%>");
-   }
+ tree type = c_parser_gimple_typespec (parser);
  struct c_expr ptr;
  ptr.value = error_mark_node;
  tree alias_off = NULL_TREE;
@@ -1378,19 +1388,33 @@ c_parser_gimple_postfix_expression (gimp
  c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
 "expected %<)%>");
}
- if (! type_name || c_parser_error (parser))
+ if (! type || c_parser_error (parser))
{
  c_parser_set_error (parser, false);
  return expr;
}
- tree tem = NULL_TREE;
- tree type = groktypename (type_name, , NULL);
- if (alignment)
-   type = build_aligned_type (type, tree_to_uhwi (alignment));
  expr.value = build2_loc (loc, MEM_REF,
   type, ptr.value, alias_off);
  break;
}
+ else if (strcmp (IDENTIFIER_POINTER (id), "__VIEW_CONVERT") == 0)
+   {
+ /* __VIEW_CONVERT '<' type-name [ ',' number ] '>'
+   '(' postfix-expression ')'  */
+ location_t loc = c_parser_peek_token (parser)->location;
+ 

[PATCH] Removing unused, non-standard function in _Rb_tree

2019-05-14 Thread Jonathan Wakely

* include/bits/stl_tree.h (_Rb_tree::erase(const Key*, const Key*)):
Remove unused, non-standard function.

As suggested in https://gcc.gnu.org/ml/libstdc++/2016-12/msg00100.html
I've removed this unused member.

Tested powerpc64le-linux, committed to trunk.


commit 4a182e12a8255450650b890cc378f57d37d194cf
Author: redi 
Date:   Tue May 14 12:19:10 2019 +

Removing unused, non-standard function in _Rb_tree

* include/bits/stl_tree.h (_Rb_tree::erase(const Key*, const Key*)):
Remove unused, non-standard function.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@271168 
138bc75d-0d04-0410-961f-82ee72b054a4

diff --git a/libstdc++-v3/include/bits/stl_tree.h 
b/libstdc++-v3/include/bits/stl_tree.h
index 7545ade3f7b..00e4a0cccbf 100644
--- a/libstdc++-v3/include/bits/stl_tree.h
+++ b/libstdc++-v3/include/bits/stl_tree.h
@@ -1231,6 +1231,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
_M_erase_aux(__position);
   }
 #endif
+
   size_type
   erase(const key_type& __x);
 
@@ -1253,8 +1254,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   erase(const_iterator __first, const_iterator __last)
   { _M_erase_aux(__first, __last); }
 #endif
-  void
-  erase(const key_type* __first, const key_type* __last);
 
   void
   clear() _GLIBCXX_NOEXCEPT
@@ -2533,16 +2532,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   return __old_size - size();
 }
 
-  template
-void
-_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
-erase(const _Key* __first, const _Key* __last)
-{
-  while (__first != __last)
-   erase(*__first++);
-}
-
   template
 typename _Rb_tree<_Key, _Val, _KeyOfValue,


Re: [PATCH] Make std::match_results::_M_resize more useful

2019-05-14 Thread Jonathan Wakely

On 04/12/18 14:30 +, Jonathan Wakely wrote:

As both callers of match_results::_M_resize(unsigned) immediately follow
it with a loop to update the value of each sub_match, that behaviour can
be moved into _M_resize itself. The first caller fills the container
with unmatched subs, which can be done with vector::assign, and the
second caller clears the container to establish a specific state, which
can be provided by a new member function specific to that purpose.

Tangentially, I also noticed that match_results::max_size() doesn't
account for the three special sub_match objects that are always present
in a fully established result state. This patch also fixes that.

* include/bits/regex.h (match_results::max_size()): Adjust return
value to account for prefix/suffix/unmatched subs.
(match_results::_M_resize(unsigned int)): Use _Base_type::assign to
reset the contained sub matches.
(match_results::_M_establish_failed_match(_Bi_iter)): Add new member
function to set result state following a failed match.
* include/bits/regex.tcc (__regex_algo_impl): Remove loop to set
sub_match states after _M_resize. Use _M_establish_failed_match.

Tested x86_64-linux.

Any objections?


Now committed to trunk.



commit 6a96a528102e1062dd2627b7eb8ddf26c43bc1e7
Author: Jonathan Wakely 
Date:   Tue Dec 4 13:21:26 2018 +

   Make std::match_results::_M_resize more useful

   As both callers of match_results::_M_resize(unsigned) immediately follow
   it with a loop to update the value of each sub_match, that behaviour can
   be moved into _M_resize itself. The first caller fills the container
   with unmatched subs, which can be done with vector::assign, and the
   second caller clears the container to establish a specific state, which
   can be provided by a new member function specific to that purpose.

   Tangentially, I also noticed that match_results::max_size() doesn't
   account for the three special sub_match objects that are always present
   in a fully established result state. This patch also fixes that.

   * include/bits/regex.h (match_results::max_size()): Adjust return
   value to account for prefix/suffix/unmatched subs.
   (match_results::_M_resize(unsigned int)): Use _Base_type::assign to
   reset the contained sub matches.
   (match_results::_M_establish_failed_match(_Bi_iter)): Add new member
   function to set result state following a failed match.
   * include/bits/regex.tcc (__regex_algo_impl): Remove loop to set
   sub_match states after _M_resize. Use _M_establish_failed_match.

diff --git a/libstdc++-v3/include/bits/regex.h 
b/libstdc++-v3/include/bits/regex.h
index af6fe3f0d79..d36ee33033d 100644
--- a/libstdc++-v3/include/bits/regex.h
+++ b/libstdc++-v3/include/bits/regex.h
@@ -1698,7 +1698,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11

  size_type
  max_size() const noexcept
-  { return _Base_type::max_size(); }
+  { return _Base_type::max_size() - 3; }

  /**
   * @brief Indicates if the %match_results contains no results.
@@ -1942,9 +1942,20 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
const basic_regex<_Cp, _Rp>&,
regex_constants::match_flag_type);

+  // Reset contents to __size unmatched sub_match objects
+  // (plus additional objects for prefix, suffix and unmatched sub).
  void
  _M_resize(unsigned int __size)
-  { _Base_type::resize(__size + 3); }
+  { _Base_type::assign(__size + 3, sub_match<_Bi_iter>{}); }
+
+  // Set state to a failed match for the given past-the-end iterator.
+  void
+  _M_establish_failed_match(_Bi_iter __end)
+  {
+   sub_match<_Bi_iter> __sm;
+   __sm.first = __sm.second = __end;
+   _Base_type::assign(3, __sm);
+  }

  const_reference
  _M_unmatched_sub() const
diff --git a/libstdc++-v3/include/bits/regex.tcc 
b/libstdc++-v3/include/bits/regex.tcc
index dcf660902bc..de0ce795b84 100644
--- a/libstdc++-v3/include/bits/regex.tcc
+++ b/libstdc++-v3/include/bits/regex.tcc
@@ -57,8 +57,6 @@ namespace __detail
  typename match_results<_BiIter, _Alloc>::_Base_type& __res = __m;
  __m._M_begin = __s;
  __m._M_resize(__re._M_automaton->_M_sub_count());
-  for (auto& __it : __res)
-   __it.matched = false;

  bool __ret;
  if ((__re.flags() & regex_constants::__polynomial)
@@ -109,12 +107,7 @@ namespace __detail
}
  else
{
- __m._M_resize(0);
- for (auto& __it : __res)
-   {
- __it.matched = false;
- __it.first = __it.second = __e;
-   }
+ __m._M_establish_failed_match(__e);
}
  return __ret;
}




[PATCH] PR libstdc++/69724 avoid temporary in std::thread construction

2019-05-14 Thread Jonathan Wakely

The std::thread constructor creates (and then moves) an unnecessary
temporary copy of each argument. Optimize it to only make the one copy
that is required.

PR libstdc++/69724
* include/std/thread (thread::_State_impl, thread::_S_make_state):
Replace single _Callable parameter with variadic _Args pack, to
forward them directly to the tuple of decayed copies.
* testsuite/30_threads/thread/cons/69724.cc: New test.

Tested powerpc64le-linux, committed to trunk.

I'll leave the bug report open as I want to do a similar optimization
for std::async's DECAY_COPY as well.


commit fddee59c34cbdc4872f65deebf5772cff9845fc7
Author: Jonathan Wakely 
Date:   Thu Mar 14 16:41:52 2019 +

PR libstdc++/69724 avoid temporary in std::thread construction

The std::thread constructor creates (and then moves) an unnecessary
temporary copy of each argument. Optimize it to only make the one copy
that is required.

PR libstdc++/69724
* include/std/thread (thread::_State_impl, thread::_S_make_state):
Replace single _Callable parameter with variadic _Args pack, to
forward them directly to the tuple of decayed copies.
* testsuite/30_threads/thread/cons/69724.cc: New test.

diff --git a/libstdc++-v3/include/std/thread b/libstdc++-v3/include/std/thread
index 2da1101eecf..90b4be6cd16 100644
--- a/libstdc++-v3/include/std/thread
+++ b/libstdc++-v3/include/std/thread
@@ -127,9 +127,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 #else
auto __depend = nullptr;
 #endif
-_M_start_thread(_S_make_state(
- __make_invoker(std::forward<_Callable>(__f),
-std::forward<_Args>(__args)...)),
+   // A call wrapper holding tuple{DECAY_COPY(__f), DECAY_COPY(__args)...}
+   using _Invoker_type = _Invoker<__decayed_tuple<_Callable, _Args...>>;
+
+   _M_start_thread(_S_make_state<_Invoker_type>(
+ std::forward<_Callable>(__f), std::forward<_Args>(__args)...),
__depend);
   }
 
@@ -188,8 +190,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   {
_Callable   _M_func;
 
-   _State_impl(_Callable&& __f) : _M_func(std::forward<_Callable>(__f))
-   { }
+   template
+ _State_impl(_Args&&... __args)
+ : _M_func{{std::forward<_Args>(__args)...}}
+ { }
 
void
_M_run() { _M_func(); }
@@ -198,12 +202,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 void
 _M_start_thread(_State_ptr, void (*)());
 
-template
+template
   static _State_ptr
-  _S_make_state(_Callable&& __f)
+  _S_make_state(_Args&&... __args)
   {
using _Impl = _State_impl<_Callable>;
-   return _State_ptr{new _Impl{std::forward<_Callable>(__f)}};
+   return _State_ptr{new _Impl{std::forward<_Args>(__args)...}};
   }
 #if _GLIBCXX_THREAD_ABI_COMPAT
   public:
diff --git a/libstdc++-v3/testsuite/30_threads/thread/cons/69724.cc 
b/libstdc++-v3/testsuite/30_threads/thread/cons/69724.cc
new file mode 100644
index 000..ee3a8602b29
--- /dev/null
+++ b/libstdc++-v3/testsuite/30_threads/thread/cons/69724.cc
@@ -0,0 +1,70 @@
+// Copyright (C) 2019 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3.  If not see
+// .
+
+// { dg-do run }
+// { dg-options "-pthread"  }
+// { dg-require-effective-target c++11 }
+// { dg-require-effective-target pthread }
+// { dg-require-gthreads "" }
+
+#include 
+#include 
+
+struct F : __gnu_test::copycounter
+{
+  F() = default;
+
+  F(const F&) = default;
+
+  // Move constructor copies base class, to use counter:
+  F(F&& f) : copycounter(f) { f.valid = false; }
+
+  void run() { VERIFY(this->valid); }
+};
+
+void
+test01()
+{
+  std::thread{::run, F{}}.join();
+  VERIFY( F::copycount == 1 );
+}
+
+void
+test02()
+{
+  F::copycount = 0;
+  const F f;
+  std::thread{::run, f}.join();
+  VERIFY( F::copycount == 1 );
+}
+
+void
+test03()
+{
+  F::copycount = 0;
+  F f;
+  std::thread{::run, std::ref(f)}.join();
+  VERIFY( F::copycount == 0 );
+}
+
+int
+main()
+{
+  test01();
+  test02();
+  test03();
+}


Re: [v3 PATCH] Inconsistency wrt Allocators in basic_string assignment vs. basic_string::assign (LWG2579)

2019-05-14 Thread Jonathan Wakely

On 09/05/19 09:26 +0100, Nina Dinka Ranns wrote:

Tested on Linux x86_64
Inconsistency wrt Allocators in basic_string assignment vs.
basic_string::assign (LWG2579)

2019-05-09  Nina Dinka Ranns  
   Inconsistency wrt Allocators in basic_string assignment vs.
basic_string::assign (LWG2579)
   * include/bits/basic_string.h:
operator=(const basic_string& __str): moved allocator
decision from operator= to assign
assign(const basic_string& __str): moved allocator decision
from operator= to assign
   * testsuite/21_strings/basic_string/allocator/char/copy_assign.cc:
Adding tests
   * testsuite/21_strings/basic_string/allocator/wchar_t/copy_assign.cc:
Adding tests


Tested and committed to trunk (with some ChangeLog reformatting,
please take a look at the ChangeLog entry I committed for future
reference).

Thanks!




[PATCH 3/3] /cp 2018-05-14 Paolo Carlini

2019-05-14 Thread Martin Liška
Missing part 3/3.

Martin
>From c026b716c0ee0595f0577b32e511dbdf7cf960a3 Mon Sep 17 00:00:00 2001
From: paolo 
Date: Fri, 26 Apr 2019 11:46:15 +
Subject: [PATCH 3/3] /cp 2018-05-14 Paolo Carlini 

	* decl.c (grokdeclarator): Fix value assigned to typespec_loc, use
	min_location.

/testsuite
2018-05-14  Paolo Carlini  

	* g++.dg/diagnostic/trailing1.C: New.
---
 gcc/cp/decl.c   | 4 ++--
 gcc/testsuite/g++.dg/diagnostic/trailing1.C | 5 +
 2 files changed, 7 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/diagnostic/trailing1.C

diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index a776f8fcd98..ec81888c1f1 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -10424,8 +10424,8 @@ grokdeclarator (const cp_declarator *declarator,
 
   location_t typespec_loc = smallest_type_quals_location (type_quals,
 		  declspecs->locations);
-  if (typespec_loc == UNKNOWN_LOCATION)
-typespec_loc = declspecs->locations[ds_type_spec];
+  typespec_loc = min_location (typespec_loc,
+			   declspecs->locations[ds_type_spec]);
   if (typespec_loc == UNKNOWN_LOCATION)
 typespec_loc = input_location;
 
diff --git a/gcc/testsuite/g++.dg/diagnostic/trailing1.C b/gcc/testsuite/g++.dg/diagnostic/trailing1.C
new file mode 100644
index 000..369781e56d5
--- /dev/null
+++ b/gcc/testsuite/g++.dg/diagnostic/trailing1.C
@@ -0,0 +1,5 @@
+// { dg-do compile { target c++11 } }
+
+int const foo1() -> double;  // { dg-error "1:.foo1. function with trailing return type" }
+int volatile foo2() -> double;  // { dg-error "1:.foo2. function with trailing return type" }
+int const volatile foo3() -> double;  // { dg-error "1:.foo3. function with trailing return type" }
-- 
2.21.0



Re: [PATCH 2/3] Fix min_location usage in line-map.c (PR preprocessor/90382).

2019-05-14 Thread Nathan Sidwell

On 5/13/19 7:10 AM, marxin wrote:


libcpp/ChangeLog:

2019-05-13  Martin Liska  

PR preprocessor/90382
* line-map.c (first_map_in_common_1): Handle ADHOC
locations.
---


ok


--
Nathan Sidwell


Re: [PATCH 1/3] Do a refactoring in linemap (PR preprocessor/90382).

2019-05-14 Thread Nathan Sidwell

On 5/13/19 7:07 AM, marxin wrote:


libcpp/ChangeLog:

2019-05-13  Martin Liska  

PR preprocessor/90382
* include/line-map.h (get_data_from_adhoc_loc): Add const to
the first argument.
(get_location_from_adhoc_loc): Likewise.
* line-map.c(get_data_from_adhoc_loc):  Add const to
the first argument.
(get_location_from_adhoc_loc): Likewise.
(get_combined_adhoc_loc): Use get_location_from_adhoc_loc
(or get_data_from_adhoc_loc).
(get_range_from_adhoc_loc): Likewise.
(get_pure_location): Likewise.
(linemap_position_for_loc_and_offset): Likewise.
(linemap_lookup): Likewise.
(linemap_ordinary_map_lookup): Likewise.
(linemap_macro_map_lookup): Likewise.
(linemap_get_expansion_line): Likewise.
(linemap_get_expansion_filename): Likewise.
(linemap_location_in_system_header_p): Likewise.
(linemap_location_from_macro_expansion_p): Likewise.
(linemap_macro_loc_to_exp_point): Likewise.
(linemap_resolve_location): Likewise.
(linemap_unwind_toward_expansion): Likewise.
(linemap_unwind_to_first_non_reserved_loc): Likewise.
(linemap_expand_location): Likewise.
(linemap_dump_location): Likewise.
---
  libcpp/include/line-map.h |  4 ++--
  libcpp/line-map.c | 48 ---
  2 files changed, 22 insertions(+), 30 deletions(-)


ok.  Thanks for cleaning this up.

nathan

--
Nathan Sidwell


[PATCH] Add __gnu_test::NullablePointer utility to testsuite

2019-05-14 Thread Jonathan Wakely

* testsuite/20_util/allocator_traits/members/allocate_hint_nonpod.cc:
Use operator-> to access raw pointer member.
* testsuite/23_containers/vector/59829.cc: Likewise.
* testsuite/23_containers/vector/bool/80893.cc: Likewise.
* testsuite/libstdc++-prettyprinters/cxx11.cc: Use NullablePointer.
* testsuite/util/testsuite_allocator.h (NullablePointer): New utility
for tests.
(PointerBase, PointerBase_void): Derive from NullablePointer and use
its constructors and equality operators. Change converting
constructors to use operator-> to access private member of the other
pointer type.
(PointerBase_void::operator->()): Add, for access to private member.
(operator-(PointerBase, PointerBase)): Change to hidden friend.
(operator==(PointerBase, PointerBase)): Remove.
(operator!=(PointerBase, PointerBase)): Remove.

There are probably more places in the testsuite that could use
NullablePointer as a minimally-conforming type that meets the
Cpp17NullablePointer requirements, instead of defining a new type each
time one is needed.

Tested powerpc64le-linux, committed to trunk.

commit d238e99b1eea20ba5bb52df6d4544fb4062fb075
Author: Jonathan Wakely 
Date:   Tue May 14 11:02:41 2019 +0100

Add __gnu_test::NullablePointer utility to testsuite

* 
testsuite/20_util/allocator_traits/members/allocate_hint_nonpod.cc:
Use operator-> to access raw pointer member.
* testsuite/23_containers/vector/59829.cc: Likewise.
* testsuite/23_containers/vector/bool/80893.cc: Likewise.
* testsuite/libstdc++-prettyprinters/cxx11.cc: Use NullablePointer.
* testsuite/util/testsuite_allocator.h (NullablePointer): New 
utility
for tests.
(PointerBase, PointerBase_void): Derive from NullablePointer and use
its constructors and equality operators. Change converting
constructors to use operator-> to access private member of the other
pointer type.
(PointerBase_void::operator->()): Add, for access to private member.
(operator-(PointerBase, PointerBase)): Change to hidden friend.
(operator==(PointerBase, PointerBase)): Remove.
(operator!=(PointerBase, PointerBase)): Remove.

diff --git 
a/libstdc++-v3/testsuite/20_util/allocator_traits/members/allocate_hint_nonpod.cc
 
b/libstdc++-v3/testsuite/20_util/allocator_traits/members/allocate_hint_nonpod.cc
index a5e2a269a15..f9193e83e94 100644
--- 
a/libstdc++-v3/testsuite/20_util/allocator_traits/members/allocate_hint_nonpod.cc
+++ 
b/libstdc++-v3/testsuite/20_util/allocator_traits/members/allocate_hint_nonpod.cc
@@ -45,7 +45,7 @@ struct Alloc
   { return pointer(std::allocator().allocate(n)); }
 
   void deallocate(pointer p, std::size_t n)
-  { std::allocator().deallocate(p.value, n); }
+  { std::allocator().deallocate(p.operator->(), n); }
 };
 
 template
diff --git a/libstdc++-v3/testsuite/23_containers/vector/59829.cc 
b/libstdc++-v3/testsuite/23_containers/vector/59829.cc
index 0e053fa6627..892b9055eb4 100644
--- a/libstdc++-v3/testsuite/23_containers/vector/59829.cc
+++ b/libstdc++-v3/testsuite/23_containers/vector/59829.cc
@@ -51,7 +51,7 @@ struct Alloc
   { return pointer(std::allocator().allocate(n)); }
 
   void deallocate(pointer p, std::size_t n)
-  { std::allocator().deallocate(p.value, n); }
+  { std::allocator().deallocate(p.operator->(), n); }
 };
 
 template
diff --git a/libstdc++-v3/testsuite/23_containers/vector/bool/80893.cc 
b/libstdc++-v3/testsuite/23_containers/vector/bool/80893.cc
index f44cdc4a75e..08b15c8d2da 100644
--- a/libstdc++-v3/testsuite/23_containers/vector/bool/80893.cc
+++ b/libstdc++-v3/testsuite/23_containers/vector/bool/80893.cc
@@ -59,7 +59,7 @@ struct Alloc
   void deallocate(pointer p, std::size_t n)
   {
 if (n)
-  std::allocator().deallocate(p.value, n);
+  std::allocator().deallocate(p.operator->(), n);
   }
 };
 
diff --git a/libstdc++-v3/testsuite/libstdc++-prettyprinters/cxx11.cc 
b/libstdc++-v3/testsuite/libstdc++-prettyprinters/cxx11.cc
index cc588125bdc..c87c8035c45 100644
--- a/libstdc++-v3/testsuite/libstdc++-prettyprinters/cxx11.cc
+++ b/libstdc++-v3/testsuite/libstdc++-prettyprinters/cxx11.cc
@@ -24,6 +24,7 @@
 #include 
 #include 
 #include 
+#include "../util/testsuite_allocator.h" // NullablePointer
 
 typedef std::tuple ExTuple;
 
@@ -59,21 +60,6 @@ struct datum
 
 std::unique_ptr global;
 
-struct Deleter
-{
-  // Deleter is not an empty class:
-  int deleter_member = -1;
-  // But pointer is an empty class:
-  struct pointer
-  {
-pointer(const void* = nullptr) { }
-explicit operator bool() const noexcept { return false; }
-friend bool operator==(pointer, pointer) noexcept { return true; }
-friend bool operator!=(pointer, pointer) noexcept { return false; }
-  };
-  void operator()(pointer) const noexcept { }
-};
-
 

[PATCH] Fix indentation in testsuite utility header

2019-05-14 Thread Jonathan Wakely

* testsuite/util/testsuite_allocator.h (memory_resource)
(default_resource_mgr): Fix indentation.

Tested powerpc64le-linux, committed to trunk.


commit 59c33c756da61c7e8c25dea832055a16156ed97a
Author: Jonathan Wakely 
Date:   Tue May 14 11:03:23 2019 +0100

Fix indentation in testsuite utility header

* testsuite/util/testsuite_allocator.h (memory_resource)
(default_resource_mgr): Fix indentation.

diff --git a/libstdc++-v3/testsuite/util/testsuite_allocator.h 
b/libstdc++-v3/testsuite/util/testsuite_allocator.h
index 428c0823395..ac7dc8ee2c4 100644
--- a/libstdc++-v3/testsuite/util/testsuite_allocator.h
+++ b/libstdc++-v3/testsuite/util/testsuite_allocator.h
@@ -743,161 +743,161 @@ namespace __gnu_test
 
 #if __cplusplus >= 201703L
 #if __cpp_aligned_new && __cpp_rtti
-// A concrete memory_resource, with error checking.
-class memory_resource : public std::pmr::memory_resource
+  // A concrete memory_resource, with error checking.
+  class memory_resource : public std::pmr::memory_resource
+  {
+  public:
+memory_resource()
+: lists(new allocation_lists)
+{ }
+
+memory_resource(const memory_resource& r) noexcept
+: lists(r.lists)
+{ lists->refcount++; }
+
+memory_resource& operator=(const memory_resource&) = delete;
+
+~memory_resource()
 {
-public:
-  memory_resource()
-  : lists(new allocation_lists)
-  { }
+  if (lists->refcount-- == 1)
+   delete lists;  // last one out turns out the lights
+}
 
-  memory_resource(const memory_resource& r) noexcept
-  : lists(r.lists)
-  { lists->refcount++; }
+struct bad_size { };
+struct bad_alignment { };
+struct bad_address { };
 
-  memory_resource& operator=(const memory_resource&) = delete;
-
-  ~memory_resource()
-  {
-   if (lists->refcount-- == 1)
- delete lists;  // last one out turns out the lights
-  }
-
-  struct bad_size { };
-  struct bad_alignment { };
-  struct bad_address { };
-
-  // Deallocate everything (moving the tracking info to the freed list)
-  void
-  deallocate_everything()
-  {
-   while (lists->active)
- {
-   auto a = lists->active;
-   // Intentionally virtual dispatch, to inform derived classes:
-   this->do_deallocate(a->p, a->bytes, a->alignment);
- }
-  }
-
-  // Clear the freed list
-  void
-  forget_freed_allocations()
-  { lists->forget_allocations(lists->freed); }
-
-  // Count how many allocations have been done and not freed.
-  std::size_t
-  number_of_active_allocations() const noexcept
-  {
-   std::size_t n = 0;
-   for (auto a = lists->active; a != nullptr; a = a->next)
- ++n;
-   return n;
-  }
-
-protected:
-  void*
-  do_allocate(std::size_t bytes, std::size_t alignment) override
-  {
-   // TODO perform a single allocation and put the allocation struct
-   // in the buffer using placement new? It means deallocation won't
-   // actually return memory to the OS, as it will stay in lists->freed.
-   //
-   // TODO adjust the returned pointer to be minimally aligned?
-   // e.g. if alignment==1 don't return something aligned to 2 bytes.
-   // Maybe not worth it, at least monotonic_buffer_resource will
-   // never ask upstream for anything with small alignment.
-   void* p = ::operator new(bytes, std::align_val_t(alignment));
-   lists->active = new allocation{p, bytes, alignment, lists->active};
-   return p;
-  }
-
-  void
-  do_deallocate(void* p, std::size_t bytes, std::size_t alignment) override
-  {
-   allocation** aptr = >active;
-   while (*aptr)
- {
-   allocation* a = *aptr;
-   if (p == a->p)
- {
-   if (bytes != a->bytes)
- throw bad_size();
-   if (alignment != a->alignment)
- throw bad_alignment();
-#if __cpp_sized_deallocation
-   ::operator delete(p, bytes, std::align_val_t(alignment));
-#else
-   ::operator delete(p, std::align_val_t(alignment));
-#endif
-   *aptr = a->next;
-   a->next = lists->freed;
-   lists->freed = a;
-   return;
- }
-   aptr = >next;
- }
-   throw bad_address();
-  }
-
-  bool
-  do_is_equal(const std::pmr::memory_resource& r) const noexcept override
-  {
-   // Equality is determined by sharing the same allocation_lists object.
-   if (auto p = dynamic_cast())
- return p->lists == lists;
-   return false;
-  }
-
-private:
-  struct allocation
-  {
-   void* p;
-   std::size_t bytes;
-   std::size_t alignment;
-   allocation* next;
-  };
-
-  // Maintain list of allocated blocks and list of freed blocks.
-  // Copies of 

[PATCH] Fix unique_ptr pretty printer for empty classes

2019-05-14 Thread Jonathan Wakely

The printer was confused when unique_ptr::pointer is an empty
class, or the deleter is not empty. Instead of assuming the tuple has a
single _M_head_impl member manually inspect the tuple base classes to
get the first element.

Doing this means the "compat" tuple in compat.cc needs to have the
same structure as the real std::tuple, so the printer works for it.

* python/libstdcxx/v6/printers.py (UniquePointerPrinter.__init__): Do
not assume field called _M_head_impl is the first tuple element.
* testsuite/libstdc++-prettyprinters/compat.cc: Make tuple
implementation more accurate.
* testsuite/libstdc++-prettyprinters/cxx11.cc: Check unique_ptr with
empty pointer type and non-empty deleter.

Tested powerpc64le-linux, committed to trunk.

commit e5d48f873a282056dd32bd1808e22b4c42ca7bb7
Author: Jonathan Wakely 
Date:   Tue May 14 00:58:53 2019 +0100

Fix unique_ptr pretty printer for empty classes

The printer was confused when unique_ptr::pointer is an empty
class, or the deleter is not empty. Instead of assuming the tuple has a
single _M_head_impl member manually inspect the tuple base classes to
get the first element.

* python/libstdcxx/v6/printers.py (UniquePointerPrinter.__init__): 
Do
not assume field called _M_head_impl is the first tuple element.
* testsuite/libstdc++-prettyprinters/compat.cc: Make tuple
implementation more accurate.
* testsuite/libstdc++-prettyprinters/cxx11.cc: Check unique_ptr with
empty pointer type and non-empty deleter.

diff --git a/libstdc++-v3/python/libstdcxx/v6/printers.py 
b/libstdc++-v3/python/libstdcxx/v6/printers.py
index eae06f93c34..162b00760e6 100644
--- a/libstdc++-v3/python/libstdcxx/v6/printers.py
+++ b/libstdc++-v3/python/libstdcxx/v6/printers.py
@@ -185,11 +185,18 @@ class UniquePointerPrinter:
 # Check for new implementations first:
 if is_specialization_of(impl_type, '__uniq_ptr_data') \
 or is_specialization_of(impl_type, '__uniq_ptr_impl'):
-self.pointer = val['_M_t']['_M_t']['_M_head_impl']
+tuple_member = val['_M_t']['_M_t']
 elif is_specialization_of(impl_type, 'tuple'):
-self.pointer = val['_M_t']['_M_head_impl']
+tuple_member = val['_M_t']
 else:
 raise ValueError("Unsupported implementation for unique_ptr: %s" % 
impl_type)
+tuple_impl_type = tuple_member.type.fields()[0].type # _Tuple_impl
+tuple_head_type = tuple_impl_type.fields()[1].type   # _Head_base
+head_field = tuple_head_type.fields()[0]
+if head_field.name == '_M_head_impl':
+self.pointer = tuple_member['_M_head_impl']
+elif head_field.is_base_class:
+self.pointer = tuple_member.cast(head_field.type)
 
 def children (self):
 return SmartPtrIterator(self.pointer)
diff --git a/libstdc++-v3/testsuite/libstdc++-prettyprinters/compat.cc 
b/libstdc++-v3/testsuite/libstdc++-prettyprinters/compat.cc
index 7bfc3c68867..28b0c2154d7 100644
--- a/libstdc++-v3/testsuite/libstdc++-prettyprinters/compat.cc
+++ b/libstdc++-v3/testsuite/libstdc++-prettyprinters/compat.cc
@@ -22,12 +22,30 @@
 
 namespace std
 {
-  template
-struct tuple
+  template
+struct _Head_base : T
+{ };
+
+  template
+struct _Head_base
 {
-  T _M_head_impl;
+  T* _M_head_impl;
 };
 
+  template struct _Tuple_impl;
+
+  template
+struct _Tuple_impl<0, T, U> : _Tuple_impl<1, U>, _Head_base
+{ };
+
+  template
+struct _Tuple_impl<1, U> : _Head_base
+{ };
+
+  template
+struct tuple : _Tuple_impl<0, T, U>
+{ };
+
   template struct default_delete { };
 
   template>
diff --git a/libstdc++-v3/testsuite/libstdc++-prettyprinters/cxx11.cc 
b/libstdc++-v3/testsuite/libstdc++-prettyprinters/cxx11.cc
index 7d0a9a21768..cc588125bdc 100644
--- a/libstdc++-v3/testsuite/libstdc++-prettyprinters/cxx11.cc
+++ b/libstdc++-v3/testsuite/libstdc++-prettyprinters/cxx11.cc
@@ -59,6 +59,21 @@ struct datum
 
 std::unique_ptr global;
 
+struct Deleter
+{
+  // Deleter is not an empty class:
+  int deleter_member = -1;
+  // But pointer is an empty class:
+  struct pointer
+  {
+pointer(const void* = nullptr) { }
+explicit operator bool() const noexcept { return false; }
+friend bool operator==(pointer, pointer) noexcept { return true; }
+friend bool operator!=(pointer, pointer) noexcept { return false; }
+  };
+  void operator()(pointer) const noexcept { }
+};
+
 int
 main()
 {
@@ -136,6 +151,11 @@ main()
   std::unique_ptr& rarrptr = arrptr;
 // { dg-final { regexp-test rarrptr {std::unique_ptr.datum \[\]. = {get\(\) = 
0x.*}} } }
 
+  std::unique_ptr empty_ptr;
+// { dg-final { note-test empty_ptr {std::unique_ptr = {get() = {}}} } }
+  std::unique_ptr& rempty_ptr = empty_ptr;
+// { dg-final { note-test rempty_ptr {std::unique_ptr = {get() = {}}} } }
+
   ExTuple 

[PATCH] LWG 2899 - Make is_move_constructible correct for unique_ptr

2019-05-14 Thread Jonathan Wakely

* include/bits/unique_ptr.h (__uniq_ptr_impl): Add move constructor,
move assignment operator.
(__uniq_ptr_impl::release(), __uniq_ptr_impl::reset(pointer)): Add.
(__uniq_ptr_data): New class template with conditionally deleted
special members.
(unique_ptr, unique_ptr): Change type of data member from
__uniq_ptr_impl to __uniq_ptr_data. Define move
constructor and move assignment operator as defaulted.
(unique_ptr::release(), unique_ptr::release()): Forward to
__uniq_ptr_impl::release().
(unique_ptr::reset(pointer), unique_ptr::reset(U)): Forward
to __uniq_ptr_impl::reset(pointer).
* python/libstdcxx/v6/printers.py (UniquePointerPrinter.__init__):
Check for new __uniq_ptr_data type.
* testsuite/20_util/unique_ptr/dr2899.cc: New test.

Tested powerpc64le-linux, committed to trunk.


commit a136419c054eeaa2e88246d682151c25c124d30e
Author: Jonathan Wakely 
Date:   Thu Feb 14 17:00:20 2019 +

LWG 2899 - Make is_move_constructible correct for unique_ptr

* include/bits/unique_ptr.h (__uniq_ptr_impl): Add move constructor,
move assignment operator.
(__uniq_ptr_impl::release(), __uniq_ptr_impl::reset(pointer)): Add.
(__uniq_ptr_data): New class template with conditionally deleted
special members.
(unique_ptr, unique_ptr): Change type of data member from
__uniq_ptr_impl to __uniq_ptr_data. Define move
constructor and move assignment operator as defaulted.
(unique_ptr::release(), unique_ptr::release()): Forward to
__uniq_ptr_impl::release().
(unique_ptr::reset(pointer), unique_ptr::reset(U)): 
Forward
to __uniq_ptr_impl::reset(pointer).
* python/libstdcxx/v6/printers.py (UniquePointerPrinter.__init__):
Check for new __uniq_ptr_data type.
* testsuite/20_util/unique_ptr/dr2899.cc: New test.

diff --git a/libstdc++-v3/include/bits/unique_ptr.h 
b/libstdc++-v3/include/bits/unique_ptr.h
index a9e74725dfd..484c8b328e4 100644
--- a/libstdc++-v3/include/bits/unique_ptr.h
+++ b/libstdc++-v3/include/bits/unique_ptr.h
@@ -119,6 +119,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
   /// @cond undocumented
 
+  // Manages the pointer and deleter of a unique_ptr
   template 
 class __uniq_ptr_impl
 {
@@ -153,14 +154,75 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   __uniq_ptr_impl(pointer __p, _Del&& __d)
: _M_t(__p, std::forward<_Del>(__d)) { }
 
+  __uniq_ptr_impl(__uniq_ptr_impl&& __u) noexcept
+  : _M_t(std::move(__u._M_t))
+  { __u._M_ptr() = nullptr; }
+
+  __uniq_ptr_impl& operator=(__uniq_ptr_impl&& __u) noexcept
+  {
+   reset(__u.release());
+   _M_deleter() = std::forward<_Dp>(__u._M_deleter());
+   return *this;
+  }
+
   pointer&   _M_ptr() { return std::get<0>(_M_t); }
   pointer_M_ptr() const { return std::get<0>(_M_t); }
   _Dp&   _M_deleter() { return std::get<1>(_M_t); }
   const _Dp& _M_deleter() const { return std::get<1>(_M_t); }
 
+  void reset(pointer __p) noexcept
+  {
+   const pointer __old_p = _M_ptr();
+   _M_ptr() = __p;
+   if (__old_p)
+ _M_deleter()(__old_p);
+  }
+
+  pointer release() noexcept
+  {
+   pointer __p = _M_ptr();
+   _M_ptr() = nullptr;
+   return __p;
+  }
+
 private:
   tuple _M_t;
 };
+
+  // Defines move construction + assignment as either defaulted or deleted.
+  template ::value,
+   bool = is_move_assignable<_Dp>::value>
+struct __uniq_ptr_data : __uniq_ptr_impl<_Tp, _Dp>
+{
+  using __uniq_ptr_impl<_Tp, _Dp>::__uniq_ptr_impl;
+  __uniq_ptr_data(__uniq_ptr_data&&) = default;
+  __uniq_ptr_data& operator=(__uniq_ptr_data&&) = default;
+};
+
+  template 
+struct __uniq_ptr_data<_Tp, _Dp, true, false> : __uniq_ptr_impl<_Tp, _Dp>
+{
+  using __uniq_ptr_impl<_Tp, _Dp>::__uniq_ptr_impl;
+  __uniq_ptr_data(__uniq_ptr_data&&) = default;
+  __uniq_ptr_data& operator=(__uniq_ptr_data&&) = delete;
+};
+
+  template 
+struct __uniq_ptr_data<_Tp, _Dp, false, true> : __uniq_ptr_impl<_Tp, _Dp>
+{
+  using __uniq_ptr_impl<_Tp, _Dp>::__uniq_ptr_impl;
+  __uniq_ptr_data(__uniq_ptr_data&&) = delete;
+  __uniq_ptr_data& operator=(__uniq_ptr_data&&) = default;
+};
+
+  template 
+struct __uniq_ptr_data<_Tp, _Dp, false, false> : __uniq_ptr_impl<_Tp, _Dp>
+{
+  using __uniq_ptr_impl<_Tp, _Dp>::__uniq_ptr_impl;
+  __uniq_ptr_data(__uniq_ptr_data&&) = delete;
+  __uniq_ptr_data& operator=(__uniq_ptr_data&&) = delete;
+};
   /// @endcond
 
   /// 20.7.1.2 unique_ptr for single objects.
@@ -171,7 +233,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
using _DeleterConstraint =
  typename __uniq_ptr_impl<_Tp, _Up>::_DeleterConstraint::type;
 
-  

[PATCH][OBVIOUS] Fix a test-case in PR middle-end/90340.

2019-05-14 Thread Martin Liška
Hi.

It's a small tweak to a test-case. I've tested that on x86_64-linux-gnu
and aarch64-linux-gnu.

I'm going to install the patch.
Martin

gcc/testsuite/ChangeLog:

2019-05-14  marxin  

PR middle-end/90340
* gcc.dg/tree-ssa/pr90340-2.c: Add case-values-threshold
param.
---
 gcc/testsuite/gcc.dg/tree-ssa/pr90340-2.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)


diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr90340-2.c b/gcc/testsuite/gcc.dg/tree-ssa/pr90340-2.c
index 21099821786..a3cb0cd069c 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/pr90340-2.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/pr90340-2.c
@@ -1,5 +1,5 @@
 /* { dg-do compile { target { { x86_64-*-* aarch64-*-* ia64-*-* powerpc64-*-* } && lp64 } } } */
-/* { dg-options "-Os --param jump-table-max-growth-ratio-for-size=200 -fdump-tree-switchlower1" } */
+/* { dg-options "-Os --param jump-table-max-growth-ratio-for-size=200 --param case-values-threshold=5 -fdump-tree-switchlower1" } */
 
 int a;
 



Re: V6 [PATCH] Optimize vector constructor

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

Re: GCC 8 backports

2019-05-14 Thread Martin Liška
On 5/6/19 4:00 PM, Martin Liška wrote:
> Hi.
> 
> I'm sending following backport that I've just tested.
> 
> Martin
> 

Hi.

There are 2 more patches that I've tested.

Martin
>From af452cc71498c097d09bc8ecd848d28555a00bb2 Mon Sep 17 00:00:00 2001
From: marxin 
Date: Mon, 13 May 2019 07:04:58 +
Subject: [PATCH 1/2] Backport r271116

gcc/ChangeLog:

2019-05-13  Martin Liska  

	PR gcov-profile/90380
	* gcov.c (enum loop_type): Remove the enum and
	the operator.
	(handle_cycle): Assert that we should not reach
	a negative count.
	(circuit): Use loop_found instead of a tri-state loop_type.
	(get_cycles_count): Do not handle NEGATIVE_LOOP as it can't
	happen.
---
 gcc/gcov.c | 53 ++---
 1 file changed, 18 insertions(+), 35 deletions(-)

diff --git a/gcc/gcov.c b/gcc/gcov.c
index c7c52ce3629..47c784a9388 100644
--- a/gcc/gcov.c
+++ b/gcc/gcov.c
@@ -604,27 +604,11 @@ bool function_info::group_line_p (unsigned n, unsigned src_idx)
 typedef vector arc_vector_t;
 typedef vector block_vector_t;
 
-/* Enum with types of loop in CFG.  */
-
-enum loop_type
-{
-  NO_LOOP = 0,
-  LOOP = 1,
-  NEGATIVE_LOOP = 3
-};
-
-/* Loop_type operator that merges two values: A and B.  */
-
-inline loop_type& operator |= (loop_type& a, loop_type b)
-{
-return a = static_cast (a | b);
-}
-
 /* Handle cycle identified by EDGES, where the function finds minimum cs_count
and subtract the value from all counts.  The subtracted value is added
to COUNT.  Returns type of loop.  */
 
-static loop_type
+static void
 handle_cycle (const arc_vector_t , int64_t )
 {
   /* Find the minimum edge of the cycle, and reduce all nodes in the cycle by
@@ -640,7 +624,7 @@ handle_cycle (const arc_vector_t , int64_t )
   for (unsigned i = 0; i < edges.size (); i++)
 edges[i]->cs_count -= cycle_count;
 
-  return cycle_count < 0 ? NEGATIVE_LOOP : LOOP;
+  gcc_assert (cycle_count >= 0);
 }
 
 /* Unblock a block U from BLOCKED.  Apart from that, iterate all blocks
@@ -671,12 +655,12 @@ unblock (const block_info *u, block_vector_t ,
blocked by a block.  COUNT is accumulated count of the current LINE.
Returns what type of loop it contains.  */
 
-static loop_type
+static bool
 circuit (block_info *v, arc_vector_t , block_info *start,
 	 block_vector_t , vector _lists,
 	 line_info , int64_t )
 {
-  loop_type result = NO_LOOP;
+  bool loop_found = false;
 
   /* Add v to the block list.  */
   gcc_assert (find (blocked.begin (), blocked.end (), v) == blocked.end ());
@@ -691,15 +675,19 @@ circuit (block_info *v, arc_vector_t , block_info *start,
 
   path.push_back (arc);
   if (w == start)
-	/* Cycle has been found.  */
-	result |= handle_cycle (path, count);
+	{
+	  /* Cycle has been found.  */
+	  handle_cycle (path, count);
+	  loop_found = true;
+	}
   else if (find (blocked.begin (), blocked.end (), w) == blocked.end ())
-	result |= circuit (w, path, start, blocked, block_lists, linfo, count);
+	loop_found |= circuit (w, path, start, blocked, block_lists, linfo,
+			   count);
 
   path.pop_back ();
 }
 
-  if (result != NO_LOOP)
+  if (loop_found)
 unblock (v, blocked, block_lists);
   else
 for (arc_info *arc = v->succ; arc; arc = arc->succ_next)
@@ -716,14 +704,13 @@ circuit (block_info *v, arc_vector_t , block_info *start,
 	  list.push_back (v);
   }
 
-  return result;
+  return loop_found;
 }
 
-/* Find cycles for a LINFO.  If HANDLE_NEGATIVE_CYCLES is set and the line
-   contains a negative loop, then perform the same function once again.  */
+/* Find cycles for a LINFO.  */
 
 static gcov_type
-get_cycles_count (line_info , bool handle_negative_cycles = true)
+get_cycles_count (line_info )
 {
   /* Note that this algorithm works even if blocks aren't in sorted order.
  Each iteration of the circuit detection is completely independent
@@ -731,7 +718,7 @@ get_cycles_count (line_info , bool handle_negative_cycles = true)
  Therefore, operating on a permuted order (i.e., non-sorted) only
  has the effect of permuting the output cycles.  */
 
-  loop_type result = NO_LOOP;
+  bool loop_found = false;
   gcov_type count = 0;
   for (vector::iterator it = linfo.blocks.begin ();
it != linfo.blocks.end (); it++)
@@ -739,14 +726,10 @@ get_cycles_count (line_info , bool handle_negative_cycles = true)
   arc_vector_t path;
   block_vector_t blocked;
   vector block_lists;
-  result |= circuit (*it, path, *it, blocked, block_lists, linfo,
-			 count);
+  loop_found |= circuit (*it, path, *it, blocked, block_lists, linfo,
+			 count);
 }
 
-  /* If we have a negative cycle, repeat the find_cycles routine.  */
-  if (result == NEGATIVE_LOOP && handle_negative_cycles)
-count += get_cycles_count (linfo, false);
-
   return count;
 }
 
-- 
2.21.0

>From 33a14c2ebe20dc58e986503fb00814e10dec9b1a Mon Sep 17 00:00:00 2001
From: marxin 
Date: Mon, 13 May 2019 07:05:23 +
Subject: [PATCH 2/2] Backport 

Re: GCC 9 backports

2019-05-14 Thread Martin Liška
On 5/14/19 10:45 AM, Martin Liška wrote:
> Hi.
> 
> There are 2 backport patches that I've just tested and I'm going to install 
> them.
> 
> Martin
> 

One more patch.

Martin
>From fb33e008c2e2a9216cae193d46c08e266250b6ae Mon Sep 17 00:00:00 2001
From: marxin 
Date: Mon, 13 May 2019 10:26:09 +
Subject: [PATCH] Backport r271118

gcc/ChangeLog:

2019-05-13  Martin Liska  

	PR tree-optimization/90416
	* tree-vect-stmts.c (vect_check_load_store_mask): Concatenate
	string instead of passing the second part as va_arg argument.
---
 gcc/tree-vect-stmts.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/tree-vect-stmts.c b/gcc/tree-vect-stmts.c
index 41a7eb0b9a7..a5fa8ec3a86 100644
--- a/gcc/tree-vect-stmts.c
+++ b/gcc/tree-vect-stmts.c
@@ -2568,7 +2568,7 @@ vect_check_load_store_mask (stmt_vec_info stmt_info, tree mask,
 {
   if (dump_enabled_p ())
 	dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
-			 "vector mask type %T",
+			 "vector mask type %T"
 			 " does not match vector data type %T.\n",
 			 mask_vectype, vectype);
 
-- 
2.21.0



GCC 9 backports

2019-05-14 Thread Martin Liška
Hi.

There are 2 backport patches that I've just tested and I'm going to install 
them.

Martin
>From 4ad5f7ebfa965fc65acca851e48e9f56e9a2f20d Mon Sep 17 00:00:00 2001
From: marxin 
Date: Mon, 13 May 2019 07:04:58 +
Subject: [PATCH 1/2] Backport r271116

gcc/ChangeLog:

2019-05-13  Martin Liska  

	PR gcov-profile/90380
	* gcov.c (enum loop_type): Remove the enum and
	the operator.
	(handle_cycle): Assert that we should not reach
	a negative count.
	(circuit): Use loop_found instead of a tri-state loop_type.
	(get_cycles_count): Do not handle NEGATIVE_LOOP as it can't
	happen.
---
 gcc/gcov.c | 53 ++---
 1 file changed, 18 insertions(+), 35 deletions(-)

diff --git a/gcc/gcov.c b/gcc/gcov.c
index 1fc37a07c34..6bcd2b23748 100644
--- a/gcc/gcov.c
+++ b/gcc/gcov.c
@@ -676,27 +676,11 @@ bool function_info::group_line_p (unsigned n, unsigned src_idx)
 typedef vector arc_vector_t;
 typedef vector block_vector_t;
 
-/* Enum with types of loop in CFG.  */
-
-enum loop_type
-{
-  NO_LOOP = 0,
-  LOOP = 1,
-  NEGATIVE_LOOP = 3
-};
-
-/* Loop_type operator that merges two values: A and B.  */
-
-inline loop_type& operator |= (loop_type& a, loop_type b)
-{
-return a = static_cast (a | b);
-}
-
 /* Handle cycle identified by EDGES, where the function finds minimum cs_count
and subtract the value from all counts.  The subtracted value is added
to COUNT.  Returns type of loop.  */
 
-static loop_type
+static void
 handle_cycle (const arc_vector_t , int64_t )
 {
   /* Find the minimum edge of the cycle, and reduce all nodes in the cycle by
@@ -712,7 +696,7 @@ handle_cycle (const arc_vector_t , int64_t )
   for (unsigned i = 0; i < edges.size (); i++)
 edges[i]->cs_count -= cycle_count;
 
-  return cycle_count < 0 ? NEGATIVE_LOOP : LOOP;
+  gcc_assert (cycle_count >= 0);
 }
 
 /* Unblock a block U from BLOCKED.  Apart from that, iterate all blocks
@@ -743,12 +727,12 @@ unblock (const block_info *u, block_vector_t ,
blocked by a block.  COUNT is accumulated count of the current LINE.
Returns what type of loop it contains.  */
 
-static loop_type
+static bool
 circuit (block_info *v, arc_vector_t , block_info *start,
 	 block_vector_t , vector _lists,
 	 line_info , int64_t )
 {
-  loop_type result = NO_LOOP;
+  bool loop_found = false;
 
   /* Add v to the block list.  */
   gcc_assert (find (blocked.begin (), blocked.end (), v) == blocked.end ());
@@ -763,15 +747,19 @@ circuit (block_info *v, arc_vector_t , block_info *start,
 
   path.push_back (arc);
   if (w == start)
-	/* Cycle has been found.  */
-	result |= handle_cycle (path, count);
+	{
+	  /* Cycle has been found.  */
+	  handle_cycle (path, count);
+	  loop_found = true;
+	}
   else if (find (blocked.begin (), blocked.end (), w) == blocked.end ())
-	result |= circuit (w, path, start, blocked, block_lists, linfo, count);
+	loop_found |= circuit (w, path, start, blocked, block_lists, linfo,
+			   count);
 
   path.pop_back ();
 }
 
-  if (result != NO_LOOP)
+  if (loop_found)
 unblock (v, blocked, block_lists);
   else
 for (arc_info *arc = v->succ; arc; arc = arc->succ_next)
@@ -788,14 +776,13 @@ circuit (block_info *v, arc_vector_t , block_info *start,
 	  list.push_back (v);
   }
 
-  return result;
+  return loop_found;
 }
 
-/* Find cycles for a LINFO.  If HANDLE_NEGATIVE_CYCLES is set and the line
-   contains a negative loop, then perform the same function once again.  */
+/* Find cycles for a LINFO.  */
 
 static gcov_type
-get_cycles_count (line_info , bool handle_negative_cycles = true)
+get_cycles_count (line_info )
 {
   /* Note that this algorithm works even if blocks aren't in sorted order.
  Each iteration of the circuit detection is completely independent
@@ -803,7 +790,7 @@ get_cycles_count (line_info , bool handle_negative_cycles = true)
  Therefore, operating on a permuted order (i.e., non-sorted) only
  has the effect of permuting the output cycles.  */
 
-  loop_type result = NO_LOOP;
+  bool loop_found = false;
   gcov_type count = 0;
   for (vector::iterator it = linfo.blocks.begin ();
it != linfo.blocks.end (); it++)
@@ -811,14 +798,10 @@ get_cycles_count (line_info , bool handle_negative_cycles = true)
   arc_vector_t path;
   block_vector_t blocked;
   vector block_lists;
-  result |= circuit (*it, path, *it, blocked, block_lists, linfo,
-			 count);
+  loop_found |= circuit (*it, path, *it, blocked, block_lists, linfo,
+			 count);
 }
 
-  /* If we have a negative cycle, repeat the find_cycles routine.  */
-  if (result == NEGATIVE_LOOP && handle_negative_cycles)
-count += get_cycles_count (linfo, false);
-
   return count;
 }
 
-- 
2.21.0

>From b566f10c6650baabc72cf090a08774936b1f703b Mon Sep 17 00:00:00 2001
From: marxin 
Date: Mon, 13 May 2019 07:05:23 +
Subject: [PATCH 2/2] Backport r271117

gcc/ChangeLog:

2019-05-13  Martin Liska  

	PR gcov-profile/90380
	* gcov.c 

  1   2   >