[gcc r16-713] [PATCH] libgcc SH: fix alignment for relaxation

2025-05-17 Thread Jeff Law via Gcc-cvs
https://gcc.gnu.org/g:de04f593efe611d64cb50575332cef03d6eba561

commit r16-713-gde04f593efe611d64cb50575332cef03d6eba561
Author: Oleg Endo 
Date:   Sat May 17 10:51:35 2025 -0600

[PATCH] libgcc SH: fix alignment for relaxation

From 6462f1e6a2565c5d4756036d9bc2f39dce9bd768 Mon Sep 17 00:00:00 2001
From: QBos07 
Date: Sat, 10 May 2025 16:56:28 +
Subject: [PATCH] libgcc SH: fix alignment for relaxation

when relaxation is enabled we can not infer the alignment
from the position as that may change. This should not change
non-relaxed builds as its allready aligned there. This was
the missing piece to building an entire toolchain with -mrelax

Credit goes to Oleg Endo: 
https://sourceware.org/bugzilla/show_bug.cgi?id=3298#c4

libgcc/
* config/sh/lib1funcs.S (ashiftrt_r4_32): Increase alignment.
(movemem): Force alignment of the mova intruction.

Diff:
---
 libgcc/config/sh/lib1funcs.S | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libgcc/config/sh/lib1funcs.S b/libgcc/config/sh/lib1funcs.S
index eda48066cdc1..11acfd5e3261 100644
--- a/libgcc/config/sh/lib1funcs.S
+++ b/libgcc/config/sh/lib1funcs.S
@@ -115,7 +115,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  
If not, see
HIDDEN_FUNC(GLOBAL(ashiftrt_r4_31))
HIDDEN_FUNC(GLOBAL(ashiftrt_r4_32))
 
-   .align  1
+   .align  4
 GLOBAL(ashiftrt_r4_32):
 GLOBAL(ashiftrt_r4_31):
rotcl   r4
@@ -764,6 +764,7 @@ LOCAL(movmem_loop): /* Reached with rts */
bt  GLOBAL(movmemSI52)
 ! done all the large groups, do the remainder
 ! jump to movmem+
+   .balign 4
movaGLOBAL(movmemSI4)+4,r0
add r6,r0
jmp @r0


[gcc/mikael/heads/refactor_descriptor_v05] Correction régression class_dummy_7

2025-05-17 Thread Mikael Morin via Gcc-cvs
The branch 'mikael/heads/refactor_descriptor_v05' was updated to point to:

 6c4ebec31681... Correction régression class_dummy_7

It previously pointed to:

 9e2bcd29e32c... Correction régression class_dummy_7

Diff:

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

  9e2bcd2... Correction régression class_dummy_7


Summary of changes (added commits):
---

  6c4ebec... Correction régression class_dummy_7


[gcc(refs/users/mikael/heads/refactor_descriptor_v05)] gimple-exec: prise en charge memcpy

2025-05-17 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:d8822da68eff0612ace646e7dfdb0921415641e9

commit d8822da68eff0612ace646e7dfdb0921415641e9
Author: Mikael Morin 
Date:   Sat May 17 18:38:28 2025 +0200

gimple-exec: prise en charge memcpy

Diff:
---
 gcc/cgraphunit.cc | 62 ---
 1 file changed, 59 insertions(+), 3 deletions(-)

diff --git a/gcc/cgraphunit.cc b/gcc/cgraphunit.cc
index cf2cfa11c534..816393414a23 100644
--- a/gcc/cgraphunit.cc
+++ b/gcc/cgraphunit.cc
@@ -2457,8 +2457,6 @@ class data_value
   void set_cst_at (unsigned dest_offset, unsigned value_width,
   const wide_int &val, unsigned src_offset);
   stored_address *find_address (unsigned offset) const;
-  void set_at (unsigned dest_offset, unsigned value_width,
-  const data_value & value_src, unsigned src_offset);
 
   friend void selftest::data_value_classify_tests ();
   friend void selftest::data_value_set_address_tests ();
@@ -2484,6 +2482,8 @@ public:
   void set_undefined_at (unsigned offset, unsigned width);
   void set_address_at (storage_address & address, unsigned offset);
   void set_address (storage_address & address);
+  void set_at (unsigned dest_offset, unsigned value_width,
+  const data_value & value_src, unsigned src_offset);
   void set_at (const data_value & value, unsigned offset);
   void set (const data_value & value);
   void set_cst_at (const wide_int & val, unsigned offset);
@@ -4439,8 +4439,10 @@ exec_context::execute_call (gcall *g)
   data_storage & storage1 = addr1.storage.get ();
   data_value src = storage1.get_value ();
   wide_int wi_len2 = len2.get_cst ();
+  wi_len2 *= CHAR_BIT;
   gcc_assert (wi::fits_uhwi_p (wi_len2));
-  dest_val.set (src);
+  dest_val.set_at (0, wi_len2.to_uhwi (),
+  src, addr1.offset);
   storage0.set (dest_val);
 }
   else
@@ -8643,6 +8645,60 @@ exec_context_execute_call_tests ()
   wide_int wi_v82 = v82_after.get_cst ();
   ASSERT_PRED1 (wi::fits_shwi_p, wi_v82);
   ASSERT_EQ (wi_v82.to_shwi (), 17);
+
+
+  tree i91 = create_var (integer_type_node, "i91");
+  tree c92 = create_var (char_type_node, "c92");
+  tree p93 = create_var (ptr_type_node, "p93");
+
+  vec decls9{};
+  decls9.safe_push (i91);
+  decls9.safe_push (c92);
+  decls9.safe_push (p93);
+
+  heap_memory mem9;
+  context_builder builder9 {};
+  builder9.add_decls (&decls9);
+  exec_context ctx9 = builder9.build (mem9, printer);
+
+  data_storage * storage_i91 = ctx9.find_reachable_var (i91);
+  gcc_assert (storage_i91 != nullptr);
+  storage_address addr91 (storage_i91->get_ref (), CHAR_BIT);
+
+  data_value val_addr91 (ptr_type_node);
+  val_addr91.set_address (addr91);
+
+  data_storage * storage_p93 = ctx9.find_reachable_var (p93);
+  gcc_assert (storage_p93 != nullptr);
+  storage_p93->set (val_addr91);
+
+  tree a92 = build1_loc (UNKNOWN_LOCATION, ADDR_EXPR,
+ptr_type_node, c92);
+
+  gcall * memcpy_call9 = gimple_build_call (memcpy_fn, 3, a92, p93,
+   size_one_node);
+
+  data_value val91 (integer_type_node);
+  wide_int wi91 = wi::uhwi (5 + 3 * 256 + 1 * 65536, HOST_BITS_PER_INT);
+  val91.set_cst (wi91);
+
+  storage_i91->set (val91);
+  
+  data_storage *storage_c92 = ctx9.find_reachable_var (c92);
+  gcc_assert (storage_c92 != nullptr);
+
+  data_value c92_before = storage_c92->get_value ();
+
+  ASSERT_EQ (c92_before.classify (), VAL_UNDEFINED);
+
+  ctx9.execute (memcpy_call9);
+
+  data_value c92_after = storage_c92->get_value ();
+
+  ASSERT_EQ (c92_after.classify (), VAL_CONSTANT);
+  wide_int wi_c92 = c92_after.get_cst ();
+  ASSERT_PRED1 (wi::fits_shwi_p, wi_c92);
+  ASSERT_EQ (wi_c92.to_shwi (), 3);
 }
 
 void


[gcc(refs/users/mikael/heads/refactor_descriptor_v05)] Correction régression class_dummy_7

2025-05-17 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:9e2bcd29e32ccb9b57026c6e42b22ca280c57907

commit 9e2bcd29e32ccb9b57026c6e42b22ca280c57907
Author: Mikael Morin 
Date:   Sat May 17 18:38:46 2025 +0200

Correction régression class_dummy_7

Diff:
---
 gcc/fortran/trans-array.cc | 16 +++-
 gcc/fortran/trans-decl.cc  |  2 +-
 gcc/fortran/trans-expr.cc  | 17 -
 3 files changed, 28 insertions(+), 7 deletions(-)

diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc
index 0e478e1d3121..569e72563653 100644
--- a/gcc/fortran/trans-array.cc
+++ b/gcc/fortran/trans-array.cc
@@ -6281,7 +6281,21 @@ gfc_trans_array_bounds (tree type, gfc_symbol * sym, 
tree * poffset,
   offset = gfc_index_zero_node;
   tree spacing = GFC_TYPE_ARRAY_SPACING (type, 0);
   if (spacing && VAR_P (spacing))
-gfc_add_modify (pblock, spacing, elem_len);
+{
+  tree spacing0;
+  if (sym->ts.type == BT_CLASS
+ && DECL_LANG_SPECIFIC (sym->backend_decl)
+ && GFC_DECL_SAVED_DESCRIPTOR (sym->backend_decl))
+   {
+ tree class_desc = GFC_DECL_SAVED_DESCRIPTOR (sym->backend_decl);
+ tree array_desc = gfc_class_data_get (class_desc);
+ spacing0 = gfc_conv_array_spacing (array_desc, 0);
+   }
+  else
+   spacing0 = elem_len;
+
+  gfc_add_modify (pblock, spacing, spacing0);
+}
   for (dim = 0; dim < as->rank; dim++)
 {
   /* Evaluate non-constant array bound expressions.
diff --git a/gcc/fortran/trans-decl.cc b/gcc/fortran/trans-decl.cc
index 92a0ccdb3588..a16487106046 100644
--- a/gcc/fortran/trans-decl.cc
+++ b/gcc/fortran/trans-decl.cc
@@ -1345,7 +1345,7 @@ gfc_build_dummy_array_decl (gfc_symbol * sym, tree dummy)
 are not repacked.  */
   if (!flag_repack_arrays || sym->attr.target)
{
- if (as->type == AS_ASSUMED_SIZE)
+ if (as->type == AS_ASSUMED_SIZE && !is_classarray)
packed = PACKED_FULL;
}
   else
diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc
index ba32bd9bfd07..9f0c3211b452 100644
--- a/gcc/fortran/trans-expr.cc
+++ b/gcc/fortran/trans-expr.cc
@@ -3068,13 +3068,20 @@ gfc_maybe_dereference_var (gfc_symbol *sym, tree var, 
bool descriptor_only_p,
   else if (!sym->attr.value)
 {
   /* Dereference temporaries for class array dummy arguments.  */
-  if (sym->attr.dummy && is_classarray
- && GFC_ARRAY_TYPE_P (TREE_TYPE (var)))
+  if (sym->attr.dummy && is_classarray)
{
- if (!descriptor_only_p)
-   var = GFC_DECL_SAVED_DESCRIPTOR (var);
+ bool dereference = false;
+ if (TREE_CODE (TREE_TYPE (var)) == REFERENCE_TYPE)
+   dereference = true;
+ else if (GFC_ARRAY_TYPE_P (TREE_TYPE (var)))
+   {
+ dereference = true;
+ if (!descriptor_only_p)
+   var = GFC_DECL_SAVED_DESCRIPTOR (var);
+   }
 
- var = build_fold_indirect_ref_loc (input_location, var);
+ if (dereference)
+   var = build_fold_indirect_ref_loc (input_location, var);
}
 
   /* Dereference non-character scalar dummy arguments.  */


[gcc(refs/users/mikael/heads/refactor_descriptor_v05)] Correction régression class_dummy_7

2025-05-17 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:6c4ebec3168114c4ebddcb81994004326d70952b

commit 6c4ebec3168114c4ebddcb81994004326d70952b
Author: Mikael Morin 
Date:   Sat May 17 18:38:46 2025 +0200

Correction régression class_dummy_7

Correction régression pr63331

Diff:
---
 gcc/fortran/trans-array.cc | 16 +++-
 gcc/fortran/trans-decl.cc  |  2 +-
 2 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc
index 0e478e1d3121..569e72563653 100644
--- a/gcc/fortran/trans-array.cc
+++ b/gcc/fortran/trans-array.cc
@@ -6281,7 +6281,21 @@ gfc_trans_array_bounds (tree type, gfc_symbol * sym, 
tree * poffset,
   offset = gfc_index_zero_node;
   tree spacing = GFC_TYPE_ARRAY_SPACING (type, 0);
   if (spacing && VAR_P (spacing))
-gfc_add_modify (pblock, spacing, elem_len);
+{
+  tree spacing0;
+  if (sym->ts.type == BT_CLASS
+ && DECL_LANG_SPECIFIC (sym->backend_decl)
+ && GFC_DECL_SAVED_DESCRIPTOR (sym->backend_decl))
+   {
+ tree class_desc = GFC_DECL_SAVED_DESCRIPTOR (sym->backend_decl);
+ tree array_desc = gfc_class_data_get (class_desc);
+ spacing0 = gfc_conv_array_spacing (array_desc, 0);
+   }
+  else
+   spacing0 = elem_len;
+
+  gfc_add_modify (pblock, spacing, spacing0);
+}
   for (dim = 0; dim < as->rank; dim++)
 {
   /* Evaluate non-constant array bound expressions.
diff --git a/gcc/fortran/trans-decl.cc b/gcc/fortran/trans-decl.cc
index 92a0ccdb3588..a16487106046 100644
--- a/gcc/fortran/trans-decl.cc
+++ b/gcc/fortran/trans-decl.cc
@@ -1345,7 +1345,7 @@ gfc_build_dummy_array_decl (gfc_symbol * sym, tree dummy)
 are not repacked.  */
   if (!flag_repack_arrays || sym->attr.target)
{
- if (as->type == AS_ASSUMED_SIZE)
+ if (as->type == AS_ASSUMED_SIZE && !is_classarray)
packed = PACKED_FULL;
}
   else


[gcc r16-710] [PATCH] gcc: add trigonometric pi-based functions as gcc builtins

2025-05-17 Thread Jeff Law via Gcc-cvs
https://gcc.gnu.org/g:591d3d02664c7b27679318de1273b09c061283bc

commit r16-710-g591d3d02664c7b27679318de1273b09c061283bc
Author: Yuao Ma 
Date:   Sat May 17 07:42:24 2025 -0600

[PATCH] gcc: add trigonometric pi-based functions as gcc builtins

 This patch adds trigonometric pi-based functions as gcc builtins: acospi, 
asinpi, atan2pi,
atanpi, cospi, sinpi, and tanpi. Latest glibc already provides support for
these functions, which we plan to leverage in future gfortran 
implementations.

The patch includes two test cases to verify both correct code generation and
function definition.

If approved, I suggest committing this foundational change first. Constant
folding for these builtins will be addressed in subsequent patches.

Best regards,
Yuao

From 9a9683d250078ce1bc687797c26ca05a9e91b350 Mon Sep 17 00:00:00 2001
From: Yuao Ma 
Date: Wed, 14 May 2025 22:14:00 +0800
Subject: [PATCH] gcc: add trigonometric pi-based functions as gcc builtins

Add trigonometric pi-based functions as GCC builtins: acospi, asinpi, 
atan2pi,
atanpi, cospi, sinpi, and tanpi. Latest glibc already provides support for
these functions, which we plan to leverage in future gfortran 
implementations.

The patch includes two test cases to verify both correct code generation and
function definition.

If approved, I suggest committing this foundational change first. Constant
folding for these builtins will be addressed in subsequent patches.

gcc/ChangeLog:

* builtins.def (TRIG_TYPE): New.
(BUILT_IN_ACOSPI): New.
(BUILT_IN_ACOSPIF): New.
(BUILT_IN_ACOSPIL): New.
(BUILT_IN_ASINPI): New.
(BUILT_IN_ASINPIF): New.
(BUILT_IN_ASINPIL): New.
(BUILT_IN_ATANPI): New.
(BUILT_IN_ATANPIF): New.
(BUILT_IN_ATANPIL): New.
(BUILT_IN_COSPI): New.
(BUILT_IN_COSPIF): New.
(BUILT_IN_COSPIL): New.
(BUILT_IN_SINPI): New.
(BUILT_IN_SINPIF): New.
(BUILT_IN_SINPIL): New.
(BUILT_IN_TANPI): New.
(BUILT_IN_TANPIF): New.
(BUILT_IN_TANPIL): New.
(TRIG2_TYPE): New.
(BUILT_IN_ATAN2PI): New.
(BUILT_IN_ATAN2PIF): New.
(BUILT_IN_ATAN2PIL): New.

gcc/testsuite/ChangeLog:

* gcc.dg/builtins-1.c: Builtin codegen test.
* gcc.dg/c23-builtins-1.c: Builtin signature test.

Diff:
---
 gcc/builtins.def  | 32 
 gcc/testsuite/gcc.dg/builtins-1.c |  7 +++
 gcc/testsuite/gcc.dg/c23-builtins-1.c | 22 ++
 3 files changed, 61 insertions(+)

diff --git a/gcc/builtins.def b/gcc/builtins.def
index ff470051e54e..fdcad54a5d75 100644
--- a/gcc/builtins.def
+++ b/gcc/builtins.def
@@ -844,6 +844,38 @@ DEF_EXT_LIB_FLOATN_NX_BUILTINS (BUILT_IN_CTANH, "ctanh", 
CPROJ_TYPE, ATTR_MATHFN
 DEF_C99_COMPL_BUILTIN(BUILT_IN_CTANL, "ctanl", 
BT_FN_COMPLEX_LONGDOUBLE_COMPLEX_LONGDOUBLE, ATTR_MATHFN_FPROUNDING)
 DEF_EXT_LIB_FLOATN_NX_BUILTINS (BUILT_IN_CTAN, "ctan", CPROJ_TYPE, 
ATTR_MATHFN_FPROUNDING)
 #undef CPROJ_TYPE
+#define TRIG_TYPE(F) BT_FN_##F##_##F
+DEF_C23_BUILTIN (BUILT_IN_ACOSPI, "acospi", BT_FN_DOUBLE_DOUBLE, 
ATTR_MATHFN_FPROUNDING_ERRNO)
+DEF_C23_BUILTIN (BUILT_IN_ACOSPIF, "acospif", BT_FN_FLOAT_FLOAT, 
ATTR_MATHFN_FPROUNDING_ERRNO)
+DEF_C23_BUILTIN (BUILT_IN_ACOSPIL, "acospil", BT_FN_LONGDOUBLE_LONGDOUBLE, 
ATTR_MATHFN_FPROUNDING_ERRNO)
+DEF_EXT_LIB_FLOATN_NX_BUILTINS (BUILT_IN_ACOSPI, "acospi", TRIG_TYPE, 
ATTR_MATHFN_FPROUNDING_ERRNO)
+DEF_C23_BUILTIN (BUILT_IN_ASINPI, "asinpi", BT_FN_DOUBLE_DOUBLE, 
ATTR_MATHFN_FPROUNDING_ERRNO)
+DEF_C23_BUILTIN (BUILT_IN_ASINPIF, "asinpif", BT_FN_FLOAT_FLOAT, 
ATTR_MATHFN_FPROUNDING_ERRNO)
+DEF_C23_BUILTIN (BUILT_IN_ASINPIL, "asinpil", BT_FN_LONGDOUBLE_LONGDOUBLE, 
ATTR_MATHFN_FPROUNDING_ERRNO)
+DEF_EXT_LIB_FLOATN_NX_BUILTINS (BUILT_IN_ASINPI, "asinpi", TRIG_TYPE, 
ATTR_MATHFN_FPROUNDING_ERRNO)
+DEF_C23_BUILTIN (BUILT_IN_ATANPI, "atanpi", BT_FN_DOUBLE_DOUBLE, 
ATTR_MATHFN_FPROUNDING_ERRNO)
+DEF_C23_BUILTIN (BUILT_IN_ATANPIF, "atanpif", BT_FN_FLOAT_FLOAT, 
ATTR_MATHFN_FPROUNDING_ERRNO)
+DEF_C23_BUILTIN (BUILT_IN_ATANPIL, "atanpil", BT_FN_LONGDOUBLE_LONGDOUBLE, 
ATTR_MATHFN_FPROUNDING_ERRNO)
+DEF_EXT_LIB_FLOATN_NX_BUILTINS (BUILT_IN_ATANPI, "atanpi", TRIG_TYPE, 
ATTR_MATHFN_FPROUNDING_ERRNO)
+DEF_C23_BUILTIN (BUILT_IN_COSPI, "cospi", BT_FN_DOUBLE_DOUBLE, 
ATTR_MATHFN_FPROUNDING_ERRNO)
+DEF_C23_BUILTIN (BUILT_IN_COSPIF, "cospif", BT_FN_FLOAT_FLOAT, 
ATTR_MATHFN_FPROUNDING_ERRNO)
+DEF_C23_BUILTIN (BUILT_IN_COSPIL, "cospil", BT_FN_LONGDOUBLE_LONGDOUBLE, 
ATTR_MATHFN_FPROUNDING_ERRNO)
+DEF_EXT_LIB_FLOATN_NX_BUILTINS (BUILT_IN_COSPI, "cospi", TRIG_TYPE, 
ATTR_MATHFN_FPROUNDING_ERRNO)
+DEF_C23_BUILTIN (BUILT_IN_SINPI, "sinpi", BT_FN_DOUBLE_DOU

[gcc r16-711] [PATCH] gcc: add trigonometric pi-based functions as gcc builtins

2025-05-17 Thread Jeff Law via Gcc-cvs
https://gcc.gnu.org/g:89935d56f768b4cdb767aae8de33f39f9b846a10

commit r16-711-g89935d56f768b4cdb767aae8de33f39f9b846a10
Author: Yuao Ma 
Date:   Sat May 17 07:45:49 2025 -0600

[PATCH] gcc: add trigonometric pi-based functions as gcc builtins

I committed the wrong version on Yuao's behalf.  This followup adds the
documentation changes -- Jeff.

This patch adds trigonometric pi-based functions as gcc builtins: acospi, 
asinpi, atan2pi,
atanpi, cospi, sinpi, and tanpi. Latest glibc already provides support for
these functions, which we plan to leverage in future gfortran 
implementations.

The patch includes two test cases to verify both correct code generation and
function definition.

If approved, I suggest committing this foundational change first. Constant
folding for these builtins will be addressed in subsequent patches.

Best regards,
Yuao

From 9a9683d250078ce1bc687797c26ca05a9e91b350 Mon Sep 17 00:00:00 2001
From: Yuao Ma 
Date: Wed, 14 May 2025 22:14:00 +0800
Subject: [PATCH] gcc: add trigonometric pi-based functions as gcc builtins

Add trigonometric pi-based functions as GCC builtins: acospi, asinpi, 
atan2pi,
atanpi, cospi, sinpi, and tanpi. Latest glibc already provides support for
these functions, which we plan to leverage in future gfortran 
implementations.

The patch includes two test cases to verify both correct code generation and
function definition.

If approved, I suggest committing this foundational change first. Constant
folding for these builtins will be addressed in subsequent patches.

gcc/ChangeLog:

* doc/extend.texi: Mention new builtins.

Diff:
---
 gcc/doc/extend.texi | 37 +++--
 1 file changed, 31 insertions(+), 6 deletions(-)

diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi
index 40ccf22b29f4..37dae2552d6a 100644
--- a/gcc/doc/extend.texi
+++ b/gcc/doc/extend.texi
@@ -14374,6 +14374,9 @@ a function call results in a compile-time error.
 @findex acoshf
 @findex acoshl
 @findex acosl
+@findex acospi
+@findex acospif
+@findex acospil
 @findex alloca
 @findex asin
 @findex asinf
@@ -14381,15 +14384,24 @@ a function call results in a compile-time error.
 @findex asinhf
 @findex asinhl
 @findex asinl
+@findex asinpi
+@findex asinpif
+@findex asinpil
 @findex atan
 @findex atan2
 @findex atan2f
 @findex atan2l
+@findex atan2pi
+@findex atan2pif
+@findex atan2pil
 @findex atanf
 @findex atanh
 @findex atanhf
 @findex atanhl
 @findex atanl
+@findex atanpi
+@findex atanpif
+@findex atanpil
 @findex bcmp
 @findex bzero
 @findex cabs
@@ -14453,6 +14465,9 @@ a function call results in a compile-time error.
 @findex coshf
 @findex coshl
 @findex cosl
+@findex cospi
+@findex cospif
+@findex cospil
 @findex cpow
 @findex cpowf
 @findex cpowl
@@ -14688,6 +14703,9 @@ a function call results in a compile-time error.
 @findex sinhf
 @findex sinhl
 @findex sinl
+@findex sinpi
+@findex sinpif
+@findex sinpil
 @findex snprintf
 @findex sprintf
 @findex sqrt
@@ -14722,6 +14740,9 @@ a function call results in a compile-time error.
 @findex tanhf
 @findex tanhl
 @findex tanl
+@findex tanpi
+@findex tanpif
+@findex tanpil
 @findex tgamma
 @findex tgammaf
 @findex tgammal
@@ -14764,7 +14785,10 @@ a particular case, a call to the library function is 
emitted.
 @opindex std
 Outside strict ISO C mode (@option{-ansi}, @option{-std=c90},
 @option{-std=c99} or @option{-std=c11}), the functions
-@code{_exit}, @code{alloca}, @code{bcmp}, @code{bzero},
+@code{_exit}, @code{alloca}, @code{acospi}, @code{acospif}, @code{acospil},
+@code{asinpi}, @code{asinpif}, @code{asinpil}, @code{atan2pi}, @code{atan2pif},
+@code{atan2pil}, @code{atanpi}, @code{atanpif}, @code{atanpil}, @code{bcmp},
+@code{bzero}, @code{cospi}, @code{cospif}, @code{cospil},
 @code{dcgettext}, @code{dgettext}, @code{dremf}, @code{dreml},
 @code{drem}, @code{exp10f}, @code{exp10l}, @code{exp10}, @code{ffsll},
 @code{ffsl}, @code{ffs}, @code{fprintf_unlocked},
@@ -14779,11 +14803,12 @@ Outside strict ISO C mode (@option{-ansi}, 
@option{-std=c90},
 @code{signbit}, @code{signbitf}, @code{signbitl}, @code{signbitd32},
 @code{signbitd64}, @code{signbitd128}, @code{significandf},
 @code{significandl}, @code{significand}, @code{sincosf},
-@code{sincosl}, @code{sincos}, @code{stpcpy}, @code{stpncpy},
-@code{strcasecmp}, @code{strdup}, @code{strfmon}, @code{strncasecmp},
-@code{strndup}, @code{strnlen}, @code{toascii}, @code{y0f}, @code{y0l},
-@code{y0}, @code{y1f}, @code{y1l}, @code{y1}, @code{ynf}, @code{ynl} and
-@code{yn}
+@code{sincosl}, @code{sincos}, @code{sinpif}, @code{sinpil}, @code{sinpi},
+@code{stpcpy}, @code{stpncpy}, @code{strcasecmp}, @code{strdup},
+@code{strfmon}, @code{strncasecmp}, @code{strndup}, @code{strnlen},
+@code{tanpif}, @code{tanpil}, @code{tanpi}, @code{toascii}, @code{y0f},
+@code{y0l}, @code{y0}, @code{y1f}, @code{y1l}, @code{y1},

[gcc r16-709] [RISC-V] Avoid setting output object more than once in IOR/XOR synthesis

2025-05-17 Thread Jeff Law via Gcc-cvs
https://gcc.gnu.org/g:6ecda1972a1e19d23e6dd238c7509c25acf5c914

commit r16-709-g6ecda1972a1e19d23e6dd238c7509c25acf5c914
Author: Jeff Law 
Date:   Sat May 17 07:16:50 2025 -0600

[RISC-V] Avoid setting output object more than once in IOR/XOR synthesis

While evaluating Shreya's logical AND synthesis work on spec2017 I ran into 
a
code quality regression where combine was failing to eliminate a redundant 
sign
extension.

I had a hunch the problem would be with the multiple sets of the same pseudo
register in the AND synthesis path.  I was right that the problem was 
multiple
sets of the same pseudo, but it was actually some of the splitters in the
RISC-V backend that were the culprit.  Those multiple sets caused the sign 
bit
tracking code to need to make conservative assumptions thus resulting in
failure to eliminate the unnecessary sign extension.

So before we start moving on the logical AND patch we're going to do some
cleanups.

There's multiple moving parts in play.  For example, we have splitters 
which do
multiple sets of the output register.  Fixing some of those independently 
would
result in a code quality regression.  Instead they need some adjustments to 
or
removal of mvconst_internal.  Of course getting rid of mvconst_internal will
trigger all kinds of code quality regressions right now which ultimately 
lead
back to the need to revamp the logical AND expander.  Point being we've got
some circular dependencies and breaking them may result in short term code
quality regressions.  I'll obviously try to avoid those as much as possible.

So to start the process this patch adjusts the recently added XOR/IOR 
synthesis
to avoid re-using the destination register.  While the reuse was clearly 
safe
from a semantic standpoint, various parts of the compiler can do a better 
job
for pseudos that are only set once.

Given this synthesis path should only be active during initial RTL 
generation,
we can create new pseudos at will, so we create a new one for each insn.  At
the end of the sequence we copy from the last set into the final 
destination.

This has various trivial impacts on the code generation, but the resulting 
code
looks no better or worse to me across spec2017.

This has been tested in my tester and is currently bootstrapping on my BPI.
Waiting on data from the pre-commit tester before moving forward...

gcc/
* config/riscv/riscv.cc (synthesize_ior_xor): Avoid writing
operands[0] more than once, use new pseudos instead.

Diff:
---
 gcc/config/riscv/riscv.cc | 52 ---
 1 file changed, 36 insertions(+), 16 deletions(-)

diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc
index b2794252291e..8d84bee46882 100644
--- a/gcc/config/riscv/riscv.cc
+++ b/gcc/config/riscv/riscv.cc
@@ -14267,17 +14267,21 @@ synthesize_ior_xor (rtx_code code, rtx operands[3])
 {
   /* Pre-flipping bits we want to preserve.  */
   rtx input = operands[1];
+  rtx output = NULL_RTX;
   ival = ~INTVAL (operands[2]);
   while (ival)
{
  HOST_WIDE_INT tmpval = HOST_WIDE_INT_UC (1) << ctz_hwi (ival);
  rtx x = GEN_INT (tmpval);
  x = gen_rtx_XOR (word_mode, input, x);
- emit_insn (gen_rtx_SET (operands[0], x));
- input = operands[0];
+ output = gen_reg_rtx (word_mode);
+ emit_insn (gen_rtx_SET (output, x));
+ input = output;
  ival &= ~tmpval;
}
 
+  gcc_assert (output);
+
   /* Now flip all the bits, which restores the bits we were
 preserving.  */
   rtx x = gen_rtx_NOT (word_mode, input);
@@ -14300,23 +14304,29 @@ synthesize_ior_xor (rtx_code code, rtx operands[3])
   int msb = BITS_PER_WORD - 1 - clz_hwi (ival);
   if (msb - lsb + 1 <= 11)
{
+ rtx output = gen_reg_rtx (word_mode);
+ rtx input = operands[1];
+
  /* Rotate the source right by LSB bits.  */
  rtx x = GEN_INT (lsb);
- x = gen_rtx_ROTATERT (word_mode, operands[1], x);
- emit_insn (gen_rtx_SET (operands[0], x));
+ x = gen_rtx_ROTATERT (word_mode, input, x);
+ emit_insn (gen_rtx_SET (output, x));
+ input = output;
 
  /* Shift the constant right by LSB bits.  */
  x = GEN_INT (ival >> lsb);
 
  /* Perform the IOR/XOR operation.  */
- x = gen_rtx_fmt_ee (code, word_mode, operands[0], x);
- emit_insn (gen_rtx_SET (operands[0], x));
+ x = gen_rtx_fmt_ee (code, word_mode, input, x);
+ output = gen_reg_rtx (word_mode);
+ emit_insn (gen_rtx_SET (output, x));
+ input = output;
 
  /* And rotate left to put everything back in place, we don't
 have rotate left by a constant, so use rotate right by
 an adjusted 

[gcc r16-712] [RISC-V] Fix ICE due to bogus use of gen_rtvec

2025-05-17 Thread Jeff Law via Gcc-cvs
https://gcc.gnu.org/g:7ed37d5ea48f6a51c81f73f35a64ca00c0325fd7

commit r16-712-g7ed37d5ea48f6a51c81f73f35a64ca00c0325fd7
Author: Jeff Law 
Date:   Sat May 17 09:37:01 2025 -0600

[RISC-V] Fix ICE due to bogus use of gen_rtvec

Found this while setting up the risc-v coordination branch off of gcc-15.  
Not
sure why I didn't use rtvec_alloc directly here since we're going to 
initialize
the whole vector ourselves.  Using gen_rtvec was just wrong as it's walking
down a non-existent varargs list.  Under the "right" circumstances it can 
walk
off a page and fault.

This was seen with a test already in the testsuite (I forget which test), 
so no
new regression test.

Tested in my tester and verified the failure on the coordination branch is
resolved a well.  Waiting on pre-commit CI to render a verdict.

gcc/
* config/riscv/riscv-vect-permconst.cc 
(vector_permconst:process_bb):
Use rtvec_alloc, not gen_rtvec since we don't want/need to 
initialize
the vector.

Diff:
---
 gcc/config/riscv/riscv-vect-permconst.cc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/config/riscv/riscv-vect-permconst.cc 
b/gcc/config/riscv/riscv-vect-permconst.cc
index 8e13cf8d5587..087f26aea8ae 100644
--- a/gcc/config/riscv/riscv-vect-permconst.cc
+++ b/gcc/config/riscv/riscv-vect-permconst.cc
@@ -227,7 +227,7 @@ vector_permconst::process_bb (basic_block bb)
 normalize it to zero.
 
 XXX This violates structure sharing conventions.  */
-  rtvec_def *nvec = gen_rtvec (CONST_VECTOR_NUNITS (cvec).to_constant ());
+  rtvec_def *nvec = rtvec_alloc (CONST_VECTOR_NUNITS (cvec).to_constant 
());
 
   for (i = 0; i < CONST_VECTOR_NUNITS (cvec).to_constant (); i++)
nvec->elem[i] = GEN_INT (INTVAL (CONST_VECTOR_ELT (cvec, i)) - bias);


[gcc r15-9695] Fortran: Fix ICE with use of c_associated.

2025-05-17 Thread Jerry DeLisle via Gcc-cvs
https://gcc.gnu.org/g:dc21caefbc2d63be1315ca062e977affa74eacc2

commit r15-9695-gdc21caefbc2d63be1315ca062e977affa74eacc2
Author: Jerry DeLisle 
Date:   Mon May 5 20:05:22 2025 -0700

Fortran: Fix ICE with use of c_associated.

PR fortran/120049

gcc/fortran/ChangeLog:

* check.cc (gfc_check_c_associated): Modify checks to avoid
ICE and allow use, intrinsic :: iso_c_binding from a separate
module file.

gcc/testsuite/ChangeLog:

* gfortran.dg/pr120049_a.f90: New test.
* gfortran.dg/pr120049_b.f90: New test.

(cherry picked from commit d0571638a6bad932b226ada98b167fa47a47d838)

Diff:
---
 gcc/fortran/check.cc | 42 
 gcc/testsuite/gfortran.dg/pr120049_a.f90 | 15 
 gcc/testsuite/gfortran.dg/pr120049_b.f90 |  8 ++
 3 files changed, 49 insertions(+), 16 deletions(-)

diff --git a/gcc/fortran/check.cc b/gcc/fortran/check.cc
index 9c66c25e0596..0073cd0b7802 100644
--- a/gcc/fortran/check.cc
+++ b/gcc/fortran/check.cc
@@ -5919,30 +5919,40 @@ gfc_check_c_sizeof (gfc_expr *arg)
 bool
 gfc_check_c_associated (gfc_expr *c_ptr_1, gfc_expr *c_ptr_2)
 {
-  if (c_ptr_1->ts.type != BT_DERIVED
-  || c_ptr_1->ts.u.derived->from_intmod != INTMOD_ISO_C_BINDING
-  || (c_ptr_1->ts.u.derived->intmod_sym_id != ISOCBINDING_PTR
- && c_ptr_1->ts.u.derived->intmod_sym_id != ISOCBINDING_FUNPTR))
+  if (c_ptr_1)
 {
-  gfc_error ("Argument C_PTR_1 at %L to C_ASSOCIATED shall have the "
-"type TYPE(C_PTR) or TYPE(C_FUNPTR)", &c_ptr_1->where);
-  return false;
+  if (c_ptr_1->expr_type == EXPR_FUNCTION && c_ptr_1->ts.type == BT_VOID)
+   return true;
+
+  if (c_ptr_1->ts.type != BT_DERIVED
+ || c_ptr_1->ts.u.derived->from_intmod != INTMOD_ISO_C_BINDING
+ || (c_ptr_1->ts.u.derived->intmod_sym_id != ISOCBINDING_PTR
+ && c_ptr_1->ts.u.derived->intmod_sym_id != ISOCBINDING_FUNPTR))
+   {
+ gfc_error ("Argument C_PTR_1 at %L to C_ASSOCIATED shall have the "
+"type TYPE(C_PTR) or TYPE(C_FUNPTR)", &c_ptr_1->where);
+ return false;
+   }
 }
 
   if (!scalar_check (c_ptr_1, 0))
 return false;
 
-  if (c_ptr_2
-  && (c_ptr_2->ts.type != BT_DERIVED
+  if (c_ptr_2)
+{
+  if (c_ptr_2->expr_type == EXPR_FUNCTION && c_ptr_2->ts.type == BT_VOID)
+   return true;
+
+  if (c_ptr_2->ts.type != BT_DERIVED
  || c_ptr_2->ts.u.derived->from_intmod != INTMOD_ISO_C_BINDING
  || (c_ptr_1->ts.u.derived->intmod_sym_id
- != c_ptr_2->ts.u.derived->intmod_sym_id)))
-{
-  gfc_error ("Argument C_PTR_2 at %L to C_ASSOCIATED shall have the "
-"same type as C_PTR_1: %s instead of %s", &c_ptr_1->where,
-gfc_typename (&c_ptr_1->ts),
-gfc_typename (&c_ptr_2->ts));
-  return false;
+ != c_ptr_2->ts.u.derived->intmod_sym_id))
+   {
+ gfc_error ("Argument C_PTR_2 at %L to C_ASSOCIATED shall have the "
+  "same type as C_PTR_1: %s instead of %s", &c_ptr_1->where,
+  gfc_typename (&c_ptr_1->ts), gfc_typename (&c_ptr_2->ts));
+ return false;
+   }
 }
 
   if (c_ptr_2 && !scalar_check (c_ptr_2, 1))
diff --git a/gcc/testsuite/gfortran.dg/pr120049_a.f90 
b/gcc/testsuite/gfortran.dg/pr120049_a.f90
new file mode 100644
index ..c404a4dedd9a
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr120049_a.f90
@@ -0,0 +1,15 @@
+! { dg-do preprocess }
+! { dg-additional-options "-cpp" }
+!
+! Test the fix for PR86248
+program tests_gtk_sup
+  use gtk_sup
+  implicit none
+  type(c_ptr), target :: val
+  if (c_associated(val, c_loc(val))) then
+stop 1
+  endif
+  if (c_associated(c_loc(val), val)) then
+stop 2
+  endif
+end program tests_gtk_sup
diff --git a/gcc/testsuite/gfortran.dg/pr120049_b.f90 
b/gcc/testsuite/gfortran.dg/pr120049_b.f90
new file mode 100644
index ..127db984077d
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr120049_b.f90
@@ -0,0 +1,8 @@
+! { dg-do  run }
+! { dg-additional-sources pr120049_a.f90 }
+!
+! Module for pr120049.f90
+!
+module gtk_sup
+  use, intrinsic :: iso_c_binding
+end module gtk_sup