Re: [PATCH] Improve bootstrap times

2018-04-26 Thread Bernhard Reutner-Fischer
On 25 April 2018 16:11:23 CEST, Richard Biener  wrote:
>On Wed, 25 Apr 2018, Jakub Jelinek wrote:
>
>> On Wed, Apr 25, 2018 at 03:52:28PM +0200, Richard Biener wrote:
>> > Forcefully setting STAGE3_[CT]FLAGS doesn't have any effect on
>> > a checking enabled build but it will disrupt profiledbootstrap
>> > on a release build by training with -fchecking.  Suggestions
>> > welcome - not sure whether adjusting STAGE3_[CT]FLAGS after
>> > setting STAGEtrain_[CT]FLAGS will have the desired effect of
>> > leaving the latter alone.
>> 
>> You could perhaps replace
>> STAGEtrain_CFLAGS = $(STAGE3_CFLAGS)
>> STAGEtrain_TFLAGS = $(STAGE3_TFLAGS)
>> with
>> STAGEtrain_CFLAGS = $(filter-out -fchecking,$(STAGE3_CFLAGS))
>> STAGEtrain_TFLAGS = $(filter-out -fchecking,$(STAGE3_TFLAGS))
>> ?
>
>Good idea - I'll check if that works.

Is filter-out guaranteed to be supported on anything other than GNU make?



[PATCH] Fix PR85450

2018-04-26 Thread Richard Biener

The following patch restores checking of integer<->pointer conversions
which I broke with a cut&paste error when introducing ptrofftype_p
and friends.  It also contains a fix from Jakub for the fallout in
omp expansion.

Bootstrapped and tested on x86_64-unknown-linux-gnu with all languages,
applied to trunk.

Richard.

2018-04-26  Richard Biener  

PR middle-end/85450
* tree-cfg.c (verify_gimple_assign_unary): Restore proper
checking of integer<->pointer conversions.
* omp-expand.c (expand_omp_for_static_nochunk): Avoid
sign-/zero-extending pointer types.
(expand_omp_for_static_chunk): Likewise.

Index: gcc/tree-cfg.c
===
--- gcc/tree-cfg.c  (revision 259638)
+++ gcc/tree-cfg.c  (working copy)
@@ -3842,7 +3842,7 @@ verify_gimple_assign_unary (gassign *stm
|| (POINTER_TYPE_P (rhs1_type)
&& INTEGRAL_TYPE_P (lhs_type)
&& (TYPE_PRECISION (rhs1_type) >= TYPE_PRECISION (lhs_type)
-   || ptrofftype_p (sizetype
+   || ptrofftype_p (lhs_type
  return false;
 
/* Allow conversion from integral to offset type and vice versa.  */
Index: gcc/omp-expand.c
===
--- gcc/omp-expand.c(revision 259638)
+++ gcc/omp-expand.c(working copy)
@@ -3501,7 +3501,12 @@ expand_omp_for_static_nochunk (struct om
   t = fold_convert (itype, s0);
   t = fold_build2 (MULT_EXPR, itype, t, step);
   if (POINTER_TYPE_P (type))
-t = fold_build_pointer_plus (n1, t);
+{
+  t = fold_build_pointer_plus (n1, t);
+  if (!POINTER_TYPE_P (TREE_TYPE (startvar))
+ && TYPE_PRECISION (TREE_TYPE (startvar)) > TYPE_PRECISION (type))
+   t = fold_convert (signed_type_for (type), t);
+}
   else
 t = fold_build2 (PLUS_EXPR, type, t, n1);
   t = fold_convert (TREE_TYPE (startvar), t);
@@ -3515,7 +3520,12 @@ expand_omp_for_static_nochunk (struct om
   t = fold_convert (itype, e0);
   t = fold_build2 (MULT_EXPR, itype, t, step);
   if (POINTER_TYPE_P (type))
-t = fold_build_pointer_plus (n1, t);
+{
+  t = fold_build_pointer_plus (n1, t);
+  if (!POINTER_TYPE_P (TREE_TYPE (startvar))
+ && TYPE_PRECISION (TREE_TYPE (startvar)) > TYPE_PRECISION (type))
+   t = fold_convert (signed_type_for (type), t);
+}
   else
 t = fold_build2 (PLUS_EXPR, type, t, n1);
   t = fold_convert (TREE_TYPE (startvar), t);
@@ -4000,7 +4010,12 @@ expand_omp_for_static_chunk (struct omp_
   t = fold_convert (itype, s0);
   t = fold_build2 (MULT_EXPR, itype, t, step);
   if (POINTER_TYPE_P (type))
-t = fold_build_pointer_plus (n1, t);
+{
+  t = fold_build_pointer_plus (n1, t);
+  if (!POINTER_TYPE_P (TREE_TYPE (startvar))
+ && TYPE_PRECISION (TREE_TYPE (startvar)) > TYPE_PRECISION (type))
+   t = fold_convert (signed_type_for (type), t);
+}
   else
 t = fold_build2 (PLUS_EXPR, type, t, n1);
   t = fold_convert (TREE_TYPE (startvar), t);
@@ -4014,7 +4029,12 @@ expand_omp_for_static_chunk (struct omp_
   t = fold_convert (itype, e0);
   t = fold_build2 (MULT_EXPR, itype, t, step);
   if (POINTER_TYPE_P (type))
-t = fold_build_pointer_plus (n1, t);
+{
+  t = fold_build_pointer_plus (n1, t);
+  if (!POINTER_TYPE_P (TREE_TYPE (startvar))
+ && TYPE_PRECISION (TREE_TYPE (startvar)) > TYPE_PRECISION (type))
+   t = fold_convert (signed_type_for (type), t);
+}
   else
 t = fold_build2 (PLUS_EXPR, type, t, n1);
   t = fold_convert (TREE_TYPE (startvar), t);


Re: [PATCH] Improve bootstrap times

2018-04-26 Thread Richard Biener
On Thu, 26 Apr 2018, Bernhard Reutner-Fischer wrote:

> On 25 April 2018 16:11:23 CEST, Richard Biener  wrote:
> >On Wed, 25 Apr 2018, Jakub Jelinek wrote:
> >
> >> On Wed, Apr 25, 2018 at 03:52:28PM +0200, Richard Biener wrote:
> >> > Forcefully setting STAGE3_[CT]FLAGS doesn't have any effect on
> >> > a checking enabled build but it will disrupt profiledbootstrap
> >> > on a release build by training with -fchecking.  Suggestions
> >> > welcome - not sure whether adjusting STAGE3_[CT]FLAGS after
> >> > setting STAGEtrain_[CT]FLAGS will have the desired effect of
> >> > leaving the latter alone.
> >> 
> >> You could perhaps replace
> >> STAGEtrain_CFLAGS = $(STAGE3_CFLAGS)
> >> STAGEtrain_TFLAGS = $(STAGE3_TFLAGS)
> >> with
> >> STAGEtrain_CFLAGS = $(filter-out -fchecking,$(STAGE3_CFLAGS))
> >> STAGEtrain_TFLAGS = $(filter-out -fchecking,$(STAGE3_TFLAGS))
> >> ?
> >
> >Good idea - I'll check if that works.
> 
> Is filter-out guaranteed to be supported on anything other than GNU make?

We use it elsewhere already.

Richard.


Re: [PATCH] Don't offer suggestions for compiler-generated variables (PR c++/85515)

2018-04-26 Thread Richard Biener
On Wed, Apr 25, 2018 at 7:10 PM, Nathan Sidwell  wrote:
> On 04/25/2018 11:41 AM, David Malcolm wrote:
>>
>> Jason Turner's video C++ Weekly - Ep 112 - GCC's Leaky Abstractions shows
>> two issues where g++ offers suggestions about implementation details:
>
>
>> For the lambda capture case, there are multiple members:
>>
>> $9 = 
>
>
> These names have a space at the end, so the user cannot name them.  We could
> move the space to the beginning, if that helps?

I think compiler-generated entities that are not supposed to be
user-visible should
be DECL_ARTIFICIAL.

>> $21 = 
>> $23 = 
>
>
> These two could also have the space treatment.
>
>> $22 = 
>
>
> This is a perfectly serviceable user available function, just as any member
> operator function.
>
> nathan
> --
> Nathan Sidwell


Re: [PATCH] Document that -Wreturn-type is enabled by default for C++

2018-04-26 Thread Richard Biener
On Wed, Apr 25, 2018 at 8:54 PM, Jonathan Wakely  wrote:
> * doc/invoke.texi (-Wreturn-type): Document default status for C++.
>
> OK for trunk and gcc-8-branch?

OK.

>


Re: [PATCH][arm][FreeBSD] PR libgcc/84292

2018-04-26 Thread Richard Biener
On Wed, Apr 25, 2018 at 10:41 PM, Andreas Tobler
 wrote:
> Hi all,
>
> I'm going to commit this patch to all active branches as soon as the branch
> status permits.
> Built and tested on native armv5 FreeBSD12.

If you think it is safe then it's fine for gcc-8-branch now.

Richard.

> Thanks,
> Andreas
>
> 2018-04-25  Andreas Tobler  
> Maryse Levavasseur 
>
> PR libgcc/84292
> * config/arm/freebsd-atomic.c (SYNC_OP_AND_FETCH_N): Fix the
> op_and_fetch to return the right result.


Re: GCC 8.1 RC1 Bootstrap comparison failure on AIX

2018-04-26 Thread Richard Biener
On Thu, Apr 26, 2018 at 3:40 AM, David Edelsohn  wrote:
> Jakub and Richi,
>
> GCC 8.1 is experiencing the same bootstrap failure with GCC 8.1 RC1 as
> we saw previously.
>
> Bootstrap comparison failure!
> gcc/function-tests.o differs
>
> And the same reason: unique, static symbol that includes a random timestamp.
>
> 1949c1949
>
> < [1936]m   0x0060 1 10x02 0x
>
> _GLOBAL__F__nasfarm_edelsohn_src_gcc_8.0.1_RC_20180425_gcc_function_tests.c_DFF67DD7_0x4eda2a0ca57bf446
> ---
>> [1936]m   0x0060 1 10x02 0x 
>> _GLOBAL__F__nasfarm_edelsohn_src_gcc_8.0.1_RC_20180425_gcc_function_tests.c_DFF67DD7_0xbe25963bf76153c
>
> The entire file is protected by CHECKING_P. As DEBUG_FUNCTION
> propagates to more and more header files, this triggers when building
> without checking.
>
> How do you suggest that we try to fix it this time? I'm not certain
> that we can pull out the one function this time.  Should we return to
> the -frandom-seed patch for self-test files that you proposed last
> time?

Does

Index: gcc/cgraph.h
===
--- gcc/cgraph.h(revision 259668)
+++ gcc/cgraph.h(working copy)
@@ -,7 +,7 @@ public:
   void dump (FILE *f);

   /* Dump symbol table to stderr.  */
-  inline DEBUG_FUNCTION void debug (void)
+  DEBUG_FUNCTION void debug (void)
   {
 dump (stderr);
   }

fix it?

> Thanks, David


Re: GCC 8.1 RC1 Bootstrap comparison failure on AIX

2018-04-26 Thread Jakub Jelinek
On Thu, Apr 26, 2018 at 09:56:30AM +0200, Richard Biener wrote:
> On Thu, Apr 26, 2018 at 3:40 AM, David Edelsohn  wrote:
> > Jakub and Richi,
> >
> > GCC 8.1 is experiencing the same bootstrap failure with GCC 8.1 RC1 as
> > we saw previously.
> >
> > Bootstrap comparison failure!
> > gcc/function-tests.o differs
> >
> > And the same reason: unique, static symbol that includes a random timestamp.
> >
> > 1949c1949
> >
> > < [1936]m   0x0060 1 10x02 0x
> >
> > _GLOBAL__F__nasfarm_edelsohn_src_gcc_8.0.1_RC_20180425_gcc_function_tests.c_DFF67DD7_0x4eda2a0ca57bf446
> > ---
> >> [1936]m   0x0060 1 10x02 0x 
> >> _GLOBAL__F__nasfarm_edelsohn_src_gcc_8.0.1_RC_20180425_gcc_function_tests.c_DFF67DD7_0xbe25963bf76153c
> >
> > The entire file is protected by CHECKING_P. As DEBUG_FUNCTION
> > propagates to more and more header files, this triggers when building
> > without checking.
> >
> > How do you suggest that we try to fix it this time? I'm not certain
> > that we can pull out the one function this time.  Should we return to
> > the -frandom-seed patch for self-test files that you proposed last
> > time?
> 
> Does

That would be my guess too, but if I try to compile (on x86_64) function-tests.c
with CHECKING_P 0 and put breakpoint on the
*t = ggc_strdup (targetm.strip_name_encoding (IDENTIFIER_POINTER (id)));
line in notice_global_symbol, it is triggered only with _ZNSt9exceptionC2Ev
for weak_global_object_name and nothing else for first_global_object_name.

Jakub


Re: [PATCH] Improve bootstrap times

2018-04-26 Thread Richard Biener
On Thu, 26 Apr 2018, Richard Biener wrote:

> On Thu, 26 Apr 2018, Bernhard Reutner-Fischer wrote:
> 
> > On 25 April 2018 16:11:23 CEST, Richard Biener  wrote:
> > >On Wed, 25 Apr 2018, Jakub Jelinek wrote:
> > >
> > >> On Wed, Apr 25, 2018 at 03:52:28PM +0200, Richard Biener wrote:
> > >> > Forcefully setting STAGE3_[CT]FLAGS doesn't have any effect on
> > >> > a checking enabled build but it will disrupt profiledbootstrap
> > >> > on a release build by training with -fchecking.  Suggestions
> > >> > welcome - not sure whether adjusting STAGE3_[CT]FLAGS after
> > >> > setting STAGEtrain_[CT]FLAGS will have the desired effect of
> > >> > leaving the latter alone.
> > >> 
> > >> You could perhaps replace
> > >> STAGEtrain_CFLAGS = $(STAGE3_CFLAGS)
> > >> STAGEtrain_TFLAGS = $(STAGE3_TFLAGS)
> > >> with
> > >> STAGEtrain_CFLAGS = $(filter-out -fchecking,$(STAGE3_CFLAGS))
> > >> STAGEtrain_TFLAGS = $(filter-out -fchecking,$(STAGE3_TFLAGS))
> > >> ?
> > >
> > >Good idea - I'll check if that works.
> > 
> > Is filter-out guaranteed to be supported on anything other than GNU make?
> 
> We use it elsewhere already.

Ok, so the following passed bootstrap & profiledbootstrap (and I checked
we only get -fno-checking at the appropriate places and not -fchecking)
on trunk, a bootstrap with all languages and release checking is running
(just to see whether no-checking but -fchecking during stage3 uncovers
any latent issue).

OK for trunk?

Thanks,
Richard.

2018-04-26  Richard Biener  

* Makefile.tpl (STAGE1_TFLAGS): Add -fno-checking.
(STAGE2_CFLAGS): Likewise.
(STAGE2_TFLAGS): Likewise.
(STAGE3_CFLAGS): Add -fchecking.
(STAGE3_TFLAGS): Likewise.
(STAGEtrain_CFLAGS): Filter out -fchecking.
(STAGEtrain_TFLAGS): Likewise.
* Makefile.in: Re-generate.

Index: Makefile.tpl
===
--- Makefile.tpl(revision 259638)
+++ Makefile.tpl(working copy)
@@ -452,11 +452,21 @@ STAGE1_CONFIGURE_FLAGS = --disable-inter
  --disable-coverage --enable-languages="$(STAGE1_LANGUAGES)" \
  --disable-build-format-warnings
 
+# When using the slow stage1 compiler disable IL verification and forcefully
+# enable it when using the stage2 compiler instead.  As we later compare
+# stage2 and stage3 we are merely avoid doing redundant work, plus we apply
+# checking when building all target libraries for release builds.
+STAGE1_TFLAGS += -fno-checking
+STAGE2_CFLAGS += -fno-checking
+STAGE2_TFLAGS += -fno-checking
+STAGE3_CFLAGS += -fchecking
+STAGE3_TFLAGS += -fchecking
+
 STAGEprofile_CFLAGS = $(STAGE2_CFLAGS) -fprofile-generate
 STAGEprofile_TFLAGS = $(STAGE2_TFLAGS)
 
-STAGEtrain_CFLAGS = $(STAGE3_CFLAGS)
-STAGEtrain_TFLAGS = $(STAGE3_TFLAGS)
+STAGEtrain_CFLAGS = $(filter-out -fchecking,$(STAGE3_CFLAGS))
+STAGEtrain_TFLAGS = $(filter-out -fchecking,$(STAGE3_TFLAGS))
 
 STAGEfeedback_CFLAGS = $(STAGE4_CFLAGS) -fprofile-use
 STAGEfeedback_TFLAGS = $(STAGE4_TFLAGS)
Index: Makefile.in
===
--- Makefile.in (revision 259638)
+++ Makefile.in (working copy)
@@ -529,11 +529,21 @@ STAGE1_CONFIGURE_FLAGS = --disable-inter
  --disable-coverage --enable-languages="$(STAGE1_LANGUAGES)" \
  --disable-build-format-warnings
 
+# When using the slow stage1 compiler disable IL verification and forcefully
+# enable it when using the stage2 compiler instead.  As we later compare
+# stage2 and stage3 we are merely avoid doing redundant work, plus we apply
+# checking when building all target libraries for release builds.
+STAGE1_TFLAGS += -fno-checking
+STAGE2_CFLAGS += -fno-checking
+STAGE2_TFLAGS += -fno-checking
+STAGE3_CFLAGS += -fchecking
+STAGE3_TFLAGS += -fchecking
+
 STAGEprofile_CFLAGS = $(STAGE2_CFLAGS) -fprofile-generate
 STAGEprofile_TFLAGS = $(STAGE2_TFLAGS)
 
-STAGEtrain_CFLAGS = $(STAGE3_CFLAGS)
-STAGEtrain_TFLAGS = $(STAGE3_TFLAGS)
+STAGEtrain_CFLAGS = $(filter-out -fchecking,$(STAGE3_CFLAGS))
+STAGEtrain_TFLAGS = $(filter-out -fchecking,$(STAGE3_TFLAGS))
 
 STAGEfeedback_CFLAGS = $(STAGE4_CFLAGS) -fprofile-use
 STAGEfeedback_TFLAGS = $(STAGE4_TFLAGS)


Re: GCC 8.1 RC1 Bootstrap comparison failure on AIX

2018-04-26 Thread Jakub Jelinek
On Thu, Apr 26, 2018 at 09:56:30AM +0200, Richard Biener wrote:
> --- gcc/cgraph.h(revision 259668)
> +++ gcc/cgraph.h(working copy)
> @@ -,7 +,7 @@ public:
>void dump (FILE *f);
> 
>/* Dump symbol table to stderr.  */
> -  inline DEBUG_FUNCTION void debug (void)
> +  DEBUG_FUNCTION void debug (void)
>{
>  dump (stderr);
>}
> 
> fix it?

This is a method defined in the class which is inline even without
inline keyword, we'd need instead:

2018-04-26  Richard Biener  
Jakub Jelinek  

* cgraph.h (symbol_table): Just declare debug method here.
* symtab.c (symbol_table::debug): Define.

--- gcc/cgraph.h.jj 2018-02-09 06:44:29.992809176 +0100
+++ gcc/cgraph.h2018-04-26 10:22:41.176748872 +0200
@@ -,10 +,7 @@ public:
   void dump (FILE *f);
 
   /* Dump symbol table to stderr.  */
-  inline DEBUG_FUNCTION void debug (void)
-  {
-dump (stderr);
-  }
+  DEBUG_FUNCTION void debug (void);
 
   /* Return true if assembler names NAME1 and NAME2 leads to the same symbol
  name.  */
--- gcc/symtab.c.jj 2018-02-09 06:44:38.389804442 +0100
+++ gcc/symtab.c2018-04-26 10:25:28.565831384 +0200
@@ -947,6 +947,12 @@ symbol_table::dump (FILE *f)
 node->dump (f);
 }
 
+DEBUG_FUNCTION void
+symbol_table::debug (void)
+{
+  dump (stderr);
+}
+
 /* Return the cgraph node that has ASMNAME for its DECL_ASSEMBLER_NAME.
Return NULL if there's no such node.  */
 


Jakub


Re: [PATCH] Improve bootstrap times

2018-04-26 Thread Jakub Jelinek
On Thu, Apr 26, 2018 at 10:08:09AM +0200, Richard Biener wrote:
> Ok, so the following passed bootstrap & profiledbootstrap (and I checked
> we only get -fno-checking at the appropriate places and not -fchecking)
> on trunk, a bootstrap with all languages and release checking is running
> (just to see whether no-checking but -fchecking during stage3 uncovers
> any latent issue).
> 
> OK for trunk?
> 
> Thanks,
> Richard.
> 
> 2018-04-26  Richard Biener  
> 
>   * Makefile.tpl (STAGE1_TFLAGS): Add -fno-checking.
>   (STAGE2_CFLAGS): Likewise.
>   (STAGE2_TFLAGS): Likewise.
>   (STAGE3_CFLAGS): Add -fchecking.
>   (STAGE3_TFLAGS): Likewise.
>   (STAGEtrain_CFLAGS): Filter out -fchecking.
>   (STAGEtrain_TFLAGS): Likewise.
>   * Makefile.in: Re-generate.

Ok, thanks.

Jakub


[PATCH] Fix loop-header copying do-while loop detection (PR85116)

2018-04-26 Thread Richard Biener

In PR85116 there's a loop which isn't optimized well, first because
it is not header copied.  The reason is the do_while_loop_p predicate is
"strange".  The following adds the natural test - whether the single
latch predecessor exits the loop.  It also removes the check that
claims that a loop header with just a condition isn't a do-while loop.
I just realized the testcase is a bit too "special" and a simple
one with a diamond starting in the header would have been enough.
I'll come up with that as well and add it.

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

Richard.

2018-04-26  Richard Biener  

PR tree-optimization/85116
* tree-ssa-loop-ch.c (do_while_loop_p): A do-while loop should
have a loop exit from the single latch predecessor.  Remove
case of header with just condition.
(ch_base::copy_headers): Exclude infinite loops from any
processing.
(pass_ch::execute): Record exits.

* gcc.dg/tree-ssa/copy-headers-2.c: New testcase.
* gcc.dg/tree-ssa/copy-headers-3.c: Likewise.

Index: gcc/tree-ssa-loop-ch.c
===
--- gcc/tree-ssa-loop-ch.c  (revision 259669)
+++ gcc/tree-ssa-loop-ch.c  (working copy)
@@ -165,17 +165,28 @@ do_while_loop_p (struct loop *loop)
   return false;
 }
 
-  /* If the header contains just a condition, it is not a do-while loop.  */
-  stmt = last_and_only_stmt (loop->header);
-  if (stmt
-  && gimple_code (stmt) == GIMPLE_COND)
+  /* If the latch does not have a single predecessor, it is not a
+ do-while loop.  */
+  if (!single_pred_p (loop->latch))
 {
   if (dump_file && (dump_flags & TDF_DETAILS))
fprintf (dump_file,
-"Loop %i is not do-while loop: "
-"header contains just condition.\n", loop->num);
+"Loop %i is not do-while loop: latch has multiple "
+"predecessors.\n", loop->num);
   return false;
 }
+
+  /* If the latch predecessor doesn't exit the loop, it is not a
+ do-while loop.  */
+  if (!loop_exits_from_bb_p (loop, single_pred (loop->latch)))
+{
+  if (dump_file && (dump_flags & TDF_DETAILS))
+   fprintf (dump_file,
+"Loop %i is not do-while loop: latch predecessor "
+"does not exit loop.\n", loop->num);
+  return false;
+}
+
   if (dump_file && (dump_flags & TDF_DETAILS))
 fprintf (dump_file, "Loop %i is do-while loop\n", loop->num);
 
@@ -305,8 +316,9 @@ ch_base::copy_headers (function *fun)
   /* If the loop is already a do-while style one (either because it was
 written as such, or because jump threading transformed it into one),
 we might be in fact peeling the first iteration of the loop.  This
-in general is not a good idea.  */
-  if (!process_loop_p (loop))
+in general is not a good idea.  Also avoid touching infinite loops.  */
+  if (!loop_has_exit_edges (loop)
+ || !process_loop_p (loop))
continue;
 
   /* Iterate the header copying up to limit; this takes care of the cases
@@ -392,6 +404,15 @@ ch_base::copy_headers (function *fun)
   split_edge (loop_preheader_edge (loop));
   split_edge (loop_latch_edge (loop));
 
+  if (dump_file && (dump_flags & TDF_DETAILS))
+   {
+ if (do_while_loop_p (loop))
+   fprintf (dump_file, "Loop %d is now do-while loop.\n", loop->num);
+ else
+   fprintf (dump_file, "Loop %d is still not do-while loop.\n",
+loop->num);
+   }
+
   changed = true;
 }
 
@@ -409,7 +430,8 @@ unsigned int
 pass_ch::execute (function *fun)
 {
   loop_optimizer_init (LOOPS_HAVE_PREHEADERS
-  | LOOPS_HAVE_SIMPLE_LATCHES);
+  | LOOPS_HAVE_SIMPLE_LATCHES
+  | LOOPS_HAVE_RECORDED_EXITS);
 
   unsigned int res = copy_headers (fun);
 
Index: gcc/testsuite/gcc.dg/tree-ssa/copy-headers-2.c
===
--- gcc/testsuite/gcc.dg/tree-ssa/copy-headers-2.c  (nonexistent)
+++ gcc/testsuite/gcc.dg/tree-ssa/copy-headers-2.c  (working copy)
@@ -0,0 +1,17 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-ch2-details" } */
+
+int *a, *b;
+int test(int n, int k)
+{
+  int it = 0;
+  while (++it < n)
+{
+  if (it % k == 1)
+   a[it] = 0;
+  else
+   b[it] = 1;
+}
+}
+
+/* { dg-final { scan-tree-dump "is now do-while loop" "ch2" } } */
Index: gcc/testsuite/gcc.dg/tree-ssa/copy-headers-3.c
===
--- gcc/testsuite/gcc.dg/tree-ssa/copy-headers-3.c  (nonexistent)
+++ gcc/testsuite/gcc.dg/tree-ssa/copy-headers-3.c  (working copy)
@@ -0,0 +1,19 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fgimple -fdump-tree-ch2-details" } */
+
+int __GIMPLE (startwith("ch"))
+test2 (int n)
+{
+bb_3:
+  if 

Re: GCC 8.1 RC1 Bootstrap comparison failure on AIX

2018-04-26 Thread Jakub Jelinek
On Thu, Apr 26, 2018 at 10:28:52AM +0200, Jakub Jelinek wrote:
> On Thu, Apr 26, 2018 at 09:56:30AM +0200, Richard Biener wrote:
> > --- gcc/cgraph.h(revision 259668)
> > +++ gcc/cgraph.h(working copy)
> > @@ -,7 +,7 @@ public:
> >void dump (FILE *f);
> > 
> >/* Dump symbol table to stderr.  */
> > -  inline DEBUG_FUNCTION void debug (void)
> > +  DEBUG_FUNCTION void debug (void)
> >{
> >  dump (stderr);
> >}
> > 
> > fix it?
> 
> This is a method defined in the class which is inline even without
> inline keyword, we'd need instead:

Oops, gengtype can't parse it this way, this should work:

2018-04-26  Richard Biener  
Jakub Jelinek  

* cgraph.h (symbol_table): Just declare debug method here.
* symtab.c (symbol_table::debug): Define.

--- gcc/cgraph.h.jj 2018-02-09 06:44:29.992809176 +0100
+++ gcc/cgraph.h2018-04-26 10:22:41.176748872 +0200
@@ -,10 +,7 @@ public:
   void dump (FILE *f);
 
   /* Dump symbol table to stderr.  */
-  inline DEBUG_FUNCTION void debug (void)
-  {
-dump (stderr);
-  }
+  void DEBUG_FUNCTION debug (void);
 
   /* Return true if assembler names NAME1 and NAME2 leads to the same symbol
  name.  */
--- gcc/symtab.c.jj 2018-02-09 06:44:38.389804442 +0100
+++ gcc/symtab.c2018-04-26 10:25:28.565831384 +0200
@@ -947,6 +947,12 @@ symbol_table::dump (FILE *f)
 node->dump (f);
 }
 
+DEBUG_FUNCTION void
+symbol_table::debug (void)
+{
+  dump (stderr);
+}
+
 /* Return the cgraph node that has ASMNAME for its DECL_ASSEMBLER_NAME.
Return NULL if there's no such node.  */
 


Jakub


Re: PR85463 '[nvptx] "exit" in offloaded region doesn't terminate process'

2018-04-26 Thread Thomas Schwinge
Hi Martin!

On Wed, 25 Apr 2018 15:56:26 +0200, Martin Jambor  wrote:
> On Thu, Apr 19 2018, Thomas Schwinge wrote:
> > * testsuite/libgomp.oacc-fortran/error_stop-1.f: New file.
> > * testsuite/libgomp.oacc-fortran/error_stop-2.f: Likewise.
> > * testsuite/libgomp.oacc-fortran/error_stop-3.f: Likewise.
> > * testsuite/libgomp.oacc-fortran/stop-1.f: Likewise.
> > * testsuite/libgomp.oacc-fortran/stop-2.f: Likewise.
> > * testsuite/libgomp.oacc-fortran/stop-3.f: Likewise.
> 
> The "output pattern test" part of all of these new testcases fail on my
> HSA tester even though no HSAIL is generated for them

(Right, that's expected: there's currently no HSA/HSAIL support for
OpenACC constructs.)

> only host
> fallback is used.

So that's essentially the configuration that a lot of people use: libgomp
testing with no offloading configured; host fallback only.

> Looking at the first one:
> 
> > diff --git libgomp/testsuite/libgomp.oacc-fortran/error_stop-1.f 
> > libgomp/testsuite/libgomp.oacc-fortran/error_stop-1.f
> > new file mode 100644
> > index 000..4965e67
> > --- /dev/null
> > +++ libgomp/testsuite/libgomp.oacc-fortran/error_stop-1.f
> > @@ -0,0 +1,20 @@
> > +! { dg-do run }
> > +
> > +  PROGRAM MAIN
> > +  IMPLICIT NONE
> > +
> > +  PRINT *, "CheCKpOInT"
> > +!$ACC PARALLEL
> > +  ERROR STOP
> > +!$ACC END PARALLEL
> > +  PRINT *, "WrONg WAy"
> > +
> > +  END PROGRAM MAIN
> > +
> > +! { dg-output "CheCKpOInT(\n|\r\n|\r)+" }
> > +! { dg-output "ERROR STOP (\n|\r\n|\r)+" }
> > +! PR85463.  The "minimal" libgfortran implementation used with nvptx
> > +! offloading is a little bit different.
> > +! { dg-output "Error termination.*" { target { ! 
> > openacc_nvidia_accel_selected } } }
> > +! { dg-output "libgomp: cuStreamSynchronize error.*" { target 
> > openacc_nvidia_accel_selected } }
> > +! { dg-shouldfail "" }
> 
> I can tell that checking for "CheCKpOInT" passes but checking for "ERROR
> STOP" and "Error termination" do not.  Running the test manually, they
> both appear, but in standard error, not standard output (where
> CheCKpOInT is printed).

ACK (stdout, then stderr).  Though, as there are no "FAIL" reports so far
(including posts on the gcc-regression and gcc-testresults mailing
lists), I'm assuming that stdout/stderr do synchronize in order here, as
expected.  (As far as I remember, the Fortran PRINT does flush stdout.)

> I am not 100% sure whether that is the reason
> why they fail but do we have a way of testing std error of the executed
> compiled binary?

Is there anything "special" in your HSA machine regarding stdout/stderr?
How are you testing GCC there: native testing or some non-standard *.exp
file, for example?  Does using strace give any idea where which part of
the output is going?


Grüße
 Thomas


[PATCH] Use response files from the driver in more cases

2018-04-26 Thread Eric Botcazou
Hi,

response files were added to the GNU toolchain to work around length limits 
put on the command line by some OSes, typically Windows.  For the compiler, 
the implementation is as follows: if a response file is passed to the driver 
at link time, typically containing the list of object files, then the list of 
object files is passed to collect2 in a (second) response file and, if the 
linker is the GNU linker, collect2 then passes *all* the arguments to the 
linker in a (third) response file.

So you can flawlessly pass a gigantic list of object files at link time.  But 
this doesn't work for a gigantic list of -L switches, because the driver will 
pass them to collect2 on the command line, even if they were passed to it in a 
response file and even if they'll be passed to the GNU linker this way again.

In other words, the ball is dropped between driver and collect2.  Similarly, 
if you pass a gigantic list of -I switches at compile time, the driver will 
pass them to cc1 on the command line, even if they were passed to it in a 
response file.

Therefore the attached patch makes it so that the -I switches and -L switches 
are passed by the driver to cc1 and collect2 respectively in a response file, 
if they were passed to it this way.  That's implemented by extending the 
spec syntax with:

 %@{...}
like %{...} but puts the result into a FILE and substitutes @FILE
if an @file argument has been supplied.

and adding '@' to the LINK_COMMAND_SPEC and cpp_unique_options specs.

Tested on x86-64/Linux and Windows.  We have been using this in production for 
a couple of months.  OK for the mainline?


2018-04-26  Eric Botcazou  

* gcc.c: Document new %@{...} sequence.
(LINK_COMMAND_SPEC): Use it for the -L switches.
(cpp_unique_options): Use it for the -I switches.
(at_file_argbuf): New global variable.
(in_at_file): Likewise.
(alloc_args): Create at_file_argbuf.
(clear_args): Truncate at_file_argbuf.
(store_arg): If in_at_file, push the argument onto at_file_argbuf.
(open_at_file): New function.
(close_at_file): Likewise.
(create_at_file): Delete.
(do_spec_1) <'i'>: Use open_at_file/close_at_file.
<'o'>: Likewise.
<'@'>: New case.
(validate_switches_from_spec): Deal with %@{...} sequence.
(validate_switches): Likewise.
(driver::finalize): Call clear_args.

-- 
Eric BotcazouIndex: gcc.c
===
--- gcc.c	(revision 259642)
+++ gcc.c	(working copy)
@@ -476,8 +476,11 @@ or with constant text in a single argume
 	into the sequence of arguments that %o will substitute later.
  %V	indicates that this compilation produces no "output file".
  %W{...}
-	like %{...} but mark last argument supplied within
-	as a file to be deleted on failure.
+	like %{...} but marks the last argument supplied within as a file
+	to be deleted on failure.
+ %@{...}
+	like %{...} but puts the result into a FILE and substitutes @FILE
+	if an @file argument has been supplied.
  %o	substitutes the names of all the output files, with spaces
 	automatically placed around them.  You should write spaces
 	around the %o as well or the results are undefined.
@@ -1037,7 +1040,7 @@ proper position among the other output f
"%{fuse-ld=*:-fuse-ld=%*} " LINK_COMPRESS_DEBUG_SPEC \
"%X %{o*} %{e*} %{N} %{n} %{r}\
 %{s} %{t} %{u*} %{z} %{Z} %{!nostdlib:%{!nostartfiles:%S}} \
-%{static|no-pie|static-pie:} %{L*} %(mfwrap) %(link_libgcc) " \
+%{static|no-pie|static-pie:} %@{L*} %(mfwrap) %(link_libgcc) " \
 VTABLE_VERIFICATION_SPEC " " SANITIZER_EARLY_SPEC " %o " CHKP_SPEC " \
 %{fopenacc|fopenmp|%:gt(%{ftree-parallelize-loops=*:%*} 1):\
 	%:include(libgomp.spec)%(link_gomp)}\
@@ -1112,7 +1115,7 @@ static const char *trad_capable_cpp =
therefore no dependency entry, confuses make into thinking a .o
file that happens to exist is up-to-date.  */
 static const char *cpp_unique_options =
-"%{!Q:-quiet} %{nostdinc*} %{C} %{CC} %{v} %{I*&F*} %{P} %I\
+"%{!Q:-quiet} %{nostdinc*} %{C} %{CC} %{v} %@{I*&F*} %{P} %I\
  %{MD:-MD %{!o:%b.d}%{o*:%.d%*}}\
  %{MMD:-MMD %{!o:%b.d}%{o*:%.d%*}}\
  %{M} %{MM} %{MF*} %{MG} %{MP} %{MQ*} %{MT*}\
@@ -1927,9 +1930,14 @@ set_spec (const char *name, const char *
 typedef const char *const_char_p; /* For DEF_VEC_P.  */
 
 /* Vector of pointers to arguments in the current line of specifications.  */
-
 static vec argbuf;
 
+/* Likewise, but for the current @file.  */
+static vec at_file_argbuf;
+
+/* Whether an @file is currently open.  */
+static bool in_at_file = false;
+
 /* Were the options -c, -S or -E passed.  */
 static int have_c = 0;
 
@@ -1969,6 +1977,7 @@ static void
 alloc_args (void)
 {
   argbuf.create (10);
+  at_file_argbuf.create (10);
 }
 
 /* Clear out the vector of arguments (after a command is executed).  */
@@ -1977,6 +1986,7 @@ static void
 clear_args (void)
 {
   argbu

dumpfile cleanup

2018-04-26 Thread Nathan Sidwell
I wanted to add '-' as a synonym for stdout in the dumping machinery.  But this 
bit of cleanup's needed first.  We check the special stdout/stderr names in 3 
different places -- that's crying out for a worker function.  We also check 
those streams by name before determining whether to fclose.  It seems more 
straight forwards to just compare to stdin & stdout themselves.


This patch does that cleanup, and the next patch will add the '-' functionality. 
 I've been using this on the modules branch for some time now.


ok for trunk?

nathan
--
Nathan Sidwell
2018-04-26  Nathan Sidwell  

	* dumpfile.c (dump_open): New.
	(dump_open_alternate_stream, dump_start, dump_begin): Call it.
	(dump_finish): Detect stdio/stderr by value not name.

Index: dumpfile.c
===
--- dumpfile.c	(revision 259657)
+++ dumpfile.c	(working copy)
@@ -312,6 +312,27 @@ get_dump_file_name (struct dump_file_inf
   return concat (dump_base_name, dump_id, dfi->suffix, NULL);
 }
 
+/* Open a dump file called FILENAME.  Some filenames are special and
+   refer to the standard streams.  TRUNC indicates whether this is the
+   first open (so the file should be truncated, rather than appended).
+   An error message is emitted in the event of failure.  */
+
+static FILE *
+dump_open (const char *filename, bool trunc)
+{
+  if (strcmp ("stderr", filename) == 0)
+return stderr;
+
+  if (strcmp ("stdout", filename) == 0)
+return stdout;
+
+  FILE *stream = fopen (filename, trunc ? "w" : "a");
+
+  if (!stream)
+error ("could not open dump file %qs: %m", filename);
+  return stream;
+}
+
 /* For a given DFI, open an alternate dump filename (which could also
be a standard stream such as stdout/stderr). If the alternate dump
file cannot be opened, return NULL.  */
@@ -319,22 +340,15 @@ get_dump_file_name (struct dump_file_inf
 static FILE *
 dump_open_alternate_stream (struct dump_file_info *dfi)
 {
-  FILE *stream ;
   if (!dfi->alt_filename)
 return NULL;
 
   if (dfi->alt_stream)
 return dfi->alt_stream;
 
-  stream = strcmp ("stderr", dfi->alt_filename) == 0
-? stderr
-: strcmp ("stdout", dfi->alt_filename) == 0
-? stdout
-: fopen (dfi->alt_filename, dfi->alt_state < 0 ? "w" : "a");
+  FILE *stream = dump_open (dfi->alt_filename, dfi->alt_state < 0);
 
-  if (!stream)
-error ("could not open dump file %qs: %m", dfi->alt_filename);
-  else
+  if (stream)
 dfi->alt_state = 1;
 
   return stream;
@@ -515,14 +529,8 @@ dump_start (int phase, dump_flags_t *fla
   name = get_dump_file_name (phase);
   if (name)
 {
-  stream = strcmp ("stderr", name) == 0
-  ? stderr
-  : strcmp ("stdout", name) == 0
-  ? stdout
-  : fopen (name, dfi->pstate < 0 ? "w" : "a");
-  if (!stream)
-error ("could not open dump file %qs: %m", name);
-  else
+  stream = dump_open (name, dfi->pstate < 0);
+  if (stream)
 {
   dfi->pstate = 1;
   count++;
@@ -562,13 +570,10 @@ dump_finish (int phase)
   if (phase < 0)
 return;
   dfi = get_dump_file_info (phase);
-  if (dfi->pstream && (!dfi->pfilename
-   || (strcmp ("stderr", dfi->pfilename) != 0
-   && strcmp ("stdout", dfi->pfilename) != 0)))
+  if (dfi->pstream && dfi->pstream != stdout && dfi->pstream != stderr)
 fclose (dfi->pstream);
 
-  if (dfi->alt_stream && strcmp ("stderr", dfi->alt_filename) != 0
-  && strcmp ("stdout", dfi->alt_filename) != 0)
+  if (dfi->alt_stream && dfi->alt_stream != stdout && dfi->alt_stream != stderr)
 fclose (dfi->alt_stream);
 
   dfi->alt_stream = NULL;
@@ -607,15 +612,8 @@ dump_begin (int phase, dump_flags_t *fla
 return NULL;
   dfi = get_dump_file_info (phase);
 
-  stream = strcmp ("stderr", name) == 0
-? stderr
-: strcmp ("stdout", name) == 0
-? stdout
-: fopen (name, dfi->pstate < 0 ? "w" : "a");
-
-  if (!stream)
-error ("could not open dump file %qs: %m", name);
-  else
+  stream = dump_open (name, dfi->pstate < 0);
+  if (stream)
 dfi->pstate = 1;
   free (name);
 


[PATCH] Fix aarch64 ILP32 ICE with vaarg gimplified code

2018-04-26 Thread Richard Biener

Seen by  Christophe Lyon, verified with a cross that this fixes the
issue.

aarch64 people, can you please test & commit this?

Thanks,
Richard.

2018-04-26  Richard Biener  

* config/aarch64/aarch64.c: Simplify ap.__stack advance and
fix for ILP32.

Index: gcc/config/aarch64/aarch64.c
===
--- gcc/config/aarch64/aarch64.c(revision 259669)
+++ gcc/config/aarch64/aarch64.c(working copy)
@@ -12278,12 +12278,9 @@ aarch64_gimplify_va_arg_expr (tree valis
   else
 roundup = NULL;
   /* Advance ap.__stack  */
-  t = fold_convert (intDI_type_node, arg);
-  t = build2 (PLUS_EXPR, TREE_TYPE (t), t,
- build_int_cst (TREE_TYPE (t), size + 7));
+  t = fold_build_pointer_plus_hwi (arg, size + 7);
   t = build2 (BIT_AND_EXPR, TREE_TYPE (t), t,
  build_int_cst (TREE_TYPE (t), -8));
-  t = fold_convert (TREE_TYPE (arg), t);
   t = build2 (MODIFY_EXPR, TREE_TYPE (stack), unshare_expr (stack), t);
   /* String up roundup and advance.  */
   if (roundup)


Re: [PATCH] Fix loop-header copying do-while loop detection (PR85116)

2018-04-26 Thread Richard Biener
On Thu, 26 Apr 2018, Richard Biener wrote:

> 
> In PR85116 there's a loop which isn't optimized well, first because
> it is not header copied.  The reason is the do_while_loop_p predicate is
> "strange".  The following adds the natural test - whether the single
> latch predecessor exits the loop.  It also removes the check that
> claims that a loop header with just a condition isn't a do-while loop.
> I just realized the testcase is a bit too "special" and a simple
> one with a diamond starting in the header would have been enough.
> I'll come up with that as well and add it.

I added one, note it would not have copied the header in the end
because of extra checks elsewhere.

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

This is what I have committed.

Richard.

2018-04-26  Richard Biener  

PR tree-optimization/85116
* tree-ssa-loop-ch.c (do_while_loop_p): A do-while loop should
have a loop exit from the single latch predecessor.  Remove
case of header with just condition.
(ch_base::copy_headers): Exclude infinite loops from any
processing.
(pass_ch::execute): Record exits.

* gcc.dg/tree-ssa/copy-headers-2.c: New testcase.
* gcc.dg/tree-ssa/copy-headers-3.c: Likewise.
* gcc.dg/tree-ssa/copy-headers-4.c: Likewise.
* gcc.dg/tree-ssa/loadpre6.c: Adjust.

Index: gcc/tree-ssa-loop-ch.c
===
--- gcc/tree-ssa-loop-ch.c  (revision 259669)
+++ gcc/tree-ssa-loop-ch.c  (working copy)
@@ -165,17 +165,28 @@ do_while_loop_p (struct loop *loop)
   return false;
 }
 
-  /* If the header contains just a condition, it is not a do-while loop.  */
-  stmt = last_and_only_stmt (loop->header);
-  if (stmt
-  && gimple_code (stmt) == GIMPLE_COND)
+  /* If the latch does not have a single predecessor, it is not a
+ do-while loop.  */
+  if (!single_pred_p (loop->latch))
 {
   if (dump_file && (dump_flags & TDF_DETAILS))
fprintf (dump_file,
-"Loop %i is not do-while loop: "
-"header contains just condition.\n", loop->num);
+"Loop %i is not do-while loop: latch has multiple "
+"predecessors.\n", loop->num);
   return false;
 }
+
+  /* If the latch predecessor doesn't exit the loop, it is not a
+ do-while loop.  */
+  if (!loop_exits_from_bb_p (loop, single_pred (loop->latch)))
+{
+  if (dump_file && (dump_flags & TDF_DETAILS))
+   fprintf (dump_file,
+"Loop %i is not do-while loop: latch predecessor "
+"does not exit loop.\n", loop->num);
+  return false;
+}
+
   if (dump_file && (dump_flags & TDF_DETAILS))
 fprintf (dump_file, "Loop %i is do-while loop\n", loop->num);
 
@@ -305,8 +316,9 @@ ch_base::copy_headers (function *fun)
   /* If the loop is already a do-while style one (either because it was
 written as such, or because jump threading transformed it into one),
 we might be in fact peeling the first iteration of the loop.  This
-in general is not a good idea.  */
-  if (!process_loop_p (loop))
+in general is not a good idea.  Also avoid touching infinite loops.  */
+  if (!loop_has_exit_edges (loop)
+ || !process_loop_p (loop))
continue;
 
   /* Iterate the header copying up to limit; this takes care of the cases
@@ -392,6 +404,15 @@ ch_base::copy_headers (function *fun)
   split_edge (loop_preheader_edge (loop));
   split_edge (loop_latch_edge (loop));
 
+  if (dump_file && (dump_flags & TDF_DETAILS))
+   {
+ if (do_while_loop_p (loop))
+   fprintf (dump_file, "Loop %d is now do-while loop.\n", loop->num);
+ else
+   fprintf (dump_file, "Loop %d is still not do-while loop.\n",
+loop->num);
+   }
+
   changed = true;
 }
 
@@ -409,7 +430,8 @@ unsigned int
 pass_ch::execute (function *fun)
 {
   loop_optimizer_init (LOOPS_HAVE_PREHEADERS
-  | LOOPS_HAVE_SIMPLE_LATCHES);
+  | LOOPS_HAVE_SIMPLE_LATCHES
+  | LOOPS_HAVE_RECORDED_EXITS);
 
   unsigned int res = copy_headers (fun);
 
Index: gcc/testsuite/gcc.dg/tree-ssa/copy-headers-2.c
===
--- gcc/testsuite/gcc.dg/tree-ssa/copy-headers-2.c  (nonexistent)
+++ gcc/testsuite/gcc.dg/tree-ssa/copy-headers-2.c  (working copy)
@@ -0,0 +1,17 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-ch2-details" } */
+
+int *a, *b;
+int test(int n, int k)
+{
+  int it = 0;
+  while (++it < n)
+{
+  if (it % k == 1)
+   a[it] = 0;
+  else
+   b[it] = 1;
+}
+}
+
+/* { dg-final { scan-tree-dump "is now do-while loop" "ch2" } } */
Index: gcc/testsuite/gcc.dg/tree-ssa/copy-headers-3.c
===
--- gcc/test

[PATCH] Prevent excessive loop-header copying with multiple exits

2018-04-26 Thread Richard Biener

The following makes loop-header copying stop after the first exit test
it copied.  The reports rightfully complain about too much peeling.
If some cases pop up which show we should peel up to a specific test
we need to improve this heuristic which simply errs on the easy side.

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

Richard.

2018-04-26  Richard Biener  

PR tree-optimization/28364
PR tree-optimization/85275
* tree-ssa-loop-ch.c (ch_base::copy_headers): Stop after
copying first exit test.

* gcc.dg/tree-ssa/copy-headers-5.c: New testcase.

Index: gcc/tree-ssa-loop-ch.c
===
--- gcc/tree-ssa-loop-ch.c  (revision 259669)
+++ gcc/tree-ssa-loop-ch.c  (working copy)
@@ -328,6 +340,11 @@ ch_base::copy_headers (function *fun)
  bbs[n_bbs++] = header;
  gcc_assert (bbs_size > n_bbs);
  header = exit->dest;
+ /* Make sure to stop copying after we copied the first exit test.
+Without further heuristics we do not want to rotate the loop
+any further.  */
+ if (loop_exits_from_bb_p (loop, exit->src))
+   break;
}
 
   if (!exit)
Index: gcc/testsuite/gcc.dg/tree-ssa/copy-headers-5.c
===
--- gcc/testsuite/gcc.dg/tree-ssa/copy-headers-5.c  (nonexistent)
+++ gcc/testsuite/gcc.dg/tree-ssa/copy-headers-5.c  (working copy)
@@ -0,0 +1,16 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-ch2-details" } */
+
+int is_sorted(int *a, int n)
+{
+  for (int i = 0; i < n - 1; i++)
+if (a[i] > a[i + 1])
+  return 0;
+  return 1;
+}
+
+/* Verify we apply loop header copying but only copy the IV test and
+   not the alternate exit test.  */
+
+/* { dg-final { scan-tree-dump "is now do-while loop" "ch2" } } */
+/* { dg-final { scan-tree-dump-times "  if " 3 "ch2" } } */


Re: PR85463 '[nvptx] "exit" in offloaded region doesn't terminate process'

2018-04-26 Thread Martin Jambor
Hi,

On Thu, Apr 26 2018, Thomas Schwinge wrote:
> Hi Martin!
>
> On Wed, 25 Apr 2018 15:56:26 +0200, Martin Jambor  wrote:
>> On Thu, Apr 19 2018, Thomas Schwinge wrote:
>> > * testsuite/libgomp.oacc-fortran/error_stop-1.f: New file.
>> > * testsuite/libgomp.oacc-fortran/error_stop-2.f: Likewise.
>> > * testsuite/libgomp.oacc-fortran/error_stop-3.f: Likewise.
>> > * testsuite/libgomp.oacc-fortran/stop-1.f: Likewise.
>> > * testsuite/libgomp.oacc-fortran/stop-2.f: Likewise.
>> > * testsuite/libgomp.oacc-fortran/stop-3.f: Likewise.
>> 
>> The "output pattern test" part of all of these new testcases fail on my
>> HSA tester even though no HSAIL is generated for them
>
>
> Is there anything "special" in your HSA machine regarding stdout/stderr?
> How are you testing GCC there: native testing or some non-standard *.exp
> file, for example?  Does using strace give any idea where which part of
> the output is going?
>

this issue was caused on my side, because the ROCm runtime produced some
debug output to stderr upon initialization.  I have backported a fix for
this to my packages and the issues is gone.

It is still slightly intriguing, because the patterns dg-output was
searching for were present there also before, the debug stuff did not
appear in the middle of them or anything, so I do not quite understand
why the tests were failing before, but it is probably not worth
investigating.  Let's hope the periodic run next week will agree with my
manual tests.

Sorry for the noise,

Martin


Re: [PATCH] Fix aarch64 ILP32 ICE with vaarg gimplified code

2018-04-26 Thread Christophe Lyon
On 26 April 2018 at 14:09, Richard Biener  wrote:
>
> Seen by  Christophe Lyon, verified with a cross that this fixes the
> issue.
>
> aarch64 people, can you please test & commit this?
>

As I have just written in bugzilla, this patch avoids an ICE when
compiling newlib's sysopen.i,
but I still see a similar crash when compiling vfprintf.i.

Thanks,

Christophe

> Thanks,
> Richard.
>
> 2018-04-26  Richard Biener  
>
> * config/aarch64/aarch64.c: Simplify ap.__stack advance and
> fix for ILP32.
>
> Index: gcc/config/aarch64/aarch64.c
> ===
> --- gcc/config/aarch64/aarch64.c(revision 259669)
> +++ gcc/config/aarch64/aarch64.c(working copy)
> @@ -12278,12 +12278,9 @@ aarch64_gimplify_va_arg_expr (tree valis
>else
>  roundup = NULL;
>/* Advance ap.__stack  */
> -  t = fold_convert (intDI_type_node, arg);
> -  t = build2 (PLUS_EXPR, TREE_TYPE (t), t,
> - build_int_cst (TREE_TYPE (t), size + 7));
> +  t = fold_build_pointer_plus_hwi (arg, size + 7);
>t = build2 (BIT_AND_EXPR, TREE_TYPE (t), t,
>   build_int_cst (TREE_TYPE (t), -8));
> -  t = fold_convert (TREE_TYPE (arg), t);
>t = build2 (MODIFY_EXPR, TREE_TYPE (stack), unshare_expr (stack), t);
>/* String up roundup and advance.  */
>if (roundup)


Re: PR testsuite/85483: Move aarch64/sve/vcond_1.c test to g++.dg/other/

2018-04-26 Thread Richard Sandiford
Kyrill  Tkachov  writes:
> Hi all,
>
> I totally botched up this sve test file in 259437.
> It needs C++, so move it to g++.dg/other and make it a .C file.
> Also adds the target guards to prevent it from running on non-aarch64 targets.
>
> Tested that it passes on aarch64-none-elf and doesn't get run on 
> arm-none-eabi.
>
> Committing to trunk as obvious.
>
> Sorry for the snafu,
>
> Kyrill
>
> 2018-04-20  Kyrylo Tkachov  
>
>  PR testsuite/85483
>  * gcc.target/aarch64/sve/vcond_1.c: Move to...
>  * g++.dg/other/sve_vcond_1.C: ... Here.  Add target directives.
>  * gcc.target/aarch64/sve/vcond_1_run.c: Move to...
>  * g++.dg/other/sve_vcond_1_run.C: ... Here.  Change include file name.

FWIW, I think it would have been better to move them to
g++.target/aarch64/sve (which already exists).  That way we avoid
forcing an -march= option when the default already includes SVE.

Thanks,
Richard




Re: [PATCH] Fix aarch64 ILP32 ICE with vaarg gimplified code

2018-04-26 Thread Richard Biener
On Thu, 26 Apr 2018, Christophe Lyon wrote:

> On 26 April 2018 at 14:09, Richard Biener  wrote:
> >
> > Seen by  Christophe Lyon, verified with a cross that this fixes the
> > issue.
> >
> > aarch64 people, can you please test & commit this?
> >
> 
> As I have just written in bugzilla, this patch avoids an ICE when
> compiling newlib's sysopen.i,
> but I still see a similar crash when compiling vfprintf.i.

There's a similar case still left.  Complete patch:

Index: gcc/config/aarch64/aarch64.c
===
--- gcc/config/aarch64/aarch64.c(revision 259669)
+++ gcc/config/aarch64/aarch64.c(working copy)
@@ -12267,23 +12267,17 @@ aarch64_gimplify_va_arg_expr (tree valis
   if (align > 8)
 {
   /* if (alignof(type) > 8) (arg = arg + 15) & -16;  */
-  t = fold_convert (intDI_type_node, arg);
-  t = build2 (PLUS_EXPR, TREE_TYPE (t), t,
- build_int_cst (TREE_TYPE (t), 15));
+  t = fold_build_pointer_plus_hwi (arg, 15);
   t = build2 (BIT_AND_EXPR, TREE_TYPE (t), t,
  build_int_cst (TREE_TYPE (t), -16));
-  t = fold_convert (TREE_TYPE (arg), t);
   roundup = build2 (MODIFY_EXPR, TREE_TYPE (arg), arg, t);
 }
   else
 roundup = NULL;
   /* Advance ap.__stack  */
-  t = fold_convert (intDI_type_node, arg);
-  t = build2 (PLUS_EXPR, TREE_TYPE (t), t,
- build_int_cst (TREE_TYPE (t), size + 7));
+  t = fold_build_pointer_plus_hwi (arg, size + 7);
   t = build2 (BIT_AND_EXPR, TREE_TYPE (t), t,
  build_int_cst (TREE_TYPE (t), -8));
-  t = fold_convert (TREE_TYPE (arg), t);
   t = build2 (MODIFY_EXPR, TREE_TYPE (stack), unshare_expr (stack), t);
   /* String up roundup and advance.  */
   if (roundup)


> Thanks,
> 
> Christophe
> 
> > Thanks,
> > Richard.
> >
> > 2018-04-26  Richard Biener  
> >
> > * config/aarch64/aarch64.c: Simplify ap.__stack advance and
> > fix for ILP32.
> >
> > Index: gcc/config/aarch64/aarch64.c
> > ===
> > --- gcc/config/aarch64/aarch64.c(revision 259669)
> > +++ gcc/config/aarch64/aarch64.c(working copy)
> > @@ -12278,12 +12278,9 @@ aarch64_gimplify_va_arg_expr (tree valis
> >else
> >  roundup = NULL;
> >/* Advance ap.__stack  */
> > -  t = fold_convert (intDI_type_node, arg);
> > -  t = build2 (PLUS_EXPR, TREE_TYPE (t), t,
> > - build_int_cst (TREE_TYPE (t), size + 7));
> > +  t = fold_build_pointer_plus_hwi (arg, size + 7);
> >t = build2 (BIT_AND_EXPR, TREE_TYPE (t), t,
> >   build_int_cst (TREE_TYPE (t), -8));
> > -  t = fold_convert (TREE_TYPE (arg), t);
> >t = build2 (MODIFY_EXPR, TREE_TYPE (stack), unshare_expr (stack), t);
> >/* String up roundup and advance.  */
> >if (roundup)
> 
> 

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


[PATCH] Fix PR c++/85400

2018-04-26 Thread Eric Botcazou
Hi,

for the attached testcase compiled/linked with -shared -fPIC -O, the Solaris 
linker chokes on SPARC because the generated code uses the local-dynamic TLS 
model for a global symbol:

ld: fatal: relocation error: R_SPARC_TLS_LDM_HI22: file /var/tmp//ccKG6GQC.o: 
symbol Test::blah(int)::mything: bound to: /var/tmp//ccKG6GQC.o: relocation 
illegal when not bound to object being created

The symbol is a local TLS symbol defined in an inline method of a class so it 
is first local so decl_default_tls_model chooses TLS_MODEL_LOCAL_DYNAMIC.  But 
then it is "commonized" by the C++ front-end:

/* If a local static variable is declared in an inline function, or if
   we have a weak definition, we must endeavor to create only one
   instance of the variable at link-time.  */

which calls comdat_linkage, which in turn calls make_decl_one_only, which 
makes it weak and public, so unsuitable for the local-dynamic TLS model.

The proposed fix is to reset the TLS model after the commonization, but of 
course only if no tls_model attribute was set on the variable, hence the fix 
for handle_tls_model_attribute.  Tested on x86-64/Linux, OK for mainline?


2018-04-26  Eric Botcazou  

cp/
PR c++/85400
* decl.c (cp_finish_decl): Recompute the TLS model after commonizing
a TLS-local variable, unless it has got an explicit TLS model.
c-family/
* c-attribs.c (handle_visibility_attribute): Do not set no_add_attrs.


2018-04-26  Eric Botcazou  

* g++.dg/tls/pr85400.C: New test.

-- 
Eric BotcazouIndex: cp/decl.c
===
--- cp/decl.c	(revision 259642)
+++ cp/decl.c	(working copy)
@@ -7216,9 +7216,14 @@ cp_finish_decl (tree decl, tree init, bo
 	{
 	  layout_var_decl (decl);
 	  maybe_commonize_var (decl);
+
+	  /* This needs to be adjusted after the linkage is set.  */
+	  if (CP_DECL_THREAD_LOCAL_P (decl)
+	  && !lookup_attribute ("tls_model", DECL_ATTRIBUTES (decl)))
+	set_decl_tls_model (decl, decl_default_tls_model (decl));
 	}
 
-  /* This needs to happen after the linkage is set. */
+  /* This needs to happen after the linkage is set.  */
   determine_visibility (decl);
 
   if (var_definition_p && TREE_STATIC (decl))
Index: c-family/c-attribs.c
===
--- c-family/c-attribs.c	(revision 259642)
+++ c-family/c-attribs.c	(working copy)
@@ -2299,14 +2299,13 @@ handle_visibility_attribute (tree *node,
 
 static tree
 handle_tls_model_attribute (tree *node, tree name, tree args,
-			int ARG_UNUSED (flags), bool *no_add_attrs)
+			int ARG_UNUSED (flags),
+			bool *ARG_UNUSED (no_add_attrs))
 {
   tree id;
   tree decl = *node;
   enum tls_model kind;
 
-  *no_add_attrs = true;
-
   if (!VAR_P (decl) || !DECL_THREAD_LOCAL_P (decl))
 {
   warning (OPT_Wattributes, "%qE attribute ignored", name);
// PR c++/85400
// Testcase by Brian Vandenberg 

// { dg-do link { target c++11 } }
// { dg-require-effective-target fpic }
// { dg-require-effective-target shared }
// { dg-require-effective-target tls }
// { dg-options "-shared -fPIC -O" }
// { dg-add-options tls }

struct Test
{
  int blah (int y)
  {
thread_local int mything = 3;
mything = y > 0 ? y : mything;
return mything;
  }
};

int stuff (Test& test, int y)
{
  return test.blah(y);
}


Re: [PATCH][AArch64] PR target/85512: Tighten SIMD right shift immediate constraints

2018-04-26 Thread Richard Sandiford
Kyrill  Tkachov  writes:
> On 24/04/18 17:41, Jakub Jelinek wrote:
>> On Tue, Apr 24, 2018 at 05:22:15PM +0100, Kyrill Tkachov wrote:
>>> I've cleaned up the testcase a bit to leave only the function that
>>> generates the invalid instruction,
>>> making it shorter.
>>>
>>> Jakub, is the patch ok to go in for GCC 8 from your perspective?
>> The PR is marked P1 now, so sure, please commit this for GCC 8, the sooner
>> the better.  We have only one other P1 left.
>
> Thanks, I've committed it as 259614.
>
>> The only thing I'm unsure about is whether you want to make the top of the
>> range 32 and 64 rather than just 31 and 63, after all the operand
>> predicate used there requires < 32 and < 64, and from middle-end's POV
>> shifts by 32 or 64 are undefined (unless SHIFT_COUNT_TRUNCATED, but
>> aarch64 defines it to
>> #define SHIFT_COUNT_TRUNCATED (!TARGET_SIMD)
>>
>> So, using
>> (match_test "IN_RANGE (ival, 1, 31)")))
>> and
>> (match_test "IN_RANGE (ival, 1, 63)")))
>> would feel safer to me, but your call.
>
> I don't think this is necessary.
> We already nominally allow shifts up to 32/64 in the SIMD versions
> (see aarch64_simd_ashr in aarch64-simd.md) though I imagine if such 
> shifts
> are undefined in the midend then it will just not generate them or at least 
> blow
> up somewhere along the way.
>
> So I've left the range as is.

But as Jakub says, it's wrong for the constraints to accept something
that the predicates don't.  That must never happen for reloadable
operands.  E.g. we could enter RA with a 32-bit shift by a register R
that is known to be equal to 32.  As it stands, the constraints allow
the RA to replace R with 32 (e.g. if R would otherwise be spilled) but
the predicates would reject the result.  We'd then get an unrecognisable
insn ICE.

So I think we either need to adjust the predicate to accept the wider
range, or adjust the constraint as above.  At this stage adjusting the
constraint seems safer.

Thanks,
Richard


Re: [PATCH] Fix aarch64 ILP32 ICE with vaarg gimplified code

2018-04-26 Thread Christophe Lyon
On 26 April 2018 at 15:41, Richard Biener  wrote:
> On Thu, 26 Apr 2018, Christophe Lyon wrote:
>
>> On 26 April 2018 at 14:09, Richard Biener  wrote:
>> >
>> > Seen by  Christophe Lyon, verified with a cross that this fixes the
>> > issue.
>> >
>> > aarch64 people, can you please test & commit this?
>> >
>>
>> As I have just written in bugzilla, this patch avoids an ICE when
>> compiling newlib's sysopen.i,
>> but I still see a similar crash when compiling vfprintf.i.
>
> There's a similar case still left.  Complete patch:
>
With this version, the toolchain build completes, but I didn't run
make check, nor tried aarch64-linux-gnu.

> Index: gcc/config/aarch64/aarch64.c
> ===
> --- gcc/config/aarch64/aarch64.c(revision 259669)
> +++ gcc/config/aarch64/aarch64.c(working copy)
> @@ -12267,23 +12267,17 @@ aarch64_gimplify_va_arg_expr (tree valis
>if (align > 8)
>  {
>/* if (alignof(type) > 8) (arg = arg + 15) & -16;  */
> -  t = fold_convert (intDI_type_node, arg);
> -  t = build2 (PLUS_EXPR, TREE_TYPE (t), t,
> - build_int_cst (TREE_TYPE (t), 15));
> +  t = fold_build_pointer_plus_hwi (arg, 15);
>t = build2 (BIT_AND_EXPR, TREE_TYPE (t), t,
>   build_int_cst (TREE_TYPE (t), -16));
> -  t = fold_convert (TREE_TYPE (arg), t);
>roundup = build2 (MODIFY_EXPR, TREE_TYPE (arg), arg, t);
>  }
>else
>  roundup = NULL;
>/* Advance ap.__stack  */
> -  t = fold_convert (intDI_type_node, arg);
> -  t = build2 (PLUS_EXPR, TREE_TYPE (t), t,
> - build_int_cst (TREE_TYPE (t), size + 7));
> +  t = fold_build_pointer_plus_hwi (arg, size + 7);
>t = build2 (BIT_AND_EXPR, TREE_TYPE (t), t,
>   build_int_cst (TREE_TYPE (t), -8));
> -  t = fold_convert (TREE_TYPE (arg), t);
>t = build2 (MODIFY_EXPR, TREE_TYPE (stack), unshare_expr (stack), t);
>/* String up roundup and advance.  */
>if (roundup)
>
>
>> Thanks,
>>
>> Christophe
>>
>> > Thanks,
>> > Richard.
>> >
>> > 2018-04-26  Richard Biener  
>> >
>> > * config/aarch64/aarch64.c: Simplify ap.__stack advance and
>> > fix for ILP32.
>> >
>> > Index: gcc/config/aarch64/aarch64.c
>> > ===
>> > --- gcc/config/aarch64/aarch64.c(revision 259669)
>> > +++ gcc/config/aarch64/aarch64.c(working copy)
>> > @@ -12278,12 +12278,9 @@ aarch64_gimplify_va_arg_expr (tree valis
>> >else
>> >  roundup = NULL;
>> >/* Advance ap.__stack  */
>> > -  t = fold_convert (intDI_type_node, arg);
>> > -  t = build2 (PLUS_EXPR, TREE_TYPE (t), t,
>> > - build_int_cst (TREE_TYPE (t), size + 7));
>> > +  t = fold_build_pointer_plus_hwi (arg, size + 7);
>> >t = build2 (BIT_AND_EXPR, TREE_TYPE (t), t,
>> >   build_int_cst (TREE_TYPE (t), -8));
>> > -  t = fold_convert (TREE_TYPE (arg), t);
>> >t = build2 (MODIFY_EXPR, TREE_TYPE (stack), unshare_expr (stack), t);
>> >/* String up roundup and advance.  */
>> >if (roundup)
>>
>>
>
> --
> Richard Biener 
> SUSE LINUX GmbH, GF: Felix Imendoerffer, Jane Smithard, Graham Norton, HRB 
> 21284 (AG Nuernberg)


Re: dumpfile cleanup

2018-04-26 Thread Richard Biener
On Thu, Apr 26, 2018 at 2:00 PM, Nathan Sidwell  wrote:
> I wanted to add '-' as a synonym for stdout in the dumping machinery.  But
> this bit of cleanup's needed first.  We check the special stdout/stderr
> names in 3 different places -- that's crying out for a worker function.  We
> also check those streams by name before determining whether to fclose.  It
> seems more straight forwards to just compare to stdin & stdout themselves.
>
> This patch does that cleanup, and the next patch will add the '-'
> functionality.  I've been using this on the modules branch for some time
> now.
>
> ok for trunk?

OK.

Richard.

>
> nathan
> --
> Nathan Sidwell


[PATCH] Do not set nothrow flag on recursive function with stack checking

2018-04-26 Thread Eric Botcazou
Hi,

when stack checking is enabled in Ada, it is supposed to be able to handle the 
case of a recursive function that does essentially nothing.  But in this case 
the IPA machinery will compute that the function is nothrow, which means that 
the Storage_Error exception cannot be caught by the caller.

Tested on x86-64/Linux, OK for the mainline?


2018-04-26  Eric Botcazou  

* ipa-pure-const.c (check_call): In non-IPA mode, set can_throw flag
for a recursive call that can throw if stack checking is enabled.
(check_stmt): Fix formatting.
(propagate_nothrow): Set can_throw for a recursive call if exceptions
and stack checking are enabled.
(pass_nothrow::execute): Do not set the nothrow flag if there is a
recursive call that can throw and stack checking is enabled.


2018-04-26  Eric Botcazou  

* gnat.dg/stack_check4.adb: New test.

-- 
Eric Botcazou
Index: ipa-pure-const.c
===
--- ipa-pure-const.c	(revision 259642)
+++ ipa-pure-const.c	(working copy)
@@ -674,12 +674,19 @@ check_call (funct_state local, gcall *ca
 local->can_free = true;
 
   /* When not in IPA mode, we can still handle self recursion.  */
-  if (!ipa && callee_t
+  if (!ipa
+  && callee_t
   && recursive_call_p (current_function_decl, callee_t))
 {
   if (dump_file)
-fprintf (dump_file, "Recursive call can loop.\n");
+fprintf (dump_file, "recursive call can loop\n");
   local->looping = true;
+  if (possibly_throws_externally && flag_stack_check)
+	{
+	  if (dump_file)
+	fprintf (dump_file, "recursive call can throw\n");
+	  local->can_throw = true;
+	}
 }
   /* Either callee is unknown or we are doing local analysis.
  Look to see if there are any bits available for the callee (such as by
@@ -795,8 +802,7 @@ check_stmt (gimple_stmt_iterator *gsip,
   print_gimple_stmt (dump_file, stmt, 0);
 }
 
-  if (gimple_has_volatile_ops (stmt)
-  && !gimple_clobber_p (stmt))
+  if (gimple_has_volatile_ops (stmt) && !gimple_clobber_p (stmt))
 {
   local->pure_const_state = IPA_NEITHER;
   if (dump_file)
@@ -808,8 +814,7 @@ check_stmt (gimple_stmt_iterator *gsip,
 			ipa ? check_ipa_load : check_load,
 			ipa ? check_ipa_store :  check_store);
 
-  if (gimple_code (stmt) != GIMPLE_CALL
-  && stmt_could_throw_p (stmt))
+  if (gimple_code (stmt) != GIMPLE_CALL && stmt_could_throw_p (stmt))
 {
   if (cfun->can_throw_non_call_exceptions)
 	{
@@ -1822,13 +1827,17 @@ propagate_nothrow (void)
 		 not be interposed.
 		 When callee is compiled with non-call exceptions we also
 		 must check that the declaration is bound to current
-		 body as other semantically equivalent body may still
-		 throw.  */
+		 body as other semantically equivalent body may throw.
+		 Moreover, if the call is recursive, we must consider that
+		 the function may throw a stack overflow exception.  */
 		  if (avail <= AVAIL_INTERPOSABLE
 		  || (!TREE_NOTHROW (y->decl)
 			  && (get_function_state (y)->can_throw
 			  || (opt_for_fn (y->decl, flag_non_call_exceptions)
-  && !e->callee->binds_to_current_def_p (w)
+  && !e->callee->binds_to_current_def_p (w))
+			  || (y == w
+  && flag_exceptions
+  && flag_stack_check
 		can_throw = true;
 		}
 	  for (ie = w->indirect_calls; ie && !can_throw;
@@ -2288,7 +2297,7 @@ make_pass_warn_function_noreturn (gcc::c
   return new pass_warn_function_noreturn (ctxt);
 }
 
-/* Simple local pass for pure const discovery reusing the analysis from
+/* Simple local pass for nothrow discovery reusing the analysis from
ipa_pure_const.   This pass is effective when executed together with
other optimization passes in early optimization pass queue.  */
 
@@ -2352,8 +2361,9 @@ pass_nothrow::execute (function *)
 	if (is_gimple_call (gsi_stmt (gsi)))
 	  {
 		tree callee_t = gimple_call_fndecl (gsi_stmt (gsi));
-		if (callee_t && recursive_call_p (current_function_decl,
-		  callee_t))
+		if (callee_t
+		&& recursive_call_p (current_function_decl, callee_t)
+		&& !flag_stack_check)
 		  continue;
 	  }
 	
-- { dg-do compile }
-- { dg-options "-Wstack-usage=512" }

with Stack_Usage4_Pkg; use Stack_Usage4_Pkg;

procedure Stack_Usage4 is
   BS : Bounded_String := Get;
   S : String := BS.Data (BS.Data'First .. BS.Len);
begin
   null;
end;


Fix wrong loop-invariant motion

2018-04-26 Thread Eric Botcazou
This fixes a wrong loop-invariant motion applied to an adjustment of the frame 
pointer generated by expand_builtin_setjmp_receiver, e.g. for a target using 
the SJLJ exception handling scheme.

Tested on x86-64/Linux, applied on the mainline.


2018-04-26  Eric Botcazou  

* loop-invariant.c (may_assign_reg_p): Return false for frame pointer.


2018-04-26  Eric Botcazou  

* gnat.dg/loop_optimization24.adb: New test.

-- 
Eric Botcazou-- { dg-do run }
-- { dg-options "-O" }

procedure Loop_Optimization24 is

   procedure Callback is
   begin
  raise Constraint_Error;
   end;

   type Thread_Name_Ptr is access constant String;
   type Callback_Ptr is access procedure;

   type Callback_Information is record
  Name : Thread_Name_Ptr;
  Proc : Callback_Ptr;
   end record;
  
   type Callback_List is array (Positive range <>) of Callback_Information;

   Cbs : Callback_List
 := (1 => (Proc => Callback'access, name => new String'("Callback")),
 2 => (Proc => Callback'access, name => new String'("Callback")));

begin
   for Index in Cbs'Range loop
  begin
 if Cbs(Index).proc /= null then
Cbs(Index).proc.all;
 end if;
  exception
 when Constraint_Error => null;
  end;
   end loop;
end;
Index: loop-invariant.c
===
--- loop-invariant.c	(revision 259642)
+++ loop-invariant.c	(working copy)
@@ -660,6 +660,9 @@ may_assign_reg_p (rtx x)
   return (GET_MODE (x) != VOIDmode
 	  && GET_MODE (x) != BLKmode
 	  && can_copy_p (GET_MODE (x))
+	  /* Do not mess with the frame pointer adjustments that can
+	 be generated e.g. by expand_builtin_setjmp_receiver.  */
+	  && x != frame_pointer_rtx
 	  && (!REG_P (x)
 	  || !HARD_REGISTER_P (x)
 	  || REGNO_REG_CLASS (REGNO (x)) != NO_REGS));


[patch] allow '-' for stdout dump

2018-04-26 Thread Nathan Sidwell
Here's the patch to allow '-' as a synonym for 'stdout'.  It's easier to type, 
and a convention used elsewhere.


Also document the existing stdout/stderr selection along with the new behaviour?

ok for trunk?

nathan
--
Nathan Sidwell
2018-04-26  Nathan Sidwell  

	* dumpfile.c (dump_open): Allow '-' for stdout.
	* doc/invoke.texi (fdump-rtl): Document stdin/stdout selection.

Index: doc/invoke.texi
===
--- doc/invoke.texi	(revision 259680)
+++ doc/invoke.texi	(working copy)
@@ -13368,9 +13368,10 @@ Says to make debugging dumps during comp
 @var{letters}.  This is used for debugging the RTL-based passes of the
 compiler.  The file names for most of the dumps are made by appending
 a pass number and a word to the @var{dumpname}, and the files are
-created in the directory of the output file.  In case of
-@option{=@var{filename}} option, the dump is output on the given file
-instead of the pass numbered dump files.  Note that the pass number is
+created in the directory of the output file.  Using a
+@option{=@var{filename}} suffix overrides this default scheme.  You
+can specify @code{stdout} or @code{-} to refer to standard output, and
+@code{stderr} for standard error.  Note that the pass number is
 assigned as passes are registered into the pass manager.  Most passes
 are registered in the order that they will execute and for these passes
 the number corresponds to the pass execution order.  However, passes
Index: dumpfile.c
===
--- dumpfile.c	(revision 259681)
+++ dumpfile.c	(working copy)
@@ -323,7 +323,8 @@ dump_open (const char *filename, bool tr
   if (strcmp ("stderr", filename) == 0)
 return stderr;
 
-  if (strcmp ("stdout", filename) == 0)
+  if (strcmp ("stdout", filename) == 0
+  || strcmp ("-", filename) == 0)
 return stdout;
 
   FILE *stream = fopen (filename, trunc ? "w" : "a");


Re: [patch] allow '-' for stdout dump

2018-04-26 Thread Sandra Loosemore

On 04/26/2018 11:12 AM, Nathan Sidwell wrote:


Index: doc/invoke.texi
===
--- doc/invoke.texi (revision 259680)
+++ doc/invoke.texi (working copy)
@@ -13368,9 +13368,10 @@ Says to make debugging dumps during comp
 @var{letters}.  This is used for debugging the RTL-based passes of the
 compiler.  The file names for most of the dumps are made by appending
 a pass number and a word to the @var{dumpname}, and the files are
-created in the directory of the output file.  In case of
-@option{=@var{filename}} option, the dump is output on the given file
-instead of the pass numbered dump files.  Note that the pass number is
+created in the directory of the output file.  Using a
+@option{=@var{filename}} suffix overrides this default scheme.  You
+can specify @code{stdout} or @code{-} to refer to standard output, and
+@code{stderr} for standard error.  Note that the pass number is
 assigned as passes are registered into the pass manager.  Most passes
 are registered in the order that they will execute and for these passes
 the number corresponds to the pass execution order.  However, passes


Hmmm, I'm not crazy about putting this material in the middle of a 
discussion about how the compiler comes up with its default dump file 
names.  How about splitting the existing paragraph into 3:


- The 2 introductory sentences explaining what the option does.
- The default dump file name description.
- How to override it.

-Sandra


Re: [PATCH] Fix PR c++/85400

2018-04-26 Thread Jason Merrill
On Thu, Apr 26, 2018 at 9:42 AM, Eric Botcazou  wrote:
> Hi,
>
> for the attached testcase compiled/linked with -shared -fPIC -O, the Solaris
> linker chokes on SPARC because the generated code uses the local-dynamic TLS
> model for a global symbol:
>
> ld: fatal: relocation error: R_SPARC_TLS_LDM_HI22: file /var/tmp//ccKG6GQC.o:
> symbol Test::blah(int)::mything: bound to: /var/tmp//ccKG6GQC.o: relocation
> illegal when not bound to object being created
>
> The symbol is a local TLS symbol defined in an inline method of a class so it
> is first local so decl_default_tls_model chooses TLS_MODEL_LOCAL_DYNAMIC.  But
> then it is "commonized" by the C++ front-end:
>
> /* If a local static variable is declared in an inline function, or if
>we have a weak definition, we must endeavor to create only one
>instance of the variable at link-time.  */
>
> which calls comdat_linkage, which in turn calls make_decl_one_only, which
> makes it weak and public, so unsuitable for the local-dynamic TLS model.
>
> The proposed fix is to reset the TLS model after the commonization, but of
> course only if no tls_model attribute was set on the variable, hence the fix
> for handle_tls_model_attribute.  Tested on x86-64/Linux, OK for mainline?
>
>
> 2018-04-26  Eric Botcazou  
>
> cp/
> PR c++/85400
> * decl.c (cp_finish_decl): Recompute the TLS model after commonizing
> a TLS-local variable, unless it has got an explicit TLS model.

It seems like we're likely to need the same thing when we get to
make_decl_one_only by other paths; perhaps we should put this
recalculation in a cxx_make_decl_one_only.

Jason


Re: [PATCH] Don't offer suggestions for compiler-generated variables (PR c++/85515)

2018-04-26 Thread Jason Merrill
On Thu, Apr 26, 2018 at 3:45 AM, Richard Biener
 wrote:
> On Wed, Apr 25, 2018 at 7:10 PM, Nathan Sidwell  wrote:
>> On 04/25/2018 11:41 AM, David Malcolm wrote:
>>>
>>> Jason Turner's video C++ Weekly - Ep 112 - GCC's Leaky Abstractions shows
>>> two issues where g++ offers suggestions about implementation details:
>>
>>
>>> For the lambda capture case, there are multiple members:
>>>
>>> $9 = 
>>
>>
>> These names have a space at the end, so the user cannot name them.  We could
>> move the space to the beginning, if that helps?
>
> I think compiler-generated entities that are not supposed to be
> user-visible should be DECL_ARTIFICIAL.

Agreed, add_capture should set that flag on the FIELD_DECLs.

Jason


[PATCH] Add _mm512_{,mask_}mullox_epi64 intrinsics (PR target/85530)

2018-04-26 Thread Jakub Jelinek
Hi!

ICC apparently has these two intrinsics (why it doesn't have a maskz_ one
is unclear to me) which are like _mm512_{,mask_}mullo_epi64, except they are
available in AVX512F rather than just AVX512DQ and if AVX512DQ is not
enabled they expand to 3 vpmuludq instructions + 3 shifts + 2 adds; for
AVX512DQ they are the same as mullo without x.

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

2018-04-26  Jakub Jelinek  

PR target/85530
* config/i386/avx512fintrin.h (_mm512_mullox_epi64,
_mm512_mask_mullox_epi64): New intrinsics.

* gcc.target/i386/avx512f-vpmullq-1.c: New test.
* gcc.target/i386/avx512f-vpmullq-2.c: New test.
* gcc.target/i386/avx512dq-vpmullq-3.c: New test.
* gcc.target/i386/avx512dq-vpmullq-4.c: New test.

--- gcc/config/i386/avx512fintrin.h.jj  2018-02-12 19:17:40.087215130 +0100
+++ gcc/config/i386/avx512fintrin.h 2018-04-26 11:51:09.176953712 +0200
@@ -567,6 +567,20 @@ _mm512_mask_mullo_epi32 (__m512i __W, __
 
 extern __inline __m512i
 __attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
+_mm512_mullox_epi64 (__m512i __A, __m512i __B)
+{
+  return (__m512i) ((__v8du) __A * (__v8du) __B);
+}
+
+extern __inline __m512i
+__attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
+_mm512_mask_mullox_epi64 (__m512i __W, __mmask8 __M, __m512i __A, __m512i __B)
+{
+  return _mm512_mask_mov_epi64 (__W, __M, _mm512_mullox_epi64 (__A, __B));
+}
+
+extern __inline __m512i
+__attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
 _mm512_sllv_epi32 (__m512i __X, __m512i __Y)
 {
   return (__m512i) __builtin_ia32_psllv16si_mask ((__v16si) __X,
--- gcc/testsuite/gcc.target/i386/avx512f-vpmullq-1.c.jj2018-04-26 
12:01:51.049333280 +0200
+++ gcc/testsuite/gcc.target/i386/avx512f-vpmullq-1.c   2018-04-26 
12:29:04.957253010 +0200
@@ -0,0 +1,20 @@
+/* { dg-do compile } */
+/* { dg-options "-mavx512f -mno-avx512dq -O2" } */
+/* { dg-final { scan-assembler-times "vpmullq\[ 
\\t\]+\[^\{\n\]*%zmm\[0-9\]+\[^\n\]*%zmm\[0-9\]+\[^\n\]*%zmm\[0-9\]+(?:\n|\[ 
\\t\]+#)"  0 } } */
+/* { dg-final { scan-assembler-times "vpmullq\[ 
\\t\]+\[^\{\n\]*%zmm\[0-9\]+\[^\n\]*%zmm\[0-9\]+\[^\n\]*%zmm\[0-9\]+\{%k\[1-7\]\}(?:\n|\[
 \\t\]+#)" 0 } } */
+/* { dg-final { scan-assembler-times "vpmuludq\[ 
\\t\]+\[^\{\n\]*%zmm\[0-9\]+\[^\n\]*%zmm\[0-9\]+\[^\n\]*%zmm\[0-9\]+(?:\n|\[ 
\\t\]+#)"  6 } } */
+/* { dg-final { scan-assembler-times "vpsrlq\[ 
\\t\]+\[^\{\n\]*\\\$32\[^\n\]*%zmm\[0-9\]+\[^\n\]*%zmm\[0-9\]+(?:\n|\[ 
\\t\]+#)"  4 } } */
+/* { dg-final { scan-assembler-times "vpsllq\[ 
\\t\]+\[^\{\n\]*\\\$32\[^\n\]*%zmm\[0-9\]+\[^\n\]*%zmm\[0-9\]+(?:\n|\[ 
\\t\]+#)"  2 } } */
+/* { dg-final { scan-assembler-times "vpaddq\[ 
\\t\]+\[^\{\n\]*%zmm\[0-9\]+\[^\n\]*%zmm\[0-9\]+\[^\n\]*%zmm\[0-9\]+(?:\n|\[ 
\\t\]+#)"  3 } } */
+/* { dg-final { scan-assembler-times "vpaddq\[ 
\\t\]+\[^\{\n\]*%zmm\[0-9\]+\[^\n\]*%zmm\[0-9\]+\[^\n\]*%zmm\[0-9\]+\{%k\[1-7\]\}(?:\n|\[
 \\t\]+#)" 1 } } */
+
+#include 
+
+volatile __m512i _x1, _y1, _z1;
+
+void extern
+avx512f_test (void)
+{
+  _x1 = _mm512_mullox_epi64 (_y1, _z1);
+  _x1 = _mm512_mask_mullox_epi64 (_x1, 3, _y1, _z1);
+}
--- gcc/testsuite/gcc.target/i386/avx512f-vpmullq-2.c.jj2018-04-26 
12:01:54.545335345 +0200
+++ gcc/testsuite/gcc.target/i386/avx512f-vpmullq-2.c   2018-04-26 
12:01:09.491308704 +0200
@@ -0,0 +1,45 @@
+/* { dg-do run } */
+/* { dg-options "-O2 -mavx512dq" } */
+/* { dg-require-effective-target avx512dq } */
+
+#define AVX512DQ
+#include "avx512f-helper.h"
+
+#define SIZE (AVX512F_LEN / 64)
+#include "avx512f-mask-type.h"
+
+void
+CALC (long long *src1, long long *src2, long long *dst)
+{
+  int i;
+
+  for (i = 0; i < SIZE; i++)
+dst[i] = src1[i] * src2[i];
+}
+
+void
+TEST (void)
+{
+  UNION_TYPE (AVX512F_LEN, i_q) src1, src2, dst1, dst2;
+  long long dst_ref[SIZE];
+  int i;
+  MASK_TYPE mask = MASK_VALUE;
+
+  for (i = 0; i < SIZE; i++)
+{
+  src1.a[i] = i + 50;
+  src2.a[i] = i + 100;
+  dst2.a[i] = DEFAULT_VALUE;
+}
+
+  dst1.x = INTRINSIC (_mullox_epi64) (src1.x, src2.x);
+  dst2.x = INTRINSIC (_mask_mullox_epi64) (dst2.x, mask, src1.x, src2.x);
+  CALC (src1.a, src2.a, dst_ref);
+
+  if (UNION_CHECK (AVX512F_LEN, i_q) (dst1, dst_ref))
+abort ();
+
+  MASK_MERGE (i_q) (dst_ref, mask, SIZE);
+  if (UNION_CHECK (AVX512F_LEN, i_q) (dst2, dst_ref))
+abort ();
+}
--- gcc/testsuite/gcc.target/i386/avx512dq-vpmullq-3.c.jj   2018-04-26 
11:58:43.604222431 +0200
+++ gcc/testsuite/gcc.target/i386/avx512dq-vpmullq-3.c  2018-04-26 
11:59:49.585261449 +0200
@@ -0,0 +1,15 @@
+/* { dg-do compile } */
+/* { dg-options "-mavx512dq -O2" } */
+/* { dg-final { scan-assembler-times "vpmullq\[ 
\\t\]+\[^\{\n\]*%zmm\[0-9\]+\[^\n\]*%zmm\[0-9\]+\[^\n\]*%zmm\[0-9\]+(?:\n|\[ 
\\t\]+#)"  1 } } */
+/* { dg-final { scan-assembler-times "vpmullq\[ 
\\t\]+\[^\{\n\]*%zmm\[0-9\]+\[^\n\]*%zmm\[0-9\]+\[^\n\]*%zmm\[0-9\]+\{%k\[1-7\]\}(?:\n|

[PATCH] Fix reassoc var_bound optimization (PR tree-optimization/85529)

2018-04-26 Thread Jakub Jelinek
Hi!

As explained in the comment below, when doing the inter-bb range test
optimization and are trying to optimize the
a >= 0 && a < b
where b is known to be >= 0 into
(unsigned) a < (unsigned) b, we need to be careful if the a >= 0 condition
is in a different bb from the a < b one and the a >= 0 bb dominates the
block with the def stmt of b; then get_nonzero_bits can return flow
dependent value range that isn't really valid if we optimize the a >= 0
condition into true and modify the a < b condition to do unsigned
comparison.

Unfortunately, giving up completely breaks some testcases in the testsuite
distilled from real-world code, so the patch handles the most common cases
where b is known to be non-negative no matter what, in particular
zero extension and masking the MSB off.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk and 8.1?
Or do we want it for 8.2 only?
The last testcase fails on 7.x branch too.

2018-04-26  Jakub Jelinek  

PR tree-optimization/85529
* tree-ssa-reassoc.c (optimize_range_tests_var_bound): Add FIRST_BB
argument.  Don't call get_nonzero_bits if opcode is ERROR_MARK_NODE,
rhs2 def stmt's bb is dominated by first_bb and it isn't an obvious
zero extension or masking of the MSB bit.
(optimize_range_tests): Add FIRST_BB argument, pass it through
to optimize_range_tests_var_bound.
(maybe_optimize_range_tests, reassociate_bb): Adjust
optimize_range_tests callers.

* gcc.c-torture/execute/pr85529-1.c: New test.
* gcc.c-torture/execute/pr85529-2.c: New test.
* gcc.dg/pr85529.c: New test.

--- gcc/tree-ssa-reassoc.c.jj   2018-03-16 09:06:06.431752536 +0100
+++ gcc/tree-ssa-reassoc.c  2018-04-26 17:23:14.850769612 +0200
@@ -3035,7 +3035,8 @@ optimize_range_tests_cmp_bitwise (enum t
 static bool
 optimize_range_tests_var_bound (enum tree_code opcode, int first, int length,
vec *ops,
-   struct range_entry *ranges)
+   struct range_entry *ranges,
+   basic_block first_bb)
 {
   int i;
   bool any_changes = false;
@@ -3143,6 +3144,60 @@ optimize_range_tests_var_bound (enum tre
   if (idx == NULL)
continue;
 
+  /* maybe_optimize_range_tests allows statements without side-effects
+in the basic blocks as long as they are consumed in the same bb.
+Make sure rhs2's def stmt is not among them, otherwise we can't
+use safely get_nonzero_bits on it.  E.g. in:
+ # RANGE [-83, 1] NONZERO 173
+ # k_32 = PHI 
+...
+ if (k_32 >= 0)
+   goto ; [26.46%]
+ else
+   goto ; [73.54%]
+
+  [local count: 140323371]:
+ # RANGE [0, 1] NONZERO 1
+ _5 = (int) k_32;
+ # RANGE [0, 4] NONZERO 4
+ _21 = _5 << 2;
+ # RANGE [0, 4] NONZERO 4
+ iftmp.0_44 = (char) _21;
+ if (k_32 < iftmp.0_44)
+   goto ; [84.48%]
+ else
+   goto ; [15.52%]
+the ranges on _5/_21/iftmp.0_44 are flow sensitive, assume that
+k_32 >= 0.  If we'd optimize k_32 >= 0 to true and k_32 < iftmp.0_44
+to (unsigned) k_32 < (unsigned) iftmp.0_44, then we would execute
+those stmts even for negative k_32 and the value ranges would be no
+longer guaranteed and so the optimization would be invalid.  */
+  if (opcode == ERROR_MARK)
+   {
+ gimple *g = SSA_NAME_DEF_STMT (rhs2);
+ basic_block bb2 = gimple_bb (g);
+ if (bb2
+ && bb2 != first_bb
+ && dominated_by_p (CDI_DOMINATORS, bb2, first_bb))
+   {
+ /* As an exception, handle a few common cases.  */
+ if (gimple_assign_cast_p (g)
+ && INTEGRAL_TYPE_P (TREE_TYPE (gimple_assign_rhs1 (g)))
+ && TYPE_UNSIGNED (TREE_TYPE (gimple_assign_rhs1 (g)))
+ && (TYPE_PRECISION (TREE_TYPE (rhs2))
+ > TYPE_PRECISION (TREE_TYPE (gimple_assign_rhs1 (g)
+   /* Zero-extension is always ok.  */ ;
+ else if (is_gimple_assign (g)
+  && gimple_assign_rhs_code (g) == BIT_AND_EXPR
+  && TREE_CODE (gimple_assign_rhs2 (g)) == INTEGER_CST
+  && !wi::neg_p (wi::to_wide (gimple_assign_rhs2 (g
+   /* Masking with INTEGER_CST with MSB clear is always ok
+  too.  */ ;
+ else
+   continue;
+   }
+   }
+
   wide_int nz = get_nonzero_bits (rhs2);
   if (wi::neg_p (nz))
continue;
@@ -3269,11 +3324,12 @@ optimize_range_tests_var_bound (enum tre
maybe_optimize_range_tests for inter-bb range optimization.
In that case if oe->op is NULL, oe->id is bb->index whose
GIMPLE_COND is && or ||ed into the test, and oe->rank says
-   the actual opcode.  */
+   the actual o

RE: [PATCH 1/2] MIPS/GCC/testsuite: Fix data-sym-pool.c for SVR4 model at -O0

2018-04-26 Thread Maciej W. Rozycki
On Wed, 18 Apr 2018, Matthew Fortune wrote:

> OK to apply but given the release date I've added RMs to approve for
> trunk right now.

 Applied to trunk, now that GCC 8 has branched.  Thanks for your review.

  Maciej


RE: [PATCH 2/2] MIPS/GCC/testsuite: Fix data-sym-pool.c for n64 code

2018-04-26 Thread Maciej W. Rozycki
On Wed, 18 Apr 2018, Matthew Fortune wrote:

> Apologies as before on slowness. This looks trivially OK to me but that's
> thanks to the description, much appreciated.

 You are welcome, that just means I did my homework right.

> OK for commit but adding RMs given the imminent release.

 Applied to trunk, now that GCC 8 has branched.  Thanks for your review.

  Maciej


[PATCH] v2: Don't offer suggestions for compiler-generated variables (PR c++/85515)

2018-04-26 Thread David Malcolm
On Thu, 2018-04-26 at 15:53 -0400, Jason Merrill wrote:
> On Thu, Apr 26, 2018 at 3:45 AM, Richard Biener
>  wrote:
> > On Wed, Apr 25, 2018 at 7:10 PM, Nathan Sidwell 
> > wrote:
> > > On 04/25/2018 11:41 AM, David Malcolm wrote:
> > > > 
> > > > Jason Turner's video C++ Weekly - Ep 112 - GCC's Leaky
> > > > Abstractions shows
> > > > two issues where g++ offers suggestions about implementation
> > > > details:
> > > 
> > > 
> > > > For the lambda capture case, there are multiple members:
> > > > 
> > > > $9 = 
> > > 
> > > 
> > > These names have a space at the end, so the user cannot name
> > > them.  We could
> > > move the space to the beginning, if that helps?
> > 
> > I think compiler-generated entities that are not supposed to be
> > user-visible should be DECL_ARTIFICIAL.
> 
> Agreed, add_capture should set that flag on the FIELD_DECLs.

I had tried flagging the lambda-captured vars as DECL_ARTIFICIAL,
but it lead to a "too many initializers" error from reshape_init,
so (before I saw your email), I tried the following approach: rather
than looking at underscores, it uses is_lambda_ignored_entity (similar
to qualify_lookup without LOOKUP_HIDDEN).

Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu.

Do you want me to do the DECL_ARTIFICAL approach, or is this OK?

gcc/cp/ChangeLog:
PR c++/85515
* name-lookup.c (consider_binding_level): Skip compiler-generated
variables.
* search.c (lookup_field_fuzzy_info::fuzzy_lookup_field): Flatten
nested if statements into a series of rejection tests.  Reject
lambda-ignored entities as suggestions.

gcc/testsuite/ChangeLog:
PR c++/85515
* g++.dg/pr85515-1.C: New test.
* g++.dg/pr85515-2.C: New test.
---
 gcc/cp/name-lookup.c |  6 ++
 gcc/cp/search.c  | 13 ++---
 gcc/testsuite/g++.dg/pr85515-1.C | 18 ++
 gcc/testsuite/g++.dg/pr85515-2.C | 22 ++
 4 files changed, 56 insertions(+), 3 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/pr85515-1.C
 create mode 100644 gcc/testsuite/g++.dg/pr85515-2.C

diff --git a/gcc/cp/name-lookup.c b/gcc/cp/name-lookup.c
index d2e5acb..a51cf1b 100644
--- a/gcc/cp/name-lookup.c
+++ b/gcc/cp/name-lookup.c
@@ -5860,6 +5860,12 @@ consider_binding_level (tree name, best_match  &bm,
  && DECL_ANTICIPATED (d))
continue;
 
+  /* Skip compiler-generated variables (e.g. __for_begin/__for_end
+within range for).  */
+  if (TREE_CODE (d) == VAR_DECL
+ && DECL_ARTIFICIAL (d))
+   continue;
+
   tree suggestion = DECL_NAME (d);
   if (!suggestion)
continue;
diff --git a/gcc/cp/search.c b/gcc/cp/search.c
index bfeaf2c..22c0492 100644
--- a/gcc/cp/search.c
+++ b/gcc/cp/search.c
@@ -1224,9 +1224,16 @@ lookup_field_fuzzy_info::fuzzy_lookup_field (tree type)
 
   for (tree field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
 {
-  if (!m_want_type_p || DECL_DECLARES_TYPE_P (field))
-   if (DECL_NAME (field))
- m_candidates.safe_push (DECL_NAME (field));
+  if (m_want_type_p && !DECL_DECLARES_TYPE_P (field))
+   continue;
+
+  if (!DECL_NAME (field))
+   continue;
+
+  if (is_lambda_ignored_entity (field))
+   continue;
+
+  m_candidates.safe_push (DECL_NAME (field));
 }
 }
 
diff --git a/gcc/testsuite/g++.dg/pr85515-1.C b/gcc/testsuite/g++.dg/pr85515-1.C
new file mode 100644
index 000..96f767d
--- /dev/null
+++ b/gcc/testsuite/g++.dg/pr85515-1.C
@@ -0,0 +1,18 @@
+// { dg-require-effective-target c++14 }
+
+void test_1 ()
+{
+  auto lambda = [val = 2](){}; 
+  lambda.val; // { dg-bogus "did you mean" }
+  // { dg-error "has no member named 'val'" "" { target *-*-* } .-1 }
+}
+
+int test_2 ()
+{
+  auto lambda = [val = 2](){ return val; };
+
+  // TODO: should we issue an error for the following assignment?
+  lambda.__val = 4;
+
+  return lambda();
+}
diff --git a/gcc/testsuite/g++.dg/pr85515-2.C b/gcc/testsuite/g++.dg/pr85515-2.C
new file mode 100644
index 000..621ddb8
--- /dev/null
+++ b/gcc/testsuite/g++.dg/pr85515-2.C
@@ -0,0 +1,22 @@
+// { dg-require-effective-target c++11 }
+
+void test_1 ()
+{
+  int arr[] = {1, 2, 3, 4, 5};
+  for (const auto v: arr) {
+_forbegin; // { dg-bogus "suggested alternative" }
+// { dg-error "'_forbegin' was not declared in this scope" "" { target 
*-*-*} .-1 }
+  }
+}
+
+int test_2 ()
+{
+  int arr[] = {1, 2, 3, 4, 5};
+  int sum = 0;
+  for (const auto v: arr) {
+sum += v;
+// TODO: should we issue an error for the following assignment?
+__for_begin = __for_end;
+  }
+  return sum;
+}
-- 
1.8.5.3



Re: [PATCH] Fix loop-header copying do-while loop detection (PR85116)

2018-04-26 Thread David Edelsohn
Hi, Richi

This patches causes a boostrap failure on AIX.  Everything miscompares.
The code itself is the same, but the DWARF debug information contains many
differences.

- David


PR85532, crtend.o built without --enable-initfini-array has bad .eh_frame

2018-04-26 Thread Alan Modra
This patch is aimed at removing bogus .eh_frame info emitted after the
zero terminator in crtend.o, which will cause a ld warning and slow
exception handling.  The right fix for the PR is probably to change
libgcc/Makefile.in to always supply -fno-asynchronous-unwind-tables
when building crtbegin.o and crtend.o, since the utility of such
unwind info is limited to say the least;  To what handler would you be
unwinding to?

This patch instead carries on in the tradition of pr31868 and pr80037,
and just fixes the problem for powerpc..  alpha, i386, s390, tilepro,
tilegx already disable unwind info for these files.  Bootstrapped and
regression tested powerpc64le-linux.  OK for master and gcc-8?

PR libgcc/85532
* config/rs6000/t-crtstuff (CRTSTUFF_T_CFLAGS): Add
-fno-asynchronous-unwind-tables.

diff --git a/libgcc/config/rs6000/t-crtstuff b/libgcc/config/rs6000/t-crtstuff
index 0b2601b..d5ff959 100644
--- a/libgcc/config/rs6000/t-crtstuff
+++ b/libgcc/config/rs6000/t-crtstuff
@@ -3,4 +3,4 @@
 # Do not build crtend.o with -Os as that can result in references to
 # out-of-line register save/restore functions, which may be unresolved
 # as crtend.o is linked after libgcc.a.  See PR45053.
-CRTSTUFF_T_CFLAGS = -msdata=none -O2
+CRTSTUFF_T_CFLAGS = -msdata=none -O2 -fno-asynchronous-unwind-tables

-- 
Alan Modra
Australia Development Lab, IBM


Re: [PATCH] [Microblaze]: PIC Data Text Relative

2018-04-26 Thread Michael Eager

On 04/19/2018 03:43 AM, Andrew Sadek wrote:

On Wed, Apr 18, 2018 at 6:57 PM, Michael Eager  wrote:


Hi Andrew --

Check indents in the following files:
(Make sure that your tabs are set at 8 chars.)
--- gcc/config/microblaze/microblaze.c
--- gcc/config/microblaze/microblaze.md


I have re-run check_GNU_Style.sh and no are issues are found now.


I corrected a large number of indent problems in microblaze.c.


Just a couple coding notes:

microblaze.c:

@@ -858,6 +879,16 @@ microblaze_classify_address (struct microblaze_add
+   && strict == 2)

Include comment in function header describing meaning of strict == 2.


Done



@@ -1022,7 +1065,7 @@ microblaze_legitimize_address (rtx x, rtx oldx ATT
   else if (flag_pic == 2 && !TARGET_PIC_DATA_TEXT_REL)
 {
   ...
 }
   else if (flag_pic == 2 && TARGET_PIC_DATA_TEXT_REL)
 {
   ...
 }

It's better to factor this into
  else if (flag_pic == 2)
{
  if (TARGET_PIC_DATA_TEXT_REL)
{
  ...
}
  else
{
  ...
}
}



Done


This code pattern appears twice in microblaze_legitimize_address.
I corrected the second one.

The code in the second occurrence can be refactored to move

  if (reload_in_progress)
df_set_regs_ever_live (PIC_OFFSET_TABLE_REGNUM, true);

out of the if(TARGET_PIC_DATA_TEXT_REL) brackets.  (Done.)


Please send me an updated ChangeLog, including testsuite.


--
Michael Eagerea...@eagerm.com
1960 Park Blvd., Palo Alto, CA 94306


ATTRIBUTE_NONSTRING

2018-04-26 Thread Alan Modra
This patch adds ATTRIBUTE_NONSTRING, which will be used to curb
-Wstringop-truncation warnings in binutils.  OK to apply?

* ansidecl.h (ATTRIBUTE_NONSTRING): Define.

diff --git a/include/ansidecl.h b/include/ansidecl.h
index c11daff..ec5f34d 100644
--- a/include/ansidecl.h
+++ b/include/ansidecl.h
@@ -283,6 +283,15 @@ So instead we use the macro below and test it against 
specific values.  */
 # endif /* GNUC >= 4.9 */
 #endif /* ATTRIBUTE_NO_SANITIZE_UNDEFINED */
 
+/* Attribute 'nonstring' was valid as of gcc 8.  */
+#ifndef ATTRIBUTE_NONSTRING
+# if GCC_VERSION >= 8000
+#  define ATTRIBUTE_NONSTRING __attribute__ ((nonstring))
+# else
+#  define ATTRIBUTE_NONSTRING
+# endif
+#endif
+
 /* We use __extension__ in some places to suppress -pedantic warnings
about GCC extensions.  This feature didn't work properly before
gcc 2.8.  */

-- 
Alan Modra
Australia Development Lab, IBM


[libstdc++; pr66689; pr68397] Backport special function fixes to 7.

2018-04-26 Thread Ed Smith-Rowland
I'm thinking of going back on my choice not to fix special function bugs 
on 7.


These build and test clean on gcc-7.

OK?


2018-04-30  Edward Smith-Rowland  <3dw...@verizon.net>

PR libstdc++/pr66689 - comp_ellint_3 and ellint_3 return garbage values
* include/tr1/ell_integral.tcc: Correct the nu sign convention
in ellint_3 and comp_ellint_3.
* testsuite/tr1/5_numerical_facilities/special_functions/
06_comp_ellint_3/check_value.cc: Regen with correct values.
* testsuite/tr1/5_numerical_facilities/special_functions/
14_ellint_3/check_value.cc: Ditto.
* testsuite/special_functions/06_comp_ellint_3/check_value.cc: Ditto.
* testsuite/special_functions/13_ellint_3/check_value.cc: Ditto.
* testsuite/special_functions/06_comp_ellint_3/pr66689.cc: New.
* testsuite/special_functions/13_ellint_3/pr66689.cc: New.
* testsuite/tr1/5_numerical_facilities/special_functions/
06_comp_ellint_3/pr66689.cc: New.
* testsuite/tr1/5_numerical_facilities/special_functions/
14_ellint_3/pr66689.cc: New.
Index: include/tr1/ell_integral.tcc
===
--- include/tr1/ell_integral.tcc(revision 259666)
+++ include/tr1/ell_integral.tcc(working copy)
@@ -685,8 +685,8 @@
   const _Tp __kk = __k * __k;
 
   return __ellint_rf(_Tp(0), _Tp(1) - __kk, _Tp(1))
-   - __nu
-   * __ellint_rj(_Tp(0), _Tp(1) - __kk, _Tp(1), _Tp(1) + __nu)
+   + __nu
+   * __ellint_rj(_Tp(0), _Tp(1) - __kk, _Tp(1), _Tp(1) - __nu)
/ _Tp(3);
 }
 }
@@ -735,9 +735,9 @@
 
   const _Tp __Pi = __s
  * __ellint_rf(__cc, _Tp(1) - __kk * __ss, _Tp(1))
- - __nu * __sss
+ + __nu * __sss
  * __ellint_rj(__cc, _Tp(1) - __kk * __ss, _Tp(1),
-   _Tp(1) + __nu * __ss) / _Tp(3);
+   _Tp(1) - __nu * __ss) / _Tp(3);
 
   if (__n == 0)
 return __Pi;
Index: testsuite/special_functions/06_comp_ellint_3/pr66689.cc
===
--- testsuite/special_functions/06_comp_ellint_3/pr66689.cc (nonexistent)
+++ testsuite/special_functions/06_comp_ellint_3/pr66689.cc (working copy)
@@ -0,0 +1,24 @@
+// { dg-do run { target c++11 } }
+// { dg-require-c-std "" }
+// { dg-options "-D__STDCPP_WANT_MATH_SPEC_FUNCS__" }
+// { dg-add-options ieee }
+
+#include 
+#include 
+
+void
+test01()
+{
+  double Pi1 = std::comp_ellint_3(0.75, 0.0);
+  VERIFY(std::abs(Pi1 - 1.91099) < 0.1);
+
+  double Pi2 = std::comp_ellint_3(0.75, 0.5);
+  VERIFY(std::abs(Pi2 - 2.80011) < 0.1);
+}
+
+int
+main()
+{
+  test01();
+  return 0;
+}
Index: testsuite/special_functions/13_ellint_3/pr66689.cc
===
--- testsuite/special_functions/13_ellint_3/pr66689.cc  (nonexistent)
+++ testsuite/special_functions/13_ellint_3/pr66689.cc  (working copy)
@@ -0,0 +1,26 @@
+// { dg-do run { target c++11 } }
+// { dg-require-c-std "" }
+// { dg-options "-D__STDCPP_WANT_MATH_SPEC_FUNCS__" }
+// { dg-add-options ieee }
+
+#include 
+#include 
+
+void
+test01()
+{
+  const double pi = 3.141592654;
+
+  double Pi1 = std::ellint_3(0.75, 0.0, pi / 2.0);
+  VERIFY(std::abs(Pi1 - 1.91099) < 0.1);
+
+  double Pi2 = std::ellint_3(0.75, 0.5, pi / 2.0);
+  VERIFY(std::abs(Pi2 - 2.80011) < 0.1);
+}
+
+int
+main()
+{
+  test01();
+  return 0;
+}
Index: 
testsuite/tr1/5_numerical_facilities/special_functions/06_comp_ellint_3/pr66689.cc
===
--- 
testsuite/tr1/5_numerical_facilities/special_functions/06_comp_ellint_3/pr66689.cc
  (nonexistent)
+++ 
testsuite/tr1/5_numerical_facilities/special_functions/06_comp_ellint_3/pr66689.cc
  (working copy)
@@ -0,0 +1,20 @@
+
+#include 
+#include 
+
+void
+test01()
+{
+  double Pi1 = std::tr1::comp_ellint_3(0.75, 0.0);
+  VERIFY(std::abs(Pi1 - 1.91099) < 0.1);
+
+  double Pi2 = std::tr1::comp_ellint_3(0.75, 0.5);
+  VERIFY(std::abs(Pi2 - 2.80011) < 0.1);
+}
+
+int
+main()
+{
+  test01();
+  return 0;
+}
Index: 
testsuite/tr1/5_numerical_facilities/special_functions/14_ellint_3/pr66689.cc
===
--- 
testsuite/tr1/5_numerical_facilities/special_functions/14_ellint_3/pr66689.cc   
(nonexistent)
+++ 
testsuite/tr1/5_numerical_facilities/special_functions/14_ellint_3/pr66689.cc   
(working copy)
@@ -0,0 +1,22 @@
+
+#include 
+#include 
+
+void
+test01()
+{
+  const double pi = 3.141592654;
+
+  double Pi1 = std::tr1::ellint_3(0.75, 0.0, pi / 2.0);
+  VERIFY(std::abs(Pi1 - 1.91099) < 0.1);
+
+  double Pi2 = std::tr1::ellint_3(0.75, 0.5, pi / 2.0);
+  VERIFY(std::abs(Pi2 

[NDS32, committed] Add missing newline character into ASM_APP_ON macro.

2018-04-26 Thread Chung-Ju Wu

Hi, all,

For nds32 inline assembly code output, a newline character was missing.
The following commit is to fix the issue.


Committed as Rev.259642: https://gcc.gnu.org/r259642

gcc/
* config/nds32/nds32.h (ASM_APP_ON): Add missing newline character.


Best regards,
jasonwucj


[NDS32, committed] Fix print operand for cctl register.

2018-04-26 Thread Chung-Ju Wu

Hi, all,

There was an error in nds32_print_operand() to output
cctl register.  It would be better to set value earlier.
The following commit is to fix such issue.

Committed as Rev.259643: https://gcc.gnu.org/r259643

gcc/
* config/nds32/nds32.c (nds32_print_operand): Set op_value earlier.



Best regards,
jasonwucj


[NDS32, committed] Fix incorrect settings in sfp-machine.h and t-nds32-newlib for hard fp.

2018-04-26 Thread Chung-Ju Wu

Hi, all,

For nds32 NDS32_ABI_2FP_PLUS abi design,
some settings and compilation options are required to be adjusted
so that we can build correct libgcc.a library.

Committed as Rev.259645: https://gcc.gnu.org/r259645

libgcc/
* config/nds32/sfp-machine.h: Fix settings for NDS32_ABI_2FP_PLUS.
* config/nds32/t-nds32-newlib (HOST_LIBGCC2_CFLAGS): Use -fwrapv.


Best regards,
jasonwucj


[NDS32, committed] Split movdi/df if reigster number is illegal.

2018-04-26 Thread Chung-Ju Wu

Hi, all,

We have to split move_di/df pattern when hard register is odd
so that the wrong assembly code can be avoided.

Committed as Rev.259646: https://gcc.gnu.org/r259646

gcc/
* config/nds32/nds32-doubleword.md: New define_split pattern for
illegal register number.


Best regards,
jasonwucj


[NDS32, committed] Fix bug in bit-instruction checking functions.

2018-04-26 Thread Chung-Ju Wu

Hi, all,

In the implementation of nds32_can_use_bclr_p(), nds32_can_use_bset_p(),
and nds32_can_use_btgl_p(), we better use HOST_WIDE_INT type and GET_MODE_MASK()
so that the mask would be good for the bit-operation checking.


Committed as Rev.259647: https://gcc.gnu.org/r259647

gcc/
* config/nds32/nds32-predicates.c (nds32_can_use_bclr_p): Mask with
GET_MODE_MASK before any checking.
(nds32_can_use_bset_p): Likewise.
(nds32_can_use_btgl_p): Likewise.


Best regards,
jasonwucj