[wwwdocs] Describe how to validate wwwdocs changes

2018-05-13 Thread Gerald Pfeifer
This is triggered by a report from Martin who rightfully pointed 
out that it's not straightforward to validate wwwdocs changes before 
committing a change.

Martin, what do you think?  Would that have avoided the challenges
your ran into?  Anything to better clarify or otherwise improve?

Gerald

Index: about.html
===
RCS file: /cvs/gcc/wwwdocs/htdocs/about.html,v
retrieving revision 1.28
diff -u -r1.28 about.html
--- about.html  6 May 2018 16:19:24 -   1.28
+++ about.html  14 May 2018 04:11:25 -
+Validating a change
+
+To validate any changes, you can use the https://validator.w3.org;>W3 Validator. Just replace the
+html tag at the beginning of the document with the following
+snippet and use the "Validate by File Upload" functionality.
+
+
+?xml version="1.0" encoding="utf-8"?
+!DOCTYPE html
+  PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";
+html xmlns="http://www.w3.org/1999/xhtml; xml:lang="en" lang="en"
+
+
 Checking in a change
 
 We recommend you list files explicitly to avoid accidental checkins


[PR63185][RFC] Improve DSE with branches

2018-05-13 Thread Kugan Vivekanandarajah
Hi,

Attached patch handles PR63185 when we reach PHI with temp != NULLL.
We could see the PHI and if there isn't any uses for PHI that is
interesting, we could ignore that ?

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

Thanks,
Kugan


gcc/ChangeLog:

2018-05-14  Kugan Vivekanandarajah  

* tree-ssa-dse.c (phi_dosent_define_nor_use_p): New.
(dse_classify_store): Use phi_dosent_define_nor_use_p.

gcc/testsuite/ChangeLog:

2018-05-14  Kugan Vivekanandarajah  

* gcc.dg/tree-ssa/ssa-dse-33.c: New test.
From a69caa24d9c1914b7617a937e84c3b612ffe6d9b Mon Sep 17 00:00:00 2001
From: Kugan Vivekanandarajah 
Date: Wed, 9 May 2018 16:26:16 +1000
Subject: [PATCH] PR63185

Change-Id: I9d307884add10d5b5ff07aa31dd86cb83b2388ec
---
 gcc/testsuite/gcc.dg/tree-ssa/ssa-dse-33.c | 13 +
 gcc/tree-ssa-dse.c | 30 +-
 2 files changed, 42 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/ssa-dse-33.c

diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ssa-dse-33.c b/gcc/testsuite/gcc.dg/tree-ssa/ssa-dse-33.c
new file mode 100644
index 000..46cb7d1
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/ssa-dse-33.c
@@ -0,0 +1,13 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-dse-details" } */
+
+void g();
+void f(int n)
+{
+char *p = malloc(1024);
+memset (p, 8, 1024);
+if (n)
+  g();
+}
+
+/* { dg-final { scan-tree-dump-times "Deleted dead calls" 1 "dse1"} } */
diff --git a/gcc/tree-ssa-dse.c b/gcc/tree-ssa-dse.c
index 9220fea..e7a4637 100644
--- a/gcc/tree-ssa-dse.c
+++ b/gcc/tree-ssa-dse.c
@@ -515,6 +515,30 @@ live_bytes_read (ao_ref use_ref, ao_ref *ref, sbitmap live)
   return true;
 }
 
+/*  Return true if there isnt any VDEF or VUSE by following PHI.  */
+
+static bool
+phi_dosent_define_nor_use_p (ao_ref *ref, gphi *phi)
+{
+  gimple *phi_use;
+  imm_use_iterator ui;
+  tree def = PHI_RESULT (phi);
+  bool ok = true;
+
+  FOR_EACH_IMM_USE_STMT (phi_use, ui, def)
+{
+  if (ref_maybe_used_by_stmt_p (phi_use, ref)
+	  || gimple_vdef (phi_use)
+	  || gimple_code (phi_use) == GIMPLE_PHI)
+	{
+	  ok = false;
+	  BREAK_FROM_IMM_USE_STMT (ui);
+	}
+}
+
+  return ok;
+}
+
 /* A helper of dse_optimize_stmt.
Given a GIMPLE_ASSIGN in STMT that writes to REF, find a candidate
statement *USE_STMT that may prove STMT to be dead.
@@ -570,6 +594,9 @@ dse_classify_store (ao_ref *ref, gimple *stmt, gimple **use_stmt,
 	  else if (gimple_code (use_stmt) == GIMPLE_PHI)
 	{
 	  if (temp
+		  && phi_dosent_define_nor_use_p (ref, as_a  (use_stmt)))
+		;
+	  else if (temp
 		  /* Make sure we are not in a loop latch block.  */
 		  || gimple_bb (stmt) == gimple_bb (use_stmt)
 		  || dominated_by_p (CDI_DOMINATORS,
@@ -585,7 +612,8 @@ dse_classify_store (ao_ref *ref, gimple *stmt, gimple **use_stmt,
 	  /* Do not consider the PHI as use if it dominates the
 	 stmt defining the virtual operand we are processing,
 		 we have processed it already in this case.  */
-	  if (gimple_bb (defvar_def) != gimple_bb (use_stmt)
+	  if (!temp
+		  && gimple_bb (defvar_def) != gimple_bb (use_stmt)
 		  && !dominated_by_p (CDI_DOMINATORS,
   gimple_bb (defvar_def),
   gimple_bb (use_stmt)))
-- 
2.7.4



Re: [RFC] Improve tree DSE

2018-05-13 Thread Kugan Vivekanandarajah
Hi Richard,

>> Given the simple testcases you add I wonder if you want a cheaper
>> implementation,
>> namely check that when reaching a loop PHI the only aliasing stmt in
>> its use-chain
>> is the use_stmt you reached the PHI from.  That would avoid this and the 
>> tests
>> for the store being redundant and simplify the patch considerably.

Tried implementing above in the attached patch.  Bootstrapped on
x86_64-linux-gnu. Full testing is ongoing.

Thanks,
Kugan

gcc/ChangeLog:

2018-05-14  Kugan Vivekanandarajah  

* tree-ssa-dse.c (phi_aliases_stmt_only): New.
(dse_classify_store): Use phi_aliases_stmt_only.

gcc/testsuite/ChangeLog:

2018-05-14  Kugan Vivekanandarajah  

* gcc.dg/tree-ssa/ssa-dse-31.c: New test.
* gcc.dg/tree-ssa/ssa-dse-32.c: New test.
From 102b1dd676446055fb881daa1fee4e96b6fe676d Mon Sep 17 00:00:00 2001
From: Kugan Vivekanandarajah 
Date: Wed, 9 May 2018 08:57:23 +1000
Subject: [PATCH] improve dse Change-Id:
 If23529a3ede8230b26de8d60c1e0c5141be8edb7

---
 gcc/testsuite/gcc.dg/tree-ssa/ssa-dse-31.c | 16 +++
 gcc/testsuite/gcc.dg/tree-ssa/ssa-dse-32.c | 23 +
 gcc/tree-ssa-dse.c | 33 +++---
 3 files changed, 69 insertions(+), 3 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/ssa-dse-31.c
 create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/ssa-dse-32.c

diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ssa-dse-31.c b/gcc/testsuite/gcc.dg/tree-ssa/ssa-dse-31.c
new file mode 100644
index 000..e4d71b2
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/ssa-dse-31.c
@@ -0,0 +1,16 @@
+
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-dse-details" } */
+#define SIZE 4
+
+int main ()
+{
+  static float a[SIZE];
+  int i;
+  for (i = 0; i < SIZE; i++)
+   __builtin_memset ((void *) a, 0, sizeof(float)*3);
+   __builtin_memset ((void *) a, 0, sizeof(float)*SIZE);
+  return 0;
+}
+
+/* { dg-final { scan-tree-dump-times "Deleted dead calls" 1 "dse1"} } */
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ssa-dse-32.c b/gcc/testsuite/gcc.dg/tree-ssa/ssa-dse-32.c
new file mode 100644
index 000..3d8fd5f
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/ssa-dse-32.c
@@ -0,0 +1,23 @@
+
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-dse-details" } */
+#define SIZE 4
+
+void s4 (float *restrict a)
+{
+  (void) __builtin_memset ((void *) a, 0, sizeof(float)*SIZE);
+}
+
+
+int main ()
+{
+  int i;
+  float a[10];
+  printf("Start\n");
+  for (i = 0; i < SIZE; i++)
+s4 (a);
+  printf("Done\n");
+  return 0;
+}
+
+/* { dg-final { scan-tree-dump-times "Deleted dead calls" 1 "dse1"} } */
diff --git a/gcc/tree-ssa-dse.c b/gcc/tree-ssa-dse.c
index 9220fea..6522a94 100644
--- a/gcc/tree-ssa-dse.c
+++ b/gcc/tree-ssa-dse.c
@@ -515,6 +515,28 @@ live_bytes_read (ao_ref use_ref, ao_ref *ref, sbitmap live)
   return true;
 }
 
+/* Return true if PHI stmt aliases only STMT1. */
+
+static bool
+phi_aliases_stmt_only (gphi *phi, gimple *stmt1)
+{
+  gimple *phi_use;
+  imm_use_iterator ui2;
+  tree def = PHI_RESULT (phi);
+  bool ok = true;
+
+  FOR_EACH_IMM_USE_STMT (phi_use, ui2, def)
+{
+  if (phi_use != stmt1)
+	{
+	  ok = false;
+	  BREAK_FROM_IMM_USE_STMT (ui2);
+	}
+}
+
+  return ok;
+}
+
 /* A helper of dse_optimize_stmt.
Given a GIMPLE_ASSIGN in STMT that writes to REF, find a candidate
statement *USE_STMT that may prove STMT to be dead.
@@ -571,9 +593,14 @@ dse_classify_store (ao_ref *ref, gimple *stmt, gimple **use_stmt,
 	{
 	  if (temp
 		  /* Make sure we are not in a loop latch block.  */
-		  || gimple_bb (stmt) == gimple_bb (use_stmt)
-		  || dominated_by_p (CDI_DOMINATORS,
- gimple_bb (stmt), gimple_bb (use_stmt))
+		  || ((gimple_bb (stmt) == gimple_bb (use_stmt)
+		   || dominated_by_p (CDI_DOMINATORS,
+	  gimple_bb (stmt), gimple_bb (use_stmt)))
+		  /* When reaching a loop PHI, the only aliasing stmt
+			 in its use-chain is the stmt you reached the
+			 PHI is OK.  */
+		  && !phi_aliases_stmt_only (as_a  (use_stmt),
+		 stmt))
 		  /* We can look through PHIs to regions post-dominating
 		 the DSE candidate stmt.  */
 		  || !dominated_by_p (CDI_POST_DOMINATORS,
-- 
2.7.4



[C++ Patch] Add TYPE_REF_P

2018-05-13 Thread Paolo Carlini

Hi,

this simply adds the missing TYPE_REF_P - counterpart of TYPE_PTR_P - 
and uses it throughout (also adjusts a few places to consistently use 
the existing TYPE_PTR_P). Tested x86_64-linux.


Thanks, Paolo.



2018-05-14  Paolo Carlini  

* cp-tree.h (TYPE_REF_P): New.
(TYPE_OBJ_P, TYPE_REF_OBJ_P, TYPE_REFFN_P): Update.
* call.c (build_list_conv, build_aggr_conv, standard_conversion,
direct_reference_binding, reference_binding, implicit_conversion,
add_builtin_candidate, build_user_type_conversion_1, build_op_call_1,
build_new_op_1, build_x_va_arg, conv_binds_ref_to_prvalue,
build_over_call, perform_implicit_conversion_flags,
extend_ref_init_temps, type_has_extended_temps): Use it.
* class.c (one_inheriting_sig, check_field_decls,
check_bases_and_members, find_flexarrays, finish_struct,
fixed_type_or_null): Likewise.
* constexpr.c (literal_type_p, cxx_bind_parameters_in_call,
non_const_var_error, cxx_eval_constant_expression,
potential_constant_expression_1): Likewise.
* cp-gimplify.c (omp_var_to_track, omp_cxx_notice_variable,
cp_genericize_r, cxx_omp_privatize_by_reference,
cxx_omp_const_qual_no_mutable, cxx_omp_finish_clause,
cp_fold_maybe_rvalue): Likewise.
* cp-ubsan.c (cp_ubsan_maybe_instrument_downcast): Likewise.
* cvt.c (build_up_reference, convert_to_reference,
convert_from_reference, convert_to_void, noexcept_conv_p,
fnptr_conv_p): Likewise.
* decl.c (poplevel, check_for_uninitialized_const_var,
check_initializer, initialize_local_var, cp_finish_decl,
get_tuple_decomp_init, cp_finish_decomp, grokdeclarator, copy_fn_p,
move_signature_fn_p, grok_op_properties, finish_function): Likewise.
* decl2.c (grok_array_decl, cp_reconstruct_complex_type,
decl_maybe_constant_var_p): Likewise.
* error.c (dump_type_prefix, dump_expr): Likewise.
* except.c (initialize_handler_parm, complete_ptr_ref_or_void_ptr_p,
is_admissible_throw_operand_or_catch_parameter): Likewise.
* expr.c (mark_use): Likewise.
* init.c (build_zero_init_1, build_value_init_noctor,
perform_member_init, diagnose_uninitialized_cst_or_ref_member_1,
build_new, build_delete): Likewise.
* lambda.c (build_lambda_object): Likewise.
* mangle.c (write_expression, write_template_arg): Likewise.
* method.c (forward_parm, do_build_copy_constructor,
do_build_copy_assign, build_stub_object, constructible_expr,
walk_field_subobs): Likewise.
* parser.c (cp_parser_omp_for_loop_init,
cp_parser_omp_declare_reduction_exprs,
cp_parser_omp_declare_reduction): Likewise.
* pt.c (convert_nontype_argument_function, convert_nontype_argument,
convert_template_argument, tsubst_pack_expansion,
tsubst_function_decl, tsubst_decl, tsubst, tsubst_copy_and_build,
maybe_adjust_types_for_deduction, check_cv_quals_for_unify, unify,
more_specialized_fn, invalid_nontype_parm_type_p, dependent_type_p_r,
value_dependent_expression_p, build_deduction_guide): Likewise.
* semantics.c (finish_handler_parms, finish_non_static_data_member,
finish_compound_literal, omp_privatize_field,
handle_omp_array_sections_1, handle_omp_array_sections,
cp_check_omp_declare_reduction, finish_omp_reduction_clause,
finish_omp_declare_simd_methods, cp_finish_omp_clause_depend_sink,
finish_omp_clauses, finish_decltype_type, capture_decltype,
finish_builtin_launder): Likewise.
* tree.c (lvalue_kind, cp_build_reference_type, move,
cp_build_qualified_type_real, stabilize_expr, stabilize_init): Likewise.
* typeck.c (cxx_safe_arg_type_equiv_p, build_class_member_access_expr,
cp_build_indirect_ref_1, convert_arguments, warn_for_null_address,
cp_build_addr_expr_1, maybe_warn_about_useless_cast,
build_static_cast_1, build_static_cast, build_reinterpret_cast_1,
build_const_cast_1, cp_build_c_cast, cp_build_modify_expr,
convert_for_initialization,
maybe_warn_about_returning_address_of_local, check_return_expr,
cp_type_quals, casts_away_constness, non_reference): Likewise.
* typeck2.c (cxx_readonly_error, store_init_value,
process_init_constructor_record, build_x_arrow, build_functional_cast,
add_exception_specifier): Likewise.
Index: call.c
===
--- call.c  (revision 260183)
+++ call.c  (working copy)
@@ -814,7 +814,7 @@ build_list_conv (tree type, tree ctor, int flags,
   flags |= LOOKUP_NO_NARROWING;
 
   /* Can't make an array of these types.  */
-  if (TREE_CODE (elttype) == REFERENCE_TYPE
+  if (TYPE_REF_P (elttype)
   || TREE_CODE 

Re: [PATCH 1/2] gcc_qsort: source code changes

2018-05-13 Thread H.J. Lu
On Thu, May 10, 2018 at 8:56 AM, Alexander Monakov  wrote:
> * sort.cc: New file.
> * system.h [!CHECKING_P] (qsort): Redirect to gcc_qsort.
> * vec.c (qsort_chk): Use gcc_qsort.
>

This breaks bootstrap on Fedora 28/i686:

https://gcc.gnu.org/ml/gcc-regression/2018-05/msg00088.html

../../src-trunk/gcc/sort.cc:112:5: note: in expansion of macro ‘REORDER_45’
 REORDER_45 (8, 8, 0);
 ^~
../../src-trunk/gcc/sort.cc:100:10: error: ‘void* memcpy(void*, const
void*, size_t)’ forming offset [5, 8] is out of the bounds [0, 4] of
object ‘t2’ with type ‘size_t’ {aka ‘unsigned int’}
[-Werror=array-bounds]
   memcpy (, e2 + OFFSET, SIZE);  \
   ~~~^~~~
../../src-trunk/gcc/sort.cc:112:5: note: in expansion of macro ‘REORDER_45’
 REORDER_45 (8, 8, 0);
 ^~
../../src-trunk/gcc/sort.cc:97:18: note: ‘t2’ declared here
   size_t t0, t1, t2, t3;\
  ^~
../../src-trunk/gcc/sort.cc:112:5: note: in expansion of macro ‘REORDER_45’
 REORDER_45 (8, 8, 0);
 ^~
../../src-trunk/gcc/sort.cc:101:10: error: ‘void* memcpy(void*, const
void*, size_t)’ forming offset [5, 8] is out of the bounds [0, 4] of
object ‘t3’ with type ‘size_t’ {aka ‘unsigned int’}
[-Werror=array-bounds]
   memcpy (, e3 + OFFSET, SIZE);  \
   ~~~^~~~
../../src-trunk/gcc/sort.cc:112:5: note: in expansion of macro ‘REORDER_45’
 REORDER_45 (8, 8, 0);
 ^~
../../src-trunk/gcc/sort.cc:97:22: note: ‘t3’ declared here
   size_t t0, t1, t2, t3;\
  ^~
../../src-trunk/gcc/sort.cc:112:5: note: in expansion of macro ‘REORDER_45’
 REORDER_45 (8, 8, 0);
 ^~
../../src-trunk/gcc/sort.cc:105:10: error: ‘void* memcpy(void*, const
void*, size_t)’ forming offset [5, 8] is out of the bounds [0, 4] of
object ‘t0’ with type ‘size_t’ {aka ‘unsigned int’}
[-Werror=array-bounds]
   memcpy (out, , SIZE); out += STRIDE;   \
   ~~~^~~~
../../src-trunk/gcc/sort.cc:112:5: note: in expansion of macro ‘REORDER_45’
 REORDER_45 (8, 8, 0);
 ^~
../../src-trunk/gcc/sort.cc:97:10: note: ‘t0’ declared here
   size_t t0, t1, t2, t3;\
  ^~
../../src-trunk/gcc/sort.cc:112:5: note: in expansion of macro ‘REORDER_45’
 REORDER_45 (8, 8, 0);
 ^~
../../src-trunk/gcc/sort.cc:106:10: error: ‘void* memcpy(void*, const
void*, size_t)’ forming offset [5, 8] is out of the bounds [0, 4] of
object ‘t1’ with type ‘size_t’ {aka ‘unsigned int’}
[-Werror=array-bounds]
   memcpy (out, , SIZE); out += STRIDE;   \
   ~~~^~~~
../../src-trunk/gcc/sort.cc:112:5: note: in expansion of macro ‘REORDER_45’
 REORDER_45 (8, 8, 0);
 ^~
../../src-trunk/gcc/sort.cc:97:14: note: ‘t1’ declared here
   size_t t0, t1, t2, t3;\
  ^~
../../src-trunk/gcc/sort.cc:112:5: note: in expansion of macro ‘REORDER_45’
 REORDER_45 (8, 8, 0);
 ^~
../../src-trunk/gcc/sort.cc:107:10: error: ‘void* memcpy(void*, const
void*, size_t)’ forming offset [5, 8] is out of the bounds [0, 4] of
object ‘t2’ with type ‘size_t’ {aka ‘unsigned int’}
[-Werror=array-bounds]
   memcpy (out, , SIZE); out += STRIDE;   \
   ~~~^~~~
../../src-trunk/gcc/sort.cc:112:5: note: in expansion of macro ‘REORDER_45’
 REORDER_45 (8, 8, 0);
 ^~
../../src-trunk/gcc/sort.cc:97:18: note: ‘t2’ declared here
   size_t t0, t1, t2, t3;\
  ^~
../../src-trunk/gcc/sort.cc:112:5: note: in expansion of macro ‘REORDER_45’
 REORDER_45 (8, 8, 0);
 ^~
../../src-trunk/gcc/sort.cc:108:10: error: ‘void* memcpy(void*, const
void*, size_t)’ forming offset [5, 8] is out of the bounds [0, 4] of
object ‘t3’ with type ‘size_t’ {aka ‘unsigned int’}
[-Werror=array-bounds]
   memcpy (out, , SIZE);  \
   ~~~^~~~
../../src-trunk/gcc/sort.cc:112:5: note: in expansion of macro ‘REORDER_45’
 REORDER_45 (8, 8, 0);
 ^~
../../src-trunk/gcc/sort.cc:97:22: note: ‘t3’ declared here
   size_t t0, t1, t2, t3;\
  ^~
../../src-trunk/gcc/sort.cc:112:5: note: in expansion of macro ‘REORDER_45’
 REORDER_45 (8, 8, 0);
 ^~


Re: [wwwdocs] Add GCC 8 Fortran feature description

2018-05-13 Thread Damian Rouson
**PING**

Could someone either approve and apply this or explain to me how to do so?  I 
don’t have commit rights so I don’t think I can do it.

Damian

On May 2, 2018 at 11:22:02 AM, Damian Rouson (dam...@sourceryinstitute.org) 
wrote:

The patch below includes a description of a new feature in gfortran for 
inclusion in the GCC 8 changes.html file.  I don’t have commit rights.  Could 
someone approve and apply this?  Thanks.  

Damian  


cvs diff: Diffing .  
Index: changes.html  
===  
RCS file: /cvs/gcc/wwwdocs/htdocs/gcc-8/changes.html,v  
retrieving revision 1.74  
diff -r1.74 changes.html  
761a762,765  
>      
>     Partial support is provided for Fortran 2018 teams, which are 
> hierarchical  
>     subsets of images that execute independently of other image subsets.   
>     


[Committed] PR fortran/63529 -- Fix documentation.

2018-05-13 Thread Steve Kargl
I've committed the attach document patch.

2018-05-13  Steven G. Kargl  

PR fortran/63529
* gfortran.texi: Clarify documentation for Cray pointer and
assumed-sized array.

-- 
Steve
Index: gcc/fortran/gfortran.texi
===
--- gcc/fortran/gfortran.texi	(revision 260209)
+++ gcc/fortran/gfortran.texi	(working copy)
@@ -1906,10 +1906,12 @@ or,
 pointer (  ,  ), (  ,  ), ...
 @end smallexample
 The pointer is an integer that is intended to hold a memory address.
-The pointee may be an array or scalar.  A pointee can be an assumed
-size array---that is, the last dimension may be left unspecified by
-using a @code{*} in place of a value---but a pointee cannot be an
-assumed shape array.  No space is allocated for the pointee.
+The pointee may be an array or scalar.
+If an assumed-size array is permitted within the scoping unit, a
+pointee can be an assumed-size array.
+That is, the last dimension may be left unspecified by using a @code{*}
+in place of a value. A pointee cannot be an assumed shape array.
+No space is allocated for the pointee.
 
 The pointee may have its type declared before or after the pointer
 statement, and its array specification (if any) may be declared


Re: [RFC][PATCH] Extend DCE to remove unnecessary new/delete-pairs

2018-05-13 Thread Marc Glisse

On Wed, 29 Nov 2017, David Malcolm wrote:


I was experimenting with optimizing away matching malloc/free pairs,
moving the allocation to either the stack, or to a thread-local
obstack, under certain conditions, or to hoist allocations out of
loops.

I didn't get any significant wins, but much of this was due to my lack
of experience with the middle-end, and being drawn back to front-
end/diagnostic improvements.


Hello,

could you share what you have? Is this something you might work on again 
at some point?


I had a go (very limited) at this problem some years ago, and would be 
interested in looking at your approach.


--
Marc Glisse


[Patch, fortran] PR85742 sizeof allocatable arrays returning wrong value

2018-05-13 Thread Paul Richard Thomas
I intend to apply this 'obvious' patch to trunk and 8-branch tonight,
unless there are any objections.

Bootstrapped and regetested on FC27/x86_64.

Paul

2018-05-13  Paul Thomas  

PR fortran/85742
* trans-types.c (gfc_get_dtype_rank_type): Reorder evaluation
of 'size'. If the element type is a pointer use the size of the
TREE_TYPE of the type, unless it is VOID_TYPE. In this latter
case, set the size to zero.

2018-05-13  Paul Thomas  

PR fortran/85742
* gfortran.dg/assumed_type_9.f90 : New test.
Index: gcc/fortran/trans-types.c
===
*** gcc/fortran/trans-types.c	(revision 260208)
--- gcc/fortran/trans-types.c	(working copy)
*** gfc_get_dtype_rank_type (int rank, tree
*** 1518,1523 
--- 1518,1525 
tree field;
vec *v = NULL;

+   size = TYPE_SIZE_UNIT (etype);
+
switch (TREE_CODE (etype))
  {
  case INTEGER_TYPE:
*** gfc_get_dtype_rank_type (int rank, tree
*** 1546,1567 
  /* We will never have arrays of arrays.  */
  case ARRAY_TYPE:
n = BT_CHARACTER;
break;

  case POINTER_TYPE:
n = BT_ASSUMED;
  break;

  default:
/* TODO: Don't do dtype for temporary descriptorless arrays.  */
!   /* We can strange array types for temporary arrays.  */
return gfc_index_zero_node;
  }

-   size = TYPE_SIZE_UNIT (etype);
-   if (n == BT_CHARACTER && size == NULL_TREE)
- size = TYPE_SIZE_UNIT (TREE_TYPE (etype));
-
tmp = get_dtype_type_node ();
field = gfc_advance_chain (TYPE_FIELDS (tmp),
  			 GFC_DTYPE_ELEM_LEN);
--- 1548,1571 
  /* We will never have arrays of arrays.  */
  case ARRAY_TYPE:
n = BT_CHARACTER;
+   if (size == NULL_TREE)
+ 	size = TYPE_SIZE_UNIT (TREE_TYPE (etype));
break;

  case POINTER_TYPE:
n = BT_ASSUMED;
+   if (TREE_CODE (TREE_TYPE (etype)) != VOID_TYPE)
+ 	size = TYPE_SIZE_UNIT (TREE_TYPE (etype));
+   else
+ 	size = build_int_cst (size_type_node, 0);
  break;

  default:
/* TODO: Don't do dtype for temporary descriptorless arrays.  */
!   /* We can encounter strange array types for temporary arrays.  */
return gfc_index_zero_node;
  }

tmp = get_dtype_type_node ();
field = gfc_advance_chain (TYPE_FIELDS (tmp),
  			 GFC_DTYPE_ELEM_LEN);
Index: gcc/testsuite/gfortran.dg/assumed_type_9.f90
===
*** gcc/testsuite/gfortran.dg/assumed_type_9.f90	(nonexistent)
--- gcc/testsuite/gfortran.dg/assumed_type_9.f90	(working copy)
***
*** 0 
--- 1,34 
+ ! { dg-do run }
+ !
+ ! Test the fix for PR85742 in which the descriptors, passed to alsize,
+ ! for 'a' and 'b' had the wrong element length.
+ !
+ ! Contributed by Cesar Philippidis  
+ !
+ program main
+   implicit none
+   integer, allocatable :: a
+   real, pointer :: b
+   integer, allocatable :: am(:,:)
+   real, pointer :: bm(:,:)
+
+   allocate (a)
+   allocate (b)
+   allocate (am(3,3))
+   allocate (bm(4,4))
+
+   if (sizeof (a) /= alsize (a)) stop 1
+   if (sizeof (b) /= alsize (b)) stop 2
+   if (sizeof (am) /= alsize (am)) stop 3
+   if (sizeof (bm) /= alsize (bm)) stop 4
+
+   deallocate (b)
+   deallocate (bm)
+ contains
+   function alsize (a)
+ integer alsize
+ type (*), dimension (..), contiguous :: a
+ alsize = sizeof(a)
+   end function
+ end program main
+


Re: [PATCH] Fortran cleanup patch

2018-05-13 Thread Andre Vehreschild


On Thu, 10 May 2018 16:08:17 -0700
Steve Kargl  wrote:

> The attached patch removed an unused function.
> OK to commit?

Removing unused code, can only make things easier. Ok to commit IMHO.

- Andre

> 
> 2018-05-10  Steven G. Kargl  
> 
>* gfortran.h: Remove prototype.
>* symbol.c (gfc_new_undo_checkpoint): Remove unused function.
> 


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


Re: [PATCH] PR fortran/85521 -- Zero length substrings in array aconstructors

2018-05-13 Thread Andre Vehreschild
Hi,

sorry, I didn't get, that this is standard conforming. So go for it: Ok for
trunk and thanks for the patch.

- Andre

On Thu, 10 May 2018 08:41:21 -0700
Steve Kargl  wrote:

> It is certainly possible to give a warning, but it
> would be odd (to me) to warn about technically
> standard conforming code.  gfortran doesn't warn
> for zero-sized array references or zero-length
> substrings in other context.
> 
> program foo
>real a(4)
>character(len=10) s
>s = '12345'
>a = 1
>print *, size(a(2:1)), len(s(3:2))
> end program foo
> % gfc -o z a.f90
> % ./z
>0   0
> 


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