patch to fix PR70689

2016-04-18 Thread Vladimir N Makarov

The following patch fixes

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

The patch was successfully tested and bootstrapped on x86/x86-64.

Committed to the trunk as rev. 235184.
Index: ChangeLog
===
--- ChangeLog	(revision 235182)
+++ ChangeLog	(working copy)
@@ -1,3 +1,11 @@
+2016-04-18  Vladimir Makarov  
+
+	PR middle-end/70689
+	* lra-constraints.c (equiv_substition_p): New.
+	(process_alt_operands): Use it.
+	(swap_operands): Swap it.
+	(curr_insn_transform): Update it.
+
 2016-04-18  Michael Matz  
 
 	* tree.h (TYPE_ALIGN, DECL_ALIGN): Return shifted amount.
Index: testsuite/ChangeLog
===
--- testsuite/ChangeLog	(revision 235182)
+++ testsuite/ChangeLog	(working copy)
@@ -1,3 +1,8 @@
+2016-04-18  Vladimir Makarov  
+
+	PR middle-end/70689
+	* testsuite/gcc.target/i386/pr70689.c: New.
+
 2016-04-18  H.J. Lu  
 
 	PR target/70708
Index: lra-constraints.c
===
--- lra-constraints.c	(revision 235176)
+++ lra-constraints.c	(working copy)
@@ -1258,6 +1258,10 @@ static bool goal_alt_swapped;
 /* The chosen insn alternative.	 */
 static int goal_alt_number;
 
+/* True if the corresponding operand is the result of an equivalence
+   substitution.  */
+static bool equiv_substition_p[MAX_RECOG_OPERANDS];
+
 /* The following five variables are used to choose the best insn
alternative.	 They reflect final characteristics of the best
alternative.	 */
@@ -2064,7 +2068,10 @@ process_alt_operands (int only_alternati
 			 memory, or make other memory by reloading the
 			 address like for 'o'.  */
 		  if (CONST_POOL_OK_P (mode, op)
-			  || MEM_P (op) || REG_P (op))
+			  || MEM_P (op) || REG_P (op)
+			  /* We can restore the equiv insn by a
+			 reload.  */
+			  || equiv_substition_p[nop])
 			badop = false;
 		  constmemok = true;
 		  offmemok = true;
@@ -3371,6 +3378,7 @@ swap_operands (int nop)
   std::swap (curr_operand_mode[nop], curr_operand_mode[nop + 1]);
   std::swap (original_subreg_reg_mode[nop], original_subreg_reg_mode[nop + 1]);
   std::swap (*curr_id->operand_loc[nop], *curr_id->operand_loc[nop + 1]);
+  std::swap (equiv_substition_p[nop], equiv_substition_p[nop + 1]);
   /* Swap the duplicates too.  */
   lra_update_dup (curr_id, nop);
   lra_update_dup (curr_id, nop + 1);
@@ -3473,8 +3481,10 @@ curr_insn_transform (bool check_only_p)
 	  old = SUBREG_REG (old);
 	subst = get_equiv_with_elimination (old, curr_insn);
 	original_subreg_reg_mode[i] = VOIDmode;
+	equiv_substition_p[i] = false;
 	if (subst != old)
 	  {
+	equiv_substition_p[i] = true;
 	subst = copy_rtx (subst);
 	lra_assert (REG_P (old));
 	if (GET_CODE (op) != SUBREG)
Index: testsuite/gcc.target/i386/pr70689.c
===
--- testsuite/gcc.target/i386/pr70689.c	(revision 0)
+++ testsuite/gcc.target/i386/pr70689.c	(working copy)
@@ -0,0 +1,27 @@
+/* { dg-do compile } */
+/* { dg-require-effective-target ia32 } */
+/* { dg-options "-O1" } */
+
+struct S
+{
+  int f;
+};
+
+double a;
+int c;
+
+static
+void fn1 (struct S *p1)
+{
+  for (; c; )
+if (p1->f++)
+  a = (int) p1;
+}
+
+int
+main ()
+{
+  struct S b = { 0 };
+  fn1 ();
+  return 0;
+}


Re: [PATCH] Optimize strchr (s, 0) to strlen

2016-04-18 Thread Oleg Endo
On Mon, 2016-04-18 at 17:00 +, Wilco Dijkstra wrote:
> Optimize strchr (s, 0) to s + strlen (s).  strchr (s, 0) appears a
> common
> idiom for finding the end of a string, however it is not a very
> efficient
> way of doing so.  Strlen is a much simpler operation which is
> significantly
> faster (eg. on x86 strlen is 50% faster for strings of 8 bytes and
> about
> twice as fast as strchr on strings of 1KB).
> 
> OK for trunk?

Can you please file this as PR 61056?

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


Cheers,
Oleg


> 
> ChangeLog:
> 2016-04-18  Wilco Dijkstra  
> 
> gcc/
>   * gcc/builtins.c (fold_builtin_strchr): Optimize strchr (s, 0)
> into
>   strlen.
> 
> testsuite/
>   * gcc/testsuite/gcc.dg/strlenopt-20.c: Update test.
>   * gcc/testsuite/gcc.dg/strlenopt-21.c: Likewise.
>   * gcc/testsuite/gcc.dg/strlenopt-22.c: Likewise.
>   * gcc/testsuite/gcc.dg/strlenopt-26.c: Likewise.
>   * gcc/testsuite/gcc.dg/strlenopt-5.c: Likewise.
>   * gcc/testsuite/gcc.dg/strlenopt-7.c: Likewise.
>   * gcc/testsuite/gcc.dg/strlenopt-9.c: Likewise.
> 
> --
> 
> diff --git a/gcc/builtins.c b/gcc/builtins.c
> index
> 058ecc39aab205099713e503861103ce6ba5ee6d..150e707178a3e119d42ef630b38
> 4da3eaf7b2182 100644
> --- a/gcc/builtins.c
> +++ b/gcc/builtins.c
> @@ -8567,20 +8567,20 @@ fold_builtin_strchr (location_t loc, tree s1,
> tree s2, tree type)
>else
>  {
>const char *p1;
> +  char c;
>  
>if (TREE_CODE (s2) != INTEGER_CST)
>   return NULL_TREE;
>  
> +  if (target_char_cast (s2, ))
> + return NULL_TREE;
> +
>p1 = c_getstr (s1);
>if (p1 != NULL)
>   {
> -   char c;
> const char *r;
> tree tem;
>  
> -   if (target_char_cast (s2, ))
> - return NULL_TREE;
> -
> r = strchr (p1, c);
>  
> if (r == NULL)
> @@ -8590,6 +8590,20 @@ fold_builtin_strchr (location_t loc, tree s1,
> tree s2, tree type)
> tem = fold_build_pointer_plus_hwi_loc (loc, s1, r - p1);
> return fold_convert_loc (loc, type, tem);
>   }
> +  else if (c == 0)
> + {
> +   tree fn = builtin_decl_implicit (BUILT_IN_STRLEN);
> +   if (!fn)
> + return NULL_TREE;
> +
> +   s1 = builtin_save_expr (s1);
> +
> +   /* Transform strchr (s1, '\0') to s1 + strlen (s1).  */
> +   fn = build_call_expr_loc (loc, fn, 1, s1);
> +   tree tem = fold_build_pointer_plus (s1, fn);
> +   return fold_convert_loc (loc, type, tem);
> + }
> +
>return NULL_TREE;
>  }
>  }
> diff --git a/gcc/testsuite/gcc.dg/strlenopt-20.c
> b/gcc/testsuite/gcc.dg/strlenopt-20.c
> index
> a83e845c26d88e5acdcabf142f7b319136663488..7b483eaeac1aa47278111a92148
> a16f00b2aaa2d 100644
> --- a/gcc/testsuite/gcc.dg/strlenopt-20.c
> +++ b/gcc/testsuite/gcc.dg/strlenopt-20.c
> @@ -86,9 +86,9 @@ main ()
>return 0;
>  }
>  
> -/* { dg-final { scan-tree-dump-times "strlen \\(" 1 "strlen" } } */
> +/* { dg-final { scan-tree-dump-times "strlen \\(" 2 "strlen" } } */
>  /* { dg-final { scan-tree-dump-times "memcpy \\(" 4 "strlen" } } */
>  /* { dg-final { scan-tree-dump-times "strcpy \\(" 0 "strlen" } } */
>  /* { dg-final { scan-tree-dump-times "strcat \\(" 0 "strlen" } } */
> -/* { dg-final { scan-tree-dump-times "strchr \\(" 1 "strlen" } } */
> +/* { dg-final { scan-tree-dump-times "strchr \\(" 0 "strlen" } } */
>  /* { dg-final { scan-tree-dump-times "stpcpy \\(" 0 "strlen" } } */
> diff --git a/gcc/testsuite/gcc.dg/strlenopt-21.c
> b/gcc/testsuite/gcc.dg/strlenopt-21.c
> index
> e22fa9fca9ba14354db2cd5f602283b64bd8dcac..05b85a49dde0a7f5d269174fd42
> 69e40be910dbd 100644
> --- a/gcc/testsuite/gcc.dg/strlenopt-21.c
> +++ b/gcc/testsuite/gcc.dg/strlenopt-21.c
> @@ -57,9 +57,9 @@ main ()
>return 0;
>  }
>  
> -/* { dg-final { scan-tree-dump-times "strlen \\(" 1 "strlen" } } */
> +/* { dg-final { scan-tree-dump-times "strlen \\(" 2 "strlen" } } */
>  /* { dg-final { scan-tree-dump-times "memcpy \\(" 3 "strlen" } } */
>  /* { dg-final { scan-tree-dump-times "strcpy \\(" 0 "strlen" } } */
>  /* { dg-final { scan-tree-dump-times "strcat \\(" 0 "strlen" } } */
> -/* { dg-final { scan-tree-dump-times "strchr \\(" 1 "strlen" } } */
> +/* { dg-final { scan-tree-dump-times "strchr \\(" 0 "strlen" } } */
>  /* { dg-final { scan-tree-dump-times "stpcpy \\(" 0 "strlen" } } */
> diff --git a/gcc/testsuite/gcc.dg/strlenopt-22.c
> b/gcc/testsuite/gcc.dg/strlenopt-22.c
> index
> aa55f5ebd6a2d4803ee9a7fd60fc538d86f47124..b4ef772f0e59252f10a5419ede6
> 837b3c8ca8265 100644
> --- a/gcc/testsuite/gcc.dg/strlenopt-22.c
> +++ b/gcc/testsuite/gcc.dg/strlenopt-22.c
> @@ -31,9 +31,9 @@ main ()
>return 0;
>  }
>  
> -/* { dg-final { scan-tree-dump-times "strlen \\(" 3 "strlen" } } */
> +/* { dg-final { scan-tree-dump-times "strlen \\(" 4 "strlen" } } */
>  /* { dg-final { scan-tree-dump-times "memcpy \\(" 1 "strlen" } } */
>  /* { dg-final { scan-tree-dump-times "strcpy \\(" 

[PATCH, rs6000] Expand vec_ld and vec_st during parsing to improve performance

2016-04-18 Thread Bill Schmidt
Hi,

Expanding built-ins in the usual way (leaving them as calls until
expanding into RTL) restricts the amount of optimization that can be
performed on the code represented by the built-ins.  This has been
observed to be particularly bad for the vec_ld and vec_st built-ins on
PowerPC, which represent the lvx and stvx instructions.  Currently these
are expanded into UNSPECs that are left untouched by the optimizers, so
no redundant load or store elimination can take place.  For certain
idiomatic usages, this leads to very bad performance.

Initially I planned to just change the UNSPEC representation to RTL that
directly expresses the address masking implicit in lvx and stvx.  This
turns out to be only partially successful in improving performance.
Among other things, by the time we reach RTL we have lost track of the
__restrict__ attribute, leading to more appearances of may-alias
relationships than should really be present.  Instead, this patch
expands the built-ins during parsing so that they are exposed to all
GIMPLE optimizations as well.

This works well for vec_ld and vec_st.  It is also possible for
programmers to instead use __builtin_altivec_lvx_ and
__builtin_altivec_stvx_.  These are not so easy to catch during
parsing, since they are not processed by the overloaded built-in
function table.  For these, I am currently falling back to expansion
during RTL while still exposing the address-masking semantics, which
seems ok for these somewhat obscure built-ins.  At some future time we
may decide to handle them similarly to vec_ld and vec_st.

For POWER8 little-endian only, the loads and stores during expand time
require some special handling, since the POWER8 expanders want to
convert these to lxvd2x/xxswapd and xxswapd/stxvd2x.  To deal with this,
I've added an extra pre-pass to the swap optimization phase that
recognizes the lvx and stvx patterns and canonicalizes them so they'll
be properly recognized.  This isn't an issue for earlier or later
processors, or for big-endian POWER8, so doing this as part of swap
optimization is appropriate.

We have a lot of existing test cases for this code, which proved very
useful in discovering bugs, so I haven't seen a reason to add any new
tests.

The patch is fairly large, but it isn't feasible to break it up into
smaller units without leaving something in a broken state.  So I will
have to just apologize for the size and leave it at that.  Sorry! :)

Bootstrapped and tested successfully on powerpc64le-unknown-linux-gnu,
and on powerpc64-unknown-linux-gnu (-m32 and -m64) with no regressions.
Is this ok for trunk after GCC 6 releases?

Thanks,
Bill


2016-04-18  Bill Schmidt  

* config/rs6000/altivec.md (altivec_lvx_): Remove.
(altivec_lvx__internal): Document.
(altivec_lvx__2op): New define_insn.
(altivec_lvx__1op): Likewise.
(altivec_lvx__2op_si): Likewise.
(altivec_lvx__1op_si): Likewise.
(altivec_stvx_): Remove.
(altivec_stvx__internal): Document.
(altivec_stvx__2op): New define_insn.
(altivec_stvx__1op): Likewise.
(altivec_stvx__2op_si): Likewise.
(altivec_stvx__1op_si): Likewise.
* config/rs6000/rs6000-c.c (altivec_resolve_overloaded_builtin):
Expand vec_ld and vec_st during parsing.
* config/rs6000/rs6000.c (altivec_expand_lvx_be): Commentary
changes.
(altivec_expand_stvx_be): Likewise.
(altivec_expand_lv_builtin): Expand lvx built-ins to expose the
address-masking behavior in RTL.
(altivec_expand_stv_builtin): Expand stvx built-ins to expose the
address-masking behavior in RTL.
(altivec_expand_builtin): Change builtin code arguments for calls
to altivec_expand_stv_builtin and altivec_expand_lv_builtin.
(insn_is_swappable_p): Avoid incorrect swap optimization in the
presence of lvx/stvx patterns.
(alignment_with_canonical_addr): New function.
(alignment_mask): Likewise.
(find_alignment_op): Likewise.
(combine_lvx_pattern): Likewise.
(combine_stvx_pattern): Likewise.
(combine_lvx_stvx_patterns): Likewise.
(rs6000_analyze_swaps): Perform a pre-pass to recognize lvx and
stvx patterns from expand.
* config/rs6000/vector.md (vector_altivec_load_): Use new
expansions.
(vector_altivec_store_): Likewise.


Index: gcc/config/rs6000/altivec.md
===
--- gcc/config/rs6000/altivec.md(revision 235090)
+++ gcc/config/rs6000/altivec.md(working copy)
@@ -2514,20 +2514,9 @@
   "lvxl %0,%y1"
   [(set_attr "type" "vecload")])
 
-(define_expand "altivec_lvx_"
-  [(parallel
-[(set (match_operand:VM2 0 "register_operand" "=v")
- (match_operand:VM2 1 "memory_operand" "Z"))
- (unspec [(const_int 0)] UNSPEC_LVX)])]
-  "TARGET_ALTIVEC"
-{
-  if (!BYTES_BIG_ENDIAN && 

Re: [wwwdocs,Java] java/index.html -- fix formatting on gcc.gnu.org

2016-04-18 Thread Mike Stump

> On Apr 16, 2016, at 1:31 PM, Gerald Pfeifer  wrote:
> Soo, GCC 6 has branched -- would it make sense for you guys to
> start this removal?

No, the home page says:

  Status: 2016-03-10 (regression fixes & docs only).

for gcc 7 (aka trunk).  Technically, that should update to say all fixes, 
_before_ any change goes in.  :-)

I must admit, I’m not sure why trunk is listed that way now.  I did expect 
branching to have switched that.

Re: [wwwdocs] Document GCC 6 Solaris changes

2016-04-18 Thread Gerald Pfeifer
On Mon, 18 Apr 2016, Rainer Orth wrote:
> While updating docs for Solaris, here's a Solaris section for
> gcc-6/changes.html.  Ok?

Looks good to me, thanks.

Gerald


Re: Free up bits in DECLs and TYPEs

2016-04-18 Thread Michael Matz
Hi,

On Thu, 10 Dec 2015, Bernd Schmidt wrote:

> On 12/10/2015 04:04 PM, Michael Matz wrote:
> > This isn't stage 3 material really, OTOH fairly low risk.  Anyway, okay
> > for trunk now or once stage 1 opens?
> 
> This is cool and we want it, but not now. Ok for stage 1, with the 
> formatting problems quoted below fixed.

Did that, reran regstrapping on x86_64-linux (no regressions).  The patch 
still mostly applied, but for completeness the below is what is now 
checked in as r235172.


Ciao,
Michael.

* tree.h (TYPE_ALIGN, DECL_ALIGN): Return shifted amount.
(SET_TYPE_ALIGN, SET_DECL_ALIGN): New.
* tree-core.h (tree_type_common.align): Use bit-field.
(tree_type_common.spare): New.
(tree_decl_common.off_align): Make smaller.
(tree_decl_common.align): Use bit-field.

* expr.c (expand_expr_addr_expr_1): Use SET_TYPE_ALIGN.
* omp-low.c (install_var_field): Use SET_DECL_ALIGN.
(scan_sharing_clauses): Ditto.
(finish_taskreg_scan): Use SET_DECL_ALIGN and SET_TYPE_ALIGN.
(omp_finish_file): Ditto.
* stor-layout.c (do_type_align): Use SET_DECL_ALIGN.
(layout_decl): Ditto.
(relayout_decl): Ditto.
(finalize_record_size): Use SET_TYPE_ALIGN.
(finalize_type_size): Ditto.
(finish_builtin_struct): Ditto.
(layout_type): Ditto.
(initialize_sizetypes): Ditto.
* targhooks.c (std_gimplify_va_arg_expr): Use SET_TYPE_ALIGN.
* tree-nested.c (insert_field_into_struct): Use SET_TYPE_ALIGN.
(lookup_field_for_decl): Use SET_DECL_ALIGN.
(get_chain_field): Ditto.
(get_trampoline_type): Ditto.
(get_nl_goto_field): Ditto.
* tree-streamer-in.c (unpack_ts_decl_common_value_fields): Use
SET_DECL_ALIGN.
(unpack_ts_type_common_value_fields): Use SET_TYPE_ALIGN.
* gimple-expr.c (copy_var_decl): Use SET_DECL_ALIGN.
* tree.c (make_node_stat): Use SET_DECL_ALIGN and SET_TYPE_ALIGN.
(build_qualified_type): Use SET_TYPE_ALIGN.
(build_aligned_type, build_range_type_1): Ditto.
(build_atomic_base): Ditto.
(build_common_tree_nodes): Ditto.
* cfgexpand.c (align_local_variable): Use SET_DECL_ALIGN.
(expand_one_stack_var_at): Ditto.
* coverage.c (build_var): Use SET_DECL_ALIGN.
* except.c (init_eh): Ditto.
* function.c (assign_parm_setup_block): Ditto.
* symtab.c (increase_alignment_1): Ditto.
* tree-ssa-ccp.c (fold_builtin_alloca_with_align): Ditto.
* tree-vect-stmts.c (ensure_base_align): Ditto.
* varasm.c (align_variable): Ditto.
(assemble_variable): Ditto.
(build_constant_desc): Ditto.
(output_constant_def_contents): Ditto.

* config/arm/arm.c (arm_relayout_function): Use SET_DECL_ALIGN.
* config/avr/avr.c (avr_adjust_type_node): Use SET_TYPE_ALIGN.
* config/mips/mips.c (mips_std_gimplify_va_arg_expr): Ditto.
* config/msp430/msp430.c (msp430_gimplify_va_arg_expr): Ditto.
* config/spu/spu.c (spu_build_builtin_va_list): Use SET_DECL_ALIGN.

ada/
* gcc-interface/decl.c (gnat_to_gnu_entity): Use SET_TYPE_ALIGN.
(gnat_to_gnu_field): Ditto.
(components_to_record): Ditto.
(create_variant_part_from): Ditto.
(copy_and_substitute_in_size): Ditto.
(substitute_in_type): Ditto.
* gcc-interface/utils.c (make_aligning_type): Use SET_TYPE_ALIGN.
(make_packable_type): Ditto.
(maybe_pad_type): Ditto.
(finish_fat_pointer_type): Ditto.
(finish_record_type): Ditto and use SET_DECL_ALIGN.
(rest_of_record_type_compilation): Use SET_TYPE_ALIGN.
(create_field_decl): Use SET_DECL_ALIGN.

c-family/
* c-common.c (handle_aligned_attribute): Use SET_TYPE_ALIGN
and SET_DECL_ALIGN.

c/
* c-decl.c (merge_decls): Use SET_DECL_ALIGN and SET_TYPE_ALIGN.
(grokdeclarator, parser_xref_tag, finish_enum): Use SET_TYPE_ALIGN.

cp/
* class.c (build_vtable): Use SET_DECL_ALIGN and SET_TYPE_ALIGN.
(layout_class_type): Ditto.
(build_base_field): Use SET_DECL_ALIGN.
(fixup_attribute_variants): Use SET_TYPE_ALIGN.
* decl.c (duplicate_decls): Use SET_DECL_ALIGN.
(record_unknown_type): Use SET_TYPE_ALIGN.
(cxx_init_decl_processing): Ditto.
(copy_type_enum): Ditto.
(grokfndecl): Use SET_DECL_ALIGN.
(copy_type_enum): Use SET_TYPE_ALIGN.
* pt.c (instantiate_class_template_1): Use SET_TYPE_ALIGN.
(tsubst): Ditto.
* tree.c (cp_build_qualified_type_real): Use SET_TYPE_ALIGN.
* lambda.c (maybe_add_lambda_conv_op): Use SET_DECL_ALIGN.
* method.c (implicitly_declare_fn): Use SET_DECL_ALIGN.
* rtti.c (emit_tinfo_decl): Ditto.

fortran/
* trans-io.c (gfc_build_io_library_fndecls): Use SET_TYPE_ALIGN.
* trans-common.c 

Re: [PATCH, GCC 5] PR 70613, -fabi-version docs don't match implementation

2016-04-18 Thread Jim Wilson

On 04/11/2016 01:41 PM, Jim Wilson wrote:

Here is a patch to correct the -fabi-version docs on the GCC 5 branch.


Ping

https://gcc.gnu.org/ml/gcc-patches/2016-04/msg00480.html

Jim



Re: RFA (6): C++ PATCH for c++/70690, wrong code in tcmalloc

2016-04-18 Thread Jakub Jelinek
On Mon, Apr 18, 2016 at 02:58:51PM -0400, Jason Merrill wrote:
> My change to type_has_constexpr_default_constructor broke build_vec_init,
> which asserts that it implies that default-initialization is the same as
> value-initialization, which is not the case for the "maybe constexpr" case.
> So this patch reverts the change and adds a new "maybe constexpr" entry
> point when we don't need a firm answer.
> 
> Tested x86_64-pc-linux-gnu, applying to trunk.  OK for 6.1?

Ok, thanks.

> commit 695043a6eb769f6510c4d495dacd5d70514c89ab
> Author: Jason Merrill 
> Date:   Mon Apr 18 14:29:19 2016 -0400
> 
>   PR c++/70690
> 
>   PR c++/70528
>   * class.c (type_maybe_constexpr_default_constructor): New.
>   (type_has_constexpr_default_constructor): Revert.

Jakub


Re: [PATCH] PR target/70708: Suboptimal code generated when using _mm_set_sd (X64)

2016-04-18 Thread Uros Bizjak
On Mon, Apr 18, 2016 at 6:07 PM, H.J. Lu  wrote:
> "movq" should used to load double into xmm register with zero_extend:
>
> (set (reg:V2DF 90)
>  (vec_concat:V2DF (reg/v:DF 88 [ d ])
>   (const_double:DF 0.0 [0x0.0p+0])))
>
> Unlike "movsd", which only works with load from memory, "movq" works
> with both memory and xmm register.
>
> OK for trunk if there is no regression?

OK.

Thanks,
Uros.

> H.J.
> --
> gcc/
>
> PR target/70708
> * config/i386/sse.md (sse2_loadlpd): Accept load from "xm" and
> replace %vmovsd with "%vmovq".
> (vec_concatv2df): Likewise.
>
> gcc/testsuite/
>
> PR target/70708
> * gcc.target/i386/pr70708.c: New test.
> ---
>  gcc/config/i386/sse.md  | 12 ++--
>  gcc/testsuite/gcc.target/i386/pr70708.c | 14 ++
>  2 files changed, 20 insertions(+), 6 deletions(-)
>  create mode 100644 gcc/testsuite/gcc.target/i386/pr70708.c
>
> diff --git a/gcc/config/i386/sse.md b/gcc/config/i386/sse.md
> index 1ffb3b9..845ef56 100644
> --- a/gcc/config/i386/sse.md
> +++ b/gcc/config/i386/sse.md
> @@ -8863,14 +8863,14 @@
>   "=x,x,x,x,x,x,x,x,m,m ,m")
> (vec_concat:V2DF
>   (match_operand:DF 2 "nonimmediate_operand"
> - " m,m,m,x,x,0,0,x,x,*f,r")
> + "xm,m,m,x,x,0,0,x,x,*f,r")
>   (vec_select:DF
> (match_operand:V2DF 1 "vector_move_operand"
>   " C,0,x,0,x,x,o,o,0,0 ,0")
> (parallel [(const_int 1)]]
>"TARGET_SSE2 && !(MEM_P (operands[1]) && MEM_P (operands[2]))"
>"@
> -   %vmovsd\t{%2, %0|%0, %2}
> +   %vmovq\t{%2, %0|%0, %2}
> movlpd\t{%2, %0|%0, %2}
> vmovlpd\t{%2, %1, %0|%0, %1, %2}
> movsd\t{%2, %0|%0, %2}
> @@ -8955,10 +8955,10 @@
> (set_attr "mode" "V2DF,DF,DF")])
>
>  (define_insn "vec_concatv2df"
> -  [(set (match_operand:V2DF 0 "register_operand" "=x,x,v,x,v,x,x,v,x,x")
> +  [(set (match_operand:V2DF 0 "register_operand" "=x,x,v,x,v,x,x, v,x,x")
> (vec_concat:V2DF
> - (match_operand:DF 1 "nonimmediate_operand" " 0,x,v,m,m,0,x,m,0,0")
> - (match_operand:DF 2 "vector_move_operand"  " 
> x,x,v,1,1,m,m,C,x,m")))]
> + (match_operand:DF 1 "nonimmediate_operand" " 0,x,v,m,m,0,x,xm,0,0")
> + (match_operand:DF 2 "vector_move_operand"  " x,x,v,1,1,m,m, 
> C,x,m")))]
>"TARGET_SSE
> && (!(MEM_P (operands[1]) && MEM_P (operands[2]))
> || (TARGET_SSE3 && rtx_equal_p (operands[1], operands[2])))"
> @@ -8970,7 +8970,7 @@
> vmovddup\t{%1, %0|%0, %1}
> movhpd\t{%2, %0|%0, %2}
> vmovhpd\t{%2, %1, %0|%0, %1, %2}
> -   %vmovsd\t{%1, %0|%0, %1}
> +   %vmovq\t{%1, %0|%0, %1}
> movlhps\t{%2, %0|%0, %2}
> movhps\t{%2, %0|%0, %2}"
>[(set_attr "isa" 
> "sse2_noavx,avx,avx512vl,sse3,avx512vl,sse2_noavx,avx,sse2,noavx,noavx")
> diff --git a/gcc/testsuite/gcc.target/i386/pr70708.c 
> b/gcc/testsuite/gcc.target/i386/pr70708.c
> new file mode 100644
> index 000..2219e61
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/i386/pr70708.c
> @@ -0,0 +1,14 @@
> +/* { dg-do compile } */
> +/* { dg-options "-O2 -msse2" } */
> +
> +typedef double __m128d __attribute__ ((__vector_size__ (16), __may_alias__));
> +
> +__m128d
> +foo (double d)
> +{
> +  return __extension__ (__m128d){ d, 0.0 };
> +}
> +
> +/* { dg-final { scan-assembler-times "movq\[ \\t\]+\[^\n\]*%xmm" 1 } } */
> +/* { dg-final { scan-assembler-not "movsd\[ \\t\]+\[^\n\]*%xmm" } } */
> +/* { dg-final { scan-assembler-not "\\(%\[er\]sp\\)" { target { ! ia32 } }} 
> } */
> --
> 2.5.5
>


Re: [PATCH] Remove UNSPEC_LOADU and UNSPEC_STOREU

2016-04-18 Thread Uros Bizjak
On Mon, Apr 18, 2016 at 9:17 PM, H.J. Lu  wrote:

>>> Here is the updated patch for GCC 7.  Tested on x86-64.  OK for
>>> trrunk?
>>
>> IIRC from previous discussion, are we sure we won't propagate
>> unaligned memory into SSE arithmetic insns?
>
> Yes, it is true and it is what
>
> (define_special_memory_constraint "Bm"
>   "@internal Vector memory operand."
>   (match_operand 0 "vector_memory_operand"))
>
> is used for.

Yes, indeed.

Thanks,
Uros.


Re: [PATCH] Remove UNSPEC_LOADU and UNSPEC_STOREU

2016-04-18 Thread H.J. Lu
On Mon, Apr 18, 2016 at 12:13 PM, Uros Bizjak  wrote:
> On Mon, Apr 18, 2016 at 8:40 PM, H.J. Lu  wrote:
>> On Sun, Jan 10, 2016 at 11:45 PM, Uros Bizjak  wrote:
>>> On Sun, Jan 10, 2016 at 11:32 PM, H.J. Lu  wrote:
 Since *mov_internal and _(load|store)_mask patterns
 can handle unaligned load and store, we can remove UNSPEC_LOADU and
 UNSPEC_STOREU.  We use function prototypes with pointer to scalar for
 unaligned load/store builtin functions so that memory passed to
 *mov_internal is unaligned.

 Tested on x86-64.  Is this OK for trunk in stage 3?
>>>
>>> This patch is not appropriate for stage 3.
>>>
>>> Uros.
>>>
 H.J.
 
 gcc/

 PR target/69201
 * config/i386/avx512bwintrin.h (_mm512_mask_loadu_epi16): Pass
 const short * to __builtin_ia32_loaddquhi512_mask.
 (_mm512_maskz_loadu_epi16): Likewise.
 (_mm512_mask_storeu_epi16): Pass short * to
 __builtin_ia32_storedquhi512_mask.
 (_mm512_mask_loadu_epi8): Pass const char * to
 __builtin_ia32_loaddquqi512_mask.
 (_mm512_maskz_loadu_epi8): Likewise.
 (_mm512_mask_storeu_epi8): Pass char * to
 __builtin_ia32_storedquqi512_mask.
 * config/i386/avx512fintrin.h (_mm512_loadu_pd): Pass
 const double * to __builtin_ia32_loadupd512_mask.
 (_mm512_mask_loadu_pd): Likewise.
 (_mm512_maskz_loadu_pd): Likewise.
 (_mm512_storeu_pd): Pass double * to
 __builtin_ia32_storeupd512_mask.
 (_mm512_mask_storeu_pd): Likewise.
 (_mm512_loadu_ps): Pass const float * to
 __builtin_ia32_loadups512_mask.
 (_mm512_mask_loadu_ps): Likewise.
 (_mm512_maskz_loadu_ps): Likewise.
 (_mm512_storeu_ps): Pass float * to
 __builtin_ia32_storeups512_mask.
 (_mm512_mask_storeu_ps): Likewise.
 (_mm512_mask_loadu_epi64): Pass const long long * to
 __builtin_ia32_loaddqudi512_mask.
 (_mm512_maskz_loadu_epi64): Likewise.
 (_mm512_mask_storeu_epi64): Pass long long *
 to __builtin_ia32_storedqudi512_mask.
 (_mm512_loadu_si512): Pass const int * to
 __builtin_ia32_loaddqusi512_mask.
 (_mm512_mask_loadu_epi32): Likewise.
 (_mm512_maskz_loadu_epi32): Likewise.
 (_mm512_storeu_si512): Pass int * to
 __builtin_ia32_storedqusi512_mask.
 (_mm512_mask_storeu_epi32): Likewise.
 * config/i386/avx512vlbwintrin.h (_mm256_mask_storeu_epi8): Pass
 char * to __builtin_ia32_storedquqi256_mask.
 (_mm_mask_storeu_epi8): Likewise.
 (_mm256_mask_loadu_epi16): Pass const short * to
 __builtin_ia32_loaddquhi256_mask.
 (_mm256_maskz_loadu_epi16): Likewise.
 (_mm_mask_loadu_epi16): Pass const short * to
 __builtin_ia32_loaddquhi128_mask.
 (_mm_maskz_loadu_epi16): Likewise.
 (_mm256_mask_loadu_epi8): Pass const char * to
 __builtin_ia32_loaddquqi256_mask.
 (_mm256_maskz_loadu_epi8): Likewise.
 (_mm_mask_loadu_epi8): Pass const char * to
 __builtin_ia32_loaddquqi128_mask.
 (_mm_maskz_loadu_epi8): Likewise.
 (_mm256_mask_storeu_epi16): Pass short * to.
 __builtin_ia32_storedquhi256_mask.
 (_mm_mask_storeu_epi16): Pass short * to.
 __builtin_ia32_storedquhi128_mask.
 * config/i386/avx512vlintrin.h (_mm256_mask_loadu_pd): Pass
 const double * to __builtin_ia32_loadupd256_mask.
 (_mm256_maskz_loadu_pd): Likewise.
 (_mm_mask_loadu_pd): Pass onst double * to
 __builtin_ia32_loadupd128_mask.
 (_mm_maskz_loadu_pd): Likewise.
 (_mm256_mask_storeu_pd): Pass double * to
 __builtin_ia32_storeupd256_mask.
 (_mm_mask_storeu_pd): Pass double * to
 __builtin_ia32_storeupd128_mask.
 (_mm256_mask_loadu_ps): Pass const float * to
 __builtin_ia32_loadups256_mask.
 (_mm256_maskz_loadu_ps): Likewise.
 (_mm_mask_loadu_ps): Pass const float * to
 __builtin_ia32_loadups128_mask.
 (_mm_maskz_loadu_ps): Likewise.
 (_mm256_mask_storeu_ps): Pass float * to
 __builtin_ia32_storeups256_mask.
 (_mm_mask_storeu_ps): ass float * to
 __builtin_ia32_storeups128_mask.
 (_mm256_mask_loadu_epi64): Pass const long long * to
 __builtin_ia32_loaddqudi256_mask.
 (_mm256_maskz_loadu_epi64): Likewise.
 (_mm_mask_loadu_epi64): Pass const long long * to
 __builtin_ia32_loaddqudi128_mask.

Re: [PATCH] Remove UNSPEC_LOADU and UNSPEC_STOREU

2016-04-18 Thread Uros Bizjak
On Mon, Apr 18, 2016 at 8:40 PM, H.J. Lu  wrote:
> On Sun, Jan 10, 2016 at 11:45 PM, Uros Bizjak  wrote:
>> On Sun, Jan 10, 2016 at 11:32 PM, H.J. Lu  wrote:
>>> Since *mov_internal and _(load|store)_mask patterns
>>> can handle unaligned load and store, we can remove UNSPEC_LOADU and
>>> UNSPEC_STOREU.  We use function prototypes with pointer to scalar for
>>> unaligned load/store builtin functions so that memory passed to
>>> *mov_internal is unaligned.
>>>
>>> Tested on x86-64.  Is this OK for trunk in stage 3?
>>
>> This patch is not appropriate for stage 3.
>>
>> Uros.
>>
>>> H.J.
>>> 
>>> gcc/
>>>
>>> PR target/69201
>>> * config/i386/avx512bwintrin.h (_mm512_mask_loadu_epi16): Pass
>>> const short * to __builtin_ia32_loaddquhi512_mask.
>>> (_mm512_maskz_loadu_epi16): Likewise.
>>> (_mm512_mask_storeu_epi16): Pass short * to
>>> __builtin_ia32_storedquhi512_mask.
>>> (_mm512_mask_loadu_epi8): Pass const char * to
>>> __builtin_ia32_loaddquqi512_mask.
>>> (_mm512_maskz_loadu_epi8): Likewise.
>>> (_mm512_mask_storeu_epi8): Pass char * to
>>> __builtin_ia32_storedquqi512_mask.
>>> * config/i386/avx512fintrin.h (_mm512_loadu_pd): Pass
>>> const double * to __builtin_ia32_loadupd512_mask.
>>> (_mm512_mask_loadu_pd): Likewise.
>>> (_mm512_maskz_loadu_pd): Likewise.
>>> (_mm512_storeu_pd): Pass double * to
>>> __builtin_ia32_storeupd512_mask.
>>> (_mm512_mask_storeu_pd): Likewise.
>>> (_mm512_loadu_ps): Pass const float * to
>>> __builtin_ia32_loadups512_mask.
>>> (_mm512_mask_loadu_ps): Likewise.
>>> (_mm512_maskz_loadu_ps): Likewise.
>>> (_mm512_storeu_ps): Pass float * to
>>> __builtin_ia32_storeups512_mask.
>>> (_mm512_mask_storeu_ps): Likewise.
>>> (_mm512_mask_loadu_epi64): Pass const long long * to
>>> __builtin_ia32_loaddqudi512_mask.
>>> (_mm512_maskz_loadu_epi64): Likewise.
>>> (_mm512_mask_storeu_epi64): Pass long long *
>>> to __builtin_ia32_storedqudi512_mask.
>>> (_mm512_loadu_si512): Pass const int * to
>>> __builtin_ia32_loaddqusi512_mask.
>>> (_mm512_mask_loadu_epi32): Likewise.
>>> (_mm512_maskz_loadu_epi32): Likewise.
>>> (_mm512_storeu_si512): Pass int * to
>>> __builtin_ia32_storedqusi512_mask.
>>> (_mm512_mask_storeu_epi32): Likewise.
>>> * config/i386/avx512vlbwintrin.h (_mm256_mask_storeu_epi8): Pass
>>> char * to __builtin_ia32_storedquqi256_mask.
>>> (_mm_mask_storeu_epi8): Likewise.
>>> (_mm256_mask_loadu_epi16): Pass const short * to
>>> __builtin_ia32_loaddquhi256_mask.
>>> (_mm256_maskz_loadu_epi16): Likewise.
>>> (_mm_mask_loadu_epi16): Pass const short * to
>>> __builtin_ia32_loaddquhi128_mask.
>>> (_mm_maskz_loadu_epi16): Likewise.
>>> (_mm256_mask_loadu_epi8): Pass const char * to
>>> __builtin_ia32_loaddquqi256_mask.
>>> (_mm256_maskz_loadu_epi8): Likewise.
>>> (_mm_mask_loadu_epi8): Pass const char * to
>>> __builtin_ia32_loaddquqi128_mask.
>>> (_mm_maskz_loadu_epi8): Likewise.
>>> (_mm256_mask_storeu_epi16): Pass short * to.
>>> __builtin_ia32_storedquhi256_mask.
>>> (_mm_mask_storeu_epi16): Pass short * to.
>>> __builtin_ia32_storedquhi128_mask.
>>> * config/i386/avx512vlintrin.h (_mm256_mask_loadu_pd): Pass
>>> const double * to __builtin_ia32_loadupd256_mask.
>>> (_mm256_maskz_loadu_pd): Likewise.
>>> (_mm_mask_loadu_pd): Pass onst double * to
>>> __builtin_ia32_loadupd128_mask.
>>> (_mm_maskz_loadu_pd): Likewise.
>>> (_mm256_mask_storeu_pd): Pass double * to
>>> __builtin_ia32_storeupd256_mask.
>>> (_mm_mask_storeu_pd): Pass double * to
>>> __builtin_ia32_storeupd128_mask.
>>> (_mm256_mask_loadu_ps): Pass const float * to
>>> __builtin_ia32_loadups256_mask.
>>> (_mm256_maskz_loadu_ps): Likewise.
>>> (_mm_mask_loadu_ps): Pass const float * to
>>> __builtin_ia32_loadups128_mask.
>>> (_mm_maskz_loadu_ps): Likewise.
>>> (_mm256_mask_storeu_ps): Pass float * to
>>> __builtin_ia32_storeups256_mask.
>>> (_mm_mask_storeu_ps): ass float * to
>>> __builtin_ia32_storeups128_mask.
>>> (_mm256_mask_loadu_epi64): Pass const long long * to
>>> __builtin_ia32_loaddqudi256_mask.
>>> (_mm256_maskz_loadu_epi64): Likewise.
>>> (_mm_mask_loadu_epi64): Pass const long long * to
>>> __builtin_ia32_loaddqudi128_mask.
>>> (_mm_maskz_loadu_epi64): Likewise.
>>> (_mm256_mask_storeu_epi64): Pass long long * to
>>> __builtin_ia32_storedqudi256_mask.
>>> 

[PATCH, i386]: Use gen_lowpart some more

2016-04-18 Thread Uros Bizjak
Hello!

After middle-end fix for PR69577 [1] allowed us to relax
ix86_cannot_change_mode_class conditions, we can substitute:

-{
-  if (REG_P (operands[1]))
-operands[1] = gen_rtx_REG (SImode, REGNO (operands[1]));
-  else
-operands[1] = adjust_address (operands[1], SImode, 0);
-})

with a gen_lowpart call that is now able to handle both, register and
memory operands:

+  "operands[1] = gen_lowpart (SImode, operands[1]);")

There are some places that generate paradoxical subregs, disallowed by
gen_lowpart. Use lowpart_subreg instead of gen_reg_RTX here.

2016-04-18  Uros Bizjak  

* config/i386/mmx.md (*vec_extractv2sf_0): Use gen_lowpart.
(*vec_extractv2si_0): Ditto.
* config/i386/sse.md (*vec_extractv4sf_0): Ditto.
(zero_extended_scalar_load_operand splitters): Ditto.
(vec_extract splitters): Ditto.
(*vec_extractv4si_0_zext): Ditto.
(avx__): Use gen_lowpart
and lowpart_subreg.
(avx512f__): Ditto.
(avx512f__256): Ditto.
(*sse4_1_extractps): Use lowpart_subreg.

Patch was bootstrapped and regression tested on x86_64-linux-gnu {,-m32}.

Committed to mainline SVN.

[1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69577

Uros.
diff --git a/gcc/config/i386/mmx.md b/gcc/config/i386/mmx.md
index a2e7231..9a239c2f 100644
--- a/gcc/config/i386/mmx.md
+++ b/gcc/config/i386/mmx.md
@@ -590,12 +590,7 @@
   "#"
   "&& reload_completed"
   [(set (match_dup 0) (match_dup 1))]
-{
-  if (REG_P (operands[1]))
-operands[1] = gen_rtx_REG (SFmode, REGNO (operands[1]));
-  else
-operands[1] = adjust_address (operands[1], SFmode, 0);
-})
+  "operands[1] = gen_lowpart (SFmode, operands[1]);")
 
 ;; Avoid combining registers from different units in a single alternative,
 ;; see comment above inline_secondary_memory_needed function in i386.c
@@ -1283,12 +1278,7 @@
   "#"
   "&& reload_completed"
   [(set (match_dup 0) (match_dup 1))]
-{
-  if (REG_P (operands[1]))
-operands[1] = gen_rtx_REG (SImode, REGNO (operands[1]));
-  else
-operands[1] = adjust_address (operands[1], SImode, 0);
-})
+  "operands[1] = gen_lowpart (SImode, operands[1]);")
 
 ;; Avoid combining registers from different units in a single alternative,
 ;; see comment above inline_secondary_memory_needed function in i386.c
diff --git a/gcc/config/i386/sse.md b/gcc/config/i386/sse.md
index 1ffb3b9..2a01dc9 100644
--- a/gcc/config/i386/sse.md
+++ b/gcc/config/i386/sse.md
@@ -1131,7 +1131,7 @@
  (match_dup 2)
  (const_int 1)))]
 {
-  operands[1] = simplify_gen_subreg (SFmode, operands[1], V4SFmode, 0);
+  operands[1] = gen_lowpart (SFmode, operands[1]);
   operands[2] = CONST0_RTX (V4SFmode);
 })
 
@@ -1141,7 +1141,7 @@
   "TARGET_SSE2 && reload_completed"
   [(set (match_dup 0) (vec_concat:V2DF (match_dup 1) (match_dup 2)))]
 {
-  operands[1] = simplify_gen_subreg (DFmode, operands[1], V2DFmode, 0);
+  operands[1] = gen_lowpart (DFmode, operands[1]);
   operands[2] = CONST0_RTX (DFmode);
 })
 
@@ -5993,7 +5993,8 @@
   else
{
  tmp[5] = gen_reg_rtx (V8SFmode);
- ix86_expand_vec_extract_even_odd (tmp[5], gen_lowpart (V8SFmode, 
tmp[2]),
+ ix86_expand_vec_extract_even_odd (tmp[5],
+   gen_lowpart (V8SFmode, tmp[2]),
gen_lowpart (V8SFmode, tmp[3]), 0);
  tmp[5] = gen_lowpart (V8SImode, tmp[5]);
}
@@ -6968,12 +6969,7 @@
   "#"
   "&& reload_completed"
   [(set (match_dup 0) (match_dup 1))]
-{
-  if (REG_P (operands[1]))
-operands[1] = gen_rtx_REG (SFmode, REGNO (operands[1]));
-  else
-operands[1] = adjust_address (operands[1], SFmode, 0);
-})
+  "operands[1] = gen_lowpart (SFmode, operands[1]);")
 
 (define_insn_and_split "*sse4_1_extractps"
   [(set (match_operand:SF 0 "nonimmediate_operand" "=rm,rm,x,x")
@@ -6989,7 +6985,7 @@
   "&& reload_completed && SSE_REG_P (operands[0])"
   [(const_int 0)]
 {
-  rtx dest = gen_rtx_REG (V4SFmode, REGNO (operands[0]));
+  rtx dest = lowpart_subreg (V4SFmode, operands[0], SFmode);
   switch (INTVAL (operands[2]))
 {
 case 1:
@@ -7200,18 +7196,11 @@
  (parallel [(const_int 0) (const_int 1)
 (const_int 2) (const_int 3)])))]
   "TARGET_AVX512F && !(MEM_P (operands[0]) && MEM_P (operands[1]))
-  && reload_completed
-  && (TARGET_AVX512VL || (REG_P (operands[0]) && !EXT_REX_SSE_REG_P 
(operands[1])))"
-  [(const_int 0)]
-{
-  rtx op1 = operands[1];
-  if (REG_P (op1))
-op1 = gen_rtx_REG (mode, REGNO (op1));
-  else
-op1 = gen_lowpart (mode, op1);
-  emit_move_insn (operands[0], op1);
-  DONE;
-})
+   && reload_completed
+   && (TARGET_AVX512VL
+   || (REG_P (operands[0]) && !EXT_REX_SSE_REG_P (operands[1])))"
+  [(set (match_dup 0) (match_dup 1))]
+  "operands[1] = gen_lowpart (mode, operands[1]);")
 
 (define_insn "vec_extract_lo__maskm"
   [(set (match_operand: 0 "memory_operand" "=m")
@@ -7403,16 +7392,8 @@
(const_int 6) (const_int 7)])))]
 

RFA (6): C++ PATCH for c++/70690, wrong code in tcmalloc

2016-04-18 Thread Jason Merrill
My change to type_has_constexpr_default_constructor broke 
build_vec_init, which asserts that it implies that 
default-initialization is the same as value-initialization, which is not 
the case for the "maybe constexpr" case.  So this patch reverts the 
change and adds a new "maybe constexpr" entry point when we don't need a 
firm answer.


Tested x86_64-pc-linux-gnu, applying to trunk.  OK for 6.1?
commit 695043a6eb769f6510c4d495dacd5d70514c89ab
Author: Jason Merrill 
Date:   Mon Apr 18 14:29:19 2016 -0400

	PR c++/70690

	PR c++/70528
	* class.c (type_maybe_constexpr_default_constructor): New.
	(type_has_constexpr_default_constructor): Revert.

diff --git a/gcc/cp/class.c b/gcc/cp/class.c
index e6d5bb0..2c5ce73 100644
--- a/gcc/cp/class.c
+++ b/gcc/cp/class.c
@@ -214,6 +214,7 @@ static bool base_derived_from (tree, tree);
 static int empty_base_at_nonzero_offset_p (tree, tree, splay_tree);
 static tree end_of_base (tree);
 static tree get_vcall_index (tree, tree);
+static bool type_maybe_constexpr_default_constructor (tree);
 
 /* Variables shared between class.c and call.c.  */
 
@@ -3346,7 +3347,11 @@ add_implicitly_declared_members (tree t, tree* access_decls,
   CLASSTYPE_LAZY_DEFAULT_CTOR (t) = 1;
   if (cxx_dialect >= cxx11)
 	TYPE_HAS_CONSTEXPR_CTOR (t)
-	  = type_has_constexpr_default_constructor (t);
+	  /* Don't force the declaration to get a hard answer; if the
+	 definition would have made the class non-literal, it will still be
+	 non-literal because of the base or member in question, and that
+	 gives a better diagnostic.  */
+	  = type_maybe_constexpr_default_constructor (t);
 }
 
   /* [class.ctor]
@@ -5348,16 +5353,28 @@ type_has_constexpr_default_constructor (tree t)
 {
   if (!TYPE_HAS_COMPLEX_DFLT (t))
 	return trivial_default_constructor_is_constexpr (t);
-  /* Assume it's constexpr to avoid unnecessary instantiation; if the
-	 definition would have made the class non-literal, it will still be
-	 non-literal because of the base or member in question, and that
-	 gives a better diagnostic.  */
-  return true;
+  /* Non-trivial, we need to check subobject constructors.  */
+  lazily_declare_fn (sfk_constructor, t);
 }
   fns = locate_ctor (t);
   return (fns && DECL_DECLARED_CONSTEXPR_P (fns));
 }
 
+/* Returns true iff class T has a constexpr default constructor or has an
+   implicitly declared default constructor that we can't tell if it's constexpr
+   without forcing a lazy declaration (which might cause undesired
+   instantiations).  */
+
+bool
+type_maybe_constexpr_default_constructor (tree t)
+{
+  if (CLASS_TYPE_P (t) && CLASSTYPE_LAZY_DEFAULT_CTOR (t)
+  && TYPE_HAS_COMPLEX_DFLT (t))
+/* Assume it's constexpr.  */
+return true;
+  return type_has_constexpr_default_constructor (t);
+}
+
 /* Returns true iff class TYPE has a virtual destructor.  */
 
 bool
diff --git a/gcc/testsuite/g++.dg/init/array41.C b/gcc/testsuite/g++.dg/init/array41.C
new file mode 100644
index 000..e8ee181
--- /dev/null
+++ b/gcc/testsuite/g++.dg/init/array41.C
@@ -0,0 +1,27 @@
+// PR c++/70690
+// { dg-do run }
+
+struct A {
+  A() {}
+};
+
+struct APadded : public A {
+  char pad[63];
+};
+
+int f();
+int i = f();
+APadded cache[50];
+APadded *p = cache;
+
+int f()
+{
+  cache[0].pad[0] = 42;
+  return 1;
+}
+
+int main()
+{
+  if (cache[0].pad[0] != 42)
+__builtin_abort();
+}


Re: [PATCH] Remove UNSPEC_LOADU and UNSPEC_STOREU

2016-04-18 Thread H.J. Lu
On Sun, Jan 10, 2016 at 11:45 PM, Uros Bizjak  wrote:
> On Sun, Jan 10, 2016 at 11:32 PM, H.J. Lu  wrote:
>> Since *mov_internal and _(load|store)_mask patterns
>> can handle unaligned load and store, we can remove UNSPEC_LOADU and
>> UNSPEC_STOREU.  We use function prototypes with pointer to scalar for
>> unaligned load/store builtin functions so that memory passed to
>> *mov_internal is unaligned.
>>
>> Tested on x86-64.  Is this OK for trunk in stage 3?
>
> This patch is not appropriate for stage 3.
>
> Uros.
>
>> H.J.
>> 
>> gcc/
>>
>> PR target/69201
>> * config/i386/avx512bwintrin.h (_mm512_mask_loadu_epi16): Pass
>> const short * to __builtin_ia32_loaddquhi512_mask.
>> (_mm512_maskz_loadu_epi16): Likewise.
>> (_mm512_mask_storeu_epi16): Pass short * to
>> __builtin_ia32_storedquhi512_mask.
>> (_mm512_mask_loadu_epi8): Pass const char * to
>> __builtin_ia32_loaddquqi512_mask.
>> (_mm512_maskz_loadu_epi8): Likewise.
>> (_mm512_mask_storeu_epi8): Pass char * to
>> __builtin_ia32_storedquqi512_mask.
>> * config/i386/avx512fintrin.h (_mm512_loadu_pd): Pass
>> const double * to __builtin_ia32_loadupd512_mask.
>> (_mm512_mask_loadu_pd): Likewise.
>> (_mm512_maskz_loadu_pd): Likewise.
>> (_mm512_storeu_pd): Pass double * to
>> __builtin_ia32_storeupd512_mask.
>> (_mm512_mask_storeu_pd): Likewise.
>> (_mm512_loadu_ps): Pass const float * to
>> __builtin_ia32_loadups512_mask.
>> (_mm512_mask_loadu_ps): Likewise.
>> (_mm512_maskz_loadu_ps): Likewise.
>> (_mm512_storeu_ps): Pass float * to
>> __builtin_ia32_storeups512_mask.
>> (_mm512_mask_storeu_ps): Likewise.
>> (_mm512_mask_loadu_epi64): Pass const long long * to
>> __builtin_ia32_loaddqudi512_mask.
>> (_mm512_maskz_loadu_epi64): Likewise.
>> (_mm512_mask_storeu_epi64): Pass long long *
>> to __builtin_ia32_storedqudi512_mask.
>> (_mm512_loadu_si512): Pass const int * to
>> __builtin_ia32_loaddqusi512_mask.
>> (_mm512_mask_loadu_epi32): Likewise.
>> (_mm512_maskz_loadu_epi32): Likewise.
>> (_mm512_storeu_si512): Pass int * to
>> __builtin_ia32_storedqusi512_mask.
>> (_mm512_mask_storeu_epi32): Likewise.
>> * config/i386/avx512vlbwintrin.h (_mm256_mask_storeu_epi8): Pass
>> char * to __builtin_ia32_storedquqi256_mask.
>> (_mm_mask_storeu_epi8): Likewise.
>> (_mm256_mask_loadu_epi16): Pass const short * to
>> __builtin_ia32_loaddquhi256_mask.
>> (_mm256_maskz_loadu_epi16): Likewise.
>> (_mm_mask_loadu_epi16): Pass const short * to
>> __builtin_ia32_loaddquhi128_mask.
>> (_mm_maskz_loadu_epi16): Likewise.
>> (_mm256_mask_loadu_epi8): Pass const char * to
>> __builtin_ia32_loaddquqi256_mask.
>> (_mm256_maskz_loadu_epi8): Likewise.
>> (_mm_mask_loadu_epi8): Pass const char * to
>> __builtin_ia32_loaddquqi128_mask.
>> (_mm_maskz_loadu_epi8): Likewise.
>> (_mm256_mask_storeu_epi16): Pass short * to.
>> __builtin_ia32_storedquhi256_mask.
>> (_mm_mask_storeu_epi16): Pass short * to.
>> __builtin_ia32_storedquhi128_mask.
>> * config/i386/avx512vlintrin.h (_mm256_mask_loadu_pd): Pass
>> const double * to __builtin_ia32_loadupd256_mask.
>> (_mm256_maskz_loadu_pd): Likewise.
>> (_mm_mask_loadu_pd): Pass onst double * to
>> __builtin_ia32_loadupd128_mask.
>> (_mm_maskz_loadu_pd): Likewise.
>> (_mm256_mask_storeu_pd): Pass double * to
>> __builtin_ia32_storeupd256_mask.
>> (_mm_mask_storeu_pd): Pass double * to
>> __builtin_ia32_storeupd128_mask.
>> (_mm256_mask_loadu_ps): Pass const float * to
>> __builtin_ia32_loadups256_mask.
>> (_mm256_maskz_loadu_ps): Likewise.
>> (_mm_mask_loadu_ps): Pass const float * to
>> __builtin_ia32_loadups128_mask.
>> (_mm_maskz_loadu_ps): Likewise.
>> (_mm256_mask_storeu_ps): Pass float * to
>> __builtin_ia32_storeups256_mask.
>> (_mm_mask_storeu_ps): ass float * to
>> __builtin_ia32_storeups128_mask.
>> (_mm256_mask_loadu_epi64): Pass const long long * to
>> __builtin_ia32_loaddqudi256_mask.
>> (_mm256_maskz_loadu_epi64): Likewise.
>> (_mm_mask_loadu_epi64): Pass const long long * to
>> __builtin_ia32_loaddqudi128_mask.
>> (_mm_maskz_loadu_epi64): Likewise.
>> (_mm256_mask_storeu_epi64): Pass long long * to
>> __builtin_ia32_storedqudi256_mask.
>> (_mm_mask_storeu_epi64): Pass long long * to
>> __builtin_ia32_storedqudi128_mask.
>> (_mm256_mask_loadu_epi32): Pass const int * to
>> 

Re: [PATCH 6/6] [ARC] Various instruction pattern fixes

2016-04-18 Thread Claudiu Zissulescu
Forgot to add the reload cases. Here it is the updated patch.

//Claudiu


gcc/
2016-04-18  Claudiu Zissulescu  

* config/arc/arc.md (mulsidi3): Change operand 0 predicate to
register_operand.
(umulsidi3): Likewise.
(indirect_jump): Fix jump instruction assembly patterns.
(arcset): Change operand 1 predicate to nonmemory_operand.
(arcsetltu, arcsetgeu): Likewise.
(arcsethi, arcsetls): Fix pattern.
---
 gcc/config/arc/arc.md | 146 --
 1 file changed, 83 insertions(+), 63 deletions(-)

diff --git a/gcc/config/arc/arc.md b/gcc/config/arc/arc.md
index 6731072..9d87b76 100644
--- a/gcc/config/arc/arc.md
+++ b/gcc/config/arc/arc.md
@@ -1964,7 +1964,7 @@
   (set_attr "cond" "nocond,canuse,nocond,canuse_limm,canuse,nocond")])
 
 (define_expand "mulsidi3"
-  [(set (match_operand:DI 0 "nonimmediate_operand" "")
+  [(set (match_operand:DI 0 "register_operand" "")
(mult:DI (sign_extend:DI(match_operand:SI 1 "register_operand" ""))
 (sign_extend:DI(match_operand:SI 2 "nonmemory_operand" ""]
   "TARGET_ANY_MPY"
@@ -2200,9 +2200,9 @@
 }")
 
 (define_expand "umulsidi3"
-  [(set (match_operand:DI 0 "nonimmediate_operand" "")
-   (mult:DI (zero_extend:DI(match_operand:SI 1 "register_operand" ""))
-(zero_extend:DI(match_operand:SI 2 "nonmemory_operand" ""]
+  [(set (match_operand:DI 0 "register_operand" "")
+   (mult:DI (zero_extend:DI (match_operand:SI 1 "register_operand" ""))
+(zero_extend:DI (match_operand:SI 2 "nonmemory_operand" ""]
   ""
 {
   if (TARGET_MPY)
@@ -3673,7 +3673,12 @@
 (define_insn "indirect_jump"
   [(set (pc) (match_operand:SI 0 "nonmemory_operand" "L,I,Cal,Rcqq,r"))]
   ""
-  "j%!%* [%0]%&"
+  "@
+   j%!%* %0%&
+   j%!%* %0%&
+   j%!%* %0%&
+   j%!%* [%0]%&
+   j%!%* [%0]%&"
   [(set_attr "type" "jump")
(set_attr "iscompact" "false,false,false,maybe,false")
(set_attr "cond" "canuse,canuse_limm,canuse,canuse,canuse")])
@@ -5425,90 +5430,105 @@
 (define_code_iterator arcCC_cond [eq ne gt lt ge le])
 
 (define_insn "arcset"
-  [(set (match_operand:SI 0 "register_operand""=r,r,r,r,r,r,r")
-   (arcCC_cond:SI (match_operand:SI 1 "register_operand"  "0,r,0,r,0,0,r")
-  (match_operand:SI 2 "nonmemory_operand" 
"r,r,L,L,I,n,n")))]
-  "TARGET_V2 && TARGET_CODE_DENSITY"
+  [(set (match_operand:SI 0 "register_operand"
"=r,r,r,r,r,r,r,r")
+   (arcCC_cond:SI (match_operand:SI 1 "nonmemory_operand" 
"0,r,n,0,r,0,0,r")
+  (match_operand:SI 2 "nonmemory_operand" 
"r,r,r,L,L,I,n,n")))]
+  "TARGET_V2 && TARGET_CODE_DENSITY
+   && (register_operand (operands[1], SImode)
+   || register_operand (operands[2], SImode))"
   "set%? %0, %1, %2"
-  [(set_attr "length" "4,4,4,4,4,8,8")
+  [(set_attr "length" "4,4,8,4,4,4,8,8")
(set_attr "iscompact" "false")
(set_attr "type" "compare")
-   (set_attr "predicable" "yes,no,yes,no,no,yes,no")
-   (set_attr "cond" "canuse,nocond,canuse,nocond,nocond,canuse,nocond")
+   (set_attr "predicable" "yes,no,no,yes,no,no,yes,no")
+   (set_attr "cond" "canuse,nocond,nocond,canuse,nocond,nocond,canuse,nocond")
])
 
 (define_insn "arcsetltu"
-  [(set (match_operand:SI 0 "register_operand" "=r,r,r,r,r,  r,  r")
-   (ltu:SI (match_operand:SI 1 "register_operand"  "0,r,0,r,0,  0,  r")
-   (match_operand:SI 2 "nonmemory_operand" "r,r,L,L,I,  n,  n")))]
-  "TARGET_V2 && TARGET_CODE_DENSITY"
+  [(set (match_operand:SI 0 "register_operand" "=r,r,r,r,r,r,  r,  r")
+   (ltu:SI (match_operand:SI 1 "nonmemory_operand" "0,r,n,0,r,0,  0,  r")
+   (match_operand:SI 2 "nonmemory_operand" "r,r,r,L,L,I,  n,  
n")))]
+  "TARGET_V2 && TARGET_CODE_DENSITY
+   && (register_operand (operands[1], SImode)
+   || register_operand (operands[2], SImode))"
   "setlo%? %0, %1, %2"
-  [(set_attr "length" "4,4,4,4,4,8,8")
+  [(set_attr "length" "4,4,8,4,4,4,8,8")
(set_attr "iscompact" "false")
(set_attr "type" "compare")
-   (set_attr "predicable" "yes,no,yes,no,no,yes,no")
-   (set_attr "cond" "canuse,nocond,canuse,nocond,nocond,canuse,nocond")
+   (set_attr "predicable" "yes,no,no,yes,no,no,yes,no")
+   (set_attr "cond" "canuse,nocond,nocond,canuse,nocond,nocond,canuse,nocond")
])
 
 (define_insn "arcsetgeu"
-  [(set (match_operand:SI 0 "register_operand" "=r,r,r,r,r,  r,  r")
-   (geu:SI (match_operand:SI 1 "register_operand"  "0,r,0,r,0,  0,  r")
-   (match_operand:SI 2 "nonmemory_operand" "r,r,L,L,I,  n,  n")))]
-  "TARGET_V2 && TARGET_CODE_DENSITY"
+  [(set (match_operand:SI 0 "register_operand" "=r,r,r,r,r,r,  r,  r")
+   (geu:SI (match_operand:SI 1 "nonmemory_operand" "0,r,n,0,r,0,  0,  r")
+   (match_operand:SI 2 "nonmemory_operand" "r,r,r,L,L,I,  n,  
n")))]
+  "TARGET_V2 && TARGET_CODE_DENSITY
+   && 

[patch] libstdc++/41759 reword static assertions in

2016-04-18 Thread Jonathan Wakely

The PR suggests using the positive condition for the static assert
message. This patch changes them from the negative condition, to a
statement about what must be true, which I think is better.

Tested x86_64-linux, committed to trunk.

commit 5f1930b675737caeb14e55e12a65f97ba96f992b
Author: Jonathan Wakely 
Date:   Wed Apr 8 17:32:47 2015 +0100

PR libstdc++/41759 reword static assertions in 

	PR libstdc++/41759
	* include/bits/random.h: Reword static assertion messages to state
	positive conditions.
	* include/bits/random.tcc: Likewise.
	* include/bits/uniform_int_dist.h: Likewise.
	* testsuite/26_numerics/random/pr60037-neg.cc: Adjust dg-error
	patterns.

diff --git a/libstdc++-v3/include/bits/random.h b/libstdc++-v3/include/bits/random.h
index 1babe80..d5182dc 100644
--- a/libstdc++-v3/include/bits/random.h
+++ b/libstdc++-v3/include/bits/random.h
@@ -158,7 +158,7 @@ _GLIBCXX_END_NAMESPACE_VERSION
   struct _Adaptor
   {
 	static_assert(std::is_floating_point<_DInputType>::value,
-		  "template argument not a floating point type");
+		  "template argument must be a floating point type");
 
   public:
 	_Adaptor(_Engine& __g)
@@ -235,8 +235,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   template
 class linear_congruential_engine
 {
-  static_assert(std::is_unsigned<_UIntType>::value, "template argument "
-		"substituting _UIntType not an unsigned integral type");
+  static_assert(std::is_unsigned<_UIntType>::value,
+		"result_type must be an unsigned integral type");
   static_assert(__m == 0u || (__a < __m && __c < __m),
 		"template argument substituting __m out of bounds");
 
@@ -443,8 +443,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 	   _UIntType __c, size_t __l, _UIntType __f>
 class mersenne_twister_engine
 {
-  static_assert(std::is_unsigned<_UIntType>::value, "template argument "
-		"substituting _UIntType not an unsigned integral type");
+  static_assert(std::is_unsigned<_UIntType>::value,
+		"result_type must be an unsigned integral type");
   static_assert(1u <= __m && __m <= __n,
 		"template argument substituting __m out of bounds");
   static_assert(__r <= __w, "template argument substituting "
@@ -658,10 +658,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   template
 class subtract_with_carry_engine
 {
-  static_assert(std::is_unsigned<_UIntType>::value, "template argument "
-		"substituting _UIntType not an unsigned integral type");
+  static_assert(std::is_unsigned<_UIntType>::value,
+		"result_type must be an unsigned integral type");
   static_assert(0u < __s && __s < __r,
-		"template argument substituting __s out of bounds");
+		"0 < s < r");
   static_assert(0u < __w && __w <= std::numeric_limits<_UIntType>::digits,
 		"template argument substituting __w out of bounds");
 
@@ -1065,8 +1065,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   template
 class independent_bits_engine
 {
-  static_assert(std::is_unsigned<_UIntType>::value, "template argument "
-		"substituting _UIntType not an unsigned integral type");
+  static_assert(std::is_unsigned<_UIntType>::value,
+		"result_type must be an unsigned integral type");
   static_assert(0u < __w && __w <= std::numeric_limits<_UIntType>::digits,
 		"template argument substituting __w out of bounds");
 
@@ -1278,7 +1278,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   /**
* @brief Produces random numbers by combining random numbers from some
* base engine to produce random numbers with a specifies number of bits
-   * @p __w.
+   * @p __k.
*/
   template
 class shuffle_order_engine
@@ -1649,7 +1649,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* @{
*/
 
-  // std::uniform_int_distribution is defined in 
+  // std::uniform_int_distribution is defined in 
 
   /**
* @brief Return true if two uniform integer distributions have
@@ -1702,7 +1702,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 class uniform_real_distribution
 {
   static_assert(std::is_floating_point<_RealType>::value,
-		"template argument not a floating point type");
+		"result_type must be a floating point type");
 
 public:
   /** The type of the range of the distribution. */
@@ -1920,7 +1920,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 class normal_distribution
 {
   static_assert(std::is_floating_point<_RealType>::value,
-		"template argument not a floating point type");
+		"result_type must be a floating point type");
 
 public:
   /** The type of the range of the distribution. */
@@ -2133,7 +2133,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 class lognormal_distribution
 {
   static_assert(std::is_floating_point<_RealType>::value,
-		"template argument not a floating point type");
+		"result_type must be a floating point type");
 
 public:
   /** The type of the range of the distribution. */
@@ -2337,7 

[gomp-nvptx] nvptx backend: write_omp_entry cosmetics

2016-04-18 Thread Alexander Monakov
This brings write_omp_entry code a bit closer in style to the rest of nvptx.c
by using write_fn_marker, and hopefully makes it a bit clearer. No functional
change.

* config/nvptx/nvptx.c (write_omp_entry): Adjust.
(nvptx_declare_function_name): Adjust.
---
Applied to amonakov/gomp-nvptx branch.

diff --git a/gcc/config/nvptx/nvptx.c b/gcc/config/nvptx/nvptx.c
index bc187ea..e9e4d06 100644
--- a/gcc/config/nvptx/nvptx.c
+++ b/gcc/config/nvptx/nvptx.c
@@ -979,19 +979,15 @@ nvptx_init_unisimt_predicate (FILE *file)
ORIG itself should not be emitted as a PTX .entry function.  */
 
 static void
-write_omp_entry (std::stringstream , const char *name, const char *orig)
+write_omp_entry (FILE *file, const char *name, const char *orig)
 {
-  /* Pointer-sized PTX integer type, .u32 or .u64 depending on target ABI.  */
-  const char *sfx = nvptx_ptx_type_from_mode (Pmode, false);
-
-  /* OpenMP target regions are entered via gomp_nvptx_main.  */
   static bool gomp_nvptx_main_declared;
   if (!gomp_nvptx_main_declared)
 {
   gomp_nvptx_main_declared = true;
-  s << "// BEGIN GLOBAL FUNCTION DECL: gomp_nvptx_main\n";
-  s << ".extern .func gomp_nvptx_main";
-  s << "(.param" << sfx << " %in_ar1, .param" << sfx << " %in_ar2);\n";
+  write_fn_marker (func_decls, false, true, "gomp_nvptx_main");
+  func_decls << ".extern .func gomp_nvptx_main (.param.u" << POINTER_SIZE
+<< " %in_ar1, .param.u" << POINTER_SIZE << " %in_ar2);\n";
 }
 #define ENTRY_TEMPLATE(PS, PS_BYTES, MAD_PS_32) "\
  (.param.u" PS " %arg, .param.u" PS " %stack, .param.u" PS " %sz)\n\
@@ -1024,12 +1020,13 @@ write_omp_entry (std::stringstream , const char 
*name, const char *orig)
}\n\
ret.uni;\n\
 }\n"
-  static const char template64[] = ENTRY_TEMPLATE ("64", "8", "mad.wide.u32");
-  static const char template32[] = ENTRY_TEMPLATE ("32", "4", "mad.lo.u32  ");
+  static const char entry64[] = ENTRY_TEMPLATE ("64", "8", "mad.wide.u32");
+  static const char entry32[] = ENTRY_TEMPLATE ("32", "4", "mad.lo.u32  ");
 #undef ENTRY_TEMPLATE
-  const char *template_1 = TARGET_ABI64 ? template64 : template32;
-  const char *template_2 = template_1 + strlen (template64) + 1;
-  s << ".visible .entry " << name << template_1 << orig << template_2;
+  const char *entry_1 = TARGET_ABI64 ? entry64 : entry32;
+  /* Position ENTRY_2 after the embedded nul using strlen of the prefix.  */
+  const char *entry_2 = entry_1 + strlen (entry64) + 1;
+  fprintf (file, ".visible .entry %s%s%s%s", name, entry_1, orig, entry_2);
   need_softstack_decl = need_unisimt_decl = true;
 }
 
@@ -1044,17 +1041,17 @@ nvptx_declare_function_name (FILE *file, const char 
*name, const_tree decl)
   tree result_type = TREE_TYPE (fntype);
   int argno = 0;
 
-  /* We construct the initial part of the function into a string
- stream, in order to share the prototype writing code.  */
-  std::stringstream s;
   if (flag_openmp
   && lookup_attribute ("omp target entrypoint", DECL_ATTRIBUTES (decl)))
 {
   char *buf = (char *) alloca (strlen (name) + sizeof ("$impl"));
   sprintf (buf, "%s$impl", name);
-  write_omp_entry (s, name, buf);
+  write_omp_entry (file, name, buf);
   name = buf;
 }
+  /* We construct the initial part of the function into a string
+ stream, in order to share the prototype writing code.  */
+  std::stringstream s;
   write_fn_proto (s, true, name, decl);
   s << "{\n";
 


Re: [PATCH] [AArch64] support -mfentry feature for arm64

2016-04-18 Thread Michael Matz
Hi,

On Mon, 18 Apr 2016, Andrew Haley wrote:

> >> That may not be safe.  Consider an implementation which looks ahead 
> >> in the instruction stream and decodes the instructions speculatively.
> > 
> > It should go without saying that patching instructions is followed by 
> > whatever means necessary to flush any such caches on a particular 
> > implementation (here after patching the jump, after patching the rest, 
> > and after patching the first insn again, i.e. three times).
> 
> That doesn't necessarily help you, though, without an ISB in the reading 
> thread.

I don't understand, which reading thread?  We're writing, not reading 
instructions.  You mean other executing threads?  I will happily declare 
any implementation where it's impossible to safely patch the 
instruction stream by flushing the respective buffers or other means 
completely under control of the patching machinery, to be broken by 
design.  What failure mode do you envision, exactly?


Ciao,
Michael.


Re: [PATCH] Optimize strchr (s, 0) to strlen

2016-04-18 Thread Wilco Dijkstra
Jakub Jelinek  wrote:
> On Mon, Apr 18, 2016 at 05:00:45PM +, Wilco Dijkstra wrote:
>> Optimize strchr (s, 0) to s + strlen (s).  strchr (s, 0) appears a common
>> idiom for finding the end of a string, however it is not a very efficient
>> way of doing so.  Strlen is a much simpler operation which is significantly
>> faster (eg. on x86 strlen is 50% faster for strings of 8 bytes and about
>> twice as fast as strchr on strings of 1KB).
>
> That is generally a bad idea, it really depends on the target.
> So, perhaps such decision should be done on a case by case basis,
> and certainly not this early.
> Often strchr (s, 0) should be just optimized as rawmemchr (s, 0) instead.

I don't see how it would depend on the target - under what circumstances could
strchr possibly be faster than strlen? The former must do 2 comparisons per 
character - the latter only 1.

Note rawmemchr is a non-standard function, ie. GCC would need to be told
whether the target library supports it, so it would require new builtins and
infrastructure.

Also rawmemchr is significantly slower than strlen on most targets, even when
an assembly implementation is available. That's why I posted this patch for 
GLIBC:
https://sourceware.org/ml/libc-alpha/2016-04/msg00382.html

Wilco



Re-apply reverted niter change 1/4

2016-04-18 Thread Jan Hubicka
Hi,
as discussed on IRC today, I would like to re-apply the patch to fix bogus
realistic bounds in niter.  As it turned out, we seem to rely on this bogus
estimate in few benchmarks and there is miscompilation with avx512. 

The performance regressions should be solved my planned patch to introduce
likely upper bounds - here we can track the assumption that there are no
trailing arrays in the structures. I plan to send it after some benchmarking.

Moreover we can get smarter about tracking trailing arrays.  We seem to get
wrong MEM_REFs (as noticed by Richard), we may disable the path for non-C
based languages (regresions are for Fortran testcases) and we can track object
sizes.

I plan to do that step-by-step so possible additional fallout is easier to
track.  This patch re-instantiate first fix included in the orignial
patch - ivopts should consider max_stmt-executions_int when giving an estimate
on number of iterations.

Bootstrapped/regtested x86_64-linux, comitted.

Honza

Index: ChangeLog
===
--- ChangeLog   (revision 235157)
+++ ChangeLog   (working copy)
@@ -1,3 +1,8 @@
+2016-04-17  Jan Hubicka  
+
+   * tree-ssa-loop-ivopts.c (avg_loop_niter): Use also
+   max_loop_iterations_int.
+
 2016-04-18  Richard Biener  
 
PR tree-optimization/43434
Index: tree-ssa-loop-ivopts.c
===
--- tree-ssa-loop-ivopts.c  (revision 235064)
+++ tree-ssa-loop-ivopts.c  (working copy)
@@ -121,7 +121,11 @@ avg_loop_niter (struct loop *loop)
 {
   HOST_WIDE_INT niter = estimated_stmt_executions_int (loop);
   if (niter == -1)
-return AVG_LOOP_NITER (loop);
+{
+  niter = max_stmt_executions_int (loop);
+  if (niter == -1 || niter > AVG_LOOP_NITER (loop))
+return AVG_LOOP_NITER (loop);
+}
 
   return niter;
 }


Re: [PATCH] [AArch64] support -mfentry feature for arm64

2016-04-18 Thread Andrew Haley
On 04/18/2016 06:13 PM, Michael Matz wrote:

> On Mon, 18 Apr 2016, Andrew Haley wrote:
> 
>> On 04/15/2016 06:29 PM, Alexander Monakov wrote:
>>
>>> Alternatively: replace first nop with a short forward branch that
>>> jumps over the rest of the pad, patch rest of the pad, patch the
>>> initial forward branch.
>>
>> That may not be safe.  Consider an implementation which looks ahead in
>> the instruction stream and decodes the instructions speculatively.
> 
> It should go without saying that patching instructions is followed by 
> whatever means necessary to flush any such caches on a particular 
> implementation (here after patching the jump, after patching the rest, and 
> after patching the first insn again, i.e. three times).

That doesn't necessarily help you, though, without an ISB in the reading
thread.

Andrew.



Re: [PATCH] [AArch64] support -mfentry feature for arm64

2016-04-18 Thread Michael Matz
Hi,

On Mon, 18 Apr 2016, Andrew Haley wrote:

> On 04/15/2016 06:29 PM, Alexander Monakov wrote:
> 
> > Alternatively: replace first nop with a short forward branch that
> > jumps over the rest of the pad, patch rest of the pad, patch the
> > initial forward branch.
> 
> That may not be safe.  Consider an implementation which looks ahead in
> the instruction stream and decodes the instructions speculatively.

It should go without saying that patching instructions is followed by 
whatever means necessary to flush any such caches on a particular 
implementation (here after patching the jump, after patching the rest, and 
after patching the first insn again, i.e. three times).  Nothing that GCC 
needs to worry about, but the patching infrastructure.


Ciao,
Michael.


Re: [PATCH] Optimize strchr (s, 0) to strlen

2016-04-18 Thread Jakub Jelinek
On Mon, Apr 18, 2016 at 05:00:45PM +, Wilco Dijkstra wrote:
> Optimize strchr (s, 0) to s + strlen (s).  strchr (s, 0) appears a common
> idiom for finding the end of a string, however it is not a very efficient
> way of doing so.  Strlen is a much simpler operation which is significantly
> faster (eg. on x86 strlen is 50% faster for strings of 8 bytes and about
> twice as fast as strchr on strings of 1KB).

That is generally a bad idea, it really depends on the target.
So, perhaps such decision should be done on a case by case basis,
and certainly not this early.
Often strchr (s, 0) should be just optimized as rawmemchr (s, 0) instead.

Jakub


[PATCH] Optimize strchr (s, 0) to strlen

2016-04-18 Thread Wilco Dijkstra
Optimize strchr (s, 0) to s + strlen (s).  strchr (s, 0) appears a common
idiom for finding the end of a string, however it is not a very efficient
way of doing so.  Strlen is a much simpler operation which is significantly
faster (eg. on x86 strlen is 50% faster for strings of 8 bytes and about
twice as fast as strchr on strings of 1KB).

OK for trunk?

ChangeLog:
2016-04-18  Wilco Dijkstra  

gcc/
* gcc/builtins.c (fold_builtin_strchr): Optimize strchr (s, 0) into
strlen.

testsuite/
* gcc/testsuite/gcc.dg/strlenopt-20.c: Update test.
* gcc/testsuite/gcc.dg/strlenopt-21.c: Likewise.
* gcc/testsuite/gcc.dg/strlenopt-22.c: Likewise.
* gcc/testsuite/gcc.dg/strlenopt-26.c: Likewise.
* gcc/testsuite/gcc.dg/strlenopt-5.c: Likewise.
* gcc/testsuite/gcc.dg/strlenopt-7.c: Likewise.
* gcc/testsuite/gcc.dg/strlenopt-9.c: Likewise.

--

diff --git a/gcc/builtins.c b/gcc/builtins.c
index 
058ecc39aab205099713e503861103ce6ba5ee6d..150e707178a3e119d42ef630b384da3eaf7b2182
 100644
--- a/gcc/builtins.c
+++ b/gcc/builtins.c
@@ -8567,20 +8567,20 @@ fold_builtin_strchr (location_t loc, tree s1, tree s2, 
tree type)
   else
 {
   const char *p1;
+  char c;
 
   if (TREE_CODE (s2) != INTEGER_CST)
return NULL_TREE;
 
+  if (target_char_cast (s2, ))
+   return NULL_TREE;
+
   p1 = c_getstr (s1);
   if (p1 != NULL)
{
- char c;
  const char *r;
  tree tem;
 
- if (target_char_cast (s2, ))
-   return NULL_TREE;
-
  r = strchr (p1, c);
 
  if (r == NULL)
@@ -8590,6 +8590,20 @@ fold_builtin_strchr (location_t loc, tree s1, tree s2, 
tree type)
  tem = fold_build_pointer_plus_hwi_loc (loc, s1, r - p1);
  return fold_convert_loc (loc, type, tem);
}
+  else if (c == 0)
+   {
+ tree fn = builtin_decl_implicit (BUILT_IN_STRLEN);
+ if (!fn)
+   return NULL_TREE;
+
+ s1 = builtin_save_expr (s1);
+
+ /* Transform strchr (s1, '\0') to s1 + strlen (s1).  */
+ fn = build_call_expr_loc (loc, fn, 1, s1);
+ tree tem = fold_build_pointer_plus (s1, fn);
+ return fold_convert_loc (loc, type, tem);
+   }
+
   return NULL_TREE;
 }
 }
diff --git a/gcc/testsuite/gcc.dg/strlenopt-20.c 
b/gcc/testsuite/gcc.dg/strlenopt-20.c
index 
a83e845c26d88e5acdcabf142f7b319136663488..7b483eaeac1aa47278111a92148a16f00b2aaa2d
 100644
--- a/gcc/testsuite/gcc.dg/strlenopt-20.c
+++ b/gcc/testsuite/gcc.dg/strlenopt-20.c
@@ -86,9 +86,9 @@ main ()
   return 0;
 }
 
-/* { dg-final { scan-tree-dump-times "strlen \\(" 1 "strlen" } } */
+/* { dg-final { scan-tree-dump-times "strlen \\(" 2 "strlen" } } */
 /* { dg-final { scan-tree-dump-times "memcpy \\(" 4 "strlen" } } */
 /* { dg-final { scan-tree-dump-times "strcpy \\(" 0 "strlen" } } */
 /* { dg-final { scan-tree-dump-times "strcat \\(" 0 "strlen" } } */
-/* { dg-final { scan-tree-dump-times "strchr \\(" 1 "strlen" } } */
+/* { dg-final { scan-tree-dump-times "strchr \\(" 0 "strlen" } } */
 /* { dg-final { scan-tree-dump-times "stpcpy \\(" 0 "strlen" } } */
diff --git a/gcc/testsuite/gcc.dg/strlenopt-21.c 
b/gcc/testsuite/gcc.dg/strlenopt-21.c
index 
e22fa9fca9ba14354db2cd5f602283b64bd8dcac..05b85a49dde0a7f5d269174fd4269e40be910dbd
 100644
--- a/gcc/testsuite/gcc.dg/strlenopt-21.c
+++ b/gcc/testsuite/gcc.dg/strlenopt-21.c
@@ -57,9 +57,9 @@ main ()
   return 0;
 }
 
-/* { dg-final { scan-tree-dump-times "strlen \\(" 1 "strlen" } } */
+/* { dg-final { scan-tree-dump-times "strlen \\(" 2 "strlen" } } */
 /* { dg-final { scan-tree-dump-times "memcpy \\(" 3 "strlen" } } */
 /* { dg-final { scan-tree-dump-times "strcpy \\(" 0 "strlen" } } */
 /* { dg-final { scan-tree-dump-times "strcat \\(" 0 "strlen" } } */
-/* { dg-final { scan-tree-dump-times "strchr \\(" 1 "strlen" } } */
+/* { dg-final { scan-tree-dump-times "strchr \\(" 0 "strlen" } } */
 /* { dg-final { scan-tree-dump-times "stpcpy \\(" 0 "strlen" } } */
diff --git a/gcc/testsuite/gcc.dg/strlenopt-22.c 
b/gcc/testsuite/gcc.dg/strlenopt-22.c
index 
aa55f5ebd6a2d4803ee9a7fd60fc538d86f47124..b4ef772f0e59252f10a5419ede6837b3c8ca8265
 100644
--- a/gcc/testsuite/gcc.dg/strlenopt-22.c
+++ b/gcc/testsuite/gcc.dg/strlenopt-22.c
@@ -31,9 +31,9 @@ main ()
   return 0;
 }
 
-/* { dg-final { scan-tree-dump-times "strlen \\(" 3 "strlen" } } */
+/* { dg-final { scan-tree-dump-times "strlen \\(" 4 "strlen" } } */
 /* { dg-final { scan-tree-dump-times "memcpy \\(" 1 "strlen" } } */
 /* { dg-final { scan-tree-dump-times "strcpy \\(" 1 "strlen" } } */
 /* { dg-final { scan-tree-dump-times "strcat \\(" 0 "strlen" } } */
-/* { dg-final { scan-tree-dump-times "strchr \\(" 1 "strlen" } } */
+/* { dg-final { scan-tree-dump-times "strchr \\(" 0 "strlen" } } */
 /* { dg-final { scan-tree-dump-times "stpcpy \\(" 0 "strlen" } } */
diff --git a/gcc/testsuite/gcc.dg/strlenopt-26.c 

[patch] Remove unused typedefs in std::bind types

2016-04-18 Thread Jonathan Wakely

Tested x86_64-linux, committed to trunk.


commit ea5d727f12fcbbb5a8b7b0789f88968649937176
Author: Jonathan Wakely 
Date:   Mon Mar 14 09:40:41 2016 +

Remove unused typedefs in std::bind types

	* include/std/function (_Bind, _Bind_result): Remove unused typedefs.

diff --git a/libstdc++-v3/include/std/functional b/libstdc++-v3/include/std/functional
index 9799410..1edd886 100644
--- a/libstdc++-v3/include/std/functional
+++ b/libstdc++-v3/include/std/functional
@@ -927,7 +927,6 @@ _GLIBCXX_MEM_FN_TRAITS(&&, false_type, true_type)
 class _Bind<_Functor(_Bound_args...)>
 : public _Weak_result_type<_Functor>
 {
-  typedef _Bind __self_type;
   typedef typename _Build_index_tuple::__type
 	_Bound_indexes;
 
@@ -1052,7 +1051,6 @@ _GLIBCXX_MEM_FN_TRAITS(&&, false_type, true_type)
   template
 class _Bind_result<_Result, _Functor(_Bound_args...)>
 {
-  typedef _Bind_result __self_type;
   typedef typename _Build_index_tuple::__type
 	_Bound_indexes;
 


[patch] Fix typo in comment

2016-04-18 Thread Jonathan Wakely

Committed to trunk.

commit 9d7cfe77dece94e80e93aebc0c159824b33fcfd5
Author: Jonathan Wakely 
Date:   Thu Apr 7 12:28:38 2016 +0100

	* config/cpu/sh/atomicity.h: Fix typo in comment.

diff --git a/libstdc++-v3/config/cpu/sh/atomicity.h b/libstdc++-v3/config/cpu/sh/atomicity.h
index bc62cf8..947b9e2 100644
--- a/libstdc++-v3/config/cpu/sh/atomicity.h
+++ b/libstdc++-v3/config/cpu/sh/atomicity.h
@@ -30,6 +30,6 @@
 // set in the environment.  This makes it impossible to enable the proper
 // atomic model on SH without modifying GCC itself, because libstdc++ always
 // thinks the target doesn't do any atomics and uses the default mutex based
-// implementation from cpu/generic/atomicity/mutex.
+// implementation from cpu/generic/atomicity_mutex.
 
 #include 



[patch] libstdc++/70294 Define std::thread::id comparison operators at namespace-scope

2016-04-18 Thread Jonathan Wakely

The operator< and operator== for std::thread::id are not visible at
namespace scope, so can only be found by ADL. This fixes it.

Tested x86_64-linux, committed to trunk.


commit 8ca18880b4c6995fbccfb661eb652ebe9cd7f75f
Author: Jonathan Wakely 
Date:   Mon Apr 18 16:58:13 2016 +0100

Define std::thread::id comparison operators at namespace-scope

diff --git a/libstdc++-v3/include/std/thread b/libstdc++-v3/include/std/thread
index ad31fbc..15aa9a9 100644
--- a/libstdc++-v3/include/std/thread
+++ b/libstdc++-v3/include/std/thread
@@ -88,22 +88,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   friend class hash;
 
   friend bool
-  operator==(thread::id __x, thread::id __y) noexcept
-  {
-	// pthread_equal is undefined if either thread ID is not valid, so we
-	// can't safely use __gthread_equal on default-constructed values (nor
-	// the non-zero value returned by this_thread::get_id() for
-	// single-threaded programs using GNU libc). Assume EqualityComparable.
-	return __x._M_thread == __y._M_thread;
-  }
+  operator==(thread::id __x, thread::id __y) noexcept;
 
   friend bool
-  operator<(thread::id __x, thread::id __y) noexcept
-  {
-	// Pthreads doesn't define any way to do this, so we just have to
-	// assume native_handle_type is LessThanComparable.
-	return __x._M_thread < __y._M_thread;
-  }
+  operator<(thread::id __x, thread::id __y) noexcept;
 
   template
 	friend basic_ostream<_CharT, _Traits>&
@@ -231,10 +219,28 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   { __x.swap(__y); }
 
   inline bool
+  operator==(thread::id __x, thread::id __y) noexcept
+  {
+// pthread_equal is undefined if either thread ID is not valid, so we
+// can't safely use __gthread_equal on default-constructed values (nor
+// the non-zero value returned by this_thread::get_id() for
+// single-threaded programs using GNU libc). Assume EqualityComparable.
+return __x._M_thread == __y._M_thread;
+  }
+
+  inline bool
   operator!=(thread::id __x, thread::id __y) noexcept
   { return !(__x == __y); }
 
   inline bool
+  operator<(thread::id __x, thread::id __y) noexcept
+  {
+// Pthreads doesn't define any way to do this, so we just have to
+// assume native_handle_type is LessThanComparable.
+return __x._M_thread < __y._M_thread;
+  }
+
+  inline bool
   operator<=(thread::id __x, thread::id __y) noexcept
   { return !(__y < __x); }
 
diff --git a/libstdc++-v3/testsuite/30_threads/thread/id/70294.cc b/libstdc++-v3/testsuite/30_threads/thread/id/70294.cc
new file mode 100644
index 000..9717637
--- /dev/null
+++ b/libstdc++-v3/testsuite/30_threads/thread/id/70294.cc
@@ -0,0 +1,24 @@
+// Copyright (C) 2016 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3.  If not see
+// .
+
+// { dg-options "-std=gnu++11" }
+// { dg-do compile }
+
+#include 
+
+bool (*lt)(std::thread::id, std::thread::id) = ::operator<;
+bool (*eq)(std::thread::id, std::thread::id) = ::operator==;


[PATCH] PR target/70708: Suboptimal code generated when using _mm_set_sd (X64)

2016-04-18 Thread H.J. Lu
"movq" should used to load double into xmm register with zero_extend:

(set (reg:V2DF 90)
 (vec_concat:V2DF (reg/v:DF 88 [ d ])
  (const_double:DF 0.0 [0x0.0p+0])))

Unlike "movsd", which only works with load from memory, "movq" works
with both memory and xmm register.

OK for trunk if there is no regression?

H.J.
--
gcc/

PR target/70708
* config/i386/sse.md (sse2_loadlpd): Accept load from "xm" and
replace %vmovsd with "%vmovq".
(vec_concatv2df): Likewise.

gcc/testsuite/

PR target/70708
* gcc.target/i386/pr70708.c: New test.
---
 gcc/config/i386/sse.md  | 12 ++--
 gcc/testsuite/gcc.target/i386/pr70708.c | 14 ++
 2 files changed, 20 insertions(+), 6 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/i386/pr70708.c

diff --git a/gcc/config/i386/sse.md b/gcc/config/i386/sse.md
index 1ffb3b9..845ef56 100644
--- a/gcc/config/i386/sse.md
+++ b/gcc/config/i386/sse.md
@@ -8863,14 +8863,14 @@
  "=x,x,x,x,x,x,x,x,m,m ,m")
(vec_concat:V2DF
  (match_operand:DF 2 "nonimmediate_operand"
- " m,m,m,x,x,0,0,x,x,*f,r")
+ "xm,m,m,x,x,0,0,x,x,*f,r")
  (vec_select:DF
(match_operand:V2DF 1 "vector_move_operand"
  " C,0,x,0,x,x,o,o,0,0 ,0")
(parallel [(const_int 1)]]
   "TARGET_SSE2 && !(MEM_P (operands[1]) && MEM_P (operands[2]))"
   "@
-   %vmovsd\t{%2, %0|%0, %2}
+   %vmovq\t{%2, %0|%0, %2}
movlpd\t{%2, %0|%0, %2}
vmovlpd\t{%2, %1, %0|%0, %1, %2}
movsd\t{%2, %0|%0, %2}
@@ -8955,10 +8955,10 @@
(set_attr "mode" "V2DF,DF,DF")])
 
 (define_insn "vec_concatv2df"
-  [(set (match_operand:V2DF 0 "register_operand" "=x,x,v,x,v,x,x,v,x,x")
+  [(set (match_operand:V2DF 0 "register_operand" "=x,x,v,x,v,x,x, v,x,x")
(vec_concat:V2DF
- (match_operand:DF 1 "nonimmediate_operand" " 0,x,v,m,m,0,x,m,0,0")
- (match_operand:DF 2 "vector_move_operand"  " x,x,v,1,1,m,m,C,x,m")))]
+ (match_operand:DF 1 "nonimmediate_operand" " 0,x,v,m,m,0,x,xm,0,0")
+ (match_operand:DF 2 "vector_move_operand"  " x,x,v,1,1,m,m, C,x,m")))]
   "TARGET_SSE
&& (!(MEM_P (operands[1]) && MEM_P (operands[2]))
|| (TARGET_SSE3 && rtx_equal_p (operands[1], operands[2])))"
@@ -8970,7 +8970,7 @@
vmovddup\t{%1, %0|%0, %1}
movhpd\t{%2, %0|%0, %2}
vmovhpd\t{%2, %1, %0|%0, %1, %2}
-   %vmovsd\t{%1, %0|%0, %1}
+   %vmovq\t{%1, %0|%0, %1}
movlhps\t{%2, %0|%0, %2}
movhps\t{%2, %0|%0, %2}"
   [(set_attr "isa" 
"sse2_noavx,avx,avx512vl,sse3,avx512vl,sse2_noavx,avx,sse2,noavx,noavx")
diff --git a/gcc/testsuite/gcc.target/i386/pr70708.c 
b/gcc/testsuite/gcc.target/i386/pr70708.c
new file mode 100644
index 000..2219e61
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr70708.c
@@ -0,0 +1,14 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -msse2" } */
+
+typedef double __m128d __attribute__ ((__vector_size__ (16), __may_alias__));
+
+__m128d
+foo (double d)
+{
+  return __extension__ (__m128d){ d, 0.0 };
+}
+
+/* { dg-final { scan-assembler-times "movq\[ \\t\]+\[^\n\]*%xmm" 1 } } */
+/* { dg-final { scan-assembler-not "movsd\[ \\t\]+\[^\n\]*%xmm" } } */
+/* { dg-final { scan-assembler-not "\\(%\[er\]sp\\)" { target { ! ia32 } }} } 
*/
-- 
2.5.5



Re: [PATCH] [AArch64] support -mfentry feature for arm64

2016-04-18 Thread Alexander Monakov
On Mon, 18 Apr 2016, Szabolcs Nagy wrote:
> On 18/04/16 14:26, Alexander Monakov wrote:
> > On Thu, 14 Apr 2016, Szabolcs Nagy wrote:
> >> looking at [2] i don't see why
> >>
> >> func:
> >>   mov x9, x30
> >>   bl _tracefunc
> >>   
> >>
> >> is not good for the kernel.
> >>
> >> mov x9, x30 is a nop at function entry, so in
> >> theory 4 byte atomic write should be enough
> >> to enable/disable tracing.
> > 
> > Overwriting x9 can be problematic because GCC has gained the ability to 
> > track
> > register usage interprocedurally: if foo() calls bar(), and GCC has already
> > emitted code for bar() and knows that it cannot change x9, it can use that
> > knowledge to avoid saving/restoring x9 in foo() around calls to bar(). See
> > option '-fipa-ra'.
> > 
> > If there's no register that can be safely used in place of x9 here, then
> > the backend should emit the entry/pad appropriately (e.g. with an unspec 
> > that
> > clobbers the possibly-overwritten register).
> > 
> 
> (1) nop padded function can be assumed to clobber all temp regs

This may be undesirable if the nop pad is expected to be left untouched
most of the time, because it would penalize the common case.  If only
sufficiently complex functions (e.g. making other calls anyway) are expected
to be padded, it's moot.

> (2) or _tracefunc must save/restore all temp regs, not just arg regs.

This doesn't work: when _tracefunc starts executing, old value of x9 is
already unrecoverable.

> on x86_64, glibc and linux _mcount and __fentry__ don't
> save %r11 (temp reg), only the arg regs, so i think nop
> padding should behave the same way (1).

That makes sense (modulo what I said above about penalizing tiny functions).

Heh, I started wondering if on x86 this is handled correctly when the calls
are nopped out, and it turns out -pg disables -fipa-ra (in toplev.c)! :)

Alexander


[patch] Patches to reduce warnings in libstdc++

2016-04-18 Thread Jonathan Wakely

Some small cleanups. These won't interfere with any testing of
backports to gcc-6-branch before the release, so I'm committing them
now.

The first two remove some noise when using -Wsystem-headers:

   Avoid -Wsign-compare warnings in std::to_string()

   * include/ext/string_conversions.h (__stoa): Avoid -Wsign-compare
   warnings.

   Add attribute((unused)) in libstdc++ headers
   
   * include/bits/locale_facets.h (ctype::do_narrow): Add attribute to

   unused parameter.
   * include/bits/regex_automaton.h (_NFA::_M_insert_alt): Likewise.

The other two remove some noise when running the testsuite with
-Wpedantic, and tidy up some tests.

Tested x86_64-linux, committed to trunk.


commit ea1ef677b26ad2cb1f811f11b089778782e7da5e
Author: Jonathan Wakely 
Date:   Sat Apr 16 16:58:47 2016 +0100

Make use of extensions more explicit in libstdc++ tests

	* testsuite/18_support/bad_exception/23591_thread-1.c: Add
	-Wno-pedantic to dg-options.
	* testsuite/20_util/align/2.cc: Use type as operand of alignof.
	* testsuite/20_util/is_floating_point/value.cc: Add -Wno-pedantic
	to dg-options.
	* testsuite/20_util/specialized_algorithms/uninitialized_fill/32158.cc:
	Remove extra semi-colon.
	* testsuite/23_containers/array/tuple_interface/tuple_element.cc:
	Always supply second argument to static_assert.
	* testsuite/25_algorithms/lower_bound/no_operator_ne.cc: Remove extra
	semi-colon.
	* testsuite/26_numerics/complex/c99.cc: Add -Wno-pedantic to
	dg-options.
	* testsuite/26_numerics/complex/literals/values.cc: Likewise.
	* testsuite/29_atomics/atomic/60695.cc: Likewise.
	* testsuite/29_atomics/atomic/62259.cc: use __alignof__ instead of
	alignof when operand is an object not a type.
	* testsuite/decimal/ctor.cc: Add -Wno-pedantic to dg-options.
	* testsuite/decimal/make-decimal.cc: Likewise.
	* testsuite/experimental/type_traits/value.cc: Always supply second
	argument to static_assert.
	* testsuite/util/testsuite_common_types.h: Use __extension__ for
	__int128 types.

diff --git a/libstdc++-v3/testsuite/18_support/bad_exception/23591_thread-1.c b/libstdc++-v3/testsuite/18_support/bad_exception/23591_thread-1.c
index a0fe0d7..fd1a76c 100644
--- a/libstdc++-v3/testsuite/18_support/bad_exception/23591_thread-1.c
+++ b/libstdc++-v3/testsuite/18_support/bad_exception/23591_thread-1.c
@@ -1,5 +1,5 @@
 // { dg-require-sharedlib "" }
-// { dg-options "-g -O2 -pthread -ldl -x c -fvtable-verify=none" { target *-*-linux* *-*-gnu* *-*-solaris2.1[2-9]* } }
+// { dg-options "-g -O2 -pthread -ldl -x c -fvtable-verify=none -Wno-pedantic" { target *-*-linux* *-*-gnu* *-*-solaris2.1[2-9]* } }
 
 // Copyright (C) 2005-2016 Free Software Foundation, Inc.
 //
diff --git a/libstdc++-v3/testsuite/20_util/align/2.cc b/libstdc++-v3/testsuite/20_util/align/2.cc
index 243debb..e2d1907 100644
--- a/libstdc++-v3/testsuite/20_util/align/2.cc
+++ b/libstdc++-v3/testsuite/20_util/align/2.cc
@@ -32,7 +32,7 @@ test01()
   int i = 0;
   void* ptr = 
   auto space = sizeof(i);
-  auto p2 = std::align(alignof(i), space, ptr, space);
+  auto p2 = std::align(alignof(int), space, ptr, space);
   VERIFY( ptr ==  );
   VERIFY( p2 ==  );
   VERIFY(space == sizeof(i));
diff --git a/libstdc++-v3/testsuite/20_util/is_floating_point/value.cc b/libstdc++-v3/testsuite/20_util/is_floating_point/value.cc
index d476383..8ed73fc 100644
--- a/libstdc++-v3/testsuite/20_util/is_floating_point/value.cc
+++ b/libstdc++-v3/testsuite/20_util/is_floating_point/value.cc
@@ -1,4 +1,4 @@
-// { dg-options "-std=gnu++11" }
+// { dg-options "-std=gnu++11 -Wno-pedantic" }
 // { dg-do compile }
 //
 // Copyright (C) 2011-2016 Free Software Foundation, Inc.
diff --git a/libstdc++-v3/testsuite/20_util/specialized_algorithms/uninitialized_fill/32158.cc b/libstdc++-v3/testsuite/20_util/specialized_algorithms/uninitialized_fill/32158.cc
index 821d012..fc05426 100644
--- a/libstdc++-v3/testsuite/20_util/specialized_algorithms/uninitialized_fill/32158.cc
+++ b/libstdc++-v3/testsuite/20_util/specialized_algorithms/uninitialized_fill/32158.cc
@@ -31,4 +31,4 @@ Alpha(MyPair* start, MyPair* end)
 {
   MyPair my_pair(1, 2);
   std::uninitialized_fill(start, end, my_pair);
-};
+}
diff --git a/libstdc++-v3/testsuite/23_containers/array/tuple_interface/tuple_element.cc b/libstdc++-v3/testsuite/23_containers/array/tuple_interface/tuple_element.cc
index 6abe049..96e0bfb 100644
--- a/libstdc++-v3/testsuite/23_containers/array/tuple_interface/tuple_element.cc
+++ b/libstdc++-v3/testsuite/23_containers/array/tuple_interface/tuple_element.cc
@@ -47,7 +47,7 @@ test01()
   static_assert(is_same::type,
 volatile int>::value, "");
   static_assert( (is_same::type,
-   volatile int>::value == true) );
+   volatile int>::value == true), "" );
 
   

Re: [doc] Update install.texi for GCC 6 on Solaris

2016-04-18 Thread Sandra Loosemore

On 04/18/2016 08:35 AM, Rainer Orth wrote:

The following patch updates the Solaris sections of install.texi for GCC
6 and beyond.  This hasn't been done in a while, and it would be good to
get it into the GCC 6.1 release due to the caveat concerning GNU as 2.26.

Perhaps the doc maintainers could do a sanity check as well.  Tested
with make doc/gccinstall.{info,dvi,pdf} html.

Will apply to mainline soon.  Ok for the gcc-6 branch?

Thanks.
 Rainer


2016-04-16  Rainer Orth  

* doc/install.texi (Specific, i?86-*-solaris2.10): Update gas and
gld requirements.
(Specific, *-*-solaris2*): Update Solaris 11 bundled gcc
versions.
Mention Solaris 11 packaging changes.
Update gas and gld requirements.
Remove reference to pre-Solaris 10 bug.
(Specific, sparc-sun-solaris2*): Remove reference to pre-Solaris 10
systems and bugs.
(Specific, sparc64-*-solaris2*): Remove reference to bootstrap
with cc.


This looks fine to me.  Thank you for whacking out all that bit-rotten 
text about old GCC versions.


-Sandra



[committed] Backport PR70297 to 5

2016-04-18 Thread Marek Polacek
To finally resolve this PR, I'm backporting the two attached patches to
gcc-5-branch.

Regtested/bootstrapped on x86_64-linux, applying.

Marek
2015-11-11  Jason Merrill  
 
* decl.c (duplicate_decls): When combining typedefs, remove the
new type from the variants list.

diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 76cc1d1..383b47d 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -2014,7 +2014,22 @@ duplicate_decls (tree newdecl, tree olddecl, bool 
newdecl_is_friend)
   /* For typedefs use the old type, as the new type's DECL_NAME points
 at newdecl, which will be ggc_freed.  */
   if (TREE_CODE (newdecl) == TYPE_DECL)
-   newtype = oldtype;
+   {
+ newtype = oldtype;
+
+ /* And remove the new type from the variants list.  */
+ if (TYPE_NAME (TREE_TYPE (newdecl)) == newdecl)
+   {
+ tree remove = TREE_TYPE (newdecl);
+ for (tree t = TYPE_MAIN_VARIANT (remove); ;
+  t = TYPE_NEXT_VARIANT (t))
+   if (TYPE_NEXT_VARIANT (t) == remove)
+ {
+   TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (remove);
+   break;
+ }
+   }
+   }
   else
/* Merge the data types specified in the two decls.  */
newtype = merge_types (TREE_TYPE (newdecl), TREE_TYPE (olddecl));

2016-03-31  Marek Polacek  

PR c/70297
* c-decl.c (merge_decls): Also set TYPE_ALIGN and TYPE_USER_ALIGN.

* decl.c (duplicate_decls): Also set TYPE_ALIGN and TYPE_USER_ALIGN.

* c-c++-common/pr70297.c: New test.
* g++.dg/cpp0x/typedef-redecl.C: New test.
* gcc.dg/typedef-redecl2.c: New test.

diff --git a/gcc/c/c-decl.c b/gcc/c/c-decl.c
index bab4715..0dd2121 100644
--- a/gcc/c/c-decl.c
+++ b/gcc/c/c-decl.c
@@ -2358,6 +2358,35 @@ merge_decls (tree newdecl, tree olddecl, tree newtype, 
tree oldtype)
   DECL_ATTRIBUTES (newdecl)
 = targetm.merge_decl_attributes (olddecl, newdecl);
 
+  /* For typedefs use the old type, as the new type's DECL_NAME points
+ at newdecl, which will be ggc_freed.  */
+  if (TREE_CODE (newdecl) == TYPE_DECL)
+{
+  /* But NEWTYPE might have an attribute, honor that.  */
+  tree tem = newtype;
+  newtype = oldtype;
+
+  if (TYPE_USER_ALIGN (tem))
+   {
+ if (TYPE_ALIGN (tem) > TYPE_ALIGN (newtype))
+   TYPE_ALIGN (newtype) = TYPE_ALIGN (tem);
+ TYPE_USER_ALIGN (newtype) = true;
+   }
+
+  /* And remove the new type from the variants list.  */
+  if (TYPE_NAME (TREE_TYPE (newdecl)) == newdecl)
+   {
+ tree remove = TREE_TYPE (newdecl);
+ for (tree t = TYPE_MAIN_VARIANT (remove); ;
+  t = TYPE_NEXT_VARIANT (t))
+   if (TYPE_NEXT_VARIANT (t) == remove)
+ {
+   TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (remove);
+   break;
+ }
+   }
+}
+
   /* Merge the data types specified in the two decls.  */
   TREE_TYPE (newdecl)
 = TREE_TYPE (olddecl)
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index cfae210..4730093 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -2028,8 +2028,17 @@ duplicate_decls (tree newdecl, tree olddecl, bool 
newdecl_is_friend)
 at newdecl, which will be ggc_freed.  */
   if (TREE_CODE (newdecl) == TYPE_DECL)
{
+ /* But NEWTYPE might have an attribute, honor that.  */
+ tree tem = TREE_TYPE (newdecl);
  newtype = oldtype;
 
+ if (TYPE_USER_ALIGN (tem))
+   {
+ if (TYPE_ALIGN (tem) > TYPE_ALIGN (newtype))
+   TYPE_ALIGN (newtype) = TYPE_ALIGN (tem);
+ TYPE_USER_ALIGN (newtype) = true;
+   }
+
  /* And remove the new type from the variants list.  */
  if (TYPE_NAME (TREE_TYPE (newdecl)) == newdecl)
{
diff --git a/gcc/testsuite/c-c++-common/pr70297.c 
b/gcc/testsuite/c-c++-common/pr70297.c
new file mode 100644
index 000..70a4f15
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/pr70297.c
@@ -0,0 +1,9 @@
+/* PR c/70297 */
+/* { dg-do compile } */
+/* { dg-options "-g" } */
+
+typedef int T;
+typedef int T __attribute__((aligned (4)));
+struct S {
+  T *t;
+};
diff --git a/gcc/testsuite/g++.dg/cpp0x/typedef-redecl.C 
b/gcc/testsuite/g++.dg/cpp0x/typedef-redecl.C
new file mode 100644
index 000..576c7ce
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/typedef-redecl.C
@@ -0,0 +1,12 @@
+// PR c/70297
+// { dg-do compile { target c++11 } }
+
+#define N 64
+
+typedef int T;
+typedef int T __attribute__((aligned (N)));
+typedef int T __attribute__((aligned (N * 2)));
+typedef int T __attribute__((aligned (N)));
+typedef int T;
+
+static_assert (alignof (T) == N * 2, "N * 2");
diff --git a/gcc/testsuite/gcc.dg/typedef-redecl2.c 
b/gcc/testsuite/gcc.dg/typedef-redecl2.c
new file mode 100644
index 000..c2314c7
--- /dev/null

[wwwdocs] Document GCC 6 Solaris changes

2016-04-18 Thread Rainer Orth
While updating docs for Solaris, here's a Solaris section for
gcc-6/changes.html.  Ok?

Rainer


2016-04-18  Rainer Orth  

* htdocs/gcc-6/changes.html (Solaris): New section.

Index: htdocs/gcc-6/changes.html
===
RCS file: /cvs/gcc/wwwdocs/htdocs/gcc-6/changes.html,v
retrieving revision 1.73
diff -u -p -r1.73 changes.html
--- htdocs/gcc-6/changes.html	7 Apr 2016 09:38:31 -	1.73
+++ htdocs/gcc-6/changes.html	18 Apr 2016 15:03:37 -
@@ -682,6 +682,20 @@ within strings:
 capabilities.
   
 
+Solaris
+  
+Solaris 12 is now fully supported.  Minimal support had already
+  been present in GCC 5.3.
+Solaris 12 provides a full set of startup files (crt1.o,
+  crti.o, crtn.o), which GCC now prefers over
+  its own ones.
+Position independent executables (PIE) are now supported on
+  Solaris 12.
+Constructor priority is now supported on Solaris 12 with the system
+  linker.
+libvtv has been ported to Solaris 11 and up.
+  
+
 Windows
   
The option -mstackrealign is now automatically activated

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


Re: [PATCH 3/4, libgomp] Resolve deadlock on plugin exit, HSA plugin parts

2016-04-18 Thread Martin Jambor
Hi,

On Sat, Apr 16, 2016 at 03:38:57PM +0800, Chung-Lin Tang wrote:
> Hi Martin, the attached patch reverts that queue_callback() change, and adds
> some more descriptions in the comments to reflect the bool return changes.
> Please see if they are acceptable.
> 

If the rest of the patch-set is approved, this can go in as well.

Thanks,

Martin


> Thanks,
> Chung-Lin
> 
> * plugin/plugin-hsa.c (hsa_warn): Adjust 'hsa_error' local variable
> to 'hsa_error_msg', for clarity.
> (hsa_fatal): Likewise.
> (hsa_error): New function.
> (init_hsa_context): Change return type to bool, adjust to return
> false on error.
> (GOMP_OFFLOAD_get_num_devices): Adjust to handle init_hsa_context
> return value.
> (GOMP_OFFLOAD_init_device): Change return type to bool, adjust to
> return false on error.
> (get_agent_info): Adjust to return NULL on error.
> (destroy_hsa_program): Change return type to bool, adjust to
> return false on error.
> (GOMP_OFFLOAD_load_image): Adjust to return -1 on error.
> (destroy_module): Change return type to bool, adjust to
> return false on error.
> (GOMP_OFFLOAD_unload_image): Likewise.
> (GOMP_OFFLOAD_fini_device): Likewise.
> (GOMP_OFFLOAD_alloc): Change to return NULL when called.
> (GOMP_OFFLOAD_free): Change to return false when called.
> (GOMP_OFFLOAD_dev2host): Likewise.
> (GOMP_OFFLOAD_host2dev): Likewise.
> (GOMP_OFFLOAD_dev2dev): Likewise.
> 
> 


Re: [doc] Update install.texi for GCC 6 on Solaris

2016-04-18 Thread Jakub Jelinek
On Mon, Apr 18, 2016 at 04:35:05PM +0200, Rainer Orth wrote:
> The following patch updates the Solaris sections of install.texi for GCC
> 6 and beyond.  This hasn't been done in a while, and it would be good to
> get it into the GCC 6.1 release due to the caveat concerning GNU as 2.26.
> 
> Perhaps the doc maintainers could do a sanity check as well.  Tested
> with make doc/gccinstall.{info,dvi,pdf} html.
> 
> Will apply to mainline soon.  Ok for the gcc-6 branch?

Ok.

Jakub


[PATCH 6/6] [ARC] Various instruction pattern fixes

2016-04-18 Thread Claudiu Zissulescu
OK to apply?
Claudiu

gcc/
2016-04-18  Claudiu Zissulescu  

* config/arc/arc.md (mulsidi3): Change operand 0 predicate to
register_operand.
(umulsidi3): Likewise.
(indirect_jump): Fix jump instruction assembly patterns.
(arcset): Change operand 1 predicate to nonmemory_operand.
(arcsetltu, arcsetgeu): Likewise.
(arcsethi, arcsetls): Fix pattern.
---
 gcc/config/arc/arc.md | 125 +++---
 1 file changed, 67 insertions(+), 58 deletions(-)

diff --git a/gcc/config/arc/arc.md b/gcc/config/arc/arc.md
index 6731072..170ac1c 100644
--- a/gcc/config/arc/arc.md
+++ b/gcc/config/arc/arc.md
@@ -1964,7 +1964,7 @@
   (set_attr "cond" "nocond,canuse,nocond,canuse_limm,canuse,nocond")])
 
 (define_expand "mulsidi3"
-  [(set (match_operand:DI 0 "nonimmediate_operand" "")
+  [(set (match_operand:DI 0 "register_operand" "")
(mult:DI (sign_extend:DI(match_operand:SI 1 "register_operand" ""))
 (sign_extend:DI(match_operand:SI 2 "nonmemory_operand" ""]
   "TARGET_ANY_MPY"
@@ -2200,9 +2200,9 @@
 }")
 
 (define_expand "umulsidi3"
-  [(set (match_operand:DI 0 "nonimmediate_operand" "")
-   (mult:DI (zero_extend:DI(match_operand:SI 1 "register_operand" ""))
-(zero_extend:DI(match_operand:SI 2 "nonmemory_operand" ""]
+  [(set (match_operand:DI 0 "register_operand" "")
+   (mult:DI (zero_extend:DI (match_operand:SI 1 "register_operand" ""))
+(zero_extend:DI (match_operand:SI 2 "nonmemory_operand" ""]
   ""
 {
   if (TARGET_MPY)
@@ -3673,7 +3673,12 @@
 (define_insn "indirect_jump"
   [(set (pc) (match_operand:SI 0 "nonmemory_operand" "L,I,Cal,Rcqq,r"))]
   ""
-  "j%!%* [%0]%&"
+  "@
+   j%!%* %0%&
+   j%!%* %0%&
+   j%!%* %0%&
+   j%!%* [%0]%&
+   j%!%* [%0]%&"
   [(set_attr "type" "jump")
(set_attr "iscompact" "false,false,false,maybe,false")
(set_attr "cond" "canuse,canuse_limm,canuse,canuse,canuse")])
@@ -5425,90 +5430,94 @@
 (define_code_iterator arcCC_cond [eq ne gt lt ge le])
 
 (define_insn "arcset"
-  [(set (match_operand:SI 0 "register_operand""=r,r,r,r,r,r,r")
-   (arcCC_cond:SI (match_operand:SI 1 "register_operand"  "0,r,0,r,0,0,r")
-  (match_operand:SI 2 "nonmemory_operand" 
"r,r,L,L,I,n,n")))]
+  [(set (match_operand:SI 0 "register_operand"
"=r,r,r,r,r,r,r,r")
+   (arcCC_cond:SI (match_operand:SI 1 "nonmemory_operand" 
"0,r,n,0,r,0,0,r")
+  (match_operand:SI 2 "nonmemory_operand" 
"r,r,r,L,L,I,n,n")))]
   "TARGET_V2 && TARGET_CODE_DENSITY"
   "set%? %0, %1, %2"
-  [(set_attr "length" "4,4,4,4,4,8,8")
+  [(set_attr "length" "4,4,8,4,4,4,8,8")
(set_attr "iscompact" "false")
(set_attr "type" "compare")
-   (set_attr "predicable" "yes,no,yes,no,no,yes,no")
-   (set_attr "cond" "canuse,nocond,canuse,nocond,nocond,canuse,nocond")
+   (set_attr "predicable" "yes,no,no,yes,no,no,yes,no")
+   (set_attr "cond" "canuse,nocond,nocond,canuse,nocond,nocond,canuse,nocond")
])
 
 (define_insn "arcsetltu"
-  [(set (match_operand:SI 0 "register_operand" "=r,r,r,r,r,  r,  r")
-   (ltu:SI (match_operand:SI 1 "register_operand"  "0,r,0,r,0,  0,  r")
-   (match_operand:SI 2 "nonmemory_operand" "r,r,L,L,I,  n,  n")))]
+  [(set (match_operand:SI 0 "register_operand" "=r,r,r,r,r,r,  r,  r")
+   (ltu:SI (match_operand:SI 1 "nonmemory_operand" "0,r,n,0,r,0,  0,  r")
+   (match_operand:SI 2 "nonmemory_operand" "r,r,r,L,L,I,  n,  
n")))]
   "TARGET_V2 && TARGET_CODE_DENSITY"
   "setlo%? %0, %1, %2"
-  [(set_attr "length" "4,4,4,4,4,8,8")
+  [(set_attr "length" "4,4,8,4,4,4,8,8")
(set_attr "iscompact" "false")
(set_attr "type" "compare")
-   (set_attr "predicable" "yes,no,yes,no,no,yes,no")
-   (set_attr "cond" "canuse,nocond,canuse,nocond,nocond,canuse,nocond")
+   (set_attr "predicable" "yes,no,no,yes,no,no,yes,no")
+   (set_attr "cond" "canuse,nocond,nocond,canuse,nocond,nocond,canuse,nocond")
])
 
 (define_insn "arcsetgeu"
-  [(set (match_operand:SI 0 "register_operand" "=r,r,r,r,r,  r,  r")
-   (geu:SI (match_operand:SI 1 "register_operand"  "0,r,0,r,0,  0,  r")
-   (match_operand:SI 2 "nonmemory_operand" "r,r,L,L,I,  n,  n")))]
+  [(set (match_operand:SI 0 "register_operand" "=r,r,r,r,r,r,  r,  r")
+   (geu:SI (match_operand:SI 1 "nonmemory_operand" "0,r,n,0,r,0,  0,  r")
+   (match_operand:SI 2 "nonmemory_operand" "r,r,r,L,L,I,  n,  
n")))]
   "TARGET_V2 && TARGET_CODE_DENSITY"
   "seths%? %0, %1, %2"
-  [(set_attr "length" "4,4,4,4,4,8,8")
+  [(set_attr "length" "4,4,8,4,4,4,8,8")
(set_attr "iscompact" "false")
(set_attr "type" "compare")
-   (set_attr "predicable" "yes,no,yes,no,no,yes,no")
-   (set_attr "cond" "canuse,nocond,canuse,nocond,nocond,canuse,nocond")
+   (set_attr "predicable" "yes,no,no,yes,no,no,yes,no")
+   (set_attr 

[PATCH 1/6] [ARC] Don't use drsub* instructions when selecting fpuda.

2016-04-18 Thread Claudiu Zissulescu
The double precision floating point assist instructions are not
implementing the reverse double subtract instruction (drsub) found in
the FPX extension, hence, this patch.

OK to apply?
Claudiu

gcc/
2016-04-18  Claudiu Zissulescu  

* config/arc/arc.md (cpu_facility): Add fpx variant.
(subdf3): Prohibit use reverse sub when assist operations option
is enabled.
* config/arc/fpx.md (subdf3_insn, *dsubh_peep2_insn): Allow drsub
instructions only when FPX is enabled.
* testsuite/gcc.target/arc/trsub.c: New test.
---
 gcc/config/arc/arc.md|  8 +++-
 gcc/config/arc/fpx.md|  7 ---
 gcc/testsuite/gcc.target/arc/trsub.c | 10 ++
 3 files changed, 21 insertions(+), 4 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/arc/trsub.c

diff --git a/gcc/config/arc/arc.md b/gcc/config/arc/arc.md
index 4193d26..9766547 100644
--- a/gcc/config/arc/arc.md
+++ b/gcc/config/arc/arc.md
@@ -265,7 +265,7 @@
 - get_attr_length (insn)")))
 
 ; for ARCv2 we need to disable/enable different instruction alternatives
-(define_attr "cpu_facility" "std,av1,av2"
+(define_attr "cpu_facility" "std,av1,av2,fpx"
   (const_string "std"))
 
 ; We should consider all the instructions enabled until otherwise
@@ -277,6 +277,10 @@
 (and (eq_attr "cpu_facility" "av2")
  (not (match_test "TARGET_V2")))
 (const_string "no")
+
+(and (eq_attr "cpu_facility" "fpx")
+ (match_test "TARGET_FP_DP_AX"))
+(const_string "no")
 ]
(const_string "yes")))
 
@@ -5709,6 +5713,8 @@
   "
if (TARGET_DPFP)
 {
+ if (TARGET_FP_DP_AX && (GET_CODE (operands[1]) == CONST_DOUBLE))
+   operands[1] = force_reg (DFmode, operands[1]);
  if ((GET_CODE (operands[1]) == CONST_DOUBLE)
   || GET_CODE (operands[2]) == CONST_DOUBLE)
   {
diff --git a/gcc/config/arc/fpx.md b/gcc/config/arc/fpx.md
index b790600..2e11157 100644
--- a/gcc/config/arc/fpx.md
+++ b/gcc/config/arc/fpx.md
@@ -304,7 +304,8 @@
  drsubh%F0%F2 0,%H1,%L1
  drsubh%F0%F2 0,%3,%L1"
   [(set_attr "type" "dpfp_addsub")
-  (set_attr "length" "4,8,4,8")])
+   (set_attr "length" "4,8,4,8")
+   (set_attr "cpu_facility" "*,*,fpx,fpx")])
 
 ;; ;; 
;
 ;; ;; Peephole for following conversion
@@ -613,5 +614,5 @@
   drsubh%F0%F2 %H6, %H1, %L1
   drsubh%F0%F2 %H6, %3, %L1"
  [(set_attr "type" "dpfp_addsub")
-  (set_attr "length" "4,8,4,8")]
-)
+  (set_attr "length" "4,8,4,8")
+  (set_attr "cpu_facility" "*,*,fpx,fpx")])
diff --git a/gcc/testsuite/gcc.target/arc/trsub.c 
b/gcc/testsuite/gcc.target/arc/trsub.c
new file mode 100644
index 000..031935f
--- /dev/null
+++ b/gcc/testsuite/gcc.target/arc/trsub.c
@@ -0,0 +1,10 @@
+/* Tests if we generate rsub instructions when compiling using
+   floating point assist instructions.  */
+/* { dg-do compile } */
+/* { dg-options "-mfpu=fpuda -mcpu=arcem" } */
+
+double foo (double a)
+{
+  return ((double) 0.12 - a);
+}
+/* { dg-final { scan-assembler-not "drsub.*" } } */
-- 
1.9.1



[PATCH 4/6] [ARC] Handle FPX NaN within optimized floating point library.

2016-04-18 Thread Claudiu Zissulescu
OK to apply?
Claudiu

gcc/
2016-04-18  Claudiu Zissulescu  

* testsuite/gcc.target/arc/ieee_eq.c: New test.

libgcc/
2016-04-18  Claudiu Zissulescu  

* config/arc/ieee-754/eqdf2.S: Handle FPX NaN.
---
 gcc/testsuite/gcc.target/arc/ieee_eq.c | 47 ++
 libgcc/config/arc/ieee-754/eqdf2.S | 13 ++
 2 files changed, 55 insertions(+), 5 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/arc/ieee_eq.c

diff --git a/gcc/testsuite/gcc.target/arc/ieee_eq.c 
b/gcc/testsuite/gcc.target/arc/ieee_eq.c
new file mode 100644
index 000..70aebad
--- /dev/null
+++ b/gcc/testsuite/gcc.target/arc/ieee_eq.c
@@ -0,0 +1,47 @@
+/* { dg-do run } */
+/* { dg-options "-O2" } */
+
+#include 
+#include 
+
+#define TEST_EQ(TYPE,X,Y,RES)  \
+  do { \
+volatile TYPE a, b;\
+a = (TYPE) X;  \
+b = (TYPE) Y;  \
+if ((a == b) != RES)   \
+  {\
+   printf ("Runtime computation error @%d. %g "\
+   "!= %g\n", __LINE__, a, b); \
+   error = 1;  \
+  }\
+  } while (0)
+
+#ifndef __HS__
+/* Special type of NaN found when using double FPX instructions.  */
+static const unsigned long long __nan = 0x7FF08000ULL;
+# define W (*(double *) &__nan)
+#else
+# define W __builtin_nan ("")
+#endif
+
+#define Q __builtin_nan ("")
+#define H __builtin_inf ()
+
+int main (void)
+{
+  int error = 0;
+
+  TEST_EQ (double, 1, 1, 1);
+  TEST_EQ (double, 1, 2, 0);
+  TEST_EQ (double, W, W, 0);
+  TEST_EQ (double, Q, Q, 0);
+  TEST_EQ (double, __DBL_MAX__, __DBL_MAX__, 1);
+  TEST_EQ (double, __DBL_MIN__, __DBL_MIN__, 1);
+  TEST_EQ (double, H, H, 1);
+
+  if (error)
+__builtin_abort ();
+
+  return 0;
+}
diff --git a/libgcc/config/arc/ieee-754/eqdf2.S 
b/libgcc/config/arc/ieee-754/eqdf2.S
index bc7d88e..3b23e04 100644
--- a/libgcc/config/arc/ieee-754/eqdf2.S
+++ b/libgcc/config/arc/ieee-754/eqdf2.S
@@ -58,11 +58,14 @@ __eqdf2:
   well predictable (as seen from the branch predictor).  */
 __eqdf2:
brne.d DBL0H,DBL1H,.Lhighdiff
-   bmsk r12,DBL0H,20
-#ifdef DPFP_COMPAT
-   or.f 0,DBL0L,DBL1L
-   bset.ne r12,r12,21
-#endif /* DPFP_COMPAT */
+#ifndef __HS__
+   /* The next two instructions are required to recognize the FPX
+   NaN, which has a pattern like this: 0x7ff0__8000_, as
+   oposite to 0x7ff8___.  */
+   or.f0,DBL0L,DBL1L
+   bset.ne DBL0H,DBL0H,19
+#endif /* __HS__ */
+   bmskr12,DBL0H,20
add1.f  r12,r12,DBL0H /* set c iff NaN; also, clear z if NaN.  */
j_s.d   [blink]
cmp.cc  DBL0L,DBL1L
-- 
1.9.1



[PATCH 5/6] [ARC] Fix unwanted match for sign extend 16-bit constant.

2016-04-18 Thread Claudiu Zissulescu
The combine pass may conclude umulhisi3_imm pattern can accept also sign
extended 16-bit constants. This patch prohibits the combine in considering
this pattern as suitable.

OK to apply?
Claudiu

gcc/
2016-04-18  Claudiu Zissulescu  

* config/arc/arc.md (umulhisi3_imm): Avoid unwanted match for sign
extend 16-bit constants.
* testsuite/gcc.target/arc/umulsihi3_z.c: New file.
---
 gcc/config/arc/arc.md  |  3 ++-
 gcc/testsuite/gcc.target/arc/umulsihi3_z.c | 23 +++
 2 files changed, 25 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gcc.target/arc/umulsihi3_z.c

diff --git a/gcc/config/arc/arc.md b/gcc/config/arc/arc.md
index 74530b1..6731072 100644
--- a/gcc/config/arc/arc.md
+++ b/gcc/config/arc/arc.md
@@ -1729,7 +1729,8 @@
 (define_insn "umulhisi3_imm"
   [(set (match_operand:SI 0 "register_operand"  "=r, 
r,r,  r,  r")
(mult:SI (zero_extend:SI (match_operand:HI 1 "register_operand" " 0, 
r,0,  0,  r"))
-(match_operand:HI 2 "short_const_int_operand"  " L, 
L,I,C16,C16")))]
+(match_operand:HI 2 "short_const_int_operand"  " L, 
L,I,C16,C16")))
+  (use (match_dup 2))]
   "TARGET_MPYW"
   "mpyuw%? %0,%1,%2"
   [(set_attr "length" "4,4,4,8,8")
diff --git a/gcc/testsuite/gcc.target/arc/umulsihi3_z.c 
b/gcc/testsuite/gcc.target/arc/umulsihi3_z.c
new file mode 100644
index 000..cf1c00d
--- /dev/null
+++ b/gcc/testsuite/gcc.target/arc/umulsihi3_z.c
@@ -0,0 +1,23 @@
+/* Check if the optimizers are not removing the umulsihi3_imm
+   instruction.  */
+/* { dg-do run } */
+/* { dg-options "-O2 -fno-inline" } */
+
+#include 
+
+static int32_t test (int16_t reg_val)
+{
+  int32_t x = (reg_val & 0xf) * 62500;
+  return x;
+}
+
+int main (void)
+{
+  volatile int32_t x = 0xc172;
+  x = test (x);
+
+  if (x != 0x0001e848)
+__builtin_abort ();
+  return 0;
+}
+
-- 
1.9.1



[PATCH 2/6] [ARC] Fix FPX/FPUDA code gen when compiling for big-endian.

2016-04-18 Thread Claudiu Zissulescu
OK to apply?
Claudiu

gcc/
2016-04-18  Claudiu Zissulescu  

* config/arc/arc.c (arc_process_double_reg_moves): Fix for
big-endian compilation.
* config/arc/arc.md (addf3): Likewise.
(subdf3): Likewise.
(muldf3): Likewise.
---
 gcc/config/arc/arc.c  | 12 
 gcc/config/arc/arc.md | 18 +-
 2 files changed, 17 insertions(+), 13 deletions(-)

diff --git a/gcc/config/arc/arc.c b/gcc/config/arc/arc.c
index d60db50..f4bef3e 100644
--- a/gcc/config/arc/arc.c
+++ b/gcc/config/arc/arc.c
@@ -8647,8 +8647,10 @@ arc_process_double_reg_moves (rtx *operands)
{
  /* When we have 'mov D, r' or 'mov D, D' then get the target
 register pair for use with LR insn.  */
- rtx destHigh = simplify_gen_subreg(SImode, dest, DFmode, 4);
- rtx destLow  = simplify_gen_subreg(SImode, dest, DFmode, 0);
+ rtx destHigh = simplify_gen_subreg (SImode, dest, DFmode,
+TARGET_BIG_ENDIAN ? 0 : 4);
+ rtx destLow  = simplify_gen_subreg (SImode, dest, DFmode,
+TARGET_BIG_ENDIAN ? 4 : 0);
 
  /* Produce the two LR insns to get the high and low parts.  */
  emit_insn (gen_rtx_SET (destHigh,
@@ -8665,8 +8667,10 @@ arc_process_double_reg_moves (rtx *operands)
 {
   /* When we have 'mov r, D' or 'mov D, D' and we have access to the
 LR insn get the target register pair.  */
-  rtx srcHigh = simplify_gen_subreg(SImode, src, DFmode, 4);
-  rtx srcLow  = simplify_gen_subreg(SImode, src, DFmode, 0);
+  rtx srcHigh = simplify_gen_subreg (SImode, src, DFmode,
+   TARGET_BIG_ENDIAN ? 0 : 4);
+  rtx srcLow  = simplify_gen_subreg (SImode, src, DFmode,
+   TARGET_BIG_ENDIAN ? 4 : 0);
 
   emit_insn (gen_rtx_UNSPEC_VOLATILE (Pmode,
  gen_rtvec (3, dest, srcHigh, srcLow),
diff --git a/gcc/config/arc/arc.md b/gcc/config/arc/arc.md
index 9766547..74530b1 100644
--- a/gcc/config/arc/arc.md
+++ b/gcc/config/arc/arc.md
@@ -5681,9 +5681,9 @@
{
 if (GET_CODE (operands[2]) == CONST_DOUBLE)
  {
-rtx high, low, tmp;
-split_double (operands[2], , );
-tmp = force_reg (SImode, high);
+rtx first, second, tmp;
+split_double (operands[2], , );
+tmp = force_reg (SImode, TARGET_BIG_ENDIAN ? first : second);
 emit_insn (gen_adddf3_insn (operands[0], operands[1],
 operands[2], tmp, const0_rtx));
  }
@@ -5718,10 +5718,10 @@
  if ((GET_CODE (operands[1]) == CONST_DOUBLE)
   || GET_CODE (operands[2]) == CONST_DOUBLE)
   {
-rtx high, low, tmp;
+rtx first, second, tmp;
 int const_index = ((GET_CODE (operands[1]) == CONST_DOUBLE) ? 1 : 2);
-split_double (operands[const_index], , );
-tmp = force_reg (SImode, high);
+split_double (operands[const_index], , );
+tmp = force_reg (SImode, TARGET_BIG_ENDIAN ? first : second);
 emit_insn (gen_subdf3_insn (operands[0], operands[1],
 operands[2], tmp, const0_rtx));
   }
@@ -5753,9 +5753,9 @@
 {
  if (GET_CODE (operands[2]) == CONST_DOUBLE)
   {
-rtx high, low, tmp;
-split_double (operands[2], , );
-tmp = force_reg (SImode, high);
+rtx first, second, tmp;
+split_double (operands[2], , );
+tmp = force_reg (SImode, TARGET_BIG_ENDIAN ? first : second);
 emit_insn (gen_muldf3_insn (operands[0], operands[1],
 operands[2], tmp, const0_rtx));
   }
-- 
1.9.1



[doc] Update install.texi for GCC 6 on Solaris

2016-04-18 Thread Rainer Orth
The following patch updates the Solaris sections of install.texi for GCC
6 and beyond.  This hasn't been done in a while, and it would be good to
get it into the GCC 6.1 release due to the caveat concerning GNU as 2.26.

Perhaps the doc maintainers could do a sanity check as well.  Tested
with make doc/gccinstall.{info,dvi,pdf} html.

Will apply to mainline soon.  Ok for the gcc-6 branch?

Thanks.
Rainer


2016-04-16  Rainer Orth  

* doc/install.texi (Specific, i?86-*-solaris2.10): Update gas and
gld requirements.
(Specific, *-*-solaris2*): Update Solaris 11 bundled gcc
versions.
Mention Solaris 11 packaging changes.
Update gas and gld requirements.
Remove reference to pre-Solaris 10 bug.
(Specific, sparc-sun-solaris2*): Remove reference to pre-Solaris 10
systems and bugs.
(Specific, sparc64-*-solaris2*): Remove reference to bootstrap
with cc.

# HG changeset patch
# Parent  85c4c8ea7bed0a55d87ae033b42714fd8b934826
Update install.texi for GCC 6 on Solaris

diff --git a/gcc/doc/install.texi b/gcc/doc/install.texi
--- a/gcc/doc/install.texi
+++ b/gcc/doc/install.texi
@@ -3924,19 +3924,24 @@ with GCC 4.7, there is also a 64-bit @sa
 @samp{x86_64-*-solaris2.1[0-9]*} configuration that corresponds to
 @samp{sparcv9-sun-solaris2*}.
 
-It is recommended that you configure GCC to use the GNU assembler, in
-@file{/usr/sfw/bin/gas}.  The versions included in Solaris 10, from GNU
-binutils 2.15, and Solaris 11, from GNU binutils 2.19, work fine,
-although the current version, from GNU binutils
-2.22, is known to work, too.  Recent versions of the Sun assembler in
-@file{/usr/ccs/bin/as} work almost as well, though.
+It is recommended that you configure GCC to use the GNU assembler.  The
+versions included in Solaris 10, from GNU binutils 2.15 (in
+@file{/usr/sfw/bin/gas}), and Solaris 11, from GNU binutils 2.19 or
+newer (also available as @file{/usr/bin/gas} and
+@file{/usr/gnu/bin/as}), work fine.  Please note that the current
+version, from GNU binutils 2.26, only works on Solaris 12 when using the
+Solaris linker.  On Solaris 10 and 11, you either have to wait for GNU
+binutils 2.26.1 or newer, or stay with GNU binutils 2.25.1.  Recent
+versions of the Solaris assembler in @file{/usr/ccs/bin/as} work almost
+as well, though.
 @c FIXME: as patch requirements?
 
-For linking, the Sun linker, is preferred.  If you want to use the GNU
-linker instead, which is available in @file{/usr/sfw/bin/gld}, note that
-due to a packaging bug the version in Solaris 10, from GNU binutils
-2.15, cannot be used, while the version in Solaris 11, from GNU binutils
-2.19, works, as does the latest version, from GNU binutils 2.22.
+For linking, the Solaris linker, is preferred.  If you want to use the GNU
+linker instead, note that due to a packaging bug the version in Solaris
+10, from GNU binutils 2.15 (in @file{/usr/sfw/bin/gld}), cannot be used,
+while the version in Solaris 11, from GNU binutils 2.19 or newer (also
+in @file{/usr/gnu/bin/ld} and @file{/usr/bin/gld}), works, as does the
+latest version, from GNU binutils 2.26.
 
 To use GNU @command{as}, configure with the options
 @option{--with-gnu-as --with-as=@//usr/@/sfw/@/bin/@/gas}.  It may be necessary
@@ -4505,7 +4510,8 @@ in GCC 4.6.
 Sun does not ship a C compiler with Solaris 2 before Solaris 10, though
 you can download the Sun Studio compilers for free.  In Solaris 10 and
 11, GCC 3.4.3 is available as @command{/usr/sfw/bin/gcc}.  Solaris 11
-also provides GCC 4.5.2 as @command{/usr/gcc/4.5/bin/gcc}.  Alternatively,
+also provides GCC 4.5.2, 4.7.3, and 4.8.2 as
+@command{/usr/gcc/4.5/bin/gcc} or similar.  Alternatively,
 you can install a pre-built GCC to bootstrap and install GCC.  See the
 @uref{binaries.html,,binaries page} for details.
 
@@ -4523,18 +4529,22 @@ and proceed as described in @uref{config
 In addition we strongly recommend specifying an absolute path to invoke
 @command{@var{srcdir}/configure}.
 
-Solaris 2 comes with a number of optional OS packages.  Some of these
+Solaris 10 comes with a number of optional OS packages.  Some of these
 are needed to use GCC fully, namely @code{SUNWarc},
 @code{SUNWbtool}, @code{SUNWesu}, @code{SUNWhea}, @code{SUNWlibm},
 @code{SUNWsprot}, and @code{SUNWtoo}.  If you did not install all
-optional packages when installing Solaris 2, you will need to verify that
+optional packages when installing Solaris 10, you will need to verify that
 the packages that GCC needs are installed.
-
 To check whether an optional package is installed, use
 the @command{pkginfo} command.  To add an optional package, use the
-@command{pkgadd} command.  For further details, see the Solaris 2
+@command{pkgadd} command.  For further details, see the Solaris 10
 documentation.
 
+Starting with Solaris 11, the package management has changed, so you
+need to check for @code{system/header}, @code{system/linker}, and

[PATCH 3/6] [ARC] Pass mfpuda to assembler.

2016-04-18 Thread Claudiu Zissulescu
OK to apply?
Claudiu

gcc/
2016-04-18  Claudiu Zissulescu  

* config/arc/arc.h (ASM_SPEC): Pass mfpuda to assembler.
---
 gcc/config/arc/arc.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/config/arc/arc.h b/gcc/config/arc/arc.h
index 1c2a38d..299e63a 100644
--- a/gcc/config/arc/arc.h
+++ b/gcc/config/arc/arc.h
@@ -153,7 +153,7 @@ along with GCC; see the file COPYING3.  If not see
 %{mcpu=ARC700:-mEA} \
 %{!mcpu=*:" ASM_DEFAULT "} \
 %{mbarrel-shifter} %{mno-mpy} %{mmul64} %{mmul32x16:-mdsp-packa} %{mnorm} \
-%{mswap} %{mEA} %{mmin-max} %{mspfp*} %{mdpfp*} \
+%{mswap} %{mEA} %{mmin-max} %{mspfp*} %{mdpfp*} %{mfpu=fpuda*:-mfpuda} \
 %{msimd} \
 %{mmac-d16} %{mmac-24} %{mdsp-packa} %{mcrc} %{mdvbf} %{mtelephony} %{mxy} \
 %{mcpu=ARC700|!mcpu=*:%{mlock}} \
-- 
1.9.1



[PATCH 0/6] [ARC] Various fixes

2016-04-18 Thread Claudiu Zissulescu
Hi,

This series of 6 patches are fixing a number of small issues found
during time with our compiler.

Patch 1 fixes the problem of using drsub* instructions when compiling
with double assist instruction support.

Patch 2 fixes big-endian emitted code when using FPX extension
instructions.

Patch 3 passes mfpuda option to the compiler whenever we use double
assist instructions in or compilation.

Patch 4 fixes the floating point optimized equality routine to handle
NaNs emitted by FPX extenssion.

Patch 5 fixes the case when combiner matches a sign-extended 16-bit
number with umulhisi3_imm pattern.

Patch 6 fixes various instruction patterns.

OK to apply?
Claudiu

Claudiu Zissulescu (6):
  [ARC] Don't use drsub* instructions when selecting fpuda.
  [ARC] Fix FPX/FPUDA code gen when compiling for big-endian.
  [ARC] Pass mfpuda to assembler.
  [ARC] Handle FPX NaN within optimized floating point library.
  [ARC] Fix unwanted match for sign extend 16-bit constant.
  [ARC] Various instruction pattern fixes

 gcc/config/arc/arc.c   |  12 ++-
 gcc/config/arc/arc.h   |   2 +-
 gcc/config/arc/arc.md  | 154 -
 gcc/config/arc/fpx.md  |   7 +-
 gcc/testsuite/gcc.target/arc/ieee_eq.c |  47 +
 gcc/testsuite/gcc.target/arc/trsub.c   |  10 ++
 gcc/testsuite/gcc.target/arc/umulsihi3_z.c |  23 +
 libgcc/config/arc/ieee-754/eqdf2.S |  13 ++-
 8 files changed, 186 insertions(+), 82 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/arc/ieee_eq.c
 create mode 100644 gcc/testsuite/gcc.target/arc/trsub.c
 create mode 100644 gcc/testsuite/gcc.target/arc/umulsihi3_z.c

-- 
1.9.1



Re: [PATCH] [AArch64] support -mfentry feature for arm64

2016-04-18 Thread Andrew Haley
On 04/15/2016 06:29 PM, Alexander Monakov wrote:

> Alternatively: replace first nop with a short forward branch that
> jumps over the rest of the pad, patch rest of the pad, patch the
> initial forward branch.

That may not be safe.  Consider an implementation which looks ahead in
the instruction stream and decodes the instructions speculatively.  I
suppse you could begin the block of instructions after the branch with
an ISB.  On balance, the trap sounds like the best plan.  We do this
in Java all the time: every method begins with a NOP, and we patch it
either to a trap or to a call to the replacement code.

Andrew.



Re: [PATCH] [AArch64] support -mfentry feature for arm64

2016-04-18 Thread Szabolcs Nagy
On 18/04/16 14:26, Alexander Monakov wrote:
> On Thu, 14 Apr 2016, Szabolcs Nagy wrote:
>> looking at [2] i don't see why
>>
>> func:
>>   mov x9, x30
>>   bl _tracefunc
>>   
>>
>> is not good for the kernel.
>>
>> mov x9, x30 is a nop at function entry, so in
>> theory 4 byte atomic write should be enough
>> to enable/disable tracing.
> 
> Overwriting x9 can be problematic because GCC has gained the ability to track
> register usage interprocedurally: if foo() calls bar(), and GCC has already
> emitted code for bar() and knows that it cannot change x9, it can use that
> knowledge to avoid saving/restoring x9 in foo() around calls to bar(). See
> option '-fipa-ra'.
> 
> If there's no register that can be safely used in place of x9 here, then
> the backend should emit the entry/pad appropriately (e.g. with an unspec that
> clobbers the possibly-overwritten register).
> 

(1) nop padded function can be assumed to clobber all temp regs
(2) or _tracefunc must save/restore all temp regs, not just arg regs.

on x86_64, glibc and linux _mcount and __fentry__ don't
save %r11 (temp reg), only the arg regs, so i think nop
padding should behave the same way (1).

> Or, with Michael Matz' suggestion, there can be one nop at function start and
> a big enough pad just before the function, and that pad can just push/pop x30
> on its own.
> 
> Alexander
> 



Re: [PATCH] [AArch64] support -mfentry feature for arm64

2016-04-18 Thread Alexander Monakov
On Mon, 18 Apr 2016, Ramana Radhakrishnan wrote:
> > - and GCC is not smart enough to be aware that intra-TU calls to 'func' (the
> >   function we're instrumenting) don't touch x16/x17.  And GCC should be that
> >   smart, if it's not, it's a bug, right? :)
> > 
> 
> That it already is - IIRC. Otherwise -fipa-ra wouldn't work .

Only if the TU is huge, or -ffunction-sections is in effect, right? Otherwise
if the TU is sufficiently small, GCC can be sure that no veneer is needed. Or
am I missing something?

> Alternatively just add x9 to the list for fipa-ra the same way as x16 / x17
> are handled already , no ?

I wouldn't recommend that; I think making it apparent as a register clobber as
part of unspec signifying the pad is better.

Thanks.
Alexander


Re: [PATCH] [AArch64] support -mfentry feature for arm64

2016-04-18 Thread Ramana Radhakrishnan


On 18/04/16 14:44, Alexander Monakov wrote:
> On Mon, 18 Apr 2016, Ramana Radhakrishnan wrote:
>> On Mon, Apr 18, 2016 at 2:26 PM, Alexander Monakov  
>> wrote:
>>> On Thu, 14 Apr 2016, Szabolcs Nagy wrote:
 looking at [2] i don't see why

 func:
   mov x9, x30
   bl _tracefunc
   

 is not good for the kernel.

 mov x9, x30 is a nop at function entry, so in
 theory 4 byte atomic write should be enough
 to enable/disable tracing.
>>>
>>> Overwriting x9 can be problematic because GCC has gained the ability to 
>>> track
>>> register usage interprocedurally: if foo() calls bar(), and GCC has already
>>> emitted code for bar() and knows that it cannot change x9, it can use that
>>> knowledge to avoid saving/restoring x9 in foo() around calls to bar(). See
>>> option '-fipa-ra'.
>>>
>>> If there's no register that can be safely used in place of x9 here, then
>>> the backend should emit the entry/pad appropriately (e.g. with an unspec 
>>> that
>>> clobbers the possibly-overwritten register).
>>
>> Can you not use one of x16 / x17 the intra-procedure-call scratch
>> registers as per the PCS ?
> 
> As long as:
> 
> - there's a guarantee that the call to _tracefunc wouldn't need some kind of
>   veneer that would clobber those; I don't know enough about AArch64 to say;
> 

A veneer could clobber them, yeah .

> - and GCC is not smart enough to be aware that intra-TU calls to 'func' (the
>   function we're instrumenting) don't touch x16/x17.  And GCC should be that
>   smart, if it's not, it's a bug, right? :)
> 

That it already is - IIRC. Otherwise -fipa-ra wouldn't work .

Alternatively just add x9 to the list for fipa-ra the same way as x16 / x17 are 
handled already , no ?

Ramana

> Thanks.
> Alexander
> 


Re: [PATCH] [AArch64] support -mfentry feature for arm64

2016-04-18 Thread Alexander Monakov
On Mon, 18 Apr 2016, Ramana Radhakrishnan wrote:
> On Mon, Apr 18, 2016 at 2:26 PM, Alexander Monakov  wrote:
> > On Thu, 14 Apr 2016, Szabolcs Nagy wrote:
> >> looking at [2] i don't see why
> >>
> >> func:
> >>   mov x9, x30
> >>   bl _tracefunc
> >>   
> >>
> >> is not good for the kernel.
> >>
> >> mov x9, x30 is a nop at function entry, so in
> >> theory 4 byte atomic write should be enough
> >> to enable/disable tracing.
> >
> > Overwriting x9 can be problematic because GCC has gained the ability to 
> > track
> > register usage interprocedurally: if foo() calls bar(), and GCC has already
> > emitted code for bar() and knows that it cannot change x9, it can use that
> > knowledge to avoid saving/restoring x9 in foo() around calls to bar(). See
> > option '-fipa-ra'.
> >
> > If there's no register that can be safely used in place of x9 here, then
> > the backend should emit the entry/pad appropriately (e.g. with an unspec 
> > that
> > clobbers the possibly-overwritten register).
> 
> Can you not use one of x16 / x17 the intra-procedure-call scratch
> registers as per the PCS ?

As long as:

- there's a guarantee that the call to _tracefunc wouldn't need some kind of
  veneer that would clobber those; I don't know enough about AArch64 to say;

- and GCC is not smart enough to be aware that intra-TU calls to 'func' (the
  function we're instrumenting) don't touch x16/x17.  And GCC should be that
  smart, if it's not, it's a bug, right? :)

Thanks.
Alexander


Re: [PATCH] [AArch64] support -mfentry feature for arm64

2016-04-18 Thread Ramana Radhakrishnan
On Mon, Apr 18, 2016 at 2:26 PM, Alexander Monakov  wrote:
> On Thu, 14 Apr 2016, Szabolcs Nagy wrote:
>> looking at [2] i don't see why
>>
>> func:
>>   mov x9, x30
>>   bl _tracefunc
>>   
>>
>> is not good for the kernel.
>>
>> mov x9, x30 is a nop at function entry, so in
>> theory 4 byte atomic write should be enough
>> to enable/disable tracing.
>
> Overwriting x9 can be problematic because GCC has gained the ability to track
> register usage interprocedurally: if foo() calls bar(), and GCC has already
> emitted code for bar() and knows that it cannot change x9, it can use that
> knowledge to avoid saving/restoring x9 in foo() around calls to bar(). See
> option '-fipa-ra'.
>
> If there's no register that can be safely used in place of x9 here, then
> the backend should emit the entry/pad appropriately (e.g. with an unspec that
> clobbers the possibly-overwritten register).

Can you not use one of x16 / x17 the intra-procedure-call scratch
registers as per the PCS ?

regards
Ramana

>
> Or, with Michael Matz' suggestion, there can be one nop at function start and
> a big enough pad just before the function, and that pad can just push/pop x30
> on its own.
>
> Alexander


Re: [PATCH] [AArch64] support -mfentry feature for arm64

2016-04-18 Thread Alexander Monakov
On Thu, 14 Apr 2016, Szabolcs Nagy wrote:
> looking at [2] i don't see why
> 
> func:
>   mov x9, x30
>   bl _tracefunc
>   
> 
> is not good for the kernel.
> 
> mov x9, x30 is a nop at function entry, so in
> theory 4 byte atomic write should be enough
> to enable/disable tracing.

Overwriting x9 can be problematic because GCC has gained the ability to track
register usage interprocedurally: if foo() calls bar(), and GCC has already
emitted code for bar() and knows that it cannot change x9, it can use that
knowledge to avoid saving/restoring x9 in foo() around calls to bar(). See
option '-fipa-ra'.

If there's no register that can be safely used in place of x9 here, then
the backend should emit the entry/pad appropriately (e.g. with an unspec that
clobbers the possibly-overwritten register).

Or, with Michael Matz' suggestion, there can be one nop at function start and
a big enough pad just before the function, and that pad can just push/pop x30
on its own.

Alexander


Re: [PATCH] Improve PTA restrict handling for non-restrict pointers

2016-04-18 Thread Richard Biener
On Mon, Feb 15, 2016 at 11:16 AM, Richard Biener  wrote:
>
> Currently we only disambiguate restrict based accesses against pointer
> based accesses that end up using a default def.  The following removes
> this restriction allowing disambiguation against any pointer based
> access where PTA computed that the pointer cannot point to one of the
> restrict tags we used to assign bases != 0 to.
>
> This results in extra disambigations (all non-restrict pointer IV
> uses were not handled previously), see the added vectorizer testcase.
>
> Bootstrapped and tested on x86_64-unknown-linux-gnu, queued for GCC 7.

Re-bootstrapped / tested and committed as r235147.

Richard.

> Richard.
>
> 2016-02-12  Richard Biener  
>
> PR tree-optimization/43434
> * tree-ssa-structalias.c (struct vls_data): New.
> (visit_loadstore): Handle all pointer-based accesses.
> (compute_dependence_clique): Compute a bitmap of restrict tags
> assigned bases and pass it to visit_loadstore.
>
> * gcc.dg/vect/pr43434.c: New testcase.
> * c-c++-common/goacc/kernels-alias-3.c: Adjust.
> * c-c++-common/goacc/kernels-alias-4.c: Likewise.
> * c-c++-common/goacc/kernels-alias-5.c: Likewise.
> * c-c++-common/goacc/kernels-alias-6.c: Likewise.
> * c-c++-common/goacc/kernels-alias-7.c: Likewise.
> * c-c++-common/goacc/kernels-alias-8.c: Likewise.
> * gcc.dg/gomp/pr68640.c: Likewise.
>
> Index: gcc/tree-ssa-structalias.c
> ===
> *** gcc/tree-ssa-structalias.c  (revision 233369)
> --- gcc/tree-ssa-structalias.c  (working copy)
> *** delete_points_to_sets (void)
> *** 7162,7174 
> obstack_free (_solutions_obstack, NULL);
>   }
>
>   /* Mark "other" loads and stores as belonging to CLIQUE and with
>  base zero.  */
>
>   static bool
> ! visit_loadstore (gimple *, tree base, tree ref, void *clique_)
>   {
> !   unsigned short clique = (uintptr_t)clique_;
> if (TREE_CODE (base) == MEM_REF
> || TREE_CODE (base) == TARGET_MEM_REF)
>   {
> --- 7162,7181 
> obstack_free (_solutions_obstack, NULL);
>   }
>
> + struct vls_data
> + {
> +   unsigned short clique;
> +   bitmap rvars;
> + };
> +
>   /* Mark "other" loads and stores as belonging to CLIQUE and with
>  base zero.  */
>
>   static bool
> ! visit_loadstore (gimple *, tree base, tree ref, void *data)
>   {
> !   unsigned short clique = ((vls_data *) data)->clique;
> !   bitmap rvars = ((vls_data *) data)->rvars;
> if (TREE_CODE (base) == MEM_REF
> || TREE_CODE (base) == TARGET_MEM_REF)
>   {
> *** visit_loadstore (gimple *, tree base, tr
> *** 7176,7188 
> if (TREE_CODE (ptr) == SSA_NAME
>   && ! SSA_NAME_IS_DEFAULT_DEF (ptr))
> {
> ! /* ???  We need to make sure 'ptr' doesn't include any of
>  the restrict tags we added bases for in its points-to set.  */
> ! return false;
> }
>
> -   /* For now let decls through.  */
> -
> /* Do not overwrite existing cliques (that includes clique, base
>pairs we just set).  */
> if (MR_DEPENDENCE_CLIQUE (base) == 0)
> --- 7183,7199 
> if (TREE_CODE (ptr) == SSA_NAME
>   && ! SSA_NAME_IS_DEFAULT_DEF (ptr))
> {
> ! /* We need to make sure 'ptr' doesn't include any of
>  the restrict tags we added bases for in its points-to set.  */
> ! varinfo_t vi = lookup_vi_for_tree (ptr);
> ! if (! vi)
> !   return false;
> !
> ! vi = get_varinfo (find (vi->id));
> ! if (bitmap_intersect_p (rvars, vi->solution))
> !   return false;
> }
>
> /* Do not overwrite existing cliques (that includes clique, base
>pairs we just set).  */
> if (MR_DEPENDENCE_CLIQUE (base) == 0)
> *** compute_dependence_clique (void)
> *** 7255,7260 
> --- 7266,7272 
>   {
> unsigned short clique = 0;
> unsigned short last_ruid = 0;
> +   bitmap rvars = BITMAP_ALLOC (NULL);
> for (unsigned i = 0; i < num_ssa_names; ++i)
>   {
> tree ptr = ssa_name (i);
> *** compute_dependence_clique (void)
> *** 7310,7347 
>   /* Now look at possible dereferences of ptr.  */
>   imm_use_iterator ui;
>   gimple *use_stmt;
>   FOR_EACH_IMM_USE_STMT (use_stmt, ui, ptr)
> {
>   /* ???  Calls and asms.  */
>   if (!gimple_assign_single_p (use_stmt))
> continue;
> ! maybe_set_dependence_info (gimple_assign_lhs (use_stmt), ptr,
> !clique, restrict_var, last_ruid);
> ! maybe_set_dependence_info (gimple_assign_rhs1 (use_stmt), ptr,
> !clique, restrict_var, last_ruid);
> }
>

Re: Allow embedded timestamps by C/C++ macros to be set externally (3)

2016-04-18 Thread Markus Trippelsdorf
On 2016.04.18 at 14:26 +0200, Dhole wrote:
> Hi!
> 
> A few months ago I submited a patch to allow the embedded timestamps by
> C/C++ macros to be set externally [2], which was already an improvement
> over [1].  I was told to wait until the GCC 7 stage 1 started to send
> this patch again.

A nice follow-up patch would be to set SOURCE_DATE_EPOCH to the current
time during -fcompare-debug. This would avoid false positives like:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70679

-- 
Markus


[Ada] File descriptors leaking

2016-04-18 Thread Arnaud Charlet
Two file descriptors are never closed when invoking Non_Blocking_Spawn version
with String parameters Stdout_File and Stderr_File. They are now closed.

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

2016-04-18  Vincent Celier  

* s-os_lib.adb (Non_Blocking_Spawn, version with Stdout_File and
Stderr_File): Close local file descriptors when no longer needed.

Index: s-os_lib.adb
===
--- s-os_lib.adb(revision 235093)
+++ s-os_lib.adb(working copy)
@@ -1867,6 +1867,14 @@
 
   Result := Non_Blocking_Spawn (Program_Name, Args);
 
+  --  Close the files just created for the output, as the file descriptors
+  --  cannot be used anywhere, being local values. It is safe to do that,
+  --  as the file descriptors have been duplicated to form standard output
+  --  and standard error of the spawned process.
+
+  Close (Stdout_FD);
+  Close (Stderr_FD);
+
   --  Restore the standard output and error
 
   Dup2 (Saved_Output, Standout);


[Ada] Compiler error and crash over iterators over qualified expressions.

2016-04-18 Thread Arnaud Charlet
This patch handles properly Ada 2012 loops whose iterator specification is
a qualified expression whose type is derived from an iterator type.

Executing

   gnatmake -q ice_primes_2.adb
   ice_primes_2

must yield:

 3
 5
 7
 11
 13
 17
 19
 23
 29
 31

---
with Ada.Text_IO;
with F552A00_Prime_Numbers; use F552A00_Prime_Numbers;
procedure ICE_Primes_2 is
   It : constant Prime_Number_Set
 := Prime_Number_Set'(Max_Value => 32);
begin
   for P in It
   loop
  Ada.Text_IO.Put_Line (P'Img);
   end loop;
end ICE_Primes_2;
---
with Ada.Iterator_Interfaces;
with Ada.Strings.Unbounded; use Ada;

package F552A00_Prime_Numbers is

   --  This package defines a simple Iterator Type that represents a
   --  set of prime numbers from 1 to N.

   function Is_Prime (Value : Natural) return Boolean;

   package Prime_Number_Iterator is new Ada.Iterator_Interfaces (
  Cursor  => Natural,
  Has_Element => Is_Prime);

   type Prime_Number_Set (Max_Value : Natural) is new
 Prime_Number_Iterator.Forward_Iterator with null record;
   --  A Prime_Number_Set represents all the prime numbers between
   --  1 and Max_Value. Two is not considered to be a prime number.
   --  Max_Value may or may not be a prime number

   overriding function First (Object : Prime_Number_Set) return Natural;

   overriding function Next
 (Object : Prime_Number_Set;
  Value  : Natural)
  return   Natural;

   function Iterate
 (Set  : Prime_Number_Set)
  return Prime_Number_Iterator.Forward_Iterator'Class;

   TC_Call_History : Strings.Unbounded.Unbounded_String;
   --
   --  A string capturing the call sequence to the above subprogams.
   --  The following gets appended to the history for the above calls;
   --  Iterate  => I
   --  First=> 1
   --  Next => N( nn)where nn is the next prime number
   --  Is_Prime => H:{T|F}( nn)  H is the Has_Element function
   --  T means Has_Element returned True
   --  F means Has_Element returns False
   --  nn is the current prime number

end F552A00_Prime_Numbers;
---
with Ada.Numerics.Elementary_Functions; use Ada.Numerics.Elementary_Functions;
package body F552A00_Prime_Numbers is

   Disable_History : Boolean := False;
   --  Used to disable call history for calls to Is_Prime that are internal
   --  and not called as a result of loop iteration.

   function First (Object : Prime_Number_Set) return Natural is
   begin
  --  The first prime number is 3, unless the Prime_Number_Set only
  --  goes up to 2 or less, in which case a non-prime number is returned
  --  since the set does not contain a prime number.

  Ada.Strings.Unbounded.Append (Source => TC_Call_History,
New_Item => '1');
  return (if Object.Max_Value >= 3 then 3 else Object.Max_Value);
   end First;

   function Next
 (Object : Prime_Number_Set;
  Value  : Natural)
  return   Natural is
   begin

  --  Disable logging of calls to Is_Prime inside this loop, since these
  --  calls are not directly related to iterator types.
  Disable_History := True;

  for I in Value + 1 .. Object.Max_Value loop
 if Is_Prime (I) then
Ada.Strings.Unbounded.Append
  (Source   => TC_Call_History,
   New_Item => "N(" & Integer'Image (I) & ')');
Disable_History := False;
return I;
 end if;
  end loop;
  Disable_History := False;

  Ada.Strings.Unbounded.Append
(Source   => TC_Call_History,
 New_Item => "N(" & Integer'Image (Value + 1) & ')');

  return Value + 1;
   end Next;

   function Is_Prime (Value : Natural) return Boolean is
   begin
  for I in 2 .. Integer (Sqrt (Float (Value))) loop
 if Value mod I = 0 then

--  Not a prime number
if not Disable_History then
   Ada.Strings.Unbounded.Append
 (Source   => TC_Call_History,
  New_Item => "H:F(" & Integer'Image (Value) & ')');
end if;

return False;
 end if;
  end loop;

  --  Is a prime number if the value is > 2.
  if not Disable_History then
 Ada.Strings.Unbounded.Append
   (Source   => TC_Call_History,
New_Item => "H:" &
(if Value > 2 then "T(" else "F(") &
Integer'Image (Value) &
')');
  end if;

  return (Value > 2);
   end Is_Prime;

   function Iterate
 (Set  : Prime_Number_Set)
  return Prime_Number_Iterator.Forward_Iterator'Class is
   begin
  Ada.Strings.Unbounded.Append (Source => TC_Call_History,
New_Item => 'I');
  return Result : Prime_Number_Set (Set.Max_Value) do
 null;
  end return;
   end Iterate;

end F552A00_Prime_Numbers;

Tested on 

[Ada] Issue check instead of error in static division by zero

2016-04-18 Thread Arnaud Charlet
In some cases of generic instantiations, or code configuration, some code
may be deactivated and contain static divisions by zero. Instead of
issuing an error in SPARK code, generate a suitable check.

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

2016-04-18  Yannick Moy  

* sem_eval.adb (Eval_Arithmetic_Op): Do not issue error on static
division by zero, instead possibly issue a warning.
* sem_res.adb (Resolve_Arithmetic_Op): Do not issue error on
static division by zero, instead add check flag on original
expression.
* sem_util.adb, sem_util.ads (Compile_Time_Constraint_Error):
Only issue error when both SPARK_Mode is On and Warn is False.

Index: sem_util.adb
===
--- sem_util.adb(revision 235122)
+++ sem_util.adb(working copy)
@@ -4574,9 +4574,16 @@
 
begin
   --  If this is a warning, convert it into an error if we are in code
-  --  subject to SPARK_Mode being set ON.
+  --  subject to SPARK_Mode being set On, unless Warn is True to force a
+  --  warning. The rationale is that a compile-time constraint error should
+  --  lead to an error instead of a warning when SPARK_Mode is On, but in
+  --  a few cases we prefer to issue a warning and generate both a suitable
+  --  run-time error in GNAT and a suitable check message in GNATprove.
+  --  Those cases are those that likely correspond to deactivated SPARK
+  --  code, so that this kind of code can be compiled and analyzed instead
+  --  of being rejected.
 
-  Error_Msg_Warn := SPARK_Mode /= On;
+  Error_Msg_Warn := Warn or SPARK_Mode /= On;
 
   --  A static constraint error in an instance body is not a fatal error.
   --  we choose to inhibit the message altogether, because there is no
@@ -4648,8 +4655,6 @@
  --  evaluated.
 
  if not Is_Statically_Unevaluated (N) then
-Error_Msg_Warn := SPARK_Mode /= On;
-
 if Present (Ent) then
Error_Msg_NEL (Msgc (1 .. Msgl), N, Ent, Eloc);
 else
Index: sem_util.ads
===
--- sem_util.ads(revision 235122)
+++ sem_util.ads(working copy)
@@ -135,7 +135,9 @@
--  is present, this is used instead. Warn is normally False. If it is
--  True then the message is treated as a warning even though it does
--  not end with a ? (this is used when the caller wants to parameterize
-   --  whether an error or warning is given).
+   --  whether an error or warning is given), or when the message should be
+   --  treated as a warning even when SPARK_Mode is On (which otherwise would
+   --  force an error).
 
function Async_Readers_Enabled (Id : Entity_Id) return Boolean;
--  Given the entity of an abstract state or a variable, determine whether
Index: sem_res.adb
===
--- sem_res.adb (revision 235116)
+++ sem_res.adb (working copy)
@@ -5440,7 +5440,9 @@
  and then Expr_Value_R (Rop) = Ureal_0))
 then
--  Specialize the warning message according to the operation.
-   --  The following warnings are for the case
+   --  When SPARK_Mode is On, force a warning instead of an error
+   --  in that case, as this likely corresponds to deactivated
+   --  code. The following warnings are for the case
 
case Nkind (N) is
   when N_Op_Divide =>
@@ -5459,23 +5461,26 @@
   ("float division by zero, may generate "
& "'+'/'- infinity??", Right_Opnd (N));
 
---  For all other cases, we get a Constraint_Error
+ --  For all other cases, we get a Constraint_Error
 
  else
 Apply_Compile_Time_Constraint_Error
   (N, "division by zero??", CE_Divide_By_Zero,
-   Loc => Sloc (Right_Opnd (N)));
+   Loc  => Sloc (Right_Opnd (N)),
+   Warn => SPARK_Mode = On);
  end if;
 
   when N_Op_Rem =>
  Apply_Compile_Time_Constraint_Error
(N, "rem with zero divisor??", CE_Divide_By_Zero,
-Loc => Sloc (Right_Opnd (N)));
+Loc  => Sloc (Right_Opnd (N)),
+Warn => SPARK_Mode = On);
 
   when N_Op_Mod =>
  Apply_Compile_Time_Constraint_Error
(N, "mod with zero divisor??", CE_Divide_By_Zero,
-Loc => Sloc (Right_Opnd (N)));
+Loc  => Sloc (Right_Opnd (N)),
+Warn => SPARK_Mode = On);
 

Allow embedded timestamps by C/C++ macros to be set externally (3)

2016-04-18 Thread Dhole
Hi!

A few months ago I submited a patch to allow the embedded timestamps by
C/C++ macros to be set externally [2], which was already an improvement
over [1].  I was told to wait until the GCC 7 stage 1 started to send
this patch again.

I'm quoting from the original emails:

> As a reminder for the motivation behind this patch, we are working on
> the reproducible builds project which aims to provide users with a way
> to reproduce bit-for-bit identical binary packages from the source and
> build environment. The project involves Debian as well as several other
> free software projects. See  for more
> information.

> In order to do this, we need to make the build processes
> deterministic.  As you can imagine, gcc is quite involved in producing
> Debian packages.  One issue we encounter in many packages that fail to
> build reproducibly is the use of the __DATE__, __TIME__ C macros [3],
> right now we have 442 affected packages that would need patching
> (either removing the macros, or passing a known date externally).

> A solution for toolchain packages that embed timestamps during the
> build process has been proposed for anyone interested and it consists
> of the following: The build environment can export an environment
> variable called SOURCE_DATE_EPOCH with a known timestamp in Unix epoch
> format (In our case, we use the last date of the package's debian
> changelog). The toolchain package running during the build can check
> if the exported variable is set and if so, instead of embedding the
> local date/time, embed the date/time from SOURCE_DATE_EPOCH.

> The proposal to use SOURCE_DATE_EPOCH has now been gathered in a more
> formal specification [4], so that any project can adhere to it to
> achieve reproducible builds when dealing with timestamps.

> It would be very beneficial to our project (and other free software
> projects working on reproducible builds) if gcc supported this
> feature.

I'm attaching a patch for the svn/trunk GCC repository (now GCC 7) that
enables this feature: it modifies the behavior of the macros __DATE__
and __TIME__ when the environment variable SOURCE_DATE_EPOCH is
exported.

Documentation of the environment variable is also provided.

Note: I have already gone through the copyright assignment process :)


[1] https://gcc.gnu.org/ml/gcc-patches/2015-06/msg02210.html
[2] https://gcc.gnu.org/ml/gcc-patches/2015-11/msg01890.html
[3] https://wiki.debian.org/ReproducibleBuilds/TimestampsFromCPPMacros
[4] https://reproducible-builds.org/specs/source-date-epoch/

Best regards,
-- 
Dhole
diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c
index f2846bb..3a83673 100644
--- a/gcc/c-family/c-common.c
+++ b/gcc/c-family/c-common.c
@@ -12741,4 +12741,38 @@ valid_array_size_p (location_t loc, tree type, tree 
name)
   return true;
 }
 
+/* Read SOURCE_DATE_EPOCH from environment to have a deterministic
+   timestamp to replace embedded current dates to get reproducible
+   results. Returns -1 if SOURCE_DATE_EPOCH is not defined.  */
+long long
+get_source_date_epoch()
+{
+  char *source_date_epoch;
+  unsigned long long epoch;
+  char *endptr;
+
+  source_date_epoch = getenv ("SOURCE_DATE_EPOCH");
+  if (!source_date_epoch)
+return -1;
+
+  errno = 0;
+  epoch = strtoull (source_date_epoch, , 10);
+  if ((errno == ERANGE && (epoch == ULLONG_MAX || epoch == 0))
+  || (errno != 0 && epoch == 0))
+fatal_error (UNKNOWN_LOCATION, "environment variable $SOURCE_DATE_EPOCH: "
+"strtoull: %s\n", xstrerror(errno));
+  if (endptr == source_date_epoch)
+fatal_error (UNKNOWN_LOCATION, "environment variable $SOURCE_DATE_EPOCH: "
+"No digits were found: %s\n", endptr);
+  if (*endptr != '\0')
+fatal_error (UNKNOWN_LOCATION, "environment variable $SOURCE_DATE_EPOCH: "
+"Trailing garbage: %s\n", endptr);
+  if (epoch > ULONG_MAX)
+fatal_error (UNKNOWN_LOCATION, "environment variable $SOURCE_DATE_EPOCH: "
+"value must be smaller than or equal to: %lu but was found to "
+"be: %llu \n", ULONG_MAX, epoch);
+
+  return (long long) epoch;
+}
+
 #include "gt-c-family-c-common.h"
diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h
index fa3746c..b4d6afc 100644
--- a/gcc/c-family/c-common.h
+++ b/gcc/c-family/c-common.h
@@ -1467,4 +1467,9 @@ extern bool reject_gcc_builtin (const_tree, location_t = 
UNKNOWN_LOCATION);
 extern void warn_duplicated_cond_add_or_warn (location_t, tree, vec **);
 extern bool valid_array_size_p (location_t, tree, tree);
 
+/* Read SOURCE_DATE_EPOCH from environment to have a deterministic
+   timestamp to replace embedded current dates to get reproducible
+   results. Returns -1 if SOURCE_DATE_EPOCH is not defined.  */
+extern long long get_source_date_epoch();
+
 #endif /* ! GCC_C_COMMON_H */
diff --git a/gcc/c-family/c-lex.c b/gcc/c-family/c-lex.c
index 96da4fc..2454c6f 100644
--- a/gcc/c-family/c-lex.c
+++ 

[Ada] Stream output to fifos

2016-04-18 Thread Arnaud Charlet
This patch fixes a regression in stream output to fifos (named pipes). When a
fifo is opened for output, the process should block until another process opens
the fifo for reading. This is now (again) the case.

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

2016-04-18  Bob Duff  

* s-fileio.adb (Fopen_Mode): If Mode = Out_File, and the file
exists, and it's a fifo, we use "w" as the open string instead of
"r+". This is necessary to make a write to the fifo block until
a reader is ready.

Index: cstreams.c
===
--- cstreams.c  (revision 235093)
+++ cstreams.c  (working copy)
@@ -39,6 +39,8 @@
 
 #include 
 #include 
+#include 
+#include 
 
 #ifdef _AIX
 /* needed to avoid conflicting declarations */
@@ -320,6 +322,24 @@
 }
 #endif
 
+/* Returns true if the path names a fifo (i.e. a named pipe). */
+int
+__gnat_is_fifo (const char* path)
+{
+/* Posix defines S_ISFIFO as a macro. If the macro doesn't exist, we return
+   false. */
+#ifdef S_ISFIFO
+  struct stat buf;
+  const int status = stat(path, );
+  if (status == 0)
+return S_ISFIFO(buf.st_mode);
+#endif
+
+  /* S_ISFIFO is not available, or stat got an error (probably
+ file not found). */
+  return 0;
+}
+
 #ifdef __cplusplus
 }
 #endif
Index: s-fileio.adb
===
--- s-fileio.adb(revision 235093)
+++ s-fileio.adb(working copy)
@@ -106,17 +106,18 @@
--  Holds open string (longest is "w+b" & nul)
 
procedure Fopen_Mode
- (Mode: File_Mode;
+ (Namestr : String;
+  Mode: File_Mode;
   Text: Boolean;
   Creat   : Boolean;
   Amethod : Character;
   Fopstr  : out Fopen_String);
--  Determines proper open mode for a file to be opened in the given Ada
-   --  mode. Text is true for a text file and false otherwise, and Creat is
-   --  true for a create call, and False for an open call. The value stored
-   --  in Fopstr is a nul-terminated string suitable for a call to fopen or
-   --  freopen. Amethod is the character designating the access method from
-   --  the Access_Method field of the FCB.
+   --  mode. Namestr is the NUL-terminated file name. Text is true for a text
+   --  file and false otherwise, and Creat is true for a create call, and False
+   --  for an open call. The value stored in Fopstr is a nul-terminated string
+   --  suitable for a call to fopen or freopen. Amethod is the character
+   --  designating the access method from the Access_Method field of the FCB.
 
function Errno_Message
  (Name  : String;
@@ -433,10 +434,14 @@
-- OPEN CREATE
-- Append_File "r+"   "w+"
-- In_File "r""w+"
-   -- Out_File (Direct_IO, Stream_IO) "r+"   "w"
+   -- Out_File (Direct_IO, Stream_IO) "r+" [*]   "w"
-- Out_File (others)   "w""w"
-- Inout_File  "r+"   "w+"
 
+   --  [*] Except that for Out_File, if the file exists and is a fifo (i.e. a
+   --  named pipe), we use "w" instead of "r+". This is necessary to make a
+   --  write to the fifo block until a reader is ready.
+
--  Note: we do not use "a" or "a+" for Append_File, since this would not
--  work in the case of stream files, where even if in append file mode,
--  you can reset to earlier points in the file. The caller must use the
@@ -458,7 +463,8 @@
--  to the mode, depending on the setting of Text.
 
procedure Fopen_Mode
- (Mode: File_Mode;
+ (Namestr : String;
+  Mode: File_Mode;
   Text: Boolean;
   Creat   : Boolean;
   Amethod : Character;
@@ -466,6 +472,9 @@
is
   Fptr : Positive;
 
+  function is_fifo (Path : Address) return Integer;
+  pragma Import (C, is_fifo, "__gnat_is_fifo");
+
begin
   case Mode is
  when In_File =>
@@ -479,7 +488,10 @@
 end if;
 
  when Out_File =>
-if Amethod in 'D' | 'S' and then not Creat then
+if Amethod in 'D' | 'S'
+  and then not Creat
+  and then is_fifo (Namestr'Address) = 0
+then
Fopstr (1) := 'r';
Fopstr (2) := '+';
Fptr := 3;
@@ -1045,7 +1057,7 @@
 
  else
 Fopen_Mode
-  (Mode, Text_Encoding in Text_Content_Encoding,
+  (Namestr, Mode, Text_Encoding in Text_Content_Encoding,
Creat, Amethod, Fopstr);
 
 --  A special case, if we are opening (OPEN case) a file and the
@@ -1218,7 +1230,7 @@
 
   else
  Fopen_Mode
-   (Mode, File.Text_Encoding in Text_Content_Encoding,
+   (File.Name.all, Mode, File.Text_Encoding in Text_Content_Encoding,
 False, File.Access_Method, 

Re: [PR target/70711][ARM] Fix big-endian ARMv8.1-A builds.

2016-04-18 Thread Matthew Wahab

On 18/04/16 10:41, Richard Biener wrote:

On Mon, 18 Apr 2016, Ramana Radhakrishnan wrote:


Testing for armeb-none-eabi with cross-compiled check-gcc and with
command line testing to confirm working executables are built.

Is this ok for trunk and for GCC-6 once testing is completed?


Oops, Thanks for catching this -

Ok for trunk.

Ok for GCC-6 by me but you need RM sign off before applying to the branch.


Ok.

Thanks,
Richard.



Tested and committed to trunk and GCC-6.
Matthew



Re: [PATCH] [AArch64] support -mfentry feature for arm64

2016-04-18 Thread Michael Matz
Hi,

On Sun, 17 Apr 2016, Alexander Monakov wrote:

> I've noticed an issue in my (and probably Michael's) solution: if 
> there's a thread that made it past the first nop, but is still executing 
> the nop pad, it's unsafe to replace the nops.  To solve that, it 
> suffices to have a forward branch in place of the first nop to begin 
> with (i.e. have the compiler emit it).

True.  I wonder if the generic solution in GCC should do that always or if 
the patch infrastructure should do that to enable more freedom like doing 
this:

> But if Szabolcs' two-instruction 
> sequence in the adjacent subthread is sufficient, this is moot.

.  It can also be solved by having just one NOP after the function label, 
and a number of them before, then no thread can be in the nop pad.  That 
seems to indicate that GCC should not try to be too clever and simply 
leave the specified number of nops before and after the function label, 
leaving safety measures to the patching infrastructure.


Ciao,
Michael.


[Ada] Improved error message for illegal procedure function definition.

2016-04-18 Thread Arnaud Charlet
This patch adds information on an illegal definition for a stream procedure,
indicating that the second argument of the procedure must be a first subtype.

Compiling host-msg.ads must yield:

   host-msg.ads:11:08: formal of stream operation must be a first subtype
   host-msg.ads:12:41: incorrect expression for "Read" attribute
   host-msg.ads:16:07: formal of stream operation must be a first subtype
   host-msg.ads:17:42: incorrect expression for "Write" attribute

---
with Ada.Streams;
package Host.Msg is


   type T_THD441_Connection_Req is new Host.T_Msg with null record;

   subtype  T_Msg  is T_THD441_Connection_Req;

   procedure Read_THD441_Connection_Req
  (Stream : access Ada.Streams.Root_Stream_Type'Class;
   Msg: out T_Msg);
   for T_THD441_Connection_Req'Read use Read_THD441_Connection_Req;

   procedure Write_THD441_Connection_Req
 (Stream : access Ada.Streams.Root_Stream_Type'Class;
  Msg: in T_Msg);
   for T_THD441_Connection_Req'Write use Write_THD441_Connection_Req;

end Host.Msg;
---
package Host is
   type T_Msg is tagged record
  Field_1 : Integer;
  Field_2 :Integer;
   end record;
end Host;

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

2016-04-18  Ed Schonberg  

* sem_ch13.adb (Analyze_Stream_TSS_Definition,
Has_Good_Profile): Additional error message to indicate that
the second parameter of the subprogram must be a first subtype.

Index: sem_ch13.adb
===
--- sem_ch13.adb(revision 235093)
+++ sem_ch13.adb(working copy)
@@ -3754,15 +3754,21 @@
  Is_Read : constant Boolean := (TSS_Nam = TSS_Stream_Read);
  --  True for Read attribute, false for other attributes
 
- function Has_Good_Profile (Subp : Entity_Id) return Boolean;
+ function Has_Good_Profile
+   (Subp   : Entity_Id;
+Report : Boolean := False) return Boolean;
  --  Return true if the entity is a subprogram with an appropriate
- --  profile for the attribute being defined.
+ --  profile for the attribute being defined. If result is false and
+ --  Report is True function emits appropriate error.
 
  --
  -- Has_Good_Profile --
  --
 
- function Has_Good_Profile (Subp : Entity_Id) return Boolean is
+ function Has_Good_Profile
+   (Subp   : Entity_Id;
+Report : Boolean := False) return Boolean
+ is
 F  : Entity_Id;
 Is_Function: constant Boolean := (TSS_Nam = TSS_Stream_Input);
 Expected_Ekind : constant array (Boolean) of Entity_Kind :=
@@ -3837,6 +3843,11 @@
   and then not Is_First_Subtype (Typ)
   and then not Is_Class_Wide_Type (Typ)
 then
+   if Report and not Is_First_Subtype (Typ) then
+  Error_Msg_N
+("formal of stream operation must be a first subtype", F);
+   end if;
+
return False;
 
 else
@@ -3885,7 +3896,7 @@
 
  if Is_Entity_Name (Expr) then
 if not Is_Overloaded (Expr) then
-   if Has_Good_Profile (Entity (Expr)) then
+   if Has_Good_Profile (Entity (Expr), Report => True) then
   Subp := Entity (Expr);
end if;
 


[Ada] Clean up global variables

2016-04-18 Thread Arnaud Charlet
This patch eliminates some uses of global variables in the GNAT front end.
No test; no change in behavior.

2016-04-18  Bob Duff  

* sem_elab.adb (Output_Calls): Use
Get_Name_String, to clearly indicate that the global Name_Buffer
is being used. The previous code used Is_Internal_Name, which
returns a Boolean, but also has a side effect of setting the
Name_Buffer. Then it called the other Is_Internal_Name, which uses
the Name_Buffer for its input. And then it called Error_Msg_N,
again using the Name_Buffer. We haven't eliminated the global
usage here, but we've made it a bit clearer.
This also allows us to have a side-effect-free version of
Is_Internal_Name.
* namet.ads, namet.adb: Provide a type Bounded_String, along with
routines that can be used without using global variables. Provide
Global_Name_Buffer so existing code can continue to use the
global. Mark the routines that use globals as obsolete.  New code
shouldn't call the obsolete ones, and we should clean up existing
code from time to time.
Name_Find_Str is renamed as Name_Find.
* namet.h: Changed as necessary to interface to the new version
of Namet.
* bindgen.adb, exp_unst.adb: Name_Find_Str is renamed as
Name_Find.

Index: bindgen.adb
===
--- bindgen.adb (revision 235093)
+++ bindgen.adb (working copy)
@@ -2922,7 +2922,7 @@
  Osint.Fail ("bind environment value """ & Value & """ too long");
   end if;
 
-  Bind_Environment.Set (Name_Find_Str (Key), Name_Find_Str (Value));
+  Bind_Environment.Set (Name_Find (Key), Name_Find (Value));
end Set_Bind_Env;
 
-
Index: exp_unst.adb
===
--- exp_unst.adb(revision 235100)
+++ exp_unst.adb(working copy)
@@ -161,7 +161,7 @@
 
   function AREC_Name (J : Pos; S : String) return Name_Id is
   begin
- return Name_Find_Str ("AREC" & Img_Pos (J) & S);
+ return Name_Find ("AREC" & Img_Pos (J) & S);
   end AREC_Name;
 
   
@@ -244,7 +244,7 @@
 if No (C) then
return Chars (Ent);
 elsif Chars (Defining_Identifier (C)) = Chars (Ent) then
-   return Name_Find_Str
+   return Name_Find
 (Get_Name_String (Chars (Ent)) & Img_Pos (Index));
 else
Next (C);
Index: namet.adb
===
--- namet.adb   (revision 235093)
+++ namet.adb   (working copy)
@@ -73,16 +73,14 @@
-- Local Subprograms --
---
 
-   function Hash return Hash_Index_Type;
+   function Hash (Buf : Bounded_String) return Hash_Index_Type;
pragma Inline (Hash);
-   --  Compute hash code for name stored in Name_Buffer (length in Name_Len)
+   --  Compute hash code for name stored in Buf
 
-   procedure Strip_Qualification_And_Suffixes;
-   --  Given an encoded entity name in Name_Buffer, remove package body
+   procedure Strip_Qualification_And_Suffixes (Buf : in out Bounded_String);
+   --  Given an encoded entity name in Buf, remove package body
--  suffix as described for Strip_Package_Body_Suffix, and also remove
-   --  all qualification, i.e. names followed by two underscores. The
-   --  contents of Name_Buffer is modified by this call, and on return
-   --  Name_Buffer and Name_Len reflect the stripped name.
+   --  all qualification, i.e. names followed by two underscores.
 
-
-- Add_Char_To_Name_Buffer --
@@ -90,10 +88,7 @@
 
procedure Add_Char_To_Name_Buffer (C : Character) is
begin
-  if Name_Len < Name_Buffer'Last then
- Name_Len := Name_Len + 1;
- Name_Buffer (Name_Len) := C;
-  end if;
+  Append (Global_Name_Buffer, C);
end Add_Char_To_Name_Buffer;
 

@@ -102,11 +97,7 @@
 
procedure Add_Nat_To_Name_Buffer (V : Nat) is
begin
-  if V >= 10 then
- Add_Nat_To_Name_Buffer (V / 10);
-  end if;
-
-  Add_Char_To_Name_Buffer (Character'Val (Character'Pos ('0') + V rem 10));
+  Append (Global_Name_Buffer, V);
end Add_Nat_To_Name_Buffer;
 

@@ -115,171 +106,56 @@
 
procedure Add_Str_To_Name_Buffer (S : String) is
begin
-  for J in S'Range loop
- Add_Char_To_Name_Buffer (S (J));
-  end loop;
+  Append (Global_Name_Buffer, S);
end Add_Str_To_Name_Buffer;
 
-   --
-   -- Finalize --
-   --
+   
+   -- Append --
+   
 
-   procedure Finalize is
-  F : array (Int range 0 .. 50) of Int;
-  --  N'th entry is the number of chains of length N, except last entry,
-  --  which is the 

[PATCH] Fix PR70701

2016-04-18 Thread Richard Biener

The following fixes a missed optimization when value-numbering
translates through memcpy calls.

Bootstrapped on x86_64-unknown-linux-gnu, testing in progress.

Richard.

2016-04-18  Richard Biener  

PR tree-optimization/70701
* tree-ssa-sccvn.c (vn_reference_lookup_3): Resolve fully constant
references after translating through a memcpy.

* gcc.dg/tree-ssa/ssa-fre-53.c: New testcase.

Index: gcc/tree-ssa-sccvn.c
===
*** gcc/tree-ssa-sccvn.c(revision 235017)
--- gcc/tree-ssa-sccvn.c(working copy)
*** vn_reference_lookup_3 (ao_ref *ref, tree
*** 2152,2157 
--- 2340,2351 
vr->operands[1] = op;
vr->hashcode = vn_reference_compute_hash (vr);
  
+   /* Try folding the new reference to a constant.  */
+   tree val = fully_constant_vn_reference_p (vr);
+   if (val)
+   return vn_reference_lookup_or_insert_for_pieces
+(vuse, vr->set, vr->type, vr->operands, val);
+ 
/* Adjust *ref from the new operands.  */
if (!ao_ref_init_from_vn_reference (, vr->set, vr->type, 
vr->operands))
return (void *)-1;
Index: gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-53.c
===
*** gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-53.c  (revision 0)
--- gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-53.c  (working copy)
***
*** 0 
--- 1,11 
+ /* { dg-do compile } */
+ /* { dg-options "-O -fno-tree-forwprop -fdump-tree-fre1" } */
+ 
+ const int a[]={1,2,3};
+ int f(){
+ int*b=__builtin_malloc(12);
+ __builtin_memcpy(b,a,12);
+ return b[0];
+ }
+ 
+ /* { dg-final { scan-tree-dump "return 1;" "fre1" } } */


[Ada] Optimization of Unbounded_Priority_Queues

2016-04-18 Thread Arnaud Charlet
This patch improves the efficiency of Ada.Containers.Unbounded_Priority_Queues,
especially in the case where many same-priority items are enqueued.

No test, because no change in behavior.

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

2016-04-18  Bob Duff  

* a-cuprqu.ads: Change the representation of List_Type from a
singly-linked list to a doubly-linked list. In addition, add a
pointer Next_Unequal, which points past a possibly-long chain
of equal-priority items. This increases efficiency, especially
in the case of many equal-priority items.
* a-cuprqu.adb (Dequeue, Enqueue): Rewrite algorithms to take
advantage of new data structure.
(Finalize): Rewrite in terms of Dequeue, for simplicity.

Index: a-cuprqu.adb
===
--- a-cuprqu.adb(revision 235093)
+++ a-cuprqu.adb(working copy)
@@ -37,9 +37,22 @@
   -- Local Subprograms --
   ---
 
+  function Before_Or_Equal (X, Y : Queue_Priority) return Boolean;
+  --  True if X is before or equal to Y. Equal means both Before(X,Y) and
+  --  Before(Y,X) are False.
+
   procedure Free is
- new Ada.Unchecked_Deallocation (Node_Type, Node_Access);
+new Ada.Unchecked_Deallocation (Node_Type, Node_Access);
 
+  -
+  -- Before_Or_Equal --
+  -
+
+  function Before_Or_Equal (X, Y : Queue_Priority) return Boolean is
+  begin
+ return (if Before (X, Y) then True else not Before (Y, X));
+  end Before_Or_Equal;
+
   -
   -- Dequeue --
   -
@@ -48,20 +61,36 @@
 (List: in out List_Type;
  Element : out Queue_Interfaces.Element_Type)
   is
- X : Node_Access;
+ H : constant Node_Access := List.Header'Unchecked_Access;
+ pragma Assert (List.Length /= 0);
+ pragma Assert (List.Header.Next /= H);
+ --  List can't be empty; see the barrier
 
-  begin
- Element := List.First.Element;
+ pragma Assert
+   (List.Header.Next.Next = H or else
+Before_Or_Equal (Get_Priority (List.Header.Next.Element),
+ Get_Priority (List.Header.Next.Next.Element)));
+ --  The first item is before-or-equal to the second
 
- X := List.First;
- List.First := List.First.Next;
+ pragma Assert
+   (List.Header.Next.Next_Unequal = H or else
+Before (Get_Priority (List.Header.Next.Element),
+Get_Priority (List.Header.Next.Next_Unequal.Element)));
+ --  The first item is before its Next_Unequal item
 
- if List.First = null then
-List.Last := null;
- end if;
+ --  The highest-priority item is always first; just remove it and
+ --  return that element.
 
+ X : Node_Access := List.Header.Next;
+
+  --  Start of processing for Dequeue
+
+  begin
+ Element := X.Element;
+ X.Next.Prev := H;
+ List.Header.Next := X.Next;
+ List.Header.Next_Unequal := X.Next;
  List.Length := List.Length - 1;
-
  Free (X);
   end Dequeue;
 
@@ -93,15 +122,13 @@
  --  dequeue an item. If it's false, it means no item is dequeued, and
  --  we return False as the Success value.
 
- if List.Length = 0
-   or else Before (At_Least, Get_Priority (List.First.Element))
- then
-Success := False;
-return;
+ Success := List.Length > 0
+   and then
+ not Before (At_Least, Get_Priority (List.Header.Next.Element));
+
+ if Success then
+List.Dequeue (Element);
  end if;
-
- List.Dequeue (Element);
- Success := True;
   end Dequeue;
 
   -
@@ -113,41 +140,55 @@
  New_Item : Queue_Interfaces.Element_Type)
   is
  P : constant Queue_Priority := Get_Priority (New_Item);
+ H : constant Node_Access := List.Header'Unchecked_Access;
 
- Node : Node_Access;
- Prev : Node_Access;
+ function Next return Node_Access;
+ --  The node before which we wish to insert the new node
 
-  begin
- Node := new Node_Type'(New_Item, null);
+ --
+ -- Next --
+ --
 
- if List.First = null then
-List.First := Node;
-List.Last := List.First;
+ function Next return Node_Access is
+ begin
+return Result : Node_Access := H.Next_Unequal do
+   while Result /= H
+ and then not Before (P, Get_Priority (Result.Element))
+   loop
+  Result := Result.Next_Unequal;
+   end loop;
+end return;
+ end Next;
 
- else
-

[Ada] Remove SPARK legality checks performed in GNATprove

2016-04-18 Thread Arnaud Charlet
Checks that some types and objects are fully default initialized should
be performed in GNATprove, where relevant information about SPARK status
of private types in particular is available. Move two tests performed in
the frontend to GNATprove here.

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

2016-04-18  Yannick Moy  

* contracts.adb (Analyze_Object_Contract,
Analyze_Protected_Contract): Remove tests performed in GNATprove.
* sem_util.adb, sem_util.ads (Has_Full_Default_Initialization):
Remove query for tests performed in GNATprove.

Index: sem_util.adb
===
--- sem_util.adb(revision 235116)
+++ sem_util.adb(working copy)
@@ -9046,110 +9046,6 @@
   end if;
end Has_Enabled_Property;
 
-   -
-   -- Has_Full_Default_Initialization --
-   -
-
-   function Has_Full_Default_Initialization (Typ : Entity_Id) return Boolean is
-  Arg  : Node_Id;
-  Comp : Entity_Id;
-  Prag : Node_Id;
-
-   begin
-  --  A private type and its full view is fully default initialized when it
-  --  is subject to pragma Default_Initial_Condition without an argument or
-  --  with a non-null argument. Since any type may act as the full view of
-  --  a private type, this check must be performed prior to the specialized
-  --  tests below.
-
-  if Has_Default_Init_Cond (Typ)
-or else Has_Inherited_Default_Init_Cond (Typ)
-  then
- Prag := Get_Pragma (Typ, Pragma_Default_Initial_Condition);
-
- --  Pragma Default_Initial_Condition must be present if one of the
- --  related entity flags is set.
-
- pragma Assert (Present (Prag));
- Arg := First (Pragma_Argument_Associations (Prag));
-
- --  A non-null argument guarantees full default initialization
-
- if Present (Arg) then
-return Nkind (Arg) /= N_Null;
-
- --  Otherwise the missing argument defaults the pragma to "True" which
- --  is considered a non-null argument (see above).
-
- else
-return True;
- end if;
-  end if;
-
-  --  A scalar type is fully default initialized if it is subject to aspect
-  --  Default_Value.
-
-  if Is_Scalar_Type (Typ) then
- return Has_Default_Aspect (Typ);
-
-  --  An array type is fully default initialized if its element type is
-  --  scalar and the array type carries aspect Default_Component_Value or
-  --  the element type is fully default initialized.
-
-  elsif Is_Array_Type (Typ) then
- return
-   Has_Default_Aspect (Typ)
- or else Has_Full_Default_Initialization (Component_Type (Typ));
-
-  --  A protected type, record type or type extension is fully default
-  --  initialized if all its components either carry an initialization
-  --  expression or have a type that is fully default initialized. The
-  --  parent type of a type extension must be fully default initialized.
-
-  elsif Is_Record_Type (Typ) or else Is_Protected_Type (Typ) then
-
- --  Inspect all entities defined in the scope of the type, looking for
- --  uninitialized components.
-
- Comp := First_Entity (Typ);
- while Present (Comp) loop
-if Ekind (Comp) = E_Component
-  and then Comes_From_Source (Comp)
-  and then No (Expression (Parent (Comp)))
-  and then not Has_Full_Default_Initialization (Etype (Comp))
-then
-   return False;
-end if;
-
-Next_Entity (Comp);
- end loop;
-
- --  Ensure that the parent type of a type extension is fully default
- --  initialized.
-
- if Etype (Typ) /= Typ
-   and then not Has_Full_Default_Initialization (Etype (Typ))
- then
-return False;
- end if;
-
- --  If we get here, then all components and parent portion are fully
- --  default initialized.
-
- return True;
-
-  --  A task type is fully default initialized by default
-
-  elsif Is_Task_Type (Typ) then
- return True;
-
-  --  Otherwise the type is not fully default initialized
-
-  else
- return False;
-  end if;
-   end Has_Full_Default_Initialization;
-

-- Has_Infinities --

Index: sem_util.ads
===
--- sem_util.ads(revision 235100)
+++ sem_util.ads(working copy)
@@ -1034,19 +1034,6 @@
--  Determine whether subprogram Subp_Id has an effectively volatile formal
--  parameter or returns an effectively volatile value.
 
-   function Has_Full_Default_Initialization (Typ : Entity_Id) return Boolean;
-   --  Determine whether type Typ defines "full 

[Ada] New function GNAT.Source_Info.Compilation_ISO_Date

2016-04-18 Thread Arnaud Charlet
This patch adds a new function Compilation_ISO_Date to package
GNAT.Source_Info. It is identical to Compilation_Date, except
that the date is returned in standard ISO form -- "-mm-dd".
This form has the advantage that string comparisons like "<"
can be used to determine the order of dates.

The following source file should compile with errors
(assuming the current date is in the 21'st century):

gnatmake -q -f very_obsolete.ads

very_obsolete.ads:4:30: Delete this package from library
gnatmake: "very_obsolete.ads" compilation error

with GNAT.Source_Info;
package Very_Obsolete is
   pragma Obsolescent
 (Very_Obsolete,"This package will be compleatly removed  1999-01-01");
   pragma Compile_Time_Error
 (GNAT.Source_Info.Compilation_ISO_Date > "1999-01-01",
  "Delete this package from library");
end Very_Obsolete;

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

2016-04-18  Bob Duff  

* g-souinf.ads (Compilation_ISO_Date): New function to return
the current date in ISO form.
* exp_intr.adb (Expand_Source_Info, Add_Source_Info): Expand
a call to Compilation_ISO_Date into a string literal containing
the current date in ISO form.
* exp_intr.ads (Add_Source_Info): Improve documentation.
* sem_intr.adb (Check_Intrinsic_Subprogram): Recognize
Compilation_ISO_Date.
* snames.ads-tmpl (Name_Compilation_ISO_Date): New Name_Id.

Index: sem_intr.adb
===
--- sem_intr.adb(revision 235093)
+++ sem_intr.adb(working copy)
@@ -359,6 +359,7 @@
  Name_Line,
  Name_Source_Location,
  Name_Enclosing_Entity,
+ Name_Compilation_ISO_Date,
  Name_Compilation_Date,
  Name_Compilation_Time)
   then
Index: g-souinf.ads
===
--- g-souinf.ads(revision 235093)
+++ g-souinf.ads(working copy)
@@ -6,7 +6,7 @@
 --  --
 -- S p e c  --
 --  --
---  Copyright (C) 2000-2014, Free Software Foundation, Inc. --
+--  Copyright (C) 2000-2015, 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- --
@@ -79,6 +79,10 @@
--  package itself. This is useful in identifying and logging information
--  from within generic templates.
 
+   function Compilation_ISO_Date return String with
+ Import, Convention => Intrinsic;
+   --  Returns date of compilation as a static string "-mm-dd".
+
function Compilation_Date return String with
  Import, Convention => Intrinsic;
--  Returns date of compilation as a static string "mmm dd ". This is
Index: exp_intr.adb
===
--- exp_intr.adb(revision 235093)
+++ exp_intr.adb(working copy)
@@ -107,14 +107,10 @@
--  System.Address_To_Access_Conversions.
 
procedure Expand_Source_Info (N : Node_Id; Nam : Name_Id);
-   --  Rewrite the node by the appropriate string or positive constant.
-   --  Nam can be one of the following:
-   --Name_File  - expand string name of source file
-   --Name_Line  - expand integer line number
-   --Name_Source_Location   - expand string of form file:line
-   --Name_Enclosing_Entity  - expand string name of enclosing entity
-   --Name_Compilation_Date  - expand string with compilation date
-   --Name_Compilation_Time  - expand string with compilation time
+   --  Rewrite the node as the appropriate string literal or positive
+   --  constant. Nam is the name of one of the intrinsics declared in
+   --  GNAT.Source_Info; see g-souinf.ads for documentation of these
+   --  intrinsics.
 
procedure Write_Entity_Name (E : Entity_Id);
--  Recursive procedure to construct string for qualified name of enclosing
@@ -165,6 +161,10 @@
 
 Write_Entity_Name (Ent);
 
+ when Name_Compilation_ISO_Date =>
+Name_Buffer (1 .. 10) := Opt.Compilation_Time (1 .. 10);
+Name_Len := 10;
+
  when Name_Compilation_Date =>
 declare
subtype S13 is String (1 .. 3);
@@ -696,6 +696,7 @@
  Name_Line,
  Name_Source_Location,
  Name_Enclosing_Entity,
+ Name_Compilation_ISO_Date,
  

[Ada] Overflow in internal compiler tables

2016-04-18 Thread Arnaud Charlet
When compiling sources with many imported units, some tables internal to
the compiler may overflow, for example the dependency table. This patch
increase the maximum size of these internal table to a value that will
never be reached.

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

2016-04-18  Vincent Celier  

* ali.ads: Increase the range of all _Id types to 100 millions.

Index: ali.ads
===
--- ali.ads (revision 235093)
+++ ali.ads (working copy)
@@ -42,32 +42,28 @@
-- Id Types --
--
 
-   --  The various entries are stored in tables with distinct subscript ranges.
-   --  The following type definitions show the ranges used for the subscripts
-   --  (Id values) for the various tables.
-
-   type ALI_Id is range 0 .. 999_999;
+   type ALI_Id is range 0 .. 99_999_999;
--  Id values used for ALIs table entries
 
-   type Unit_Id is range 1_000_000 .. 1_999_999;
+   type Unit_Id is range 0 .. 99_999_999;
--  Id values used for Unit table entries
 
-   type With_Id is range 2_000_000 .. 2_999_999;
+   type With_Id is range 0 .. 99_999_999;
--  Id values used for Withs table entries
 
-   type Arg_Id is range 3_000_000 .. 3_999_999;
+   type Arg_Id is range 0 .. 99_999_999;
--  Id values used for argument table entries
 
-   type Sdep_Id is range 4_000_000 .. 4_999_999;
+   type Sdep_Id is range 0 .. 99_999_999;
--  Id values used for Sdep table entries
 
-   type Source_Id is range 5_000_000 .. 5_999_999;
+   type Source_Id is range 0 .. 99_999_999;
--  Id values used for Source table entries
 
-   type Interrupt_State_Id is range 6_000_000 .. 6_999_999;
+   type Interrupt_State_Id is range 0 .. 99_999_999;
--  Id values used for Interrupt_State table entries
 
-   type Priority_Specific_Dispatching_Id is range 7_000_000 .. 7_999_999;
+   type Priority_Specific_Dispatching_Id is range 0 .. 99_999_999;
--  Id values used for Priority_Specific_Dispatching table entries
 



[Ada] Warning on (others => <>) that does not cover any components.

2016-04-18 Thread Arnaud Charlet
This patch adds a warning on a record aggregate that includes an association
with a box, when all other components of the record have explicit associations
in the aggregate.

Compiling:

  gcc -c -gnatwr question.ads

must yield:

   question.ads:13:53: warning: others choice is redundant
   question.ads:13:53: warning: previous choices cover all components
   question.ads:14:57: warning: others choice is redundant
   question.ads:14:57: warning: previous choices cover all components
   question.ads:14:72: warning: others choice is redundant
   question.ads:14:72: warning: previous choices cover all components
   question.ads:19:12: warning: "others" choice is redundant
   question.ads:19:12: warning: previous choices cover all values

---
package Question is

type Mon_Enum_T is (A, B);

type Mon_Record_T is record
Mon_Enum : Mon_Enum_T;
end record;

type nested is record
   this : Mon_Record_T;
end record;

Mon_Record : Mon_Record_T := (Mon_Enum=>A,others=><>);
My_Nest : Nested := (THis => (Mon_Enum => A, others => <>), others => <>);

function Ma_Fonction(Mon_Enum : in Mon_Enum_T) return Boolean is
((case Mon_Enum is
  when A | B  => True,
  when others => False)); --line 14

end Question;

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

2016-04-18  Ed Schonberg  

* sem_aggr.adb (Resolve_Record_Aggregate): If
Warn_On_Redundant_Constructs is enabled, report a redundant box
association that does not cover any components, as it done for
redundant others associations in case statements.

Index: sem_aggr.adb
===
--- sem_aggr.adb(revision 235093)
+++ sem_aggr.adb(working copy)
@@ -2972,14 +2972,20 @@
   --
   --  This variable is updated as a side effect of function Get_Value.
 
+  Box_Node   : Node_Id;
   Is_Box_Present : Boolean := False;
-  Others_Box : Boolean := False;
+  Others_Box : Integer := 0;
+
   --  Ada 2005 (AI-287): Variables used in case of default initialization
   --  to provide a functionality similar to Others_Etype. Box_Present
   --  indicates that the component takes its default initialization;
-  --  Others_Box indicates that at least one component takes its default
-  --  initialization. Similar to Others_Etype, they are also updated as a
+  --  Others_Box counts the number of components of the current aggregate
+  --  (which may be a sub-aggregate of a larger one) that are default-
+  --  initialized. A value of One indicates that an others_box is present.
+  --  Any larger value indicates that the others_box is not redundant.
+  --  These variables, similar to Others_Etype, are also updated as a
   --  side effect of function Get_Value.
+  --  Box_Node is used to place a warning on a redundant others_box.
 
   procedure Add_Association
 (Component  : Entity_Id;
@@ -3231,7 +3237,7 @@
  --  checks when the default includes function calls.
 
  if Box_Present (Assoc) then
-Others_Box := True;
+Others_Box := Others_Box + 1;
 Is_Box_Present := True;
 
 if Expander_Active then
@@ -3704,7 +3710,8 @@
   --  any component.
 
   elsif Box_Present (Assoc) then
- Others_Box := True;
+ Others_Box := 1;
+ Box_Node   := Assoc;
   end if;
 
else
@@ -4439,7 +4446,8 @@
 
   Comp_Elmt := First_Elmt (Components);
   while Present (Comp_Elmt) loop
- if Ekind (Node (Comp_Elmt)) /= E_Discriminant
+ if
+   Ekind (Node (Comp_Elmt)) /= E_Discriminant
  then
 Process_Component (Node (Comp_Elmt));
  end if;
@@ -4585,9 +4593,14 @@
 
--  Ada 2005 (AI-287): others choice may have expression or box
 
-   if No (Others_Etype) and then not Others_Box then
+   if No (Others_Etype) and then Others_Box = 0 then
   Error_Msg_N
 ("OTHERS must represent at least one component", Selectr);
+
+   elsif Others_Box = 1 and then Warn_On_Redundant_Constructs then
+  Error_Msg_N ("others choice is redundant?", Box_Node);
+  Error_Msg_N ("\previous choices cover all components?",
+ Box_Node);
end if;
 
exit Verification;


[Ada] Derivation of Ghost types

2016-04-18 Thread Arnaud Charlet
This patch implements the following rules from the SPARK RM:

   6.9(8) - A ghost primitive subprogram of a non-ghost type extension shall
   not override an inherited non-ghost primitive subprogram. A non-ghost
   primitive subprogram of a type extension shall not override an inherited
   ghost primitive subprogram.

   6.9(16) - The Ghost assertion policies in effect at the declaration of a
   primitive subprogram of a ghost tagged type and at the declaration of the
   ghost tagged type shall be the same.

   6.9(17) - If a tagged type is not a disabled ghost type, and if a primitive
   operation of the tagged type overrides an inherited operation, then the
   corresponding operation of the ancestor type shall be a disabled ghost
   subprogram if and only if the overriding subprogram is a disabled ghost
   subprogram.


-- Source --


--  bad_ancestor.ads

package Bad_Ancestor with SPARK_Mode is
   type R is tagged null record;

   procedure P   (X : R);  --  OK
   pragma Assertion_Policy (Ghost => Check);
   procedure PGC (X : R) with Ghost;   --  OK
   pragma Assertion_Policy (Ghost => Ignore);
   procedure PGI (X : R) with Ghost;   --  OK

   pragma Assertion_Policy (Ghost => Check);
   type RGC is tagged null record with Ghost;

   procedure P   (X : RGC);--  Error 6.9(10)
   pragma Assertion_Policy (Ghost => Check);
   procedure PGC (X : RGC) with Ghost; --  OK
   pragma Assertion_Policy (Ghost => Ignore);
   procedure PGI (X : RGC) with Ghost; --  Error 6.9(13,17)

   pragma Assertion_Policy (Ghost => Ignore);
   type RGI is tagged null record with Ghost;

   procedure P   (X : RGI);--  Error 6.9(10)
   pragma Assertion_Policy (Ghost => Check);
   procedure PGC (X : RGI) with Ghost; --  Error 6.9(13,17)
   pragma Assertion_Policy (Ghost => Ignore);
   procedure PGI (X : RGI) with Ghost; --  OK
end Bad_Ancestor;

--  bad_extension.ads

with Bad_Ancestor; use Bad_Ancestor;

package Bad_Extension with SPARK_Mode is
   type E1 is new R with null record;

   overriding procedure P   (X : E1);  --  OK
   overriding procedure PGC (X : E1);  --  Error 6.9(8)
   overriding procedure PGI (X : E1);  --  Error 6.9(8)

   type E2 is new R with null record;

   pragma Assertion_Policy (Ghost => Check);
   overriding procedure P   (X : E2) with Ghost;   --  Error 6.9(8)
   overriding procedure PGC (X : E2) with Ghost;   --  OK
   overriding procedure PGI (X : E2) with Ghost;   --  Error 6.9(17)

   type E3 is new R with null record;

   pragma Assertion_Policy (Ghost => Ignore);
   overriding procedure P   (X : E3) with Ghost;   --  Error 6.9(8)
   overriding procedure PGC (X : E3) with Ghost;   --  Error 6.9(17)
   overriding procedure PGI (X : E3) with Ghost;   --  OK

   type E1GC is new RGC with null record;  --  Error 6.9(10)

   overriding procedure P   (X : E1GC);--  Error 6.9(10)
   overriding procedure PGC (X : E1GC);--  Error 6.9(8,10)
   overriding procedure PGI (X : E1GC);--  Error bad inher

   type E2GC is new RGC with null record;  --  Error 6.9(10)

   pragma Assertion_Policy (Ghost => Check);
   overriding procedure P   (X : E2GC) with Ghost; --  Error 6.9(13,16)
   overriding procedure PGC (X : E2GC) with Ghost; --  Error 6.9(13,16)
   overriding procedure PGI (X : E2GC) with Ghost; --  Error 6.9(13,16)

   type E3GC is new RGC with null record;  --  Error 6.9(10)

   pragma Assertion_Policy (Ghost => Ignore);
   overriding procedure P   (X : E3GC) with Ghost; --  Error 6.9(13,17)
   overriding procedure PGC (X : E3GC) with Ghost; --  Error 6.9(13,17)
   overriding procedure PGI (X : E3GC) with Ghost; --  Error 6.9(13,16)

   type E1GI is new RGI with null record;  --  Error 6.9(10)

   overriding procedure P   (X : E1GI);--  Error 6.9(10)
   overriding procedure PGC (X : E1GI);--  Error bad inher
   overriding procedure PGI (X : E1GI);--  Error 6.9(8,10)

   type E2GI is new RGI with null record;  --  Error 6.9(10)

   pragma Assertion_Policy (Ghost => Check);
   overriding procedure P   (X : E2GI) with Ghost; --  Error 6.9(13,17)
   overriding procedure PGC (X : E2GI) with Ghost; --  Error 6.9(13,17)
   overriding procedure PGI (X : E2GI) with Ghost; --  Error 6.9(13,16)

   type E3GI is new RGI with null record;  --  Error 6.9(10)

   pragma Assertion_Policy (Ghost => Ignore);
   overriding procedure P   (X : E3GI) with Ghost; --  Error 6.9(13,17)
   

[Ada] Implicit self dependence of task on itself

2016-04-18 Thread Arnaud Charlet
This patch implements the following SPARK rule from 6.1.4:

   The Depends and Refined_Depends aspect of a task unit T need not mention
   this implicit parameter; an implicit specification of "T => T" is assumed,
   although this may be confirmed explicitly.


-- Source --


--  implicit_tasks.ads

package Implicit_Tasks with
  SPARK_Mode,
  Abstract_State => State
is
   --  Single tasks

   task OK_1 with
 Global  => (Input => State),
 Depends => (null => State); --  OK

   task OK_2 with
 Global  => (Output => State),
 Depends => ((State, OK_2) => OK_2); --  OK

   task Error_1 with
 Global  => (Output => State),
 Depends => (State => Error_1);  --  Error

   task Error_2 with
 Global  => (In_Out => State),
 Depends => ((State, Error_2) => State); --  Error

   --  Task types

   task type OK_3 with
 Global  => (Input => State),
 Depends => (null => State); --  OK

   task type OK_4 with
 Global  => (Output => State),
 Depends => ((State, OK_4) => OK_4); --  OK

   task type Error_3 with
 Global  => (Output => State),
 Depends => (State => Error_3);  --  Error

   task type Error_4 with
 Global  => (In_Out => State),
 Depends => ((State, Error_4) => State); --  Error

   --  Task types with definitions

   task type OK_5 with
 Global  => (Input => State),
 Depends => (null => State)  --  OK
   is end OK_5;

   task type OK_6 with
 Global  => (Output => State),
 Depends => ((State, OK_6) => OK_6)  --  OK
   is end OK_6;

   task type Error_5 with
 Global  => (Output => State),
 Depends => (State => Error_5)   --  Error
   is end Error_5;

   task type Error_6 with
 Global  => (In_Out => State),
 Depends => ((State, Error_6) => State)  --  Error
   is end Error_6;

end Implicit_Tasks;

--  implicit_tasks.adb

package body Implicit_Tasks with
  SPARK_Mode,
  Refined_State => (State => Var)
is
   Var : Integer := 1;

   task body OK_1 with
 Refined_Global  => (Input => Var),
 Refined_Depends => (null => Var)--  OK
   is begin null; end OK_1;

   task body OK_2 with
 Refined_Global  => (Output => Var),
 Refined_Depends => ((Var, OK_2) => OK_2)--  OK
   is begin null; end OK_2;

   task body Error_1 with
 Refined_Global  => (Output => Var),
 Refined_Depends => (Var => Error_1) --  Error
   is begin null; end Error_1;

   task body Error_2 with
 Refined_Global  => (In_Out => Var),
 Refined_Depends => ((Var, Error_2) => Var)  --  Error
   is begin null; end Error_2;

   task body OK_3 with
 Refined_Global  => (Input => Var),
 Refined_Depends => (null => Var)--  OK
   is begin null; end OK_3;

   task body OK_4 with
 Refined_Global  => (Output => Var),
 Refined_Depends => ((Var, OK_4) => OK_4)--  OK
   is begin null; end OK_4;

   task body Error_3 with
 Refined_Global  => (Output => Var),
 Refined_Depends => (Var => Error_3) --  Error
   is begin null; end Error_3;

   task body Error_4 with
 Refined_Global  => (In_Out => Var),
 Refined_Depends => ((Var, Error_4) => Var)  --  Error
   is begin null; end Error_4;

   task body OK_5 with
 Refined_Global  => (Input => Var),
 Refined_Depends => (null => Var)--  OK
   is begin null; end OK_5;

   task body OK_6 with
 Refined_Global  => (Output => Var),
 Refined_Depends => ((Var, OK_6) => OK_6)--  OK
   is begin null; end OK_6;

   task body Error_5 with
 Refined_Global  => (Output => Var),
 Refined_Depends => (Var => Error_5) --  Error
   is begin null; end Error_5;

   task body Error_6 with
 Refined_Global  => (In_Out => Var),
 Refined_Depends => ((Var, Error_6) => Var)  --  Error
   is begin null; end Error_6;

end Implicit_Tasks;


-- Compilation and output --


$ gcc -c implicit_tasks.adb
implicit_tasks.adb:19:06: current instance of task type "Error_1" is missing
  from output dependence list
implicit_tasks.adb:24:06: current instance of task type "Error_2" is missing
  from input dependence list
implicit_tasks.adb:39:06: current instance of task type "Error_3" is missing
  from output dependence list
implicit_tasks.adb:44:06: current instance of task type "Error_4" is missing
  from input dependence list
implicit_tasks.adb:59:06: 

[Ada] Spurious errors on tag indeterminate calls.

2016-04-18 Thread Arnaud Charlet
This patch removes spurious errors on tag indeterminate calls that are
actuals of other dispatching calls that may themselves be tag-indeterminate.

Full test in ACATS 4.0G BC60004

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

2016-04-18  Ed Schonberg  

* sem_disp.adb (Check_Dispatching_Call): Major rewriting to
handle some complex cases of tag indeterminate calls that are
actuals in other dispatching calls that are themselves tag
indeterminate.
(Check_Dispatching_Context): Add parameter to support recursive
check for an enclosing construct that may provide a tag for a
tag-indeterminate call.

Index: sem_disp.adb
===
--- sem_disp.adb(revision 235093)
+++ sem_disp.adb(working copy)
@@ -409,7 +409,7 @@
   --  fact direct. This routine detects the above case and modifies the
   --  call accordingly.
 
-  procedure Check_Dispatching_Context;
+  procedure Check_Dispatching_Context (Call : Node_Id);
   --  If the call is tag-indeterminate and the entity being called is
   --  abstract, verify that the context is a call that will eventually
   --  provide a tag for dispatching, or has provided one already.
@@ -508,10 +508,9 @@
   -- Check_Dispatching_Context --
   ---
 
-  procedure Check_Dispatching_Context is
- Subp : constant Entity_Id := Entity (Name (N));
+  procedure Check_Dispatching_Context (Call : Node_Id) is
+ Subp : constant Entity_Id := Entity (Name (Call));
  Typ  : constant Entity_Id := Etype (Subp);
- Par  : Node_Id;
 
  procedure Abstract_Context_Error;
  --  Error for abstract call dispatching on result is not dispatching
@@ -536,11 +535,15 @@
 end if;
  end Abstract_Context_Error;
 
+ --  Local variables
+
+ Par : Node_Id;
+
   --  Start of processing for Check_Dispatching_Context
 
   begin
  if Is_Abstract_Subprogram (Subp)
-   and then No (Controlling_Argument (N))
+   and then No (Controlling_Argument (Call))
  then
 if Present (Alias (Subp))
   and then not Is_Abstract_Subprogram (Alias (Subp))
@@ -565,7 +568,8 @@
 --  but will be legal in overridings of the operation.
 
 elsif In_Spec_Expression
-  and then Is_Subprogram (Current_Scope)
+  and then (Is_Subprogram (Current_Scope)
+ or else Chars (Current_Scope) = Name_Postcondition)
   and then
 ((Nkind (Parent (Current_Scope)) = N_Procedure_Specification
and then Null_Present (Parent (Current_Scope)))
@@ -588,82 +592,110 @@
 
if not Is_Tagged_Type (Typ)
  and then not
-(Ekind (Typ) = E_Anonymous_Access_Type
-  and then Is_Tagged_Type (Designated_Type (Typ)))
+   (Ekind (Typ) = E_Anonymous_Access_Type
+ and then Is_Tagged_Type (Designated_Type (Typ)))
then
   Abstract_Context_Error;
   return;
end if;
 
-   Par := Parent (N);
+   Par := Parent (Call);
 
if Nkind (Par) = N_Parameter_Association then
   Par := Parent (Par);
end if;
 
-   while Present (Par) loop
-  if Nkind_In (Par, N_Function_Call,
-N_Procedure_Call_Statement)
-and then Is_Entity_Name (Name (Par))
-  then
- declare
-Enc_Subp : constant Entity_Id := Entity (Name (Par));
-A : Node_Id;
-F : Entity_Id;
+   if Nkind (Par) = N_Qualified_Expression
+ or else Nkind (Par) = N_Unchecked_Type_Conversion
+   then
+  Par := Parent (Par);
+   end if;
 
- begin
---  Find formal for which call is the actual, and is
---  a controlling argument.
+   if Nkind_In (Par, N_Function_Call, N_Procedure_Call_Statement)
+ and then Is_Entity_Name (Name (Par))
+   then
+  declare
+ Enc_Subp : constant Entity_Id := Entity (Name (Par));
+ A: Node_Id;
+ F: Entity_Id;
+ Control  : Entity_Id;
+ Ret_Type : Entity_Id;
 
-F := First_Formal (Enc_Subp);
-A := First_Actual (Par);
+  begin
+ --  Find controlling formal that can provide tag for the
+ --  tag-indeterminate actual. The 

[Ada] Spurious inlining error with function completed by an expression function

2016-04-18 Thread Arnaud Charlet
This patch fixes a spurious error on a call to an expression function whose
expression is a call to a function whose full declaration is another expression
function, when compiling with optimization and inlining warnings enabled.

The following must compile quietly:

   gcc -c p.adb -gnatn -O -fdump-tree-optimized
   grep is_two p.adb.*.optimized

---
with Q; use Q;
procedure P is
begin
  if not Is_Two (2) then
raise Program_Error;
  end if;
end;
---
with R; use R;
package Q is

  function Is_Two (I : Integer) return Boolean;

private
  function Is_Two (I : Integer) return Boolean is (Is_One (I - 1));
end Q;
---
package R is
  function Is_One (I : Integer) return Boolean is (I = 1);

  pragma Inline_Always (Is_One);
end R;

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

2016-04-18  Ed Schonberg  

* sem_ch6.adb (Analyze_Expression_Function): Set Inlined flag
on the entity of a subprogram declaration that is completed by
an expression function.

Index: sem_ch6.adb
===
--- sem_ch6.adb (revision 235093)
+++ sem_ch6.adb (working copy)
@@ -362,7 +362,7 @@
  Set_Is_Inlined (Prev);
 
   --  If the expression function is a completion, the previous declaration
-  --  must come from source. We know already that appears in the current
+  --  must come from source. We know already that it appears in the current
   --  scope. The entity itself may be internally created if within a body
   --  to be inlined.
 
@@ -371,6 +371,7 @@
 and then not Is_Formal_Subprogram (Prev)
   then
  Set_Has_Completion (Prev, False);
+ Set_Is_Inlined (Prev);
 
  --  An expression function that is a completion freezes the
  --  expression. This means freezing the return type, and if it is
@@ -411,7 +412,6 @@
  --  Not clear that the backend can inline it in this case ???
 
  if Has_Completion (Prev) then
-Set_Is_Inlined (Prev);
 
 --  The formals of the expression function are body formals,
 --  and do not appear in the ali file, which will only contain


[Ada] Add statistics dumping function to Atree package

2016-04-18 Thread Arnaud Charlet
This adds a statistics dumping function to the Atree package, which is the
package responsible for the allocation of the nodes of the front-end tree.

No user-visible functional changes.

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

2016-04-18  Eric Botcazou  

* atree.ads (Num_Extension_Nodes): Add couple of figures
to comment.
* atree.adb: Add GNAT.Heap_Sort_G dependency.
(Print_Statistics): New exported procedure to print statistics.

Index: atree.adb
===
--- atree.adb   (revision 235100)
+++ atree.adb   (working copy)
@@ -44,6 +44,8 @@
 with Sinput;  use Sinput;
 with Tree_IO; use Tree_IO;
 
+with GNAT.Heap_Sort_G;
+
 package body Atree is
 
Reporting_Proc : Report_Proc := null;
@@ -115,6 +117,10 @@
procedure Node_Debug_Output (Op : String; N : Node_Id);
--  Common code for nnd and rrd, writes Op followed by information about N
 
+   procedure Print_Statistics;
+   pragma Export (Ada, Print_Statistics);
+   --  Print various statistics on the tables maintained by the package
+
-
-- Local Objects and Types --
-
@@ -1955,6 +1961,102 @@
 Nodes.Table (OldN).Comes_From_Source;
end Preserve_Comes_From_Source;
 
+   --
+   -- Print_Statistics --
+   --
+
+   procedure Print_Statistics is
+  N_Count : constant Natural := Natural (Nodes.Last - First_Node_Id + 1);
+  E_Count : Natural := 0;
+
+   begin
+  Write_Str ("Maximum number of nodes per entity: ");
+  Write_Int (Int (Num_Extension_Nodes + 1));
+  Write_Eol;
+  Write_Str ("Number of allocated nodes: ");
+  Write_Int (Int (N_Count));
+  Write_Eol;
+
+  Write_Str ("Number of entities: ");
+  Write_Eol;
+
+  declare
+ function CP_Lt (Op1, Op2 : Natural) return Boolean;
+ --  Compare routine for Sort
+
+ procedure CP_Move (From : Natural; To : Natural);
+ --  Move routine for Sort
+
+ Kind_Count : array (Node_Kind) of Natural := (others => 0);
+ --  Array of occurrence count per node kind
+
+ Kind_Max : constant Natural := Node_Kind'Pos (N_Unused_At_End) - 1;
+ --  The index of the largest (interesting) node kind
+
+ Ranking : array (0 .. Kind_Max) of Node_Kind;
+ --  Ranking array for node kinds (index 0 is used for the temporary)
+
+ package Sorting is new GNAT.Heap_Sort_G (CP_Move, CP_Lt);
+
+ function CP_Lt (Op1, Op2 : Natural) return Boolean is
+ begin
+return Kind_Count (Ranking (Op2)) < Kind_Count (Ranking (Op1));
+ end CP_Lt;
+
+ procedure CP_Move (From : Natural; To : Natural) is
+ begin
+Ranking (To) := Ranking (From);
+ end CP_Move;
+
+  begin
+ --  Count the number of occurrences of each node kind
+
+ for I in First_Node_Id .. Nodes.Last loop
+declare
+   Nkind : constant Node_Kind := Nodes.Table (I).Nkind;
+begin
+   if not Nodes.Table (I).Is_Extension then
+  Kind_Count (Nkind) := Kind_Count (Nkind) + 1;
+   end if;
+end;
+ end loop;
+
+ --  Sort the node kinds by number of occurrences
+
+ for N in 1 .. Kind_Max loop
+Ranking (N) := Node_Kind'Val (N);
+ end loop;
+
+ Sorting.Sort (Kind_Max);
+
+ --  Print the list in descending order
+
+ for N in 1 .. Kind_Max loop
+declare
+   Count : constant Natural := Kind_Count (Ranking (N));
+begin
+   if Count > 0 then
+  Write_Str ("  ");
+  Write_Str (Node_Kind'Image (Ranking (N)));
+  Write_Str (": ");
+  Write_Int (Int (Count));
+  Write_Eol;
+
+  E_Count := E_Count + Count;
+   end if;
+end;
+ end loop;
+  end;
+
+  Write_Str ("Total number of entities: ");
+  Write_Int (Int (E_Count));
+  Write_Eol;
+  Write_Str ("Ratio allocated nodes/entities: ");
+  Write_Int (Int (N_Count * 100 / E_Count));
+  Write_Str ("/100");
+  Write_Eol;
+   end Print_Statistics;
+
---
-- Relocate_Node --
---
Index: atree.ads
===
--- atree.ads   (revision 235100)
+++ atree.ads   (working copy)
@@ -76,6 +76,10 @@
--  This value is increased by one if debug flag -gnatd.N is set. This is
--  for testing performance impact of adding a new extension node. We make
--  this of type Node_Id for easy reference in loops using this value.
+   --  Print_Statistics can be used to display statistics on entities & nodes.
+   --  Measurements conducted for the 5->6 bump showed an increase 

[Ada] Fix small inefficiency in Disambiguate

2016-04-18 Thread Arnaud Charlet
This prevents the procedure from calling Covers for standard operators when
this is not necessary.  No functional changes.

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

2016-04-18  Eric Botcazou  

* sem_type.adb (Disambiguate): Call Covers only when necessary
for standard operators.

Index: sem_type.adb
===
--- sem_type.adb(revision 235100)
+++ sem_type.adb(working copy)
@@ -1751,17 +1751,16 @@
 begin
Get_First_Interp (N, I, It);
while Present (It.Typ) loop
-  if (Covers (Typ, It.Typ) or else Typ = Any_Type)
-and then
- (It.Typ = Universal_Integer
+  if (It.Typ = Universal_Integer
or else It.Typ = Universal_Real)
+and then (Typ = Any_Type or else Covers (Typ, It.Typ))
   then
  return It;
 
-  elsif Covers (Typ, It.Typ)
+  elsif Is_Numeric_Type (It.Typ)
 and then Scope (It.Typ) = Standard_Standard
 and then Scope (It.Nam) = Standard_Standard
-and then Is_Numeric_Type (It.Typ)
+and then Covers (Typ, It.Typ)
   then
  Candidate := It;
   end if;
@@ -3026,19 +3025,19 @@
---
 
function Operator_Matches_Spec (Op, New_S : Entity_Id) return Boolean is
+  New_First_F : constant Entity_Id := First_Formal (New_S);
   Op_Name : constant Name_Id   := Chars (Op);
   T   : constant Entity_Id := Etype (New_S);
-  New_First_F : constant Entity_Id := First_Formal (New_S);
   New_F   : Entity_Id;
-  Old_F   : Entity_Id;
   Num : Int;
+  Old_F   : Entity_Id;
   T1  : Entity_Id;
   T2  : Entity_Id;
 
begin
-  --  To verify that a predefined operator matches a given signature,
-  --  do a case analysis of the operator classes. Function can have one
-  --  or two formals and must have the proper result type.
+  --  To verify that a predefined operator matches a given signature, do a
+  --  case analysis of the operator classes. Function can have one or two
+  --  formals and must have the proper result type.
 
   New_F := New_First_F;
   Old_F := First_Formal (Op);


Re: [PR target/70711][ARM] Fix big-endian ARMv8.1-A builds.

2016-04-18 Thread Richard Biener
On Mon, 18 Apr 2016, Ramana Radhakrishnan wrote:

> On 18/04/16 10:20, Matthew Wahab wrote:
> > When ARMv8.1 support was added to the ARM target, the
> > bpabi.h/BE8_LINK_SPEC list wasn't updated. That means that when GCC
> > targets ARMv8.1 big-endian, it fails to generate working binaries.
> > 
> > This patch addds the required 'march=armv8.1-a' entries to
> > BE8_LINK_SPEC. It also adds the missing entries for armv8-a+crc.
> > 
> > Testing for armeb-none-eabi with cross-compiled check-gcc and with
> > command line testing to confirm working executables are built.
> > 
> > Is this ok for trunk and for GCC-6 once testing is completed?
> 
> Oops, Thanks for catching this - 
> 
> Ok for trunk. 
> 
> Ok for GCC-6 by me but you need RM sign off before applying to the branch.

Ok.

Thanks,
Richard.

> Ramana
> 
> > Matthew
> > 
> > 2016-04-18  Matthew Wahab  
> > 
> > PR target/70711
> > * config/arm/bpabi.h (BE8_LINK_SPEC): Add entries for armv8+crc,
> > armv8.1-a and armv8.1-a+crc.


Re: [PATCH] Some tree-vect-data-refs.c cleanup

2016-04-18 Thread Richard Biener
On Wed, Apr 13, 2016 at 12:42 PM, Robin Dapp  wrote:
> Hi,
>
> the attached patch is a start at cleaning up tree-vect-data-refs.c.
> I refactored some stuff I found strange and/or difficult to understand.
> Probably more to come.
>
> The misalignment calculation in vect_compute_data_ref_alignment seems
> quite coarse, is there any work planned for the future?

What do you mean by "coarse"?

> No regressions on s390x and amd64.

+#define DR_MISALIGNMENT_UNKNOWN (-1)
+#define DR_MISALIGNMENT_NONE (0)

Better than NONE would be ALIGNED.  But I wouldn't bother adding a define
for that, it's supposed to be hidden by aligned_access_p already.

Adding DR_MISALIGNMENT_UNKNOWN and replacing -1 by that is ok.

The rest of the changes seem to be just noise to me, they are not better
or worse so I'd rather not do changes like CSEing or renaming vars
just for the sake of it.

Thanks,
Richard.

> Regards
>  Robin
>
> --
>
> gcc/ChangeLog:
>
> 2016-04-13  Robin Dapp  
>
> * tree-vectorizer.h
> (dr_misalignment): Introduce named DR_MISALIGNMENT constants.
> (aligned_access_p): Use constants.
> (known_alignment_for_access_p): Likewise.
> * tree-vect-data-refs.c
> (vect_compute_data_ref_alignment):
> Improve output messages and cleanup.
> (vect_duplicate_ssa_name_ptr_info): Use new constants.
> (vect_enhance_data_refs_alignment): Likewise.
> (vect_supportable_dr_alignment): Likewise.
> (vect_update_misalignment_for_peel): Likewise.
>
> gcc/testsuite/ChangeLog:
>
> 2016-04-13  Robin Dapp  
>
> * gcc.dg/vect/vect-outer-3a-big-array.c: Use new output message.
> * gcc.dg/vect/vect-outer-3a.c: Likewise.


Re: [PATCH][combine] Check WORD_REGISTER_OPERATIONS normally rather than through preprocessor

2016-04-18 Thread Kyrill Tkachov

Hi Jeff,

On 17/04/16 21:16, Jeff Law wrote:

On 12/15/2015 10:07 AM, Kyrill Tkachov wrote:

Hi all,

As part of the war on conditional compilation here's an #if check on
WORD_REGISTER_OPERATIONS that
seems to have been missed out.

Bootstrapped and tested on arm, aarch64, x86_64.

Is it still ok to commit these kinds of conditional compilation
conversions?

Thanks,
Kyrill

2015-12-15  Kyrylo Tkachov  

 * combine.c (simplify_comparison): Convert preprocessor check of
 WORD_REGISTER_OPERATIONS into runtime check.

This patch, and others like it are fine for the trunk (gcc-7) again.



Thanks, but I've committed this already in December after approval from Segher
(https://gcc.gnu.org/ml/gcc-patches/2015-12/msg01771.html)


I'll channel the release managers' request that we don't make large scale 
changes that would make backporting patches exceedingly difficult.  So just 
keep that in mind if you find more conditionally compiled code to kill.



I do have some cleanups like that, but I'll post them after the release. I'm in 
no hurry to get
them in right this moment.

Thanks,
Kyrill


jeff




Re: [PR target/70711][ARM] Fix big-endian ARMv8.1-A builds.

2016-04-18 Thread Ramana Radhakrishnan
On 18/04/16 10:20, Matthew Wahab wrote:
> When ARMv8.1 support was added to the ARM target, the
> bpabi.h/BE8_LINK_SPEC list wasn't updated. That means that when GCC
> targets ARMv8.1 big-endian, it fails to generate working binaries.
> 
> This patch addds the required 'march=armv8.1-a' entries to
> BE8_LINK_SPEC. It also adds the missing entries for armv8-a+crc.
> 
> Testing for armeb-none-eabi with cross-compiled check-gcc and with
> command line testing to confirm working executables are built.
> 
> Is this ok for trunk and for GCC-6 once testing is completed?

Oops, Thanks for catching this - 

Ok for trunk. 

Ok for GCC-6 by me but you need RM sign off before applying to the branch.

Ramana

> Matthew
> 
> 2016-04-18  Matthew Wahab  
> 
> PR target/70711
> * config/arm/bpabi.h (BE8_LINK_SPEC): Add entries for armv8+crc,
> armv8.1-a and armv8.1-a+crc.



Re: [PATCH][GCC 7] Remove broken path in extract_bit_field_1

2016-04-18 Thread Richard Biener
On Mon, Apr 4, 2016 at 3:33 PM, Jakub Jelinek  wrote:
> On Mon, Apr 04, 2016 at 03:27:23PM +0200, Richard Biener wrote:
>> It ICEs in
>>
>> /space/rguenther/src/svn/trunk/gcc/testsuite/gcc.target/i386/pr37870.c:19:1:
>> internal compiler error: in subreg_get_info, at rtlanal.c:3695
>> 0xddee5a subreg_get_info(unsigned int, machine_mode, unsigned int,
>> machine_mode, subreg_info*)
>> /space/rguenther/src/svn/trunk/gcc/rtlanal.c:3695
>> 0xddf12b simplify_subreg_regno(unsigned int, machine_mode, unsigned int,
>> machine_mode)
>> /space/rguenther/src/svn/trunk/gcc/rtlanal.c:3808
>> 0xd8bc7a simplifiable_subregs(subreg_shape const&)
>> /space/rguenther/src/svn/trunk/gcc/reginfo.c:1234
>> 0xd8be1d record_subregs_of_mode
>> /space/rguenther/src/svn/trunk/gcc/reginfo.c:1294
>> 0xd8c246 init_subregs_of_mode()
>> /space/rguenther/src/svn/trunk/gcc/reginfo.c:1348
>> 0xc1a55c init_costs
>> /space/rguenther/src/svn/trunk/gcc/ira-costs.c:2187
>>
>> which is
>>
>>   /* This should always pass, otherwise we don't know how to verify
>>  the constraint.  These conditions may be relaxed but
>>  subreg_regno_offset would need to be redesigned.  */
>>   gcc_assert ((GET_MODE_SIZE (xmode) % GET_MODE_SIZE (ymode)) == 0);
>
> So perhaps either validate_subreg should check the same thing, or
> the extraction could check this.
> Anyway, I don't have anything against removing that hunk from
> extract_bit_field_1 for GCC7.

Now committed.

Richard.

> Jakub


[Ada] Fix inefficiency in Operator_Matches_Spec

2016-04-18 Thread Arnaud Charlet
First_Formal is not as cheap as it used to be so this patch eliminates a few
redundant invocations in Operator_Matches_Spec.  No functional changes.

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

2016-04-18  Eric Botcazou  

* sem_type.adb (Operator_Matches_Spec): Call First_Formal on
New_S only once at the beginning of the function.

Index: sem_type.adb
===
--- sem_type.adb(revision 235093)
+++ sem_type.adb(working copy)
@@ -3026,20 +3026,21 @@
---
 
function Operator_Matches_Spec (Op, New_S : Entity_Id) return Boolean is
-  Op_Name : constant Name_Id   := Chars (Op);
-  T   : constant Entity_Id := Etype (New_S);
-  New_F   : Entity_Id;
-  Old_F   : Entity_Id;
-  Num : Int;
-  T1  : Entity_Id;
-  T2  : Entity_Id;
+  Op_Name : constant Name_Id   := Chars (Op);
+  T   : constant Entity_Id := Etype (New_S);
+  New_First_F : constant Entity_Id := First_Formal (New_S);
+  New_F   : Entity_Id;
+  Old_F   : Entity_Id;
+  Num : Int;
+  T1  : Entity_Id;
+  T2  : Entity_Id;
 
begin
   --  To verify that a predefined operator matches a given signature,
   --  do a case analysis of the operator classes. Function can have one
   --  or two formals and must have the proper result type.
 
-  New_F := First_Formal (New_S);
+  New_F := New_First_F;
   Old_F := First_Formal (Op);
   Num := 0;
   while Present (New_F) and then Present (Old_F) loop
@@ -3056,7 +3057,7 @@
   --  Unary operators
 
   elsif Num = 1 then
- T1 := Etype (First_Formal (New_S));
+ T1 := Etype (New_First_F);
 
  if Nam_In (Op_Name, Name_Op_Subtract, Name_Op_Add, Name_Op_Abs) then
 return Base_Type (T1) = Base_Type (T)
@@ -3073,8 +3074,8 @@
   --  Binary operators
 
   else
- T1 := Etype (First_Formal (New_S));
- T2 := Etype (Next_Formal (First_Formal (New_S)));
+ T1 := Etype (New_First_F);
+ T2 := Etype (Next_Formal (New_First_F));
 
  if Nam_In (Op_Name, Name_Op_And, Name_Op_Or, Name_Op_Xor) then
 return Base_Type (T1) = Base_Type (T2)


[PR target/70711][ARM] Fix big-endian ARMv8.1-A builds.

2016-04-18 Thread Matthew Wahab

When ARMv8.1 support was added to the ARM target, the
bpabi.h/BE8_LINK_SPEC list wasn't updated. That means that when GCC
targets ARMv8.1 big-endian, it fails to generate working binaries.

This patch addds the required 'march=armv8.1-a' entries to
BE8_LINK_SPEC. It also adds the missing entries for armv8-a+crc.

Testing for armeb-none-eabi with cross-compiled check-gcc and with
command line testing to confirm working executables are built.

Is this ok for trunk and for GCC-6 once testing is completed?
Matthew

2016-04-18  Matthew Wahab  

PR target/70711
* config/arm/bpabi.h (BE8_LINK_SPEC): Add entries for armv8+crc,
armv8.1-a and armv8.1-a+crc.
>From 627f689c37eeec3f0d846cda4577385158ca8d10 Mon Sep 17 00:00:00 2001
From: Matthew Wahab 
Date: Mon, 18 Apr 2016 09:32:54 +0100
Subject: [PATCH] [ARM] Fix big-endian ARMv8.1-A builds.

When ARMv8.1 support was added to the ARM target, the
bpabi.h/BE8_LINK_SPEC list wasn't updated. That means that when GCC
targets ARMv8.1 big-endian, it fails to generate working binaries.

This patch addds the required 'march=armv8.1-a' entries to
BE8_LINK_SPEC. It also adds the missing entries for armv8-a+crc.

Tested for armeb-none-eabi with cross-compiled check-gcc and with
command line testing to confirm working executables are built.

Is this ok for trunk and for GCC-6?
Matthew

2016-04-18  Matthew Wahab  

	PR target/70711
	* config/arm/bpabi.h (BE8_LINK_SPEC): Add entries for armv8+crc,
	armv8.1-a and armv8.1-a+crc.

Change-Id: I8a825421b6c4355d9fd611432c11a8d7b4d61bbf
---
 gcc/config/arm/bpabi.h | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/gcc/config/arm/bpabi.h b/gcc/config/arm/bpabi.h
index 5d6c4ed..06488ba 100644
--- a/gcc/config/arm/bpabi.h
+++ b/gcc/config/arm/bpabi.h
@@ -87,6 +87,9 @@
|march=armv7e-m|mcpu=cortex-m4|mcpu=cortex-m7\
|march=armv6-m|mcpu=cortex-m0\
|march=armv8-a	\
+   |march=armv8-a+crc	\
+   |march=armv8.1-a	\
+   |march=armv8.1-a+crc	\
:%{!r:--be8}}}"
 #else
 #define BE8_LINK_SPEC \
@@ -115,6 +118,9 @@
|march=armv7e-m|mcpu=cortex-m4|mcpu=cortex-m7\
|march=armv6-m|mcpu=cortex-m0\
|march=armv8-a	\
+   |march=armv8-a+crc	\
+   |march=armv8.1-a	\
+   |march=armv8.1-a+crc	\
:%{!r:--be8}}}"
 #endif
 
-- 
2.1.4



Re: [i386] Support .lbss etc. sections with Solaris as (PR target/59407)

2016-04-18 Thread Rainer Orth
Uros Bizjak  writes:

> On Thu, Mar 17, 2016 at 11:40 PM, Rainer Orth
>  wrote:
>> gcc.target/i386/pr58218.c currently FAILs on 64-bit Solaris/x86 with the
>> native assembler:
>>
>> FAIL: gcc.target/i386/pr58218.c (test for excess errors)
>>
>> Excess errors:
>> Assembler: pr58218.c
>> "/var/tmp//cciHFIO7.s", line 3 : Section attributes do not match
>>
>> .section.lbss,"aw",@nobits
>>
>> It turns out x86_64 large sections need to marked with a 'h' section
>> flag for as.  gas implicitly sets SHF_AMD64_LARGE based on section
>> names, but also accepts an 'l' for the same purpose.
>>
>> The following patch fixes this by using the SECTION_MACH_DEP section
>> flag to mark large sections and emit the right flag in
>> default_elf_asm_named_section.
>>
>> Given this comment in output.h
>>
>> #define SECTION_MACH_DEP 0x400 /* subsequent bits reserved for target
>> */
>>
>> handling only a single SECTION_MACH_DEP can be considered a hack.
>> Currently, only one user of SECTION_MACH_DEP (avr) uses more than one
>> section flag, so maybe I can get away with this for now.
>>
>> A full solution would split out the part of
>> default_elf_asm_named_section that emits the flags into a new
>> default_elf_asm_section_flags which prints the flag string to a stream,
>> invoking it either via a macro than be overridden or perhaps a target
>> hook (which seems not fully right either since those are object file
>> format agnostic and this is just a small part of emitting ELF named
>> sections).
>>
>> The patch has been bootstrapped without regressions on
>> i386-pc-solaris2.12 (with both as and gas) and x86_64-pc-linux-gnu.
>> This is not a regression, so this may have to wait for GCC 7 stage 1.
>>
>> Ok for mainline now or then?
>
> I'd rather leave this and subsequent patch for gcc-7 at this point.
> The patch touches middle-end, and from the explanation above, it looks
> that some discussion with middle-end maintainers (relevant people
> CC'd) and their approval  is still needed.

Given that gcc-6 has branched now, could I please get a review for this
patch

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

and its companion

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

now?

Thanks.
Rainer


>> 2016-03-15  Rainer Orth  
>>
>> PR target/59407
>> * config/i386/i386.c (SECTION_LARGE): Define.
>> (x86_64_elf_select_section): Set it for large data/bss sections.
>> Only clear SECTION_WRITE for .lrodata.
>> (x86_64_elf_section_type_flags): Set SECTION_LARGE for large
>> data/bss sections.
>> * config/i386/sol2.h (MACH_DEP_SECTION_ASM_FLAG): Define.
>> * varasm.c (default_elf_asm_named_section): Grow flagchars.
>> [MACH_DEP_SECTION_ASM_FLAG] Emit MACH_DEP_SECTION_ASM_FLAG for
>> SECTION_MACH_DEP.
>> * doc/tm.texi.in (Sections, MACH_DEP_SECTION_ASM_FLAG): Describe.
>> * doc/tm.texi: Regenerate.
>>
>>
>>
>> --
>> -
>> Rainer Orth, Center for Biotechnology, Bielefeld University
>>

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


Re: [wwwdocs,Java] Remove java/status.html

2016-04-18 Thread Andrew Haley
On 17/04/16 17:09, Gerald Pfeifer wrote:
> My recommendation is to handle that via java/index, which is the
> main page, and redirect other GCJ pages to that one as we remove
> them.
> 
> Like in the following, for java/status.html.
> 
> Are you fine with that?

OK, thanks.

Andrew.



Re: [PATCH] Fix missed DSE opportunity with operator delete.

2016-04-18 Thread Richard Biener
On Sat, Apr 16, 2016 at 11:32 PM, Mikhail Maltsev  wrote:
> Hi, all!
>
> Currently GCC can optimize away the following dead store:
>
> void test(char *x)
> {
>   *x = 1;
>   free(x);
> }
>
> but not this one (Clang handles both cases):
>
> void test(char *x)
> {
>   *x = 1;
>   delete x;
> }
>
> The attached patch fixes this by introducing a new __attribute__((free)). I
> first tried to add new built-ins for each version of operator delete (there 
> are
> four of them), but it looked a little clumsy, and would require some special
> handling for warning about taking address of built-in function.
>
> Is such approach (i.e. adding a new attribute) OK? Bootstrapped and regtested 
> on
> x86_64-pc-linux-gnu.

Enlarging tree_function_decl is bad.  I think as you made this a decl attribute
it won't work for virtual delete methods which are called indirectly.

Passes should get at the info via flags_from_decl_or_type () and a new
ECF_FREE.

Richard.

> --
> Regards,
> Mikhail Maltsev
>
> gcc/c/ChangeLog:
>
> 2016-04-16  Mikhail Maltsev  
>
> * c-decl.c (merge_decls): Handle free_flag.
>
> gcc/ChangeLog:
>
> 2016-04-16  Mikhail Maltsev  
>
> * builtin-attrs.def: Add attribute free.
> * builtins.def (free): Add attribute free.
> * doc/extend.texi: Document attribute free.
> * gtm-builtins.def (_ITM_free): Add attribute free.
> * tree-core.h (struct tree_function_decl): Add free_flag.
> * tree-ssa-alias.c (ref_maybe_used_by_call_p_1): Handle free_flag.
> (call_may_clobber_ref_p_1): Likewise.
> (stmt_kills_ref_p): Likewise.
> * tree-streamer-in.c (unpack_ts_function_decl_value_fields): Likewise.
> * tree-streamer-out.c (pack_ts_function_decl_value_fields): Likewise.
> * tree.h (DECL_IS_FREE): New accessor macro.
>
> gcc/testsuite/ChangeLog:
>
> 2016-04-16  Mikhail Maltsev  
>
> * g++.dg/opt/op-delete-dse.C: New test.
> * gcc.dg/attr-free.c: New test.
>
> gcc/c-family/ChangeLog:
>
> 2016-04-16  Mikhail Maltsev  
>
>
>
> * c-common.c (handle_free_attribute): New function.
>
>
>
>
>
> gcc/cp/ChangeLog:
>
>
>
>
>
> 2016-04-16  Mikhail Maltsev  
>
>
>
>
>
> * decl.c (cxx_init_decl_processing): Set flag_free for operator 
> delete.


Re: Edit the C++14 library warning header to not indicate experimental.

2016-04-18 Thread Jonathan Wakely

On 17/04/16 23:21 -0400, Ed Smith-Rowland wrote:


Since the default is C++14 it seems apropos to *not* treat that C++ 
version thusly in the warning in libstdc++.

Ed

OK for trunk?  And maybe some 6 branch later?


OK for trunk, for now. Thanks.


2016-04-17  Edward Smith-Rowland  <3dw...@verizon.net>

* include/bits/c++14_warning.h: Do not refer C++14 as experimental.




Index: include/bits/c++14_warning.h
===
--- include/bits/c++14_warning.h(revision 235086)
+++ include/bits/c++14_warning.h(working copy)
@@ -29,9 +29,9 @@
#define _CXX14_WARNING_H 1

#if __cplusplus <= 201103L
-#error This file requires compiler and library support for the forthcoming \
-ISO C++ 2014 standard. This support is currently experimental, and must be \
-enabled with the -std=c++1y or -std=gnu++1y compiler options.
+#error This file requires compiler and library support \
+for the ISO C++ 2014 standard. This support must be enabled \
+with the -std=c++14 or -std=gnu++14 compiler options.
#endif

#endif




Re: [PATCH] lto-streamer.h: Include gimple.h for LAST_AND_UNUSED_GIMPLE_CODE.

2016-04-18 Thread Richard Biener
On Sat, Apr 16, 2016 at 6:59 PM, Khem Raj  wrote:
> gcc/:
> 2016-04-16  Khem Raj  
>
> * lto-streamer.h: Include gimple.h for LAST_AND_UNUSED_GIMPLE_CODE.
>
>
> Fixes build errors e.g.
>
> | 
> ../../../../../../../work-shared/gcc-6.0.0-r0/git/gcc/lto-streamer.h:159:34: 
> error: 'LAST_AND_UNUSED_GIMPLE_CODE' was not declared in this scope
> |LTO_bb0 = 1 + MAX_TREE_CODES + LAST_AND_UNUSED_GIMPLE_CODE,

You should have included gimple.h before lto-streamer.h in the file
you included it.

Richard.

> ---
>  gcc/lto-streamer.h | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/gcc/lto-streamer.h b/gcc/lto-streamer.h
> index f391161..489801b 100644
> --- a/gcc/lto-streamer.h
> +++ b/gcc/lto-streamer.h
> @@ -26,6 +26,7 @@ along with GCC; see the file COPYING3.  If not see
>  #include "plugin-api.h"
>  #include "gcov-io.h"
>  #include "diagnostic.h"
> +#include "gimple.h"
>
>  /* Define when debugging the LTO streamer.  This causes the writer
> to output the numeric value for the memory address of the tree node
> --
> 2.8.0
>


Re: [PATCH] [6 and trunk] Fix bootstrap with older host compilers

2016-04-18 Thread Richard Biener
On Fri, Apr 15, 2016 at 8:31 PM, Segher Boessenkool
 wrote:
> We didn't have __builtin_swap16 on all targets before GCC 4.8; hsa-brig
> tries to use it if the host GCC is 4.6 or up though, breaking bootstrap.
> This trivial patch fixes it.
>
> Noticed on gcc22.
>
> Is this okay for trunk and gcc-6?

Ok.

Thanks,
Richard.

>
> Segher
>
>
> 2016-04-15  Segher Boessenkool  
>
> * has-brig.c (lendian16): Don't try to use __builtin_bswap16
> unless compiling with at least GCC-4.8.
>
> ---
>  gcc/hsa-brig.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/gcc/hsa-brig.c b/gcc/hsa-brig.c
> index a943e37..9c74b9a 100644
> --- a/gcc/hsa-brig.c
> +++ b/gcc/hsa-brig.c
> @@ -51,7 +51,7 @@ along with GCC; see the file COPYING3.  If not see
>  static uint16_t
>  lendian16 (uint16_t val)
>  {
> -#if GCC_VERSION >= 4006
> +#if GCC_VERSION >= 4008
>  #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
>return val;
>  #elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
> --
> 1.9.3
>


Re: [PING, testsuite] Add dot-file scan to test-case

2016-04-18 Thread Richard Biener
On Mon, 18 Apr 2016, Tom de Vries wrote:

> On 18-04-16 09:30, Richard Biener wrote:
> > > > diff --git a/gcc/testsuite/lib/scandump.exp
> > > > b/gcc/testsuite/lib/scandump.exp
> > > > > >index 74d27cc..89b3944 100644
> > > > > >--- a/gcc/testsuite/lib/scandump.exp
> > > > > >+++ b/gcc/testsuite/lib/scandump.exp
> > > > > >@@ -22,7 +22,7 @@
> > > > > >   # Extract the constant part of the dump file suffix from the
> > > > regexp.
> > > > > >   # Argument 0 is the regular expression.
> > > > > >   proc dump-suffix { arg } {
> > > > > >-set idx [expr [string last "." $arg] + 1]
> > > > > >+set idx [expr [string first "." $arg] + 1]
> > Does that even work?  For t.c.012t.foo the first "." is after 't'.
> 
> With this patch:
> 
> diff --git a/gcc/testsuite/lib/scandump.exp b/gcc/testsuite/lib/scandump.exp
> index 89b3944..89e5754 100644
> --- a/gcc/testsuite/lib/scandump.exp
> +++ b/gcc/testsuite/lib/scandump.exp
> @@ -22,6 +22,7 @@
>  # Extract the constant part of the dump file suffix from the regexp.
>  # Argument 0 is the regular expression.
>  proc dump-suffix { arg } {
> +puts "dump-suffix arg: $arg"
>  set idx [expr [string first "." $arg] + 1]
>  return [string range $arg $idx end]
>  }
> ...
> 
> I see:
> ...
> dump-suffix arg: [0-9][0-9][0-9]i.inline.dot
> dump-suffix arg: [0-9][0-9][0-9]i.cp.dot
> ...
> 
> So, by cutting off after the first dot, we find 'inline.dot' and 'cp.dot',
> instead of just 'dot'.

Ah, I see.  Patch is ok for trunk then.

Richard.


Re: [PING, testsuite] Add dot-file scan to test-case

2016-04-18 Thread Tom de Vries

On 18-04-16 09:30, Richard Biener wrote:

diff --git a/gcc/testsuite/lib/scandump.exp b/gcc/testsuite/lib/scandump.exp
> >index 74d27cc..89b3944 100644
> >--- a/gcc/testsuite/lib/scandump.exp
> >+++ b/gcc/testsuite/lib/scandump.exp
> >@@ -22,7 +22,7 @@
> >   # Extract the constant part of the dump file suffix from the regexp.
> >   # Argument 0 is the regular expression.
> >   proc dump-suffix { arg } {
> >-set idx [expr [string last "." $arg] + 1]
> >+set idx [expr [string first "." $arg] + 1]

Does that even work?  For t.c.012t.foo the first "." is after 't'.


With this patch:

diff --git a/gcc/testsuite/lib/scandump.exp b/gcc/testsuite/lib/scandump.exp
index 89b3944..89e5754 100644
--- a/gcc/testsuite/lib/scandump.exp
+++ b/gcc/testsuite/lib/scandump.exp
@@ -22,6 +22,7 @@
 # Extract the constant part of the dump file suffix from the regexp.
 # Argument 0 is the regular expression.
 proc dump-suffix { arg } {
+puts "dump-suffix arg: $arg"
 set idx [expr [string first "." $arg] + 1]
 return [string range $arg $idx end]
 }
...

I see:
...
dump-suffix arg: [0-9][0-9][0-9]i.inline.dot
dump-suffix arg: [0-9][0-9][0-9]i.cp.dot
...

So, by cutting off after the first dot, we find 'inline.dot' and 'cp.dot', 
instead of just 'dot'.


Thanks,
- Tom


Re: [PING, testsuite] Add dot-file scan to test-case

2016-04-18 Thread Richard Biener
On Sun, 17 Apr 2016, Tom de Vries wrote:

> [ was: PATCH, PR70161] Fix fdump-ipa-all-graph ]
> 
> On 18/03/16 10:35, Tom de Vries wrote:
> > On 18/03/16 10:23, Tom de Vries wrote:
> > > On 15/03/16 12:37, Richard Biener wrote:
> > > > On Mon, 14 Mar 2016, Tom de Vries wrote:
> > > > 
> > > > > Hi,
> > > > > 
> > > > > this patch fixes PR70161, a 4.9/5/6 regression.
> > > > > 
> > > > > Currently when using -fdump-ipa-all-graph, the compiler ICEs in
> > > > > execute_function_dump when testing for pass->graph_dump_initialized,
> > > > > because
> > > > > pass == NULL.
> > > > > 
> > > > > The patch fixes:
> > > > > - the ICE by setting the pass argument in the call to
> > > > >execute_function_dump in execute_one_ipa_transform_pass
> > > > > - a subsequent ICE (triggered with -fipa-pta) by saving, resetting and
> > > > >restoring dump_file_name in cgraph_node::get_body, alongside the
> > > > >saving and restoring of the dump_file variable.
> > > > > - the duplicate edges in the subsequently generated dot file by
> > > > >ensuring that execute_function_dump is called only once per
> > > > > function
> > > > >per pass. [ Note that this bit also has an effect for the normal
> > > > > dump
> > > > >files for the ipa passes with transform function. For those
> > > > > functions,
> > > > >atm execute_function_dump is called both after execute and after
> > > > >transform. With the patch, it's only called after transform. ]
> > > > > 
> > > > > Bootstrapped and reg-tested on x86_64.
> > > > > 
> > > > > OK for stage4?
> > > > 
> > > > Ok.
> > > > 
> > > 
> > > I've added these two test-cases that test the first two fixes.
> > > 
> > > Committed to trunk as obvious.
> > > 
> > 
> > This patch adds testing for the last fix.
> > 
> > In order to make scanning lines in a .dot file work, I needed a fix in
> > dump-suffix to show cp.dot and inline.dot in the test summary:
> > ...
> > PASS: gcc.dg/pr70161.c scan-ipa-dump-times cp.dot "subgraph" 1
> > PASS: gcc.dg/pr70161.c scan-ipa-dump-times inline.dot "subgraph" 1
> > ...
> > Otherwise it would just show 'dot'.
> > 
> > Bootstrapped and reg-tested on x86_64.
> > 
> > OK for stage4 trunk, 4.9/5 release branches?
> > 
> 
> Ping.
> 
> Thanks,
> - Tom
> 
> > 0004-Add-dot-file-scans-to-pr70161.c.patch
> > 
> > 
> > Add dot-file scans to pr70161.c
> > 
> > 2016-03-18  Tom de Vries  
> > 
> > * gcc.dg/pr70161.c: Add dot-file scans.
> > * lib/scandump.exp (dump-suffix): Return suffix after first dot char,
> > instead of after last dot char.
> > 
> > ---
> >   gcc/testsuite/gcc.dg/pr70161.c | 3 +++
> >   gcc/testsuite/lib/scandump.exp | 2 +-
> >   2 files changed, 4 insertions(+), 1 deletion(-)
> > 
> > diff --git a/gcc/testsuite/gcc.dg/pr70161.c b/gcc/testsuite/gcc.dg/pr70161.c
> > index 0b173c7..9b77d90 100644
> > --- a/gcc/testsuite/gcc.dg/pr70161.c
> > +++ b/gcc/testsuite/gcc.dg/pr70161.c
> > @@ -5,3 +5,6 @@ void
> >   foo (void)
> >   {
> >   }
> > +
> > +/* { dg-final { scan-ipa-dump-times "subgraph" 1 "inline.dot" } } */
> > +/* { dg-final { scan-ipa-dump-times "subgraph" 1 "cp.dot" } } */
> > diff --git a/gcc/testsuite/lib/scandump.exp b/gcc/testsuite/lib/scandump.exp
> > index 74d27cc..89b3944 100644
> > --- a/gcc/testsuite/lib/scandump.exp
> > +++ b/gcc/testsuite/lib/scandump.exp
> > @@ -22,7 +22,7 @@
> >   # Extract the constant part of the dump file suffix from the regexp.
> >   # Argument 0 is the regular expression.
> >   proc dump-suffix { arg } {
> > -set idx [expr [string last "." $arg] + 1]
> > +set idx [expr [string first "." $arg] + 1]

Does that even work?  For t.c.012t.foo the first "." is after 't'.

Richard.

> >   return [string range $arg $idx end]
> >   }
> > 
> > 
> 
> 

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