[gcc(refs/users/mikael/heads/refactor_descriptor_v08)] Refactoring gfc_nullify_descriptor/gfc_init_descriptor_variable

2025-09-20 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:29b9e1d7599ad9de54f40bf91b69da72bb69f5a9

commit 29b9e1d7599ad9de54f40bf91b69da72bb69f5a9
Author: Mikael Morin 
Date:   Thu Aug 7 11:42:13 2025 +0200

Refactoring gfc_nullify_descriptor/gfc_init_descriptor_variable

Diff:
---
 gcc/fortran/trans-descriptor.cc | 35 ---
 gcc/fortran/trans-expr.cc   | 11 +--
 gcc/fortran/trans-types.h   |  1 +
 gcc/fortran/trans.h |  1 +
 4 files changed, 35 insertions(+), 13 deletions(-)

diff --git a/gcc/fortran/trans-descriptor.cc b/gcc/fortran/trans-descriptor.cc
index d2b908c875b2..2ed8a6453949 100644
--- a/gcc/fortran/trans-descriptor.cc
+++ b/gcc/fortran/trans-descriptor.cc
@@ -597,12 +597,11 @@ gfc_conv_descriptor_ubound_set (stmtblock_t *block, tree 
desc,
unknown cases abort.  */
 
 tree
-gfc_get_dtype_rank_type (int rank, tree etype)
+gfc_get_dtype_rank_type_slen (int rank, tree etype, tree length)
 {
   tree ptype;
   tree size;
   int n;
-  tree tmp;
   tree dtype;
   tree field;
   vec *v = NULL;
@@ -666,7 +665,7 @@ gfc_get_dtype_rank_type (int rank, tree etype)
 {
 case BT_CHARACTER:
   gcc_assert (TREE_CODE (ptype) == ARRAY_TYPE);
-  size = gfc_get_character_len_in_bytes (ptype);
+  size = gfc_get_character_len_in_bytes (ptype, length);
   break;
 case BT_VOID:
   gcc_assert (TREE_CODE (ptype) == POINTER_TYPE);
@@ -677,14 +676,12 @@ gfc_get_dtype_rank_type (int rank, tree etype)
   break;
 }
 
-  tree dtype_type_node = get_dtype_type_node ();
-
   gcc_assert (size);
 
   STRIP_NOPS (size);
   size = fold_convert (size_type_node, size);
-  tmp = get_dtype_type_node ();
-  field = gfc_advance_chain (TYPE_FIELDS (tmp),
+  tree dtype_type_node = get_dtype_type_node ();
+  field = gfc_advance_chain (TYPE_FIELDS (dtype_type_node),
 GFC_DTYPE_ELEM_LEN);
   CONSTRUCTOR_APPEND_ELT (v, field,
  fold_convert (TREE_TYPE (field), size));
@@ -704,11 +701,19 @@ gfc_get_dtype_rank_type (int rank, tree etype)
   CONSTRUCTOR_APPEND_ELT (v, field,
  build_int_cst (TREE_TYPE (field), n));
 
-  dtype = build_constructor (tmp, v);
+  dtype = build_constructor (dtype_type_node, v);
 
   return dtype;
 }
 
+
+tree
+gfc_get_dtype_rank_type (int rank, tree etype)
+{
+  return gfc_get_dtype_rank_type_slen (rank, etype, NULL_TREE);
+}
+
+
 /* Build a null array descriptor constructor.  */
 
 tree
@@ -843,7 +848,8 @@ gfc_init_static_descriptor (tree descr)
 
 
 void
-gfc_init_descriptor_variable (stmtblock_t *block, gfc_symbol *sym, gfc_expr 
*expr, tree descr)
+gfc_nullify_descriptor (stmtblock_t *block, gfc_symbol *sym, gfc_expr *expr,
+   tree descr, tree string_length)
 {
   symbol_attribute attr = gfc_symbol_attr (sym);
 
@@ -875,8 +881,15 @@ gfc_init_descriptor_variable (stmtblock_t *block, 
gfc_symbol *sym, gfc_expr *exp
 rank = -1;
 
   tree etype = gfc_get_element_type (TREE_TYPE (descr));
-  gfc_conv_descriptor_dtype_set (block, descr,
-gfc_get_dtype_rank_type (rank, etype));
+  tree dtype = gfc_get_dtype_rank_type_slen (rank, etype, string_length);
+  gfc_conv_descriptor_dtype_set (block, descr, dtype);
+}
+
+void
+gfc_init_descriptor_variable (stmtblock_t *block, gfc_symbol *sym,
+ gfc_expr *expr, tree descr)
+{
+  return gfc_nullify_descriptor (block, sym, expr, descr, NULL_TREE);
 }
 
 
diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc
index e553bd34a148..d8705f9a7196 100644
--- a/gcc/fortran/trans-expr.cc
+++ b/gcc/fortran/trans-expr.cc
@@ -66,7 +66,7 @@ gfc_get_character_len (tree type)
 /* Calculate the number of bytes in a string.  */
 
 tree
-gfc_get_character_len_in_bytes (tree type)
+gfc_get_character_len_in_bytes (tree type, tree slen)
 {
   tree tmp, len;
 
@@ -76,7 +76,7 @@ gfc_get_character_len_in_bytes (tree type)
   tmp = TYPE_SIZE_UNIT (TREE_TYPE (type));
   tmp = (tmp && !integer_zerop (tmp))
 ? (fold_convert (gfc_charlen_type_node, tmp)) : (NULL_TREE);
-  len = gfc_get_character_len (type);
+  len = slen ? slen : gfc_get_character_len (type);
   if (tmp && len && !integer_zerop (len))
 len = fold_build2_loc (input_location, MULT_EXPR,
   gfc_charlen_type_node, len, tmp);
@@ -84,6 +84,13 @@ gfc_get_character_len_in_bytes (tree type)
 }
 
 
+tree
+gfc_get_character_len_in_bytes (tree type)
+{
+  return gfc_get_character_len_in_bytes (type, NULL_TREE);
+}
+
+
 /* Convert a scalar to an array descriptor. To be used for assumed-rank
arrays.  */
 
diff --git a/gcc/fortran/trans-types.h b/gcc/fortran/trans-types.h
index aba841da9cb5..dc75cd82a841 100644
--- a/gcc/fortran/trans-types.h
+++ b/gcc/fortran/trans-types.h
@@ -116,6 +116,7 @@ bool gfc_return_by_reference (gfc_symbol *);
 bool gfc_is_nodesc_array (gfc_symbol *);
 
 /* Return the DTYPE for an array.  */
+tree gfc_get_dtype_rank_type_slen (int, tree, tree);
 tree gfc_get_dt

[gcc(refs/users/mikael/heads/refactor_descriptor_v08)] Correction régression pdt_31

2025-09-20 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:bfd00602df897b58564613faf0724d6776e2621d

commit bfd00602df897b58564613faf0724d6776e2621d
Author: Mikael Morin 
Date:   Sun Sep 14 13:43:25 2025 +0200

Correction régression pdt_31

Correction régression transfer_class_5

Correction régression class_dummy_11.f90

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

diff --git a/gcc/fortran/trans-descriptor.cc b/gcc/fortran/trans-descriptor.cc
index 55e2798234b4..3fa03c5fc234 100644
--- a/gcc/fortran/trans-descriptor.cc
+++ b/gcc/fortran/trans-descriptor.cc
@@ -1606,6 +1606,9 @@ gfc_copy_descriptor (stmtblock_t *block, tree dest, tree 
src, bool lhs_type)
   gfc_conv_descriptor_dtype_set (block, dest,
 gfc_conv_descriptor_dtype_get (src));
 
+  gfc_conv_descriptor_span_set (block, dest,
+   gfc_conv_descriptor_span_get (src));
+
   /* Assign the dimension as range-ref.  */
   tree tmp = gfc_get_descriptor_dimension (dest);
   tree tmp2 = gfc_get_descriptor_dimension (src);
@@ -1802,7 +1805,25 @@ gfc_set_descriptor (stmtblock_t *block, tree dest, tree 
src, gfc_expr *src_expr,
   /* Set the dtype.  */
   tree dtype;
   if (unlimited_polymorphic)
-dtype = gfc_get_dtype (TREE_TYPE (src), &rank);
+{
+  if (UNLIMITED_POLY (src_expr))
+   {
+ tree tmp2 = src;
+ if (TREE_CODE (tmp2) == INDIRECT_REF
+ && DECL_P (TREE_OPERAND (tmp2, 0)))
+   tmp2 = TREE_OPERAND (tmp2, 0);
+ if (DECL_P (tmp2)
+ && DECL_LANG_SPECIFIC (tmp2)
+ && GFC_DECL_SAVED_DESCRIPTOR (tmp2))
+   tmp2 = GFC_DECL_SAVED_DESCRIPTOR (tmp2);
+ tmp2 = gfc_class_data_get (tmp2);
+ if (POINTER_TYPE_P (TREE_TYPE (tmp2)))
+   tmp2 = build_fold_indirect_ref_loc (input_location, tmp2);
+ dtype = gfc_conv_descriptor_dtype_get (tmp2);
+   }
+  else
+   dtype = gfc_get_dtype (TREE_TYPE (src), &rank);
+}
   else if (src_expr->ts.type == BT_ASSUMED)
 {
   tree tmp2 = src;
@@ -2635,6 +2656,8 @@ gfc_set_pdt_array_descriptor (stmtblock_t *block, tree 
descr,
   gfc_conv_descriptor_dtype_set (block, descr,
 gfc_get_dtype (TREE_TYPE (descr)));
 
+  gfc_conv_descriptor_span_set (block, descr, elt_size);
+
   size = fold_build2_loc (input_location, MULT_EXPR,
  gfc_array_index_type, size, elt_size);
   size = gfc_evaluate_now (size, block);
diff --git a/libgfortran/libgfortran.h b/libgfortran/libgfortran.h
index 5cdd564ab0e6..5937cac4c365 100644
--- a/libgfortran/libgfortran.h
+++ b/libgfortran/libgfortran.h
@@ -485,7 +485,7 @@ typedef GFC_FULL_ARRAY_DESCRIPTOR (GFC_MAX_DIMENSIONS, 
GFC_INTEGER_4) gfc_full_a
 
 #define GFC_DESCRIPTOR_STRIDE(desc,i) ((desc)->dim[i]._stride)
 #define GFC_DESCRIPTOR_STRIDE_BYTES(desc,i) \
-  (GFC_DESCRIPTOR_STRIDE(desc,i) * GFC_DESCRIPTOR_SIZE(desc))
+  (GFC_DESCRIPTOR_STRIDE(desc,i) * GFC_DESCRIPTOR_SPAN(desc))
 
 /* Macros to get both the size and the type with a single masking operation  */


[gcc r14-12030] testsuite: arm: Simplify fp16-aapcs tests

2025-09-20 Thread Torbjorn Svensson via Gcc-cvs
https://gcc.gnu.org/g:bfd2c5550130e7cb8596f0621afc59dee082f212

commit r14-12030-gbfd2c5550130e7cb8596f0621afc59dee082f212
Author: Torbjörn SVENSSON 
Date:   Wed Aug 27 16:25:14 2025 +0200

testsuite: arm: Simplify fp16-aapcs tests

Reduce fp16-aapcs testcases to return value testing since parameter
passing are already tested in aapcs/vfp*.c

gcc/testsuite/ChangeLog:
* gcc.target/arm/fp16-aapcs.c: New test.
* gcc.target/arm/fp16-aapcs-1.c: Removed.
* gcc.target/arm/fp16-aapcs-2.c: Likewise.
* gcc.target/arm/fp16-aapcs-3.c: Likewise.
* gcc.target/arm/fp16-aapcs-4.c: Likewise.

Signed-off-by: Torbjörn SVENSSON 
(cherry picked from commit 1cf8cb45d872a5f09d65c63c891c091710c37432)

Diff:
---
 gcc/testsuite/gcc.target/arm/fp16-aapcs-1.c | 65 -
 gcc/testsuite/gcc.target/arm/fp16-aapcs-2.c | 44 ---
 gcc/testsuite/gcc.target/arm/fp16-aapcs-3.c | 65 -
 gcc/testsuite/gcc.target/arm/fp16-aapcs-4.c | 44 ---
 gcc/testsuite/gcc.target/arm/fp16-aapcs.c   | 24 +++
 5 files changed, 24 insertions(+), 218 deletions(-)

diff --git a/gcc/testsuite/gcc.target/arm/fp16-aapcs-1.c 
b/gcc/testsuite/gcc.target/arm/fp16-aapcs-1.c
deleted file mode 100644
index b18d7cda65c8..
--- a/gcc/testsuite/gcc.target/arm/fp16-aapcs-1.c
+++ /dev/null
@@ -1,65 +0,0 @@
-/* { dg-do compile }  */
-/* { dg-require-effective-target arm_hard_vfp_ok }  */
-/* { dg-require-effective-target arm_fp16_ok } */
-/* { dg-options "-O2" }  */
-/* { dg-add-options arm_fp16_ieee } */
-/* { dg-final { check-function-bodies "**" "" "" } } */
-
-/* Test __fp16 arguments and return value in registers (hard-float).  */
-
-void
-swap (__fp16, __fp16);
-
-/*
-** F:
-** ...
-** (
-
-Below block is for non-armv8.1
-** (
-** vmov\.f32   (s[3-9]|s1[0-5]), s0
-** ...
-** vmov\.f32   s0, s1
-** ...
-** vmov\.f32   s1, \1
-** |
-** vmov\.f32   (s[3-9]|s1[0-5]), s1
-** ...
-** vmov\.f32   s1, s0
-** ...
-** vmov\.f32   s0, \2
-** )
-** vstr\.32s2, \[sp, #4\]  @ int
-** bl  swap
-** vldr\.32s2, \[sp, #4\]  @ int
-** vmov\.f32   s0, s2
-
-** |
-
-Below block is for armv8.1
-** (
-** vmov(s[3-9]|s1[0-5]), s0@ __fp16
-** ...
-** vmovs0, s1  @ __fp16
-** ...
-** vmovs1, \3  @ __fp16
-** |
-** vmov(s[3-9]|s1[0-5]), s1@ __fp16
-** ...
-** vmovs1, s0  @ __fp16
-** ...
-** vmovs0, \4  @ __fp16
-** )
-** vstr\.32s2, \[sp, #4\]  @ int
-** bl  swap
-** vldr\.16s0, \[sp, #4\]
-
-** )
-** ...
-*/
-__fp16
-F (__fp16 a, __fp16 b, __fp16 c)
-{
-  swap (b, a);
-  return c;
-}
diff --git a/gcc/testsuite/gcc.target/arm/fp16-aapcs-2.c 
b/gcc/testsuite/gcc.target/arm/fp16-aapcs-2.c
deleted file mode 100644
index 48510e895368..
--- a/gcc/testsuite/gcc.target/arm/fp16-aapcs-2.c
+++ /dev/null
@@ -1,44 +0,0 @@
-/* { dg-do compile }  */
-/* { dg-require-effective-target arm_fp16_ok } */
-/* { dg-options "-mfloat-abi=softfp -O2 -mno-long-calls" }  */
-/* { dg-add-options arm_fp16_ieee } */
-/* { dg-skip-if "incompatible float-abi" { arm*-*-* } { "-mfloat-abi=hard" } } 
*/
-/* { dg-final { check-function-bodies "**" "" "" } } */
-
-/* Test __fp16 arguments and return value in registers (softfp).  */
-
-void
-swap (__fp16, __fp16);
-
-/*
-** F:
-** ...
-** (
-** mov r3, r0  @ __fp16
-** ...
-** mov r0, r1  @ __fp16
-** ...
-** mov r1, r3  @ __fp16
-** |
-** mov r3, r1  @ __fp16
-** ...
-** mov r1, r0  @ __fp16
-** ...
-** mov r0, r3  @ __fp16
-** )
-** ...
-*/
-/*
-** F: { target arm_little_endian }
-** ...
-** str r2, \[sp, #4\]
-** bl  swap
-** ldrhr0, \[sp, #4\]  @ __fp16
-** ...
-*/
-__fp16
-F (__fp16 a, __fp16 b, __fp16 c)
-{
-  swap (b, a);
-  return c;
-}
diff --git a/gcc/testsuite/gcc.target/arm/fp16-aapcs-3.c 
b/gcc/testsuite/gcc.target/arm/fp16-aapcs-3.c
deleted file mode 100644
index 7238ef3a02e0..
--- a/gcc/testsuite/gcc.target/arm/fp16-aapcs-3.c
+++ /dev/null
@@ -1,65 +0,0 @@
-/* { dg-do compile }  */
-/* { dg-require-effective-target arm_hard_vfp_ok }  */
-/* { dg-require-effective-target arm_fp16_alternative_ok } */
-/* { dg-options "-O2" }  */
-/* { dg-add-options arm_fp16_alternative } */
-/* { dg-final { check-function-bodies "**" "" "" } } */
-
-/* Test __fp16 arguments and return value in registers (hard-float).  */
-
-void
-swap (__fp16, __fp16);
-
-/*
-** F:
-** ...
-** (
-
-Below block is for non-armv8.1
-** (
-** vmov\.f32   (s[3-9]|s1[0-5]), s0
-** ...
-** vmov\.f32   s0, s1
-** ...
-** vmov\.f32   s1, \1
-** |
-** vmov\.f32   (s[3-9]|s1[0-5]), s1
-** ...
-** vmov\.f32   s1, s0
-** ...
-** vmov\.f32   s0, \2
-** )
-** vstr\.32s2, \[sp, #4\]  @ int
-** bl

[gcc(refs/users/meissner/heads/work222)] Add cpu option flag bits

2025-09-20 Thread Michael Meissner via Gcc-cvs
https://gcc.gnu.org/g:3107708d6391eb7625f64ca4c6bc33de0985532c

commit 3107708d6391eb7625f64ca4c6bc33de0985532c
Author: Michael Meissner 
Date:   Sun Sep 21 01:13:41 2025 -0400

Add cpu option flag bits

2025-09-21  Michael Meissner  

gcc/

* config/rs6000/aix71.h (RS6000_CPU_OPTION): Define and undefine 
macro.
* config/rs6000/aix72.h (RS6000_CPU_OPTION): Likewise.
* config/rs6000/aix73.h (RS6000_CPU_OPTION): Likewise.
* config/rs6000/default64.h (RS6000_CPU_OPTION): Likewise.
* config/rs6000/driver-rs6000.cc (RS6000_CPU_OPTION): Likewise.
* config/rs6000/rs6000-c.cc (rs6000_target_modify_macros): Add CPU
options parameter.
(rs6000_cpu_cpp_builtins): Likewise.
* config/rs6000/rs6000-cpus.def (toplevel): Add comment describing 
ISA
mask bits and CPU option mask bits.
(CPU_OPTION_POWER7_MASK): New macro.
(CPU_OPTION_POWER8_MASK): Likewise.
(CPU_OPTION_POWER9_MASK): Likewise.
(CPU_OPTION_POWER10_MASK): Likewise.
(CPU_OPTION_POWER11_MASK): Likewise.
(CPU_OPTION_POWER7_ALL_MASKS): Likewise.
(CPU_OPTION_POWER8_ALL_MASKS): Likewise.
(CPU_OPTION_POWER9_ALL_MASKS): Likewise.
(CPU_OPTION_POWER10_ALL_MASKS): Likewise.
(CPU_OPTION_POWER11_ALL_MASKS): Likewise.
(power7 cpu): Switch to use RS6000_CPU_OPTION in order to set the 
CPU
option mask bits.
(power8): Likewise.
(power9): Likewise.
(power10): Likewise.
(power11): Likewise.
* config/rs6000/rs6000-protos.h (rs6000_target_modify_macros): Add 
CPU
option argument.
(rs6000_target_modify_macros_ptr): Likewise.
* config/rs6000/rs6000.cc (rs6000_target_modify_macros_ptr): 
Likewise.
(rs6000_print_isa_options): Likewise.
(struct rs6000_ptt): Likewise.
(RS6000_CPU): Likewise.
(RS6000_CPU_OPTION): Likewise.
(DEBUG_FMT_WX): Likewise.
(rs6000_debug_reg_global): Likewise.
(rs6000_option_override_internal): Likewise.
(struct rs6000_cpu_opt_mask): Likewise.
(rs6000_cpu_opt_masks): Likewise.
(rs6000_pragma_target_parse): Likewise.
(rs6000_function_specific_print): Likewise.
(rs6000_print_options_internal): Likewise.
* config/rs6000/rs6000.opt (rs6000_cpu_option_flags): New target
variable.
(x_rs6000_cpu_option_flags): Likewise.

Diff:
---
 gcc/config/rs6000/aix71.h  |   2 +
 gcc/config/rs6000/aix72.h  |   2 +
 gcc/config/rs6000/aix73.h  |   2 +
 gcc/config/rs6000/default64.h  |   2 +
 gcc/config/rs6000/driver-rs6000.cc |   2 +
 gcc/config/rs6000/rs6000-c.cc  |  12 ++--
 gcc/config/rs6000/rs6000-cpus.def  |  99 ++---
 gcc/config/rs6000/rs6000-protos.h  |   5 +-
 gcc/config/rs6000/rs6000.cc| 127 -
 gcc/config/rs6000/rs6000.opt   |   9 +++
 10 files changed, 217 insertions(+), 45 deletions(-)

diff --git a/gcc/config/rs6000/aix71.h b/gcc/config/rs6000/aix71.h
index 2b21dd7cd1e0..5423252f7688 100644
--- a/gcc/config/rs6000/aix71.h
+++ b/gcc/config/rs6000/aix71.h
@@ -133,8 +133,10 @@ do {   
\
%{pthread: -D_THREAD_SAFE}"
 
 #define RS6000_CPU(NAME, CPU, FLAGS)
+#define RS6000_CPU_OPTION(NAME, CPU, FLAGS, CPU_OPTION)
 #include "rs6000-cpus.def"
 #undef RS6000_CPU
+#undef RS6000_CPU_OPTION
 
 #undef  TARGET_DEFAULT
 #ifdef RS6000_BI_ARCH
diff --git a/gcc/config/rs6000/aix72.h b/gcc/config/rs6000/aix72.h
index 53c0bde5ad4a..fdddc4327963 100644
--- a/gcc/config/rs6000/aix72.h
+++ b/gcc/config/rs6000/aix72.h
@@ -134,8 +134,10 @@ do {   
\
%{pthread: -D_THREAD_SAFE}"
 
 #define RS6000_CPU(NAME, CPU, FLAGS)
+#define RS6000_CPU_OPTION(NAME, CPU, FLAGS, CPU_OPTION)
 #include "rs6000-cpus.def"
 #undef RS6000_CPU
+#undef RS6000_CPU_OPTION
 
 #undef  TARGET_DEFAULT
 #ifdef RS6000_BI_ARCH
diff --git a/gcc/config/rs6000/aix73.h b/gcc/config/rs6000/aix73.h
index c7639368a264..37c2c081c34a 100644
--- a/gcc/config/rs6000/aix73.h
+++ b/gcc/config/rs6000/aix73.h
@@ -135,8 +135,10 @@ do {   
\
%{pthread: -D_THREAD_SAFE}"
 
 #define RS6000_CPU(NAME, CPU, FLAGS)
+#define RS6000_CPU_OPTION(NAME, CPU, FLAGS, CPU_OPTION)
 #include "rs6000-cpus.def"
 #undef RS6000_CPU
+#undef RS6000_CPU_OPTION
 
 #undef  TARGET_DEFAULT
 #ifdef RS6000_BI_ARCH
diff --git a/gcc/config/rs6000/default64.h b/gcc/config/rs6000/default64.h
index 7f6001ded852..d289c6dfd6d8 100644
--- a/gcc/config/rs6000/default64.h
+++ b/gcc/config/rs6000/default64.h
@@ -19,8 +19,10 

[gcc(refs/users/meissner/heads/work222)] Add -mcpu=future support.

2025-09-20 Thread Michael Meissner via Gcc-cvs
https://gcc.gnu.org/g:239581ebbda4846c409f7c7c42237a7bbae2296c

commit 239581ebbda4846c409f7c7c42237a7bbae2296c
Author: Michael Meissner 
Date:   Sun Sep 21 01:57:56 2025 -0400

Add -mcpu=future support.

2025-09-21  Michael Meissner  

gcc/

* config/rs6000/aix71.h (ASM_CPU_SPEC): If -mcpu=future, pass 
-mfuture
to the assembler.
* config/rs6000/aix72.h (ASM_CPU_SPEC): Likewise.
* config/rs6000/aix73.h (ASM_CPU_SPEC): Likewise.
* config/rs6000/rs6000.c.cc (rs6000_target_modify_macros): If
-mcpu=future define _ARCH_FUTURE.
* config/rs6000/rs6000-cpus.def (CPU_OPTION_FUTURE_MASK): Add 
support
for -mcpu=future.
(CPU_OPTION_FUTURE_ALL_MASKS): Likewise.
(future cpu): Likewise.
* config/rs6000/rs6000-tables.opt: Regenerate.
* config/rs6000/rs6000.cc (power10_cost): Update comment.
(rs6000_machine_from_flags): Add support for -mcpu=future.
(rs6000_cpu_opt_masks): Likewise.
(rs6000_function_specific_save): Likewise.
(rs6000_function_specific_restore): Likewise.
* config/rs6000/rs6000.h (ASM_CPU_SPEC): If -mcpu=future, pass 
-mfuture
to the assembler.
(TARGET_FUTURE): New macro.

gcc/testsuite/

* gcc.target/powerpc/future-1.c: New test.
* gcc.target/powerpc/future-2.c: Likewise.

Diff:
---
 gcc/config/rs6000/aix71.h   |  1 +
 gcc/config/rs6000/aix72.h   |  1 +
 gcc/config/rs6000/aix73.h   |  1 +
 gcc/config/rs6000/rs6000-c.cc   |  2 ++
 gcc/config/rs6000/rs6000-cpus.def   | 14 ++
 gcc/config/rs6000/rs6000-tables.opt | 11 +++
 gcc/config/rs6000/rs6000.cc |  5 -
 gcc/config/rs6000/rs6000.h  |  6 ++
 gcc/testsuite/gcc.target/powerpc/future-1.c | 13 +
 gcc/testsuite/gcc.target/powerpc/future-2.c | 24 
 10 files changed, 73 insertions(+), 5 deletions(-)

diff --git a/gcc/config/rs6000/aix71.h b/gcc/config/rs6000/aix71.h
index 5423252f7688..7c437be201ec 100644
--- a/gcc/config/rs6000/aix71.h
+++ b/gcc/config/rs6000/aix71.h
@@ -79,6 +79,7 @@ do {  
\
 #undef ASM_CPU_SPEC
 #define ASM_CPU_SPEC \
 "%{mcpu=native: %(asm_cpu_native); \
+  mcpu=future: -mfuture; \
   mcpu=power11: -mpwr11; \
   mcpu=power10: -mpwr10; \
   mcpu=power9: -mpwr9; \
diff --git a/gcc/config/rs6000/aix72.h b/gcc/config/rs6000/aix72.h
index fdddc4327963..bab23491debc 100644
--- a/gcc/config/rs6000/aix72.h
+++ b/gcc/config/rs6000/aix72.h
@@ -79,6 +79,7 @@ do {  
\
 #undef ASM_CPU_SPEC
 #define ASM_CPU_SPEC \
 "%{mcpu=native: %(asm_cpu_native); \
+  mcpu=future: -mfuture; \
   mcpu=power11: -mpwr11; \
   mcpu=power10: -mpwr10; \
   mcpu=power9: -mpwr9; \
diff --git a/gcc/config/rs6000/aix73.h b/gcc/config/rs6000/aix73.h
index 37c2c081c34a..bcf236665604 100644
--- a/gcc/config/rs6000/aix73.h
+++ b/gcc/config/rs6000/aix73.h
@@ -79,6 +79,7 @@ do {  
\
 #undef ASM_CPU_SPEC
 #define ASM_CPU_SPEC \
 "%{mcpu=native: %(asm_cpu_native); \
+  mcpu=future: -mfuture; \
   mcpu=power11: -mpwr11; \
   mcpu=power10: -mpwr10; \
   mcpu=power9: -mpwr9; \
diff --git a/gcc/config/rs6000/rs6000-c.cc b/gcc/config/rs6000/rs6000-c.cc
index 823531d5e5a7..0261f672ef21 100644
--- a/gcc/config/rs6000/rs6000-c.cc
+++ b/gcc/config/rs6000/rs6000-c.cc
@@ -440,6 +440,8 @@ rs6000_target_modify_macros (bool define_p,
 rs6000_define_or_undefine_macro (define_p, "_ARCH_PWR10");
   if ((flags & OPTION_MASK_POWER11) != 0)
 rs6000_define_or_undefine_macro (define_p, "_ARCH_PWR11");
+  if ((cpu_option & CPU_OPTION_FUTURE_MASK) != 0)
+rs6000_define_or_undefine_macro (define_p, "_ARCH_FUTURE");
   if ((flags & OPTION_MASK_SOFT_FLOAT) != 0)
 rs6000_define_or_undefine_macro (define_p, "_SOFT_FLOAT");
   if ((flags & OPTION_MASK_RECIP_PRECISION) != 0)
diff --git a/gcc/config/rs6000/rs6000-cpus.def 
b/gcc/config/rs6000/rs6000-cpus.def
index 9de97cb9c6bd..0d88f12520c8 100644
--- a/gcc/config/rs6000/rs6000-cpus.def
+++ b/gcc/config/rs6000/rs6000-cpus.def
@@ -125,6 +125,10 @@
 #define POWER11_MASKS_SERVER (ISA_3_1_MASKS_SERVER \
  | OPTION_MASK_POWER11)
 
+/* At the moment, do not define any addition -m arguments for -mcpu=future
+   support.  */
+#define FUTURE_MASKS_SERVER  POWER11_MASKS_SERVER
+
 /* Flags that need to be turned off if -mno-vsx.  */
 #define OTHER_VSX_VECTOR_MASKS (OPTION_MASK_EFFICIENT_UNALIGNED_VSX\
 | OPTION_MASK_FLOAT128_KEYWORD \
@@ -200,6 +204,7 @@
 #define CPU_OPTION_POWER9_MASK HOST_WIDE_INT_UC (0x0004)
 #define CP

[gcc(refs/users/meissner/heads/work222)] Add cpu option flag bits

2025-09-20 Thread Michael Meissner via Gcc-cvs
https://gcc.gnu.org/g:50b297dbde4917c1cca931ac3b289fb83255b994

commit 50b297dbde4917c1cca931ac3b289fb83255b994
Author: Michael Meissner 
Date:   Sun Sep 21 02:06:44 2025 -0400

Add cpu option flag bits

2025-09-21  Michael Meissner  

gcc/

* config/rs6000/aix71.h (RS6000_CPU_OPTION): Define and undefine 
macro.
* config/rs6000/aix72.h (RS6000_CPU_OPTION): Likewise.
* config/rs6000/aix73.h (RS6000_CPU_OPTION): Likewise.
* config/rs6000/default64.h (RS6000_CPU_OPTION): Likewise.
* config/rs6000/driver-rs6000.cc (RS6000_CPU_OPTION): Likewise.
* config/rs6000/rs6000-c.cc (rs6000_target_modify_macros): Add CPU
options parameter.
(rs6000_cpu_cpp_builtins): Likewise.
* config/rs6000/rs6000-cpus.def (toplevel): Add comment describing 
ISA
mask bits and CPU option mask bits.
(CPU_OPTION_POWER7_MASK): New macro.
(CPU_OPTION_POWER8_MASK): Likewise.
(CPU_OPTION_POWER9_MASK): Likewise.
(CPU_OPTION_POWER10_MASK): Likewise.
(CPU_OPTION_POWER11_MASK): Likewise.
(CPU_OPTION_POWER7_ALL_MASKS): Likewise.
(CPU_OPTION_POWER8_ALL_MASKS): Likewise.
(CPU_OPTION_POWER9_ALL_MASKS): Likewise.
(CPU_OPTION_POWER10_ALL_MASKS): Likewise.
(CPU_OPTION_POWER11_ALL_MASKS): Likewise.
(power7 cpu): Switch to use RS6000_CPU_OPTION in order to set the 
CPU
option mask bits.
(power8): Likewise.
(power9): Likewise.
(power10): Likewise.
(power11): Likewise.
* config/rs6000/rs6000-protos.h (rs6000_target_modify_macros): Add 
CPU
option argument.
(rs6000_target_modify_macros_ptr): Likewise.
* config/rs6000/rs6000.cc (rs6000_target_modify_macros_ptr): 
Likewise.
(rs6000_print_isa_options): Likewise.
(struct rs6000_ptt): Likewise.
(RS6000_CPU): Likewise.
(RS6000_CPU_OPTION): Likewise.
(DEBUG_FMT_WX): Likewise.
(rs6000_debug_reg_global): Likewise.
(rs6000_option_override_internal): Likewise.
(struct rs6000_cpu_opt_mask): Likewise.
(rs6000_cpu_opt_masks): Likewise.
(rs6000_pragma_target_parse): Likewise.
(rs6000_function_specific_save): Likewise.
(rs6000_function_specific_restore): Likewise.
(rs6000_function_specific_print): Likewise.
(rs6000_print_options_internal): Likewise.
* config/rs6000/rs6000.opt (rs6000_cpu_option_flags): New target
variable.
(x_rs6000_cpu_option_flags): Likewise.

Diff:
---
 gcc/config/rs6000/aix71.h  |   2 +
 gcc/config/rs6000/aix72.h  |   2 +
 gcc/config/rs6000/aix73.h  |   2 +
 gcc/config/rs6000/default64.h  |   2 +
 gcc/config/rs6000/driver-rs6000.cc |   2 +
 gcc/config/rs6000/rs6000-c.cc  |  12 ++--
 gcc/config/rs6000/rs6000-cpus.def  |  99 +---
 gcc/config/rs6000/rs6000-protos.h  |   5 +-
 gcc/config/rs6000/rs6000.cc| 129 -
 gcc/config/rs6000/rs6000.opt   |   9 +++
 10 files changed, 219 insertions(+), 45 deletions(-)

diff --git a/gcc/config/rs6000/aix71.h b/gcc/config/rs6000/aix71.h
index 2b21dd7cd1e0..5423252f7688 100644
--- a/gcc/config/rs6000/aix71.h
+++ b/gcc/config/rs6000/aix71.h
@@ -133,8 +133,10 @@ do {   
\
%{pthread: -D_THREAD_SAFE}"
 
 #define RS6000_CPU(NAME, CPU, FLAGS)
+#define RS6000_CPU_OPTION(NAME, CPU, FLAGS, CPU_OPTION)
 #include "rs6000-cpus.def"
 #undef RS6000_CPU
+#undef RS6000_CPU_OPTION
 
 #undef  TARGET_DEFAULT
 #ifdef RS6000_BI_ARCH
diff --git a/gcc/config/rs6000/aix72.h b/gcc/config/rs6000/aix72.h
index 53c0bde5ad4a..fdddc4327963 100644
--- a/gcc/config/rs6000/aix72.h
+++ b/gcc/config/rs6000/aix72.h
@@ -134,8 +134,10 @@ do {   
\
%{pthread: -D_THREAD_SAFE}"
 
 #define RS6000_CPU(NAME, CPU, FLAGS)
+#define RS6000_CPU_OPTION(NAME, CPU, FLAGS, CPU_OPTION)
 #include "rs6000-cpus.def"
 #undef RS6000_CPU
+#undef RS6000_CPU_OPTION
 
 #undef  TARGET_DEFAULT
 #ifdef RS6000_BI_ARCH
diff --git a/gcc/config/rs6000/aix73.h b/gcc/config/rs6000/aix73.h
index c7639368a264..37c2c081c34a 100644
--- a/gcc/config/rs6000/aix73.h
+++ b/gcc/config/rs6000/aix73.h
@@ -135,8 +135,10 @@ do {   
\
%{pthread: -D_THREAD_SAFE}"
 
 #define RS6000_CPU(NAME, CPU, FLAGS)
+#define RS6000_CPU_OPTION(NAME, CPU, FLAGS, CPU_OPTION)
 #include "rs6000-cpus.def"
 #undef RS6000_CPU
+#undef RS6000_CPU_OPTION
 
 #undef  TARGET_DEFAULT
 #ifdef RS6000_BI_ARCH
diff --git a/gcc/config/rs6000/default64.h b/gcc/config/rs6000/default64.h
index 7f6001ded8

[gcc(refs/users/meissner/heads/work222)] Revert changes

2025-09-20 Thread Michael Meissner via Gcc-cvs
https://gcc.gnu.org/g:971476ce7ba3f825a6661d2015045cb982a9c1db

commit 971476ce7ba3f825a6661d2015045cb982a9c1db
Author: Michael Meissner 
Date:   Sun Sep 21 01:59:06 2025 -0400

Revert changes

Diff:
---
 gcc/config/rs6000/aix71.h   |   3 -
 gcc/config/rs6000/aix72.h   |   3 -
 gcc/config/rs6000/aix73.h   |   3 -
 gcc/config/rs6000/default64.h   |   2 -
 gcc/config/rs6000/driver-rs6000.cc  |   2 -
 gcc/config/rs6000/rs6000-c.cc   |  14 +--
 gcc/config/rs6000/rs6000-cpus.def   | 113 +++-
 gcc/config/rs6000/rs6000-protos.h   |   5 +-
 gcc/config/rs6000/rs6000-tables.opt |  11 +--
 gcc/config/rs6000/rs6000.cc | 132 +++-
 gcc/config/rs6000/rs6000.h  |   6 --
 gcc/config/rs6000/rs6000.opt|   9 --
 gcc/testsuite/gcc.target/powerpc/future-1.c |  13 ---
 gcc/testsuite/gcc.target/powerpc/future-2.c |  24 -
 14 files changed, 50 insertions(+), 290 deletions(-)

diff --git a/gcc/config/rs6000/aix71.h b/gcc/config/rs6000/aix71.h
index 7c437be201ec..2b21dd7cd1e0 100644
--- a/gcc/config/rs6000/aix71.h
+++ b/gcc/config/rs6000/aix71.h
@@ -79,7 +79,6 @@ do {  
\
 #undef ASM_CPU_SPEC
 #define ASM_CPU_SPEC \
 "%{mcpu=native: %(asm_cpu_native); \
-  mcpu=future: -mfuture; \
   mcpu=power11: -mpwr11; \
   mcpu=power10: -mpwr10; \
   mcpu=power9: -mpwr9; \
@@ -134,10 +133,8 @@ do {   
\
%{pthread: -D_THREAD_SAFE}"
 
 #define RS6000_CPU(NAME, CPU, FLAGS)
-#define RS6000_CPU_OPTION(NAME, CPU, FLAGS, CPU_OPTION)
 #include "rs6000-cpus.def"
 #undef RS6000_CPU
-#undef RS6000_CPU_OPTION
 
 #undef  TARGET_DEFAULT
 #ifdef RS6000_BI_ARCH
diff --git a/gcc/config/rs6000/aix72.h b/gcc/config/rs6000/aix72.h
index bab23491debc..53c0bde5ad4a 100644
--- a/gcc/config/rs6000/aix72.h
+++ b/gcc/config/rs6000/aix72.h
@@ -79,7 +79,6 @@ do {  
\
 #undef ASM_CPU_SPEC
 #define ASM_CPU_SPEC \
 "%{mcpu=native: %(asm_cpu_native); \
-  mcpu=future: -mfuture; \
   mcpu=power11: -mpwr11; \
   mcpu=power10: -mpwr10; \
   mcpu=power9: -mpwr9; \
@@ -135,10 +134,8 @@ do {   
\
%{pthread: -D_THREAD_SAFE}"
 
 #define RS6000_CPU(NAME, CPU, FLAGS)
-#define RS6000_CPU_OPTION(NAME, CPU, FLAGS, CPU_OPTION)
 #include "rs6000-cpus.def"
 #undef RS6000_CPU
-#undef RS6000_CPU_OPTION
 
 #undef  TARGET_DEFAULT
 #ifdef RS6000_BI_ARCH
diff --git a/gcc/config/rs6000/aix73.h b/gcc/config/rs6000/aix73.h
index bcf236665604..c7639368a264 100644
--- a/gcc/config/rs6000/aix73.h
+++ b/gcc/config/rs6000/aix73.h
@@ -79,7 +79,6 @@ do {  
\
 #undef ASM_CPU_SPEC
 #define ASM_CPU_SPEC \
 "%{mcpu=native: %(asm_cpu_native); \
-  mcpu=future: -mfuture; \
   mcpu=power11: -mpwr11; \
   mcpu=power10: -mpwr10; \
   mcpu=power9: -mpwr9; \
@@ -136,10 +135,8 @@ do {   
\
%{pthread: -D_THREAD_SAFE}"
 
 #define RS6000_CPU(NAME, CPU, FLAGS)
-#define RS6000_CPU_OPTION(NAME, CPU, FLAGS, CPU_OPTION)
 #include "rs6000-cpus.def"
 #undef RS6000_CPU
-#undef RS6000_CPU_OPTION
 
 #undef  TARGET_DEFAULT
 #ifdef RS6000_BI_ARCH
diff --git a/gcc/config/rs6000/default64.h b/gcc/config/rs6000/default64.h
index d289c6dfd6d8..7f6001ded852 100644
--- a/gcc/config/rs6000/default64.h
+++ b/gcc/config/rs6000/default64.h
@@ -19,10 +19,8 @@ along with GCC; see the file COPYING3.  If not see
 .  */
 
 #define RS6000_CPU(NAME, CPU, FLAGS)
-#define RS6000_CPU_OPTION(NAME, CPU, FLAGS, CPU_OPTION)
 #include "rs6000-cpus.def"
 #undef RS6000_CPU
-#undef RS6000_CPU_OPTION
 
 #if (TARGET_DEFAULT & MASK_LITTLE_ENDIAN)
 #undef TARGET_DEFAULT
diff --git a/gcc/config/rs6000/driver-rs6000.cc 
b/gcc/config/rs6000/driver-rs6000.cc
index cacf25e9dfa4..2ab675e6d042 100644
--- a/gcc/config/rs6000/driver-rs6000.cc
+++ b/gcc/config/rs6000/driver-rs6000.cc
@@ -45,10 +45,8 @@ along with GCC; see the file COPYING3.  If not see
 static const char *rs6000_supported_cpu_names[] =
 {
 #define RS6000_CPU(NAME, CPU, FLAGS) NAME,
-#define RS6000_CPU_OPTION(NAME, CPU, FLAGS, CPU_OPTION)NAME,
 #include "rs6000-cpus.def"
 #undef RS6000_CPU
-#undef RS6000_CPU_OPTION
 };
 
 /* This table holds a list of cpus where their Linux AT_PLATFORM name differs
diff --git a/gcc/config/rs6000/rs6000-c.cc b/gcc/config/rs6000/rs6000-c.cc
index 0261f672ef21..d3b0a5668212 100644
--- a/gcc/config/rs6000/rs6000-c.cc
+++ b/gcc/config/rs6000/rs6000-c.cc
@@ -338,16 +338,13 @@ rs6000_define_or_undefine_macro (bool define_p, const 
char *name)
#pragma GCC target, we need to adjust the macros dynamically.  */
 
 void
-rs6000_target_modify_macr

[gcc(refs/users/meissner/heads/work222)] Add -mcpu=future support.

2025-09-20 Thread Michael Meissner via Gcc-cvs
https://gcc.gnu.org/g:960e882b900e3368d93e29d6d6cb5f3dcc63d120

commit 960e882b900e3368d93e29d6d6cb5f3dcc63d120
Author: Michael Meissner 
Date:   Sun Sep 21 02:08:34 2025 -0400

Add -mcpu=future support.

2025-09-21  Michael Meissner  

gcc/

* config/rs6000/aix71.h (ASM_CPU_SPEC): If -mcpu=future, pass 
-mfuture
to the assembler.
* config/rs6000/aix72.h (ASM_CPU_SPEC): Likewise.
* config/rs6000/aix73.h (ASM_CPU_SPEC): Likewise.
* config/rs6000/rs6000.c.cc (rs6000_target_modify_macros): If
-mcpu=future define _ARCH_FUTURE.
* config/rs6000/rs6000-cpus.def (CPU_OPTION_FUTURE_MASK): Add 
support
for -mcpu=future.
(CPU_OPTION_FUTURE_ALL_MASKS): Likewise.
(future cpu): Likewise.
* config/rs6000/rs6000-tables.opt: Regenerate.
* config/rs6000/rs6000.cc (power10_cost): Update comment.
(rs6000_machine_from_flags): Add support for -mcpu=future.
(rs6000_cpu_opt_masks): Likewise.
* config/rs6000/rs6000.h (ASM_CPU_SPEC): If -mcpu=future, pass 
-mfuture
to the assembler.
(TARGET_FUTURE): New macro.

gcc/testsuite/

* gcc.target/powerpc/future-1.c: New test.
* gcc.target/powerpc/future-2.c: Likewise.

Diff:
---
 gcc/config/rs6000/aix71.h   |  1 +
 gcc/config/rs6000/aix72.h   |  1 +
 gcc/config/rs6000/aix73.h   |  1 +
 gcc/config/rs6000/rs6000-c.cc   |  2 ++
 gcc/config/rs6000/rs6000-cpus.def   | 14 ++
 gcc/config/rs6000/rs6000-tables.opt | 11 +++
 gcc/config/rs6000/rs6000.cc |  5 -
 gcc/config/rs6000/rs6000.h  |  6 ++
 gcc/testsuite/gcc.target/powerpc/future-1.c | 13 +
 gcc/testsuite/gcc.target/powerpc/future-2.c | 24 
 10 files changed, 73 insertions(+), 5 deletions(-)

diff --git a/gcc/config/rs6000/aix71.h b/gcc/config/rs6000/aix71.h
index 5423252f7688..7c437be201ec 100644
--- a/gcc/config/rs6000/aix71.h
+++ b/gcc/config/rs6000/aix71.h
@@ -79,6 +79,7 @@ do {  
\
 #undef ASM_CPU_SPEC
 #define ASM_CPU_SPEC \
 "%{mcpu=native: %(asm_cpu_native); \
+  mcpu=future: -mfuture; \
   mcpu=power11: -mpwr11; \
   mcpu=power10: -mpwr10; \
   mcpu=power9: -mpwr9; \
diff --git a/gcc/config/rs6000/aix72.h b/gcc/config/rs6000/aix72.h
index fdddc4327963..bab23491debc 100644
--- a/gcc/config/rs6000/aix72.h
+++ b/gcc/config/rs6000/aix72.h
@@ -79,6 +79,7 @@ do {  
\
 #undef ASM_CPU_SPEC
 #define ASM_CPU_SPEC \
 "%{mcpu=native: %(asm_cpu_native); \
+  mcpu=future: -mfuture; \
   mcpu=power11: -mpwr11; \
   mcpu=power10: -mpwr10; \
   mcpu=power9: -mpwr9; \
diff --git a/gcc/config/rs6000/aix73.h b/gcc/config/rs6000/aix73.h
index 37c2c081c34a..bcf236665604 100644
--- a/gcc/config/rs6000/aix73.h
+++ b/gcc/config/rs6000/aix73.h
@@ -79,6 +79,7 @@ do {  
\
 #undef ASM_CPU_SPEC
 #define ASM_CPU_SPEC \
 "%{mcpu=native: %(asm_cpu_native); \
+  mcpu=future: -mfuture; \
   mcpu=power11: -mpwr11; \
   mcpu=power10: -mpwr10; \
   mcpu=power9: -mpwr9; \
diff --git a/gcc/config/rs6000/rs6000-c.cc b/gcc/config/rs6000/rs6000-c.cc
index 823531d5e5a7..0261f672ef21 100644
--- a/gcc/config/rs6000/rs6000-c.cc
+++ b/gcc/config/rs6000/rs6000-c.cc
@@ -440,6 +440,8 @@ rs6000_target_modify_macros (bool define_p,
 rs6000_define_or_undefine_macro (define_p, "_ARCH_PWR10");
   if ((flags & OPTION_MASK_POWER11) != 0)
 rs6000_define_or_undefine_macro (define_p, "_ARCH_PWR11");
+  if ((cpu_option & CPU_OPTION_FUTURE_MASK) != 0)
+rs6000_define_or_undefine_macro (define_p, "_ARCH_FUTURE");
   if ((flags & OPTION_MASK_SOFT_FLOAT) != 0)
 rs6000_define_or_undefine_macro (define_p, "_SOFT_FLOAT");
   if ((flags & OPTION_MASK_RECIP_PRECISION) != 0)
diff --git a/gcc/config/rs6000/rs6000-cpus.def 
b/gcc/config/rs6000/rs6000-cpus.def
index 9de97cb9c6bd..0d88f12520c8 100644
--- a/gcc/config/rs6000/rs6000-cpus.def
+++ b/gcc/config/rs6000/rs6000-cpus.def
@@ -125,6 +125,10 @@
 #define POWER11_MASKS_SERVER (ISA_3_1_MASKS_SERVER \
  | OPTION_MASK_POWER11)
 
+/* At the moment, do not define any addition -m arguments for -mcpu=future
+   support.  */
+#define FUTURE_MASKS_SERVER  POWER11_MASKS_SERVER
+
 /* Flags that need to be turned off if -mno-vsx.  */
 #define OTHER_VSX_VECTOR_MASKS (OPTION_MASK_EFFICIENT_UNALIGNED_VSX\
 | OPTION_MASK_FLOAT128_KEYWORD \
@@ -200,6 +204,7 @@
 #define CPU_OPTION_POWER9_MASK HOST_WIDE_INT_UC (0x0004)
 #define CPU_OPTION_POWER10_MASKHOST_WIDE_INT_UC (0x0008)
 #define CPU_OPTION_POWER11_MASK  

[gcc(refs/users/meissner/heads/work222)] Update ChangeLog.*

2025-09-20 Thread Michael Meissner via Gcc-cvs
https://gcc.gnu.org/g:c43ecbc7e6703de2e401eddb7aefb4419682eab3

commit c43ecbc7e6703de2e401eddb7aefb4419682eab3
Author: Michael Meissner 
Date:   Sun Sep 21 02:46:27 2025 -0400

Update ChangeLog.*

Diff:
---
 gcc/ChangeLog.meissner | 18 ++
 1 file changed, 18 insertions(+)

diff --git a/gcc/ChangeLog.meissner b/gcc/ChangeLog.meissner
index c58ac5f1ee7f..10c5fde68a0f 100644
--- a/gcc/ChangeLog.meissner
+++ b/gcc/ChangeLog.meissner
@@ -1,3 +1,21 @@
+ Branch work222, patch #3 
+
+Remove internal -mpower11 support.
+
+2025-09-21  Michael Meissner  
+
+gcc/
+
+   * config/rs6000/rs6000-c.cc (rs6000_target_modify_macros): Move power11
+   support to use CPU options.
+   * config/rs6000/rs6000-cpus.def (POWER11_MASKS_SERVER): Likewise.
+   (POWERPC_MASKS): Likewise.
+   * config/rs6000/rs6000.cc (rs6000_machine_from_flags): Likewise.
+   (rs6000_opt_masks): Likewise.
+   * config/rs6000/rs6000.h (TARGET_POWER11): New macro.
+   * config/rs6000/rs6000.opt (-mpower11): Drop power11 from being an ISA
+   option.
+
  Branch work222, patch #2 
 
 Add -mcpu=future support.


[gcc(refs/users/meissner/heads/work222)] Remove internal -mpower11 support.

2025-09-20 Thread Michael Meissner via Gcc-cvs
https://gcc.gnu.org/g:f70de710bb95f56dd02ed623e9a93424eaa34b3f

commit f70de710bb95f56dd02ed623e9a93424eaa34b3f
Author: Michael Meissner 
Date:   Sun Sep 21 02:45:27 2025 -0400

Remove internal -mpower11 support.

2025-09-21  Michael Meissner  

gcc/

* config/rs6000/rs6000-c.cc (rs6000_target_modify_macros): Move 
power11
support to use CPU options.
* config/rs6000/rs6000-cpus.def (POWER11_MASKS_SERVER): Likewise.
(POWERPC_MASKS): Likewise.
* config/rs6000/rs6000.cc (rs6000_machine_from_flags): Likewise.
(rs6000_opt_masks): Likewise.
* config/rs6000/rs6000.h (TARGET_POWER11): New macro.
* config/rs6000/rs6000.opt (-mpower11): Drop power11 from being an 
ISA
option.

Diff:
---
 gcc/config/rs6000/rs6000-c.cc | 2 +-
 gcc/config/rs6000/rs6000-cpus.def | 4 +---
 gcc/config/rs6000/rs6000.cc   | 3 +--
 gcc/config/rs6000/rs6000.h| 2 ++
 gcc/config/rs6000/rs6000.opt  | 5 +
 5 files changed, 6 insertions(+), 10 deletions(-)

diff --git a/gcc/config/rs6000/rs6000-c.cc b/gcc/config/rs6000/rs6000-c.cc
index 0261f672ef21..2e6713dee5d6 100644
--- a/gcc/config/rs6000/rs6000-c.cc
+++ b/gcc/config/rs6000/rs6000-c.cc
@@ -438,7 +438,7 @@ rs6000_target_modify_macros (bool define_p,
 rs6000_define_or_undefine_macro (define_p, "_ARCH_PWR9");
   if ((flags & OPTION_MASK_POWER10) != 0)
 rs6000_define_or_undefine_macro (define_p, "_ARCH_PWR10");
-  if ((flags & OPTION_MASK_POWER11) != 0)
+  if ((cpu_option & CPU_OPTION_POWER11_MASK) != 0)
 rs6000_define_or_undefine_macro (define_p, "_ARCH_PWR11");
   if ((cpu_option & CPU_OPTION_FUTURE_MASK) != 0)
 rs6000_define_or_undefine_macro (define_p, "_ARCH_FUTURE");
diff --git a/gcc/config/rs6000/rs6000-cpus.def 
b/gcc/config/rs6000/rs6000-cpus.def
index 0d88f12520c8..fc133ed11851 100644
--- a/gcc/config/rs6000/rs6000-cpus.def
+++ b/gcc/config/rs6000/rs6000-cpus.def
@@ -122,8 +122,7 @@
 | OPTION_MASK_POWER10  \
 | OTHER_POWER10_MASKS)
 
-#define POWER11_MASKS_SERVER (ISA_3_1_MASKS_SERVER \
- | OPTION_MASK_POWER11)
+#define POWER11_MASKS_SERVER   ISA_3_1_MASKS_SERVER
 
 /* At the moment, do not define any addition -m arguments for -mcpu=future
support.  */
@@ -166,7 +165,6 @@
 | OPTION_MASK_FLOAT128_KEYWORD \
 | OPTION_MASK_FPRND\
 | OPTION_MASK_POWER10  \
-| OPTION_MASK_POWER11  \
 | OPTION_MASK_P10_FUSION   \
 | OPTION_MASK_HTM  \
 | OPTION_MASK_ISEL \
diff --git a/gcc/config/rs6000/rs6000.cc b/gcc/config/rs6000/rs6000.cc
index 296aa8bc1f3e..1d4f87161e16 100644
--- a/gcc/config/rs6000/rs6000.cc
+++ b/gcc/config/rs6000/rs6000.cc
@@ -5931,7 +5931,7 @@ rs6000_machine_from_flags (void)
 
   if ((rs6000_cpu_option_flags & CPU_OPTION_FUTURE_MASK) != 0)
 return "future";
-  if ((flags & (POWER11_MASKS_SERVER & ~ISA_3_1_MASKS_SERVER)) != 0)
+  if ((rs6000_cpu_option_flags & CPU_OPTION_POWER11_MASK) != 0)
 return "power11";
   if ((flags & (ISA_3_1_MASKS_SERVER & ~ISA_3_0_MASKS_SERVER)) != 0)
 return "power10";
@@ -24482,7 +24482,6 @@ static struct rs6000_opt_mask const rs6000_opt_masks[] =
   { "float128-hardware",   OPTION_MASK_FLOAT128_HW,false, true  },
   { "fprnd",   OPTION_MASK_FPRND,  false, true  },
   { "power10", OPTION_MASK_POWER10,false, true  },
-  { "power11", OPTION_MASK_POWER11,false, false },
   { "hard-dfp",OPTION_MASK_DFP,false, 
true  },
   { "htm", OPTION_MASK_HTM,false, true  },
   { "isel",OPTION_MASK_ISEL,   false, true  },
diff --git a/gcc/config/rs6000/rs6000.h b/gcc/config/rs6000/rs6000.h
index bcee3e025822..78c674b1e05d 100644
--- a/gcc/config/rs6000/rs6000.h
+++ b/gcc/config/rs6000/rs6000.h
@@ -558,6 +558,8 @@ extern int rs6000_vector_align[];
 
 /* ISA bits that are set via -mcpu=, but that do not have an associated
switch with the option.  */
+#define TARGET_POWER11 \
+  ((rs6000_cpu_option_flags & CPU_OPTION_POWER11_MASK) != 0)
 #define TARGET_FUTURE  \
   ((rs6000_cpu_option_flags & CPU_OPTION_FUTURE_MASK) != 0)
 
diff --git a/gcc/config/rs6000/rs6000.opt b/gcc/config/rs6000/rs6000.opt
index 7c9602e68211..fb323beff9b4 100644
--- a/gcc/config/rs6000/rs6000.opt
+++ b/gcc/config/rs6000/rs6000.opt
@@ -598,11 +598,8 @@ Target Undoc

[gcc(refs/users/mikael/heads/refactor_descriptor_v08)] Refactor set_dimension_fields descriptor_init_count

2025-09-20 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:a54c389f9eac340ac6683595903a1de9e4b35b6e

commit a54c389f9eac340ac6683595903a1de9e4b35b6e
Author: Mikael Morin 
Date:   Sat Aug 16 19:16:15 2025 +0200

Refactor set_dimension_fields descriptor_init_count

Correction régression class_allocate_22

Ajout scan tree var

Correction dumps coarray_12

Diff:
---
 gcc/fortran/trans-descriptor.cc  | 18 +++-
 gcc/testsuite/gfortran.dg/coarray_12.f90 |  3 +-
 gcc/testsuite/lib/scandump.exp   | 50 
 gcc/testsuite/lib/scantree.exp   | 26 +
 4 files changed, 82 insertions(+), 15 deletions(-)

diff --git a/gcc/fortran/trans-descriptor.cc b/gcc/fortran/trans-descriptor.cc
index 071840f0e871..1b08120e74a3 100644
--- a/gcc/fortran/trans-descriptor.cc
+++ b/gcc/fortran/trans-descriptor.cc
@@ -2816,15 +2816,8 @@ gfc_descriptor_init_count (tree descriptor, int rank, 
int corank,
  ubound = lower[n];
}
}
-  gfc_conv_descriptor_lbound_set (descriptor_block, descriptor,
- gfc_rank_cst[n], se.expr);
   conv_lbound = se.expr;
-
-  /* Work out the offset for this component.  */
-  tmp = fold_build2_loc (input_location, MULT_EXPR, gfc_array_index_type,
-se.expr, stride);
-  offset = fold_build2_loc (input_location, MINUS_EXPR,
-   gfc_array_index_type, offset, tmp);
+  conv_lbound = gfc_evaluate_now (conv_lbound, pblock);
 
   /* Set upper bound.  */
   gfc_init_se (&se, NULL);
@@ -2860,13 +2853,11 @@ gfc_descriptor_init_count (tree descriptor, int rank, 
int corank,
  if (ubound->expr_type == EXPR_FUNCTION)
se.expr = gfc_evaluate_now (se.expr, pblock);
}
-  gfc_conv_descriptor_ubound_set (descriptor_block, descriptor,
- gfc_rank_cst[n], se.expr);
   conv_ubound = se.expr;
+  conv_ubound = gfc_evaluate_now (conv_ubound, pblock);
 
-  /* Store the stride.  */
-  gfc_conv_descriptor_stride_set (descriptor_block, descriptor,
- gfc_rank_cst[n], stride);
+  set_dimension_fields (descriptor_block, descriptor, gfc_rank_cst[n],
+   conv_lbound, conv_ubound, stride, &offset);
 
   /* Calculate size and check whether extent is negative.  */
   size = gfc_conv_array_extent_dim (conv_lbound, conv_ubound, &empty_cond);
@@ -2950,7 +2941,6 @@ gfc_descriptor_init_count (tree descriptor, int rank, int 
corank,
 return gfc_index_one_node;
 
   /* Update the array descriptor with the offset and the span.  */
-  offset = gfc_evaluate_now (offset, pblock);
   gfc_conv_descriptor_offset_set (descriptor_block, descriptor, offset);
   tmp = fold_convert (gfc_array_index_type, element_size);
   gfc_conv_descriptor_span_set (descriptor_block, descriptor, tmp);
diff --git a/gcc/testsuite/gfortran.dg/coarray_12.f90 
b/gcc/testsuite/gfortran.dg/coarray_12.f90
index 70efaaff5160..9bbb9e3a3035 100644
--- a/gcc/testsuite/gfortran.dg/coarray_12.f90
+++ b/gcc/testsuite/gfortran.dg/coarray_12.f90
@@ -46,7 +46,8 @@ end subroutine testAlloc5
 
 
 ! { dg-final { scan-tree-dump-times "a.dim.0..lbound = 1;" 1 "original" } }
-! { dg-final { scan-tree-dump-times "a.dim.0..ubound = .*nn;" 1 "original" } }
+! { dg-final { global ubound_value; scan-tree-dump-var {a\.dim\[0\]\.ubound = 
(D\.\d+);} "original" "ubound_value" } }
+! { dg-final { global ubound_value; scan-tree-dump-times "$ubound_value = 
.*nn;" 1 "original" } }
 ! { dg-final { scan-tree-dump-times "a.dim.1..lbound = 1;" 1 "original" } }
 ! { dg-final { scan-tree-dump-times "a.dim.1..ubound = .*mm;" 1 "original" } }
 ! { dg-final { scan-tree-dump-times "a.dim.2..lbound = 1;" 1 "original" } }
diff --git a/gcc/testsuite/lib/scandump.exp b/gcc/testsuite/lib/scandump.exp
index a8441daa22fa..74a77f0a57e1 100644
--- a/gcc/testsuite/lib/scandump.exp
+++ b/gcc/testsuite/lib/scandump.exp
@@ -214,6 +214,56 @@ proc scan-dump-not { args } {
 }
 }
 
+# Utility for scanning compiler result, invoked via dg-final.
+# Call pass if pattern is present, otherwise fail.
+#
+# Argument 0 is the type of dump we are searching (rtl, tree, ipa)
+# Argument 1 is the regexp to match.
+# Argument 2 is the suffix for the dump file
+# Argument 3 is the suffix of the dump base
+# Argument 4 is the variable name to store the matched content
+# Argument 5 handles expected failures and the like
+proc scan-dump-var { args } {
+
+if { [llength $args] >= 6 } {
+switch [dg-process-target [lindex $args 5]] {
+"S" { }
+"N" { return }
+"F" { setup_xfail "*-*-*" }
+"P" { }
+}
+}
+
+set testcase [testname-for-summary]
+# The name might include a list of options; extract the file name.
+set filename [lindex $testcase 0]
+
+set printable_pattern [make_pattern_printable [li

[gcc/meissner/heads/work221-float] (4 commits) Merge commit 'refs/users/meissner/heads/work221-float' of g

2025-09-20 Thread Michael Meissner via Gcc-cvs
The branch 'meissner/heads/work221-float' was updated to point to:

 a47411498b20... Merge commit 'refs/users/meissner/heads/work221-float' of g

It previously pointed to:

 4bda7271f24c... Add ChangeLog.float and update REVISION.

Diff:

Summary of changes (added commits):
---

  a474114... Merge commit 'refs/users/meissner/heads/work221-float' of g
  2f69257... Add ChangeLog.float and update REVISION.
  ef08919... Update ChangeLog.* (*)
  e81e8b3... Add support for -mcpu=future (*)

(*) This commit already exists in another branch.
Because the reference `refs/users/meissner/heads/work221-float' matches
your hooks.email-new-commits-only configuration,
no separate email is sent for this commit.


[gcc(refs/users/meissner/heads/work221-float)] Update ChangeLog.*

2025-09-20 Thread Michael Meissner via Gcc-cvs
https://gcc.gnu.org/g:0a69ad10fc41883c7543a908d54b07ae62e5b5ad

commit 0a69ad10fc41883c7543a908d54b07ae62e5b5ad
Author: Michael Meissner 
Date:   Mon Sep 8 23:31:36 2025 -0400

Update ChangeLog.*

Diff:
---
 gcc/ChangeLog.float | 16 
 1 file changed, 16 insertions(+)

diff --git a/gcc/ChangeLog.float b/gcc/ChangeLog.float
index 4006bf572854..03fc7d7fd94b 100644
--- a/gcc/ChangeLog.float
+++ b/gcc/ChangeLog.float
@@ -1,3 +1,19 @@
+ Branch work221-float, patch #302 
+
+Update conversions between _Float16 and various floating point types.
+
+2025-09-08  Michael Meissner  
+
+gcc/
+
+   * config/rs6000/rs6000.md (HF_CONVERT): New mode iterator.
+   (extendhf2): Move from vsx.md, add conversion to/from decimal
+   types.
+   (trunc2): Likewise.
+   * config/rs6000/vsx.md (extendhf2): Move to vsx.md.
+   (trunchf2): Likewise.
+
+
  Branch work221-float, patch #301 
 
 Convert between _Float16 and 128-bit binary floating point.


[gcc(refs/users/meissner/heads/work221-sha)] PR target/117251: Improve vector nor to vector xor fusion

2025-09-20 Thread Michael Meissner via Gcc-cvs
https://gcc.gnu.org/g:940dd240c64c32e51a9cfcfa0ccb7c020d654a00

commit 940dd240c64c32e51a9cfcfa0ccb7c020d654a00
Author: Michael Meissner 
Date:   Mon Sep 8 15:32:41 2025 -0400

PR target/117251: Improve vector nor to vector xor fusion

See the following post for a complete explanation of what the patches
for PR target/117251:

 * https://gcc.gnu.org/pipermail/gcc-patches/2025-June/686474.html

This is patch #25 of 45 to generate the 'XXEVAL' instruction on power10
and power11 instead of using the Altivec 'VNOR' instruction feeding
into 'VXOR'.  The 'XXEVAL' instruction can use all 64 vector registers,
instead of the 32 registers that traditional Altivec vector
instructions use.  By allowing all of the vector registers to be used,
it reduces the amount of spilling that a large benchmark generated.

Currently the following code:

vector int a, b, c, d;
a = (~ (c | d)) ^ b;

Generates:

vnor   t,c,d
vxor   a,t,b

Now in addition with this patch, if the arguments or result is
allocated to a traditional FPR register, the GCC compiler will now
generate the following code instead of adding vector move instructions:

xxeval a,b,c,135

Since fusion using 2 Altivec instructions is slightly faster than using
the 'XXEVAL' instruction we prefer to generate the Altivec instructions
if we can.  In addition, because 'XXEVAL' is a prefixed instruction, it
possibly might generate an extra NOP instruction to align the 'XXEVAL'
instruction.

I have tested these patches on both big endian and little endian
PowerPC servers, with no regressions.  Can I check these patchs into
the trunk?

2025-09-08  Michael Meissner  

gcc/

PR target/117251
* config/rs6000/fusion.md: Regenerate.
* config/rs6000/genfusion.pl (gen_logical_addsubf): Add support
to generate vector nor => xor fusion if XXEVAL is supported.

Diff:
---
 gcc/config/rs6000/fusion.md| 15 +--
 gcc/config/rs6000/genfusion.pl |  1 +
 2 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/gcc/config/rs6000/fusion.md b/gcc/config/rs6000/fusion.md
index c55e9d4abd67..1f1756dbe63e 100644
--- a/gcc/config/rs6000/fusion.md
+++ b/gcc/config/rs6000/fusion.md
@@ -3017,20 +3017,23 @@
 ;; logical-logical fusion pattern generated by gen_logical_addsubf
 ;; vector vnor -> vxor
 (define_insn "*fuse_vnor_vxor"
-  [(set (match_operand:VM 3 "altivec_register_operand" "=&0,&1,&v,v")
-(xor:VM (and:VM (not:VM (match_operand:VM 0 "altivec_register_operand" 
"v,v,v,v"))
-  (not:VM (match_operand:VM 1 
"altivec_register_operand" "v,v,v,v")))
- (match_operand:VM 2 "altivec_register_operand" "v,v,v,v")))
-   (clobber (match_scratch:VM 4 "=X,X,X,&v"))]
+  [(set (match_operand:VM 3 "vector_fusion_operand" "=&0,&1,&v,wa,v")
+(xor:VM (and:VM (not:VM (match_operand:VM 0 "vector_fusion_operand" 
"v,v,v,wa,v"))
+  (not:VM (match_operand:VM 1 "vector_fusion_operand" 
"v,v,v,wa,v")))
+ (match_operand:VM 2 "vector_fusion_operand" "v,v,v,wa,v")))
+   (clobber (match_scratch:VM 4 "=X,X,X,X,&v"))]
   "(TARGET_P10_FUSION)"
   "@
vnor %3,%1,%0\;vxor %3,%3,%2
vnor %3,%1,%0\;vxor %3,%3,%2
vnor %3,%1,%0\;vxor %3,%3,%2
+   xxeval %x3,%x2,%x1,%x0,135
vnor %4,%1,%0\;vxor %3,%4,%2"
   [(set_attr "type" "fused_vector")
(set_attr "cost" "6")
-   (set_attr "length" "8")])
+   (set_attr "length" "8")
+   (set_attr "prefixed" "*,*,*,yes,*")
+   (set_attr "isa" "*,*,*,xxeval,*")])
 
 ;; logical-logical fusion pattern generated by gen_logical_addsubf
 ;; vector vor -> vxor
diff --git a/gcc/config/rs6000/genfusion.pl b/gcc/config/rs6000/genfusion.pl
index 58f900640bef..0fea2d6d8482 100755
--- a/gcc/config/rs6000/genfusion.pl
+++ b/gcc/config/rs6000/genfusion.pl
@@ -239,6 +239,7 @@ sub gen_logical_addsubf
   "vor_vxor"=> 120,
   "vor_vor" => 127,
   "vor_vnor"=> 128,
+  "vnor_vxor"   => 135,
 );
 
 KIND: foreach $kind ('scalar','vector') {


[gcc(refs/users/aoliva/heads/testme)] [aarch64] [testsuite] accept ldr after failed ira-remat

2025-09-20 Thread Alexandre Oliva via Gcc-cvs
https://gcc.gnu.org/g:98b34b440ffb58ad2ad139900aaae5a90d1b12ce

commit 98b34b440ffb58ad2ad139900aaae5a90d1b12ce
Author: Alexandre Oliva 
Date:   Wed Sep 10 20:04:57 2025 -0300

[aarch64] [testsuite] accept ldr after failed ira-remat

When -fPIE is enabled (by default), nonlocal_goto tests fail because
ira drops reg equivalences for function invariants such as stack
addresses, and then, instead of the expected add instructions, we get
ldr to restore the pseudo holding the address, as it ends up living in
a stack slot across a call.


for  gcc/testsuite/ChangeLog

* gcc.target/aarch64/sme/nonlocal_goto_1.c: Accept ldr.
* gcc.target/aarch64/sme/nonlocal_goto_2.c: Likewise.
* gcc.target/aarch64/sme/nonlocal_goto_3.c: Likewise.

Diff:
---
 gcc/testsuite/gcc.target/aarch64/sme/nonlocal_goto_1.c | 2 +-
 gcc/testsuite/gcc.target/aarch64/sme/nonlocal_goto_2.c | 2 +-
 gcc/testsuite/gcc.target/aarch64/sme/nonlocal_goto_3.c | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/gcc/testsuite/gcc.target/aarch64/sme/nonlocal_goto_1.c 
b/gcc/testsuite/gcc.target/aarch64/sme/nonlocal_goto_1.c
index 11578279b928..de9702e74451 100644
--- a/gcc/testsuite/gcc.target/aarch64/sme/nonlocal_goto_1.c
+++ b/gcc/testsuite/gcc.target/aarch64/sme/nonlocal_goto_1.c
@@ -17,7 +17,7 @@ void run(void (*)());
 ** ldr x16, \1
 ** tbz x16, 0, .*
 ** smstart sm
-** add x0, .*
+** (add|ldr)   x0, .*
 ** ldr x16, \1
 ** tbz x16, 0, .*
 ** smstop  sm
diff --git a/gcc/testsuite/gcc.target/aarch64/sme/nonlocal_goto_2.c 
b/gcc/testsuite/gcc.target/aarch64/sme/nonlocal_goto_2.c
index 37dbcbae1a4f..598db3cad38d 100644
--- a/gcc/testsuite/gcc.target/aarch64/sme/nonlocal_goto_2.c
+++ b/gcc/testsuite/gcc.target/aarch64/sme/nonlocal_goto_2.c
@@ -9,7 +9,7 @@ void run(void (*)());
 ** smstop  sm
 ** bl  [^\n]*[cC]ache[^\n]*
 ** smstart sm
-** add x0, .*
+** (add|ldr)   x0, .*
 ** smstop  sm
 ** bl  run
 ** smstart sm
diff --git a/gcc/testsuite/gcc.target/aarch64/sme/nonlocal_goto_3.c 
b/gcc/testsuite/gcc.target/aarch64/sme/nonlocal_goto_3.c
index ae661653f302..9aedd088d780 100644
--- a/gcc/testsuite/gcc.target/aarch64/sme/nonlocal_goto_3.c
+++ b/gcc/testsuite/gcc.target/aarch64/sme/nonlocal_goto_3.c
@@ -11,7 +11,7 @@ void run(void (*)());
 ** smstop  sm
 ** bl  [^\n]*[cC]ache[^\n]*
 ** smstart sm
-** add x0, .*
+** (add|ldr)   x0, .*
 ** smstop  sm
 ** bl  run
 ** smstart sm


[gcc(refs/users/mikael/heads/refactor_descriptor_v08)] gimple-simulate: Réécriture de MEM_REF à l'intérieur de ARRAY_REF

2025-09-20 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:5826c0d9f05d77cd7b080730a1eae4b4e285c71f

commit 5826c0d9f05d77cd7b080730a1eae4b4e285c71f
Author: Mikael Morin 
Date:   Sat Aug 30 21:11:38 2025 +0200

gimple-simulate: Réécriture de MEM_REF à l'intérieur de ARRAY_REF

Diff:
---
 gcc/gimple-simulate.cc | 81 +++---
 1 file changed, 64 insertions(+), 17 deletions(-)

diff --git a/gcc/gimple-simulate.cc b/gcc/gimple-simulate.cc
index 85c37ed468d9..e33f8d8d5b46 100644
--- a/gcc/gimple-simulate.cc
+++ b/gcc/gimple-simulate.cc
@@ -982,6 +982,9 @@ static bool
 rewrite_ref (tree * data_ref, unsigned * offset, simul_scope & context)
 {
   tree ref = *data_ref;
+  if (DECL_P (ref))
+return true;
+
   switch (TREE_CODE (*data_ref))
 {
 case MEM_REF:
@@ -1007,34 +1010,24 @@ rewrite_ref (tree * data_ref, unsigned * offset, 
simul_scope & context)
return true;
   }
 
-#if 0
 case ARRAY_REF:
   {
tree base = TREE_OPERAND (ref, 0);
tree index = TREE_OPERAND (ref, 1);
-   tree type = TREE_TYPE (ref);
-   unsigned type_size = get_constant_type_size (type);
-   data_value idx_val = context.evaluate (index);
-   gcc_assert (idx_val.classify () == VAL_KNOWN);
-   wide_int wi_idx = idx_val.get_known ();
-   wide_int total_off = wi::shwi (*offset, HOST_BITS_PER_WIDE_INT);
-   wide_int idx_off = wi_idx * type_size;
-   gcc_assert (wi::ges_p (total_off, idx_off));
-   wide_int remaining_off = total_off - idx_off;
-   gcc_assert (wi::fits_uhwi_p (remaining_off));
-   unsigned rem = remaining_off.to_uhwi ();
 
tree rewritten_base = base;
-   if (!rewrite_ref (&base, &rem, context,
- get_constant_type_size (TREE_TYPE (base
+   unsigned rewritten_off = *offset;
+   if (!rewrite_ref (&rewritten_base, &rewritten_off, context)
+   && TREE_CODE (index) == INTEGER_CST)
  return false;
-   *data_ref = build4 (ARRAY_REF, type, rewritten_base,
+
+   data_value idx_val = context.evaluate (index);
+   *data_ref = build4 (ARRAY_REF, TREE_TYPE (ref), rewritten_base,
idx_val.to_tree (TREE_TYPE (index)),
NULL_TREE, NULL_TREE);
-   *offset = rem;
+   *offset = rewritten_off;
return true;
   }
-#endif
 
 default:
   return false;
@@ -4487,6 +4480,60 @@ context_printer_print_first_data_ref_part_tests ()
   ASSERT_EQ (res14, integer_type_node);
   const char * str14 = pp_formatted_text (&pp14);
   ASSERT_STREQ (str14, "# a14[0].der2i_i2");
+
+
+  tree der1a1i = make_node (RECORD_TYPE);
+  tree der1a1i_i2 = build_decl (input_location, FIELD_DECL,
+   get_identifier ("der1a1i_i2"),
+   integer_type_node);
+  DECL_CONTEXT (der1a1i_i2) = der1a1i;
+  DECL_CHAIN (der1a1i_i2) = NULL_TREE;
+  tree der1a1i_a1 = build_decl (input_location, FIELD_DECL,
+   get_identifier ("der1a1i_a1"), a2i);
+  DECL_CONTEXT (der1a1i_a1) = der1a1i;
+  DECL_CHAIN (der1a1i_a1) = der1a1i_i2;
+  TYPE_FIELDS (der1a1i) = der1a1i_a1;
+  layout_type (der1a1i);
+
+  heap_memory mem15;
+
+  context_printer printer15;
+  pretty_printer & pp15 = printer15.pp;
+
+  tree d_15 = create_var (der1a1i, "d");
+  tree p_15 = create_var (ptr_type_node, "p");
+
+  vec decls15{};
+  decls15.safe_push (d_15);
+  decls15.safe_push (p_15);
+
+  context_builder builder15 {};
+  builder15.add_decls (&decls15);
+  simul_scope ctx15 = builder15.build (mem15, printer15);
+
+  data_storage *strg_d15 = ctx15.find_reachable_var (d_15);
+  gcc_assert (strg_d15 != nullptr);
+
+  storage_address addr_d15 (strg_d15->get_ref (), 0);
+  data_value val_p15 (ptr_type_node);
+  val_p15.set_address (addr_d15);
+
+  data_storage *strg_p15 = ctx15.find_reachable_var (p_15);
+  gcc_assert (strg_p15 != nullptr);
+  strg_p15->set (val_p15);
+
+  tree zero_15 = build_zero_cst (build_pointer_type (void_type_node));
+  tree ref_d15 = build2 (MEM_REF, a2i, p_15, zero_15);
+  tree ref15 = build4 (ARRAY_REF, integer_type_node, ref_d15,
+  build_one_cst (integer_type_node), NULL_TREE, NULL_TREE);
+
+  tree res15 = printer15.print_first_data_ref_part (ctx15, ref15, 0,
+   nullptr,
+   VAL_UNDEFINED);
+
+  ASSERT_EQ (res15, integer_type_node);
+  const char * str15 = pp_formatted_text (&pp15);
+  ASSERT_STREQ (str15, "# d.der1a1i_a1[1]");
 }


[gcc(refs/users/mikael/heads/refactor_descriptor_v08)] Factorisation utilisation shapeval

2025-09-20 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:fbe90409178cf8ff25cfbe391edb9d35c2edf56c

commit fbe90409178cf8ff25cfbe391edb9d35c2edf56c
Author: Mikael Morin 
Date:   Sun Aug 17 19:56:14 2025 +0200

Factorisation utilisation shapeval

Diff:
---
 gcc/fortran/trans-descriptor.cc | 10 --
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/gcc/fortran/trans-descriptor.cc b/gcc/fortran/trans-descriptor.cc
index d283c741767f..f3d6d83fd902 100644
--- a/gcc/fortran/trans-descriptor.cc
+++ b/gcc/fortran/trans-descriptor.cc
@@ -1755,12 +1755,12 @@ gfc_set_descriptor_with_shape (stmtblock_t *block, tree 
desc, tree ptr,
 
   gfc_conv_expr (&shapese, shape);
   gfc_add_block_to_block (&body, &shapese.pre);
+  tree shapeval = fold_convert (gfc_array_index_type, shapese.expr);
+  shapeval = gfc_evaluate_now (shapeval, &body);
   tmp = fold_build2_loc (input_location, MINUS_EXPR, gfc_array_index_type,
 lbound, gfc_index_one_node);
   tree ubound = fold_build2_loc (input_location, PLUS_EXPR,
-gfc_array_index_type, tmp,
-fold_convert (gfc_array_index_type,
-  shapese.expr));
+gfc_array_index_type, tmp, shapeval);
   gfc_conv_descriptor_ubound_set (&body, desc, dim, ubound);
   gfc_add_block_to_block (&body, &shapese.post);
 
@@ -1774,9 +1774,7 @@ gfc_set_descriptor_with_shape (stmtblock_t *block, tree 
desc, tree ptr,
   /* Update stride.  */
   gfc_add_modify (&body, stride,
  fold_build2_loc (input_location, MULT_EXPR,
-  gfc_array_index_type, stride,
-  fold_convert (gfc_array_index_type,
-shapese.expr)));
+  gfc_array_index_type, stride, shapeval));
   /* Finish scalarization loop.  */
   gfc_trans_scalarizing_loops (&loop, &body);
   gfc_add_block_to_block (block, &loop.pre);


[gcc(refs/users/mikael/heads/refactor_descriptor_v08)] Ajout locations setters

2025-09-20 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:6dc370a15a8378c54814b7462b6b5595bb793c7e

commit 6dc370a15a8378c54814b7462b6b5595bb793c7e
Author: Mikael Morin 
Date:   Tue Jul 1 22:20:34 2025 +0200

Ajout locations setters

Diff:
---
 gcc/fortran/trans-descriptor.cc | 28 
 1 file changed, 20 insertions(+), 8 deletions(-)

diff --git a/gcc/fortran/trans-descriptor.cc b/gcc/fortran/trans-descriptor.cc
index c1b4f3b5e019..e22dcbd8a03b 100644
--- a/gcc/fortran/trans-descriptor.cc
+++ b/gcc/fortran/trans-descriptor.cc
@@ -217,10 +217,10 @@ gfc_conv_descriptor_data_get (tree desc)
   tree type = TREE_TYPE (desc);
   gcc_assert (TREE_CODE (type) != REFERENCE_TYPE);
 
+  location_t loc = input_location;
   tree field = get_descriptor_data (desc);
   tree target_type = GFC_TYPE_ARRAY_DATAPTR_TYPE (TREE_TYPE (desc));
-  tree t = fold_convert (target_type, field);
-  return non_lvalue_loc (input_location, t);
+  return non_lvalue_loc (loc, fold_convert_loc (loc, target_type, field));
 }
 
 /* This provides WRITE access to the data field.
@@ -234,8 +234,10 @@ gfc_conv_descriptor_data_get (tree desc)
 void
 gfc_conv_descriptor_data_set (stmtblock_t *block, tree desc, tree value)
 {
+  location_t loc = input_location;
   tree field = get_descriptor_data (desc);
-  gfc_add_modify (block, field, fold_convert (TREE_TYPE (field), value));
+  gfc_add_modify_loc (loc, block, field,
+ fold_convert_loc (loc, TREE_TYPE (field), value));
 }
 
 
@@ -254,8 +256,10 @@ gfc_conv_descriptor_offset_get (tree desc)
 void
 gfc_conv_descriptor_offset_set (stmtblock_t *block, tree desc, tree value)
 {
+  location_t loc = input_location;
   tree t = get_descriptor_offset (desc);
-  gfc_add_modify (block, t, fold_convert (TREE_TYPE (t), value));
+  gfc_add_modify_loc (loc, block, t,
+ fold_convert_loc (loc, TREE_TYPE (t), value));
 }
 
 
@@ -296,8 +300,10 @@ gfc_conv_descriptor_span_get (tree desc)
 void
 gfc_conv_descriptor_span_set (stmtblock_t *block, tree desc, tree value)
 {
+  location_t loc = input_location;
   tree t = gfc_conv_descriptor_span (desc);
-  gfc_add_modify (block, t, fold_convert (TREE_TYPE (t), value));
+  gfc_add_modify_loc (loc, block, t,
+ fold_convert_loc (loc, TREE_TYPE (t), value));
 }
 
 
@@ -544,8 +550,10 @@ void
 gfc_conv_descriptor_stride_set (stmtblock_t *block, tree desc,
tree dim, tree value)
 {
+  location_t loc = input_location;
   tree t = get_descriptor_stride (desc, dim);
-  gfc_add_modify (block, t, fold_convert (TREE_TYPE (t), value));
+  gfc_add_modify_loc (loc, block, t,
+ fold_convert_loc (loc, TREE_TYPE (t), value));
 }
 
 static tree
@@ -564,8 +572,10 @@ void
 gfc_conv_descriptor_lbound_set (stmtblock_t *block, tree desc,
tree dim, tree value)
 {
+  location_t loc = input_location;
   tree t = get_descriptor_lbound (desc, dim);
-  gfc_add_modify (block, t, fold_convert (TREE_TYPE (t), value));
+  gfc_add_modify_loc (loc, block, t,
+ fold_convert_loc (loc, TREE_TYPE (t), value));
 }
 
 static tree
@@ -584,8 +594,10 @@ void
 gfc_conv_descriptor_ubound_set (stmtblock_t *block, tree desc,
tree dim, tree value)
 {
+  location_t loc = input_location;
   tree t = get_descriptor_ubound (desc, dim);
-  gfc_add_modify (block, t, fold_convert (TREE_TYPE (t), value));
+  gfc_add_modify_loc (loc, block, t,
+ fold_convert_loc (loc, TREE_TYPE (t), value));
 }


[gcc(refs/users/mikael/heads/refactor_descriptor_v08)] Correction ifindloc0.m4

2025-09-20 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:669cb09f8a5e47d05d9861e43bd2ce251ee34dd1

commit 669cb09f8a5e47d05d9861e43bd2ce251ee34dd1
Author: Mikael Morin 
Date:   Tue Sep 9 21:23:12 2025 +0200

Correction ifindloc0.m4

Diff:
---
 libgfortran/m4/ifindloc0.m4 | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libgfortran/m4/ifindloc0.m4 b/libgfortran/m4/ifindloc0.m4
index 7675a03def98..f5e392c5e791 100644
--- a/libgfortran/m4/ifindloc0.m4
+++ b/libgfortran/m4/ifindloc0.m4
@@ -228,7 +228,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  
If not, see
 
   if (back)
 {
-  base = (const 'atype_name` *) (((char*)array->base_addr) + (sz - 1) * 
'base_mult`);
+  base = array->base_addr + (sz - 1) * 'base_mult`;
   mbase = mbase + (sz - 1) * mask_kind;
   while (1)
 {


[gcc(refs/users/mikael/heads/refactor_descriptor_v08)] Extraction gfc_set_descriptor_from_scalar

2025-09-20 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:88172a0b8db03a6d01e4ef13f76e1349c52bd050

commit 88172a0b8db03a6d01e4ef13f76e1349c52bd050
Author: Mikael Morin 
Date:   Tue Jul 22 21:14:56 2025 +0200

Extraction gfc_set_descriptor_from_scalar

Correction code en doublon

Diff:
---
 gcc/fortran/trans-descriptor.cc | 17 +
 gcc/fortran/trans-descriptor.h  |  1 +
 gcc/fortran/trans-expr.cc   | 14 +++---
 3 files changed, 21 insertions(+), 11 deletions(-)

diff --git a/gcc/fortran/trans-descriptor.cc b/gcc/fortran/trans-descriptor.cc
index ff59042049e9..253d6638f2ed 100644
--- a/gcc/fortran/trans-descriptor.cc
+++ b/gcc/fortran/trans-descriptor.cc
@@ -970,3 +970,20 @@ gfc_set_descriptor_from_scalar (stmtblock_t *block, tree 
descr,
   null_pointer_node));
   gfc_conv_descriptor_data_set (block, descr, scalar);
 }
+
+
+void
+gfc_set_descriptor_from_scalar (stmtblock_t *block, tree descr, tree scalar)
+{
+  tree etype = TREE_TYPE (scalar);
+  if (!POINTER_TYPE_P (TREE_TYPE (scalar)))
+scalar = gfc_build_addr_expr (NULL_TREE, scalar);
+  else if (TREE_TYPE (etype) && TREE_CODE (TREE_TYPE (etype)) == ARRAY_TYPE)
+etype = TREE_TYPE (etype);
+
+  gfc_conv_descriptor_dtype_set (block, descr,
+gfc_get_dtype_rank_type (0, etype));
+  gfc_conv_descriptor_data_set (block, descr, scalar);
+  gfc_conv_descriptor_span_set (block, descr,
+   gfc_conv_descriptor_elem_len_get (descr));
+}
diff --git a/gcc/fortran/trans-descriptor.h b/gcc/fortran/trans-descriptor.h
index 2848dcc01a4e..79db264c91c1 100644
--- a/gcc/fortran/trans-descriptor.h
+++ b/gcc/fortran/trans-descriptor.h
@@ -101,6 +101,7 @@ tree gfc_create_null_actual_descriptor (stmtblock_t *, 
gfc_typespec *,
 void gfc_init_descriptor_variable (stmtblock_t *block, gfc_symbol *sym, tree 
descr);
 
 void gfc_set_descriptor_from_scalar_class (stmtblock_t *, tree, tree, gfc_expr 
*);
+void gfc_set_descriptor_from_scalar (stmtblock_t *, tree, tree);
 void gfc_set_descriptor_from_scalar (stmtblock_t *, tree, tree, gfc_expr *,
 tree);
 
diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc
index 3347212217c0..708e13067119 100644
--- a/gcc/fortran/trans-expr.cc
+++ b/gcc/fortran/trans-expr.cc
@@ -94,10 +94,9 @@ gfc_get_character_len_in_bytes (tree type)
 tree
 gfc_conv_scalar_to_descriptor (gfc_se *se, tree scalar, symbol_attribute attr)
 {
-  tree desc, type, etype;
+  tree desc, type;
 
   type = gfc_get_scalar_to_descriptor_type (TREE_TYPE (scalar), attr);
-  etype = TREE_TYPE (scalar);
   desc = gfc_create_var (type, "desc");
   DECL_ARTIFICIAL (desc) = 1;
 
@@ -108,15 +107,8 @@ gfc_conv_scalar_to_descriptor (gfc_se *se, tree scalar, 
symbol_attribute attr)
   gfc_add_modify (&se->pre, tmp, scalar);
   scalar = tmp;
 }
-  if (!POINTER_TYPE_P (TREE_TYPE (scalar)))
-scalar = gfc_build_addr_expr (NULL_TREE, scalar);
-  else if (TREE_TYPE (etype) && TREE_CODE (TREE_TYPE (etype)) == ARRAY_TYPE)
-etype = TREE_TYPE (etype);
-  gfc_conv_descriptor_dtype_set (&se->pre, desc,
-gfc_get_dtype_rank_type (0, etype));
-  gfc_conv_descriptor_data_set (&se->pre, desc, scalar);
-  gfc_conv_descriptor_span_set (&se->pre, desc,
-   gfc_conv_descriptor_elem_len_get (desc));
+
+  gfc_set_descriptor_from_scalar (&se->pre, desc, scalar);
 
   /* Copy pointer address back - but only if it could have changed and
  if the actual argument is a pointer and not, e.g., NULL().  */


[gcc(refs/users/mikael/heads/refactor_descriptor_v08)] Refactoring set_dimension_fields set_pdt_array_descriptor

2025-09-20 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:977ca8e46461052aaac11eb7fa0c45cde185a4fe

commit 977ca8e46461052aaac11eb7fa0c45cde185a4fe
Author: Mikael Morin 
Date:   Sat Aug 16 19:09:50 2025 +0200

Refactoring set_dimension_fields set_pdt_array_descriptor

Diff:
---
 gcc/fortran/trans-descriptor.cc | 11 +--
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/gcc/fortran/trans-descriptor.cc b/gcc/fortran/trans-descriptor.cc
index 510fc984de34..071840f0e871 100644
--- a/gcc/fortran/trans-descriptor.cc
+++ b/gcc/fortran/trans-descriptor.cc
@@ -2606,18 +2606,17 @@ gfc_set_pdt_array_descriptor (stmtblock_t *block, tree 
descr,
   gfc_conv_expr_type (&tse, e, gfc_array_index_type);
   gfc_free_expr (e);
   tree lower = tse.expr;
+
   gfc_conv_descriptor_lbound_set (block, descr, gfc_rank_cst[i], lower);
   e = gfc_copy_expr (as->upper[i]);
   gfc_insert_parameter_exprs (e, pdt_param_list);
   gfc_conv_expr_type (&tse, e, gfc_array_index_type);
   gfc_free_expr (e);
   tree upper = tse.expr;
-  gfc_conv_descriptor_ubound_set (block, descr, gfc_rank_cst[i], upper);
-  gfc_conv_descriptor_stride_set (block, descr, gfc_rank_cst[i], size);
-  size = gfc_evaluate_now (size, block);
-  offset = fold_build2_loc (input_location, MINUS_EXPR,
-   gfc_array_index_type, offset, size);
-  offset = gfc_evaluate_now (offset, block);
+
+  set_dimension_fields (block, descr, gfc_rank_cst[i], lower, upper, size,
+   &offset);
+
   tree tmp = fold_build2_loc (input_location, MINUS_EXPR,
  gfc_array_index_type, upper, lower);
   tmp = fold_build2_loc (input_location, PLUS_EXPR, gfc_array_index_type,


[gcc(refs/users/mikael/heads/refactor_descriptor_v08)] Factorisation set_dimension_fields gfc_set_descriptor_with_shape

2025-09-20 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:efcf7f5ef0edf4b6985a426e16b82097af2378c7

commit efcf7f5ef0edf4b6985a426e16b82097af2378c7
Author: Mikael Morin 
Date:   Sat Aug 16 18:19:27 2025 +0200

Factorisation set_dimension_fields gfc_set_descriptor_with_shape

Correction régression c_f_pointer_tests_4

Diff:
---
 gcc/fortran/trans-descriptor.cc | 18 --
 1 file changed, 4 insertions(+), 14 deletions(-)

diff --git a/gcc/fortran/trans-descriptor.cc b/gcc/fortran/trans-descriptor.cc
index ce7495ab1f34..6ada111b9e6e 100644
--- a/gcc/fortran/trans-descriptor.cc
+++ b/gcc/fortran/trans-descriptor.cc
@@ -1995,15 +1995,12 @@ gfc_set_descriptor_with_shape (stmtblock_t *block, tree 
desc, tree ptr,
   gfc_conv_expr (&lowerse, lower);
   gfc_add_block_to_block (&body, &lowerse.pre);
   lbound = fold_convert (gfc_array_index_type, lowerse.expr);
+  lbound = gfc_evaluate_now (lbound, &body);
   gfc_add_block_to_block (&body, &lowerse.post);
 }
   else
 lbound = gfc_index_one_node;
 
-  /* Set bounds and stride.  */
-  gfc_conv_descriptor_lbound_set (&body, desc, dim, lbound);
-  gfc_conv_descriptor_stride_set (&body, desc, dim, stride);
-
   gfc_conv_expr (&shapese, shape);
   gfc_add_block_to_block (&body, &shapese.pre);
   tree shapeval = fold_convert (gfc_array_index_type, shapese.expr);
@@ -2012,29 +2009,22 @@ gfc_set_descriptor_with_shape (stmtblock_t *block, tree 
desc, tree ptr,
 lbound, gfc_index_one_node);
   tree ubound = fold_build2_loc (input_location, PLUS_EXPR,
 gfc_array_index_type, tmp, shapeval);
-  gfc_conv_descriptor_ubound_set (&body, desc, dim, ubound);
+  ubound = gfc_evaluate_now (ubound, &body);
   gfc_add_block_to_block (&body, &shapese.post);
 
-  /* Calculate offset.  */
-  tmp = fold_build2_loc (input_location, MULT_EXPR, gfc_array_index_type,
-stride, lbound);
-  gfc_add_modify (&body, offset,
- fold_build2_loc (input_location, PLUS_EXPR,
-  gfc_array_index_type, offset, tmp));
+  set_dimension_fields (&body, desc, dim, lbound, ubound, stride, offset);
 
   /* Update stride.  */
   gfc_add_modify (&body, stride,
  fold_build2_loc (input_location, MULT_EXPR,
   gfc_array_index_type, stride, shapeval));
+
   /* Finish scalarization loop.  */
   gfc_trans_scalarizing_loops (&loop, &body);
   gfc_add_block_to_block (block, &loop.pre);
   gfc_add_block_to_block (block, &loop.post);
   gfc_cleanup_loop (&loop);
 
-  gfc_add_modify (block, offset,
- fold_build1_loc (input_location, NEGATE_EXPR,
-  gfc_array_index_type, offset));
   gfc_conv_descriptor_offset_set (block, desc, offset);
 }


[gcc(refs/users/mikael/heads/refactor_descriptor_v08)] Réduction utilisation stride pour allocation/initialisation

2025-09-20 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:5a3078edebdc9d4a4f64310861244565e81a3ea2

commit 5a3078edebdc9d4a4f64310861244565e81a3ea2
Author: Mikael Morin 
Date:   Sun Sep 14 18:44:25 2025 +0200

Réduction utilisation stride pour allocation/initialisation

Diff:
---
 libgfortran/intrinsics/cshift0.c| 12 --
 libgfortran/intrinsics/eoshift2.c   | 12 --
 libgfortran/m4/cshift1.m4   | 12 --
 libgfortran/m4/eoshift1.m4  | 13 +-
 libgfortran/m4/eoshift3.m4  | 13 --
 libgfortran/m4/ifindloc1.m4 | 48 ++---
 libgfortran/m4/ifunction-s.m4   | 48 ++---
 libgfortran/m4/ifunction-s2.m4  | 41 +--
 libgfortran/m4/ifunction.m4 | 48 ++---
 libgfortran/m4/ifunction_logical.m4 | 16 +
 10 files changed, 102 insertions(+), 161 deletions(-)

diff --git a/libgfortran/intrinsics/cshift0.c b/libgfortran/intrinsics/cshift0.c
index a490f81b8aee..a94dade9145c 100644
--- a/libgfortran/intrinsics/cshift0.c
+++ b/libgfortran/intrinsics/cshift0.c
@@ -58,23 +58,21 @@ cshift0 (gfc_array_char * ret, const gfc_array_char * array,
 
   if (ret->base_addr == NULL)
 {
+  index_type cnt;
   int i;
 
   ret->offset = 0;
   GFC_DTYPE_COPY(ret,array);
+  cnt = 1;
   for (i = 0; i < GFC_DESCRIPTOR_RANK (array); i++)
 {
- index_type ub, str;
+ index_type ub;
 
   ub = GFC_DESCRIPTOR_EXTENT(array,i) - 1;
 
-  if (i == 0)
-str = 1;
-  else
-str = GFC_DESCRIPTOR_EXTENT(ret,i-1) *
- GFC_DESCRIPTOR_STRIDE(ret,i-1);
+ GFC_DESCRIPTOR_DIMENSION_SET(ret, i, 0, ub, cnt);
 
- GFC_DESCRIPTOR_DIMENSION_SET(ret, i, 0, ub, str);
+ cnt = cnt * GFC_DESCRIPTOR_EXTENT(ret,i);
 }
 
   /* xmallocarray allocates a single byte for zero size.  */
diff --git a/libgfortran/intrinsics/eoshift2.c 
b/libgfortran/intrinsics/eoshift2.c
index 2ebd1d5164f4..7752614cffd8 100644
--- a/libgfortran/intrinsics/eoshift2.c
+++ b/libgfortran/intrinsics/eoshift2.c
@@ -69,6 +69,7 @@ eoshift2 (gfc_array_char *ret, const gfc_array_char *array,
 
   if (ret->base_addr == NULL)
 {
+  index_type cnt;
   int i;
 
   ret->offset = 0;
@@ -77,19 +78,16 @@ eoshift2 (gfc_array_char *ret, const gfc_array_char *array,
   /* xmallocarray allocates a single byte for zero size.  */
   ret->base_addr = xmallocarray (arraysize, size);
 
+  cnt = 1;
   for (i = 0; i < GFC_DESCRIPTOR_RANK (array); i++)
 {
- index_type ub, str;
+ index_type ub;
 
   ub = GFC_DESCRIPTOR_EXTENT(array,i) - 1;
 
-  if (i == 0)
-   str = 1;
-  else
-str = GFC_DESCRIPTOR_EXTENT(ret,i-1)
- * GFC_DESCRIPTOR_STRIDE(ret,i-1);
+ GFC_DESCRIPTOR_DIMENSION_SET(ret, i, 0, ub, cnt);
 
- GFC_DESCRIPTOR_DIMENSION_SET(ret, i, 0, ub, str);
+ cnt = cnt * GFC_DESCRIPTOR_EXTENT(ret,i);
 }
 }
   else if (unlikely (compile_options.bounds_check))
diff --git a/libgfortran/m4/cshift1.m4 b/libgfortran/m4/cshift1.m4
index e35c5aa0f563..b368029dd729 100644
--- a/libgfortran/m4/cshift1.m4
+++ b/libgfortran/m4/cshift1.m4
@@ -78,22 +78,20 @@ cshift1 (gfc_array_char * const restrict ret,
 
   if (ret->base_addr == NULL)
 {
+  index_type cnt;
   ret->base_addr = xmallocarray (arraysize, size);
   ret->offset = 0;
   GFC_DTYPE_COPY(ret,array);
+  cnt = 1;
   for (index_type i = 0; i < GFC_DESCRIPTOR_RANK (array); i++)
 {
- index_type ub, str;
+ index_type ub;
 
   ub = GFC_DESCRIPTOR_EXTENT(array,i) - 1;
 
-  if (i == 0)
-str = 1;
-  else
-   str = GFC_DESCRIPTOR_EXTENT(ret,i-1) *
- GFC_DESCRIPTOR_STRIDE(ret,i-1);
+ GFC_DESCRIPTOR_DIMENSION_SET(ret, i, 0, ub, cnt);
 
- GFC_DESCRIPTOR_DIMENSION_SET(ret, i, 0, ub, str);
+ cnt = cnt * GFC_DESCRIPTOR_EXTENT(ret,i);
 }
 }
   else if (unlikely (compile_options.bounds_check))
diff --git a/libgfortran/m4/eoshift1.m4 b/libgfortran/m4/eoshift1.m4
index 7de92f2054e2..90db7b5df9b2 100644
--- a/libgfortran/m4/eoshift1.m4
+++ b/libgfortran/m4/eoshift1.m4
@@ -85,21 +85,20 @@ eoshift1 (gfc_array_char * const restrict ret,
   arraysize = size0 ((array_t *) array);
   if (ret->base_addr == NULL)
 {
+  index_type cnt;
+
   ret->offset = 0;
   GFC_DTYPE_COPY(ret,array);
+  cnt = 1;
   for (index_type i = 0; i < GFC_DESCRIPTOR_RANK (array); i++)
 {
- index_type ub, str;
+ index_type ub;
 
  ub = GFC_DESCRIPTOR_EXTENT(array,i) - 1;
 
-  if (i == 0)
-str = 1;
-  else
-str = GFC_DESCRIPTOR_EXTENT(ret,i-1)
- * GFC_DESCRIPTOR_STRIDE(ret,i-1);
+ GFC_DESCRIPTOR_DIMENSION_SET(ret, i, 0, ub, cn

[gcc(refs/users/mikael/heads/refactor_descriptor_v08)] Renseignement dtype initialisation statique

2025-09-20 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:0f05d1555ac0e0c906fe012a5b349a2848c6f69e

commit 0f05d1555ac0e0c906fe012a5b349a2848c6f69e
Author: Mikael Morin 
Date:   Mon Aug 11 19:59:55 2025 +0200

Renseignement dtype initialisation statique

Diff:
---
 gcc/fortran/trans-descriptor.cc | 234 +++-
 gcc/fortran/trans-descriptor.h  |   2 +-
 2 files changed, 163 insertions(+), 73 deletions(-)

diff --git a/gcc/fortran/trans-descriptor.cc b/gcc/fortran/trans-descriptor.cc
index a173530cbc70..d16127cf3ed7 100644
--- a/gcc/fortran/trans-descriptor.cc
+++ b/gcc/fortran/trans-descriptor.cc
@@ -727,7 +727,8 @@ enum descriptor_write_case
   POINTER_NULLIFY,
   RESULT_INIT,
   ABSENT_ARG_INIT,
-  STATIC_INIT
+  STATIC_INIT,
+  NONSTATIC_INIT
 };
 
 
@@ -797,6 +798,44 @@ struct descriptor_write
 };
 
 
+struct value_source
+{
+  const descriptor_write_case type;
+
+  union u
+  {
+struct nsi
+{
+  gfc_symbol * const sym;
+  gfc_expr * const expr;
+  tree string_length;
+
+  nsi (gfc_symbol *s, gfc_expr *e, tree sl)
+ : sym (s), expr (e), string_length (sl) {}
+}
+nonstatic_init;
+
+struct si
+{
+  gfc_symbol * const sym;
+
+  si (gfc_symbol *s) : sym (s) {}
+}
+static_init;
+
+u () {}
+u (gfc_symbol *s) : static_init (s) {}
+u (gfc_symbol *s, gfc_expr *e, tree sl) : nonstatic_init (s, e, sl) {}
+  }
+  u;
+
+  value_source (descriptor_write_case t) : type (t), u () {}
+  value_source (gfc_symbol *s) : type (STATIC_INIT), u (s) {}
+  value_source (gfc_symbol *s, gfc_expr *e, tree sl)
+  : type (NONSTATIC_INIT), u (s, e, sl) {}
+};
+
+
 static void
 set_descriptor_field (descriptor_write &dest, descriptor_field field, tree 
value)
 {
@@ -814,10 +853,117 @@ set_descriptor_field (descriptor_write &dest, 
descriptor_field field, tree value
 }
 
 
+static tree
+get_descriptor_data_value (const value_source &src)
+{
+  if (src.type == NONSTATIC_INIT)
+{
+  gfc_symbol *sym = src.u.nonstatic_init.sym;
+
+  symbol_attribute attr = gfc_symbol_attr (sym);
+  if (!attr.save
+ && (attr.allocatable
+ || (attr.pointer && (gfc_option.rtcheck & GFC_RTCHECK_POINTER
+   return null_pointer_node;
+  else
+   return NULL_TREE;
+}
+  else
+return null_pointer_node;
+}
+
+
+static tree
+get_descriptor_dtype_value (tree descr, const value_source &src)
+{
+  if (src.type == NONSTATIC_INIT)
+{
+  gfc_symbol *sym = src.u.nonstatic_init.sym;
+  gfc_expr *expr = src.u.nonstatic_init.expr;
+  tree string_length = src.u.nonstatic_init.string_length;
+
+  gfc_array_spec *as;
+  if (sym->ts.type == BT_CLASS)
+   as = CLASS_DATA (sym)->as;
+  else
+   as = sym->as;
+
+  int rank;
+  if (as == nullptr)
+   rank = 0;
+  else if (as->type != AS_ASSUMED_RANK)
+   rank = as->rank;
+  else if (expr)
+   rank = expr->rank;
+  else
+   rank = -1;
+
+  tree etype = gfc_get_element_type (TREE_TYPE (descr));
+  return gfc_get_dtype_rank_type_slen (rank, etype, string_length);
+}
+  else if (src.type == STATIC_INIT)
+{
+  gfc_symbol *sym = src.u.nonstatic_init.sym;
+
+  gfc_array_spec *as;
+  if (sym->ts.type == BT_CLASS)
+   as = CLASS_DATA (sym)->as;
+  else
+   as = sym->as;
+
+  int rank;
+  if (as == nullptr)
+   rank = 0;
+  else if (as->type != AS_ASSUMED_RANK)
+   rank = as->rank;
+  else
+   rank = -1;
+
+  tree etype = gfc_get_element_type (TREE_TYPE (descr));
+  return gfc_get_dtype_rank_type (rank, etype);
+}
+
+  return NULL_TREE;
+}
+
+
+static tree
+get_descriptor_offset_value (const value_source &src)
+{
+  if (src.type == NONSTATIC_INIT)
+{
+  gfc_symbol *sym = src.u.nonstatic_init.sym;
+
+  symbol_attribute attr = gfc_symbol_attr (sym);
+  if ((attr.allocatable
+  || attr.optional
+  || (attr.pointer && (gfc_option.rtcheck & GFC_RTCHECK_POINTER)))
+ && attr.codimension)
+   return null_pointer_node;
+}
+
+  return NULL_TREE;
+}
+
+
 static void
-set_descriptor (descriptor_write &dest)
+set_descriptor (descriptor_write &dest, const value_source &src)
 {
-  set_descriptor_field (dest, DATA_FIELD, null_pointer_node);
+  tree data_value = get_descriptor_data_value (src);
+  if (data_value != NULL_TREE)
+set_descriptor_field (dest, DATA_FIELD, data_value);
+
+  tree dtype_value = get_descriptor_dtype_value (dest.ref, src);
+  if (dtype_value != NULL_TREE)
+set_descriptor_field (dest, DTYPE_FIELD, dtype_value);
+
+  if (flag_coarray == GFC_FCOARRAY_LIB)
+{
+  tree offset_value = get_descriptor_offset_value (src);
+  if (offset_value != NULL_TREE)
+   set_descriptor_field (dest, OFFSET_FIELD, offset_value);
+}
+
   if (dest.type == descriptor_write::STATIC_INIT)
 {
   tree decl = dest.ref;
@@ -936,103 +1082,47 @@ void
 gfc_nullify_descriptor (stmtblock_t *block, tree de

[gcc(refs/users/mikael/heads/refactor_descriptor_v08)] Factorisation set_dimension_bounds/shift_dimension_bounds gfc_set_descriptor_for_assign_realloc

2025-09-20 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:cd8d7c629676655e2464e7bb4e12d4cddae39383

commit cd8d7c629676655e2464e7bb4e12d4cddae39383
Author: Mikael Morin 
Date:   Sun Aug 17 17:05:28 2025 +0200

Factorisation set_dimension_bounds/shift_dimension_bounds 
gfc_set_descriptor_for_assign_realloc

Revert partiel

Diff:
---
 gcc/fortran/trans-descriptor.cc | 39 +++
 1 file changed, 11 insertions(+), 28 deletions(-)

diff --git a/gcc/fortran/trans-descriptor.cc b/gcc/fortran/trans-descriptor.cc
index f2fbe4e77045..510fc984de34 100644
--- a/gcc/fortran/trans-descriptor.cc
+++ b/gcc/fortran/trans-descriptor.cc
@@ -2492,38 +2492,21 @@ gfc_set_descriptor_for_assign_realloc (stmtblock_t 
*block, gfc_loopinfo *loop,
   tree tmp = fold_build2_loc (input_location, MINUS_EXPR,
  gfc_array_index_type,
  loop->to[n], loop->from[n]);
-  tmp = fold_build2_loc (input_location, PLUS_EXPR,
-gfc_array_index_type,
-tmp, gfc_index_one_node);
-
-  tree lbound = gfc_index_one_node;
-  tree ubound = tmp;
+  tree ubound = fold_build2_loc (input_location, PLUS_EXPR,
+gfc_array_index_type,
+tmp, gfc_index_one_node);
 
   if (as)
-   {
- tree lbd = get_std_lbound (expr2, desc2, n,
-as->type == AS_ASSUMED_SIZE);
- ubound = fold_build2_loc (input_location,
-   MINUS_EXPR,
-   gfc_array_index_type,
-   ubound, lbound);
- ubound = fold_build2_loc (input_location,
-   PLUS_EXPR,
-   gfc_array_index_type,
-   ubound, lbd);
- lbound = lbd;
-   }
+   shift_dimension_fields (block, desc, gfc_rank_cst[n],
+   get_std_lbound (expr2, desc2, n,
+   as->type == AS_ASSUMED_SIZE),
+   gfc_index_one_node, ubound, size1, &offset);
+  else
+   set_dimension_fields (block, desc, gfc_rank_cst[n], gfc_index_one_node,
+ ubound, size1, &offset);
 
-  gfc_conv_descriptor_lbound_set (block, desc, gfc_rank_cst[n], lbound);
-  gfc_conv_descriptor_ubound_set (block, desc, gfc_rank_cst[n], ubound);
-  gfc_conv_descriptor_stride_set (block, desc, gfc_rank_cst[n], size1);
-  lbound = gfc_conv_descriptor_lbound_get (desc, gfc_rank_cst[n]);
-  tree tmp2 = fold_build2_loc (input_location, MULT_EXPR, 
gfc_array_index_type,
-  lbound, size1);
-  offset = fold_build2_loc (input_location, MINUS_EXPR,
-   gfc_array_index_type, offset, tmp2);
   size1 = fold_build2_loc (input_location, MULT_EXPR, gfc_array_index_type,
-  tmp, size1);
+  ubound, size1);
 }
 
   /* Set the lhs descriptor and scalarizer offsets.  For rank > 1,


[gcc(refs/users/mikael/heads/refactor_descriptor_v08)] Correction quotation macros m4

2025-09-20 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:a759ce1cfa05679e27ca5261d080c2e4f22a92c7

commit a759ce1cfa05679e27ca5261d080c2e4f22a92c7
Author: Mikael Morin 
Date:   Mon Sep 8 14:41:36 2025 +0200

Correction quotation macros m4

modif quotation

Correction quotation

Retour en arrière partiel PTR_INCREMENT_BYTES

Diff:
---
 libgfortran/m4/ifindloc0.m4 | 28 +++
 libgfortran/m4/ifindloc1.m4 | 22 +--
 libgfortran/m4/ifindloc2.m4 | 24 ++--
 libgfortran/m4/iforeach-s.m4| 38 
 libgfortran/m4/iforeach-s2.m4   | 32 +--
 libgfortran/m4/iforeach.m4  | 40 -
 libgfortran/m4/ifunction-s.m4   | 34 ++--
 libgfortran/m4/ifunction-s2.m4  | 44 ++---
 libgfortran/m4/ifunction.m4 | 38 
 libgfortran/m4/ifunction_logical.m4 |  8 +++
 libgfortran/m4/iparm.m4 |  4 ++--
 libgfortran/m4/maxloc0.m4   | 12 +-
 libgfortran/m4/maxloc0s.m4  |  4 ++--
 libgfortran/m4/maxloc1.m4   | 12 +-
 libgfortran/m4/maxval.m4| 14 ++--
 libgfortran/m4/maxval1s.m4  |  4 ++--
 libgfortran/m4/minloc0.m4   |  6 ++---
 libgfortran/m4/minloc1.m4   | 20 -
 libgfortran/m4/minval.m4| 14 ++--
 19 files changed, 199 insertions(+), 199 deletions(-)

diff --git a/libgfortran/m4/ifindloc0.m4 b/libgfortran/m4/ifindloc0.m4
index 47f311f84d78..c484342f3cb9 100644
--- a/libgfortran/m4/ifindloc0.m4
+++ b/libgfortran/m4/ifindloc0.m4
@@ -79,7 +79,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If 
not, see
 
   if (back)
 {
-  base = array->base_addr + (sz - 1) * 'base_mult`'`;
+  base = array->base_addr + (sz - 1) * 'base_mult`;
 
   while (1)
 {
@@ -92,7 +92,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If 
not, see
 
  return;
}
- base -= sstride[0] * 'base_mult`'`;
+ base -= sstride[0] * 'base_mult`;
} while(++count[0] != extent[0]);
 
  n = 0;
@@ -103,14 +103,14 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  
If not, see
  count[n] = 0;
  /* We could precalculate these products, but this is a less
 frequently used path so probably not worth it.  */
- base += sstride[n] * extent[n] * 'base_mult`'`;
+ base += sstride[n] * extent[n] * 'base_mult`;
  n++;
  if (n >= rank)
return;
  else
{
  count[n]++;
- base -= sstride[n] * 'base_mult`'`;
+ base -= sstride[n] * 'base_mult`;
}
} while (count[n] == extent[n]);  
}
@@ -129,7 +129,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  
If not, see
 
  return;
}
- base += sstride[0] * 'base_mult`'`;
+ base += sstride[0] * 'base_mult`;
} while(++count[0] != extent[0]);
 
  n = 0;
@@ -140,14 +140,14 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  
If not, see
  count[n] = 0;
  /* We could precalculate these products, but this is a less
 frequently used path so probably not worth it.  */
- base -= sstride[n] * extent[n] * 'base_mult`'`;
+ base -= sstride[n] * extent[n] * 'base_mult`;
  n++;
  if (n >= rank)
return;
  else
{
  count[n]++;
- base += sstride[n] * 'base_mult`'`;
+ base += sstride[n] * 'base_mult`;
}
} while (count[n] == extent[n]);
}
@@ -228,7 +228,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  
If not, see
 
   if (back)
 {
-  base = array->base_addr + (sz - 1) * 'base_mult`'`;
+  base = array->base_addr + (sz - 1) * 'base_mult`;
   mbase = mbase + (sz - 1) * mask_kind;
   while (1)
 {
@@ -241,7 +241,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  
If not, see
 
  return;
}
- base -= sstride[0] * 'base_mult`'`;
+ base -= sstride[0] * 'base_mult`;
  mbase -= mstride[0];
} while(++count[0] != extent[0]);
 
@@ -253,7 +253,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  
If not, see
  count[n] = 0;
  /* We could precalculate these products, but this is a less
 frequently used path so probably not worth it.  */
- base += sstride[n] * extent[n] * 'base_mult`'`;
+ base += sstride[n] * extent[n] * 'base_mult`;

[gcc(refs/users/mikael/heads/refactor_descriptor_v08)] Refactoring gfc_set_descriptor_from_scalar

2025-09-20 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:b53111d7efdcab477af41a0e1d6a1a820e67557d

commit b53111d7efdcab477af41a0e1d6a1a820e67557d
Author: Mikael Morin 
Date:   Tue Aug 12 18:57:20 2025 +0200

Refactoring gfc_set_descriptor_from_scalar

Correction pr87992.f90

Diff:
---
 gcc/fortran/trans-descriptor.cc | 83 ++---
 gcc/fortran/trans-descriptor.h  |  3 +-
 gcc/fortran/trans-expr.cc   |  2 +-
 3 files changed, 40 insertions(+), 48 deletions(-)

diff --git a/gcc/fortran/trans-descriptor.cc b/gcc/fortran/trans-descriptor.cc
index 87ddf839a931..9d30f42063ea 100644
--- a/gcc/fortran/trans-descriptor.cc
+++ b/gcc/fortran/trans-descriptor.cc
@@ -600,7 +600,6 @@ tree
 gfc_get_dtype_rank_type_slen (int rank, tree etype, tree length)
 {
   tree ptype;
-  tree size;
   int n;
   tree dtype;
   tree field;
@@ -661,6 +660,7 @@ gfc_get_dtype_rank_type_slen (int rank, tree etype, tree 
length)
   gcc_unreachable ();
 }
 
+  tree size = NULL_TREE;
   switch (n)
 {
 case BT_CHARACTER:
@@ -668,23 +668,24 @@ gfc_get_dtype_rank_type_slen (int rank, tree etype, tree 
length)
   size = gfc_get_character_len_in_bytes (ptype, length);
   break;
 case BT_VOID:
-  gcc_assert (TREE_CODE (ptype) == POINTER_TYPE);
-  size = size_in_bytes (ptype);
+  if (TREE_CODE (ptype) == POINTER_TYPE)
+   size = size_in_bytes (ptype);
   break;
 default:
   size = size_in_bytes (etype);
   break;
 }
 
-  gcc_assert (size);
-
-  STRIP_NOPS (size);
-  size = fold_convert (size_type_node, size);
   tree dtype_type_node = get_dtype_type_node ();
-  field = gfc_advance_chain (TYPE_FIELDS (dtype_type_node),
-GFC_DTYPE_ELEM_LEN);
-  CONSTRUCTOR_APPEND_ELT (v, field,
- fold_convert (TREE_TYPE (field), size));
+  if (size)
+{
+  STRIP_NOPS (size);
+  size = fold_convert (size_type_node, size);
+  field = gfc_advance_chain (TYPE_FIELDS (dtype_type_node),
+GFC_DTYPE_ELEM_LEN);
+  CONSTRUCTOR_APPEND_ELT (v, field,
+ fold_convert (TREE_TYPE (field), size));
+}
   field = gfc_advance_chain (TYPE_FIELDS (dtype_type_node),
 GFC_DTYPE_VERSION);
   CONSTRUCTOR_APPEND_ELT (v, field,
@@ -936,56 +937,46 @@ gfc_create_null_actual_descriptor (stmtblock_t *block, 
gfc_typespec *ts,
 
 
 void
-gfc_set_descriptor_from_scalar_class (stmtblock_t *block, tree descr,
- tree scalar, gfc_expr *scalar_expr)
-{
-  tree type = gfc_get_scalar_to_descriptor_type (TREE_TYPE (scalar),
-gfc_expr_attr (scalar_expr));
-  gfc_conv_descriptor_dtype_set (block, descr,
-gfc_get_dtype (type));
-
-  tree tmp = gfc_class_data_get (scalar);
-  if (!POINTER_TYPE_P (TREE_TYPE (tmp)))
-tmp = gfc_build_addr_expr (NULL_TREE, tmp);
-
-  gfc_conv_descriptor_data_set (block, descr, tmp);
-}
-
-
-void
-gfc_set_descriptor_from_scalar (stmtblock_t *block, tree descr,
-   tree scalar, gfc_expr *scalar_expr,
-   tree cond_presence, tree caf_token)
+gfc_set_descriptor_from_scalar (stmtblock_t *block, tree descr, tree scalar,
+   symbol_attribute attr,
+   tree cond_presence = NULL_TREE,
+   tree caf_token = NULL_TREE)
 {
   if (flag_coarray == GFC_FCOARRAY_LIB && caf_token)
 gfc_conv_descriptor_token_set (block, descr, caf_token);
 
-  tree type = gfc_get_scalar_to_descriptor_type (TREE_TYPE (scalar),
-gfc_expr_attr (scalar_expr));
-  gfc_conv_descriptor_dtype_set (block, descr,
-gfc_get_dtype (type));
+  tree type = gfc_get_scalar_to_descriptor_type (TREE_TYPE (scalar), attr);
+  if (!POINTER_TYPE_P (TREE_TYPE (scalar)))
+scalar = gfc_build_addr_expr (NULL_TREE, scalar);
   if (cond_presence)
 scalar = build3_loc (input_location, COND_EXPR,
 TREE_TYPE (scalar),
 cond_presence, scalar,
 fold_convert (TREE_TYPE (scalar),
   null_pointer_node));
+
+  gfc_conv_descriptor_dtype_set (block, descr, gfc_get_dtype (type));
   gfc_conv_descriptor_data_set (block, descr, scalar);
+  gfc_conv_descriptor_span_set (block, descr,
+   gfc_conv_descriptor_elem_len_get (descr));
 }
 
 
 void
-gfc_set_descriptor_from_scalar (stmtblock_t *block, tree descr, tree scalar)
+gfc_set_descriptor_from_scalar_class (stmtblock_t *block, tree descr,
+ tree scalar, gfc_expr *scalar_expr)
 {
-  tree etype = TREE_TYPE (scalar);
-  if (!POINTER_TYPE_P (TREE_TYPE (scalar)))
-scalar = gfc_build_addr_expr (NULL_TREE, scalar);
-  else if (TREE_TYPE (etype) && TREE_CODE (TREE_

[gcc(refs/users/mikael/heads/refactor_descriptor_v08)] Renseignement token dans gcf_set_descriptor_from_scalar

2025-09-20 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:5207d0e1525ec3e85d6fabc8c1422636c1dc4773

commit 5207d0e1525ec3e85d6fabc8c1422636c1dc4773
Author: Mikael Morin 
Date:   Wed Jul 23 09:44:49 2025 +0200

Renseignement token dans gcf_set_descriptor_from_scalar

Correction renseignement token

Diff:
---
 gcc/fortran/trans-descriptor.cc | 10 ++
 gcc/fortran/trans-descriptor.h  |  2 +-
 gcc/fortran/trans-expr.cc   | 16 +++-
 3 files changed, 18 insertions(+), 10 deletions(-)

diff --git a/gcc/fortran/trans-descriptor.cc b/gcc/fortran/trans-descriptor.cc
index 253d6638f2ed..87ddf839a931 100644
--- a/gcc/fortran/trans-descriptor.cc
+++ b/gcc/fortran/trans-descriptor.cc
@@ -955,11 +955,13 @@ gfc_set_descriptor_from_scalar_class (stmtblock_t *block, 
tree descr,
 void
 gfc_set_descriptor_from_scalar (stmtblock_t *block, tree descr,
tree scalar, gfc_expr *scalar_expr,
-   tree cond_presence)
+   tree cond_presence, tree caf_token)
 {
-  tree type;
-  type = gfc_get_scalar_to_descriptor_type (TREE_TYPE (scalar),
-   gfc_expr_attr (scalar_expr));
+  if (flag_coarray == GFC_FCOARRAY_LIB && caf_token)
+gfc_conv_descriptor_token_set (block, descr, caf_token);
+
+  tree type = gfc_get_scalar_to_descriptor_type (TREE_TYPE (scalar),
+gfc_expr_attr (scalar_expr));
   gfc_conv_descriptor_dtype_set (block, descr,
 gfc_get_dtype (type));
   if (cond_presence)
diff --git a/gcc/fortran/trans-descriptor.h b/gcc/fortran/trans-descriptor.h
index 79db264c91c1..9284320f0ba1 100644
--- a/gcc/fortran/trans-descriptor.h
+++ b/gcc/fortran/trans-descriptor.h
@@ -103,6 +103,6 @@ void gfc_init_descriptor_variable (stmtblock_t *block, 
gfc_symbol *sym, tree des
 void gfc_set_descriptor_from_scalar_class (stmtblock_t *, tree, tree, gfc_expr 
*);
 void gfc_set_descriptor_from_scalar (stmtblock_t *, tree, tree);
 void gfc_set_descriptor_from_scalar (stmtblock_t *, tree, tree, gfc_expr *,
-tree);
+tree, tree);
 
 #endif /* GFC_TRANS_DESCRIPTOR_H */
diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc
index 708e13067119..ed6ecc8417cb 100644
--- a/gcc/fortran/trans-expr.cc
+++ b/gcc/fortran/trans-expr.cc
@@ -806,6 +806,7 @@ gfc_conv_derived_to_class (gfc_se *parmse, gfc_expr *e, 
gfc_symbol *fsym,
   tree var;
   tree tmp;
   tree packed = NULL_TREE;
+  tree caf_token = NULL_TREE;
 
   /* The derived type needs to be converted to a temporary CLASS object.  */
   tmp = gfc_typenode_for_spec (&fsym->ts);
@@ -822,12 +823,17 @@ gfc_conv_derived_to_class (gfc_se *parmse, gfc_expr *e, 
gfc_symbol *fsym,
 
   if (flag_coarray == GFC_FCOARRAY_LIB && CLASS_DATA (fsym)->attr.codimension)
 {
-  tree token;
   tmp = gfc_get_tree_for_caf_expr (e);
   if (POINTER_TYPE_P (TREE_TYPE (tmp)))
tmp = build_fold_indirect_ref (tmp);
-  gfc_get_caf_token_offset (parmse, &token, nullptr, tmp, NULL_TREE, e);
-  gfc_conv_descriptor_token_set (&parmse->pre, ctree, token);
+  gfc_get_caf_token_offset (parmse, &caf_token, nullptr, tmp, NULL_TREE, 
e);
+  /* Update the token here, unless it's done elsewhere like in
+ gfc_set_descriptor_from_scalar.  */
+  if ((parmse->expr && POINTER_TYPE_P (TREE_TYPE (parmse->expr)))
+  || (parmse->ss && parmse->ss->info && parmse->ss->info->useflags)
+  || e->rank != 0
+  || fsym->ts.u.derived->components->as == nullptr)
+   gfc_conv_descriptor_token_set (&parmse->pre, ctree, caf_token);
 }
 
   if (optional)
@@ -893,8 +899,8 @@ gfc_conv_derived_to_class (gfc_se *parmse, gfc_expr *e, 
gfc_symbol *fsym,
 
  /* Scalar to an assumed-rank array.  */
  if (fsym->ts.u.derived->components->as)
-   gfc_set_descriptor_from_scalar (&parmse->pre, ctree,
-   parmse->expr, e, cond_optional);
+   gfc_set_descriptor_from_scalar (&parmse->pre, ctree, parmse->expr,
+   e, cond_optional, caf_token);
   else
{
  tmp = fold_convert (TREE_TYPE (ctree), parmse->expr);


[gcc(refs/users/mikael/heads/refactor_descriptor_v08)] Introduction gfc_conv_descriptor_extent_get

2025-09-20 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:b9cb2239e58ba0191b0a1dce20a4c80bc2300556

commit b9cb2239e58ba0191b0a1dce20a4c80bc2300556
Author: Mikael Morin 
Date:   Sat Sep 6 16:34:11 2025 +0200

Introduction gfc_conv_descriptor_extent_get

Modif implémentation descriptor_extent_get

Correction motif bind_c_array_params_2

Ajout motif dump coarray_lock_7

Correction dump intrinsic_size_3

Mise à jour motif dump pr48636

Correction motif dump intrinsic_size_3

Correction motif dump bind_c_array_params_2

Correction motif dump coarray_lock_7

Diff:
---
 gcc/fortran/trans-array.cc | 20 ++---
 gcc/fortran/trans-decl.cc  |  6 +---
 gcc/fortran/trans-descriptor.cc| 34 +++---
 gcc/fortran/trans-descriptor.h |  1 +
 gcc/fortran/trans-expr.cc  |  9 ++
 gcc/fortran/trans-intrinsic.cc | 30 +--
 gcc/fortran/trans-openmp.cc| 34 --
 gcc/fortran/trans-stmt.cc  | 10 +++
 .../gfortran.dg/bind_c_array_params_2.f90  |  2 +-
 gcc/testsuite/gfortran.dg/coarray_lock_7.f90   |  4 +--
 gcc/testsuite/gfortran.dg/intrinsic_size_3.f90 |  2 +-
 gcc/testsuite/gfortran.dg/pr48636.f90  |  2 +-
 12 files changed, 46 insertions(+), 108 deletions(-)

diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc
index 885f7440f3a2..92680c4b0fb0 100644
--- a/gcc/fortran/trans-array.cc
+++ b/gcc/fortran/trans-array.cc
@@ -7972,13 +7972,8 @@ gfc_tree_array_size (stmtblock_t *block, tree desc, 
gfc_expr *expr, tree dim)
 {
   if (!dim)
dim = gfc_index_zero_node;
-  tree ubound = gfc_conv_descriptor_ubound_get (desc, dim);
-  tree lbound = gfc_conv_descriptor_lbound_get (desc, dim);
 
-  size = fold_build2_loc (input_location, MINUS_EXPR,
- gfc_array_index_type, ubound, lbound);
-  size = fold_build2_loc (input_location, PLUS_EXPR, gfc_array_index_type,
- size, gfc_index_one_node);
+  size = gfc_conv_descriptor_extent_get (desc, dim);
   /* if (!allocatable && !pointer && assumed rank)
   size = (idx == rank && ubound[rank-1] == -1 ? -1 : size;
 else
@@ -8039,11 +8034,7 @@ gfc_tree_array_size (stmtblock_t *block, tree desc, 
gfc_expr *expr, tree dim)
   cond = fold_build2_loc (input_location, TRUTH_AND_EXPR, 
boolean_type_node,
  cond, tmp);
 }
-  tmp = fold_build2_loc (input_location, MINUS_EXPR, gfc_array_index_type,
-gfc_conv_descriptor_ubound_get (desc, idx),
-gfc_conv_descriptor_lbound_get (desc, idx));
-  tmp = fold_build2_loc (input_location, PLUS_EXPR, gfc_array_index_type,
-tmp, gfc_index_one_node);
+  tmp = gfc_conv_descriptor_extent_get (desc, idx);
   gfc_add_modify (&cond_block, extent, tmp);
   tmp = fold_build2_loc (input_location, LT_EXPR, boolean_type_node,
 extent, gfc_index_zero_node);
@@ -8610,12 +8601,7 @@ gfc_full_array_size (stmtblock_t *block, tree decl, int 
rank)
 idx = gfc_conv_descriptor_rank_get (decl);
   else
 idx = gfc_rank_cst[rank - 1];
-  nelems = gfc_conv_descriptor_ubound_get (decl, idx);
-  tmp = gfc_conv_descriptor_lbound_get (decl, idx);
-  tmp = fold_build2_loc (input_location, MINUS_EXPR, gfc_array_index_type,
-nelems, tmp);
-  tmp = fold_build2_loc (input_location, PLUS_EXPR, gfc_array_index_type,
-tmp, gfc_index_one_node);
+  tmp = gfc_conv_descriptor_extent_get (decl, idx);
   tmp = gfc_evaluate_now (tmp, block);
 
   nelems = gfc_conv_descriptor_stride_get (decl, idx);
diff --git a/gcc/fortran/trans-decl.cc b/gcc/fortran/trans-decl.cc
index 9f5200f34d33..64ca5d76e6c8 100644
--- a/gcc/fortran/trans-decl.cc
+++ b/gcc/fortran/trans-decl.cc
@@ -7621,11 +7621,7 @@ done:
   gfc_add_modify (&loop_body, gfc_get_cfi_dim_lbound (cfi, idx),
  gfc_conv_descriptor_lbound_get (gfc_desc, idx));
   /* cfi->dim[i].extent = gfc->dim[i].ubound - gfc->dim[i].lbound + 1.  */
-  tmp = fold_build2_loc (input_location, MINUS_EXPR, gfc_array_index_type,
-gfc_conv_descriptor_ubound_get (gfc_desc, idx),
-gfc_conv_descriptor_lbound_get (gfc_desc, idx));
-  tmp = fold_build2_loc (input_location, PLUS_EXPR, gfc_array_index_type, tmp,
-gfc_index_one_node);
+  tmp = gfc_conv_descriptor_extent_get (gfc_desc, idx);
   gfc_add_modify (&loop_body, gfc_get_cfi_dim_extent (cfi, idx), tmp);
   /* d->dim[n].sm = gfc->dim[i].stride  * gfc->span); */
   tmp = fold_build2_loc (input_location, MULT_EXPR, gfc_array_index_type,
diff --git a/gcc/fortran/trans-descriptor.cc b/gcc/fortran/trans-descriptor.cc
index 9b296f17ed14..556a749fad

[gcc(refs/users/mikael/heads/refactor_descriptor_v08)] Factorisation set_dimension_fields gfc_set_descriptor_with_shape

2025-09-20 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:6ce639860b0db5eed334e179fac445d852268e56

commit 6ce639860b0db5eed334e179fac445d852268e56
Author: Mikael Morin 
Date:   Sat Aug 16 18:19:27 2025 +0200

Factorisation set_dimension_fields gfc_set_descriptor_with_shape

Correction régression c_f_pointer_tests_4

Diff:
---
 gcc/fortran/trans-descriptor.cc | 18 --
 1 file changed, 4 insertions(+), 14 deletions(-)

diff --git a/gcc/fortran/trans-descriptor.cc b/gcc/fortran/trans-descriptor.cc
index ce7495ab1f34..6ada111b9e6e 100644
--- a/gcc/fortran/trans-descriptor.cc
+++ b/gcc/fortran/trans-descriptor.cc
@@ -1995,15 +1995,12 @@ gfc_set_descriptor_with_shape (stmtblock_t *block, tree 
desc, tree ptr,
   gfc_conv_expr (&lowerse, lower);
   gfc_add_block_to_block (&body, &lowerse.pre);
   lbound = fold_convert (gfc_array_index_type, lowerse.expr);
+  lbound = gfc_evaluate_now (lbound, &body);
   gfc_add_block_to_block (&body, &lowerse.post);
 }
   else
 lbound = gfc_index_one_node;
 
-  /* Set bounds and stride.  */
-  gfc_conv_descriptor_lbound_set (&body, desc, dim, lbound);
-  gfc_conv_descriptor_stride_set (&body, desc, dim, stride);
-
   gfc_conv_expr (&shapese, shape);
   gfc_add_block_to_block (&body, &shapese.pre);
   tree shapeval = fold_convert (gfc_array_index_type, shapese.expr);
@@ -2012,29 +2009,22 @@ gfc_set_descriptor_with_shape (stmtblock_t *block, tree 
desc, tree ptr,
 lbound, gfc_index_one_node);
   tree ubound = fold_build2_loc (input_location, PLUS_EXPR,
 gfc_array_index_type, tmp, shapeval);
-  gfc_conv_descriptor_ubound_set (&body, desc, dim, ubound);
+  ubound = gfc_evaluate_now (ubound, &body);
   gfc_add_block_to_block (&body, &shapese.post);
 
-  /* Calculate offset.  */
-  tmp = fold_build2_loc (input_location, MULT_EXPR, gfc_array_index_type,
-stride, lbound);
-  gfc_add_modify (&body, offset,
- fold_build2_loc (input_location, PLUS_EXPR,
-  gfc_array_index_type, offset, tmp));
+  set_dimension_fields (&body, desc, dim, lbound, ubound, stride, offset);
 
   /* Update stride.  */
   gfc_add_modify (&body, stride,
  fold_build2_loc (input_location, MULT_EXPR,
   gfc_array_index_type, stride, shapeval));
+
   /* Finish scalarization loop.  */
   gfc_trans_scalarizing_loops (&loop, &body);
   gfc_add_block_to_block (block, &loop.pre);
   gfc_add_block_to_block (block, &loop.post);
   gfc_cleanup_loop (&loop);
 
-  gfc_add_modify (block, offset,
- fold_build1_loc (input_location, NEGATE_EXPR,
-  gfc_array_index_type, offset));
   gfc_conv_descriptor_offset_set (block, desc, offset);
 }


[gcc(refs/users/mikael/heads/refactor_descriptor_v08)] Factorisation set_dimension_fields gfc_set_descriptor

2025-09-20 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:215eb06af7873eb0c10f393382343db0703ea2fc

commit 215eb06af7873eb0c10f393382343db0703ea2fc
Author: Mikael Morin 
Date:   Sat Aug 16 18:11:01 2025 +0200

Factorisation set_dimension_fields gfc_set_descriptor

Diff:
---
 gcc/fortran/trans-descriptor.cc | 17 ++---
 1 file changed, 2 insertions(+), 15 deletions(-)

diff --git a/gcc/fortran/trans-descriptor.cc b/gcc/fortran/trans-descriptor.cc
index d16127cf3ed7..ce7495ab1f34 100644
--- a/gcc/fortran/trans-descriptor.cc
+++ b/gcc/fortran/trans-descriptor.cc
@@ -1860,27 +1860,14 @@ gfc_set_descriptor (stmtblock_t *block, tree dest, tree 
src, gfc_expr *src_expr,
   tree from = lowers[dim];
   tree to = uppers[dim];
 
-  gfc_conv_descriptor_lbound_set (block, dest,
- gfc_rank_cst[dim], from);
-
-  /* Set the new upper bound.  */
-  gfc_conv_descriptor_ubound_set (block, dest,
- gfc_rank_cst[dim], to);
-
   /* Multiply the stride by the section stride to get the
 total stride.  */
   stride = fold_build2_loc (input_location, MULT_EXPR,
gfc_array_index_type,
stride, info->stride[n]);
 
-  tmp = fold_build2_loc (input_location, MULT_EXPR,
-TREE_TYPE (offset), stride, from);
-  offset = fold_build2_loc (input_location, MINUS_EXPR,
-  TREE_TYPE (offset), offset, tmp);
-
-  /* Store the new stride.  */
-  gfc_conv_descriptor_stride_set (block, dest,
- gfc_rank_cst[dim], stride);
+  set_dimension_fields (block, dest, gfc_rank_cst[dim], from, to, stride,
+   &offset);
 }
 
   for (int n = rank; n < rank + corank; n++)


[gcc(refs/users/mikael/heads/refactor_descriptor_v08)] Refactor gfc_init_descriptor_variable

2025-09-20 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:591c36977752d909f74126133cbe7d07092b371d

commit 591c36977752d909f74126133cbe7d07092b371d
Author: Mikael Morin 
Date:   Wed Aug 6 21:29:10 2025 +0200

Refactor gfc_init_descriptor_variable

Diff:
---
 gcc/fortran/trans-descriptor.cc | 23 ---
 1 file changed, 20 insertions(+), 3 deletions(-)

diff --git a/gcc/fortran/trans-descriptor.cc b/gcc/fortran/trans-descriptor.cc
index b0ade4a70862..d2b908c875b2 100644
--- a/gcc/fortran/trans-descriptor.cc
+++ b/gcc/fortran/trans-descriptor.cc
@@ -843,13 +843,14 @@ gfc_init_static_descriptor (tree descr)
 
 
 void
-gfc_init_descriptor_variable (stmtblock_t *block, gfc_symbol *sym, tree descr)
+gfc_init_descriptor_variable (stmtblock_t *block, gfc_symbol *sym, gfc_expr 
*expr, tree descr)
 {
   symbol_attribute attr = gfc_symbol_attr (sym);
 
   /* NULLIFY the data pointer for non-saved allocatables, or for non-saved
  pointers when -fcheck=pointer is specified.  */
   if (attr.allocatable
+  || attr.optional
   || (attr.pointer && (gfc_option.rtcheck & GFC_RTCHECK_POINTER)))
 {
   gfc_conv_descriptor_data_set (block, descr, null_pointer_node);
@@ -863,8 +864,24 @@ gfc_init_descriptor_variable (stmtblock_t *block, 
gfc_symbol *sym, tree descr)
   else
 as = sym->as;
 
-  gcc_assert (as && as->rank >= 0);
+  int rank;
+  if (as == nullptr)
+rank = 0;
+  else if (as->type != AS_ASSUMED_RANK)
+rank = as->rank;
+  else if (expr)
+rank = expr->rank;
+  else
+rank = -1;
+
   tree etype = gfc_get_element_type (TREE_TYPE (descr));
   gfc_conv_descriptor_dtype_set (block, descr,
-gfc_get_dtype_rank_type (as->rank, etype));
+gfc_get_dtype_rank_type (rank, etype));
+}
+
+
+void
+gfc_init_descriptor_variable (stmtblock_t *block, gfc_symbol *sym, tree descr)
+{
+  return gfc_init_descriptor_variable (block, sym, nullptr, descr);
 }


[gcc(refs/users/mikael/heads/refactor_descriptor_v08)] Extraction gfc_copy_descriptor

2025-09-20 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:f20d1d53e139de278a6f23daa86ecf55211d3cfb

commit f20d1d53e139de278a6f23daa86ecf55211d3cfb
Author: Mikael Morin 
Date:   Wed Jul 16 22:09:17 2025 +0200

Extraction gfc_copy_descriptor

Diff:
---
 gcc/fortran/trans-array.cc  | 25 ++---
 gcc/fortran/trans-descriptor.cc | 33 +
 gcc/fortran/trans-descriptor.h  |  1 +
 3 files changed, 36 insertions(+), 23 deletions(-)

diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc
index 123e7de97566..4572d16313fa 100644
--- a/gcc/fortran/trans-array.cc
+++ b/gcc/fortran/trans-array.cc
@@ -7871,29 +7871,8 @@ gfc_conv_expr_descriptor (gfc_se *se, gfc_expr *expr)
   if (full && !transposed_dims (ss))
{
  if (se->direct_byref && !se->byref_noassign)
-   {
- struct lang_type *lhs_ls
-   = TYPE_LANG_SPECIFIC (TREE_TYPE (se->expr)),
-   *rhs_ls = TYPE_LANG_SPECIFIC (TREE_TYPE (desc));
- /* When only the array_kind differs, do a view_convert.  */
- tmp = lhs_ls && rhs_ls && lhs_ls->rank == rhs_ls->rank
-   && lhs_ls->akind != rhs_ls->akind
- ? build1 (VIEW_CONVERT_EXPR, TREE_TYPE (se->expr), desc)
- : desc;
- /* Copy the descriptor for pointer assignments.  */
- gfc_add_modify (&se->pre, se->expr, tmp);
-
- /* Add any offsets from subreferences.  */
- gfc_get_dataptr_offset (&se->pre, se->expr, desc, NULL_TREE,
- subref_array_target, expr);
-
- /* and set the span field.  */
- if (ss_info->expr->ts.type == BT_CHARACTER)
-   tmp = gfc_conv_descriptor_span_get (desc);
- else
-   tmp = gfc_get_array_span (desc, expr);
- gfc_conv_descriptor_span_set (&se->pre, se->expr, tmp);
-   }
+   gfc_copy_descriptor (&se->pre, se->expr, desc, expr,
+subref_array_target);
  else if (se->want_pointer)
{
  /* We pass full arrays directly.  This means that pointers and
diff --git a/gcc/fortran/trans-descriptor.cc b/gcc/fortran/trans-descriptor.cc
index d5ca4d4fb82f..8b80c332f47d 100644
--- a/gcc/fortran/trans-descriptor.cc
+++ b/gcc/fortran/trans-descriptor.cc
@@ -1270,3 +1270,36 @@ gfc_copy_sequence_descriptor (stmtblock_t *block, tree 
dest, tree src, int rank)
gfc_conv_descriptor_span_get (src));
   gfc_conv_descriptor_offset_set (block, dest, gfc_index_zero_node);
 }
+
+
+void
+gfc_copy_descriptor (stmtblock_t *block, tree dest, tree src,
+gfc_expr *src_expr, bool subref)
+{
+  struct lang_type *dest_ls = TYPE_LANG_SPECIFIC (TREE_TYPE (dest));
+  struct lang_type *src_ls = TYPE_LANG_SPECIFIC (TREE_TYPE (src));
+
+  /* When only the array_kind differs, do a view_convert.  */
+  tree tmp1;
+  if (dest_ls
+  && src_ls
+  && dest_ls->rank == src_ls->rank
+  && dest_ls->akind != src_ls->akind)
+tmp1 = build1 (VIEW_CONVERT_EXPR, TREE_TYPE (dest), src);
+  else
+tmp1 = src;
+
+  /* Copy the descriptor for pointer assignments.  */
+  gfc_add_modify (block, dest, tmp1);
+
+  /* Add any offsets from subreferences.  */
+  gfc_get_dataptr_offset (block, dest, src, NULL_TREE, subref, src_expr);
+
+  /* and set the span field.  */
+  tree tmp2;
+  if (src_expr->ts.type == BT_CHARACTER)
+tmp2 = gfc_conv_descriptor_span_get (src);
+  else
+tmp2 = gfc_get_array_span (src, src_expr);
+  gfc_conv_descriptor_span_set (block, dest, tmp2);
+}
diff --git a/gcc/fortran/trans-descriptor.h b/gcc/fortran/trans-descriptor.h
index cb920ff2cbbb..3a22abab72c2 100644
--- a/gcc/fortran/trans-descriptor.h
+++ b/gcc/fortran/trans-descriptor.h
@@ -108,6 +108,7 @@ void gfc_shift_descriptor (stmtblock_t *, tree, int, tree 
[GFC_MAX_DIMENSIONS],
   tree [GFC_MAX_DIMENSIONS]);
 
 void gfc_copy_sequence_descriptor (stmtblock_t *, tree, tree, int);
+void gfc_copy_descriptor (stmtblock_t *, tree, tree, gfc_expr *, bool);
 
 void gfc_set_descriptor_from_scalar_class (stmtblock_t *, tree, tree, gfc_expr 
*);
 void gfc_set_descriptor_from_scalar (stmtblock_t *, tree, tree, 
symbol_attribute,


[gcc(refs/users/mikael/heads/refactor_descriptor_v08)] Extraction gfc_copy_descriptor

2025-09-20 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:858f47328be1ff546d3cddfdea47ef2b84fe7ec1

commit 858f47328be1ff546d3cddfdea47ef2b84fe7ec1
Author: Mikael Morin 
Date:   Thu Jul 31 20:42:28 2025 +0200

Extraction gfc_copy_descriptor

Diff:
---
 gcc/fortran/trans-descriptor.cc | 24 
 gcc/fortran/trans-descriptor.h  |  1 +
 gcc/fortran/trans-expr.cc   | 23 +++
 3 files changed, 28 insertions(+), 20 deletions(-)

diff --git a/gcc/fortran/trans-descriptor.cc b/gcc/fortran/trans-descriptor.cc
index 7fcd8a8bb207..66fa9d57b725 100644
--- a/gcc/fortran/trans-descriptor.cc
+++ b/gcc/fortran/trans-descriptor.cc
@@ -1305,6 +1305,30 @@ gfc_copy_descriptor (stmtblock_t *block, tree dest, tree 
src,
 }
 
 
+void
+gfc_copy_descriptor (stmtblock_t *block, tree dest, tree src, bool lhs_type)
+{
+  gfc_conv_descriptor_data_set (block, dest,
+   gfc_conv_descriptor_data_get (src));
+  gfc_conv_descriptor_offset_set (block, dest,
+ gfc_conv_descriptor_offset_get (src));
+
+  gfc_conv_descriptor_dtype_set (block, dest,
+gfc_conv_descriptor_dtype_get (src));
+
+  /* Assign the dimension as range-ref.  */
+  tree tmp = gfc_get_descriptor_dimension (dest);
+  tree tmp2 = gfc_get_descriptor_dimension (src);
+
+  tree type = lhs_type ? TREE_TYPE (tmp) : TREE_TYPE (tmp2);
+  tmp = build4_loc (input_location, ARRAY_RANGE_REF, type, tmp,
+   gfc_index_zero_node, NULL_TREE, NULL_TREE);
+  tmp2 = build4_loc (input_location, ARRAY_RANGE_REF, type, tmp2,
+gfc_index_zero_node, NULL_TREE, NULL_TREE);
+  gfc_add_modify (block, tmp, tmp2);
+}
+
+
 void
 gfc_copy_descriptor (stmtblock_t *block, tree dest, tree src, tree ptr,
 int rank, gfc_ss *ss)
diff --git a/gcc/fortran/trans-descriptor.h b/gcc/fortran/trans-descriptor.h
index ab4d1755132a..44f6d51dc6cd 100644
--- a/gcc/fortran/trans-descriptor.h
+++ b/gcc/fortran/trans-descriptor.h
@@ -110,6 +110,7 @@ void gfc_shift_descriptor (stmtblock_t *, tree, int, tree 
[GFC_MAX_DIMENSIONS],
 void gfc_copy_sequence_descriptor (stmtblock_t *, tree, tree, int);
 void gfc_copy_descriptor (stmtblock_t *, tree, tree, gfc_expr *, bool);
 void gfc_copy_descriptor (stmtblock_t *, tree, tree, tree, int, gfc_ss *);
+void gfc_copy_descriptor (stmtblock_t *, tree, tree, bool);
 
 void gfc_set_descriptor_from_scalar_class (stmtblock_t *, tree, tree, gfc_expr 
*);
 void gfc_set_descriptor_from_scalar (stmtblock_t *, tree, tree, 
symbol_attribute,
diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc
index e6434f56cb22..b989e7aecb19 100644
--- a/gcc/fortran/trans-expr.cc
+++ b/gcc/fortran/trans-expr.cc
@@ -760,32 +760,15 @@ gfc_get_vptr_from_expr (tree expr)
   return NULL_TREE;
 }
 
+
 void
 gfc_class_array_data_assign (stmtblock_t *block, tree lhs_desc, tree rhs_desc,
 bool lhs_type)
 {
-  tree tmp, tmp2, type;
-
-  gfc_conv_descriptor_data_set (block, lhs_desc,
-   gfc_conv_descriptor_data_get (rhs_desc));
-  gfc_conv_descriptor_offset_set (block, lhs_desc,
- gfc_conv_descriptor_offset_get (rhs_desc));
-
-  gfc_conv_descriptor_dtype_set (block, lhs_desc,
-gfc_conv_descriptor_dtype_get (rhs_desc));
-
-  /* Assign the dimension as range-ref.  */
-  tmp = gfc_get_descriptor_dimension (lhs_desc);
-  tmp2 = gfc_get_descriptor_dimension (rhs_desc);
-
-  type = lhs_type ? TREE_TYPE (tmp) : TREE_TYPE (tmp2);
-  tmp = build4_loc (input_location, ARRAY_RANGE_REF, type, tmp,
-   gfc_index_zero_node, NULL_TREE, NULL_TREE);
-  tmp2 = build4_loc (input_location, ARRAY_RANGE_REF, type, tmp2,
-gfc_index_zero_node, NULL_TREE, NULL_TREE);
-  gfc_add_modify (block, tmp, tmp2);
+  gfc_copy_descriptor (block, lhs_desc, rhs_desc, lhs_type);
 }
 
+
 /* Takes a derived type expression and returns the address of a temporary
class object of the 'declared' type.  If opt_vptr_src is not NULL, this is
used for the temporary class object.


[gcc(refs/users/mikael/heads/refactor_descriptor_v08)] Extraction gfc_conv_remap_descriptor

2025-09-20 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:e1f024a6468215891ef9f8380561259c45a93e80

commit e1f024a6468215891ef9f8380561259c45a93e80
Author: Mikael Morin 
Date:   Wed Jul 23 17:07:24 2025 +0200

Extraction gfc_conv_remap_descriptor

Diff:
---
 gcc/fortran/trans-descriptor.cc | 105 +
 gcc/fortran/trans-descriptor.h  |   3 ++
 gcc/fortran/trans-expr.cc   | 111 +---
 3 files changed, 110 insertions(+), 109 deletions(-)

diff --git a/gcc/fortran/trans-descriptor.cc b/gcc/fortran/trans-descriptor.cc
index 43aa236acfb7..3df958c4ec86 100644
--- a/gcc/fortran/trans-descriptor.cc
+++ b/gcc/fortran/trans-descriptor.cc
@@ -1396,3 +1396,108 @@ gfc_copy_descriptor (stmtblock_t *block, tree dest, 
tree src, tree ptr,
 
   gfc_conv_descriptor_data_set (block, dest, ptr);
 }
+
+
+void
+gfc_conv_remap_descriptor (stmtblock_t *block, tree dest, int dest_rank,
+  tree src, int src_rank, gfc_array_ref *ar)
+{
+  /* Set dtype.  */
+  gfc_conv_descriptor_dtype_set (block, dest,
+gfc_get_dtype (TREE_TYPE (dest)));
+
+  /* Copy data pointer.  */
+  gfc_conv_descriptor_data_set (block, dest,
+   gfc_conv_descriptor_data_get (src));
+
+  /* Copy the span.  */
+  tree span;
+  if (VAR_P (src)
+  && GFC_DECL_PTR_ARRAY_P (src))
+span = gfc_conv_descriptor_span_get (src);
+  else
+{
+  tree tmp = TREE_TYPE (src);
+  tmp = TYPE_SIZE_UNIT (gfc_get_element_type (tmp));
+  span = fold_convert (gfc_array_index_type, tmp);
+}
+  gfc_conv_descriptor_span_set (block, dest, span);
+
+  /* Copy offset but adjust it such that it would correspond
+ to a lbound of zero.  */
+  if (src_rank == -1)
+gfc_conv_descriptor_offset_set (block, dest,
+   gfc_index_zero_node);
+  else
+{
+  tree offs = gfc_conv_descriptor_offset_get (src);
+  for (int dim = 0; dim < src_rank; ++dim)
+   {
+ tree stride = gfc_conv_descriptor_stride_get (src, gfc_rank_cst[dim]);
+ tree lbound = gfc_conv_descriptor_lbound_get (src, gfc_rank_cst[dim]);
+ tree tmp = fold_build2_loc (input_location, MULT_EXPR,
+ gfc_array_index_type, stride, lbound);
+ offs = fold_build2_loc (input_location, PLUS_EXPR,
+ gfc_array_index_type, offs, tmp);
+   }
+  gfc_conv_descriptor_offset_set (block, dest, offs);
+}
+
+  /* Set the bounds as declared for the LHS and calculate strides as
+ well as another offset update accordingly.  */
+  tree stride = gfc_conv_descriptor_stride_get (src, gfc_rank_cst[0]);
+  for (int dim = 0; dim < dest_rank; ++dim)
+{
+  gfc_se lower_se;
+  gfc_se upper_se;
+
+  gcc_assert (ar->start[dim] && ar->end[dim]);
+
+  if (ar->start[dim]->expr_type != EXPR_CONSTANT
+ || ar->start[dim]->expr_type != EXPR_VARIABLE)
+   gfc_resolve_expr (ar->start[dim]);
+  if (ar->end[dim]->expr_type != EXPR_CONSTANT
+ || ar->end[dim]->expr_type != EXPR_VARIABLE)
+   gfc_resolve_expr (ar->end[dim]);
+
+  /* Convert declared bounds.  */
+  gfc_init_se (&lower_se, NULL);
+  gfc_init_se (&upper_se, NULL);
+  gfc_conv_expr (&lower_se, ar->start[dim]);
+  gfc_conv_expr (&upper_se, ar->end[dim]);
+
+  gfc_add_block_to_block (block, &lower_se.pre);
+  gfc_add_block_to_block (block, &upper_se.pre);
+
+  tree lbound = fold_convert (gfc_array_index_type, lower_se.expr);
+  tree ubound = fold_convert (gfc_array_index_type, upper_se.expr);
+
+  lbound = gfc_evaluate_now (lbound, block);
+  ubound = gfc_evaluate_now (ubound, block);
+
+  gfc_add_block_to_block (block, &lower_se.post);
+  gfc_add_block_to_block (block, &upper_se.post);
+
+  /* Set bounds in descriptor.  */
+  gfc_conv_descriptor_lbound_set (block, dest, gfc_rank_cst[dim], lbound);
+  gfc_conv_descriptor_ubound_set (block, dest, gfc_rank_cst[dim], ubound);
+
+  /* Set stride.  */
+  stride = gfc_evaluate_now (stride, block);
+  gfc_conv_descriptor_stride_set (block, dest, gfc_rank_cst[dim], stride);
+
+  /* Update offset.  */
+  tree offs = gfc_conv_descriptor_offset_get (dest);
+  tree tmp = fold_build2_loc (input_location, MULT_EXPR,
+ gfc_array_index_type, lbound, stride);
+  offs = fold_build2_loc (input_location, MINUS_EXPR,
+ gfc_array_index_type, offs, tmp);
+  offs = gfc_evaluate_now (offs, block);
+  gfc_conv_descriptor_offset_set (block, dest, offs);
+
+  /* Update stride.  */
+  tmp = gfc_conv_array_extent_dim (lbound, ubound, NULL);
+  stride = fold_build2_loc (input_location, MULT_EXPR,
+   gfc_array_index_type, stride, tmp);
+}
+}
diff --git a/gcc/fortran/trans-descriptor.h b/gcc/fortran/trans-descriptor.h
index f445a76aef09..35f50c144304 

[gcc(refs/users/mikael/heads/refactor_descriptor_v08)] gimple-simulate: Réécriture de MEM_REF à l'intérieur de ARRAY_REF

2025-09-20 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:5826c0d9f05d77cd7b080730a1eae4b4e285c71f

commit 5826c0d9f05d77cd7b080730a1eae4b4e285c71f
Author: Mikael Morin 
Date:   Sat Aug 30 21:11:38 2025 +0200

gimple-simulate: Réécriture de MEM_REF à l'intérieur de ARRAY_REF

Diff:
---
 gcc/gimple-simulate.cc | 81 +++---
 1 file changed, 64 insertions(+), 17 deletions(-)

diff --git a/gcc/gimple-simulate.cc b/gcc/gimple-simulate.cc
index 85c37ed468d9..e33f8d8d5b46 100644
--- a/gcc/gimple-simulate.cc
+++ b/gcc/gimple-simulate.cc
@@ -982,6 +982,9 @@ static bool
 rewrite_ref (tree * data_ref, unsigned * offset, simul_scope & context)
 {
   tree ref = *data_ref;
+  if (DECL_P (ref))
+return true;
+
   switch (TREE_CODE (*data_ref))
 {
 case MEM_REF:
@@ -1007,34 +1010,24 @@ rewrite_ref (tree * data_ref, unsigned * offset, 
simul_scope & context)
return true;
   }
 
-#if 0
 case ARRAY_REF:
   {
tree base = TREE_OPERAND (ref, 0);
tree index = TREE_OPERAND (ref, 1);
-   tree type = TREE_TYPE (ref);
-   unsigned type_size = get_constant_type_size (type);
-   data_value idx_val = context.evaluate (index);
-   gcc_assert (idx_val.classify () == VAL_KNOWN);
-   wide_int wi_idx = idx_val.get_known ();
-   wide_int total_off = wi::shwi (*offset, HOST_BITS_PER_WIDE_INT);
-   wide_int idx_off = wi_idx * type_size;
-   gcc_assert (wi::ges_p (total_off, idx_off));
-   wide_int remaining_off = total_off - idx_off;
-   gcc_assert (wi::fits_uhwi_p (remaining_off));
-   unsigned rem = remaining_off.to_uhwi ();
 
tree rewritten_base = base;
-   if (!rewrite_ref (&base, &rem, context,
- get_constant_type_size (TREE_TYPE (base
+   unsigned rewritten_off = *offset;
+   if (!rewrite_ref (&rewritten_base, &rewritten_off, context)
+   && TREE_CODE (index) == INTEGER_CST)
  return false;
-   *data_ref = build4 (ARRAY_REF, type, rewritten_base,
+
+   data_value idx_val = context.evaluate (index);
+   *data_ref = build4 (ARRAY_REF, TREE_TYPE (ref), rewritten_base,
idx_val.to_tree (TREE_TYPE (index)),
NULL_TREE, NULL_TREE);
-   *offset = rem;
+   *offset = rewritten_off;
return true;
   }
-#endif
 
 default:
   return false;
@@ -4487,6 +4480,60 @@ context_printer_print_first_data_ref_part_tests ()
   ASSERT_EQ (res14, integer_type_node);
   const char * str14 = pp_formatted_text (&pp14);
   ASSERT_STREQ (str14, "# a14[0].der2i_i2");
+
+
+  tree der1a1i = make_node (RECORD_TYPE);
+  tree der1a1i_i2 = build_decl (input_location, FIELD_DECL,
+   get_identifier ("der1a1i_i2"),
+   integer_type_node);
+  DECL_CONTEXT (der1a1i_i2) = der1a1i;
+  DECL_CHAIN (der1a1i_i2) = NULL_TREE;
+  tree der1a1i_a1 = build_decl (input_location, FIELD_DECL,
+   get_identifier ("der1a1i_a1"), a2i);
+  DECL_CONTEXT (der1a1i_a1) = der1a1i;
+  DECL_CHAIN (der1a1i_a1) = der1a1i_i2;
+  TYPE_FIELDS (der1a1i) = der1a1i_a1;
+  layout_type (der1a1i);
+
+  heap_memory mem15;
+
+  context_printer printer15;
+  pretty_printer & pp15 = printer15.pp;
+
+  tree d_15 = create_var (der1a1i, "d");
+  tree p_15 = create_var (ptr_type_node, "p");
+
+  vec decls15{};
+  decls15.safe_push (d_15);
+  decls15.safe_push (p_15);
+
+  context_builder builder15 {};
+  builder15.add_decls (&decls15);
+  simul_scope ctx15 = builder15.build (mem15, printer15);
+
+  data_storage *strg_d15 = ctx15.find_reachable_var (d_15);
+  gcc_assert (strg_d15 != nullptr);
+
+  storage_address addr_d15 (strg_d15->get_ref (), 0);
+  data_value val_p15 (ptr_type_node);
+  val_p15.set_address (addr_d15);
+
+  data_storage *strg_p15 = ctx15.find_reachable_var (p_15);
+  gcc_assert (strg_p15 != nullptr);
+  strg_p15->set (val_p15);
+
+  tree zero_15 = build_zero_cst (build_pointer_type (void_type_node));
+  tree ref_d15 = build2 (MEM_REF, a2i, p_15, zero_15);
+  tree ref15 = build4 (ARRAY_REF, integer_type_node, ref_d15,
+  build_one_cst (integer_type_node), NULL_TREE, NULL_TREE);
+
+  tree res15 = printer15.print_first_data_ref_part (ctx15, ref15, 0,
+   nullptr,
+   VAL_UNDEFINED);
+
+  ASSERT_EQ (res15, integer_type_node);
+  const char * str15 = pp_formatted_text (&pp15);
+  ASSERT_STREQ (str15, "# d.der1a1i_a1[1]");
 }


[gcc(refs/users/mikael/heads/refactor_descriptor_v08)] Déplacement initialisation dernière borne sup assumed size

2025-09-20 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:18eebb350521745383c224f1f75f8884013cf07c

commit 18eebb350521745383c224f1f75f8884013cf07c
Author: Mikael Morin 
Date:   Sun Aug 10 11:13:41 2025 +0200

Déplacement initialisation dernière borne sup assumed size

Diff:
---
 gcc/fortran/trans-array.cc | 37 ++---
 gcc/fortran/trans-expr.cc  | 32 
 2 files changed, 22 insertions(+), 47 deletions(-)

diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc
index e837c1582efb..71077af59c1a 100644
--- a/gcc/fortran/trans-array.cc
+++ b/gcc/fortran/trans-array.cc
@@ -7826,21 +7826,28 @@ gfc_conv_expr_descriptor (gfc_se *se, gfc_expr *expr)
expr->ts.u.cl->backend_decl = tmp;
}
 
-  /* If we have an array section, are assigning  or passing an array
-section argument make sure that the lower bound is 1.  References
-to the full array should otherwise keep the original bounds.  */
-  if (!info->ref || info->ref->u.ar.type != AR_FULL)
-   for (dim = 0; dim < loop.dimen; dim++)
- if (!integer_onep (loop.from[dim]))
-   {
- tmp = fold_build2_loc (input_location, MINUS_EXPR,
-gfc_array_index_type, gfc_index_one_node,
-loop.from[dim]);
- loop.to[dim] = fold_build2_loc (input_location, PLUS_EXPR,
- gfc_array_index_type,
- loop.to[dim], tmp);
- loop.from[dim] = gfc_index_one_node;
-   }
+  if (info->ref && info->ref->u.ar.type == AR_FULL)
+   {
+ if (info->ref->u.ar.as->type == AS_ASSUMED_SIZE)
+   loop.to[loop.dimen - 1] = build_int_cst (gfc_array_index_type, -1);
+   }
+  else
+   {
+ /* If we have an array section, are assigning  or passing an array
+section argument make sure that the lower bound is 1.  References
+to the full array should otherwise keep the original bounds.  */
+ for (dim = 0; dim < loop.dimen; dim++)
+   if (!integer_onep (loop.from[dim]))
+ {
+   tmp = fold_build2_loc (input_location, MINUS_EXPR,
+  gfc_array_index_type, gfc_index_one_node,
+  loop.from[dim]);
+   loop.to[dim] = fold_build2_loc (input_location, PLUS_EXPR,
+   gfc_array_index_type,
+   loop.to[dim], tmp);
+   loop.from[dim] = gfc_index_one_node;
+ }
+   }
 
   desc = info->descriptor;
   if (se->direct_byref && !se->byref_noassign)
diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc
index 76ec12d23b48..9f26c95a9719 100644
--- a/gcc/fortran/trans-expr.cc
+++ b/gcc/fortran/trans-expr.cc
@@ -7665,38 +7665,6 @@ gfc_conv_procedure_call (gfc_se * se, gfc_symbol * sym,
}
}
}
-  /* Special case for an assumed-rank dummy argument. */
-  if (!sym->attr.is_bind_c && e && fsym && e->rank > 0
- && (fsym->ts.type == BT_CLASS
- ? (CLASS_DATA (fsym)->as
-&& CLASS_DATA (fsym)->as->type == AS_ASSUMED_RANK)
- : (fsym->as && fsym->as->type == AS_ASSUMED_RANK))
- && !(fsym->ts.type == BT_CLASS
-  ? (CLASS_DATA (fsym)->attr.class_pointer
- || CLASS_DATA (fsym)->attr.allocatable)
-  : (fsym->attr.pointer || fsym->attr.allocatable))
- && e->expr_type == EXPR_VARIABLE
- && e->symtree->n.sym->attr.dummy
- && (e->ts.type == BT_CLASS
- ? (e->ref && e->ref->next
-&& e->ref->next->type == REF_ARRAY
-&& e->ref->next->u.ar.type == AR_FULL
-&& e->ref->next->u.ar.as->type == AS_ASSUMED_SIZE)
- : (e->ref && e->ref->type == REF_ARRAY
-&& e->ref->u.ar.type == AR_FULL
-&& e->ref->u.ar.as->type == AS_ASSUMED_SIZE)))
-   {
- /* Assumed-size actual to assumed-rank dummy requires
-dim[rank-1].ubound = -1. */
- tree minus_one;
- tmp = build_fold_indirect_ref_loc (input_location, parmse.expr);
- if (fsym->ts.type == BT_CLASS)
-   tmp = gfc_class_data_get (tmp);
- minus_one = build_int_cst (gfc_array_index_type, -1);
- gfc_conv_descriptor_ubound_set (&parmse.pre, tmp,
- gfc_rank_cst[e->rank - 1],
- minus_one);
-   }
 
   /* The case with fsym->attr.optional is that of a user subroutine
 with an interface indicating an optional argument.  When we call


[gcc(refs/vendors/riscv/heads/gcc-15-with-riscv-opts)] RISC-V: Extract vector stepped for expand_const_vector [NFC]

2025-09-20 Thread Jeff Law via Gcc-cvs
https://gcc.gnu.org/g:1e94dbcca462169b3938d8ceaf1506553ff5090d

commit 1e94dbcca462169b3938d8ceaf1506553ff5090d
Author: Pan Li 
Date:   Thu Apr 17 10:27:17 2025 +0800

RISC-V: Extract vector stepped for expand_const_vector [NFC]

Consider the expand_const_vector is quit long (about 500 lines)
and complicated, we would like to extract the different case
into different functions.  For example, the const vector stepped
will be extracted into expand_const_vector_stepped.

The below test suites are passed for this patch.
* The rv64gcv fully regression test.

gcc/ChangeLog:

* config/riscv/riscv-v.cc (expand_const_vector): Extract
const vector stepped into separated func.
(expand_const_vector_single_step_npatterns): Add new func
to take care of single step.
(expand_const_vector_interleaved_stepped_npatterns): Add new
func to take care of interleaved step.
(expand_const_vector_stepped): Add new func to take care of
const vector stepped.

Signed-off-by: Pan Li 
(cherry picked from commit ab22b8c630769330b4f37eb64d2bc285344a647a)

Diff:
---
 gcc/config/riscv/riscv-v.cc | 590 ++--
 1 file changed, 299 insertions(+), 291 deletions(-)

diff --git a/gcc/config/riscv/riscv-v.cc b/gcc/config/riscv/riscv-v.cc
index 2132216d356f..66c8b2921e26 100644
--- a/gcc/config/riscv/riscv-v.cc
+++ b/gcc/config/riscv/riscv-v.cc
@@ -1340,334 +1340,342 @@ expand_const_vector_duplicate (rtx target, 
rvv_builder *builder)
 }
 
 static void
-expand_const_vector (rtx target, rtx src)
+expand_const_vector_single_step_npatterns (rtx target, rvv_builder *builder)
 {
   machine_mode mode = GET_MODE (target);
   rtx result = register_operand (target, mode) ? target : gen_reg_rtx (mode);
-  rtx elt;
 
-  if (const_vec_duplicate_p (src, &elt))
-return expand_const_vec_duplicate (target, src, elt);
+  /* Describe the case by choosing NPATTERNS = 4 as an example.  */
+  insn_code icode;
 
-  /* Support scalable const series vector.  */
-  rtx base, step;
-  if (const_vec_series_p (src, &base, &step))
-return expand_const_vec_series (target, base, step);
+  /* Step 1: Generate vid = { 0, 1, 2, 3, 4, 5, 6, 7, ... }.  */
+  rtx vid = gen_reg_rtx (builder->mode ());
+  rtx vid_ops[] = {vid};
+  icode = code_for_pred_series (builder->mode ());
+  emit_vlmax_insn (icode, NULLARY_OP, vid_ops);
 
-  /* Handle variable-length vector.  */
-  unsigned int nelts_per_pattern = CONST_VECTOR_NELTS_PER_PATTERN (src);
-  unsigned int npatterns = CONST_VECTOR_NPATTERNS (src);
-  rvv_builder builder (mode, npatterns, nelts_per_pattern);
-  for (unsigned int i = 0; i < nelts_per_pattern; i++)
+  if (builder->npatterns_all_equal_p ())
 {
-  for (unsigned int j = 0; j < npatterns; j++)
-   builder.quick_push (CONST_VECTOR_ELT (src, i * npatterns + j));
-}
-  builder.finalize ();
+  /* Generate the variable-length vector following this rule:
+{ a, a, a + step, a + step, a + step * 2, a + step * 2, ...}
+  E.g. { 0, 0, 8, 8, 16, 16, ... } */
+
+  /* We want to create a pattern where value[idx] = floor (idx /
+NPATTERNS). As NPATTERNS is always a power of two we can
+rewrite this as = idx & -NPATTERNS.  */
+  /* Step 2: VID AND -NPATTERNS:
+{ 0&-4, 1&-4, 2&-4, 3 &-4, 4 &-4, 5 &-4, 6 &-4, 7 &-4, ... } */
+  rtx imm = gen_int_mode (-builder->npatterns (), builder->inner_mode ());
+  rtx tmp1 = gen_reg_rtx (builder->mode ());
+  rtx and_ops[] = {tmp1, vid, imm};
+  icode = code_for_pred_scalar (AND, builder->mode ());
+  emit_vlmax_insn (icode, BINARY_OP, and_ops);
+
+  /* Step 3: Convert to step size 1.  */
+  rtx tmp2 = gen_reg_rtx (builder->mode ());
+  /* log2 (npatterns) to get the shift amount to convert
+Eg.  { 0, 0, 0, 0, 4, 4, ... }
+into { 0, 0, 0, 0, 1, 1, ... }.  */
+  HOST_WIDE_INT shift_amt = exact_log2 (builder->npatterns ());
+  rtx shift = gen_int_mode (shift_amt, builder->inner_mode ());
+  rtx shift_ops[] = {tmp2, tmp1, shift};
+  icode = code_for_pred_scalar (ASHIFTRT, builder->mode ());
+  emit_vlmax_insn (icode, BINARY_OP, shift_ops);
+
+  /* Step 4: Multiply to step size n.  */
+  HOST_WIDE_INT step_size =
+   INTVAL (builder->elt (builder->npatterns ()))
+ - INTVAL (builder->elt (0));
+  rtx tmp3 = gen_reg_rtx (builder->mode ());
+  if (pow2p_hwi (step_size))
+   {
+ /* Power of 2 can be handled with a left shift.  */
+ HOST_WIDE_INT shift = exact_log2 (step_size);
+ rtx shift_amount = gen_int_mode (shift, Pmode);
+ insn_code icode = code_for_pred_scalar (ASHIFT, mode);
+ rtx ops[] = {tmp3, tmp2, shift_amount};
+ emit_vlmax_insn (icode, BINARY_OP, ops);
+   }
+  else
+   {
+ rtx mult_amt = gen_int_mode (step_size, builder

[gcc(refs/users/mikael/heads/refactor_descriptor_v08)] Renseignement token dans gcf_set_descriptor_from_scalar

2025-09-20 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:ff179b8a8ff6839473b6a7e57f6acc74ebe9f755

commit ff179b8a8ff6839473b6a7e57f6acc74ebe9f755
Author: Mikael Morin 
Date:   Wed Jul 23 09:44:49 2025 +0200

Renseignement token dans gcf_set_descriptor_from_scalar

Correction renseignement token

Diff:
---
 gcc/fortran/trans-descriptor.cc | 10 ++
 gcc/fortran/trans-descriptor.h  |  2 +-
 gcc/fortran/trans-expr.cc   | 16 +++-
 3 files changed, 18 insertions(+), 10 deletions(-)

diff --git a/gcc/fortran/trans-descriptor.cc b/gcc/fortran/trans-descriptor.cc
index 253d6638f2ed..87ddf839a931 100644
--- a/gcc/fortran/trans-descriptor.cc
+++ b/gcc/fortran/trans-descriptor.cc
@@ -955,11 +955,13 @@ gfc_set_descriptor_from_scalar_class (stmtblock_t *block, 
tree descr,
 void
 gfc_set_descriptor_from_scalar (stmtblock_t *block, tree descr,
tree scalar, gfc_expr *scalar_expr,
-   tree cond_presence)
+   tree cond_presence, tree caf_token)
 {
-  tree type;
-  type = gfc_get_scalar_to_descriptor_type (TREE_TYPE (scalar),
-   gfc_expr_attr (scalar_expr));
+  if (flag_coarray == GFC_FCOARRAY_LIB && caf_token)
+gfc_conv_descriptor_token_set (block, descr, caf_token);
+
+  tree type = gfc_get_scalar_to_descriptor_type (TREE_TYPE (scalar),
+gfc_expr_attr (scalar_expr));
   gfc_conv_descriptor_dtype_set (block, descr,
 gfc_get_dtype (type));
   if (cond_presence)
diff --git a/gcc/fortran/trans-descriptor.h b/gcc/fortran/trans-descriptor.h
index 79db264c91c1..9284320f0ba1 100644
--- a/gcc/fortran/trans-descriptor.h
+++ b/gcc/fortran/trans-descriptor.h
@@ -103,6 +103,6 @@ void gfc_init_descriptor_variable (stmtblock_t *block, 
gfc_symbol *sym, tree des
 void gfc_set_descriptor_from_scalar_class (stmtblock_t *, tree, tree, gfc_expr 
*);
 void gfc_set_descriptor_from_scalar (stmtblock_t *, tree, tree);
 void gfc_set_descriptor_from_scalar (stmtblock_t *, tree, tree, gfc_expr *,
-tree);
+tree, tree);
 
 #endif /* GFC_TRANS_DESCRIPTOR_H */
diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc
index a72af35fa298..7bb2f01f7366 100644
--- a/gcc/fortran/trans-expr.cc
+++ b/gcc/fortran/trans-expr.cc
@@ -806,6 +806,7 @@ gfc_conv_derived_to_class (gfc_se *parmse, gfc_expr *e, 
gfc_symbol *fsym,
   tree var;
   tree tmp;
   tree packed = NULL_TREE;
+  tree caf_token = NULL_TREE;
 
   /* The derived type needs to be converted to a temporary CLASS object.  */
   tmp = gfc_typenode_for_spec (&fsym->ts);
@@ -822,12 +823,17 @@ gfc_conv_derived_to_class (gfc_se *parmse, gfc_expr *e, 
gfc_symbol *fsym,
 
   if (flag_coarray == GFC_FCOARRAY_LIB && CLASS_DATA (fsym)->attr.codimension)
 {
-  tree token;
   tmp = gfc_get_tree_for_caf_expr (e);
   if (POINTER_TYPE_P (TREE_TYPE (tmp)))
tmp = build_fold_indirect_ref (tmp);
-  gfc_get_caf_token_offset (parmse, &token, nullptr, tmp, NULL_TREE, e);
-  gfc_conv_descriptor_token_set (&parmse->pre, ctree, token);
+  gfc_get_caf_token_offset (parmse, &caf_token, nullptr, tmp, NULL_TREE, 
e);
+  /* Update the token here, unless it's done elsewhere like in
+ gfc_set_descriptor_from_scalar.  */
+  if ((parmse->expr && POINTER_TYPE_P (TREE_TYPE (parmse->expr)))
+  || (parmse->ss && parmse->ss->info && parmse->ss->info->useflags)
+  || e->rank != 0
+  || fsym->ts.u.derived->components->as == nullptr)
+   gfc_conv_descriptor_token_set (&parmse->pre, ctree, caf_token);
 }
 
   if (optional)
@@ -893,8 +899,8 @@ gfc_conv_derived_to_class (gfc_se *parmse, gfc_expr *e, 
gfc_symbol *fsym,
 
  /* Scalar to an assumed-rank array.  */
  if (fsym->ts.u.derived->components->as)
-   gfc_set_descriptor_from_scalar (&parmse->pre, ctree,
-   parmse->expr, e, cond_optional);
+   gfc_set_descriptor_from_scalar (&parmse->pre, ctree, parmse->expr,
+   e, cond_optional, caf_token);
   else
{
  tmp = fold_convert (TREE_TYPE (ctree), parmse->expr);


[gcc r16-3831] RISC-V: Support vnclip idiom testcase [PR120378]

2025-09-20 Thread Edwin Lu via Gcc-cvs
https://gcc.gnu.org/g:d0c08415310d1daecb28f8fbfeef3d7f18b21d56

commit r16-3831-gd0c08415310d1daecb28f8fbfeef3d7f18b21d56
Author: Edwin Lu 
Date:   Mon Sep 8 10:48:45 2025 -0700

RISC-V: Support vnclip idiom testcase [PR120378]

This patch contains testcases for PR120378 after the change made to
support the vnclipu variant of the SAT_TRUNC pattern.

PR target/120378

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/autovec/pr120378-1.c: New test.
* gcc.target/riscv/rvv/autovec/pr120378-2.c: New test.
* gcc.target/riscv/rvv/autovec/pr120378-3.c: New test.
* gcc.target/riscv/rvv/autovec/pr120378-4.c: New test.

Signed-off-by: Edwin Lu 

Diff:
---
 .../gcc.target/riscv/rvv/autovec/pr120378-1.c   | 21 +
 .../gcc.target/riscv/rvv/autovec/pr120378-2.c   | 21 +
 .../gcc.target/riscv/rvv/autovec/pr120378-3.c   | 21 +
 .../gcc.target/riscv/rvv/autovec/pr120378-4.c   | 21 +
 4 files changed, 84 insertions(+)

diff --git a/gcc/testsuite/gcc.target/riscv/rvv/autovec/pr120378-1.c 
b/gcc/testsuite/gcc.target/riscv/rvv/autovec/pr120378-1.c
new file mode 100644
index ..500028e7a150
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/pr120378-1.c
@@ -0,0 +1,21 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv64gcv -mabi=lp64d -O3" } */
+
+#include 
+
+inline uint8_t
+clip_uint8 (int x)
+{
+  return x & (~255) ? (-x) >> 31 : x;
+}
+
+void __attribute__ ((noipa))
+clip_loop (uint8_t *res, int *x, int w)
+{
+  for (int i = 0; i < w; i++)
+res[i] = clip_uint8 (x[i]);
+}
+
+/* { dg-final { scan-tree-dump-times ".SAT_TRUNC " 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "MAX_EXPR " 1 "optimized" } } */
+/* { dg-final { scan-assembler-times {vnclipu\.wi} 2 } } */
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/autovec/pr120378-2.c 
b/gcc/testsuite/gcc.target/riscv/rvv/autovec/pr120378-2.c
new file mode 100644
index ..9a880e0f67b2
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/pr120378-2.c
@@ -0,0 +1,21 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv64gcv -mabi=lp64d -O3" } */
+
+#include 
+
+inline uint16_t
+clip_uint16 (int x)
+{
+  return x & (~65535) ? (-x) >> 31 : x;
+}
+
+void __attribute__ ((noipa))
+clip_loop (uint16_t *res, int *x, int w)
+{
+  for (int i = 0; i < w; i++)
+res[i] = clip_uint16 (x[i]);
+}
+
+/* { dg-final { scan-tree-dump-times ".SAT_TRUNC " 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "MAX_EXPR " 1 "optimized" } } */
+/* { dg-final { scan-assembler-times {vnclipu\.wi} 1 } } */
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/autovec/pr120378-3.c 
b/gcc/testsuite/gcc.target/riscv/rvv/autovec/pr120378-3.c
new file mode 100644
index ..d6b2ddd3f8d0
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/pr120378-3.c
@@ -0,0 +1,21 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv64gcv -mabi=lp64d -O3" } */
+
+#include 
+
+inline uint8_t
+clip_uint8 (int64_t x)
+{
+  return x & (~255) ? (-x) >> 63 : x;
+}
+
+void __attribute__ ((noipa))
+clip_loop (uint8_t *res, int64_t *x, int w)
+{
+  for (int i = 0; i < w; i++)
+res[i] = clip_uint8 (x[i]);
+}
+
+/* { dg-final { scan-tree-dump-times ".SAT_TRUNC " 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "MAX_EXPR " 1 "optimized" } } */
+/* { dg-final { scan-assembler-times {vnclipu\.wi} 3 } } */
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/autovec/pr120378-4.c 
b/gcc/testsuite/gcc.target/riscv/rvv/autovec/pr120378-4.c
new file mode 100644
index ..4657e52f8839
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/pr120378-4.c
@@ -0,0 +1,21 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv64gcv -mabi=lp64d -O3" } */
+
+#include 
+
+inline uint16_t
+clip_uint16 (int64_t x)
+{
+  return x & (~65535) ? (-x) >> 63 : x;
+}
+
+void __attribute__ ((noipa))
+clip_loop (uint16_t *res, int64_t *x, int w)
+{
+  for (int i = 0; i < w; i++)
+res[i] = clip_uint16 (x[i]);
+}
+
+/* { dg-final { scan-tree-dump-times ".SAT_TRUNC " 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "MAX_EXPR " 1 "optimized" } } */
+/* { dg-final { scan-assembler-times {vnclipu\.wi} 2 } } */


[gcc(refs/users/mikael/heads/refactor_descriptor_v08)] Extraction gfc_create_unallocated_library_result_descriptor

2025-09-20 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:d8ec93c5d6d3546459546191d672d520893f2afc

commit d8ec93c5d6d3546459546191d672d520893f2afc
Author: Mikael Morin 
Date:   Wed Sep 10 20:38:07 2025 +0200

Extraction gfc_create_unallocated_library_result_descriptor

Diff:
---
 gcc/fortran/trans-descriptor.cc | 14 ++
 gcc/fortran/trans-descriptor.h  |  2 ++
 gcc/fortran/trans-expr.cc   | 10 ++
 3 files changed, 18 insertions(+), 8 deletions(-)

diff --git a/gcc/fortran/trans-descriptor.cc b/gcc/fortran/trans-descriptor.cc
index 556a749fad6c..994e9543adab 100644
--- a/gcc/fortran/trans-descriptor.cc
+++ b/gcc/fortran/trans-descriptor.cc
@@ -2959,3 +2959,17 @@ gfc_set_empty_descriptor_bounds (stmtblock_t *block, 
tree descr, int rank)
 
   gfc_conv_descriptor_offset_set (block, descr, gfc_index_zero_node);
 }
+
+
+tree
+gfc_create_unallocated_library_result_descriptor (stmtblock_t *block, tree 
source_descr, tree dtype)
+{
+  if (dtype == NULL_TREE)
+dtype = gfc_get_dtype (TREE_TYPE (source_descr));
+
+  gfc_conv_descriptor_dtype_set (block, source_descr, dtype);
+  tree res_desc = gfc_evaluate_now (source_descr, block);
+  gfc_conv_descriptor_data_set (block, res_desc, null_pointer_node);
+
+  return res_desc;
+}
diff --git a/gcc/fortran/trans-descriptor.h b/gcc/fortran/trans-descriptor.h
index 52762c3c94a4..70dfab8b6f6d 100644
--- a/gcc/fortran/trans-descriptor.h
+++ b/gcc/fortran/trans-descriptor.h
@@ -144,5 +144,7 @@ gfc_descriptor_init_count (tree, int, int, gfc_expr **, 
gfc_expr **,
   tree, gfc_expr *, tree, bool, gfc_expr *, tree,
   bool, tree *);
 void gfc_set_empty_descriptor_bounds (stmtblock_t *, tree, int);
+tree gfc_create_unallocated_library_result_descriptor (stmtblock_t *, tree,
+  tree);
 
 #endif /* GFC_TRANS_DESCRIPTOR_H */
diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc
index 90a0a49375b9..dae41a0818d8 100644
--- a/gcc/fortran/trans-expr.cc
+++ b/gcc/fortran/trans-expr.cc
@@ -11422,14 +11422,8 @@ fcncall_realloc_result (gfc_se *se, int rank, tree 
dtype)
 desc = build_fold_indirect_ref_loc (input_location, desc);
 
   /* Unallocated, the descriptor does not have a dtype.  */
-  if (dtype != NULL_TREE)
-gfc_conv_descriptor_dtype_set (&se->pre, desc, dtype);
-  else
-gfc_conv_descriptor_dtype_set (&se->pre, desc,
-  gfc_get_dtype (TREE_TYPE (desc)));
-
-  res_desc = gfc_evaluate_now (desc, &se->pre);
-  gfc_conv_descriptor_data_set (&se->pre, res_desc, null_pointer_node);
+  res_desc = gfc_create_unallocated_library_result_descriptor (&se->pre, desc,
+  dtype);
   se->expr = gfc_build_addr_expr (NULL_TREE, res_desc);
 
   /* Free the lhs after the function call and copy the result data to


[gcc r15-10315] ada: Compiler crash on container aggregate association with nonstatic key choice

2025-09-20 Thread Eric Botcazou via Gcc-cvs
https://gcc.gnu.org/g:b97c46eebe72992ec4cc21df36b272ad431b92ca

commit r15-10315-gb97c46eebe72992ec4cc21df36b272ad431b92ca
Author: Gary Dismukes 
Date:   Thu Aug 21 18:48:12 2025 +

ada: Compiler crash on container aggregate association with nonstatic key 
choice

The compiler blows up on a container aggregate with a container element
association that has a key_choice given by a nonstatic key expression.
This happens in the size computation for the aggregate due to calling
Update_Choices with the nonstatic expression.  The fix is simply to
condition the call to Update_Choices on whether the choice expression
is static.

gcc/ada/ChangeLog:

* exp_aggr.adb (Build_Container_Aggr_Code.Build_Size_Expr): In the 
case
of an association with a single choice, only call Update_Choices 
when
the choice expression is nonstatic.

Diff:
---
 gcc/ada/exp_aggr.adb | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/gcc/ada/exp_aggr.adb b/gcc/ada/exp_aggr.adb
index f0cf8393c7e1..f35e16b67616 100644
--- a/gcc/ada/exp_aggr.adb
+++ b/gcc/ada/exp_aggr.adb
@@ -6789,7 +6789,9 @@ package body Exp_Aggr is
--  Choice is a single discrete value
 
elsif Is_Discrete_Type (Etype (Choice)) then
-  Update_Choices (Choice, Choice);
+  if Is_Static_Expression (Choice) then
+ Update_Choices (Choice, Choice);
+  end if;
 
   Temp_Siz_Exp := Make_Integer_Literal (Loc, 1);
   Set_Is_Static_Expression (Temp_Siz_Exp);


[gcc(refs/users/mikael/heads/refactor_descriptor_v08)] Suppression gfc_conv_descriptor_type compil' OK

2025-09-20 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:4955110ac3d8ccdc1d79c1600b2fd9877708143f

commit 4955110ac3d8ccdc1d79c1600b2fd9877708143f
Author: Mikael Morin 
Date:   Sun Jun 29 14:11:50 2025 +0200

Suppression gfc_conv_descriptor_type compil' OK

Correction régression PR97046

Suppression non_lvalue type_get

Ajout location set_type

Diff:
---
 gcc/fortran/trans-decl.cc   | 23 -
 gcc/fortran/trans-descriptor.cc | 71 +++--
 gcc/fortran/trans-descriptor.h  |  5 ++-
 gcc/fortran/trans-expr.cc   |  2 +-
 4 files changed, 80 insertions(+), 21 deletions(-)

diff --git a/gcc/fortran/trans-decl.cc b/gcc/fortran/trans-decl.cc
index 0c893a5c0135..94d5aa30e8ce 100644
--- a/gcc/fortran/trans-decl.cc
+++ b/gcc/fortran/trans-decl.cc
@@ -7284,25 +7284,20 @@ gfc_conv_cfi_to_gfc (stmtblock_t *init, stmtblock_t 
*finally,
   ctype = fold_build2_loc (input_location, BIT_AND_EXPR, TREE_TYPE (ctype),
   ctype, build_int_cst (TREE_TYPE (ctype),
 CFI_type_mask));
-  tree type = gfc_conv_descriptor_type (gfc_desc);
 
   /* if (CFI_type_cptr) BT_VOID else BT_UNKNOWN  */
   /* Note: BT_VOID is could also be CFI_type_funcptr, but assume c_ptr. */
   cond = fold_build2_loc (input_location, EQ_EXPR, boolean_type_node, 
ctype,
  build_int_cst (TREE_TYPE (ctype), CFI_type_cptr));
-  tmp = fold_build2_loc (input_location, MODIFY_EXPR, void_type_node, type,
-build_int_cst (TREE_TYPE (type), BT_VOID));
-  tmp2 = fold_build2_loc (input_location, MODIFY_EXPR, void_type_node,
- type,
- build_int_cst (TREE_TYPE (type), BT_UNKNOWN));
+  tmp = gfc_conv_descriptor_type_set (gfc_desc, BT_VOID);
+  tmp2 = gfc_conv_descriptor_type_set (gfc_desc, BT_UNKNOWN);
   tmp2 = fold_build3_loc (input_location, COND_EXPR, void_type_node, cond,
  tmp, tmp2);
   /* if (CFI_type_struct) BT_DERIVED else  < tmp2 >  */
   cond = fold_build2_loc (input_location, EQ_EXPR, boolean_type_node, 
ctype,
  build_int_cst (TREE_TYPE (ctype),
 CFI_type_struct));
-  tmp = fold_build2_loc (input_location, MODIFY_EXPR, void_type_node, type,
-build_int_cst (TREE_TYPE (type), BT_DERIVED));
+  tmp = gfc_conv_descriptor_type_set (gfc_desc, BT_DERIVED);
   tmp2 = fold_build3_loc (input_location, COND_EXPR, void_type_node, cond,
  tmp, tmp2);
   /* if (CFI_type_Character) BT_CHARACTER else  < tmp2 >  */
@@ -7311,8 +7306,7 @@ gfc_conv_cfi_to_gfc (stmtblock_t *init, stmtblock_t 
*finally,
   cond = fold_build2_loc (input_location, EQ_EXPR, boolean_type_node, 
ctype,
  build_int_cst (TREE_TYPE (ctype),
  CFI_type_Character));
-  tmp = fold_build2_loc (input_location, MODIFY_EXPR, void_type_node, type,
-build_int_cst (TREE_TYPE (type), BT_CHARACTER));
+  tmp = gfc_conv_descriptor_type_set (gfc_desc, BT_CHARACTER);
   tmp2 = fold_build3_loc (input_location, COND_EXPR, void_type_node, cond,
  tmp, tmp2);
   /* if (CFI_type_ucs4_char) BT_CHARACTER else  < tmp2 >  */
@@ -7324,16 +7318,14 @@ gfc_conv_cfi_to_gfc (stmtblock_t *init, stmtblock_t 
*finally,
   cond = fold_build2_loc (input_location, EQ_EXPR, boolean_type_node, tmp,
  build_int_cst (TREE_TYPE (tmp),
 CFI_type_ucs4_char));
-  tmp = fold_build2_loc (input_location, MODIFY_EXPR, void_type_node, type,
-build_int_cst (TREE_TYPE (type), BT_CHARACTER));
+  tmp = gfc_conv_descriptor_type_set (gfc_desc, BT_CHARACTER);
   tmp2 = fold_build3_loc (input_location, COND_EXPR, void_type_node, cond,
  tmp, tmp2);
   /* if (CFI_type_Complex) BT_COMPLEX + cfi->elem_len/2 else  < tmp2 >  */
   cond = fold_build2_loc (input_location, EQ_EXPR, boolean_type_node, 
ctype,
  build_int_cst (TREE_TYPE (ctype),
  CFI_type_Complex));
-  tmp = fold_build2_loc (input_location, MODIFY_EXPR, void_type_node, type,
-build_int_cst (TREE_TYPE (type), BT_COMPLEX));
+  tmp = gfc_conv_descriptor_type_set (gfc_desc, BT_COMPLEX);
   tmp2 = fold_build3_loc (input_location, COND_EXPR, void_type_node, cond,
  tmp, tmp2);
   /* if (CFI_type_Integer || CFI_type_Logical || CFI_type_Real)
@@ -7351,8 +7343,7 @@ gfc_conv_cfi_to_gfc (stmtblock_t *init, stmtblock_t 
*finally,
 CFI_type_Real));
   cond = fold_build2_loc (input_location, TRUTH_OR_EXPR, boolean_type_node,

[gcc(refs/users/mikael/heads/refactor_descriptor_v08)] Refactoring shift descriptor

2025-09-20 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:6441e6b2c681e53cda4aeedb1845648683c5449e

commit 6441e6b2c681e53cda4aeedb1845648683c5449e
Author: Mikael Morin 
Date:   Wed Aug 13 14:02:37 2025 +0200

Refactoring shift descriptor

Correction pr85938

Correction régression associate_33

Correction pr43808

Correction associate_38

Sauvegarde compil' OK

Suppression évaluation redondante lbound & stride

Diff:
---
 gcc/fortran/trans-descriptor.cc | 123 ++--
 1 file changed, 54 insertions(+), 69 deletions(-)

diff --git a/gcc/fortran/trans-descriptor.cc b/gcc/fortran/trans-descriptor.cc
index b34943395c00..e8058752bd81 100644
--- a/gcc/fortran/trans-descriptor.cc
+++ b/gcc/fortran/trans-descriptor.cc
@@ -982,6 +982,35 @@ gfc_set_descriptor_from_scalar (stmtblock_t *block, tree 
descr,
 }
 
 
+static void
+shift_dimension_bounds (stmtblock_t * block, tree descr, tree dim,
+   tree new_lbound, tree orig_lbound, tree orig_ubound,
+   tree orig_stride, tree *offset_value)
+{
+  new_lbound = fold_convert (gfc_array_index_type, new_lbound);
+  new_lbound = gfc_evaluate_now (new_lbound, block);
+
+  orig_stride = gfc_evaluate_now (orig_stride, block);
+
+  /* Get difference (new - old) by which to shift stuff.  */
+  tree diff = fold_build2_loc (input_location, MINUS_EXPR, 
gfc_array_index_type,
+  new_lbound, orig_lbound);
+
+  /* Shift ubound and offset accordingly.  This has to be done before
+ updating the lbound, as they depend on the lbound expression!  */
+  tree ubound = fold_build2_loc (input_location, PLUS_EXPR,
+gfc_array_index_type, orig_ubound, diff);
+  gfc_conv_descriptor_ubound_set (block, descr, dim, ubound);
+  tree tmp = fold_build2_loc (input_location, MULT_EXPR,
+ gfc_array_index_type, new_lbound, orig_stride);
+  *offset_value = fold_build2_loc (input_location, MINUS_EXPR,
+  gfc_array_index_type, *offset_value, tmp);
+
+  /* Finally set lbound to value we want.  */
+  gfc_conv_descriptor_lbound_set (block, descr, dim, new_lbound);
+}
+
+
 /* Modify a descriptor such that the lbound of a given dimension is the value
specified.  This also updates ubound and offset accordingly.  */
 
@@ -990,32 +1019,15 @@ conv_shift_descriptor_lbound (stmtblock_t* block, tree 
desc,
  int dim, tree new_lbound, tree *offset)
 {
   tree ubound, lbound, stride;
-  tree diff;
 
   new_lbound = fold_convert (gfc_array_index_type, new_lbound);
-  new_lbound = gfc_evaluate_now (new_lbound, block);
 
   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,
- new_lbound, lbound);
-
-  /* Shift ubound and offset accordingly.  This has to be done before
- updating the lbound, as they depend on the lbound expression!  */
-  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);
-  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);
+  shift_dimension_bounds (block, desc, gfc_rank_cst[dim], new_lbound, lbound,
+ ubound, stride, offset);
 }
 
 
@@ -1025,8 +1037,8 @@ 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)
-conv_shift_descriptor_lbound (block, desc, dim,
- gfc_index_one_node, &offset);
+conv_shift_descriptor_lbound (block, desc, dim, gfc_index_one_node,
+ &offset);
   gfc_conv_descriptor_offset_set (block, desc, offset);
 }
 
@@ -1141,23 +1153,14 @@ gfc_conv_shift_descriptor (stmtblock_t *block, tree 
dest, tree src,
gfc_index_one_node, lbound);
   lbound = gfc_evaluate_now (lbound, block);
 
-  tmp = gfc_conv_descriptor_ubound_get (src, gfc_rank_cst[n]);
-  tmp = fold_build2_loc (input_location, PLUS_EXPR,
-gfc_array_index_type, tmp, lbound);
-  gfc_conv_descriptor_lbound_set (block, dest,
- g

[gcc(refs/users/mikael/heads/refactor_descriptor_v08)] gimple-simulate: Réécriture de MEM_REF à l'interieur ce COMPONENT_EXPR

2025-09-20 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:167382c77c04fbec473498ba5fb6baeed53db489

commit 167382c77c04fbec473498ba5fb6baeed53db489
Author: Mikael Morin 
Date:   Sat Aug 30 19:00:46 2025 +0200

gimple-simulate: Réécriture de MEM_REF à l'interieur ce COMPONENT_EXPR

Diff:
---
 gcc/gimple-simulate.cc | 252 +
 1 file changed, 169 insertions(+), 83 deletions(-)

diff --git a/gcc/gimple-simulate.cc b/gcc/gimple-simulate.cc
index 3bdfd2bf6f7d..85c37ed468d9 100644
--- a/gcc/gimple-simulate.cc
+++ b/gcc/gimple-simulate.cc
@@ -797,36 +797,40 @@ context_printer::print_bb_entry (basic_block bb)
 }
 
 
-/* Find the smallest subreference of VAR_REF starting at at least OFFSET
+/* Find the smallest subreference of VAR_REF starting at at least MIN_OFFSET
bit and of minimal size min_size.  If no subreference was found at
-   OFFSET exactly but a reference was found at a further offset, store the
+   MIN_OFFSET exactly but a reference was found at a further offset, store the
difference of offset in IGNORED_BITS.  Return NULL_TREE if the smallest
-   reference is smaller than MIN_SIZE.  Otherwise return the reference found.
-*/
+   reference is smaller than MIN_SIZE.  Otherwise return the reference
+   found.  */
+
 static tree
-pick_subref_at (tree var_ref, unsigned offset, int * ignored_bits,
-   unsigned min_size)
+pick_subref_at (tree var_ref, unsigned min_offset,
+   int * ignored_bits, unsigned min_size)
 {
   if (ignored_bits != nullptr)
 *ignored_bits = 0;
   tree ref = var_ref;
-  unsigned remaining_offset = offset;
+  unsigned remaining_offset = min_offset;
   while (true)
 {
   tree var_type = TREE_TYPE (ref);
+  unsigned type_size = get_constant_type_size (var_type);
+  if (type_size == min_size)
+   break;
+
   if (TREE_CODE (var_type) == ARRAY_TYPE)
{
  tree elt_type = TREE_TYPE (var_type);
  unsigned elt_width = get_constant_type_size (elt_type);
  if (elt_width < min_size)
return NULL_TREE;
+
  unsigned HOST_WIDE_INT hw_idx = remaining_offset / elt_width;
  tree t_idx = build_int_cst (integer_type_node, hw_idx);
  ref = build4 (ARRAY_REF, elt_type, ref,
t_idx, NULL_TREE, NULL_TREE);
  remaining_offset -= hw_idx * elt_width;
- if (elt_width == min_size)
-   break;
}
   else if (TREE_CODE (var_type) == RECORD_TYPE)
{
@@ -865,8 +869,7 @@ pick_subref_at (tree var_ref, unsigned offset, int * 
ignored_bits,
  tree field_type = TREE_TYPE (field);
 
  unsigned field_width = get_constant_type_size (field_type);
- if (field_width < min_size)
-   return NULL_TREE;
+ gcc_assert (field_width >= min_size);
 
  ref = build3 (COMPONENT_REF, field_type,
ref, field, NULL_TREE);
@@ -878,9 +881,6 @@ pick_subref_at (tree var_ref, unsigned offset, int * 
ignored_bits,
}
  else
remaining_offset -= field_position;
-
- if (field_width == min_size)
-   break;
}
   else
break;
@@ -934,11 +934,9 @@ find_mem_ref_replacement (tree * repl, unsigned * offset, 
simul_scope & context,
   tree access_offset = TREE_OPERAND (data_ref, 1);
   gcc_assert (TREE_CONSTANT (access_offset));
   wide_int wi_offset = wi::to_wide (access_offset);
-  wide_int remaining_offset = wi_offset * CHAR_BIT
- + *offset + ptr_address->offset;
-
-  gcc_assert (wi::ges_p (remaining_offset, 0)
- && wi::fits_shwi_p (remaining_offset));
+  int align = TYPE_ALIGN (access_type);
+  wide_int total_offset = wi_offset * CHAR_BIT
+ + *offset + ptr_address->offset;
   if (TREE_CODE (data_ref) == TARGET_MEM_REF)
{
  tree idx = TREE_OPERAND (data_ref, 2);
@@ -952,40 +950,101 @@ find_mem_ref_replacement (tree * repl, unsigned * 
offset, simul_scope & context,
  wide_int wi_step = step_val.get_known ();
 
  wi_idx *= wi_step;
- remaining_offset += wi_idx * CHAR_BIT;
+ total_offset += wi_idx * CHAR_BIT;
}
 
-  int ignored_bits;
-  tree t = pick_subref_at (var_ref, remaining_offset.to_shwi (),
-  &ignored_bits,
+  wide_int ref_offset = total_offset
+   & wi::mask (exact_log2 (align), true,
+   total_offset.get_precision ());
+  gcc_assert (wi::ges_p (ref_offset, 0)
+ && wi::fits_uhwi_p (ref_offset));
+
+  tree t = pick_subref_at (var_ref, ref_offset.to_uhwi (), nullptr,
   get_constant_type_size (access_type));
   if (t == NULL_TREE)
{
  *repl = var_ref;
- *offset = remaining_offset.to_shwi ();
+ gcc_assert (wi::ges_p (total_offset, 0)
+ && wi::fits_shwi_p 

[gcc(refs/users/mikael/heads/refactor_descriptor_v08)] Déplacement copy_descriptor

2025-09-20 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:2888c8afb2a8cb6a9517e696ff99770b205727b4

commit 2888c8afb2a8cb6a9517e696ff99770b205727b4
Author: Mikael Morin 
Date:   Thu Jul 31 20:48:05 2025 +0200

Déplacement copy_descriptor

Diff:
---
 gcc/fortran/trans-descriptor.cc | 42 +
 gcc/fortran/trans-descriptor.h  |  1 +
 gcc/fortran/trans-stmt.cc   | 46 ++---
 3 files changed, 45 insertions(+), 44 deletions(-)

diff --git a/gcc/fortran/trans-descriptor.cc b/gcc/fortran/trans-descriptor.cc
index 66fa9d57b725..43aa236acfb7 100644
--- a/gcc/fortran/trans-descriptor.cc
+++ b/gcc/fortran/trans-descriptor.cc
@@ -1329,6 +1329,48 @@ gfc_copy_descriptor (stmtblock_t *block, tree dest, tree 
src, bool lhs_type)
 }
 
 
+void
+gfc_copy_descriptor (stmtblock_t *block, tree dst, tree src, int rank)
+{
+  int n;
+  tree dim;
+  tree tmp;
+  tree tmp2;
+  tree size;
+  tree offset;
+
+  offset = gfc_index_zero_node;
+
+  /* Use memcpy to copy the descriptor. The size is the minimum of
+ the sizes of 'src' and 'dst'. This avoids a non-trivial conversion.  */
+  tmp = TYPE_SIZE_UNIT (TREE_TYPE (src));
+  tmp2 = TYPE_SIZE_UNIT (TREE_TYPE (dst));
+  size = fold_build2_loc (input_location, MIN_EXPR,
+ TREE_TYPE (tmp), tmp, tmp2);
+  tmp = builtin_decl_explicit (BUILT_IN_MEMCPY);
+  tmp = build_call_expr_loc (input_location, tmp, 3,
+gfc_build_addr_expr (NULL_TREE, dst),
+gfc_build_addr_expr (NULL_TREE, src),
+fold_convert (size_type_node, size));
+  gfc_add_expr_to_block (block, tmp);
+
+  /* Set the offset correctly.  */
+  for (n = 0; n < rank; n++)
+{
+  dim = gfc_rank_cst[n];
+  tmp = gfc_conv_descriptor_lbound_get (src, dim);
+  tmp2 = gfc_conv_descriptor_stride_get (src, dim);
+  tmp = fold_build2_loc (input_location, MULT_EXPR, TREE_TYPE (tmp),
+tmp, tmp2);
+  offset = fold_build2_loc (input_location, MINUS_EXPR,
+   TREE_TYPE (offset), offset, tmp);
+  offset = gfc_evaluate_now (offset, block);
+}
+
+  gfc_conv_descriptor_offset_set (block, dst, offset);
+}
+
+
 void
 gfc_copy_descriptor (stmtblock_t *block, tree dest, tree src, tree ptr,
 int rank, gfc_ss *ss)
diff --git a/gcc/fortran/trans-descriptor.h b/gcc/fortran/trans-descriptor.h
index 44f6d51dc6cd..f445a76aef09 100644
--- a/gcc/fortran/trans-descriptor.h
+++ b/gcc/fortran/trans-descriptor.h
@@ -111,6 +111,7 @@ void gfc_copy_sequence_descriptor (stmtblock_t *, tree, 
tree, int);
 void gfc_copy_descriptor (stmtblock_t *, tree, tree, gfc_expr *, bool);
 void gfc_copy_descriptor (stmtblock_t *, tree, tree, tree, int, gfc_ss *);
 void gfc_copy_descriptor (stmtblock_t *, tree, tree, bool);
+void gfc_copy_descriptor (stmtblock_t *, tree, tree, int);
 
 void gfc_set_descriptor_from_scalar_class (stmtblock_t *, tree, tree, gfc_expr 
*);
 void gfc_set_descriptor_from_scalar (stmtblock_t *, tree, tree, 
symbol_attribute,
diff --git a/gcc/fortran/trans-stmt.cc b/gcc/fortran/trans-stmt.cc
index 57ca11e1bafb..b525c4348916 100644
--- a/gcc/fortran/trans-stmt.cc
+++ b/gcc/fortran/trans-stmt.cc
@@ -1825,48 +1825,6 @@ class_has_len_component (gfc_symbol *sym)
 }
 
 
-static void
-copy_descriptor (stmtblock_t *block, tree dst, tree src, int rank)
-{
-  int n;
-  tree dim;
-  tree tmp;
-  tree tmp2;
-  tree size;
-  tree offset;
-
-  offset = gfc_index_zero_node;
-
-  /* Use memcpy to copy the descriptor. The size is the minimum of
- the sizes of 'src' and 'dst'. This avoids a non-trivial conversion.  */
-  tmp = TYPE_SIZE_UNIT (TREE_TYPE (src));
-  tmp2 = TYPE_SIZE_UNIT (TREE_TYPE (dst));
-  size = fold_build2_loc (input_location, MIN_EXPR,
- TREE_TYPE (tmp), tmp, tmp2);
-  tmp = builtin_decl_explicit (BUILT_IN_MEMCPY);
-  tmp = build_call_expr_loc (input_location, tmp, 3,
-gfc_build_addr_expr (NULL_TREE, dst),
-gfc_build_addr_expr (NULL_TREE, src),
-fold_convert (size_type_node, size));
-  gfc_add_expr_to_block (block, tmp);
-
-  /* Set the offset correctly.  */
-  for (n = 0; n < rank; n++)
-{
-  dim = gfc_rank_cst[n];
-  tmp = gfc_conv_descriptor_lbound_get (src, dim);
-  tmp2 = gfc_conv_descriptor_stride_get (src, dim);
-  tmp = fold_build2_loc (input_location, MULT_EXPR, TREE_TYPE (tmp),
-tmp, tmp2);
-  offset = fold_build2_loc (input_location, MINUS_EXPR,
-   TREE_TYPE (offset), offset, tmp);
-  offset = gfc_evaluate_now (offset, block);
-}
-
-  gfc_conv_descriptor_offset_set (block, dst, offset);
-}
-
-
 /* Do proper initialization for ASSOCIATE names.  */
 
 static void
@@ -1995,7 +1953,7 @@ trans_associate_var (gfc_symbol *sym, gfc_wrapped_block 
*block)
 attributes so the selector descriptor must be copied in and
  

[gcc(refs/users/mikael/heads/refactor_descriptor_v08)] gimple-simulate: propagation valeurs indéfinies

2025-09-20 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:de5836501f705cdf5312439e70820d1344f65b3c

commit de5836501f705cdf5312439e70820d1344f65b3c
Author: Mikael Morin 
Date:   Fri Aug 29 11:31:42 2025 +0200

gimple-simulate: propagation valeurs indéfinies

Ajout test

gimple-simulate: Propagation des valeurs indéfinies

Revert partiel

Diff:
---
 gcc/gimple-simulate.cc | 34 ++
 1 file changed, 34 insertions(+)

diff --git a/gcc/gimple-simulate.cc b/gcc/gimple-simulate.cc
index 9187efce399c..aeda491db332 100644
--- a/gcc/gimple-simulate.cc
+++ b/gcc/gimple-simulate.cc
@@ -2167,6 +2167,15 @@ simul_scope::evaluate_binary (enum tree_code code, tree 
type, tree lhs,
   else
gcc_unreachable ();
 }
+  else if ((lhs_type == VAL_UNDEFINED || rhs_type == VAL_UNDEFINED)
+  && (lhs_type != VAL_ADDRESS
+  && rhs_type != VAL_ADDRESS
+  && lhs_type != VAL_MIXED
+  && rhs_type != VAL_MIXED))
+{
+  data_value result (type);
+  return result;
+}
   else
 gcc_unreachable ();
 }
@@ -5797,6 +5806,31 @@ simul_scope_evaluate_binary_tests ()
   wide_int wi_rshift6 = rshift_6.get_known ();
   ASSERT_PRED1 (wi::fits_shwi_p, wi_rshift6);
   ASSERT_EQ (wi_rshift6.to_shwi (), 5);
+
+
+  tree i1_7 = create_var (integer_type_node, "i1");
+  tree i2_7 = create_var (integer_type_node, "i2");
+
+  vec decls7{};
+  decls7.safe_push (i1_7);
+  decls7.safe_push (i2_7);
+
+  context_builder builder7 {};
+  builder7.add_decls (&decls7);
+  simul_scope ctx7 = builder7.build (mem, printer);
+
+  data_value undef7_1 = ctx7.evaluate_binary (PLUS_EXPR,
+ integer_type_node,
+ i1_7, i2_7);
+
+  ASSERT_EQ (undef7_1.classify (), VAL_UNDEFINED);
+
+  tree cst_i1 = build_one_cst (integer_type_node);
+  data_value undef7_2 = ctx7.evaluate_binary (PLUS_EXPR,
+ integer_type_node,
+ i1_7, cst_i1);
+
+  ASSERT_EQ (undef7_2.classify (), VAL_UNDEFINED);
 }


[gcc(refs/users/mikael/heads/refactor_descriptor_v08)] Refactor set_dimension_bounds

2025-09-20 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:c2a505ae9ac7f2efc273e4005d1a058bc2fb955a

commit c2a505ae9ac7f2efc273e4005d1a058bc2fb955a
Author: Mikael Morin 
Date:   Fri Aug 15 22:08:28 2025 +0200

Refactor set_dimension_bounds

Correction régression pr85938

Diff:
---
 gcc/fortran/trans-descriptor.cc | 54 ++---
 1 file changed, 34 insertions(+), 20 deletions(-)

diff --git a/gcc/fortran/trans-descriptor.cc b/gcc/fortran/trans-descriptor.cc
index a26a3b2b01a9..cddffac71246 100644
--- a/gcc/fortran/trans-descriptor.cc
+++ b/gcc/fortran/trans-descriptor.cc
@@ -989,13 +989,40 @@ gfc_set_descriptor_from_scalar (stmtblock_t *block, tree 
descr,
 }
 
 
+static void
+set_dimension_bounds (stmtblock_t * block, tree descr, tree dim,
+ tree lbound, tree ubound, tree stride, tree *offset)
+{
+  lbound = gfc_evaluate_now (lbound, block);
+
+  gfc_conv_descriptor_ubound_set (block, descr, dim, ubound);
+
+  tree tmp = fold_build2_loc (input_location, MULT_EXPR,
+ gfc_array_index_type, 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, descr, dim, lbound);
+}
+
+
+static void
+set_dimension_bounds (stmtblock_t * block, tree descr, tree dim,
+ tree lbound, tree ubound, tree stride, tree offset_var)
+{
+  tree offset = offset_var;
+  set_dimension_bounds (block, descr, dim, lbound, ubound, stride, &offset);
+  gfc_add_modify (block, offset_var, offset);
+}
+
+
 static void
 shift_dimension_bounds (stmtblock_t * block, tree descr, tree dim,
tree new_lbound, tree orig_lbound, tree orig_ubound,
tree orig_stride, tree *offset_value)
 {
   new_lbound = fold_convert (gfc_array_index_type, new_lbound);
-  new_lbound = gfc_evaluate_now (new_lbound, block);
 
   orig_stride = gfc_evaluate_now (orig_stride, block);
 
@@ -1007,14 +1034,9 @@ shift_dimension_bounds (stmtblock_t * block, tree descr, 
tree dim,
  updating the lbound, as they depend on the lbound expression!  */
   tree ubound = fold_build2_loc (input_location, PLUS_EXPR,
 gfc_array_index_type, orig_ubound, diff);
-  gfc_conv_descriptor_ubound_set (block, descr, dim, ubound);
-  tree tmp = fold_build2_loc (input_location, MULT_EXPR,
- gfc_array_index_type, new_lbound, orig_stride);
-  *offset_value = fold_build2_loc (input_location, MINUS_EXPR,
-  gfc_array_index_type, *offset_value, tmp);
 
-  /* Finally set lbound to value we want.  */
-  gfc_conv_descriptor_lbound_set (block, descr, dim, new_lbound);
+  set_dimension_bounds (block, descr, dim, new_lbound, ubound, orig_stride,
+   offset_value);
 }
 
 
@@ -1802,15 +1824,12 @@ set_gfc_dimension_from_cfi (stmtblock_t *block, tree 
gfc, tree cfi, tree idx,
 {
   /* gfc->dim[i].lbound = ... */
   lbound = fold_convert (gfc_array_index_type, lbound);
-  lbound = gfc_evaluate_now (lbound, block);
-  gfc_conv_descriptor_lbound_set (block, gfc, idx, lbound);
 
   /* gfc->dim[i].ubound = gfc->dim[i].lbound + cfi->dim[i].extent - 1. */
   tree tmp = fold_build2_loc (input_location, MINUS_EXPR, gfc_array_index_type,
  lbound, gfc_index_one_node);
-  tmp = fold_build2_loc (input_location, PLUS_EXPR, gfc_array_index_type,
-gfc_get_cfi_dim_extent (cfi, idx), tmp);
-  gfc_conv_descriptor_ubound_set (block, gfc, idx, tmp);
+  tree ubound = fold_build2_loc (input_location, PLUS_EXPR, 
gfc_array_index_type,
+gfc_get_cfi_dim_extent (cfi, idx), tmp);
 
   tree stride;
   if (contiguous)
@@ -1839,14 +1858,9 @@ set_gfc_dimension_from_cfi (stmtblock_t *block, tree 
gfc, tree cfi, tree idx,
   gfc_get_cfi_desc_elem_len (cfi)));
   stride = gfc_evaluate_now (tmp, block);
 }
-  gfc_conv_descriptor_stride_set (block, gfc, idx, stride);
 
-  /* gfc->offset -= gfc->dim[i].stride * gfc->dim[i].lbound. */
-  tmp = fold_build2_loc (input_location, MULT_EXPR, gfc_array_index_type,
-stride, lbound);
-  tmp = fold_build2_loc (input_location, MINUS_EXPR, gfc_array_index_type,
-offset_var, tmp);
-  gfc_add_modify (block, offset_var, tmp);
+  set_dimension_bounds (block, gfc, idx, lbound, ubound, stride, offset_var);
+  gfc_conv_descriptor_stride_set (block, gfc, idx, stride);
 }


[gcc(refs/users/meissner/heads/work221-bugs)] Fix PR 118541, do not generate floating point cmoves for IEEE compares.

2025-09-20 Thread Michael Meissner via Gcc-cvs
https://gcc.gnu.org/g:937a418ac32a9f5eb15506d030c9abe8c696b89a

commit 937a418ac32a9f5eb15506d030c9abe8c696b89a
Author: Michael Meissner 
Date:   Mon Sep 8 14:28:08 2025 -0400

Fix PR 118541, do not generate floating point cmoves for IEEE compares.

In bug PR target/118541 on power9, power10, and power11 systems, for the
function:

extern double __ieee754_acos (double);

double
__acospi (double x)
{
  double ret = __ieee754_acos (x) / 3.14;
  return __builtin_isgreater (ret, 1.0) ? 1.0 : ret;
}

GCC currently generates the following code:

Power9  Power10 and Power11
==  ===
bl __ieee754_acos   bl __ieee754_acos@notoc
nop plfd 0,.LC0@pcrel
addis 9,2,.LC2@toc@ha   xxspltidp 12,1065353216
addi 1,1,32 addi 1,1,32
lfd 0,.LC2@toc@l(9) ld 0,16(1)
addis 9,2,.LC0@toc@ha   fdiv 0,1,0
ld 0,16(1)  mtlr 0
lfd 12,.LC0@toc@l(9)xscmpgtdp 1,0,12
fdiv 0,1,0  xxsel 1,0,12,1
mtlr 0  blr
xscmpgtdp 1,0,12
xxsel 1,0,12,1
blr

This is because ifcvt.cc optimizes the conditional floating point move to 
use the
XSCMPGTDP instruction.

However, the XSCMPGTDP instruction will generate an interrupt if one of the
arguments is a signalling NaN and signalling NaNs can generate an interrupt.
The IEEE comparison functions (isgreater, etc.) require that the comparison 
not
raise an interrupt.

This patch just eliminates the generation of XSCMPEQDP, XSCMPEQQP, 
XSCMPGTDP,
XSCMPGTQP, XSCMPGEDP, and XSCMPGEQP instructions.

2025-09-08  Michael Meissner  

gcc/

PR target/118541
* config/rs6000/predicates.md (fpmask_comparison_operator): Delete
predicate.
(invert_fpmask_comparison_operator): Likewise.
* config/rs6000/rs6000.cc (rs6000_maybe_emit_fp_cmove): Delete 
function.
(have_fp_minc_maxc): Rename from have_compare_and_set_mask since we 
no
longer generate the floating point compare and set mask 
instructions,
but we also need the test for floating point min/max.
(rs6000_emit_cmove): Delete support for generating floating point
compare and set mask instructions since those instructions can raise
NaN exceptions.
* config/rs6000/rs6000.md (movcc_p9): Delete
insn.
(fpmask, SFDF iterator): Likewise.
(xxsel): Likewise.
(movcc_p10): Likewise.
(movcc_invert_p10): Likewise.
(fpmask, IEEE128 iterator): Likewise.

gcc/testsuite/

PR target/118541
* gcc.target/powerpc/p9-minmax-2.c: Remove tests for floating point
compare and mask instructions.
* gcc.target/powerpc/float128-cmove.c: Delete test.
* gcc.target/powerpc/p9-minmax-1.c: Likewise.

Diff:
---
 gcc/config/rs6000/predicates.md   |  11 --
 gcc/config/rs6000/rs6000.cc   | 108 +--
 gcc/config/rs6000/rs6000.md   | 210 ++
 gcc/testsuite/gcc.target/powerpc/float128-cmove.c |  58 --
 gcc/testsuite/gcc.target/powerpc/p9-minmax-1.c| 170 --
 gcc/testsuite/gcc.target/powerpc/p9-minmax-2.c| 175 +-
 6 files changed, 27 insertions(+), 705 deletions(-)

diff --git a/gcc/config/rs6000/predicates.md b/gcc/config/rs6000/predicates.md
index 647e89afb6a7..065cdb10e10f 100644
--- a/gcc/config/rs6000/predicates.md
+++ b/gcc/config/rs6000/predicates.md
@@ -1458,17 +1458,6 @@
   (and (match_operand 0 "branch_comparison_operator")
(match_code "ne,le,ge,leu,geu,ordered")))
 
-;; Return 1 if OP is a comparison operator suitable for floating point
-;; vector/scalar comparisons that generate a -1/0 mask.
-(define_predicate "fpmask_comparison_operator"
-  (match_code "eq,gt,ge"))
-
-;; Return 1 if OP is a comparison operator suitable for vector/scalar
-;; comparisons that generate a 0/-1 mask (i.e. the inverse of
-;; fpmask_comparison_operator).
-(define_predicate "invert_fpmask_comparison_operator"
-  (match_code "ne,unlt,unle"))
-
 ;; Return 1 if OP is a comparison operation suitable for integer vector/scalar
 ;; comparisons that generate a -1/0 mask.
 (define_predicate "vecint_comparison_operator"
diff --git a/gcc/config/rs6000/rs6000.cc b/gcc/config/rs6000/rs6000.cc
index 5f8f750ce469..5440323a1004 100644
--- a/gcc/config/rs6000/rs6000.cc
+++ b/gcc/config/rs6000/rs6000.cc
@@ -16353,98 +16353,11 @@ rs6000_maybe_emit_maxc

[gcc r16-3919] i386/testsuite: Correct res_ref2 array size for avx512bw-vpmov{, us}wb-2.c

2025-09-20 Thread Haochen Jiang via Gcc-cvs
https://gcc.gnu.org/g:39c7b08d4ea33254c74ac0d2d7c2420ab1cb7f98

commit r16-3919-g39c7b08d4ea33254c74ac0d2d7c2420ab1cb7f98
Author: Haochen Jiang 
Date:   Tue Sep 16 14:40:12 2025 +0800

i386/testsuite: Correct res_ref2 array size for avx512bw-vpmov{,us}wb-2.c

Both of the tests under 128 bit are raising:

warning: writing 16 bytes into a region of size 8 [-Wstringop-overflow=]

when compiling, leading to a test fail. The warning is caused by the
incorrect array size for res_ref2. The wrong size caused the overflow.

Correct them in this patch to fix the test fail.

gcc/testsuite/ChangeLog:

* gcc.target/i386/avx512bw-vpmovuswb-2.c: Correct res_ref2
array size.
* gcc.target/i386/avx512bw-vpmovwb-2.c: Ditto.

Diff:
---
 gcc/testsuite/gcc.target/i386/avx512bw-vpmovuswb-2.c | 2 +-
 gcc/testsuite/gcc.target/i386/avx512bw-vpmovwb-2.c   | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/gcc/testsuite/gcc.target/i386/avx512bw-vpmovuswb-2.c 
b/gcc/testsuite/gcc.target/i386/avx512bw-vpmovuswb-2.c
index d5198f39eb61..2311dfea34f5 100644
--- a/gcc/testsuite/gcc.target/i386/avx512bw-vpmovuswb-2.c
+++ b/gcc/testsuite/gcc.target/i386/avx512bw-vpmovuswb-2.c
@@ -27,7 +27,7 @@ TEST (void)
   UNION_TYPE (AVX512F_LEN, i_w) src;
   MASK_TYPE mask = MASK_VALUE;
   unsigned char res_ref[32];
-  unsigned char res_ref2[SIZE];
+  unsigned char res_ref2[SIZE_HALF];
 
   for (i = 0; i < SIZE; i++)
 {
diff --git a/gcc/testsuite/gcc.target/i386/avx512bw-vpmovwb-2.c 
b/gcc/testsuite/gcc.target/i386/avx512bw-vpmovwb-2.c
index 6b0f86f57d8c..ea91181284f2 100644
--- a/gcc/testsuite/gcc.target/i386/avx512bw-vpmovwb-2.c
+++ b/gcc/testsuite/gcc.target/i386/avx512bw-vpmovwb-2.c
@@ -28,7 +28,7 @@ TEST (void)
   UNION_TYPE (AVX512F_LEN, i_w) src;
   MASK_TYPE mask = MASK_VALUE;
   char res_ref[32];
-  char res_ref2[SIZE];
+  char res_ref2[SIZE_HALF];
 
   sign = -1;
   for (i = 0; i < SIZE; i++)


[gcc r13-9889] Fix latent LRA bug

2025-09-20 Thread Jeff Law via Gcc-cvs
https://gcc.gnu.org/g:56c69b1887a8cd031dec5ba04709badff083d6aa

commit r13-9889-g56c69b1887a8cd031dec5ba04709badff083d6aa
Author: Jeff Law 
Date:   Fri Sep 12 16:08:38 2025 -0600

Fix latent LRA bug

Shreya's work to add the addptr pattern on the RISC-V port exposed a latent 
bug
in LRA.

We lazily allocate/reallocate the ira_reg_equiv structure and when we do
(re)allocation we'll over-allocate and zero-fill so that we don't have to
actually allocate and relocate the data so often.

In the case exposed by Shreya's work we had N requested entries at the last
rellocation step.  We actually allocate N+M entries.  During LRA we allocate
enough new pseudos and thus have N+M+1 pseudos.

In get_equiv we read ira_reg_equiv[regno] without bounds checking so we read
past the allocated part of the array and get back junk which we use and
depending on the precise contents we fault in various fun and interesting 
ways.

We could either arrange to re-allocate ira_reg_equiv again on some path 
through
LRA (possibly in get_equiv itself).  We could also just insert the bounds 
check
in get_equiv like is done elsewhere in LRA.  Vlad indicated no strong
preference in an email last week.

So this just adds the bounds check in a manner similar to what's done 
elsewhere
in LRA.  Bootstrapped and regression tested on x86_64 as well as RISC-V with
Shreya's work enabled and regtested across the various embedded targets.

gcc/
* lra-constraints.cc (get_equiv): Bounds check before accessing
data in ira_reg_equiv.

(cherry picked from commit 0c6ad3f5dfbd45150eeef2474899ba7ef0d8e592)

Diff:
---
 gcc/lra-constraints.cc | 1 +
 1 file changed, 1 insertion(+)

diff --git a/gcc/lra-constraints.cc b/gcc/lra-constraints.cc
index 21f05df0d618..a63e42bc32ad 100644
--- a/gcc/lra-constraints.cc
+++ b/gcc/lra-constraints.cc
@@ -518,6 +518,7 @@ get_equiv (rtx x)
   rtx res;
 
   if (! REG_P (x) || (regno = REGNO (x)) < FIRST_PSEUDO_REGISTER
+  || regno >= ira_reg_equiv_len
   || ! ira_reg_equiv[regno].defined_p
   || ! ira_reg_equiv[regno].profitable_p
   || lra_get_regno_hard_regno (regno) >= 0)


[gcc] Deleted branch 'mikael/heads/refactor_descriptor_v08' in namespace 'refs/users'

2025-09-20 Thread Mikael Morin via Gcc-cvs
The branch 'mikael/heads/refactor_descriptor_v08' in namespace 'refs/users' was 
deleted.
It previously pointed to:

 69e49ef041f4... Nouvelle fonction build_array_ref

Diff:

!!! WARNING: THE FOLLOWING COMMITS ARE NO LONGER ACCESSIBLE (LOST):
---

  69e49ef... Nouvelle fonction build_array_ref
  2e3d7b1... Suppression appel build_class_array_ref
  099f653... Refactoring calcul stride
  522f7cf... Factorisation calcul index dimension
  b48d545... Déplacement évaluation stride
  af347c1... Renommage element_ref -> current_elem
  e0bc576... Déplacement accumulation index dans conv_array_index_offse
  2fa490b... Introduction gfc_array_ref_info
  5c80102... Modification ordre argument gfc_build_array_ref
  bfd0060... Correction régression pdt_31
  510548b... Régénération des fichiers générés
  0ce1a94... Réduction utilisations macro GFC_DESCRIPTOR_STRIDE
  895c129... Régénération fichiers générés
  3f4ca32... Réduction utilisation stride pour allocation/initialisatio
  90b59ec... Régénération fichiers générés
  e8a62f4... Extraction ARRAY_ELEM_AT_OFFSET, PTR_ADD_OFFSET
  e7df527... Régénération des fichiers générés
  5d13f9d... Introduction macro PTR_INCREMENT_BYTES
  6750dc8... Régénération des fichiers générés
  daf39f4... Ajout macros GFC_DESCRIPTOR1_ELEM, etc
  f59ee42... Régénération fichiers générés
  47ffb89... Décalage indexs matmul
  491644b... Régénération fichiers générés
  d49f694... Correction quotation macros m4
  d23f1b6... Remplacement macro GFC_DIMENSION_SET -> GFC_DESCRIPTOR_DIME
  6e6cfa7... Renseignement span
  f5fa330... Extraction gfc_create_unallocated_library_result_descriptor
  b9cb223... Introduction gfc_conv_descriptor_extent_get
  6b00d5f... Refactor set_dimension_fields set_empty_descriptor
  a54c389... Refactor set_dimension_fields descriptor_init_count
  60e0b09... Refactoring set_dimension_fields set_pdt_array_descriptor
  77ed1d8... Factorisation set_dimension_bounds/shift_dimension_bounds g
  67666ef... Factorisation shift_dimension_fields/set_dimension_fields g
  6ce6398... Factorisation set_dimension_fields gfc_set_descriptor_with_
  215eb06... Factorisation set_dimension_fields gfc_set_descriptor
  5f77e19... Renseignement dtype initialisation statique
  35ddc62... Refactoring descriptor_write
  c877f34... Refactoring nullifcations descripteur
  97d3534... Suppression déclarations inutiles
  7069cc7... Déplacement initialisation dernière borne sup assumed siz
  93dbd09... Suppression set_dtype_if_unallocated
  6a96de7... Suppression déclarations inutiles
  35967a1... Extraction gfc_set_empty_descriptor_bounds
  6d9ca30... Déplacement gfc_array_init_count -> gfc_descriptor_init_co
  66251d0... Déplacement gfc_grow_array
  b47af53... Déplacemement plus de code gfc_set_pdt_array_descriptor
  680ce9d... Extraction gfc_set_pdt_array_descriptor
  f5c0fa1... Extraction gfc_set_descriptor_for_assign_realloc
  325ea51... Suppression mise à jour offset forall
  d594ecb... Extraction get_array_memory_size
  9738042... Mise à jour offset & span dans gfc_array_init_size
  b552327... Factorisation descriptor_element_size
  6dd4da9... Extraction gfc_set_temporary_descriptor
  5243a81... Refactoring set_dimension_fields
  0e943e2... Refactor set_dimension_bounds
  a15a4f5... Déroulement boucle set_gfc_from_cfi
  ef2b995... Refactor set_gfc_from_cfi
  ea74ff4... Extraction set_gfc_from_cfi
  be565a7... Extraction gfc_set_gfc_from_cfi
  5cf798d... Refactoring gfc_conv_descriptor_sm_get
  fbe9040... Factorisation utilisation shapeval
  baad800... Reindentation retour à la ligne set_descriptor_with_shape
  616fc48... Extraction set_descriptor_with_shape
  973ef63... Factorisation gfc_set_contiguous_descriptor
  f1bc70e... Extraction gfc_set_descriptor
  eca4e72... Calcul offset sans passer par le descripteur
  c4de21a... Modification initialisation stride
  238146e... Simplification initialisation offset remap descriptor
  e1f024a... Extraction gfc_conv_remap_descriptor
  2888c8a... Déplacement copy_descriptor
  a79b1e7... Extraction gfc_copy_descriptor
  cb75a4a... Extraction gfc_copy_descriptor
  f20d1d5... Extraction gfc_copy_descriptor
  a108733... Extraction gfc_copy_sequence_descriptor
  6441e6b... Refactoring shift descriptor
  57d5e98... Initialisation shifted offset en partant de zero
  07506fe... Extraction gfc_shift_descriptor
  e2e353d... Extraction gfc_conv_shift_subarray_descriptor
  13b2631... Factorisation gfc_conv_shift_descriptor
  671cb2b... Extraction gfc_conv_shift_descriptor
  a312a4a... Appel méthode shift descriptor dans gfc_trans_pointer_assi
  877f897... Déplacement shift descriptor vers gfc_conv_array_parameter
  bce0873... Refactoring gfc_set_descriptor_from_scalar
  ff179b8... Renseignement token dans gcf_set_descriptor_from_scalar
  a3c24bc... Extraction gfc_set_descriptor_from_scalar
  9c131b3... Extraction gfc_set_descriptor_from_scalar
  53b1048... Extraction gfc_set_descriptor_from_scalar
  94d5fa

[gcc(refs/users/mikael/heads/refactor_descriptor_v08)] Factorisation set_dimension_bounds/shift_dimension_bounds gfc_set_descriptor_for_assign_realloc

2025-09-20 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:77ed1d831b6dbf07984e906dcf51852c4a28ee88

commit 77ed1d831b6dbf07984e906dcf51852c4a28ee88
Author: Mikael Morin 
Date:   Sun Aug 17 17:05:28 2025 +0200

Factorisation set_dimension_bounds/shift_dimension_bounds 
gfc_set_descriptor_for_assign_realloc

Revert partiel

Diff:
---
 gcc/fortran/trans-descriptor.cc | 39 +++
 1 file changed, 11 insertions(+), 28 deletions(-)

diff --git a/gcc/fortran/trans-descriptor.cc b/gcc/fortran/trans-descriptor.cc
index f2fbe4e77045..510fc984de34 100644
--- a/gcc/fortran/trans-descriptor.cc
+++ b/gcc/fortran/trans-descriptor.cc
@@ -2492,38 +2492,21 @@ gfc_set_descriptor_for_assign_realloc (stmtblock_t 
*block, gfc_loopinfo *loop,
   tree tmp = fold_build2_loc (input_location, MINUS_EXPR,
  gfc_array_index_type,
  loop->to[n], loop->from[n]);
-  tmp = fold_build2_loc (input_location, PLUS_EXPR,
-gfc_array_index_type,
-tmp, gfc_index_one_node);
-
-  tree lbound = gfc_index_one_node;
-  tree ubound = tmp;
+  tree ubound = fold_build2_loc (input_location, PLUS_EXPR,
+gfc_array_index_type,
+tmp, gfc_index_one_node);
 
   if (as)
-   {
- tree lbd = get_std_lbound (expr2, desc2, n,
-as->type == AS_ASSUMED_SIZE);
- ubound = fold_build2_loc (input_location,
-   MINUS_EXPR,
-   gfc_array_index_type,
-   ubound, lbound);
- ubound = fold_build2_loc (input_location,
-   PLUS_EXPR,
-   gfc_array_index_type,
-   ubound, lbd);
- lbound = lbd;
-   }
+   shift_dimension_fields (block, desc, gfc_rank_cst[n],
+   get_std_lbound (expr2, desc2, n,
+   as->type == AS_ASSUMED_SIZE),
+   gfc_index_one_node, ubound, size1, &offset);
+  else
+   set_dimension_fields (block, desc, gfc_rank_cst[n], gfc_index_one_node,
+ ubound, size1, &offset);
 
-  gfc_conv_descriptor_lbound_set (block, desc, gfc_rank_cst[n], lbound);
-  gfc_conv_descriptor_ubound_set (block, desc, gfc_rank_cst[n], ubound);
-  gfc_conv_descriptor_stride_set (block, desc, gfc_rank_cst[n], size1);
-  lbound = gfc_conv_descriptor_lbound_get (desc, gfc_rank_cst[n]);
-  tree tmp2 = fold_build2_loc (input_location, MULT_EXPR, 
gfc_array_index_type,
-  lbound, size1);
-  offset = fold_build2_loc (input_location, MINUS_EXPR,
-   gfc_array_index_type, offset, tmp2);
   size1 = fold_build2_loc (input_location, MULT_EXPR, gfc_array_index_type,
-  tmp, size1);
+  ubound, size1);
 }
 
   /* Set the lhs descriptor and scalarizer offsets.  For rank > 1,


[gcc(refs/users/mikael/heads/refactor_descriptor_v08)] Refactoring gfc_get_scalar_to_descriptor_type

2025-09-20 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:94d5fa0b04041270b0ae1ae20a9a293c714c7749

commit 94d5fa0b04041270b0ae1ae20a9a293c714c7749
Author: Mikael Morin 
Date:   Thu Aug 7 14:05:20 2025 +0200

Refactoring gfc_get_scalar_to_descriptor_type

Correction gfc_get_scalar_to_descriptor_type

Correction gfc_get_scalar_to_descriptor_type

Diff:
---
 gcc/fortran/trans-expr.cc  | 6 +++---
 gcc/fortran/trans-types.cc | 8 
 2 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc
index 185554fcfe4e..f7bb11dbf52f 100644
--- a/gcc/fortran/trans-expr.cc
+++ b/gcc/fortran/trans-expr.cc
@@ -96,7 +96,7 @@ gfc_conv_scalar_to_descriptor (gfc_se *se, tree scalar, 
symbol_attribute attr)
 {
   tree desc, type, etype;
 
-  type = gfc_get_scalar_to_descriptor_type (scalar, attr);
+  type = gfc_get_scalar_to_descriptor_type (TREE_TYPE (scalar), attr);
   etype = TREE_TYPE (scalar);
   desc = gfc_create_var (type, "desc");
   DECL_ARTIFICIAL (desc) = 1;
@@ -903,7 +903,7 @@ gfc_conv_derived_to_class (gfc_se *parmse, gfc_expr *e, 
gfc_symbol *fsym,
  if (fsym->ts.u.derived->components->as)
{
  tree type;
- type = gfc_get_scalar_to_descriptor_type (parmse->expr,
+ type = gfc_get_scalar_to_descriptor_type (TREE_TYPE 
(parmse->expr),
gfc_expr_attr (e));
  gfc_conv_descriptor_dtype_set (&parmse->pre, ctree,
 gfc_get_dtype (type));
@@ -1312,7 +1312,7 @@ gfc_conv_class_to_class (gfc_se *parmse, gfc_expr *e, 
gfc_typespec class_ts,
 {
   if (e->rank == 0)
{
- tree type = gfc_get_scalar_to_descriptor_type (parmse->expr,
+ tree type = gfc_get_scalar_to_descriptor_type (TREE_TYPE 
(parmse->expr),
 gfc_expr_attr (e));
  gfc_conv_descriptor_dtype_set (&block, ctree,
 gfc_get_dtype (type));
diff --git a/gcc/fortran/trans-types.cc b/gcc/fortran/trans-types.cc
index e0eed7da7fe3..cc9ddeb463fe 100644
--- a/gcc/fortran/trans-types.cc
+++ b/gcc/fortran/trans-types.cc
@@ -2167,7 +2167,7 @@ gfc_get_array_type_bounds (tree etype, int dimen, int 
codimen, tree * lbound,
arrays.  */
 
 tree
-gfc_get_scalar_to_descriptor_type (tree scalar, symbol_attribute attr)
+gfc_get_scalar_to_descriptor_type (tree scalar_type, symbol_attribute attr)
 {
   enum gfc_array_kind akind;
 
@@ -2178,9 +2178,9 @@ gfc_get_scalar_to_descriptor_type (tree scalar, 
symbol_attribute attr)
   else
 akind = GFC_ARRAY_ASSUMED_SHAPE_CONT;
 
-  if (POINTER_TYPE_P (TREE_TYPE (scalar)))
-scalar = TREE_TYPE (scalar);
-  return gfc_get_array_type_bounds (TREE_TYPE (scalar), 0, 0, NULL, NULL, 1,
+  if (POINTER_TYPE_P (scalar_type))
+scalar_type = TREE_TYPE (scalar_type);
+  return gfc_get_array_type_bounds (scalar_type, 0, 0, NULL, NULL, 1,
akind, !(attr.pointer || attr.target));
 }


[gcc(refs/users/mikael/heads/refactor_descriptor_v08)] Refactor set_dimension_fields descriptor_init_count

2025-09-20 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:a54c389f9eac340ac6683595903a1de9e4b35b6e

commit a54c389f9eac340ac6683595903a1de9e4b35b6e
Author: Mikael Morin 
Date:   Sat Aug 16 19:16:15 2025 +0200

Refactor set_dimension_fields descriptor_init_count

Correction régression class_allocate_22

Ajout scan tree var

Correction dumps coarray_12

Diff:
---
 gcc/fortran/trans-descriptor.cc  | 18 +++-
 gcc/testsuite/gfortran.dg/coarray_12.f90 |  3 +-
 gcc/testsuite/lib/scandump.exp   | 50 
 gcc/testsuite/lib/scantree.exp   | 26 +
 4 files changed, 82 insertions(+), 15 deletions(-)

diff --git a/gcc/fortran/trans-descriptor.cc b/gcc/fortran/trans-descriptor.cc
index 071840f0e871..1b08120e74a3 100644
--- a/gcc/fortran/trans-descriptor.cc
+++ b/gcc/fortran/trans-descriptor.cc
@@ -2816,15 +2816,8 @@ gfc_descriptor_init_count (tree descriptor, int rank, 
int corank,
  ubound = lower[n];
}
}
-  gfc_conv_descriptor_lbound_set (descriptor_block, descriptor,
- gfc_rank_cst[n], se.expr);
   conv_lbound = se.expr;
-
-  /* Work out the offset for this component.  */
-  tmp = fold_build2_loc (input_location, MULT_EXPR, gfc_array_index_type,
-se.expr, stride);
-  offset = fold_build2_loc (input_location, MINUS_EXPR,
-   gfc_array_index_type, offset, tmp);
+  conv_lbound = gfc_evaluate_now (conv_lbound, pblock);
 
   /* Set upper bound.  */
   gfc_init_se (&se, NULL);
@@ -2860,13 +2853,11 @@ gfc_descriptor_init_count (tree descriptor, int rank, 
int corank,
  if (ubound->expr_type == EXPR_FUNCTION)
se.expr = gfc_evaluate_now (se.expr, pblock);
}
-  gfc_conv_descriptor_ubound_set (descriptor_block, descriptor,
- gfc_rank_cst[n], se.expr);
   conv_ubound = se.expr;
+  conv_ubound = gfc_evaluate_now (conv_ubound, pblock);
 
-  /* Store the stride.  */
-  gfc_conv_descriptor_stride_set (descriptor_block, descriptor,
- gfc_rank_cst[n], stride);
+  set_dimension_fields (descriptor_block, descriptor, gfc_rank_cst[n],
+   conv_lbound, conv_ubound, stride, &offset);
 
   /* Calculate size and check whether extent is negative.  */
   size = gfc_conv_array_extent_dim (conv_lbound, conv_ubound, &empty_cond);
@@ -2950,7 +2941,6 @@ gfc_descriptor_init_count (tree descriptor, int rank, int 
corank,
 return gfc_index_one_node;
 
   /* Update the array descriptor with the offset and the span.  */
-  offset = gfc_evaluate_now (offset, pblock);
   gfc_conv_descriptor_offset_set (descriptor_block, descriptor, offset);
   tmp = fold_convert (gfc_array_index_type, element_size);
   gfc_conv_descriptor_span_set (descriptor_block, descriptor, tmp);
diff --git a/gcc/testsuite/gfortran.dg/coarray_12.f90 
b/gcc/testsuite/gfortran.dg/coarray_12.f90
index 70efaaff5160..9bbb9e3a3035 100644
--- a/gcc/testsuite/gfortran.dg/coarray_12.f90
+++ b/gcc/testsuite/gfortran.dg/coarray_12.f90
@@ -46,7 +46,8 @@ end subroutine testAlloc5
 
 
 ! { dg-final { scan-tree-dump-times "a.dim.0..lbound = 1;" 1 "original" } }
-! { dg-final { scan-tree-dump-times "a.dim.0..ubound = .*nn;" 1 "original" } }
+! { dg-final { global ubound_value; scan-tree-dump-var {a\.dim\[0\]\.ubound = 
(D\.\d+);} "original" "ubound_value" } }
+! { dg-final { global ubound_value; scan-tree-dump-times "$ubound_value = 
.*nn;" 1 "original" } }
 ! { dg-final { scan-tree-dump-times "a.dim.1..lbound = 1;" 1 "original" } }
 ! { dg-final { scan-tree-dump-times "a.dim.1..ubound = .*mm;" 1 "original" } }
 ! { dg-final { scan-tree-dump-times "a.dim.2..lbound = 1;" 1 "original" } }
diff --git a/gcc/testsuite/lib/scandump.exp b/gcc/testsuite/lib/scandump.exp
index a8441daa22fa..74a77f0a57e1 100644
--- a/gcc/testsuite/lib/scandump.exp
+++ b/gcc/testsuite/lib/scandump.exp
@@ -214,6 +214,56 @@ proc scan-dump-not { args } {
 }
 }
 
+# Utility for scanning compiler result, invoked via dg-final.
+# Call pass if pattern is present, otherwise fail.
+#
+# Argument 0 is the type of dump we are searching (rtl, tree, ipa)
+# Argument 1 is the regexp to match.
+# Argument 2 is the suffix for the dump file
+# Argument 3 is the suffix of the dump base
+# Argument 4 is the variable name to store the matched content
+# Argument 5 handles expected failures and the like
+proc scan-dump-var { args } {
+
+if { [llength $args] >= 6 } {
+switch [dg-process-target [lindex $args 5]] {
+"S" { }
+"N" { return }
+"F" { setup_xfail "*-*-*" }
+"P" { }
+}
+}
+
+set testcase [testname-for-summary]
+# The name might include a list of options; extract the file name.
+set filename [lindex $testcase 0]
+
+set printable_pattern [make_pattern_printable [li

[gcc(refs/users/mikael/heads/refactor_descriptor_v08)] Mise à jour offset & span dans gfc_array_init_size

2025-09-20 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:973804222e18699ad649c1d406e30dded298e6eb

commit 973804222e18699ad649c1d406e30dded298e6eb
Author: Mikael Morin 
Date:   Fri Feb 14 11:22:35 2025 +0100

Mise à jour offset & span dans gfc_array_init_size

Diff:
---
 gcc/fortran/trans-array.cc | 30 ++
 1 file changed, 10 insertions(+), 20 deletions(-)

diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc
index 2bd625db6aee..abf311351e25 100644
--- a/gcc/fortran/trans-array.cc
+++ b/gcc/fortran/trans-array.cc
@@ -5816,8 +5816,8 @@ descriptor_element_size (tree descriptor, tree 
expr3_elem_size,
 /*GCC ARRAYS*/
 
 static tree
-gfc_array_init_size (tree descriptor, int rank, int corank, tree * poffset,
-gfc_expr ** lower, gfc_expr ** upper, stmtblock_t * pblock,
+gfc_array_init_size (tree descriptor, int rank, int corank, gfc_expr ** lower,
+gfc_expr ** upper, stmtblock_t * pblock,
 stmtblock_t * descriptor_block, tree * overflow,
 tree expr3_elem_size, gfc_expr *expr3, tree expr3_desc,
 bool e3_has_nodescriptor, gfc_expr *expr,
@@ -6060,6 +6060,12 @@ gfc_array_init_size (tree descriptor, int rank, int 
corank, tree * poffset,
   if (rank == 0)
 return element_size;
 
+  /* Update the array descriptor with the offset and the span.  */
+  offset = gfc_evaluate_now (offset, pblock);
+  gfc_conv_descriptor_offset_set (descriptor_block, descriptor, offset);
+  tmp = fold_convert (gfc_array_index_type, element_size);
+  gfc_conv_descriptor_span_set (descriptor_block, descriptor, tmp);
+
   stride = fold_convert (size_type_node, stride);
 
   /* First check for overflow. Since an array of type character can
@@ -6086,12 +6092,6 @@ gfc_array_init_size (tree descriptor, int rank, int 
corank, tree * poffset,
   size = fold_build2_loc (input_location, MULT_EXPR, size_type_node,
  stride, element_size);
 
-  if (poffset != NULL)
-{
-  offset = gfc_evaluate_now (offset, pblock);
-  *poffset = offset;
-}
-
   if (integer_zerop (or_expr))
 return size;
   if (integer_onep (or_expr))
@@ -6153,7 +6153,6 @@ gfc_array_allocate (gfc_se * se, gfc_expr * expr, tree 
status, tree errmsg,
 {
   tree tmp;
   tree pointer;
-  tree offset = NULL_TREE;
   tree token = NULL_TREE;
   tree size;
   tree msg;
@@ -6282,9 +6281,8 @@ gfc_array_allocate (gfc_se * se, gfc_expr * expr, tree 
status, tree errmsg,
   size = gfc_array_init_size (se->expr, alloc_w_e3_arr_spec ? expr->rank
   : ref->u.ar.as->rank,
  coarray ? ref->u.ar.as->corank : 0,
- &offset, lower, upper,
- &se->pre, &set_descriptor_block, &overflow,
- expr3_elem_size, expr3, e3_arr_desc,
+ lower, upper, &se->pre, &set_descriptor_block,
+ &overflow, expr3_elem_size, expr3, e3_arr_desc,
  e3_has_nodescriptor, expr, element_size,
  explicit_ts);
 
@@ -6422,14 +6420,6 @@ gfc_array_allocate (gfc_se * se, gfc_expr * expr, tree 
status, tree errmsg,
 
   gfc_add_expr_to_block (&se->pre, tmp);
 
-  /* Update the array descriptor with the offset and the span.  */
-  if (dimension)
-{
-  gfc_conv_descriptor_offset_set (&set_descriptor_block, se->expr, offset);
-  tmp = fold_convert (gfc_array_index_type, element_size);
-  gfc_conv_descriptor_span_set (&set_descriptor_block, se->expr, tmp);
-}
-
   set_descriptor = gfc_finish_block (&set_descriptor_block);
   if (status != NULL_TREE)
 {


[gcc(refs/users/mikael/heads/refactor_descriptor_v08)] gimple-simulate: Affichage des arguments à l'appel de fonction

2025-09-20 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:af133b12e3c2b1601890e9b7b627f50a63d745e0

commit af133b12e3c2b1601890e9b7b627f50a63d745e0
Author: Mikael Morin 
Date:   Tue Jul 29 11:45:38 2025 +0200

gimple-simulate: Affichage des arguments à l'appel de fonction

Diff:
---
 gcc/gimple-simulate.cc | 1 +
 1 file changed, 1 insertion(+)

diff --git a/gcc/gimple-simulate.cc b/gcc/gimple-simulate.cc
index 1f7492fae06a..1836f5d4b539 100644
--- a/gcc/gimple-simulate.cc
+++ b/gcc/gimple-simulate.cc
@@ -2838,6 +2838,7 @@ simulate (struct function * func, simul_scope & caller,
   data_storage *storage = ctx.find_reachable_var (arg);
   gcc_assert (storage != nullptr);
   storage->set (value);
+  printer.print_value_update (ctx, arg, value);
 
   arg = TREE_CHAIN (arg);
   i++;


[gcc(refs/users/mikael/heads/refactor_descriptor_v08)] fortran: Factor array descriptor references

2025-09-20 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:c97a2baa85eca4ba997a5995334d2c63fa4bc0a0

commit c97a2baa85eca4ba997a5995334d2c63fa4bc0a0
Author: Mikael Morin 
Date:   Wed Jul 9 21:18:18 2025 +0200

fortran: Factor array descriptor references

Regression tested on x86_64-pc-linux-gnu.
OK for master?

-- >8 --

Save subexpressions of array descriptor references to variables, so that
all the expressions using the descriptor as base object benefit from a
simplified reference using the variables.

This limits the size of the expressions generated in the original tree
dump, easing analysis of the code involving those expressions.
This is especially helpful with chains of array references where each
array in the chain uses a descriptor.

After optimizations, the effect of the change shouldn't be visible in
the vast majority of cases.  In rare cases it seems to permit a couple
more jump threadings.

gcc/fortran/ChangeLog:

* trans-array.cc (gfc_conv_ss_descriptor): Move the descriptor
expression initialisation...
(set_factored_descriptor_value): ... to this new function.
Before initialisation, walk the reference expression passed as
argument and save some of its subexpressions to a variable.
(substitute_t): New struct.
(maybe_substitute_expr): New function.
(substitute_subexpr_in_expr): New function.

Diff:
---
 gcc/fortran/trans-array.cc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc
index 7f9168410a2e..832aaed5e6e2 100644
--- a/gcc/fortran/trans-array.cc
+++ b/gcc/fortran/trans-array.cc
@@ -3656,7 +3656,7 @@ gfc_conv_ss_descriptor (stmtblock_t * block, gfc_ss * ss, 
int base)
   /* Also the data pointer.  */
   tmp = gfc_conv_array_data (se.expr);
   /* If this is a variable or address or a class array, use it directly.
- Otherwise we must evaluate it now to avoid breaking dependency
+Otherwise we must evaluate it now to avoid breaking dependency
 analysis by pulling the expressions for elemental array indices
 inside the loop.  */
   if (save_descriptor_data (se.expr, tmp) && !ss->is_alloc_lhs)


[gcc(refs/users/mikael/heads/refactor_descriptor_v08)] Factorisation utilisation shapeval

2025-09-20 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:bd0bdb095e6982bf9d00444d3512e25900a6502a

commit bd0bdb095e6982bf9d00444d3512e25900a6502a
Author: Mikael Morin 
Date:   Sun Aug 17 19:56:14 2025 +0200

Factorisation utilisation shapeval

Diff:
---
 gcc/fortran/trans-descriptor.cc | 10 --
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/gcc/fortran/trans-descriptor.cc b/gcc/fortran/trans-descriptor.cc
index d283c741767f..f3d6d83fd902 100644
--- a/gcc/fortran/trans-descriptor.cc
+++ b/gcc/fortran/trans-descriptor.cc
@@ -1755,12 +1755,12 @@ gfc_set_descriptor_with_shape (stmtblock_t *block, tree 
desc, tree ptr,
 
   gfc_conv_expr (&shapese, shape);
   gfc_add_block_to_block (&body, &shapese.pre);
+  tree shapeval = fold_convert (gfc_array_index_type, shapese.expr);
+  shapeval = gfc_evaluate_now (shapeval, &body);
   tmp = fold_build2_loc (input_location, MINUS_EXPR, gfc_array_index_type,
 lbound, gfc_index_one_node);
   tree ubound = fold_build2_loc (input_location, PLUS_EXPR,
-gfc_array_index_type, tmp,
-fold_convert (gfc_array_index_type,
-  shapese.expr));
+gfc_array_index_type, tmp, shapeval);
   gfc_conv_descriptor_ubound_set (&body, desc, dim, ubound);
   gfc_add_block_to_block (&body, &shapese.post);
 
@@ -1774,9 +1774,7 @@ gfc_set_descriptor_with_shape (stmtblock_t *block, tree 
desc, tree ptr,
   /* Update stride.  */
   gfc_add_modify (&body, stride,
  fold_build2_loc (input_location, MULT_EXPR,
-  gfc_array_index_type, stride,
-  fold_convert (gfc_array_index_type,
-shapese.expr)));
+  gfc_array_index_type, stride, shapeval));
   /* Finish scalarization loop.  */
   gfc_trans_scalarizing_loops (&loop, &body);
   gfc_add_block_to_block (block, &loop.pre);


[gcc(refs/users/mikael/heads/refactor_descriptor_v08)] Refactoring gfc_set_descriptor_from_scalar

2025-09-20 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:b53111d7efdcab477af41a0e1d6a1a820e67557d

commit b53111d7efdcab477af41a0e1d6a1a820e67557d
Author: Mikael Morin 
Date:   Tue Aug 12 18:57:20 2025 +0200

Refactoring gfc_set_descriptor_from_scalar

Correction pr87992.f90

Diff:
---
 gcc/fortran/trans-descriptor.cc | 83 ++---
 gcc/fortran/trans-descriptor.h  |  3 +-
 gcc/fortran/trans-expr.cc   |  2 +-
 3 files changed, 40 insertions(+), 48 deletions(-)

diff --git a/gcc/fortran/trans-descriptor.cc b/gcc/fortran/trans-descriptor.cc
index 87ddf839a931..9d30f42063ea 100644
--- a/gcc/fortran/trans-descriptor.cc
+++ b/gcc/fortran/trans-descriptor.cc
@@ -600,7 +600,6 @@ tree
 gfc_get_dtype_rank_type_slen (int rank, tree etype, tree length)
 {
   tree ptype;
-  tree size;
   int n;
   tree dtype;
   tree field;
@@ -661,6 +660,7 @@ gfc_get_dtype_rank_type_slen (int rank, tree etype, tree 
length)
   gcc_unreachable ();
 }
 
+  tree size = NULL_TREE;
   switch (n)
 {
 case BT_CHARACTER:
@@ -668,23 +668,24 @@ gfc_get_dtype_rank_type_slen (int rank, tree etype, tree 
length)
   size = gfc_get_character_len_in_bytes (ptype, length);
   break;
 case BT_VOID:
-  gcc_assert (TREE_CODE (ptype) == POINTER_TYPE);
-  size = size_in_bytes (ptype);
+  if (TREE_CODE (ptype) == POINTER_TYPE)
+   size = size_in_bytes (ptype);
   break;
 default:
   size = size_in_bytes (etype);
   break;
 }
 
-  gcc_assert (size);
-
-  STRIP_NOPS (size);
-  size = fold_convert (size_type_node, size);
   tree dtype_type_node = get_dtype_type_node ();
-  field = gfc_advance_chain (TYPE_FIELDS (dtype_type_node),
-GFC_DTYPE_ELEM_LEN);
-  CONSTRUCTOR_APPEND_ELT (v, field,
- fold_convert (TREE_TYPE (field), size));
+  if (size)
+{
+  STRIP_NOPS (size);
+  size = fold_convert (size_type_node, size);
+  field = gfc_advance_chain (TYPE_FIELDS (dtype_type_node),
+GFC_DTYPE_ELEM_LEN);
+  CONSTRUCTOR_APPEND_ELT (v, field,
+ fold_convert (TREE_TYPE (field), size));
+}
   field = gfc_advance_chain (TYPE_FIELDS (dtype_type_node),
 GFC_DTYPE_VERSION);
   CONSTRUCTOR_APPEND_ELT (v, field,
@@ -936,56 +937,46 @@ gfc_create_null_actual_descriptor (stmtblock_t *block, 
gfc_typespec *ts,
 
 
 void
-gfc_set_descriptor_from_scalar_class (stmtblock_t *block, tree descr,
- tree scalar, gfc_expr *scalar_expr)
-{
-  tree type = gfc_get_scalar_to_descriptor_type (TREE_TYPE (scalar),
-gfc_expr_attr (scalar_expr));
-  gfc_conv_descriptor_dtype_set (block, descr,
-gfc_get_dtype (type));
-
-  tree tmp = gfc_class_data_get (scalar);
-  if (!POINTER_TYPE_P (TREE_TYPE (tmp)))
-tmp = gfc_build_addr_expr (NULL_TREE, tmp);
-
-  gfc_conv_descriptor_data_set (block, descr, tmp);
-}
-
-
-void
-gfc_set_descriptor_from_scalar (stmtblock_t *block, tree descr,
-   tree scalar, gfc_expr *scalar_expr,
-   tree cond_presence, tree caf_token)
+gfc_set_descriptor_from_scalar (stmtblock_t *block, tree descr, tree scalar,
+   symbol_attribute attr,
+   tree cond_presence = NULL_TREE,
+   tree caf_token = NULL_TREE)
 {
   if (flag_coarray == GFC_FCOARRAY_LIB && caf_token)
 gfc_conv_descriptor_token_set (block, descr, caf_token);
 
-  tree type = gfc_get_scalar_to_descriptor_type (TREE_TYPE (scalar),
-gfc_expr_attr (scalar_expr));
-  gfc_conv_descriptor_dtype_set (block, descr,
-gfc_get_dtype (type));
+  tree type = gfc_get_scalar_to_descriptor_type (TREE_TYPE (scalar), attr);
+  if (!POINTER_TYPE_P (TREE_TYPE (scalar)))
+scalar = gfc_build_addr_expr (NULL_TREE, scalar);
   if (cond_presence)
 scalar = build3_loc (input_location, COND_EXPR,
 TREE_TYPE (scalar),
 cond_presence, scalar,
 fold_convert (TREE_TYPE (scalar),
   null_pointer_node));
+
+  gfc_conv_descriptor_dtype_set (block, descr, gfc_get_dtype (type));
   gfc_conv_descriptor_data_set (block, descr, scalar);
+  gfc_conv_descriptor_span_set (block, descr,
+   gfc_conv_descriptor_elem_len_get (descr));
 }
 
 
 void
-gfc_set_descriptor_from_scalar (stmtblock_t *block, tree descr, tree scalar)
+gfc_set_descriptor_from_scalar_class (stmtblock_t *block, tree descr,
+ tree scalar, gfc_expr *scalar_expr)
 {
-  tree etype = TREE_TYPE (scalar);
-  if (!POINTER_TYPE_P (TREE_TYPE (scalar)))
-scalar = gfc_build_addr_expr (NULL_TREE, scalar);
-  else if (TREE_TYPE (etype) && TREE_CODE (TREE_

[gcc(refs/users/mikael/heads/refactor_descriptor_v08)] Déplacement gfc_array_init_count -> gfc_descriptor_init_count

2025-09-20 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:dcba401dd45d27c3ef3f287fe94aa8f8420fc876

commit dcba401dd45d27c3ef3f287fe94aa8f8420fc876
Author: Mikael Morin 
Date:   Thu Jul 31 16:51:20 2025 +0200

Déplacement gfc_array_init_count -> gfc_descriptor_init_count

Diff:
---
 gcc/fortran/trans-array.cc  | 301 ++--
 gcc/fortran/trans-descriptor.cc | 283 +
 gcc/fortran/trans-descriptor.h  |   5 +
 3 files changed, 297 insertions(+), 292 deletions(-)

diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc
index 7c1dab102030..2306f8939818 100644
--- a/gcc/fortran/trans-array.cc
+++ b/gcc/fortran/trans-array.cc
@@ -5817,289 +5817,6 @@ get_array_memory_size (tree element_size, tree 
elements_count,
 }
 
 
-/* Fills in an array descriptor, and returns the size of the array.
-   The size will be a simple_val, ie a variable or a constant.  Also
-   calculates the offset of the base.  The pointer argument overflow,
-   which should be of integer type, will increase in value if overflow
-   occurs during the size calculation.  Returns the size of the array.
-   {
-stride = 1;
-offset = 0;
-for (n = 0; n < rank; n++)
-  {
-   a.lbound[n] = specified_lower_bound;
-   offset = offset + a.lbond[n] * stride;
-   size = 1 - lbound;
-   a.ubound[n] = specified_upper_bound;
-   a.stride[n] = stride;
-   size = size >= 0 ? ubound + size : 0; //size = ubound + 1 - lbound
-   overflow += size == 0 ? 0: (MAX/size < stride ? 1: 0);
-   stride = stride * size;
-  }
-for (n = rank; n < rank+corank; n++)
-  (Set lcobound/ucobound as above.)
-element_size = sizeof (array element);
-if (!rank)
-  return element_size
-stride = (size_t) stride;
-overflow += element_size == 0 ? 0: (MAX/element_size < stride ? 1: 0);
-stride = stride * element_size;
-return (stride);
-   }  */
-/*GCC ARRAYS*/
-
-static tree
-gfc_array_init_count (tree descriptor, int rank, int corank, gfc_expr ** lower,
- gfc_expr ** upper, stmtblock_t * pblock,
- stmtblock_t * descriptor_block, tree * overflow,
- tree expr3_elem_size, gfc_expr *expr3, tree expr3_desc,
- bool e3_has_nodescriptor, gfc_expr *expr,
- tree element_size, bool explicit_ts,
- tree *empty_array_cond)
-{
-  tree type;
-  tree tmp;
-  tree size;
-  tree offset;
-  tree stride;
-  tree cond;
-  gfc_expr *ubound;
-  gfc_se se;
-  int n;
-
-  type = TREE_TYPE (descriptor);
-
-  stride = gfc_index_one_node;
-  offset = gfc_index_zero_node;
-
-  /* Set the dtype before the alloc, because registration of coarrays needs
- it initialized.  */
-  if (expr->ts.type == BT_CHARACTER
-  && expr->ts.deferred
-  && VAR_P (expr->ts.u.cl->backend_decl))
-{
-  type = gfc_typenode_for_spec (&expr->ts);
-  gfc_conv_descriptor_dtype_set (pblock, descriptor,
-gfc_get_dtype_rank_type (rank, type));
-}
-  else if (expr->ts.type == BT_CHARACTER
-  && expr->ts.deferred
-  && TREE_CODE (descriptor) == COMPONENT_REF)
-{
-  /* Deferred character components have their string length tucked away
-in a hidden field of the derived type. Obtain that and use it to
-set the dtype. The charlen backend decl is zero because the field
-type is zero length.  */
-  gfc_ref *ref;
-  tmp = NULL_TREE;
-  for (ref = expr->ref; ref; ref = ref->next)
-   if (ref->type == REF_COMPONENT
-   && gfc_deferred_strlen (ref->u.c.component, &tmp))
- break;
-  gcc_assert (tmp != NULL_TREE);
-  tmp = fold_build3_loc (input_location, COMPONENT_REF, TREE_TYPE (tmp),
-TREE_OPERAND (descriptor, 0), tmp, NULL_TREE);
-  tmp = fold_convert (gfc_charlen_type_node, tmp);
-  type = gfc_get_character_type_len (expr->ts.kind, tmp);
-  gfc_conv_descriptor_dtype_set (pblock, descriptor,
-gfc_get_dtype_rank_type (rank, type));
-}
-  else if (expr3_desc && GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (expr3_desc)))
-gfc_conv_descriptor_dtype_set (pblock, descriptor,
-  gfc_conv_descriptor_dtype_get (expr3_desc));
-  else if (expr->ts.type == BT_CLASS && !explicit_ts
-  && expr3 && expr3->ts.type != BT_CLASS
-  && expr3_elem_size != NULL_TREE && expr3_desc == NULL_TREE)
-gfc_conv_descriptor_elem_len_set (pblock, descriptor, expr3_elem_size);
-  else
-gfc_conv_descriptor_dtype_set (pblock, descriptor, gfc_get_dtype (type));
-
-  tree empty_cond = logical_false_node;
-
-  for (n = 0; n < rank; n++)
-{
-  tree conv_lbound;
-  tree conv_ubound;
-
-  /* We have 3 possibilities for determining the size of the array:
-lower == NULL=> lbound = 1, ubound = upper[n]
-upper[n] = NULL  => lbound = 1, ubound 

[gcc(refs/users/mikael/heads/refactor_descriptor_v08)] Déplacement gfc_grow_array

2025-09-20 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:9a548bb793ed35bb0476292d2b3b5e9d189fe435

commit 9a548bb793ed35bb0476292d2b3b5e9d189fe435
Author: Mikael Morin 
Date:   Thu Jul 31 14:41:23 2025 +0200

Déplacement gfc_grow_array

Diff:
---
 gcc/fortran/trans-array.cc  | 37 -
 gcc/fortran/trans-descriptor.cc | 39 +++
 gcc/fortran/trans-descriptor.h  |  1 +
 3 files changed, 40 insertions(+), 37 deletions(-)

diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc
index 81209ad1f389..7c1dab102030 100644
--- a/gcc/fortran/trans-array.cc
+++ b/gcc/fortran/trans-array.cc
@@ -1309,43 +1309,6 @@ gfc_get_iteration_count (tree start, tree end, tree step)
 }
 
 
-/* Extend the data in array DESC by EXTRA elements.  */
-
-static void
-gfc_grow_array (stmtblock_t * pblock, tree desc, tree extra)
-{
-  tree arg0, arg1;
-  tree tmp;
-  tree size;
-  tree ubound;
-
-  if (integer_zerop (extra))
-return;
-
-  ubound = gfc_conv_descriptor_ubound_get (desc, gfc_rank_cst[0]);
-
-  /* Add EXTRA to the upper bound.  */
-  tmp = fold_build2_loc (input_location, PLUS_EXPR, gfc_array_index_type,
-ubound, extra);
-  gfc_conv_descriptor_ubound_set (pblock, desc, gfc_rank_cst[0], tmp);
-
-  /* Get the value of the current data pointer.  */
-  arg0 = gfc_conv_descriptor_data_get (desc);
-
-  /* Calculate the new array size.  */
-  size = TYPE_SIZE_UNIT (gfc_get_element_type (TREE_TYPE (desc)));
-  tmp = fold_build2_loc (input_location, PLUS_EXPR, gfc_array_index_type,
-ubound, gfc_index_one_node);
-  arg1 = fold_build2_loc (input_location, MULT_EXPR, size_type_node,
- fold_convert (size_type_node, tmp),
- fold_convert (size_type_node, size));
-
-  /* Call the realloc() function.  */
-  tmp = gfc_call_realloc (pblock, arg0, arg1);
-  gfc_conv_descriptor_data_set (pblock, desc, tmp);
-}
-
-
 /* Return true if the bounds of iterator I can only be determined
at run time.  */
 
diff --git a/gcc/fortran/trans-descriptor.cc b/gcc/fortran/trans-descriptor.cc
index a885ad4d77aa..5ab51ad326f2 100644
--- a/gcc/fortran/trans-descriptor.cc
+++ b/gcc/fortran/trans-descriptor.cc
@@ -2468,3 +2468,42 @@ gfc_set_pdt_array_descriptor (stmtblock_t *block, tree 
descr,
 
   return size;
 }
+
+
+/* Extend the data in array DESC by EXTRA elements.  */
+
+void
+gfc_grow_array (stmtblock_t * pblock, tree desc, tree extra)
+{
+  tree arg0, arg1;
+  tree tmp;
+  tree size;
+  tree ubound;
+
+  if (integer_zerop (extra))
+return;
+
+  ubound = gfc_conv_descriptor_ubound_get (desc, gfc_rank_cst[0]);
+
+  /* Add EXTRA to the upper bound.  */
+  tmp = fold_build2_loc (input_location, PLUS_EXPR, gfc_array_index_type,
+ubound, extra);
+  gfc_conv_descriptor_ubound_set (pblock, desc, gfc_rank_cst[0], tmp);
+
+  /* Get the value of the current data pointer.  */
+  arg0 = gfc_conv_descriptor_data_get (desc);
+
+  /* Calculate the new array size.  */
+  size = TYPE_SIZE_UNIT (gfc_get_element_type (TREE_TYPE (desc)));
+  tmp = fold_build2_loc (input_location, PLUS_EXPR, gfc_array_index_type,
+ubound, gfc_index_one_node);
+  arg1 = fold_build2_loc (input_location, MULT_EXPR, size_type_node,
+ fold_convert (size_type_node, tmp),
+ fold_convert (size_type_node, size));
+
+  /* Call the realloc() function.  */
+  tmp = gfc_call_realloc (pblock, arg0, arg1);
+  gfc_conv_descriptor_data_set (pblock, desc, tmp);
+}
+
+
diff --git a/gcc/fortran/trans-descriptor.h b/gcc/fortran/trans-descriptor.h
index 33ed46d1c47a..f383cd97c262 100644
--- a/gcc/fortran/trans-descriptor.h
+++ b/gcc/fortran/trans-descriptor.h
@@ -147,5 +147,6 @@ void gfc_set_descriptor_for_assign_realloc (stmtblock_t *, 
gfc_loopinfo *,
tree, tree, bool);
 tree gfc_set_pdt_array_descriptor (stmtblock_t *, tree, gfc_array_spec *,
   gfc_actual_arglist *, tree);
+void gfc_grow_array (stmtblock_t *, tree, tree);
 
 #endif /* GFC_TRANS_DESCRIPTOR_H */


[gcc(refs/users/mikael/heads/refactor_descriptor_v08)] Extraction get_array_memory_size

2025-09-20 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:ba19fe86955e771d6bc079a5f2e1c6644826e190

commit ba19fe86955e771d6bc079a5f2e1c6644826e190
Author: Mikael Morin 
Date:   Wed Jul 23 22:21:15 2025 +0200

Extraction get_array_memory_size

Diff:
---
 gcc/fortran/trans-array.cc | 155 -
 1 file changed, 84 insertions(+), 71 deletions(-)

diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc
index 4614aa71b845..78483ad30d72 100644
--- a/gcc/fortran/trans-array.cc
+++ b/gcc/fortran/trans-array.cc
@@ -5784,6 +5784,63 @@ descriptor_element_size (tree descriptor, tree 
expr3_elem_size,
 }
 
 
+static tree
+get_array_memory_size (tree element_size, tree elements_count,
+  tree empty_array_cond, stmtblock_t *pblock,
+  tree *overflow)
+{
+  elements_count = fold_convert (size_type_node, elements_count);
+
+  /* First check for overflow. Since an array of type character can
+ have zero element_size, we must check for that before
+ dividing.  */
+  tree tmp = fold_build2_loc (input_location, TRUNC_DIV_EXPR,
+ size_type_node, TYPE_MAX_VALUE (size_type_node),
+ element_size);
+  tree cond = gfc_unlikely (fold_build2_loc (input_location, LT_EXPR,
+logical_type_node, tmp,
+elements_count),
+   PRED_FORTRAN_OVERFLOW);
+  tmp = fold_build3_loc (input_location, COND_EXPR, integer_type_node, cond,
+integer_one_node, integer_zero_node);
+  cond = gfc_unlikely (fold_build2_loc (input_location, EQ_EXPR,
+   logical_type_node, element_size,
+   build_int_cst (size_type_node, 0)),
+  PRED_FORTRAN_SIZE_ZERO);
+  tmp = fold_build3_loc (input_location, COND_EXPR, integer_type_node, cond,
+integer_zero_node, tmp);
+  tmp = fold_build2_loc (input_location, PLUS_EXPR, integer_type_node,
+*overflow, tmp);
+  *overflow = gfc_evaluate_now (tmp, pblock);
+
+  tree size = fold_build2_loc (input_location, MULT_EXPR, size_type_node,
+  elements_count, element_size);
+
+  if (integer_zerop (empty_array_cond))
+return size;
+  if (integer_onep (empty_array_cond))
+return build_int_cst (size_type_node, 0);
+
+  tree var = gfc_create_var (TREE_TYPE (size), "size");
+
+  stmtblock_t thenblock;
+  gfc_start_block (&thenblock);
+  gfc_add_modify (&thenblock, var, build_int_cst (size_type_node, 0));
+  tree thencase = gfc_finish_block (&thenblock);
+
+  stmtblock_t elseblock;
+  gfc_start_block (&elseblock);
+  gfc_add_modify (&elseblock, var, size);
+  tree elsecase = gfc_finish_block (&elseblock);
+
+  tmp = gfc_evaluate_now (empty_array_cond, pblock);
+  tmp = build3_v (COND_EXPR, tmp, thencase, elsecase);
+  gfc_add_expr_to_block (pblock, tmp);
+
+  return var;
+}
+
+
 /* Fills in an array descriptor, and returns the size of the array.
The size will be a simple_val, ie a variable or a constant.  Also
calculates the offset of the base.  The pointer argument overflow,
@@ -5816,25 +5873,20 @@ descriptor_element_size (tree descriptor, tree 
expr3_elem_size,
 /*GCC ARRAYS*/
 
 static tree
-gfc_array_init_size (tree descriptor, int rank, int corank, gfc_expr ** lower,
-gfc_expr ** upper, stmtblock_t * pblock,
-stmtblock_t * descriptor_block, tree * overflow,
-tree expr3_elem_size, gfc_expr *expr3, tree expr3_desc,
-bool e3_has_nodescriptor, gfc_expr *expr,
-tree element_size, bool explicit_ts)
+gfc_array_init_count (tree descriptor, int rank, int corank, gfc_expr ** lower,
+ gfc_expr ** upper, stmtblock_t * pblock,
+ stmtblock_t * descriptor_block, tree * overflow,
+ tree expr3_elem_size, gfc_expr *expr3, tree expr3_desc,
+ bool e3_has_nodescriptor, gfc_expr *expr,
+ tree element_size, bool explicit_ts,
+ tree *empty_array_cond)
 {
   tree type;
   tree tmp;
   tree size;
   tree offset;
   tree stride;
-  tree or_expr;
-  tree thencase;
-  tree elsecase;
   tree cond;
-  tree var;
-  stmtblock_t thenblock;
-  stmtblock_t elseblock;
   gfc_expr *ubound;
   gfc_se se;
   int n;
@@ -5886,7 +5938,7 @@ gfc_array_init_size (tree descriptor, int rank, int 
corank, gfc_expr ** lower,
   else
 gfc_conv_descriptor_dtype_set (pblock, descriptor, gfc_get_dtype (type));
 
-  or_expr = logical_false_node;
+  tree empty_cond = logical_false_node;
 
   for (n = 0; n < rank; n++)
 {
@@ -5982,7 +6034,7 @@ gfc_array_init_size (tree descriptor, int rank, int 
corank, gfc_expr ** lower,
  gfc_rank_cst[n], stride);
 
   /* Calculate size and check whether extent i

[gcc(refs/users/mikael/heads/refactor_descriptor_v08)] Refactoring shift descriptor

2025-09-20 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:6441e6b2c681e53cda4aeedb1845648683c5449e

commit 6441e6b2c681e53cda4aeedb1845648683c5449e
Author: Mikael Morin 
Date:   Wed Aug 13 14:02:37 2025 +0200

Refactoring shift descriptor

Correction pr85938

Correction régression associate_33

Correction pr43808

Correction associate_38

Sauvegarde compil' OK

Suppression évaluation redondante lbound & stride

Diff:
---
 gcc/fortran/trans-descriptor.cc | 123 ++--
 1 file changed, 54 insertions(+), 69 deletions(-)

diff --git a/gcc/fortran/trans-descriptor.cc b/gcc/fortran/trans-descriptor.cc
index b34943395c00..e8058752bd81 100644
--- a/gcc/fortran/trans-descriptor.cc
+++ b/gcc/fortran/trans-descriptor.cc
@@ -982,6 +982,35 @@ gfc_set_descriptor_from_scalar (stmtblock_t *block, tree 
descr,
 }
 
 
+static void
+shift_dimension_bounds (stmtblock_t * block, tree descr, tree dim,
+   tree new_lbound, tree orig_lbound, tree orig_ubound,
+   tree orig_stride, tree *offset_value)
+{
+  new_lbound = fold_convert (gfc_array_index_type, new_lbound);
+  new_lbound = gfc_evaluate_now (new_lbound, block);
+
+  orig_stride = gfc_evaluate_now (orig_stride, block);
+
+  /* Get difference (new - old) by which to shift stuff.  */
+  tree diff = fold_build2_loc (input_location, MINUS_EXPR, 
gfc_array_index_type,
+  new_lbound, orig_lbound);
+
+  /* Shift ubound and offset accordingly.  This has to be done before
+ updating the lbound, as they depend on the lbound expression!  */
+  tree ubound = fold_build2_loc (input_location, PLUS_EXPR,
+gfc_array_index_type, orig_ubound, diff);
+  gfc_conv_descriptor_ubound_set (block, descr, dim, ubound);
+  tree tmp = fold_build2_loc (input_location, MULT_EXPR,
+ gfc_array_index_type, new_lbound, orig_stride);
+  *offset_value = fold_build2_loc (input_location, MINUS_EXPR,
+  gfc_array_index_type, *offset_value, tmp);
+
+  /* Finally set lbound to value we want.  */
+  gfc_conv_descriptor_lbound_set (block, descr, dim, new_lbound);
+}
+
+
 /* Modify a descriptor such that the lbound of a given dimension is the value
specified.  This also updates ubound and offset accordingly.  */
 
@@ -990,32 +1019,15 @@ conv_shift_descriptor_lbound (stmtblock_t* block, tree 
desc,
  int dim, tree new_lbound, tree *offset)
 {
   tree ubound, lbound, stride;
-  tree diff;
 
   new_lbound = fold_convert (gfc_array_index_type, new_lbound);
-  new_lbound = gfc_evaluate_now (new_lbound, block);
 
   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,
- new_lbound, lbound);
-
-  /* Shift ubound and offset accordingly.  This has to be done before
- updating the lbound, as they depend on the lbound expression!  */
-  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);
-  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);
+  shift_dimension_bounds (block, desc, gfc_rank_cst[dim], new_lbound, lbound,
+ ubound, stride, offset);
 }
 
 
@@ -1025,8 +1037,8 @@ 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)
-conv_shift_descriptor_lbound (block, desc, dim,
- gfc_index_one_node, &offset);
+conv_shift_descriptor_lbound (block, desc, dim, gfc_index_one_node,
+ &offset);
   gfc_conv_descriptor_offset_set (block, desc, offset);
 }
 
@@ -1141,23 +1153,14 @@ gfc_conv_shift_descriptor (stmtblock_t *block, tree 
dest, tree src,
gfc_index_one_node, lbound);
   lbound = gfc_evaluate_now (lbound, block);
 
-  tmp = gfc_conv_descriptor_ubound_get (src, gfc_rank_cst[n]);
-  tmp = fold_build2_loc (input_location, PLUS_EXPR,
-gfc_array_index_type, tmp, lbound);
-  gfc_conv_descriptor_lbound_set (block, dest,
- g

[gcc(refs/users/mikael/heads/refactor_descriptor_v08)] gimple-simulate: prise en charge BUILTIN_REALLOC

2025-09-20 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:a5061ffa67886407134353a316386343ce7d8d74

commit a5061ffa67886407134353a316386343ce7d8d74
Author: Mikael Morin 
Date:   Tue Jul 29 17:43:43 2025 +0200

gimple-simulate: prise en charge BUILTIN_REALLOC

Diff:
---
 gcc/gimple-simulate.cc | 181 +
 1 file changed, 181 insertions(+)

diff --git a/gcc/gimple-simulate.cc b/gcc/gimple-simulate.cc
index 1836f5d4b539..7f8c9d31b3b3 100644
--- a/gcc/gimple-simulate.cc
+++ b/gcc/gimple-simulate.cc
@@ -2526,6 +2526,39 @@ simul_scope::simulate_call (gcall *g)
 
   storage0.set (dest_val);
 }
+  else if (gimple_call_builtin_p (g, BUILT_IN_REALLOC))
+{
+  gcc_assert (lhs != NULL_TREE);
+  result.emplace (data_value (TREE_TYPE (lhs)));
+
+  gcc_assert (gimple_call_num_args (g) == 2);
+  tree arg0 = gimple_call_arg (g, 0);
+  tree arg1 = gimple_call_arg (g, 1);
+  data_value ptr0 = evaluate (arg0);
+  data_value size1 = evaluate (arg1);
+  gcc_assert (ptr0.classify () == VAL_ADDRESS);
+  gcc_assert (size1.classify () == VAL_KNOWN);
+
+  wide_int wi_size1 = size1.get_known ();
+  gcc_assert (wi::fits_uhwi_p (wi_size1));
+  HOST_WIDE_INT alloc_amount = wi_size1.to_uhwi ();
+  data_storage &storage = allocate (alloc_amount);
+
+  storage_address addr0 = *ptr0.get_address ();
+  data_storage & storage0 = addr0.storage.get ();
+  data_value src = storage0.get_value ();
+
+  wide_int wi_bitwidth = wi_size1 * CHAR_BIT;
+  gcc_assert (wi::fits_uhwi_p (wi_bitwidth));
+  HOST_WIDE_INT bitwidth = wi_bitwidth.to_uhwi ();
+  data_value dest (bitwidth);
+  dest.set_at (0, std::min (src.get_bitwidth (), dest.get_bitwidth ()),
+  src, 0);
+  storage.set (dest);
+
+  storage_address address (storage.get_ref (), 0);
+  (*result).set_address (address);
+}
   else
 {
   tree fn = gimple_call_fn (g);
@@ -6979,6 +7012,154 @@ simul_scope_simulate_call_tests ()
   wide_int wi105_after2 = val105_after2.get_known ();
   ASSERT_PRED1 (wi::fits_shwi_p, wi105_after2);
   ASSERT_EQ (wi105_after2.to_shwi (), 17);
+
+
+  tree p1_11 = create_var (ptr_type_node, "p1");
+  tree p2_11 = create_var (ptr_type_node, "p2");
+  tree c29 = build_array_type_nelts (char_type_node, 29);
+  tree ac29_11 = create_var (c29, "ac29");
+
+  vec decls11{};
+  decls11.safe_push (p1_11);
+  decls11.safe_push (p2_11);
+  decls11.safe_push (ac29_11);
+
+  heap_memory mem11;
+  context_builder builder11 {};
+  builder11.add_decls (&decls11);
+  simul_scope ctx11 = builder11.build (mem11, printer);
+
+  data_storage * storage_ac29_11 = ctx11.find_reachable_var (ac29_11);
+  gcc_assert (storage_ac29_11 != nullptr);
+
+  storage_address addr29_11 (storage_ac29_11->get_ref (), CHAR_BIT);
+  data_value val_addr29_11 (ptr_type_node);
+  val_addr29_11.set_address (addr29_11);
+
+  data_storage * storage_p2_11 = ctx11.find_reachable_var (p2_11);
+  gcc_assert (storage_p2_11 != nullptr);
+  storage_p2_11->set (val_addr29_11);
+
+  storage_address addr_p2_11 (storage_p2_11->get_ref (), 0);
+  data_value val_c29 (c29);
+  val_c29.set_address_at (addr_p2_11, HOST_BITS_PER_PTR);
+  wide_int wi23_11 = wi::shwi (23, TYPE_PRECISION (integer_type_node));
+  val_c29.set_known_at (wi23_11, 20 * CHAR_BIT);
+  storage_ac29_11->set (val_c29);
+
+  tree realloc_fn = builtin_decl_explicit (BUILT_IN_REALLOC);
+  gcall *realloc_call11 = gimple_build_call (realloc_fn, 2, p2_11,
+build_int_cst (size_type_node, 
31));
+  gimple_call_set_lhs (realloc_call11, p1_11);
+
+  data_storage * storage_p1_11 = ctx11.find_reachable_var (p1_11);
+  gcc_assert (storage_p1_11 != nullptr);
+
+  data_value val_p1_11_before = storage_p1_11->get_value ();
+  ASSERT_EQ (val_p1_11_before.classify (), VAL_UNDEFINED);
+
+  ctx11.simulate (realloc_call11);
+
+  data_value val_p1_11_after = storage_p1_11->get_value ();
+  ASSERT_EQ (val_p1_11_after.classify (), VAL_ADDRESS);
+  storage_address * addr_p1_11 = val_p1_11_after.get_address ();
+  storage_ref storage_ref_addr_p1_11 = addr_p1_11->storage;
+  ASSERT_EQ (storage_ref_addr_p1_11.type, STRG_ALLOC);
+  data_storage & storage_addr_p1_11 = storage_ref_addr_p1_11.get ();
+  ASSERT_EQ (storage_addr_p1_11.get_type (), STRG_ALLOC);
+
+  data_value val_strg_p1_11 = storage_addr_p1_11.get_value ();
+  ASSERT_EQ (val_strg_p1_11.get_bitwidth (), 31 * CHAR_BIT);
+  ASSERT_EQ (val_strg_p1_11.classify (), VAL_MIXED);
+
+  ASSERT_EQ (val_strg_p1_11.classify (0, HOST_BITS_PER_PTR),
+VAL_UNDEFINED);
+  ASSERT_EQ (val_strg_p1_11.classify (HOST_BITS_PER_PTR, HOST_BITS_PER_PTR),
+VAL_ADDRESS);
+  ASSERT_EQ (val_strg_p1_11.classify (2 * HOST_BITS_PER_PTR, 
HOST_BITS_PER_INT),
+VAL_UNDEFINED);
+  ASSERT_EQ (val_strg_p1_11.classify (20 * CHAR_BIT, HOST_BITS_PER_INT),
+VAL_KNOWN);
+
+  data_value val_ptr_strg_p1_11 = val_strg_p1_11.get_at (HOST_BITS_PER_

[gcc(refs/users/mikael/heads/refactor_descriptor_v08)] Utilisation gfc_conv_descriptor_offset_{g, s}et

2025-09-20 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:af9b8a993514761e956673ad0978eb3ab61e66a9

commit af9b8a993514761e956673ad0978eb3ab61e66a9
Author: Mikael Morin 
Date:   Thu Jun 19 18:04:56 2025 +0200

Utilisation gfc_conv_descriptor_offset_{g,s}et

Correction pr43808

Correction gfc_conv_descriptor_offset

Utilisation gfc_conv_descriptor_offset_set

Suppression retour à la ligne inutile offset_set

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

diff --git a/gcc/fortran/trans-descriptor.cc b/gcc/fortran/trans-descriptor.cc
index cbee0fa9aca8..e898f2a8d406 100644
--- a/gcc/fortran/trans-descriptor.cc
+++ b/gcc/fortran/trans-descriptor.cc
@@ -215,8 +215,8 @@ gfc_conv_descriptor_data_set (stmtblock_t *block, tree 
desc, tree value)
 }
 
 
-tree
-gfc_conv_descriptor_offset (tree desc)
+static tree
+get_descriptor_offset (tree desc)
 {
   tree field = gfc_get_descriptor_field (desc, OFFSET_FIELD);
   gcc_assert (TREE_TYPE (field) == gfc_array_index_type);
@@ -226,13 +226,13 @@ gfc_conv_descriptor_offset (tree desc)
 tree
 gfc_conv_descriptor_offset_get (tree desc)
 {
-  return gfc_conv_descriptor_offset (desc);
+  return get_descriptor_offset (desc);
 }
 
 void
 gfc_conv_descriptor_offset_set (stmtblock_t *block, tree desc, tree value)
 {
-  tree t = gfc_conv_descriptor_offset (desc);
+  tree t = get_descriptor_offset (desc);
   gfc_add_modify (block, t, fold_convert (TREE_TYPE (t), value));
 }
 
diff --git a/gcc/fortran/trans-descriptor.h b/gcc/fortran/trans-descriptor.h
index ade63bf19751..36365ff32ae0 100644
--- a/gcc/fortran/trans-descriptor.h
+++ b/gcc/fortran/trans-descriptor.h
@@ -57,7 +57,6 @@ tree gfc_conv_descriptor_type (tree desc);
 tree gfc_get_descriptor_dimension (tree desc);
 tree gfc_conv_descriptor_dimension (tree desc, tree dim);
 tree gfc_conv_descriptor_token (tree desc);
-tree gfc_conv_descriptor_offset (tree desc);
 
 tree gfc_conv_descriptor_data_get (tree desc);
 tree gfc_conv_descriptor_offset_get (tree desc);


[gcc(refs/users/meissner/heads/work221-sha)] PR target/117251: Improve vector orc to vector orc fusion

2025-09-20 Thread Michael Meissner via Gcc-cvs
https://gcc.gnu.org/g:474e1cdf6c6480bda90415e3130128761978808f

commit 474e1cdf6c6480bda90415e3130128761978808f
Author: Michael Meissner 
Date:   Mon Sep 8 15:24:37 2025 -0400

PR target/117251: Improve vector orc to vector orc fusion

See the following post for a complete explanation of what the patches
for PR target/117251:

 * https://gcc.gnu.org/pipermail/gcc-patches/2025-June/686474.html

This is patch #17 of 45 to generate the 'XXEVAL' instruction on power10
and power11 instead of using the Altivec 'VORC' instruction feeding
into 'VORC'.  The 'XXEVAL' instruction can use all 64 vector registers,
instead of the 32 registers that traditional Altivec vector
instructions use.  By allowing all of the vector registers to be used,
it reduces the amount of spilling that a large benchmark generated.

Currently the following code:

vector int a, b, c, d;
a = (c | ~ d) | ~ b;

Generates:

vorc   t,c,d
vorc   a,t,b

Now in addition with this patch, if the arguments or result is
allocated to a traditional FPR register, the GCC compiler will now
generate the following code instead of adding vector move instructions:

xxeval a,b,c,79

Since fusion using 2 Altivec instructions is slightly faster than using
the 'XXEVAL' instruction we prefer to generate the Altivec instructions
if we can.  In addition, because 'XXEVAL' is a prefixed instruction, it
possibly might generate an extra NOP instruction to align the 'XXEVAL'
instruction.

I have tested these patches on both big endian and little endian
PowerPC servers, with no regressions.  Can I check these patchs into
the trunk?

2025-09-08  Michael Meissner  

gcc/

PR target/117251
* config/rs6000/fusion.md: Regenerate.
* config/rs6000/genfusion.pl (gen_logical_addsubf): Add support
to generate vector orc => orc fusion if XXEVAL is supported.

Diff:
---
 gcc/config/rs6000/fusion.md| 15 +--
 gcc/config/rs6000/genfusion.pl |  1 +
 2 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/gcc/config/rs6000/fusion.md b/gcc/config/rs6000/fusion.md
index f84d0aee5d79..486aa813575d 100644
--- a/gcc/config/rs6000/fusion.md
+++ b/gcc/config/rs6000/fusion.md
@@ -2885,20 +2885,23 @@
 ;; logical-logical fusion pattern generated by gen_logical_addsubf
 ;; vector vorc -> vorc
 (define_insn "*fuse_vorc_vorc"
-  [(set (match_operand:VM 3 "altivec_register_operand" "=&0,&1,&v,v")
-(ior:VM (ior:VM (not:VM (match_operand:VM 0 "altivec_register_operand" 
"v,v,v,v"))
-  (match_operand:VM 1 "altivec_register_operand" 
"v,v,v,v"))
- (not:VM (match_operand:VM 2 "altivec_register_operand" 
"v,v,v,v"
-   (clobber (match_scratch:VM 4 "=X,X,X,&v"))]
+  [(set (match_operand:VM 3 "vector_fusion_operand" "=&0,&1,&v,wa,v")
+(ior:VM (ior:VM (not:VM (match_operand:VM 0 "vector_fusion_operand" 
"v,v,v,wa,v"))
+  (match_operand:VM 1 "vector_fusion_operand" 
"v,v,v,wa,v"))
+ (not:VM (match_operand:VM 2 "vector_fusion_operand" 
"v,v,v,wa,v"
+   (clobber (match_scratch:VM 4 "=X,X,X,X,&v"))]
   "(TARGET_P10_FUSION)"
   "@
vorc %3,%1,%0\;vorc %3,%3,%2
vorc %3,%1,%0\;vorc %3,%3,%2
vorc %3,%1,%0\;vorc %3,%3,%2
+   xxeval %x3,%x2,%x1,%x0,79
vorc %4,%1,%0\;vorc %3,%4,%2"
   [(set_attr "type" "fused_vector")
(set_attr "cost" "6")
-   (set_attr "length" "8")])
+   (set_attr "length" "8")
+   (set_attr "prefixed" "*,*,*,yes,*")
+   (set_attr "isa" "*,*,*,xxeval,*")])
 
 ;; logical-logical fusion pattern generated by gen_logical_addsubf
 ;; vector vxor -> vorc
diff --git a/gcc/config/rs6000/genfusion.pl b/gcc/config/rs6000/genfusion.pl
index 8ba1aa081f75..8f60fe76c87b 100755
--- a/gcc/config/rs6000/genfusion.pl
+++ b/gcc/config/rs6000/genfusion.pl
@@ -231,6 +231,7 @@ sub gen_logical_addsubf
   "vandc_vor"   =>  47,
   "vorc_vnor"   =>  64,
   "vorc_veqv"   =>  75,
+  "vorc_vorc"   =>  79,
 );
 
 KIND: foreach $kind ('scalar','vector') {


[gcc(refs/vendors/riscv/heads/gcc-15-with-riscv-opts)] RISC-V: Adjust vx combine test case to avoid name conflict

2025-09-20 Thread Jeff Law via Gcc-cvs
https://gcc.gnu.org/g:3970b35b22ffbd31b0d1e8caabb2b73305f5c95a

commit 3970b35b22ffbd31b0d1e8caabb2b73305f5c95a
Author: Pan Li 
Date:   Tue May 13 11:12:53 2025 +0800

RISC-V: Adjust vx combine test case to avoid name conflict

Given we will put all vx combine for int8 in a single file,
we need to make sure the generate function for different
types and ops has different function name.  Thus, refactor
the test helper macros for avoiding possible function name
conflict.

The below test suites are passed for this patch series.
* The rv64gcv fully regression test.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/autovec/vx_vf/vx-1-i16.c: Add
type and op name to generate test function name.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-1-i32.c: Ditto
* gcc.target/riscv/rvv/autovec/vx_vf/vx-1-i64.c: Ditto
* gcc.target/riscv/rvv/autovec/vx_vf/vx-1-i8.c: Ditto
* gcc.target/riscv/rvv/autovec/vx_vf/vx-1-u16.c: Ditto
* gcc.target/riscv/rvv/autovec/vx_vf/vx-1-u32.c: Ditto
* gcc.target/riscv/rvv/autovec/vx_vf/vx-1-u64.c: Ditto
* gcc.target/riscv/rvv/autovec/vx_vf/vx-1-u8.c: Ditto
* gcc.target/riscv/rvv/autovec/vx_vf/vx-2-i16.c: Ditto
* gcc.target/riscv/rvv/autovec/vx_vf/vx-2-i32.c: Ditto
* gcc.target/riscv/rvv/autovec/vx_vf/vx-2-i64.c: Ditto
* gcc.target/riscv/rvv/autovec/vx_vf/vx-2-i8.c: Ditto
* gcc.target/riscv/rvv/autovec/vx_vf/vx-2-u16.c: Ditto
* gcc.target/riscv/rvv/autovec/vx_vf/vx-2-u32.c: Ditto
* gcc.target/riscv/rvv/autovec/vx_vf/vx-2-u64.c: Ditto
* gcc.target/riscv/rvv/autovec/vx_vf/vx-2-u8.c: Ditto
* gcc.target/riscv/rvv/autovec/vx_vf/vx-3-i16.c: Ditto
* gcc.target/riscv/rvv/autovec/vx_vf/vx-3-i32.c: Ditto
* gcc.target/riscv/rvv/autovec/vx_vf/vx-3-i64.c: Ditto
* gcc.target/riscv/rvv/autovec/vx_vf/vx-3-i8.c: Ditto
* gcc.target/riscv/rvv/autovec/vx_vf/vx-3-u16.c: Ditto
* gcc.target/riscv/rvv/autovec/vx_vf/vx-3-u32.c: Ditto
* gcc.target/riscv/rvv/autovec/vx_vf/vx-3-u64.c: Ditto
* gcc.target/riscv/rvv/autovec/vx_vf/vx-3-u8.c: Ditto
* gcc.target/riscv/rvv/autovec/vx_vf/vx-4-i16.c: Ditto
* gcc.target/riscv/rvv/autovec/vx_vf/vx-4-i32.c: Ditto
* gcc.target/riscv/rvv/autovec/vx_vf/vx-4-i64.c: Ditto
* gcc.target/riscv/rvv/autovec/vx_vf/vx-4-i8.c: Ditto
* gcc.target/riscv/rvv/autovec/vx_vf/vx-4-u16.c: Ditto
* gcc.target/riscv/rvv/autovec/vx_vf/vx-4-u32.c: Ditto
* gcc.target/riscv/rvv/autovec/vx_vf/vx-4-u64.c: Ditto
* gcc.target/riscv/rvv/autovec/vx_vf/vx-4-u8.c: Ditto
* gcc.target/riscv/rvv/autovec/vx_vf/vx-5-i16.c: Ditto
* gcc.target/riscv/rvv/autovec/vx_vf/vx-5-i32.c: Ditto
* gcc.target/riscv/rvv/autovec/vx_vf/vx-5-i64.c: Ditto
* gcc.target/riscv/rvv/autovec/vx_vf/vx-5-i8.c: Ditto
* gcc.target/riscv/rvv/autovec/vx_vf/vx-5-u16.c: Ditto
* gcc.target/riscv/rvv/autovec/vx_vf/vx-5-u32.c: Ditto
* gcc.target/riscv/rvv/autovec/vx_vf/vx-5-u64.c: Ditto
* gcc.target/riscv/rvv/autovec/vx_vf/vx-5-u8.c: Ditto
* gcc.target/riscv/rvv/autovec/vx_vf/vx-6-i16.c: Ditto
* gcc.target/riscv/rvv/autovec/vx_vf/vx-6-i32.c: Ditto
* gcc.target/riscv/rvv/autovec/vx_vf/vx-6-i64.c: Ditto
* gcc.target/riscv/rvv/autovec/vx_vf/vx-6-i8.c: Ditto
* gcc.target/riscv/rvv/autovec/vx_vf/vx-6-u16.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-6-u32.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-6-u64.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-6-u8.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx_vadd-run-1-i16.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx_vadd-run-1-i32.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx_vadd-run-1-i64.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx_vadd-run-1-i8.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx_vadd-run-1-u16.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx_vadd-run-1-u32.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx_vadd-run-1-u64.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx_vadd-run-1-u8.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx_binary.h: Refine the
test helper macros to avoid conflict.
* gcc.target/riscv/rvv/autovec/vx_vf/vx_binary_run.h: Ditto.

Signed-off-by: Pan Li 
(cherry picked from commit 4f4eb9b7dd7dad0eec4eae8443a98eeded4fe070)

Diff:
---
 .../gcc.target/riscv/rvv/autovec/vx_vf/vx-1-i16.c  |  2 +-
 .../gcc.target/riscv/rvv/autovec/vx_vf/vx-1-i32.c  |  2 +-
 .../gcc.target/riscv/rvv/autovec/vx_vf/

[gcc(refs/users/mikael/heads/refactor_descriptor_v08)] Correction matmul.m4

2025-09-20 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:0d733c8fd019d8de0e6467f5525f0705f9ceef2a

commit 0d733c8fd019d8de0e6467f5525f0705f9ceef2a
Author: Mikael Morin 
Date:   Tue Sep 9 15:54:32 2025 +0200

Correction matmul.m4

Diff:
---
 libgfortran/m4/matmul_internal.m4 | 7 +++
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/libgfortran/m4/matmul_internal.m4 
b/libgfortran/m4/matmul_internal.m4
index 2343cd6cc837..b5fe0c1213f3 100644
--- a/libgfortran/m4/matmul_internal.m4
+++ b/libgfortran/m4/matmul_internal.m4
@@ -106,12 +106,12 @@ sinclude(`matmul_asm_'rtype_code`.m4')dnl
   rystride = GFC_DESCRIPTOR_STRIDE(retarray,1);
 }
 
-
   if (GFC_DESCRIPTOR_RANK (a) == 1)
 {
   /* Treat it as a a row matrix A[1,count]. */
   axstride = GFC_DESCRIPTOR_STRIDE(a,0);
   aystride = 1;
+  aystride_bytes = sizeof ('rtype_name`);
 
   xcount = 1;
   count = GFC_DESCRIPTOR_EXTENT(a,0);
@@ -120,6 +120,7 @@ sinclude(`matmul_asm_'rtype_code`.m4')dnl
 {
   axstride = GFC_DESCRIPTOR_STRIDE(a,0);
   aystride = GFC_DESCRIPTOR_STRIDE(a,1);
+  aystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,1);
 
   count = GFC_DESCRIPTOR_EXTENT(a,1);
   xcount = GFC_DESCRIPTOR_EXTENT(a,0);
@@ -148,6 +149,7 @@ sinclude(`matmul_asm_'rtype_code`.m4')dnl
 {
   bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
   bystride = GFC_DESCRIPTOR_STRIDE(b,1);
+  bystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,1);
   ycount = GFC_DESCRIPTOR_EXTENT(b,1);
 }
 
@@ -193,9 +195,6 @@ sinclude(`matmul_asm_'rtype_code`.m4')dnl
}
 }
 
-  aystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,1);
-  bystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,1);
-
   if (rxstride == 1 && axstride == 1 && bxstride == 1
   && GFC_DESCRIPTOR_RANK (b) != 1)
 {


[gcc r16-3865] ada: Recommend GPR's Toolchain_Name for GNAT LLVM more prominently

2025-09-20 Thread Marc Poulhies via Gcc-cvs
https://gcc.gnu.org/g:f915b22580ef608485ad1ae3d20c4c42107a6083

commit r16-3865-gf915b22580ef608485ad1ae3d20c4c42107a6083
Author: Sebastian Poeplau 
Date:   Wed Aug 27 10:00:10 2025 +0200

ada: Recommend GPR's Toolchain_Name for GNAT LLVM more prominently

gcc/ada/ChangeLog:

* doc/gnat_ugn/building_executable_programs_with_gnat.rst: Move
recommendation of Toolchain_Name up.
* gnat_ugn.texi: Regenerate.

Diff:
---
 .../building_executable_programs_with_gnat.rst | 26 +--
 gcc/ada/gnat_ugn.texi  | 30 ++
 2 files changed, 26 insertions(+), 30 deletions(-)

diff --git a/gcc/ada/doc/gnat_ugn/building_executable_programs_with_gnat.rst 
b/gcc/ada/doc/gnat_ugn/building_executable_programs_with_gnat.rst
index fdf19481a6fc..2a26e4659b8b 100644
--- a/gcc/ada/doc/gnat_ugn/building_executable_programs_with_gnat.rst
+++ b/gcc/ada/doc/gnat_ugn/building_executable_programs_with_gnat.rst
@@ -8116,20 +8116,18 @@ We provide two options that you can use to build code 
with GNAT LLVM:
 
 * ``gprbuild`` can detect and use GNAT LLVM when it is installed.
 
-  ``gprbuild`` uses the first applicable compiler on the executable
-  search path, including GNAT LLVM.  An easy way to build with GNAT
-  LLVM is to make it available on the operating system's search path
-  before any other Ada compiler (such as the GCC version of GNAT). To
-  avoid accidentally using a different compiler than the one you want
-  to use, we recommend generating an explicit toolchain configuration
-  file with ``gprconfig`` and using it with ``gprbuild``; see the
-  *GPRbuild and GPR Companion Tools User's Guide* for details. You
-  can determine from the first line of the :file:`.ali` file
-  which version of GNAT built that file because it contains either
-  :code:`GNAT` or :code:`GNAT-LLVM`.
-
-  You can also explicitly select GNAT LLVM in your existing GPR project
-  file by adding :code:`for Toolchain_Name("Ada") use "GNAT_LLVM";`
+  ``gprbuild`` uses the first applicable compiler on the executable search
+  path, including GNAT LLVM. An easy way to build with GNAT LLVM is to make
+  it available on the operating system's search path before any other Ada
+  compiler (such as the GCC version of GNAT). To avoid accidentally using a
+  different compiler than the one you want to use, we recommend explicitly
+  selecting GNAT LLVM in your existing GPR project file by adding
+  :code:`for Toolchain_Name ("Ada") use "GNAT_LLVM";`. You can also
+  generate an explicit toolchain configuration file with ``gprconfig`` and
+  use it with ``gprbuild``; see the *GPRbuild and GPR Companion Tools
+  User's Guide* for details. You can determine from the first line of the
+  :file:`.ali` file which version of GNAT built that file because it
+  contains either :code:`GNAT` or :code:`GNAT-LLVM`.
 
 .. only:: PRO
 
diff --git a/gcc/ada/gnat_ugn.texi b/gcc/ada/gnat_ugn.texi
index 48958f89256e..e0c2d2571f61 100644
--- a/gcc/ada/gnat_ugn.texi
+++ b/gcc/ada/gnat_ugn.texi
@@ -19,7 +19,7 @@
 
 @copying
 @quotation
-GNAT User's Guide for Native Platforms , Sep 05, 2025
+GNAT User's Guide for Native Platforms , Sep 12, 2025
 
 AdaCore
 
@@ -17653,20 +17653,18 @@ version of GNAT.
 @item 
 @code{gprbuild} can detect and use GNAT LLVM when it is installed.
 
-@code{gprbuild} uses the first applicable compiler on the executable
-search path, including GNAT LLVM.  An easy way to build with GNAT
-LLVM is to make it available on the operating system’s search path
-before any other Ada compiler (such as the GCC version of GNAT). To
-avoid accidentally using a different compiler than the one you want
-to use, we recommend generating an explicit toolchain configuration
-file with @code{gprconfig} and using it with @code{gprbuild}; see the
-`GPRbuild and GPR Companion Tools User’s Guide' for details. You
-can determine from the first line of the @code{.ali} file
-which version of GNAT built that file because it contains either
-@code{GNAT} or @code{GNAT-LLVM}.
-
-You can also explicitly select GNAT LLVM in your existing GPR project
-file by adding @code{for Toolchain_Name("Ada") use "GNAT_LLVM";}
+@code{gprbuild} uses the first applicable compiler on the executable search
+path, including GNAT LLVM. An easy way to build with GNAT LLVM is to make
+it available on the operating system’s search path before any other Ada
+compiler (such as the GCC version of GNAT). To avoid accidentally using a
+different compiler than the one you want to use, we recommend explicitly
+selecting GNAT LLVM in your existing GPR project file by adding
+@code{for Toolchain_Name ("Ada") use "GNAT_LLVM";}. You can also
+generate an explicit toolchain configuration file with @code{gprconfig} and
+use it with @code{gprbuild}; see the `GPRbuild and GPR Companion Tools
+User’s Guide' for details. You can determine from the first line of the
+@code{.ali} file which version of GNAT built that file because 

[gcc(refs/users/mikael/heads/refactor_descriptor_v08)] Appel méthode shift descriptor dans gfc_trans_pointer_assignment

2025-09-20 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:a312a4aa8243d993235262cfc6e2660d89c9a6b1

commit a312a4aa8243d993235262cfc6e2660d89c9a6b1
Author: Mikael Morin 
Date:   Wed Jul 16 15:07:58 2025 +0200

Appel méthode shift descriptor dans gfc_trans_pointer_assignment

Diff:
---
 gcc/fortran/trans-descriptor.cc | 92 +
 gcc/fortran/trans-descriptor.h  |  1 +
 gcc/fortran/trans-expr.cc   | 28 +
 3 files changed, 95 insertions(+), 26 deletions(-)

diff --git a/gcc/fortran/trans-descriptor.cc b/gcc/fortran/trans-descriptor.cc
index b8ab46190fe4..591887cb70e2 100644
--- a/gcc/fortran/trans-descriptor.cc
+++ b/gcc/fortran/trans-descriptor.cc
@@ -1027,3 +1027,95 @@ gfc_conv_shift_descriptor (stmtblock_t* block, tree 
desc, int rank)
 gfc_conv_shift_descriptor_lbound (block, desc, dim,
  gfc_index_one_node);
 }
+
+
+static void
+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.  */
+  for (int dim = 0; dim < rank; ++dim)
+{
+  gfc_expr *lb_expr = lbound[dim];
+
+  tree lower_bound;
+  if (lb_expr == nullptr)
+   lower_bound = gfc_index_one_node;
+  else
+   {
+ gfc_se lb_se;
+
+ gfc_init_se (&lb_se, nullptr);
+ gfc_conv_expr (&lb_se, lb_expr);
+
+ gfc_add_block_to_block (block, &lb_se.pre);
+ tree lb_var = gfc_create_var (TREE_TYPE (lb_se.expr), "lower_bound");
+ gfc_add_modify (block, lb_var, lb_se.expr);
+ gfc_add_block_to_block (block, &lb_se.post);
+
+ lower_bound = lb_var;
+   }
+
+  gfc_conv_shift_descriptor_lbound (block, desc, dim, lower_bound);
+}
+}
+
+
+static void
+conv_shift_descriptor (stmtblock_t *block, tree desc,
+  const gfc_array_spec &as)
+{
+  conv_shift_descriptor (block, desc, as.rank, as.lower);
+}
+
+
+static void
+set_type (array_type &type, array_type value)
+{
+  gcc_assert (type == AS_UNKNOWN || type == value);
+  type = value;
+}
+
+
+static void
+array_ref_to_array_spec (const gfc_array_ref &ref, gfc_array_spec &spec)
+{
+  spec.rank = ref.dimen;
+  spec.corank = ref.codimen;
+
+  spec.type = AS_UNKNOWN;
+  spec.cotype = AS_ASSUMED_SIZE;
+
+  for (int dim = 0; dim < spec.rank + spec.corank; dim++)
+switch (ref.dimen_type[dim])
+  {
+  case DIMEN_ELEMENT:
+   spec.upper[dim] = ref.start[dim];
+   set_type (spec.type, AS_EXPLICIT);
+   break;
+
+  case DIMEN_RANGE:
+   spec.lower[dim] = ref.start[dim];
+   spec.upper[dim] = ref.end[dim];
+   if (spec.upper[dim] == nullptr)
+ set_type (spec.type, AS_DEFERRED);
+   else
+ set_type (spec.type, AS_EXPLICIT);
+   break;
+
+  default:
+   break;
+  }
+}
+
+
+void
+gfc_conv_shift_descriptor (stmtblock_t *block, tree desc,
+  const gfc_array_ref &ar)
+{
+  gfc_array_spec as;
+
+  array_ref_to_array_spec (ar, as);
+
+  conv_shift_descriptor (block, desc, as);
+}
diff --git a/gcc/fortran/trans-descriptor.h b/gcc/fortran/trans-descriptor.h
index 21c52e37f0e0..1d9a640bccb5 100644
--- a/gcc/fortran/trans-descriptor.h
+++ b/gcc/fortran/trans-descriptor.h
@@ -102,6 +102,7 @@ void gfc_init_descriptor_variable (stmtblock_t *block, 
gfc_symbol *sym, tree des
 
 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_set_descriptor_from_scalar_class (stmtblock_t *, tree, tree, gfc_expr 
*);
 void gfc_set_descriptor_from_scalar (stmtblock_t *, tree, tree, 
symbol_attribute,
diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc
index 440e9783ac45..969b6712ea7f 100644
--- a/gcc/fortran/trans-expr.cc
+++ b/gcc/fortran/trans-expr.cc
@@ -11306,32 +11306,8 @@ gfc_trans_pointer_assignment (gfc_expr * expr1, 
gfc_expr * expr2)
}
}
  else
-   {
- /* Bounds remapping.  Just shift the lower bounds.  */
-
- gcc_assert (expr1->rank == expr2->rank);
-
- for (dim = 0; dim < remap->u.ar.dimen; ++dim)
-   {
- gfc_se lbound_se;
-
- gcc_assert (!remap->u.ar.end[dim]);
- gfc_init_se (&lbound_se, NULL);
- if (remap->u.ar.start[dim])
-   {
- gfc_conv_expr (&lbound_se, remap->u.ar.start[dim]);
- gfc_add_block_to_block (&block, &lbound_se.pre);
-   }
- else
-   /* This remap arises from a target that is not a whole
-  array. The start expressions will be NULL but we need
-  the lbounds to be one.  */
-   lbound_se.expr = gfc_index_one_node;
- gfc_conv_shif

[gcc(refs/users/mikael/heads/refactor_descriptor_v08)] gimple-simulate: prise en charge BUILTIN_REALLOC

2025-09-20 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:5032e81841e0aa1f5ae3baf5aaff9a71b4efeeac

commit 5032e81841e0aa1f5ae3baf5aaff9a71b4efeeac
Author: Mikael Morin 
Date:   Tue Jul 29 17:43:43 2025 +0200

gimple-simulate: prise en charge BUILTIN_REALLOC

Diff:
---
 gcc/gimple-simulate.cc | 181 +
 1 file changed, 181 insertions(+)

diff --git a/gcc/gimple-simulate.cc b/gcc/gimple-simulate.cc
index 1836f5d4b539..7f8c9d31b3b3 100644
--- a/gcc/gimple-simulate.cc
+++ b/gcc/gimple-simulate.cc
@@ -2526,6 +2526,39 @@ simul_scope::simulate_call (gcall *g)
 
   storage0.set (dest_val);
 }
+  else if (gimple_call_builtin_p (g, BUILT_IN_REALLOC))
+{
+  gcc_assert (lhs != NULL_TREE);
+  result.emplace (data_value (TREE_TYPE (lhs)));
+
+  gcc_assert (gimple_call_num_args (g) == 2);
+  tree arg0 = gimple_call_arg (g, 0);
+  tree arg1 = gimple_call_arg (g, 1);
+  data_value ptr0 = evaluate (arg0);
+  data_value size1 = evaluate (arg1);
+  gcc_assert (ptr0.classify () == VAL_ADDRESS);
+  gcc_assert (size1.classify () == VAL_KNOWN);
+
+  wide_int wi_size1 = size1.get_known ();
+  gcc_assert (wi::fits_uhwi_p (wi_size1));
+  HOST_WIDE_INT alloc_amount = wi_size1.to_uhwi ();
+  data_storage &storage = allocate (alloc_amount);
+
+  storage_address addr0 = *ptr0.get_address ();
+  data_storage & storage0 = addr0.storage.get ();
+  data_value src = storage0.get_value ();
+
+  wide_int wi_bitwidth = wi_size1 * CHAR_BIT;
+  gcc_assert (wi::fits_uhwi_p (wi_bitwidth));
+  HOST_WIDE_INT bitwidth = wi_bitwidth.to_uhwi ();
+  data_value dest (bitwidth);
+  dest.set_at (0, std::min (src.get_bitwidth (), dest.get_bitwidth ()),
+  src, 0);
+  storage.set (dest);
+
+  storage_address address (storage.get_ref (), 0);
+  (*result).set_address (address);
+}
   else
 {
   tree fn = gimple_call_fn (g);
@@ -6979,6 +7012,154 @@ simul_scope_simulate_call_tests ()
   wide_int wi105_after2 = val105_after2.get_known ();
   ASSERT_PRED1 (wi::fits_shwi_p, wi105_after2);
   ASSERT_EQ (wi105_after2.to_shwi (), 17);
+
+
+  tree p1_11 = create_var (ptr_type_node, "p1");
+  tree p2_11 = create_var (ptr_type_node, "p2");
+  tree c29 = build_array_type_nelts (char_type_node, 29);
+  tree ac29_11 = create_var (c29, "ac29");
+
+  vec decls11{};
+  decls11.safe_push (p1_11);
+  decls11.safe_push (p2_11);
+  decls11.safe_push (ac29_11);
+
+  heap_memory mem11;
+  context_builder builder11 {};
+  builder11.add_decls (&decls11);
+  simul_scope ctx11 = builder11.build (mem11, printer);
+
+  data_storage * storage_ac29_11 = ctx11.find_reachable_var (ac29_11);
+  gcc_assert (storage_ac29_11 != nullptr);
+
+  storage_address addr29_11 (storage_ac29_11->get_ref (), CHAR_BIT);
+  data_value val_addr29_11 (ptr_type_node);
+  val_addr29_11.set_address (addr29_11);
+
+  data_storage * storage_p2_11 = ctx11.find_reachable_var (p2_11);
+  gcc_assert (storage_p2_11 != nullptr);
+  storage_p2_11->set (val_addr29_11);
+
+  storage_address addr_p2_11 (storage_p2_11->get_ref (), 0);
+  data_value val_c29 (c29);
+  val_c29.set_address_at (addr_p2_11, HOST_BITS_PER_PTR);
+  wide_int wi23_11 = wi::shwi (23, TYPE_PRECISION (integer_type_node));
+  val_c29.set_known_at (wi23_11, 20 * CHAR_BIT);
+  storage_ac29_11->set (val_c29);
+
+  tree realloc_fn = builtin_decl_explicit (BUILT_IN_REALLOC);
+  gcall *realloc_call11 = gimple_build_call (realloc_fn, 2, p2_11,
+build_int_cst (size_type_node, 
31));
+  gimple_call_set_lhs (realloc_call11, p1_11);
+
+  data_storage * storage_p1_11 = ctx11.find_reachable_var (p1_11);
+  gcc_assert (storage_p1_11 != nullptr);
+
+  data_value val_p1_11_before = storage_p1_11->get_value ();
+  ASSERT_EQ (val_p1_11_before.classify (), VAL_UNDEFINED);
+
+  ctx11.simulate (realloc_call11);
+
+  data_value val_p1_11_after = storage_p1_11->get_value ();
+  ASSERT_EQ (val_p1_11_after.classify (), VAL_ADDRESS);
+  storage_address * addr_p1_11 = val_p1_11_after.get_address ();
+  storage_ref storage_ref_addr_p1_11 = addr_p1_11->storage;
+  ASSERT_EQ (storage_ref_addr_p1_11.type, STRG_ALLOC);
+  data_storage & storage_addr_p1_11 = storage_ref_addr_p1_11.get ();
+  ASSERT_EQ (storage_addr_p1_11.get_type (), STRG_ALLOC);
+
+  data_value val_strg_p1_11 = storage_addr_p1_11.get_value ();
+  ASSERT_EQ (val_strg_p1_11.get_bitwidth (), 31 * CHAR_BIT);
+  ASSERT_EQ (val_strg_p1_11.classify (), VAL_MIXED);
+
+  ASSERT_EQ (val_strg_p1_11.classify (0, HOST_BITS_PER_PTR),
+VAL_UNDEFINED);
+  ASSERT_EQ (val_strg_p1_11.classify (HOST_BITS_PER_PTR, HOST_BITS_PER_PTR),
+VAL_ADDRESS);
+  ASSERT_EQ (val_strg_p1_11.classify (2 * HOST_BITS_PER_PTR, 
HOST_BITS_PER_INT),
+VAL_UNDEFINED);
+  ASSERT_EQ (val_strg_p1_11.classify (20 * CHAR_BIT, HOST_BITS_PER_INT),
+VAL_KNOWN);
+
+  data_value val_ptr_strg_p1_11 = val_strg_p1_11.get_at (HOST_BITS_PER_

[gcc(refs/users/mikael/heads/refactor_descriptor_v08)] Utilisation gfc_conv_descriptor_token_set

2025-09-20 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:282c45c404ca4c15ecfdb1ee5e199e558a94c449

commit 282c45c404ca4c15ecfdb1ee5e199e558a94c449
Author: Mikael Morin 
Date:   Tue Jul 15 17:17:33 2025 +0200

Utilisation gfc_conv_descriptor_token_set

Diff:
---
 gcc/fortran/trans-array.cc  | 12 +---
 gcc/fortran/trans-descriptor.cc | 10 ++
 gcc/fortran/trans-descriptor.h  |  1 +
 gcc/fortran/trans-expr.cc   | 12 +---
 gcc/fortran/trans-intrinsic.cc  |  3 +--
 5 files changed, 22 insertions(+), 16 deletions(-)

diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc
index 5c31b3879206..3b86377e3e29 100644
--- a/gcc/fortran/trans-array.cc
+++ b/gcc/fortran/trans-array.cc
@@ -8444,7 +8444,7 @@ gfc_conv_expr_descriptor (gfc_se *se, gfc_expr *expr)
  tmp = GFC_TYPE_ARRAY_CAF_TOKEN (TREE_TYPE (tmp));
}
 
- gfc_add_modify (&loop.pre, gfc_conv_descriptor_token (parm), tmp);
+ gfc_conv_descriptor_token_set (&loop.pre, parm, tmp);
}
   desc = parm;
 }
@@ -9053,7 +9053,7 @@ gfc_conv_array_parameter (gfc_se *se, gfc_expr *expr, 
bool g77,
}
  else if (!ctree)
{
- tree old_field, new_field;
+ tree old_field;
 
  /* The original descriptor has transposed dims so we can't reuse
 it directly; we have to create a new one.  */
@@ -9081,8 +9081,8 @@ gfc_conv_array_parameter (gfc_se *se, gfc_expr *expr, 
bool g77,
 == GFC_ARRAY_ALLOCATABLE)
{
  old_field = gfc_conv_descriptor_token (old_desc);
- new_field = gfc_conv_descriptor_token (new_desc);
- gfc_add_modify (&se->pre, new_field, old_field);
+ gfc_conv_descriptor_token_set (&se->pre, new_desc,
+old_field);
}
 
  gfc_conv_descriptor_data_set (&se->pre, new_desc, ptr);
@@ -11938,9 +11938,7 @@ gfc_trans_deferred_array (gfc_symbol * sym, 
gfc_wrapped_block * block)
 image.  This may happen, for example, with the caf_mpi
 implementation.  */
  TREE_STATIC (descriptor) = 1;
- tmp = gfc_conv_descriptor_token (descriptor);
- gfc_add_modify (&init, tmp, fold_convert (TREE_TYPE (tmp),
-   null_pointer_node));
+ gfc_conv_descriptor_token_set (&init, descriptor, null_pointer_node);
}
 }
 
diff --git a/gcc/fortran/trans-descriptor.cc b/gcc/fortran/trans-descriptor.cc
index 578dcb21ef06..1430f948bd1f 100644
--- a/gcc/fortran/trans-descriptor.cc
+++ b/gcc/fortran/trans-descriptor.cc
@@ -519,6 +519,16 @@ gfc_conv_descriptor_token (tree desc)
   return field;
 }
 
+void
+gfc_conv_descriptor_token_set (stmtblock_t *block, tree desc, tree value)
+{
+  location_t loc = input_location;
+  tree t = gfc_conv_descriptor_token (desc);
+  gfc_add_modify_loc (loc, block, t,
+ fold_convert_loc (loc, TREE_TYPE (t), value));
+}
+
+
 static tree
 gfc_conv_descriptor_subfield (tree desc, tree dim, unsigned field_idx)
 {
diff --git a/gcc/fortran/trans-descriptor.h b/gcc/fortran/trans-descriptor.h
index 0547157bf2af..3f602219c284 100644
--- a/gcc/fortran/trans-descriptor.h
+++ b/gcc/fortran/trans-descriptor.h
@@ -83,6 +83,7 @@ void gfc_conv_descriptor_dimension_set (stmtblock_t *block, 
tree desc, int dim,
 void gfc_conv_descriptor_stride_set (stmtblock_t *block, tree desc, tree dim, 
tree value);
 void gfc_conv_descriptor_lbound_set (stmtblock_t *block, tree desc, tree dim, 
tree value);
 void gfc_conv_descriptor_ubound_set (stmtblock_t *block, tree desc, tree dim, 
tree value);
+void gfc_conv_descriptor_token_set (stmtblock_t *block, tree desc, tree value);
 
 tree gfc_build_null_descriptor (tree type);
 
diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc
index 4f17c1545974..96f3a9e5e16c 100644
--- a/gcc/fortran/trans-expr.cc
+++ b/gcc/fortran/trans-expr.cc
@@ -849,7 +849,7 @@ gfc_conv_derived_to_class (gfc_se *parmse, gfc_expr *e, 
gfc_symbol *fsym,
   if (POINTER_TYPE_P (TREE_TYPE (tmp)))
tmp = build_fold_indirect_ref (tmp);
   gfc_get_caf_token_offset (parmse, &token, nullptr, tmp, NULL_TREE, e);
-  gfc_add_modify (&parmse->pre, gfc_conv_descriptor_token (ctree), token);
+  gfc_conv_descriptor_token_set (&parmse->pre, ctree, token);
 }
 
   if (optional)
@@ -9945,8 +9945,7 @@ gfc_trans_subcomponent_assign (tree dest, gfc_component * 
cm,
{
  gfc_conv_descriptor_data_set (&block, dest, null_pointer_node);
  if (cm->attr.codimension && flag_coarray == GFC_FCOARRAY_LIB)
-   gfc_add_modify (&block, gfc_conv_descriptor_token (dest),
-   null_pointer_node);
+   gfc_conv_descriptor_token_set (&block, dest, null_pointer_node);
}
   else if (cm->attr.allocatable || cm->attr.pdt_array)
{
@@ -11710,10 +11709,9 @@ gfc_trans_scalar

[gcc r16-3770] ada: Disable signals when calling pthread_create on QNX

2025-09-20 Thread Marc Poulhies via Gcc-cvs
https://gcc.gnu.org/g:7cbf4b85b2c98b503a7fdff507fa39fca3a09b6e

commit r16-3770-g7cbf4b85b2c98b503a7fdff507fa39fca3a09b6e
Author: Johannes Kliemann 
Date:   Wed Jul 9 17:40:55 2025 +0200

ada: Disable signals when calling pthread_create on QNX

The QNX Certified Products Defect Notification from February 2025
mentions a potential memory leak when pthread_create is interrupted by a
signal. It recommends to disable signals for this function call.

gcc/ada/ChangeLog:

* adaint.c: Add functions to disable and enable signals on QNX.
* libgnarl/s-taprop__qnx.adb (Create_Task): Disable
signals when calling pthread_create.

Diff:
---
 gcc/ada/adaint.c   | 63 ++
 gcc/ada/libgnarl/s-taprop__qnx.adb | 24 ---
 2 files changed, 83 insertions(+), 4 deletions(-)

diff --git a/gcc/ada/adaint.c b/gcc/ada/adaint.c
index adc39517280a..7b78d91e0e72 100644
--- a/gcc/ada/adaint.c
+++ b/gcc/ada/adaint.c
@@ -107,6 +107,7 @@
 #ifdef __QNX__
 #include 
 #include 
+#include 
 #endif
 
 #ifdef IN_RTS
@@ -3719,6 +3720,68 @@ void __gnat_killprocesstree (int pid, int sig_num)
   */
 }
 
+#if defined (__QNX__)
+
+static __thread sigset_t set;
+static __thread sigset_t oset;
+static __thread int signals_disabled = 0;
+
+int __gnat_disable_signals(void)
+{
+sigemptyset(&set);
+sigaddset(&set, SIGHUP);
+sigaddset(&set, SIGINT);
+sigaddset(&set, SIGQUIT);
+sigaddset(&set, SIGILL);
+sigaddset(&set, SIGTRAP);
+sigaddset(&set, SIGIOT);
+sigaddset(&set, SIGABRT);
+sigaddset(&set, SIGEMT);
+sigaddset(&set, SIGDEADLK);
+sigaddset(&set, SIGFPE);
+sigaddset(&set, SIGKILL);
+sigaddset(&set, SIGBUS);
+sigaddset(&set, SIGSEGV);
+sigaddset(&set, SIGSYS);
+sigaddset(&set, SIGPIPE);
+sigaddset(&set, SIGALRM);
+sigaddset(&set, SIGTERM);
+sigaddset(&set, SIGUSR1);
+sigaddset(&set, SIGUSR2);
+sigaddset(&set, SIGCHLD);
+sigaddset(&set, SIGCLD);
+sigaddset(&set, SIGPWR);
+sigaddset(&set, SIGWINCH);
+sigaddset(&set, SIGURG);
+sigaddset(&set, SIGPOLL);
+sigaddset(&set, SIGIO);
+sigaddset(&set, SIGSTOP);
+sigaddset(&set, SIGTSTP);
+sigaddset(&set, SIGCONT);
+sigaddset(&set, SIGTTIN);
+sigaddset(&set, SIGTTOU);
+sigaddset(&set, SIGVTALRM);
+sigaddset(&set, SIGPROF);
+sigaddset(&set, SIGXCPU);
+sigaddset(&set, SIGXFSZ);
+sigaddset(&set, SIGDOOM);
+
+int ret = sigprocmask(SIG_BLOCK, &set, &oset);
+signals_disabled = !ret;
+return ret;
+}
+
+int __gnat_enable_signals(void)
+{
+if (!signals_disabled) {
+return 0;
+}
+signals_disabled = 0;
+return sigprocmask(SIG_SETMASK, &oset, 0);
+}
+
+#endif
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/gcc/ada/libgnarl/s-taprop__qnx.adb 
b/gcc/ada/libgnarl/s-taprop__qnx.adb
index e7d245fec7de..b51f2b527082 100644
--- a/gcc/ada/libgnarl/s-taprop__qnx.adb
+++ b/gcc/ada/libgnarl/s-taprop__qnx.adb
@@ -766,6 +766,16 @@ package body System.Task_Primitives.Operations is
   function Thread_Body_Access is new
 Ada.Unchecked_Conversion (System.Address, Thread_Body);
 
+  function Disable_Signals return Interfaces.C.int with
+Import,
+Convention=> C,
+External_Name => "__gnat_disable_signals";
+
+  function Enable_Signals return Interfaces.C.int with
+Import,
+Convention=> C,
+External_Name => "__gnat_enable_signals";
+
begin
   Adjusted_Stack_Size :=
  Interfaces.C.size_t (Stack_Size + Alternate_Stack_Size);
@@ -840,10 +850,11 @@ package body System.Task_Primitives.Operations is
 
   pragma Assert (Result = 0);
 
-  --  Since the initial signal mask of a thread is inherited from the
-  --  creator, and the Environment task has all its signals masked, we
-  --  do not need to manipulate caller's signal mask at this point.
-  --  All tasks in RTS will have All_Tasks_Mask initially.
+  --  (QMS3263) lists PR 2894086. This defect causes a memory leak when
+  --  pthread_create is interrupted by a signal and later resumed. To avoid
+  --  avoid such a leak the document suggests to disable signals while
+  --  calling pthread_create. The signal mask of the calling thread is
+  --  restored after the call to pthread_create.
 
   --  The write to T.Common.LL.Thread is not racy with regard to the
   --  created thread because the created thread will not access it until
@@ -851,6 +862,8 @@ package body System.Task_Primitives.Operations is
   --  Restricted.Stages is used). One can verify that by inspecting the
   --  Task_Wrapper procedures.
 
+  Result := Disable_Signals;
+  pragma Assert (Result = 0);
   Result := pthread_create
 (T.Common.LL.Thread'Access,
  Attributes'Access,
@@ -860,6 +873,9 @@ package body System.Task_Primitives.Operations is
 
   Succeeded 

[gcc] Deleted branch 'mikael/heads/refactor_descriptor_v08' in namespace 'refs/users'

2025-09-20 Thread Mikael Morin via Gcc-cvs
The branch 'mikael/heads/refactor_descriptor_v08' in namespace 'refs/users' was 
deleted.
It previously pointed to:

 467f55e0bcb1... Correction régression pdt_31

Diff:

!!! WARNING: THE FOLLOWING COMMITS ARE NO LONGER ACCESSIBLE (LOST):
---

  467f55e... Correction régression pdt_31
  12bb1c7... Régénération des fichiers générés
  3191711... Réduction utilisations macro GFC_DESCRIPTOR_STRIDE
  671d6aa... Régénération fichiers générés
  eab8896... Réduction utilisation stride pour allocation/initialisatio
  9bb106c... Régénération fichiers générés
  7aa3c8d... Extraction ARRAY_ELEM_AT_OFFSET, PTR_ADD_OFFSET
  7247f16... Régénération des fichiers générés
  5d13f9d... Introduction macro PTR_INCREMENT_BYTES
  6750dc8... Régénération des fichiers générés
  daf39f4... Ajout macros GFC_DESCRIPTOR1_ELEM, etc
  f59ee42... Régénération fichiers générés
  47ffb89... Décalage indexs matmul
  491644b... Régénération fichiers générés
  d49f694... Correction quotation macros m4
  d23f1b6... Remplacement macro GFC_DIMENSION_SET -> GFC_DESCRIPTOR_DIME
  6e6cfa7... Renseignement span
  f5fa330... Extraction gfc_create_unallocated_library_result_descriptor
  b9cb223... Introduction gfc_conv_descriptor_extent_get
  6b00d5f... Refactor set_dimension_fields set_empty_descriptor
  a54c389... Refactor set_dimension_fields descriptor_init_count
  60e0b09... Refactoring set_dimension_fields set_pdt_array_descriptor
  77ed1d8... Factorisation set_dimension_bounds/shift_dimension_bounds g
  67666ef... Factorisation shift_dimension_fields/set_dimension_fields g
  6ce6398... Factorisation set_dimension_fields gfc_set_descriptor_with_
  215eb06... Factorisation set_dimension_fields gfc_set_descriptor
  5f77e19... Renseignement dtype initialisation statique
  35ddc62... Refactoring descriptor_write
  c877f34... Refactoring nullifcations descripteur
  97d3534... Suppression déclarations inutiles
  7069cc7... Déplacement initialisation dernière borne sup assumed siz
  93dbd09... Suppression set_dtype_if_unallocated
  6a96de7... Suppression déclarations inutiles
  35967a1... Extraction gfc_set_empty_descriptor_bounds
  6d9ca30... Déplacement gfc_array_init_count -> gfc_descriptor_init_co
  66251d0... Déplacement gfc_grow_array
  b47af53... Déplacemement plus de code gfc_set_pdt_array_descriptor
  680ce9d... Extraction gfc_set_pdt_array_descriptor
  f5c0fa1... Extraction gfc_set_descriptor_for_assign_realloc
  325ea51... Suppression mise à jour offset forall
  d594ecb... Extraction get_array_memory_size
  9738042... Mise à jour offset & span dans gfc_array_init_size
  b552327... Factorisation descriptor_element_size
  6dd4da9... Extraction gfc_set_temporary_descriptor
  5243a81... Refactoring set_dimension_fields
  0e943e2... Refactor set_dimension_bounds
  a15a4f5... Déroulement boucle set_gfc_from_cfi
  ef2b995... Refactor set_gfc_from_cfi
  ea74ff4... Extraction set_gfc_from_cfi
  be565a7... Extraction gfc_set_gfc_from_cfi
  5cf798d... Refactoring gfc_conv_descriptor_sm_get
  fbe9040... Factorisation utilisation shapeval
  baad800... Reindentation retour à la ligne set_descriptor_with_shape
  616fc48... Extraction set_descriptor_with_shape
  973ef63... Factorisation gfc_set_contiguous_descriptor
  f1bc70e... Extraction gfc_set_descriptor
  eca4e72... Calcul offset sans passer par le descripteur
  c4de21a... Modification initialisation stride
  238146e... Simplification initialisation offset remap descriptor
  e1f024a... Extraction gfc_conv_remap_descriptor
  2888c8a... Déplacement copy_descriptor
  a79b1e7... Extraction gfc_copy_descriptor
  cb75a4a... Extraction gfc_copy_descriptor
  f20d1d5... Extraction gfc_copy_descriptor
  a108733... Extraction gfc_copy_sequence_descriptor
  6441e6b... Refactoring shift descriptor
  57d5e98... Initialisation shifted offset en partant de zero
  07506fe... Extraction gfc_shift_descriptor
  e2e353d... Extraction gfc_conv_shift_subarray_descriptor
  13b2631... Factorisation gfc_conv_shift_descriptor
  671cb2b... Extraction gfc_conv_shift_descriptor
  a312a4a... Appel méthode shift descriptor dans gfc_trans_pointer_assi
  877f897... Déplacement shift descriptor vers gfc_conv_array_parameter
  bce0873... Refactoring gfc_set_descriptor_from_scalar
  ff179b8... Renseignement token dans gcf_set_descriptor_from_scalar
  a3c24bc... Extraction gfc_set_descriptor_from_scalar
  9c131b3... Extraction gfc_set_descriptor_from_scalar
  53b1048... Extraction gfc_set_descriptor_from_scalar
  94d5fa0... Refactoring gfc_get_scalar_to_descriptor_type
  c61566f... Refactoring gfc_get_scalar_to_descriptor_type
  0583678... Introduction gfc_create_null_actual_descriptor
  4a85dd0... Refactoring gfc_nullify_descriptor/gfc_init_descriptor_vari
  591c369... Refactor gfc_init_descriptor_variable
  a1964fd... Modif gfc_init_descriptor_variable
  5009dd1... Introduction gfc_symbol_attr
  f0297fd... Renseignement dtype par défaut
  df4f4e5... Extraction gfc_init_descr

[gcc(refs/users/mikael/heads/refactor_descriptor_v08)] Refactoring nullifcations descripteur

2025-09-20 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:c877f3484854b0016d04865d8d170a6d04ab9da9

commit c877f3484854b0016d04865d8d170a6d04ab9da9
Author: Mikael Morin 
Date:   Sun Aug 10 18:30:59 2025 +0200

Refactoring nullifcations descripteur

Revert partiel

Diff:
---
 gcc/fortran/trans-descriptor.cc | 104 ++--
 1 file changed, 101 insertions(+), 3 deletions(-)

diff --git a/gcc/fortran/trans-descriptor.cc b/gcc/fortran/trans-descriptor.cc
index ad07726d52bc..d0ef2baf9966 100644
--- a/gcc/fortran/trans-descriptor.cc
+++ b/gcc/fortran/trans-descriptor.cc
@@ -722,6 +722,103 @@ gfc_get_dtype_rank_type (int rank, tree etype)
 }
 
 
+class constructor_elements
+{
+  vec *values;
+  bool constant;
+
+public:
+  constructor_elements () : values (nullptr), constant (true) {}
+  void add_value (tree elt, tree val);
+  tree build (tree type);
+};
+
+
+void
+constructor_elements::add_value (tree elt, tree val)
+{
+  CONSTRUCTOR_APPEND_ELT (values, elt, val);
+  if (!TREE_CONSTANT (val))
+constant = false;
+}
+
+
+tree
+constructor_elements::build (tree type)
+{
+  tree cstr = build_constructor (type, values);
+  if (constant)
+TREE_CONSTANT (cstr) = 1;
+
+  return cstr;
+}
+
+
+struct write_destination
+{
+  enum write_type
+  {
+STATIC_INIT,
+REGULAR_ASSIGN
+  }
+  type;
+
+  tree ref;
+
+  union u
+  {
+struct rw
+{
+  stmtblock_t *block;
+
+  rw (stmtblock_t *b) : block(b) {}
+}
+regular_assign;
+
+constructor_elements static_init;
+
+u(stmtblock_t *block) : regular_assign (block) {}
+u() : static_init () {}
+  }
+  u;
+
+  write_destination (tree r, stmtblock_t *b)
+  : type (REGULAR_ASSIGN), ref (r), u (b) {}
+  write_destination (tree d) : type (STATIC_INIT), ref (d), u () {}
+};
+
+
+static void
+set_descriptor_field (write_destination &dest, descriptor_field field, tree 
value)
+{
+  if (dest.type == write_destination::STATIC_INIT)
+{
+  tree field_decl = gfc_advance_chain (TYPE_FIELDS (TREE_TYPE (dest.ref)),
+  field);
+  dest.u.static_init.add_value (field_decl, value);
+}
+  else
+{
+  tree comp_ref = get_ref_comp (dest.ref, field);
+  set_value (dest.u.regular_assign.block, comp_ref, value);
+}
+}
+
+
+static void
+set_descriptor (write_destination &dest)
+{
+  set_descriptor_field (dest, DATA_FIELD, null_pointer_node);
+  if (dest.type == write_destination::STATIC_INIT)
+{
+  tree decl = dest.ref;
+  tree type = TREE_TYPE (decl);
+  tree cstr = dest.u.static_init.build (type);
+  DECL_INITIAL (decl) = cstr;
+}
+}
+
+
 /* Build a null array descriptor constructor.  */
 
 tree
@@ -829,21 +926,22 @@ gfc_conv_descriptor_cosize (tree desc, int rank, int 
corank)
 void
 gfc_nullify_descriptor (stmtblock_t *block, tree descr)
 {
-  gfc_conv_descriptor_data_set (block, descr, null_pointer_node); 
+  write_destination dest(descr, block);
+  set_descriptor (dest);
 }
 
 
 void
 gfc_init_descriptor_result (stmtblock_t *block, tree descr)
 {
-  gfc_conv_descriptor_data_set (block, descr, null_pointer_node);
+  gfc_nullify_descriptor (block, descr);
 }
 
 
 void
 gfc_init_absent_descriptor (stmtblock_t *block, tree descr)
 {
-  gfc_conv_descriptor_data_set (block, descr, null_pointer_node);
+  gfc_nullify_descriptor (block, descr);
 }


[gcc(refs/users/mikael/heads/refactor_descriptor_v08)] gimple-simulate: Correction prise en charge offset coupé en deux MEM_REF/ARRAY_REF

2025-09-20 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:89874dfab4d15e292ecf222796a6d3747749aa7b

commit 89874dfab4d15e292ecf222796a6d3747749aa7b
Author: Mikael Morin 
Date:   Sun Aug 31 20:17:06 2025 +0200

gimple-simulate: Correction prise en charge offset coupé en deux 
MEM_REF/ARRAY_REF

Diff:
---
 gcc/gimple-simulate.cc | 22 +-
 1 file changed, 17 insertions(+), 5 deletions(-)

diff --git a/gcc/gimple-simulate.cc b/gcc/gimple-simulate.cc
index 30b512260b2b..721d34bea9aa 100644
--- a/gcc/gimple-simulate.cc
+++ b/gcc/gimple-simulate.cc
@@ -1022,14 +1022,14 @@ rewrite_ref (tree * data_ref, unsigned * offset, 
simul_scope & context)
tree comp = TREE_OPERAND (ref, 1);
 
tree rewritten_base = base;
-   unsigned off = 0;
+   unsigned off = *offset;
if (!rewrite_ref (&rewritten_base, &off, context))
  return false;
 
tree t = build3 (COMPONENT_REF, TREE_TYPE (ref), rewritten_base,
 comp, NULL_TREE);
*data_ref = t;
-   *offset += off;
+   *offset = off;
return true;
   }
 
@@ -1039,16 +1039,28 @@ rewrite_ref (tree * data_ref, unsigned * offset, 
simul_scope & context)
tree index = TREE_OPERAND (ref, 1);
 
tree rewritten_base = base;
-   unsigned rewritten_off = 0;
+   unsigned rewritten_off = *offset;
if (!rewrite_ref (&rewritten_base, &rewritten_off, context)
&& TREE_CODE (index) == INTEGER_CST)
  return false;
 
data_value idx_val = context.evaluate (index);
+   wide_int wi_idx = idx_val.get_known ();
+   unsigned elt_size;
+   elt_size = get_constant_type_size (TREE_TYPE (TREE_TYPE (base)));
+   wide_int total_off = wi_idx * elt_size + rewritten_off;
+   wide_int wi_elt_size = wi::uhwi (elt_size, total_off.get_precision ());
+   wide_int global_idx = wi::udiv_trunc (total_off, wi_elt_size);
+   gcc_assert (wi::ges_p (global_idx, 0)
+   && wi::fits_uhwi_p (global_idx));
*data_ref = build4 (ARRAY_REF, TREE_TYPE (ref), rewritten_base,
-   idx_val.to_tree (TREE_TYPE (index)),
+   build_int_cst (TREE_TYPE (index),
+  global_idx.to_uhwi ()),
NULL_TREE, NULL_TREE);
-   *offset += rewritten_off;
+   wide_int remaining_offset = total_off - global_idx * elt_size;
+   gcc_assert (wi::ges_p (remaining_offset, 0)
+   && wi::fits_uhwi_p (remaining_offset));
+   *offset = remaining_offset.to_uhwi ();
return true;
   }


[gcc r16-3973] ada: Do not set Esize for Extended Accesses

2025-09-20 Thread Marc Poulhies via Gcc-cvs
https://gcc.gnu.org/g:dc61789283a297102dbbdc140c635b02991a12c5

commit r16-3973-gdc61789283a297102dbbdc140c635b02991a12c5
Author: Marc Poulhiès 
Date:   Thu Apr 24 17:15:36 2025 +0200

ada: Do not set Esize for Extended Accesses

The size of an extended access is unknown at this stage, so leave Esize
empty.

gcc/ada/ChangeLog:

* layout.adb (Layout_Type): Adjust comment and code extended
accesses.

Diff:
---
 gcc/ada/layout.adb | 30 +-
 1 file changed, 21 insertions(+), 9 deletions(-)

diff --git a/gcc/ada/layout.adb b/gcc/ada/layout.adb
index 099ea49656d9..51facf6070da 100644
--- a/gcc/ada/layout.adb
+++ b/gcc/ada/layout.adb
@@ -248,13 +248,21 @@ package body Layout is
   end if;
 
   --  For access types, set size/alignment. This is system address size,
-  --  except for fat pointers (unconstrained array access types), where the
-  --  size is two times the address size, to accommodate the two pointers
-  --  that are required for a fat pointer (data and template). Note that
-  --  E_Access_Protected_Subprogram_Type is not an access type for this
-  --  purpose since it is not a pointer but is equivalent to a record. For
-  --  access subtypes, copy the size from the base type since Gigi
-  --  represents them the same way.
+  --  except for unconstrained array access types:
+  --
+  --   - fat pointers where the size is two times the address size, to
+  -- accommodate the two pointers that are required for a fat pointer
+  -- (data and template).
+  --
+  --   - extended access where the size is the size of an address (data
+  -- pointer) plus the size of the template. The template size can't be
+  -- computed yet (will be done in the code generator), leave it empty
+  -- for now.
+  --
+  --  Note that E_Access_Protected_Subprogram_Type is not an access type
+  --  for this purpose since it is not a pointer but is equivalent to a
+  --  record. For access subtypes, copy the size from the base type since
+  --  the code generator represents them the same way.
 
   if Is_Access_Type (E) then
  Desig_Type := Underlying_Type (Designated_Type (E));
@@ -301,7 +309,9 @@ package body Layout is
 
and then not Debug_Flag_6
  then
-Init_Size (E, 2 * System_Address_Size);
+if not Is_Extended_Access_Type (E) then
+   Init_Size (E, 2 * System_Address_Size);
+end if;
 
 --  Check for bad convention set
 
@@ -326,7 +336,9 @@ package body Layout is
  N_Unconstrained_Array_Definition
and then not Debug_Flag_6
  then
-Init_Size (E, 2 * System_Address_Size);
+if not Is_Extended_Access_Type (E) then
+   Init_Size (E, 2 * System_Address_Size);
+end if;
 
  --  If unnesting subprograms, subprogram access types contain the
  --  address of both the subprogram and an activation record. But if we


[gcc(refs/users/mikael/heads/refactor_descriptor_v08)] gimple-simulate: sauvegarde

2025-09-20 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:64eb5fd110ad4bff744af289763a34ef66274e59

commit 64eb5fd110ad4bff744af289763a34ef66274e59
Author: Mikael Morin 
Date:   Fri Aug 29 20:52:19 2025 +0200

gimple-simulate: sauvegarde

Diff:
---
 gcc/gimple-simulate.cc | 18 --
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/gcc/gimple-simulate.cc b/gcc/gimple-simulate.cc
index 9333c64aa77d..3bdfd2bf6f7d 100644
--- a/gcc/gimple-simulate.cc
+++ b/gcc/gimple-simulate.cc
@@ -807,6 +807,8 @@ static tree
 pick_subref_at (tree var_ref, unsigned offset, int * ignored_bits,
unsigned min_size)
 {
+  if (ignored_bits != nullptr)
+*ignored_bits = 0;
   tree ref = var_ref;
   unsigned remaining_offset = offset;
   while (true)
@@ -953,8 +955,20 @@ find_mem_ref_replacement (tree * repl, unsigned * offset, 
simul_scope & context,
  remaining_offset += wi_idx * CHAR_BIT;
}
 
-  *repl = var_ref;
-  *offset = remaining_offset.to_shwi ();
+  int ignored_bits;
+  tree t = pick_subref_at (var_ref, remaining_offset.to_shwi (),
+  &ignored_bits,
+  get_constant_type_size (access_type));
+  if (t == NULL_TREE)
+   {
+ *repl = var_ref;
+ *offset = remaining_offset.to_shwi ();
+   }
+  else
+   {
+ *repl = t;
+ *offset = ignored_bits;
+   }
   return true;
 }
 }


[gcc(refs/users/mikael/heads/refactor_descriptor_v08)] Correction régression pdt_31

2025-09-20 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:bfd00602df897b58564613faf0724d6776e2621d

commit bfd00602df897b58564613faf0724d6776e2621d
Author: Mikael Morin 
Date:   Sun Sep 14 13:43:25 2025 +0200

Correction régression pdt_31

Correction régression transfer_class_5

Correction régression class_dummy_11.f90

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

diff --git a/gcc/fortran/trans-descriptor.cc b/gcc/fortran/trans-descriptor.cc
index 55e2798234b4..3fa03c5fc234 100644
--- a/gcc/fortran/trans-descriptor.cc
+++ b/gcc/fortran/trans-descriptor.cc
@@ -1606,6 +1606,9 @@ gfc_copy_descriptor (stmtblock_t *block, tree dest, tree 
src, bool lhs_type)
   gfc_conv_descriptor_dtype_set (block, dest,
 gfc_conv_descriptor_dtype_get (src));
 
+  gfc_conv_descriptor_span_set (block, dest,
+   gfc_conv_descriptor_span_get (src));
+
   /* Assign the dimension as range-ref.  */
   tree tmp = gfc_get_descriptor_dimension (dest);
   tree tmp2 = gfc_get_descriptor_dimension (src);
@@ -1802,7 +1805,25 @@ gfc_set_descriptor (stmtblock_t *block, tree dest, tree 
src, gfc_expr *src_expr,
   /* Set the dtype.  */
   tree dtype;
   if (unlimited_polymorphic)
-dtype = gfc_get_dtype (TREE_TYPE (src), &rank);
+{
+  if (UNLIMITED_POLY (src_expr))
+   {
+ tree tmp2 = src;
+ if (TREE_CODE (tmp2) == INDIRECT_REF
+ && DECL_P (TREE_OPERAND (tmp2, 0)))
+   tmp2 = TREE_OPERAND (tmp2, 0);
+ if (DECL_P (tmp2)
+ && DECL_LANG_SPECIFIC (tmp2)
+ && GFC_DECL_SAVED_DESCRIPTOR (tmp2))
+   tmp2 = GFC_DECL_SAVED_DESCRIPTOR (tmp2);
+ tmp2 = gfc_class_data_get (tmp2);
+ if (POINTER_TYPE_P (TREE_TYPE (tmp2)))
+   tmp2 = build_fold_indirect_ref_loc (input_location, tmp2);
+ dtype = gfc_conv_descriptor_dtype_get (tmp2);
+   }
+  else
+   dtype = gfc_get_dtype (TREE_TYPE (src), &rank);
+}
   else if (src_expr->ts.type == BT_ASSUMED)
 {
   tree tmp2 = src;
@@ -2635,6 +2656,8 @@ gfc_set_pdt_array_descriptor (stmtblock_t *block, tree 
descr,
   gfc_conv_descriptor_dtype_set (block, descr,
 gfc_get_dtype (TREE_TYPE (descr)));
 
+  gfc_conv_descriptor_span_set (block, descr, elt_size);
+
   size = fold_build2_loc (input_location, MULT_EXPR,
  gfc_array_index_type, size, elt_size);
   size = gfc_evaluate_now (size, block);
diff --git a/libgfortran/libgfortran.h b/libgfortran/libgfortran.h
index 5cdd564ab0e6..5937cac4c365 100644
--- a/libgfortran/libgfortran.h
+++ b/libgfortran/libgfortran.h
@@ -485,7 +485,7 @@ typedef GFC_FULL_ARRAY_DESCRIPTOR (GFC_MAX_DIMENSIONS, 
GFC_INTEGER_4) gfc_full_a
 
 #define GFC_DESCRIPTOR_STRIDE(desc,i) ((desc)->dim[i]._stride)
 #define GFC_DESCRIPTOR_STRIDE_BYTES(desc,i) \
-  (GFC_DESCRIPTOR_STRIDE(desc,i) * GFC_DESCRIPTOR_SIZE(desc))
+  (GFC_DESCRIPTOR_STRIDE(desc,i) * GFC_DESCRIPTOR_SPAN(desc))
 
 /* Macros to get both the size and the type with a single masking operation  */


[gcc(refs/users/meissner/heads/work221-sha)] PR target/117251: Improve vector nand to vector or fusion

2025-09-20 Thread Michael Meissner via Gcc-cvs
https://gcc.gnu.org/g:b57895fd7f4e9583e5806116012d1a79ee924b23

commit b57895fd7f4e9583e5806116012d1a79ee924b23
Author: Michael Meissner 
Date:   Mon Sep 8 15:43:35 2025 -0400

PR target/117251: Improve vector nand to vector or fusion

See the following post for a complete explanation of what the patches
for PR target/117251:

 * https://gcc.gnu.org/pipermail/gcc-patches/2025-June/686474.html

This is patch #36 of 45 to generate the 'XXEVAL' instruction on power10
and power11 instead of using the Altivec 'VNAND' instruction feeding
into 'VOR'.  The 'XXEVAL' instruction can use all 64 vector registers,
instead of the 32 registers that traditional Altivec vector
instructions use.  By allowing all of the vector registers to be used,
it reduces the amount of spilling that a large benchmark generated.

Currently the following code:

vector int a, b, c, d;
a = (~ (c & d)) | b;

Generates:

vnand  t,c,d
vora,t,b

Now in addition with this patch, if the arguments or result is
allocated to a traditional FPR register, the GCC compiler will now
generate the following code instead of adding vector move instructions:

xxeval a,b,c,239

Since fusion using 2 Altivec instructions is slightly faster than using
the 'XXEVAL' instruction we prefer to generate the Altivec instructions
if we can.  In addition, because 'XXEVAL' is a prefixed instruction, it
possibly might generate an extra NOP instruction to align the 'XXEVAL'
instruction.

I have tested these patches on both big endian and little endian
PowerPC servers, with no regressions.  Can I check these patchs into
the trunk?

2025-09-08  Michael Meissner  

gcc/

PR target/117251
* config/rs6000/fusion.md: Regenerate.
* config/rs6000/genfusion.pl (gen_logical_addsubf): Add support
to generate vector nand => or fusion if XXEVAL is supported.

Diff:
---
 gcc/config/rs6000/fusion.md| 15 +--
 gcc/config/rs6000/genfusion.pl |  1 +
 2 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/gcc/config/rs6000/fusion.md b/gcc/config/rs6000/fusion.md
index e6d13b38415a..ba3a5a52b990 100644
--- a/gcc/config/rs6000/fusion.md
+++ b/gcc/config/rs6000/fusion.md
@@ -2711,20 +2711,23 @@
 ;; logical-logical fusion pattern generated by gen_logical_addsubf
 ;; vector vnand -> vor
 (define_insn "*fuse_vnand_vor"
-  [(set (match_operand:VM 3 "altivec_register_operand" "=&0,&1,&v,v")
-(ior:VM (ior:VM (not:VM (match_operand:VM 0 "altivec_register_operand" 
"v,v,v,v"))
-  (not:VM (match_operand:VM 1 
"altivec_register_operand" "v,v,v,v")))
- (match_operand:VM 2 "altivec_register_operand" "v,v,v,v")))
-   (clobber (match_scratch:VM 4 "=X,X,X,&v"))]
+  [(set (match_operand:VM 3 "vector_fusion_operand" "=&0,&1,&v,wa,v")
+(ior:VM (ior:VM (not:VM (match_operand:VM 0 "vector_fusion_operand" 
"v,v,v,wa,v"))
+  (not:VM (match_operand:VM 1 "vector_fusion_operand" 
"v,v,v,wa,v")))
+ (match_operand:VM 2 "vector_fusion_operand" "v,v,v,wa,v")))
+   (clobber (match_scratch:VM 4 "=X,X,X,X,&v"))]
   "(TARGET_P10_FUSION)"
   "@
vnand %3,%1,%0\;vor %3,%3,%2
vnand %3,%1,%0\;vor %3,%3,%2
vnand %3,%1,%0\;vor %3,%3,%2
+   xxeval %x3,%x2,%x1,%x0,239
vnand %4,%1,%0\;vor %3,%4,%2"
   [(set_attr "type" "fused_vector")
(set_attr "cost" "6")
-   (set_attr "length" "8")])
+   (set_attr "length" "8")
+   (set_attr "prefixed" "*,*,*,yes,*")
+   (set_attr "isa" "*,*,*,xxeval,*")])
 
 ;; logical-logical fusion pattern generated by gen_logical_addsubf
 ;; vector vnor -> vor
diff --git a/gcc/config/rs6000/genfusion.pl b/gcc/config/rs6000/genfusion.pl
index 94eae471c64b..54699d199fc5 100755
--- a/gcc/config/rs6000/genfusion.pl
+++ b/gcc/config/rs6000/genfusion.pl
@@ -250,6 +250,7 @@ sub gen_logical_addsubf
   "vandc_veqv"  => 210,
   "vand_vnor"   => 224,
   "vnand_vxor"  => 225,
+  "vnand_vor"   => 239,
 );
 
 KIND: foreach $kind ('scalar','vector') {


[gcc(refs/users/mikael/heads/refactor_descriptor_v08)] Refactoring getters & setters

2025-09-20 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:d56ee42aa6bb00e66355a127e6b9f121d4d3c1c5

commit d56ee42aa6bb00e66355a127e6b9f121d4d3c1c5
Author: Mikael Morin 
Date:   Tue Jul 1 22:10:35 2025 +0200

Refactoring getters & setters

Nettoyage refactoring

Correction refactoring

Diff:
---
 gcc/fortran/trans-descriptor.cc | 18 --
 1 file changed, 8 insertions(+), 10 deletions(-)

diff --git a/gcc/fortran/trans-descriptor.cc b/gcc/fortran/trans-descriptor.cc
index 5ebd3a10a868..c1b4f3b5e019 100644
--- a/gcc/fortran/trans-descriptor.cc
+++ b/gcc/fortran/trans-descriptor.cc
@@ -184,7 +184,6 @@ get_type_field (tree type, unsigned field_idx, tree 
field_type = NULL_TREE)
   return field;
 }
 
-
 static tree
 get_ref_comp (tree ref, unsigned field_idx, tree type = NULL_TREE)
 {
@@ -195,8 +194,7 @@ get_ref_comp (tree ref, unsigned field_idx, tree type = 
NULL_TREE)
 
 
 static tree
-gfc_get_descriptor_field (tree desc, unsigned field_idx,
- tree type = NULL_TREE)
+get_descr_comp (tree desc, unsigned field_idx, tree type = NULL_TREE)
 {
   gcc_assert (GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (desc)));
 
@@ -207,7 +205,7 @@ gfc_get_descriptor_field (tree desc, unsigned field_idx,
 static tree
 get_descriptor_data (tree desc)
 {
-  return gfc_get_descriptor_field (desc, DATA_FIELD);
+  return get_descr_comp (desc, DATA_FIELD);
 }
 
 /* This provides READ-ONLY access to the data field.  The field itself
@@ -236,7 +234,7 @@ gfc_conv_descriptor_data_get (tree desc)
 void
 gfc_conv_descriptor_data_set (stmtblock_t *block, tree desc, tree value)
 {
-  tree field = gfc_get_descriptor_field (desc, DATA_FIELD);
+  tree field = get_descriptor_data (desc);
   gfc_add_modify (block, field, fold_convert (TREE_TYPE (field), value));
 }
 
@@ -244,7 +242,7 @@ gfc_conv_descriptor_data_set (stmtblock_t *block, tree 
desc, tree value)
 static tree
 get_descriptor_offset (tree desc)
 {
-  return gfc_get_descriptor_field (desc, OFFSET_FIELD, gfc_array_index_type);
+  return get_descr_comp (desc, OFFSET_FIELD, gfc_array_index_type);
 }
 
 tree
@@ -264,7 +262,7 @@ gfc_conv_descriptor_offset_set (stmtblock_t *block, tree 
desc, tree value)
 static tree
 get_descriptor_dtype (tree desc)
 {
-  return gfc_get_descriptor_field (desc, DTYPE_FIELD, get_dtype_type_node ());
+  return get_descr_comp (desc, DTYPE_FIELD, get_dtype_type_node ());
 }
 
 tree
@@ -286,7 +284,7 @@ gfc_conv_descriptor_dtype_set (stmtblock_t *block, tree 
desc, tree value)
 static tree
 gfc_conv_descriptor_span (tree desc)
 {
-  return gfc_get_descriptor_field (desc, SPAN_FIELD, gfc_array_index_type);
+  return get_descr_comp (desc, SPAN_FIELD, gfc_array_index_type);
 }
 
 tree
@@ -443,7 +441,7 @@ gfc_conv_descriptor_type_set (tree desc, int value)
 tree
 gfc_get_descriptor_dimension (tree desc)
 {
-  tree field = gfc_get_descriptor_field (desc, DIMENSION_FIELD);
+  tree field = get_descr_comp (desc, DIMENSION_FIELD);
   gcc_assert (TREE_CODE (TREE_TYPE (field)) == ARRAY_TYPE
  && TREE_CODE (TREE_TYPE (TREE_TYPE (field))) == RECORD_TYPE);
   return field;
@@ -494,7 +492,7 @@ tree
 gfc_conv_descriptor_token (tree desc)
 {
   gcc_assert (flag_coarray == GFC_FCOARRAY_LIB);
-  tree field = gfc_get_descriptor_field (desc, CAF_TOKEN_FIELD);
+  tree field = get_descr_comp (desc, CAF_TOKEN_FIELD);
   /* Should be a restricted pointer - except in the finalization wrapper.  */
   gcc_assert (TREE_TYPE (field) == prvoid_type_node
  || TREE_TYPE (field) == pvoid_type_node);


[gcc r16-3806] testsuite: Add tests for PR c/107419 and PR c++/107393

2025-09-20 Thread H.J. Lu via Gcc-cvs
https://gcc.gnu.org/g:9eab6c6f223808ceeebb55b5453c75782224cd9e

commit r16-3806-g9eab6c6f223808ceeebb55b5453c75782224cd9e
Author: H.J. Lu 
Date:   Mon Sep 8 15:10:02 2025 -0700

testsuite: Add tests for PR c/107419 and PR c++/107393

Both C and C++ frontends should set a tentative TLS model in grokvardecl
and update TLS mode with the default TLS access model after a TLS variable
has been fully processed if the default TLS access model is stronger.

PR c/107419
PR c++/107393
* c-c++-common/tls-attr-common.c: New test.
* c-c++-common/tls-attr-le-pic.c: Likewise.
* c-c++-common/tls-attr-le-pie.c: Likewise.

Signed-off-by: H.J. Lu 

Diff:
---
 gcc/testsuite/c-c++-common/tls-attr-common.c | 20 
 gcc/testsuite/c-c++-common/tls-attr-le-pic.c | 15 +++
 gcc/testsuite/c-c++-common/tls-attr-le-pie.c | 15 +++
 3 files changed, 50 insertions(+)

diff --git a/gcc/testsuite/c-c++-common/tls-attr-common.c 
b/gcc/testsuite/c-c++-common/tls-attr-common.c
new file mode 100644
index ..551538f5
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/tls-attr-common.c
@@ -0,0 +1,20 @@
+/* { dg-do compile } */
+/* { dg-require-effective-target pie } */
+/* { dg-require-effective-target tls } */
+/* { dg-options "-O2 -fdump-ipa-whole-program" } */
+/* Add -fPIE or -mno-direct-extern-access to disable direct access to
+   external symbol from executable.  */
+/* { dg-additional-options "-fPIE" { target { ! { i?86-*-* x86_64-*-* } } } } 
*/
+/* { dg-additional-options "-mno-direct-extern-access" { target { i?86-*-* 
x86_64-*-* } } } */
+
+__attribute__((common))
+__thread int i;
+
+int *
+foo (void)
+{
+  return &i;
+}
+
+/* tls_model should be tls-initial-exec due to common attribute.  */
+/* { dg-final { scan-ipa-dump "Varpool flags: tls-initial-exec" 
"whole-program" } } */
diff --git a/gcc/testsuite/c-c++-common/tls-attr-le-pic.c 
b/gcc/testsuite/c-c++-common/tls-attr-le-pic.c
new file mode 100644
index ..c02df6919f1a
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/tls-attr-le-pic.c
@@ -0,0 +1,15 @@
+/* { dg-do compile } */
+/* { dg-require-effective-target fpic } */
+/* { dg-require-effective-target tls } */
+/* { dg-options "-O2 -fpic -fdump-ipa-whole-program" } */
+
+__attribute__ ((tls_model ("local-exec"))) __thread int i;
+
+int *
+foo (void)
+{
+  return &i;
+}
+
+/* tls_model should be local-exec due to tls_model attribute.  */
+/* { dg-final { scan-ipa-dump "Varpool flags: tls-local-exec" "whole-program" 
} } */
diff --git a/gcc/testsuite/c-c++-common/tls-attr-le-pie.c 
b/gcc/testsuite/c-c++-common/tls-attr-le-pie.c
new file mode 100644
index ..b8ef7840d791
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/tls-attr-le-pie.c
@@ -0,0 +1,15 @@
+/* { dg-do compile { target { tls && pie } } } */
+/* { dg-options "-O2 -fPIE -fdump-ipa-whole-program" } */
+
+extern const int afoo[3];
+
+__thread const int *pfoo __attribute__ ((tls_model ("initial-exec"))) = afoo;
+
+const int **
+ppfoo (void)
+{
+  return &pfoo;
+}
+
+/* tls_model should be local-exec due to -fPIE.  */
+/* { dg-final { scan-ipa-dump "Varpool flags: initialized tls-local-exec" 
"whole-program" } } */


[gcc(refs/users/meissner/heads/work221-dmf)] RFC2656-Support load/store vector with right length.

2025-09-20 Thread Michael Meissner via Gcc-cvs
https://gcc.gnu.org/g:782a22d92eb2adaeb1732dd26b41decf20e19982

commit 782a22d92eb2adaeb1732dd26b41decf20e19982
Author: Michael Meissner 
Date:   Mon Sep 8 14:39:52 2025 -0400

RFC2656-Support load/store vector with right length.

This patch adds support for new instructions that may be added to the 
PowerPC
architecture in the future to enhance the load and store vector with length
instructions.

The current instructions (lxvl, lxvll, stxvl, and stxvll) are inconvient to 
use
since the count for the number of bytes must be in the top 8 bits of the GPR
register, instead of the bottom 8 bits.  This meant that code generating 
these
instructions typically had to do a shift left by 56 bits to get the count 
into
the right position.  In a future version of the PowerPC architecture, new
variants of these instructions might be added that expect the count to be in
the bottom 8 bits of the GPR register.  These patches add this support to 
GCC
if the user uses the -mcpu=future option.

I discovered that the code in rs6000-string.cc to generate ISA 3.1 
lxvl/stxvl
future lxvll/stxvll instructions would generate these instructions on 
32-bit.
However the patterns for these instructions is only done on 64-bit systems. 
 So
I added a check for 64-bit support before generating the instructions.

The patches have been tested on both little and big endian systems.  Can I 
check
it into the master branch?

2025-09-08   Michael Meissner  

gcc/

* config/rs6000/rs6000-string.cc (expand_block_move): Do not 
generate
lxvl and stxvl on 32-bit.
* config/rs6000/vsx.md (lxvl): If -mcpu=future, generate the lxvl 
with
the shift count automaticaly used in the insn.
(lxvrl): New insn for -mcpu=future.
(lxvrll): Likewise.
(stxvl): If -mcpu=future, generate the stxvl with the shift count
automaticaly used in the insn.
(stxvrl): New insn for -mcpu=future.
(stxvrll): Likewise.

gcc/testsuite/

* gcc.target/powerpc/lxvrl.c: New test.
* lib/target-supports.exp 
(check_effective_target_powerpc_future_ok):
New effective target.

Diff:
---
 gcc/config/rs6000/rs6000-string.cc   |   1 +
 gcc/config/rs6000/vsx.md | 122 +--
 gcc/testsuite/gcc.target/powerpc/lxvrl.c |  32 
 3 files changed, 134 insertions(+), 21 deletions(-)

diff --git a/gcc/config/rs6000/rs6000-string.cc 
b/gcc/config/rs6000/rs6000-string.cc
index 3d2911ca08a0..7f55778965bc 100644
--- a/gcc/config/rs6000/rs6000-string.cc
+++ b/gcc/config/rs6000/rs6000-string.cc
@@ -2786,6 +2786,7 @@ expand_block_move (rtx operands[], bool might_overlap)
 
   if (TARGET_MMA && TARGET_BLOCK_OPS_UNALIGNED_VSX
  && TARGET_BLOCK_OPS_VECTOR_PAIR
+ && TARGET_POWERPC64
  && bytes >= 32
  && (align >= 256 || !STRICT_ALIGNMENT))
{
diff --git a/gcc/config/rs6000/vsx.md b/gcc/config/rs6000/vsx.md
index dd3573b80868..89523cf4a0e5 100644
--- a/gcc/config/rs6000/vsx.md
+++ b/gcc/config/rs6000/vsx.md
@@ -5712,20 +5712,32 @@
   DONE;
 })
 
-;; Load VSX Vector with Length
+;; Load VSX Vector with Length.  If we have lxvrl, we don't have to do an
+;; explicit shift left into a pseudo.
 (define_expand "lxvl"
-  [(set (match_dup 3)
-(ashift:DI (match_operand:DI 2 "register_operand")
-   (const_int 56)))
-   (set (match_operand:V16QI 0 "vsx_register_operand")
-   (unspec:V16QI
-[(match_operand:DI 1 "gpc_reg_operand")
-  (mem:V16QI (match_dup 1))
- (match_dup 3)]
-UNSPEC_LXVL))]
+  [(use (match_operand:V16QI 0 "vsx_register_operand"))
+   (use (match_operand:DI 1 "gpc_reg_operand"))
+   (use (match_operand:DI 2 "gpc_reg_operand"))]
   "TARGET_P9_VECTOR && TARGET_64BIT"
 {
-  operands[3] = gen_reg_rtx (DImode);
+  rtx shift_len = gen_rtx_ASHIFT (DImode, operands[2], GEN_INT (56));
+  rtx len;
+
+  if (TARGET_FUTURE)
+len = shift_len;
+  else
+{
+  len = gen_reg_rtx (DImode);
+  emit_insn (gen_rtx_SET (len, shift_len));
+}
+
+  rtx dest = operands[0];
+  rtx addr = operands[1];
+  rtx mem = gen_rtx_MEM (V16QImode, addr);
+  rtvec rv = gen_rtvec (3, addr, mem, len);
+  rtx lxvl = gen_rtx_UNSPEC (V16QImode, rv, UNSPEC_LXVL);
+  emit_insn (gen_rtx_SET (dest, lxvl));
+  DONE;
 })
 
 (define_insn "*lxvl"
@@ -5749,6 +5761,34 @@
   "lxvll %x0,%1,%2"
   [(set_attr "type" "vecload")])
 
+;; For lxvrl and lxvrll, use the combiner to eliminate the shift.  The
+;; define_expand for lxvl will already incorporate the shift in generating the
+;; insn.  The lxvll buitl-in function required the user to have already done
+;; the shift.  Defining lxvrll this way, will optimize cases where the user has
+;; done the shift immediately before the built-in.
+(define_insn "*lxvrl"
+  [(set (match

[gcc(refs/users/mikael/heads/refactor_descriptor_v08)] gimple-simulate: Correction assertion évaluation LSHIFT_EXPR et RSHIFT_EXPR

2025-09-20 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:4425aca695b084e862b9ecdeaaf0e3725d2b480a

commit 4425aca695b084e862b9ecdeaaf0e3725d2b480a
Author: Mikael Morin 
Date:   Fri Aug 29 10:14:50 2025 +0200

gimple-simulate: Correction assertion évaluation LSHIFT_EXPR et RSHIFT_EXPR

Diff:
---
 gcc/gimple-simulate.cc | 41 -
 1 file changed, 40 insertions(+), 1 deletion(-)

diff --git a/gcc/gimple-simulate.cc b/gcc/gimple-simulate.cc
index 4fc64d342089..0951731a1d2c 100644
--- a/gcc/gimple-simulate.cc
+++ b/gcc/gimple-simulate.cc
@@ -2105,7 +2105,9 @@ simul_scope::evaluate_binary (enum tree_code code, tree 
type, tree lhs,
  && TYPE_PRECISION (TREE_TYPE (lhs))
 == TYPE_PRECISION (TREE_TYPE (rhs))
  && TYPE_UNSIGNED (TREE_TYPE (lhs))
-== TYPE_UNSIGNED (TREE_TYPE (rhs;
+== TYPE_UNSIGNED (TREE_TYPE (rhs)))
+ || code == LSHIFT_EXPR
+ || code == RSHIFT_EXPR);
   tree lval = val_lhs.to_tree (TREE_TYPE (lhs));
   tree rval = val_rhs.to_tree (TREE_TYPE (rhs));
   tree t = fold_binary (code, type, lval, rval);
@@ -5723,6 +5725,43 @@ simul_scope_evaluate_binary_tests ()
   wide_int wi_ne5 = val_ne5.get_known ();
   ASSERT_PRED1 (wi::fits_uhwi_p, wi_ne5);
   ASSERT_EQ (wi_ne5.to_uhwi (), 1);
+
+
+  tree l6 = create_var (long_integer_type_node, "l6");
+
+  vec decls6{};
+  decls6.safe_push (l6);
+
+  context_builder builder6 {};
+  builder6.add_decls (&decls6);
+  simul_scope ctx6 = builder6.build (mem, printer);
+
+  wide_int wi11_6 = wi::shwi (11, TYPE_PRECISION (long_integer_type_node));
+  data_value cst11_6 (long_integer_type_node);
+  cst11_6.set_known (wi11_6);
+  data_storage *strg_l6 = ctx6.find_reachable_var (l6);
+  gcc_assert (strg_l6 != nullptr);
+  strg_l6->set (cst11_6);
+
+  tree int3 = build_int_cst (integer_type_node, 3);
+  data_value lshift_6 = ctx6.evaluate_binary (LSHIFT_EXPR,
+ long_integer_type_node,
+ l6, int3);
+
+  ASSERT_EQ (lshift_6.classify (), VAL_KNOWN);
+  wide_int wi_lshift6 = lshift_6.get_known ();
+  ASSERT_PRED1 (wi::fits_shwi_p, wi_lshift6);
+  ASSERT_EQ (wi_lshift6.to_shwi (), 88);
+
+  tree int1 = build_int_cst (integer_type_node, 1);
+  data_value rshift_6 = ctx6.evaluate_binary (RSHIFT_EXPR,
+ long_integer_type_node,
+ l6, int1);
+
+  ASSERT_EQ (rshift_6.classify (), VAL_KNOWN);
+  wide_int wi_rshift6 = rshift_6.get_known ();
+  ASSERT_PRED1 (wi::fits_shwi_p, wi_rshift6);
+  ASSERT_EQ (wi_rshift6.to_shwi (), 5);
 }


[gcc(refs/users/meissner/heads/work222-bugs)] Add ChangeLog.bugs and update REVISION.

2025-09-20 Thread Michael Meissner via Gcc-cvs
https://gcc.gnu.org/g:cc55e4d17d3349c8a8938af49cafdcffbd0321fb

commit cc55e4d17d3349c8a8938af49cafdcffbd0321fb
Author: Michael Meissner 
Date:   Fri Sep 19 13:13:02 2025 -0400

Add ChangeLog.bugs and update REVISION.

2025-09-19  Michael Meissner  

gcc/

* ChangeLog.bugs: New file for branch.
* REVISION: Update.

Diff:
---
 gcc/ChangeLog.bugs | 14 ++
 gcc/REVISION   |  2 +-
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/gcc/ChangeLog.bugs b/gcc/ChangeLog.bugs
new file mode 100644
index ..6041f1156457
--- /dev/null
+++ b/gcc/ChangeLog.bugs
@@ -0,0 +1,14 @@
+ Branch work222-bugs, baseline 
+
+2025-09-19   Michael Meissner  
+
+Add ChangeLog.bugs and update REVISION.
+
+2025-09-19  Michael Meissner  
+
+gcc/
+
+   * ChangeLog.bugs: New file for branch.
+   * REVISION: Update.
+
+   Clone branch
diff --git a/gcc/REVISION b/gcc/REVISION
index 6cb180fd55bf..6d9b69b7ef4a 100644
--- a/gcc/REVISION
+++ b/gcc/REVISION
@@ -1 +1 @@
-work222 branch
+work222-bugs branch


[gcc r16-3741] testsuite: Only scan for known file extensions in lto.exp

2025-09-20 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:2bb8cd3609f5997b5a22925267b675808127311a

commit r16-3741-g2bb8cd3609f5997b5a22925267b675808127311a
Author: Jakub Jelinek 
Date:   Wed Sep 10 12:39:11 2025 +0200

testsuite: Only scan for known file extensions in lto.exp

This is something that has bothered me for a few years but I've only found
time for it now.
The glob used for finding *_1.* etc. counterparts to the *_0.* tests is too
broad, so if one has say next to *_1.c file also *_1.c~ or *_1.c.~1~
or *_1.c.orig or *_1.c.bak etc. files, lto.exp will report a warning and the
test will fail.
So, e.g. in rpm build if some backported commit in patch form adds some
gcc/testsuite/*.dg/lto/ test and one uses -b option to patch, if one doesn't
remove the backup files, the test will fail.

Looking through all the *.dg/lto/ directories, I only see c, C, ii, f, f90
and d extensions used right now for the *_1.* files (and higher), while for
the *_0.* files also m, mm and f03 extensions are used.

So, the following patch only searches for those (plus for Fortran uses the
extensions searched by the gfortran.dg/lto/ driver, i.e. 
\[fF\]{,90,95,03,08}
, not just f, f90 and f03).

Tested on x86_64-linux and verified I got exactly the same number of
grep '^Executing.on.host.*_[1-9]\.' testsuite/*/*.log
before/after this patch when doing make check RUNTESTFLAGS=lto.exp
except for 2 new ones which were previously failed because I had backup
files for 2 tests.

2025-09-10  Jakub Jelinek  

* lib/lto.exp (lto-execute-1): Search for _1.* etc. files
only with a list of known extensions.

Diff:
---
 gcc/testsuite/lib/lto.exp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/gcc/testsuite/lib/lto.exp b/gcc/testsuite/lib/lto.exp
index 81519b580e13..9231e8550afb 100644
--- a/gcc/testsuite/lib/lto.exp
+++ b/gcc/testsuite/lib/lto.exp
@@ -659,9 +659,9 @@ proc lto-execute-1 { src1 sid } {
 set i 1
 set done 0
 while { !$done } {
-   set names [glob -nocomplain -types f -- "${dir}/${base}_${i}.*"]
+   set names [glob -nocomplain -types f -- 
"${dir}/${base}_${i}.{c,C,ii,\[fF\]{,90,95,03,08},d,m,mm}"]
if { [llength ${names}] > 1 } {
-   warning "lto-execute: more than one file matched 
${dir}/${base}_${i}.*"
+   warning "lto-execute: more than one file matched 
${dir}/${base}_${i}.{c,C,ii,\[fF\]{,90,95,03,08},d,m,mm}"
}
if { [llength ${names}] == 1 } {
lappend src_list [lindex ${names} 0]


[gcc(refs/users/mikael/heads/refactor_descriptor_v08)] Extraction gfc_shift_descriptor

2025-09-20 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:07506fe86e96ff655f9d60964aad83b3f258e569

commit 07506fe86e96ff655f9d60964aad83b3f258e569
Author: Mikael Morin 
Date:   Wed Jul 23 14:59:35 2025 +0200

Extraction gfc_shift_descriptor

Diff:
---
 gcc/fortran/trans-descriptor.cc | 32 
 gcc/fortran/trans-descriptor.h  |  2 ++
 gcc/fortran/trans-expr.cc   | 39 ++-
 3 files changed, 36 insertions(+), 37 deletions(-)

diff --git a/gcc/fortran/trans-descriptor.cc b/gcc/fortran/trans-descriptor.cc
index db9dc8c326b7..4da8a1f24899 100644
--- a/gcc/fortran/trans-descriptor.cc
+++ b/gcc/fortran/trans-descriptor.cc
@@ -1231,3 +1231,35 @@ gfc_set_subarray_descriptor (stmtblock_t *block, tree 
descr, tree value,
   gfc_conv_descriptor_offset_set (block, descr, tmp);
 }
 }
+
+
+void
+gfc_shift_descriptor (stmtblock_t *block, tree descr, int rank,
+ tree lbound[GFC_MAX_DIMENSIONS],
+ tree ubound[GFC_MAX_DIMENSIONS])
+{
+  tree size = gfc_index_one_node;
+  tree offset = gfc_index_zero_node;
+  for (int n = 0; n < rank; n++)
+{
+  tree tmp = gfc_conv_descriptor_ubound_get (descr, gfc_rank_cst[n]);
+  tmp = fold_build2_loc (input_location, PLUS_EXPR,
+gfc_array_index_type, tmp,
+gfc_index_one_node);
+  gfc_conv_descriptor_ubound_set (block, descr, gfc_rank_cst[n], tmp);
+  gfc_conv_descriptor_lbound_set (block, descr, gfc_rank_cst[n],
+ gfc_index_one_node);
+  size = gfc_evaluate_now (size, block);
+  offset = fold_build2_loc (input_location, MINUS_EXPR,
+   gfc_array_index_type, offset, size);
+  offset = gfc_evaluate_now (offset, block);
+  tmp = fold_build2_loc (input_location, MINUS_EXPR,
+gfc_array_index_type, ubound[n], lbound[n]);
+  tmp = fold_build2_loc (input_location, PLUS_EXPR,
+gfc_array_index_type, tmp, gfc_index_one_node);
+  size = fold_build2_loc (input_location, MULT_EXPR,
+ gfc_array_index_type, size, tmp);
+}
+
+  gfc_conv_descriptor_offset_set (block, descr, offset);
+}
diff --git a/gcc/fortran/trans-descriptor.h b/gcc/fortran/trans-descriptor.h
index 2a36a6c3623a..17ef086343aa 100644
--- a/gcc/fortran/trans-descriptor.h
+++ b/gcc/fortran/trans-descriptor.h
@@ -105,6 +105,8 @@ 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);
 void gfc_set_subarray_descriptor (stmtblock_t *, tree, tree, gfc_expr *, 
gfc_expr *);
+void gfc_shift_descriptor (stmtblock_t *, tree, int, tree [GFC_MAX_DIMENSIONS],
+  tree [GFC_MAX_DIMENSIONS]);
 
 void gfc_set_descriptor_from_scalar_class (stmtblock_t *, tree, tree, gfc_expr 
*);
 void gfc_set_descriptor_from_scalar (stmtblock_t *, tree, tree, 
symbol_attribute,
diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc
index 873f1a81893b..9b8d10dc968f 100644
--- a/gcc/fortran/trans-expr.cc
+++ b/gcc/fortran/trans-expr.cc
@@ -5327,7 +5327,6 @@ gfc_conv_subref_array_arg (gfc_se *se, gfc_expr * expr, 
int g77,
   tree tmp_index;
   tree tmp;
   tree base_type;
-  tree size;
   stmtblock_t body;
   int n;
   int dimen;
@@ -5568,42 +5567,8 @@ class_array_fcn:
   /* Determine the offset for pointer formal arguments and set the
  lbounds to one.  */
   if (formal_ptr)
-{
-  size = gfc_index_one_node;
-  offset = gfc_index_zero_node;
-  for (n = 0; n < dimen; n++)
-   {
- tmp = gfc_conv_descriptor_ubound_get (parmse->expr,
-   gfc_rank_cst[n]);
- tmp = fold_build2_loc (input_location, PLUS_EXPR,
-gfc_array_index_type, tmp,
-gfc_index_one_node);
- gfc_conv_descriptor_ubound_set (&parmse->pre,
- parmse->expr,
- gfc_rank_cst[n],
- tmp);
- gfc_conv_descriptor_lbound_set (&parmse->pre,
- parmse->expr,
- gfc_rank_cst[n],
- gfc_index_one_node);
- size = gfc_evaluate_now (size, &parmse->pre);
- offset = fold_build2_loc (input_location, MINUS_EXPR,
-   gfc_array_index_type,
-   offset, size);
- offset = gfc_evaluate_now (offset, &parmse->pre);
- tmp = fold_build2_loc (input_location, MINUS_EXPR,
-gfc_array_index_type,
-rse.loop->to[n], rse.loop->from[n]);
- tmp = fold_build2_loc (input_location, PLUS_E

[gcc(refs/users/mikael/heads/refactor_descriptor_v08)] Suppression gfc_conv_descriptor_attribute compil' OK

2025-09-20 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:0dc0b55c11380304d0c0ce623f363f44a9f5c4f6

commit 0dc0b55c11380304d0c0ce623f363f44a9f5c4f6
Author: Mikael Morin 
Date:   Sun Jun 29 14:15:55 2025 +0200

Suppression gfc_conv_descriptor_attribute compil' OK

Diff:
---
 gcc/fortran/trans-descriptor.cc | 16 
 gcc/fortran/trans-descriptor.h  |  1 -
 2 files changed, 17 deletions(-)

diff --git a/gcc/fortran/trans-descriptor.cc b/gcc/fortran/trans-descriptor.cc
index c656bc722a75..9d04a4801233 100644
--- a/gcc/fortran/trans-descriptor.cc
+++ b/gcc/fortran/trans-descriptor.cc
@@ -392,22 +392,6 @@ gfc_conv_descriptor_elem_len_set (stmtblock_t *block, tree 
desc, tree value)
 }
 
 
-tree
-gfc_conv_descriptor_attribute (tree desc)
-{
-  tree tmp;
-  tree dtype;
-
-  dtype = get_descriptor_dtype (desc);
-  tmp = gfc_advance_chain (TYPE_FIELDS (TREE_TYPE (dtype)),
-  GFC_DTYPE_ATTRIBUTE);
-  gcc_assert (tmp!= NULL_TREE
- && TREE_TYPE (tmp) == short_integer_type_node);
-  return fold_build3_loc (input_location, COMPONENT_REF, TREE_TYPE (tmp),
- dtype, tmp, NULL_TREE);
-}
-
-
 static tree
 get_descriptor_type (tree desc)
 {
diff --git a/gcc/fortran/trans-descriptor.h b/gcc/fortran/trans-descriptor.h
index 96f66b004ecb..69cc4f3e2ac6 100644
--- a/gcc/fortran/trans-descriptor.h
+++ b/gcc/fortran/trans-descriptor.h
@@ -48,7 +48,6 @@ tree gfc_get_cfi_dim_extent (tree desc, tree idx);
 tree gfc_get_cfi_dim_sm (tree desc, tree idx);
 
 
-tree gfc_conv_descriptor_attribute (tree desc);
 tree gfc_get_descriptor_dimension (tree desc);
 tree gfc_conv_descriptor_dimension (tree desc, tree dim);
 tree gfc_conv_descriptor_token (tree desc);


[gcc(refs/users/mikael/heads/refactor_descriptor_v08)] Extraction ARRAY_ELEM_AT_OFFSET, PTR_ADD_OFFSET

2025-09-20 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:e8a62f40338b992b9e597e18a1843a89397ca90f

commit e8a62f40338b992b9e597e18a1843a89397ca90f
Author: Mikael Morin 
Date:   Sun Sep 14 21:38:56 2025 +0200

Extraction ARRAY_ELEM_AT_OFFSET, PTR_ADD_OFFSET

Modification definition macros

Diff:
---
 libgfortran/intrinsics/reduce.c  | 44 ---
 libgfortran/intrinsics/reshape_generic.c | 31 +--
 libgfortran/libgfortran.h| 25 
 libgfortran/m4/cshift0.m4|  2 +-
 libgfortran/m4/cshift1.m4|  2 +-
 libgfortran/m4/cshift1a.m4   |  2 +-
 libgfortran/m4/ifindloc1.m4  |  4 +--
 libgfortran/m4/matmul_internal.m4| 51 ++--
 8 files changed, 85 insertions(+), 76 deletions(-)

diff --git a/libgfortran/intrinsics/reduce.c b/libgfortran/intrinsics/reduce.c
index aa391fb1373d..2895bd3dd587 100644
--- a/libgfortran/intrinsics/reduce.c
+++ b/libgfortran/intrinsics/reduce.c
@@ -51,8 +51,9 @@ reduce (parray *ret,
   void *res;
   index_type ext0, ext1, ext2;
   index_type str0, str1, str2;
+  index_type mstr0, mstr1, mstr2;
   index_type idx0, idx1, idx2;
-  index_type dimen, dimen_m1, ldx, ext, str;
+  index_type dimen, dimen_m1, ext, str;
   bool started;
   bool masked = false;
   bool dim_present = dim != NULL;
@@ -95,7 +96,8 @@ reduce (parray *ret,
  painless by the use of pointer arithmetic throughout (except for MASK,
  whose type is known.  */
   ext0 = ext1 = ext2 = 1;
-  str0 = str1 = str2 = 1;
+  str0 = str1 = str2 = GFC_DESCRIPTOR_SIZE (array);
+  mstr0 = mstr1 = mstr2 = sizeof (GFC_LOGICAL_4);
 
   scalar_result = (!dim_present && array_rank > 1) || array_rank == 1;
 
@@ -104,7 +106,6 @@ reduce (parray *ret,
 {
   /* Obtain the shape of the reshaped ARRAY.  */
   ext = GFC_DESCRIPTOR_EXTENT (array,i);
-  str = GFC_DESCRIPTOR_STRIDE (array,i);
 
   if (masked && (ext != GFC_DESCRIPTOR_EXTENT (mask, i)))
{
@@ -136,11 +137,15 @@ reduce (parray *ret,
 
   if (!scalar_result)
 {
-  str1 = GFC_DESCRIPTOR_STRIDE (array, dimen_m1);
+  str1 = GFC_DESCRIPTOR_STRIDE_BYTES (array, dimen_m1);
+  if (mask_present)
+   mstr1 = GFC_DESCRIPTOR_STRIDE_BYTES (mask, dimen_m1);
   if (dimen < array_rank)
-   str2 = GFC_DESCRIPTOR_STRIDE (array, dimen);
-  else
-   str2 = 1;
+   {
+ str2 = GFC_DESCRIPTOR_STRIDE_BYTES (array, dimen);
+ if (mask_present)
+   mstr2 = GFC_DESCRIPTOR_STRIDE_BYTES (mask, dimen);
+   }
 }
 
   /* Allocate the result data, the result buffer and zero.  */
@@ -154,14 +159,14 @@ reduce (parray *ret,
 {
   for (idx2 = 0; idx2 < ext2; idx2++)
{
- ldx = idx0 * str0  + idx2 * str2;
  if (mask_present)
-   maskR = mask->base_addr[ldx];
+   maskR = ARRAY_ELEM_AT_OFFSET (mask->base_addr,
+ idx0 * mstr0 + idx2 * mstr2);
 
  started = (mask_present && maskR) || !mask_present;
 
- buffer_ptr = array->base_addr
-   + (size_t)((idx0 * str0 + idx2 * str2) * elem_len);
+ buffer_ptr = PTR_ADD_OFFSET (array->base_addr,
+  idx0 * str0 + idx2 * str2);
 
  /* Start the iteration over the second dimension of ARRAY.  */
  for (idx1 = 1; idx1 < ext1; idx1++)
@@ -169,13 +174,16 @@ reduce (parray *ret,
  /* If masked, cycle until after first element that is not masked
 out. Then set 'started' and cycle so that this becomes the
 first element in the reduction.  */
- ldx = idx0 * str0 + idx1 * str1 + idx2 * str2;
  if (mask_present)
-   maskR = mask->base_addr[ldx];
-
- array_ptr = array->base_addr
- + (size_t)((idx0 * str0 + idx1 * str1
- + idx2 * str2) * elem_len);
+   maskR = ARRAY_ELEM_AT_OFFSET (mask->base_addr,
+ idx0 * mstr0
+ + idx1 * mstr1
+ + idx2 * mstr2);
+
+ array_ptr = PTR_ADD_OFFSET (array->base_addr,
+ idx0 * str0
+ + idx1 * str1
+ + idx2 * str2);
  if (!started)
{
  if (mask_present && maskR)
@@ -199,7 +207,7 @@ reduce (parray *ret,
 result. If this result element is empty emit an error or, if
 available, set to identity. Note that str1 is paired with idx2
 here because the result skips a dimension.  */
- res = ret->base_addr + (size_t)((idx0 * str0 + idx2 * str1) * 
elem_len);
+ res = PTR_ADD_OFFSET (ret->base_addr, idx0 * str0 + idx2 * str1);
  if (started)

[gcc r16-3696] ada: Avoid renamed declaration becoming both ignored and checked

2025-09-20 Thread Marc Poulhies via Gcc-cvs
https://gcc.gnu.org/g:db243f7f414828ff35ff53fa11c718394fe76522

commit r16-3696-gdb243f7f414828ff35ff53fa11c718394fe76522
Author: Viljar Indus 
Date:   Fri Aug 1 13:41:24 2025 +0300

ada: Avoid renamed declaration becoming both ignored and checked

gcc/ada/ChangeLog:

* ghost.adb (Mark_Ghost_Declaration_Or_Body): Mark ghost
entity explicitly as ignored or checked.

Diff:
---
 gcc/ada/ghost.adb | 37 +
 1 file changed, 33 insertions(+), 4 deletions(-)

diff --git a/gcc/ada/ghost.adb b/gcc/ada/ghost.adb
index 31d171dee00c..9474beb26b2c 100644
--- a/gcc/ada/ghost.adb
+++ b/gcc/ada/ghost.adb
@@ -2298,16 +2298,45 @@ package body Ghost is
   Param: Node_Id;
   Param_Id : Entity_Id;
 
+  procedure Mark_And_Set_Is_Checked_Ghost_Entity (E : Entity_Id);
+  --  Sets Is_Checked_Ghost_Entity, unsets Is_Ignored_Ghost_Entity
+
+  procedure Mark_And_Set_Is_Ignored_Ghost_Entity (E : Entity_Id);
+  --  Sets Is_Ignored_Ghost_Entity, unsets Is_Checked_Ghost_Entity
+
+  --
+  -- Mark_And_Set_Is_Checked_Ghost_Entity --
+  --
+
+  procedure Mark_And_Set_Is_Checked_Ghost_Entity (E : Entity_Id) is
+  begin
+ Set_Is_Checked_Ghost_Entity (E, True);
+ Set_Is_Ignored_Ghost_Entity (E, False);
+  end Mark_And_Set_Is_Checked_Ghost_Entity;
+
+  --
+  -- Mark_And_Set_Is_Ignored_Ghost_Entity --
+  --
+
+  procedure Mark_And_Set_Is_Ignored_Ghost_Entity (E : Entity_Id) is
+  begin
+ Set_Is_Checked_Ghost_Entity (E, False);
+ Set_Is_Ignored_Ghost_Entity (E, True);
+  end Mark_And_Set_Is_Ignored_Ghost_Entity;
+
+   --  Start of processing for Mark_Ghost_Declaration_Or_Body
+
begin
   Set_Ghost_Assertion_Level (Id, Level);
 
   if Mode = Name_Check then
  Mark_Formals := True;
- Set_Is_Checked_Ghost_Entity (Id);
+ Mark_And_Set_Is_Checked_Ghost_Entity (Id);
 
   elsif Mode = Name_Ignore then
  Mark_Formals := True;
- Set_Is_Ignored_Ghost_Entity (Id);
+ Mark_And_Set_Is_Ignored_Ghost_Entity (Id);
+
  Set_Is_Ignored_Ghost_Node (N);
  Record_Ignored_Ghost_Node (N);
   end if;
@@ -2335,10 +2364,10 @@ package body Ghost is
 Set_Ghost_Assertion_Level (Param_Id, Level);
 
 if Mode = Name_Check then
-   Set_Is_Checked_Ghost_Entity (Param_Id);
+   Mark_And_Set_Is_Checked_Ghost_Entity (Param_Id);
 
 elsif Mode = Name_Ignore then
-   Set_Is_Ignored_Ghost_Entity (Param_Id);
+   Mark_And_Set_Is_Ignored_Ghost_Entity (Param_Id);
 end if;
 
 Next (Param);


[gcc(refs/users/mikael/heads/refactor_descriptor_v08)] Extraction gfc_set_gfc_from_cfi

2025-09-20 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:be565a7a832f44d519574651565b2292a008

commit be565a7a832f44d519574651565b2292a008
Author: Mikael Morin 
Date:   Tue Jul 22 12:17:50 2025 +0200

Extraction gfc_set_gfc_from_cfi

Diff:
---
 gcc/fortran/trans-descriptor.cc | 99 +
 gcc/fortran/trans-descriptor.h  |  3 ++
 gcc/fortran/trans-expr.cc   | 92 +-
 3 files changed, 103 insertions(+), 91 deletions(-)

diff --git a/gcc/fortran/trans-descriptor.cc b/gcc/fortran/trans-descriptor.cc
index 28031526ad76..c8352f46c6c7 100644
--- a/gcc/fortran/trans-descriptor.cc
+++ b/gcc/fortran/trans-descriptor.cc
@@ -1793,3 +1793,102 @@ gfc_set_descriptor_with_shape (stmtblock_t *block, tree 
desc, tree ptr,
   gfc_array_index_type, offset));
   gfc_conv_descriptor_offset_set (block, desc, offset);
 }
+
+
+void
+gfc_set_gfc_from_cfi (stmtblock_t *block, tree gfc, gfc_expr *e, tree rank,
+ tree gfc_strlen, tree cfi, gfc_symbol *fsym)
+{
+  stmtblock_t block2;
+  gfc_init_block (&block2);
+  if (e->rank == 0)
+{
+  tree tmp = gfc_get_cfi_desc_base_addr (cfi);
+  gfc_add_modify (block, gfc, fold_convert (TREE_TYPE (gfc), tmp));
+}
+  else
+{
+  tree tmp = gfc_get_cfi_desc_base_addr (cfi);
+  gfc_conv_descriptor_data_set (block, gfc, tmp);
+
+  if (fsym->attr.allocatable)
+   {
+ /* gfc->span = cfi->elem_len.  */
+ tmp = fold_convert (gfc_array_index_type,
+ gfc_get_cfi_dim_sm (cfi, gfc_rank_cst[0]));
+   }
+  else
+   {
+ /* gfc->span = ((cfi->dim[0].sm % cfi->elem_len)
+ ? cfi->dim[0].sm : cfi->elem_len).  */
+ tmp = gfc_get_cfi_dim_sm (cfi, gfc_rank_cst[0]);
+ tree tmp2 = fold_convert (gfc_array_index_type,
+   gfc_get_cfi_desc_elem_len (cfi));
+ tmp = fold_build2_loc (input_location, TRUNC_MOD_EXPR,
+gfc_array_index_type, tmp, tmp2);
+ tmp = fold_build2_loc (input_location, NE_EXPR, boolean_type_node,
+tmp, gfc_index_zero_node);
+ tmp = build3_loc (input_location, COND_EXPR, gfc_array_index_type, 
tmp,
+   gfc_get_cfi_dim_sm (cfi, gfc_rank_cst[0]), tmp2);
+   }
+  gfc_conv_descriptor_span_set (&block2, gfc, tmp);
+
+  /* Calculate offset + set lbound, ubound and stride.  */
+  gfc_conv_descriptor_offset_set (&block2, gfc, gfc_index_zero_node);
+  /* Loop: for (i = 0; i < rank; ++i).  */
+  tree idx = gfc_create_var (TREE_TYPE (rank), "idx");
+  /* Loop body.  */
+  stmtblock_t loop_body;
+  gfc_init_block (&loop_body);
+  /* gfc->dim[i].lbound = ... */
+  tmp = gfc_get_cfi_dim_lbound (cfi, idx);
+  gfc_conv_descriptor_lbound_set (&loop_body, gfc, idx, tmp);
+
+  /* gfc->dim[i].ubound = gfc->dim[i].lbound + cfi->dim[i].extent - 1. */
+  tmp = fold_build2_loc (input_location, MINUS_EXPR, gfc_array_index_type,
+gfc_conv_descriptor_lbound_get (gfc, idx),
+gfc_index_one_node);
+  tmp = fold_build2_loc (input_location, PLUS_EXPR, gfc_array_index_type,
+gfc_get_cfi_dim_extent (cfi, idx), tmp);
+  gfc_conv_descriptor_ubound_set (&loop_body, gfc, idx, tmp);
+
+  /* gfc->dim[i].stride = cfi->dim[i].sm / cfi>elem_len */
+  tmp = gfc_get_cfi_dim_sm (cfi, idx);
+  tmp = fold_build2_loc (input_location, TRUNC_DIV_EXPR,
+gfc_array_index_type, tmp,
+fold_convert (gfc_array_index_type,
+  gfc_get_cfi_desc_elem_len (cfi)));
+  gfc_conv_descriptor_stride_set (&loop_body, gfc, idx, tmp);
+
+  /* gfc->offset -= gfc->dim[i].stride * gfc->dim[i].lbound. */
+  tmp = fold_build2_loc (input_location, MULT_EXPR, gfc_array_index_type,
+gfc_conv_descriptor_stride_get (gfc, idx),
+gfc_conv_descriptor_lbound_get (gfc, idx));
+  tmp = fold_build2_loc (input_location, MINUS_EXPR, gfc_array_index_type,
+gfc_conv_descriptor_offset_get (gfc), tmp);
+  gfc_conv_descriptor_offset_set (&loop_body, gfc, tmp);
+  /* Generate loop.  */
+  gfc_simple_for_loop (&block2, idx, build_int_cst (TREE_TYPE (idx), 0),
+  rank, LT_EXPR, build_int_cst (TREE_TYPE (idx), 1),
+  gfc_finish_block (&loop_body));
+}
+
+  if (e->ts.type == BT_CHARACTER && !e->ts.u.cl->length)
+{
+  tree tmp = fold_convert (gfc_charlen_type_node,
+  gfc_get_cfi_desc_elem_len (cfi));
+  if (e->ts.kind != 1)
+   tmp = fold_build2_loc (input_location, TRUNC_DIV_EXPR,
+  gfc_charlen_type_node, tmp,
+  buil

[gcc r16-3717] Revert "aarch64: Handle DImode BCAX operations"

2025-09-20 Thread Kyrylo Tkachov via Gcc-cvs
https://gcc.gnu.org/g:768f3610e2639b5a1c33fb0f166d26244999dac3

commit r16-3717-g768f3610e2639b5a1c33fb0f166d26244999dac3
Author: Kyrylo Tkachov 
Date:   Tue Sep 9 15:14:51 2025 +0200

Revert "aarch64: Handle DImode BCAX operations"

This reverts commit 1b7bcac0327ccd84f1966c748f4d1aedef64a9c5.

PR target/121785

gcc/

* config/aarch64/aarch64-simd.md (*bcaxqdi4): Delete.

gcc/testsuite/

* gcc.target/aarch64/simd/bcax_d.c: Remove tests for DImode 
arguments.

Diff:
---
 gcc/config/aarch64/aarch64-simd.md | 29 --
 gcc/testsuite/gcc.target/aarch64/simd/bcax_d.c |  6 +-
 2 files changed, 1 insertion(+), 34 deletions(-)

diff --git a/gcc/config/aarch64/aarch64-simd.md 
b/gcc/config/aarch64/aarch64-simd.md
index 14b9d5c78e3f..82db2402f135 100644
--- a/gcc/config/aarch64/aarch64-simd.md
+++ b/gcc/config/aarch64/aarch64-simd.md
@@ -9263,35 +9263,6 @@
   [(set_attr "type" "crypto_sha3")]
 )
 
-(define_insn_and_split "*bcaxqdi4"
-  [(set (match_operand:DI 0 "register_operand")
-   (xor:DI
- (and:DI
-   (not:DI (match_operand:DI 3 "register_operand"))
-   (match_operand:DI 2 "register_operand"))
- (match_operand:DI 1 "register_operand")))]
-  "TARGET_SHA3"
-  {@ [ cons: =0, 1, 2 , 3  ; attrs: type ]
- [ w   , w, w , w  ; crypto_sha3 ] bcax\t%0.16b, %1.16b, %2.16b, %3.16b
- [ &r  , r, r0, r0 ; multiple] #
-  }
-  "&& REG_P (operands[0]) && GP_REGNUM_P (REGNO (operands[0]))"
-  [(set (match_dup 4)
-   (and:DI (not:DI (match_dup 3))
-   (match_dup 2)))
-   (set (match_dup 0)
-   (xor:DI (match_dup 4)
-   (match_dup 1)))]
-  {
-if (reload_completed)
-  operands[4] = operands[0];
-else if (can_create_pseudo_p ())
-  operands[4] = gen_reg_rtx (DImode);
-else
-  FAIL;
-  }
-)
-
 ;; SM3
 
 (define_insn "aarch64_sm3ss1qv4si"
diff --git a/gcc/testsuite/gcc.target/aarch64/simd/bcax_d.c 
b/gcc/testsuite/gcc.target/aarch64/simd/bcax_d.c
index a7640c3f6f1e..d68f0e102bf1 100644
--- a/gcc/testsuite/gcc.target/aarch64/simd/bcax_d.c
+++ b/gcc/testsuite/gcc.target/aarch64/simd/bcax_d.c
@@ -7,13 +7,9 @@
 
 #define BCAX(x,y,z)  ((x) ^ ((y) & ~(z)))
 
-/* When the inputs come from GP regs don't form a BCAX.  */
-uint64_t bcax_d_gp (uint64_t a, uint64_t b, uint64_t c) { return BCAX (a, b, 
c); }
-
-uint64x1_t bcax_d (uint64x1_t a, uint64x1_t b, uint64x1_t c) { return BCAX (a, 
b, c); }
 uint32x2_t bcax_s (uint32x2_t a, uint32x2_t b, uint32x2_t c) { return BCAX (a, 
b, c); }
 uint16x4_t bcax_h (uint16x4_t a, uint16x4_t b, uint16x4_t c) { return BCAX (a, 
b, c); }
 uint8x8_t bcax_b (uint8x8_t a, uint8x8_t b, uint8x8_t c) { return BCAX (a, b, 
c); }
 
-/* { dg-final { scan-assembler-times {bcax\tv0.16b, v0.16b, v1.16b, v2.16b} 4 
} } */
+/* { dg-final { scan-assembler-times {bcax\tv0.16b, v0.16b, v1.16b, v2.16b} 3 
} } */


[gcc(refs/users/mikael/heads/refactor_descriptor_v08)] Utilisation gfc_conv_descriptor_offset_{g, s}et

2025-09-20 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:af9b8a993514761e956673ad0978eb3ab61e66a9

commit af9b8a993514761e956673ad0978eb3ab61e66a9
Author: Mikael Morin 
Date:   Thu Jun 19 18:04:56 2025 +0200

Utilisation gfc_conv_descriptor_offset_{g,s}et

Correction pr43808

Correction gfc_conv_descriptor_offset

Utilisation gfc_conv_descriptor_offset_set

Suppression retour à la ligne inutile offset_set

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

diff --git a/gcc/fortran/trans-descriptor.cc b/gcc/fortran/trans-descriptor.cc
index cbee0fa9aca8..e898f2a8d406 100644
--- a/gcc/fortran/trans-descriptor.cc
+++ b/gcc/fortran/trans-descriptor.cc
@@ -215,8 +215,8 @@ gfc_conv_descriptor_data_set (stmtblock_t *block, tree 
desc, tree value)
 }
 
 
-tree
-gfc_conv_descriptor_offset (tree desc)
+static tree
+get_descriptor_offset (tree desc)
 {
   tree field = gfc_get_descriptor_field (desc, OFFSET_FIELD);
   gcc_assert (TREE_TYPE (field) == gfc_array_index_type);
@@ -226,13 +226,13 @@ gfc_conv_descriptor_offset (tree desc)
 tree
 gfc_conv_descriptor_offset_get (tree desc)
 {
-  return gfc_conv_descriptor_offset (desc);
+  return get_descriptor_offset (desc);
 }
 
 void
 gfc_conv_descriptor_offset_set (stmtblock_t *block, tree desc, tree value)
 {
-  tree t = gfc_conv_descriptor_offset (desc);
+  tree t = get_descriptor_offset (desc);
   gfc_add_modify (block, t, fold_convert (TREE_TYPE (t), value));
 }
 
diff --git a/gcc/fortran/trans-descriptor.h b/gcc/fortran/trans-descriptor.h
index ade63bf19751..36365ff32ae0 100644
--- a/gcc/fortran/trans-descriptor.h
+++ b/gcc/fortran/trans-descriptor.h
@@ -57,7 +57,6 @@ tree gfc_conv_descriptor_type (tree desc);
 tree gfc_get_descriptor_dimension (tree desc);
 tree gfc_conv_descriptor_dimension (tree desc, tree dim);
 tree gfc_conv_descriptor_token (tree desc);
-tree gfc_conv_descriptor_offset (tree desc);
 
 tree gfc_conv_descriptor_data_get (tree desc);
 tree gfc_conv_descriptor_offset_get (tree desc);


[gcc(refs/users/mikael/heads/refactor_descriptor_v08)] Déplacement gfc_array_init_count -> gfc_descriptor_init_count

2025-09-20 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:6d9ca3056a95456cb8b796818bde13a789525341

commit 6d9ca3056a95456cb8b796818bde13a789525341
Author: Mikael Morin 
Date:   Thu Jul 31 16:51:20 2025 +0200

Déplacement gfc_array_init_count -> gfc_descriptor_init_count

Diff:
---
 gcc/fortran/trans-array.cc  | 301 ++--
 gcc/fortran/trans-descriptor.cc | 283 +
 gcc/fortran/trans-descriptor.h  |   5 +
 3 files changed, 297 insertions(+), 292 deletions(-)

diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc
index ea2723064cd4..a0ab5a284015 100644
--- a/gcc/fortran/trans-array.cc
+++ b/gcc/fortran/trans-array.cc
@@ -5817,289 +5817,6 @@ get_array_memory_size (tree element_size, tree 
elements_count,
 }
 
 
-/* Fills in an array descriptor, and returns the size of the array.
-   The size will be a simple_val, ie a variable or a constant.  Also
-   calculates the offset of the base.  The pointer argument overflow,
-   which should be of integer type, will increase in value if overflow
-   occurs during the size calculation.  Returns the size of the array.
-   {
-stride = 1;
-offset = 0;
-for (n = 0; n < rank; n++)
-  {
-   a.lbound[n] = specified_lower_bound;
-   offset = offset + a.lbond[n] * stride;
-   size = 1 - lbound;
-   a.ubound[n] = specified_upper_bound;
-   a.stride[n] = stride;
-   size = size >= 0 ? ubound + size : 0; //size = ubound + 1 - lbound
-   overflow += size == 0 ? 0: (MAX/size < stride ? 1: 0);
-   stride = stride * size;
-  }
-for (n = rank; n < rank+corank; n++)
-  (Set lcobound/ucobound as above.)
-element_size = sizeof (array element);
-if (!rank)
-  return element_size
-stride = (size_t) stride;
-overflow += element_size == 0 ? 0: (MAX/element_size < stride ? 1: 0);
-stride = stride * element_size;
-return (stride);
-   }  */
-/*GCC ARRAYS*/
-
-static tree
-gfc_array_init_count (tree descriptor, int rank, int corank, gfc_expr ** lower,
- gfc_expr ** upper, stmtblock_t * pblock,
- stmtblock_t * descriptor_block, tree * overflow,
- tree expr3_elem_size, gfc_expr *expr3, tree expr3_desc,
- bool e3_has_nodescriptor, gfc_expr *expr,
- tree element_size, bool explicit_ts,
- tree *empty_array_cond)
-{
-  tree type;
-  tree tmp;
-  tree size;
-  tree offset;
-  tree stride;
-  tree cond;
-  gfc_expr *ubound;
-  gfc_se se;
-  int n;
-
-  type = TREE_TYPE (descriptor);
-
-  stride = gfc_index_one_node;
-  offset = gfc_index_zero_node;
-
-  /* Set the dtype before the alloc, because registration of coarrays needs
- it initialized.  */
-  if (expr->ts.type == BT_CHARACTER
-  && expr->ts.deferred
-  && VAR_P (expr->ts.u.cl->backend_decl))
-{
-  type = gfc_typenode_for_spec (&expr->ts);
-  gfc_conv_descriptor_dtype_set (pblock, descriptor,
-gfc_get_dtype_rank_type (rank, type));
-}
-  else if (expr->ts.type == BT_CHARACTER
-  && expr->ts.deferred
-  && TREE_CODE (descriptor) == COMPONENT_REF)
-{
-  /* Deferred character components have their string length tucked away
-in a hidden field of the derived type. Obtain that and use it to
-set the dtype. The charlen backend decl is zero because the field
-type is zero length.  */
-  gfc_ref *ref;
-  tmp = NULL_TREE;
-  for (ref = expr->ref; ref; ref = ref->next)
-   if (ref->type == REF_COMPONENT
-   && gfc_deferred_strlen (ref->u.c.component, &tmp))
- break;
-  gcc_assert (tmp != NULL_TREE);
-  tmp = fold_build3_loc (input_location, COMPONENT_REF, TREE_TYPE (tmp),
-TREE_OPERAND (descriptor, 0), tmp, NULL_TREE);
-  tmp = fold_convert (gfc_charlen_type_node, tmp);
-  type = gfc_get_character_type_len (expr->ts.kind, tmp);
-  gfc_conv_descriptor_dtype_set (pblock, descriptor,
-gfc_get_dtype_rank_type (rank, type));
-}
-  else if (expr3_desc && GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (expr3_desc)))
-gfc_conv_descriptor_dtype_set (pblock, descriptor,
-  gfc_conv_descriptor_dtype_get (expr3_desc));
-  else if (expr->ts.type == BT_CLASS && !explicit_ts
-  && expr3 && expr3->ts.type != BT_CLASS
-  && expr3_elem_size != NULL_TREE && expr3_desc == NULL_TREE)
-gfc_conv_descriptor_elem_len_set (pblock, descriptor, expr3_elem_size);
-  else
-gfc_conv_descriptor_dtype_set (pblock, descriptor, gfc_get_dtype (type));
-
-  tree empty_cond = logical_false_node;
-
-  for (n = 0; n < rank; n++)
-{
-  tree conv_lbound;
-  tree conv_ubound;
-
-  /* We have 3 possibilities for determining the size of the array:
-lower == NULL=> lbound = 1, ubound = upper[n]
-upper[n] = NULL  => lbound = 1, ubound 

[gcc(refs/users/mikael/heads/refactor_descriptor_v08)] gimple-simulate: Correction assertion évaluation LSHIFT_EXPR et RSHIFT_EXPR

2025-09-20 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:4425aca695b084e862b9ecdeaaf0e3725d2b480a

commit 4425aca695b084e862b9ecdeaaf0e3725d2b480a
Author: Mikael Morin 
Date:   Fri Aug 29 10:14:50 2025 +0200

gimple-simulate: Correction assertion évaluation LSHIFT_EXPR et RSHIFT_EXPR

Diff:
---
 gcc/gimple-simulate.cc | 41 -
 1 file changed, 40 insertions(+), 1 deletion(-)

diff --git a/gcc/gimple-simulate.cc b/gcc/gimple-simulate.cc
index 4fc64d342089..0951731a1d2c 100644
--- a/gcc/gimple-simulate.cc
+++ b/gcc/gimple-simulate.cc
@@ -2105,7 +2105,9 @@ simul_scope::evaluate_binary (enum tree_code code, tree 
type, tree lhs,
  && TYPE_PRECISION (TREE_TYPE (lhs))
 == TYPE_PRECISION (TREE_TYPE (rhs))
  && TYPE_UNSIGNED (TREE_TYPE (lhs))
-== TYPE_UNSIGNED (TREE_TYPE (rhs;
+== TYPE_UNSIGNED (TREE_TYPE (rhs)))
+ || code == LSHIFT_EXPR
+ || code == RSHIFT_EXPR);
   tree lval = val_lhs.to_tree (TREE_TYPE (lhs));
   tree rval = val_rhs.to_tree (TREE_TYPE (rhs));
   tree t = fold_binary (code, type, lval, rval);
@@ -5723,6 +5725,43 @@ simul_scope_evaluate_binary_tests ()
   wide_int wi_ne5 = val_ne5.get_known ();
   ASSERT_PRED1 (wi::fits_uhwi_p, wi_ne5);
   ASSERT_EQ (wi_ne5.to_uhwi (), 1);
+
+
+  tree l6 = create_var (long_integer_type_node, "l6");
+
+  vec decls6{};
+  decls6.safe_push (l6);
+
+  context_builder builder6 {};
+  builder6.add_decls (&decls6);
+  simul_scope ctx6 = builder6.build (mem, printer);
+
+  wide_int wi11_6 = wi::shwi (11, TYPE_PRECISION (long_integer_type_node));
+  data_value cst11_6 (long_integer_type_node);
+  cst11_6.set_known (wi11_6);
+  data_storage *strg_l6 = ctx6.find_reachable_var (l6);
+  gcc_assert (strg_l6 != nullptr);
+  strg_l6->set (cst11_6);
+
+  tree int3 = build_int_cst (integer_type_node, 3);
+  data_value lshift_6 = ctx6.evaluate_binary (LSHIFT_EXPR,
+ long_integer_type_node,
+ l6, int3);
+
+  ASSERT_EQ (lshift_6.classify (), VAL_KNOWN);
+  wide_int wi_lshift6 = lshift_6.get_known ();
+  ASSERT_PRED1 (wi::fits_shwi_p, wi_lshift6);
+  ASSERT_EQ (wi_lshift6.to_shwi (), 88);
+
+  tree int1 = build_int_cst (integer_type_node, 1);
+  data_value rshift_6 = ctx6.evaluate_binary (RSHIFT_EXPR,
+ long_integer_type_node,
+ l6, int1);
+
+  ASSERT_EQ (rshift_6.classify (), VAL_KNOWN);
+  wide_int wi_rshift6 = rshift_6.get_known ();
+  ASSERT_PRED1 (wi::fits_shwi_p, wi_rshift6);
+  ASSERT_EQ (wi_rshift6.to_shwi (), 5);
 }


[gcc(refs/users/mikael/heads/refactor_descriptor_v08)] gimple-simulate: Prise en charge tableaux non bornés

2025-09-20 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:ec2ed6504c195761bfa8da127662e2627a2cc29b

commit ec2ed6504c195761bfa8da127662e2627a2cc29b
Author: Mikael Morin 
Date:   Sat Aug 30 22:22:39 2025 +0200

gimple-simulate: Prise en charge tableaux non bornés

Diff:
---
 gcc/gimple-simulate.cc | 90 ++
 1 file changed, 84 insertions(+), 6 deletions(-)

diff --git a/gcc/gimple-simulate.cc b/gcc/gimple-simulate.cc
index e33f8d8d5b46..7075c6e14cf7 100644
--- a/gcc/gimple-simulate.cc
+++ b/gcc/gimple-simulate.cc
@@ -806,17 +806,30 @@ context_printer::print_bb_entry (basic_block bb)
 
 static tree
 pick_subref_at (tree var_ref, unsigned min_offset,
-   int * ignored_bits, unsigned min_size)
+   int * ignored_bits, unsigned min_size,
+   tree target_type = NULL_TREE)
 {
   if (ignored_bits != nullptr)
 *ignored_bits = 0;
+  if (target_type != NULL_TREE
+  && TYPE_SIZE (target_type) != NULL_TREE)
+min_size = get_constant_type_size (target_type);
   tree ref = var_ref;
   unsigned remaining_offset = min_offset;
   while (true)
 {
   tree var_type = TREE_TYPE (ref);
-  unsigned type_size = get_constant_type_size (var_type);
-  if (type_size == min_size)
+  if (target_type == NULL_TREE
+ || TYPE_SIZE (target_type) != NULL_TREE)
+   {
+ unsigned type_size = get_constant_type_size (var_type);
+ if (type_size == min_size)
+   break;
+   }
+  else if (var_type == target_type
+  || (TREE_CODE (var_type) == ARRAY_TYPE
+  && TREE_CODE (target_type) == ARRAY_TYPE
+  && TREE_TYPE (var_type) == TREE_TYPE (target_type)))
break;
 
   if (TREE_CODE (var_type) == ARRAY_TYPE)
@@ -868,8 +881,13 @@ pick_subref_at (tree var_ref, unsigned min_offset,
 
  tree field_type = TREE_TYPE (field);
 
- unsigned field_width = get_constant_type_size (field_type);
- gcc_assert (field_width >= min_size);
+ if (TYPE_SIZE (field_type) == NULL_TREE)
+   gcc_assert (next_field == NULL_TREE);
+ else
+   {
+ unsigned field_width = get_constant_type_size (field_type);
+ gcc_assert (field_width >= min_size);
+   }
 
  ref = build3 (COMPONENT_REF, field_type,
ref, field, NULL_TREE);
@@ -960,7 +978,7 @@ find_mem_ref_replacement (tree * repl, unsigned * offset, 
simul_scope & context,
  && wi::fits_uhwi_p (ref_offset));
 
   tree t = pick_subref_at (var_ref, ref_offset.to_uhwi (), nullptr,
-  get_constant_type_size (access_type));
+  0, access_type);
   if (t == NULL_TREE)
{
  *repl = var_ref;
@@ -4534,6 +4552,66 @@ context_printer_print_first_data_ref_part_tests ()
   ASSERT_EQ (res15, integer_type_node);
   const char * str15 = pp_formatted_text (&pp15);
   ASSERT_STREQ (str15, "# d.der1a1i_a1[1]");
+
+
+  tree range = build_range_type (integer_type_node,
+build_zero_cst (integer_type_node),
+NULL_TREE);
+  tree ai = build_array_type (integer_type_node, range, false);
+
+  tree der1i1a = make_node (RECORD_TYPE);
+  tree der1i1a_a2 = build_decl (input_location, FIELD_DECL,
+   get_identifier ("der1i1a_a2"), ai);
+  DECL_CONTEXT (der1i1a_a2) = der1i1a;
+  DECL_CHAIN (der1i1a_a2) = NULL_TREE;
+  tree der1i1a_i1 = build_decl (input_location, FIELD_DECL,
+   get_identifier ("der1i1a_i1"),
+   integer_type_node);
+  DECL_CONTEXT (der1i1a_i1) = der1i1a;
+  DECL_CHAIN (der1i1a_i1) = der1i1a_a2;
+  TYPE_FIELDS (der1i1a) = der1i1a_i1;
+  layout_type (der1i1a);
+
+  heap_memory mem16;
+
+  context_printer printer16;
+  pretty_printer & pp16 = printer16.pp;
+
+  tree d_16 = create_var (der1i1a, "d");
+  tree p_16 = create_var (ptr_type_node, "p");
+
+  vec decls16{};
+  decls16.safe_push (d_16);
+  decls16.safe_push (p_16);
+
+  context_builder builder16 {};
+  builder16.add_decls (&decls16);
+  simul_scope ctx16 = builder16.build (mem16, printer16);
+
+  data_storage *strg_d16 = ctx16.find_reachable_var (d_16);
+  gcc_assert (strg_d16 != nullptr);
+
+  storage_address addr_d16 (strg_d16->get_ref (), 0);
+  data_value val_p16 (ptr_type_node);
+  val_p16.set_address (addr_d16);
+
+  data_storage *strg_p16 = ctx16.find_reachable_var (p_16);
+  gcc_assert (strg_p16 != nullptr);
+  strg_p16->set (val_p16);
+
+  tree four_16 = build_int_cst (build_pointer_type (void_type_node),
+   HOST_BITS_PER_INT / CHAR_BIT);
+  tree ref_d16 = build2 (MEM_REF, ai, p_16, four_16);
+  tree ref16 = build4 (ARRAY_REF, integer_type_node, ref_d16,
+  build_one_cst (integer_type_node), NULL_TREE, NULL_TREE);
+
+  tree res16 = printer16.print_first_data_ref_part (ctx16, ref16, 0,
+  

[gcc r16-3885] ada: Remove dependence on secondary stack for type with controlled component

2025-09-20 Thread Marc Poulhies via Gcc-cvs
https://gcc.gnu.org/g:91b51fc42b167eedaaded6360c490a4306bc5c55

commit r16-3885-g91b51fc42b167eedaaded6360c490a4306bc5c55
Author: Gary Dismukes 
Date:   Mon Aug 25 23:44:41 2025 +

ada: Remove dependence on secondary stack for type with controlled component

There are cases where GNAT introduces a dependence on the secondary stack
in a build-in-place function with a result subtype that is definite, when
this dependence could be avoided.  In particular this is done for record
types that requires finalization due to having a controlled component.

At one time such functions required the secondary stack in order to
properly handle cases where the function might raise an exception
(to avoid improper finalization in the caller), but that is no longer
necessary.  We remove the dependence of these functions on the SS,
along with the BIPalloc formal and the generation of the big if_statement
that uses that formal.

An additional small change is to revise the condition for determining when
to generate SS mark/release within functions.

gcc/ada/ChangeLog:

* exp_ch6.ads (Make_Build_In_Place_Call_In_Allocator): Simplify 
comment.
* exp_ch6.adb (Make_Build_In_Place_Call_In_Allocator): Remove 
obsolete
comment about not being able to allocate fixed-size controlled 
results
on the caller side, and replace another obsolete comment with a 
simpler
comment. Call Build_Allocate_Deallocate_Proc when the function 
doesn't
need a BIPalloc formal to ensure that function results with 
controlled
parts allocated on the caller side will be chained for finalization.
(Make_Build_In_Place_Call_In_Object_Declaration): Call 
Needs_BIP_Collection
on the function's Entity_Id rather than the function call.
(Needs_BIP_Collection): If a BIP function doesn't need a BIPalloc 
formal
then it doesn't need a BIP collection either; return False in that 
case.
(Needs_BIP_Alloc_Form): Remove test of Needs_BIP_Collection.
* exp_ch7.adb (Expand_Cleanup_Actions): Move test of Uses_Sec_Stack
to be the first conjunct in setting of Needs_Sec_Stack_Mark, and put
the other tests in a disjunction subsidiary to that. Improve 
preceding
comment.

Diff:
---
 gcc/ada/exp_ch6.adb | 49 -
 gcc/ada/exp_ch6.ads |  6 ++
 gcc/ada/exp_ch7.adb | 20 ++--
 3 files changed, 28 insertions(+), 47 deletions(-)

diff --git a/gcc/ada/exp_ch6.adb b/gcc/ada/exp_ch6.adb
index 5056b1f990fa..58361e10bd9c 100644
--- a/gcc/ada/exp_ch6.adb
+++ b/gcc/ada/exp_ch6.adb
@@ -9093,27 +9093,6 @@ package body Exp_Ch6 is
   --  tagged, the called function itself must perform the allocation of
   --  the return object, so we pass parameters indicating that.
 
-  --  But that's also the case when the result subtype needs finalization
-  --  actions because the caller side allocation may result in undesirable
-  --  finalization. Consider the following example:
-  --
-  --function Make_Lim_Ctrl return Lim_Ctrl is
-  --begin
-  --   return Result : Lim_Ctrl := raise Program_Error do
-  --  null;
-  --   end return;
-  --end Make_Lim_Ctrl;
-  --
-  --Obj : Lim_Ctrl_Ptr := new Lim_Ctrl'(Make_Lim_Ctrl);
-  --
-  --  Even though the size of limited controlled type Lim_Ctrl is known,
-  --  allocating Obj at the caller side will chain Obj on Lim_Ctrl_Ptr's
-  --  finalization collection. The subsequent call to Make_Lim_Ctrl will
-  --  fail during the initialization actions for Result, which means that
-  --  Result (and Obj by extension) should not be finalized. However Obj
-  --  will be finalized when access type Lim_Ctrl_Ptr goes out of scope
-  --  since it is already attached on the its finalization collection.
-
   if Needs_BIP_Alloc_Form (Function_Id) then
  Temp_Init := Empty;
 
@@ -9278,11 +9257,7 @@ package body Exp_Ch6 is
  end if;
   end;
 
-  --  When the function has a controlling result, an allocation-form
-  --  parameter must be passed indicating that the caller is allocating
-  --  the result object. This is needed because such a function can be
-  --  called as a dispatching operation and must be treated similarly
-  --  to functions with unconstrained result subtypes.
+  --  Add implicit actuals for the BIP formal parameters, if any
 
   Add_Unconstrained_Actuals_To_Build_In_Place_Call
 (Func_Call,
@@ -9307,6 +9282,14 @@ package body Exp_Ch6 is
   Add_Access_Actual_To_Build_In_Place_Call
 (Func_Call, Function_Id, Return_Obj_Actual);
 
+  --  If the allocation is done in the caller, create a custom Allocate
+  --  procedure if need be.
+
+  if not Nee

[gcc(refs/users/mikael/heads/refactor_descriptor_v08)] Déplacement gfc_grow_array

2025-09-20 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:66251d041e8186d71d518722cbe2cc5058687c3a

commit 66251d041e8186d71d518722cbe2cc5058687c3a
Author: Mikael Morin 
Date:   Thu Jul 31 14:41:23 2025 +0200

Déplacement gfc_grow_array

Diff:
---
 gcc/fortran/trans-array.cc  | 37 -
 gcc/fortran/trans-descriptor.cc | 39 +++
 gcc/fortran/trans-descriptor.h  |  1 +
 3 files changed, 40 insertions(+), 37 deletions(-)

diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc
index 06e6418591d5..ea2723064cd4 100644
--- a/gcc/fortran/trans-array.cc
+++ b/gcc/fortran/trans-array.cc
@@ -1309,43 +1309,6 @@ gfc_get_iteration_count (tree start, tree end, tree step)
 }
 
 
-/* Extend the data in array DESC by EXTRA elements.  */
-
-static void
-gfc_grow_array (stmtblock_t * pblock, tree desc, tree extra)
-{
-  tree arg0, arg1;
-  tree tmp;
-  tree size;
-  tree ubound;
-
-  if (integer_zerop (extra))
-return;
-
-  ubound = gfc_conv_descriptor_ubound_get (desc, gfc_rank_cst[0]);
-
-  /* Add EXTRA to the upper bound.  */
-  tmp = fold_build2_loc (input_location, PLUS_EXPR, gfc_array_index_type,
-ubound, extra);
-  gfc_conv_descriptor_ubound_set (pblock, desc, gfc_rank_cst[0], tmp);
-
-  /* Get the value of the current data pointer.  */
-  arg0 = gfc_conv_descriptor_data_get (desc);
-
-  /* Calculate the new array size.  */
-  size = TYPE_SIZE_UNIT (gfc_get_element_type (TREE_TYPE (desc)));
-  tmp = fold_build2_loc (input_location, PLUS_EXPR, gfc_array_index_type,
-ubound, gfc_index_one_node);
-  arg1 = fold_build2_loc (input_location, MULT_EXPR, size_type_node,
- fold_convert (size_type_node, tmp),
- fold_convert (size_type_node, size));
-
-  /* Call the realloc() function.  */
-  tmp = gfc_call_realloc (pblock, arg0, arg1);
-  gfc_conv_descriptor_data_set (pblock, desc, tmp);
-}
-
-
 /* Return true if the bounds of iterator I can only be determined
at run time.  */
 
diff --git a/gcc/fortran/trans-descriptor.cc b/gcc/fortran/trans-descriptor.cc
index a885ad4d77aa..5ab51ad326f2 100644
--- a/gcc/fortran/trans-descriptor.cc
+++ b/gcc/fortran/trans-descriptor.cc
@@ -2468,3 +2468,42 @@ gfc_set_pdt_array_descriptor (stmtblock_t *block, tree 
descr,
 
   return size;
 }
+
+
+/* Extend the data in array DESC by EXTRA elements.  */
+
+void
+gfc_grow_array (stmtblock_t * pblock, tree desc, tree extra)
+{
+  tree arg0, arg1;
+  tree tmp;
+  tree size;
+  tree ubound;
+
+  if (integer_zerop (extra))
+return;
+
+  ubound = gfc_conv_descriptor_ubound_get (desc, gfc_rank_cst[0]);
+
+  /* Add EXTRA to the upper bound.  */
+  tmp = fold_build2_loc (input_location, PLUS_EXPR, gfc_array_index_type,
+ubound, extra);
+  gfc_conv_descriptor_ubound_set (pblock, desc, gfc_rank_cst[0], tmp);
+
+  /* Get the value of the current data pointer.  */
+  arg0 = gfc_conv_descriptor_data_get (desc);
+
+  /* Calculate the new array size.  */
+  size = TYPE_SIZE_UNIT (gfc_get_element_type (TREE_TYPE (desc)));
+  tmp = fold_build2_loc (input_location, PLUS_EXPR, gfc_array_index_type,
+ubound, gfc_index_one_node);
+  arg1 = fold_build2_loc (input_location, MULT_EXPR, size_type_node,
+ fold_convert (size_type_node, tmp),
+ fold_convert (size_type_node, size));
+
+  /* Call the realloc() function.  */
+  tmp = gfc_call_realloc (pblock, arg0, arg1);
+  gfc_conv_descriptor_data_set (pblock, desc, tmp);
+}
+
+
diff --git a/gcc/fortran/trans-descriptor.h b/gcc/fortran/trans-descriptor.h
index 33ed46d1c47a..f383cd97c262 100644
--- a/gcc/fortran/trans-descriptor.h
+++ b/gcc/fortran/trans-descriptor.h
@@ -147,5 +147,6 @@ void gfc_set_descriptor_for_assign_realloc (stmtblock_t *, 
gfc_loopinfo *,
tree, tree, bool);
 tree gfc_set_pdt_array_descriptor (stmtblock_t *, tree, gfc_array_spec *,
   gfc_actual_arglist *, tree);
+void gfc_grow_array (stmtblock_t *, tree, tree);
 
 #endif /* GFC_TRANS_DESCRIPTOR_H */


[gcc(refs/vendors/riscv/heads/gcc-15-with-riscv-opts)] RISC-V: Add test for vec_dup + vmax.vv combine case 0 with max func 0 and GR2VR cost 0, 2 and 15

2025-09-20 Thread Jeff Law via Gcc-cvs
https://gcc.gnu.org/g:e432c75476b3e20d0860684ba68508681c67bf67

commit e432c75476b3e20d0860684ba68508681c67bf67
Author: Pan Li 
Date:   Wed Jun 11 21:51:08 2025 +0800

RISC-V: Add test for vec_dup + vmax.vv combine case 0 with max func 0 and 
GR2VR cost 0, 2 and 15

Add asm dump check test for vec_duplicate + vmax.vv combine to vmax.vx,
with the GR2VR cost is 0, 2 and 15.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/autovec/vx_vf/vx-1-i16.c: Add asm check
for max func 1 vmax.vx combine.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-1-i32.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-1-i64.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-1-i8.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-2-i16.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-2-i32.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-2-i64.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-2-i8.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-3-i16.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-3-i32.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-3-i64.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-3-i8.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx_binary.h: Add test
helper macros.
* gcc.target/riscv/rvv/autovec/vx_vf/vx_binary_data.h: Add test
data for run test.
* gcc.target/riscv/rvv/autovec/vx_vf/vx_vmax-run-1-i16.c: New test.
* gcc.target/riscv/rvv/autovec/vx_vf/vx_vmax-run-1-i32.c: New test.
* gcc.target/riscv/rvv/autovec/vx_vf/vx_vmax-run-1-i64.c: New test.
* gcc.target/riscv/rvv/autovec/vx_vf/vx_vmax-run-1-i8.c: New test.

Signed-off-by: Pan Li 
(cherry picked from commit 2ebb805fe2f29262a455aaf412b3f77060e05fe2)

Diff:
---
 .../gcc.target/riscv/rvv/autovec/vx_vf/vx-1-i16.c  |   2 +
 .../gcc.target/riscv/rvv/autovec/vx_vf/vx-1-i32.c  |   2 +
 .../gcc.target/riscv/rvv/autovec/vx_vf/vx-1-i64.c  |   2 +
 .../gcc.target/riscv/rvv/autovec/vx_vf/vx-1-i8.c   |   2 +
 .../gcc.target/riscv/rvv/autovec/vx_vf/vx-2-i16.c  |   2 +
 .../gcc.target/riscv/rvv/autovec/vx_vf/vx-2-i32.c  |   2 +
 .../gcc.target/riscv/rvv/autovec/vx_vf/vx-2-i64.c  |   2 +
 .../gcc.target/riscv/rvv/autovec/vx_vf/vx-2-i8.c   |   2 +
 .../gcc.target/riscv/rvv/autovec/vx_vf/vx-3-i16.c  |   2 +
 .../gcc.target/riscv/rvv/autovec/vx_vf/vx-3-i32.c  |   2 +
 .../gcc.target/riscv/rvv/autovec/vx_vf/vx-3-i64.c  |   2 +
 .../gcc.target/riscv/rvv/autovec/vx_vf/vx-3-i8.c   |   2 +
 .../gcc.target/riscv/rvv/autovec/vx_vf/vx_binary.h |  93 ++
 .../riscv/rvv/autovec/vx_vf/vx_binary_data.h   | 196 +
 .../riscv/rvv/autovec/vx_vf/vx_vmax-run-1-i16.c|  17 ++
 .../riscv/rvv/autovec/vx_vf/vx_vmax-run-1-i32.c|  17 ++
 .../riscv/rvv/autovec/vx_vf/vx_vmax-run-1-i64.c|  17 ++
 .../riscv/rvv/autovec/vx_vf/vx_vmax-run-1-i8.c |  17 ++
 18 files changed, 381 insertions(+)

diff --git a/gcc/testsuite/gcc.target/riscv/rvv/autovec/vx_vf/vx-1-i16.c 
b/gcc/testsuite/gcc.target/riscv/rvv/autovec/vx_vf/vx-1-i16.c
index 893d910538ca..36df981182b9 100644
--- a/gcc/testsuite/gcc.target/riscv/rvv/autovec/vx_vf/vx-1-i16.c
+++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/vx_vf/vx-1-i16.c
@@ -14,6 +14,7 @@ DEF_VX_BINARY_CASE_0_WRAP(T, ^, xor)
 DEF_VX_BINARY_CASE_0_WRAP(T, *, mul)
 DEF_VX_BINARY_CASE_0_WRAP(T, /, div)
 DEF_VX_BINARY_CASE_0_WRAP(T, %, rem)
+DEF_VX_BINARY_CASE_2_WRAP(T, MAX_FUNC_0_WARP(T), max)
 
 /* { dg-final { scan-assembler-times {vadd.vx} 1 } } */
 /* { dg-final { scan-assembler-times {vsub.vx} 1 } } */
@@ -24,3 +25,4 @@ DEF_VX_BINARY_CASE_0_WRAP(T, %, rem)
 /* { dg-final { scan-assembler-times {vmul.vx} 1 } } */
 /* { dg-final { scan-assembler-times {vdiv.vx} 1 } } */
 /* { dg-final { scan-assembler-times {vrem.vx} 1 } } */
+/* { dg-final { scan-assembler-times {vmax.vx} 1 } } */
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/autovec/vx_vf/vx-1-i32.c 
b/gcc/testsuite/gcc.target/riscv/rvv/autovec/vx_vf/vx-1-i32.c
index 26170de40d0c..ceb499f5edfe 100644
--- a/gcc/testsuite/gcc.target/riscv/rvv/autovec/vx_vf/vx-1-i32.c
+++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/vx_vf/vx-1-i32.c
@@ -14,6 +14,7 @@ DEF_VX_BINARY_CASE_0_WRAP(T, ^, xor)
 DEF_VX_BINARY_CASE_0_WRAP(T, *, mul)
 DEF_VX_BINARY_CASE_0_WRAP(T, /, div)
 DEF_VX_BINARY_CASE_0_WRAP(T, %, rem)
+DEF_VX_BINARY_CASE_2_WRAP(T, MAX_FUNC_0_WARP(T), max)
 
 /* { dg-final { scan-assembler-times {vadd.vx} 1 } } */
 /* { dg-final { scan-assembler-times {vsub.vx} 1 } } */
@@ -24,3 +25,4 @@ DEF_VX_BINARY_CASE_0_WRAP(T, %, rem)
 /* { dg-final { scan-assembler-times {vmul.vx} 1 } } */
 /* { dg-final { scan-assembler-times {vdiv.vx} 1 } } */
 /* { dg-final { scan-assembler-times {vrem.vx} 1 } } */
+/* { dg-final { scan-assembler-times {vmax.vx} 1 } } */
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/auto

  1   2   3   4   >