diff mbox

[fortran] merge two gfc_trans_scalar_assign flags

Message ID 5533C1BD.4000707@sfr.fr
State New
Headers show

Commit Message

Mikael Morin April 19, 2015, 2:54 p.m. UTC
Hello,

while working on pr65792, I noticed that gfc_trans_scalar_assign's
l_is_temp and dealloc flags are used only once, and at the same place.
This patch merges them together.
The calls are changed from
	gfc_trans_scalar_assign (...blah..., foo, x, bar);
to
	gfc_trans_scalar_assign (...blah..., x, !foo && bar);
As foo is most of the time either true or false, this is a simplification.

regression tested on x86-64-unknown-linux-gnu.
OK for post 5.1 trunk?

Mikael
2015-04-19  Mikael Morin  <mikael@gcc.gnu.org>

	* trans.h (gfc_trans_scalar_assign): Remove fourth argument.
	* trans-expr.c (gfc_trans_scalar_assign): Merge fourth into sixth
	argument.
	(gfc_conv_subref_array_arg, gfc_trans_subarray_assign,
	 gfc_trans_subcomponent_assign, gfc_trans_assignment_1): Update callers.
	* trans-array.c (gfc_conv_expr_descriptor): Ditto.
	* trans-stmt.c (forall_make_variable_temp,
	generate_loop_for_temp_to_lhs, generate_loop_for_rhs_to_temp,
	gfc_trans_where_assign, gfc_trans_where_3): Ditto.

Comments

Mikael Morin Aug. 6, 2015, 10:07 a.m. UTC | #1
Le 19/04/2015 16:54, Mikael Morin a écrit :
> Hello,
>
> while working on pr65792, I noticed that gfc_trans_scalar_assign's
> l_is_temp and dealloc flags are used only once, and at the same place.
> This patch merges them together.
> The calls are changed from
> 	gfc_trans_scalar_assign (...blah..., foo, x, bar);
> to
> 	gfc_trans_scalar_assign (...blah..., x, !foo && bar);
> As foo is most of the time either true or false, this is a simplification.
>
> regression tested on x86-64-unknown-linux-gnu.
> OK for post 5.1 trunk?
>

Ping: https://gcc.gnu.org/ml/gcc-patches/2015-04/msg00966.html
Paul Richard Thomas Aug. 6, 2015, 10:15 a.m. UTC | #2
Dear Mikael,

Well spotted! This is fine for trunk, since it is 'obvious' once seen.

Cheers

Paul

On 6 August 2015 at 12:07, Mikael Morin <mikael.morin@sfr.fr> wrote:
> Le 19/04/2015 16:54, Mikael Morin a écrit :
>>
>> Hello,
>>
>> while working on pr65792, I noticed that gfc_trans_scalar_assign's
>> l_is_temp and dealloc flags are used only once, and at the same place.
>> This patch merges them together.
>> The calls are changed from
>>         gfc_trans_scalar_assign (...blah..., foo, x, bar);
>> to
>>         gfc_trans_scalar_assign (...blah..., x, !foo && bar);
>> As foo is most of the time either true or false, this is a simplification.
>>
>> regression tested on x86-64-unknown-linux-gnu.
>> OK for post 5.1 trunk?
>>
>
> Ping: https://gcc.gnu.org/ml/gcc-patches/2015-04/msg00966.html
diff mbox

Patch

Index: trans-array.c
===================================================================
--- trans-array.c	(révision 221972)
+++ trans-array.c	(copie de travail)
@@ -6760,9 +6760,9 @@  gfc_conv_expr_descriptor (gfc_se *se, gfc_expr *ex
       gfc_add_block_to_block (&block, &lse.pre);
 
       lse.string_length = rse.string_length;
-      tmp = gfc_trans_scalar_assign (&lse, &rse, expr->ts, true,
+      tmp = gfc_trans_scalar_assign (&lse, &rse, expr->ts,
 				     expr->expr_type == EXPR_VARIABLE
-				     || expr->expr_type == EXPR_ARRAY, true);
+				     || expr->expr_type == EXPR_ARRAY, false);
       gfc_add_expr_to_block (&block, tmp);
 
       /* Finish the copying loops.  */
Index: trans-expr.c
===================================================================
--- trans-expr.c	(révision 221972)
+++ trans-expr.c	(copie de travail)
@@ -4191,7 +4191,7 @@  gfc_conv_subref_array_arg (gfc_se * parmse, gfc_ex
 
   if (intent != INTENT_OUT)
     {
-      tmp = gfc_trans_scalar_assign (&lse, &rse, expr->ts, true, false, true);
+      tmp = gfc_trans_scalar_assign (&lse, &rse, expr->ts, false, false);
       gfc_add_expr_to_block (&body, tmp);
       gcc_assert (rse.ss == gfc_ss_terminator);
       gfc_trans_scalarizing_loops (&loop, &body);
@@ -4298,7 +4298,7 @@  gfc_conv_subref_array_arg (gfc_se * parmse, gfc_ex
 
   gcc_assert (lse.ss == gfc_ss_terminator);
 
-  tmp = gfc_trans_scalar_assign (&lse, &rse, expr->ts, false, false, true);
+  tmp = gfc_trans_scalar_assign (&lse, &rse, expr->ts, false, true);
   gfc_add_expr_to_block (&body, tmp);
 
   /* Generate the copying loops.  */
@@ -6504,7 +6504,7 @@  gfc_trans_subarray_assign (tree dest, gfc_componen
 
   gfc_conv_expr (&rse, expr);
 
-  tmp = gfc_trans_scalar_assign (&lse, &rse, cm->ts, true, false, true);
+  tmp = gfc_trans_scalar_assign (&lse, &rse, cm->ts, false, false);
   gfc_add_expr_to_block (&body, tmp);
 
   gcc_assert (rse.ss == gfc_ss_terminator);
@@ -6977,7 +6977,7 @@  gfc_trans_subcomponent_assign (tree dest, gfc_comp
       if (cm->ts.type == BT_CHARACTER)
 	lse.string_length = cm->ts.u.cl->backend_decl;
       lse.expr = dest;
-      tmp = gfc_trans_scalar_assign (&lse, &se, cm->ts, true, false, true);
+      tmp = gfc_trans_scalar_assign (&lse, &se, cm->ts, false, false);
       gfc_add_expr_to_block (&block, tmp);
     }
   return gfc_finish_block (&block);
@@ -7882,7 +7882,7 @@  gfc_conv_string_parameter (gfc_se * se)
 
 tree
 gfc_trans_scalar_assign (gfc_se * lse, gfc_se * rse, gfc_typespec ts,
-			 bool l_is_temp, bool deep_copy, bool dealloc)
+			 bool deep_copy, bool dealloc)
 {
   stmtblock_t block;
   tree tmp;
@@ -7931,7 +7931,7 @@  gfc_trans_scalar_assign (gfc_se * lse, gfc_se * rs
 	 the same as the rhs.  This must be done following the assignment
 	 to prevent deallocating data that could be used in the rhs
 	 expression.  */
-      if (!l_is_temp && dealloc)
+      if (dealloc)
 	{
 	  tmp_var = gfc_evaluate_now (lse->expr, &lse->pre);
 	  tmp = gfc_deallocate_alloc_comp_no_caf (ts.u.derived, tmp_var, 0);
@@ -9013,9 +9013,9 @@  gfc_trans_assignment_1 (gfc_expr * expr1, gfc_expr
     }
 
   tmp = gfc_trans_scalar_assign (&lse, &rse, expr1->ts,
-				 l_is_temp || init_flag,
 				 expr_is_variable (expr2) || scalar_to_array
-				 || expr2->expr_type == EXPR_ARRAY, dealloc);
+				 || expr2->expr_type == EXPR_ARRAY,
+				 !(l_is_temp || init_flag) && dealloc);
   gfc_add_expr_to_block (&body, tmp);
 
   if (lss == gfc_ss_terminator)
@@ -9056,7 +9056,7 @@  gfc_trans_assignment_1 (gfc_expr * expr1, gfc_expr
 	    rse.string_length = string_length;
 
 	  tmp = gfc_trans_scalar_assign (&lse, &rse, expr1->ts,
-					 false, false, dealloc);
+					 false, dealloc);
 	  gfc_add_expr_to_block (&body, tmp);
 	}
 
Index: trans-stmt.c
===================================================================
--- trans-stmt.c	(révision 221973)
+++ trans-stmt.c	(copie de travail)
@@ -2835,8 +2835,8 @@  forall_make_variable_temp (gfc_code *c, stmtblock_
 	  tse.expr = gfc_create_var (tmp, "temp");
 	}
 
-      tmp = gfc_trans_scalar_assign (&tse, &rse, e->ts, true,
-				     e->expr_type == EXPR_VARIABLE, true);
+      tmp = gfc_trans_scalar_assign (&tse, &rse, e->ts,
+				     e->expr_type == EXPR_VARIABLE, false);
       gfc_add_expr_to_block (pre, tmp);
     }
   gfc_free_expr (e);
@@ -3207,7 +3207,7 @@  generate_loop_for_temp_to_lhs (gfc_expr *expr, tre
 
       /* Use the scalar assignment.  */
       rse.string_length = lse.string_length;
-      tmp = gfc_trans_scalar_assign (&lse, &rse, expr->ts, false, true, true);
+      tmp = gfc_trans_scalar_assign (&lse, &rse, expr->ts, true, true);
 
       /* Form the mask expression according to the mask tree list.  */
       if (wheremask)
@@ -3305,8 +3305,8 @@  generate_loop_for_rhs_to_temp (gfc_expr *expr2, tr
 
   /* Use the scalar assignment.  */
   lse.string_length = rse.string_length;
-  tmp = gfc_trans_scalar_assign (&lse, &rse, expr2->ts, true,
-				 expr2->expr_type == EXPR_VARIABLE, true);
+  tmp = gfc_trans_scalar_assign (&lse, &rse, expr2->ts,
+				 expr2->expr_type == EXPR_VARIABLE, false);
 
   /* Form the mask expression according to the mask tree list.  */
   if (wheremask)
@@ -4480,7 +4480,7 @@  gfc_trans_where_assign (gfc_expr *expr1, gfc_expr
 
   /* Use the scalar assignment as is.  */
   tmp = gfc_trans_scalar_assign (&lse, &rse, expr1->ts,
-				 loop.temp_ss != NULL, false, true);
+				 false, loop.temp_ss == NULL);
 
   tmp = build3_v (COND_EXPR, maskexpr, tmp, build_empty_stmt (input_location));
 
@@ -4533,8 +4533,7 @@  gfc_trans_where_assign (gfc_expr *expr1, gfc_expr
 					TREE_TYPE (maskexpr), maskexpr);
 
           /* Use the scalar assignment as is.  */
-          tmp = gfc_trans_scalar_assign (&lse, &rse, expr1->ts, false, false,
-					 true);
+          tmp = gfc_trans_scalar_assign (&lse, &rse, expr1->ts, false, true);
           tmp = build3_v (COND_EXPR, maskexpr, tmp,
 			  build_empty_stmt (input_location));
           gfc_add_expr_to_block (&body, tmp);
@@ -4934,8 +4933,8 @@  gfc_trans_where_3 (gfc_code * cblock, gfc_code * e
 	gfc_conv_expr (&edse, edst);
     }
 
-  tstmt = gfc_trans_scalar_assign (&tdse, &tsse, tdst->ts, false, false, true);
-  estmt = eblock ? gfc_trans_scalar_assign (&edse, &esse, edst->ts, false,
+  tstmt = gfc_trans_scalar_assign (&tdse, &tsse, tdst->ts, false, true);
+  estmt = eblock ? gfc_trans_scalar_assign (&edse, &esse, edst->ts,
 					    false, true)
 		 : build_empty_stmt (input_location);
   tmp = build3_v (COND_EXPR, cexpr, tstmt, estmt);
Index: trans.h
===================================================================
--- trans.h	(révision 221972)
+++ trans.h	(copie de travail)
@@ -471,8 +471,7 @@  int gfc_conv_procedure_call (gfc_se *, gfc_symbol
 void gfc_conv_subref_array_arg (gfc_se *, gfc_expr *, int, sym_intent, bool);
 
 /* Generate code for a scalar assignment.  */
-tree gfc_trans_scalar_assign (gfc_se *, gfc_se *, gfc_typespec, bool, bool,
-			      bool);
+tree gfc_trans_scalar_assign (gfc_se *, gfc_se *, gfc_typespec, bool, bool);
 
 /* Translate COMMON blocks.  */
 void gfc_trans_common (gfc_namespace *);