Re: [PATCH] Allow relayout_decl on FIELD_DECLs (PR c/72816)

2016-08-07 Thread Richard Biener
On August 6, 2016 9:09:08 PM GMT+02:00, Jakub Jelinek  wrote:
>Hi!
>
>As the testcase shows, the C FE can call relayout_decl even on
>FIELD_DECLs
>in certain cases.  Trying to call only layout_decl on FIELD_DECL and
>relayout_decl on other decls would be insufficient, we'd need to repeat
>there most of the relayout_decl code (except for SET_DECL_RTL, which
>FIELD_DECLs don't have).
>
>So I think it is better to allow relayout_decl also on FIELD_DECLs.
>
>Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

OK.

Thanks,
Richard.

>2016-08-06  Jakub Jelinek  
>
>   PR c/72816
>   * stor-layout.c (layout_decl): Fix up formatting.
>   (relayout_decl): Allow DECL to be FIELD_DECL.
>
>   * gcc.dg/pr72816.c: New test.
>
>--- gcc/stor-layout.c.jj   2016-08-06 12:11:56.0 +0200
>+++ gcc/stor-layout.c  2016-08-06 13:04:43.662532852 +0200
>@@ -596,7 +596,7 @@ layout_decl (tree decl, unsigned int kno
> return;
> 
>gcc_assert (code == VAR_DECL || code == PARM_DECL || code ==
>RESULT_DECL
>-|| code == TYPE_DECL ||code == FIELD_DECL);
>+|| code == TYPE_DECL || code == FIELD_DECL);
> 
>   rtl = DECL_RTL_IF_SET (decl);
> 
>@@ -768,8 +768,8 @@ layout_decl (tree decl, unsigned int kno
> }
> }
> 
>-/* Given a VAR_DECL, PARM_DECL or RESULT_DECL, clears the results of
>-   a previous call to layout_decl and calls it again.  */
>+/* Given a VAR_DECL, PARM_DECL, RESULT_DECL, or FIELD_DECL, clears the
>+   results of a previous call to layout_decl and calls it again.  */
> 
> void
> relayout_decl (tree decl)
>@@ -778,7 +778,8 @@ relayout_decl (tree decl)
>   DECL_MODE (decl) = VOIDmode;
>   if (!DECL_USER_ALIGN (decl))
> SET_DECL_ALIGN (decl, 0);
>-  SET_DECL_RTL (decl, 0);
>+  if (DECL_RTL_SET_P (decl))
>+SET_DECL_RTL (decl, 0);
> 
>   layout_decl (decl, 0);
> }
>--- gcc/testsuite/gcc.dg/pr72816.c.jj  2016-08-06 13:06:45.046003282
>+0200
>+++ gcc/testsuite/gcc.dg/pr72816.c 2016-08-06 13:07:57.217093845 +0200
>@@ -0,0 +1,9 @@
>+/* PR c/72816 */
>+/* { dg-do compile } */
>+/* { dg-options "-std=gnu11" } */
>+
>+typedef const int A[];
>+struct S {
>+  int a;
>+  A b;/* { dg-error "array size missing" } */
>+};
>
>   Jakub




[Fortran, Patch, PR72698, v1] [5/6/7 Regression] ICE in lhd_incomplete_type_error, at langhooks.c:205

2016-08-07 Thread Andre Vehreschild
Hi all,

attached patch fixes the ICE caused by a zero-sized string. Assigning
that string to a temporary variable obviously did not work out. The
patch fixes this by checking for zero-sized strings in SOURCE= and not
producing the code to assign "nothing" to the temporary
variable and later to the allocated memory. The version for gcc-5 had
to be adapted slightly, because the version of the ALLOCATE()
implementation is way behind.

Bootstrapped and regtested on x86_64-linux-gnu/F23. Ok for trunk, gcc-6
and gcc-5?

Regards,
Andre
-- 
Andre Vehreschild * Email: vehre ad gmx dot de 
diff --git a/gcc/fortran/trans-stmt.c b/gcc/fortran/trans-stmt.c
index 1af8732..4891201 100644
--- a/gcc/fortran/trans-stmt.c
+++ b/gcc/fortran/trans-stmt.c
@@ -5303,7 +5303,8 @@ gfc_trans_allocate (gfc_code * code)
   stmtblock_t block;
   stmtblock_t post;
   tree nelems;
-  bool upoly_expr, tmp_expr3_len_flag = false, al_len_needs_set;
+  bool upoly_expr, tmp_expr3_len_flag = false, al_len_needs_set,
+  do_assign = true;
   gfc_symtree *newsym = NULL;
 
   if (!code->ext.alloc.list)
@@ -5393,6 +5394,14 @@ gfc_trans_allocate (gfc_code * code)
 		  expr3_len = se.string_length;
 		  gfc_add_block_to_block (&block, &se.pre);
 		  gfc_add_block_to_block (&post, &se.post);
+		  /* Special case when string in expr3 is zero.  */
+		  if (code->expr3->ts.type == BT_CHARACTER
+		  && integer_zerop (se.string_length))
+		{
+		  expr3 = expr3_tmp = NULL_TREE;
+		  expr3_len = integer_zero_node;
+		  do_assign = false;
+		}
 		}
 	  /* else expr3 = NULL_TREE set above.  */
 	}
@@ -5415,7 +5424,16 @@ gfc_trans_allocate (gfc_code * code)
 	  gfc_add_block_to_block (&block, &se.pre);
 	  gfc_add_block_to_block (&post, &se.post);
 
-	  if (!VAR_P (se.expr))
+	  /* Special case when string in expr3 is zero.  */
+	  if (code->expr3->ts.type == BT_CHARACTER
+		  && integer_zerop (se.string_length))
+		{
+		  gfc_init_se (&se, NULL);
+		  expr3_len = integer_zero_node;
+		  tmp = NULL_TREE;
+		  do_assign = false;
+		}
+	  else if (!VAR_P (se.expr))
 		{
 		  tree var;
 
@@ -5956,7 +5974,7 @@ gfc_trans_allocate (gfc_code * code)
 			fold_convert (TREE_TYPE (al_len),
 	  integer_zero_node));
 	}
-  if (code->expr3 && !code->expr3->mold)
+  if (code->expr3 && !code->expr3->mold && do_assign)
 	{
 	  /* Initialization via SOURCE block
 	 (or static default initializer).  */
diff --git a/gcc/testsuite/gfortran.dg/allocate_with_source_20.f03 b/gcc/testsuite/gfortran.dg/allocate_with_source_20.f03
new file mode 100644
index 000..c145267
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/allocate_with_source_20.f03
@@ -0,0 +1,20 @@
+! { dg-do compile }
+
+! Check that PR72698 is fixed.
+! Contributed by Gerhard Steinmetz
+
+module m
+contains
+   integer function f()
+  f = 4
+   end
+end
+program p
+   use m
+   character(3), parameter :: c = 'abc'
+   character(:), allocatable :: z
+   allocate (z, source=repeat(c(2:1), f()))
+   print *, len(z), '  >>' // z // '<<'
+end
+
+
gcc/testsuite/ChangeLog:

2016-08-06  Andre Vehreschild  

PR fortran/72698
* gfortran.dg/allocate_with_source_20.f03: New test.


gcc/fortran/ChangeLog:

2016-08-06  Andre Vehreschild  

PR fortran/72698
* trans-stmt.c (gfc_trans_allocate): Prevent generating code for
copy of zero sized string and with it an ICE.

diff --git a/gcc/fortran/trans-stmt.c b/gcc/fortran/trans-stmt.c
index 6e4e2a7..5884e7a 100644
--- a/gcc/fortran/trans-stmt.c
+++ b/gcc/fortran/trans-stmt.c
@@ -5448,9 +5448,19 @@ gfc_trans_allocate (gfc_code * code)
 	}
   gfc_add_block_to_block (&block, &se.pre);
   gfc_add_block_to_block (&post, &se.post);
+
+  /* Special case when string in expr3 is zero.  */
+  if (code->expr3->ts.type == BT_CHARACTER
+	  && integer_zerop (se.string_length))
+	{
+	  gfc_init_se (&se, NULL);
+	  temp_var_needed = false;
+	  expr3_len = integer_zero_node;
+	  e3_is = E3_MOLD;
+	}
   /* Prevent aliasing, i.e., se.expr may be already a
 	 variable declaration.  */
-  if (se.expr != NULL_TREE && temp_var_needed)
+  else if (se.expr != NULL_TREE && temp_var_needed)
 	{
 	  tree var, desc;
 	  tmp = GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (se.expr)) || is_coarray ?
@@ -5679,11 +5689,8 @@ gfc_trans_allocate (gfc_code * code)
   gcc_assert (expr3_esize);
   expr3_esize = fold_convert (sizetype, expr3_esize);
   if (e3_is == E3_MOLD)
-	{
-	  /* The expr3 is no longer valid after this point.  */
-	  expr3 = NULL_TREE;
-	  e3_is = E3_UNSET;
-	}
+	/* The expr3 is no longer valid after this point.  */
+	expr3 = NULL_TREE;
 }
   else if (code->ext.alloc.ts.type != BT_UNKNOWN)
 {
@@ -6012,7 +6019,7 @@ gfc_trans_allocate (gfc_code * code)
 			fold_convert (TREE_TYPE (al_len),
 	  integer_zero_node));
 	}
-  if (code->expr3 && !code->expr3->mold)
+  if (code->expr3 && !code->expr3->mold && e3_is != E3_MOLD)
 	{

Re: libgo patch committed: Change build procedure to use build tags

2016-08-07 Thread Andreas Schwab
That breaks ia64:

../../../libgo/go/internal/syscall/unix/getrandom_linux.go:29:5: error: 
reference to undefined name 'randomTrap'
  if randomTrap == 0 {
 ^
../../../libgo/go/internal/syscall/unix/getrandom_linux.go:38:34: error: 
reference to undefined name 'randomTrap'
  r1, _, errno := syscall.Syscall(randomTrap,
  ^
make[4]: *** [internal/syscall/unix.lo] Error 1

Andreas.

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."


[Fortran, patch, pr71936, v1] [6/7 Regression] ICE in wide_int_to_tree, at tree.c:1487

2016-08-07 Thread Andre Vehreschild
Hi all,

attached patch fixes the ICE by ensuring that when the SOURCE=/MOLD=
expression is an array-valued function call with no ref, the ref of
object to allocate is taken. The array properties nevertheless are
taken from the function's result.

Bootstraps and regtests ok on x86_64-linux-gnu/F23. Ok for trunk and
gcc-6?

Regards,
Andre
-- 
Andre Vehreschild * Email: vehre ad gmx dot de 
gcc/fortran/ChangeLog:

2016-08-07  Andre Vehreschild  

PR fortran/71936
* trans-array.c (gfc_array_allocate): When SOURCE= is a function
stick with the ref of the object to allocate.

gcc/testsuite/ChangeLog:

2016-08-07  Andre Vehreschild  

PR fortran/71936
* gfortran.dg/allocate_with_source_21.f03: New test.


diff --git a/gcc/fortran/trans-array.c b/gcc/fortran/trans-array.c
index 7572755..6d5a0ef 100644
--- a/gcc/fortran/trans-array.c
+++ b/gcc/fortran/trans-array.c
@@ -5431,12 +5431,19 @@ gfc_array_allocate (gfc_se * se, gfc_expr * expr, tree status, tree errmsg,
 
   if (ref->u.ar.type == AR_FULL && expr3 != NULL)
 {
+  gfc_ref *old_ref = ref;
   /* F08:C633: Array shape from expr3.  */
   ref = expr3->ref;
 
   /* Find the last reference in the chain.  */
   if (!retrieve_last_ref (&ref, &prev_ref))
-	return false;
+	{
+	  if (expr3->expr_type == EXPR_FUNCTION
+	  && gfc_expr_attr (expr3).dimension)
+	ref = old_ref;
+	  else
+	return false;
+	}
   alloc_w_e3_arr_spec = true;
 }
 
diff --git a/gcc/testsuite/gfortran.dg/allocate_with_source_21.f03 b/gcc/testsuite/gfortran.dg/allocate_with_source_21.f03
new file mode 100644
index 000..fbf3159
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/allocate_with_source_21.f03
@@ -0,0 +1,52 @@
+! { dg-do compile }
+
+! Check fix for pr71936.
+! Contributed by Gerhard Steinmetz
+
+program p
+  type t
+  end type
+
+  call test2()
+  call test4()
+  call test1()
+  call test3()
+contains
+  function f_p()
+class(t), pointer :: f_p(:)
+nullify(f_p)
+  end
+
+  function f_a()
+class(t), allocatable :: f_a(:)
+  end
+
+  subroutine test1()
+class(t), allocatable :: x(:)
+allocate (x, mold=f_a())
+deallocate (x)
+allocate (x, source=f_a())
+  end subroutine
+
+  subroutine test2()
+class(t), pointer :: x(:)
+allocate (x, mold=f_p())
+deallocate (x)
+allocate (x, source=f_p())
+  end
+
+  subroutine test3()
+class(t), pointer :: x(:)
+allocate (x, mold=f_a())
+deallocate (x)
+allocate (x, source=f_a())
+  end
+
+  subroutine test4()
+class(t), allocatable :: x(:)
+allocate (x, mold=f_p())
+deallocate (x)
+allocate (x, source=f_p())
+  end subroutine
+end
+


Re: [Fortran, Patch, PR72698, v1] [5/6/7 Regression] ICE in lhd_incomplete_type_error, at langhooks.c:205

2016-08-07 Thread Andre Vehreschild
To prevent further confusion: The patch-file

pr72698_1.patch is for trunk and the gcc-6-branch, the

pr72698_v5_1.patch is for gcc-5-branch. 

Sorry for not pointing that out immediately.

- Andre

On Sun, 7 Aug 2016 13:52:34 +0200
Andre Vehreschild  wrote:

> Hi all,
> 
> attached patch fixes the ICE caused by a zero-sized string. Assigning
> that string to a temporary variable obviously did not work out. The
> patch fixes this by checking for zero-sized strings in SOURCE= and not
> producing the code to assign "nothing" to the temporary
> variable and later to the allocated memory. The version for gcc-5 had
> to be adapted slightly, because the version of the ALLOCATE()
> implementation is way behind.
> 
> Bootstrapped and regtested on x86_64-linux-gnu/F23. Ok for trunk,
> gcc-6 and gcc-5?
> 
> Regards,
>   Andre


-- 
Andre Vehreschild * Email: vehre ad gmx dot de 


Re: libgo patch committed: Change build procedure to use build tags

2016-08-07 Thread Matthias Klose
On 07.08.2016 14:14, Andreas Schwab wrote:
> That breaks ia64:
> 
> ../../../libgo/go/internal/syscall/unix/getrandom_linux.go:29:5: error: 
> reference to undefined name 'randomTrap'
>   if randomTrap == 0 {
>  ^
> ../../../libgo/go/internal/syscall/unix/getrandom_linux.go:38:34: error: 
> reference to undefined name 'randomTrap'
>   r1, _, errno := syscall.Syscall(randomTrap,
>   ^
> make[4]: *** [internal/syscall/unix.lo] Error 1

same on s390x.



Re: backward threading heuristics tweek

2016-08-07 Thread Andrew Pinski
On Mon, Jun 6, 2016 at 3:19 AM, Jan Hubicka  wrote:
> Hi,
> while looking into profile mismatches introduced by the backward threading 
> pass
> I noticed that the heuristics seems quite simplistics.  First it should be
> profile sensitive and disallow duplication when optimizing cold paths. Second
> it should use estimate_num_insns because gimple statement count is not really
> very realistic estimate of final code size effect and third there seems to be
> no reason to disable the pass for functions optimized for size.
>
> If we block duplication for more than 1 insns for size optimized paths the 
> pass
> is able to do majority of threading decisions that are for free and improve 
> codegen.
> The code size benefit was between 0.5% to 2.7% on testcases I tried (tramp3d,
> GCC modules, xlanancbmk and some other stuff around my hd).
>
> Bootstrapped/regtested x86_64-linux, seems sane?
>
> The pass should also avoid calling cleanup_cfg when no trheading was done
> and i do not see why it is guarded by expensive_optimizations. What are the
> main compile time complexity limitations?

This patch caused a huge regression (~11%) on coremarks on ThunderX.
I assume other targets too.
Basically it looks like the path is no longer thread jumped.

Thanks,
Andrew


>
> Honza
>
> * tree-ssa-threadbackward.c: Include tree-inline.h
> (profitable_jump_thread_path): Use estimate_num_insns to estimate
> size of copied block; for cold paths reduce duplication.
> (find_jump_threads_backwards): Remove redundant tests.
> (pass_thread_jumps::gate): Enable for -Os.
> * gcc.dg/tree-ssa/ssa-dom-thread-7.c: Update testcase.
> Index: tree-ssa-threadbackward.c
> ===
> --- tree-ssa-threadbackward.c   (revision 237101)
> +++ tree-ssa-threadbackward.c   (working copy)
> @@ -35,6 +35,7 @@ along with GCC; see the file COPYING3.
>  #include "tree-pass.h"
>  #include "gimple-ssa.h"
>  #include "tree-phinodes.h"
> +#include "tree-inline.h"
>
>  static int max_threaded_paths;
>
> @@ -210,7 +211,7 @@ profitable_jump_thread_path (vec   && !(gimple_code (stmt) == GIMPLE_ASSIGN
>&& gimple_assign_rhs_code (stmt) == ASSERT_EXPR)
>   && !is_gimple_debug (stmt))
> -   ++n_insns;
> +   n_insns += estimate_num_insns (stmt, &eni_size_weights);
> }
>
>   /* We do not look at the block with the threaded branch
> @@ -238,13 +239,15 @@ profitable_jump_thread_path (vec threaded_through_latch = true;
>  }
>
> +  gimple *stmt = get_gimple_control_stmt ((*path)[0]);
> +  gcc_assert (stmt);
> +
>/* We are going to remove the control statement at the end of the
>   last block in the threading path.  So don't count it against our
>   statement count.  */
> -  n_insns--;
>
> -  gimple *stmt = get_gimple_control_stmt ((*path)[0]);
> -  gcc_assert (stmt);
> +  n_insns-= estimate_num_insns (stmt, &eni_size_weights);
> +
>/* We have found a constant value for ARG.  For GIMPLE_SWITCH
>   and GIMPLE_GOTO, we use it as-is.  However, for a GIMPLE_COND
>   we need to substitute, fold and simplify so we can determine
> @@ -290,12 +293,24 @@ profitable_jump_thread_path (vecreturn NULL;
>  }
>
> -  if (n_insns >= PARAM_VALUE (PARAM_MAX_FSM_THREAD_PATH_INSNS))
> +  if (optimize_edge_for_speed_p (taken_edge))
> +{
> +  if (n_insns >= PARAM_VALUE (PARAM_MAX_FSM_THREAD_PATH_INSNS))
> +   {
> + if (dump_file && (dump_flags & TDF_DETAILS))
> +   fprintf (dump_file, "FSM jump-thread path not considered: "
> +"the number of instructions on the path "
> +"exceeds PARAM_MAX_FSM_THREAD_PATH_INSNS.\n");
> + path->pop ();
> + return NULL;
> +   }
> +}
> +  else if (n_insns > 1)
>  {
>if (dump_file && (dump_flags & TDF_DETAILS))
> fprintf (dump_file, "FSM jump-thread path not considered: "
> -"the number of instructions on the path "
> -"exceeds PARAM_MAX_FSM_THREAD_PATH_INSNS.\n");
> +"duplication of %i insns is needed and optimizing for 
> size.\n",
> +n_insns);
>path->pop ();
>return NULL;
>  }
> @@ -600,10 +615,6 @@ fsm_find_control_statement_thread_paths
>  void
>  find_jump_threads_backwards (basic_block bb)
>  {
> -  if (!flag_expensive_optimizations
> -  || optimize_function_for_size_p (cfun))
> -return;
> -
>gimple *stmt = get_gimple_control_stmt (bb);
>if (!stmt)
>  return;
> @@ -668,8 +679,7 @@ public:
>  bool
>  pass_thread_jumps::gate (function *fun ATTRIBUTE_UNUSED)
>  {
> -  return (flag_expensive_optimizations
> - && ! optimize_function_for_size_p (cfun));
> +  return flag_expensive_optimizations;
>  }
>
>
> Index: testsuite/gcc.dg/tree-ssa/ssa-dom-thread-7.c
> ===

Re: [PATCH] gcov tool: Implement Hawick's algorithm for cycle detection, (PR gcov-profile/67992)

2016-08-07 Thread Martin Liška

On 08/06/2016 12:31 PM, Jakub Jelinek wrote:

On Fri, Aug 05, 2016 at 08:27:39AM -0700, Andrew Pinski wrote:

On Fri, Aug 5, 2016 at 12:32 AM, Martin Liška  wrote:

On 08/05/2016 09:30 AM, Martin Liška wrote:

Hi.

Sorry for the mistake with the enum, that was silly ;)
New patch version also handles the unnecessary braces.

Martin


I attached a wrong patch, sending the new one.



This broke cross aarch64-elf-gnu building.

/home/jenkins/workspace/BuildToolchainAARCH64_thunder_elf_upstream/toolchain/scripts/../src/gcc/gcov.c:
In function ‘loop_type handle_cycle(const arc_vector_t&, int64_t&)’:
/home/jenkins/workspace/BuildToolchainAARCH64_thunder_elf_upstream/toolchain/scripts/../src/gcc/gcov.c:468:25:
error: ‘INT64_MAX’ was not declared in this scope


See 
http://stackoverflow.com/questions/3233054/error-int32-max-was-not-declared-in-this-scope
.


Fixed thusly, committed as obvious to trunk:

2016-08-06  Jakub Jelinek  

* gcov.c (handle_cycle): Use INTTYPE_MAXIMUM (int64_t) instead of
INT64_MAX.

--- gcc/gcov.c.jj   2016-08-06 12:11:51.0 +0200
+++ gcc/gcov.c  2016-08-06 12:28:32.373898684 +0200
@@ -465,7 +465,7 @@ handle_cycle (const arc_vector_t &edges,
 {
   /* Find the minimum edge of the cycle, and reduce all nodes in the cycle by
  that amount.  */
-  int64_t cycle_count = INT64_MAX;
+  int64_t cycle_count = INTTYPE_MAXIMUM (int64_t);
   for (unsigned i = 0; i < edges.size (); i++)
 {
   int64_t ecount = edges[i]->cs_count;


Jakub



Thank you Jakub for the fixed and sorry to all affected by the breakage.

Martin


Re: [RFC] ipa bitwise constant propagation

2016-08-07 Thread Prathamesh Kulkarni
On 5 August 2016 at 18:06, Martin Jambor  wrote:
> Hi,
Hi Martin,
Thanks for the review. Please find my responses inline.
>
> generally speaking, the ipa-cp.c and ipa-cp.[hc] bits look reasonable,
> but I have a few comments:
>
> On Thu, Aug 04, 2016 at 12:06:18PM +0530, Prathamesh Kulkarni wrote:
>> Hi,
>> This is a prototype patch for propagating known/unknown bits 
>> inter-procedurally.
>> for integral types which propagates info obtained from get_nonzero_bits ().
>>
>> Patch required making following changes:
>> a) To make info from get_nonzero_bits() available to ipa
>
> in IPA phase, you should not be looking at SSA_NAMEs, those will not
> be available with LTO when you do not have access to function bodies
> and thus also not to SSA_NAMES.  In IPA, you should only rely on hat
> you have in jump functions.
>
>> , I had to remove
>> guard !nonzero_p in ccp_finalize. However that triggered the following ICE
>> in get_ptr_info() for default_none.f95 (and several other fortran tests)
>> with options: -fopenacc -O2
>> ICE: http://pastebin.com/KjD7HMQi
>> I confirmed with Richard that this was a latent issue.
>>
>>
>> I suppose we would want to gate this on some flag, say -fipa-bit-cp ?
>
> Yes, definitely.
Added -fipa-cp-bit (mirroring -fipa-cp-alignment)
>
>> I haven't yet gated it on the flag, will do in next version of patch.
>> I have added some very simple test-cases, I will try to add more
>> meaningful ones.
>
>
>>
>> Patch passes bootstrap+test on x86_64-unknown-linux-gnu
>> and cross-tested on arm*-*-* and aarch64*-*-* with the exception
>> of some fortran tests failing due to above ICE.
>>
>> As next steps, I am planning to extend it to handle alignment propagation,
>> and do further testing (lto-bootstrap, chromium).
>> I would be grateful for feedback on the current patch.
>>
>> Thanks,
>> Prathamesh
>
>> diff --git a/gcc/ipa-cp.c b/gcc/ipa-cp.c
>> index 5b6cb9a..b770f6a 100644
>> --- a/gcc/ipa-cp.c
>> +++ b/gcc/ipa-cp.c
>> @@ -120,6 +120,7 @@ along with GCC; see the file COPYING3.  If not see
>>  #include "params.h"
>>  #include "ipa-inline.h"
>>  #include "ipa-utils.h"
>> +#include "tree-ssa-ccp.h"
>>
>>  template  class ipcp_value;
>>
>> @@ -266,6 +267,40 @@ private:
>>bool meet_with_1 (unsigned new_align, unsigned new_misalign);
>>  };
>>
>> +/* Lattice of known bits, only capable of holding one value.
>> +   Similar to ccp_prop_value_t, mask represents which bits of value are 
>> constant.
>> +   If a bit in mask is set to 0, then the corresponding bit in
>> +   value is known to be constant.  */
>> +
>> +class ipcp_bits_lattice
>> +{
>> +public:
>> +  bool bottom_p () { return lattice_val == IPA_BITS_VARYING; }
>> +  bool top_p () { return lattice_val == IPA_BITS_UNDEFINED; }
>> +  bool constant_p () { return lattice_val == IPA_BITS_CONSTANT; }
>> +  bool set_to_bottom ();
>> +  bool set_to_constant (widest_int, widest_int, signop, unsigned);
>> +
>> +  widest_int get_value () { return value; }
>> +  widest_int get_mask () { return mask; }
>> +  signop get_sign () { return sgn; }
>> +  unsigned get_precision () { return precision; }
>> +
>> +  bool meet_with (ipcp_bits_lattice& other, enum tree_code, tree);
>> +  bool meet_with (widest_int, widest_int, signop, unsigned);
>> +
>> +  void print (FILE *);
>> +
>> +private:
>> +  enum { IPA_BITS_UNDEFINED, IPA_BITS_CONSTANT, IPA_BITS_VARYING } 
>> lattice_val;
>> +  widest_int value, mask;
>> +  signop sgn;
>> +  unsigned precision;
>> +
>> +  bool meet_with_1 (widest_int, widest_int);
>> +  void get_value_and_mask (tree, widest_int *, widest_int *);
>> +};
>> +
>>  /* Structure containing lattices for a parameter itself and for pieces of
>> aggregates that are passed in the parameter or by a reference in a 
>> parameter
>> plus some other useful flags.  */
>> @@ -281,6 +316,8 @@ public:
>>ipcp_agg_lattice *aggs;
>>/* Lattice describing known alignment.  */
>>ipcp_alignment_lattice alignment;
>> +  /* Lattice describing known bits.  */
>> +  ipcp_bits_lattice bits_lattice;
>>/* Number of aggregate lattices */
>>int aggs_count;
>>/* True if aggregate data were passed by reference (as opposed to by
>> @@ -458,6 +495,21 @@ ipcp_alignment_lattice::print (FILE * f)
>>  fprintf (f, " Alignment %u, misalignment %u\n", align, 
>> misalign);
>>  }
>>
>> +void
>> +ipcp_bits_lattice::print (FILE *f)
>> +{
>> +  if (top_p ())
>> +fprintf (f, " Bits unknown (TOP)\n");
>> +  else if (bottom_p ())
>> +fprintf (f, " Bits unusable (BOTTOM)\n");
>> +  else
>> +{
>> +  fprintf (f, " Bits: value = "); print_hex (get_value (), f);
>> +  fprintf (f, ", mask = "); print_hex (get_mask (), f);
>> +  fprintf (f, "\n");
>> +}
>> +}
>> +
>>  /* Print all ipcp_lattices of all functions to F.  */
>>
>>  static void
>> @@ -484,6 +536,7 @@ print_all_lattices (FILE * f, bool dump_sources, bool 
>> dump_benefits)
>> fprintf (f, " ctxs: ");
>> plats->ct

[RFC] [ipa bitwise cp] tree-ssa-ccp changes

2016-08-07 Thread Prathamesh Kulkarni
Hi Richard,
In the attached version, I tried to address your suggestions from:
https://gcc.gnu.org/ml/gcc-patches/2016-08/msg00279.html

In ccp_finalize we do:
wide_int nonzero_bits = wide_int::from (val->mask, precision,
  UNSIGNED) | val->value;

Similar to the change to extend_mask to extend based on signop,
should this be changed to:
wide_int::from (val->mask, precision, TYPE_SIGN (TREE_TYPE (val->value))) ?
(although I guess we are narrowing the type here rather than extending).

Thanks,
Prathamesh
diff --git a/gcc/tree-ssa-ccp.c b/gcc/tree-ssa-ccp.c
index 06e2905..7cd4012 100644
--- a/gcc/tree-ssa-ccp.c
+++ b/gcc/tree-ssa-ccp.c
@@ -142,7 +142,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "cfgloop.h"
 #include "stor-layout.h"
 #include "optabs-query.h"
-
+#include "tree-ssa-ccp.h"
 
 /* Possible lattice values.  */
 typedef enum
@@ -536,9 +536,9 @@ set_lattice_value (tree var, ccp_prop_value_t *new_val)
 
 static ccp_prop_value_t get_value_for_expr (tree, bool);
 static ccp_prop_value_t bit_value_binop (enum tree_code, tree, tree, tree);
-static void bit_value_binop_1 (enum tree_code, tree, widest_int *, widest_int 
*,
-  tree, const widest_int &, const widest_int &,
-  tree, const widest_int &, const widest_int &);
+void bit_value_binop (enum tree_code, signop, int, widest_int *, widest_int *,
+ signop, int, const widest_int &, const widest_int &,
+ signop, int, const widest_int &, const widest_int &);
 
 /* Return a widest_int that can be used for bitwise simplifications
from VAL.  */
@@ -894,7 +894,7 @@ do_dbg_cnt (void)
Return TRUE when something was optimized.  */
 
 static bool
-ccp_finalize (bool nonzero_p)
+ccp_finalize (bool nonzero_p) 
 {
   bool something_changed;
   unsigned i;
@@ -920,7 +920,8 @@ ccp_finalize (bool nonzero_p)
 
   val = get_value (name);
   if (val->lattice_val != CONSTANT
- || TREE_CODE (val->value) != INTEGER_CST)
+ || TREE_CODE (val->value) != INTEGER_CST
+ || val->mask == 0)
continue;
 
   if (POINTER_TYPE_P (TREE_TYPE (name)))
@@ -1224,10 +1225,11 @@ ccp_fold (gimple *stmt)
RVAL and RMASK representing a value of type RTYPE and set
the value, mask pair *VAL and *MASK to the result.  */
 
-static void
-bit_value_unop_1 (enum tree_code code, tree type,
- widest_int *val, widest_int *mask,
- tree rtype, const widest_int &rval, const widest_int &rmask)
+void
+bit_value_unop (enum tree_code code, signop type_sgn, int type_precision, 
+   widest_int *val, widest_int *mask,
+   signop rtype_sgn, int rtype_precision,
+   const widest_int &rval, const widest_int &rmask)
 {
   switch (code)
 {
@@ -1240,25 +1242,23 @@ bit_value_unop_1 (enum tree_code code, tree type,
   {
widest_int temv, temm;
/* Return ~rval + 1.  */
-   bit_value_unop_1 (BIT_NOT_EXPR, type, &temv, &temm, type, rval, rmask);
-   bit_value_binop_1 (PLUS_EXPR, type, val, mask,
-  type, temv, temm, type, 1, 0);
+   bit_value_unop (BIT_NOT_EXPR, type_sgn, type_precision, &temv, &temm,
+   type_sgn, type_precision, rval, rmask);
+   bit_value_binop (PLUS_EXPR, type_sgn, type_precision, val, mask,
+type_sgn, type_precision, temv, temm,
+type_sgn, type_precision, 1, 0);
break;
   }
 
 CASE_CONVERT:
   {
-   signop sgn;
-
/* First extend mask and value according to the original type.  */
-   sgn = TYPE_SIGN (rtype);
-   *mask = wi::ext (rmask, TYPE_PRECISION (rtype), sgn);
-   *val = wi::ext (rval, TYPE_PRECISION (rtype), sgn);
+   *mask = wi::ext (rmask, rtype_precision, rtype_sgn);
+   *val = wi::ext (rval, rtype_precision, rtype_sgn);
 
/* Then extend mask and value according to the target type.  */
-   sgn = TYPE_SIGN (type);
-   *mask = wi::ext (*mask, TYPE_PRECISION (type), sgn);
-   *val = wi::ext (*val, TYPE_PRECISION (type), sgn);
+   *mask = wi::ext (*mask, type_precision, type_sgn);
+   *val = wi::ext (*val, type_precision, type_sgn);
break;
   }
 
@@ -1272,15 +1272,14 @@ bit_value_unop_1 (enum tree_code code, tree type,
R1VAL, R1MASK and R2VAL, R2MASK representing a values of type R1TYPE
and R2TYPE and set the value, mask pair *VAL and *MASK to the result.  */
 
-static void
-bit_value_binop_1 (enum tree_code code, tree type,
-  widest_int *val, widest_int *mask,
-  tree r1type, const widest_int &r1val,
-  const widest_int &r1mask, tree r2type,
-  const widest_int &r2val, const widest_int &r2mask)
+void
+bit_value_binop (enum tree_code code, signop sgn, int width, 
+widest_int *val, widest_int *mask,
+

Re: libgo patch committed: Change build procedure to use build tags

2016-08-07 Thread Ian Lance Taylor
On Sun, Aug 7, 2016 at 8:18 AM, Matthias Klose  wrote:
> On 07.08.2016 14:14, Andreas Schwab wrote:
>> That breaks ia64:
>>
>> ../../../libgo/go/internal/syscall/unix/getrandom_linux.go:29:5: error: 
>> reference to undefined name 'randomTrap'
>>   if randomTrap == 0 {
>>  ^
>> ../../../libgo/go/internal/syscall/unix/getrandom_linux.go:38:34: error: 
>> reference to undefined name 'randomTrap'
>>   r1, _, errno := syscall.Syscall(randomTrap,
>>   ^
>> make[4]: *** [internal/syscall/unix.lo] Error 1
>
> same on s390x.

Thanks for the reports.  This patch should fix these problems, and
also fix the build for Alpha GNU/Linux.  Bootstrapped on
x86_64-pc-linux-gnu and verified that the ia64, s390, and alpha should
pick the right files.  Committed to mainline.

Ian
Index: gcc/go/gofrontend/MERGE
===
--- gcc/go/gofrontend/MERGE (revision 239210)
+++ gcc/go/gofrontend/MERGE (working copy)
@@ -1,4 +1,4 @@
-b50a0c3fa975186f934b76e25dae42eb65148d67
+ff3e3dd6c09aaefdf13cce99a5beff47a095
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
Index: libgo/configure.ac
===
--- libgo/configure.ac  (revision 238743)
+++ libgo/configure.ac  (working copy)
@@ -191,6 +191,7 @@ is_386=no
 is_alpha=no
 is_arm=no
 is_arm64=no
+is_ia64=no
 is_m68k=no
 mips_abi=unknown
 is_ppc=no
@@ -229,6 +230,10 @@ changequote([,])dnl
   GOARCH=amd64
 fi
 ;;
+  ia64-*-*)
+is_ia64=yes
+GOARCH=ia64
+;;
   m68k*-*-*)
 is_m68k=yes
 GOARCH=m68k
@@ -311,6 +316,7 @@ AM_CONDITIONAL(LIBGO_IS_386, test $is_38
 AM_CONDITIONAL(LIBGO_IS_ALPHA, test $is_alpha = yes)
 AM_CONDITIONAL(LIBGO_IS_ARM, test $is_arm = yes)
 AM_CONDITIONAL(LIBGO_IS_ARM64, test $is_arm64 = yes)
+AM_CONDITIONAL(LIBGO_IS_IA64, test $is_ia64 = yes)
 AM_CONDITIONAL(LIBGO_IS_M68K, test $is_m68k = yes)
 AM_CONDITIONAL(LIBGO_IS_MIPS, test $mips_abi != unknown)
 AM_CONDITIONAL(LIBGO_IS_MIPSO32, test $mips_abi = o32)
Index: libgo/go/internal/syscall/unix/getrandom_linux_alpha.go
===
--- libgo/go/internal/syscall/unix/getrandom_linux_alpha.go (revision 0)
+++ libgo/go/internal/syscall/unix/getrandom_linux_alpha.go (working copy)
@@ -0,0 +1,9 @@
+// Copyright 2016 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package unix
+
+// Linux getrandom system call number.
+// See GetRandom in getrandom_linux.go.
+const randomTrap uintptr = 511
Index: libgo/go/internal/syscall/unix/getrandom_linux_ia64.go
===
--- libgo/go/internal/syscall/unix/getrandom_linux_ia64.go  (revision 0)
+++ libgo/go/internal/syscall/unix/getrandom_linux_ia64.go  (working copy)
@@ -0,0 +1,9 @@
+// Copyright 2016 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package unix
+
+// Linux getrandom system call number.
+// See GetRandom in getrandom_linux.go.
+const randomTrap uintptr = 1339
Index: libgo/go/internal/syscall/unix/getrandom_linux_s390.go
===
--- libgo/go/internal/syscall/unix/getrandom_linux_s390.go  (revision 0)
+++ libgo/go/internal/syscall/unix/getrandom_linux_s390.go  (working copy)
@@ -0,0 +1,9 @@
+// Copyright 2016 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package unix
+
+// Linux getrandom system call number.
+// See GetRandom in getrandom_linux.go.
+const randomTrap uintptr = 349
Index: libgo/match.sh
===
--- libgo/match.sh  (revision 239189)
+++ libgo/match.sh  (working copy)
@@ -116,7 +116,7 @@ for f in $gofiles; do
android | darwin | dragonfly | freebsd | linux | nacl | netbsd | 
openbsd | plan9 | solaris | windows)
tag1=nonmatchingtag
;;
-   386 | amd64 | amd64p32 | arm | armbe | arm64 | arm64be | alpha | m68k | 
ppc64 | ppc64le | mips | mipsle | mips64 | mips64le | mips64p32 | mips64p32le | 
mipso32 | mipsn32 | mipsn64 | mipso64 | ppc | s390 | s390x | sparc | sparc64)
+   386 | amd64 | amd64p32 | arm | armbe | arm64 | arm64be | alpha | ia64 | 
m68k | ppc64 | ppc64le | mips | mipsle | mips64 | mips64le | mips64p32 | 
mips64p32le | mipso32 | mipsn32 | mipsn64 | mipso64 | ppc | s390 | s390x | 
sparc | sparc64)
tag1=nonmatchingtag
;;
 esac
@@ -128,7 +128,7 @@ for f in $gofiles; do
android | darwin | dragonfly | freebsd | linux | nacl | netbsd | 
openbsd | plan9 | solaris | windows)

[RFC] Use ccp mask and val to refine value_range

2016-08-07 Thread kugan

Hi All,

I was experimenting with using ccp mask and value to refine value_ranges 
for SSA_NAME. Attached patch does this. This might be particularly 
useful for early_vrp. Bootstrap on x86_64-linux-gnu is OK. However, 
there are some test-cases (as shown below) are failing.



Is this worth investigating? Any thoughts?

# Comparing directories
## Dir1=build-base/: 11 sum files
## Dir2=build: 11 sum files

# Comparing 11 common sum files
## /bin/sh ./gcc/contrib/compare_tests  /tmp/gxx-sum1.26167 
/tmp/gxx-sum2.26167

Tests that now fail, but worked before:

gcc.c-torture/execute/pr57124.c   -O2  execution test
gcc.c-torture/execute/pr57124.c   -O2 -flto -fno-use-linker-plugin 
-flto-partition=none  execution test

gcc.c-torture/execute/pr57124.c   -O3 -g  execution test
gcc.c-torture/execute/pr57124.c   -Os  execution test
gcc.dg/Wstrict-overflow-12.c correct warning (test for warnings, line 13)
gcc.dg/Wstrict-overflow-13.c correct warning (test for warnings, line 14)
gcc.dg/Wstrict-overflow-21.c correct warning (test for warnings, line 8)
gcc.dg/no-strict-overflow-6.c scan-tree-dump optimized "return 0"
gcc.dg/tree-ssa/pr61743-1.c scan-tree-dump-times cunroll "loop with 4 
iterations completely unrolled" 2
gcc.dg/tree-ssa/pr61743-1.c scan-tree-dump-times cunroll "loop with 8 
iterations completely unrolled" 2
gcc.dg/tree-ssa/ssa-dom-thread-7.c scan-tree-dump thread3 "Jumps 
threaded: 3"


## Differences found:
# 1 differences in 11 common sum files found


Thanks,
Kugan


gcc/ChangeLog:

2016-08-08  Kugan Vivekanandarajah  

* tree-ssanames.c (refine_range_info): New.
* tree-ssa-ccp.c (ccp_finalize): Call refine_range_info.
* tree-ssanames.c (refine_range_info): Declare.

diff --git a/gcc/tree-ssa-ccp.c b/gcc/tree-ssa-ccp.c
index ae120a8..e7326c7 100644
--- a/gcc/tree-ssa-ccp.c
+++ b/gcc/tree-ssa-ccp.c
@@ -940,8 +940,14 @@ ccp_finalize (bool nonzero_p)
  unsigned int precision = TYPE_PRECISION (TREE_TYPE (val->value));
  wide_int nonzero_bits = wide_int::from (val->mask, precision,
  UNSIGNED) | val->value;
+ wide_int mask = wide_int::from (val->mask, TYPE_PRECISION (TREE_TYPE 
(name)),
+ TYPE_SIGN (TREE_TYPE (name)));
+ wide_int ones = wi::bit_and (val->value, wi::bit_not (mask));
+ wide_int zeros = wi::bit_not (wi::bit_and (wi::bit_not (val->value),
+wi::bit_not (mask)));
  nonzero_bits &= get_nonzero_bits (name);
  set_nonzero_bits (name, nonzero_bits);
+ refine_range_info (name, zeros, ones);
}
 }
 
diff --git a/gcc/tree-ssanames.c b/gcc/tree-ssanames.c
index 91a8f97..a69d8e9 100644
--- a/gcc/tree-ssanames.c
+++ b/gcc/tree-ssanames.c
@@ -388,6 +388,36 @@ set_nonzero_bits (tree name, const wide_int_ref &mask)
   ri->set_nonzero_bits (mask);
 }
 
+/* Refine value range of NAME based on allways ZEROS and always ONES bits.  */
+void
+refine_range_info (tree name, const wide_int_ref &zeros,
+  const wide_int_ref &ones)
+{
+  tree type = TREE_TYPE (name);
+  gcc_assert (!POINTER_TYPE_P (TREE_TYPE (name)));
+  if (SSA_NAME_RANGE_INFO (name) == NULL)
+set_range_info (name, VR_RANGE,
+   TYPE_MIN_VALUE (type),
+   TYPE_MAX_VALUE (type));
+
+  if (SSA_NAME_RANGE_TYPE (name) != VR_RANGE)
+return;
+
+  wide_int min = wi::min_value (type);
+  wide_int max = wi::max_value (type);
+
+  max &= zeros;
+  max |= ones;
+  min &= zeros;
+  min |= ones;
+
+  range_info_def *ri = SSA_NAME_RANGE_INFO (name);
+  if (wi::cmp (ri->get_min(), min, TYPE_SIGN (TREE_TYPE (name))) == -1)
+ri->set_min (min);
+  if (wi::cmp (max, ri->get_max(), TYPE_SIGN (TREE_TYPE (name))) == -1)
+ri->set_max (max);
+}
+
 /* Return a widest_int with potentially non-zero bits in SSA_NAME
NAME, or -1 if unknown.  */
 
diff --git a/gcc/tree-ssanames.h b/gcc/tree-ssanames.h
index c81b1a1..c18047a 100644
--- a/gcc/tree-ssanames.h
+++ b/gcc/tree-ssanames.h
@@ -74,6 +74,8 @@ extern void set_range_info (tree, enum value_range_type, 
const wide_int_ref &,
 extern enum value_range_type get_range_info (const_tree, wide_int *,
 wide_int *);
 extern void set_nonzero_bits (tree, const wide_int_ref &);
+extern void refine_range_info (tree name, const wide_int_ref &zeros,
+  const wide_int_ref &ones);
 extern wide_int get_nonzero_bits (const_tree);
 extern bool ssa_name_has_boolean_range (tree);
 extern void init_ssanames (struct function *, int);


[PATCH, RELOAD] Don't assume subreg mem address is ok

2016-08-07 Thread Alan Modra
This patch fixes a case where reload blindly assumes a subreg mem
is OK if its address has been partially reloaded by
legitimize_reload_address.  The change ought to be fairly obvious
considering that the analogous non-subreg case only gives a win to
address_reloaded[i] == 1.  Bootstrapped and regression tested
powerpc64le-linux using
  RUNTESTFLAGS="--target_board=unix'{-mlra,-mno-lra}'"
to run the testsuite using both lra and reload.  OK for mainline
and active branches?

In the testcase we see this insn
(insn 316 272 349 38 (parallel [
(set (reg:SF 336 [ _46 ])
(unsigned_float:SF (subreg/s/v:HI (reg:DI 360 [ g ]) 0)))
(clobber (scratch:DI))
(clobber (scratch:DI))
(clobber (scratch:HI))
]) 358 {*floatunshisf2_internal}
not getting a hard reg for reg 360, which has an equivalent constant.
Reload substitutes the constant, but the pattern does not allow
constants so it is forced to mem.  The mem address is legitimized by
rs6000_legitimize_reload_address to a lo_sum/high constant pool ref.
But this particular address form is not valid for the pattern, which
wants either an indirect or indexed address.

PR rtl-optimization/72771
* reload.c (find_reloads): Don't assume that a subreg mem is OK
when find_reloads_toplev returns address_reloaded==-1.
(alternative_allows_const_pool_ref): Update comment.
testsuite/
* gcc.c-torture/compile/pr72771.c: New.

diff --git a/gcc/reload.c b/gcc/reload.c
index 1945133..bcd15a1 100644
--- a/gcc/reload.c
+++ b/gcc/reload.c
@@ -3960,7 +3960,7 @@ find_reloads (rtx_insn *insn, int replace, int 
ind_levels, int live_known,
   there will be no reload needed at all.  */
if (plus == NULL_RTX
&& subreg == NULL_RTX
-   && alternative_allows_const_pool_ref (this_address_reloaded == 0
+   && alternative_allows_const_pool_ref (this_address_reloaded != 1
  ? substed_operand[i]
  : NULL,
  recog_data.constraints[i],
@@ -4605,8 +4605,8 @@ find_reloads (rtx_insn *insn, int replace, int 
ind_levels, int live_known,
 
 /* Return true if alternative number ALTNUM in constraint-string
CONSTRAINT is guaranteed to accept a reloaded constant-pool reference.
-   MEM gives the reference if it didn't need any reloads, otherwise it
-   is null.  */
+   MEM gives the reference if its address hasn't been fully reloaded,
+   otherwise it is NULL.  */
 
 static bool
 alternative_allows_const_pool_ref (rtx mem ATTRIBUTE_UNUSED,
diff --git a/gcc/testsuite/gcc.c-torture/compile/pr72771.c 
b/gcc/testsuite/gcc.c-torture/compile/pr72771.c
new file mode 100644
index 000..1cc13e3
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/compile/pr72771.c
@@ -0,0 +1,29 @@
+void fn2(void);
+void fn3(unsigned long);
+
+signed char a;
+int b, c, e, f;
+float *d;
+
+void fn1(void) {
+unsigned short g = 0;
+lbl_986:
+for (;;) {
+c = 0;
+for (; c <= 2;) {
+*d = g;
+fn2();
+if (e)
+goto lbl_986;
+}
+g = 2;
+for (; (short) g >= 0; g--) {
+for (; b;) {
+fn3(45360);
+f = 0;
+for (; a >= 0; a--)
+;
+}
+}
+}
+}

-- 
Alan Modra
Australia Development Lab, IBM


Re: [PATCH, RELOAD] Don't assume subreg mem address is ok

2016-08-07 Thread Alan Modra
On Mon, Aug 08, 2016 at 12:13:18PM +0930, Alan Modra wrote:
> This patch fixes a case where reload blindly assumes a subreg mem
> is OK if its address has been partially reloaded by
> legitimize_reload_address.  The change ought to be fairly obvious
> considering that the analogous non-subreg case only gives a win to
> address_reloaded[i] == 1.  Bootstrapped and regression tested
> powerpc64le-linux using
>   RUNTESTFLAGS="--target_board=unix'{-mlra,-mno-lra}'"
> to run the testsuite using both lra and reload.  OK for mainline
> and active branches?

When I look at the correct bootstrap I see I have some regressions.
Sorry for the noise, patch withdrawn.

-- 
Alan Modra
Australia Development Lab, IBM


Set nonnull attribute to ptr_info_def based on VRP

2016-08-07 Thread kugan

Hi,

This patch tries to add nonnull_p attribute to ptr_info_def. As it 
stands, range_info_def is bigger in size than ptr_info_def. Therefore 
adding  nonnull_p should not change the size.


I am setting this based on the VRP analysis. Right there is no uses for 
this. But the idea is, this can be used in IPA-VRP such that redundant 
check for NULL can be eliminated.


Bootstrapped and regression tested on x86_64-linux-gnu. Is this OK for 
trunk.


Thanks,
Kugan


gcc/ChangeLog:

2016-08-08  Kugan Vivekanandarajah  

* tree-ssanames.c (set_ptr_nonnull): New.
(get_ptr_nonnull): Likewise.
* tree-ssanames.h (struct ptr_info_def): Add nonnull_p attribute.
* tree-vrp.c (vrp_finalize): Call set_ptr_nonnull.
diff --git a/gcc/tree-ssanames.c b/gcc/tree-ssanames.c
index 91a8f97..19c9027 100644
--- a/gcc/tree-ssanames.c
+++ b/gcc/tree-ssanames.c
@@ -374,6 +374,27 @@ get_range_info (const_tree name, wide_int *min, wide_int 
*max)
   return SSA_NAME_RANGE_TYPE (name);
 }
 
+/* Set nonnull attribute to pointer NAME.  */
+
+void
+set_ptr_nonnull (tree name, bool nonnull_p)
+{
+  gcc_assert (POINTER_TYPE_P (TREE_TYPE (name)));
+  struct ptr_info_def *pi = get_ptr_info (name);
+  pi->nonnull_p = nonnull_p;;
+}
+
+/* Return nonnull attribute of pointer NAME.  */
+bool
+get_ptr_nonnull (tree name)
+{
+  gcc_assert (POINTER_TYPE_P (TREE_TYPE (name)));
+  struct ptr_info_def *pi = SSA_NAME_PTR_INFO (name);
+  if (pi == NULL)
+return false;
+  return pi->nonnull_p;
+}
+
 /* Change non-zero bits bitmask of NAME.  */
 
 void
diff --git a/gcc/tree-ssanames.h b/gcc/tree-ssanames.h
index c81b1a1..6e34433 100644
--- a/gcc/tree-ssanames.h
+++ b/gcc/tree-ssanames.h
@@ -43,6 +43,9 @@ struct GTY(()) ptr_info_def
  above alignment.  Access only through the same helper functions as align
  above.  */
   unsigned int misalign;
+  /* When this pointer is knonw to be nnonnull this would be true otherwise
+ false.  */
+  bool  nonnull_p;
 };
 
 /* Value range information for SSA_NAMEs representing non-pointer variables.  
*/
@@ -89,6 +92,8 @@ extern void set_ptr_info_alignment (struct ptr_info_def *, 
unsigned int,
 extern void adjust_ptr_info_misalignment (struct ptr_info_def *,
  unsigned int);
 extern struct ptr_info_def *get_ptr_info (tree);
+extern void set_ptr_nonnull (tree name, bool nonnull_p);
+extern bool get_ptr_nonnull (tree name);
 
 extern tree copy_ssa_name_fn (struct function *, tree, gimple *);
 extern void duplicate_ssa_name_ptr_info (tree, struct ptr_info_def *);
diff --git a/gcc/tree-vrp.c b/gcc/tree-vrp.c
index 7c7ad91..40c4d48 100644
--- a/gcc/tree-vrp.c
+++ b/gcc/tree-vrp.c
@@ -10352,18 +10352,24 @@ vrp_finalize (bool warn_array_bounds_p)
   {
tree name = ssa_name (i);
 
-  if (!name
- || POINTER_TYPE_P (TREE_TYPE (name))
- || (vr_value[i]->type == VR_VARYING)
- || (vr_value[i]->type == VR_UNDEFINED))
-   continue;
+   if (!name
+   || (vr_value[i]->type == VR_VARYING)
+   || (vr_value[i]->type == VR_UNDEFINED)
+   || (TREE_CODE (vr_value[i]->min) != INTEGER_CST)
+   || (TREE_CODE (vr_value[i]->max) != INTEGER_CST))
+ continue;
 
-  if ((TREE_CODE (vr_value[i]->min) == INTEGER_CST)
- && (TREE_CODE (vr_value[i]->max) == INTEGER_CST)
- && (vr_value[i]->type == VR_RANGE
- || vr_value[i]->type == VR_ANTI_RANGE))
-   set_range_info (name, vr_value[i]->type, vr_value[i]->min,
-   vr_value[i]->max);
+   if (POINTER_TYPE_P (TREE_TYPE (name))
+   && ((vr_value[i]->type == VR_RANGE
+&& range_includes_zero_p (vr_value[i]->min,
+  vr_value[i]->max) == 0)
+   || (vr_value[i]->type == VR_ANTI_RANGE
+   && range_includes_zero_p (vr_value[i]->min,
+ vr_value[i]->max) == 1)))
+ set_ptr_nonnull (name, true);
+   else if (!POINTER_TYPE_P (TREE_TYPE (name)))
+ set_range_info (name, vr_value[i]->type, vr_value[i]->min,
+ vr_value[i]->max);
   }
 
   substitute_and_fold (op_with_constant_singleton_value_range,


Re: [PATCH 0/7, GCC, V8M] ARMv8-M Security Extensions

2016-08-07 Thread Sandra Loosemore

On 07/25/2016 07:17 AM, Andre Vieira (lists) wrote:

[PATCH 0/7, GCC, V8M] ARMv8-M Security Extensions

Hello,

This is a respin of a previous patch series for ARMv8-M Security
Extensions. In this version I have removed one patch, rebased the rest
and changed some of them.

This patch series aims at implementing support for ARMv8-M's Security
Extensions. You can find the specification of ARMV8-M Security
Extensions in: ARM®v8-M Security Extensions: Requirements on Development
Tools
(http://infocenter.arm.com/help/topic/com.arm.doc.ecm0359818/index.html).

We currently:
- do not support passing arguments or returning on the stack for
cmse_nonsecure_{call,entry} functions,
- only test Security Extensions for -mfpu=fpv5-d16 and fpv5-sp-d16 and
only support single and double precision FPU's with d16.

Bootstrapped and tested on arm-none-linux-gnueabihf and tested on
arm-none-eabi with ARMv8-M Baseline and Mainline targets.

Andre Vieira (7):
  Add support for ARMv8-M's Security Extensions flag and intrinsics
  Handling ARMv8-M Security Extension's cmse_nonsecure_entry attribute
  ARMv8-M Security Extension's cmse_nonsecure_entry: __acle_se label and
bxns return
  ARMv8-M Security Extension's cmse_nonsecure_entry: clear registers
  Handling ARMv8-M Security Extension's cmse_nonsecure_call attribute
  ARMv8-M Security Extension's cmse_nonsecure_call: use
__gnu_cmse_nonsecure_call
  Added support for ARMV8-M Security Extension cmse_nonsecure_caller
intrinsic


I didn't see any documentation here for the new attributes and built-in 
function.


-Sandra



Re: [avr,RFC,patch] Add var attribute "absdata" to support LDS / STS on AVR_TINY.

2016-08-07 Thread Sandra Loosemore

On 08/03/2016 10:17 AM, Georg-Johann Lay wrote:


Index: doc/extend.texi
===
--- doc/extend.texi (revision 238983)
+++ doc/extend.texi (working copy)
@@ -5957,6 +5957,25 @@ memory-mapped peripherals that may lie o
 volatile int porta __attribute__((address (0x600)));
 @end smallexample

+@item absdata
+@cindex @code{absdata} variable attribute, AVR
+Variables in static storage and with the @code{absdata} attribute can
+be accessed by the @code{LDS} and @code{STS} instructions which take
+absolute addresses.
+
+@itemize @bullet
+@item
+This attribute is only supported for the reduced AVR Tiny core
+like @code{ATtiny40}.
+
+@item
+There is currently no Binutils support for this attribute and the user has
+to make sure that respective data is located into an address range that
+can actually be handled by @code{LDS} and @code{STS}.
+This applies to addresses in the range @code{0x40}@dots{}@code{0xbf}.


The wording here is a little awkward -- in particular, "the user" is 
really "you", the reader of the manual.  How about something like this 
instead?


@item
You must use an appropriate linker script to locate the data in the 
address range accessible by @code{LDS} and @code{STS} 
(@code{0x40}@dots{}@code{0xbf}).


-Sandra



Re: [patch] New libstdc++ docs on testing and library versioning

2016-08-07 Thread Sandra Loosemore

On 08/04/2016 06:37 PM, Jonathan Wakely wrote:

I've been working on some changes to the libstdc++ manual recently.

A lot of the changes are just using DocBook markup with more semantic
meaning (e.g.  or  instead of using  for
everything that should use a monospace font) but there are some
changes to content too.

I've added a new subsection documenting the steps needed to bump the
library version when adding new symbols, and rewritten the section on
writing testcases. The main reason for the latter is to encourage the
use of { dg-do run { target c++11 } } rather than the { dg-options
"-std=gnu++11" } approach used until now. I've also started
documenting the libstdc++-specific dg-require-SUPPORT directives
available for our tests.

[snip]


I tried to look over this patch and my eyes started glazing over

I suggest trying to separate the markup changes (possibly multiple 
patches, for different kinds of changes) from the new content.  From my 
perspective, I think formatting cleanups and minor copy-editing can go 
in under the obvious patch rule as long as you are satisfied with the 
way it looks and have self-reviewed the patch to make sure you didn't 
accidentally delete some chunk of text or introduce some other 
unintended change.


The new material should be reviewed by someone knowledgeable enough to 
catch problems with the content.


-Sandra



Re: [patch, avr] Fix mmcu to specs issues

2016-08-07 Thread Pitchumani Sivanupandi

Ping!

On Friday 29 July 2016 05:14 PM, Pitchumani Sivanupandi wrote:

On Friday 29 July 2016 02:06 PM, Georg-Johann Lay wrote:

On 28.07.2016 13:50, Pitchumani Sivanupandi wrote:

On Tuesday 26 July 2016 06:00 PM, Georg-Johann Lay wrote:

On 26.07.2016 12:20, Pitchumani Sivanupandi wrote:
avr-gcc expected to find the device specs in the search paths 
specified. But
it doesn't work as expected when device specs in different place 
than the

installed location.

Example-1:
avr-gcc wrongly assumes the device specs will be in first identified
'device-specs' folder in prefix path. avr-gcc natively supports 
device
at90pwm1, but complains as it couldn't find the specs file in the 
first

'device-specs' directory in the search path.


$ avr-gcc test.c -mmcu=at90pwm1 -B /home/install/dev/atxmega128a1u/

avr-gcc: error: cannot access device-specs for _at90pwm1_ expected at


Are the "_"s literally? Then the spec file name should be 
"specs-_at90pwm1_".
No, It was mangled character shown by my terminal for format 
specifier "%qs" in

printf.
Ignore it.
...

Example-2:
Similar issue happens when -flto option is enabled and device 
specs in custom

search path.

atxmega128a1u device specs in custom path and that is passed with 
-B option.
Architecture spec files such as specs-avrxmega7 will be in 
installed location.


$ avr-gcc test.c -mmcu=atxmega128a1u -flto -B 
/home/install/dev/atxmega128a1u/


avr-gcc: error: cannot access device-specs for _avrxmega7_ 
expected at

_/home/install/dev/atxmega128a1u/device-specs/specs-avrxmega7_
avr-gcc: note: supported core architectures: avr2 avr25 avr3 avr31 
avr35 avr4
avr5 avr51 avr6 avrxmega2 avrxmega4 avrxmega5 avrxmega6 avrxmega7 
avrtiny avr1

avr-gcc: note: you can provide your own specs files, see
 for details
lto-wrapper: fatal error: avr-gcc returned 1 exit status
compilation terminated.
/home/avr-trunk/install/lib/gcc/avr/7.0.0/../../../../avr/bin/ld: 
error:

lto-wrapper failed
collect2: error: ld returned 1 exit status

Attached patch to address these issues.

Fix:
Replace device-specs-file spec function with mmcu-to-device-specs. 
This will
not assume that specs files are in first identified device-specs 
directory.
Instead this spec function will let gcc identify the absolute path 
of specs

file
using spec string "device-specs-file (device-specs/specs-%s)".


IIUC this leads to problems with LTO and when the install path 
contains
spaces which windows distros usually have.  The problem is that the 
spec
function cannot escape the spaces as it would need more than 1 
escape level.


It might also be the case that -mmcu= is specified more than once 
(with the
same MCU), but I don't remember exactly in which situations this 
happens...

Doesn't this lead to inclusion of more than one specs-file?


Yes, it lead to space problem.

Modified the patch because of path with spaces problem. When LTO 
enabled,

multiple specs-file are
included as -mmcu= is fed back to gcc. It happens with/ 
without of this

patch.
e.g. For atmega164p, device's and architecture's specs file given 
when invoking

collect2.
 -specs=device-specs/specs-atmega164p -specs=device-specs/specs-avr5

Attached new patch. It just removes the conditions that led to 
originally

stated issues.
(In driver-avr.c:avr_devicespecs_file)
Removed first condition as -mmcu=avr* shall come when LTO enabled. 
Second

condition to
check absolute path is wrong as the specfile_name composed here will 
not be

available
if the specs file is not present in first 'device-specs' directory.

With this approach, we can't issue 'descriptive' error for 
unavailable specs-file.

But, avr-gcc will issue below error if specs file is not found.
$ avr-gcc -mmcu=unknown test.c
avr-gcc: error: device-specs/specs-unknown: No such file or directory

Is that Ok?


Looks reasonable, just ...



Regards,
Pitchumani

gcc/ChangeLog

2016-07-28  Pitchumani Sivanupandi 

* config/avr/driver-avr.c (specfiles_doc_url): Remove.
(avr_diagnose_devicespecs_error): Remove.
(avr_devicespecs_file): Remove conditions to check specs-file,
let -specs= option handler do the validation.
 const char*
 avr_devicespecs_file (int argc, const char **argv)
 {
-  char *specfile_name;
   const char *mmcu = NULL;

 #ifdef DEBUG_SPECS
@@ -111,12 +88,10 @@ avr_devicespecs_file (int argc, const char **argv)
   break;
 }

-  specfile_name = concat (argv[0], dir_separator_str, "specs-", 
mmcu, NULL);

-
 #ifdef DEBUG_SPECS
   if (verbose_flag)
-fnotice (stderr, "'%s': mmcu='%s'\n'%s': specfile='%s'\n\n",
- __FUNCTION__, mmcu, __FUNCTION__, specfile_name);
+fnotice (stderr, "'%s': mmcu='%s'\n\n",
+ __FUNCTION__, mmcu);
 #endif


... this DEBUG_SPECS makes hardly any sense any more because it 
doesn't print any specs-related info.


Thanks for the review. Updated the patch.

If Ok, could someone commit please?

Regards,
Pitchumani


gcc/ChangeLog

2016-07-29  Pitc

Re: Ping [Fortran, Patch, pr70524, v1] [5/6/7 Regression] ICE when using -frepack-arrays -Warray-temporaries

2016-08-07 Thread Thomas Koenig

Hi Andre,

the patch is OK.



Ping.


Regards

Thomas



Re: Set nonnull attribute to ptr_info_def based on VRP

2016-08-07 Thread Jakub Jelinek
On Mon, Aug 08, 2016 at 01:36:51PM +1000, kugan wrote:
> diff --git a/gcc/tree-ssanames.h b/gcc/tree-ssanames.h
> index c81b1a1..6e34433 100644
> --- a/gcc/tree-ssanames.h
> +++ b/gcc/tree-ssanames.h
> @@ -43,6 +43,9 @@ struct GTY(()) ptr_info_def
>   above alignment.  Access only through the same helper functions as align
>   above.  */
>unsigned int misalign;
> +  /* When this pointer is knonw to be nnonnull this would be true otherwise
> + false.  */
> +  bool  nonnull_p;
>  };

Why do you need this?  Doesn't the pt.null bit represent that already?
Also, formatting and spelling:
s/knonw/known/
s/nnon/non/
s/bool  /bool /

Jakub


Re: [Fortran, Patch, PR72698, v1] [5/6/7 Regression] ICE in lhd_incomplete_type_error, at langhooks.c:205

2016-08-07 Thread Thomas Koenig

Am 07.08.2016 um 13:52 schrieb Andre Vehreschild:
Hi Andre,


attached patch fixes the ICE caused by a zero-sized string. Assigning
that string to a temporary variable obviously did not work out. The
patch fixes this by checking for zero-sized strings in SOURCE= and not
producing the code to assign "nothing" to the temporary
variable and later to the allocated memory. The version for gcc-5 had
to be adapted slightly, because the version of the ALLOCATE()
implementation is way behind.

Bootstrapped and regtested on x86_64-linux-gnu/F23. Ok for trunk, gcc-6
and gcc-5?


Looks good.

With the test case, you might consider changing that into a runtime
test to make sure that the correct result is obtained.

So, OK with that change.

Regards

Thomas



Re: [RS6000] PR72802 part 2, reload ICE

2016-08-07 Thread Alan Modra
On Fri, Aug 05, 2016 at 08:31:45PM -0500, Segher Boessenkool wrote:
> On Sat, Aug 06, 2016 at 10:53:33AM +0930, Alan Modra wrote:
> > On Fri, Aug 05, 2016 at 06:01:47PM -0500, Segher Boessenkool wrote:
> > > I agree reg-reg moves should come after reg-mem moves, but is it such
> > > a good idea to put e.g. f->f after r->*c*l?
> > 
> > I doubt it matters but I agree that it's unnecessary to move the
> > reg-reg moves to the last alternative.  They just need to be after
> > equivalent class reg-mem moves.  I'll move them earlier, which is
> > better since exact matches cut short the alternative evaluation.
> 
> Thanks!

Alternatives rearranged again.  This has been bootstrapped and
regression tested powerpc64le-linux using
RUNTESTFLAGS="--target_board=unix'{-mlra,-mno-lra}'" and
powerpc64-linux using
RUNTESTFLAGS="--target_board=unix'{-m32,-m64}{-mlra,-mno-lra}'"

PR target/72802
* config/rs6000/rs6000.md (mov_hardflow): Sort
alternatives.  Put loads first, then stores, and reg/reg moves
within same class later.  Delete attr length.
testsuite/
* gcc.c-torture/compile/pr72802.c: New.

diff --git a/gcc/config/rs6000/rs6000.md b/gcc/config/rs6000/rs6000.md
index 1430799..84cb066 100644
--- a/gcc/config/rs6000/rs6000.md
+++ b/gcc/config/rs6000/rs6000.md
@@ -6689,32 +6689,37 @@
 }")
 
 (define_insn "mov_hardfloat"
-  [(set (match_operand:FMOVE32 0 "nonimmediate_operand" 
"=!r,!r,m,f,,,!r,,Z,?,?r,*c*l,!r,*h")
-   (match_operand:FMOVE32 1 "input_operand" 
"r,m,r,fZ,,r,,r,h,0"))]
+  [(set (match_operand:FMOVE32 0 "nonimmediate_operand"
+"=!r,   ,  , ,  m, ,
+ , Z, , !r,?, ?r,
+ f, , !r,*c*l,  !r,*h")
+   (match_operand:FMOVE32 1 "input_operand"
+"m, ,  , Z, r, ,
+ , ,  , , r, ,
+ f, , r, r, *h,0"))]
   "(gpc_reg_operand (operands[0], mode)
|| gpc_reg_operand (operands[1], mode))
&& (TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT)"
   "@
-   mr %0,%1
lwz%U1%X1 %0,%1
-   stw%U0%X0 %1,%0
-   fmr %0,%1
-   xscpsgndp %x0,%x1,%x1
-   xxlxor %x0,%x0,%x0
-   li %0,0


+   
+   stw%U0%X0 %1,%0


-   

+   xxlxor %x0,%x0,%x0
+   li %0,0
mtvsrwz %x0,%1
mfvsrwz %0,%x1
+   fmr %0,%1
+   xscpsgndp %x0,%x1,%x1
+   mr %0,%1
mt%0 %1
mf%1 %0
nop"
-  [(set_attr "type" 
"*,load,store,fpsimple,fpsimple,veclogical,integer,fpload,fpload,fpstore,fpstore,fpload,fpstore,mffgpr,mftgpr,mtjmpr,mfjmpr,*")
-   (set_attr "length" "4")])
+  [(set_attr "type" 
"load,fpload,fpload,fpload,store,fpstore,fpstore,fpstore,veclogical,integer,mffgpr,mftgpr,fpsimple,fpsimple,*,mtjmpr,mfjmpr,*")])
 
 (define_insn "*mov_softfloat"
   [(set (match_operand:FMOVE32 0 "nonimmediate_operand" 
"=r,cl,r,r,m,r,r,r,r,*h")
diff --git a/gcc/testsuite/gcc.c-torture/compile/pr72802.c 
b/gcc/testsuite/gcc.c-torture/compile/pr72802.c
new file mode 100644
index 000..b9e1ab3
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/compile/pr72802.c
@@ -0,0 +1,211 @@
+static a[];
+static b, h, m, n, o, p, q, t, u, v, t5, t6, t16, t17, t18, t25;
+c;
+static volatile d;
+static volatile e;
+static volatile f;
+static volatile g;
+j;
+static volatile k;
+static volatile l;
+static volatile r;
+const volatile s;
+static volatile w;
+static volatile x;
+const volatile y;
+static volatile z;
+static volatile t1;
+static volatile t2;
+const t3;
+t4;
+const volatile t8;
+const volatile t9;
+const volatile t10;
+static volatile t11;
+static volatile t12;
+static volatile t13;
+static volatile t14;
+const volatile t15;
+static volatile t19;
+static volatile t20;
+const volatile t21;
+static volatile t22;
+static volatile t23;
+const volatile t24;
+*t29;
+fn1() { b = 5; }
+fn2(long);
+#pragma pack(1)
+struct S0 {
+  short f3;
+  float f4;
+  signed f5
+};
+const struct S0 t7[] = {};
+static fn3() {
+  int t26[] = {};
+  int t27[10] = {};
+  --t25;
+  if (fn4()) {
+t5++;
+fn5();
+int t28[] = {t26, t27};
+return;
+  }
+}
+fn6() {
+  int i, t30 = 0;
+  if (fn6 == 2)
+t30 = 1;
+  {
+int t31, i = 0;
+for (; i < 256; i++) {
+  t31 = i;
+  if (i & 1)
+t31 = 0;
+  a[i] = t31;
+}
+i = 0;
+for (; i < 3; i++)
+  t29[i] = t6;
+fn7();
+fn3();
+t4 = c = j = 0;
+  }
+  fn2(h);
+  if (t30)
+printf(b);
+  g;
+  fn2(g);
+  printf(b);
+  f;
+  fn2(f);
+  if (t30)
+printf(b);
+  e;
+  fn2(e);
+  printf(b);
+  fn8();
+  d;
+  fn2(d);
+  if (t30)
+printf(b);
+  l;
+  fn2(l);
+  printf(b);
+  k;
+  fn2(k);
+  if (t30)
+printf(b);
+  printf(b);
+  for (; i; i++) {
+y;
+fn2(y);
+printf(b);
+x;
+fn2(x);
+if (t30)
+  printf(b);
+w;
+fn2(w);
+printf(b);
+fn2(v);
+printf(b);
+fn2(u);
+if (t30)
+  printf(b);
+fn2(t);
+printf(b);
+s;
+fn2(s);
+if (t30)
+  printf(b);
+