[PR tree-optimization/71328] Fix off-by-one error in CFG/SSA updates for backward threading

2016-06-02 Thread Jeff Law



This bug has actually been around since the introduction of the 
FSM/backwards threader a few years ago.  It was just latent.


Essentially we need to look at the copied path for branches back into 
the path -- due to an off-by-one error, we missed the case where the 
last block in the path branches back to itself.


This results in the verification failure reported in pr71328.

I'd already had this in my tree as I'd run into it dealing with one of 
the other regressions from my recent changes.  Given it's a totally 
independent issue it seemed wise to extract and fix this one independently.


Bootstrapped on x86_64 linux and installed on the trunk.

Jeff
commit 96a568909e429b0f24d61c8a2f3dd3c183d720d7
Author: law 
Date:   Fri Jun 3 05:20:16 2016 +

PR tree-optimization/71328
* tree-ssa-threadupdate.c (duplicate_thread_path): Fix off-by-one
error when checking for a jump back onto the copied path.  */

PR tree-optimization/71328
* gcc.c-torture/compile/pr71328.c: New test.

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

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 2a0951b..2c6f6b1 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,9 @@
+2016-06-02  Jeff Law  
+
+   PR tree-optimization/71328
+   * tree-ssa-threadupdate.c (duplicate_thread_path): Fix off-by-one
+   error when checking for a jump back onto the copied path.  */
+
 2016-06-02  David Malcolm  
 
* config/microblaze/microblaze.c (get_branch_target): Add return
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 9f7da16..263d91b 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2016-06-02  Jeff Law  
+
+   PR tree-optimization/71328
+   * gcc.c-torture/compile/pr71328.c: New test.
+
 2016-06-02  Jerry DeLisle  
 
PR fortran/52393
diff --git a/gcc/testsuite/gcc.c-torture/compile/pr71328.c 
b/gcc/testsuite/gcc.c-torture/compile/pr71328.c
new file mode 100644
index 000..aa384e8
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/compile/pr71328.c
@@ -0,0 +1,16 @@
+
+
+int a, b, c;
+void fn1() {
+  unsigned char d = 3;
+  if (d > 11)
+  lbl_596:
+  c = 0;
+  while (!d)
+b = b;
+  unsigned char e = e || d;
+  d = e;
+  if (a)
+d = d || a;
+  goto lbl_596;
+}
diff --git a/gcc/tree-ssa-threadupdate.c b/gcc/tree-ssa-threadupdate.c
index 620948c..1ff007a 100644
--- a/gcc/tree-ssa-threadupdate.c
+++ b/gcc/tree-ssa-threadupdate.c
@@ -2298,11 +2298,11 @@ duplicate_thread_path (edge entry, edge exit,
}
 
   /* Special case the last block on the path: make sure that it does not
-jump back on the copied path.  */
+jump back on the copied path, including back to itself.  */
   if (i + 1 == n_region)
{
  FOR_EACH_EDGE (e, ei, bb->succs)
-   if (bb_in_bbs (e->dest, region_copy, n_region - 1))
+   if (bb_in_bbs (e->dest, region_copy, n_region))
  {
basic_block orig = get_bb_original (e->dest);
if (orig)


Re: [PATCH v2] gcc/config/tilegx/tilegx.c (tilegx_function_profiler): Save r10 to stack before call mcount

2016-06-02 Thread Richard Henderson

On 06/02/2016 03:23 PM, cheng...@emindsoft.com.cn wrote:

   fprintf (file,
+  "\t{\n"
+  "\taddi\tsp, sp, -8\n"
+  "\tst\tsp, r10\n"
+  "\t}\n"
   "\t{\n"


You need only do this if cfun->static_chain_decl is set.


r~


Re: [PATCH] integer overflow checking builtins in constant expressions

2016-06-02 Thread Martin Sebor

+{
+  /* Perform the computation in the target type and check for
overflow.  */
+  arg0 = fold_convert (type, arg0);
+  arg1 = fold_convert (type, arg1);
+
+  if (tree result = size_binop_loc (loc, opcode, arg0, arg1))
+return TREE_OVERFLOW (result) ? build_one_cst (boolean_type_node)
+  : build_zero_cst (boolean_type_node);


This is wrong, it is not the computation of overflow that is intended.
The documentation says that we compute
(infinite_precision_signed_type) arg0
op (infinite_precision_signed_type) arg1 and then cast it to type, extend
again to infinite_precision_signed_type and compare.  And we have a
helper
function for that already.


Thank you for the suggestion.  Using the helper instead is simpler
(though my tests don't show any difference in the computed result
so I'm not sure I see in what way the original code was wrong).

...


Again, this is wrong, it should have used arith_overflowed_p.


No.  As is apparent from the rest of hunk, we need the result or
the computation here, not just the overflow bit.


It just dawned on me what the problem was and why both places
need arith_overflowed_p:  Converting the arguments to the result
type and doing the arithmetic and checking for overflow in it
would mask it in cases like:

  __builtin_add_overflow (SCHAR_MAX + 1, 1, (signed char*)0)

I've fixed it in the attached patch (and added test cases to
verify it).

Martin
PR c++/70507 - integer overflow builtins not constant expressions
PR c/68120 - can't easily deal with integer overflow at compile time

gcc/cp/ChangeLog:
2016-06-02  Martin Sebor  

	PR c++/70507
	PR c/68120
	* constexpr.c (cxx_eval_internal_function): New function.
	(cxx_eval_call_expression): Call it.
	(potential_constant_expression_1): Handle integer arithmetic
	overflow built-ins.
	* tree.c (builtin_valid_in_constant_expr_p): Same.

gcc/ChangeLog:
2016-06-02  Martin Sebor  

	PR c++/70507
	PR c/68120
	* builtins.c (fold_builtin_unordered_cmp): Handle integer arithmetic
	overflow built-ins.
	* doc/extend.texi (Integer Overflow Builtins): Update.

gcc/testsuite/ChangeLog:
2016-06-02  Martin Sebor  

	PR c++/70507
	PR c/68120
	* c-c++-common/builtin-arith-overflow-1.c: Add test cases.
	* c-c++-common/builtin-arith-overflow-2.c: New test.
	* g++.dg/cpp0x/constexpr-arith-overflow.C: New test.
	* g++.dg/cpp1y/constexpr-arith-overflow.C: New test.

diff --git a/gcc/builtins.c b/gcc/builtins.c
index 931d4a6..ada1904 100644
--- a/gcc/builtins.c
+++ b/gcc/builtins.c
@@ -64,6 +64,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "rtl-chkp.h"
 #include "internal-fn.h"
 #include "case-cfn-macros.h"
+#include "gimple-fold.h"
 
 
 struct target_builtins default_target_builtins;
@@ -7957,11 +7958,14 @@ fold_builtin_arith_overflow (location_t loc, enum built_in_function fcode,
 			 tree arg0, tree arg1, tree arg2)
 {
   enum internal_fn ifn = IFN_LAST;
-  tree type = TREE_TYPE (TREE_TYPE (arg2));
-  tree mem_arg2 = build_fold_indirect_ref_loc (loc, arg2);
+  /* The code of the expression corresponding to the type-generic
+ built-in, or ERROR_MARK for the type-specific ones.  */
+  enum tree_code opcode = ERROR_MARK;
+
   switch (fcode)
 {
 case BUILT_IN_ADD_OVERFLOW:
+  opcode = PLUS_EXPR;
 case BUILT_IN_SADD_OVERFLOW:
 case BUILT_IN_SADDL_OVERFLOW:
 case BUILT_IN_SADDLL_OVERFLOW:
@@ -7971,6 +7975,7 @@ fold_builtin_arith_overflow (location_t loc, enum built_in_function fcode,
   ifn = IFN_ADD_OVERFLOW;
   break;
 case BUILT_IN_SUB_OVERFLOW:
+  opcode = MINUS_EXPR;
 case BUILT_IN_SSUB_OVERFLOW:
 case BUILT_IN_SSUBL_OVERFLOW:
 case BUILT_IN_SSUBLL_OVERFLOW:
@@ -7980,6 +7985,7 @@ fold_builtin_arith_overflow (location_t loc, enum built_in_function fcode,
   ifn = IFN_SUB_OVERFLOW;
   break;
 case BUILT_IN_MUL_OVERFLOW:
+  opcode = MULT_EXPR;
 case BUILT_IN_SMUL_OVERFLOW:
 case BUILT_IN_SMULL_OVERFLOW:
 case BUILT_IN_SMULLL_OVERFLOW:
@@ -7991,6 +7997,26 @@ fold_builtin_arith_overflow (location_t loc, enum built_in_function fcode,
 default:
   gcc_unreachable ();
 }
+
+  /* For the "generic" overloads, the first two arguments can have different
+ types and the last argument determines the target type to use to check
+ for overflow.  The arguments of the other overloads all have the same
+ type.  */
+  bool isnullp = integer_zerop (arg2);
+  tree type = TREE_TYPE (TREE_TYPE (arg2));
+
+  /* When the last argument to the type-generic built-in is a null pointer
+ and the first two arguments are constant, attempt to fold the built-in
+ call into a constant expression indicating whether or not it detected
+ an overflow but without storing the result.  */
+  if (opcode != ERROR_MARK && isnullp
+  && TREE_CODE (arg0) == INTEGER_CST && TREE_CODE (arg1) == INTEGER_CST)
+{
+  /* Perform the 

[PATCH] c/71392 - SEGV calling integer overflow built-ins with a null pointer

2016-06-02 Thread Martin Sebor

In a discussion of a patch in a this area (c/68120 and c++/70507)
Jakub noticed that the integer arithmetic built-ins with overflow
checking that expect a pointer to an integer as the last argument
silently (i.e., without a warning) accept a null pointer.  As the
test case in the bug referenced in in subject shows, such calls
then crash at runtime.

The attached patch follows the same approach used by other built
ins that take a pointer to an object (such as __built_strlen) to
issue a -Wnonnull warning for such invalid calls.

Martin
PR c/71392 - SEGV calling integer overflow built-ins with a null pointer

gcc/testsuite/ChangeLog:
2016-06-02  Martin Sebor  

	PR c/71392
	* c-c++-common/builtin-arith-overflow-1.c: Add test cases.

gcc/ChangeLog:
2016-06-02  Martin Sebor  

	PR c/71392
	* builtin-attrs.def (ATTR_NOTHROW_NONNULL_LEAF_LIST): New macro.
	* builtins.def (BUILT_IN_SADD_OVERFLOW, BUILT_IN_SADDL_OVERFLOW): Use it.
	(BUILT_IN_SADDLL_OVERFLOW, BUILT_IN_SSUB_OVERFLOW): Same.
	(BUILT_IN_SSUBL_OVERFLOW, BUILT_IN_SSUBLL_OVERFLOW): Same.
	(BUILT_IN_SMUL_OVERFLOW, BUILT_IN_SMULL_OVERFLOW): Same.
	(BUILT_IN_SMULLL_OVERFLOW, BUILT_IN_UADD_OVERFLOW): Same.
	(BUILT_IN_UADDL_OVERFLOW, BUILT_IN_UADDLL_OVERFLOW): Same.
	(BUILT_IN_USUB_OVERFLOW, BUILT_IN_USUBL_OVERFLOW): Same.
	(BUILT_IN_USUBLL_OVERFLOW, BUILT_IN_UMUL_OVERFLOW): Same.
	(BUILT_IN_UMULL_OVERFLOW, BUILT_IN_UMULLL_OVERFLOW):

diff --git a/gcc/builtin-attrs.def b/gcc/builtin-attrs.def
index 089817a..cefe121 100644
--- a/gcc/builtin-attrs.def
+++ b/gcc/builtin-attrs.def
@@ -165,6 +165,7 @@ DEF_ATTR_TREE_LIST (ATTR_NOTHROW_NONNULL, ATTR_NONNULL, ATTR_NULL, \
 /* Nothrow leaf functions whose pointer parameter(s) are all nonnull.  */
 DEF_ATTR_TREE_LIST (ATTR_NOTHROW_NONNULL_LEAF, ATTR_NONNULL, ATTR_NULL, \
 			ATTR_NOTHROW_LEAF_LIST)
+DEF_ATTR_TREE_LIST (ATTR_NOTHROW_NONNULL_LEAF_LIST, ATTR_LEAF, ATTR_NULL, ATTR_NOTHROW_NONNULL_LEAF)
 /* Nothrow functions whose first parameter is a nonnull pointer.  */
 DEF_ATTR_TREE_LIST (ATTR_NOTHROW_NONNULL_1, ATTR_NONNULL, ATTR_LIST_1, \
 			ATTR_NOTHROW_LIST)
diff --git a/gcc/builtins.def b/gcc/builtins.def
index 2fc7f65..4df15e4 100644
--- a/gcc/builtins.def
+++ b/gcc/builtins.def
@@ -711,24 +711,24 @@ DEF_GCC_BUILTIN(BUILT_IN_ADD_OVERFLOW, "add_overflow", BT_FN_BOOL_VAR, A
 DEF_GCC_BUILTIN(BUILT_IN_SUB_OVERFLOW, "sub_overflow", BT_FN_BOOL_VAR, ATTR_NOTHROW_TYPEGENERIC_LEAF)
 DEF_GCC_BUILTIN(BUILT_IN_MUL_OVERFLOW, "mul_overflow", BT_FN_BOOL_VAR, ATTR_NOTHROW_TYPEGENERIC_LEAF)
 /* Clang compatibility.  */
-DEF_GCC_BUILTIN(BUILT_IN_SADD_OVERFLOW, "sadd_overflow", BT_FN_BOOL_INT_INT_INTPTR, ATTR_NOTHROW_LEAF_LIST)
-DEF_GCC_BUILTIN(BUILT_IN_SADDL_OVERFLOW, "saddl_overflow", BT_FN_BOOL_LONG_LONG_LONGPTR, ATTR_NOTHROW_LEAF_LIST)
-DEF_GCC_BUILTIN(BUILT_IN_SADDLL_OVERFLOW, "saddll_overflow", BT_FN_BOOL_LONGLONG_LONGLONG_LONGLONGPTR, ATTR_NOTHROW_LEAF_LIST)
-DEF_GCC_BUILTIN(BUILT_IN_SSUB_OVERFLOW, "ssub_overflow", BT_FN_BOOL_INT_INT_INTPTR, ATTR_NOTHROW_LEAF_LIST)
-DEF_GCC_BUILTIN(BUILT_IN_SSUBL_OVERFLOW, "ssubl_overflow", BT_FN_BOOL_LONG_LONG_LONGPTR, ATTR_NOTHROW_LEAF_LIST)
-DEF_GCC_BUILTIN(BUILT_IN_SSUBLL_OVERFLOW, "ssubll_overflow", BT_FN_BOOL_LONGLONG_LONGLONG_LONGLONGPTR, ATTR_NOTHROW_LEAF_LIST)
-DEF_GCC_BUILTIN(BUILT_IN_SMUL_OVERFLOW, "smul_overflow", BT_FN_BOOL_INT_INT_INTPTR, ATTR_NOTHROW_LEAF_LIST)
-DEF_GCC_BUILTIN(BUILT_IN_SMULL_OVERFLOW, "smull_overflow", BT_FN_BOOL_LONG_LONG_LONGPTR, ATTR_NOTHROW_LEAF_LIST)
-DEF_GCC_BUILTIN(BUILT_IN_SMULLL_OVERFLOW, "smulll_overflow", BT_FN_BOOL_LONGLONG_LONGLONG_LONGLONGPTR, ATTR_NOTHROW_LEAF_LIST)
-DEF_GCC_BUILTIN(BUILT_IN_UADD_OVERFLOW, "uadd_overflow", BT_FN_BOOL_UINT_UINT_UINTPTR, ATTR_NOTHROW_LEAF_LIST)
-DEF_GCC_BUILTIN(BUILT_IN_UADDL_OVERFLOW, "uaddl_overflow", BT_FN_BOOL_ULONG_ULONG_ULONGPTR, ATTR_NOTHROW_LEAF_LIST)
-DEF_GCC_BUILTIN(BUILT_IN_UADDLL_OVERFLOW, "uaddll_overflow", BT_FN_BOOL_ULONGLONG_ULONGLONG_ULONGLONGPTR, ATTR_NOTHROW_LEAF_LIST)
-DEF_GCC_BUILTIN(BUILT_IN_USUB_OVERFLOW, "usub_overflow", BT_FN_BOOL_UINT_UINT_UINTPTR, ATTR_NOTHROW_LEAF_LIST)
-DEF_GCC_BUILTIN(BUILT_IN_USUBL_OVERFLOW, "usubl_overflow", BT_FN_BOOL_ULONG_ULONG_ULONGPTR, ATTR_NOTHROW_LEAF_LIST)
-DEF_GCC_BUILTIN(BUILT_IN_USUBLL_OVERFLOW, "usubll_overflow", BT_FN_BOOL_ULONGLONG_ULONGLONG_ULONGLONGPTR, ATTR_NOTHROW_LEAF_LIST)
-DEF_GCC_BUILTIN(BUILT_IN_UMUL_OVERFLOW, "umul_overflow", BT_FN_BOOL_UINT_UINT_UINTPTR, ATTR_NOTHROW_LEAF_LIST)
-DEF_GCC_BUILTIN(BUILT_IN_UMULL_OVERFLOW, "umull_overflow", BT_FN_BOOL_ULONG_ULONG_ULONGPTR, ATTR_NOTHROW_LEAF_LIST)
-DEF_GCC_BUILTIN(BUILT_IN_UMULLL_OVERFLOW, "umulll_overflow", BT_FN_BOOL_ULONGLONG_ULONGLONG_ULONGLONGPTR, ATTR_NOTHROW_LEAF_LIST)
+DEF_GCC_BUILTIN(BUILT_IN_SADD_OVERFLOW, "sadd_overflow", BT_FN_BOOL_INT_INT_INTPTR, 

Re: [PATCH] integer overflow checking builtins in constant expressions

2016-06-02 Thread Martin Sebor

+  /* For the "generic" overloads, the first two arguments can have different
+ types and the last argument determines the target type to use to check
+ for overflow.  The arguments of the other overloads all have the same
+ type.  */
+  tree type = TREE_TYPE (TREE_TYPE (arg2));
+  bool isnullp = integer_zerop (arg2);
+
+  /* When the last argument is a null pointer and the first two arguments
+ are constant, attempt to fold the built-in call into a constant
+ expression indicating whether or not it detected an overflow but
+ without storing the result.  */
+  if (isnullp
+  && TREE_CODE (arg0) == INTEGER_CST && TREE_CODE (arg1) == INTEGER_CST)


Doesn't this mean you allow NULL arg2 even for BUILT_IN_ADDL_OVERFLOW and
similar clang builtins?


Yes, that's possible, and always has been.  I've raised a new bug
for it: c/71392 - SEGV calling integer overflow built-ins with
a null pointer.  The built-ins are missing the non-null attribute.
I've assigned the bug to myself and will submit a separate patch
for it in a minute.


+{
+  /* Perform the computation in the target type and check for overflow.  */
+  arg0 = fold_convert (type, arg0);
+  arg1 = fold_convert (type, arg1);
+
+  if (tree result = size_binop_loc (loc, opcode, arg0, arg1))
+   return TREE_OVERFLOW (result) ? build_one_cst (boolean_type_node)
+ : build_zero_cst (boolean_type_node);


This is wrong, it is not the computation of overflow that is intended.
The documentation says that we compute (infinite_precision_signed_type) arg0
op (infinite_precision_signed_type) arg1 and then cast it to type, extend
again to infinite_precision_signed_type and compare.  And we have a helper
function for that already.


Thank you for the suggestion.  Using the helper instead is simpler
(though my tests don't show any difference in the computed result
so I'm not sure I see in what way the original code was wrong).


+  tree arg0 = cxx_eval_constant_expression (ctx, CALL_EXPR_ARG (t, 0), lval,
+   non_constant_p, overflow_p);
+  tree arg1 = cxx_eval_constant_expression (ctx, CALL_EXPR_ARG (t, 1), lval,
+   non_constant_p, overflow_p);
+
+  if (TREE_CODE (arg0) == INTEGER_CST && TREE_CODE (arg1) == INTEGER_CST)
+{
+  if (tree result = size_binop_loc (EXPR_LOC_OR_LOC (t, input_location),
+   opcode, arg0, arg1))
+   {
+ if (TREE_OVERFLOW (result))
+   {
+ /* Reset TREE_OVERFLOW to avoid warnings for the overflow.  */
+ TREE_OVERFLOW (result) = 0;


Again, this is wrong, it should have used arith_overflowed_p.


No.  As is apparent from the rest of hunk, we need the result or
the computation here, not just the overflow bit.


AFAIK the docs use either C++98, C++11 (without space), or
ISO/IEC 14882:2011 etc., but not C++ 98 or C++ 11.

Also, perhaps just a documentation thing, it would be good to clarify the
NULL last argument.  From the POV of generating efficient code, I think we
should say something that the last argument (for the GNU builtins) must be
either a pointer to a valid object, or NULL/nullptr constant cast expression
cast to a pointer type, but nothing else.  That is actually what your patch
implements.


I've updated the manual to make it clear that the null pointer
must be a constant.

While testing the updated patch I noticed that I had neglected
to update potential_constant_expression_1 in constexpr.c to handle
the internal functions corresponding to the built-ins, so I've
made that change and added test cases to exercise it.  (In the
process, I also uncovered a new constexpr bug and raised
c++/71391 - error on aggregate initialization with side-effects
in a constexpr function.

Attached is an updated patch with these changes.

Martin
diff --git a/gcc/builtins.c b/gcc/builtins.c
index 931d4a6..ada1904 100644
--- a/gcc/builtins.c
+++ b/gcc/builtins.c
@@ -64,6 +64,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "rtl-chkp.h"
 #include "internal-fn.h"
 #include "case-cfn-macros.h"
+#include "gimple-fold.h"
 
 
 struct target_builtins default_target_builtins;
@@ -7957,11 +7958,14 @@ fold_builtin_arith_overflow (location_t loc, enum built_in_function fcode,
 			 tree arg0, tree arg1, tree arg2)
 {
   enum internal_fn ifn = IFN_LAST;
-  tree type = TREE_TYPE (TREE_TYPE (arg2));
-  tree mem_arg2 = build_fold_indirect_ref_loc (loc, arg2);
+  /* The code of the expression corresponding to the type-generic
+ built-in, or ERROR_MARK for the type-specific ones.  */
+  enum tree_code opcode = ERROR_MARK;
+
   switch (fcode)
 {
 case BUILT_IN_ADD_OVERFLOW:
+  opcode = PLUS_EXPR;
 case BUILT_IN_SADD_OVERFLOW:
 case BUILT_IN_SADDL_OVERFLOW:
 case BUILT_IN_SADDLL_OVERFLOW:
@@ -7971,6 +7975,7 @@ fold_builtin_arith_overflow (location_t loc, enum built_in_function 

Re: [PATCH 01/16] Core of selftest framework (v6)

2016-06-02 Thread Bernd Schmidt

On 06/02/2016 11:06 PM, David Malcolm wrote:

gcc/ChangeLog:
* Makefile.in (OBJS): Add function-tests.o,
hash-map-tests.o, hash-set-tests.o, rtl-tests.o,
selftest-run-tests.o.
(OBJS-libcommon): Add selftest.o.
(OBJS-libcommon-target): Add selftest.o.
(all.internal): Add "selftests".
(all.cross): Likewise.
(selftests): New phony target.
(s-selftests): New target.
(selftests-gdb): New phony target.
(COLLECT2_OBJS): Add selftest.o.
* common.opt (fself-test): New.
* selftest-run-tests.c: New file.
* selftest.c: New file.
* selftest.h: New file.
* toplev.c: Include selftest.h.
(toplev::run_self_tests): New.
(toplev::main): Handle -fself-test.
* toplev.h (toplev::run_self_tests): New.


This one looks good to me. I kind of liked the auto-registration, but I 
guess manually calling functions is preferrable to including C files and 
similar in effort required. So it's probably better this way.



+  fprintf (stderr,
+  "%s:%i: FAIL: %s\n",
+  file, line, msg);
+  /* TODO: add calling function name as well?  */
+  abort ();
+}


That'll fit on one line. Otherwise OK. Likewise for anything Jeff has 
already approved in a different form - but please make another pass and 
add brief function comments for new functions, and please ensure every 
step you commit actually compiles (this patch alone won't). Let me know 
which patches still need approval after that.



Bernd


[PATCH v2] gcc/config/tilegx/tilegx.c (tilegx_function_profiler): Save r10 to stack before call mcount

2016-06-02 Thread chengang
From: Chen Gang 

r10 may also be as parameter stack pointer for the nested function, so
need save it before call mcount.

2016-06-03  Chen Gang  

gcc/
PR target/71331
* config/tilegx/tilegx.c (tilegx_function_profiler): Save r10
to stack before call mcount.
---
 gcc/config/tilegx/tilegx.c | 14 --
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/gcc/config/tilegx/tilegx.c b/gcc/config/tilegx/tilegx.c
index 06c832c..bc41105 100644
--- a/gcc/config/tilegx/tilegx.c
+++ b/gcc/config/tilegx/tilegx.c
@@ -5510,18 +5510,32 @@ tilegx_function_profiler (FILE *file, int labelno 
ATTRIBUTE_UNUSED)
   if (flag_pic)
 {
   fprintf (file,
+  "\t{\n"
+  "\taddi\tsp, sp, -8\n"
+  "\tst\tsp, r10\n"
+  "\t}\n"
   "\t{\n"
   "\tmove\tr10, lr\n"
   "\tjal\tplt(%s)\n"
-  "\t}\n", MCOUNT_NAME);
+  "\t}\n"
+  "\taddi\tsp, sp, 8\n"
+  "\tld\tr10, sp\n",
+  MCOUNT_NAME);
 }
   else
 {
   fprintf (file,
+  "\t{\n"
+  "\taddi\tsp, sp, -8\n"
+  "\tst\tsp, r10\n"
+  "\t}\n"
   "\t{\n"
   "\tmove\tr10, lr\n"
   "\tjal\t%s\n"
-  "\t}\n", MCOUNT_NAME);
+  "\t}\n"
+  "\taddi\tsp, sp, 8\n"
+  "\tld\tr10, sp\n",
+  MCOUNT_NAME);
 }
 
   tilegx_in_bundle = false;
-- 
1.9.3



[C++ Patch] Change a few error + error to error + inform

2016-06-02 Thread Paolo Carlini

Hi,

while working on c++/70202, I noticed a few more of those pairs for 
errors which we changed in the past to error + inform. Tested x86_64-linux.


Thanks,
Paolo.

/
/cp
2016-06-02  Paolo Carlini  

* decl.c (xref_tag_1): Change pairs of errors to error + inform.
(start_enum): Likewise.
* parser.c (cp_parser_class_head): Likewise.

/testsuite
2016-06-02  Paolo Carlini  

* g++.dg/cpp0x/forw_enum10.C: Adjust for dg-message vs dg-error.
* g++.dg/cpp0x/forw_enum6.C: Likewise.
* g++.dg/cpp0x/forw_enum8.C: Likewise.
* g++.dg/cpp0x/override2.C: Likewise.
* g++.dg/parse/crash5.C: Likewise.
* g++.dg/parse/error16.C: Likewise.
* g++.dg/parse/error27.C: Likewise.
* g++.dg/template/qualttp15.C: Likewise.
* g++.dg/template/redecl4.C: Likewise.
* g++.old-deja/g++.other/crash39.C: Likewise.
* g++.old-deja/g++.other/struct1.C: Likewise.
* g++.old-deja/g++.pt/m9a.C: Likewise.
* g++.old-deja/g++.pt/memclass10.C: Likewise.
Index: cp/decl.c
===
--- cp/decl.c   (revision 237042)
+++ cp/decl.c   (working copy)
@@ -12793,7 +12793,7 @@ xref_tag_1 (enum tag_types tag_code, tree name,
   && CLASSTYPE_IS_TEMPLATE (t))
{
  error ("redeclaration of %qT as a non-template", t);
- error ("previous declaration %q+D", t);
+ inform (location_of (t), "previous declaration %qD", t);
  return error_mark_node;
}
 
@@ -13149,8 +13149,8 @@ start_enum (tree name, tree enumtype, tree underly
{
  error_at (input_location, "scoped/unscoped mismatch "
"in enum %q#T", enumtype);
- error_at (DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (enumtype)),
-   "previous definition here");
+ inform (DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (enumtype)),
+ "previous definition here");
  enumtype = error_mark_node;
}
   else if (ENUM_FIXED_UNDERLYING_TYPE_P (enumtype) != !! underlying_type)
@@ -13157,8 +13157,8 @@ start_enum (tree name, tree enumtype, tree underly
{
  error_at (input_location, "underlying type mismatch "
"in enum %q#T", enumtype);
- error_at (DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (enumtype)),
-   "previous definition here");
+ inform (DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (enumtype)),
+ "previous definition here");
  enumtype = error_mark_node;
}
   else if (underlying_type && ENUM_UNDERLYING_TYPE (enumtype)
@@ -13169,8 +13169,8 @@ start_enum (tree name, tree enumtype, tree underly
{
  error_at (input_location, "different underlying type "
"in enum %q#T", enumtype);
- error_at (DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (enumtype)),
-   "previous definition here");
+ inform (DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (enumtype)),
+ "previous definition here");
  underlying_type = NULL_TREE;
}
 }
Index: cp/parser.c
===
--- cp/parser.c (revision 237042)
+++ cp/parser.c (working copy)
@@ -22008,8 +22008,8 @@ cp_parser_class_head (cp_parser* parser,
 {
   error_at (type_start_token->location, "redefinition of %q#T",
type);
-  error_at (type_start_token->location, "previous definition of %q+#T",
-   type);
+  inform (location_of (type), "previous definition of %q#T",
+ type);
   type = NULL_TREE;
   goto done;
 }
Index: testsuite/g++.dg/cpp0x/forw_enum10.C
===
--- testsuite/g++.dg/cpp0x/forw_enum10.C(revision 237042)
+++ testsuite/g++.dg/cpp0x/forw_enum10.C(working copy)
@@ -3,7 +3,7 @@
 //This error is diagnosed at instantiation time
 template struct S1
 {
-enum E : T;   // { dg-error "previous definition" }
+enum E : T;   // { dg-message "previous definition" }
 enum E : int; // { dg-error "different underlying type" }
 };
 template struct S1; // { dg-message "required from here" }
@@ -24,7 +24,7 @@ template struct S3;
 
 template struct S4
 {
-enum E : T1; // { dg-error "previous definition" }
+enum E : T1; // { dg-message "previous definition" }
 enum E : T2; // { dg-error "different underlying type" }
 };
 template struct S4; // { dg-message "required from here" }
Index: testsuite/g++.dg/cpp0x/forw_enum6.C
===
--- testsuite/g++.dg/cpp0x/forw_enum6.C (revision 237042)
+++ testsuite/g++.dg/cpp0x/forw_enum6.C (working copy)
@@ -1,18 +1,18 @@
 // { dg-do compile { target c++11 } }
 
-enum class E1 : int; // { dg-error 

Re: [C++ Patch] Change a few error + error to error + inform

2016-06-02 Thread Jason Merrill
OK.

Jason


Re: [PATCH] nvptx per-warp compiler-defined stacks (-msoft-stack)

2016-06-02 Thread Alexander Monakov
On Wed, 25 May 2016, Nathan Sidwell wrote:
> > > It seems like we should reject the combination of -msoft-stack -fopenacc?
> >
> > Possibly; the doc text makes it explicit that the option is exposed only for
> > the purpose of testing the compiler, anyway.
> 
> It is always best to prevent the user doing something you don't recommend,
> rather than presume they'll be sensible.

No change for that yet in the respin; do you want something like

  if (flag_openacc && TARGET_SOFT_STACK)
sorry ("-fopenacc and -msoft-stack are mutually exclusive");

in nvptx_override_options?

> > > > +  bool using_softstack; /* Need to restore __nvptx_stacks[tid.y].  */
> > >
> > > Comment should describe what the attribute is, not what it implies.  In
> > > this
> > > case I think it's /*  Current function has   a soft stack frame.  */
> >
> > Yes; note it's false when current function is leaf, so the description
> > should
> > be more like "Current function has a soft stack frame that needs restoring".
> 
> Ok.  so the name doesn't match the semantics.  I suggest renaming it to
> 'restore_softstack', with a similarly adjusted comment.

I went with 'has_softstack' (and the comment you've suggested previously) and
made the code check leafness separately.

> > > Are changes needed in nvptx's  crt0.s (or an auxilary file in libc or
> > > libgcc)
> > > to make this work for testing?
> >
> > Yes.
> 
> Please include  that chunk in the next revision of this patch.  But see the
> commit I just made.  I intend to move the malloc stuff to newlib next, but
> that shouldn't affect the changes needed for this.

Done.

Updated patch below.

Alexander

gcc/:
* config/nvptx/nvptx-protos.h (nvptx_output_set_softstack): Declare.
* config/nvptx/nvptx.c: (need_softstack_decl): New variable.
(init_softstack_frame): New.
(nvptx_declare_function_name): Handle TARGET_SOFT_STACK.
(nvptx_output_set_softstack): New.
(nvptx_output_return): Emit stack restore if needed.
(nvptx_get_drap_rtx): Return %argp as the DRAP if needed.
(nvptx_file_end): Handle need_softstack_decl.
* config/nvptx/nvptx.h: (TARGET_CPU_CPP_BUILTINS): Define
__nvptx_softstack__ when -msoft-stack is active.
(STACK_SIZE_MODE): Define.
(FIXED_REGISTERS): Adjust.
(SOFTSTACK_SLOT_REGNUM): New.
(SOFTSTACK_PREV_REGNUM): New.
(REGISTER_NAMES): Adjust.
(struct machine_function): New bool field has_softstack.
* config/nvptx/nvptx.md (UNSPEC_SET_SOFTSTACK): New.
(allocate_stack): Implement for TARGET_SOFT_STACK.  Remove unused code.
(allocate_stack_): Remove unused pattern.
(set_softstack_insn): New pattern.
(restore_stack_block): Handle for TARGET_SOFT_STACK.
* config/nvptx/nvptx.opt: (msoft-stack): New option.
* doc/invoke.texi (msoft-stack): Document.

gcc/testsuite/:
* gcc.target/nvptx/softstack.c: New test.
* lib/target-supports.exp (check_effective_target_alloca): Use a
compile test.

libgcc/:
* config/nvptx/crt0.c (__main) [__nvptx_softstack__]: Setup
__nvptx_stacks.
* config/nvptx/stacks.c: New file.
* config/nvptx/t-nvptx (LIB2ADD): Add stacks.c.


diff --git a/gcc/config/nvptx/nvptx-protos.h b/gcc/config/nvptx/nvptx-protos.h
index ec4588e..331ec0a 100644
--- a/gcc/config/nvptx/nvptx-protos.h
+++ b/gcc/config/nvptx/nvptx-protos.h
@@ -36,5 +36,6 @@ extern void nvptx_register_pragmas (void);
 extern const char *nvptx_output_mov_insn (rtx, rtx);
 extern const char *nvptx_output_call_insn (rtx_insn *, rtx, rtx);
 extern const char *nvptx_output_return (void);
+extern const char *nvptx_output_set_softstack (unsigned);
 #endif
 #endif
diff --git a/gcc/config/nvptx/nvptx.c b/gcc/config/nvptx/nvptx.c
index 2d4dad1..05cc6dd 100644
--- a/gcc/config/nvptx/nvptx.c
+++ b/gcc/config/nvptx/nvptx.c
@@ -139,6 +129,9 @@ static GTY(()) rtx worker_red_sym;
 /* Global lock variable, needed for 128bit worker & gang reductions.  */
 static GTY(()) tree global_lock_var;
 
+/* True if any function references __nvptx_stacks.  */
+static bool need_softstack_decl;
+
 /* Allocate a new, cleared machine_function structure.  */
 
 static struct machine_function *
@@ -931,6 +932,60 @@ init_frame (FILE  *file, int regno, unsigned align, 
unsigned size)
   POINTER_SIZE, reg_names[regno], reg_names[regno]);
 }
 
+/* Emit soft stack frame setup sequence.  */
+
+static void
+init_softstack_frame (FILE *file, unsigned alignment, unsigned size)
+{
+  /* Maintain 64-bit stack alignment.  */
+  int keep_align = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
+  size = ROUND_UP (size, keep_align);
+  int bits = POINTER_SIZE;
+  const char *reg_stack = reg_names[STACK_POINTER_REGNUM];
+  const char *reg_frame = reg_names[FRAME_POINTER_REGNUM];
+  const char *reg_sspslot = reg_names[SOFTSTACK_SLOT_REGNUM];
+  const char *reg_sspprev = reg_names[SOFTSTACK_PREV_REGNUM];
+  fprintf (file, 

[PATCH 11/16] Add hash-set-tests.c

2016-06-02 Thread David Malcolm
Jeff approved an earlier version of this (as
unittests/test-hash-set.c):
 https://gcc.gnu.org/ml/gcc-patches/2015-10/msg03300.html
> OK if/when prereqs are approved. Minor twiddling if we end up
> moving it elsewhere or standardizing/reducing header files is
> pre-approved.

This version moves the tests to gcc/hash-set-tests.c and updates
them to the new style.

gcc/ChangeLog:
* hash-set-tests.c: New file.
---
 gcc/hash-set-tests.c | 64 
 1 file changed, 64 insertions(+)
 create mode 100644 gcc/hash-set-tests.c

diff --git a/gcc/hash-set-tests.c b/gcc/hash-set-tests.c
new file mode 100644
index 000..cdca42a
--- /dev/null
+++ b/gcc/hash-set-tests.c
@@ -0,0 +1,64 @@
+/* Unit tests for hash-set.h.
+   Copyright (C) 2015-2016 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC 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.
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING3.  If not see
+.  */
+
+#include "config.h"
+#include "system.h"
+#include "coretypes.h"
+#include "tm.h"
+#include "opts.h"
+#include "signop.h"
+#include "hash-set.h"
+#include "selftest.h"
+
+#if CHECKING_P
+
+static void
+test_set_of_strings ()
+{
+  hash_set  s;
+  ASSERT_EQ (0, s.elements ());
+
+  const char *red = "red";
+  const char *green = "green";
+  const char *blue = "blue";
+
+  ASSERT_EQ (false, s.contains (red));
+
+  /* Populate the hash_set.  */
+  ASSERT_EQ (false, s.add (red));
+  ASSERT_EQ (false, s.add (green));
+  ASSERT_EQ (false, s.add (blue));
+
+  /* Verify that the values are now within the set.  */
+  ASSERT_EQ (true, s.contains (red));
+  ASSERT_EQ (true, s.contains (green));
+  ASSERT_EQ (true, s.contains (blue));
+}
+
+namespace selftest {
+
+void
+hash_set_tests_c_tests ()
+{
+  test_set_of_strings ();
+}
+
+} // namespace selftest
+
+#endif /* #if CHECKING_P */
-- 
1.8.5.3



[PATCH 06/16] et-forest.c: add selftests

2016-06-02 Thread David Malcolm
Jeff approved an earlier version of this:
https://gcc.gnu.org/ml/gcc-patches/2015-10/msg03295.html
> OK if/when prereqs are approved. Minor twiddling if we end up
> moving it elsewhere or standardizing/reducing header files
> is pre-approved.

This version has been updated to the new style.

gcc/ChangeLog:
* et-forest.c: Include "selftest.h".
(test_single_node): New function.
(test_simple_tree): New function.
(test_disconnected_nodes): New function.
(selftest::et_forest_c_tests): New function.
---
 gcc/et-forest.c | 112 
 1 file changed, 112 insertions(+)

diff --git a/gcc/et-forest.c b/gcc/et-forest.c
index cd36752..679abee 100644
--- a/gcc/et-forest.c
+++ b/gcc/et-forest.c
@@ -27,6 +27,7 @@ License along with libiberty; see the file COPYING3.  If not 
see
 #include "coretypes.h"
 #include "alloc-pool.h"
 #include "et-forest.h"
+#include "selftest.h"
 
 /* We do not enable this with CHECKING_P, since it is awfully slow.  */
 #undef DEBUG_ET
@@ -764,3 +765,114 @@ et_root (struct et_node *node)
 
   return r->of;
 }
+
+#if CHECKING_P
+
+/* Selftests for et-forest.c.  */
+
+static void
+test_single_node ()
+{
+  void *test_data = (void *)0xcafebabe;
+
+  et_node *n = et_new_tree (test_data);
+  ASSERT_EQ (n->data, test_data);
+  ASSERT_EQ (n, et_root (n));
+  et_free_tree (n);
+}
+
+/* Test of this tree:
+   a
+  / \
+ /   \
+b c
+   / \|
+  d   e   f.  */
+
+static void
+test_simple_tree ()
+{
+  et_node *a = et_new_tree (NULL);
+  et_node *b = et_new_tree (NULL);
+  et_node *c = et_new_tree (NULL);
+  et_node *d = et_new_tree (NULL);
+  et_node *e = et_new_tree (NULL);
+  et_node *f = et_new_tree (NULL);
+
+  et_set_father (b, a);
+  et_set_father (c, a);
+  et_set_father (d, b);
+  et_set_father (e, b);
+  et_set_father (f, c);
+
+  ASSERT_TRUE (et_below (a, a));
+  ASSERT_TRUE (et_below (b, a));
+  ASSERT_TRUE (et_below (c, a));
+  ASSERT_TRUE (et_below (d, a));
+  ASSERT_TRUE (et_below (e, a));
+  ASSERT_TRUE (et_below (f, a));
+
+  ASSERT_FALSE (et_below (a, b));
+  ASSERT_TRUE (et_below (b, b));
+  ASSERT_FALSE (et_below (c, b));
+  ASSERT_TRUE (et_below (d, b));
+  ASSERT_TRUE (et_below (e, b));
+  ASSERT_FALSE (et_below (f, b));
+
+  ASSERT_FALSE (et_below (a, c));
+  ASSERT_FALSE (et_below (b, c));
+  ASSERT_TRUE (et_below (c, c));
+  ASSERT_FALSE (et_below (d, c));
+  ASSERT_FALSE (et_below (e, c));
+  ASSERT_TRUE (et_below (f, c));
+
+  ASSERT_FALSE (et_below (a, d));
+  ASSERT_FALSE (et_below (b, d));
+  ASSERT_FALSE (et_below (c, d));
+  ASSERT_TRUE (et_below (d, d));
+  ASSERT_FALSE (et_below (e, d));
+  ASSERT_FALSE (et_below (f, d));
+
+  ASSERT_FALSE (et_below (a, e));
+  ASSERT_FALSE (et_below (b, e));
+  ASSERT_FALSE (et_below (c, e));
+  ASSERT_FALSE (et_below (d, e));
+  ASSERT_TRUE (et_below (e, e));
+  ASSERT_FALSE (et_below (f, e));
+
+  ASSERT_FALSE (et_below (a, f));
+  ASSERT_FALSE (et_below (b, f));
+  ASSERT_FALSE (et_below (c, f));
+  ASSERT_FALSE (et_below (d, f));
+  ASSERT_FALSE (et_below (e, f));
+  ASSERT_TRUE (et_below (f, f));
+
+  et_free_tree_force (a);
+}
+
+static void
+test_disconnected_nodes ()
+{
+  et_node *a = et_new_tree (NULL);
+  et_node *b = et_new_tree (NULL);
+
+  ASSERT_FALSE (et_below (a, b));
+  ASSERT_FALSE (et_below (b, a));
+
+  et_free_tree (a);
+  et_free_tree (b);
+}
+
+namespace selftest {
+
+void
+et_forest_c_tests ()
+{
+  test_single_node ();
+  test_simple_tree ();
+  test_disconnected_nodes ();
+}
+
+} // namespace selftest
+
+#endif /* CHECKING_P */
-- 
1.8.5.3



[PATCH 07/16] fold-const.c: add selftests

2016-06-02 Thread David Malcolm
Jeff approved an older version of this (as a separate
unittests/test-folding.c):
https://gcc.gnu.org/ml/gcc-patches/2015-10/msg03305.html
> OK if/when prereqs are approved. Minor twiddling if we end up
> moving it elsewhere or standardizing/reducing header files
> is pre-approved.

gcc/ChangeLog:
* fold-const.c: Include "selftest.h".
(assert_binop_folds_to_const): New function.
(assert_binop_folds_to_nonlvalue): New function.
(test_arithmetic_folding): New function.
(selftest::fold_const_c_tests): New function.
---
 gcc/fold-const.c | 75 
 1 file changed, 75 insertions(+)

diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index 8a7c93e..dd8cdab 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -76,6 +76,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "case-cfn-macros.h"
 #include "stringpool.h"
 #include "tree-ssanames.h"
+#include "selftest.h"
 
 #ifndef LOAD_EXTEND_OP
 #define LOAD_EXTEND_OP(M) UNKNOWN
@@ -14455,3 +14456,77 @@ c_getstr (tree src)
 
   return TREE_STRING_POINTER (src) + tree_to_uhwi (offset_node);
 }
+
+#if CHECKING_P
+
+/* Helper functions for writing tests of folding trees.  */
+
+/* Verify that the binary op (LHS CODE RHS) folds to CONSTANT.  */
+
+static void
+assert_binop_folds_to_const (tree lhs, enum tree_code code, tree rhs,
+tree constant)
+{
+  ASSERT_EQ (constant, fold_build2 (code, TREE_TYPE (lhs), lhs, rhs));
+}
+
+/* Verify that the binary op (LHS CODE RHS) folds to an NON_LVALUE_EXPR
+   wrapping WRAPPED_EXPR.  */
+
+static void
+assert_binop_folds_to_nonlvalue (tree lhs, enum tree_code code, tree rhs,
+tree wrapped_expr)
+{
+  tree result = fold_build2 (code, TREE_TYPE (lhs), lhs, rhs);
+  ASSERT_NE (wrapped_expr, result);
+  ASSERT_EQ (NON_LVALUE_EXPR, TREE_CODE (result));
+  ASSERT_EQ (wrapped_expr, TREE_OPERAND (result, 0));
+}
+
+static void
+test_arithmetic_folding ()
+{
+  tree type = integer_type_node;
+  tree x = create_tmp_var_raw (type, "x");
+  tree zero = build_zero_cst (type);
+  tree one = build_int_cst (type, 1);
+
+  /* Addition.  */
+  /* 1 <-- (0 + 1) */
+  assert_binop_folds_to_const (zero, PLUS_EXPR, one,
+  one);
+  assert_binop_folds_to_const (one, PLUS_EXPR, zero,
+  one);
+
+  /* (nonlvalue)x <-- (x + 0) */
+  assert_binop_folds_to_nonlvalue (x, PLUS_EXPR, zero,
+  x);
+
+  /* Subtraction.  */
+  /* 0 <-- (x - x) */
+  assert_binop_folds_to_const (x, MINUS_EXPR, x,
+  zero);
+  assert_binop_folds_to_nonlvalue (x, MINUS_EXPR, zero,
+  x);
+
+  /* Multiplication.  */
+  /* 0 <-- (x * 0) */
+  assert_binop_folds_to_const (x, MULT_EXPR, zero,
+  zero);
+
+  /* (nonlvalue)x <-- (x * 1) */
+  assert_binop_folds_to_nonlvalue (x, MULT_EXPR, one,
+  x);
+}
+
+namespace selftest {
+
+void
+fold_const_c_tests ()
+{
+  test_arithmetic_folding ();
+}
+
+} // namespace selftest
+
+#endif /* CHECKING_P */
-- 
1.8.5.3



[PATCH 15/16] vec.c: add selftests

2016-06-02 Thread David Malcolm
Jeff approved an earlier version of this (as
unittests/test-vec.c):
https://gcc.gnu.org/ml/gcc-patches/2015-10/msg03308.html
> OK if/when prereqs are approved. Minor twiddling if we end up
> moving it elsewhere or standardizing/reducing header files is
> pre-approved.

gcc/ChangeLog:
* vec.c: Include "selftest.h".
(safe_push_range): New function.
(test_quick_push): New function.
(test_safe_push): New function.
(test_truncate): New function.
(test_safe_grow_cleared): New function.
(test_safe_pop): New function.
(test_safe_insert): New function.
(test_ordered_remove): New function.
(test_unordered_remove): New function.
(test_block_remove): New function.
(reverse_cmp): New function.
(test_qsort): New function.
(selftest::vec_c_tests): New function.c.
---
 gcc/vec.c | 162 ++
 1 file changed, 162 insertions(+)

diff --git a/gcc/vec.c b/gcc/vec.c
index a483d5b..b64a012 100644
--- a/gcc/vec.c
+++ b/gcc/vec.c
@@ -30,6 +30,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "system.h"
 #include "coretypes.h"
 #include "hash-table.h"
+#include "selftest.h"
 
 /* vNULL is an empty type with a template cast operation that returns
a zero-initialized vec instance.  Use this when you want
@@ -188,3 +189,164 @@ dump_vec_loc_statistics (void)
 {
   vec_mem_desc.dump (VEC_ORIGIN);
 }
+
+#ifndef GENERATOR_FILE
+#if CHECKING_P
+
+static void
+safe_push_range (vec , int start, int limit)
+{
+  for (int i = start; i < limit; i++)
+v.safe_push (i);
+}
+
+static void
+test_quick_push ()
+{
+  auto_vec  v;
+  ASSERT_EQ (0, v.length ());
+  v.reserve (3);
+  ASSERT_EQ (0, v.length ());
+  ASSERT_TRUE (v.space (3));
+  v.quick_push (5);
+  v.quick_push (6);
+  v.quick_push (7);
+  ASSERT_EQ (3, v.length ());
+  ASSERT_EQ (5, v[0]);
+  ASSERT_EQ (6, v[1]);
+  ASSERT_EQ (7, v[2]);
+}
+
+static void
+test_safe_push ()
+{
+  auto_vec  v;
+  ASSERT_EQ (0, v.length ());
+  v.safe_push (5);
+  v.safe_push (6);
+  v.safe_push (7);
+  ASSERT_EQ (3, v.length ());
+  ASSERT_EQ (5, v[0]);
+  ASSERT_EQ (6, v[1]);
+  ASSERT_EQ (7, v[2]);
+}
+
+static void
+test_truncate ()
+{
+  auto_vec  v;
+  ASSERT_EQ (0, v.length ());
+  safe_push_range (v, 0, 10);
+  ASSERT_EQ (10, v.length ());
+
+  v.truncate (5);
+  ASSERT_EQ (5, v.length ());
+}
+
+static void
+test_safe_grow_cleared ()
+{
+  auto_vec  v;
+  ASSERT_EQ (0, v.length ());
+  v.safe_grow_cleared (50);
+  ASSERT_EQ (50, v.length ());
+  ASSERT_EQ (0, v[0]);
+  ASSERT_EQ (0, v[49]);
+}
+
+static void
+test_safe_pop ()
+{
+  auto_vec  v;
+  safe_push_range (v, 5, 20);
+  ASSERT_EQ (15, v.length ());
+
+  int last = v.pop ();
+  ASSERT_EQ (19, last);
+  ASSERT_EQ (14, v.length ());
+}
+
+static void
+test_safe_insert ()
+{
+  auto_vec  v;
+  safe_push_range (v, 0, 10);
+  v.safe_insert (5, 42);
+  ASSERT_EQ (4, v[4]);
+  ASSERT_EQ (42, v[5]);
+  ASSERT_EQ (5, v[6]);
+  ASSERT_EQ (11, v.length ());
+}
+
+static void
+test_ordered_remove ()
+{
+  auto_vec  v;
+  safe_push_range (v, 0, 10);
+  v.ordered_remove (5);
+  ASSERT_EQ (4, v[4]);
+  ASSERT_EQ (6, v[5]);
+  ASSERT_EQ (9, v.length ());
+}
+
+static void
+test_unordered_remove ()
+{
+  auto_vec  v;
+  safe_push_range (v, 0, 10);
+  v.unordered_remove (5);
+  ASSERT_EQ (9, v.length ());
+}
+
+static void
+test_block_remove ()
+{
+  auto_vec  v;
+  safe_push_range (v, 0, 10);
+  v.block_remove (5, 3);
+  ASSERT_EQ (3, v[3]);
+  ASSERT_EQ (4, v[4]);
+  ASSERT_EQ (8, v[5]);
+  ASSERT_EQ (9, v[6]);
+  ASSERT_EQ (7, v.length ());
+}
+
+static int reverse_cmp (const void *p_i, const void *p_j)
+{
+  return *(const int *)p_j - *(const int *)p_i;
+}
+
+static void
+test_qsort ()
+{
+  auto_vec  v;
+  safe_push_range (v, 0, 10);
+  v.qsort (reverse_cmp);
+  ASSERT_EQ (9, v[0]);
+  ASSERT_EQ (8, v[1]);
+  ASSERT_EQ (1, v[8]);
+  ASSERT_EQ (0, v[9]);
+  ASSERT_EQ (10, v.length ());
+}
+
+namespace selftest {
+
+void
+vec_c_tests ()
+{
+  test_quick_push ();
+  test_safe_push ();
+  test_truncate ();
+  test_safe_grow_cleared ();
+  test_safe_pop ();
+  test_safe_insert ();
+  test_ordered_remove ();
+  test_unordered_remove ();
+  test_block_remove ();
+  test_qsort ();
+}
+
+} // namespace selftest
+
+#endif /* #if CHECKING_P */
+#endif /* #ifndef GENERATOR_FILE */
-- 
1.8.5.3



[PATCH 13/16] Add rtl-tests.c

2016-06-02 Thread David Malcolm
Jeff approved an earlier version of this (as
unittests/test-rtl.c):
https://gcc.gnu.org/ml/gcc-patches/2015-10/msg03302.html
> OK if/when prereqs are approved. Minor twiddling if we end up
> moving it elsewhere or standardizing/reducing header files is
>pre-approved.

gcc/ChangeLog:
* rtl-tests.c: New file.
---
 gcc/rtl-tests.c | 108 
 1 file changed, 108 insertions(+)
 create mode 100644 gcc/rtl-tests.c

diff --git a/gcc/rtl-tests.c b/gcc/rtl-tests.c
new file mode 100644
index 000..a4ba79d
--- /dev/null
+++ b/gcc/rtl-tests.c
@@ -0,0 +1,108 @@
+/* Unit tests for RTL-handling.
+   Copyright (C) 2015-2016 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC 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.
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING3.  If not see
+.  */
+
+#include "config.h"
+#include "system.h"
+#include "coretypes.h"
+#include "tm.h"
+#include "opts.h"
+#include "signop.h"
+#include "hash-set.h"
+#include "fixed-value.h"
+#include "alias.h"
+#include "flags.h"
+#include "symtab.h"
+#include "tree-core.h"
+#include "stor-layout.h"
+#include "tree.h"
+#include "stringpool.h"
+#include "stor-layout.h"
+#include "rtl.h"
+#include "pretty-print.h"
+#include "cfgbuild.h"
+#include "print-rtl.h"
+#include "selftest.h"
+#include "function.h"
+#include "emit-rtl.h"
+
+#if CHECKING_P
+
+static void
+verify_print_pattern (const char *expected, rtx pat)
+{
+  pretty_printer pp;
+  print_pattern (, pat, 1);
+  ASSERT_STREQ (expected, pp_formatted_text ());
+}
+
+/* Unit testing of "single_set".  */
+static void
+test_single_set ()
+{
+  /* A label is not a SET.  */
+  ASSERT_EQ (NULL_RTX, single_set (gen_label_rtx ()));
+
+  /* An unconditional jump insn is a single SET.  */
+  rtx set_pc = gen_rtx_SET (pc_rtx,
+   gen_rtx_LABEL_REF (VOIDmode,
+  gen_label_rtx ()));
+  rtx_insn *jump_insn = emit_jump_insn (set_pc);
+  ASSERT_EQ (set_pc, single_set (jump_insn));
+
+  /* etc */
+}
+
+static void
+test_uncond_jump ()
+{
+  rtx_insn *label = gen_label_rtx ();
+  rtx jump_pat = gen_rtx_SET (pc_rtx,
+ gen_rtx_LABEL_REF (VOIDmode,
+label));
+  ASSERT_EQ (SET, jump_pat->code);
+  ASSERT_EQ (LABEL_REF, SET_SRC (jump_pat)->code);
+  ASSERT_EQ (label, LABEL_REF_LABEL (SET_SRC (jump_pat)));
+  ASSERT_EQ (PC, SET_DEST (jump_pat)->code);
+
+  verify_print_pattern ("pc=L0", jump_pat);
+
+  rtx_insn *jump_insn = emit_jump_insn (jump_pat);
+  ASSERT_FALSE (any_condjump_p (jump_insn));
+  ASSERT_TRUE (any_uncondjump_p (jump_insn));
+  ASSERT_TRUE (pc_set (jump_insn));
+  ASSERT_TRUE (simplejump_p (jump_insn));
+  ASSERT_TRUE (onlyjump_p (jump_insn));
+  ASSERT_TRUE (control_flow_insn_p (jump_insn));
+}
+
+namespace selftest {
+
+void
+rtl_tests_c_tests ()
+{
+  test_single_set ();
+  test_uncond_jump ();
+
+  /* Purge state.  */
+  set_first_insn (NULL);
+  set_last_insn (NULL);
+}
+
+} // namespace selftest
+#endif /* #if CHECKING_P */
-- 
1.8.5.3



[PATCH 16/16] wide-int.cc: add selftests

2016-06-02 Thread David Malcolm
Jeff approved an early version of this:
https://gcc.gnu.org/ml/gcc-patches/2015-10/msg03309.html
> OK if/when prereqs are approved. Minor twiddling if we end up
> moving it elsewhere or standardizing/reducing header files is
> pre-approved.

This version moves it to wide-int.cc and converts it to the new
style.  It's the only example so far of a type-parametrized test.

gcc/ChangeLog:
* selftest-run-tests.c (selftest::run_tests): Add call
to wide_int_cc_tests.
* selftest.h (wide_int_cc_tests): New declaration.
* wide-int.cc: Include selftest.h and wide-int-print.h.
(from_int ): New function.
(from_int ): New function.
(from_int ): New function.
(assert_deceq): New function.
(assert_hexeq): New function.
(test_printing ): New function template.
(test_ops ): New function template.
(test_comparisons ): New function template.
(run_all_wide_int_tests ): New function template.
(selftest::wide_int_cc_tests): New function.
---
 gcc/selftest-run-tests.c |   1 +
 gcc/selftest.h   |   1 +
 gcc/wide-int.cc  | 152 +++
 3 files changed, 154 insertions(+)

diff --git a/gcc/selftest-run-tests.c b/gcc/selftest-run-tests.c
index 4233351..ab334aa 100644
--- a/gcc/selftest-run-tests.c
+++ b/gcc/selftest-run-tests.c
@@ -46,6 +46,7 @@ selftest::run_tests ()
   hash_map_tests_c_tests ();
   hash_set_tests_c_tests ();
   vec_c_tests ();
+  wide_int_cc_tests ();
 
   /* Mid-level data structures.  */
   input_c_tests ();
diff --git a/gcc/selftest.h b/gcc/selftest.h
index 2062a8b..a1d3074 100644
--- a/gcc/selftest.h
+++ b/gcc/selftest.h
@@ -55,6 +55,7 @@ extern void spellcheck_c_tests ();
 extern void tree_c_tests ();
 extern void tree_cfg_c_tests ();
 extern void vec_c_tests ();
+extern void wide_int_cc_tests ();
 
 extern int num_passes;
 
diff --git a/gcc/wide-int.cc b/gcc/wide-int.cc
index 8648e7d..634dfb8 100644
--- a/gcc/wide-int.cc
+++ b/gcc/wide-int.cc
@@ -23,6 +23,8 @@ along with GCC; see the file COPYING3.  If not see
 #include "coretypes.h"
 #include "tm.h"
 #include "tree.h"
+#include "selftest.h"
+#include "wide-int-print.h"
 
 
 #define HOST_BITS_PER_HALF_WIDE_INT 32
@@ -2144,3 +2146,153 @@ template void generic_wide_int  >::dump () const;
 template void generic_wide_int  >::dump () const;
 template void offset_int::dump () const;
 template void widest_int::dump () const;
+
+
+#if CHECKING_P
+
+/* Selftests for wide ints.  We run these multiple times, once per type.  */
+
+/* Helper function for building a test value.  */
+
+template 
+static VALUE_TYPE
+from_int (int i);
+
+/* Specializations of the fixture for each wide-int type.  */
+
+template <>
+wide_int
+from_int (int i)
+{
+  return wi::shwi (i, 32);
+}
+
+template <>
+offset_int
+from_int (int i)
+{
+  return offset_int (i);
+}
+
+template <>
+widest_int
+from_int (int i)
+{
+  return widest_int (i);
+}
+
+/* Verify that print_dec (WI, ..., SGN) gives the expected string
+   representation (using base 10).  */
+
+static void
+assert_deceq (const char *expected, const wide_int_ref , signop sgn)
+{
+  char buf[WIDE_INT_PRINT_BUFFER_SIZE];
+  print_dec (wi, buf, sgn);
+  ASSERT_STREQ (expected, buf);
+}
+
+/* Likewise for base 16.  */
+
+static void
+assert_hexeq (const char *expected, const wide_int_ref )
+{
+  char buf[WIDE_INT_PRINT_BUFFER_SIZE];
+  print_hex (wi, buf);
+  ASSERT_STREQ (expected, buf);
+}
+
+/* Test cases.  */
+
+template 
+static void
+test_printing ()
+{
+  VALUE_TYPE a = from_int (42);
+  assert_deceq ("42", a, SIGNED);
+  assert_hexeq ("0x2a", a);
+}
+
+template 
+static void
+test_ops ()
+{
+  VALUE_TYPE a = from_int (7);
+  VALUE_TYPE b = from_int (3);
+
+  /* Using functions.  */
+  assert_deceq ("-7", wi::neg (a), SIGNED);
+  assert_deceq ("10", wi::add (a, b), SIGNED);
+  assert_deceq ("4", wi::sub (a, b), SIGNED);
+  assert_deceq ("-4", wi::sub (b, a), SIGNED);
+  assert_deceq ("21", wi::mul (a, b), SIGNED);
+
+  /* Using operators.  */
+  assert_deceq ("-7", -a, SIGNED);
+  assert_deceq ("10", a + b, SIGNED);
+  assert_deceq ("4", a - b, SIGNED);
+  assert_deceq ("-4", b - a, SIGNED);
+  assert_deceq ("21", a * b, SIGNED);
+}
+
+template 
+static void
+test_comparisons ()
+{
+  VALUE_TYPE a = from_int (7);
+  VALUE_TYPE b = from_int (3);
+
+  /* == */
+  ASSERT_TRUE (wi::eq_p (a, a));
+  ASSERT_FALSE (wi::eq_p (a, b));
+
+  /* != */
+  ASSERT_TRUE (wi::ne_p (a, b));
+  ASSERT_FALSE (wi::ne_p (a, a));
+
+  /* < */
+  ASSERT_FALSE (wi::lts_p (a, a));
+  ASSERT_FALSE (wi::lts_p (a, b));
+  ASSERT_TRUE (wi::lts_p (b, a));
+
+  /* <= */
+  ASSERT_TRUE (wi::les_p (a, a));
+  ASSERT_FALSE (wi::les_p (a, b));
+  ASSERT_TRUE (wi::les_p (b, a));
+
+  /* > */
+  ASSERT_FALSE (wi::gts_p (a, a));
+  ASSERT_TRUE (wi::gts_p (a, b));
+  ASSERT_FALSE (wi::gts_p (b, a));
+
+  /* >= */
+  ASSERT_TRUE (wi::ges_p (a, a));
+  ASSERT_TRUE (wi::ges_p (a, b));
+  ASSERT_FALSE (wi::ges_p 

[PATCH 12/16] input.c: add selftests

2016-06-02 Thread David Malcolm
Jeff conditionally approved an earlier version of this (as
unittests/test-locations.c):
https://gcc.gnu.org/ml/gcc-patches/2015-10/msg03307.html
> OK if/when prereqs are approved. Minor twiddling if we end up
> moving it elsewhere or standardizing/reducing header files is
> pre-approved.

gcc/ChangeLog:
* input.c: Include "selftest.h".
(assert_loceq): New function.
(test_accessing_ordinary_linemaps): New function.
(test_unknown_location): New function.
(test_builtins): New function.
(test_reading_source_line): New function.
(selftest::input_c_tests): New function.
---
 gcc/input.c | 112 
 1 file changed, 112 insertions(+)

diff --git a/gcc/input.c b/gcc/input.c
index 61b1e44..b15b595 100644
--- a/gcc/input.c
+++ b/gcc/input.c
@@ -22,6 +22,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "coretypes.h"
 #include "intl.h"
 #include "diagnostic-core.h"
+#include "selftest.h"
 
 /* This is a cache used by get_next_line to store the content of a
file to be searched for file lines.  */
@@ -1136,3 +1137,114 @@ dump_location_info (FILE *stream)
   dump_labelled_location_range (stream, "AD-HOC LOCATIONS",
MAX_SOURCE_LOCATION + 1, UINT_MAX);
 }
+
+#if CHECKING_P
+
+/* Selftests of location handling.  */
+
+/* Verify the result of LOCATION_FILE/LOCATION_LINE/LOCATION_COLUMN
+   on LOC.  */
+
+static void
+assert_loceq (const char *exp_filename,
+ int exp_linenum,
+ int exp_colnum,
+ location_t loc)
+{
+  ASSERT_STREQ (exp_filename, LOCATION_FILE (loc));
+  ASSERT_EQ (exp_linenum, LOCATION_LINE (loc));
+  ASSERT_EQ (exp_colnum, LOCATION_COLUMN (loc));
+}
+
+/* Verify basic operation of ordinary linemaps.  */
+
+static void
+test_accessing_ordinary_linemaps ()
+{
+  /* Build a simple linemap describing some locations. */
+  linemap_add (line_table, LC_ENTER, false, "foo.c", 0);
+
+  linemap_line_start (line_table, 1, 100);
+  location_t loc_a = linemap_position_for_column (line_table, 1);
+  location_t loc_b = linemap_position_for_column (line_table, 23);
+
+  linemap_line_start (line_table, 2, 100);
+  location_t loc_c = linemap_position_for_column (line_table, 1);
+  location_t loc_d = linemap_position_for_column (line_table, 17);
+
+  /* Example of a very long line.  */
+  linemap_line_start (line_table, 3, 2000);
+  location_t loc_e = linemap_position_for_column (line_table, 700);
+
+  linemap_add (line_table, LC_LEAVE, false, NULL, 0);
+
+  /* Multiple files.  */
+  linemap_add (line_table, LC_ENTER, false, "bar.c", 0);
+  linemap_line_start (line_table, 1, 200);
+  location_t loc_f = linemap_position_for_column (line_table, 150);
+  linemap_add (line_table, LC_LEAVE, false, NULL, 0);
+
+  /* Verify that we can recover the location info.  */
+  assert_loceq ("foo.c", 1, 1, loc_a);
+  assert_loceq ("foo.c", 1, 23, loc_b);
+  assert_loceq ("foo.c", 2, 1, loc_c);
+  assert_loceq ("foo.c", 2, 17, loc_d);
+  assert_loceq ("foo.c", 3, 700, loc_e);
+  assert_loceq ("bar.c", 1, 150, loc_f);
+
+  ASSERT_FALSE (is_location_from_builtin_token (loc_a));
+}
+
+static void
+test_unknown_location ()
+{
+  ASSERT_EQ (NULL, LOCATION_FILE (UNKNOWN_LOCATION));
+  ASSERT_EQ (0, LOCATION_LINE (UNKNOWN_LOCATION));
+  ASSERT_EQ (0, LOCATION_COLUMN (UNKNOWN_LOCATION));
+}
+
+static void
+test_builtins ()
+{
+  assert_loceq ("", 0, 0, BUILTINS_LOCATION);
+  ASSERT_PRED1 (is_location_from_builtin_token, BUILTINS_LOCATION);
+}
+
+/* Verify reading of input files (e.g. for caret-based diagnostics.  */
+
+static void
+test_reading_source_line ()
+{
+  /* We will read *this* source file, using __FILE__.
+ Here is some specific text to read and test for:
+ The quick brown fox jumps over the lazy dog.  */
+  const int linenum_after_test_message = __LINE__;
+  const int linenum = linenum_after_test_message - 1;
+
+  int line_size;
+  const char *source_line = location_get_source_line (__FILE__, linenum, 
_size);
+  ASSERT_TRUE (source_line != NULL);
+  ASSERT_EQ (53, line_size);
+  if (!strncmp (" The quick brown fox jumps over the lazy dog.  */",
+  source_line, line_size))
+::selftest::pass (__FILE__, __LINE__,
+ "source_line matched expected value");
+  else
+::selftest::fail (__FILE__, __LINE__,
+ "source_line did not match expected value");
+}
+
+namespace selftest {
+
+void
+input_c_tests ()
+{
+  test_accessing_ordinary_linemaps ();
+  test_unknown_location ();
+  test_builtins ();
+  test_reading_source_line ();
+}
+
+} // namespace selftest
+
+#endif /* CHECKING_P */
-- 
1.8.5.3



tuple code simplification patch

2016-06-02 Thread François Dumont

Hi

I was trying to play with tuple implementation and was annoyed by 
repetition of _Head type when instantiating _Head_base so I thought 
about this patch.


How do you like it ?

I still need to run tests, will do before commit, ok ?

François
Index: include/std/tuple
===
--- include/std/tuple	(revision 237045)
+++ include/std/tuple	(working copy)
@@ -48,7 +48,24 @@
*  @{
*/
 
-  template
+  template
+class tuple;
+
+  template
+struct __is_empty_non_tuple : is_empty<_Tp> { };
+
+  // Using EBO for elements that are tuples causes ambiguous base errors.
+  template
+struct __is_empty_non_tuple> : false_type { };
+
+  // Use the Empty Base-class Optimization for empty, non-final types.
+  template
+using __empty_not_final
+= typename conditional<__is_final(_Tp), false_type,
+			   __is_empty_non_tuple<_Tp>>::type;
+
+  template::value>
 struct _Head_base;
 
   template
@@ -158,19 +175,6 @@
   template
 struct _Tuple_impl; 
 
-  template
-struct __is_empty_non_tuple : is_empty<_Tp> { };
-
-  // Using EBO for elements that are tuples causes ambiguous base errors.
-  template
-struct __is_empty_non_tuple> : false_type { };
-
-  // Use the Empty Base-class Optimization for empty, non-final types.
-  template
-using __empty_not_final
-= typename conditional<__is_final(_Tp), false_type,
-			   __is_empty_non_tuple<_Tp>>::type;
-
   /**
* Recursive tuple implementation. Here we store the @c Head element
* and derive from a @c Tuple_impl containing the remaining elements
@@ -179,12 +183,12 @@
   template
 struct _Tuple_impl<_Idx, _Head, _Tail...>
 : public _Tuple_impl<_Idx + 1, _Tail...>,
-  private _Head_base<_Idx, _Head, __empty_not_final<_Head>::value>
+  private _Head_base<_Idx, _Head>
 {
   template friend class _Tuple_impl;
 
   typedef _Tuple_impl<_Idx + 1, _Tail...> _Inherited;
-  typedef _Head_base<_Idx, _Head, __empty_not_final<_Head>::value> _Base;
+  typedef _Head_base<_Idx, _Head> _Base;
 
   static constexpr _Head&  
   _M_head(_Tuple_impl& __t) noexcept { return _Base::_M_head(__t); }
@@ -336,11 +340,11 @@
   // Basis case of inheritance recursion.
   template
 struct _Tuple_impl<_Idx, _Head>
-: private _Head_base<_Idx, _Head, __empty_not_final<_Head>::value>
+: private _Head_base<_Idx, _Head>
 {
   template friend class _Tuple_impl;
 
-  typedef _Head_base<_Idx, _Head, __empty_not_final<_Head>::value> _Base;
+  typedef _Head_base<_Idx, _Head> _Base;
 
   static constexpr _Head&
   _M_head(_Tuple_impl& __t) noexcept { return _Base::_M_head(__t); }
@@ -457,9 +461,6 @@
   }
 };
 
-  template
-class tuple;
-
   // Concept utility functions, reused in conditionally-explicit
   // constructors.
   template


[PATCH 14/16] tree.c: add selftests

2016-06-02 Thread David Malcolm
Jeff approved an earlier version of this (as
unittests/test-tree.c):
https://gcc.gnu.org/ml/gcc-patches/2015-10/msg03303.html
> OK if/when prereqs are approved. Minor twiddling if we end up
> moving it elsewhere or standardizing/reducing header files is
> pre-approved.

gcc/ChangeLog:
* tree.c: Include "selftest.h".
(test_integer_constants): New function.
(test_identifiers): New function.
(test_labels): New function.
(selftest::tree_c_tests): New function.
---
 gcc/tree.c | 60 
 1 file changed, 60 insertions(+)

diff --git a/gcc/tree.c b/gcc/tree.c
index 5a1d167..ba22525 100644
--- a/gcc/tree.c
+++ b/gcc/tree.c
@@ -61,6 +61,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "builtins.h"
 #include "print-tree.h"
 #include "ipa-utils.h"
+#include "selftest.h"
 
 /* Tree code classes.  */
 
@@ -14179,4 +14180,63 @@ combined_fn_name (combined_fn fn)
 return internal_fn_name (as_internal_fn (fn));
 }
 
+#if CHECKING_P
+
+/* Selftests for tree.  */
+
+/* Verify that integer constants are sane.  */
+
+static void
+test_integer_constants ()
+{
+  ASSERT_TRUE (integer_type_node != NULL);
+  ASSERT_TRUE (build_int_cst (integer_type_node, 0) != NULL);
+
+  tree type = integer_type_node;
+
+  tree zero = build_zero_cst (type);
+  ASSERT_EQ (INTEGER_CST, TREE_CODE (zero));
+  ASSERT_EQ (type, TREE_TYPE (zero));
+
+  tree one = build_int_cst (type, 1);
+  ASSERT_EQ (INTEGER_CST, TREE_CODE (one));
+  ASSERT_EQ (type, TREE_TYPE (zero));
+}
+
+/* Verify identifiers.  */
+
+static void
+test_identifiers ()
+{
+  tree identifier = get_identifier ("foo");
+  ASSERT_EQ (3, IDENTIFIER_LENGTH (identifier));
+  ASSERT_STREQ ("foo", IDENTIFIER_POINTER (identifier));
+}
+
+/* Verify LABEL_DECL.  */
+
+static void
+test_labels ()
+{
+  tree identifier = get_identifier ("err");
+  tree label_decl = build_decl (UNKNOWN_LOCATION, LABEL_DECL,
+   identifier, void_type_node);
+  ASSERT_EQ (-1, LABEL_DECL_UID (label_decl));
+  ASSERT_FALSE (FORCED_LABEL (label_decl));
+}
+
+namespace selftest {
+
+void
+tree_c_tests ()
+{
+  test_integer_constants ();
+  test_identifiers ();
+  test_labels ();
+}
+
+} // namespace selftest
+
+#endif /* CHECKING_P */
+
 #include "gt-tree.h"
-- 
1.8.5.3



[PATCH 08/16] Add function-tests.c

2016-06-02 Thread David Malcolm
Jeff approved an earlier version of this (as
unittests/test-functions.c):
  https://gcc.gnu.org/ml/gcc-patches/2015-10/msg03310.html
with:

> OK if/when prereqs are approved. Minor twiddling if we end up moving
> it elsewhere or standardizing/reducing header files is pre-approved.

gcc/ChangeLog:
* function-tests.c: New file.
---
 gcc/function-tests.c | 639 +++
 1 file changed, 639 insertions(+)
 create mode 100644 gcc/function-tests.c

diff --git a/gcc/function-tests.c b/gcc/function-tests.c
new file mode 100644
index 000..71e19e9
--- /dev/null
+++ b/gcc/function-tests.c
@@ -0,0 +1,639 @@
+/* Unit tests for function-handling.
+   Copyright (C) 2015-2016 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC 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.
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING3.  If not see
+.  */
+
+#include "config.h"
+#include "system.h"
+#include "coretypes.h"
+#include "tm.h"
+#include "opts.h"
+#include "signop.h"
+#include "hash-set.h"
+#include "fixed-value.h"
+#include "alias.h"
+#include "flags.h"
+#include "symtab.h"
+#include "tree-core.h"
+#include "stor-layout.h"
+#include "tree.h"
+#include "stringpool.h"
+#include "stor-layout.h"
+#include "rtl.h"
+#include "predict.h"
+#include "vec.h"
+#include "hashtab.h"
+#include "hash-set.h"
+#include "machmode.h"
+#include "hard-reg-set.h"
+#include "input.h"
+#include "function.h"
+#include "dominance.h"
+#include "cfg.h"
+#include "cfganal.h"
+#include "basic-block.h"
+#include "tree-ssa-alias.h"
+#include "internal-fn.h"
+#include "gimple-fold.h"
+#include "gimple-expr.h"
+#include "toplev.h"
+#include "print-tree.h"
+#include "tree-iterator.h"
+#include "gimplify.h"
+#include "tree-cfg.h"
+#include "basic-block.h"
+#include "double-int.h"
+#include "alias.h"
+#include "symtab.h"
+#include "wide-int.h"
+#include "inchash.h"
+#include "tree.h"
+#include "fold-const.h"
+#include "stor-layout.h"
+#include "stmt.h"
+#include "hash-table.h"
+#include "tree-ssa-alias.h"
+#include "internal-fn.h"
+#include "gimple-expr.h"
+#include "is-a.h"
+#include "gimple.h"
+#include "tree-pass.h"
+#include "context.h"
+#include "hash-map.h"
+#include "plugin-api.h"
+#include "ipa-ref.h"
+#include "cgraph.h"
+#include "selftest.h"
+
+#if CHECKING_P
+
+/* Helper function for selftests of function-creation.  */
+
+static tree
+make_fndecl (tree return_type,
+const char *name,
+vec  _types,
+bool is_variadic = false)
+{
+  tree fn_type;
+  if (is_variadic)
+fn_type = build_varargs_function_type_array (return_type,
+param_types.length (),
+param_types.address ());
+  else
+fn_type = build_function_type_array (return_type,
+param_types.length (),
+param_types.address ());
+  /* FIXME: this uses input_location: */
+  tree fndecl = build_fn_decl (name, fn_type);
+
+  return fndecl;
+}
+
+static void
+test_fndecl_int_void ()
+{
+  auto_vec  param_types;
+  const char *name = "test_fndecl_int_void";
+  tree fndecl = make_fndecl (integer_type_node,
+name,
+param_types);
+  ASSERT_TRUE (fndecl != NULL);
+
+  /* Verify name of decl.  */
+  tree declname = DECL_NAME (fndecl);
+  ASSERT_TRUE (declname != NULL);
+  ASSERT_EQ (IDENTIFIER_NODE, TREE_CODE (declname));
+  /* We expect it to use a *copy* of the string we passed in.  */
+  const char *identifier_ptr = IDENTIFIER_POINTER (declname);
+  ASSERT_NE (name, identifier_ptr);
+  ASSERT_EQ (0, strcmp ("test_fndecl_int_void", identifier_ptr));
+
+  /* Verify type of fndecl.  */
+  ASSERT_EQ (FUNCTION_DECL, TREE_CODE (fndecl));
+  tree fntype = TREE_TYPE (fndecl);
+  ASSERT_EQ (FUNCTION_TYPE, TREE_CODE (fntype));
+
+  /* Verify return type.  */
+  ASSERT_EQ (integer_type_node, TREE_TYPE (fntype));
+
+  /* Verify "void" args.  */
+  tree argtypes = TYPE_ARG_TYPES (fntype);
+  ASSERT_EQ (TREE_LIST, TREE_CODE (argtypes));
+  ASSERT_EQ (void_type_node, TREE_VALUE (argtypes));
+  ASSERT_EQ (NULL, TREE_CHAIN (argtypes));
+}
+
+static void
+test_fndecl_float_intchar ()
+{
+  auto_vec  param_types;
+  param_types.safe_push (integer_type_node);
+  param_types.safe_push (char_type_node);
+  const char *name = "test_fndecl_float_intchar";
+  tree fndecl = make_fndecl (float_type_node,
+

[PATCH, RS6000] Add RS6000_BTM_MODULO to set of RS6000_BTM_COMMON flags

2016-06-02 Thread Kelvin Nilsen

This patch adds the RS6000_BTM_MODULO flag to to the set of flags 
associated with the RS6000_BTM_COMMON variable.

This patch has bootstrapped with the trunk and the gcc-6-branch on
powerpc64le-unknown-linux-gnu and there were no regressions.

Is it ok to merge this with the trunk?  Can I merge with the 
gcc-6-branch after waiting a few days following the trunk integration?

gcc/ChangeLog:

2016-06-02  Kelvin Nilsen  

* config/rs6000/rs6000.h (RS6000_BTM_COMMON): Add the
RS6000_BTM_MODULO flag into the set of flags that are considered
to be part of the common configuration.

Index: gcc/config/rs6000/rs6000.h
===
--- gcc/config/rs6000/rs6000.h  (revision 237038)
+++ gcc/config/rs6000/rs6000.h  (working copy)
@@ -2694,6 +2694,7 @@ extern int frame_pointer_needed;
 | RS6000_BTM_VSX   \
 | RS6000_BTM_P8_VECTOR \
 | RS6000_BTM_P9_VECTOR \
+| RS6000_BTM_MODULO\
 | RS6000_BTM_CRYPTO\
 | RS6000_BTM_FRE   \
 | RS6000_BTM_FRES  \



[PATCH, rs6000] Fix PR70957 (skip vsx-elemrev-[24].c tests for a downlevel assembler)

2016-06-02 Thread Bill Schmidt
Hi,

PR70957 reports that the two subject tests fail on an older P7 machine.  These 
tests rely on
built-ins that exploit POWER9 vector support.  It turns out that the failure 
occurs because the
configured assembler is downlevel, and does not support even POWER8 
instructions.  This 
causes TARGET_P8_VECTOR to be set to false, which in turn causes 
TARGET_P9_VECTOR
to be set to false, so the built-ins in question are not linked into the 
overloaded built-in table.

The only way I know to make the test predictable is to use a run-time test to 
check whether
P9 vector instructions will execute.  Thus this solution.  I’ve verified we no 
longer have test
failures on machines with a downlevel assembler, and the tests run correctly on 
machines
with an up-to-date assembler.  Is this ok for trunk and 6.2?

Thanks,
Bill


[2016-06-02]  Bill Schmidt  

PR target/70957
* gcc.target/powerpc/vsx-elemrev-2.c: Require p9vector hardware
support.
* gcc.target/powerpc/vsx-elemrev-4.c: Likewise.


Index: gcc/testsuite/gcc.target/powerpc/vsx-elemrev-2.c
===
--- gcc/testsuite/gcc.target/powerpc/vsx-elemrev-2.c(revision 237044)
+++ gcc/testsuite/gcc.target/powerpc/vsx-elemrev-2.c(working copy)
@@ -1,6 +1,7 @@
 /* { dg-do compile { target { powerpc64le*-*-* } } } */
 /* { dg-skip-if "do not override mcpu" { powerpc*-*-* } { "-mcpu=*" } { 
"-mcpu=power9" } } */
 /* { dg-options "-mcpu=power9 -O0" } */
+/* { dg-require-effective-target p9vector_hw } */
 /* { dg-final { scan-assembler-times "lxvd2x" 6 } } */
 /* { dg-final { scan-assembler-times "lxvw4x" 6 } } */
 /* { dg-final { scan-assembler-times "lxvh8x" 4 } } */
Index: gcc/testsuite/gcc.target/powerpc/vsx-elemrev-4.c
===
--- gcc/testsuite/gcc.target/powerpc/vsx-elemrev-4.c(revision 237044)
+++ gcc/testsuite/gcc.target/powerpc/vsx-elemrev-4.c(working copy)
@@ -1,6 +1,7 @@
 /* { dg-do compile { target { powerpc64-*-* } } } */
 /* { dg-skip-if "do not override mcpu" { powerpc*-*-* } { "-mcpu=*" } { 
"-mcpu=power9" } } */
 /* { dg-options "-mcpu=power9 -O0" } */
+/* { dg-require-effective-target p9vector_hw } */
 /* { dg-final { scan-assembler-times "lxvx" 40 } } */
 /* { dg-final { scan-assembler-times "stxvx" 40 } } */
 





[PATCH 02/16] diagnostic-show-locus.c: add selftests

2016-06-02 Thread David Malcolm
gcc/ChangeLog:
* diagnostic-show-locus.c: Include "selftest.h".
(make_range): New function.
(test_range_contains_point_for_single_point): New function.
(test_range_contains_point_test_for_single_line): New function.
(test_range_contains_point_for_multiple_lines): New function.
(assert_eq): New function.
(test_get_line_width_without_trailing_whitespace): New function.
(selftest::diagnostic_show_locus_c_tests): New function.
---
 gcc/diagnostic-show-locus.c | 156 
 1 file changed, 156 insertions(+)

diff --git a/gcc/diagnostic-show-locus.c b/gcc/diagnostic-show-locus.c
index eeccee5..38b424d 100644
--- a/gcc/diagnostic-show-locus.c
+++ b/gcc/diagnostic-show-locus.c
@@ -27,6 +27,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "backtrace.h"
 #include "diagnostic.h"
 #include "diagnostic-color.h"
+#include "selftest.h"
 
 #ifdef HAVE_TERMIOS_H
 # include 
@@ -442,6 +443,118 @@ layout_range::contains_point (int row, int column) const
   return column <= m_finish.m_column;
 }
 
+#if CHECKING_P
+
+/* A helper function for testing layout_range::contains_point.  */
+
+static layout_range
+make_range (int start_line, int start_col,
+   int end_line, int end_col)
+{
+  const expanded_location start_exploc
+= {"test.c", start_line, start_col, NULL, false};
+  const expanded_location finish_exploc
+= {"test.c", end_line, end_col, NULL, false};
+  return layout_range (_exploc, _exploc, false,
+  _exploc);
+}
+
+/* Selftests for layout_range::contains_point.  */
+
+static void
+test_range_contains_point_for_single_point ()
+{
+  /* A range with start==end.  */
+  layout_range point = make_range (7, 10, 7, 10);
+
+  /* Before the line. */
+  ASSERT_FALSE (point.contains_point (6, 1));
+
+  /* On the line, but before start.  */
+  ASSERT_FALSE (point.contains_point (7, 9));
+
+  /* At the point.  */
+  ASSERT_TRUE (point.contains_point (7, 10));
+
+  /* On the line, after the point.  */
+  ASSERT_FALSE (point.contains_point (7, 11));
+
+  /* After the line.  */
+  ASSERT_FALSE (point.contains_point (8, 1));
+}
+
+static void
+test_range_contains_point_test_for_single_line ()
+{
+  /* The single-line example from above.  */
+  layout_range example_a = make_range (2, 22, 2, 38);
+
+  /* Before the line. */
+  ASSERT_FALSE (example_a.contains_point (1, 1));
+
+  /* On the line, but before start.  */
+  ASSERT_FALSE (example_a.contains_point (2, 21));
+
+  /* On the line, at the start.  */
+  ASSERT_TRUE (example_a.contains_point (2, 22));
+
+  /* On the line, within the range.  */
+  ASSERT_TRUE (example_a.contains_point (2, 23));
+
+  /* On the line, at the end.  */
+  ASSERT_TRUE (example_a.contains_point (2, 38));
+
+  /* On the line, after the end.  */
+  ASSERT_FALSE (example_a.contains_point (2, 39));
+
+  /* After the line.  */
+  ASSERT_FALSE (example_a.contains_point (2, 39));
+}
+
+static void
+test_range_contains_point_for_multiple_lines ()
+{
+  /* The multi-line example from above.  */
+  layout_range example_b = make_range (3, 14, 5, 8);
+
+  /* Before first line. */
+  ASSERT_FALSE (example_b.contains_point (1, 1));
+
+  /* On the first line, but before start.  */
+  ASSERT_FALSE (example_b.contains_point (3, 13));
+
+  /* At the start.  */
+  ASSERT_TRUE (example_b.contains_point (3, 14));
+
+  /* On the first line, within the range.  */
+  ASSERT_TRUE (example_b.contains_point (3, 15));
+
+  /* On an interior line.
+ The column number should not matter; try various boundary
+ values.  */
+  ASSERT_TRUE (example_b.contains_point (4, 1));
+  ASSERT_TRUE (example_b.contains_point (4, 7));
+  ASSERT_TRUE (example_b.contains_point (4, 8));
+  ASSERT_TRUE (example_b.contains_point (4, 9));
+  ASSERT_TRUE (example_b.contains_point (4, 13));
+  ASSERT_TRUE (example_b.contains_point (4, 14));
+  ASSERT_TRUE (example_b.contains_point (4, 15));
+
+  /* On the final line, before the end.  */
+  ASSERT_TRUE (example_b.contains_point (5, 7));
+
+  /* On the final line, at the end.  */
+  ASSERT_TRUE (example_b.contains_point (5, 8));
+
+  /* On the final line, after the end.  */
+  ASSERT_FALSE (example_b.contains_point (5, 9));
+
+  /* After the line.  */
+  ASSERT_FALSE (example_b.contains_point (6, 1));
+}
+
+#endif /* #if CHECKING_P */
+
 /* Given a source line LINE of length LINE_WIDTH, determine the width
without any trailing whitespace.  */
 
@@ -465,6 +578,31 @@ get_line_width_without_trailing_whitespace (const char 
*line, int line_width)
   return result;
 }
 
+#if CHECKING_P
+
+/* A helper function for testing get_line_width_without_trailing_whitespace.  
*/
+
+static void
+assert_eq (const char *line, int expected_width)
+{
+  int actual_value
+= get_line_width_without_trailing_whitespace (line, strlen (line));
+  ASSERT_EQ (actual_value, expected_width);
+}
+
+static void
+test_get_line_width_without_trailing_whitespace ()
+{
+  

[PATCH 05/16] tree-cfg.c: add selftests

2016-06-02 Thread David Malcolm
Jeff approved an older version of this:
https://gcc.gnu.org/ml/gcc-patches/2015-10/msg03285.html
with:
> Unless there's a good reason, drop the presumably redundant tests
> and this is OK. Save preapprovald for these changes as the bitmap
> patch.

This version removes the redundant tests, moves the tests
from being in a new file to being in tree-cfg.c, and converts
them to the new style.

gcc/ChangeLog:
* tree-cfg.c: Include "selftest.h".
(push_fndecl): New function.
(test_linear_chain): New function.
(test_diamond): New function.
(test_fully_connected): New function.
(selftest::tree_cfg_c_tests): New function.
---
 gcc/tree-cfg.c | 277 +
 1 file changed, 277 insertions(+)

diff --git a/gcc/tree-cfg.c b/gcc/tree-cfg.c
index 6573702..dd2f7d2 100644
--- a/gcc/tree-cfg.c
+++ b/gcc/tree-cfg.c
@@ -58,6 +58,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "tree-cfgcleanup.h"
 #include "gimplify.h"
 #include "attribs.h"
+#include "selftest.h"
 
 /* This file contains functions for building the Control Flow Graph (CFG)
for a function tree.  */
@@ -9145,3 +9146,279 @@ gt_pch_nx (edge_def *e, gt_pointer_operator op, void 
*cookie)
 op (&(e->insns.r), cookie);
   op (&(block), cookie);
 }
+
+#if CHECKING_P
+
+/* Helper function for CFG selftests: create a dummy function decl
+   and push it as cfun.  */
+
+static tree
+push_fndecl (const char *name)
+{
+  tree fn_type = build_function_type_array (integer_type_node, /* return_type 
*/
+   0, NULL);
+  /* FIXME: this uses input_location: */
+  tree fndecl = build_fn_decl (name, fn_type);
+  tree retval = build_decl (UNKNOWN_LOCATION, RESULT_DECL,
+   NULL_TREE, integer_type_node);
+  DECL_RESULT (fndecl) = retval;
+  push_struct_function (fndecl);
+  function *fun = DECL_STRUCT_FUNCTION (fndecl);
+  ASSERT_TRUE (fun != NULL);
+  init_empty_tree_cfg_for_function (fun);
+  ASSERT_EQ (2, n_basic_blocks_for_fn (fun));
+  ASSERT_EQ (0, n_edges_for_fn (fun));
+  return fndecl;
+}
+
+/* These tests directly create CFGs.
+   Compare with the static fns within tree-cfg.c:
+ - build_gimple_cfg
+ - make_blocks: calls create_basic_block (seq, bb);
+ - make_edges.   */
+
+/* Verify a simple cfg of the form:
+ ENTRY -> A -> B -> C -> EXIT.  */
+
+static void
+test_linear_chain ()
+{
+  gimple_register_cfg_hooks ();
+
+  tree fndecl = push_fndecl ("cfg_test_linear_chain");
+  function *fun = DECL_STRUCT_FUNCTION (fndecl);
+
+  /* Create some empty blocks.  */
+  basic_block bb_a = create_empty_bb (ENTRY_BLOCK_PTR_FOR_FN (fun));
+  basic_block bb_b = create_empty_bb (bb_a);
+  basic_block bb_c = create_empty_bb (bb_b);
+
+  ASSERT_EQ (5, n_basic_blocks_for_fn (fun));
+  ASSERT_EQ (0, n_edges_for_fn (fun));
+
+  /* Create some edges: a simple linear chain of BBs.  */
+  make_edge (ENTRY_BLOCK_PTR_FOR_FN (fun), bb_a, EDGE_FALLTHRU);
+  make_edge (bb_a, bb_b, 0);
+  make_edge (bb_b, bb_c, 0);
+  make_edge (bb_c, EXIT_BLOCK_PTR_FOR_FN (fun), 0);
+
+  /* Verify the edges.  */
+  ASSERT_EQ (4, n_edges_for_fn (fun));
+  ASSERT_EQ (NULL, ENTRY_BLOCK_PTR_FOR_FN (fun)->preds);
+  ASSERT_EQ (1, ENTRY_BLOCK_PTR_FOR_FN (fun)->succs->length ());
+  ASSERT_EQ (1, bb_a->preds->length ());
+  ASSERT_EQ (1, bb_a->succs->length ());
+  ASSERT_EQ (1, bb_b->preds->length ());
+  ASSERT_EQ (1, bb_b->succs->length ());
+  ASSERT_EQ (1, bb_c->preds->length ());
+  ASSERT_EQ (1, bb_c->succs->length ());
+  ASSERT_EQ (1, EXIT_BLOCK_PTR_FOR_FN (fun)->preds->length ());
+  ASSERT_EQ (NULL, EXIT_BLOCK_PTR_FOR_FN (fun)->succs);
+
+  /* Verify the dominance information
+ Each BB in our simple chain should be dominated by the one before
+ it.  */
+  calculate_dominance_info (CDI_DOMINATORS);
+  ASSERT_EQ (bb_a, get_immediate_dominator (CDI_DOMINATORS, bb_b));
+  ASSERT_EQ (bb_b, get_immediate_dominator (CDI_DOMINATORS, bb_c));
+  vec dom_by_b = get_dominated_by (CDI_DOMINATORS, bb_b);
+  ASSERT_EQ (1, dom_by_b.length ());
+  ASSERT_EQ (bb_c, dom_by_b[0]);
+  free_dominance_info (CDI_DOMINATORS);
+
+  /* Similarly for post-dominance: each BB in our chain is post-dominated
+ by the one after it.  */
+  calculate_dominance_info (CDI_POST_DOMINATORS);
+  ASSERT_EQ (bb_b, get_immediate_dominator (CDI_POST_DOMINATORS, bb_a));
+  ASSERT_EQ (bb_c, get_immediate_dominator (CDI_POST_DOMINATORS, bb_b));
+  vec postdom_by_b = get_dominated_by (CDI_POST_DOMINATORS, bb_b);
+  ASSERT_EQ (1, postdom_by_b.length ());
+  ASSERT_EQ (bb_a, postdom_by_b[0]);
+  free_dominance_info (CDI_POST_DOMINATORS);
+
+  pop_cfun ();
+}
+
+/* Verify a simple CFG of the form:
+ ENTRY
+   |
+   A
+  / \
+ /t  \f
+B C
+ \   /
+  \ /
+   D
+   |
+  EXIT.  */
+
+static void
+test_diamond ()
+{
+  gimple_register_cfg_hooks ();
+
+  tree fndecl = push_fndecl ("cfg_test_diamond");
+  

[PATCH 10/16] Add hash-map-tests.c

2016-06-02 Thread David Malcolm
Jeff approved an earlier version of this (as
unittests/test-hash-map.c):
 https://gcc.gnu.org/ml/gcc-patches/2015-10/msg03301.html
> OK if/when prereqs are approved. Minor twiddling if we end up
> moving it elsewhere or standardizing/reducing header files is
> pre-approved.

This version moves the tests to gcc/hash-map-tests.c and
updates them to the new style.

gcc/ChangeLog:
* hash-map-tests.c: New file.
---
 gcc/hash-map-tests.c | 88 
 1 file changed, 88 insertions(+)
 create mode 100644 gcc/hash-map-tests.c

diff --git a/gcc/hash-map-tests.c b/gcc/hash-map-tests.c
new file mode 100644
index 000..b2b9095
--- /dev/null
+++ b/gcc/hash-map-tests.c
@@ -0,0 +1,88 @@
+/* Unit tests for hash-map.h.
+   Copyright (C) 2015-2016 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC 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.
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING3.  If not see
+.  */
+
+#include "config.h"
+#include "system.h"
+#include "coretypes.h"
+#include "tm.h"
+#include "opts.h"
+#include "signop.h"
+#include "hash-set.h"
+#include "fixed-value.h"
+#include "alias.h"
+#include "flags.h"
+#include "symtab.h"
+#include "tree-core.h"
+#include "stor-layout.h"
+#include "tree.h"
+#include "stringpool.h"
+#include "selftest.h"
+
+#if CHECKING_P
+
+static void
+test_map_of_strings_to_int ()
+{
+  hash_map  m;
+
+  const char *ostrich = "ostrich";
+  const char *elephant = "elephant";
+  const char *ant = "ant";
+  const char *spider = "spider";
+  const char *millipede = "Illacme plenipes";
+  const char *eric = "half a bee";
+
+  /* A fresh hash_map should be empty.  */
+  ASSERT_EQ (0, m.elements ());
+  ASSERT_EQ (NULL, m.get (ostrich));
+
+  /* Populate the hash_map.  */
+  ASSERT_EQ (false, m.put (ostrich, 2));
+  ASSERT_EQ (false, m.put (elephant, 4));
+  ASSERT_EQ (false, m.put (ant, 6));
+  ASSERT_EQ (false, m.put (spider, 8));
+  ASSERT_EQ (false, m.put (millipede, 750));
+  ASSERT_EQ (false, m.put (eric, 3));
+
+  /* Verify that we can recover the stored values.  */
+  ASSERT_EQ (6, m.elements ());
+  ASSERT_EQ (2, *m.get (ostrich));
+  ASSERT_EQ (4, *m.get (elephant));
+  ASSERT_EQ (6, *m.get (ant));
+  ASSERT_EQ (8, *m.get (spider));
+  ASSERT_EQ (750, *m.get (millipede));
+  ASSERT_EQ (3, *m.get (eric));
+
+  /* Verify removing an item.  */
+  m.remove (eric);
+  ASSERT_EQ (5, m.elements ());
+  ASSERT_EQ (NULL, m.get (eric));
+}
+
+namespace selftest {
+
+void
+hash_map_tests_c_tests ()
+{
+  test_map_of_strings_to_int ();
+}
+
+} // namespace selftest
+
+#endif /* CHECKING_P */
-- 
1.8.5.3



[PATCH 04/16] bitmap.c: add selftests

2016-06-02 Thread David Malcolm
Jeff pre-approved the plugin version of this (as a new
file unittests/test-bitmap.c):
https://gcc.gnu.org/ml/gcc-patches/2015-10/msg03284.html
with:
> OK if/when prereqs are approved.  Minor twiddling if we end up moving it
> elsewhere or standardizing/reducing header files is pre-approved.

This version moves them to bitmap.c and converts them to
functions.

gcc/ChangeLog:
* bitmap.c: Include "selftest.h".
(test_gc_alloc): New function.
(test_set_range): New function.
(test_clear_bit_in_middle): New function.
(test_copying): New function.
(test_bitmap_single_bit_set_p): New function.
(selftest::bitmap_c_tests): New function.
---
 gcc/bitmap.c | 110 +++
 1 file changed, 110 insertions(+)

diff --git a/gcc/bitmap.c b/gcc/bitmap.c
index 0c05512..21149e7 100644
--- a/gcc/bitmap.c
+++ b/gcc/bitmap.c
@@ -21,6 +21,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "system.h"
 #include "coretypes.h"
 #include "bitmap.h"
+#include "selftest.h"
 
 /* Memory allocation statistics purpose instance.  */
 mem_alloc_description bitmap_mem_desc;
@@ -2162,5 +2163,114 @@ debug (const bitmap_head *ptr)
 fprintf (stderr, "\n");
 }
 
+#if CHECKING_P
+
+/* Selftests for bitmaps.  */
+
+/* Freshly-created bitmaps ought to be empty.  */
+
+static void
+test_gc_alloc ()
+{
+  bitmap b = bitmap_gc_alloc ();
+  ASSERT_TRUE (bitmap_empty_p (b));
+}
+
+/* Verify bitmap_set_range.  */
+
+static void
+test_set_range ()
+{
+  bitmap b = bitmap_gc_alloc ();
+  ASSERT_TRUE (bitmap_empty_p (b));
+
+  bitmap_set_range (b, 7, 5);
+  ASSERT_FALSE (bitmap_empty_p (b));
+  ASSERT_EQ (5, bitmap_count_bits (b));
+
+  /* Verify bitmap_bit_p at the boundaries.  */
+  ASSERT_FALSE (bitmap_bit_p (b, 6));
+  ASSERT_TRUE (bitmap_bit_p (b, 7));
+  ASSERT_TRUE (bitmap_bit_p (b, 11));
+  ASSERT_FALSE (bitmap_bit_p (b, 12));
+}
+
+/* Verify splitting a range into two pieces using bitmap_clear_bit.  */
+
+static void
+test_clear_bit_in_middle ()
+{
+  bitmap b = bitmap_gc_alloc ();
+
+  /* Set b to [100..200].  */
+  bitmap_set_range (b, 100, 100);
+  ASSERT_EQ (100, bitmap_count_bits (b));
+
+  /* Clear a bit in the middle.  */
+  bool changed = bitmap_clear_bit (b, 150);
+  ASSERT_TRUE (changed);
+  ASSERT_EQ (99, bitmap_count_bits (b));
+  ASSERT_TRUE (bitmap_bit_p (b, 149));
+  ASSERT_FALSE (bitmap_bit_p (b, 150));
+  ASSERT_TRUE (bitmap_bit_p (b, 151));
+}
+
+/* Verify bitmap_copy.  */
+
+static void
+test_copying ()
+{
+  bitmap src = bitmap_gc_alloc ();
+  bitmap_set_range (src, 40, 10);
+
+  bitmap dst = bitmap_gc_alloc ();
+  ASSERT_FALSE (bitmap_equal_p (src, dst));
+  bitmap_copy (dst, src);
+  ASSERT_TRUE (bitmap_equal_p (src, dst));
+
+  /* Verify that we can make them unequal again...  */
+  bitmap_set_range (src, 70, 5);
+  ASSERT_FALSE (bitmap_equal_p (src, dst));
+
+  /* ...and that changing src after the copy didn't affect
+ the other: */
+  ASSERT_FALSE (bitmap_bit_p (dst, 70));
+}
+
+/* Verify bitmap_single_bit_set_p.  */
+static void
+test_bitmap_single_bit_set_p ()
+{
+  bitmap b = bitmap_gc_alloc ();
+
+  ASSERT_FALSE (bitmap_single_bit_set_p (b));
+
+  bitmap_set_range (b, 42, 1);
+  ASSERT_TRUE (bitmap_single_bit_set_p (b));
+  ASSERT_EQ (42, bitmap_first_set_bit (b));
+
+  bitmap_set_range (b, 1066, 1);
+  ASSERT_FALSE (bitmap_single_bit_set_p (b));
+  ASSERT_EQ (42, bitmap_first_set_bit (b));
+
+  bitmap_clear_range (b, 0, 100);
+  ASSERT_TRUE (bitmap_single_bit_set_p (b));
+  ASSERT_EQ (1066, bitmap_first_set_bit (b));
+}
+
+namespace selftest {
+
+void
+bitmap_c_tests ()
+{
+  test_gc_alloc ();
+  test_set_range ();
+  test_clear_bit_in_middle ();
+  test_copying ();
+  test_bitmap_single_bit_set_p ();
+}
+
+} // namespace selftest
+#endif /* CHECKING_P */
 
 #include "gt-bitmap.h"
-- 
1.8.5.3



[PATCH 03/16] spellcheck.c: convert Levenshtein test from a plugin to a selftest

2016-06-02 Thread David Malcolm
This is an example of converting one of our existing plugin-based
tests to run within -fself-test instead.

gcc/ChangeLog:
* spellcheck.c: Include "selftest.h".
(levenshtein_distance_unit_test_oneway): New function, adapted
from testsuite/gcc.dg/plugin/levenshtein_plugin.c.
(levenshtein_distance_unit_test): Likewise.
(selftest::spellcheck_c_tests): Likewise.

gcc/testsuite/ChangeLog:
* gcc.dg/plugin/levenshtein-test-1.c: Delete.
* gcc.dg/plugin/levenshtein_plugin.c: Delete.
* gcc.dg/plugin/plugin.exp (plugin_test_list): Remove the
above.
---
 gcc/spellcheck.c | 45 +
 gcc/testsuite/gcc.dg/plugin/levenshtein-test-1.c |  9 
 gcc/testsuite/gcc.dg/plugin/levenshtein_plugin.c | 64 
 gcc/testsuite/gcc.dg/plugin/plugin.exp   |  1 -
 4 files changed, 45 insertions(+), 74 deletions(-)
 delete mode 100644 gcc/testsuite/gcc.dg/plugin/levenshtein-test-1.c
 delete mode 100644 gcc/testsuite/gcc.dg/plugin/levenshtein_plugin.c

diff --git a/gcc/spellcheck.c b/gcc/spellcheck.c
index e4e83a5..07c033a 100644
--- a/gcc/spellcheck.c
+++ b/gcc/spellcheck.c
@@ -23,6 +23,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "tm.h"
 #include "tree.h"
 #include "spellcheck.h"
+#include "selftest.h"
 
 /* The Levenshtein distance is an "edit-distance": the minimal
number of one-character insertions, removals or substitutions
@@ -165,3 +166,47 @@ find_closest_string (const char *target,
 
   return best_candidate;
 }
+
+#if CHECKING_P
+
+static void
+levenshtein_distance_unit_test_oneway (const char *a, const char *b,
+  edit_distance_t expected)
+{
+  edit_distance_t actual = levenshtein_distance (a, b);
+  ASSERT_EQ (actual, expected);
+}
+
+static void
+levenshtein_distance_unit_test (const char *a, const char *b,
+   edit_distance_t expected)
+{
+  /* Run every test both ways to ensure it's symmetric.  */
+  levenshtein_distance_unit_test_oneway (a, b, expected);
+  levenshtein_distance_unit_test_oneway (b, a, expected);
+}
+
+namespace selftest {
+
+void
+spellcheck_c_tests ()
+{
+  levenshtein_distance_unit_test ("", "nonempty", strlen ("nonempty"));
+  levenshtein_distance_unit_test ("saturday", "sunday", 3);
+  levenshtein_distance_unit_test ("foo", "m_foo", 2);
+  levenshtein_distance_unit_test ("hello_world", "HelloWorld", 3);
+  levenshtein_distance_unit_test
+("the quick brown fox jumps over the lazy dog", "dog", 40);
+  levenshtein_distance_unit_test
+("the quick brown fox jumps over the lazy dog",
+ "the quick brown dog jumps over the lazy fox",
+ 4);
+  levenshtein_distance_unit_test
+("Lorem ipsum dolor sit amet, consectetur adipiscing elit,",
+ "All your base are belong to us",
+ 44);
+}
+
+} // namespace selftest
+
+#endif /* #if CHECKING_P */
diff --git a/gcc/testsuite/gcc.dg/plugin/levenshtein-test-1.c 
b/gcc/testsuite/gcc.dg/plugin/levenshtein-test-1.c
deleted file mode 100644
index ac49992..000
--- a/gcc/testsuite/gcc.dg/plugin/levenshtein-test-1.c
+++ /dev/null
@@ -1,9 +0,0 @@
-/* Placeholder C source file for unit-testing gcc/spellcheck.c.  */
-/* { dg-do compile } */
-/* { dg-options "-O" } */
-
-int
-main (int argc, char **argv)
-{
-  return 0;
-}
diff --git a/gcc/testsuite/gcc.dg/plugin/levenshtein_plugin.c 
b/gcc/testsuite/gcc.dg/plugin/levenshtein_plugin.c
deleted file mode 100644
index 3e7dc78..000
--- a/gcc/testsuite/gcc.dg/plugin/levenshtein_plugin.c
+++ /dev/null
@@ -1,64 +0,0 @@
-/* Plugin for unittesting gcc/spellcheck.h.  */
-
-#include "config.h"
-#include "gcc-plugin.h"
-#include "system.h"
-#include "coretypes.h"
-#include "spellcheck.h"
-#include "diagnostic.h"
-
-int plugin_is_GPL_compatible;
-
-static void
-levenshtein_distance_unit_test_oneway (const char *a, const char *b,
-  edit_distance_t expected)
-{
-  edit_distance_t actual = levenshtein_distance (a, b);
-  if (actual != expected)
-error ("levenshtein_distance (\"%s\", \"%s\") : expected: %i got %i",
-  a, b, expected, actual);
-}
-
-
-static void
-levenshtein_distance_unit_test (const char *a, const char *b,
-   edit_distance_t expected)
-{
-  /* Run every test both ways to ensure it's symmetric.  */
-  levenshtein_distance_unit_test_oneway (a, b, expected);
-  levenshtein_distance_unit_test_oneway (b, a, expected);
-}
-
-/* Callback handler for the PLUGIN_FINISH event; run
-   levenshtein_distance unit tests here.  */
-
-static void
-on_finish (void */*gcc_data*/, void */*user_data*/)
-{
-  levenshtein_distance_unit_test ("", "nonempty", strlen ("nonempty"));
-  levenshtein_distance_unit_test ("saturday", "sunday", 3);
-  levenshtein_distance_unit_test ("foo", "m_foo", 2);
-  levenshtein_distance_unit_test ("hello_world", "HelloWorld", 3);
-  levenshtein_distance_unit_test
-("the quick 

[PATCH 09/16] gimple.c: add selftests

2016-06-02 Thread David Malcolm
Jeff approved an earlier version of this (as
unittests/test-gimple.c):
https://gcc.gnu.org/ml/gcc-patches/2015-10/msg03304.html

> OK if/when prereqs are approved. Minor twiddling if we end
> up moving it elsewhere or standardizing/reducing header files
> is pre-approved.

This version moves the tests into gimple.c and updates them to
the new style.

gcc/ChangeLog:
* gimple.c: Include "selftest.h".
Include "gimple-pretty-print.h".
(verify_gimple_pp): New function.
(test_assign_single): New function.
(test_assign_binop): New function.
(test_nop_stmt): New function.
(test_return_stmt): New function.
(test_return_without_value): New function.
(selftest::gimple_c_tests): New function.
---
 gcc/gimple.c | 119 +++
 1 file changed, 119 insertions(+)

diff --git a/gcc/gimple.c b/gcc/gimple.c
index d822fab..c0a11a9 100644
--- a/gcc/gimple.c
+++ b/gcc/gimple.c
@@ -38,6 +38,8 @@ along with GCC; see the file COPYING3.  If not see
 #include "gimple-walk.h"
 #include "gimplify.h"
 #include "target.h"
+#include "selftest.h"
+#include "gimple-pretty-print.h"
 
 
 /* All the tuples have their operand vector (if present) at the very bottom
@@ -3016,3 +3018,120 @@ maybe_remove_unused_call_args (struct function *fn, 
gimple *stmt)
   update_stmt_fn (fn, stmt);
 }
 }
+
+#if CHECKING_P
+
+/* Selftests for core gimple structures.  */
+
+/* Helper function for selftests.  */
+
+static void
+verify_gimple_pp (const char *expected, gimple *stmt)
+{
+  pretty_printer pp;
+  pp_gimple_stmt_1 (, stmt, 0 /* spc */, 0 /* flags */);
+  ASSERT_STREQ (expected, pp_formatted_text ());
+}
+
+static void
+test_assign_single ()
+{
+  /* Build "tmp = 5;"  */
+  tree type = integer_type_node;
+  tree lhs = build_decl (UNKNOWN_LOCATION, VAR_DECL,
+get_identifier ("tmp"),
+type);
+  tree rhs = build_int_cst (type, 5);
+  gassign *stmt = gimple_build_assign (lhs, rhs);
+  verify_gimple_pp ("tmp = 5;", stmt);
+
+  ASSERT_TRUE (is_gimple_assign (stmt));
+  ASSERT_EQ (lhs, gimple_assign_lhs (stmt));
+  ASSERT_EQ (lhs, gimple_get_lhs (stmt));
+  ASSERT_EQ (rhs, gimple_assign_rhs1 (stmt));
+  ASSERT_EQ (NULL, gimple_assign_rhs2 (stmt));
+  ASSERT_EQ (NULL, gimple_assign_rhs3 (stmt));
+  ASSERT_TRUE (gimple_assign_single_p (stmt));
+  ASSERT_EQ (INTEGER_CST, gimple_assign_rhs_code (stmt));
+}
+
+static void
+test_assign_binop ()
+{
+  /* Build "tmp = a * b;"  */
+  tree type = integer_type_node;
+  tree lhs = build_decl (UNKNOWN_LOCATION, VAR_DECL,
+get_identifier ("tmp"),
+type);
+  tree a = build_decl (UNKNOWN_LOCATION, VAR_DECL,
+  get_identifier ("a"),
+  type);
+  tree b = build_decl (UNKNOWN_LOCATION, VAR_DECL,
+  get_identifier ("b"),
+  type);
+  gassign *stmt = gimple_build_assign (lhs, MULT_EXPR, a, b);
+  verify_gimple_pp ("tmp = a * b;", stmt);
+
+  ASSERT_TRUE (is_gimple_assign (stmt));
+  ASSERT_EQ (lhs, gimple_assign_lhs (stmt));
+  ASSERT_EQ (lhs, gimple_get_lhs (stmt));
+  ASSERT_EQ (a, gimple_assign_rhs1 (stmt));
+  ASSERT_EQ (b, gimple_assign_rhs2 (stmt));
+  ASSERT_EQ (NULL, gimple_assign_rhs3 (stmt));
+  ASSERT_FALSE (gimple_assign_single_p (stmt));
+  ASSERT_EQ (MULT_EXPR, gimple_assign_rhs_code (stmt));
+}
+
+static void
+test_nop_stmt ()
+{
+  gimple *stmt = gimple_build_nop ();
+  verify_gimple_pp ("GIMPLE_NOP", stmt);
+  ASSERT_EQ (GIMPLE_NOP, gimple_code (stmt));
+  ASSERT_EQ (NULL, gimple_get_lhs (stmt));
+  ASSERT_FALSE (gimple_assign_single_p (stmt));
+}
+
+static void
+test_return_stmt ()
+{
+  /* Build "return 7;"  */
+  tree type = integer_type_node;
+  tree val = build_int_cst (type, 7);
+  greturn *stmt = gimple_build_return (val);
+  verify_gimple_pp ("return 7;", stmt);
+
+  ASSERT_EQ (GIMPLE_RETURN, gimple_code (stmt));
+  ASSERT_EQ (NULL, gimple_get_lhs (stmt));
+  ASSERT_EQ (val, gimple_return_retval (stmt));
+  ASSERT_FALSE (gimple_assign_single_p (stmt));
+}
+
+static void
+test_return_without_value ()
+{
+  greturn *stmt = gimple_build_return (NULL);
+  verify_gimple_pp ("return;", stmt);
+
+  ASSERT_EQ (GIMPLE_RETURN, gimple_code (stmt));
+  ASSERT_EQ (NULL, gimple_get_lhs (stmt));
+  ASSERT_EQ (NULL, gimple_return_retval (stmt));
+  ASSERT_FALSE (gimple_assign_single_p (stmt));
+}
+
+namespace selftest {
+
+void
+gimple_c_tests ()
+{
+  test_assign_single ();
+  test_assign_binop ();
+  test_nop_stmt ();
+  test_return_stmt ();
+  test_return_without_value ();
+}
+
+} // namespace selftest
+
+
+#endif /* CHECKING_P */
-- 
1.8.5.3



[PATCH 01/16] Core of selftest framework (v6)

2016-06-02 Thread David Malcolm
gcc/ChangeLog:
* Makefile.in (OBJS): Add function-tests.o,
hash-map-tests.o, hash-set-tests.o, rtl-tests.o,
selftest-run-tests.o.
(OBJS-libcommon): Add selftest.o.
(OBJS-libcommon-target): Add selftest.o.
(all.internal): Add "selftests".
(all.cross): Likewise.
(selftests): New phony target.
(s-selftests): New target.
(selftests-gdb): New phony target.
(COLLECT2_OBJS): Add selftest.o.
* common.opt (fself-test): New.
* selftest-run-tests.c: New file.
* selftest.c: New file.
* selftest.h: New file.
* toplev.c: Include selftest.h.
(toplev::run_self_tests): New.
(toplev::main): Handle -fself-test.
* toplev.h (toplev::run_self_tests): New.
---
 gcc/Makefile.in  |  31 --
 gcc/common.opt   |   4 ++
 gcc/selftest-run-tests.c |  76 
 gcc/selftest.c   |  49 +++
 gcc/selftest.h   | 152 +++
 gcc/toplev.c |  26 
 gcc/toplev.h |   2 +
 7 files changed, 335 insertions(+), 5 deletions(-)
 create mode 100644 gcc/selftest-run-tests.c
 create mode 100644 gcc/selftest.c
 create mode 100644 gcc/selftest.h

diff --git a/gcc/Makefile.in b/gcc/Makefile.in
index 673f87d..2c5faa3 100644
--- a/gcc/Makefile.in
+++ b/gcc/Makefile.in
@@ -1264,6 +1264,7 @@ OBJS = \
fold-const.o \
fold-const-call.o \
function.o \
+   function-tests.o \
fwprop.o \
gcc-rich-location.o \
gcse.o \
@@ -1299,6 +1300,8 @@ OBJS = \
graphite-sese-to-poly.o \
gtype-desc.o \
haifa-sched.o \
+   hash-map-tests.o \
+   hash-set-tests.o \
hsa.o \
hsa-gen.o \
hsa-regalloc.o \
@@ -1399,6 +1402,7 @@ OBJS = \
resource.o \
rtl-chkp.o \
rtl-error.o \
+   rtl-tests.o \
rtl.o \
rtlhash.o \
rtlanal.o \
@@ -1411,6 +1415,7 @@ OBJS = \
sel-sched-ir.o \
sel-sched-dump.o \
sel-sched.o \
+   selftest-run-tests.o \
sese.o \
shrink-wrap.o \
simplify-rtx.o \
@@ -1543,13 +1548,14 @@ OBJS = \
 # no target dependencies.
 OBJS-libcommon = diagnostic.o diagnostic-color.o diagnostic-show-locus.o \
pretty-print.o intl.o \
-   vec.o input.o version.o hash-table.o ggc-none.o memory-block.o
+   vec.o input.o version.o hash-table.o ggc-none.o memory-block.o \
+   selftest.o
 
 # Objects in libcommon-target.a, used by drivers and by the core
 # compiler and containing target-dependent code.
 OBJS-libcommon-target = $(common_out_object_file) prefix.o params.o \
opts.o opts-common.o options.o vec.o hooks.o common/common-targhooks.o \
-   hash-table.o file-find.o
+   hash-table.o file-find.o selftest.o
 
 # This lists all host objects for the front ends.
 ALL_HOST_FRONTEND_OBJS = $(foreach v,$(CONFIG_LANGUAGES),$($(v)_OBJS))
@@ -1816,10 +1822,10 @@ config.status: $(srcdir)/configure $(srcdir)/config.gcc
 quickstrap: all
cd $(toplevel_builddir) && $(MAKE) all-target-libgcc
 
-all.internal: start.encap rest.encap doc
+all.internal: start.encap rest.encap doc selftests
 # This is what to compile if making a cross-compiler.
 all.cross: native gcc-cross$(exeext) cpp$(exeext) specs \
-   libgcc-support lang.all.cross doc @GENINSRC@ srcextra
+   libgcc-support lang.all.cross doc selftests @GENINSRC@ srcextra
 # This is what must be made before installing GCC and converting libraries.
 start.encap: native xgcc$(exeext) cpp$(exeext) specs \
libgcc-support lang.start.encap @GENINSRC@ srcextra
@@ -1839,6 +1845,21 @@ endif
 # This does the things that can't be done on the host machine.
 rest.cross: specs
 
+# Run the selftests during the build once we have a driver and a cc1,
+# so that self-test failures are caught as early as possible.
+# Use "s-selftests" to ensure that we only run the selftests if the
+# driver or cc1 change.
+.PHONY: selftests
+selftests: s-selftests
+s-selftests: $(GCC_PASSES) cc1$(exeext) stmp-int-hdrs
+   $(GCC_FOR_TARGET) -xc -S -c /dev/null -fself-test
+   $(STAMP) $@
+
+# Convenience method for running selftests under gdb:
+.PHONY: selftests-gdb
+selftests-gdb: $(GCC_PASSES) cc1$(exeext) stmp-int-hdrs
+   $(GCC_FOR_TARGET) -xc -S -c /dev/null -fself-test -wrapper gdb,--args
+
 # Recompile all the language-independent object files.
 # This is used only if the user explicitly asks for it.
 compilations: $(BACKEND)
@@ -1986,7 +2007,7 @@ gcc-nm.c: gcc-ar.c
cp $^ $@
 
 COLLECT2_OBJS = collect2.o collect2-aix.o tlink.o vec.o ggc-none.o \
-  collect-utils.o file-find.o hash-table.o
+  collect-utils.o file-find.o hash-table.o selftest.o
 COLLECT2_LIBS = @COLLECT2_LIBS@
 collect2$(exeext): $(COLLECT2_OBJS) $(LIBDEPS)
 # Don't try modifying collect2 (aka ld) in place--it might be linking this.
diff --git 

[PATCH 00/16] v6 of -fself-test/unit-testing patch

2016-06-02 Thread David Malcolm
Given that we're now using an "abort on first failure" model, I
renamed all of the EXPECT_ macros to ASSERT_ (for consistency with
GTest).

As per Bernd's suggestions I eliminated the runner class and moved
to a more function-based rather than class-based approach.

At this point, the only reasons left for "class test" were
auto-registration, and giving names to tests.

So I tried removing it, and invoking tests manually.

I like the resulting code; it seems much simpler and clearer, with
very little "magic".

The following is an updated version of the patch kit that uses this
simpler approach.

In theory there's a slight risk to the manual-invocation approach.
If you forget a test within a file, the compiler tells you:

../../src/gcc/vec.c:204:1: warning: ‘void test_quick_push()’ defined but not 
used [-Wunused-function]

but if you forget to call the file from selftests.c, there's no warning.
I believe that adding a new test file will be a rare event, so this
kind of mistake will (I hope) be unlikely.
I've verified that the pass count before/after the change matches up.
By constrast, the auto-registration approach put us at the mercy of
the implementation of C++ global constructors, and I ran into at
least one surprise with that
( https://sourceware.org/bugzilla/show_bug.cgi?id=20152 ).

I've added the wide-int tests back.  These are parametrized by type,
and it was fairly easy to do this manually using templates once I
eliminated test registration.  I also added some new tests to
diagnostic-show-locus.c.

Although I'm posted this as a patch kit, it would be applied in one
commit: the initial patch makes reference to tests added in later
patches. I split it up so that each test file is in its own patch,
to make review easier (I hope).

As in v5, the tests are run in gcc/Makefile.in at each stage of a
bootstrap:
  $ grep "fself-test:" test/experiment/x86_64-pc-linux-gnu/build/make.log
  -fself-test: 621 pass(es) in 0.013000 seconds
  -fself-test: 621 pass(es) in 0.006000 seconds
  -fself-test: 621 pass(es) in 0.007000 seconds

Successfully bootstrapped tested on x86_64-pc-linux-gnu.
A test against all configurations using contrib/config-list.mk is
in progress.

OK for trunk?

David Malcolm (16):
  Core of selftest framework (v6)
  diagnostic-show-locus.c: add selftests
  spellcheck.c: convert Levenshtein test from a plugin to a selftest
  bitmap.c: add selftests
  tree-cfg.c: add selftests
  et-forest.c: add selftests
  fold-const.c: add selftests
  Add function-tests.c
  gimple.c: add selftests
  Add hash-map-tests.c
  Add hash-set-tests.c
  input.c: add selftests
  Add rtl-tests.c
  tree.c: add selftests
  vec.c: add selftests
  wide-int.cc: add selftests

 gcc/Makefile.in  |  31 +-
 gcc/bitmap.c | 110 
 gcc/common.opt   |   4 +
 gcc/diagnostic-show-locus.c  | 156 ++
 gcc/et-forest.c  | 112 
 gcc/fold-const.c |  75 +++
 gcc/function-tests.c | 639 +++
 gcc/gimple.c | 119 +
 gcc/hash-map-tests.c |  88 
 gcc/hash-set-tests.c |  64 +++
 gcc/input.c  | 112 
 gcc/rtl-tests.c  | 108 
 gcc/selftest-run-tests.c |  77 +++
 gcc/selftest.c   |  49 ++
 gcc/selftest.h   | 153 ++
 gcc/spellcheck.c |  45 ++
 gcc/testsuite/gcc.dg/plugin/levenshtein-test-1.c |   9 -
 gcc/testsuite/gcc.dg/plugin/levenshtein_plugin.c |  64 ---
 gcc/testsuite/gcc.dg/plugin/plugin.exp   |   1 -
 gcc/toplev.c |  26 +
 gcc/toplev.h |   2 +
 gcc/tree-cfg.c   | 277 ++
 gcc/tree.c   |  60 +++
 gcc/vec.c| 162 ++
 gcc/wide-int.cc  | 152 ++
 25 files changed, 2616 insertions(+), 79 deletions(-)
 create mode 100644 gcc/function-tests.c
 create mode 100644 gcc/hash-map-tests.c
 create mode 100644 gcc/hash-set-tests.c
 create mode 100644 gcc/rtl-tests.c
 create mode 100644 gcc/selftest-run-tests.c
 create mode 100644 gcc/selftest.c
 create mode 100644 gcc/selftest.h
 delete mode 100644 gcc/testsuite/gcc.dg/plugin/levenshtein-test-1.c
 delete mode 100644 gcc/testsuite/gcc.dg/plugin/levenshtein_plugin.c

-- 
1.8.5.3



Re: [PATCH] Fix 416.gamess miscompare (PR71311)

2016-06-02 Thread Bernhard Reutner-Fischer
On June 2, 2016 9:05:36 PM GMT+02:00, Richard Biener  wrote:
>On June 2, 2016 7:47:19 PM GMT+02:00, Bernhard Reutner-Fischer
> wrote:
>>On June 1, 2016 9:37:26 AM GMT+02:00, Richard Biener
>> wrote:
>>
PR tree-optimization/71311
* genmatch.c (comparison_code_p): New predicate.
>>
>>TREE_CODE_CLASS (code) == tcc_comparison
>
>Only if I'd pull all of the tree stuff into the generator.

Ah, I thought this already was in there.



[PATCH, applied] Backport PowerPC ISA 3.0 C min/max support to GCC 6.2

2016-06-02 Thread Michael Meissner
I backported the changes for adding the ISA 3.0 C min/max and floating point
scalar compare generating a mask (for conditional move) to the GCC 6.2 branch.
The changes in this patch were checked into the trunk on May 25th (with one
patch from May 18th from a patch set that has not been backported yet).  I did
a bootstrap and make check, and there were no regresions.

[gcc]
2016-06-02  Michael Meissner  

Back port from trunk
2016-05-26  Michael Meissner  

* config/rs6000/rs6000.c (rs6000_emit_p9_fp_minmax): New function
for ISA 3.0 min/max support.
(rs6000_emit_p9_fp_cmove): New function for ISA 3.0 floating point
conditional move support.
(rs6000_emit_cmove): Call rs6000_emit_p9_fp_minmax and
rs6000_emit_p9_fp_cmove if the ISA 3.0 instructions are
available.
* config/rs6000/rs6000.md (SFDF2): New iterator to allow doing
conditional moves where the comparison type is different from move
type.
(fp_minmax): New code iterator for smin/smax.
(minmax): New code attributes for min/max.
(SMINMAX): Likewise.
(smax3): Combine min, max insns into one insn using the
fp_minmax code iterator.  Add support for ISA 3.0 min/max
instructions that don't need -ffast-math.
(s3): Likewise.
(smax3_vsx): Likewise.
(smin3): Likewise.
(s3_vsx): Likewise.
(smin3_vsx): Likewise.
(pre-VSX min/max splitters): Likewise.
(s3_fpr): Likewise.
(movsfcc): Rewrite floating point conditional moves to combine
SFmode/DFmode into a single insn.
(movcc): Likewise.
(movdfcc): Likewise.
(fselsfsf4): Combine FSEL cases into a single insn, using SFDF and
SFDF2 iterators to handle all combinations.
(fseldfsf4): Likewise.
(fsel4): Likewise.
(fseldfdf4): Likewise.
(fselsfdf4): Likewise.
(movcc_p9): Add support for the ISA 3.0
comparison instructions that set a 0/-1 mask, and use it for
floating point conditional move via XXSEL.
(fpmask): Likewise.
(xxsel): Likewise.
* config/rs6000/predicates.md (min_max_operator): Delete, no
longer used.
(fpmask_comparison_operaton): New insn for ISA 3.0 comparison
instructions that generate a 0/-1 mask for use with XXSEL.
* config/rs6000/rs6000.h (TARGET_MINMAX_SF): New helper macros to
say whether floating point min/max is available, either through
FSEL, ISA 2.06 min/max, and ISA 3.0 min/max instrucitons.
(TARGET_MINMAX_DF): Likewise.

Back port from trunk
2016-05-18  Michael Meissner  

* config/rs6000/predicate.md (all_ones_constant): New predicate
for vector constant with all 1's set.

[gcc/testsuite]
2016-06-02  Michael Meissner  

Back port from trunk
2016-05-26  Michael Meissner  

* gcc.target/powerpc/p9-minmax-1.c: New tests for ISA 3.0
floating point min/max/comparison instructions.
* gcc.target/powerpc/p9-minmax-2.c: Likewise.


-- 
Michael Meissner, IBM
IBM, M/S 2506R, 550 King Street, Littleton, MA 01460-6245, USA
email: meiss...@linux.vnet.ibm.com, phone: +1 (978) 899-4797



[PATCH] Fix cgraph edge redirection with non-POD lhs (PR middle-end/71387)

2016-06-02 Thread Jakub Jelinek
Hi!

Apparently my r236430 change (trunk) and r236431 (6.x) broke the following
testcase.  In the later similar change to gimple-fold.c in r236506
I've added code to tweak gimple_call_fntype if we have newly one of the
void something (void) __attribute__((noreturn)) functions like
__builtin_unreachable or __cxa_pure_virtual, and drop the lhs even if it
has been before non-POD, but the new fntype has void return type,
but apparently we need to do the same in cgraph.c as well.

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

2016-06-02  Jakub Jelinek  

PR middle-end/71387
* cgraph.c (cgraph_edge::redirect_call_stmt_to_callee): If redirecting
to noreturn e->callee->decl that has void return type and void
arguments, adjust gimple_call_fntype and remove lhs even if it had
previously addressable type.

* g++.dg/opt/pr71387.C: New test.

--- gcc/cgraph.c.jj 2016-05-26 10:37:54.0 +0200
+++ gcc/cgraph.c2016-06-02 17:17:58.963052785 +0200
@@ -1512,8 +1512,20 @@ cgraph_edge::redirect_call_stmt_to_calle
   update_stmt_fn (DECL_STRUCT_FUNCTION (e->caller->decl), new_stmt);
 }
 
+  /* If changing the call to __cxa_pure_virtual or similar noreturn function,
+ adjust gimple_call_fntype too.  */
+  if (gimple_call_noreturn_p (new_stmt)
+  && VOID_TYPE_P (TREE_TYPE (TREE_TYPE (e->callee->decl)))
+  && TYPE_ARG_TYPES (TREE_TYPE (e->callee->decl))
+  && (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (e->callee->decl)))
+ == void_type_node))
+gimple_call_set_fntype (new_stmt, TREE_TYPE (e->callee->decl));
+
   /* If the call becomes noreturn, remove the LHS if possible.  */
-  if (gimple_call_noreturn_p (new_stmt) && should_remove_lhs_p (lhs))
+  if (lhs
+  && gimple_call_noreturn_p (new_stmt)
+  && (VOID_TYPE_P (TREE_TYPE (gimple_call_fntype (new_stmt)))
+ || should_remove_lhs_p (lhs)))
 {
   if (TREE_CODE (lhs) == SSA_NAME)
{
--- gcc/testsuite/g++.dg/opt/pr71387.C.jj   2016-06-02 17:37:59.868769557 
+0200
+++ gcc/testsuite/g++.dg/opt/pr71387.C  2016-06-02 17:23:51.0 +0200
@@ -0,0 +1,52 @@
+// PR middle-end/71387
+// { dg-do compile }
+// { dg-options "-Og" }
+
+struct A
+{
+  A ();
+  inline A (const A &);
+};
+
+struct B
+{
+  explicit B (unsigned long) : b(0), c(1) {}
+  A a;
+  unsigned long b;
+  int c;
+};
+
+struct C {};
+
+struct D
+{
+  explicit D (const C *) {}
+};
+
+struct E : public D
+{
+  E (const C *x) : D(x) {}
+  virtual A foo () const = 0;
+  virtual A bar () const = 0;
+};
+
+struct F : public B
+{
+  inline void baz ();
+  F (const E *);
+  const E *f;
+};
+
+inline void
+F::baz ()
+{
+  if (b == 0)
+a = f->bar ();
+  else
+a = f->foo ();
+}
+
+F::F (const E *) : B(4)
+{
+  baz ();
+}

Jakub


Re: [PATCH] Fix 416.gamess miscompare (PR71311)

2016-06-02 Thread Richard Biener
On June 2, 2016 7:47:19 PM GMT+02:00, Bernhard Reutner-Fischer 
 wrote:
>On June 1, 2016 9:37:26 AM GMT+02:00, Richard Biener
> wrote:
>
>>> PR tree-optimization/71311
>>> * genmatch.c (comparison_code_p): New predicate.
>
>TREE_CODE_CLASS (code) == tcc_comparison

Only if I'd pull all of the tree stuff into the generator.

Richard.

>?
>thanks,




Re: [PATCH] x86 interrupt attribute patch [2/2]

2016-06-02 Thread Sandra Loosemore

On 06/01/2016 08:19 AM, Koval, Julia wrote:


diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi
index 2d4f028..3e6a796 100644
--- a/gcc/doc/extend.texi
+++ b/gcc/doc/extend.texi
@@ -5266,6 +5266,79 @@ On x86-32 targets, the @code{stdcall} attribute causes 
the compiler to
 assume that the called function pops off the stack space used to
 pass arguments, unless it takes a variable number of arguments.

+@item no_caller_saved_registers
+@cindex @code{no_caller_saved_registers} function attribute, x86
+Use this attribute to indicate that the specified function has no
+caller-saved registers. That is, all registers are callee-saved. For
+example, this attribute can be used for a function, called from an


s/function,/function/

The documentation parts are OK with that change.

-Sandra



[Patch, fortran] PR70350 - [5 Regression] ICE with -fcheck=all and array initialization

2016-06-02 Thread Paul Richard Thomas
Dear All,

I just backported the fix for this as revision 237043. This was fixed
on 6-branch, when it was trunk, as r232850.

I apologise for not doing this much earlier but, as the fortran list
knows, life outside gfortran has intervened big-time over the last few
months.

I did not add a testcase, since the likelihood of any further fortran
patches to 5.3.1 causing a regression here is essentially zero.

Cheers

Paul


Re: [PATCH] Fix 416.gamess miscompare (PR71311)

2016-06-02 Thread Bernhard Reutner-Fischer
On June 1, 2016 9:37:26 AM GMT+02:00, Richard Biener  wrote:

>>  PR tree-optimization/71311
>>  * genmatch.c (comparison_code_p): New predicate.

TREE_CODE_CLASS (code) == tcc_comparison

?
thanks,




[RFC: Patch 6/6] Remove second cost model from noce_try_store_flag_mask

2016-06-02 Thread James Greenhalgh

Hi,

This transformation tries two cost models, one estimating the number
of insns to use, one estimating the RTX cost of the transformed sequence.
This is inconsistent with the other cost models used in ifcvt.c and
unnecessary - eliminate the second cost model.

Thanks,
James

---
2016-06-02  James Greenhalgh  

* ifcvt.c (noce_try_store_flag_mask): Delete redundant cost model.

diff --git a/gcc/ifcvt.c b/gcc/ifcvt.c
index f71889e..6e9997e 100644
--- a/gcc/ifcvt.c
+++ b/gcc/ifcvt.c
@@ -1670,8 +1670,8 @@ noce_try_store_flag_mask (struct noce_if_info *if_info)
 
   reversep = 0;
 
-  /* Two insns, AND, NEG.  */
-  if ((noce_estimate_conversion_profitable_p (if_info, 2)
+  /* One insn, AND.  */
+  if ((noce_estimate_conversion_profitable_p (if_info, 1)
|| STORE_FLAG_VALUE == -1)
   && ((if_info->a == const0_rtx
 	   && rtx_equal_p (if_info->b, if_info->x))
@@ -1693,9 +1693,6 @@ noce_try_store_flag_mask (struct noce_if_info *if_info)
 
   if (target)
 	{
-	  int old_cost, new_cost, insn_cost;
-	  int speed_p;
-
 	  if (target != if_info->x)
 	noce_emit_move_insn (if_info->x, target);
 
@@ -1703,15 +1700,6 @@ noce_try_store_flag_mask (struct noce_if_info *if_info)
 	  if (!seq)
 	return FALSE;
 
-	  speed_p = optimize_bb_for_speed_p (BLOCK_FOR_INSN (if_info->insn_a));
-	  insn_cost = insn_rtx_cost (PATTERN (if_info->insn_a), speed_p);
-	  /* TODO: Revisit this cost model.  */
-	  old_cost = if_info->rtx_edge_cost + insn_cost;
-	  new_cost = seq_cost (seq, speed_p);
-
-	  if (new_cost > old_cost)
-	return FALSE;
-
 	  emit_insn_before_setloc (seq, if_info->jump,
    INSN_LOCATION (if_info->insn_a));
 	  return TRUE;


[RFC: Patch 3/6] Remove if_info->branch_cost

2016-06-02 Thread James Greenhalgh

Hi,

This patch removes what is left of branch_cost uses, moving them to use
the new hook and tagging each left over spot with a TODO to revisit them.
All these uses are in rtx costs units, so we don't have more work to do at
this point.

OK?

Thanks,
James

---
2016-06-02  James Greenhalgh  

* ifcvt.c (noce_if_info): Remove branch_cost.
(noce_try_store_flag_mask): Use rtx_edge_cost rather than
branch_cost, tag as a TODO..
(noce_try_cmove_arith): Likewise.
(noce_convert_multiple_sets): Likewise.
(bb_ok_for_noce_convert_multiple_sets): Likewise.
(noce_find_if_block): Remove set of branch_cost.

diff --git a/gcc/ifcvt.c b/gcc/ifcvt.c
index 22cb5e7..b192c85 100644
--- a/gcc/ifcvt.c
+++ b/gcc/ifcvt.c
@@ -812,7 +812,6 @@ struct noce_if_info
   unsigned int else_cost;
 
   /* Estimated cost of the particular branch instruction.  */
-  unsigned int branch_cost;
   unsigned int rtx_edge_cost;
 };
 
@@ -1634,7 +1633,8 @@ noce_try_store_flag_mask (struct noce_if_info *if_info)
 
 	  speed_p = optimize_bb_for_speed_p (BLOCK_FOR_INSN (if_info->insn_a));
 	  insn_cost = insn_rtx_cost (PATTERN (if_info->insn_a), speed_p);
-	  old_cost = COSTS_N_INSNS (if_info->branch_cost) + insn_cost;
+	  /* TODO: Revisit this cost model.  */
+	  old_cost = if_info->rtx_edge_cost + insn_cost;
 	  new_cost = seq_cost (seq, speed_p);
 
 	  if (new_cost > old_cost)
@@ -2105,7 +2105,9 @@ noce_try_cmove_arith (struct noce_if_info *if_info)
 
   /* We're going to execute one of the basic blocks anyway, so
  bail out if the most expensive of the two blocks is unacceptable.  */
-  if (MAX (then_cost, else_cost) > COSTS_N_INSNS (if_info->branch_cost))
+
+  /* TODO: Revisit cost model.  */
+  if (MAX (then_cost, else_cost) > if_info->rtx_edge_cost)
 return FALSE;
 
   /* Possibly rearrange operands to make things come out more natural.  */
@@ -3280,8 +3282,8 @@ noce_convert_multiple_sets (struct noce_if_info *if_info)
of conditional moves.  FORNOW: Use II to find the expected cost of
the branch into/over TEST_BB.
 
-   TODO: This creates an implicit "magic number" for branch_cost.
-   II->branch_cost now guides the maximum number of set instructions in
+   TODO: This creates an implicit "magic number" for if conversion.
+   II->rtx_edge_cost now guides the maximum number of set instructions in
a basic block which is considered profitable to completely
if-convert.  */
 
@@ -3292,7 +3294,8 @@ bb_ok_for_noce_convert_multiple_sets (basic_block test_bb,
   rtx_insn *insn;
   unsigned count = 0;
   unsigned param = PARAM_VALUE (PARAM_MAX_RTL_IF_CONVERSION_INSNS);
-  unsigned limit = MIN (ii->branch_cost, param);
+  /* TODO:  Revisit this cost model.  */
+  unsigned limit = MIN (ii->rtx_edge_cost / COSTS_N_INSNS (1), param);
 
   FOR_BB_INSNS (test_bb, insn)
 {
@@ -3993,8 +3996,6 @@ noce_find_if_block (basic_block test_bb, edge then_edge, edge else_edge,
   if_info.cond_earliest = cond_earliest;
   if_info.jump = jump;
   if_info.then_else_reversed = then_else_reversed;
-  if_info.branch_cost = BRANCH_COST (optimize_bb_for_speed_p (test_bb),
- predictable_edge_p (then_edge));
   if_info.rtx_edge_cost
 = targetm.rtx_branch_cost (optimize_bb_for_speed_p (test_bb),
 			   predictable_edge_p (then_edge));


[RFC: Patch 2/6] Factor out the comparisons against magic numbers in ifcvt

2016-06-02 Thread James Greenhalgh

Hi,

This patch pulls the comparisons between if_info->branch_cost and a magic
number representing an instruction count to a common function. While I'm
doing it, I've documented the instructions that the magic numbers relate
to, and updated them where they were inconsistent.

If our measure of the cost of a branch is now in rtx costs units, we can
get to an estimate for the cost of an expression from the number of
instructions by multiplying through by COSTS_N_INSNS (1).

This isn't the great revolution in ifcvt costs I hoped for when I sat down
to take on the work. But, it looks like the best I can do short of
constructing ADD and SUB rtx all over the place just to get back a
judgement from the target that they are "cheap". The nicest thing about
doing it this way is that it mostly preserves behaviour, and by factoring
it out we have an upgrade path to a more detailed cost model should we want
it.

OK?

Thanks,
James

---

2016-06-02  James Greenhalgh  

* ifcvt.c (noce_if_info): New field: rtx_edge_cost.
(noce_estimate_conversion_profitable_p): New.
(noce_try_store_flag_constants): Use it.
(noce_try_addcc): Likewise.
(noce_try_store_flag_mask): Likewise.
(noce_try_cmove): Likewise.
(noce_try_cmove_arith): Likewise.
(noce_find_if_block): Record targetm.rtx_edge_cost.

diff --git a/gcc/ifcvt.c b/gcc/ifcvt.c
index 44ae020..22cb5e7 100644
--- a/gcc/ifcvt.c
+++ b/gcc/ifcvt.c
@@ -813,6 +813,7 @@ struct noce_if_info
 
   /* Estimated cost of the particular branch instruction.  */
   unsigned int branch_cost;
+  unsigned int rtx_edge_cost;
 };
 
 static rtx noce_emit_store_flag (struct noce_if_info *, rtx, int, int);
@@ -830,6 +831,17 @@ static int noce_try_minmax (struct noce_if_info *);
 static int noce_try_abs (struct noce_if_info *);
 static int noce_try_sign_mask (struct noce_if_info *);
 
+/* This function is always called when we would expand a number of "cheap"
+   instructions.  Multiply NINSNS by COSTS_N_INSNS (1) to approximate the
+   RTX cost of those cheap instructions.  */
+
+inline static bool
+noce_estimate_conversion_profitable_p (struct noce_if_info *if_info,
+   unsigned int ninsns)
+{
+  return (if_info->rtx_edge_cost >= ninsns * COSTS_N_INSNS (1));
+}
+
 /* Helper function for noce_try_store_flag*.  */
 
 static rtx
@@ -1279,7 +1291,8 @@ noce_try_store_flag_constants (struct noce_if_info *if_info)
   && (REG_P (XEXP (a, 0))
 	  || (noce_operand_ok (XEXP (a, 0))
 	  && ! reg_overlap_mentioned_p (if_info->x, XEXP (a, 0
-  && if_info->branch_cost >= 2)
+  /* We need one instruction, the ADD of the store flag.  */
+  && noce_estimate_conversion_profitable_p (if_info, 1))
 {
   common = XEXP (a, 0);
   a = XEXP (a, 1);
@@ -1352,22 +1365,32 @@ noce_try_store_flag_constants (struct noce_if_info *if_info)
 	  else
 	gcc_unreachable ();
 	}
+  /* Is this (cond) ? 2^n : 0?  */
   else if (ifalse == 0 && exact_log2 (itrue) >= 0
 	   && (STORE_FLAG_VALUE == 1
-		   || if_info->branch_cost >= 2))
+		   /* We need ASHIFT, IOR.   */
+		   || noce_estimate_conversion_profitable_p (if_info, 2)))
 	normalize = 1;
+  /* Is this (cond) ? 0 : 2^n?  */
   else if (itrue == 0 && exact_log2 (ifalse) >= 0 && can_reverse
-	   && (STORE_FLAG_VALUE == 1 || if_info->branch_cost >= 2))
+	   && (STORE_FLAG_VALUE == 1
+		   /* We need ASHIFT, IOR.  */
+		   || noce_estimate_conversion_profitable_p (if_info, 2)))
 	{
 	  normalize = 1;
 	  reversep = true;
 	}
+  /* Is this (cond) ? -1 : x?  */
   else if (itrue == -1
 	   && (STORE_FLAG_VALUE == -1
-		   || if_info->branch_cost >= 2))
+		   /* Just an IOR.  */
+		   || noce_estimate_conversion_profitable_p (if_info, 1)))
 	normalize = -1;
+  /* Is this (cond) ? x : -1?  */
   else if (ifalse == -1 && can_reverse
-	   && (STORE_FLAG_VALUE == -1 || if_info->branch_cost >= 2))
+	   && (STORE_FLAG_VALUE == -1
+		   /* Just an IOR.  */
+		   || noce_estimate_conversion_profitable_p (if_info, 1)))
 	{
 	  normalize = -1;
 	  reversep = true;
@@ -1519,8 +1542,8 @@ noce_try_addcc (struct noce_if_info *if_info)
 	}
 
   /* If that fails, construct conditional increment or decrement using
-	 setcc.  */
-  if (if_info->branch_cost >= 2
+	 setcc.  We'd only need an ADD/SUB for this.  */
+  if (noce_estimate_conversion_profitable_p (if_info, 1)
 	  && (XEXP (if_info->a, 1) == const1_rtx
 	  || XEXP (if_info->a, 1) == constm1_rtx))
 {
@@ -1575,7 +1598,9 @@ noce_try_store_flag_mask (struct noce_if_info *if_info)
 return FALSE;
 
   reversep = 0;
-  if ((if_info->branch_cost >= 2
+
+  /* Two insns, AND, NEG.  */
+  if ((noce_estimate_conversion_profitable_p (if_info, 2)
|| STORE_FLAG_VALUE == -1)
   && ((if_info->a == const0_rtx
 	   && rtx_equal_p (if_info->b, if_info->x))
@@ -1778,8 +1803,11 @@ noce_try_cmove (struct noce_if_info *if_info)
 	 approach.  

[RFC: Patch 5/6] Improve the cost model for multiple-sets

2016-06-02 Thread James Greenhalgh

Hi,

This patch is a small rewrite to the cost model for
bb_ok_for_noce_multiple_sets to use the new noce_cmove_estimate_cost
function added in the previous patches.

Thanks,
James

---
2016-06-02  James Greenhalgh  

* ifcvt.c (bb_of_for_noce_convert_multiple_sets): Change cost model.

diff --git a/gcc/ifcvt.c b/gcc/ifcvt.c
index bd3f55d..f71889e 100644
--- a/gcc/ifcvt.c
+++ b/gcc/ifcvt.c
@@ -3373,12 +3373,7 @@ noce_convert_multiple_sets (struct noce_if_info *if_info)
 /* Return true iff basic block TEST_BB is comprised of only
(SET (REG) (REG)) insns suitable for conversion to a series
of conditional moves.  FORNOW: Use II to find the expected cost of
-   the branch into/over TEST_BB.
-
-   TODO: This creates an implicit "magic number" for if conversion.
-   II->rtx_edge_cost now guides the maximum number of set instructions in
-   a basic block which is considered profitable to completely
-   if-convert.  */
+   the branch into/over TEST_BB.  */
 
 static bool
 bb_ok_for_noce_convert_multiple_sets (basic_block test_bb,
@@ -3387,8 +3382,11 @@ bb_ok_for_noce_convert_multiple_sets (basic_block test_bb,
   rtx_insn *insn;
   unsigned count = 0;
   unsigned param = PARAM_VALUE (PARAM_MAX_RTL_IF_CONVERSION_INSNS);
-  /* TODO:  Revisit this cost model.  */
-  unsigned limit = MIN (ii->rtx_edge_cost / COSTS_N_INSNS (1), param);
+  unsigned cost_limit = ii->rtx_edge_cost;
+  unsigned cost = 0;
+  bool speed_p = optimize_bb_for_speed_p (ii->test_bb);
+  rtx_code code = GET_CODE (ii->cond);
+  machine_mode cmode = GET_MODE (XEXP (ii->cond, 0));
 
   FOR_BB_INSNS (test_bb, insn)
 {
@@ -3404,6 +3402,9 @@ bb_ok_for_noce_convert_multiple_sets (basic_block test_bb,
   rtx dest = SET_DEST (set);
   rtx src = SET_SRC (set);
 
+  cost += noce_cmove_estimate_cost (cmode, GET_MODE (dest),
+	code, speed_p);
+
   /* We can possibly relax this, but for now only handle REG to REG
 	 moves.  This avoids any issues that might come from introducing
 	 loads/stores that might violate data-race-freedom guarantees.  */
@@ -3418,14 +3419,14 @@ bb_ok_for_noce_convert_multiple_sets (basic_block test_bb,
   if (!can_conditionally_move_p (GET_MODE (dest)))
 	return false;
 
-  /* FORNOW: Our cost model is a count of the number of instructions we
-	 would if-convert.  This is suboptimal, and should be improved as part
-	 of a wider rework of branch_cost.  */
-  if (++count > limit)
-	return false;
+  count++;
 }
 
-  return count > 1;
+  /* If we would only put out one conditional move, the other strategies
+ this pass tries are better optimized and will be more appropriate.
+ If the cost in instructions is higher than the limit we've imposed,
+ also give up.  */
+  return (count > 1 && cost <= cost_limit && count <= param);
 }
 
 /* Given a simple IF-THEN-JOIN or IF-THEN-ELSE-JOIN block, attempt to convert


[RFC: Patch 0/6] Rewrite the noce-ifcvt cost models

2016-06-02 Thread James Greenhalgh
Hi,

When I was working in the area last year, I promised to revisit the cost
model for noce if-conversion and see if I could improve the modeling. This
turned out to be more tricky than I expected.

This patch set rewrites the cost model for noce if-conversion. The goal is
to rationalise the units used in the calculations away from BRANCH_COST,
which is only defined relative to itself.

I've introduced a new target hook "rtx_branch_cost" which is defined to return
the cost of a branch in RTX cost units, suitable for comparing directly with
the calculated cost of a conditional move, or the conditionally executed
branches.

If you're looking at that and thinking it doesn't sound much different from
our current call to BRANCH_COST, you're right. This isn't as large a
departure from the existing cost model as I had originally intended. I
started out experimenting with much larger hooks (with many
parameters/pass-specific data), or hooks that passed the whole edge to
the target asking for the cost. These ended up feeling quite silly
to write in the target, and don't match with the direction discussed at
last year's cauldron. We don't want to go around leaking pass-internal
data around to back-ends. That is a path of madness as the passes change but
find that targets have invented baroque calculations to help invent a
magic number.

I tried implementing a "replacement_cost" hook, which would take before
and after code sequences and try to guess profitability, but because you
want to take edge probabilities in to consideration while trying to calculate
the costs of an if-then-else structure, the code gets hairy quickly. Worse
is that this would need duplicating across any target implementing the
hook. I found that I was constructing lots of RTX just to throw it away
again, and sometimes we were constructing RTX that would trivially be
optimised by a future pass. As a metric for if-conversion, this hook
seemed more harmful than useful for both the quality of the decision we'd
make, and for the quality of the GCC source.

As I iterated through versions of this patch set, I realised that all we
really wanted for ifcvt was a way to estimate the cost of a branch in units
that were comparable to the cost of instructions. The trouble with BRANCH_COST
wasn't that it was returning a magic number, it was just that it was returning
a magic number which had inconsistent meanings in the compiler. Otherwise,
BRANCH_COST was a straightforward, low-complexity target hook.

So the new hook simply defines the relative units that it will use and
splits off the use in ifcvt from other BRANCH_COST calls.

Having introduced the hook, and added some framework to make use of it, the
rest of the patch set works through each of the cost models in ifcvt.c,
makes them consistent, and moves them to the new hook.

This act of making the cost models consistent will cause code generation
changes on a number of targets - most notably x86_64. On x86_64 the RTX
cost of a conditional move comes out at "20" - this is far higher than
COSTS_N_INSNS (BRANCH_COST) for the x86 targets, so they lose lots
of if-conversion. The easy fix for this would be to implement the new hook.
I measured the performance impact on Spec2000 as a smoke test, it didn't
seem to harm anything, and the result was a slight (< 3%) uplift on
Spec2000FP. I'm no expert on x86_64, so I haven't taken a closer look for
the reasons.

Having worked through the patch set, I'd say it is probably a small
improvement over what we currently do, but I'm not very happy with it. I'm
posting it for comment so we can discuss any directions for costs that I
haven't thought about or prototyped. I'm also happy to drop the costs
rewrite if this seems like complexity for no benefit.

Any thoughts?

I've bootstrapped and tested the patch set on x86_64 and aarch64, but
they probably need some further polishing if we were to decide this was a
useful direction.

Thanks,
James

James Greenhalgh (6):
  [RFC: Patch 1/6] New target hook: rtx_branch_cost
  [RFC: Patch 2/6] Factor out the comparisons against magic numbers in
ifcvt
  [RFC: Patch 3/6] Remove if_info->branch_cost
  [RFC: Patch 4/6] Modify cost model for noce_cmove_arith
  [RFC: Patch 5/6] Improve the cost model for multiple-sets
  [RFC: Patch 6/6] Remove second cost model from
noce_try_store_flag_mask

 gcc/doc/tm.texi|  10 +++
 gcc/doc/tm.texi.in |   2 +
 gcc/ifcvt.c| 204 +
 gcc/target.def |  14 
 gcc/targhooks.c|  10 +++
 gcc/targhooks.h|   2 +
 6 files changed, 197 insertions(+), 45 deletions(-)



[RFC: Patch 4/6] Modify cost model for noce_cmove_arith

2016-06-02 Thread James Greenhalgh

Hi,

This patch clears up the cost model for noce_try_cmove_arith. We lose
the "??? FIXME: Magic number 5" comment, and gain a more realistic cost
model for if-converting memory accesses.

This is the patch that will cause the largest behavioural change for most
targets - the current heuristic does not take in to consideration the cost
of a conditional move - once we add that the cost of the converted sequence
often looks much higher than (BRANCH_COST * COSTS_N_INSNS (1)).

I think that missing the cost of the conditional move from these sequences
is not a good idea, and that the cost model should rely on the target giving
back good information. A target that finds tests failing after this patch
should consider either reducing the cost of a conditional move sequence, or
increasing TARGET_RTX_BRANCH_COST.

OK?

Thanks,
James

---
gcc/

2016-06-02  James Greenhalgh  

* ifcvt.c (noce_code_is_comparison_p): New.
(noce_cmove_cost): Likewise.
(noce_try_cmove_arith): Use it.

diff --git a/gcc/ifcvt.c b/gcc/ifcvt.c
index b192c85..bd3f55d 100644
--- a/gcc/ifcvt.c
+++ b/gcc/ifcvt.c
@@ -830,6 +830,78 @@ static int noce_try_minmax (struct noce_if_info *);
 static int noce_try_abs (struct noce_if_info *);
 static int noce_try_sign_mask (struct noce_if_info *);
 
+/* Return TRUE if CODE is an RTX comparison operator.  */
+
+static bool
+noce_code_is_comparison_p (rtx_code code)
+{
+  switch (code)
+{
+case NE:
+case EQ:
+case GE:
+case GT:
+case LE:
+case LT:
+case GEU:
+case GTU:
+case LEU:
+case LTU:
+case UNORDERED:
+case ORDERED:
+case UNEQ:
+case UNGE:
+case UNGT:
+case UNLE:
+case UNLT:
+case LTGT:
+  return true;
+default:
+  return false;
+}
+}
+
+/* Return the estimated cost of a single conditional move, where the
+   condition is calculated using the COMPARISON operator in mode CMODE,
+   and the store is in mode SMODE, depending on whether we are compiling
+   for SPEED_P.  */
+
+static unsigned int
+noce_cmove_estimate_cost (machine_mode cmode, machine_mode smode,
+			  rtx_code comparison, bool speed_p)
+{
+  unsigned int cost = 0;
+
+  gcc_checking_assert (noce_code_is_comparison_p (comparison));
+
+  start_sequence ();
+
+  /* We're only estimating, so we don't need to be too cautious about
+ getting the operands correct, but we would like an estimate.  We
+ do need at least two registers, to avoid the comparison being
+ folded.  */
+  rtx creg = gen_reg_rtx (cmode);
+  rtx creg2 = gen_reg_rtx (cmode);
+  rtx sreg = gen_reg_rtx (smode);
+  rtx sreg2 = gen_reg_rtx (smode);
+  rtx dest = emit_conditional_move (sreg, comparison, creg, creg2,
+cmode, sreg, sreg2, smode, false);
+  if (!dest)
+{
+  /* Set something suitably high in here, as our best guess
+	 is that the if-conversion will fail.  */
+  cost = COSTS_N_INSNS (32);
+}
+  else
+{
+  rtx_insn *seq = get_insns ();
+  cost = seq_cost (seq, speed_p);
+}
+  end_sequence ();
+
+  return cost;
+}
+
 /* This function is always called when we would expand a number of "cheap"
instructions.  Multiply NINSNS by COSTS_N_INSNS (1) to approximate the
RTX cost of those cheap instructions.  */
@@ -2040,7 +2112,8 @@ noce_try_cmove_arith (struct noce_if_info *if_info)
   rtx a = if_info->a;
   rtx b = if_info->b;
   rtx x = if_info->x;
-  rtx orig_a, orig_b;
+  rtx orig_a = a;
+  rtx orig_b = b;
   rtx_insn *insn_a, *insn_b;
   bool a_simple = if_info->then_simple;
   bool b_simple = if_info->else_simple;
@@ -2050,16 +2123,15 @@ noce_try_cmove_arith (struct noce_if_info *if_info)
   int is_mem = 0;
   enum rtx_code code;
   rtx_insn *ifcvt_seq;
+  bool speed_p = optimize_bb_for_speed_p (if_info->test_bb);
 
   /* A conditional move from two memory sources is equivalent to a
  conditional on their addresses followed by a load.  Don't do this
  early because it'll screw alias analysis.  Note that we've
  already checked for no side effects.  */
-  /* ??? FIXME: Magic number 5.  */
   if (cse_not_expected
   && MEM_P (a) && MEM_P (b)
-  && MEM_ADDR_SPACE (a) == MEM_ADDR_SPACE (b)
-  && noce_estimate_conversion_profitable_p (if_info, 5))
+  && MEM_ADDR_SPACE (a) == MEM_ADDR_SPACE (b))
 {
   machine_mode address_mode = get_address_mode (a);
 
@@ -2087,6 +2159,7 @@ noce_try_cmove_arith (struct noce_if_info *if_info)
   insn_b = if_info->insn_b;
 
   machine_mode x_mode = GET_MODE (x);
+  machine_mode cmode = GET_MODE (XEXP (if_info->cond, 0));
 
   if (!can_conditionally_move_p (x_mode))
 return FALSE;
@@ -2103,12 +2176,32 @@ noce_try_cmove_arith (struct noce_if_info *if_info)
   else
 else_cost = 0;
 
-  /* We're going to execute one of the basic blocks anyway, so
- bail out if the most expensive of the two blocks is unacceptable.  */
+  if (!is_mem)
+{
+  /* If convert in the case that:
+
+	 then_cost + else_cost + 

[RFC: Patch 1/6] New target hook: rtx_branch_cost

2016-06-02 Thread James Greenhalgh

Hi,

This patch introduces a new target hook, to be used like BRANCH_COST but
with a guaranteed unit of measurement. We want this to break away from
the current ambiguous uses of BRANCH_COST.

BRANCH_COST is used in ifcvt.c in two types of comparisons. One against
instruction counts - where it is used as the limit on the number of new
instructions we are permitted to generate. The other (after multiplying
by COSTS_N_INSNS (1)) directly against RTX costs.

Of these, a comparison against RTX costs is the more easily understood
metric across the compiler, and the one I've pulled out to the new hook.
To keep things consistent for targets which don't migrate, this new hook
has a default value of BRANCH_COST * COSTS_N_INSNS (1).

OK?

Thanks,
James

---
2016-06-02  James Greenhalgh  

* target.def (rtx_branch_cost): New.
* doc/tm.texi.in (TARGET_RTX_BRANCH_COST): Document it.
* doc/tm.texi: Regenerate.
* targhooks.h (default_rtx_branch_cost): New.
* targhooks.c (default_rtx_branch_cost): New.
diff --git a/gcc/doc/tm.texi b/gcc/doc/tm.texi
index 8c7f2a1..32efa1f 100644
--- a/gcc/doc/tm.texi
+++ b/gcc/doc/tm.texi
@@ -6499,6 +6499,16 @@ should probably only be given to addresses with different numbers of
 registers on machines with lots of registers.
 @end deftypefn
 
+@deftypefn {Target Hook} {unsigned int} TARGET_RTX_BRANCH_COST (bool @var{speed_p}, bool @var{predictable_p})
+This hook should return a cost in the same units as
+  @code{TARGET_RTX_COSTS}, giving the estimated cost of a branch.
+  @code{speed_p} is true if we are compiling for speed.
+  @code{predictable_p} is true if analysis suggests that the branch
+  will be predictable.  The default implementation of this hook
+  multiplies @code{BRANCH_COST} by the cost of a cheap instruction to
+  approximate the cost of a branch in the appropriate units.
+@end deftypefn
+
 @deftypefn {Target Hook} bool TARGET_NO_SPECULATION_IN_DELAY_SLOTS_P (void)
 This predicate controls the use of the eager delay slot filler to disallow
 speculatively executed instructions being placed in delay slots.  Targets
diff --git a/gcc/doc/tm.texi.in b/gcc/doc/tm.texi.in
index f963a58..92461b0 100644
--- a/gcc/doc/tm.texi.in
+++ b/gcc/doc/tm.texi.in
@@ -4748,6 +4748,8 @@ Define this macro if a non-short-circuit operation produced by
 
 @hook TARGET_ADDRESS_COST
 
+@hook TARGET_RTX_BRANCH_COST
+
 @hook TARGET_NO_SPECULATION_IN_DELAY_SLOTS_P
 
 @node Scheduling
diff --git a/gcc/target.def b/gcc/target.def
index 6392e73..f049a8b 100644
--- a/gcc/target.def
+++ b/gcc/target.def
@@ -3559,6 +3559,20 @@ registers on machines with lots of registers.",
  int, (rtx address, machine_mode mode, addr_space_t as, bool speed),
  default_address_cost)
 
+/* Give a cost, in RTX Costs units, for an edge.  Like BRANCH_COST, but with
+   well defined units.  */
+DEFHOOK
+(rtx_branch_cost,
+ "This hook should return a cost in the same units as\n\
+  @code{TARGET_RTX_COSTS}, giving the estimated cost of a branch.\n\
+  @code{speed_p} is true if we are compiling for speed.\n\
+  @code{predictable_p} is true if analysis suggests that the branch\n\
+  will be predictable.  The default implementation of this hook\n\
+  multiplies @code{BRANCH_COST} by the cost of a cheap instruction to\n\
+  approximate the cost of a branch in the appropriate units.",
+  unsigned int, (bool speed_p, bool predictable_p),
+  default_rtx_branch_cost)
+
 /* Permit speculative instructions in delay slots during delayed-branch 
scheduling.  */
 DEFHOOK
diff --git a/gcc/targhooks.c b/gcc/targhooks.c
index 6b4601b..dcffeb8 100644
--- a/gcc/targhooks.c
+++ b/gcc/targhooks.c
@@ -74,6 +74,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "intl.h"
 #include "opts.h"
 #include "gimplify.h"
+#include "predict.h"
 
 
 bool
@@ -1965,4 +1966,13 @@ default_optab_supported_p (int, machine_mode, machine_mode, optimization_type)
   return true;
 }
 
+/* Default implementation of TARGET_RTX_BRANCH_COST.  */
+
+unsigned int
+default_rtx_branch_cost (bool speed_p,
+			 bool predictable_p)
+{
+  return BRANCH_COST (speed_p, predictable_p) * COSTS_N_INSNS (1);
+}
+
 #include "gt-targhooks.h"
diff --git a/gcc/targhooks.h b/gcc/targhooks.h
index 7687c39..b7ff94c 100644
--- a/gcc/targhooks.h
+++ b/gcc/targhooks.h
@@ -254,4 +254,6 @@ extern void default_setup_incoming_vararg_bounds (cumulative_args_t ca ATTRIBUTE
 extern bool default_optab_supported_p (int, machine_mode, machine_mode,
    optimization_type);
 
+extern unsigned int default_rtx_branch_cost (bool, bool);
+
 #endif /* GCC_TARGHOOKS_H */


Re: [PR middle-end/71373] Handle more OMP_CLAUSE_* in nested function decomposition

2016-06-02 Thread Jakub Jelinek
On Thu, Jun 02, 2016 at 06:20:57PM +0200, Thomas Schwinge wrote:
> relevant.  Nested function decomposition is not applicable to C++, so we
> don't need any C++ test cases, right?

C++ has lambdas, but those are already lowered in the FE, so yes,
from the OpenMP/OpenACC FEs, tree-nested.c is only used by C and Fortran.

> [PR middle-end/71373] Handle more OMP_CLAUSE_* in nested function 
> decomposition
> 
>   gcc/
>   * gimplify.c (gimplify_adjust_omp_clauses): Discard
>   OMP_CLAUSE_TILE.
>   * omp-low.c (scan_sharing_clauses): Don't expect OMP_CLAUSE_TILE.
>   gcc/testsuite/
>   * c-c++-common/goacc/combined-directives.c: XFAIL tree scanning
>   for OpenACC tile clauses.
>   * gfortran.dg/goacc/combined-directives.f90: Likewise.
> 
>   gcc/
>   PR middle-end/71373
>   * tree-nested.c (convert_nonlocal_omp_clauses)
>   (convert_local_omp_clauses): Handle OMP_CLAUSE_ASYNC,
>   OMP_CLAUSE_WAIT, OMP_CLAUSE_INDEPENDENT, OMP_CLAUSE_AUTO,
>   OMP_CLAUSE__CACHE_, OMP_CLAUSE_TILE.
>   gcc/testsuite/
>   PR middle-end/71373
>   * gcc.dg/goacc/nested.c: New file.
>   * gcc.dg/goacc/pr71373.c: Likewise.
>   * gfortran.dg/goacc/subroutines.f90: Update.

LGTM.

Jakub


Re: [PATCH][wwwdocs][AArch64] Mention -mcpu=qdf24xx support for GCC 6

2016-06-02 Thread James Greenhalgh
On Thu, Jun 02, 2016 at 03:54:43PM +0100, Kyrill Tkachov wrote:
> Hi all,
> 
> As discussed some time ago with Jim, here's the AArch64 note mentioning the
> support for Qualcomm QDF24xx that was added in GCC 6.
> 
> Ok to commit?

OK.

Thanks,
James

> Index: htdocs/gcc-6/changes.html
> ===
> RCS file: /cvs/gcc/wwwdocs/htdocs/gcc-6/changes.html,v
> retrieving revision 1.82
> diff -U 3 -r1.82 changes.html
> --- htdocs/gcc-6/changes.html 31 May 2016 08:01:35 -  1.82
> +++ htdocs/gcc-6/changes.html 2 Jun 2016 14:44:02 -
> @@ -435,6 +435,11 @@
> options as well as the equivalent target attributes and pragmas.
>   
>   
> +   The Qualcomm QDF24xx processor is now supported via the
> +   -mcpu=qdf24xx and -mtune=qdf24xx
> +   options as well as the equivalent target attributes and pragmas.
> + 
> + 
> Code generation for the ARM Cortex-A57 processor is improved.
> Among general code generation improvements, a better algorithm is
> added for allocating registers to floating-point multiply-accumulate



Re: [PATCH][AArch64] Add missing fcsel in Cortex-A57 scheduler

2016-06-02 Thread James Greenhalgh
On Thu, Jun 02, 2016 at 04:09:32PM +, Wilco Dijkstra wrote:
> The Cortex-A57 scheduler is missing fcsel, so add it.
> 
> OK for commit?

OK.

Thanks,
James

> 
> ChangeLog:
> 2016-06-02  Wilco Dijkstra  
> 
>   * config/arm/cortex-a57.md (cortex_a57_fp_cpys): Add fcsel.
> 
> ---
> diff --git a/gcc/config/arm/cortex-a57.md b/gcc/config/arm/cortex-a57.md
> index 
> 37912db464315a0d70835b81991e8e07a4d9db89..9b5970a0b647abc364b733cb4e2e22ae03056235
>  100644
> --- a/gcc/config/arm/cortex-a57.md
> +++ b/gcc/config/arm/cortex-a57.md
> @@ -726,7 +726,7 @@
>  
>  (define_insn_reservation "cortex_a57_fp_cpys" 4
>(and (eq_attr "tune" "cortexa57")
> -   (eq_attr "type" "fmov"))
> +   (eq_attr "type" "fmov,fcsel"))
>"(ca57_cx1|ca57_cx2)")
>  
>  (define_insn_reservation "cortex_a57_fp_divs" 12
> 



Re: [PR middle-end/71373] Handle more OMP_CLAUSE_* in nested function decomposition

2016-06-02 Thread Thomas Schwinge
Hi!

On Wed, 1 Jun 2016 17:12:17 +0200, Jakub Jelinek  wrote:
> On Wed, Jun 01, 2016 at 05:06:42PM +0200, Thomas Schwinge wrote:
> > Here are the OpenACC bits of .
> > 
> > As we're currently not paying attention to OpenACC tile clauses in the
> > middle end, and thus OMP_CLAUSE_TILE's arguments are not to be considered
> > stable, I opted to simply discard them early, simplifying their
> > gcc/tree-nested.c handling.  Everything else should be self-explanatory.
> > 
> > OK for trunk and gcc-6-branch?
> 
> LGTM for both, but please as a follow-up try to work also on a C testcase
> with nested functions that covers all the clauses (both referencing
> vars/expressions that are defined in the current function and used by a
> nested function, and for vars/expressions that are defined in parent
> function and used in clauses inside of nested function.

OK, I translated gcc/testsuite/gfortran.dg/goacc/subroutines.f90 from
Fortran to C: gcc/testsuite/gcc.dg/goacc/nested.c.  For amusement ;-) I'm
also including the test case that originally made us aware of the
problem, gcc/testsuite/gcc.dg/goacc/pr71373.c.  Oh, and I just remembered
,
so after re-testing, I'll also include these test cases, as far as still
relevant.  Nested function decomposition is not applicable to C++, so we
don't need any C++ test cases, right?

During the translation of gcc/testsuite/gfortran.dg/goacc/subroutines.f90
from Fortran to C, I stumbled upon  "C/C++
OpenACC cache directive rejects valid syntax",
,
so that one will need to go in first, before I'll then commit the
following:

commit 7eff9da0e8fe5eda7d76b9a27dbb1ec4e6183844
Author: Thomas Schwinge 
Date:   Wed Jun 1 17:01:35 2016 +0200

[PR middle-end/71373] Handle more OMP_CLAUSE_* in nested function 
decomposition

gcc/
* gimplify.c (gimplify_adjust_omp_clauses): Discard
OMP_CLAUSE_TILE.
* omp-low.c (scan_sharing_clauses): Don't expect OMP_CLAUSE_TILE.
gcc/testsuite/
* c-c++-common/goacc/combined-directives.c: XFAIL tree scanning
for OpenACC tile clauses.
* gfortran.dg/goacc/combined-directives.f90: Likewise.

gcc/
PR middle-end/71373
* tree-nested.c (convert_nonlocal_omp_clauses)
(convert_local_omp_clauses): Handle OMP_CLAUSE_ASYNC,
OMP_CLAUSE_WAIT, OMP_CLAUSE_INDEPENDENT, OMP_CLAUSE_AUTO,
OMP_CLAUSE__CACHE_, OMP_CLAUSE_TILE.
gcc/testsuite/
PR middle-end/71373
* gcc.dg/goacc/nested.c: New file.
* gcc.dg/goacc/pr71373.c: Likewise.
* gfortran.dg/goacc/subroutines.f90: Update.
---
 gcc/gimplify.c |   6 ++
 gcc/omp-low.c  |   4 +-
 .../c-c++-common/goacc/combined-directives.c   |   3 +-
 gcc/testsuite/gcc.dg/goacc/nested.c| 100 +
 gcc/testsuite/gcc.dg/goacc/pr71373.c   |  41 +
 .../gfortran.dg/goacc/combined-directives.f90  |   3 +-
 gcc/testsuite/gfortran.dg/goacc/subroutines.f90|  56 
 gcc/tree-nested.c  |  30 +++
 8 files changed, 221 insertions(+), 22 deletions(-)

diff --git gcc/gimplify.c gcc/gimplify.c
index f12c6a1..7c19cf3 100644
--- gcc/gimplify.c
+++ gcc/gimplify.c
@@ -8280,7 +8280,13 @@ gimplify_adjust_omp_clauses (gimple_seq *pre_p, 
gimple_seq body, tree *list_p,
case OMP_CLAUSE_VECTOR:
case OMP_CLAUSE_AUTO:
case OMP_CLAUSE_SEQ:
+ break;
+
case OMP_CLAUSE_TILE:
+ /* We're not yet making use of the information provided by OpenACC
+tile clauses.  Discard these here, to simplify later middle end
+processing.  */
+ remove = true;
  break;
 
default:
diff --git gcc/omp-low.c gcc/omp-low.c
index 91d5fcf..c6ba31c 100644
--- gcc/omp-low.c
+++ gcc/omp-low.c
@@ -2187,7 +2187,6 @@ scan_sharing_clauses (tree clauses, omp_context *ctx,
case OMP_CLAUSE_GANG:
case OMP_CLAUSE_WORKER:
case OMP_CLAUSE_VECTOR:
-   case OMP_CLAUSE_TILE:
case OMP_CLAUSE_INDEPENDENT:
case OMP_CLAUSE_AUTO:
case OMP_CLAUSE_SEQ:
@@ -2201,6 +2200,7 @@ scan_sharing_clauses (tree clauses, omp_context *ctx,
  break;
 
case OMP_CLAUSE__CACHE_:
+   case OMP_CLAUSE_TILE:
default:
  gcc_unreachable ();
}
@@ -2357,7 +2357,6 @@ scan_sharing_clauses (tree clauses, omp_context *ctx,
case OMP_CLAUSE_GANG:
case OMP_CLAUSE_WORKER:
case OMP_CLAUSE_VECTOR:
-   case OMP_CLAUSE_TILE:
case OMP_CLAUSE_INDEPENDENT:
case OMP_CLAUSE_AUTO:
case OMP_CLAUSE_SEQ:
@@ 

Re: [PATCH][AArch64] Improve aarch64_modes_tieable_p

2016-06-02 Thread Wilco Dijkstra
ping


From: Wilco Dijkstra
Sent: 17 May 2016 17:08
To: James Greenhalgh
Cc: gcc-patches@gcc.gnu.org; nd
Subject: Re: [PATCH][AArch64] Improve aarch64_modes_tieable_p

James Greenhalgh wrote:
> It would be handy if you could raise something in bugzilla for the
> register allocator deficiency.

The register allocation issues are well known and we have multiple
workarounds for this in place. When you allow modes to be tieable
the workarounds are not as effective.

> -  if (TARGET_SIMD
> -  && aarch64_vector_mode_p (mode1)
> -  && aarch64_vector_mode_p (mode2))
> +  if (aarch64_vector_mode_p (mode1) && aarch64_vector_mode_p (mode2))
> +return true;

> This relaxes the TARGET_SIMD check that would have prevented
> OImode/CImode/XImode ties when !TARGET_SIMD. What's the reasoning
> behind that?

There is no need for TARGET_SIMD checks here - in order to create a
vector_struct mode you need to call aarch64_array_mode_supported_p first.

> +  /* Also allow any scalar modes with vectors.  */
> +  if (aarch64_vector_mode_supported_p (mode1)
> +  || aarch64_vector_mode_supported_p (mode2))
>  return true;

> Does this always hold? It seems like you might need to be more restrictive
> with what we allow to avoid ties with some of the more obscure modes
> (V4DF etc.).

Well it is safe to always return true - this passes regression tests (it's just 
a bad
idea from a CQ point of view).

Wilco




[PATCH, COMMITTED] Fix display name of PRED_FORTRAN_FAIL_IO

2016-06-02 Thread Martin Liška
Hi.

Following patch fixes an obvious typo in definition of a predictor.

Installed as r237040.

Martin
>From f78bf4238b4a3c7d6e03d7c00718204123a2cbfd Mon Sep 17 00:00:00 2001
From: marxin 
Date: Thu, 2 Jun 2016 18:13:25 +0200
Subject: [PATCH] Fix display name of PRED_FORTRAN_FAIL_IO

gcc/ChangeLog:

2016-06-02  Martin Liska  

	* predict.def: Fix typo in PRED_FORTRAN_FAIL_IO display name.
---
 gcc/predict.def | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/predict.def b/gcc/predict.def
index b83ec60..67de6f3 100644
--- a/gcc/predict.def
+++ b/gcc/predict.def
@@ -162,7 +162,7 @@ DEF_PREDICTOR (PRED_FORTRAN_FAIL_ALLOC, "fail alloc", PROB_VERY_LIKELY, 0)
used for I/O failures such as for invalid unit numbers.  This predictor
only occurs when the user explicitly asked for a return status.  By default,
the code aborts, which is handled via PRED_NORETURN.  */
-DEF_PREDICTOR (PRED_FORTRAN_FAIL_IO, "fail alloc", HITRATE(85), 0)
+DEF_PREDICTOR (PRED_FORTRAN_FAIL_IO, "fail IO", HITRATE (85), 0)
 
 /* Branch leading to a run-time warning message which is printed only once
are unlikely.  The print-warning branch itself can be likely or unlikely.  */
-- 
2.8.3



Re: [PATCH][3/3] No need to vectorize simple only-live stmts

2016-06-02 Thread Alan Hayward

>Statements which are live but not relevant need marking to ensure they are
>vectorized.
>
>Live statements which are simple and all uses of them are invariant do not
>need
>to be vectorized.
>
>This patch adds a check to make sure those stmts which pass both the above
>checks are not vectorized and then discarded.
>
>Tested on x86 and aarch64.
>
>
>gcc/
>*tree-vect-stmts.c (vect_stmt_relevant_p): Do not vectorize non
>live
>relevant stmts which are simple and invariant.
>
>testsuite/
>* gcc.dg/vect/vect-live-slp-5.c: Remove dg check.


This version adds an addition relevance check in
vectorizable_live_operation.
It requires the "Remove duplicated GOMP SIMD LANE code” to work.

gcc/
\* tree-vect-stmts.c (vect_stmt_relevant_p): Do not vectorize non live
relevant stmts which are simple and invariant.
\* tree-vect-loop.c (vectorizable_live_operation): Check relevance
instead of simple and invariant

testsuite/
\* gcc.dg/vect/vect-live-slp-5.c: Remove dg check.




Alan.



3of3relevant.patch
Description: Binary data


Re: [PATCH][2/3] Vectorize inductions that are live after the loop

2016-06-02 Thread Alan Hayward


On 01/06/2016 10:51, "Richard Biener"  wrote:

>On Wed, Jun 1, 2016 at 10:46 AM, Alan Hayward 
>wrote:
>>
>>
>> On 30/05/2016 14:22, "Richard Biener" 
>>wrote:
>>
>>>On Fri, May 27, 2016 at 5:12 PM, Alan Hayward 
>>>wrote:

 On 27/05/2016 12:41, "Richard Biener" 
wrote:

>On Fri, May 27, 2016 at 11:09 AM, Alan Hayward 
>wrote:
>>

>
>The rest of the changes look ok to me.

 Does that include PATCH 1/3  ?
>>>
>>>I don't like how 1/3 ends up looking :/  So what was the alternative
>>>again?
>>>I looked into 1/3 and what it takes to remove the 'stmt' argument and
>>>instead pass in a vect_def_type.  It's a bit twisted and just adding
>>>another
>>>argument (the loop_vinfo) doesn't help things here.
>>>
>>>So - instead of 1/3 you might want to split out a function
>>>
>>>tree
>>>vect_get_vec_def_for_operand_1 (gimple *def_stmt, enum vect_def_type
>>>dt, tree vectype)
>>>{
>>>  switch (dt)
>>>{
>>>...
>>>}
>>>}
>>>
>>>and for constant/external force vectype != NULL.
>>
>> I’m still a little confused as to exactly what you want here.
>>
>> From your two comments I think you wanted me to completely remove the
>> boolean type check and the vect_init_vector call. But if I remove that
>> then other code paths will break.
>>
>> However, I’ve just realised that in vectorized_live_operation I already
>> have the def stmt and I can easily get hold of dt from
>>STMT_VINFO_DEF_TYPE.
>> Which means I can call vect_get_vec_def_for_operand_1 from
>> vectorized_live_operation.
>>
>> I’ve put together a version where I have:
>>
>> tree
>> vect_get_vec_def_for_operand_1 (gimple *def_stmt, enum vect_def_type dt)
>> {
>>
>>  switch (dt)
>>  {
>>case vect_internal_def || vect_external_def:
>>  gcc_unreachable ()
>>
>>.. code for for all other cases..
>>  }
>> }
>>
>> /* Used by existing code  */
>> tree
>> vect_get_vec_def_for_operand (tree op, gimple *stmt, tree vectype)
>> {
>>   vect_is_simple_use(op, loop_vinfo, _stmt, ); ..and the dump
>>code
>>
>>
>>   If dt == internal_def || vect_external_def:
>>   .. Check for BOOLEAN_TYPE ..
>>   return vect_init_vector (stmt, op, vector_type, NULL);
>>
>>   else
>> vect_get_vec_def_for_operand_1 (def_stmt, dt)
>> }
>>
>>
>> Does that look better?
>
>Yes!
>
>Thanks,
>Richard.
>


This version of the patch addresses the simple+invariant issues
(and patch [3/3] optimizes it).

Also includes a small change to handle when the vect pattern has introduced
new pattern match statements (in vectorizable_live_operation if
STMT_VINFO_RELATED_STMT is not null then use it instead of stmt).

gcc/
* tree-vect-loop.c (vect_analyze_loop_operations): Allow live stmts.
(vectorizable_reduction): Check for new relevant state.
(vectorizable_live_operation): vectorize live stmts using
BIT_FIELD_REF.  Remove special case for gimple assigns stmts.
* tree-vect-stmts.c (is_simple_and_all_uses_invariant): New function.
(vect_stmt_relevant_p): Check for stmts which are only used live.
(process_use): Use of a stmt does not inherit it's live value.
(vect_mark_stmts_to_be_vectorized): Simplify relevance inheritance.
(vect_analyze_stmt): Check for new relevant state.
*tree-vectorizer.h (vect_relevant): New entry for a stmt which is used
outside the loop, but not inside it.

testsuite/
* gcc.dg/tree-ssa/pr64183.c: Ensure test does not vectorize.
* testsuite/gcc.dg/vect/no-scevccp-vect-iv-2.c: Remove xfail.
* gcc.dg/vect/vect-live-1.c: New test.
* gcc.dg/vect/vect-live-2.c: New test.
* gcc.dg/vect/vect-live-3.c: New test.
* gcc.dg/vect/vect-live-4.c: New test.
* gcc.dg/vect/vect-live-5.c: New test.
* gcc.dg/vect/vect-live-slp-1.c: New test.
* gcc.dg/vect/vect-live-slp-2.c: New test.
* gcc.dg/vect/vect-live-slp-3.c: New test.


Alan.



2of3live.patch
Description: Binary data


[PATCH][AArch64] Add missing fcsel in Cortex-A57 scheduler

2016-06-02 Thread Wilco Dijkstra
The Cortex-A57 scheduler is missing fcsel, so add it.

OK for commit?

ChangeLog:
2016-06-02  Wilco Dijkstra  

* config/arm/cortex-a57.md (cortex_a57_fp_cpys): Add fcsel.

---
diff --git a/gcc/config/arm/cortex-a57.md b/gcc/config/arm/cortex-a57.md
index 
37912db464315a0d70835b81991e8e07a4d9db89..9b5970a0b647abc364b733cb4e2e22ae03056235
 100644
--- a/gcc/config/arm/cortex-a57.md
+++ b/gcc/config/arm/cortex-a57.md
@@ -726,7 +726,7 @@
 
 (define_insn_reservation "cortex_a57_fp_cpys" 4
   (and (eq_attr "tune" "cortexa57")
-   (eq_attr "type" "fmov"))
+   (eq_attr "type" "fmov,fcsel"))
   "(ca57_cx1|ca57_cx2)")
 
 (define_insn_reservation "cortex_a57_fp_divs" 12



Re: [PATCH][1/3] Add loop_vinfo to vect_get_vec_def_for_operand

2016-06-02 Thread Alan Hayward

> This patch simply adds loop_vinfo as an extra argument to
> vect_get_vec_def_for_operand and only generates a stmt_vinfo if required.
> This is a required cleanup for patch [2/3].
> Tested on x86 and aarch64.
>
> gcc/
> * tree-vectorizer.h (vect_get_vec_def_for_operand): Pass loop_vinfo in.
> * tree-vect-stmts.c (vect_get_vec_def_for_operand): Pass loop_vinfo in.
> (vect_get_vec_defs): Pass down loop_vinfo.
> (vectorizable_mask_load_store): Likewise.
> (vectorizable_call): Likewise.
> (vectorizable_simd_clone_call): Likewise.
> (vect_get_loop_based_defs): Likewise.
> (vectorizable_conversion): Likewise.
> (vectorizable_operation): Likewise.
> (vectorizable_store): Likewise.
> (vectorizable_load): Likewise.
> (vectorizable_condition): Likewise.
> (vectorizable_comparison): Likewise.
> * tree-vect-loop.c (get_initial_def_for_induction): Likewise.
> (get_initial_def_for_reduction): Likewise.
> (vectorizable_reduction):  Likewise.

New version. I've removed the additional loop_vinfo arg.
Instead, I've split part of vect_get_vec_def_for_operand into a new
function vect_get_vec_def_for_operand_1.
My [2/3] patch will call vect_get_vec_def_for_operand_1 direct from
vectorizeable_live_operation

gcc/
* tree-vectorizer.h (vect_get_vec_def_for_operand_1): New
* tree-vect-stmts.c (vect_get_vec_def_for_operand_1): New
(vect_get_vec_def_for_operand): Split out code.






Alan.



1of3get_vec_def.patch
Description: Binary data


Remove duplicated GOMP SIMD LANE code

2016-06-02 Thread Alan Hayward
The IFN_GOMP_SIMD_LANE code in vectorizable_call is essentially a
duplicate of
the code in vectorizable_live_operation. They both replace all uses
outside the
loop with the constant VF - 1.

Note that my patch to vectorize inductions that are live after the loop
will
also remove the IFN_GOMP_SIMD_LANE code in vectorizable_live_operation.

This patch is required in order for the follow on optimisation (No need to
Vectorise simple only-live stmts) to work.

Tested with libgomp on x86 and aarch64

gcc/
* tree-vect-stmts.c (vectorizable_call) Remove GOMP_SIMD_LANE code.

Alan.



duplicatedGOMP.patch
Description: Binary data


Re: [PATCH] microblaze.c: fix warnings

2016-06-02 Thread Michael Eager

OK to apply,

On 06/01/2016 01:04 PM, David Malcolm wrote:

The two microblaze configurations in contrib/config-list.mk
   microblaze-elf
   microblaze-linux
currently fail to build due to warnings:
   microblaze.c: In function 'void insert_wic_for_ilb_runout(rtx_insn*)':
   microblaze.c:3653:7: error: unused variable 'wic_addr1' 
[-Werror=unused-variable]
  int wic_addr1 = 128 * 4;
  ^
   microblaze.c: In function 'void insert_wic()':
   microblaze.c:3696:10: error: unused variable 'j' [-Werror=unused-variable]
  int i, j;
 ^
   microblaze.c: In function 'rtx_def* get_branch_target(rtx)':
   microblaze.c:3627:1: error: control reaches end of non-void function 
[-Werror=return-type]
}
^

(tested with compiling trunk using gcc 6).

It looks like these warnings were introduced in this last commit to
microblaze.c, r232683:

   2016-01-21  Ajit Agarwal  

* config/microblaze/microblaze.c
(get_branch_target): New.
(insert_wic_for_ilb_runout): New.
(insert_wic): New.
(microblaze_machine_dependent_reorg): New.
(TARGET_MACHINE_DEPENDENT_REORG): Define macro.
* config/microblaze/microblaze.md
(UNSPEC_IPREFETCH): Define.
(iprefetch): New pattern
* config/microblaze/microblaze.opt
(mxl-prefetch): New flag.

The attached patch fixes them.

I picked NULL_RTX as a return value for get_branch_target; is this
sane?   The result is only ever assigned to the local "branch_target"
here:

   3732  if ((branch_target = get_branch_target (insn)))

and that local appears to be unused otherwise.

OK for trunk?  (I've only verified that it compiles and fixes the
warnings; I haven't tested the results).

gcc/ChangeLog:
* config/microblaze/microblaze.c (get_branch_target): Add return
NULL_RTX for the non-CALL_P case.
(insert_wic_for_ilb_runout): Remove unused local "wic_addr1".
(insert_wic): Remove unused local "j".
---
  gcc/config/microblaze/microblaze.c | 5 +++--
  1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/gcc/config/microblaze/microblaze.c 
b/gcc/config/microblaze/microblaze.c
index baff67a..8f4768e 100644
--- a/gcc/config/microblaze/microblaze.c
+++ b/gcc/config/microblaze/microblaze.c
@@ -3624,6 +3624,8 @@ get_branch_target (rtx branch)
  abort ();
return XEXP (XEXP (call, 0), 0);
  }
+
+  return NULL_RTX;
  }

  /* Heuristics to identify where to insert at the
@@ -3650,7 +3652,6 @@ insert_wic_for_ilb_runout (rtx_insn *first)
int addr_offset = 0;
int length;
int wic_addr0 = 128 * 4;
-  int wic_addr1 = 128 * 4;

int first_addr = INSN_ADDRESSES (INSN_UID (first));

@@ -3693,7 +3694,7 @@ static void
  insert_wic (void)
  {
rtx_insn *insn;
-  int i, j;
+  int i;
basic_block bb, prev = 0;
rtx branch_target = 0;





--
Michael Eagerea...@eagercon.com
1960 Park Blvd., Palo Alto, CA 94306  650-325-8077


Re: [C++ PATCH] Fix cp_fold dropping TREE_THIS_VOLATILE flag (PR c++/71372)

2016-06-02 Thread Jakub Jelinek
On Thu, Jun 02, 2016 at 11:14:48AM -0400, Jason Merrill wrote:
> On Thu, Jun 2, 2016 at 8:13 AM, Jakub Jelinek  wrote:
> > When cp_fold is called on INDIRECT_REF and ARRAY*_REF and any of the
> > arguments change in the recursive calls, we fail to copy TREE_THIS_VOLATILE
> > flag.
> >
> > PR c++/71372
> > * cp-gimplify.c (cp_fold): For INDIRECT_REF, if the folded 
> > expression
> > is INDIRECT_REF or MEM_REF, copy over TREE_READONLY, 
> > TREE_SIDE_EFFECTS
> > and TREE_THIS_VOLATILE flags.  For ARRAY_REF and ARRAY_RANGE_REF, 
> > copy
> > over TREE_READONLY, TREE_SIDE_EFFECTS and TREE_THIS_VOLATILE flags
> > to the newly built tree.
> 
> Hmm, maybe we should be using build_indirect_ref and build_array_ref.

Those look too much front-endish to me (having lots of diagnostics etc. in them
for something that should have been already long diagnosed).

> Or perhaps factor the simple build and set flags out of
> cp_build_indirect_ref and call that.
> 
> If you don't feel like making that change, the patch is also OK as is.

I've tried to follow what the C FE does here:

  if (op0 != orig_op0
  && code == ADDR_EXPR
  && (op1 = get_base_address (op0)) != NULL_TREE
  && INDIRECT_REF_P (op1)
  && TREE_CONSTANT (TREE_OPERAND (op1, 0)))
ret = fold_convert_loc (loc, TREE_TYPE (expr), fold_offsetof_1 (op0));
  else if (op0 != orig_op0 || in_init)
ret = in_init
  ? fold_build1_initializer_loc (loc, code, TREE_TYPE (expr), op0)
  : fold_build1_loc (loc, code, TREE_TYPE (expr), op0);
  else
ret = fold (expr);
  if (code == INDIRECT_REF
  && ret != expr
  && INDIRECT_REF_P (ret))
{
  TREE_READONLY (ret) = TREE_READONLY (expr);
  TREE_SIDE_EFFECTS (ret) = TREE_SIDE_EFFECTS (expr);
  TREE_THIS_VOLATILE (ret) = TREE_THIS_VOLATILE (expr);
}

and similar.

Note, we have also the same
problem in fold-const.c (fold), though we'd hit that more rarely than this, and
there we also should just copy the flags.

Jakub


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

2016-06-02 Thread Christophe Lyon
On 2 June 2016 at 17:04, Jakub Jelinek  wrote:
> On Thu, Jun 02, 2016 at 04:49:59PM +0200, Christophe Lyon wrote:
>> I'm also seeing that the new gcc.dg/cpp/source_date_epoch-1.c fails because
>> the output pattern finishes with '\n' instead of the usual '(\n|\r\n|\r)'
>>
>> Can I add this as obvious?
>
> Some remote test invocations even eat the final newline from what I vaguely
> remember from various complains about the asan and ubsan testsuite.
>
Yes, that's a nightmare :)
Also when combined with qemu, in my configuration it thinks that stderr is
a tty so *san tests use the colorization codes.

And when it comes to cross-testing as we do it in Linaro, we have problems
with dejagnu eating the trailing \n in the remote execution functions.
But that's
another different problem.

> So we could just drop that ^ and \n$ from dg-output, but then, what is the
> point of using dg-output at all here?
>
> Isn't following just better?  Tested on x86_64-linux, ok for trunk?
LGTM

Thanks

> 2016-06-02  Jakub Jelinek  
>
> * gcc.dg/cpp/source_date_epoch-1.c (main): Test __DATE__ and
> __TIME__ strings with __builtin_strcmp instead of printf and
> dg-output.
>
> --- gcc/testsuite/gcc.dg/cpp/source_date_epoch-1.c.jj   2016-06-01 
> 21:26:27.0 +0200
> +++ gcc/testsuite/gcc.dg/cpp/source_date_epoch-1.c  2016-06-02 
> 17:02:06.164281564 +0200
> @@ -2,10 +2,10 @@
>  /* { dg-set-compiler-env-var SOURCE_DATE_EPOCH "630333296" } */
>
>  int
> -main(void)
> +main ()
>  {
> -  __builtin_printf ("%s %s\n", __DATE__, __TIME__);
> +  if (__builtin_strcmp (__DATE__, "Dec 22 1989") != 0
> +  || __builtin_strcmp (__TIME__, "12:34:56") != 0)
> +__builtin_abort ();
>return 0;
>  }
> -
> -/* { dg-output "^Dec 22 1989 12:34:56\n$" } */
>
>
> Jakub


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

2016-06-02 Thread Bernd Schmidt

On 06/02/2016 05:04 PM, Jakub Jelinek wrote:

Isn't following just better?  Tested on x86_64-linux, ok for trunk?

2016-06-02  Jakub Jelinek  

* gcc.dg/cpp/source_date_epoch-1.c (main): Test __DATE__ and
__TIME__ strings with __builtin_strcmp instead of printf and
dg-output.



Sure.


Bernd



Re: [C++ PATCH] Fix cp_fold dropping TREE_THIS_VOLATILE flag (PR c++/71372)

2016-06-02 Thread Jason Merrill
On Thu, Jun 2, 2016 at 8:13 AM, Jakub Jelinek  wrote:
> When cp_fold is called on INDIRECT_REF and ARRAY*_REF and any of the
> arguments change in the recursive calls, we fail to copy TREE_THIS_VOLATILE
> flag.
>
> PR c++/71372
> * cp-gimplify.c (cp_fold): For INDIRECT_REF, if the folded expression
> is INDIRECT_REF or MEM_REF, copy over TREE_READONLY, TREE_SIDE_EFFECTS
> and TREE_THIS_VOLATILE flags.  For ARRAY_REF and ARRAY_RANGE_REF, copy
> over TREE_READONLY, TREE_SIDE_EFFECTS and TREE_THIS_VOLATILE flags
> to the newly built tree.

Hmm, maybe we should be using build_indirect_ref and build_array_ref.
Or perhaps factor the simple build and set flags out of
cp_build_indirect_ref and call that.

If you don't feel like making that change, the patch is also OK as is.

Jason


Re: [PATCH] c++/60760 - arithmetic on null pointers should not be allowed in constant expressions

2016-06-02 Thread Jason Merrill

On 06/01/2016 10:49 PM, Martin Sebor wrote:

On 06/01/2016 01:20 PM, Jason Merrill wrote:

On 06/01/2016 02:44 PM, Martin Sebor wrote:

The new code in cxx_eval_component_reference diagnoses the following
problem that's not detected otherwise:

  struct S { const S *s; };

  constexpr S s = { 0 };

  constexpr const void *p = >s;


Note that this falls under core issue 1530, which has not been
resolved.


I don't quite see the relevance of this issue.  It's concerned
with storage in which an object will exist at some point in
the future when its lifetime begins or where it existed in
the past before its lifetime ended.  There is no object or
storage at s.s above because s.s is null.


True.  Unfortunately there isn't any wording about what you can do with
the result of indirecting a null pointer or pointer to one-past-the-end
of an array.  There was some proposed for issue 232, but that hasn't
been a high priority.  What do you see in the standard currently that
makes it undefined?


In N4567, expr.ref, the E1->E2 expression which is equivalent
to (*E1).E2, the closest match is paragraph 4.2:

  If E2 is a non-static data member and the type of E1 is "cq1
  vq1 X", and the type of E2 is "cq2 vq2 T", the expression
  designates the named member of the object designated by the
  first expression.

There is no object, so 4.2 doesn't apply, and since there is
no other bullet that would apply, the behavior is undefined.


OK, I'll buy that.


+  if (code == POINTER_PLUS_EXPR && !*non_constant_p
+  && tree_int_cst_equal (lhs, null_pointer_node))
+{
+  if (!ctx->quiet)
+error ("arithmetic involving a null pointer in %qE", lhs);
+  return t;
+}



+  if (TREE_CODE (whole) == INDIRECT_REF
+  && integer_zerop (TREE_OPERAND (whole, 0))
+  && !ctx->quiet)
+error ("dereferencing a null pointer in %qE", orig_whole);



+  if (TREE_CODE (t) == INTEGER_CST
+  && TREE_CODE (TREE_TYPE (t)) == POINTER_TYPE
+  && !integer_zerop (t))
+{
+  if (!ctx->quiet)
+error ("arithmetic involving a null pointer in %qE", t);
+}


These places should all set *non_constant_p, and the second should
return t after doing so.  OK with that change.


Thanks.  I've made the change, but I haven't managed to come up
with a test to exercise it.  IIUC, the purpose setting
non_constant_p while the quiet flag is set is to determine without
causing errors that expressions are not valid constant expressions
by passing them to __builtin_constant_p, correct?


No, __builtin_constant_p allows more things than C++ constant 
expressions.  The purpose of setting *non_constant_p is to cause 
maybe_constant_value to return its argument unchanged.


Jason



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

2016-06-02 Thread Jakub Jelinek
On Thu, Jun 02, 2016 at 04:49:59PM +0200, Christophe Lyon wrote:
> I'm also seeing that the new gcc.dg/cpp/source_date_epoch-1.c fails because
> the output pattern finishes with '\n' instead of the usual '(\n|\r\n|\r)'
> 
> Can I add this as obvious?

Some remote test invocations even eat the final newline from what I vaguely
remember from various complains about the asan and ubsan testsuite.

So we could just drop that ^ and \n$ from dg-output, but then, what is the
point of using dg-output at all here?

Isn't following just better?  Tested on x86_64-linux, ok for trunk?

2016-06-02  Jakub Jelinek  

* gcc.dg/cpp/source_date_epoch-1.c (main): Test __DATE__ and
__TIME__ strings with __builtin_strcmp instead of printf and
dg-output.

--- gcc/testsuite/gcc.dg/cpp/source_date_epoch-1.c.jj   2016-06-01 
21:26:27.0 +0200
+++ gcc/testsuite/gcc.dg/cpp/source_date_epoch-1.c  2016-06-02 
17:02:06.164281564 +0200
@@ -2,10 +2,10 @@
 /* { dg-set-compiler-env-var SOURCE_DATE_EPOCH "630333296" } */
 
 int
-main(void)
+main ()
 {
-  __builtin_printf ("%s %s\n", __DATE__, __TIME__);
+  if (__builtin_strcmp (__DATE__, "Dec 22 1989") != 0
+  || __builtin_strcmp (__TIME__, "12:34:56") != 0)
+__builtin_abort ();
   return 0;
 }
-
-/* { dg-output "^Dec 22 1989 12:34:56\n$" } */


Jakub


Re: move increase_alignment from simple to regular ipa pass

2016-06-02 Thread Jan Hubicka
> On Thu, 2 Jun 2016, David Edelsohn wrote:
> 
> > > Richard Biener wrote:
> > 
> > >> "This would mean the pass should get its own non-Optimization flag
> > >> initialized by targets where section anchors are usually used"
> > >> IIUC should we add a new option -fno-increase_alignment and gate the
> > >> pass on it ? Um sorry I didn't understand why targets
> > >> with section anchors (arm, aarch64, ppc) should initialize this option ?
> > >
> > > Currently the pass is only run for targets with section anchors (and there
> > > by default if they are enabled by default).  So it makes sense to
> > > run on those by default and the pass is not necessary on targets w/o
> > > section anchors as the vectorizer can easily adjust alignment itself on
> > > those.
> > 
> > PPC does not always enable section anchors -- it depends on the code
> > model.  Shouldn't this be tied to use of section anchors?
> 
> It effectively is with the patch by walking all functions to see if they
> have section anchors enabled.  That is unnecessary work for targets that

fsection-anchors
Common Report Var(flag_section_anchors) 
Access data in the same section from shared anchor points.  

flag_section_anchors is not declared as Optimiation, so it can't be function
specific right now. It probably should because it is an optimization.  This
makes me wonder what happens when one function have anchors enabled and other
doesn't?  Probably anchroing or not anchoring the var will then depend on what
function comes first in the compilation order and then we will need to make
backend grok the case where static var is anchored but flag_section_anchors is
off.

I dunno what is the desired behaviour for LTOint together different code models.

Honza

> do not support section anchors at all, of course.
> 
> Richard.


[PATCH][wwwdocs][AArch64] Mention -mcpu=qdf24xx support for GCC 6

2016-06-02 Thread Kyrill Tkachov

Hi all,

As discussed some time ago with Jim, here's the AArch64 note mentioning the 
support for Qualcomm QDF24xx
that was added in GCC 6.

Ok to commit?

Thanks,
Kyrill
Index: htdocs/gcc-6/changes.html
===
RCS file: /cvs/gcc/wwwdocs/htdocs/gcc-6/changes.html,v
retrieving revision 1.82
diff -U 3 -r1.82 changes.html
--- htdocs/gcc-6/changes.html	31 May 2016 08:01:35 -	1.82
+++ htdocs/gcc-6/changes.html	2 Jun 2016 14:44:02 -
@@ -435,6 +435,11 @@
options as well as the equivalent target attributes and pragmas.
  
  
+   The Qualcomm QDF24xx processor is now supported via the
+   -mcpu=qdf24xx and -mtune=qdf24xx
+   options as well as the equivalent target attributes and pragmas.
+ 
+ 
Code generation for the ARM Cortex-A57 processor is improved.
Among general code generation improvements, a better algorithm is
added for allocating registers to floating-point multiply-accumulate


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

2016-06-02 Thread Christophe Lyon
On 2 June 2016 at 15:01, Christophe Lyon  wrote:
> On 1 June 2016 at 18:59, Matthias Klose  wrote:
>> On 01.06.2016 18:29, Bernd Schmidt wrote:
>>> On 05/13/2016 07:09 PM, Dhole wrote:
 +pfile->source_date_epoch = pfile->cb.get_source_date_epoch(pfile);
>>>
>>> Space before paren. Ok with that change.
>>>
 * c-common.h (c_omp_region_type): Remove trailing coma.
>>>
>>> Also, comma.
>>
>> committed with these changes.
>>
>
> Hi,
>
> Since this was committed, I'm seeing:
> - ~random failures of pr61861:
> /aci-gcc-fsf/sources/gcc-fsf/gccsrc/gcc/testsuite/gcc.dg/pr61861.c:22:3:
> error: environment variable SOURCE_DATE_EPOCH must expand to a
> non-negative integer less than or equal to 253402300799
>
> I've noticed that HJ has reported it on gcc-regressions, too.
>
> It would help if the error message showed the value of SOURCE_DATE_EPOCH :)

I'm also seeing that the new gcc.dg/cpp/source_date_epoch-1.c fails because
the output pattern finishes with '\n' instead of the usual '(\n|\r\n|\r)'

Can I add this as obvious?

Thanks,

Christophe


Re: [Patch, ARM] PR71061, length pop* pattern in epilogue correctly

2016-06-02 Thread Jiong Wang

On 31/05/16 15:15, Kyrill Tkachov wrote:


+/* Compute the atrribute "length" of insn.  Currently, this function 
is used

+   for "*load_multiple_with_writeback", "*pop_multiple_with_return" and
+   "*pop_multiple_with_writeback_and_return".  */
+

s/atrribute/attribute/

Also, please add a description of the function arguments to the 
function comment.


 +int
+arm_attr_length_pop_multi(rtx *operands, bool return_pc, bool 
write_back_p)

+{

space between function name and '('.

 +  /* ARM mode.  */
+  if (TARGET_ARM)
+return 4;
+  /* Thumb1 mode.  */
+  if (TARGET_THUMB1)
+return 2;
+
+  /* For POP/PUSH/LDM/STM under Thumb2 mode, we can use 16-bit Thumb 
encodings
+ if the register list is 8-bit.  Normally this means all 
registers in the
+ list must be LO_REGS, that is (R0 -R7).  If any HI_REGS used, 
then we must
+ use 32-bit encodings.  But there are two exceptions to this rule 
where

+ special HI_REGS used in PUSH/POP.
+
+ 1. 16-bit Thumb encoding POP can use an 8-bit register list, and an
+additional bit, P, that corresponds to the PC.  This means it 
can access

+any of {PC, R7-R0}.


It took me a bit to figure it out but this bit 'P' you're talking 
about is a just a bit
in the illustration in the ARM Architecture Reference Manual (section 
A8.8.131).

I don't think it's useful to refer to it.
This would be better phrased as "The encoding is 16 bits wide if the 
register list contains

only the registers in {R0 - R7} or the PC".

 + 2. 16-bit Thumb encoding PUSH can use an 8-bit register list, 
and an

+additional bit, M , that corresponds to the LR.  This means it can
+access any of {LR, R7-R0}.  */
+

This function only deals with POP instructions, so talking about PUSH 
encodings

is confusing. I suggest you drop point 2).


Thanks, all fixed.

Meanwhile I splitted the comments to keep PUSH part in 
arm_attr_length_push_multi.

Patch updated.

OK for trunk?

gcc/

2016-06-02  Jiong Wang  

PR target/71061
* config/arm/arm-protos.h (arm_attr_length_pop_multi): New declaration.
* config/arm/arm.c (arm_attr_length_pop_multi): New function to return
length for pop patterns.
(arm_attr_length_push_multi): Update comments.
* config/arm/arm.md (*load_multiple_with_writeback): Set "length" attribute.
(*pop_multiple_with_writeback_and_return): Likewise.
(*pop_multiple_with_return): Likewise.



diff --git a/gcc/config/arm/arm-protos.h b/gcc/config/arm/arm-protos.h
index 34fd06a..c707fd5 100644
--- a/gcc/config/arm/arm-protos.h
+++ b/gcc/config/arm/arm-protos.h
@@ -163,6 +163,7 @@ extern const char *arm_output_iwmmxt_shift_immediate (const char *, rtx *, bool)
 extern const char *arm_output_iwmmxt_tinsr (rtx *);
 extern unsigned int arm_sync_loop_insns (rtx , rtx *);
 extern int arm_attr_length_push_multi(rtx, rtx);
+extern int arm_attr_length_pop_multi(rtx *, bool, bool);
 extern void arm_expand_compare_and_swap (rtx op[]);
 extern void arm_split_compare_and_swap (rtx op[]);
 extern void arm_split_atomic_op (enum rtx_code, rtx, rtx, rtx, rtx, rtx, rtx);
diff --git a/gcc/config/arm/arm.c b/gcc/config/arm/arm.c
index 16499ce..350e46e 100644
--- a/gcc/config/arm/arm.c
+++ b/gcc/config/arm/arm.c
@@ -27795,7 +27795,7 @@ arm_preferred_rename_class (reg_class_t rclass)
 return NO_REGS;
 }
 
-/* Compute the atrribute "length" of insn "*push_multi".
+/* Compute the attribute "length" of insn "*push_multi".
So this function MUST be kept in sync with that insn pattern.  */
 int
 arm_attr_length_push_multi(rtx parallel_op, rtx first_op)
@@ -27812,6 +27812,11 @@ arm_attr_length_push_multi(rtx parallel_op, rtx first_op)
 
   /* Thumb2 mode.  */
   regno = REGNO (first_op);
+  /* For PUSH/STM under Thumb2 mode, we can use 16-bit encodings if the register
+ list is 8-bit.  Normally this means all registers in the list must be
+ LO_REGS, that is (R0 -R7).  If any HI_REGS used, then we must use 32-bit
+ encodings.  There is one exception for PUSH that LR in HI_REGS can be used
+ with 16-bit encoding.  */
   hi_reg = (REGNO_REG_CLASS (regno) == HI_REGS) && (regno != LR_REGNUM);
   for (i = 1; i < num_saves && !hi_reg; i++)
 {
@@ -27824,6 +27829,56 @@ arm_attr_length_push_multi(rtx parallel_op, rtx first_op)
   return 4;
 }
 
+/* Compute the attribute "length" of insn.  Currently, this function is used
+   for "*load_multiple_with_writeback", "*pop_multiple_with_return" and
+   "*pop_multiple_with_writeback_and_return".  OPERANDS is the toplevel PARALLEL
+   rtx, RETURN_PC is true if OPERANDS contains return insn.  WRITE_BACK_P is
+   true if OPERANDS contains insn which explicit updates base register.  */
+
+int
+arm_attr_length_pop_multi (rtx *operands, bool return_pc, bool write_back_p)
+{
+  /* ARM mode.  */
+  if (TARGET_ARM)
+return 4;
+  /* Thumb1 mode.  */
+  if (TARGET_THUMB1)
+return 2;
+
+  rtx parallel_op = operands[0];
+  /* Initialize to elements number of PARALLEL.  

[PATCH][ARM][wwwdocs] Mention some arm port changes for GCC 6

2016-06-02 Thread Kyrill Tkachov

Hi all,

A bit belatedly, but here are some arm-related entries for the changes.html 
page for GCC 6.
Is this ok to commit?

Thanks,
Kyrill
Index: htdocs/gcc-6/changes.html
===
RCS file: /cvs/gcc/wwwdocs/htdocs/gcc-6/changes.html,v
retrieving revision 1.80
diff -U 3 -r1.80 changes.html
--- htdocs/gcc-6/changes.html	27 Apr 2016 13:24:19 -	1.80
+++ htdocs/gcc-6/changes.html	28 Apr 2016 09:01:45 -
@@ -478,6 +478,14 @@
armv2,armv2a,armv3,armv3m,armv4.
  
  
+   Support has been added for the ARMv8.1-A architecture through the
+   armv8.1-a and armv8.1-a+crc arguments
+   to the -march command-line option.  This allows access
+   to a number of new ACLE intrinsics.  For details please refer to the
+   http://infocenter.arm.com/help/topic/com.arm.doc.ihi0053c/IHI0053C_acle_2_0.pdf>
+   documentation.
+ 
+ 
The ARM port now supports target attributes and pragmas.  Please
refer to the https://gcc.gnu.org/onlinedocs/gcc-6.1.0/gcc/ARM-Function-Attributes.html#ARM-Function-Attributes;>
documentation for details of available attributes and
@@ -486,12 +494,24 @@
  
Support has been added for the following processors
(GCC identifiers in parentheses): ARM Cortex-A32
-   (cortex-a32), ARM Cortex-A35 (cortex-a35).
+   (cortex-a32), ARM Cortex-A35 (cortex-a35),
+   ARM Cortex-R8 (cortex-r8), Qualcomm QDF24xx
+   (qdf24xx).
The GCC identifiers can be used
as arguments to the -mcpu or -mtune options,
for example: -mcpu=cortex-a32 or
-mtune=cortex-a35.
  
+ 
+   The ARM port now emits assembly in the Unified format for both ARM and
+   Thumb states.  This doesn't affect the functionality of user-supplied
+   inline assembly constructs.
+ 
+ 
+   The ARM port now accepts the value armv6kz as an argument
+   to the -march.  The value armv6zk is still
+   supported.
+ 

 
 


Re: [PATCH, i386, AVX-512] Add vectorizer support builtins

2016-06-02 Thread Ilya Verbin
On Mon, May 23, 2016 at 19:11:53 +0300, Ilya Verbin wrote:
> This patch adds missed 512-bit rounding builtins for vectorization.
> Regtested on x86_64-linux and i686-linux.  OK for trunk?
> 
> gcc/
>   * config/i386/i386-builtin-types.def: Add V16SI_FTYPE_V16SF,
>   V8DF_FTYPE_V8DF_ROUND, V16SF_FTYPE_V16SF_ROUND, V16SI_FTYPE_V16SF_ROUND.
>   * config/i386/i386.c (enum ix86_builtins): Add
>   IX86_BUILTIN_CVTPS2DQ512_MASK, IX86_BUILTIN_FLOORPS512,
>   IX86_BUILTIN_FLOORPD512, IX86_BUILTIN_CEILPS512, IX86_BUILTIN_CEILPD512,
>   IX86_BUILTIN_TRUNCPS512, IX86_BUILTIN_TRUNCPD512,
>   IX86_BUILTIN_CVTPS2DQ512, IX86_BUILTIN_VEC_PACK_SFIX512,
>   IX86_BUILTIN_FLOORPS_SFIX512, IX86_BUILTIN_CEILPS_SFIX512,
>   IX86_BUILTIN_ROUNDPS_AZ_SFIX512.
>   (builtin_description bdesc_args): Add __builtin_ia32_floorps512,
>   __builtin_ia32_ceilps512, __builtin_ia32_truncps512,
>   __builtin_ia32_floorpd512, __builtin_ia32_ceilpd512,
>   __builtin_ia32_truncpd512, __builtin_ia32_cvtps2dq512,
>   __builtin_ia32_vec_pack_sfix512, __builtin_ia32_roundps_az_sfix512,
>   __builtin_ia32_floorps_sfix512, __builtin_ia32_ceilps_sfix512.
>   Change IX86_BUILTIN_CVTPS2DQ512 to IX86_BUILTIN_CVTPS2DQ512_MASK for
>   __builtin_ia32_cvtps2dq512_mask.
>   (ix86_expand_args_builtin): Handle V8DF_FTYPE_V8DF_ROUND,
>   V16SF_FTYPE_V16SF_ROUND, V16SI_FTYPE_V16SF_ROUND, V16SI_FTYPE_V16SF.
>   (ix86_builtin_vectorized_function): Handle builtins mentioned above.
>   * config/i386/sse.md
>   (avx512f_fix_notruncv16sfv16si):
>   Rename to ...
>   (avx512f_fix_notruncv16sfv16si): ... this.
>   (avx512f_cvtpd2dq512): Rename
>   to ...
>   (avx512f_cvtpd2dq512): ... this.
>   (avx512f_vec_pack_sfix_v8df): New define_expand.
>   (avx512f_roundpd512): Rename to ...
>   (avx512f_round512): ... this.  Change iterator.
>   (avx512f_roundps512_sfix): New define_expand.
>   (round2_sfix): Change iterator.
> gcc/testsuite/
>   * gcc.target/i386/avx512f-ceil-vec-1.c: New test.
>   * gcc.target/i386/avx512f-ceil-vec-2.c: New test.
>   * gcc.target/i386/avx512f-ceilf-sfix-vec-1.c: New test.
>   * gcc.target/i386/avx512f-ceilf-sfix-vec-2.c: New test.
>   * gcc.target/i386/avx512f-ceilf-vec-1.c: New test.
>   * gcc.target/i386/avx512f-ceilf-vec-2.c: New test.
>   * gcc.target/i386/avx512f-floor-vec-1.c: New test.
>   * gcc.target/i386/avx512f-floor-vec-2.c: New test.
>   * gcc.target/i386/avx512f-floorf-sfix-vec-1.c: New test.
>   * gcc.target/i386/avx512f-floorf-sfix-vec-2.c: New test.
>   * gcc.target/i386/avx512f-floorf-vec-1.c: New test.
>   * gcc.target/i386/avx512f-floorf-vec-2.c: New test.
>   * gcc.target/i386/avx512f-rint-sfix-vec-1.c: New test.
>   * gcc.target/i386/avx512f-rint-sfix-vec-2.c: New test.
>   * gcc.target/i386/avx512f-rintf-sfix-vec-1.c: New test.
>   * gcc.target/i386/avx512f-rintf-sfix-vec-2.c: New test.
>   * gcc.target/i386/avx512f-round-sfix-vec-1.c: New test.
>   * gcc.target/i386/avx512f-round-sfix-vec-2.c: New test.
>   * gcc.target/i386/avx512f-roundf-sfix-vec-1.c: New test.
>   * gcc.target/i386/avx512f-roundf-sfix-vec-2.c: New test.
>   * gcc.target/i386/avx512f-trunc-vec-1.c: New test.
>   * gcc.target/i386/avx512f-trunc-vec-2.c: New test.
>   * gcc.target/i386/avx512f-truncf-vec-1.c: New test.
>   * gcc.target/i386/avx512f-truncf-vec-2.c: New test.

Is it OK for gcc-6-branch?

  -- Ilya


Re: [PATCH, OpenACC] Make reduction arguments addressable

2016-06-02 Thread Jakub Jelinek
On Thu, Jun 02, 2016 at 09:55:05PM +0800, Chung-Lin Tang wrote:
>   fortran/
>   * trans-openmp.c (gfc_trans_omp_clauses): Mark OpenACC reduction
>   arguments as addressable when async clause exists.

Wouldn't it be better to pass either a bool openacc_async flag, or
whole clauses, down to gfc_trans_omp_reduction_list and handle it there
instead of walking the list after the fact?

> Index: trans-openmp.c
> ===
> --- trans-openmp.c(revision 236845)
> +++ trans-openmp.c(working copy)
> @@ -1748,6 +1748,12 @@ gfc_trans_omp_clauses (stmtblock_t *block, gfc_omp
>   {
>   case OMP_LIST_REDUCTION:
> omp_clauses = gfc_trans_omp_reduction_list (n, omp_clauses, where);
> +   /* An OpenACC async clause indicates the need to set reduction
> +  arguments addressable, to allow asynchronous copy-out.  */
> +   if (clauses->async)
> + for (c = omp_clauses; c; c = OMP_CLAUSE_CHAIN (c))
> +   if (DECL_P (OMP_CLAUSE_DECL (c)))
> + TREE_ADDRESSABLE (OMP_CLAUSE_DECL (c)) = 1;
> break;
>   case OMP_LIST_PRIVATE:
> clause_code = OMP_CLAUSE_PRIVATE;


Jakub


Re: [PATCH, OpenACC] Make reduction arguments addressable

2016-06-02 Thread Chung-Lin Tang
On 2016/6/1 09:38 PM, Jakub Jelinek wrote:
>>  construct_clauses.lists[OMP_LIST_REDUCTION] = NULL;
>> >oacc_clauses = gfc_trans_omp_clauses (, _clauses,
>> >code->loc);
>> > +  for (tree c = oacc_clauses; c; c = OMP_CLAUSE_CHAIN (c))
>> > +  if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ASYNC)
>> > +{
>> > +  for (c = oacc_clauses; c; c = OMP_CLAUSE_CHAIN (c))
>> > +if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
>> > +&& DECL_P (OMP_CLAUSE_DECL (c)))
>> > +  TREE_ADDRESSABLE (OMP_CLAUSE_DECL (c)) = 1;
>> > +  break;
>> > +}
>> >  }
> These 2 look wrong to me.  1) you really don't need to walk all the clauses
> to find if there is OMP_CLAUSE_ASYNC, you can just test the
> async field of struct gfc_omp_clauses.  And, 2) is there any reason why you
> can't just do this in gfc_trans_omp_clauses instead, when crating
> OMP_CLAUSE_REDUCTION if clauses->async is set?  Or are there some cases
> where on OpenACC constructs you don't want to do this?

Thanks for reminding, I didn't notice there was such a gfc_omp_clauses->async 
field.

Here's a much more succinct patch that does it inside gfc_trans_omp_clauses.
Again re-tested gfortran and libgomp without regressions.
Is this and the C/C++ patches (and the new testsuite cases) okay for trunk?

Thanks,
Chung-Lin

fortran/
* trans-openmp.c (gfc_trans_omp_clauses): Mark OpenACC reduction
arguments as addressable when async clause exists.

Index: trans-openmp.c
===
--- trans-openmp.c  (revision 236845)
+++ trans-openmp.c  (working copy)
@@ -1748,6 +1748,12 @@ gfc_trans_omp_clauses (stmtblock_t *block, gfc_omp
{
case OMP_LIST_REDUCTION:
  omp_clauses = gfc_trans_omp_reduction_list (n, omp_clauses, where);
+ /* An OpenACC async clause indicates the need to set reduction
+arguments addressable, to allow asynchronous copy-out.  */
+ if (clauses->async)
+   for (c = omp_clauses; c; c = OMP_CLAUSE_CHAIN (c))
+ if (DECL_P (OMP_CLAUSE_DECL (c)))
+   TREE_ADDRESSABLE (OMP_CLAUSE_DECL (c)) = 1;
  break;
case OMP_LIST_PRIVATE:
  clause_code = OMP_CLAUSE_PRIVATE;


Re: [PATCH 00/21] Add -fself-test framework for fast, early unit-testing (unittests v5)

2016-06-02 Thread David Malcolm
On Thu, 2016-06-02 at 12:29 +0200, Bernd Schmidt wrote:
> On 06/01/2016 11:19 PM, David Malcolm wrote:
> > This is effectively v5 of the unittests proposal; for the earlier
> > versions see:
> 
> In general: nice to see this moving forward.

Thanks.

> There are some issues with the patch kit, some patches seem to fix 
> issues with earlier ones (#3 or #13). One patch adds a sorry, the
> next 
> changes it to inform; patch #1 adds includes top toplev.c without
> adding 
> the included files. All these issues should be resolved: any patch 
> series should compile if it is applied only partially up to a point;
> no 
> early patch should depend on later ones. Also, bugfixes and behaviour
> changes should be merged directly into the code so as to not
> hopelessly 
> confuse the reviewers.
> Some of the cover letters, in particular #1 seem to contain outdated 
> information.

Sorry about that.  I was hoping to emphasize the changes from the last
version, but clearly it made things more confusing.

> > I also patched things so that it aborts on the first failure,
> > making
> > failures easy to track down in the debugger, though requiring us to
> > make the selftests robust.
> 
> Is there any kind of doubt that this is a good requirement?

I was uncertain about how acceptable the "run the tests from within
gcc/Makefile.in" approach is, so I was hedging my bets somewhat in the
kit.  It seems like you do like the gcc/Makefile.in approach, so this
implies each of:
(1) that tests should be fast (which is why I left out the test-ggc
tests in this iteration for now, as one of them is relatively slow)
(2) that tests must be 100% reliable
(3) it must be trivially easy to track down failures (since in this
approach test failure means build failure); "make selftests-gdb" is the
solution here

Given (3), this implies that we should halt on the first failure (as in
this version of the kit).  My experience when writing new tests and
experimenting with the gcc/Makefile.in approach was that "halt on first
failure" was much easier to work with than "run everything and report".


> > * conversion of the Levenshtein selftest from a plugin to using
> >-fself-test (we could move various other tests from plugins to
> > run
> >earlier).
> 
> That sounds good.
> 
> > Patch 4 shows a way of filtering the tests using a command-line
> > regex.
> 
> What's the use case for this?

Say there's a problem with many tests and that you suspect an issue in,
say, bitmap.c.  This would let you run e.g. ".*bitmap.*" to better
isolate the issue.

Maybe this suggests that we should go even simpler, and hard-code the
order in which tests run, manually encoding the dependencies (e.g. test
the fundamental types first, then test the things that build on top of
them, etc).  This would be losing auto-registration, but has the virtue
of simplicity.

Thought experiment: imagine trying to bring up gcc on a new host, and
3/4 of the self tests are failing; it turns out to be some sizeof()
assumption about int vs long or somesuch in one of the fundamental data
structures.  How do we make it easy to isolate such a problem?

> > For (a), this version of the patch kit switches to stopping at the
> > first failure.
> > For (b), this version of the patch kit stays with auto
> > -registration.
> > For (c), this version stays with a "lite" version of GTest.
> > 
> > Thoughts?   Does the "running tests early" approach suggest answers
> > to
> > these?
> 
> I think this is mostly a good resolution, 

Given that we're going with "halt on first failure", that means that
there's no longer a distinction between EXPECT_EQ and ASSERT_EQ.  I'll
eliminate the former in favor of the latter.

> although I have one particular 
> issue that rubs me the wrong way where I'd go even "liter" on the
> GTest. 
> In my view, tests are functions, and using object-orientation leads
> to 
> oddly contorted code. An example can be found in patch #5:
> 
> +class range_contains_point_tests : public ::selftest::test
> +{
> + protected:
> +  layout_range
> +  make_range (int start_line, int start_col,
> +   int end_line, int end_col)
> (note also that this defeats the purpose of the GNU function
> formatting 
> which is to enable grep ^function_name to find them)
> +  {
> +const expanded_location start_exploc
> +  = {"test.c", start_line, start_col, NULL, false};
> +expanded_location finish_exploc
> +  = {"test.c", end_line, end_col, NULL, false};
> +
> +return layout_range (_exploc, _exploc, false,
> +  _exploc);
> +  }
> +};
> 
> I think I raised this before, but defining a class only to define 
> functions inside them seems relatively pointless; if anything you
> want 
> namespaces. This one doesn't even seem to contain any references to
> the 
> selftest framework so it could immediately be converted to a
> function.
> 
> Other such cases appear to use the EXPECT_EQ etc. macros, which call 
> pass and fail methods, but these just 

Re: [middle-end][PATCH] Update alignment_for_piecewise_move

2016-06-02 Thread H.J. Lu
On Tue, Apr 26, 2016 at 11:39 AM, H.J. Lu  wrote:
> On Tue, Apr 26, 2016 at 11:31 AM, Bernd Schmidt  wrote:
>> On 04/26/2016 08:21 PM, Richard Sandiford wrote:
>>>
>>> "H.J. Lu"  writes:

 I am working a patch to enable SSE, AVX and AVX512 for memcpy/memset
 optimization.  x86 backend defines MAX_BITSIZE_MODE_ANY_INT to 128
 to keep the OI and XI modes from confusing the compiler into thinking
 that these modes could actually be used for computation.  But the OI
 and XI modes can be used for data movement with vector instructions.
>>>
>>>
>>> But doesn't this then open the possibility that a memset or memcpy
>>> will be seen as a "normal" integer operation?  Routines like
>>> simplify_immed_subreg could in principle create a constant integer
>>> for the stored value, which could then be treated by later passes as
>>> a wide_int, breaking the MAX_BITSIZE_MODE_ANY_INT assumption.
>>>
>>> Couldn't we move to allowing vector modes instead?  That seems better
>>> than having to pander to the current situation in which every vector
>>> effectively needs an associated integer mode.
>>
>>
>> I'm actually working on a patch in this area. Haven't gotten to the point of
>> allowing vector modes yet, but it's something that I've had on my mind; I
>> think it would be a good idea.
>>
>
> I am looking forward to seeing your patch.
>

Hi Bernd,

Are you planning to submit your patch before July?  If not, I will resubmit
mine and work out all the issues.  It may take a long time to review and I
have patches to enable SSE, AVX, AVX512 f memset and memcpy, which
depend on it.  I'd like to see them before stage 2 for GCC 7.

Thanks.

-- 
H.J.


Re: [PATCH, libstdc++/testsuite, ping] 29_atomics/atomic/65913.cc: require atomic-builtins rather than specific target

2016-06-02 Thread Thomas Preudhomme
Ping?

On Thursday 26 May 2016 14:00:55 Thomas Preudhomme wrote:
> [Sorry for the large recipient list, I wasn't sure who of C++ and x86
> maintainers should approve this]
> 
> Hi,
> 
> 29_atomics/atomic/65913.cc test in libstdc++ is a runtime test that only
> rely on atomic and gnu++11 support. Therefore I propose to require
> atomic-builtins instead of an x86 (32 or 64 bits) target.
> 
> ChangeLog entry is as follows:
> 
> 2016-05-19  Thomas Preud'homme  
> 
> * testsuite/29_atomics/atomic/65913.cc: Require atomic-builtins
> rather than specific target.
> 
> 
> Patch is in attachment.
> 
> 
> Is this ok for trunk?
> 
> Best regards,
> 
> Thomas
diff --git a/libstdc++-v3/testsuite/29_atomics/atomic/65913.cc b/libstdc++-v3/testsuite/29_atomics/atomic/65913.cc
index 713ef42d03cb9f7c1e691995df2d0943e24036c3..32a58ec991b41c74aafab84deed2c543d72505f5 100644
--- a/libstdc++-v3/testsuite/29_atomics/atomic/65913.cc
+++ b/libstdc++-v3/testsuite/29_atomics/atomic/65913.cc
@@ -15,7 +15,8 @@
 // with this library; see the file COPYING3.  If not see
 // .
 
-// { dg-do run { target x86_64-*-linux* powerpc*-*-linux* } }
+// { dg-do run }
+// { dg-require-atomic-builtins "" }
 // { dg-options "-std=gnu++11 -O0" }
 
 #include 


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

2016-06-02 Thread Jakub Jelinek
On Thu, Jun 02, 2016 at 03:21:03PM +0200, Christophe Lyon wrote:
> Ha, thanks, I had missed it.
> 
> But why do I see "random" failures?
> Looking at your patch, I have the impression that the test should always fail?

Only with make -j1 -k check it should always FAIL.  With -j2 and above, it
really depends if the same runtest instance runs after the second of these
tests any test with __DATE__ etc. macros in it or not.

Jakub


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

2016-06-02 Thread Christophe Lyon
On 2 June 2016 at 15:05, Jakub Jelinek  wrote:
> On Thu, Jun 02, 2016 at 03:01:07PM +0200, Christophe Lyon wrote:
>> On 1 June 2016 at 18:59, Matthias Klose  wrote:
>> > On 01.06.2016 18:29, Bernd Schmidt wrote:
>> >> On 05/13/2016 07:09 PM, Dhole wrote:
>> >>> +pfile->source_date_epoch = 
>> >>> pfile->cb.get_source_date_epoch(pfile);
>> >>
>> >> Space before paren. Ok with that change.
>> >>
>> >>> * c-common.h (c_omp_region_type): Remove trailing coma.
>> >>
>> >> Also, comma.
>> >
>> > committed with these changes.
>> >
>>
>> Since this was committed, I'm seeing:
>> - ~random failures of pr61861:
>> /aci-gcc-fsf/sources/gcc-fsf/gccsrc/gcc/testsuite/gcc.dg/pr61861.c:22:3:
>> error: environment variable SOURCE_DATE_EPOCH must expand to a
>> non-negative integer less than or equal to 253402300799
>>
>> I've noticed that HJ has reported it on gcc-regressions, too.
>>
>> It would help if the error message showed the value of SOURCE_DATE_EPOCH :)
>
> I've fixed that already in r237035.
>

Ha, thanks, I had missed it.

But why do I see "random" failures?
Looking at your patch, I have the impression that the test should always fail?

Christophe

> Jakub


Re: [PATCH 00/21] Add -fself-test framework for fast, early unit-testing (unittests v5)

2016-06-02 Thread David Malcolm
On Wed, 2016-06-01 at 15:20 -0600, Sandra Loosemore wrote:
> On 06/01/2016 03:19 PM, David Malcolm wrote:
> > This is effectively v5 of the unittests proposal; for the earlier
> > versions see:
> >   * v1: https://gcc.gnu.org/ml/gcc-patches/2015-06/msg00765.html
> >   * v2: https://gcc.gnu.org/ml/gcc-patches/2015-06/msg01224.html
> >   * v3: https://gcc.gnu.org/ml/gcc-patches/2015-10/msg02947.html
> >   * v4: https://gcc.gnu.org/ml/gcc-patches/2015-11/msg02379.html
> > 
> > Bernd said (in 
> > https://gcc.gnu.org/ml/gcc-patches/2015-11/msg01981.html ):
> > > For some of the simpler infrastructure tests such as the ones in
> > > this
> > > patch kit (bitmap, vec or wide-int functionality testing and
> > > such),
> > > we had the idea of putting these into every ENABLE_CHECKING
> > > compiler,
> > > and run them after building stage1, controlled by a -fself-test
> > > flag.
> > > It's better to detect such basic failures early rather than
> > > complete
> > > a full bootstrap and test cycle. It also keeps the tests
> > > alongside the
> > > rest of the implementation, which I consider desirable for such
> > > relatively simple data structures."
> > 
> > So the main difference is this version of the patch kit is that the
> > tests
> > are run much earlier: rather than have a DejaGnu test below gcc.dg
> > that
> > compiles a dummy file with -fself-test, in this iteration,
> > gcc/Makefile.in
> > is updated so that the selftests are run during the build.
> > 
> > [snip]
> 
> I don't see any documentation here for the new command-line options. 
>  If 
> these are not intended to be user-visible, I think you should set the
> "Undocumented" flag for them in the .opt file instead.

Thanks; I'll do that in the next iteration of the patches.


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

2016-06-02 Thread Jakub Jelinek
On Thu, Jun 02, 2016 at 03:01:07PM +0200, Christophe Lyon wrote:
> On 1 June 2016 at 18:59, Matthias Klose  wrote:
> > On 01.06.2016 18:29, Bernd Schmidt wrote:
> >> On 05/13/2016 07:09 PM, Dhole wrote:
> >>> +pfile->source_date_epoch = 
> >>> pfile->cb.get_source_date_epoch(pfile);
> >>
> >> Space before paren. Ok with that change.
> >>
> >>> * c-common.h (c_omp_region_type): Remove trailing coma.
> >>
> >> Also, comma.
> >
> > committed with these changes.
> >
> 
> Since this was committed, I'm seeing:
> - ~random failures of pr61861:
> /aci-gcc-fsf/sources/gcc-fsf/gccsrc/gcc/testsuite/gcc.dg/pr61861.c:22:3:
> error: environment variable SOURCE_DATE_EPOCH must expand to a
> non-negative integer less than or equal to 253402300799
> 
> I've noticed that HJ has reported it on gcc-regressions, too.
> 
> It would help if the error message showed the value of SOURCE_DATE_EPOCH :)

I've fixed that already in r237035.

Jakub


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

2016-06-02 Thread Christophe Lyon
On 1 June 2016 at 18:59, Matthias Klose  wrote:
> On 01.06.2016 18:29, Bernd Schmidt wrote:
>> On 05/13/2016 07:09 PM, Dhole wrote:
>>> +pfile->source_date_epoch = pfile->cb.get_source_date_epoch(pfile);
>>
>> Space before paren. Ok with that change.
>>
>>> * c-common.h (c_omp_region_type): Remove trailing coma.
>>
>> Also, comma.
>
> committed with these changes.
>

Hi,

Since this was committed, I'm seeing:
- ~random failures of pr61861:
/aci-gcc-fsf/sources/gcc-fsf/gccsrc/gcc/testsuite/gcc.dg/pr61861.c:22:3:
error: environment variable SOURCE_DATE_EPOCH must expand to a
non-negative integer less than or equal to 253402300799

I've noticed that HJ has reported it on gcc-regressions, too.

It would help if the error message showed the value of SOURCE_DATE_EPOCH :)


Re: move increase_alignment from simple to regular ipa pass

2016-06-02 Thread Richard Biener
On Thu, 2 Jun 2016, David Edelsohn wrote:

> > Richard Biener wrote:
> 
> >> "This would mean the pass should get its own non-Optimization flag
> >> initialized by targets where section anchors are usually used"
> >> IIUC should we add a new option -fno-increase_alignment and gate the
> >> pass on it ? Um sorry I didn't understand why targets
> >> with section anchors (arm, aarch64, ppc) should initialize this option ?
> >
> > Currently the pass is only run for targets with section anchors (and there
> > by default if they are enabled by default).  So it makes sense to
> > run on those by default and the pass is not necessary on targets w/o
> > section anchors as the vectorizer can easily adjust alignment itself on
> > those.
> 
> PPC does not always enable section anchors -- it depends on the code
> model.  Shouldn't this be tied to use of section anchors?

It effectively is with the patch by walking all functions to see if they
have section anchors enabled.  That is unnecessary work for targets that
do not support section anchors at all, of course.

Richard.


Re: move increase_alignment from simple to regular ipa pass

2016-06-02 Thread David Edelsohn
> Richard Biener wrote:

>> "This would mean the pass should get its own non-Optimization flag
>> initialized by targets where section anchors are usually used"
>> IIUC should we add a new option -fno-increase_alignment and gate the
>> pass on it ? Um sorry I didn't understand why targets
>> with section anchors (arm, aarch64, ppc) should initialize this option ?
>
> Currently the pass is only run for targets with section anchors (and there
> by default if they are enabled by default).  So it makes sense to
> run on those by default and the pass is not necessary on targets w/o
> section anchors as the vectorizer can easily adjust alignment itself on
> those.

PPC does not always enable section anchors -- it depends on the code
model.  Shouldn't this be tied to use of section anchors?

Thanks, David


Re: Fix up dg-set-compiler-env-var

2016-06-02 Thread Jakub Jelinek
On Thu, Jun 02, 2016 at 02:26:28PM +0200, Bernd Schmidt wrote:
> On 06/02/2016 02:19 PM, Jakub Jelinek wrote:
> >The problem is that in cleanup-after-saved-dg-test, there are missing global
> >directives, so when it tests/uses the set_compiler_env_var and
> >saved_compiler_env_var vars to see if it should call
> >restore-compiler-env-var, it uses local (non-existing) vars instead and
> >never restores the env var.
> 
> I'm puzzled how failing to restore the env var causes a failure, but your
> patch is (obviously) ok.

The second of the tests using the new dg-set-compiler-env-var directive is
doing
/* { dg-set-compiler-env-var SOURCE_DATE_EPOCH "AAA" } */
and then expecting an error.  If the env var isn't restored, then on any of
the following testcases that uses __DATE__ and similar macros the env var
contains still AAA and thus results in an error.

Jakub


Re: Ping Re: Add option for whether ceil etc. can raise "inexact", adjust x86 conditions

2016-06-02 Thread Joseph Myers
On Thu, 2 Jun 2016, Jan Hubicka wrote:

> > Ping.  This patch 
> >  is pending 
> > review (for the non-x86-specific parts).
> The inliner bits looks fine to me. Of course it is easy to check whether the
> function actually calls floor/ceil and thus is affected by this flag.  Do you
> expect this to matter? I.e. do you expect that codebases will mix both values
> of this flag in one project and expect cross-module inlining to work with LTO?

I don't expect much use of this option until -fno-fp-int-builtin-inexact 
is implied by -std=c2x / -std=gnu2x (supposing TS 18661-1 gets integrated 
for the next major revision of the C standard - not the bug-fix revision 
due first).  At that point people might start using those options (I'd 
still expect people to be consistent within one project, but maybe not for 
separately maintained libraries).

-- 
Joseph S. Myers
jos...@codesourcery.com


Re: Ping Re: Add option for whether ceil etc. can raise "inexact", adjust x86 conditions

2016-06-02 Thread Joseph Myers
On Thu, 2 Jun 2016, Bernd Schmidt wrote:

> On 06/02/2016 02:00 PM, Jan Hubicka wrote:
> > > Ping.  This patch
> > >  is pending
> > > review (for the non-x86-specific parts).
> > The inliner bits looks fine to me.
> 
> In case that leaves anything unapproved, the remaining parts are OK too,
> modulo one question - shouldn't this option be added to the set enabled by
> -funsafe-math-optimizations? It looks like one pattern in i386.md used to be
> enabled by this option and now is no longer.

-funsafe-math-optimizations implies -fno-trapping-math which causes this 
option to have no effect (the difference between -ffp-int-builtin-inexact 
and -fno-fp-int-builtin-inexact is only meaningful if -ftrapping-math, 
since it relates to the raising of exceptions).  The patterns testing this 
option all test (flag_fp_int_builtin_inexact || !flag_trapping_math).

-- 
Joseph S. Myers
jos...@codesourcery.com


Re: Fix up dg-set-compiler-env-var

2016-06-02 Thread Bernd Schmidt

On 06/02/2016 02:19 PM, Jakub Jelinek wrote:

The problem is that in cleanup-after-saved-dg-test, there are missing global
directives, so when it tests/uses the set_compiler_env_var and
saved_compiler_env_var vars to see if it should call
restore-compiler-env-var, it uses local (non-existing) vars instead and
never restores the env var.


I'm puzzled how failing to restore the env var causes a failure, but 
your patch is (obviously) ok.



Bernd


Re: Ping Re: Add option for whether ceil etc. can raise "inexact", adjust x86 conditions

2016-06-02 Thread Bernd Schmidt

On 06/02/2016 02:00 PM, Jan Hubicka wrote:

Ping.  This patch
 is pending
review (for the non-x86-specific parts).

The inliner bits looks fine to me.


In case that leaves anything unapproved, the remaining parts are OK too, 
modulo one question - shouldn't this option be added to the set enabled 
by -funsafe-math-optimizations? It looks like one pattern in i386.md 
used to be enabled by this option and now is no longer.



Bernd


Re: [PATCH v4] gcov: Runtime configurable destination output

2016-06-02 Thread Nathan Sidwell

On 05/31/16 11:04, Aaron Conole wrote:

Nathan Sidwell  writes:


On 05/26/16 13:08, Aaron Conole wrote:

The previous gcov behavior was to always output errors on the stderr channel.
This is fine for most uses, but some programs will require stderr to be
untouched by libgcov for certain tests. This change allows configuring
the gcov output via an environment variable which will be used to open
the appropriate file.


this is ok, thanks.



After offlist discussion, I committed this patch.  Thanks Aaron!


nathan

2016-06-02  Aaron Conole  

	* libgcov-driver-system.c (__gcov_error_file): New.
	(get_gcov_error_file): New.
	(gcov_error): Use and set __gcov_error_file.
	(gcov_error_exit): New.
	* libgcov-driver.c (gcov_exit): Call gcov_error_exit.

Index: libgcov-driver-system.c
===
--- libgcov-driver-system.c	(revision 237032)
+++ libgcov-driver-system.c	(working copy)
@@ -23,19 +23,64 @@ a copy of the GCC Runtime Library Except
 see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 .  */
 
-/* A utility function for outputing errors.  */
+/* Configured via the GCOV_ERROR_FILE environment variable;
+   it will either be stderr, or a file of the user's choosing.
+   Non-static to prevent multiple gcov-aware shared objects from
+   instantiating their own copies. */
+FILE *__gcov_error_file = NULL;
+
+/* A utility function to populate the __gcov_error_file pointer.
+   This should NOT be called outside of the gcov system driver code. */
+
+static FILE *
+get_gcov_error_file(void)
+{
+#if !IN_GCOV_TOOL
+  return stderr;
+#else
+  char *gcov_error_filename = getenv ("GCOV_ERROR_FILE");
+
+  if (gcov_error_filename)
+{
+  FILE *openfile = fopen (gcov_error_filename, "a");
+  if (openfile)
+__gcov_error_file = openfile;
+}
+  if (!__gcov_error_file)
+__gcov_error_file = stderr;
+  return __gcov_error_file;
+#endif
+}
+
+/* A utility function for outputting errors.  */
 
 static int __attribute__((format(printf, 1, 2)))
 gcov_error (const char *fmt, ...)
 {
   int ret;
   va_list argp;
+
+  if (!__gcov_error_file)
+__gcov_error_file = get_gcov_error_file ();
+
   va_start (argp, fmt);
-  ret = vfprintf (stderr, fmt, argp);
+  ret = vfprintf (__gcov_error_file, fmt, argp);
   va_end (argp);
   return ret;
 }
 
+#if !IN_GCOV_TOOL
+static void
+gcov_error_exit (void)
+{
+  if (__gcov_error_file && __gcov_error_file != stderr)
+{
+  fclose (__gcov_error_file);
+  __gcov_error_file = NULL;
+}
+}
+#endif
+
 /* Make sure path component of the given FILENAME exists, create
missing directories. FILENAME must be writable.
Returns zero on success, or -1 if an error occurred.  */
Index: libgcov-driver.c
===
--- libgcov-driver.c	(revision 237032)
+++ libgcov-driver.c	(working copy)
@@ -43,9 +43,13 @@ void __gcov_init (struct gcov_info *p __
 
 #ifdef L_gcov
 
-/* A utility function for outputing errors.  */
+/* A utility function for outputting errors.  */
 static int gcov_error (const char *, ...);
 
+#if !IN_GCOV_TOOL
+static void gcov_error_exit (void);
+#endif
+
 #include "gcov-io.c"
 
 struct gcov_fn_buffer
@@ -878,6 +882,8 @@ gcov_exit (void)
 __gcov_root.prev->next = __gcov_root.next;
   else
 __gcov_master.root = __gcov_root.next;
+
+  gcov_error_exit ();
 }
 
 /* Add a new object file onto the bb chain.  Invoked automatically


Fix up dg-set-compiler-env-var

2016-06-02 Thread Jakub Jelinek
Hi!

On Fri, May 13, 2016 at 07:09:30PM +0200, Dhole wrote:
> --- a/gcc/testsuite/lib/gcc-dg.exp
> +++ b/gcc/testsuite/lib/gcc-dg.exp
> @@ -451,6 +451,38 @@ proc restore-target-env-var { } {
>  }
>  }
>  
> +proc dg-set-compiler-env-var { args } {

I've noticed last night pr61861.c FAIL in i686-linux bootstrap,
easily reproduceable with short:
make check-gcc RUNTESTFLAGS='cpp.exp=source_date* dg.exp=pr61861.c'

The problem is that in cleanup-after-saved-dg-test, there are missing global
directives, so when it tests/uses the set_compiler_env_var and
saved_compiler_env_var vars to see if it should call
restore-compiler-env-var, it uses local (non-existing) vars instead and
never restores the env var.

Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok of
trunk?

2016-06-02  Jakub Jelinek  

* lib/gcc-dg.exp (cleanup-after-saved-dg-test): Add missing
global set_compiler_env_var and global saved_compiler_env_var.

--- gcc/testsuite/lib/gcc-dg.exp.jj 2016-06-01 19:16:51.0 +0200
+++ gcc/testsuite/lib/gcc-dg.exp2016-06-02 11:56:54.429137894 +0200
@@ -895,6 +895,8 @@ if { [info procs saved-dg-test] == [list
global shouldfail
global testname_with_flags
global set_target_env_var
+   global set_compiler_env_var
+   global saved_compiler_env_var
global keep_saved_temps_suffixes
global multiline_expected_outputs
 


Jakub


Re: [PATCH] Fix first match heuristics

2016-06-02 Thread Jan Hubicka
> Hi.
> 
> Following patch fixes a typo in first match heuristics that blocks
> selection of best first match heuristics.
> 
> It's questionable whether to add a spacial test-case for that? I'm bit
> concerned that it can be a bit fragile.

Lets add it now to have better coverage. If it will keep breaking, we can 
always remove it later.
> 
> Bootstrapped and regtested on x86_64-linux.
> 
> Ready for trunk?
OK.

Honza


[C++ PATCH] Fix cp_fold dropping TREE_THIS_VOLATILE flag (PR c++/71372)

2016-06-02 Thread Jakub Jelinek
Hi!

When cp_fold is called on INDIRECT_REF and ARRAY*_REF and any of the
arguments change in the recursive calls, we fail to copy TREE_THIS_VOLATILE
flag.

Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for
trunk/6.2?

2016-06-02  Jakub Jelinek  

PR c++/71372
* cp-gimplify.c (cp_fold): For INDIRECT_REF, if the folded expression
is INDIRECT_REF or MEM_REF, copy over TREE_READONLY, TREE_SIDE_EFFECTS
and TREE_THIS_VOLATILE flags.  For ARRAY_REF and ARRAY_RANGE_REF, copy
over TREE_READONLY, TREE_SIDE_EFFECTS and TREE_THIS_VOLATILE flags
to the newly built tree.

* c-c++-common/pr71372.c: New test.

--- gcc/cp/cp-gimplify.c.jj 2016-05-26 10:38:01.0 +0200
+++ gcc/cp/cp-gimplify.c2016-06-02 10:21:33.903655321 +0200
@@ -2035,7 +2035,16 @@ cp_fold (tree x)
  if (op0 == error_mark_node)
x = error_mark_node;
  else
-   x = fold_build1_loc (loc, code, TREE_TYPE (x), op0);
+   {
+ x = fold_build1_loc (loc, code, TREE_TYPE (x), op0);
+ if (code == INDIRECT_REF
+ && (INDIRECT_REF_P (x) || TREE_CODE (x) == MEM_REF))
+   {
+ TREE_READONLY (x) = TREE_READONLY (org_x);
+ TREE_SIDE_EFFECTS (x) = TREE_SIDE_EFFECTS (org_x);
+ TREE_THIS_VOLATILE (x) = TREE_THIS_VOLATILE (org_x);
+   }
+   }
}
   else
x = fold (x);
@@ -2312,7 +2321,12 @@ cp_fold (tree x)
  || op3 == error_mark_node)
x = error_mark_node;
  else
-   x = build4_loc (loc, code, TREE_TYPE (x), op0, op1, op2, op3);
+   {
+ x = build4_loc (loc, code, TREE_TYPE (x), op0, op1, op2, op3);
+ TREE_READONLY (x) = TREE_READONLY (org_x);
+ TREE_SIDE_EFFECTS (x) = TREE_SIDE_EFFECTS (org_x);
+ TREE_THIS_VOLATILE (x) = TREE_THIS_VOLATILE (org_x);
+   }
}
 
   x = fold (x);
--- gcc/testsuite/c-c++-common/pr71372.c.jj 2016-06-02 10:53:40.994678549 
+0200
+++ gcc/testsuite/c-c++-common/pr71372.c2016-06-02 10:53:04.0 
+0200
@@ -0,0 +1,14 @@
+/* PR c++/71372 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+
+void
+foo (volatile int *p, int q)
+{
+  *(volatile int *)p = 0;
+  *(p + (q - q) + 1) = 0;
+  *(p + (q - q) + 2) = 0;
+  *(p + (q - q) + 3) = 0;
+}
+
+/* { dg-final { scan-tree-dump-times " ={v} " 4 "optimized" } } */

Jakub


Re: Ping Re: Add option for whether ceil etc. can raise "inexact", adjust x86 conditions

2016-06-02 Thread Jan Hubicka
> Ping.  This patch 
>  is pending 
> review (for the non-x86-specific parts).
The inliner bits looks fine to me. Of course it is easy to check whether the
function actually calls floor/ceil and thus is affected by this flag.  Do you
expect this to matter? I.e. do you expect that codebases will mix both values
of this flag in one project and expect cross-module inlining to work with LTO?
(Dealing with codegen flags in inliner is really painful. Basically I am trying
to do that on demand now - when I see it blocks inlining in one of larger 
project
I test. We will need better longer term strategry later I suppose.)

Honza
> 
> -- 
> Joseph S. Myers
> jos...@codesourcery.com


[PATCH 2/2] Add edge predictions pruning

2016-06-02 Thread marxin
contrib/ChangeLog:

2016-06-01  Martin Liska  

* analyze_brprob.py: Cover new dump output format.

gcc/ChangeLog:

2016-06-01  Martin Liska  

* predict.c (dump_prediction): Add new argument.
(enum predictor_reason): New enum.
(struct predictor_hash): New struct.
(predictor_hash::hash): New function.
(predictor_hash::equal): Likewise.
(not_removed_prediction_p): New function.
(prune_predictions_for_bb): Likewise.
(combine_predictions_for_bb): Prune predictions.

gcc/testsuite/ChangeLog:

2016-06-02  Martin Liska  

* g++.dg/predict-loop-exit-1.C: Cover new dump format.
* g++.dg/predict-loop-exit-2.C: Likewise.
* g++.dg/predict-loop-exit-3.C: Likewise.
* gcc.dg/predict-1.c: Likewise.
* gcc.dg/predict-3.c: Likewise.
* gcc.dg/predict-4.c: Likewise.
* gcc.dg/predict-5.c: Likewise.
* gcc.dg/predict-6.c: Likewise.
---
 contrib/analyze_brprob.py  |  10 +-
 gcc/predict.c  | 171 ++---
 gcc/testsuite/g++.dg/predict-loop-exit-1.C |   4 +-
 gcc/testsuite/g++.dg/predict-loop-exit-2.C |   4 +-
 gcc/testsuite/g++.dg/predict-loop-exit-3.C |   4 +-
 gcc/testsuite/gcc.dg/predict-1.c   |   2 +-
 gcc/testsuite/gcc.dg/predict-3.c   |   2 +-
 gcc/testsuite/gcc.dg/predict-4.c   |   2 +-
 gcc/testsuite/gcc.dg/predict-5.c   |   2 +-
 gcc/testsuite/gcc.dg/predict-6.c   |   2 +-
 10 files changed, 171 insertions(+), 32 deletions(-)

diff --git a/contrib/analyze_brprob.py b/contrib/analyze_brprob.py
index 36371ff..9416eed 100755
--- a/contrib/analyze_brprob.py
+++ b/contrib/analyze_brprob.py
@@ -122,14 +122,14 @@ if len(sys.argv) != 2:
 exit(1)
 
 profile = Profile(sys.argv[1])
-r = re.compile('  (.*) heuristics: (.*)%.*exec ([0-9]*) hit ([0-9]*)')
+r = re.compile('  (.*) heuristics( of edge [0-9]*->[0-9]*)?( \\(.*\\))?: 
(.*)%.*exec ([0-9]*) hit ([0-9]*)')
 for l in open(profile.filename).readlines():
 m = r.match(l)
-if m != None:
+if m != None and m.group(3) == None:
 name = m.group(1)
-prediction = float(m.group(2))
-count = int(m.group(3))
-hits = int(m.group(4))
+prediction = float(m.group(4))
+count = int(m.group(5))
+hits = int(m.group(6))
 
 profile.add(name, prediction, count, hits)
 
diff --git a/gcc/predict.c b/gcc/predict.c
index 51a9993..dab97ad 100644
--- a/gcc/predict.c
+++ b/gcc/predict.c
@@ -55,13 +55,25 @@ along with GCC; see the file COPYING3.  If not see
 #include "tree-ssa-loop.h"
 #include "tree-scalar-evolution.h"
 
+enum predictor_reason
+{
+  NONE,
+  IGNORED,
+  SINGLE_EDGE_DUPLICATE,
+  EDGE_PAIR_DUPLICATE
+};
+
+static const char *reason_messages[] = {"", " (ignored)",
+" (single edge duplicate)", " (edge pair duplicate)"};
+
 /* real constants: 0, 1, 1-1/REG_BR_PROB_BASE, REG_BR_PROB_BASE,
   1/REG_BR_PROB_BASE, 0.5, BB_FREQ_MAX.  */
 static sreal real_almost_one, real_br_prob_base,
 real_inv_br_prob_base, real_one_half, real_bb_freq_max;
 
 static void combine_predictions_for_insn (rtx_insn *, basic_block);
-static void dump_prediction (FILE *, enum br_predictor, int, basic_block, int);
+static void dump_prediction (FILE *, enum br_predictor, int, basic_block,
+enum predictor_reason, edge);
 static void predict_paths_leading_to (basic_block, enum br_predictor, enum 
prediction);
 static void predict_paths_leading_to_edge (edge, enum br_predictor, enum 
prediction);
 static bool can_predict_insn_p (const rtx_insn *);
@@ -724,7 +736,8 @@ invert_br_probabilities (rtx insn)
 
 static void
 dump_prediction (FILE *file, enum br_predictor predictor, int probability,
-basic_block bb, int used)
+basic_block bb, enum predictor_reason reason = NONE,
+edge ep_edge = NULL)
 {
   edge e;
   edge_iterator ei;
@@ -736,9 +749,17 @@ dump_prediction (FILE *file, enum br_predictor predictor, 
int probability,
 if (! (e->flags & EDGE_FALLTHRU))
   break;
 
-  fprintf (file, "  %s heuristics%s: %.1f%%",
+  char edge_info_str[128];
+  if (ep_edge)
+sprintf (edge_info_str, " of edge %d->%d", ep_edge->src->index,
+ep_edge->dest->index);
+  else
+edge_info_str[0] = '\0';
+
+  fprintf (file, "  %s heuristics%s%s: %.1f%%",
   predictor_info[predictor].name,
-  used ? "" : " (ignored)", probability * 100.0 / REG_BR_PROB_BASE);
+  edge_info_str, reason_messages[reason],
+  probability * 100.0 / REG_BR_PROB_BASE);
 
   if (bb->count)
 {
@@ -835,18 +856,18 @@ combine_predictions_for_insn (rtx_insn *insn, basic_block 
bb)
 
   if (!found)
 dump_prediction (dump_file, PRED_NO_PREDICTION,
-combined_probability, bb, true);
+combined_probability, bb);
   else
  

[PATCH 0/2] Deduplicate edge predictors

2016-06-02 Thread marxin
Hi.

Following small series makes deduplication of predictors in following 2 ways:
   1) remove duplicate prediction that is guessed with the same probability
  (different than 1/2) to both edges
   2) remove duplicates for a prediction that belongs with the same probability
  to a single edge

Patch also changes dump output format a bit, thus analyze_brprob.py script
has been also modified to understand the format.

Bootstrapped and regtested on x86_64-linux

Ready for trunk?
Martin

marxin (2):
  Introduce filtering for edge_predictions.
  Add edge predictions pruning

 contrib/analyze_brprob.py  |  10 +-
 gcc/predict.c  | 209 +
 gcc/testsuite/g++.dg/predict-loop-exit-1.C |   4 +-
 gcc/testsuite/g++.dg/predict-loop-exit-2.C |   4 +-
 gcc/testsuite/g++.dg/predict-loop-exit-3.C |   4 +-
 gcc/testsuite/gcc.dg/predict-1.c   |   2 +-
 gcc/testsuite/gcc.dg/predict-3.c   |   2 +-
 gcc/testsuite/gcc.dg/predict-4.c   |   2 +-
 gcc/testsuite/gcc.dg/predict-5.c   |   2 +-
 gcc/testsuite/gcc.dg/predict-6.c   |   2 +-
 10 files changed, 201 insertions(+), 40 deletions(-)

-- 
2.8.3



[PATCH 1/2] Introduce filtering for edge_predictions.

2016-06-02 Thread marxin
gcc/ChangeLog:

2016-05-31  Martin Liska  

* predict.c (filter_predictions): New function.
(remove_predictions_associated_with_edge): Use the filter
function.
(equal_edge_p): New function.
---
 gcc/predict.c | 38 ++
 1 file changed, 30 insertions(+), 8 deletions(-)

diff --git a/gcc/predict.c b/gcc/predict.c
index e9dda20..51a9993 100644
--- a/gcc/predict.c
+++ b/gcc/predict.c
@@ -609,16 +609,16 @@ gimple_predict_edge (edge e, enum br_predictor predictor, 
int probability)
 }
 }
 
-/* Remove all predictions on given basic block that are attached
-   to edge E.  */
+/* Filter edge predictions PREDS by a function FILTER.  DATA are passed
+   to the filter function.  */
+
 void
-remove_predictions_associated_with_edge (edge e)
+filter_predictions (edge_prediction **preds,
+   bool (*filter) (edge_prediction *, void *), void *data)
 {
   if (!bb_predictions)
 return;
 
-  edge_prediction **preds = bb_predictions->get (e->src);
-
   if (preds)
 {
   struct edge_prediction **prediction = preds;
@@ -626,18 +626,40 @@ remove_predictions_associated_with_edge (edge e)
 
   while (*prediction)
{
- if ((*prediction)->ep_edge == e)
+ if ((*filter) (*prediction, data))
+   prediction = &((*prediction)->ep_next);
+ else
{
  next = (*prediction)->ep_next;
  free (*prediction);
  *prediction = next;
}
- else
-   prediction = &((*prediction)->ep_next);
}
 }
 }
 
+/* Filter function predicate that returns true for a edge predicate P
+   if its edge is equal to DATA.  */
+
+bool
+equal_edge_p (edge_prediction *p, void *data)
+{
+  return p->ep_edge == (edge)data;
+}
+
+/* Remove all predictions on given basic block that are attached
+   to edge E.  */
+
+void
+remove_predictions_associated_with_edge (edge e)
+{
+  if (!bb_predictions)
+return;
+
+  edge_prediction **preds = bb_predictions->get (e->src);
+  filter_predictions (preds, equal_edge_p, e);
+}
+
 /* Clears the list of predictions stored for BB.  */
 
 static void
-- 
2.8.3




Ping Re: Add option for whether ceil etc. can raise "inexact", adjust x86 conditions

2016-06-02 Thread Joseph Myers
Ping.  This patch 
 is pending 
review (for the non-x86-specific parts).

-- 
Joseph S. Myers
jos...@codesourcery.com


[PR c/71381] C/C++ OpenACC cache directive rejects valid syntax (was: [gomp4] OpenACC cache directive for C.)

2016-06-02 Thread Thomas Schwinge
Hi!

On Wed, 05 Nov 2014 17:29:19 +0100, I wrote:
> In r217145, I applied Jim's patch to gomp-4_0-branch:
> 
> commit 4361f9b6b2c74c2961c3a5290a4945abe2d7a444
> Author: tschwinge 
> Date:   Wed Nov 5 16:26:47 2014 +
> 
> OpenACC cache directive for C.

(That, and the corresponding C++ changes later made it into trunk.)

> --- gcc/c/c-parser.c
> +++ gcc/c/c-parser.c
> @@ -10053,6 +10053,14 @@ c_parser_omp_variable_list (c_parser *parser,
>   {
> switch (kind)
>   {
> + case OMP_NO_CLAUSE_CACHE:
> +   if (c_parser_peek_token (parser)->type != CPP_OPEN_SQUARE)
> + {
> +   c_parser_error (parser, "expected %<[%>");
> +   t = error_mark_node;
> +   break;
> + }
> +   /* FALL THROUGH.  */
>   case OMP_CLAUSE_MAP:
>   case OMP_CLAUSE_FROM:
>   case OMP_CLAUSE_TO:

Strictly speaking (OpenACC 2.0a specification), that is correct: the
OpenACC cache directive explicitly only allows "array elements or
subarrays".  However, I wonder if it would make sense to allow complete
arrays as a GNU extension?  That is, syntactic sugar to allow "cache (a)"
to mean "cache (a[0:LENGTH])"?

> @@ -10091,6 +10099,29 @@ c_parser_omp_variable_list (c_parser *parser,
> t = error_mark_node;
> break;
>   }
> +
> +   if (kind == OMP_NO_CLAUSE_CACHE)
> + {
> +   mark_exp_read (low_bound);
> +   mark_exp_read (length);
> +
> +   if (TREE_CODE (low_bound) != INTEGER_CST
> +   && !TREE_READONLY (low_bound))
> + {
> +   error_at (clause_loc,
> + "%qD is not a constant", low_bound);
> +   t = error_mark_node;
> + }

WHile OpenACC 2.0a specifies that "the lower bound is a constant", it
also permits the lower bound to be a "loop invariant, or the for loop
index variable plus or minus a constant or loop invariant".  So, we're
rejecting valid syntax here.

> +
> +   if (TREE_CODE (length) != INTEGER_CST
> +   && !TREE_READONLY (length))
> + {
> +   error_at (clause_loc,
> + "%qD is not a constant", length);
> +   t = error_mark_node;
> + }
> + }

The idea is correct (OpenACC 2.0a: "the length is a constant"), but we
can't reliably check that here; for example:

#pragma acc cache (a[0:n + 1])

... will run into an ICE, "tree check: expected tree that contains 'decl
minimal' structure, have 'plus_expr' in [...]".

Currently we're discarding the OpenACC cache directive in the middle end;
I expect checking of the lower bound and length will come automatically
as soon as we start to do something with OACC_CACHE/OMP_CLAUSE__CACHE_.
Until then, I propose we simple remove these checks from the front ends.
OK for trunk and gcc-6-branch?

commit a620ebe6fa509ec6441ba87276e55078eb2d00fc
Author: Thomas Schwinge 
Date:   Thu Jun 2 12:19:49 2016 +0200

[PR c/71381] C/C++ OpenACC cache directive rejects valid syntax

gcc/c/
PR c/71381
* c-parser.c (c_parser_omp_variable_list) :
Loosen checking.
gcc/cp/
PR c/71381
* parser.c (cp_parser_omp_var_list_no_open) :
Loosen checking.
gcc/fortran/
PR c/71381
* openmp.c (gfc_match_oacc_cache): Add comment.
gcc/testsuite/
PR c/71381
* c-c++-common/goacc/cache-1.c: Update.  Move invalid usage tests
to...
* c-c++-common/goacc/cache-2.c: ... this new file.
* gfortran.dg/goacc/cache-1.f95: Move invalid usage tests to...
* gfortran.dg/goacc/cache-2.f95: ... this new file.
* gfortran.dg/goacc/coarray.f95: Update OpenACC cache directive
usage.
* gfortran.dg/goacc/cray.f95: Likewise.
* gfortran.dg/goacc/loop-1.f95: Likewise.
libgomp/
PR c/71381
* testsuite/libgomp.oacc-c-c++-common/cache-1.c: #include
"../../../gcc/testsuite/c-c++-common/goacc/cache-1.c".
* testsuite/libgomp.oacc-fortran/cache-1.f95: New file.

gcc/
* omp-low.c (scan_sharing_clauses): Don't expect
OMP_CLAUSE__CACHE_.
---
 gcc/c/c-parser.c   | 22 +---
 gcc/cp/parser.c| 22 +---
 gcc/fortran/openmp.c   |  5 ++
 gcc/omp-low.c  |  6 --
 gcc/testsuite/c-c++-common/goacc/cache-1.c | 66 --
 .../c-c++-common/goacc/{cache-1.c => cache-2.c}| 39 ++---
 gcc/testsuite/gfortran.dg/goacc/cache-1.f95|  7 +--
 

[PATCH] Fix first match heuristics

2016-06-02 Thread Martin Liška
Hi.

Following patch fixes a typo in first match heuristics that blocks
selection of best first match heuristics.

It's questionable whether to add a spacial test-case for that? I'm bit
concerned that it can be a bit fragile.

Bootstrapped and regtested on x86_64-linux.

Ready for trunk?
Thanks,
Martin
>From 4106928c3eea80c732d32d73d653525c698515d6 Mon Sep 17 00:00:00 2001
From: marxin 
Date: Thu, 2 Jun 2016 11:51:57 +0200
Subject: [PATCH] Fix first match heuristics

gcc/ChangeLog:

2016-06-02  Martin Liska  

	* predict.c (combine_predictions_for_bb): Fix first match in
	cases where a first predictor contains more than one occurence
	in list of predictors.  Take the best value in such case.

gcc/testsuite/ChangeLog:

2016-06-02  Martin Liska  

	* gcc.dg/predict-9.c: New test.
---
 gcc/predict.c|  2 +-
 gcc/testsuite/gcc.dg/predict-9.c | 23 +++
 2 files changed, 24 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gcc.dg/predict-9.c

diff --git a/gcc/predict.c b/gcc/predict.c
index e9dda20..429f44e 100644
--- a/gcc/predict.c
+++ b/gcc/predict.c
@@ -939,7 +939,7 @@ combine_predictions_for_bb (basic_block bb, bool dry_run)
 		   pred2; pred2 = pred2->ep_next)
 	   if (pred2 != pred && pred2->ep_predictor == pred->ep_predictor)
 	 {
-	   int probability2 = pred->ep_probability;
+		   int probability2 = pred2->ep_probability;
 
 		   if (pred2->ep_edge != first)
 		 probability2 = REG_BR_PROB_BASE - probability2;
diff --git a/gcc/testsuite/gcc.dg/predict-9.c b/gcc/testsuite/gcc.dg/predict-9.c
new file mode 100644
index 000..59be16e
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/predict-9.c
@@ -0,0 +1,23 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-profile_estimate" } */
+
+extern int global;
+extern int global2;
+extern int global3;
+
+void foo (int base)
+{
+  int i;
+  while (global < 10)
+  {
+if(global || global2 || global3)
+  return;
+
+for (i = base; i < 10; i++)
+  if (i > 123)
+	return;
+  }
+}
+
+/* { dg-final { scan-tree-dump-times "first match heuristics: 2.0%" 4 "profile_estimate"} } */
+/* { dg-final { scan-tree-dump-times "first match heuristics: 4.5%" 0 "profile_estimate"} } */
-- 
2.8.3



[ipa-comdats] create a new comdat group for symbol if it's referenced from multiple comdat groups

2016-06-02 Thread Prathamesh Kulkarni
Hi,
I was trying to address first TODO from ipa-comdats.c (attached patch)
TODO: When symbol is used only by comdat symbols, but from different groups,
it would make sense to produce a new comdat group for it with anonymous name.

The patch simply puts symbol in a new comdat group and makes symbol
the head of that group if newgroup and *val2 are COMDAT but not equal
instead of setting newgroup to BOTTOM.
Does this approach look reasonable ?

For test-1.C (attached) q() is referenced from i1() and i2()
which are comdat symbols and hence q() is put in it's own comdat-section.
I suppose that's the expected result ?

However it fails for test-2.C (attached) with the error
error: comdat-local function called by int i1() outside its comdat
and ICE verify_cgraph_node failed follows, which comes from
cgraph.c:3095:

bool check_comdat = comdat_local_p ();

if (check_comdat
&& !in_same_comdat_group_p (e->caller))
  {
  error ("comdat-local function called by %s outside its comdat",
 identifier_to_locale (e->caller->name ()));
   error_found = true;
   }

Patch works for test-1.C because although q() is in different comdat
group from it's
callers, it's the only function in that group and hence
same_comdat_group is NULL
so comdat_local_p() returns false. Since check_comdat becomes false, we don't
hit the error.

For test-2.C, since r() is called by q(), the patch puts r() and q() in same
comdat group with name "q".
In this case for q(), comdat_local_p() returns true, because
same_comdat_group is non-NULL.
Since check_comdat is true and q() and it's caller i1() are not in
same comdat groups, we hit the error.

I am not sure how to fix this, and would be grateful for suggestions.
I assumed r() and q() should be in same comdat group since q() became
a comdat symbol
and r() is only referenced from q().

Also, what name would be appropriate for "anonymous" comdat group ?
I am currently giving it the name of the first symbol that gets put into it.

Thanks,
Prathamesh
diff --git a/gcc/ipa-comdats.c b/gcc/ipa-comdats.c
index 6e0f762..ea59bd9 100644
--- a/gcc/ipa-comdats.c
+++ b/gcc/ipa-comdats.c
@@ -55,6 +55,48 @@ along with GCC; see the file COPYING3.  If not see
 #include "tree.h"
 #include "tree-pass.h"
 #include "cgraph.h"
+#include "tree-pretty-print.h"
+
+tree
+merge_comdat_group  (tree *val2, tree newgroup,
+symtab_node *symbol,
+hash_map& comdat_head_map)
+{
+  /* *val2 is TOP.  */ 
+  if (val2 == NULL || *val2 == NULL)
+return newgroup;
+
+  /* *val2 is BOTTOM.  */ 
+  else if (*val2 == error_mark_node)
+return error_mark_node;
+
+  /* *val2 is COMDAT.  */
+  else
+{
+  /* COMDAT meet TOP == COMDAT.  */
+  if (newgroup == NULL)
+   return *val2;
+
+  /* COMDAT meet BOTTOM == BOTTOM.  */
+  else if (newgroup == error_mark_node)
+   return error_mark_node;
+
+  /* COMDAT meet COMDAT == COMDAT if both are equal else
+create new comdat group and assign it to symbol.  */ 
+  else
+   {
+ if (newgroup == *val2)
+   return newgroup;
+ 
+ /* FIXME: using DECL_NAME (symbol->decl) as name of comdat section.  
*/
+ newgroup = DECL_NAME (symbol->decl);
+ DECL_COMDAT (symbol->decl) = 1;
+ symbol->set_comdat_group (newgroup);
+ comdat_head_map.put (newgroup, symbol);
+ return newgroup;
+   }
+}
+}
 
 /* Main dataflow loop propagating comdat groups across
the symbol table.  All references to SYMBOL are examined
@@ -63,7 +105,8 @@ along with GCC; see the file COPYING3.  If not see
 
 tree
 propagate_comdat_group (struct symtab_node *symbol,
-   tree newgroup, hash_map )
+   tree newgroup, hash_map ,
+   hash_map& comdat_head_map)
 {
   int i;
   struct ipa_ref *ref;
@@ -78,7 +121,7 @@ propagate_comdat_group (struct symtab_node *symbol,
 
   if (ref->use == IPA_REF_ALIAS)
{
- newgroup = propagate_comdat_group (symbol2, newgroup, map);
+ newgroup = propagate_comdat_group (symbol2, newgroup, map, 
comdat_head_map);
  continue;
}
 
@@ -105,7 +148,8 @@ propagate_comdat_group (struct symtab_node *symbol,
   /* The actual merge operation.  */
 
   tree *val2 = map.get (symbol2);
-
+  newgroup = merge_comdat_group (val2, newgroup, symbol, comdat_head_map);
+#if 0
   if (val2 && *val2 != newgroup)
{
  if (!newgroup)
@@ -113,6 +157,7 @@ propagate_comdat_group (struct symtab_node *symbol,
  else
newgroup = error_mark_node;
}
+#endif
 }
 
   /* If we analyze function, walk also callers.  */
@@ -129,7 +174,7 @@ propagate_comdat_group (struct symtab_node *symbol,
  {
/* Thunks can not call across section boundary.  */
if (cn->thunk.thunk_p)
- newgroup = 

Re: [PATCH] Improve *vec_concatv2si_sse4_1

2016-06-02 Thread Uros Bizjak
On Thu, May 26, 2016 at 9:24 PM, Jakub Jelinek  wrote:
> On Thu, May 26, 2016 at 07:39:01PM +0200, Uros Bizjak wrote:
>> On Thu, May 26, 2016 at 7:05 PM, Jakub Jelinek  wrote:
>> > Hi!
>> >
>> > This patch adds an avx512dq alternative (EVEX vpinsrd requires that) and
>> > enables EVEX vmovd and vpunpckldq.
>> >
>> > Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
>> >
>> > 2016-05-26  Jakub Jelinek  
>> >
>> > * config/i386/sse.md (*vec_concatv2si_sse4_1): Add avx512dq v=Yv,rm
>> > alternative.  Change x=x,x alternative to v=Yv,Yv and x=rm,C
>> > alternative to v=rm,C.
>> >
>> > * gcc.target/i386/avx512dq-concatv2si-1.c: New test.
>> > * gcc.target/i386/avx512vl-concatv2si-1.c: New test.
>>
>> Ouch, I have just changed these mega strings in attribute definitions
>> to something more readable. Can you please redo the attribute part? It
>> should be much more pleasant experience than counting all the
>> commas...).
>
> Here is updated version of this patch (the other two pending sse.md patches
> from me still apply cleanly):
>
> 2016-05-26  Jakub Jelinek  
>
> * config/i386/sse.md (*vec_concatv2si_sse4_1): Add avx512dq v=Yv,rm
> alternative.  Change x=x,x alternative to v=Yv,Yv and x=rm,C
> alternative to v=rm,C.
>
> * gcc.target/i386/avx512dq-concatv2si-1.c: New test.
> * gcc.target/i386/avx512vl-concatv2si-1.c: New test.

OK.

Thanks,
Uros.

> --- gcc/config/i386/sse.md.jj   2016-05-26 10:44:25.0 +0200
> +++ gcc/config/i386/sse.md  2016-05-26 14:22:26.819313220 +0200
> @@ -13488,43 +13488,44 @@
>
>  (define_insn "*vec_concatv2si_sse4_1"
>[(set (match_operand:V2SI 0 "register_operand"
> - "=Yr,*x,x, Yr,*x,x, x, *y,*y")
> + "=Yr,*x, x, v,Yr,*x, v, v, *y,*y")
> (vec_concat:V2SI
>   (match_operand:SI 1 "nonimmediate_operand"
> - "  0, 0,x,  0,0, x,rm,  0,rm")
> + "  0, 0, x,Yv, 0, 0,Yv,rm,  0,rm")
>   (match_operand:SI 2 "vector_move_operand"
> - " rm,rm,rm,Yr,*x,x, C,*ym, C")))]
> + " rm,rm,rm,rm,Yr,*x,Yv, C,*ym, C")))]
>"TARGET_SSE4_1 && !(MEM_P (operands[1]) && MEM_P (operands[2]))"
>"@
> pinsrd\t{$1, %2, %0|%0, %2, 1}
> pinsrd\t{$1, %2, %0|%0, %2, 1}
> vpinsrd\t{$1, %2, %1, %0|%0, %1, %2, 1}
> +   vpinsrd\t{$1, %2, %1, %0|%0, %1, %2, 1}
> punpckldq\t{%2, %0|%0, %2}
> punpckldq\t{%2, %0|%0, %2}
> vpunpckldq\t{%2, %1, %0|%0, %1, %2}
> %vmovd\t{%1, %0|%0, %1}
> punpckldq\t{%2, %0|%0, %2}
> movd\t{%1, %0|%0, %1}"
> -  [(set_attr "isa" "noavx,noavx,avx,noavx,noavx,avx,*,*,*")
> +  [(set_attr "isa" "noavx,noavx,avx,avx512dq,noavx,noavx,avx,*,*,*")
> (set (attr "type")
> - (cond [(eq_attr "alternative" "6")
> + (cond [(eq_attr "alternative" "7")
>   (const_string "ssemov")
> -   (eq_attr "alternative" "7")
> - (const_string "mmxcvt")
> (eq_attr "alternative" "8")
> + (const_string "mmxcvt")
> +   (eq_attr "alternative" "9")
>   (const_string "mmxmov")
>]
>(const_string "sselog")))
> (set (attr "prefix_extra")
> - (if_then_else (eq_attr "alternative" "0,1,2")
> + (if_then_else (eq_attr "alternative" "0,1,2,3")
>(const_string "1")
>(const_string "*")))
> (set (attr "length_immediate")
> - (if_then_else (eq_attr "alternative" "0,1,2")
> + (if_then_else (eq_attr "alternative" "0,1,2,3")
>(const_string "1")
>(const_string "*")))
> -   (set_attr "prefix" "orig,orig,vex,orig,orig,vex,maybe_vex,orig,orig")
> -   (set_attr "mode" "TI,TI,TI,TI,TI,TI,TI,DI,DI")])
> +   (set_attr "prefix" 
> "orig,orig,vex,evex,orig,orig,maybe_evex,maybe_vex,orig,orig")
> +   (set_attr "mode" "TI,TI,TI,TI,TI,TI,TI,TI,DI,DI")])
>
>  ;; ??? In theory we can match memory for the MMX alternative, but allowing
>  ;; nonimmediate_operand for operand 2 and *not* allowing memory for the SSE
> --- gcc/testsuite/gcc.target/i386/avx512dq-concatv2si-1.c.jj2016-05-26 
> 15:14:55.853786550 +0200
> +++ gcc/testsuite/gcc.target/i386/avx512dq-concatv2si-1.c   2016-05-26 
> 15:13:57.0 +0200
> @@ -0,0 +1,43 @@
> +/* { dg-do compile { target { ! ia32 } } } */
> +/* { dg-options "-O2 -mavx512vl -mavx512dq -masm=att" } */
> +
> +typedef int V __attribute__((vector_size (8)));
> +
> +void
> +f1 (int x, int y)
> +{
> +  register int a __asm ("xmm16");
> +  register int b __asm ("xmm17");
> +  register V c __asm ("xmm3");
> +  a = x;
> +  b = y;
> +  asm volatile ("" : "+v" (a), "+v" (b));
> +  c = (V) { a, b };
> +  asm volatile ("" : "+v" (c));
> +}
> +
> +/* { dg-final { scan-assembler 
> "vpunpckldq\[^\n\r]*%xmm17\[^\n\r]*%xmm16\[^\n\r]*%xmm3" } } */
> +
> +void
> +f2 (int x, int y)
> +{
> +  register int a __asm ("xmm16");
> +  

Re: [PATCH] Improve *vec_concatv4si

2016-06-02 Thread Uros Bizjak
On Thu, May 26, 2016 at 7:07 PM, Jakub Jelinek  wrote:
> Hi!
>
> Both vpunpcklqdq and vmovhps are available with XMM EVEX args in AVX512VL.
>
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
>
> 2016-05-26  Jakub Jelinek  
>
> * config/i386/sse.md (*vec_concatv4si): Use v=v,v instead of
> x=x,x and v=v,m instead of x=x,m.
>
> * gcc.target/i386/avx512vl-concatv4si-1.c: New test.

OK.

Thanks,
Uros.

> --- gcc/config/i386/sse.md.jj   2016-05-26 14:22:26.0 +0200
> +++ gcc/config/i386/sse.md  2016-05-26 15:37:40.029856077 +0200
> @@ -13386,10 +13386,10 @@ (define_insn "*vec_concatv2si"
> (set_attr "mode" "TI,TI,DI,V4SF,SF,DI,DI")])
>
>  (define_insn "*vec_concatv4si"
> -  [(set (match_operand:V4SI 0 "register_operand"   "=x,x,x,x,x")
> +  [(set (match_operand:V4SI 0 "register_operand"   "=x,v,x,x,v")
> (vec_concat:V4SI
> - (match_operand:V2SI 1 "register_operand" " 0,x,0,0,x")
> - (match_operand:V2SI 2 "nonimmediate_operand" " x,x,x,m,m")))]
> + (match_operand:V2SI 1 "register_operand" " 0,v,0,0,v")
> + (match_operand:V2SI 2 "nonimmediate_operand" " x,v,x,m,m")))]
>"TARGET_SSE"
>"@
> punpcklqdq\t{%2, %0|%0, %2}
> @@ -13399,7 +13399,7 @@ (define_insn "*vec_concatv4si"
> vmovhps\t{%2, %1, %0|%0, %1, %q2}"
>[(set_attr "isa" "sse2_noavx,avx,noavx,noavx,avx")
> (set_attr "type" "sselog,sselog,ssemov,ssemov,ssemov")
> -   (set_attr "prefix" "orig,vex,orig,orig,vex")
> +   (set_attr "prefix" "orig,maybe_evex,orig,orig,maybe_evex")
> (set_attr "mode" "TI,TI,V4SF,V2SF,V2SF")])
>
>  ;; movd instead of movq is required to handle broken assemblers.
> --- gcc/testsuite/gcc.target/i386/avx512vl-concatv4si-1.c.jj2016-05-26 
> 15:45:13.978880684 +0200
> +++ gcc/testsuite/gcc.target/i386/avx512vl-concatv4si-1.c   2016-05-26 
> 15:46:27.643911021 +0200
> @@ -0,0 +1,23 @@
> +/* { dg-do compile { target { ! ia32 } } } */
> +/* { dg-options "-O2 -mavx512vl" } */
> +
> +typedef int V __attribute__((vector_size (8)));
> +typedef int W __attribute__((vector_size (16)));
> +
> +void
> +f1 (V x, V y)
> +{
> +  register W c __asm ("xmm16");
> +  c = (W) { x[0], x[1], x[0], x[1] };
> +  asm volatile ("" : "+v" (c));
> +}
> +
> +void
> +f2 (V x, V *y)
> +{
> +  register W c __asm ("xmm16");
> +  c = (W) { x[0], x[1], (*y)[0], (*y)[1] };
> +  asm volatile ("" : "+v" (c));
> +}
> +
> +/* { dg-final { scan-assembler-times "vpunpcklqdq\[^\n\r]*xmm16" 2 } } */
>
> Jakub


Re: [PATCH] Support for SPARC M7 and VIS 4.0

2016-06-02 Thread Jose E. Marchesi

> I will also fix all the other points you raised.
> Thanks!

You're welcome.  And if you want to have commit rights to the SVN 
repository, 
you can put me as your sponsor (Eric Botcazou ).

I just sent a request.  Thank you.


  1   2   >