Re: [PATCH] Disable guality tests for powerpc*-linux*

2016-03-31 Thread Aldy Hernandez
Richard Biener  writes:

> Hell, even slapping a xfail powerpc*-*-* on all current ppc FAILs
> would be better
> than simply disabling all of guality for ppc.

FWIW, I agree.  While working on the debug early project, I found at
least two legitimate bugs affecting all architectures with guality tests
on ppc64.

Aldy


[PATCH] Prevent loops from being optimized away

2016-03-31 Thread Segher Boessenkool
Sometimes people write loops that they do not want optimized away, even
when the compiler can replace those loops by a simple expression (or
nothing).  For such people, this patch adds a compiler option.

Bootstrapped on powerpc64-linux; regression check still in progress
(with Init(1) to actually test anything).


Segher


2016-04-01  Segher Boessenkool  

* loop-init.c: Include some more stuff that really doesn't belong
here, oh well.
(loop_optimizer_init): Add empty asm statements in all gimple loops,
if asked to.
* common.opt: Add new option.

---
 gcc/common.opt  |  4 
 gcc/loop-init.c | 15 +++
 2 files changed, 19 insertions(+)

diff --git a/gcc/loop-init.c b/gcc/loop-init.c
index 8634591..7c5dc24 100644
--- a/gcc/loop-init.c
+++ b/gcc/loop-init.c
@@ -24,6 +24,8 @@ along with GCC; see the file COPYING3.  If not see
 #include "target.h"
 #include "rtl.h"
 #include "tree.h"
+#include "gimple.h"
+#include "gimple-iterator.h"
 #include "cfghooks.h"
 #include "df.h"
 #include "regs.h"
@@ -91,6 +93,19 @@ loop_optimizer_init (unsigned flags)
 
   /* Find the loops.  */
   current_loops = flow_loops_find (NULL);
+
+  if (flag_never_gonna_give_you_up && current_ir_type () == IR_GIMPLE)
+   {
+ struct loop *loop;
+ FOR_EACH_LOOP (loop, 0)
+   if (loop->latch)
+ {
+   gasm *p = gimple_build_asm_vec ("", 0, 0, 0, 0);
+   gimple_asm_set_volatile (p, true);
+   gimple_stmt_iterator bsi = gsi_after_labels (loop->latch);
+   gsi_insert_before (, p, GSI_SAME_STMT);
+ }
+   }
 }
   else
 {
diff --git a/gcc/common.opt b/gcc/common.opt
index 0f3bb4e..b7c0a6a 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -2002,6 +2002,10 @@ frerun-loop-opt
 Common Ignore
 Does nothing.  Preserved for backward compatibility.
 
+frickroll-all-loops
+Common Report Var(flag_never_gonna_give_you_up) Init(0) Optimization
+You know the rules, and so do I.
+
 frounding-math
 Common Report Var(flag_rounding_math) Optimization SetByCombined
 Disable optimizations that assume default FP rounding behavior.
-- 
1.9.3



Fix for PR70492

2016-03-31 Thread Marcel Böhme
Hi,

This fixes the invalid write of size 8 detailed in 
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70492

Handle the special case when consume_count returns -1 due to an integer 
overflow when parsing the length of the virtual table qualifier in 
cplus-dem.c:2994 (gnu_special).

Index: libiberty/cplus-dem.c
===
--- libiberty/cplus-dem.c   (revision 234663)
+++ libiberty/cplus-dem.c   (working copy)
@@ -3001,6 +3001,11 @@ gnu_special (work, mangled, declp)
  success = 1;
  break;
}
+  else if (n == -1)
+{
+  success = 0;
+  break;
+}
}
  else
{



Re: [PATCH 1/2] Fix new -Wparentheses warnings encountered during bootstrap

2016-03-31 Thread Trevor Saunders
On Thu, Mar 31, 2016 at 04:53:45PM -0400, Patrick Palka wrote:
> This patch fixes the new -Wparentheses warnings (implemented by the
> subsequent patch) that are encountered during bootstrap:
> 
> /home/patrick/code/gcc/gcc/omp-low.c: In function ‘void 
> scan_sharing_clauses(tree, omp_context*, bool)’:
> /home/patrick/code/gcc/gcc/omp-low.c:2381:6: error: suggest explicit braces 
> to avoid ambiguous ‘else’ [-Werror=parentheses]
>if (scan_array_reductions)
>   ^
> /home/patrick/code/gcc/gcc/gimplify.c: In function ‘gimple* 
> gimplify_omp_ordered(tree, gimple_seq)’:
> /home/patrick/code/gcc/gcc/gimplify.c:9880:6: error: suggest explicit braces 
> to avoid ambiguous ‘else’ [-Werror=parentheses]
>if (gimplify_omp_ctxp)
>   ^

I imagine you noticed, but these warnings aren't that friendly, it seems
like it would be nice to point at the else, and maybe what it is an else
for  and the thing it might seem to be an else for?

Trev

> In file included from /home/patrick/code/gcc/gcc/cp/optimize.c:25:0:
> /home/patrick/code/gcc/gcc/cp/optimize.c: In function ‘void 
> populate_clone_array(tree, tree_node**)’:
> /home/patrick/code/gcc/gcc/cp/cp-tree.h:2529:6: error: suggest explicit 
> braces to avoid ambiguous ‘else’ [-Werror=parentheses]
>if (TREE_CODE (FN) == FUNCTION_DECL   \
>   ^
> /home/patrick/code/gcc/gcc/cp/optimize.c:222:3: note: in expansion of macro 
> ‘FOR_EACH_CLONE’
>FOR_EACH_CLONE (clone, fn)
>^~
> /home/patrick/code/gcc/gcc/fortran/openmp.c: In function ‘gfc_omp_udr* 
> gfc_find_omp_udr(gfc_namespace*, const char*, gfc_typespec*)’:
> /home/patrick/code/gcc/gcc/fortran/openmp.c:177:10: error: suggest explicit 
> braces to avoid ambiguous ‘else’ [-Werror=parentheses]
>if (st != NULL)
>   ^
> 
> In each case I think the warning is harmless since the indentation of
> the code in question corresponds to how the "else" is actually parsed
> so I fixed each case simply by enclosing the entire body of the outer
> "if" in braces.
> 
> The FOR_EACH_CLONE change resolves the cp/optimize.c warning.  It
> adjusts the layout of the macro from
> 
>   if (p)
> for (...)
> 
> to
> 
>   if (!p)
> ;
>   else for (...)
> 
> so that an "else" encountered in the body of the for-statement can no
> longer possibly bind to the outer "if (p)" conditional.
> 
> Is this OK to commit after bootstrap + regtesting?
> 
> gcc/cp/ChangeLog:
> 
>   PR c/70436
>   * cp-tree.h (FOR_EACH_CLONE): Restructure macro to avoid
>   potentially generating a future -Wparentheses warning in its
>   callers.
> 
> gcc/fortran/ChangeLog:
> 
>   PR c/70436
>   * openmp.c (gfc_find_omp_udr): Add explicit braces to resolve a
>   future -Wparentheses warning.
> 
> gcc/ChangeLog:
> 
>   PR c/70436
>   * gimplify.c (gimplify_omp_ordered): Add explicit braces to
>   resolve a future -Wparentheses warning.
>   * omp-low.c (scan_sharing_clauses): Likewise.
> 
> gcc/testsuite/ChangeLog:
> 
>   PR c/70436
>   * g++.dg/plugin/pragma_plugin.c (handle_pragma_sayhello): Add
>   explicit braces to resolve a future -Wparentheses warning.
> ---
>  gcc/cp/cp-tree.h|  13 ++--
>  gcc/fortran/openmp.c|  36 +-
>  gcc/gimplify.c  | 108 
> ++--
>  gcc/omp-low.c   |  28 
>  gcc/testsuite/g++.dg/plugin/pragma_plugin.c |  12 ++--
>  5 files changed, 103 insertions(+), 94 deletions(-)
> 
> diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
> index b7b770f..65f5693 100644
> --- a/gcc/cp/cp-tree.h
> +++ b/gcc/cp/cp-tree.h
> @@ -2526,12 +2526,13 @@ struct GTY(()) lang_decl {
>  
>*/
>  #define FOR_EACH_CLONE(CLONE, FN)\
> -  if (TREE_CODE (FN) == FUNCTION_DECL\
> -  && (DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (FN)\
> -   || DECL_MAYBE_IN_CHARGE_DESTRUCTOR_P (FN)))   \
> - for (CLONE = DECL_CHAIN (FN);   \
> -   CLONE && DECL_CLONED_FUNCTION_P (CLONE);  \
> -   CLONE = DECL_CHAIN (CLONE))
> +  if (!(TREE_CODE (FN) == FUNCTION_DECL  \
> + && (DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (FN) \
> + || DECL_MAYBE_IN_CHARGE_DESTRUCTOR_P (FN\
> +;\
> +  else for (CLONE = DECL_CHAIN (FN); \
> + CLONE && DECL_CLONED_FUNCTION_P (CLONE);\
> + CLONE = DECL_CHAIN (CLONE))
>  
>  /* Nonzero if NODE has DECL_DISCRIMINATOR and not DECL_ACCESS.  */
>  #define DECL_DISCRIMINATOR_P(NODE)   \
> diff --git a/gcc/fortran/openmp.c b/gcc/fortran/openmp.c
> index a6c39cd..0dd1a92 100644
> --- a/gcc/fortran/openmp.c
> +++ b/gcc/fortran/openmp.c
> @@ -175,24 +175,26 @@ gfc_find_omp_udr (gfc_namespace *ns, const char *name, 
> gfc_typespec *ts)
>  
>st = gfc_find_symtree (ns->omp_udr_root, name);
>if (st != NULL)
> 

Re: [PATCH 2/4][AArch64] Increase the loop peeling limit

2016-03-31 Thread Evandro Menezes

On 03/16/16 14:48, Evandro Menezes wrote:

On 02/03/16 13:46, Evandro Menezes wrote:

On 01/08/16 16:55, Evandro Menezes wrote:

On 12/16/2015 02:11 PM, Evandro Menezes wrote:

On 12/16/2015 05:24 AM, Richard Earnshaw (lists) wrote:

On 15/12/15 23:34, Evandro Menezes wrote:

On 12/14/2015 05:26 AM, James Greenhalgh wrote:

On Thu, Dec 03, 2015 at 03:07:43PM -0600, Evandro Menezes wrote:

On 11/20/2015 05:53 AM, James Greenhalgh wrote:

On Thu, Nov 19, 2015 at 04:04:41PM -0600, Evandro Menezes wrote:

On 11/05/2015 02:51 PM, Evandro Menezes wrote:

2015-11-05  Evandro Menezes 

gcc/

* config/aarch64/aarch64.c
(aarch64_override_options_internal):
Increase loop peeling limit.

This patch increases the limit for the number of peeled insns.
With this change, I noticed no major regression in either
Geekbench v3 or SPEC CPU2000 while some benchmarks, 
typically FP

ones, improved significantly.

I tested this tuning on Exynos M1 and on A57. ThunderX seems to
benefit from this tuning too.  However, I'd appreciate comments

>from other stakeholders.

Ping.


I'd like to leave this for a call from the port maintainers. I 
can

see why
this leads to more opportunities for vectorization, but I'm
concerned about
the wider impact on code size. Certainly I wouldn't expect 
this to

be our
default at -O2 and below.

My gut feeling is that this doesn't really belong in the back-end
(there are
presumably good reasons why the default for this parameter across
GCC has
fluctuated from 400 to 100 to 200 over recent years), but as I 
say, I'd
like Marcus or Richard to make the call as to whether or not 
we take

this
patch.


Please, correct me if I'm wrong, but loop peeling is enabled only
with loop unrolling (and with PGO).  If so, then extra code 
size is

not a concern, for this heuristic is only active when unrolling
loops, when code size is already of secondary importance.


My understanding was that loop peeling is enabled from -O2 
upwards, and

is also used to partially peel unaligned loops for vectorization
(allowing
the vector code to be well aligned), or to completely peel inner 
loops

which
may then become amenable to SLP vectorization.

If I'm wrong then I take back these objections. But I was sure this
parameter was used in a number of situations outside of just
-funroll-loops/-funroll-all-loops . Certainly I remember seeing
performance
sensitivities to this parameter at -O3 in some internal 
workloads I was

analysing.


Vectorization, including SLP, is only enabled at -O3, isn't it?  It
seems to me that peeling is only used by optimizations which already
lead to potential increase in code size.

For instance, with "-Ofast -funroll-all-loops", the total text 
size for
the SPEC CPU2000 suite is 26.9MB with this proposed change and 
26.8MB
without it; with just "-O2", it is the same at 23.1MB regardless 
of this

setting.

So it seems to me that this proposal should be neutral for up to 
-O2.


My preference would be to not diverge from the global parameter
settings.  I haven't looked in detail at this parameter but it 
seems to

me there are two possible paths:

1) We could get agreement globally that the parameter should be 
increased.

2) We could agree that this specific use of the parameter is distinct
from some other uses and deserves a new param in its own right with a
higher value.


Here's what I have observed, not only in AArch64: architectures 
benefit differently from certain loop optimizations, especially 
those dealing with vectorization. Be it because some have plenty of 
registers of more aggressive loop unrolling, or because some have 
lower costs to vectorize.  With this, I'm trying to imply that 
there may be the case to wiggle this parameter to suit loop 
optimizations better to specific targets.  While it is not the only 
parameter related to loop optimizations, it seems to be the one 
with the desired effects, as exemplified by PPC, S390 and x86 
(AOSP).  Though there is the possibility that they are actually 
side-effects, as Richard Biener perhaps implied in another reply.


Gents,

Any new thoughts on this proposal?


Ping?


Ping^2



Ping^3

--
Evandro Menezes



Re: [AArch64] Add precision choices for the reciprocal square root approximation

2016-03-31 Thread Evandro Menezes

On 03/18/16 18:00, Evandro Menezes wrote:

On 03/18/16 17:20, Wilco Dijkstra wrote:

Evandro Menezes  wrote:

On 03/18/16 10:21, Wilco Dijkstra wrote:

Hi Evandro,


For example, though this approximation is improves the performance
noticeably for DF on A57, for SF, not so much, if at all.
I'm still skeptical that you ever can get any gain on scalars. I 
bet the only gain is on

4x vectorized floats.

I created a simple test that loops around an inline asm version of the
Newton series using scalar insns and got these results on A57:

That's pure max throughput rather than answering the question whether
it speeds up code that does real work. A test that loads an array of 
vectors and

writes back the unit vectors would be a more realistic scenario.

Note our testing showed rsqrt slows down various benchmarks:
https://gcc.gnu.org/ml/gcc-patches/2016-01/msg00574.html.


I remember having seen that, but my point is that if A57 enabled this 
for only DF, it might be an overall improvement.



If I understood you correctly, would something like coarse tuning flags
along with target-specific cost or parameters tables be what you 
have in

mind?
Yes, the magic tuning flags can be coarse (on/off is good enough). If 
we can
agree that these expansions are really only useful for 4x vectorized 
code and
not much else then all we need is a function that enables it for 
those modes.
Otherwise we would need per-CPU settings that select which expansions 
are

enabled for which modes (not just single/double).


Just to be clear, the flags refer to the inner mode, whether scalar or 
vector.
I'm not hopeful that it can be said that this is only useful when 
vectorized though.




Ping^1

--
Evandro Menezes



Re: [AArch64] Emit division using the Newton series

2016-03-31 Thread Evandro Menezes

On 03/23/16 11:24, Evandro Menezes wrote:

On 03/17/16 15:09, Evandro Menezes wrote:

This patch implements FP division by an approximation using the Newton
series.

With this patch, DF division is sped up by over 100% and SF division,
zilch, both on A57 and on M1.


gcc/
* config/aarch64/aarch64-tuning-flags.def
(AARCH64_EXTRA_TUNE_APPROX_DIV_{SF,DF}: New tuning macros.
* config/aarch64/aarch64-protos.h
(AARCH64_EXTRA_TUNE_APPROX_DIV): New macro.
(aarch64_emit_approx_div): Declare new function.
* config/aarch64/aarch64.c
(aarch64_emit_approx_div): Define new function.
* config/aarch64/aarch64.md ("div3"): New expansion.
* config/aarch64/aarch64-simd.md ("div3"): Likewise.


This version of the patch cleans up the changes to the MD files and 
optimizes the division when the numerator is 1.0.


Ping^1

--
Evandro Menezes



Re: [PATCH 2/2] Fix C++ side of PR c/70436 (missing -Wparentheses warnings)

2016-03-31 Thread Patrick Palka
On Thu, 31 Mar 2016, Jakub Jelinek wrote:

> On Thu, Mar 31, 2016 at 04:54:04PM -0400, Patrick Palka wrote:
> > I think that covers all the vanilla C++ constructs that this warning has
> > to consider.  As for C++ extensions, we still fail to warn for
> > 
> >   if (a)
> >   #pragma GCC ivdep
> >  while (1)
> >if (b)
> >  bar ();
> >   else
> > baz ();
> > 
> > and
> > 
> >   if (a)
> > _Cilk_for (int i = 0; i < 10; i++)
> >   if (b)
> > bar ();
> >   else
> > baz ();
> > 
> > and probably other constructs.  I suppose support for this can be
> > implemented in a subsequent patch if deemed appropriate at this stage.
> > It would probably just involve more threading of the parameter IF_P.
> > 
> > Is this OK to commit after bootstrap + regtesting?
> 
> If this makes it in, I can take care of OpenMP, perhaps Cilk+ too.
> 
> > --- a/gcc/cp/parser.c
> > +++ b/gcc/cp/parser.c
> > @@ -2104,7 +2104,7 @@ static tree cp_parser_selection_statement
> >  static tree cp_parser_condition
> >(cp_parser *);
> >  static tree cp_parser_iteration_statement
> > -  (cp_parser *, bool);
> > +  (cp_parser *, bool *if_p, bool);
> 
> I wouldn't add a named argument where all others are unnamed in the
> prototype.
> 
> >  static bool cp_parser_for_init_statement
> >(cp_parser *, tree *decl);
> >  static tree cp_parser_for
> > @@ -2127,7 +2127,7 @@ static void cp_parser_declaration_statement
> >  static tree cp_parser_implicitly_scoped_statement
> >(cp_parser *, bool *, const token_indent_info &, vec * = NULL);
> >  static void cp_parser_already_scoped_statement
> > -  (cp_parser *, const token_indent_info &);
> > +  (cp_parser *, bool *if_p, const token_indent_info &);
> 
> Likewise here.
> 
> > +void
> > +foo (void)
> > +{
> > +  if (a) /* { dg-warning "ambiguous" }  */
> > +for (;;)
> > +  if (b)
> > +bar ();
> > +  else
> > +baz ();
> 
> What about multiple nested for or while loops, like:
>   if (a)
> for (i = 0; i < 10; i++)
>   for (j = 0; j < 10; j++)
> if (b)
>   bar ();
>   else
> baz ();
> and similarly for multiple nested while loops?
> I only see while (1) for (;;) in the test.
> 
> Otherwise, I'll defer to Jason.
> 
>   Jakub
> 

Thanks, patch updated with your requested changes.  Here's an
incremental diff of the changes (since they are relatively minor):

diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index af2a8f2..6dd6280 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -2104,7 +2104,7 @@ static tree cp_parser_selection_statement
 static tree cp_parser_condition
   (cp_parser *);
 static tree cp_parser_iteration_statement
-  (cp_parser *, bool *if_p, bool);
+  (cp_parser *, bool *, bool);
 static bool cp_parser_for_init_statement
   (cp_parser *, tree *decl);
 static tree cp_parser_for
@@ -2127,7 +2127,7 @@ static void cp_parser_declaration_statement
 static tree cp_parser_implicitly_scoped_statement
   (cp_parser *, bool *, const token_indent_info &, vec * = NULL);
 static void cp_parser_already_scoped_statement
-  (cp_parser *, bool *if_p, const token_indent_info &);
+  (cp_parser *, bool *, const token_indent_info &);
 
 /* Declarations [gram.dcl.dcl] */
 
diff --git a/gcc/testsuite/g++.dg/warn/Wparentheses-29.C 
b/gcc/testsuite/g++.dg/warn/Wparentheses-29.C
index 125e6b4..7832415 100644
--- a/gcc/testsuite/g++.dg/warn/Wparentheses-29.C
+++ b/gcc/testsuite/g++.dg/warn/Wparentheses-29.C
@@ -1,13 +1,15 @@
 /* PR c/70436  */
 /* { dg-options "-Wparentheses" }  */
 
-int a, b;
+int a, b, c;
 void bar (void);
 void baz (void);
 
 void
 foo (void)
 {
+  int i, j;
+
   if (a) /* { dg-warning "ambiguous" }  */
 for (;;)
   if (b)
@@ -31,6 +33,42 @@ foo (void)
   baz ();
 
   if (a) /* { dg-warning "ambiguous" }  */
+while (1)
+  while (1)
+if (b)
+  bar ();
+  else
+baz ();
+
+  if (a) /* { dg-warning "ambiguous" }  */
+for (i = 0; i < 10; i++)
+  for (j = 0; j < 10; j++)
+if (b)
+  bar ();
+  else
+baz ();
+
+  if (a)
+for (i = 0; i < 10; i++)
+  if (b) /* { dg-warning "ambiguous" }  */
+for (j = 0; j < 10; j++)
+  if (c)
+bar ();
+  else
+baz ();
+
+  if (a) /* { dg-warning "ambiguous" }  */
+for (i = 0; i < 10; i++)
+  if (b)
+for (j = 0; j < 10; j++)
+  if (c)
+bar ();
+  else
+baz ();
+  else
+bar ();
+
+  if (a) /* { dg-warning "ambiguous" }  */
 for (;;)
   if (b)
 while (1)


Re: [PATCH 2/2] Fix C++ side of PR c/70436 (missing -Wparentheses warnings)

2016-03-31 Thread Jakub Jelinek
On Thu, Mar 31, 2016 at 04:54:04PM -0400, Patrick Palka wrote:
> I think that covers all the vanilla C++ constructs that this warning has
> to consider.  As for C++ extensions, we still fail to warn for
> 
>   if (a)
>   #pragma GCC ivdep
>  while (1)
>if (b)
>  bar ();
>   else
> baz ();
> 
> and
> 
>   if (a)
> _Cilk_for (int i = 0; i < 10; i++)
>   if (b)
> bar ();
>   else
> baz ();
> 
> and probably other constructs.  I suppose support for this can be
> implemented in a subsequent patch if deemed appropriate at this stage.
> It would probably just involve more threading of the parameter IF_P.
> 
> Is this OK to commit after bootstrap + regtesting?

If this makes it in, I can take care of OpenMP, perhaps Cilk+ too.

> --- a/gcc/cp/parser.c
> +++ b/gcc/cp/parser.c
> @@ -2104,7 +2104,7 @@ static tree cp_parser_selection_statement
>  static tree cp_parser_condition
>(cp_parser *);
>  static tree cp_parser_iteration_statement
> -  (cp_parser *, bool);
> +  (cp_parser *, bool *if_p, bool);

I wouldn't add a named argument where all others are unnamed in the
prototype.

>  static bool cp_parser_for_init_statement
>(cp_parser *, tree *decl);
>  static tree cp_parser_for
> @@ -2127,7 +2127,7 @@ static void cp_parser_declaration_statement
>  static tree cp_parser_implicitly_scoped_statement
>(cp_parser *, bool *, const token_indent_info &, vec * = NULL);
>  static void cp_parser_already_scoped_statement
> -  (cp_parser *, const token_indent_info &);
> +  (cp_parser *, bool *if_p, const token_indent_info &);

Likewise here.

> +void
> +foo (void)
> +{
> +  if (a) /* { dg-warning "ambiguous" }  */
> +for (;;)
> +  if (b)
> +bar ();
> +  else
> +baz ();

What about multiple nested for or while loops, like:
  if (a)
for (i = 0; i < 10; i++)
  for (j = 0; j < 10; j++)
if (b)
  bar ();
  else
baz ();
and similarly for multiple nested while loops?
I only see while (1) for (;;) in the test.

Otherwise, I'll defer to Jason.

Jakub


Re: [PATCH 1/2] Fix new -Wparentheses warnings encountered during bootstrap

2016-03-31 Thread Jakub Jelinek
On Thu, Mar 31, 2016 at 04:53:45PM -0400, Patrick Palka wrote:
> @@ -2526,12 +2526,13 @@ struct GTY(()) lang_decl {
>  
>*/
>  #define FOR_EACH_CLONE(CLONE, FN)\
> -  if (TREE_CODE (FN) == FUNCTION_DECL\
> -  && (DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (FN)\
> -   || DECL_MAYBE_IN_CHARGE_DESTRUCTOR_P (FN)))   \
> - for (CLONE = DECL_CHAIN (FN);   \
> -   CLONE && DECL_CLONED_FUNCTION_P (CLONE);  \
> -   CLONE = DECL_CHAIN (CLONE))
> +  if (!(TREE_CODE (FN) == FUNCTION_DECL  \
> + && (DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (FN) \
> + || DECL_MAYBE_IN_CHARGE_DESTRUCTOR_P (FN\
> +;\
> +  else for (CLONE = DECL_CHAIN (FN); \
> + CLONE && DECL_CLONED_FUNCTION_P (CLONE);\
> + CLONE = DECL_CHAIN (CLONE))

Can you please do
+  else \
+for (CLONE = DECL_CHAIN (FN);  \
...
instead?

> --- a/gcc/testsuite/g++.dg/plugin/pragma_plugin.c
> +++ b/gcc/testsuite/g++.dg/plugin/pragma_plugin.c
> @@ -32,14 +32,16 @@ handle_pragma_sayhello (cpp_reader *dummy)
>return;
>  }
>if (TREE_STRING_LENGTH (message) > 1)
> -if (cfun)
> -  warning (OPT_Wpragmas, 
> -   "% from function %qE: %s",
> -   cfun->decl, TREE_STRING_POINTER (message));
> +{
> +  if (cfun)
> +warning (OPT_Wpragmas, 
> + "% from function %qE: %s",
> + cfun->decl, TREE_STRING_POINTER (message));
>else
> - warning (OPT_Wpragmas, 
> +warning (OPT_Wpragmas, 
>   "% outside of function: %s",
>   TREE_STRING_POINTER (message));
> +}

Several lines with 8 spaces instead of tab above.  Can you also indent
the last warning's following lines to be below OPT_?

Otherwise LGTM.

Jakub


Re: [PATCH 1/2] Fix new -Wparentheses warnings encountered during bootstrap

2016-03-31 Thread Patrick Palka
On Thu, 31 Mar 2016, Bernd Schmidt wrote:

> On 03/31/2016 10:53 PM, Patrick Palka wrote:
> > This patch fixes the new -Wparentheses warnings (implemented by the
> > subsequent patch) that are encountered during bootstrap:
> > 
> > /home/patrick/code/gcc/gcc/omp-low.c: In function ‘void
> > scan_sharing_clauses(tree, omp_context*, bool)’:
> > /home/patrick/code/gcc/gcc/omp-low.c:2381:6: error: suggest explicit braces
> > to avoid ambiguous ‘else’ [-Werror=parentheses]
> > if (scan_array_reductions)
> >^
> > /home/patrick/code/gcc/gcc/gimplify.c: In function ‘gimple*
> > gimplify_omp_ordered(tree, gimple_seq)’:
> > /home/patrick/code/gcc/gcc/gimplify.c:9880:6: error: suggest explicit braces
> > to avoid ambiguous ‘else’ [-Werror=parentheses]
> > if (gimplify_omp_ctxp)
> >^
> > In file included from /home/patrick/code/gcc/gcc/cp/optimize.c:25:0:
> > /home/patrick/code/gcc/gcc/cp/optimize.c: In function ‘void
> > populate_clone_array(tree, tree_node**)’:
> > /home/patrick/code/gcc/gcc/cp/cp-tree.h:2529:6: error: suggest explicit
> > braces to avoid ambiguous ‘else’ [-Werror=parentheses]
> > if (TREE_CODE (FN) == FUNCTION_DECL   \
> >^
> > /home/patrick/code/gcc/gcc/cp/optimize.c:222:3: note: in expansion of macro
> > ‘FOR_EACH_CLONE’
> > FOR_EACH_CLONE (clone, fn)
> > ^~
> > /home/patrick/code/gcc/gcc/fortran/openmp.c: In function ‘gfc_omp_udr*
> > gfc_find_omp_udr(gfc_namespace*, const char*, gfc_typespec*)’:
> > /home/patrick/code/gcc/gcc/fortran/openmp.c:177:10: error: suggest explicit
> > braces to avoid ambiguous ‘else’ [-Werror=parentheses]
> > if (st != NULL)
> >^
> > 
> > In each case I think the warning is harmless since the indentation of
> > the code in question corresponds to how the "else" is actually parsed
> > so I fixed each case simply by enclosing the entire body of the outer
> > "if" in braces.
> > 
> > The FOR_EACH_CLONE change resolves the cp/optimize.c warning.  It
> > adjusts the layout of the macro from
> > 
> >if (p)
> >  for (...)
> > 
> > to
> > 
> >if (!p)
> >  ;
> >else for (...)
> > 
> > so that an "else" encountered in the body of the for-statement can no
> > longer possibly bind to the outer "if (p)" conditional.
> > 
> > Is this OK to commit after bootstrap + regtesting?
> 
> I think this is OK, now or in stage1 depending on whether the warning
> improvements go in now or later.
> 
> I see a patch for the C++ side fixing the warning, do you also intend to do C?
> 
> 
> Bernd
> 
> 

I hope someone else could do it since I'm not very familiar with the C
parser :)  I think Marek said he would take care of it.

Re: [PATCH 1/2] Fix new -Wparentheses warnings encountered during bootstrap

2016-03-31 Thread Bernd Schmidt

On 03/31/2016 10:53 PM, Patrick Palka wrote:

This patch fixes the new -Wparentheses warnings (implemented by the
subsequent patch) that are encountered during bootstrap:

/home/patrick/code/gcc/gcc/omp-low.c: In function ‘void 
scan_sharing_clauses(tree, omp_context*, bool)’:
/home/patrick/code/gcc/gcc/omp-low.c:2381:6: error: suggest explicit braces to 
avoid ambiguous ‘else’ [-Werror=parentheses]
if (scan_array_reductions)
   ^
/home/patrick/code/gcc/gcc/gimplify.c: In function ‘gimple* 
gimplify_omp_ordered(tree, gimple_seq)’:
/home/patrick/code/gcc/gcc/gimplify.c:9880:6: error: suggest explicit braces to 
avoid ambiguous ‘else’ [-Werror=parentheses]
if (gimplify_omp_ctxp)
   ^
In file included from /home/patrick/code/gcc/gcc/cp/optimize.c:25:0:
/home/patrick/code/gcc/gcc/cp/optimize.c: In function ‘void 
populate_clone_array(tree, tree_node**)’:
/home/patrick/code/gcc/gcc/cp/cp-tree.h:2529:6: error: suggest explicit braces 
to avoid ambiguous ‘else’ [-Werror=parentheses]
if (TREE_CODE (FN) == FUNCTION_DECL   \
   ^
/home/patrick/code/gcc/gcc/cp/optimize.c:222:3: note: in expansion of macro 
‘FOR_EACH_CLONE’
FOR_EACH_CLONE (clone, fn)
^~
/home/patrick/code/gcc/gcc/fortran/openmp.c: In function ‘gfc_omp_udr* 
gfc_find_omp_udr(gfc_namespace*, const char*, gfc_typespec*)’:
/home/patrick/code/gcc/gcc/fortran/openmp.c:177:10: error: suggest explicit 
braces to avoid ambiguous ‘else’ [-Werror=parentheses]
if (st != NULL)
   ^

In each case I think the warning is harmless since the indentation of
the code in question corresponds to how the "else" is actually parsed
so I fixed each case simply by enclosing the entire body of the outer
"if" in braces.

The FOR_EACH_CLONE change resolves the cp/optimize.c warning.  It
adjusts the layout of the macro from

   if (p)
 for (...)

to

   if (!p)
 ;
   else for (...)

so that an "else" encountered in the body of the for-statement can no
longer possibly bind to the outer "if (p)" conditional.

Is this OK to commit after bootstrap + regtesting?


I think this is OK, now or in stage1 depending on whether the warning 
improvements go in now or later.


I see a patch for the C++ side fixing the warning, do you also intend to 
do C?



Bernd



Re: [PATCH 1/2] Fix new -Wparentheses warnings encountered during bootstrap

2016-03-31 Thread Patrick Palka
On Thu, 31 Mar 2016, Patrick Palka wrote:

> This patch fixes the new -Wparentheses warnings (implemented by the
> subsequent patch) that are encountered during bootstrap:
> 
> /home/patrick/code/gcc/gcc/omp-low.c: In function ‘void 
> scan_sharing_clauses(tree, omp_context*, bool)’:
> /home/patrick/code/gcc/gcc/omp-low.c:2381:6: error: suggest explicit braces 
> to avoid ambiguous ‘else’ [-Werror=parentheses]
>if (scan_array_reductions)
>   ^
> /home/patrick/code/gcc/gcc/gimplify.c: In function ‘gimple* 
> gimplify_omp_ordered(tree, gimple_seq)’:
> /home/patrick/code/gcc/gcc/gimplify.c:9880:6: error: suggest explicit braces 
> to avoid ambiguous ‘else’ [-Werror=parentheses]
>if (gimplify_omp_ctxp)
>   ^
> In file included from /home/patrick/code/gcc/gcc/cp/optimize.c:25:0:
> /home/patrick/code/gcc/gcc/cp/optimize.c: In function ‘void 
> populate_clone_array(tree, tree_node**)’:
> /home/patrick/code/gcc/gcc/cp/cp-tree.h:2529:6: error: suggest explicit 
> braces to avoid ambiguous ‘else’ [-Werror=parentheses]
>if (TREE_CODE (FN) == FUNCTION_DECL   \
>   ^
> /home/patrick/code/gcc/gcc/cp/optimize.c:222:3: note: in expansion of macro 
> ‘FOR_EACH_CLONE’
>FOR_EACH_CLONE (clone, fn)
>^~
> /home/patrick/code/gcc/gcc/fortran/openmp.c: In function ‘gfc_omp_udr* 
> gfc_find_omp_udr(gfc_namespace*, const char*, gfc_typespec*)’:
> /home/patrick/code/gcc/gcc/fortran/openmp.c:177:10: error: suggest explicit 
> braces to avoid ambiguous ‘else’ [-Werror=parentheses]
>if (st != NULL)
>   ^
> 
> In each case I think the warning is harmless since the indentation of
> the code in question corresponds to how the "else" is actually parsed
> so I fixed each case simply by enclosing the entire body of the outer
> "if" in braces.
> 
> The FOR_EACH_CLONE change resolves the cp/optimize.c warning.  It
> adjusts the layout of the macro from
> 
>   if (p)
> for (...)
> 
> to
> 
>   if (!p)
> ;
>   else for (...)
> 
> so that an "else" encountered in the body of the for-statement can no
> longer possibly bind to the outer "if (p)" conditional.
> 
> Is this OK to commit after bootstrap + regtesting?
> 
> gcc/cp/ChangeLog:
> 
>   PR c/70436
>   * cp-tree.h (FOR_EACH_CLONE): Restructure macro to avoid
>   potentially generating a future -Wparentheses warning in its
>   callers.
> 
> gcc/fortran/ChangeLog:
> 
>   PR c/70436
>   * openmp.c (gfc_find_omp_udr): Add explicit braces to resolve a
>   future -Wparentheses warning.
> 
> gcc/ChangeLog:
> 
>   PR c/70436
>   * gimplify.c (gimplify_omp_ordered): Add explicit braces to
>   resolve a future -Wparentheses warning.
>   * omp-low.c (scan_sharing_clauses): Likewise.

Forgot about a tree-parloops.c change:

diff:

diff --git a/gcc/tree-parloops.c b/gcc/tree-parloops.c
index e498e5b..2e55b79 100644
--- a/gcc/tree-parloops.c
+++ b/gcc/tree-parloops.c
@@ -767,14 +767,16 @@ eliminate_local_variables (edge entry, edge exit)
 
   FOR_EACH_VEC_ELT (body, i, bb)
 if (bb != entry_bb && bb != exit_bb)
-  for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next ())
-   if (is_gimple_debug (gsi_stmt (gsi)))
- {
-   if (gimple_debug_bind_p (gsi_stmt (gsi)))
- has_debug_stmt = true;
- }
-   else
- eliminate_local_variables_stmt (entry, , _address);
+  {
+for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next ())
+ if (is_gimple_debug (gsi_stmt (gsi)))
+   {
+ if (gimple_debug_bind_p (gsi_stmt (gsi)))
+   has_debug_stmt = true;
+   }
+ else
+   eliminate_local_variables_stmt (entry, , _address);
+  }
 
   if (has_debug_stmt)
 FOR_EACH_VEC_ELT (body, i, bb)


diff -w:

diff --git a/gcc/tree-parloops.c b/gcc/tree-parloops.c
index e498e5b..2e55b79 100644
--- a/gcc/tree-parloops.c
+++ b/gcc/tree-parloops.c
@@ -767,6 +767,7 @@ eliminate_local_variables (edge entry, edge exit)
 
   FOR_EACH_VEC_ELT (body, i, bb)
 if (bb != entry_bb && bb != exit_bb)
+  {
 for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next ())
  if (is_gimple_debug (gsi_stmt (gsi)))
{
@@ -775,6 +776,7 @@ eliminate_local_variables (edge entry, edge exit)
}
  else
eliminate_local_variables_stmt (entry, , _address);
+  }
 
   if (has_debug_stmt)
 FOR_EACH_VEC_ELT (body, i, bb)

Re: [PATCH 1/2] Fix new -Wparentheses warnings encountered during bootstrap

2016-03-31 Thread Patrick Palka
On Thu, 31 Mar 2016, Patrick Palka wrote:

> This patch fixes the new -Wparentheses warnings (implemented by the
> subsequent patch) that are encountered during bootstrap:
> 
> /home/patrick/code/gcc/gcc/omp-low.c: In function ‘void 
> scan_sharing_clauses(tree, omp_context*, bool)’:
> /home/patrick/code/gcc/gcc/omp-low.c:2381:6: error: suggest explicit braces 
> to avoid ambiguous ‘else’ [-Werror=parentheses]
>if (scan_array_reductions)
>   ^
> /home/patrick/code/gcc/gcc/gimplify.c: In function ‘gimple* 
> gimplify_omp_ordered(tree, gimple_seq)’:
> /home/patrick/code/gcc/gcc/gimplify.c:9880:6: error: suggest explicit braces 
> to avoid ambiguous ‘else’ [-Werror=parentheses]
>if (gimplify_omp_ctxp)
>   ^
> In file included from /home/patrick/code/gcc/gcc/cp/optimize.c:25:0:
> /home/patrick/code/gcc/gcc/cp/optimize.c: In function ‘void 
> populate_clone_array(tree, tree_node**)’:
> /home/patrick/code/gcc/gcc/cp/cp-tree.h:2529:6: error: suggest explicit 
> braces to avoid ambiguous ‘else’ [-Werror=parentheses]
>if (TREE_CODE (FN) == FUNCTION_DECL   \
>   ^
> /home/patrick/code/gcc/gcc/cp/optimize.c:222:3: note: in expansion of macro 
> ‘FOR_EACH_CLONE’
>FOR_EACH_CLONE (clone, fn)
>^~
> /home/patrick/code/gcc/gcc/fortran/openmp.c: In function ‘gfc_omp_udr* 
> gfc_find_omp_udr(gfc_namespace*, const char*, gfc_typespec*)’:
> /home/patrick/code/gcc/gcc/fortran/openmp.c:177:10: error: suggest explicit 
> braces to avoid ambiguous ‘else’ [-Werror=parentheses]
>if (st != NULL)
>   ^
> 
> In each case I think the warning is harmless since the indentation of
> the code in question corresponds to how the "else" is actually parsed
> so I fixed each case simply by enclosing the entire body of the outer
> "if" in braces.
> 
> The FOR_EACH_CLONE change resolves the cp/optimize.c warning.  It
> adjusts the layout of the macro from
> 
>   if (p)
> for (...)
> 
> to
> 
>   if (!p)
> ;
>   else for (...)
> 
> so that an "else" encountered in the body of the for-statement can no
> longer possibly bind to the outer "if (p)" conditional.
> 
> Is this OK to commit after bootstrap + regtesting?
> 
> gcc/cp/ChangeLog:
> 
>   PR c/70436
>   * cp-tree.h (FOR_EACH_CLONE): Restructure macro to avoid
>   potentially generating a future -Wparentheses warning in its
>   callers.
> 
> gcc/fortran/ChangeLog:
> 
>   PR c/70436
>   * openmp.c (gfc_find_omp_udr): Add explicit braces to resolve a
>   future -Wparentheses warning.
> 
> gcc/ChangeLog:
> 
>   PR c/70436
>   * gimplify.c (gimplify_omp_ordered): Add explicit braces to
>   resolve a future -Wparentheses warning.
>   * omp-low.c (scan_sharing_clauses): Likewise.
> 
> gcc/testsuite/ChangeLog:
> 
>   PR c/70436
>   * g++.dg/plugin/pragma_plugin.c (handle_pragma_sayhello): Add
>   explicit braces to resolve a future -Wparentheses warning.

Here's a diff -w of the same patch:

---
 gcc/cp/cp-tree.h| 7 ---
 gcc/fortran/openmp.c| 2 ++
 gcc/gimplify.c  | 2 ++
 gcc/omp-low.c   | 2 ++
 gcc/testsuite/g++.dg/plugin/pragma_plugin.c | 2 ++
 5 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index b7b770f..65f5693 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -2526,10 +2526,11 @@ struct GTY(()) lang_decl {
 
   */
 #define FOR_EACH_CLONE(CLONE, FN)  \
-  if (TREE_CODE (FN) == FUNCTION_DECL  \
+  if (!(TREE_CODE (FN) == FUNCTION_DECL\
&& (DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (FN) \
- || DECL_MAYBE_IN_CHARGE_DESTRUCTOR_P (FN)))   \
- for (CLONE = DECL_CHAIN (FN); \
+   || DECL_MAYBE_IN_CHARGE_DESTRUCTOR_P (FN\
+;  \
+  else for (CLONE = DECL_CHAIN (FN);   \
CLONE && DECL_CLONED_FUNCTION_P (CLONE);\
CLONE = DECL_CHAIN (CLONE))
 
diff --git a/gcc/fortran/openmp.c b/gcc/fortran/openmp.c
index a6c39cd..0dd1a92 100644
--- a/gcc/fortran/openmp.c
+++ b/gcc/fortran/openmp.c
@@ -175,6 +175,7 @@ gfc_find_omp_udr (gfc_namespace *ns, const char *name, 
gfc_typespec *ts)
 
   st = gfc_find_symtree (ns->omp_udr_root, name);
   if (st != NULL)
+   {
  for (omp_udr = st->n.omp_udr; omp_udr; omp_udr = omp_udr->next)
if (ts == NULL)
  return omp_udr;
@@ -193,6 +194,7 @@ gfc_find_omp_udr (gfc_namespace *ns, const char *name, 
gfc_typespec *ts)
  }
return omp_udr;
  }
+   }
 
   /* Don't escape an interface block.  */
   if (ns && !ns->has_import_set
diff --git a/gcc/gimplify.c b/gcc/gimplify.c
index 26b5a10..1c824fa 100644
--- a/gcc/gimplify.c
+++ b/gcc/gimplify.c
@@ -9878,6 +9878,7 @@ gimplify_omp_ordered (tree expr, 

[PATCH 2/2] Fix C++ side of PR c/70436 (missing -Wparentheses warnings)

2016-03-31 Thread Patrick Palka
-Wparentheses currently warns about an ambiguous "else" in this code

  if (a)
if (b)
  bar ();
  else
baz ();

but it fails to warn if there is an iteration statement between the
inner and outer ifs:

  if (a)
for (;;)
  if (b)
bar ();
  else
baz ();

To fix this it's sufficient to just thread the IF_P parameter in
cp_parser_statement() through to cp_parser_iteration_statement() and
then to cp_parser_already_scoped_statement() and finally back to
cp_parser_statement().  In cp_parser_iteration_statement(), avoid
passing IF_P through a do-while statement, and in
cp_parser_already_scoped_statement() avoid passing IF_P through a
compound statement.

I think that covers all the vanilla C++ constructs that this warning has
to consider.  As for C++ extensions, we still fail to warn for

  if (a)
  #pragma GCC ivdep
 while (1)
   if (b)
 bar ();
  else
baz ();

and

  if (a)
_Cilk_for (int i = 0; i < 10; i++)
  if (b)
bar ();
  else
baz ();

and probably other constructs.  I suppose support for this can be
implemented in a subsequent patch if deemed appropriate at this stage.
It would probably just involve more threading of the parameter IF_P.

Is this OK to commit after bootstrap + regtesting?

gcc/cp/ChangeLog:

PR c/70436
* parser.c (cp_parser_iteration_statement): New parameter IF_P.
Pass it through to cp_parser_already_scoped_statement.
(cp_parser_already_scoped_statement): New parameter IF_P.  Pass
it through to cp_parser_statement.
(cp_parser_statement): Pass IF_P through to
cp_parser_iteration_statement.
(cp_parser_pragma): Adjust call to
cp_parser_iteration_statement.

gcc/testsuite/ChangeLog:

PR c/70436
* g++.dg/warn/Wparentheses-29.C: New test.
---
 gcc/cp/parser.c | 20 +++---
 gcc/testsuite/g++.dg/warn/Wparentheses-29.C | 97 +
 2 files changed, 107 insertions(+), 10 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/warn/Wparentheses-29.C

diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 2f80856..af2a8f2 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -2104,7 +2104,7 @@ static tree cp_parser_selection_statement
 static tree cp_parser_condition
   (cp_parser *);
 static tree cp_parser_iteration_statement
-  (cp_parser *, bool);
+  (cp_parser *, bool *if_p, bool);
 static bool cp_parser_for_init_statement
   (cp_parser *, tree *decl);
 static tree cp_parser_for
@@ -2127,7 +2127,7 @@ static void cp_parser_declaration_statement
 static tree cp_parser_implicitly_scoped_statement
   (cp_parser *, bool *, const token_indent_info &, vec * = NULL);
 static void cp_parser_already_scoped_statement
-  (cp_parser *, const token_indent_info &);
+  (cp_parser *, bool *if_p, const token_indent_info &);
 
 /* Declarations [gram.dcl.dcl] */
 
@@ -10392,7 +10392,7 @@ cp_parser_statement (cp_parser* parser, tree 
in_statement_expr,
case RID_WHILE:
case RID_DO:
case RID_FOR:
- statement = cp_parser_iteration_statement (parser, false);
+ statement = cp_parser_iteration_statement (parser, if_p, false);
  break;
 
case RID_CILK_FOR:
@@ -10947,7 +10947,7 @@ cp_parser_selection_statement (cp_parser* parser, bool 
*if_p,
else
  {
/* This if statement does not have an else clause.  If
-  NESTED_IF is true, then the then-clause is an if
+  NESTED_IF is true, then the then-clause has an if
   statement which does have an else clause.  We warn
   about the potential ambiguity.  */
if (nested_if)
@@ -11544,7 +11544,7 @@ cp_parser_range_for_member_function (tree range, tree 
identifier)
Returns the new WHILE_STMT, DO_STMT, FOR_STMT or RANGE_FOR_STMT.  */
 
 static tree
-cp_parser_iteration_statement (cp_parser* parser, bool ivdep)
+cp_parser_iteration_statement (cp_parser* parser, bool *if_p, bool ivdep)
 {
   cp_token *token;
   enum rid keyword;
@@ -11582,7 +11582,7 @@ cp_parser_iteration_statement (cp_parser* parser, bool 
ivdep)
cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN);
/* Parse the dependent statement.  */
parser->in_statement = IN_ITERATION_STMT;
-   cp_parser_already_scoped_statement (parser, guard_tinfo);
+   cp_parser_already_scoped_statement (parser, if_p, guard_tinfo);
parser->in_statement = in_statement;
/* We're done with the while-statement.  */
finish_while_stmt (statement);
@@ -11627,7 +11627,7 @@ cp_parser_iteration_statement (cp_parser* parser, bool 
ivdep)
 
/* Parse the body of the for-statement.  */
parser->in_statement = IN_ITERATION_STMT;
-   cp_parser_already_scoped_statement (parser, guard_tinfo);
+   cp_parser_already_scoped_statement (parser, if_p, guard_tinfo);
parser->in_statement = in_statement;
 

[PATCH 1/2] Fix new -Wparentheses warnings encountered during bootstrap

2016-03-31 Thread Patrick Palka
This patch fixes the new -Wparentheses warnings (implemented by the
subsequent patch) that are encountered during bootstrap:

/home/patrick/code/gcc/gcc/omp-low.c: In function ‘void 
scan_sharing_clauses(tree, omp_context*, bool)’:
/home/patrick/code/gcc/gcc/omp-low.c:2381:6: error: suggest explicit braces to 
avoid ambiguous ‘else’ [-Werror=parentheses]
   if (scan_array_reductions)
  ^
/home/patrick/code/gcc/gcc/gimplify.c: In function ‘gimple* 
gimplify_omp_ordered(tree, gimple_seq)’:
/home/patrick/code/gcc/gcc/gimplify.c:9880:6: error: suggest explicit braces to 
avoid ambiguous ‘else’ [-Werror=parentheses]
   if (gimplify_omp_ctxp)
  ^
In file included from /home/patrick/code/gcc/gcc/cp/optimize.c:25:0:
/home/patrick/code/gcc/gcc/cp/optimize.c: In function ‘void 
populate_clone_array(tree, tree_node**)’:
/home/patrick/code/gcc/gcc/cp/cp-tree.h:2529:6: error: suggest explicit braces 
to avoid ambiguous ‘else’ [-Werror=parentheses]
   if (TREE_CODE (FN) == FUNCTION_DECL   \
  ^
/home/patrick/code/gcc/gcc/cp/optimize.c:222:3: note: in expansion of macro 
‘FOR_EACH_CLONE’
   FOR_EACH_CLONE (clone, fn)
   ^~
/home/patrick/code/gcc/gcc/fortran/openmp.c: In function ‘gfc_omp_udr* 
gfc_find_omp_udr(gfc_namespace*, const char*, gfc_typespec*)’:
/home/patrick/code/gcc/gcc/fortran/openmp.c:177:10: error: suggest explicit 
braces to avoid ambiguous ‘else’ [-Werror=parentheses]
   if (st != NULL)
  ^

In each case I think the warning is harmless since the indentation of
the code in question corresponds to how the "else" is actually parsed
so I fixed each case simply by enclosing the entire body of the outer
"if" in braces.

The FOR_EACH_CLONE change resolves the cp/optimize.c warning.  It
adjusts the layout of the macro from

  if (p)
for (...)

to

  if (!p)
;
  else for (...)

so that an "else" encountered in the body of the for-statement can no
longer possibly bind to the outer "if (p)" conditional.

Is this OK to commit after bootstrap + regtesting?

gcc/cp/ChangeLog:

PR c/70436
* cp-tree.h (FOR_EACH_CLONE): Restructure macro to avoid
potentially generating a future -Wparentheses warning in its
callers.

gcc/fortran/ChangeLog:

PR c/70436
* openmp.c (gfc_find_omp_udr): Add explicit braces to resolve a
future -Wparentheses warning.

gcc/ChangeLog:

PR c/70436
* gimplify.c (gimplify_omp_ordered): Add explicit braces to
resolve a future -Wparentheses warning.
* omp-low.c (scan_sharing_clauses): Likewise.

gcc/testsuite/ChangeLog:

PR c/70436
* g++.dg/plugin/pragma_plugin.c (handle_pragma_sayhello): Add
explicit braces to resolve a future -Wparentheses warning.
---
 gcc/cp/cp-tree.h|  13 ++--
 gcc/fortran/openmp.c|  36 +-
 gcc/gimplify.c  | 108 ++--
 gcc/omp-low.c   |  28 
 gcc/testsuite/g++.dg/plugin/pragma_plugin.c |  12 ++--
 5 files changed, 103 insertions(+), 94 deletions(-)

diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index b7b770f..65f5693 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -2526,12 +2526,13 @@ struct GTY(()) lang_decl {
 
   */
 #define FOR_EACH_CLONE(CLONE, FN)  \
-  if (TREE_CODE (FN) == FUNCTION_DECL  \
-  && (DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (FN)  \
- || DECL_MAYBE_IN_CHARGE_DESTRUCTOR_P (FN)))   \
- for (CLONE = DECL_CHAIN (FN); \
- CLONE && DECL_CLONED_FUNCTION_P (CLONE);  \
- CLONE = DECL_CHAIN (CLONE))
+  if (!(TREE_CODE (FN) == FUNCTION_DECL\
+   && (DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (FN) \
+   || DECL_MAYBE_IN_CHARGE_DESTRUCTOR_P (FN\
+;  \
+  else for (CLONE = DECL_CHAIN (FN);   \
+   CLONE && DECL_CLONED_FUNCTION_P (CLONE);\
+   CLONE = DECL_CHAIN (CLONE))
 
 /* Nonzero if NODE has DECL_DISCRIMINATOR and not DECL_ACCESS.  */
 #define DECL_DISCRIMINATOR_P(NODE) \
diff --git a/gcc/fortran/openmp.c b/gcc/fortran/openmp.c
index a6c39cd..0dd1a92 100644
--- a/gcc/fortran/openmp.c
+++ b/gcc/fortran/openmp.c
@@ -175,24 +175,26 @@ gfc_find_omp_udr (gfc_namespace *ns, const char *name, 
gfc_typespec *ts)
 
   st = gfc_find_symtree (ns->omp_udr_root, name);
   if (st != NULL)
-   for (omp_udr = st->n.omp_udr; omp_udr; omp_udr = omp_udr->next)
- if (ts == NULL)
-   return omp_udr;
- else if (gfc_compare_types (_udr->ts, ts))
-   {
- if (ts->type == BT_CHARACTER)
-   {
- if (omp_udr->ts.u.cl->length == NULL)
-   return omp_udr;
- if (ts->u.cl->length == NULL)
-   continue;
- if (gfc_compare_expr 

Re: Patches to fix optimizer bug & C++ exceptions for GCC VAX backend

2016-03-31 Thread Jake Hamby
Hi JBG,

Thanks for the interest! Unfortunately, I need a few more days to work on this 
patch to clean it up and fix a few more bugs, then I'll send out a new version 
to NetBSD port-vax for testing, with ChangeLog entry. Please consider what I 
sent out earlier to be a work-in-progress at this point.

The version I have on my machine is now generating bad code, after trying to 
change a few "clobbers" to "compares", so I need to fix those bugs and also 
further clean up some stuff that I know is broken. For example, there's some 
old code in vax.c marked "#if HOST_BITS_PER_WIDE_INT == 32" and "if 
(HOST_BITS_PER_WIDE_INT == 32)" that will never be used because HOST_WIDE_INT 
is now always 64 (in hwint.h). I found another bug in a NetBSD command 
(/usr/sbin/pkg_info) processing command-line arguments in main() that goes away 
at "-O0". That bug should be easy to track down considering the small size of 
the program and that it's failing immediately in main().

There's one more thing that's broken in the VAX backend which I'd *really* like 
to fix: GCC can't compile many of its own files at -O2, as well as a few other 
.c files in the NetBSD tree, because it can't expand an insn pattern. The 
Makefiles have hacks to add "-O0" on VAX, and when I remove that workaround, I 
get GCC assertion failures, all of the form:

/home/netbsd/current/src/external/gpl3/gcc/dist/gcc/builtins.c: In function 
'void maybe_emit_chk_warning(tree, built_in_function)':
/home/netbsd/current/src/external/gpl3/gcc/dist/gcc/builtins.c:11549:1: error: 
unrecognizable insn:
 }
 ^
(insn 295 294 296 25 (set (reg:SI 111)
(subreg:SI (mem:DI (plus:SI (mult:SI (reg:SI 109)
(const_int 8 [0x8]))
(reg/f:SI 45 [ D.85015 ])) [7 *_98+0 S8 A32]) 4)) 
/home/netbsd/current/src/external/gpl3/gcc/dist/gcc/wide-int.h:799 -1
 (nil))
/home/netbsd/current/src/external/gpl3/gcc/dist/gcc/builtins.c:11549:1: 
internal compiler error: in extract_insn, at recog.c:2343
0xbd0365 _fatal_insn(char const*, rtx_def const*, char const*, int, char const*)

/home/netbsd/current/src/tools/gcc/../../external/gpl3/gcc/dist/gcc/rtl-error.c:110
0xbd03fa _fatal_insn_not_found(rtx_def const*, char const*, int, char const*)

/home/netbsd/current/src/tools/gcc/../../external/gpl3/gcc/dist/gcc/rtl-error.c:118
0xb92a2d extract_insn(rtx_insn*)

/home/netbsd/current/src/tools/gcc/../../external/gpl3/gcc/dist/gcc/recog.c:2343
0x9612cd instantiate_virtual_regs_in_insn

/home/netbsd/current/src/tools/gcc/../../external/gpl3/gcc/dist/gcc/function.c:1598
0x9612cd instantiate_virtual_regs

/home/netbsd/current/src/tools/gcc/../../external/gpl3/gcc/dist/gcc/function.c:1966
0x9612cd execute

/home/netbsd/current/src/tools/gcc/../../external/gpl3/gcc/dist/gcc/function.c:2015

The failures all seem to be related to trying to read a value from an array of 
64-bit values and loading it into a 32-bit register. It seems like there should 
be a special insn defined for this sort of array access, since VAX has mova* 
and pusha* variants to set a value from an address plus an index into a byte, 
word, long, or 64-bit array (it uses movab/pushab, put not the other variants). 
The addressing modes, constraints, and predicates all get very complicated, and 
I still need to understand a bit better what is actually required, and what 
could be simplified and cleaned up.

If anyone has suggestions on how to define an instruction that would solve the 
previous failure, please let me know. Even without a special pattern for the 
"(plus:SI (mult:SI (reg:SI) (const_int 8)))", it should be able to generate 
something. It seems like it's expanding something and then the insn that's 
supposed to go with it isn't matching.

I tried adding define_insns for "movstrictsi" and for "truncdisi2", hoping that 
one of them would solve the "(set (reg:SI (subreg:SI (mem:DI (...)" part of 
the situation, but it didn't help. The "(subreg:SI)" stuff is strange, and I 
don't understand exactly what GCC is expecting the backend to define. I'll keep 
working on things and as soon as I have something that I think is in a 
contributable state and doesn't generate bad code, I'll email it.

Best regards,
Jake

> On Mar 31, 2016, at 07:30, Jan-Benedict Glaw  wrote:
> 
> Hi Jake!
> 
> On Mon, 2016-03-28 16:34:56 -0700, Jake Hamby  wrote:
>> Amazingly enough, my patch worked well enough that my NetBSD VAX
>> kernel built with GCC 5.3 is no longer crashing. I feel pretty good
>> about what I have so far so here's the complete diff for both the
>> C++ exception fix and the bad condition codes optimizer bug. It
>> should be good enough to check into NetBSD current, at least, and I
>> believe it does fix most, if not all, of the bad code generation
>> bugs with optimization on VAX.
> 
> I'd like to suggest to also Cc Matt Thomas , at
> least once the patch is tested with 

Re: [PATCH] Fix PR c++/70096 (wrong code for pointer-to-member-function copy)

2016-03-31 Thread Rainer Orth
Jason Merrill  writes:

> OK.

The testcase FAILs on Solaris with the native ld:

FAIL: g++.dg/template/ptrmem30.C  -std=c++11 (test for excess errors)
FAIL: g++.dg/template/ptrmem30.C  -std=c++14 (test for excess errors)
FAIL: g++.dg/template/ptrmem30.C  -std=c++98 (test for excess errors)

Excess errors:
ld: warning: symbol 'read' has differing types:
(file /var/tmp//ccXQGwka.o type=OBJT; file /lib/libc.so type=FUNC);
/var/tmp//ccXQGwka.o definition taken

Fixed as follows.  Tested with the appropriate runtest invocation on
i386-pc-solaris2.12 and x86_64-pc-linux-gnu, installed on mainline.

Rainer


2016-03-31  Rainer Orth  

* g++.dg/template/ptrmem30.C (read): Rename to data_read.
(Holder::foo): Reflect this.

# HG changeset patch
# Parent  fb299874d0c97ca07d2d329ba94ff195243f2499
Fix g++.dg/template/ptrmem30.C with Solaris ld

diff --git a/gcc/testsuite/g++.dg/template/ptrmem30.C b/gcc/testsuite/g++.dg/template/ptrmem30.C
--- a/gcc/testsuite/g++.dg/template/ptrmem30.C
+++ b/gcc/testsuite/g++.dg/template/ptrmem30.C
@@ -1,11 +1,11 @@
 // PR c++/70096
 // { dg-do run }
 
-int read;
+int data_read;
 
 struct Holder
 {
-  void foo () { read = data; }
+  void foo () { data_read = data; }
   int data;
 };
 

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


Re: [PATCH][ARM][4.9 Backport] PR target/69875 Fix atomic_loaddi expansion

2016-03-31 Thread Christophe Lyon
On 31 March 2016 at 18:26, Kyrill Tkachov  wrote:
>
> On 30/03/16 09:34, Kyrill Tkachov wrote:
>>
>>
>> On 29/03/16 19:46, Christophe Lyon wrote:
>>>
>>> On 16 March 2016 at 16:54, Ramana Radhakrishnan
>>>  wrote:

 On Wed, Feb 24, 2016 at 11:23 AM, Kyrill Tkachov
  wrote:
>
> Hi all,
>
> This is the GCC 4.9 backport of
> https://gcc.gnu.org/ml/gcc-patches/2016-02/msg01338.html.
> The differences are that TARGET_HAVE_LPAE has to be defined in arm.h in
> a
> different way because
> the ARM_FSET_HAS_CPU1 mechanism doesn't exist on this branch. Also, due
> to
> the location of insn_flags
> and the various FL_* (on the 4.9 branch they're defined locally in
> arm.c
> rather than in arm-protos.h)
> I chose to define TARGET_HAVE_LPAE in terms of hardware divide
> instruction
> availability. This should be
> an equivalent definition.
>
> Also, the scan-assembler tests that check for the DMB instruction are
> updated to check for
> "dmb sy" rather than "dmb ish", because the memory barrier instruction
> changed on trunk for GCC 6.
>
> Bootstrapped and tested on the GCC 4.9 branch on
> arm-none-linux-gnueabihf.
>
>
> Ok for the branch after the trunk patch has had a few days to bake?


 OK.

>>> Hi Kyrylo,
>>>
>>> Since you backported this to branches 4.9 and 5, I've noticed cross-GCC
>>> build
>>> failures:
>>> --target arm-none-linux-gnueabihf
>>> --with-mode=arm
>>> --with-cpu=cortex-a57
>>> --with-fpu=crypto-neon-fp-armv8
>>>
>>> The build succeeds --with-mode=thumb.
>>>
>>> The error message I'm seeing is:
>>> /tmp/6190285_22.tmpdir/ccuX17sh.s: Assembler messages:
>>> /tmp/6190285_22.tmpdir/ccuX17sh.s:34: Error: bad instruction `ldrdeq
>>> r0,r1,[r0]'
>>> make[4]: *** [load_8_.lo] Error 1
>>>
>>> while building libatomic
>>
>>
>> Darn, I had re-tested before committing with --with-mode=thumb :(
>> The problem here is that GCC 5 and 4.9 don't use unified syntax
>> for arm state (it was switched on for GCC 6), so the output template
>> in the new arm_atomic_loaddi2_ldrd pattern should be "ldr%(d%)" instead
>> of "ldrd%?".
>>
>> I'll prepare a patch.
>> Thanks for catching this,
>> Kyrill
>>
>
> And here it is.
> I've reproduced the build failure on 4.9 and 5 and confirmed that this patch
> fixes
> them and that a build with --with-mode=thumb is unaffected.
>
> I'm committing this as obvious in order to fix the broken build in the
> affected configurations.
>
> Sorry for the trouble.
>

Thanks, I confirm that this fixed the build and that the new test
passes in the 4.9 branch.
For the 5 branch, the validation is still running, I'll warn you if
there is any problem.

Thanks

Christophe

> Kyrill
>
> 2016-03-31  Kyrylo Tkachov  
>
> * config/arm/sync.md (arm_atomic_loaddi2_ldrd): Fix output template
> for non-unified syntax.
>
> 2016-03-31  Kyrylo Tkachov  
>
> * gcc.target/arm/atomic_loaddi_relaxed_cond.c: New test.
>
>
>>
>>> Christophe
>>>
>>>
 Ramana
>
> Thanks,
> Kyrill
>
> 2016-02-24  Kyrylo Tkachov  
>
>  PR target/69875
>  * config/arm/arm.h (TARGET_HAVE_LPAE): Define.
>  * config/arm/unspecs.md (VUNSPEC_LDRD_ATOMIC): New value.
>  * config/arm/sync.md (arm_atomic_loaddi2_ldrd): New pattern.
>  (atomic_loaddi_1): Delete.
>  (atomic_loaddi): Rewrite expander using the above changes.
>
> 2016-02-24  Kyrylo Tkachov  
>
>  PR target/69875
>  * gcc.target/arm/atomic_loaddi_acquire.x: New file.
>  * gcc.target/arm/atomic_loaddi_relaxed.x: Likewise.
>  * gcc.target/arm/atomic_loaddi_seq_cst.x: Likewise.
>  * gcc.target/arm/atomic_loaddi_1.c: New test.
>  * gcc.target/arm/atomic_loaddi_2.c: Likewise.
>  * gcc.target/arm/atomic_loaddi_3.c: Likewise.
>  * gcc.target/arm/atomic_loaddi_4.c: Likewise.
>  * gcc.target/arm/atomic_loaddi_5.c: Likewise.
>  * gcc.target/arm/atomic_loaddi_6.c: Likewise.
>  * gcc.target/arm/atomic_loaddi_7.c: Likewise.
>  * gcc.target/arm/atomic_loaddi_8.c: Likewise.
>  * gcc.target/arm/atomic_loaddi_9.c: Likewise.
>>
>>
>


Re: [PATCH] c++/67376 Comparison with pointer to past-the-end, of array fails inside constant expression

2016-03-31 Thread Jason Merrill

OK, thanks.

Jason


Re: [PATCH] c++/67376 Comparison with pointer to past-the-end, of array fails inside constant expression

2016-03-31 Thread Martin Sebor

+   /* Avoid folding references to struct members at offset
0 to
+  prevent tests like '>firstmember == 0' from getting
+  eliminated.  When ptr is null, although the -> expression
+  is strictly speaking invalid, GCC retains it as a matter
+  of QoI.  See PR c/44555. */
+   && (TREE_CODE (op0) != ADDR_EXPR
+   || TREE_CODE (TREE_OPERAND (op0, 0)) != COMPONENT_REF
+   || compare_tree_int (DECL_FIELD_OFFSET ((TREE_OPERAND
+   (TREE_OPERAND (op0, 0), 1))), 0))


Can we look at offset/bitpos here rather than examine the tree structure
of op0?  get_inner_reference already examined it for us.


Good suggestion, thanks!


But you're still examining the tree structure:


+   && (TREE_CODE (op0) != ADDR_EXPR
+   || TREE_CODE (TREE_OPERAND (op0, 0)) != COMPONENT_REF
+   || bitpos0 != 0)


Here instead of looking at op0 we can check (offset0 == NULL_TREE &&
bitpos0 != 0), which indicates a constant non-zero offset.


+   && TREE_CODE (arg1) == INTEGER_CST
+   && integer_zerop (arg1))


And here you don't need the check for INTEGER_CST.


I've updated the patch to simplify the tests.

I have to confess I don't yet find it straightforward to tell
exactly which tests are essential to avoid an ICE and which
ones can safely be simplified.

Martin
PR c++/67376 - [5/6 regression] Comparison with pointer to past-the-end
	of array fails inside constant expression
PR c++/70170 - [6 regression] bogus not a constant expression error comparing
	pointer to array to null
PR c++/70172 - incorrect reinterpret_cast from integer to pointer error
	on invalid constexpr initialization
PR c++/70228 - insufficient detail in diagnostics for a constexpr out of bounds
	array subscript

gcc/testsuite/ChangeLog:
2016-03-31  Martin Sebor  

	PR c++/67376
	PR c++/70170
	PR c++/70172
	PR c++/70228
	* g++.dg/cpp0x/constexpr-array-ptr10.C: New test.
	* g++.dg/cpp0x/constexpr-array-ptr9.C: New test.
	* g++.dg/cpp0x/constexpr-nullptr-1.C: New test.
	* g++.dg/cpp0x/constexpr-array5.C: Adjust text of expected diagnostic.
	* g++.dg/cpp0x/constexpr-string.C: Same.
	* g++.dg/cpp0x/constexpr-wstring2.C: Same.
	* g++.dg/cpp0x/pr65398.C: Same.
	* g++.dg/ext/constexpr-vla1.C: Same.
	* g++.dg/ext/constexpr-vla2.C: Same.
	* g++.dg/ext/constexpr-vla3.C: Same.
	* g++.dg/ubsan/pr63956.C: Same.

gcc/cp/ChangeLog:
2016-03-31  Martin Sebor  

	PR c++/67376
	PR c++/70170
	PR c++/70172
	PR c++/70228
	* constexpr.c (diag_array_subscript): New function.
	(cxx_eval_array_reference): Detect out of bounds array indices.

gcc/ChangeLog:
2016-03-31  Martin Sebor  

	PR c++/67376
	* fold-const.c (maybe_nonzero_address): New function.
	(fold_comparison): Call it.  Fold equality and relational
	expressions involving null pointers.
	(tree_single_nonzero_warnv_p): Call maybe_nonzero_address.

diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c
index 8ea7111..5d1b8b3 100644
--- a/gcc/cp/constexpr.c
+++ b/gcc/cp/constexpr.c
@@ -1837,6 +1837,30 @@ find_array_ctor_elt (tree ary, tree dindex, bool insert = false)
   return -1;
 }
 
+/* Under the control of CTX, issue a detailed diagnostic for
+   an out-of-bounds subscript INDEX into the expression ARRAY.  */
+
+static void
+diag_array_subscript (const constexpr_ctx *ctx, tree array, tree index)
+{
+  if (!ctx->quiet)
+{
+  tree arraytype = TREE_TYPE (array);
+
+  /* Convert the unsigned array subscript to a signed integer to avoid
+	 printing huge numbers for small negative values.  */
+  tree sidx = fold_convert (ssizetype, index);
+  if (DECL_P (array))
+	{
+	  error ("array subscript value %qE is outside the bounds "
+		 "of array %qD of type %qT", sidx, array, arraytype);
+	  inform (DECL_SOURCE_LOCATION (array), "declared here");
+	}
+  else
+	error ("array subscript value %qE is outside the bounds "
+	   "of array type %qT", sidx, arraytype);
+}
+}
 
 /* Subroutine of cxx_eval_constant_expression.
Attempt to reduce a reference to an array slot.  */
@@ -1885,8 +1909,7 @@ cxx_eval_array_reference (const constexpr_ctx *ctx, tree t,
   if (!tree_fits_shwi_p (index)
   || (i = tree_to_shwi (index)) < 0)
 {
-  if (!ctx->quiet)
-	error ("negative array subscript");
+  diag_array_subscript (ctx, ary, index);
   *non_constant_p = true;
   return t;
 }
@@ -1898,8 +1921,7 @@ cxx_eval_array_reference (const constexpr_ctx *ctx, tree t,
   VERIFY_CONSTANT (nelts);
   if (!tree_int_cst_lt (index, nelts))
 {
-  if (!ctx->quiet)
-	error ("array subscript out of bound");
+  diag_array_subscript (ctx, ary, index);
   *non_constant_p = true;
   return t;
 }
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index 44fe2a2..eb66143 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -8336,6 +8336,20 @@ pointer_may_wrap_p (tree base, tree offset, HOST_WIDE_INT bitpos)
   return 

patch fixing PR70461

2016-03-31 Thread Vladimir Makarov

  The following patch fixes

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70461

  I tried to do minimal changes.  It is hard to create a test for the 
PR as the generated code can be changed in future.  So the patch has no 
test.


  The patch was bootstrapped and tested on x86-64.

Committed as rev. 234649.


Index: ChangeLog
===
--- ChangeLog	(revision 234648)
+++ ChangeLog	(working copy)
@@ -1,3 +1,9 @@
+2016-03-31  Vladimir Makarov  
+
+	PR rtl-optimization/70461
+	* ira-color.c (allocno_copy_cost_saving): Use allocno class if it
+	is necessary.
+
 2016-03-31  Martin Liska  
 
 	PR hsa/70399
Index: ira-color.c
===
--- ira-color.c	(revision 234648)
+++ ira-color.c	(working copy)
@@ -2734,10 +2734,16 @@ static int
 allocno_copy_cost_saving (ira_allocno_t allocno, int hard_regno)
 {
   int cost = 0;
+  enum machine_mode allocno_mode = ALLOCNO_MODE (allocno);
   enum reg_class rclass;
   ira_copy_t cp, next_cp;
 
   rclass = REGNO_REG_CLASS (hard_regno);
+  if (ira_reg_class_max_nregs[rclass][allocno_mode]
+  > ira_class_hard_regs_num[rclass])
+/* For the above condition the cost can be wrong.  Use the allocno
+   class in this case.  */
+rclass = ALLOCNO_CLASS (allocno);
   for (cp = ALLOCNO_COPIES (allocno); cp != NULL; cp = next_cp)
 {
   if (cp->first == allocno)
@@ -2754,7 +2760,7 @@ allocno_copy_cost_saving (ira_allocno_t
 	}
   else
 	gcc_unreachable ();
-  cost += cp->freq * ira_register_move_cost[ALLOCNO_MODE (allocno)][rclass][rclass];
+  cost += cp->freq * ira_register_move_cost[allocno_mode][rclass][rclass];
 }
   return cost;
 }


Re: [PATCH] c++/67376 Comparison with pointer to past-the-end, of array fails inside constant expression

2016-03-31 Thread Jeff Law

On 03/30/2016 01:25 PM, Jason Merrill wrote:

On 03/30/2016 12:32 PM, Martin Sebor wrote:

On 03/30/2016 09:30 AM, Jason Merrill wrote:

On 03/29/2016 11:57 PM, Martin Sebor wrote:

Are we confident that arr[0] won't make it here as
POINTER_PLUS_EXPR or
some such?


I'm as confident as I can be given that this is my first time
working in this area.  Which piece of code or what assumption
in particular are you concerned about?


I want to be sure that we don't fold these conditions to false.

constexpr int *ip = 0;
constexpr struct A { int ar[3]; } *ap = 0;

static_assert([0] == 0);
static_assert(&(ap->ar[0]) == 0);


I see.  Thanks for clarifying.  The asserts pass.  The expressions
are folded earlier on (in fact, as we discussed, the second one
too early and is accepted even though it's undefined and should be
rejected in a constexpr context) and never reach fold_comparison.


Good, then let's add at least the first to one of the tests.


+   /* Avoid folding references to struct members at offset 0 to
+  prevent tests like '>firstmember == 0' from getting
+  eliminated.  When ptr is null, although the -> expression
+  is strictly speaking invalid, GCC retains it as a matter
+  of QoI.  See PR c/44555. */
+   && (TREE_CODE (op0) != ADDR_EXPR
+   || TREE_CODE (TREE_OPERAND (op0, 0)) != COMPONENT_REF
+   || compare_tree_int (DECL_FIELD_OFFSET ((TREE_OPERAND
+   (TREE_OPERAND (op0, 0), 1))), 0))


Can we look at offset/bitpos here rather than examine the tree structure
of op0?  get_inner_reference already examined it for us.

Also, it looks like you aren't handling the case with the operands
switched, i.e. 0 == p and such.
Presumably all this stuff runs prior to the call to shorten_compare and 
friends which would canonicalize 0 == p into p == 0?


And yes, I still want to separate the canonicalization, warning and 
optimization that's done by shorten_compare and friends.  It just fell 
out of gcc-6 due to lack of time.


jeff





Jason





Re: [PATCH, HSA]: Fix PR hsa/70399

2016-03-31 Thread Martin Liška
On 03/24/2016 03:59 PM, Martin Liška wrote:
> Hello.
> 
> Current HSA back-end wrongly handles memory stores. Although, we properly 
> identify
> that an immediate operand needs to respect type of a memory store instruction 
> it belongs to,
> the binary representation of the operand is not updated.
> 
> Following patch delays emission of the binary representation and updates 
> hsa_op_immmed::m_brig_repr_size
> every time the m_type field of the operand is updated.
> 
> I've been testing the patch, ready after it finishes?
> 
> Thanks,
> Martin

Hi.

I've prepared v2 of the patch, where I postpone emission of binary 
representation of an immediate
value.

The patch is pre-approved by Martin Jambor.

Installed as r234647.

Thanks,
Martin
>From 1b77faf3ae850b2620b88fb656c372e7736540bd Mon Sep 17 00:00:00 2001
From: marxin 
Date: Thu, 24 Mar 2016 15:41:59 +0100
Subject: [PATCH] Fix PR hsa/70399

gcc/ChangeLog:

2016-03-24  Martin Liska  

	PR hsa/70399
	* hsa-brig.c (hsa_op_immed::emit_to_buffer): Emit either
	a tree value or an immediate integer value to a buffer
	that is eventually copied to a BRIG section.
	(emit_immediate_operand): Call the function here.
	* hsa-dump.c (dump_hsa_immed): Remove checking assert.
	* hsa-gen.c (hsa_op_immed::hsa_op_immed): Remove initialization
	of class' fields that are removed.
	(hsa_op_immed::~hsa_op_immed): Remove deinitialization.
	* hsa.h (class hsa_op_immed): Remove m_brig_repr and
	m_brig_repr_size fields.
---
 gcc/hsa-brig.c | 133 ++---
 gcc/hsa-dump.c |   2 -
 gcc/hsa-gen.c  |  68 +++--
 gcc/hsa.h  |  12 +++---
 4 files changed, 109 insertions(+), 106 deletions(-)

diff --git a/gcc/hsa-brig.c b/gcc/hsa-brig.c
index 9b6c0b8..71d4f66 100644
--- a/gcc/hsa-brig.c
+++ b/gcc/hsa-brig.c
@@ -932,62 +932,101 @@ emit_immediate_scalar_to_buffer (tree value, char *data, unsigned need_len)
   return len;
 }
 
-void
-hsa_op_immed::emit_to_buffer (tree value)
+char *
+hsa_op_immed::emit_to_buffer (unsigned *brig_repr_size)
 {
-  unsigned total_len = m_brig_repr_size;
-
-  /* As we can have a constructor with fewer elements, fill the memory
- with zeros.  */
-  m_brig_repr = XCNEWVEC (char, total_len);
-  char *p = m_brig_repr;
+  char *brig_repr;
+  *brig_repr_size = hsa_get_imm_brig_type_len (m_type);
 
-  if (TREE_CODE (value) == VECTOR_CST)
+  if (m_tree_value != NULL_TREE)
 {
-  int i, num = VECTOR_CST_NELTS (value);
-  for (i = 0; i < num; i++)
+  /* Update brig_repr_size for special tree values.  */
+  if (TREE_CODE (m_tree_value) == STRING_CST)
+	*brig_repr_size = TREE_STRING_LENGTH (m_tree_value);
+  else if (TREE_CODE (m_tree_value) == CONSTRUCTOR)
+	*brig_repr_size
+	  = tree_to_uhwi (TYPE_SIZE_UNIT (TREE_TYPE (m_tree_value)));
+
+  unsigned total_len = *brig_repr_size;
+
+  /* As we can have a constructor with fewer elements, fill the memory
+	 with zeros.  */
+  brig_repr = XCNEWVEC (char, total_len);
+  char *p = brig_repr;
+
+  if (TREE_CODE (m_tree_value) == VECTOR_CST)
 	{
+	  int i, num = VECTOR_CST_NELTS (m_tree_value);
+	  for (i = 0; i < num; i++)
+	{
+	  tree v = VECTOR_CST_ELT (m_tree_value, i);
+	  unsigned actual = emit_immediate_scalar_to_buffer (v, p, 0);
+	  total_len -= actual;
+	  p += actual;
+	}
+	  /* Vectors should have the exact size.  */
+	  gcc_assert (total_len == 0);
+	}
+  else if (TREE_CODE (m_tree_value) == STRING_CST)
+	memcpy (brig_repr, TREE_STRING_POINTER (m_tree_value),
+		TREE_STRING_LENGTH (m_tree_value));
+  else if (TREE_CODE (m_tree_value) == COMPLEX_CST)
+	{
+	  gcc_assert (total_len % 2 == 0);
 	  unsigned actual;
 	  actual
-	= emit_immediate_scalar_to_buffer (VECTOR_CST_ELT (value, i), p, 0);
-	  total_len -= actual;
+	= emit_immediate_scalar_to_buffer (TREE_REALPART (m_tree_value), p,
+	   total_len / 2);
+
+	  gcc_assert (actual == total_len / 2);
 	  p += actual;
+
+	  actual
+	= emit_immediate_scalar_to_buffer (TREE_IMAGPART (m_tree_value), p,
+	   total_len / 2);
+	  gcc_assert (actual == total_len / 2);
 	}
-  /* Vectors should have the exact size.  */
-  gcc_assert (total_len == 0);
-}
-  else if (TREE_CODE (value) == STRING_CST)
-memcpy (m_brig_repr, TREE_STRING_POINTER (value),
-	TREE_STRING_LENGTH (value));
-  else if (TREE_CODE (value) == COMPLEX_CST)
-{
-  gcc_assert (total_len % 2 == 0);
-  unsigned actual;
-  actual
-	= emit_immediate_scalar_to_buffer (TREE_REALPART (value), p,
-	   total_len / 2);
-
-  gcc_assert (actual == total_len / 2);
-  p += actual;
-
-  actual
-	= emit_immediate_scalar_to_buffer (TREE_IMAGPART (value), p,
-	   total_len / 2);
-  gcc_assert (actual == total_len / 2);
+  else if (TREE_CODE (m_tree_value) == CONSTRUCTOR)
+	{
+	  unsigned len = vec_safe_length (CONSTRUCTOR_ELTS (m_tree_value));
+	  for (unsigned 

[HSA branch, PATCH] introduce append_phi method

2016-03-31 Thread Martin Liška
Hello.

Following patch introduces just a single helper method,
install to HSA branch as r234648.

Thanks,
Martin
>From 6d7c765425de3363a8edef2c25572b8208123fb8 Mon Sep 17 00:00:00 2001
From: marxin 
Date: Thu, 31 Mar 2016 11:39:56 +0200
Subject: [PATCH] HSA: introduce append_phi method

gcc/ChangeLog:

2016-03-31  Martin Liska  

	* hsa-gen.c (hsa_bb::append_phi): New function.
	(gen_hsa_phi_from_gimple_phi): Use it.
	* hsa.h: Declare the method.
---
 gcc/hsa-gen.c | 22 +++---
 gcc/hsa.h |  3 +++
 2 files changed, 18 insertions(+), 7 deletions(-)

diff --git a/gcc/hsa-gen.c b/gcc/hsa-gen.c
index ef987d2..84dbcf6 100644
--- a/gcc/hsa-gen.c
+++ b/gcc/hsa-gen.c
@@ -1766,6 +1766,20 @@ hsa_bb::append_insn (hsa_insn_basic *insn)
 m_first_insn = insn;
 }
 
+void
+hsa_bb::append_phi (hsa_insn_phi *hphi)
+{
+  hphi->m_bb = m_bb;
+
+  hphi->m_prev = m_last_phi;
+  hphi->m_next = NULL;
+  if (m_last_phi)
+m_last_phi->m_next = hphi;
+  m_last_phi = hphi;
+  if (!m_first_phi)
+m_first_phi = hphi;
+}
+
 /* Insert HSA instruction NEW_INSN immediately before an existing instruction
OLD_INSN.  */
 
@@ -5761,13 +5775,7 @@ gen_hsa_phi_from_gimple_phi (gimple *phi_stmt, hsa_bb *hbb)
 	}
 }
 
-  hphi->m_prev = hbb->m_last_phi;
-  hphi->m_next = NULL;
-  if (hbb->m_last_phi)
-hbb->m_last_phi->m_next = hphi;
-  hbb->m_last_phi = hphi;
-  if (!hbb->m_first_phi)
-hbb->m_first_phi = hphi;
+  hbb->append_phi (hphi);
 }
 
 /* Constructor of class containing HSA-specific information about a basic
diff --git a/gcc/hsa.h b/gcc/hsa.h
index 1d6baab..03c0c98 100644
--- a/gcc/hsa.h
+++ b/gcc/hsa.h
@@ -1056,6 +1056,9 @@ public:
   /* Append an instruction INSN into the basic block.  */
   void append_insn (hsa_insn_basic *insn);
 
+  /* Add a PHI instruction.  */
+  void append_phi (hsa_insn_phi *phi);
+
   /* The real CFG BB that this HBB belongs to.  */
   basic_block m_bb;
 
-- 
2.7.1



Re: Fix for PR70481 Libiberty Demangler

2016-03-31 Thread Jeff Law

On 03/31/2016 11:29 AM, Bernd Schmidt wrote:

On 03/31/2016 07:22 PM, Jeff Law wrote:

@@ -1237,11 +1237,13 @@  squangle_mop_up (struct work_stuff *work)

Thanks.  I've just installed this patch, along with suitable tests from
70481 and 67394.


What are the rules for modifying libiberty again? Do we have to patch
binutils/gdb at the same time, or is there an automated process?
My recollection is that gcc is considered the master for libiberty and 
the gdb project will resync as needed.


jeff


Re: C++ PATCH for c++/70449 (ICE when printing a filename of unknown location)

2016-03-31 Thread Jeff Law

On 03/31/2016 08:14 AM, Marek Polacek wrote:

On Wed, Mar 30, 2016 at 11:51:26PM +0100, Manuel López-Ibáñez wrote:

On 30 March 2016 at 23:42, Manuel López-Ibáñez  wrote:

On 30/03/16 17:14, Marek Polacek wrote:


This test ICEs since the addition of the assert in pp_string which ensures
that
we aren't trying to print an empty string.  But that's what happens here,
the
location is actually UNKNOWN_LOCATION, so LOCATION_FILE on that yields
null.
Fixed byt not trying to print the filename of UNKNOWN_LOCATION.



Even if we accept the broken location for now (adding some FIXME to the code
would help the next person to realise this is not normal), if
LOCATION_FILE() is NULL, we should print "progname" like
diagnostic_build_prefix() does. Moreover, the filename string should be
built with file_name_as_prefix() to get correct coloring.


Even better: Use "f ? f : progname" in file_name_as_prefix() and
simplify the code to:


It seems wrong to me to just add that.  I wonder if the function shouldn't
use diagnostic_get_location_text instead which also handles "" etc.
In any case I'd rather not touch the diagnostic stuff in the scope of this
patch (which wouldn't probably be suitable for stage4 anyway).


   /* FIXME: Somehow we may get UNKNOWN_LOCATION here: See
g++.dg/cpp0x/constexpr-70449.C */
   const char * prefix = file_name_as_prefix (context,
LOCATION_FILE (location));
 pp_verbatim (context->printer,
  TREE_CODE (p->decl) == TREE_LIST
  ? _("%s: In substitution of %qS:\n")
  : _("%s: In instantiation of %q#D:\n"),
  prefix, p->decl);
   free (prefix);

Fixes the ICE, adds colors, mentions the broken location and does not
add extra strings.


It fixes the ICE, but I don't see any more colors than with my patch.
Moreover your suggestion would print
cc1plus: : In instantiation of ‘constexpr int f() [with int I = 0]’:
, not sure how's that better than simply saying
In instantiation of ‘constexpr int f() [with int I = 0]’:
I.e. adding "cc1plus" to the output doesn't seem like an improvement.

Anyway, here's a patch which uses file_name_as_prefix.

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

2016-03-31  Marek Polacek  

PR c++/70449
* error.c (print_instantiation_full_context): Build prefix by using
file_name_as_prefix.

* g++.dg/cpp0x/constexpr-70449.C: New test.
I'd prefer to dig into why we don't have a good location here before 
approving this patch.  Depending on what's found, I might approve the 
patch as-is or request the root cause be fixed.


Obviously if you get conflicting feedback from Jason, then ignore mine.


jeff




Re: Fix for PR70481 Libiberty Demangler

2016-03-31 Thread Bernd Schmidt

On 03/31/2016 07:22 PM, Jeff Law wrote:

@@ -1237,11 +1237,13 @@  squangle_mop_up (struct work_stuff *work)

Thanks.  I've just installed this patch, along with suitable tests from
70481 and 67394.


What are the rules for modifying libiberty again? Do we have to patch 
binutils/gdb at the same time, or is there an automated process?



Bernd



Re: Fix for PR70481 Libiberty Demangler

2016-03-31 Thread Jeff Law

On 03/31/2016 08:55 AM, Marcel Böhme wrote:

Hi,

This fixes the use-after-free detailed in 
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70481

There is a variable ksize storing the amount of allocated memory for the array 
ktypevec. ksize being zero (0) indicates that some memory must be allocated 
upon the first write. When more memory is needed, both ksize and the memory are 
doubled during reallocation. At some point the memory for the array is freed 
(in squangle_mop_up) but the value of ksize remains. Since ksize is not 0, 
there is no indication that new memory must be allocated when there is another 
write to the array.

The same holds for bsize and btypevec.

Best regards,
- Marcel


Index: libiberty/cplus-dem.c
===
--- libiberty/cplus-dem.c   (revision 234607)
+++ libiberty/cplus-dem.c   (working copy)
@@ -1237,11 +1237,13 @@  squangle_mop_up (struct work_stuff *work)
Thanks.  I've just installed this patch, along with suitable tests from 
70481 and 67394.


Jeff

commit 6e4dbbe6a1d6dd21e2ae87cabd1eae81312feac2
Author: law 
Date:   Thu Mar 31 17:20:53 2016 +

* cplus-dem.c (squangle_mop_up): Zero bsize/ksize after freeing
btypevec/ktypevec.
* testsuite/demangle-expected: Add coverage tests.

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

diff --git a/libiberty/ChangeLog b/libiberty/ChangeLog
index d11f4ce..b4054bd 100644
--- a/libiberty/ChangeLog
+++ b/libiberty/ChangeLog
@@ -1,3 +1,10 @@
+2016-03-31  Mikhail Maltsev  
+   Marcel Bohme  boehme.mar...@gmail.com
+
+   * cplus-dem.c (squangle_mop_up): Zero bsize/ksize after freeing
+   btypevec/ktypevec.
+   * testsuite/demangle-expected: Add coverage tests.
+
 2016-01-27  Iain Buclaw  
 
* d-demangle.c (dlang_call_convention): Handle extern Objective-C
diff --git a/libiberty/cplus-dem.c b/libiberty/cplus-dem.c
index c68b981..7ab46dd 100644
--- a/libiberty/cplus-dem.c
+++ b/libiberty/cplus-dem.c
@@ -1237,11 +1237,13 @@ squangle_mop_up (struct work_stuff *work)
 {
   free ((char *) work -> btypevec);
   work->btypevec = NULL;
+  work->bsize = 0;
 }
   if (work -> ktypevec != NULL)
 {
   free ((char *) work -> ktypevec);
   work->ktypevec = NULL;
+  work->ksize = 0;
 }
 }
 
diff --git a/libiberty/testsuite/demangle-expected 
b/libiberty/testsuite/demangle-expected
index aebf01b..e214ee5 100644
--- a/libiberty/testsuite/demangle-expected
+++ b/libiberty/testsuite/demangle-expected
@@ -4421,3 +4421,13 @@ void baz(A*)
 --format=gnu-v3
 _Z3fooI1FEN1XIXszdtcl1PclcvT__EEE5arrayEE4TypeEv
 X::Type foo()
+#
+# Tests a use-after-free problem
+
+_Q.__0
+::Q.(void)
+#
+# Tests a use-after-free problem
+
+_Q10-__9cafebabe.
+cafebabe.::-(void)


Re: [PATCH 2/2] HSA: handle alignment of string builtins (PR hsa/70391)

2016-03-31 Thread Martin Liška
On 03/31/2016 04:58 PM, Martin Jambor wrote:
> Hi,
> 
> On Wed, Mar 23, 2016 at 02:43:17PM +0100, Martin Liska wrote:
>> gcc/ChangeLog:
>>
>> 2016-03-23  Martin Liska  
>>
>>  PR hsa/70391
>>  * hsa-gen.c (hsa_function_representation::update_cfg): New
>>  function.
>>  (convert_addr_to_flat_segment): Likewise.
>>  (gen_hsa_memory_set): New alignment argument.
>>  (gen_hsa_ctor_assignment): Likewise.
>>  (gen_hsa_insns_for_single_assignment): Provide alignment
>>  to gen_hsa_ctor_assignment.
>>  (gen_hsa_insns_for_direct_call): Add new argument.
>>  (expand_lhs_of_string_op): New function.
>>  (expand_string_operation_builtin): Likewise.
>>  (expand_memory_copy): New function.
>>  (expand_memory_set): New function.
>>  (gen_hsa_insns_for_call): Use HOST_WIDE_INT.
>>  (convert_switch_statements): Change signature.
>>  (generate_hsa): Use a return value of the function.
>>  (pass_gen_hsail::execute): Do not call
>>  convert_switch_statements here.
>>  * hsa-regalloc.c (hsa_regalloc): Call update_cfg.
>>  * hsa.h (hsa_function_representation::m_need_cfg_update):
>>  New flag.
>>  (hsa_function_representation::update_cfg): New function.
> 
> As we already discussed, update_cfg and m_need_cfg_update should
> really be called differently, because CFG has already been modified
> and only dominance needs to be re-computed.  If you havent't thought
> about any names yet, what about m_modified_cfg and update_dominance() ?

Hi.

Done in the attached version of the patch.

> 
> 
>> ---
>>  gcc/hsa-gen.c  | 372 
>> ++---
>>  gcc/hsa-regalloc.c |   1 +
>>  gcc/hsa.h  |   9 +-
>>  3 files changed, 275 insertions(+), 107 deletions(-)
>>
>> diff --git a/gcc/hsa-gen.c b/gcc/hsa-gen.c
>> index db39813..db7fc3d 100644
>> --- a/gcc/hsa-gen.c
>> +++ b/gcc/hsa-gen.c
>> @@ -214,7 +214,7 @@ hsa_symbol::fillup_for_decl (tree decl)
>> should be set to number of SSA names used in the function.  */
>>  
>>  hsa_function_representation::hsa_function_representation
>> -  (tree fdecl, bool kernel_p, unsigned ssa_names_count)
>> +  (tree fdecl, bool kernel_p, unsigned ssa_names_count, bool 
>> need_cfg_update)
>>: m_name (NULL),
>>  m_reg_count (0), m_input_args (vNULL),
>>  m_output_arg (NULL), m_spill_symbols (vNULL), m_global_symbols (vNULL),
>> @@ -223,7 +223,8 @@ hsa_function_representation::hsa_function_representation
>>  m_in_ssa (true), m_kern_p (kernel_p), m_declaration_p (false),
>>  m_decl (fdecl), m_internal_fn (NULL), m_shadow_reg (NULL),
>>  m_kernel_dispatch_count (0), m_maximum_omp_data_size (0),
>> -m_seen_error (false), m_temp_symbol_count (0), m_ssa_map ()
>> +m_seen_error (false), m_temp_symbol_count (0), m_ssa_map (),
>> +m_need_cfg_update (need_cfg_update)
>>  {
>>int sym_init_len = (vec_safe_length (cfun->local_decls) / 2) + 1;;
>>m_local_symbols = new hash_table  (sym_init_len);
>> @@ -319,6 +320,16 @@ hsa_function_representation::init_extra_bbs ()
>>hsa_init_new_bb (EXIT_BLOCK_PTR_FOR_FN (cfun));
>>  }
>>  
>> +void
>> +hsa_function_representation::update_cfg ()
>> +{
>> +  if (m_need_cfg_update)
>> +{
>> +  free_dominance_info (CDI_DOMINATORS);
>> +  calculate_dominance_info (CDI_DOMINATORS);
>> +}
>> +}
>> +
>>  hsa_symbol *
>>  hsa_function_representation::create_hsa_temporary (BrigType16_t type)
>>  {
>> @@ -2246,30 +2257,14 @@ gen_hsa_addr_for_arg (tree tree_type, int index)
>>return new hsa_op_address (sym);
>>  }
>>  
>> -/* Generate HSA instructions that calculate address of VAL including all
>> -   necessary conversions to flat addressing and place the result into DEST.
>> +/* Generate HSA instructions that process all necessary conversions
>> +   of an ADDR to flat addressing and place the result into DEST.
>> Instructions are appended to HBB.  */
>>  
>>  static void
>> -gen_hsa_addr_insns (tree val, hsa_op_reg *dest, hsa_bb *hbb)
>> +convert_addr_to_flat_segment (hsa_op_address *addr, hsa_op_reg *dest,
>> +  hsa_bb *hbb)
>>  {
>> -  /* Handle cases like tmp = NULL, where we just emit a move instruction
>> - to a register.  */
>> -  if (TREE_CODE (val) == INTEGER_CST)
>> -{
>> -  hsa_op_immed *c = new hsa_op_immed (val);
>> -  hsa_insn_basic *insn = new hsa_insn_basic (2, BRIG_OPCODE_MOV,
>> - dest->m_type, dest, c);
>> -  hbb->append_insn (insn);
>> -  return;
>> -}
>> -
>> -  hsa_op_address *addr;
>> -
>> -  gcc_assert (dest->m_type == hsa_get_segment_addr_type 
>> (BRIG_SEGMENT_FLAT));
>> -  if (TREE_CODE (val) == ADDR_EXPR)
>> -val = TREE_OPERAND (val, 0);
>> -  addr = gen_hsa_addr (val, hbb);
>>hsa_insn_basic *insn = new hsa_insn_basic (2, BRIG_OPCODE_LDA);
>>insn->set_op (1, addr);
>>if (addr->m_symbol && addr->m_symbol->m_segment != 

Re: [PATCH 1/2] HSA: support alignment for hsa_symbols (PR hsa/70391)

2016-03-31 Thread Martin Liška
On 03/31/2016 04:40 PM, Martin Jambor wrote:
> Let's say "efficient memory copy instructions."  It is of curse
> possible to use slower ones.
> 
> Thanks,
> 
> Martin

Thanks for review, I'm attaching the version of the patch
I'm going to install.

Martin
>From 9a6ab745a88b5d40d1c1523e75dff00d4fe2ed74 Mon Sep 17 00:00:00 2001
From: marxin 
Date: Tue, 22 Mar 2016 15:51:53 +0100
Subject: [PATCH 1/2] HSA: support alignment for hsa_symbols (PR hsa/70391)

gcc/ChangeLog:

2016-03-23  Martin Liska  

	PR hsa/70391
	* hsa-brig.c (emit_directive_variable): Emit alignment
	according to hsa_symbol::m_align.
	* hsa-dump.c (hsa_byte_alignment): Move the function to
	another file.
	(dump_hsa_symbol): Dump alignment of HSA symbols.
	* hsa-gen.c (get_symbol_for_decl): Set-up alignment
	of a symbol.
	(gen_hsa_addr_with_align): New function.
	(hsa_bitmemref_alignment): Use newly added function.
	(gen_hsa_insns_for_load): Likewise.
	(gen_hsa_insns_for_store): Likewise.
	(gen_hsa_memory_copy): New argument added.
	(gen_hsa_insns_for_single_assignment): Respect
	alignment for assignments processed via
	gen_hsa_memory_copy.
	(gen_hsa_insns_for_direct_call): Likewise.
	(gen_hsa_insns_for_return): Likewise.
	(gen_function_def_parameters): Set default
	alignment.
	* hsa.c (hsa_object_alignment): New function.
	(hsa_byte_alignment): Pasted function.
	* hsa.h (hsa_symbol::m_align): New field.
---
 gcc/hsa-brig.c |  5 +---
 gcc/hsa-dump.c | 13 ++---
 gcc/hsa-gen.c  | 88 +-
 gcc/hsa.c  | 20 +
 gcc/hsa.h  |  8 +-
 5 files changed, 99 insertions(+), 35 deletions(-)

diff --git a/gcc/hsa-brig.c b/gcc/hsa-brig.c
index 9b6c0b8..ee587db 100644
--- a/gcc/hsa-brig.c
+++ b/gcc/hsa-brig.c
@@ -605,10 +605,7 @@ emit_directive_variable (struct hsa_symbol *symbol)
   dirvar.init = 0;
   dirvar.type = lendian16 (symbol->m_type);
   dirvar.segment = symbol->m_segment;
-  /* TODO: Once we are able to access global variables, we must copy their
- alignment.  */
-  dirvar.align = MAX (hsa_natural_alignment (dirvar.type),
-		  (BrigAlignment8_t) BRIG_ALIGNMENT_4);
+  dirvar.align = symbol->m_align;
   dirvar.linkage = symbol->m_linkage;
   dirvar.dim.lo = symbol->m_dim;
   dirvar.dim.hi = symbol->m_dim >> 32;
diff --git a/gcc/hsa-dump.c b/gcc/hsa-dump.c
index b69b34d..d33ac4b 100644
--- a/gcc/hsa-dump.c
+++ b/gcc/hsa-dump.c
@@ -621,16 +621,6 @@ hsa_m_atomicop_name (enum BrigAtomicOperation op)
 }
 }
 
-/* Return byte alignment for given BrigAlignment8_t value.  */
-
-static unsigned
-hsa_byte_alignment (BrigAlignment8_t alignment)
-{
-  gcc_assert (alignment != BRIG_ALIGNMENT_NONE);
-
-  return 1 << (alignment - 1);
-}
-
 /* Dump textual representation of HSA IL register REG to file F.  */
 
 static void
@@ -716,7 +706,8 @@ dump_hsa_symbol (FILE *f, hsa_symbol *symbol)
   name = buf;
 }
 
-  fprintf (f, "%s_%s %s", hsa_seg_name (symbol->m_segment),
+  fprintf (f, "align(%u) %s_%s %s", hsa_byte_alignment (symbol->m_align),
+	   hsa_seg_name (symbol->m_segment),
 	   hsa_type_name (symbol->m_type & ~BRIG_TYPE_ARRAY_MASK), name);
 
   if (symbol->m_type & BRIG_TYPE_ARRAY_MASK)
diff --git a/gcc/hsa-gen.c b/gcc/hsa-gen.c
index 72eecf9..55c46ca 100644
--- a/gcc/hsa-gen.c
+++ b/gcc/hsa-gen.c
@@ -169,12 +169,12 @@ hsa_symbol::hsa_symbol ()
 
 hsa_symbol::hsa_symbol (BrigType16_t type, BrigSegment8_t segment,
 			BrigLinkage8_t linkage, bool global_scope_p,
-			BrigAllocation allocation)
+			BrigAllocation allocation, BrigAlignment8_t align)
   : m_decl (NULL_TREE), m_name (NULL), m_name_number (0),
 m_directive_offset (0), m_type (type), m_segment (segment),
 m_linkage (linkage), m_dim (0), m_cst_value (NULL),
 m_global_scope_p (global_scope_p), m_seen_error (false),
-m_allocation (allocation), m_emitted_to_brig (false)
+m_allocation (allocation), m_emitted_to_brig (false), m_align (align)
 {
 }
 
@@ -908,21 +908,29 @@ get_symbol_for_decl (tree decl)
 {
   hsa_symbol *sym;
   gcc_assert (TREE_CODE (decl) == VAR_DECL);
+  BrigAlignment8_t align = hsa_object_alignment (decl);
 
   if (is_in_global_vars)
 	{
 	  sym = new hsa_symbol (BRIG_TYPE_NONE, BRIG_SEGMENT_GLOBAL,
 BRIG_LINKAGE_PROGRAM, true,
-BRIG_ALLOCATION_PROGRAM);
+BRIG_ALLOCATION_PROGRAM, align);
 	  hsa_cfun->m_global_symbols.safe_push (sym);
 	}
   else
 	{
+	  /* As generation of efficient memory copy instructions relies
+	 on alignment greater or equal to 8 bytes,
+	 we need to increase alignment of all aggregate types.. */
+	  if (AGGREGATE_TYPE_P (TREE_TYPE (decl)))
+	align = MAX ((BrigAlignment8_t) BRIG_ALIGNMENT_8, align);
+
 	  /* PARM_DECL and RESULT_DECL should be already in m_local_symbols.  */
 	  gcc_assert (TREE_CODE (decl) == VAR_DECL);
 
 	  sym = new hsa_symbol (BRIG_TYPE_NONE, BRIG_SEGMENT_PRIVATE,
 BRIG_LINKAGE_FUNCTION);
+	  sym->m_align = align;
 	  

Re: [c++/68475] ICE with fno-exceptions

2016-03-31 Thread Jason Merrill

OK.

Jason


Re: [c++/68475] ICE with fno-exceptions

2016-03-31 Thread Nathan Sidwell

On 03/30/16 09:44, Jason Merrill wrote:


Hmm, I think the use of the flag there was meant to allow leaving the exception
specification off in some declarations.  I'm open to getting stricter, but I'd
prefer to make it a pedwarn when !flag_exceptions rather than an error, in which
case we still need to deal with the mismatch in merge_exception_specifiers.


ok.  Like this?

nathan
2016-03-31  Nathan Sidwell  

	PR c++/68475
	* decl.c (check_redeclaration_exception_specification): Check
	regardless of -fno-exceptions.
	* typeck2.c (merge_exception_specifiers): Relax assert by checking
	flag_exceptions too.

	PR c++/68475
	* g++.dg/g++.dg/cpp0x/noexcept29.C: New.

Index: cp/decl.c
===
--- cp/decl.c	(revision 234641)
+++ cp/decl.c	(working copy)
@@ -1202,16 +1202,19 @@ check_redeclaration_exception_specificat
  specialization, of that function shall have an
  exception-specification with the same set of type-ids.  */
   if (! DECL_IS_BUILTIN (old_decl)
-  && flag_exceptions
   && !comp_except_specs (new_exceptions, old_exceptions, ce_normal))
 {
   const char *msg
 	= "declaration of %q+F has a different exception specifier";
   bool complained = true;
-  if (! DECL_IN_SYSTEM_HEADER (old_decl))
-	error (msg, new_decl);
-  else
+  if (DECL_IN_SYSTEM_HEADER (old_decl))
 	complained = pedwarn (0, OPT_Wsystem_headers, msg, new_decl);
+  else if (!flag_exceptions)
+	/* We used to silently permit mismatched eh specs with
+	   -fno-exceptions, so make them a pedwarn now.  */
+	complained = pedwarn (0, OPT_Wpedantic, msg, new_decl);
+  else
+	error (msg, new_decl);
   if (complained)
 	inform (0, "from previous declaration %q+F", old_decl);
 }
Index: cp/typeck2.c
===
--- cp/typeck2.c	(revision 234641)
+++ cp/typeck2.c	(working copy)
@@ -2143,7 +2143,7 @@ merge_exception_specifiers (tree list, t
 return add;
   noex = TREE_PURPOSE (list);
   gcc_checking_assert (!TREE_PURPOSE (add)
-		   || errorcount
+		   || errorcount || !flag_exceptions
 		   || cp_tree_equal (noex, TREE_PURPOSE (add)));
 
   /* Combine the dynamic-exception-specifiers, if any.  */
Index: testsuite/g++.dg/cpp0x/noexcept29.C
===
--- testsuite/g++.dg/cpp0x/noexcept29.C	(nonexistent)
+++ testsuite/g++.dg/cpp0x/noexcept29.C	(working copy)
@@ -0,0 +1,19 @@
+// { dg-do compile { target c++11 } }
+// { dg-additional-options "-fno-exceptions" }
+
+// PR68475 we used to not check eh spec matching with -fno-exceptions,
+// but this could lead to ICEs.
+
+template  struct traits;
+
+template  struct X
+{
+  void Foo () noexcept (traits ::foo ()); // { dg-message "previous declaration" }
+};
+
+template 
+void
+X::Foo () noexcept (traits ::bar ()) // { dg-error "different exception specifier" }
+{
+}
+


Re: [PATCH PR69489/01]Improve tree ifcvt by storing/tracking DR against its innermost loop bahavior if possible

2016-03-31 Thread Bin.Cheng
On Tue, Mar 29, 2016 at 9:37 AM, Richard Biener
 wrote:
> On Mon, Mar 28, 2016 at 9:57 PM, Bin.Cheng  wrote:
>> Sorry, Should have replied to gcc-patches list.
>>
>> Thanks,
>> bin
>>
>> -- Forwarded message --
>> From: "Bin.Cheng" 
>> Date: Tue, 29 Mar 2016 03:55:04 +0800
>> Subject: Re: [PATCH PR69489/01]Improve tree ifcvt by storing/tracking
>> DR against its innermost loop bahavior if possible
>> To: Richard Biener 
>>
>> On 3/17/16, Richard Biener  wrote:
>>> On Wed, Mar 16, 2016 at 5:17 PM, Bin.Cheng  wrote:
 On Wed, Mar 16, 2016 at 12:20 PM, Richard Biener
  wrote:
>
> Hmm.
 Hi,
 Thanks for reviewing.
>
> +  equal_p = true;
> +  if (e1->base_address && e2->base_address)
> +equal_p &= operand_equal_p (e1->base_address, e2->base_address, 0);
> +  if (e1->offset && e2->offset)
> +equal_p &= operand_equal_p (e1->offset, e2->offset, 0);
>
> surely better to return false early.
>
> I think we don't want this in tree-data-refs.h also because of ...
>
> @@ -615,15 +619,29 @@
> hash_memrefs_baserefs_and_store_DRs_read_written_info
> (data_reference_p a)
>data_reference_p *master_dr, *base_master_dr;and REALPART) before
> creating the DR (or adjust the equality function
 and hashing
>tree ref = DR_REF (a);
>tree base_ref = DR_BASE_OBJECT (a);
> +  innermost_loop_behavior *innermost = _INNERMOST (a);
>tree ca = bb_predicate (gimple_bb (DR_STMT (a)));
>bool exist1, exist2;
>
> -  while (TREE_CODE (ref) == COMPONENT_REF
> -|| TREE_CODE (ref) == IMAGPART_EXPR
> -|| TREE_CODE (ref) == REALPART_EXPR)
> -ref = TREE_OPERAND (ref, 0);
> +  /* If reference in DR has innermost loop behavior and it is not
> + a compound memory reference, we store it to innermost_DR_map,
> + otherwise to ref_DR_map.  */
> +  if (TREE_CODE (ref) == COMPONENT_REF
> +  || TREE_CODE (ref) == IMAGPART_EXPR
> +  || TREE_CODE (ref) == REALPART_EXPR
> +  || !(DR_BASE_ADDRESS (a) || DR_OFFSET (a)
> +  || DR_INIT (a) || DR_STEP (a) || DR_ALIGNED_TO (a)))
> +{
> +  while (TREE_CODE (ref) == COMPONENT_REF
> +|| TREE_CODE (ref) == IMAGPART_EXPR
> +|| TREE_CODE (ref) == REALPART_EXPR)
> +   ref = TREE_OPERAND (ref, 0);
> +
> +  master_dr = _DR_map->get_or_insert (ref, );
> +}
> +  else
> +master_dr = _DR_map->get_or_insert (innermost, );
>
> we don't want an extra hashmap but replace ref_DR_map entirely.  So we'd
> need to
> strip outermost non-variant handled-components (COMPONENT_REF, IMAGPART
> and REALPART) before creating the DR (or adjust the equality function
> and hashing
> to disregard them which means subtracting their offset from DR_INIT.
 I am not sure if I understand correctly.  But for component reference,
 it is the base object that we want to record/track.  For example,

   for (i = 0; i < N; i++) {
 m = *data++;

 m1 = p1->x - m;
 m2 = p2->x + m;

 p3->y = (m1 >= m2) ? p1->y : p2->y;

 p1++;
 p2++;
 p3++;
   }
 We want to infer that reads of p1/p2 in condition statement won't trap
 because there are unconditional reads of the structures, though the
 unconditional reads are actual of other sub-objects.  Here it is the
 invariant part of address that we want to track.
>>>
>>> Well, the variant parts - we want to strip invariant parts as far as we can
>>> (offsetof (x) and offsetof (y))
>>>
 Also illustrated by this example, we can't rely on data-ref analyzer
 here.  Because in gathering/scattering cases, the address could be not
 affine at all.
>>>
>>> Sure, but that's a different issue.
>>>
>
> To adjust the references we collect you'd maybe could use a callback
> to get_references_in_stmt
> to adjust them.
>
> OTOH post-processing the DRs in if_convertible_loop_p_1 can be as simple
> as
 Is this a part of the method you suggested above, or is it an
 alternative one?  If it's the latter, then I have below questions
 embedded.
>>>
>>> It is an alternative to adding a hook to get_references_in_stmt and
>>> probably "easier".
>>>
>
> Index: tree-if-conv.c
> ===
> --- tree-if-conv.c  (revision 234215)
> +++ tree-if-conv.c  (working copy)
> @@ -1235,6 +1220,38 @@ if_convertible_loop_p_1 (struct loop *lo
>
>for (i = 0; refs->iterate (i, ); i++)
>  {
> +  tree *refp = _REF (dr);
> +  while ((TREE_CODE (*refp) == 

Re: [Patch AArch64] Fix PR target/63874

2016-03-31 Thread James Greenhalgh
On Thu, Mar 31, 2016 at 02:11:49PM +0100, Ramana Radhakrishnan wrote:
> Hi,
> 
>   In this PR we have a situation where we aren't really detecting
> weak references vs weak definitions. If one has a weak definition
> that binds locally there's no reason not to put out PC relative
> relocations.
> 
> However if you have a genuine weak reference that is
> known not to bind locally it makes very little sense
> to put out an entry into the literal pool which doesn't always
> work with DSOs and shared objects.
> 
> Tested aarch64-none-linux-gnu bootstrap and regression test with no 
> regressions
> 
> This is not a regression and given what we've seen recently with protected
> symbols and binds_locally_p I'd rather this were queued for GCC 7. 
> 
> Ok ?

Based on the bugzilla report, this looks OK for GCC 7 to me. But I don't
know the dark corners of the elf specification, so I'd rather leave the
final review to Richard or Marcus.

Thanks,
James

> gcc/
> 
> * config/aarch64/aarch64.c (aarch64_classify_symbol): Typo in comment fixed.
>   Only force to memory if it is a weak external reference.
> 
> gcc/testsuite
> 
> * gcc.target/aarch64/pr63874.c: New test.



[C++] Remove unused delete

2016-03-31 Thread Nathan Sidwell
In looking at  PR55635, I got confused as to why changes to 
finish_destructor_body didn't affect the generated code.  Then I realized that 
the delete call and in-charge stuff being emitted there was entirely inactive. 
 We now generate  the deleting dtor in build_delete_destructor_body 
(optimize.c) as a call the the full destructor and an  explicit delete operator 
call.


So I've committed this patch to remove the ineffective code generation. (We 
still  need the in-charge pseudo-parm to distinguish full and base destruction.)


nathan
2016-03-31  Nathan Sidwell  

	* decl.c (start_preparsed_function): Remove unnecessary bracing.
	(finish_destructor_body): Don't emit operator delete here.

Index: cp/decl.c
===
--- cp/decl.c	(revision 234635)
+++ cp/decl.c	(working copy)
@@ -14170,9 +14170,7 @@ start_preparsed_function (tree decl1, tr
   if (DECL_DESTRUCTOR_P (decl1)
   || (DECL_CONSTRUCTOR_P (decl1)
 	  && targetm.cxx.cdtor_returns_this ()))
-{
-  cdtor_label = create_artificial_label (input_location);
-}
+cdtor_label = create_artificial_label (input_location);
 
   start_fname_decls ();
 
@@ -14428,35 +14426,6 @@ finish_destructor_body (void)
  and member cleanups will be run when the function returns.  */
   add_stmt (build_stmt (input_location, LABEL_EXPR, cdtor_label));
 
-  /* In a virtual destructor, we must call delete.  */
-  if (DECL_VIRTUAL_P (current_function_decl))
-{
-  tree if_stmt;
-  tree virtual_size = cxx_sizeof (current_class_type);
-
-  /* [class.dtor]
-
-  At the point of definition of a virtual destructor (including
-  an implicit definition), non-placement operator delete shall
-  be looked up in the scope of the destructor's class and if
-  found shall be accessible and unambiguous.  */
-  exprstmt = build_op_delete_call (DELETE_EXPR, current_class_ptr,
-   virtual_size,
-   /*global_p=*/false,
-   /*placement=*/NULL_TREE,
-   /*alloc_fn=*/NULL_TREE,
-   tf_warning_or_error);
-
-  if_stmt = begin_if_stmt ();
-  finish_if_stmt_cond (build2 (BIT_AND_EXPR, integer_type_node,
-   current_in_charge_parm,
-   integer_one_node),
-			   if_stmt);
-  finish_expr_stmt (exprstmt);
-  finish_then_clause (if_stmt);
-  finish_if_stmt (if_stmt);
-}
-
   if (targetm.cxx.cdtor_returns_this ())
 {
   tree val;


Re: [PATCH][ARM][4.9 Backport] PR target/69875 Fix atomic_loaddi expansion

2016-03-31 Thread Kyrill Tkachov


On 30/03/16 09:34, Kyrill Tkachov wrote:


On 29/03/16 19:46, Christophe Lyon wrote:

On 16 March 2016 at 16:54, Ramana Radhakrishnan
 wrote:

On Wed, Feb 24, 2016 at 11:23 AM, Kyrill Tkachov
 wrote:

Hi all,

This is the GCC 4.9 backport of
https://gcc.gnu.org/ml/gcc-patches/2016-02/msg01338.html.
The differences are that TARGET_HAVE_LPAE has to be defined in arm.h in a
different way because
the ARM_FSET_HAS_CPU1 mechanism doesn't exist on this branch. Also, due to
the location of insn_flags
and the various FL_* (on the 4.9 branch they're defined locally in arm.c
rather than in arm-protos.h)
I chose to define TARGET_HAVE_LPAE in terms of hardware divide instruction
availability. This should be
an equivalent definition.

Also, the scan-assembler tests that check for the DMB instruction are
updated to check for
"dmb sy" rather than "dmb ish", because the memory barrier instruction
changed on trunk for GCC 6.

Bootstrapped and tested on the GCC 4.9 branch on arm-none-linux-gnueabihf.


Ok for the branch after the trunk patch has had a few days to bake?


OK.


Hi Kyrylo,

Since you backported this to branches 4.9 and 5, I've noticed cross-GCC build
failures:
--target arm-none-linux-gnueabihf
--with-mode=arm
--with-cpu=cortex-a57
--with-fpu=crypto-neon-fp-armv8

The build succeeds --with-mode=thumb.

The error message I'm seeing is:
/tmp/6190285_22.tmpdir/ccuX17sh.s: Assembler messages:
/tmp/6190285_22.tmpdir/ccuX17sh.s:34: Error: bad instruction `ldrdeq r0,r1,[r0]'
make[4]: *** [load_8_.lo] Error 1

while building libatomic


Darn, I had re-tested before committing with --with-mode=thumb :(
The problem here is that GCC 5 and 4.9 don't use unified syntax
for arm state (it was switched on for GCC 6), so the output template
in the new arm_atomic_loaddi2_ldrd pattern should be "ldr%(d%)" instead
of "ldrd%?".

I'll prepare a patch.
Thanks for catching this,
Kyrill



And here it is.
I've reproduced the build failure on 4.9 and 5 and confirmed that this patch 
fixes
them and that a build with --with-mode=thumb is unaffected.

I'm committing this as obvious in order to fix the broken build in the affected 
configurations.

Sorry for the trouble.

Kyrill

2016-03-31  Kyrylo Tkachov  

* config/arm/sync.md (arm_atomic_loaddi2_ldrd): Fix output template
for non-unified syntax.

2016-03-31  Kyrylo Tkachov  

* gcc.target/arm/atomic_loaddi_relaxed_cond.c: New test.




Christophe



Ramana

Thanks,
Kyrill

2016-02-24  Kyrylo Tkachov  

 PR target/69875
 * config/arm/arm.h (TARGET_HAVE_LPAE): Define.
 * config/arm/unspecs.md (VUNSPEC_LDRD_ATOMIC): New value.
 * config/arm/sync.md (arm_atomic_loaddi2_ldrd): New pattern.
 (atomic_loaddi_1): Delete.
 (atomic_loaddi): Rewrite expander using the above changes.

2016-02-24  Kyrylo Tkachov  

 PR target/69875
 * gcc.target/arm/atomic_loaddi_acquire.x: New file.
 * gcc.target/arm/atomic_loaddi_relaxed.x: Likewise.
 * gcc.target/arm/atomic_loaddi_seq_cst.x: Likewise.
 * gcc.target/arm/atomic_loaddi_1.c: New test.
 * gcc.target/arm/atomic_loaddi_2.c: Likewise.
 * gcc.target/arm/atomic_loaddi_3.c: Likewise.
 * gcc.target/arm/atomic_loaddi_4.c: Likewise.
 * gcc.target/arm/atomic_loaddi_5.c: Likewise.
 * gcc.target/arm/atomic_loaddi_6.c: Likewise.
 * gcc.target/arm/atomic_loaddi_7.c: Likewise.
 * gcc.target/arm/atomic_loaddi_8.c: Likewise.
 * gcc.target/arm/atomic_loaddi_9.c: Likewise.




diff --git a/gcc/config/arm/sync.md b/gcc/config/arm/sync.md
index acafd0a6ec474466ff7e2c67ae16d9a0dbb9cf5c..17eab93d55c00fd8db3f612bed1caf0e29335f27 100644
--- a/gcc/config/arm/sync.md
+++ b/gcc/config/arm/sync.md
@@ -107,7 +107,7 @@ (define_insn "arm_atomic_loaddi2_ldrd"
 	  [(match_operand:DI 1 "arm_sync_memory_operand" "Q")]
 	VUNSPEC_LDRD_ATOMIC))]
   "ARM_DOUBLEWORD_ALIGN && TARGET_HAVE_LPAE"
-  "ldrd%?\t%0, %H0, %C1"
+  "ldr%(d%)\t%0, %H0, %C1"
   [(set_attr "predicable" "yes")
(set_attr "predicable_short_it" "no")])
 
diff --git a/gcc/testsuite/gcc.target/arm/atomic_loaddi_relaxed_cond.c b/gcc/testsuite/gcc.target/arm/atomic_loaddi_relaxed_cond.c
new file mode 100644
index ..d69775150813a01b7fcab64deac218a6b2c33c56
--- /dev/null
+++ b/gcc/testsuite/gcc.target/arm/atomic_loaddi_relaxed_cond.c
@@ -0,0 +1,20 @@
+/* { dg-do assemble } */
+/* { dg-options "-std=c11 -O" } */
+/* { dg-require-effective-target arm_arch_v8a_ok } */
+/* { dg-add-options arm_arch_v8a } */
+
+/* Check that if we conditionalise the atomic load we put the condition
+   code in the right place to create valid assembly.  */
+
+#include 
+
+atomic_ullong foo;
+int glob;
+
+int
+main (int argc, char *argv[])
+{
+  if (argc > 2)
+atomic_load_explicit (, memory_order_relaxed);
+  return glob;
+}


Re: [PATCH GCC]Reduce compilation time for IVOPT by skipping cost computation in use group

2016-03-31 Thread Bin.Cheng
On Thu, Mar 31, 2016 at 1:27 PM, H.J. Lu  wrote:
> On Wed, Mar 30, 2016 at 5:11 AM, Bin.Cheng  wrote:
>> On Wed, Mar 30, 2016 at 9:09 AM, Richard Biener
>>  wrote:
>>> On Thu, Mar 24, 2016 at 6:26 PM, Bin Cheng  wrote:
 Hi,
 Quite lot of time is used when IVOPT computes cost for  pairs.  
 As a matter of fact, some pairs are very similar to each other, and we can 
 abstract and compute cost only once for these pairs.  This is a patch 
 doing so, the idea is skipping cost computation for sub-uses in each 
 group, of course it may result in different assembly code for some 
 complicated cases because it estimates cost rather than doing real 
 computation.  I did double check one of such case that the change in 
 generated assembly is not degeneration.  For an IVOPT heavy program 
 (spec2k/173), this patch reduces IVOPT's compilation time by 7~8%, as well 
 as the memory consumption on my developing machine.

 Bootstrap & test on x86_64.

 For spec2k6 data on x86_64.  Maybe because I ran spec2k6 compiled with 
 patched GCC in unclean environment, some cases are regressed by small 
 amount (< %1).  I manually compared assembly code for several cases, 
 including ones with the largest regression (still within <1%).  I could 
 confirm that generated assembly code is exact the same as unpatched GCC, 
 except for function emit_library_call_value_1 in 403.gcc/calls.c.

 In this case, difference of IVOPT dumps is as below:

 $ diff -y trunk/calls.c.154t.ivopts patch/calls.c.154t.ivopts

   ::
   # val_21 = PHI   # val_21 
 = PHI 
   _811 = (void *) ivtmp.322_829;  _811 = 
 (void *) ivtmp.322_829;
   MEM[base: _811, offset: -48B] = val_21; |   
 MEM[base: _811, offset: -32B] = val_21;
   _810 = (void *) ivtmp.322_829;  _810 = 
 (void *) ivtmp.322_829;
   MEM[base: _810, offset: -40B] = mode_163;   |   
 MEM[base: _810, offset: -24B] = mode_163;
   _182 = function_arg (_so_far, mode_163, 0B, 1);_182 = 
 function_arg (_so_far, mode_163, 0B, 1);
   _809 = (void *) ivtmp.322_829;  _809 = 
 (void *) ivtmp.322_829;
   MEM[base: _809, offset: -32B] = _182;   |   
 MEM[base: _809, offset: -16B] = _182;
   _807 = (void *) ivtmp.322_829;  _807 = 
 (void *) ivtmp.322_829;
   MEM[base: _807, offset: -24B] = 0;  |   
 MEM[base: _807, offset: -8B] = 0;
   _185 = (struct args_size *) ivtmp.322_829;  |   _801 = 
 ivtmp.322_829 + 16;
   _801 = ivtmp.322_829 + 18446744073709551600;<
   _800 = (struct args_size *) _801;   _800 = 
 (struct args_size *) _801;
   _186 = _800;|   _185 = 
 _800;
   >   _186 = 
 (struct args_size *) ivtmp.322_829;
   _187 = _182 != 0B;  _187 = 
 _182 != 0B;
   _188 = (int) _187;  _188 = 
 (int) _187;
   locate_and_pad_parm (mode_163, 0B, _188, 0B, _size, _1 
 locate_and_pad_parm (mode_163, 0B, _188, 0B, _size, _1
   _802 = (void *) ivtmp.322_829;  _802 = 
 (void *) ivtmp.322_829;
   _190 = MEM[base: _802, offset: 8B]; |   _190 = 
 MEM[base: _802, offset: 24B];
   if (_190 != 0B) if (_190 
 != 0B)
 goto ;   goto 
 ;
   elseelse
 goto ;   goto 
 ;

   ::
   fancy_abort ("calls.c", 3724, &__FUNCTION__);   
 fancy_abort ("calls.c", 3724, &__FUNCTION__);

 It's only an offset difference in IV.  And below is difference of 
 generated assembly:
 $ diff -y trunk/calls.S patch/calls.S
 .L489:  .L489:
 leaq-80(%rbp), %rdi 
 leaq-80(%rbp), %rdi
 xorl%edx, %edx  
 xorl%edx, %edx
 movl$1, %ecx
 movl$1, %ecx
 

Re: Patches to fix optimizer bug & C++ exceptions for GCC VAX backend

2016-03-31 Thread Jeff Law

On 03/31/2016 08:30 AM, Jan-Benedict Glaw wrote:

Hi Jake!

On Mon, 2016-03-28 16:34:56 -0700, Jake Hamby  wrote:

Amazingly enough, my patch worked well enough that my NetBSD VAX
kernel built with GCC 5.3 is no longer crashing. I feel pretty good
about what I have so far so here's the complete diff for both the
C++ exception fix and the bad condition codes optimizer bug. It
should be good enough to check into NetBSD current, at least, and I
believe it does fix most, if not all, of the bad code generation
bugs with optimization on VAX.


I'd like to suggest to also Cc Matt Thomas , at
least once the patch is tested with GCC trunk/HEAD/master, instead of
5.3.  There isn't probably much of a difference, but you've done
substancial and important work here, so let's see it's applicable to
upstream GCC.

   And keep in mind that a ChangeLog entry is also needed.

FWIW, I put this in my gcc-7 queue.
jeff


Re: [Patch ARM] Delete ASM_OUTPUT_DEF and fall back to default .set directive

2016-03-31 Thread Ramana Radhakrishnan
On 31/03/16 16:41, James Greenhalgh wrote:
> 
> Hi,
> 
> gcc.dg/torture/pr69951.c has been failing for arm*-*-linux* targets, as
> we put out "b = a" as a way of defining a symbol alias, which trips an
> assembler warning if the left hand side is an instruction name (such as 'b'
> for branch, see [1] for context).
> 
> We don't want to do this, a simple .set directive will suffice. This can
> be achieved by deleting the definition of ASM_OUTPUT_DEF in
> config/arm/linux-elf.h . This will cause us to fall back to the default
> definition, as we have SET_ASM_OP defined through config/elfos.h for all
> ARM ports. This patch makes that change.
> 
> Built and tested on an arm-none-linux-gnueabihf box with no issues.
> 
> OK?


Ok.

Ramana
> 
> Thanks,
> James
> 
> ---
> 2016-03-31  James Greenhalgh  
> 
>   * config/arm/linux-elf.h (ASM_OUTPUT_DEF): Delete.
> 
> ---
> 
> [1]: https://gcc.gnu.org/ml/gcc-patches/2016-03/msg00018.html
> 



[Patch ARM] Delete ASM_OUTPUT_DEF and fall back to default .set directive

2016-03-31 Thread James Greenhalgh

Hi,

gcc.dg/torture/pr69951.c has been failing for arm*-*-linux* targets, as
we put out "b = a" as a way of defining a symbol alias, which trips an
assembler warning if the left hand side is an instruction name (such as 'b'
for branch, see [1] for context).

We don't want to do this, a simple .set directive will suffice. This can
be achieved by deleting the definition of ASM_OUTPUT_DEF in
config/arm/linux-elf.h . This will cause us to fall back to the default
definition, as we have SET_ASM_OP defined through config/elfos.h for all
ARM ports. This patch makes that change.

Built and tested on an arm-none-linux-gnueabihf box with no issues.

OK?

Thanks,
James

---
2016-03-31  James Greenhalgh  

* config/arm/linux-elf.h (ASM_OUTPUT_DEF): Delete.

---

[1]: https://gcc.gnu.org/ml/gcc-patches/2016-03/msg00018.html

diff --git a/gcc/config/arm/linux-elf.h b/gcc/config/arm/linux-elf.h
index 472141d..a94bd2d 100644
--- a/gcc/config/arm/linux-elf.h
+++ b/gcc/config/arm/linux-elf.h
@@ -85,17 +85,6 @@
 }		\
   while (0)
 
-/* This is how we tell the assembler that two symbols have the same value.  */
-#define ASM_OUTPUT_DEF(FILE, NAME1, NAME2) \
-  do	   \
-{	   \
-  assemble_name (FILE, NAME1); 	   \
-  fputs (" = ", FILE);		   \
-  assemble_name (FILE, NAME2);	   \
-  fputc ('\n', FILE);		   \
-}	   \
-  while (0)
-
 #undef  FPUTYPE_DEFAULT
 #define FPUTYPE_DEFAULT "vfp"
 


Re: [PATCH, PR target/70442] STV: suppport undefined registers for reg copies

2016-03-31 Thread Ilya Enkovich
On 31 Mar 13:47, Uros Bizjak wrote:
> On Thu, Mar 31, 2016 at 1:31 PM, Jakub Jelinek  wrote:
> > On Thu, Mar 31, 2016 at 02:25:41PM +0300, Ilya Enkovich wrote:
> >> This patch adds support for undefined register copies.
> >> This is simply done by calling scalar_chain::convert_op
> >> for copied registers.  Bootstrapped and regtested on
> >> x86_64-unknown-linux-gnu{-m32}.  OK for trunk?
> >>
> >> Thanks,
> >> Ilya
> >> --
> >> gcc/
> >>
> >> 2016-03-31  Ilya Enkovich  
> >>
> >
> > Missing
> > PR target/70442
> > here.
> >
> >> 2016-03-31  Ilya Enkovich  
> >>
> > And here too.
> >
> >>   * gcc.target/i386/pr70442.c: New test.
> >
> >> @@ -3467,6 +3468,8 @@ scalar_chain::convert_insn (rtx_insn *insn)
> >>break;
> >>
> >>  case REG:
> >> +  if (!MEM_P(dst))
> >
> > Missing space before (.
> >
> >> --- /dev/null
> >> +++ b/gcc/testsuite/gcc.target/i386/pr70442.c
> >> @@ -0,0 +1,18 @@
> >
> > I'd add
> > /* PR target/70442 */
> > here.
> >
> >> +/* { dg-do compile { target { ia32 } } } */
> >> +/* { dg-options "-O2 -msse2" } */
> >
> > There is really nothing ia32 specific on the test, so I'd move it
> > to gcc.dg/pr70442.c instead, and just
> > /* { dg-do compile } */
> > /* { dg-options "-O2" } */
> > /* { dg-additional-options "-msse2" { target ia32 } } */
> > or so.
> >
> > For the i386.c change I'll defer to Uros as the maintainer.
> 
> It is OK with the above proposed improvements.
> 
> Thanks,
> Uros.

Thanks for review!

Here is a committed version.

Thanks,
Ilya
--
gcc/

2016-03-31  Ilya Enkovich  

PR target/70442
* config/i386/i386.c (scalar_chain::convert_op): Fix
description.
(scalar_chain::convert_insn): Call convert_op for reg
moves to handle undefined registers.

gcc/testsuite/

2016-03-31  Ilya Enkovich  

PR target/70442
* gcc.dg/pr70442.c: New test.



diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
index 1639704..f06baf0 100644
--- a/gcc/config/i386/i386.c
+++ b/gcc/config/i386/i386.c
@@ -3384,9 +3384,10 @@ scalar_chain::convert_reg (unsigned regno)
   BITMAP_FREE (conv);
 }
 
-/* Convert operand OP in INSN.  All register uses
-   are converted during registers conversion.
-   Therefore we should just handle memory operands.  */
+/* Convert operand OP in INSN.  We should handle
+   memory operands and uninitialized registers.
+   All other register uses are converted during
+   registers conversion.  */
 
 void
 scalar_chain::convert_op (rtx *op, rtx_insn *insn)
@@ -3467,6 +3468,8 @@ scalar_chain::convert_insn (rtx_insn *insn)
   break;
 
 case REG:
+  if (!MEM_P (dst))
+   convert_op (, insn);
   break;
 
 case SUBREG:
diff --git a/gcc/testsuite/gcc.dg/pr70442.c b/gcc/testsuite/gcc.dg/pr70442.c
new file mode 100644
index 000..b9c11ea
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr70442.c
@@ -0,0 +1,20 @@
+/* PR target/70442 */
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+/* { dg-additional-options "-msse2" { target ia32 } } */
+
+char a, c;
+void
+fn1 ()
+{
+  long long b;
+  long m;
+  int d;
+  switch (d)
+{
+case 5:
+  b = a;
+}
+  b ^= m;
+  c = b >> b;
+}


Re: [PATCH 2/2] HSA: handle alignment of string builtins (PR hsa/70391)

2016-03-31 Thread Martin Jambor
Hi,

On Wed, Mar 23, 2016 at 02:43:17PM +0100, Martin Liska wrote:
> gcc/ChangeLog:
> 
> 2016-03-23  Martin Liska  
> 
>   PR hsa/70391
>   * hsa-gen.c (hsa_function_representation::update_cfg): New
>   function.
>   (convert_addr_to_flat_segment): Likewise.
>   (gen_hsa_memory_set): New alignment argument.
>   (gen_hsa_ctor_assignment): Likewise.
>   (gen_hsa_insns_for_single_assignment): Provide alignment
>   to gen_hsa_ctor_assignment.
>   (gen_hsa_insns_for_direct_call): Add new argument.
>   (expand_lhs_of_string_op): New function.
>   (expand_string_operation_builtin): Likewise.
>   (expand_memory_copy): New function.
>   (expand_memory_set): New function.
>   (gen_hsa_insns_for_call): Use HOST_WIDE_INT.
>   (convert_switch_statements): Change signature.
>   (generate_hsa): Use a return value of the function.
>   (pass_gen_hsail::execute): Do not call
>   convert_switch_statements here.
>   * hsa-regalloc.c (hsa_regalloc): Call update_cfg.
>   * hsa.h (hsa_function_representation::m_need_cfg_update):
>   New flag.
>   (hsa_function_representation::update_cfg): New function.

As we already discussed, update_cfg and m_need_cfg_update should
really be called differently, because CFG has already been modified
and only dominance needs to be re-computed.  If you havent't thought
about any names yet, what about m_modified_cfg and update_dominance() ?


> ---
>  gcc/hsa-gen.c  | 372 
> ++---
>  gcc/hsa-regalloc.c |   1 +
>  gcc/hsa.h  |   9 +-
>  3 files changed, 275 insertions(+), 107 deletions(-)
> 
> diff --git a/gcc/hsa-gen.c b/gcc/hsa-gen.c
> index db39813..db7fc3d 100644
> --- a/gcc/hsa-gen.c
> +++ b/gcc/hsa-gen.c
> @@ -214,7 +214,7 @@ hsa_symbol::fillup_for_decl (tree decl)
> should be set to number of SSA names used in the function.  */
>  
>  hsa_function_representation::hsa_function_representation
> -  (tree fdecl, bool kernel_p, unsigned ssa_names_count)
> +  (tree fdecl, bool kernel_p, unsigned ssa_names_count, bool need_cfg_update)
>: m_name (NULL),
>  m_reg_count (0), m_input_args (vNULL),
>  m_output_arg (NULL), m_spill_symbols (vNULL), m_global_symbols (vNULL),
> @@ -223,7 +223,8 @@ hsa_function_representation::hsa_function_representation
>  m_in_ssa (true), m_kern_p (kernel_p), m_declaration_p (false),
>  m_decl (fdecl), m_internal_fn (NULL), m_shadow_reg (NULL),
>  m_kernel_dispatch_count (0), m_maximum_omp_data_size (0),
> -m_seen_error (false), m_temp_symbol_count (0), m_ssa_map ()
> +m_seen_error (false), m_temp_symbol_count (0), m_ssa_map (),
> +m_need_cfg_update (need_cfg_update)
>  {
>int sym_init_len = (vec_safe_length (cfun->local_decls) / 2) + 1;;
>m_local_symbols = new hash_table  (sym_init_len);
> @@ -319,6 +320,16 @@ hsa_function_representation::init_extra_bbs ()
>hsa_init_new_bb (EXIT_BLOCK_PTR_FOR_FN (cfun));
>  }
>  
> +void
> +hsa_function_representation::update_cfg ()
> +{
> +  if (m_need_cfg_update)
> +{
> +  free_dominance_info (CDI_DOMINATORS);
> +  calculate_dominance_info (CDI_DOMINATORS);
> +}
> +}
> +
>  hsa_symbol *
>  hsa_function_representation::create_hsa_temporary (BrigType16_t type)
>  {
> @@ -2246,30 +2257,14 @@ gen_hsa_addr_for_arg (tree tree_type, int index)
>return new hsa_op_address (sym);
>  }
>  
> -/* Generate HSA instructions that calculate address of VAL including all
> -   necessary conversions to flat addressing and place the result into DEST.
> +/* Generate HSA instructions that process all necessary conversions
> +   of an ADDR to flat addressing and place the result into DEST.
> Instructions are appended to HBB.  */
>  
>  static void
> -gen_hsa_addr_insns (tree val, hsa_op_reg *dest, hsa_bb *hbb)
> +convert_addr_to_flat_segment (hsa_op_address *addr, hsa_op_reg *dest,
> +   hsa_bb *hbb)
>  {
> -  /* Handle cases like tmp = NULL, where we just emit a move instruction
> - to a register.  */
> -  if (TREE_CODE (val) == INTEGER_CST)
> -{
> -  hsa_op_immed *c = new hsa_op_immed (val);
> -  hsa_insn_basic *insn = new hsa_insn_basic (2, BRIG_OPCODE_MOV,
> -  dest->m_type, dest, c);
> -  hbb->append_insn (insn);
> -  return;
> -}
> -
> -  hsa_op_address *addr;
> -
> -  gcc_assert (dest->m_type == hsa_get_segment_addr_type (BRIG_SEGMENT_FLAT));
> -  if (TREE_CODE (val) == ADDR_EXPR)
> -val = TREE_OPERAND (val, 0);
> -  addr = gen_hsa_addr (val, hbb);
>hsa_insn_basic *insn = new hsa_insn_basic (2, BRIG_OPCODE_LDA);
>insn->set_op (1, addr);
>if (addr->m_symbol && addr->m_symbol->m_segment != BRIG_SEGMENT_GLOBAL)
> @@ -2298,6 +2293,34 @@ gen_hsa_addr_insns (tree val, hsa_op_reg *dest, hsa_bb 
> *hbb)
>  }
>  }
>  
> +/* Generate HSA instructions that calculate address of VAL including all
> +   necessary 

Re: [PATCH][PR rtl-optimization/69307] Handle hard registers in modes that span more than one register properly

2016-03-31 Thread Andrey Belevantsev

Hello,

On 12.03.2016 20:13, Jeff Law wrote:


As Andrey outlined in the PR, selective-scheduling was missing a check &
handling of hard registers in modes that span more than one hard reg. This
caused an incorrect register selection during renaming.

I verified removing the printf call from the test would not compromise the
test.  Then I did a normal x86 bootstrap & regression test with the patch.
Of course that's essentially useless, so I also did another bootstrap and
regression test with -fselective-scheduling in BOOT_CFLAGS with and without
this patch.  In both cases there were no regressions.

I'm installing Andrey's patch on the trunk.  I'm not sure this is worth
addressing in gcc-5.


I've looked at the patch again and as it fixes general code and has a 
regression marker I've included it in the bunch of other PRs that were 
backported to gcc-5.  I forgot you were hesitant putting it to gcc-5 though 
:) So I can revert it from the branch if you want me to.


Andrey



Jeff




[PATCH, i386, AVX-512] Fix for PR target/70453.

2016-03-31 Thread Kirill Yukhin
Hello,
Patch in the bottom fixes typo causing PR target/70453.

Boostrapped and regtested on i?86/x86_64.

I'll check it into main trunk and gcc-5-branch.

gcc/
PR target/70453
* config/i386/sse.md (define_mode_attr shuffletype): Fix typo.

gcc/testsuite/
PR target/70453
* gcc.target/i386/pr70453.c: New test.

--
Thanks, K

commit 06a60a6aa22b24962b315de1f07cc75b074e47d2
Author: Kirill Yukhin 
Date:   Wed Mar 30 17:43:12 2016 +0300

AVX-512. Fix typo in  mode attribute.

diff --git a/gcc/config/i386/sse.md b/gcc/config/i386/sse.md
index 44141ea..5fd650f 100644
--- a/gcc/config/i386/sse.md
+++ b/gcc/config/i386/sse.md
@@ -493,7 +493,7 @@
   [(V16SF "f") (V16SI "i") (V8DF "f") (V8DI "i")
   (V8SF "f") (V8SI "i") (V4DF "f") (V4DI "i")
   (V4SF "f") (V4SI "i") (V2DF "f") (V2DI "i")
-  (V32QI "i") (V16HI "u") (V16QI "i") (V8HI "i")
+  (V32QI "i") (V16HI "i") (V16QI "i") (V8HI "i")
   (V64QI "i") (V1TI "i") (V2TI "i")])
 
 (define_mode_attr ssequartermode
diff --git a/gcc/testsuite/gcc.target/i386/pr70453.c 
b/gcc/testsuite/gcc.target/i386/pr70453.c
new file mode 100755
index 000..2ff1fbb
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr70453.c
@@ -0,0 +1,18 @@
+/* PR target/70453 */
+/* { dg-do assemble { target { lp64 } } } */
+/* { dg-require-effective-target avx512vbmi } */
+/* { dg-options "-Og -fschedule-insns -mavx512vbmi" } */
+
+
+typedef char v64u8 __attribute__ ((vector_size (64)));
+typedef short v64u16 __attribute__ ((vector_size (64)));
+typedef __int128 v64u128 __attribute__ ((vector_size (64)));
+
+int
+foo(v64u8 v64u8_0, v64u16 v64u16_0, v64u128 v64u128_0)
+{
+  v64u128_0 /= (v64u128){ v64u8_0[28] }  | 0x1424171b0c;
+  v64u8_0 %= (v64u8){ v64u16_0[25], v64u128_0[1]}  ;
+  v64u128_0 %= (v64u128){ v64u16_0[8] };
+  return v64u8_0[0] + v64u8_0[1] + v64u16_0[0] + v64u128_0[0];
+}


Fix for PR70481 Libiberty Demangler

2016-03-31 Thread Marcel Böhme
Hi,

This fixes the use-after-free detailed in 
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70481

There is a variable ksize storing the amount of allocated memory for the array 
ktypevec. ksize being zero (0) indicates that some memory must be allocated 
upon the first write. When more memory is needed, both ksize and the memory are 
doubled during reallocation. At some point the memory for the array is freed 
(in squangle_mop_up) but the value of ksize remains. Since ksize is not 0, 
there is no indication that new memory must be allocated when there is another 
write to the array.

The same holds for bsize and btypevec.

Best regards,
- Marcel


Index: libiberty/cplus-dem.c
===
--- libiberty/cplus-dem.c   (revision 234607)
+++ libiberty/cplus-dem.c   (working copy)
@@ -1237,11 +1237,13 @@  squangle_mop_up (struct work_stuff *work)
 {
   free ((char *) work -> btypevec);
   work->btypevec = NULL;
+  work->bsize = 0;
 }
   if (work -> ktypevec != NULL)
 {
   free ((char *) work -> ktypevec);
   work->ktypevec = NULL;
+  work->ksize = 0;
 }
 }



Re: Various selective scheduling fixes

2016-03-31 Thread Andrey Belevantsev

Hello,

On 14.03.2016 12:10, Andrey Belevantsev wrote:

Hello,

In this thread I will be posting the patches for the fixed selective
scheduling PRs (except the one that was already kindly checked in by Jeff).
 The patches were tested both on x86-64 and ia64 with the following
combination: 1) the usual bootstrap/regtest, which only utilizes sel-sched
on its own tests, made by default to run on arm/ppc/x86-64/ia64; 2) the
bootstrap/regtest with the second scheduler forced to sel-sched; 3) both
schedulers forced to sel-sched.  In all cases everything seemed to be fine.

Three of the PRs are regressions, the other two showed different errors
across the variety of releases tested by submitters;  I think all of them
are appropriate at this stage -- they do not touch anything outside of
selective scheduling except the first patch where a piece of code from
sched-deps.c needs to be refactored into a function to be called from
sel-sched.c.


I've backported all regression PRs to gcc-5-branch after testing there 
again with selective scheduling force enabled: PRs 64411, 0, 69032, 
69102.  The first one was not marked as a regression as such but the test 
for PR 70292, which is duplicate, works for me on gcc 5.1 thus making it a 
regression, too.


Andrey



Andrey




[committed] Add patch for PR 70292

2016-03-31 Thread Andrey Belevantsev

Hello,

PR 70292 turned out to be the duplicate of PR 64411, which is already fixed 
on trunk, but still the testcase from the PR is worth adding.  It can be 
tortured instead of being a target test, and also this PR showed that 64411 
is a regression and should be backported to gcc-5-branch.


Committed the test to trunk.  I don't think we need it for gcc-5 though.

Andrey
Index: gcc/testsuite/gcc.dg/pr70292.c
===
*** gcc/testsuite/gcc.dg/pr70292.c	(revision 0)
--- gcc/testsuite/gcc.dg/pr70292.c	(revision 234627)
***
*** 0 
--- 1,12 
+ /* { dg-do compile { target powerpc*-*-* ia64-*-* i?86-*-* x86_64-*-* } } */
+ /* { dg-options "-O1 -fno-inline -fno-dce -fschedule-insns -fselective-scheduling -fno-tree-dce" } */
+ 
+ void bar() {}
+ 
+ int t106_1mul(unsigned int x, unsigned int y) {
+ int r;
+ if (__builtin_mul_overflow(x, y, )) {
+ bar();
+ }
+ return r;
+ }
Index: gcc/testsuite/ChangeLog
===
*** gcc/testsuite/ChangeLog	(revision 234626)
--- gcc/testsuite/ChangeLog	(revision 234627)
***
*** 1,3 
--- 1,8 
+ 2016-03-31  Andrey Belevantsev  
+ 
+ 	PR target/70292
+ 	* gcc.c-torture/pr70292.c: New test.
+ 
  2016-03-31  Marek Polacek  
  
  	PR c/70297


Re: [PATCH 1/2] HSA: support alignment for hsa_symbols (PR hsa/70391)

2016-03-31 Thread Martin Jambor
Hi,

this is OK with one small adjustments in a comment:

On Tue, Mar 22, 2016 at 03:51:53PM +0100, Martin Liska wrote:
> gcc/ChangeLog:
> 
> 2016-03-23  Martin Liska  
> 
>   PR hsa/70391
>   * hsa-brig.c (emit_directive_variable): Emit alignment
>   according to hsa_symbol::m_align.
>   * hsa-dump.c (hsa_byte_alignment): Move the function to
>   another file.
>   (dump_hsa_symbol): Dump alignment of HSA symbols.
>   * hsa-gen.c (get_symbol_for_decl): Set-up alignment
>   of a symbol.
>   (gen_hsa_addr_with_align): New function.
>   (hsa_bitmemref_alignment): Use newly added function.
>   (gen_hsa_insns_for_load): Likewise.
>   (gen_hsa_insns_for_store): Likewise.
>   (gen_hsa_memory_copy): New argument added.
>   (gen_hsa_insns_for_single_assignment): Respect
>   alignment for assignments processed via
>   gen_hsa_memory_copy.
>   (gen_hsa_insns_for_direct_call): Likewise.
>   (gen_hsa_insns_for_return): Likewise.
>   (gen_function_def_parameters): Set default
>   alignment.
>   * hsa.c (hsa_object_alignment): New function.
>   (hsa_byte_alignment): Pasted function.
>   * hsa.h (hsa_symbol::m_align): New field.
> ---
>  gcc/hsa-brig.c |  5 +---
>  gcc/hsa-dump.c | 13 ++---
>  gcc/hsa-gen.c  | 88 
> +-
>  gcc/hsa.c  | 20 +
>  gcc/hsa.h  |  8 +-
>  5 files changed, 99 insertions(+), 35 deletions(-)
> 
> diff --git a/gcc/hsa-gen.c b/gcc/hsa-gen.c
> index 72eecf9..db39813 100644
> --- a/gcc/hsa-gen.c
> +++ b/gcc/hsa-gen.c
> @@ -169,12 +169,12 @@ hsa_symbol::hsa_symbol ()
>  
>  hsa_symbol::hsa_symbol (BrigType16_t type, BrigSegment8_t segment,
>   BrigLinkage8_t linkage, bool global_scope_p,
> - BrigAllocation allocation)
> + BrigAllocation allocation, BrigAlignment8_t align)
>: m_decl (NULL_TREE), m_name (NULL), m_name_number (0),
>  m_directive_offset (0), m_type (type), m_segment (segment),
>  m_linkage (linkage), m_dim (0), m_cst_value (NULL),
>  m_global_scope_p (global_scope_p), m_seen_error (false),
> -m_allocation (allocation), m_emitted_to_brig (false)
> +m_allocation (allocation), m_emitted_to_brig (false), m_align (align)
>  {
>  }
>  
> @@ -908,21 +908,29 @@ get_symbol_for_decl (tree decl)
>  {
>hsa_symbol *sym;
>gcc_assert (TREE_CODE (decl) == VAR_DECL);
> +  BrigAlignment8_t align = hsa_object_alignment (decl);
>  
>if (is_in_global_vars)
>   {
> sym = new hsa_symbol (BRIG_TYPE_NONE, BRIG_SEGMENT_GLOBAL,
>   BRIG_LINKAGE_PROGRAM, true,
> - BRIG_ALLOCATION_PROGRAM);
> + BRIG_ALLOCATION_PROGRAM, align);
> hsa_cfun->m_global_symbols.safe_push (sym);
>   }
>else
>   {
> +   /* As generation of memory copy instructions relies on alignment
> +  greater or equal to 8 bytes, we need to increase alignment
> +  of all aggregate types.. */

Let's say "efficient memory copy instructions."  It is of curse
possible to use slower ones.

Thanks,

Martin



Re: Patches to fix optimizer bug & C++ exceptions for GCC VAX backend

2016-03-31 Thread Jan-Benedict Glaw
Hi Jake!

On Mon, 2016-03-28 16:34:56 -0700, Jake Hamby  wrote:
> Amazingly enough, my patch worked well enough that my NetBSD VAX
> kernel built with GCC 5.3 is no longer crashing. I feel pretty good
> about what I have so far so here's the complete diff for both the
> C++ exception fix and the bad condition codes optimizer bug. It
> should be good enough to check into NetBSD current, at least, and I
> believe it does fix most, if not all, of the bad code generation
> bugs with optimization on VAX.

I'd like to suggest to also Cc Matt Thomas , at
least once the patch is tested with GCC trunk/HEAD/master, instead of
5.3.  There isn't probably much of a difference, but you've done
substancial and important work here, so let's see it's applicable to
upstream GCC.

  And keep in mind that a ChangeLog entry is also needed.

MfG, JBG

-- 
  Jan-Benedict Glaw  jbg...@lug-owl.de  +49-172-7608481
Signature of:   Ich hatte in letzter Zeit ein bißchen viel Realitycheck.
the second  :   Langsam möchte ich mal wieder weiterträumen können.
 -- Maximilian Wilhelm (18. Mai 2005, #lug-owl.de)


signature.asc
Description: Digital signature


Re: C++ PATCH for c++/70449 (ICE when printing a filename of unknown location)

2016-03-31 Thread Marek Polacek
On Wed, Mar 30, 2016 at 11:51:26PM +0100, Manuel López-Ibáñez wrote:
> On 30 March 2016 at 23:42, Manuel López-Ibáñez  wrote:
> > On 30/03/16 17:14, Marek Polacek wrote:
> >>
> >> This test ICEs since the addition of the assert in pp_string which ensures
> >> that
> >> we aren't trying to print an empty string.  But that's what happens here,
> >> the
> >> location is actually UNKNOWN_LOCATION, so LOCATION_FILE on that yields
> >> null.
> >> Fixed byt not trying to print the filename of UNKNOWN_LOCATION.
> 
> > Even if we accept the broken location for now (adding some FIXME to the code
> > would help the next person to realise this is not normal), if
> > LOCATION_FILE() is NULL, we should print "progname" like
> > diagnostic_build_prefix() does. Moreover, the filename string should be
> > built with file_name_as_prefix() to get correct coloring.
> 
> Even better: Use "f ? f : progname" in file_name_as_prefix() and
> simplify the code to:

It seems wrong to me to just add that.  I wonder if the function shouldn't
use diagnostic_get_location_text instead which also handles "" etc.
In any case I'd rather not touch the diagnostic stuff in the scope of this
patch (which wouldn't probably be suitable for stage4 anyway).
 
>   /* FIXME: Somehow we may get UNKNOWN_LOCATION here: See
> g++.dg/cpp0x/constexpr-70449.C */
>   const char * prefix = file_name_as_prefix (context,
> LOCATION_FILE (location));
> pp_verbatim (context->printer,
>  TREE_CODE (p->decl) == TREE_LIST
>  ? _("%s: In substitution of %qS:\n")
>  : _("%s: In instantiation of %q#D:\n"),
>  prefix, p->decl);
>   free (prefix);
> 
> Fixes the ICE, adds colors, mentions the broken location and does not
> add extra strings.

It fixes the ICE, but I don't see any more colors than with my patch.
Moreover your suggestion would print
cc1plus: : In instantiation of ‘constexpr int f() [with int I = 0]’:
, not sure how's that better than simply saying
In instantiation of ‘constexpr int f() [with int I = 0]’:
I.e. adding "cc1plus" to the output doesn't seem like an improvement.

Anyway, here's a patch which uses file_name_as_prefix.

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

2016-03-31  Marek Polacek  

PR c++/70449
* error.c (print_instantiation_full_context): Build prefix by using
file_name_as_prefix.

* g++.dg/cpp0x/constexpr-70449.C: New test.

diff --git gcc/cp/error.c gcc/cp/error.c
index aa5fd41..14b0205 100644
--- gcc/cp/error.c
+++ gcc/cp/error.c
@@ -3312,12 +3312,15 @@ print_instantiation_full_context (diagnostic_context 
*context)
 
   if (p)
 {
+  char *prefix = file_name_as_prefix (context, LOCATION_FILE (location)
+  ? LOCATION_FILE (location)
+  : progname);
   pp_verbatim (context->printer,
   TREE_CODE (p->decl) == TREE_LIST
-  ? _("%s: In substitution of %qS:\n")
-  : _("%s: In instantiation of %q#D:\n"),
-  LOCATION_FILE (location),
-  p->decl);
+  ? _("%sIn substitution of %qS:\n")
+  : _("%sIn instantiation of %q#D:\n"),
+  prefix, p->decl);
+  free (prefix);
 
   location = p->locus;
   p = p->next;
diff --git gcc/testsuite/g++.dg/cpp0x/constexpr-70449.C 
gcc/testsuite/g++.dg/cpp0x/constexpr-70449.C
index e69de29..bc5dd71 100644
--- gcc/testsuite/g++.dg/cpp0x/constexpr-70449.C
+++ gcc/testsuite/g++.dg/cpp0x/constexpr-70449.C
@@ -0,0 +1,12 @@
+// PR c++/70449
+// { dg-do compile { target c++11 } }
+
+template 
+constexpr
+int f (void)
+{
+  enum E { a = f<0> () };
+  return 0;
+}
+
+// { dg-error "body of constexpr function" "" { target { ! c++14 } } 0 }

Marek


[Patch AArch64] Fix PR target/63874

2016-03-31 Thread Ramana Radhakrishnan
Hi,

In this PR we have a situation where we aren't really detecting
weak references vs weak definitions. If one has a weak definition
that binds locally there's no reason not to put out PC relative
relocations.

However if you have a genuine weak reference that is
known not to bind locally it makes very little sense
to put out an entry into the literal pool which doesn't always
work with DSOs and shared objects.

Tested aarch64-none-linux-gnu bootstrap and regression test with no regressions

This is not a regression and given what we've seen recently with protected
symbols and binds_locally_p I'd rather this were queued for GCC 7. 

Ok ?

regards
Ramana

gcc/

* config/aarch64/aarch64.c (aarch64_classify_symbol): Typo in comment fixed.
  Only force to memory if it is a weak external reference.


gcc/testsuite

* gcc.target/aarch64/pr63874.c: New test.
commit e41d4bd6abbee99628909d4af612504844dee640
Author: Ramana Radhakrishnan 
Date:   Thu Mar 31 13:47:33 2016 +0100

fix PR63874

diff --git a/gcc/config/aarch64/aarch64.c b/gcc/config/aarch64/aarch64.c
index cf1239d..6782316 100644
--- a/gcc/config/aarch64/aarch64.c
+++ b/gcc/config/aarch64/aarch64.c
@@ -9387,15 +9387,18 @@ aarch64_classify_symbol (rtx x, rtx offset)
   switch (aarch64_cmodel)
{
case AARCH64_CMODEL_TINY:
- /* When we retreive symbol + offset address, we have to make sure
+ /* When we retrieve symbol + offset address, we have to make sure
 the offset does not cause overflow of the final address.  But
 we have no way of knowing the address of symbol at compile time
 so we can't accurately say if the distance between the PC and
 symbol + offset is outside the addressible range of +/-1M in the
 TINY code model.  So we rely on images not being greater than
 1M and cap the offset at 1M and anything beyond 1M will have to
-be loaded using an alternative mechanism.  */
- if (SYMBOL_REF_WEAK (x)
+be loaded using an alternative mechanism.  Furthermore if the
+symbol is a weak reference to something that isn't known to
+resolve to a symbol in this module, then force to memory.  */
+ if ((SYMBOL_REF_WEAK (x)
+  && !aarch64_symbol_binds_local_p (x))
  || INTVAL (offset) < -1048575 || INTVAL (offset) > 1048575)
return SYMBOL_FORCE_TO_MEM;
  return SYMBOL_TINY_ABSOLUTE;
@@ -9403,7 +9406,8 @@ aarch64_classify_symbol (rtx x, rtx offset)
case AARCH64_CMODEL_SMALL:
  /* Same reasoning as the tiny code model, but the offset cap here is
 4G.  */
- if (SYMBOL_REF_WEAK (x)
+ if ((SYMBOL_REF_WEAK (x)
+  && !aarch64_symbol_binds_local_p (x))
  || !IN_RANGE (INTVAL (offset), HOST_WIDE_INT_C (-4294967263),
HOST_WIDE_INT_C (4294967264)))
return SYMBOL_FORCE_TO_MEM;
diff --git a/gcc/testsuite/gcc.target/aarch64/pr63874.c 
b/gcc/testsuite/gcc.target/aarch64/pr63874.c
new file mode 100644
index 000..1a745a0
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/pr63874.c
@@ -0,0 +1,22 @@
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+/* { dg-skip-if "Not applicable for mcmodel=large" { aarch64*-*-* }  { 
"-mcmodel=large" } { "" } } */
+
+extern void __attribute__((weak)) foo_weakref (void);
+void __attribute__((weak, noinline)) bar (void)
+{
+ return;
+}
+void (*f) (void);
+void (*g) (void);
+
+int
+main (void)
+{
+ f = _weakref;
+ g = 
+ return 0;
+}
+
+/* { dg-final { scan-assembler-not "adr*foo_weakref" } } */
+/* { dg-final { scan-assembler-not "\\.(word|xword)\tbar" } } */


not a type buglet in c/c-array-notation

2016-03-31 Thread Andrew MacLeod
Another potential buglet  I stumbled across whilst testing the tree-type 
work:

in c/c-array-notation.c::fix_builtin_array_notation_fn()
<...>
  if (list_size > 1)
{
  new_yes_ind = build_modify_expr
(location, *new_var, TREE_TYPE (*new_var), NOP_EXPR,
 location, an_loop_info[0].var, TREE_TYPE 
(an_loop_info[0].var));

  new_yes_expr = build_modify_expr
(location, array_ind_value, TREE_TYPE (array_ind_value),
 NOP_EXPR,
 location, func_parm, TREE_TYPE ((*array_operand)[0]));
}
  else
{
  new_yes_ind = build_modify_expr
(location, *new_var, TREE_TYPE (*new_var), NOP_EXPR,
 location, TREE_OPERAND (array_op0, 1),
 TREE_TYPE (TREE_OPERAND (array_op0, 1)));
  new_yes_expr = build_modify_expr
(location, array_ind_value, TREE_TYPE (array_ind_value),
 NOP_EXPR,
 location, func_parm, TREE_OPERAND (array_op0, 1));   
<<<

}

'build_modify_expr' expects a type in that final parameter position. It 
triggered as showing a non-type being passed into a type parameter.


I think the last operand on the last line ought to be wrapped in 
TREE_TYPE() just like it is in the first expression of the else.. Either 
that, or someone who understands the code needs to figure out whats 
really wanted there.   There is a second occurrence later in the same 
routine.   Patch number 1 makes this change and bootstraps/passes 
regression.


If someone that understands the code wants to have a look, The test can 
be triggered in the cilk testsuite by adding an assert to 
build_modify_expr  (thats patch number 2 for convenience)  and running 
testcase :

make RUNTESTFLAGS=cilk-plus.exp=sec_reduce_ind_same_value.c check-gcc

 I still have a couple from last fall that were discussed..I'm queuing 
these up for once stage 1 opens and we can discuss them again.


Andrew
c/
	* c-array-notation.c (fix_builtin_array_notation_fn): Add missing
	TREE_TYPE()s.

Index: c/c-array-notation.c
===
*** c/c-array-notation.c	(revision 234427)
--- c/c-array-notation.c	(working copy)
*** fix_builtin_array_notation_fn (tree an_b
*** 489,495 
  	  new_yes_expr = build_modify_expr
  	(location, array_ind_value, TREE_TYPE (array_ind_value),
  	 NOP_EXPR,
! 	 location, func_parm, TREE_OPERAND (array_op0, 1));
  	}
new_yes_list = alloc_stmt_list ();
append_to_statement_list (new_yes_ind, _yes_list);
--- 489,495 
  	  new_yes_expr = build_modify_expr
  	(location, array_ind_value, TREE_TYPE (array_ind_value),
  	 NOP_EXPR,
! 	 location, func_parm, TREE_TYPE (TREE_OPERAND (array_op0, 1)));
  	}
new_yes_list = alloc_stmt_list ();
append_to_statement_list (new_yes_ind, _yes_list);
*** fix_builtin_array_notation_fn (tree an_b
*** 539,545 
  	  new_yes_expr = build_modify_expr
  	(location, array_ind_value, TREE_TYPE (array_ind_value),
  	 NOP_EXPR,
! 	 location, func_parm, TREE_OPERAND (array_op0, 1));
  	}
new_yes_list = alloc_stmt_list ();
append_to_statement_list (new_yes_ind, _yes_list);
--- 539,545 
  	  new_yes_expr = build_modify_expr
  	(location, array_ind_value, TREE_TYPE (array_ind_value),
  	 NOP_EXPR,
! 	 location, func_parm, TREE_TYPE (TREE_OPERAND (array_op0, 1)));
  	}
new_yes_list = alloc_stmt_list ();
append_to_statement_list (new_yes_ind, _yes_list);
Index: c/c-typeck.c
===
*** c/c-typeck.c(revision 234568)
--- c/c-typeck.c(working copy)
*** build_modify_expr (location_t location,
*** 5542,5547 
--- 5542,5550 
if (TREE_CODE (lhs) == ERROR_MARK || TREE_CODE (rhs) == ERROR_MARK)
  return error_mark_node;
  
+   gcc_assert (!rhs_origtype || TREE_CODE (rhs_origtype) == ERROR_MARK
+ || TYPE_P (rhs_origtype));
+ 
/* Ensure an error for assigning a non-lvalue array to an array in
   C90.  */
if (TREE_CODE (lhstype) == ARRAY_TYPE)


Re: [PATCH][ARM] Add deprecation warning on pre-v4t architecture revisions

2016-03-31 Thread Kyrill Tkachov

Ping.

Thanks,
Kyrill

On 23/03/16 10:11, Kyrill Tkachov wrote:

Ping.

Thanks,
Kyrill

On 07/03/16 15:40, Kyrill Tkachov wrote:

Ping.
https://gcc.gnu.org/ml/gcc-patches/2016-03/msg00046.html

Thanks,
Kyrill

On 01/03/16 16:17, Kyrill Tkachov wrote:

Hi all,

For GCC 6 we want to deprecate architecture revisions prior to ARMv4T.
This patch implements this by documenting the deprecation in invoke.texi and 
adding
a warning whenever the user specifies an -march or -mcpu option that selects 
such
an architecture revision.

Bootstrapped and tested on arm.

Ok for trunk?

Thanks,
Kyrill

P.S. I'll add a note to changes.html to that effect separately.

2016-03-01  Kyrylo Tkachov  

* config/arm/arm.c (arm_option_override): Warn on pre-ARMv4T
architecture revisions.
* doc/invoke.texi (ARM Options): Add note on deprecation of pre-ARMv4T
architecture revisions.

2016-03-01  Kyrylo Tkachov  

* gcc.target/arm/ftest-armv4-arm.c: Add dg-warning for deprecation
warning.
* gcc.target/arm/pr62554.c: Likewise.
* gcc.target/arm/pr69610-1.c: Likewise.
* gcc.target/arm/pr69610-2.c: Likewise.








Re: [PATCH GCC]Reduce compilation time for IVOPT by skipping cost computation in use group

2016-03-31 Thread H.J. Lu
On Wed, Mar 30, 2016 at 5:11 AM, Bin.Cheng  wrote:
> On Wed, Mar 30, 2016 at 9:09 AM, Richard Biener
>  wrote:
>> On Thu, Mar 24, 2016 at 6:26 PM, Bin Cheng  wrote:
>>> Hi,
>>> Quite lot of time is used when IVOPT computes cost for  pairs.  
>>> As a matter of fact, some pairs are very similar to each other, and we can 
>>> abstract and compute cost only once for these pairs.  This is a patch doing 
>>> so, the idea is skipping cost computation for sub-uses in each group, of 
>>> course it may result in different assembly code for some complicated cases 
>>> because it estimates cost rather than doing real computation.  I did double 
>>> check one of such case that the change in generated assembly is not 
>>> degeneration.  For an IVOPT heavy program (spec2k/173), this patch reduces 
>>> IVOPT's compilation time by 7~8%, as well as the memory consumption on my 
>>> developing machine.
>>>
>>> Bootstrap & test on x86_64.
>>>
>>> For spec2k6 data on x86_64.  Maybe because I ran spec2k6 compiled with 
>>> patched GCC in unclean environment, some cases are regressed by small 
>>> amount (< %1).  I manually compared assembly code for several cases, 
>>> including ones with the largest regression (still within <1%).  I could 
>>> confirm that generated assembly code is exact the same as unpatched GCC, 
>>> except for function emit_library_call_value_1 in 403.gcc/calls.c.
>>>
>>> In this case, difference of IVOPT dumps is as below:
>>>
>>> $ diff -y trunk/calls.c.154t.ivopts patch/calls.c.154t.ivopts
>>>
>>>   ::
>>>   # val_21 = PHI   # val_21 
>>> = PHI 
>>>   _811 = (void *) ivtmp.322_829;  _811 = 
>>> (void *) ivtmp.322_829;
>>>   MEM[base: _811, offset: -48B] = val_21; |   MEM[base: 
>>> _811, offset: -32B] = val_21;
>>>   _810 = (void *) ivtmp.322_829;  _810 = 
>>> (void *) ivtmp.322_829;
>>>   MEM[base: _810, offset: -40B] = mode_163;   |   MEM[base: 
>>> _810, offset: -24B] = mode_163;
>>>   _182 = function_arg (_so_far, mode_163, 0B, 1);_182 = 
>>> function_arg (_so_far, mode_163, 0B, 1);
>>>   _809 = (void *) ivtmp.322_829;  _809 = 
>>> (void *) ivtmp.322_829;
>>>   MEM[base: _809, offset: -32B] = _182;   |   MEM[base: 
>>> _809, offset: -16B] = _182;
>>>   _807 = (void *) ivtmp.322_829;  _807 = 
>>> (void *) ivtmp.322_829;
>>>   MEM[base: _807, offset: -24B] = 0;  |   MEM[base: 
>>> _807, offset: -8B] = 0;
>>>   _185 = (struct args_size *) ivtmp.322_829;  |   _801 = 
>>> ivtmp.322_829 + 16;
>>>   _801 = ivtmp.322_829 + 18446744073709551600;<
>>>   _800 = (struct args_size *) _801;   _800 = 
>>> (struct args_size *) _801;
>>>   _186 = _800;|   _185 = 
>>> _800;
>>>   >   _186 = 
>>> (struct args_size *) ivtmp.322_829;
>>>   _187 = _182 != 0B;  _187 = 
>>> _182 != 0B;
>>>   _188 = (int) _187;  _188 = 
>>> (int) _187;
>>>   locate_and_pad_parm (mode_163, 0B, _188, 0B, _size, _1 
>>> locate_and_pad_parm (mode_163, 0B, _188, 0B, _size, _1
>>>   _802 = (void *) ivtmp.322_829;  _802 = 
>>> (void *) ivtmp.322_829;
>>>   _190 = MEM[base: _802, offset: 8B]; |   _190 = 
>>> MEM[base: _802, offset: 24B];
>>>   if (_190 != 0B) if (_190 
>>> != 0B)
>>> goto ;   goto 
>>> ;
>>>   elseelse
>>> goto ;   goto 
>>> ;
>>>
>>>   ::
>>>   fancy_abort ("calls.c", 3724, &__FUNCTION__);   
>>> fancy_abort ("calls.c", 3724, &__FUNCTION__);
>>>
>>> It's only an offset difference in IV.  And below is difference of generated 
>>> assembly:
>>> $ diff -y trunk/calls.S patch/calls.S
>>> .L489:  .L489:
>>> leaq-80(%rbp), %rdi 
>>> leaq-80(%rbp), %rdi
>>> xorl%edx, %edx  
>>> xorl%edx, %edx
>>> movl$1, %ecx
>>> movl$1, %ecx
>>> movl%r13d, %esi 
>>> movl%r13d, %esi
>>> movq%rax, -48(%r15)   <

Re: [PATCH] nvptx backend: fix and streamline symbol renaming

2016-03-31 Thread Nathan Sidwell

On 03/31/16 07:18, Alexander Monakov wrote:

This fixes a bug in the NVPTX backend where taking the address of a function
renamed by the backend (e.g. 'call' or 'malloc') would wrongly use the
original name. Now all decl renaming is handled up front via
TARGET_MANGLE_DECL_ASSEMBLER_NAME hook, which becomes the only caller of
nvptx_name_replacement.

En passant, it also fixes one instance where handling of star prefix on
user-supplied DECL_ASSEMBLER_NAME was missing.

gcc/
* config/nvptx/nvptx.c (nvptx_name_replacement): Return NULL if no
replacement needed.
(nvptx_mangle_decl_assembler_name): New.
(write_fn_proto): Do not call nvptx_name_replacement.
(write_fn_proto_from_insn): Ditto.
(nvptx_output_call_insn): Ditto.
(TARGET_MANGLE_DECL_ASSEMBLER_NAME): Define.

gcc/testsuite/
* gcc.target/nvptx/rename-call.c: New test.
* gcc.target/nvptx/rename-call-2.c: New test.
* gcc.target/nvptx/asm-name.c: New test.


ok

nathan



Re: [PATCH, PR target/70442] STV: suppport undefined registers for reg copies

2016-03-31 Thread Uros Bizjak
On Thu, Mar 31, 2016 at 1:31 PM, Jakub Jelinek  wrote:
> On Thu, Mar 31, 2016 at 02:25:41PM +0300, Ilya Enkovich wrote:
>> This patch adds support for undefined register copies.
>> This is simply done by calling scalar_chain::convert_op
>> for copied registers.  Bootstrapped and regtested on
>> x86_64-unknown-linux-gnu{-m32}.  OK for trunk?
>>
>> Thanks,
>> Ilya
>> --
>> gcc/
>>
>> 2016-03-31  Ilya Enkovich  
>>
>
> Missing
> PR target/70442
> here.
>
>> 2016-03-31  Ilya Enkovich  
>>
> And here too.
>
>>   * gcc.target/i386/pr70442.c: New test.
>
>> @@ -3467,6 +3468,8 @@ scalar_chain::convert_insn (rtx_insn *insn)
>>break;
>>
>>  case REG:
>> +  if (!MEM_P(dst))
>
> Missing space before (.
>
>> --- /dev/null
>> +++ b/gcc/testsuite/gcc.target/i386/pr70442.c
>> @@ -0,0 +1,18 @@
>
> I'd add
> /* PR target/70442 */
> here.
>
>> +/* { dg-do compile { target { ia32 } } } */
>> +/* { dg-options "-O2 -msse2" } */
>
> There is really nothing ia32 specific on the test, so I'd move it
> to gcc.dg/pr70442.c instead, and just
> /* { dg-do compile } */
> /* { dg-options "-O2" } */
> /* { dg-additional-options "-msse2" { target ia32 } } */
> or so.
>
> For the i386.c change I'll defer to Uros as the maintainer.

It is OK with the above proposed improvements.

Thanks,
Uros.


Re: [PATCH] Fix ira.c indirect_jump_optimize (PR rtl-optimization/70460)

2016-03-31 Thread Bernd Schmidt

On 03/30/2016 11:27 PM, Jakub Jelinek wrote:

Hi!

As mentioned in the PR, we are miscompiling glibc on i686-linux, because
the new indirect_jump_optimize mini-pass thinks that a insn
which has REG_LABEL_OPERAND note necessarily has to set the target register
to that label, while in the glibc case it is actually that label + some
offset, where the offset is read from a table which contains other labels -
this label differences.

The following patch changes it to just look at SET_SRC of single_set and/or
REG_EQUAL note, and only consider those if one of them is a LABEL_REF.
That alone broke lots of tests, which contain non-local gotos, so I had
to add a check that we don't do anything in this mini-pass (like old ira.c
code did) if there is REG_NON_LOCAL_GOTO note.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk/5/4.9?
Bernd has preapproved the patch, but that was before the REG_NON_LOCAL_GOTO
changes.


Still ok.


Bernd




Re: [PATCH, PR target/70442] STV: suppport undefined registers for reg copies

2016-03-31 Thread Jakub Jelinek
On Thu, Mar 31, 2016 at 02:25:41PM +0300, Ilya Enkovich wrote:
> This patch adds support for undefined register copies.
> This is simply done by calling scalar_chain::convert_op
> for copied registers.  Bootstrapped and regtested on
> x86_64-unknown-linux-gnu{-m32}.  OK for trunk?
> 
> Thanks,
> Ilya
> --
> gcc/
> 
> 2016-03-31  Ilya Enkovich  
> 

Missing
PR target/70442
here.

> 2016-03-31  Ilya Enkovich  
> 
And here too.

>   * gcc.target/i386/pr70442.c: New test.

> @@ -3467,6 +3468,8 @@ scalar_chain::convert_insn (rtx_insn *insn)
>break;
>  
>  case REG:
> +  if (!MEM_P(dst))

Missing space before (.

> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/i386/pr70442.c
> @@ -0,0 +1,18 @@

I'd add
/* PR target/70442 */
here.

> +/* { dg-do compile { target { ia32 } } } */
> +/* { dg-options "-O2 -msse2" } */

There is really nothing ia32 specific on the test, so I'd move it
to gcc.dg/pr70442.c instead, and just
/* { dg-do compile } */
/* { dg-options "-O2" } */
/* { dg-additional-options "-msse2" { target ia32 } } */
or so.

For the i386.c change I'll defer to Uros as the maintainer.

Jakub


[PATCH, PR target/70442] STV: suppport undefined registers for reg copies

2016-03-31 Thread Ilya Enkovich
Hi,

This patch adds support for undefined register copies.
This is simply done by calling scalar_chain::convert_op
for copied registers.  Bootstrapped and regtested on
x86_64-unknown-linux-gnu{-m32}.  OK for trunk?

Thanks,
Ilya
--
gcc/

2016-03-31  Ilya Enkovich  

* config/i386/i386.c (scalar_chain::convert_op): Fix
description.
(scalar_chain::convert_insn): Call convert_op for reg
moves to handle undefined registers.

gcc/testsuite/

2016-03-31  Ilya Enkovich  

* gcc.target/i386/pr70442.c: New test.


diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
index 1639704..ca07880 100644
--- a/gcc/config/i386/i386.c
+++ b/gcc/config/i386/i386.c
@@ -3384,9 +3384,10 @@ scalar_chain::convert_reg (unsigned regno)
   BITMAP_FREE (conv);
 }
 
-/* Convert operand OP in INSN.  All register uses
-   are converted during registers conversion.
-   Therefore we should just handle memory operands.  */
+/* Convert operand OP in INSN.  We should handle
+   memory operands and uninitialized registers.
+   All other register uses are converted during
+   registers conversion.  */
 
 void
 scalar_chain::convert_op (rtx *op, rtx_insn *insn)
@@ -3467,6 +3468,8 @@ scalar_chain::convert_insn (rtx_insn *insn)
   break;
 
 case REG:
+  if (!MEM_P(dst))
+   convert_op (, insn);
   break;
 
 case SUBREG:
diff --git a/gcc/testsuite/gcc.target/i386/pr70442.c 
b/gcc/testsuite/gcc.target/i386/pr70442.c
new file mode 100644
index 000..f5c6caf
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr70442.c
@@ -0,0 +1,18 @@
+/* { dg-do compile { target { ia32 } } } */
+/* { dg-options "-O2 -msse2" } */
+
+char a, c;
+void
+fn1 ()
+{
+  long long b;
+  long m;
+  int d;
+  switch (d)
+{
+case 5:
+  b = a;
+}
+  b ^= m;
+  c = b >> b;
+}


[PATCH] nvptx backend: fix and streamline symbol renaming

2016-03-31 Thread Alexander Monakov
This fixes a bug in the NVPTX backend where taking the address of a function
renamed by the backend (e.g. 'call' or 'malloc') would wrongly use the
original name. Now all decl renaming is handled up front via
TARGET_MANGLE_DECL_ASSEMBLER_NAME hook, which becomes the only caller of
nvptx_name_replacement.

En passant, it also fixes one instance where handling of star prefix on
user-supplied DECL_ASSEMBLER_NAME was missing.

gcc/
* config/nvptx/nvptx.c (nvptx_name_replacement): Return NULL if no
replacement needed.
(nvptx_mangle_decl_assembler_name): New.
(write_fn_proto): Do not call nvptx_name_replacement.
(write_fn_proto_from_insn): Ditto.
(nvptx_output_call_insn): Ditto.
(TARGET_MANGLE_DECL_ASSEMBLER_NAME): Define.

gcc/testsuite/
* gcc.target/nvptx/rename-call.c: New test.
* gcc.target/nvptx/rename-call-2.c: New test.
* gcc.target/nvptx/asm-name.c: New test.
---
Hello,

This is an NVPTX bug fix that I'm going to apply to gomp-nvptx branch, but
it's a generally useful fix. OK for trunk? Now or when stage1 opens?

Thanks.
Alexander


 gcc/config/nvptx/nvptx.c   | 26 --
 gcc/testsuite/gcc.target/nvptx/asm-name.c  | 14 ++
 gcc/testsuite/gcc.target/nvptx/rename-call-2.c | 12 
 gcc/testsuite/gcc.target/nvptx/rename-call.c   | 16 
 4 files changed, 58 insertions(+), 10 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/nvptx/asm-name.c
 create mode 100644 gcc/testsuite/gcc.target/nvptx/rename-call-2.c
 create mode 100644 gcc/testsuite/gcc.target/nvptx/rename-call.c

diff --git a/gcc/config/nvptx/nvptx.c b/gcc/config/nvptx/nvptx.c
index 1fc25e5..0c55976 100644
--- a/gcc/config/nvptx/nvptx.c
+++ b/gcc/config/nvptx/nvptx.c
@@ -273,7 +273,16 @@ nvptx_name_replacement (const char *name)
   for (size_t i = 0; i < ARRAY_SIZE (replacements) / 2; i++)
 if (!strcmp (name, replacements[2 * i]))
   return replacements[2 * i + 1];
-  return name;
+  return NULL;
+}
+
+/* Implement TARGET_MANGLE_DECL_ASSEMBLER_NAME.  */
+
+static tree
+nvptx_mangle_decl_assembler_name (tree ARG_UNUSED (decl), tree id)
+{
+  const char *name = nvptx_name_replacement (IDENTIFIER_POINTER (id));
+  return name ? get_identifier (name) : id;
 }
 
 /* If MODE should be treated as two registers of an inner mode, return
@@ -735,13 +744,8 @@ write_fn_proto (std::stringstream , bool is_defn,
   if (is_defn)
 /* Emit a declaration. The PTX assembler gets upset without it.   */
 name = write_fn_proto (s, false, name, decl);
-  else
-{
-  /* Avoid repeating the name replacement.  */
-  name = nvptx_name_replacement (name);
-  if (name[0] == '*')
-   name++;
-}
+  else if (name[0] == '*')
+name++;
 
   write_fn_marker (s, is_defn, TREE_PUBLIC (decl), name);
 
@@ -822,7 +826,8 @@ write_fn_proto_from_insn (std::stringstream , const char 
*name,
 }
   else
 {
-  name = nvptx_name_replacement (name);
+  if (name[0] == '*')
+   name++;
   write_fn_marker (s, false, true, name);
   s << "\t.extern .func ";
 }
@@ -1976,7 +1981,6 @@ nvptx_output_call_insn (rtx_insn *insn, rtx result, rtx 
callee)
   if (decl)
 {
   const char *name = get_fnname_from_decl (decl);
-  name = nvptx_name_replacement (name);
   assemble_name (asm_out_file, name);
 }
   else
@@ -5124,6 +5128,8 @@ nvptx_goacc_reduction (gcall *call)
 #undef TARGET_NO_REGISTER_ALLOCATION
 #define TARGET_NO_REGISTER_ALLOCATION true
 
+#undef TARGET_MANGLE_DECL_ASSEMBLER_NAME
+#define TARGET_MANGLE_DECL_ASSEMBLER_NAME nvptx_mangle_decl_assembler_name
 #undef TARGET_ENCODE_SECTION_INFO
 #define TARGET_ENCODE_SECTION_INFO nvptx_encode_section_info
 #undef TARGET_RECORD_OFFLOAD_SYMBOL
diff --git a/gcc/testsuite/gcc.target/nvptx/asm-name.c 
b/gcc/testsuite/gcc.target/nvptx/asm-name.c
new file mode 100644
index 000..db52fff
--- /dev/null
+++ b/gcc/testsuite/gcc.target/nvptx/asm-name.c
@@ -0,0 +1,14 @@
+/* { dg-options "-std=gnu99" } */
+/* { dg-do assemble } */
+
+void foo(void) asm("bar");
+void foo_np()  asm("baz");
+
+void *p1 = foo;
+void *p2 = foo_np;
+
+void *r1() { return foo; }
+void *r2() { return foo_np; }
+
+void f1() { foo(); }
+void f2() { foo_np(); }
diff --git a/gcc/testsuite/gcc.target/nvptx/rename-call-2.c 
b/gcc/testsuite/gcc.target/nvptx/rename-call-2.c
new file mode 100644
index 000..230c680
--- /dev/null
+++ b/gcc/testsuite/gcc.target/nvptx/rename-call-2.c
@@ -0,0 +1,12 @@
+/* { dg-options "-std=gnu99" } */
+/* { dg-do assemble } */
+
+/* Like rename-call.c, but using old-style prototype.  */
+
+void call();
+
+void *p = call;
+
+void *r() { return call; }
+
+void f() { call(); }
diff --git a/gcc/testsuite/gcc.target/nvptx/rename-call.c 
b/gcc/testsuite/gcc.target/nvptx/rename-call.c
new file mode 100644
index 000..d5685a7
--- /dev/null
+++ b/gcc/testsuite/gcc.target/nvptx/rename-call.c
@@ -0,0 +1,16 @@
+/* { 

Re: [PATCH 2/2] Fix PR hsa/70402

2016-03-31 Thread Martin Liška
On 03/29/2016 01:44 PM, Martin Liška wrote:
> Second part of the patch set which omits one split_block (compared to the 
> original patch).
> Acceptable just in case the first part will be accepted.
> 
> Thanks
> Martin
> 

Hi.

I'm sending v3 of the patch which does not immediately update dominator,
but sets a flag that eventually triggers the update.

Thanks,
Martin
>From ffa7d2a3ea0fbf454303c9b8d190feeb40d12a4b Mon Sep 17 00:00:00 2001
From: marxin 
Date: Tue, 29 Mar 2016 12:06:20 +0200
Subject: [PATCH] Fix PR hsa/70402

gcc/ChangeLog:

2016-03-29  Martin Liska  

	PR hsa/70402
	* hsa-gen.c (gen_hsa_insns_for_switch_stmt): Guard index
	value that is really in range handled by SBR instruction.
	* hsa-brig.c (emit_switch_insn): Do not emit unconditional
	jump.
	* hsa-dump.c (dump_hsa_insn_1): Do not dump default BB.
	* hsa.h (hsa_insn_sbr::m_default_bb): Remove field.
---
 gcc/hsa-brig.c |  4 
 gcc/hsa-dump.c |  3 ---
 gcc/hsa-gen.c  | 44 ++--
 gcc/hsa.h  |  3 ---
 4 files changed, 38 insertions(+), 16 deletions(-)

diff --git a/gcc/hsa-brig.c b/gcc/hsa-brig.c
index ee587db..da4735a 100644
--- a/gcc/hsa-brig.c
+++ b/gcc/hsa-brig.c
@@ -1534,10 +1534,6 @@ emit_switch_insn (hsa_insn_sbr *sbr)
 
   brig_code.add (, sizeof (repr));
   brig_insn_count++;
-
-  /* Emit jump to default label.  */
-  hsa_bb *hbb = hsa_bb_for_bb (sbr->m_default_bb);
-  emit_unconditional_jump (>m_label_ref);
 }
 
 /* Emit a HSA convert instruction and all necessary directives, schedule
diff --git a/gcc/hsa-dump.c b/gcc/hsa-dump.c
index d33ac4b..bab056a 100644
--- a/gcc/hsa-dump.c
+++ b/gcc/hsa-dump.c
@@ -922,9 +922,6 @@ dump_hsa_insn_1 (FILE *f, hsa_insn_basic *insn, int *indent)
 	  if (i != sbr->m_jump_table.length () - 1)
 	fprintf (f, ", ");
 	}
-
-  fprintf (f, "] /* default: BB %i */",
-	   hsa_bb_for_bb (sbr->m_default_bb)->m_index);
 }
   else if (is_a  (insn))
 {
diff --git a/gcc/hsa-gen.c b/gcc/hsa-gen.c
index db7fc3d..c65e0f9 100644
--- a/gcc/hsa-gen.c
+++ b/gcc/hsa-gen.c
@@ -1549,7 +1549,7 @@ hsa_insn_br::operator new (size_t)
 
 hsa_insn_sbr::hsa_insn_sbr (hsa_op_reg *index, unsigned jump_count)
   : hsa_insn_basic (1, BRIG_OPCODE_SBR, BRIG_TYPE_B1, index),
-m_width (BRIG_WIDTH_1), m_jump_table (vNULL), m_default_bb (NULL),
+m_width (BRIG_WIDTH_1), m_jump_table (vNULL),
 m_label_code_list (new hsa_op_code_list (jump_count))
 {
 }
@@ -3470,11 +3470,48 @@ get_switch_size (gswitch *s)
 static void
 gen_hsa_insns_for_switch_stmt (gswitch *s, hsa_bb *hbb)
 {
+  gimple_stmt_iterator it = gsi_for_stmt (s);
+  gsi_prev ();
+
+  /* Create preambule that verifies that index - lowest_label >= 0.  */
+  edge e = split_block (hbb->m_bb, gsi_stmt (it));
+  e->flags &= ~EDGE_FALLTHRU;
+  e->flags |= EDGE_TRUE_VALUE;
+
   function *func = DECL_STRUCT_FUNCTION (current_function_decl);
   tree index_tree = gimple_switch_index (s);
   tree lowest = get_switch_low (s);
+  tree highest = get_switch_high (s);
 
   hsa_op_reg *index = hsa_cfun->reg_for_gimple_ssa (index_tree);
+
+  hsa_op_reg *cmp1_reg = new hsa_op_reg (BRIG_TYPE_B1);
+  hsa_op_immed *cmp1_immed = new hsa_op_immed (lowest);
+  hbb->append_insn (new hsa_insn_cmp (BRIG_COMPARE_GE, cmp1_reg->m_type,
+  cmp1_reg, index, cmp1_immed));
+
+  hsa_op_reg *cmp2_reg = new hsa_op_reg (BRIG_TYPE_B1);
+  hsa_op_immed *cmp2_immed = new hsa_op_immed (highest);
+  hbb->append_insn (new hsa_insn_cmp (BRIG_COMPARE_LE, cmp2_reg->m_type,
+  cmp2_reg, index, cmp2_immed));
+
+  hsa_op_reg *cmp_reg = new hsa_op_reg (BRIG_TYPE_B1);
+  hbb->append_insn (new hsa_insn_basic (3, BRIG_OPCODE_AND, cmp_reg->m_type,
+	cmp_reg, cmp1_reg, cmp2_reg));
+
+  hbb->append_insn (new hsa_insn_br (cmp_reg));
+
+  tree default_label = gimple_switch_default_label (s);
+  basic_block default_label_bb = label_to_block_fn (func,
+		CASE_LABEL (default_label));
+
+  make_edge (e->src, default_label_bb, EDGE_FALSE_VALUE);
+
+  hsa_cfun->m_need_cfg_update = true;
+
+  /* Basic block with the SBR instruction.  */
+  hbb = hsa_init_new_bb (e->dest);
+
   hsa_op_reg *sub_index = new hsa_op_reg (index->m_type);
   hbb->append_insn (new hsa_insn_basic (3, BRIG_OPCODE_SUB, sub_index->m_type,
 	sub_index, index,
@@ -3486,11 +3523,6 @@ gen_hsa_insns_for_switch_stmt (gswitch *s, hsa_bb *hbb)
   unsigned HOST_WIDE_INT size = tree_to_uhwi (get_switch_size (s));
 
   hsa_insn_sbr *sbr = new hsa_insn_sbr (sub_index, size + 1);
-  tree default_label = gimple_switch_default_label (s);
-  basic_block default_label_bb = label_to_block_fn (func,
-		CASE_LABEL (default_label));
-
-  sbr->m_default_bb = default_label_bb;
 
   /* Prepare array with default label destination.  */
   for (unsigned HOST_WIDE_INT i = 0; i <= size; i++)
diff --git a/gcc/hsa.h b/gcc/hsa.h
index 3732700..70e8212 100644
--- a/gcc/hsa.h
+++ b/gcc/hsa.h
@@ -566,9 +566,6 @@ public:
   /* Jump table.  */
   vec  

[PATCH 1/2] HSA: support alignment for hsa_symbols (PR hsa/70391)

2016-03-31 Thread marxin
gcc/ChangeLog:

2016-03-23  Martin Liska  

PR hsa/70391
* hsa-brig.c (emit_directive_variable): Emit alignment
according to hsa_symbol::m_align.
* hsa-dump.c (hsa_byte_alignment): Move the function to
another file.
(dump_hsa_symbol): Dump alignment of HSA symbols.
* hsa-gen.c (get_symbol_for_decl): Set-up alignment
of a symbol.
(gen_hsa_addr_with_align): New function.
(hsa_bitmemref_alignment): Use newly added function.
(gen_hsa_insns_for_load): Likewise.
(gen_hsa_insns_for_store): Likewise.
(gen_hsa_memory_copy): New argument added.
(gen_hsa_insns_for_single_assignment): Respect
alignment for assignments processed via
gen_hsa_memory_copy.
(gen_hsa_insns_for_direct_call): Likewise.
(gen_hsa_insns_for_return): Likewise.
(gen_function_def_parameters): Set default
alignment.
* hsa.c (hsa_object_alignment): New function.
(hsa_byte_alignment): Pasted function.
* hsa.h (hsa_symbol::m_align): New field.
---
 gcc/hsa-brig.c |  5 +---
 gcc/hsa-dump.c | 13 ++---
 gcc/hsa-gen.c  | 88 +-
 gcc/hsa.c  | 20 +
 gcc/hsa.h  |  8 +-
 5 files changed, 99 insertions(+), 35 deletions(-)

diff --git a/gcc/hsa-brig.c b/gcc/hsa-brig.c
index 9b6c0b8..ee587db 100644
--- a/gcc/hsa-brig.c
+++ b/gcc/hsa-brig.c
@@ -605,10 +605,7 @@ emit_directive_variable (struct hsa_symbol *symbol)
   dirvar.init = 0;
   dirvar.type = lendian16 (symbol->m_type);
   dirvar.segment = symbol->m_segment;
-  /* TODO: Once we are able to access global variables, we must copy their
- alignment.  */
-  dirvar.align = MAX (hsa_natural_alignment (dirvar.type),
- (BrigAlignment8_t) BRIG_ALIGNMENT_4);
+  dirvar.align = symbol->m_align;
   dirvar.linkage = symbol->m_linkage;
   dirvar.dim.lo = symbol->m_dim;
   dirvar.dim.hi = symbol->m_dim >> 32;
diff --git a/gcc/hsa-dump.c b/gcc/hsa-dump.c
index b69b34d..d33ac4b 100644
--- a/gcc/hsa-dump.c
+++ b/gcc/hsa-dump.c
@@ -621,16 +621,6 @@ hsa_m_atomicop_name (enum BrigAtomicOperation op)
 }
 }
 
-/* Return byte alignment for given BrigAlignment8_t value.  */
-
-static unsigned
-hsa_byte_alignment (BrigAlignment8_t alignment)
-{
-  gcc_assert (alignment != BRIG_ALIGNMENT_NONE);
-
-  return 1 << (alignment - 1);
-}
-
 /* Dump textual representation of HSA IL register REG to file F.  */
 
 static void
@@ -716,7 +706,8 @@ dump_hsa_symbol (FILE *f, hsa_symbol *symbol)
   name = buf;
 }
 
-  fprintf (f, "%s_%s %s", hsa_seg_name (symbol->m_segment),
+  fprintf (f, "align(%u) %s_%s %s", hsa_byte_alignment (symbol->m_align),
+  hsa_seg_name (symbol->m_segment),
   hsa_type_name (symbol->m_type & ~BRIG_TYPE_ARRAY_MASK), name);
 
   if (symbol->m_type & BRIG_TYPE_ARRAY_MASK)
diff --git a/gcc/hsa-gen.c b/gcc/hsa-gen.c
index 72eecf9..db39813 100644
--- a/gcc/hsa-gen.c
+++ b/gcc/hsa-gen.c
@@ -169,12 +169,12 @@ hsa_symbol::hsa_symbol ()
 
 hsa_symbol::hsa_symbol (BrigType16_t type, BrigSegment8_t segment,
BrigLinkage8_t linkage, bool global_scope_p,
-   BrigAllocation allocation)
+   BrigAllocation allocation, BrigAlignment8_t align)
   : m_decl (NULL_TREE), m_name (NULL), m_name_number (0),
 m_directive_offset (0), m_type (type), m_segment (segment),
 m_linkage (linkage), m_dim (0), m_cst_value (NULL),
 m_global_scope_p (global_scope_p), m_seen_error (false),
-m_allocation (allocation), m_emitted_to_brig (false)
+m_allocation (allocation), m_emitted_to_brig (false), m_align (align)
 {
 }
 
@@ -908,21 +908,29 @@ get_symbol_for_decl (tree decl)
 {
   hsa_symbol *sym;
   gcc_assert (TREE_CODE (decl) == VAR_DECL);
+  BrigAlignment8_t align = hsa_object_alignment (decl);
 
   if (is_in_global_vars)
{
  sym = new hsa_symbol (BRIG_TYPE_NONE, BRIG_SEGMENT_GLOBAL,
BRIG_LINKAGE_PROGRAM, true,
-   BRIG_ALLOCATION_PROGRAM);
+   BRIG_ALLOCATION_PROGRAM, align);
  hsa_cfun->m_global_symbols.safe_push (sym);
}
   else
{
+ /* As generation of memory copy instructions relies on alignment
+greater or equal to 8 bytes, we need to increase alignment
+of all aggregate types.. */
+ if (AGGREGATE_TYPE_P (TREE_TYPE (decl)))
+   align = MAX ((BrigAlignment8_t) BRIG_ALIGNMENT_8, align);
+
  /* PARM_DECL and RESULT_DECL should be already in m_local_symbols.  */
  gcc_assert (TREE_CODE (decl) == VAR_DECL);
 
  sym = new hsa_symbol (BRIG_TYPE_NONE, BRIG_SEGMENT_PRIVATE,
BRIG_LINKAGE_FUNCTION);
+ sym->m_align = align;
  hsa_cfun->m_private_variables.safe_push (sym);
}
 
@@ 

[PATCH 0/2] HSA: support alignment for hsa_symbols (PR hsa/70391)

2016-03-31 Thread marxin
Hello.

Following small series implements missing support for alignment
of HSA symbols. So far we were very optimistic about the alignment.
The first patch adds tracking of alignment of HSA symbols and
takes minimum every time we do generation of memory copy instruction.
The second part handles string operations (memcpy, memset, ...), where
we add a CFG that distinguishes between aligned and not aligned
operands.

Patch can bootstrap on x86_64-linux-gnu w/o any regression.

Thanks,
Martin

marxin (2):
  HSA: support alignment for hsa_symbols (PR hsa/70391)
  HSA: handle alignment of string builtins (PR hsa/70391)

 gcc/hsa-brig.c |   5 +-
 gcc/hsa-dump.c |  13 +-
 gcc/hsa-gen.c  | 456 ++---
 gcc/hsa-regalloc.c |   1 +
 gcc/hsa.c  |  20 +++
 gcc/hsa.h  |  17 +-
 6 files changed, 372 insertions(+), 140 deletions(-)

-- 
2.7.1



[PATCH 2/2] HSA: handle alignment of string builtins (PR hsa/70391)

2016-03-31 Thread marxin
gcc/ChangeLog:

2016-03-23  Martin Liska  

PR hsa/70391
* hsa-gen.c (hsa_function_representation::update_cfg): New
function.
(convert_addr_to_flat_segment): Likewise.
(gen_hsa_memory_set): New alignment argument.
(gen_hsa_ctor_assignment): Likewise.
(gen_hsa_insns_for_single_assignment): Provide alignment
to gen_hsa_ctor_assignment.
(gen_hsa_insns_for_direct_call): Add new argument.
(expand_lhs_of_string_op): New function.
(expand_string_operation_builtin): Likewise.
(expand_memory_copy): New function.
(expand_memory_set): New function.
(gen_hsa_insns_for_call): Use HOST_WIDE_INT.
(convert_switch_statements): Change signature.
(generate_hsa): Use a return value of the function.
(pass_gen_hsail::execute): Do not call
convert_switch_statements here.
* hsa-regalloc.c (hsa_regalloc): Call update_cfg.
* hsa.h (hsa_function_representation::m_need_cfg_update):
New flag.
(hsa_function_representation::update_cfg): New function.
---
 gcc/hsa-gen.c  | 372 ++---
 gcc/hsa-regalloc.c |   1 +
 gcc/hsa.h  |   9 +-
 3 files changed, 275 insertions(+), 107 deletions(-)

diff --git a/gcc/hsa-gen.c b/gcc/hsa-gen.c
index db39813..db7fc3d 100644
--- a/gcc/hsa-gen.c
+++ b/gcc/hsa-gen.c
@@ -214,7 +214,7 @@ hsa_symbol::fillup_for_decl (tree decl)
should be set to number of SSA names used in the function.  */
 
 hsa_function_representation::hsa_function_representation
-  (tree fdecl, bool kernel_p, unsigned ssa_names_count)
+  (tree fdecl, bool kernel_p, unsigned ssa_names_count, bool need_cfg_update)
   : m_name (NULL),
 m_reg_count (0), m_input_args (vNULL),
 m_output_arg (NULL), m_spill_symbols (vNULL), m_global_symbols (vNULL),
@@ -223,7 +223,8 @@ hsa_function_representation::hsa_function_representation
 m_in_ssa (true), m_kern_p (kernel_p), m_declaration_p (false),
 m_decl (fdecl), m_internal_fn (NULL), m_shadow_reg (NULL),
 m_kernel_dispatch_count (0), m_maximum_omp_data_size (0),
-m_seen_error (false), m_temp_symbol_count (0), m_ssa_map ()
+m_seen_error (false), m_temp_symbol_count (0), m_ssa_map (),
+m_need_cfg_update (need_cfg_update)
 {
   int sym_init_len = (vec_safe_length (cfun->local_decls) / 2) + 1;;
   m_local_symbols = new hash_table  (sym_init_len);
@@ -319,6 +320,16 @@ hsa_function_representation::init_extra_bbs ()
   hsa_init_new_bb (EXIT_BLOCK_PTR_FOR_FN (cfun));
 }
 
+void
+hsa_function_representation::update_cfg ()
+{
+  if (m_need_cfg_update)
+{
+  free_dominance_info (CDI_DOMINATORS);
+  calculate_dominance_info (CDI_DOMINATORS);
+}
+}
+
 hsa_symbol *
 hsa_function_representation::create_hsa_temporary (BrigType16_t type)
 {
@@ -2246,30 +2257,14 @@ gen_hsa_addr_for_arg (tree tree_type, int index)
   return new hsa_op_address (sym);
 }
 
-/* Generate HSA instructions that calculate address of VAL including all
-   necessary conversions to flat addressing and place the result into DEST.
+/* Generate HSA instructions that process all necessary conversions
+   of an ADDR to flat addressing and place the result into DEST.
Instructions are appended to HBB.  */
 
 static void
-gen_hsa_addr_insns (tree val, hsa_op_reg *dest, hsa_bb *hbb)
+convert_addr_to_flat_segment (hsa_op_address *addr, hsa_op_reg *dest,
+ hsa_bb *hbb)
 {
-  /* Handle cases like tmp = NULL, where we just emit a move instruction
- to a register.  */
-  if (TREE_CODE (val) == INTEGER_CST)
-{
-  hsa_op_immed *c = new hsa_op_immed (val);
-  hsa_insn_basic *insn = new hsa_insn_basic (2, BRIG_OPCODE_MOV,
-dest->m_type, dest, c);
-  hbb->append_insn (insn);
-  return;
-}
-
-  hsa_op_address *addr;
-
-  gcc_assert (dest->m_type == hsa_get_segment_addr_type (BRIG_SEGMENT_FLAT));
-  if (TREE_CODE (val) == ADDR_EXPR)
-val = TREE_OPERAND (val, 0);
-  addr = gen_hsa_addr (val, hbb);
   hsa_insn_basic *insn = new hsa_insn_basic (2, BRIG_OPCODE_LDA);
   insn->set_op (1, addr);
   if (addr->m_symbol && addr->m_symbol->m_segment != BRIG_SEGMENT_GLOBAL)
@@ -2298,6 +2293,34 @@ gen_hsa_addr_insns (tree val, hsa_op_reg *dest, hsa_bb 
*hbb)
 }
 }
 
+/* Generate HSA instructions that calculate address of VAL including all
+   necessary conversions to flat addressing and place the result into DEST.
+   Instructions are appended to HBB.  */
+
+static void
+gen_hsa_addr_insns (tree val, hsa_op_reg *dest, hsa_bb *hbb)
+{
+  /* Handle cases like tmp = NULL, where we just emit a move instruction
+ to a register.  */
+  if (TREE_CODE (val) == INTEGER_CST)
+{
+  hsa_op_immed *c = new hsa_op_immed (val);
+  hsa_insn_basic *insn = new hsa_insn_basic (2, BRIG_OPCODE_MOV,
+dest->m_type, dest, c);
+  

Re: [PATCH] Fix PR23471

2016-03-31 Thread Richard Biener
On Thu, Mar 31, 2016 at 12:12 PM, Hurugalawadi, Naveen
 wrote:
>>> With -O1 there is -fno-strict-overflow in effect which is not
>>> TYPE_OVERFLOW_UNDEFINED.
>
> Thanks for the details. The below code has the following condition
> and hence not working for O1.
> if (FLOAT_TYPE_P (type) || TYPE_OVERFLOW_UNDEFINED (type))

Yes, and that's correct.

> Then PR23471 is fixed with the current sources.

Yes.

Richard.

> Thanks,
> Naveen


[gomp4] Merge trunk r234469 (2016-03-24) into gomp-4_0-branch

2016-03-31 Thread Thomas Schwinge
Hi!

Committed to gomp-4_0-branch in r234610:

commit e252cf1daa16c5857e4358c214937c6fb0452b5f
Merge: 8fff8ae 6846439
Author: tschwinge 
Date:   Thu Mar 31 08:21:26 2016 +

svn merge -r 234323:234469 svn+ssh://gcc.gnu.org/svn/gcc/trunk


git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/gomp-4_0-branch@234610 
138bc75d-0d04-0410-961f-82ee72b054a4


Grüße
 Thomas


Re: [PATCH] Fix PR23471

2016-03-31 Thread Hurugalawadi, Naveen
>> With -O1 there is -fno-strict-overflow in effect which is not
>> TYPE_OVERFLOW_UNDEFINED.

Thanks for the details. The below code has the following condition
and hence not working for O1. 
if (FLOAT_TYPE_P (type) || TYPE_OVERFLOW_UNDEFINED (type))

Then PR23471 is fixed with the current sources.

Thanks,
Naveen


Re: [PATCH] Fix PR23471

2016-03-31 Thread Richard Biener
On Thu, Mar 31, 2016 at 11:55 AM, Hurugalawadi, Naveen
 wrote:
>>> Er, the code just below your patch should already handle this case, no?
>
> Hi,
>
> Thanks for the review and your comments on the patch.
>
> The code below seems to handle this case for O2 or higher optimization.
>
> However, somehow its not being handled with O1 and hence has this
> implemented for better optimization.
> Can you please let me know if it can be handled in a better way or neglect
> this one just for this case?

With -O1 there is -fno-strict-overflow in effect which is not
TYPE_OVERFLOW_UNDEFINED.
Your !flag_wrapv check is simply wrong (for -fno-strict-overflow
neither TYPE_OVERFLOW_WRAPS nor
TYPE_OVERFLOW_UNDEFINED is set).

Richard.

> Thanks,
> Naveen


Re: [PATCH] Fix PR23471

2016-03-31 Thread Hurugalawadi, Naveen
>> Er, the code just below your patch should already handle this case, no?

Hi,

Thanks for the review and your comments on the patch.

The code below seems to handle this case for O2 or higher optimization.

However, somehow its not being handled with O1 and hence has this
implemented for better optimization.
Can you please let me know if it can be handled in a better way or neglect
this one just for this case?

Thanks,
Naveen


Re: [AArch64] Fix SIMD predicate

2016-03-31 Thread James Greenhalgh
On Wed, Mar 30, 2016 at 11:18:27AM -0500, Evandro Menezes wrote:
>Add scalar 0.0 to the aarch64_simd_reg_or_zero predicate.
> 
>2016-03-30  Evandro Menezes  
> 
> * gcc/config/aarch64/predicates.md
> (aarch64_simd_reg_or_zero predicate): Add the "const_double"
>constraint.
> 
> 
> It seems to me that the aarch64_simd_reg_or_zero should also handle
> the scalar constant 0.0 as well.

It took me an extra few minutes to figure out why this patch was correct - a
more detailed description of what the code-gen issue this was intended to
fix would have helped. The only pattern I can see for which this matters
is aarch64_cm for the SF and DF modes. Clearly the predicate
is too tight here, and the relaxation you propose is correct.

> OK to commit?

OK, and low-risk enough to take now.

Thanks,
James



Re: backported patch for PR69614

2016-03-31 Thread Christophe Lyon
On 30 March 2016 at 18:01, Vladimir Makarov  wrote:
>   The patch for PR69614 has been backported to gcc-5 branch:
>
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69614
>
>   Committed as rev. 234577.
>
Hi,

As I've already reported:
https://gcc.gnu.org/ml/gcc-patches/2016-03/msg00773.html
the new test executes incorrectly on armeb --with-fpu=neon

Christophe.


Re: Please include ada-hurd.diff upstream (try2)

2016-03-31 Thread Svante Signell
On Thu, 2016-03-17 at 08:51 +0100, Arnaud Charlet wrote:
> > 
> > > 
> > > The copyright notices are wrong (or at least incomplete).
> > Hi, what is wrong then, copyright years and/or the text?
> Both. The copyright year should include 2016 and the text should be
> copyright FSF, not AdaCore.

Attached is an updated ada-hurd.diff with your comments above taken care of.
OK now?

Thanks!2016-03-31  Svante Signell  

* gcc-interface/Makefile.in: Add support for x86 GNU/Hurd.
* s-osinte-gnu.ads: New specification file.
* s-osinte-gnu.adb: New body file, basically s-osinte-posix.adb
  adding dummy implementation of functions not yet implemented.
---
Index: gcc-5-5.3.1/src/gcc/ada/s-osinte-gnu.adb
===
--- /dev/null
+++ gcc-5-5.3.1/src/gcc/ada/s-osinte-gnu.adb
@@ -0,0 +1,146 @@
+--
+--  --
+-- GNAT RUN-TIME LIBRARY (GNARL) COMPONENTS --
+--  --
+--   S Y S T E M . O S _ I N T E R F A C E  --
+--  --
+--   B o d y--
+--  --
+-- Copyright (C) 1991-1994, Florida State University--
+-- Copyright (C) 1995-2014, AdaCore --
+--  Copyright (C) 2015-2016, Free Software Foundation, Inc. --
+--  --
+-- GNAT is free software;  you can  redistribute it  and/or modify it under --
+-- terms of the  GNU General Public License as published  by the Free Soft- --
+-- ware  Foundation;  either version 3,  or (at your option) any later ver- --
+-- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
+-- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
+-- or FITNESS FOR A PARTICULAR PURPOSE. --
+--  --
+-- As a special exception under Section 7 of GPL version 3, you are granted --
+-- additional permissions described in the GCC Runtime Library Exception,   --
+-- version 3.1, as published by the Free Software Foundation.   --
+--  --
+-- You should have received a copy of the GNU General Public License and--
+-- a copy of the GCC Runtime Library Exception along with this program; --
+-- see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see--
+-- .  --
+--  --
+-- GNARL was developed by the GNARL team at Florida State University.   --
+-- Extensive contributions were provided by Ada Core Technologies, Inc. --
+--  --
+--
+
+--  This is the GNU/Hurd version of this package.
+
+pragma Polling (Off);
+--  Turn off polling, we do not want ATC polling to take place during
+--  tasking operations. It causes infinite loops and other problems.
+
+--  This package encapsulates all direct interfaces to OS services
+--  that are needed by children of System.
+
+package body System.OS_Interface is
+
+   
+   -- Get_Stack_Base --
+   
+
+   function Get_Stack_Base (thread : pthread_t) return Address is
+  pragma Warnings (Off, thread);
+
+   begin
+  return Null_Address;
+   end Get_Stack_Base;
+
+   --
+   -- pthread_init --
+   --
+
+   procedure pthread_init is
+   begin
+  null;
+   end pthread_init;
+
+   --
+   -- pthread_mutexattr_setprioceiling --
+   --
+
+   function pthread_mutexattr_setprioceiling
+ (attr : access pthread_mutexattr_t;
+  prioceiling : int) return int is
+  pragma Unreferenced (attr, prioceiling);
+   begin
+  return 0;
+   end pthread_mutexattr_setprioceiling;
+
+   --
+   -- pthread_mutexattr_getprioceiling --
+   --
+
+   function pthread_mutexattr_getprioceiling
+ (attr : access pthread_mutexattr_t;
+  prioceiling : access int) return int is
+  pragma Unreferenced (attr, prioceiling);
+   begin
+  return 0;
+   end 

Re: [PATCH] Fix PR31096

2016-03-31 Thread Ramana Radhakrishnan


On 31/03/16 09:55, Hurugalawadi, Naveen wrote:
> +/* { dg-final { scan-assembler-not "addl" } } */


addl is not the mnemonic for add on all architectures  


Ramana


Re: [PATCH] Fix PR31096

2016-03-31 Thread Marc Glisse

On Thu, 31 Mar 2016, Hurugalawadi, Naveen wrote:


Hi,

Please find attached the patch that fixes the PR31096.
Should the optimization be extended to addition and other
operations as well?

Please review the patch and let me know if its okay?

Regression tested on X86_64.

Thanks,
Naveen

2016-03-31  Naveen H.S  

   * match.pd (cmp (mult:cs @0 @1) (mult:cs @2 @1)) : New Pattern.

   * gcc.dg/pr31096.c: New testcase.


Looks like you are turning x*-1 < y*-1 into x

Re: [PATCH] Fix PR23471

2016-03-31 Thread Marc Glisse

On Thu, 31 Mar 2016, Hurugalawadi, Naveen wrote:


Please find attached the patch that fixes the tree optimization 23471.

Please review the patch and let me know if its okay?

Regression tested on X86_64.

Thanks,
Naveen

2016-03-31  Naveen H.S  

   * fold-const.c (tree_binary_nonnegative_warnv_p) : Handle the case
   a * a; where it should be positive always.

   * gcc.dg/pr23471.c: New testcase.


Er, the code just below your patch should already handle this case, no?

--
Marc Glisse


Re: Backports to 5.x branch

2016-03-31 Thread Jakub Jelinek
On Thu, Mar 31, 2016 at 09:53:28AM +0100, Kyrill Tkachov wrote:
> 
> On 31/03/16 09:48, Christophe Lyon wrote:
> >On 30 March 2016 at 14:49, Jakub Jelinek  wrote:
> >>Hi!
> >>
> >>I've bootstrapped/regtested on x86_64-linux and i686-linux following
> >>backports from trunk and committed them to gcc-5-branch.
> >>
> >Hi,
> >I've noticed that r234548 shows regressions on aarch64:
> >PASS->FAILL:
> >   gcc.target/aarch64/scalar_shift_1.c scan-assembler-times
> >neg\td[0-9]+, d[0-9]+ 4
> 
> Maybe that test just needs a backport of the fix for PR 70004?

Sorry, haven't remembered PR70004 has been a follow up to the invalid shift
counts PRs.  PR70004 patch is preapproved for 5.x branch.

Jakub


[PATCH] Fix PR23471

2016-03-31 Thread Hurugalawadi, Naveen
Hi,

Please find attached the patch that fixes the tree optimization 23471.

Please review the patch and let me know if its okay?

Regression tested on X86_64.

Thanks,
Naveen

2016-03-31  Naveen H.S  

* fold-const.c (tree_binary_nonnegative_warnv_p) : Handle the case
a * a; where it should be positive always.

* gcc.dg/pr23471.c: New testcase.
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index 788ecc3..a0b0def 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -12923,6 +12923,15 @@ tree_binary_nonnegative_warnv_p (enum tree_code code, tree type, tree op0,
   break;
 
 case MULT_EXPR:
+  /* a * a is non-negative.  */
+  if (!flag_wrapv && operand_equal_p (op0, op1, 0))
+	{
+	  if (ANY_INTEGRAL_TYPE_P (type)
+	  && TYPE_OVERFLOW_UNDEFINED (type))
+	*strict_overflow_p = true;
+	  return true;
+	}
+
   if (FLOAT_TYPE_P (type) || TYPE_OVERFLOW_UNDEFINED (type))
 	{
 	  /* x * x is always non-negative for floating point x
diff --git a/gcc/testsuite/gcc.dg/pr23471.c b/gcc/testsuite/gcc.dg/pr23471.c
new file mode 100644
index 000..72b29cc
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr23471.c
@@ -0,0 +1,16 @@
+/* PR tree-optimization/23471 */
+/* { dg-do compile } */
+/* { dg-options "-O1 -fno-wrapv -fdump-tree-optimized" } */
+
+extern void link_error (void);
+
+void
+f (int a)
+{
+  int b = a;
+  b *= a;
+  if (b < 0)
+link_error ();
+}
+
+/* { dg-final { scan-tree-dump-not "link_error" "optimized" } } */


[PATCH] Fix PR31096

2016-03-31 Thread Hurugalawadi, Naveen
Hi,

Please find attached the patch that fixes the PR31096.
Should the optimization be extended to addition and other
operations as well?

Please review the patch and let me know if its okay?

Regression tested on X86_64.

Thanks,
Naveen

2016-03-31  Naveen H.S  

* match.pd (cmp (mult:cs @0 @1) (mult:cs @2 @1)) : New Pattern.

* gcc.dg/pr31096.c: New testcase.diff --git a/gcc/match.pd b/gcc/match.pd
index c0ed305..e1e1b04 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -894,7 +894,11 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
   && tree_nop_conversion_p (type, TREE_TYPE (@1)))
   (convert (bit_and (bit_not @1) @0
 
-
+/* Fold A * 10 == B * 10 into A == B.  */
+(for cmp (tcc_comparison)
+ (simplify
+  (cmp (mult:cs @0 @1) (mult:cs @2 @1))
+   (cmp @0 @2)))
 
 /* ((X inner_op C0) outer_op C1)
With X being a tree where value_range has reasoned certain bits to always be
diff --git a/gcc/testsuite/gcc.dg/pr31096.c b/gcc/testsuite/gcc.dg/pr31096.c
new file mode 100644
index 000..5476db1
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr31096.c
@@ -0,0 +1,17 @@
+/* PR middle-end/31096 */
+/* { dg-do compile } */
+/* { dg-options "-O1" } */
+
+int
+f (int a, int b)
+{
+  return a * 10 == b * 10;
+}
+
+int
+f1 (int a, int b)
+{
+  return a == b;
+}
+
+/* { dg-final { scan-assembler-not "addl" } } */


Re: Backports to 5.x branch

2016-03-31 Thread Kyrill Tkachov


On 31/03/16 09:48, Christophe Lyon wrote:

On 30 March 2016 at 14:49, Jakub Jelinek  wrote:

Hi!

I've bootstrapped/regtested on x86_64-linux and i686-linux following
backports from trunk and committed them to gcc-5-branch.


Hi,
I've noticed that r234548 shows regressions on aarch64:
PASS->FAILL:
   gcc.target/aarch64/scalar_shift_1.c scan-assembler-times
neg\td[0-9]+, d[0-9]+ 4


Maybe that test just needs a backport of the fix for PR 70004?

Kyrill




 Jakub




Re: Backports to 5.x branch

2016-03-31 Thread Christophe Lyon
On 30 March 2016 at 14:49, Jakub Jelinek  wrote:
> Hi!
>
> I've bootstrapped/regtested on x86_64-linux and i686-linux following
> backports from trunk and committed them to gcc-5-branch.
>

Hi,
I've noticed that r234548 shows regressions on aarch64:
PASS->FAILL:
  gcc.target/aarch64/scalar_shift_1.c scan-assembler-times
neg\td[0-9]+, d[0-9]+ 4


> Jakub