[gcc(refs/users/mikael/heads/refactor_descriptor_v291.01)] Initialisation shifted offset en partant de zero

Mikael Morin via Gcc-cvs <[email protected]>
Newsgroups gmane.comp.gcc.cvs
Message-ID <[email protected]>
https://gcc.gnu.org/g:4aa9cba7c097da094863707e16dca8a054a7620f

commit 4aa9cba7c097da094863707e16dca8a054a7620f
Author: Mikael Morin <[email protected]>
Date:   Thu Aug 14 11:59:54 2025 +0200

    Initialisation shifted offset en partant de zero
    
    Suppression utilisation offset descripteur comme variable temporaire

Diff:
---
 gcc/fortran/trans-descriptor.cc | 39 ++++++++++++++++++++-------------------
 gcc/fortran/trans-descriptor.h  |  1 -
 2 files changed, 20 insertions(+), 20 deletions(-)

diff --git a/gcc/fortran/trans-descriptor.cc b/gcc/fortran/trans-descriptor.cc
index ff9b2a80f352..88c5cabab210 100644
--- a/gcc/fortran/trans-descriptor.cc
+++ b/gcc/fortran/trans-descriptor.cc
@@ -767,19 +767,20 @@ gfc_conv_descriptor_cosize (tree desc, int rank, int corank)
 /* Modify a descriptor such that the lbound of a given dimension is the value
    specified.  This also updates ubound and offset accordingly.  */
 
-void
-gfc_conv_shift_descriptor_lbound (stmtblock_t* block, tree desc,
-				  int dim, tree new_lbound)
+static void
+conv_shift_descriptor_lbound (stmtblock_t* block, tree desc,
+			      int dim, tree new_lbound, tree *offset)
 {
-  tree offs, ubound, lbound, stride;
-  tree diff, offs_diff;
+  tree ubound, lbound, stride;
+  tree diff;
 
   new_lbound = fold_convert (gfc_array_index_type, new_lbound);
+  new_lbound = gfc_evaluate_now (new_lbound, block);
 
-  offs = gfc_conv_descriptor_offset_get (desc);
   lbound = gfc_conv_descriptor_lbound_get (desc, gfc_rank_cst[dim]);
   ubound = gfc_conv_descriptor_ubound_get (desc, gfc_rank_cst[dim]);
   stride = gfc_conv_descriptor_stride_get (desc, gfc_rank_cst[dim]);
+  stride = gfc_evaluate_now (stride, block);
 
   /* Get difference (new - old) by which to shift stuff.  */
   diff = fold_build2_loc (input_location, MINUS_EXPR, gfc_array_index_type,
@@ -790,11 +791,10 @@ gfc_conv_shift_descriptor_lbound (stmtblock_t* block, tree desc,
   ubound = fold_build2_loc (input_location, PLUS_EXPR, gfc_array_index_type,
 			    ubound, diff);
   gfc_conv_descriptor_ubound_set (block, desc, gfc_rank_cst[dim], ubound);
-  offs_diff = fold_build2_loc (input_location, MULT_EXPR, gfc_array_index_type,
-			       diff, stride);
-  offs = fold_build2_loc (input_location, MINUS_EXPR, gfc_array_index_type,
-			  offs, offs_diff);
-  gfc_conv_descriptor_offset_set (block, desc, offs);
+  tree tmp = fold_build2_loc (input_location, MULT_EXPR, gfc_array_index_type,
+			      new_lbound, stride);
+  *offset = fold_build2_loc (input_location, MINUS_EXPR, gfc_array_index_type,
+			     *offset, tmp);
 
   /* Finally set lbound to value we want.  */
   gfc_conv_descriptor_lbound_set (block, desc, gfc_rank_cst[dim], new_lbound);
@@ -1095,9 +1095,11 @@ void
 gfc_conv_shift_descriptor (stmtblock_t* block, tree desc, int rank)
 {
   /* Apply a shift of the lbound when supplied.  */
+  tree offset = gfc_index_zero_node;
   for (int dim = 0; dim < rank; ++dim)
-    gfc_conv_shift_descriptor_lbound (block, desc, dim,
-				      gfc_index_one_node);
+    conv_shift_descriptor_lbound (block, desc, dim,
+				  gfc_index_one_node, &offset);
+  gfc_conv_descriptor_offset_set (block, desc, offset);
 }
 
 
@@ -1106,6 +1108,7 @@ conv_shift_descriptor (stmtblock_t *block, tree desc, int rank,
 		       gfc_expr * const (lbound[GFC_MAX_DIMENSIONS]))
 {
   /* Apply a shift of the lbound when supplied.  */
+  tree offset = gfc_index_zero_node;
   for (int dim = 0; dim < rank; ++dim)
     {
       gfc_expr *lb_expr = lbound[dim];
@@ -1128,8 +1131,9 @@ conv_shift_descriptor (stmtblock_t *block, tree desc, int rank,
 	  lower_bound = lb_var;
 	}
 
-      gfc_conv_shift_descriptor_lbound (block, desc, dim, lower_bound);
+      conv_shift_descriptor_lbound (block, desc, dim, lower_bound, &offset);
     }
+  gfc_conv_descriptor_offset_set (block, desc, offset);
 }
 
 
@@ -1249,9 +1253,7 @@ gfc_set_subarray_descriptor (stmtblock_t *block, tree descr, tree value,
 
   /* Shift the lbound and ubound of temporaries to being unity,
      rather than zero, based. Always calculate the offset.  */
-  gfc_conv_descriptor_offset_set (block, descr, gfc_index_zero_node);
-  tree offset = gfc_conv_descriptor_offset_get (descr);
-  tree tmp2 = gfc_create_var (gfc_array_index_type, NULL);
+  tree offset = gfc_index_zero_node;
 
   for (int n = 0; n < value_expr->rank; n++)
     {
@@ -1297,9 +1299,8 @@ gfc_set_subarray_descriptor (stmtblock_t *block, tree descr, tree value,
 							     gfc_rank_cst[n]),
 			     gfc_conv_descriptor_stride_get (descr,
 							     gfc_rank_cst[n]));
-      gfc_add_modify (block, tmp2, tmp);
       tmp = fold_build2_loc (input_location, MINUS_EXPR, gfc_array_index_type,
-			     offset, tmp2);
+			     offset, tmp);
       gfc_conv_descriptor_offset_set (block, descr, tmp);
     }
 }
diff --git a/gcc/fortran/trans-descriptor.h b/gcc/fortran/trans-descriptor.h
index ade35475c836..ccd22a3160c7 100644
--- a/gcc/fortran/trans-descriptor.h
+++ b/gcc/fortran/trans-descriptor.h
@@ -87,7 +87,6 @@ void gfc_init_descriptor_variable (stmtblock_t *block, gfc_symbol *sym, tree des
 
 void gfc_copy_coarray_desc_part (stmtblock_t *, tree, tree);
 
-void gfc_conv_shift_descriptor_lbound (stmtblock_t *, tree, int, tree);
 void gfc_conv_shift_descriptor (stmtblock_t *, tree, int);
 void gfc_conv_shift_descriptor (stmtblock_t *, tree, const gfc_array_ref &);
 void gfc_conv_shift_descriptor (stmtblock_t *, tree, tree, int, tree);
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.