[gcc r16-3534] fold: Unwrap MEM_REF after get_inner_reference in split_address_to_core_and_offset [PR121355]

2025-09-03 Thread Andrew Pinski via Gcc-cvs
https://gcc.gnu.org/g:9f94029829daf3b83bb95226dcfe003c5ddcade2

commit r16-3534-g9f94029829daf3b83bb95226dcfe003c5ddcade2
Author: Andrew Pinski 
Date:   Sat Aug 30 15:16:20 2025 -0700

fold: Unwrap MEM_REF after get_inner_reference in 
split_address_to_core_and_offset  [PR121355]

Inside split_address_to_core_and_offset, this calls get_inner_reference.

Take:
```
  _6 = t_3(D) + 12;
  _8 = &MEM[(struct s1 *)t_3(D) + 4B].t;
  _1 = _6 - _8;
```

On the assignement of _8, get_inner_reference will return `MEM[(struct s1 
*)t_3(D) + 4B]`
and an offset but that does not match up with `t_3(D)` which is how 
split_address_to_core_and_offset
handles pointer plus.
So this patch adds the unwrapping of the MEM_REF after the call to 
get_inner_reference
and have it act like a pointer plus.

Changes since v1:
* v2: Remove check on operand 1 for poly_int_tree_p, it is always.
  Add before the check to see if it fits in shwi instead of after.

Bootstrapped and tested on x86_64-linux-gnu.

PR tree-optimization/121355

gcc/ChangeLog:

* fold-const.cc (split_address_to_core_and_offset): Handle an 
MEM_REF after the call
to get_inner_reference.

gcc/testsuite/ChangeLog:

* gcc.dg/tree-ssa/ptrdiff-1.c: New test.

Signed-off-by: Andrew Pinski 

Diff:
---
 gcc/fold-const.cc | 11 
 gcc/testsuite/gcc.dg/tree-ssa/ptrdiff-1.c | 45 +++
 2 files changed, 56 insertions(+)

diff --git a/gcc/fold-const.cc b/gcc/fold-const.cc
index 8867540243b8..fe7a5fee5e25 100644
--- a/gcc/fold-const.cc
+++ b/gcc/fold-const.cc
@@ -16514,6 +16514,17 @@ split_address_to_core_and_offset (tree exp,
   core = get_inner_reference (TREE_OPERAND (exp, 0), &bitsize, pbitpos,
  poffset, &mode, &unsignedp, &reversep,
  &volatilep);
+  /* If we are left with MEM[a + CST] strip that and add it to the
+pbitpos and return a. */
+  if (TREE_CODE (core) == MEM_REF)
+   {
+ poly_offset_int tem;
+ tem = wi::to_poly_offset (TREE_OPERAND (core, 1));
+ tem <<= LOG2_BITS_PER_UNIT;
+ tem += *pbitpos;
+ if (tem.to_shwi (pbitpos))
+   return TREE_OPERAND (core, 0);
+   }
   core = build_fold_addr_expr_loc (loc, core);
 }
   else if (TREE_CODE (exp) == POINTER_PLUS_EXPR)
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ptrdiff-1.c 
b/gcc/testsuite/gcc.dg/tree-ssa/ptrdiff-1.c
new file mode 100644
index ..af9291c6608c
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/ptrdiff-1.c
@@ -0,0 +1,45 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+
+/* PR tree-optimization/121355 */
+
+#define array_size 2
+struct s1
+{
+  int t[array_size];
+};
+
+struct s2
+{
+  int p;
+  struct s1 t;
+};
+static inline int *b(struct s1 *t)
+{
+  return t->t;
+}
+static inline int *e(struct s1 *t)
+{
+  return b(t) + array_size;
+}
+void g(struct s2 *t)
+{
+  struct s1 *t2 = &t->t;
+  int *te = e(t2);
+  int *ts = b(t2);
+  int tt = te - ts;
+/*
+  _6 = t_3(D) + 12;
+  _8 = &MEM[(struct s1 *)t_3(D) + 4B].t;
+  _1 = _6 - _8;
+
+  _1 should be optimized to 2*sizeof(int) == 8.
+ */
+
+  if (tt != array_size)
+__builtin_abort();
+}
+
+/* the call to abort should be removed. */
+
+/* { dg-final { scan-tree-dump-not "abort " "optimized" } } */


[gcc r16-3529] Fortran: Allow PDT parameterized procedure pointer components [PR89707]

2025-09-03 Thread Paul Thomas via Gcc-cvs
https://gcc.gnu.org/g:f7dee170ba6d37aba6a9e1fa73711e4e03e42990

commit r16-3529-gf7dee170ba6d37aba6a9e1fa73711e4e03e42990
Author: Paul Thomas 
Date:   Tue Sep 2 21:51:33 2025 +0100

Fortran: Allow PDT parameterized procedure pointer components [PR89707]

2025-09-02  Paul Thomas  

gcc/fortran
PR fortran/89707
* decl.cc (gfc_get_pdt_instance): Copy the typebound procedure
field from the PDT template. If the template interface has
kind=0, provide the new instance with an interface with a type
spec that points to that of the parameterized component.
(match_ppc_decl): When 'saved_kind_expr' this is a PDT and the
expression should be copied to the component kind_expr.
* gfortran.h: Define gfc_get_tbp.

gcc/testsuite/
PR fortran/89707
* gfortran.dg/pdt_43.f03: New test.

Diff:
---
 gcc/fortran/decl.cc  | 19 +++
 gcc/fortran/gfortran.h   |  1 +
 gcc/testsuite/gfortran.dg/pdt_43.f03 | 28 
 3 files changed, 48 insertions(+)

diff --git a/gcc/fortran/decl.cc b/gcc/fortran/decl.cc
index 1e91b57aa96d..fcbbc2f8c6e2 100644
--- a/gcc/fortran/decl.cc
+++ b/gcc/fortran/decl.cc
@@ -4076,6 +4076,11 @@ gfc_get_pdt_instance (gfc_actual_arglist *param_list, 
gfc_symbol **sym,
 
   c2->ts = c1->ts;
   c2->attr = c1->attr;
+  if (c1->tb)
+   {
+ c2->tb = gfc_get_tbp ();
+ c2->tb = c1->tb;
+   }
 
   /* The order of declaration of the type_specs might not be the
 same as that of the components.  */
@@ -4163,6 +4168,17 @@ gfc_get_pdt_instance (gfc_actual_arglist *param_list, 
gfc_symbol **sym,
 c2->ts.kind, gfc_basic_typename (c2->ts.type));
  goto error_return;
}
+ if (c2->attr.proc_pointer && c2->attr.function
+ && c1->ts.interface && c1->ts.interface->ts.kind == 0)
+   {
+ c2->ts.interface = gfc_new_symbol ("", gfc_current_ns);
+ c2->ts.interface->result = c2->ts.interface;
+ c2->ts.interface->ts = c2->ts;
+ c2->ts.interface->attr.flavor = FL_PROCEDURE;
+ c2->ts.interface->attr.function = 1;
+ c2->attr.function = 1;
+ c2->attr.if_source = IFSRC_UNKNOWN;
+   }
}
 
   /* Similarly, set the string length if parameterized.  */
@@ -7573,6 +7589,9 @@ match_ppc_decl (void)
  *c->tb = *tb;
}
 
+  if (saved_kind_expr)
+   c->kind_expr = gfc_copy_expr (saved_kind_expr);
+
   /* Set interface.  */
   if (proc_if != NULL)
{
diff --git a/gcc/fortran/gfortran.h b/gcc/fortran/gfortran.h
index 2644cd822108..482031d26005 100644
--- a/gcc/fortran/gfortran.h
+++ b/gcc/fortran/gfortran.h
@@ -1916,6 +1916,7 @@ typedef struct gfc_typebound_proc
 }
 gfc_typebound_proc;
 
+#define gfc_get_tbp() XCNEW (gfc_typebound_proc)
 
 /* Symbol nodes.  These are important things.  They are what the
standard refers to as "entities".  The possibly multiple names that
diff --git a/gcc/testsuite/gfortran.dg/pdt_43.f03 
b/gcc/testsuite/gfortran.dg/pdt_43.f03
new file mode 100644
index ..c9f25021ab90
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pdt_43.f03
@@ -0,0 +1,28 @@
+! { dg-do run )
+!
+! Test the fix for PR89707 in which the procedure pointer component
+! with a parameterized KIND expression caused an ICE in resolution.
+!
+! Contributed by Janus Weil  
+!
+program pdt_with_ppc
+  integer, parameter :: kt = kind (0d0)
+  type :: q(k)
+ integer, kind :: k = 4
+ procedure (real(kind=kt)), pointer, nopass :: p
+  end type
+  type (q(kt)) :: x
+  x%p => foo
+  if (int (x%p(2d0)) /= 4) stop 1
+  x%p => bar
+  if (int (x%p(2d0, 4d0)) /= 16) stop 2
+contains
+  real(kind=kt) function foo (x)
+real(kind = kt) :: x
+foo = 2.0 * x
+  end
+  real(kind=kt) function bar (x, y)
+real(kind = kt) :: x, y
+bar = x ** y
+  end
+end


[gcc r16-3522] s390: Adjust s390/spaceship-fp-*.c tests for recent changes

2025-09-03 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:a41d8edf304e896cb541a0ec7daafb02b8d442c7

commit r16-3522-ga41d8edf304e896cb541a0ec7daafb02b8d442c7
Author: Jakub Jelinek 
Date:   Tue Sep 2 17:01:30 2025 +0200

s390: Adjust s390/spaceship-fp-*.c tests for recent changes

In r16-3414 libstdc++ changed ABI for (still experimental C++20) and uses
unordered value -128 instead of 2.  Generally the change improved code
generation on all targets tested, see
https://gcc.gnu.org/pipermail/gcc-patches/2025-August/693534.html
for details.
In r16-3474 I've adjusted the middle-end and backends to use that value.
This apparently broke the gcc.target/s390/spaceship-fp-2.c test,
with -ffast-math the 2 value is unreachable and so the .SPACESHIP last
argument in that case is the default, which changed from 2 to -128.
But spaceship-fp-1.c test also doesn't test what libstdc++ uses anymore,
so the following patch uses -128 in all the spots.

2025-09-02  Jakub Jelinek  

* gcc.target/s390/spaceship-fp-1.c: Expect .SPACESHIP call with
-128 as last argument instead of 2.
(TEST): Use -128 instead of 2.
* gcc.target/s390/spaceship-fp-2.c: Expect .SPACESHIP call with
-128 as last argument instead of 2.
(TEST): Use -128 instead of 2.

Diff:
---
 gcc/testsuite/gcc.target/s390/spaceship-fp-1.c | 4 ++--
 gcc/testsuite/gcc.target/s390/spaceship-fp-2.c | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/gcc/testsuite/gcc.target/s390/spaceship-fp-1.c 
b/gcc/testsuite/gcc.target/s390/spaceship-fp-1.c
index 56c3d77de3ce..34b9ba66d7b0 100644
--- a/gcc/testsuite/gcc.target/s390/spaceship-fp-1.c
+++ b/gcc/testsuite/gcc.target/s390/spaceship-fp-1.c
@@ -1,6 +1,6 @@
 /* { dg-do compile { target lp64 } } */
 /* { dg-options "-O2 -mzarch -march=z13 -fdump-tree-optimized" } */
-/* { dg-final { scan-tree-dump-times {\.SPACESHIP \([^,]+, [^,]+, 2\)} 3 
optimized } } */
+/* { dg-final { scan-tree-dump-times {\.SPACESHIP \([^,]+, [^,]+, -128\)} 3 
optimized } } */
 /* { dg-final { scan-assembler-times {\tk[edx]br\t} 3 } } */
 /* { dg-final { scan-assembler-not {\tbrc} } } */
 /* { dg-final { scan-assembler-not {\tc[edx]br\t} } } */
@@ -15,7 +15,7 @@
 else if (x > y)\
   return 1;\
 else   \
-  return 2;\
+  return -128; \
   }
 
 TEST (float, float)
diff --git a/gcc/testsuite/gcc.target/s390/spaceship-fp-2.c 
b/gcc/testsuite/gcc.target/s390/spaceship-fp-2.c
index 0c6e6b6aeb4f..6fe4d22b2783 100644
--- a/gcc/testsuite/gcc.target/s390/spaceship-fp-2.c
+++ b/gcc/testsuite/gcc.target/s390/spaceship-fp-2.c
@@ -1,6 +1,6 @@
 /* { dg-do compile { target lp64 } } */
 /* { dg-options "-O2 -mzarch -march=z13 -ffinite-math-only 
-fdump-tree-optimized" } */
-/* { dg-final { scan-tree-dump-times {\.SPACESHIP \([^,]+, [^,]+, 2\)} 3 
optimized } } */
+/* { dg-final { scan-tree-dump-times {\.SPACESHIP \([^,]+, [^,]+, -128\)} 3 
optimized } } */
 /* { dg-final { scan-assembler-times {\tc[edx]br\t} 3 } } */
 /* { dg-final { scan-assembler-not {\tbrc} } } */
 /* { dg-final { scan-assembler-not {\tk[edx]br\t} } } */
@@ -15,7 +15,7 @@
 else if (x > y)\
   return 1;\
 else   \
-  return 2;\
+  return -128; \
   }
 
 TEST (float, float)


[gcc r16-3506] Testsuite: Don't test vector-compare-1.C on strict alignment targets

2025-09-03 Thread Andrew Pinski via Gcc-cvs
https://gcc.gnu.org/g:db195c5381ceb2570f8a1798fd82996f7ba8f82e

commit r16-3506-gdb195c5381ceb2570f8a1798fd82996f7ba8f82e
Author: Andrew Pinski 
Date:   Mon Sep 1 17:18:06 2025 -0700

Testsuite: Don't test vector-compare-1.C on strict alignment targets

This testcase will fail on strict alignment targets due to
the requirement of doing a possible unaligned load. This fixes
that.

Note this testcase still fails on arm (and maybe riscv) targets while
having unaligned loads, they have slow ones.

Pushed as obvious after testing on x86_64-linux-gnu to make sure it
is still testing.

gcc/testsuite/ChangeLog:

* g++.dg/tree-ssa/vector-compare-1.C: Restrict to
non_strict_align targets.

Signed-off-by: Andrew Pinski 

Diff:
---
 gcc/testsuite/g++.dg/tree-ssa/vector-compare-1.C | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/testsuite/g++.dg/tree-ssa/vector-compare-1.C 
b/gcc/testsuite/g++.dg/tree-ssa/vector-compare-1.C
index d9b2bc2533ed..e3f5421aba43 100644
--- a/gcc/testsuite/g++.dg/tree-ssa/vector-compare-1.C
+++ b/gcc/testsuite/g++.dg/tree-ssa/vector-compare-1.C
@@ -1,4 +1,4 @@
-// { dg-do compile { target c++11 } }
+// { dg-do compile { target { c++11 && non_strict_align } } }
 // { dg-options "-O2 -fdump-tree-optimized" }
 
 // PR tree-optimization/116651


[gcc r16-3521] c++, contracts: Simplify contracts headers [NFC].

2025-09-03 Thread Iain D Sandoe via Gcc-cvs
https://gcc.gnu.org/g:ff9e44ee3189d24127bc754a8563be4615239730

commit r16-3521-gff9e44ee3189d24127bc754a8563be4615239730
Author: Iain Sandoe 
Date:   Sat Aug 30 12:14:58 2025 +0100

c++, contracts: Simplify contracts headers [NFC].

We have contracts-related declarations and macros split between contracts.h
and cp-tree.h, and then contracts.h is included in the latter, which means
that it is included in all c++ front end files.

This patch:
 - moves all the contracts-related material to contracts.h.
 - makes some functions that are only used in contracts.cc static.
 - tries to group the external API for contracts into related topics.
 - includes contracts.h in the front end sources that need it.

gcc/cp/ChangeLog:

* constexpr.cc: Include contracts.h
* coroutines.cc: Likewise.
* cp-gimplify.cc: Likewise.
* decl.cc: Likewise.
* decl2.cc: Likewise.
* mangle.cc: Likewise.
* module.cc: Likewise.
* pt.cc: Likewise.
* search.cc: Likewise.
* semantics.cc: Likewise.
* contracts.cc (validate_contract_role, setup_default_contract_role,
add_contract_role, get_concrete_axiom_semantic,
get_default_contract_role): Make static.
* cp-tree.h (make_postcondition_variable, grok_contract,
finish_contract_condition, find_contract, set_decl_contracts,
get_contract_semantic, set_contract_semantic): Move to contracts.h.
* contracts.h (get_contract_role, add_contract_role,
validate_contract_role, setup_default_contract_role,
lookup_concrete_semantic, get_default_contract_role): Remove.

Signed-off-by: Iain Sandoe 

Diff:
---
 gcc/cp/constexpr.cc   |  1 +
 gcc/cp/contracts.cc   | 22 
 gcc/cp/contracts.h| 98 ++-
 gcc/cp/coroutines.cc  |  1 +
 gcc/cp/cp-gimplify.cc |  1 +
 gcc/cp/cp-tree.h  | 45 ---
 gcc/cp/decl.cc|  1 +
 gcc/cp/decl2.cc   |  1 +
 gcc/cp/mangle.cc  |  1 +
 gcc/cp/module.cc  |  1 +
 gcc/cp/pt.cc  |  1 +
 gcc/cp/search.cc  |  1 +
 gcc/cp/semantics.cc   |  1 +
 13 files changed, 91 insertions(+), 84 deletions(-)

diff --git a/gcc/cp/constexpr.cc b/gcc/cp/constexpr.cc
index 701420ca8ec0..c3d05248a9a7 100644
--- a/gcc/cp/constexpr.cc
+++ b/gcc/cp/constexpr.cc
@@ -41,6 +41,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "fold-const.h"
 #include "intl.h"
 #include "toplev.h"
+#include "contracts.h"
 
 static bool verify_constant (tree, bool, bool *, bool *);
 #define VERIFY_CONSTANT(X) \
diff --git a/gcc/cp/contracts.cc b/gcc/cp/contracts.cc
index d0cfd2efd552..042524dca382 100644
--- a/gcc/cp/contracts.cc
+++ b/gcc/cp/contracts.cc
@@ -159,7 +159,7 @@ bool valid_configs[CCS_MAYBE + 1][CCS_MAYBE + 1] = {
   { 0, 1, 0, 0, 1, },
 };
 
-void
+static void
 validate_contract_role (contract_role *role)
 {
   gcc_assert (role);
@@ -171,7 +171,7 @@ validate_contract_role (contract_role *role)
"the % semantic");
 }
 
-contract_semantic
+static contract_semantic
 lookup_concrete_semantic (const char *name)
 {
   if (strcmp (name, "ignore") == 0)
@@ -210,7 +210,9 @@ role_name_equal (contract_role *role, const char *name)
   return role_name_equal (role->name, name);
 }
 
-contract_role *
+static void setup_default_contract_role (bool update = true);
+
+static contract_role *
 get_contract_role (const char *name)
 {
   for (int i = 0; i < max_custom_roles; ++i)
@@ -227,12 +229,12 @@ get_contract_role (const char *name)
   return NULL;
 }
 
-contract_role *
+static contract_role *
 add_contract_role (const char *name,
   contract_semantic des,
   contract_semantic aus,
   contract_semantic axs,
-  bool update)
+  bool update = true)
 {
   for (int i = 0; i < max_custom_roles; ++i)
 {
@@ -271,7 +273,7 @@ get_concrete_axiom_semantic ()
   return flag_contract_assumption_mode ? CCS_ASSUME : CCS_IGNORE;
 }
 
-void
+static void
 setup_default_contract_role (bool update)
 {
   contract_semantic check = get_concrete_check ();
@@ -491,6 +493,14 @@ handle_OPT_fcontract_semantic_ (const char *arg)
   validate_contract_role (role);
 }
 
+/* Returns the default role.  */
+
+static contract_role *
+get_default_contract_role ()
+{
+  return get_contract_role ("default");
+}
+
 /* Convert a contract CONFIG into a contract_mode.  */
 
 static contract_mode
diff --git a/gcc/cp/contracts.h b/gcc/cp/contracts.h
index 7d955f7881d6..ead07d19fb7b 100644
--- a/gcc/cp/contracts.h
+++ b/gcc/cp/contracts.h
@@ -131,38 +131,20 @@ struct contract_mode
   } u;
 };
 
-extern contract_role *get_contract_role(const char *);
-extern contract_role *add_contract_role(const char *,
-   

[gcc/devel/gfortran-test] (966 commits) Merge branch 'master' into gfortran-test

2025-09-03 Thread Jerry DeLisle via Gcc-cvs
The branch 'devel/gfortran-test' was updated to point to:

 071b4126c613... Merge branch 'master' into gfortran-test

It previously pointed to:

 cb4b73da2371... Fortran: Andre's tweak

Diff:

Summary of changes (added commits):
---

  071b412... Merge branch 'master' into gfortran-test
  845d23f... Revert "Fortran: Recommit changes for coarray after merging
  3cb2c2f... Revert "Fortran: Andre's tweak"
  caa1c2f... strlen: Fixup load alignment for memcmp (*)
  a6e0a61... forwprop: Fix alignment of types in expansion of memcmp (*)
  f7dee17... Fortran: Allow PDT parameterized procedure pointer componen (*)
  2d93be8... Fortran: Handle PDTs correctly with unlimited selector [PR8 (*)
  4ce7722... arm: testsuite: improve test compatibility of asm-hard-reg- (*)
  edeb5b8... tree-optimization/121753 - ICE with pattern breaking reduct (*)
  9bbf099... RISC-V: Fix is_vlmax_len_p and use for strided ops. (*)
  f957d35... RISC-V: Handle overlap in expand_vec_perm PR121742. (*)
  6e0590b... docs: Add NoOffload option flag to the internals manual (*)
  a41d8ed... s390: Adjust s390/spaceship-fp-*.c tests for recent changes (*)
  ff9e44e... c++, contracts: Simplify contracts headers [NFC]. (*)
  2552c73... D, Darwin, Powerpc: Fix build error. (*)
  b839cac... RISC-V: Add Zbb extension sext testcase. (*)
  0ffe59c... RISC-V: Update Zba 'shNadd.uw' testcase.` (*)
  dea668d... libstdc++: Move _Index_tuple, _Build_index_tuple to  features [PR119670] (*)
  00e8690... c++: > in lambda in template arg [PR107953] (*)
  6750f59... passes: Move cleanup_eh before first tailr [PR115201] (*)
  0545b65... MAINTAINERS: add myself to write after approval (*)
  31a180d... RISC-V: Add pattern for vector-scalar floating-point min (*)
  48ef4af... Dump niter assumption versioning when vectorizing (*)
  8187d26... AArch64: Add isinf expander [PR 66462] (*)
  f4b9699... libstdc++: Test comparing ordering with type convertible to (*)
  2649c79... Compute reduction var in vectorize_fold_left_reduction (*)
  33cb72f... libstdc++: Remove implicit type conversions in std::complex (*)
  bbc0e70... libstdc++: Constrain bitset(const CharT*) constructor [PR12 (*)
  fcb5cd8... libstdc++: Provide helpers to interoperate between __cmp_ca (*)
  10418a6... c++/modules: Add explanatory note for incomplete types with (*)
  69faef0... PR modula2/121629: adding third party modules (*)
  098cf06... [gcn] gcc/configure.ac + install.texi - changes to detect H (*)
  cddae3e... c++: Fix auto return type deduction with expansion statemen (*)
  cc85998... c++: Fix ICE with parameter uses in expansion stmts [PR1215 (*)
  fa03e49... Avoid mult pattern if that will break reduction constraints (*)
  674b1d7... The divmod pattern will break reduction constraints (*)
  866697b... configure: Add readelf fallback for HAVE_AS_ULEB128 test [P (*)
  b7f5a73... dwarf2out: Use DW_LNS_advance_pc instead of DW_LNS_fixed_ad (*)
  fbaaefa... Fortran: Constructors with PDT components did not work [PR8 (*)
  68700ca... Fortran: Implement correct form of PDT constructors [PR8220 (*)
  6aa1cbb... Daily bump. (*)
  58a8ecc... Remove xfail marker on RISC-V test (*)
  3fb7bed... Fortran: H edit descriptor error with -std=f95 (*)
  a78f34b... ifcvt: fix factor_out_operators (again) [PR121695] (*)
  6fd3f8c... RISC-V: testsuite: Fix vf_vfmul and vf_vfrdiv (*)
  b3038e1... libstdc++: Use _M_reverse to reverse partial_ordering using (*)
  806de30... libstdc++: Move tai_- and gps_clock::now impls out of ABI (*)
  5de587c... Remove dead code (*)
  fcb3009... libsupc++: Change _Unordered comparison value to minimum va (*)
  f707c09... c++: Fix up cpp_warn on __STDCPP_FLOAT*_T__ [PR121520] (*)
  2027574... tree-optimization/121686 - failed SLP discovery for live re (*)
  18d4496... testsuite; Fix unprotected-allocas-1.c at -O3 [PR121684] (*)
  45ea1c5... libstdc++: Reduce chances of object aliasing for function w (*)
  a950998... x86-64: Emit the TLS call after debug marker (*)
  775ecdb... Move pr121656.c to gcc.dg/torture (*)
  edcbec0... More RISC-V testsuite hygiene (*)
  29787cf... Daily bump. (*)
  a43c30c... OpenMP: give error when variant is the same as the base fun (*)
  445ce98... OpenMP: Improve front-end error-checking for "declare varia (*)
  06d5889... [committed] RISC-V Testsuite hygiene (*)
  06e627e... libstdc++/ranges: Prefer using offset-based _CachedPosition (*)
  de04eb4... testsuite: restrict ctf-array-7 test to 64-bit targets [PR1 (*)
  4b4ee2f... testsuite: arm: Disable sched2 and sched3 in unsigned-exten (*)
  390f3a6... libstdc++: Do not require assignment for vector::resize(n,  (*)
  250dd5b... libstdc++: Refactor bound arguments storage for bind_front/ (*)
  36ab9b9... libstdc++: Specialize _Never_valueless_alt for jthread, sto (*)
  9823624... Enable unroll in the vectorizer when there's reduction for  (*)
  7c2ab58... [PATCH] RISC-V: Add pattern for reverse floating-point divi (*)
  28ab833... AArch64: extend cost model to cost outer lo

[gcc r16-3495] PR target/89828 Inernal compiler error on "-fno-omit-frame-pointer"

2025-09-03 Thread Jeff Law via Gcc-cvs
https://gcc.gnu.org/g:713299077407bd1472e14fa10a8d4565932da8da

commit r16-3495-g713299077407bd1472e14fa10a8d4565932da8da
Author: Yoshinori Sato 
Date:   Mon Sep 1 11:12:17 2025 -0600

PR target/89828 Inernal compiler error on "-fno-omit-frame-pointer"

The problem was caused by an erroneous note about creating a stack frame,
which caused the cur_cfa reg to fail to assert with a value other than
the frame pointer.

This fix will generate notes that correctly update cur_cfa.

v2 changes.
Add testcase.
All tests that failed with
"internal compiler error: in dwarf2out_frame_debug_adjust_cfa, at 
dwarf2cfi.cc"
now pass.

PR target/89828
gcc
* config/rx/rx.cc (add_pop_cfi_notes): Release the frame pointer if 
it is
used.
(rx_expand_prologue): Redesigned stack pointer and frame pointer 
update
process.

gcc/testsuite/
* gcc.dg/pr89828.c: New.

Diff:
---
 gcc/config/rx/rx.cc| 49 +++---
 gcc/testsuite/gcc.dg/pr89828.c | 49 ++
 2 files changed, 66 insertions(+), 32 deletions(-)

diff --git a/gcc/config/rx/rx.cc b/gcc/config/rx/rx.cc
index dd730dca3c01..c5638817d08c 100644
--- a/gcc/config/rx/rx.cc
+++ b/gcc/config/rx/rx.cc
@@ -1648,16 +1648,20 @@ mark_frame_related (rtx insn)
 static void
 add_pop_cfi_notes (rtx_insn *insn, unsigned int high, unsigned int low)
 {
-  rtx t = plus_constant (Pmode, stack_pointer_rtx,
-(high - low + 1) * UNITS_PER_WORD);
+  rtx src = stack_pointer_rtx;
+  rtx t;
+  for (unsigned int i = low; i <= high; i++)
+{
+  add_reg_note (insn, REG_CFA_RESTORE, gen_rtx_REG (word_mode, i));
+  if (i == FRAME_POINTER_REGNUM && frame_pointer_needed)
+   src = frame_pointer_rtx;
+}
+  t = plus_constant (Pmode, src, (high - low + 1) * UNITS_PER_WORD);
   t = gen_rtx_SET (stack_pointer_rtx, t);
   add_reg_note (insn, REG_CFA_ADJUST_CFA, t);
   RTX_FRAME_RELATED_P (insn) = 1;
-  for (unsigned int i = low; i <= high; i++)
-add_reg_note (insn, REG_CFA_RESTORE, gen_rtx_REG (word_mode, i));
 }
 
-
 static bool
 ok_for_max_constant (HOST_WIDE_INT val)
 {
@@ -1816,36 +1820,17 @@ rx_expand_prologue (void)
}
 }
 
-  /* If needed, set up the frame pointer.  */
-  if (frame_pointer_needed)
-gen_safe_add (frame_pointer_rtx, stack_pointer_rtx,
- GEN_INT (- (HOST_WIDE_INT) frame_size), true);
-
-  /* Allocate space for the outgoing args.
- If the stack frame has not already been set up then handle this as well.  
*/
-  if (stack_size)
+  if (stack_size || frame_size)
 {
-  if (frame_size)
-   {
- if (frame_pointer_needed)
-   gen_safe_add (stack_pointer_rtx, frame_pointer_rtx,
- GEN_INT (- (HOST_WIDE_INT) stack_size), true);
- else
-   gen_safe_add (stack_pointer_rtx, stack_pointer_rtx,
- GEN_INT (- (HOST_WIDE_INT) (frame_size + stack_size)),
- true);
-   }
-  else
-   gen_safe_add (stack_pointer_rtx, stack_pointer_rtx,
- GEN_INT (- (HOST_WIDE_INT) stack_size), true);
+  gen_safe_add (stack_pointer_rtx, stack_pointer_rtx,
+   GEN_INT (- (HOST_WIDE_INT) (stack_size + frame_size)),
+   true);
 }
-  else if (frame_size)
+  if (frame_pointer_needed)
 {
-  if (! frame_pointer_needed)
-   gen_safe_add (stack_pointer_rtx, stack_pointer_rtx,
- GEN_INT (- (HOST_WIDE_INT) frame_size), true);
-  else
-   gen_safe_add (stack_pointer_rtx, frame_pointer_rtx, NULL_RTX, true);
+  gen_safe_add (frame_pointer_rtx, stack_pointer_rtx,
+   GEN_INT ((HOST_WIDE_INT) stack_size),
+   true);
 }
 }
 
diff --git a/gcc/testsuite/gcc.dg/pr89828.c b/gcc/testsuite/gcc.dg/pr89828.c
new file mode 100644
index ..d41fbae4cfab
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr89828.c
@@ -0,0 +1,49 @@
+/* { dg-do compile { target rx-*-* } } */
+/* { dg-options "-O2 -g -fno-omit-frame-pointer" } */
+struct baz;
+struct foo {
+  struct baz *c;
+  unsigned int flags;
+};
+struct bar {
+  const struct bar *b;
+  void (*func)(struct foo *a, struct baz *c, int flags);
+};
+struct baz {
+  int flag;
+  const struct bar *b;
+};
+static inline
+__attribute__((always_inline))
+__attribute__((no_instrument_function)) void inline1(struct foo *a)
+{
+  a->flags |= 1;
+}
+static inline
+__attribute__((always_inline))
+__attribute__((no_instrument_function)) int inline2(struct baz *c)
+{
+  return c->flag == 1;
+}
+extern const struct bar _bar;
+extern void func(struct foo *a);
+void pr89828(struct foo *a, struct baz *c, int flags)
+{
+  const struct bar *b;
+
+  if (c->b == a->c->b) {
+a->c->b->func(a, c, flags);
+  } else {
+for (b = (&_bar); b; b = b->b) {
+  if (b == a->c->b)
+ 

[gcc r16-3512] Pass vectype to vect_check_gather_scatter

2025-09-03 Thread Richard Biener via Gcc-cvs
https://gcc.gnu.org/g:d5b1baa7f2251895447d99cd2f6a1eabb2c94601

commit r16-3512-gd5b1baa7f2251895447d99cd2f6a1eabb2c94601
Author: Richard Biener 
Date:   Mon Sep 1 15:01:24 2025 +0200

Pass vectype to vect_check_gather_scatter

The strided-store path needs to have the SLP trees vector type so
the following patch passes dowm the vector type to be used to
vect_check_gather_scatter and adjusts all other callers.  This
removes one of the last pieces requiring STMT_VINFO_VECTYPE
during SLP stmt analysis.

* tree-vectorizer.h (vect_check_gather_scatter): Add
vectype parameter.
* tree-vect-data-refs.cc (vect_check_gather_scatter): Get
vectype as parameter.
(vect_analyze_data_refs): Adjust.
* tree-vect-patterns.cc (vect_recog_gather_scatter_pattern): 
Likewise.
* tree-vect-slp.cc (vect_get_and_check_slp_defs): Get vectype
as parameter, pass down.
(vect_build_slp_tree_2): Adjust.
* tree-vect-stmts.cc (vect_mark_stmts_to_be_vectorized): Likewise.
(vect_use_strided_gather_scatters_p): Likewise.

Diff:
---
 gcc/tree-vect-data-refs.cc | 12 ++--
 gcc/tree-vect-patterns.cc  | 10 +-
 gcc/tree-vect-slp.cc   |  7 ---
 gcc/tree-vect-stmts.cc |  7 +--
 gcc/tree-vectorizer.h  |  4 ++--
 5 files changed, 22 insertions(+), 18 deletions(-)

diff --git a/gcc/tree-vect-data-refs.cc b/gcc/tree-vect-data-refs.cc
index f9bf6a216970..1395776599a2 100644
--- a/gcc/tree-vect-data-refs.cc
+++ b/gcc/tree-vect-data-refs.cc
@@ -4554,12 +4554,13 @@ vect_describe_gather_scatter_call (stmt_vec_info 
stmt_info,
 }
 
 /* Return true if a non-affine read or write in STMT_INFO is suitable for a
-   gather load or scatter store.  Describe the operation in *INFO if so.
-   If it is suitable and ELSVALS is nonzero store the supported else values
-   in the vector it points to.  */
+   gather load or scatter store with VECTYPE.  Describe the operation in *INFO
+   if so.  If it is suitable and ELSVALS is nonzero store the supported else
+   values in the vector it points to.  */
 
 bool
-vect_check_gather_scatter (stmt_vec_info stmt_info, loop_vec_info loop_vinfo,
+vect_check_gather_scatter (stmt_vec_info stmt_info, tree vectype,
+  loop_vec_info loop_vinfo,
   gather_scatter_info *info, vec *elsvals)
 {
   HOST_WIDE_INT scale = 1;
@@ -4568,7 +4569,6 @@ vect_check_gather_scatter (stmt_vec_info stmt_info, 
loop_vec_info loop_vinfo,
   struct data_reference *dr = STMT_VINFO_DATA_REF (stmt_info);
   tree offtype = NULL_TREE;
   tree decl = NULL_TREE, base, off;
-  tree vectype = STMT_VINFO_VECTYPE (stmt_info);
   tree memory_type = TREE_TYPE (DR_REF (dr));
   machine_mode pmode;
   int punsignedp, reversep, pvolatilep = 0;
@@ -5273,7 +5273,7 @@ vect_analyze_data_refs (vec_info *vinfo, bool *fatal)
   if (gatherscatter != SG_NONE)
{
  gather_scatter_info gs_info;
- if (!vect_check_gather_scatter (stmt_info,
+ if (!vect_check_gather_scatter (stmt_info, vectype,
  as_a  (vinfo),
  &gs_info)
  || !get_vectype_for_scalar_type (vinfo,
diff --git a/gcc/tree-vect-patterns.cc b/gcc/tree-vect-patterns.cc
index 16694d7991cd..64a49245 100644
--- a/gcc/tree-vect-patterns.cc
+++ b/gcc/tree-vect-patterns.cc
@@ -6032,16 +6032,17 @@ vect_recog_gather_scatter_pattern (vec_info *vinfo,
  This is null if the operation is unconditional.  */
   tree mask = vect_get_load_store_mask (stmt_info);
 
+  /* DR analysis nailed down the vector type for the access.  */
+  tree gs_vectype = STMT_VINFO_VECTYPE (stmt_info);
+
   /* Make sure that the target supports an appropriate internal
  function for the gather/scatter operation.  */
   gather_scatter_info gs_info;
-  if (!vect_check_gather_scatter (stmt_info, loop_vinfo, &gs_info)
+  if (!vect_check_gather_scatter (stmt_info, gs_vectype, loop_vinfo, &gs_info)
   || gs_info.ifn == IFN_LAST)
 return NULL;
 
   /* Convert the mask to the right form.  */
-  tree gs_vectype = get_vectype_for_scalar_type (loop_vinfo,
-gs_info.element_type);
   if (mask)
 mask = vect_convert_mask_for_vectype (mask, gs_vectype, stmt_info,
  loop_vinfo);
@@ -6103,8 +6104,7 @@ vect_recog_gather_scatter_pattern (vec_info *vinfo,
   stmt_vec_info pattern_stmt_info = loop_vinfo->add_stmt (pattern_stmt);
   loop_vinfo->move_dr (pattern_stmt_info, stmt_info);
 
-  tree vectype = STMT_VINFO_VECTYPE (stmt_info);
-  *type_out = vectype;
+  *type_out = gs_vectype;
   vect_pattern_detected ("gather/scatter pattern", stmt_info->stmt);
 
   return pattern_stmt;
diff --git a/gcc/tree-vect-slp.cc b/gcc/tree-vect-slp.cc
index 5236eac5a42a..6258a8eb53de 100644
--- a/gcc/tree-vect-slp.cc
+++ b/gcc/

[gcc r16-3504] install: Fix spelling of "support" and "arithmetic"

2025-09-03 Thread Gerald Pfeifer via Gcc-cvs
https://gcc.gnu.org/g:217008f7372227eb573154de9905675bf737ae94

commit r16-3504-g217008f7372227eb573154de9905675bf737ae94
Author: Jonathan Grant 
Date:   Sun Dec 3 00:15:12 2023 +

install: Fix spelling of "support" and "arithmetic"

gcc:
* doc/install.texi (Configuration): Fix spelling of "support"
and "floating-point arithmetic".

Signed-off-by: Jonathan Grant 

Diff:
---
 gcc/doc/install.texi | 14 +++---
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/gcc/doc/install.texi b/gcc/doc/install.texi
index 0def9eff49e4..c399b1f20559 100644
--- a/gcc/doc/install.texi
+++ b/gcc/doc/install.texi
@@ -1561,23 +1561,23 @@ for riscv*-*-elf*.  The accepted values and meanings 
are given below.
 Every config is constructed with four components: architecture string, ABI,
 reuse rule with architecture string and reuse rule with sub-extension.
 
-Example 1: Add multi-lib suppport for rv32i with ilp32.
+Example 1: Add multi-lib support for rv32i with ilp32.
 @smallexample
 rv32i-ilp32--
 @end smallexample
 
-Example 2: Add multi-lib suppport for rv32i with ilp32 and rv32imafd with 
ilp32.
+Example 2: Add multi-lib support for rv32i with ilp32 and rv32imafd with ilp32.
 @smallexample
 rv32i-ilp32--;rv32imafd-ilp32--
 @end smallexample
 
-Example 3: Add multi-lib suppport for rv32i with ilp32; rv32im with ilp32 and
+Example 3: Add multi-lib support for rv32i with ilp32; rv32im with ilp32 and
 rv32ic with ilp32 will reuse this multi-lib set.
 @smallexample
 rv32i-ilp32-rv32im-c
 @end smallexample
 
-Example 4: Add multi-lib suppport for rv64ima with lp64; rv64imaf with lp64,
+Example 4: Add multi-lib support for rv64ima with lp64; rv64imaf with lp64,
 rv64imac with lp64 and rv64imafc with lp64 will reuse this multi-lib set.
 @smallexample
 rv64ima-lp64--f,c,fc
@@ -1588,13 +1588,13 @@ rv64ima-lp64--f,c,fc
 config options, @var{val} is a comma separated list of possible code model,
 currently we support medlow and medany.
 
-Example 5: Add multi-lib suppport for rv64ima with lp64; rv64ima with lp64 and
+Example 5: Add multi-lib support for rv64ima with lp64; rv64ima with lp64 and
 medlow code model
 @smallexample
 rv64ima-lp64--;--cmodel=medlow
 @end smallexample
 
-Example 6: Add multi-lib suppport for rv64ima with lp64; rv64ima with lp64 and
+Example 6: Add multi-lib support for rv64ima with lp64; rv64ima with lp64 and
 medlow code model; rv64ima with lp64 and medany code model
 @smallexample
 rv64ima-lp64--;--cmodel=medlow,medany
@@ -1723,7 +1723,7 @@ libraries.  This option is only supported on Epiphany 
targets.
 
 @item --with-fpmath=@var{isa}
 This options sets @option{-mfpmath=sse} by default and specifies the default
-ISA for floating-point arithmetics.  You can select either @samp{sse} which
+ISA for floating-point arithmetic.  You can select either @samp{sse} which
 enables @option{-msse2} or @samp{avx} which enables @option{-mavx} by default.
 This option is only supported on i386 and x86-64 targets.


[gcc r16-3555] RISC-V: Add support for the XAndesbfhcvt ISA extension.

2025-09-03 Thread Jeff Law via Gcc-cvs
https://gcc.gnu.org/g:2963f5f7bd6db0e3f023fadb4c9c3d9e1a3fdcad

commit r16-3555-g2963f5f7bd6db0e3f023fadb4c9c3d9e1a3fdcad
Author: Kuan-Lin Chen 
Date:   Wed Sep 3 17:03:05 2025 -0600

RISC-V: Add support for the XAndesbfhcvt ISA extension.

This extension defines instructions to perform scalar floating-point
conversion between the BFLOAT16 floating-point data and the IEEE-754
32-bit single-precision floating-point (SP) data in a scalar
floating point register.

gcc/ChangeLog:

* config/riscv/andes.def: Add nds_fcvt_s_bf16 and nds_fcvt_bf16_s.
* config/riscv/riscv.md (truncsfbf2): Add TARGET_XANDESBFHCVT 
support.
(extendbfsf2): Ditto.
* config/riscv/riscv-builtins.cc: New AVAIL andesbfhcvt.
Add new define RISCV_ATYPE_BF and RISCV_ATYPE_SF.
* config/riscv/riscv-ftypes.def: New DEF_RISCV_FTYPE.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/xandes/xandesbfhcvt-1.c: New test.
* gcc.target/riscv/xandes/xandesbfhcvt-2.c: New test.

Diff:
---
 gcc/config/riscv/andes.def |  4 
 gcc/config/riscv/riscv-builtins.cc |  3 +++
 gcc/config/riscv/riscv-ftypes.def  |  2 ++
 gcc/config/riscv/riscv.md  | 18 ++
 gcc/testsuite/gcc.target/riscv/xandes/xandesbfhcvt-1.c | 11 +++
 gcc/testsuite/gcc.target/riscv/xandes/xandesbfhcvt-2.c | 11 +++
 6 files changed, 45 insertions(+), 4 deletions(-)

diff --git a/gcc/config/riscv/andes.def b/gcc/config/riscv/andes.def
index e2d67b8b2f18..8345ef6c13be 100644
--- a/gcc/config/riscv/andes.def
+++ b/gcc/config/riscv/andes.def
@@ -8,3 +8,7 @@ RISCV_BUILTIN (nds_ffmismsi, "nds_ffmism_32", 
RISCV_BUILTIN_DIRECT, RISCV_SI_FTY
 RISCV_BUILTIN (nds_ffmismdi, "nds_ffmism_64", RISCV_BUILTIN_DIRECT, 
RISCV_DI_FTYPE_UDI_UDI, andesperf64),
 RISCV_BUILTIN (nds_flmismsi, "nds_flmism_32", RISCV_BUILTIN_DIRECT, 
RISCV_SI_FTYPE_USI_USI, andesperf32),
 RISCV_BUILTIN (nds_flmismdi, "nds_flmism_64", RISCV_BUILTIN_DIRECT, 
RISCV_DI_FTYPE_UDI_UDI, andesperf64),
+
+/* Andes Scalar BFLOAT16 Conversion Extension */
+RISCV_BUILTIN_NO_PREFIX (extendbfsf2, "nds_fcvt_s_bf16", RISCV_BUILTIN_DIRECT, 
RISCV_SF_FTYPE_BF, andesbfhcvt),
+RISCV_BUILTIN_NO_PREFIX (truncsfbf2, "nds_fcvt_bf16_s", RISCV_BUILTIN_DIRECT, 
RISCV_BF_FTYPE_SF, andesbfhcvt),
diff --git a/gcc/config/riscv/riscv-builtins.cc 
b/gcc/config/riscv/riscv-builtins.cc
index cfcacf40a93b..5d8ff3278e74 100644
--- a/gcc/config/riscv/riscv-builtins.cc
+++ b/gcc/config/riscv/riscv-builtins.cc
@@ -140,6 +140,7 @@ AVAIL (cvsimd, TARGET_XCVSIMD && !TARGET_64BIT)
 /* ANDES AVAIL.  */
 AVAIL (andesperf32, !TARGET_64BIT && TARGET_XANDESPERF)
 AVAIL (andesperf64, TARGET_64BIT && TARGET_XANDESPERF)
+AVAIL (andesbfhcvt, TARGET_XANDESBFHCVT)
 
 /* Construct a riscv_builtin_description from the given arguments.
 
@@ -198,6 +199,8 @@ AVAIL (andesperf64, TARGET_64BIT && TARGET_XANDESPERF)
 #define RISCV_ATYPE_DI intDI_type_node
 #define RISCV_ATYPE_VOID_PTR ptr_type_node
 #define RISCV_ATYPE_INT_PTR integer_ptr_type_node
+#define RISCV_ATYPE_BF bfloat16_type_node
+#define RISCV_ATYPE_SF float_type_node
 
 /* RISCV_FTYPE_ATYPESN takes N RISCV_FTYPES-like type codes and lists
their associated RISCV_ATYPEs.  */
diff --git a/gcc/config/riscv/riscv-ftypes.def 
b/gcc/config/riscv/riscv-ftypes.def
index 6db41adc63ce..9aaea7d3c7e8 100644
--- a/gcc/config/riscv/riscv-ftypes.def
+++ b/gcc/config/riscv/riscv-ftypes.def
@@ -37,6 +37,8 @@ DEF_RISCV_FTYPE (1, (USI, UQI))
 DEF_RISCV_FTYPE (1, (USI, UHI))
 DEF_RISCV_FTYPE (1, (SI, QI))
 DEF_RISCV_FTYPE (1, (SI, HI))
+DEF_RISCV_FTYPE (1, (BF, SF))
+DEF_RISCV_FTYPE (1, (SF, BF))
 DEF_RISCV_FTYPE (2, (USI, UQI, UQI))
 DEF_RISCV_FTYPE (2, (USI, USI, UHI))
 DEF_RISCV_FTYPE (2, (USI, USI, QI))
diff --git a/gcc/config/riscv/riscv.md b/gcc/config/riscv/riscv.md
index 63d7daa01b0a..8c7d9aca16c2 100644
--- a/gcc/config/riscv/riscv.md
+++ b/gcc/config/riscv/riscv.md
@@ -1864,8 +1864,13 @@
   [(set (match_operand:BF0 "register_operand" "=f")
(float_truncate:BF
   (match_operand:SF 1 "register_operand" " f")))]
-  "TARGET_ZFBFMIN"
-  "fcvt.bf16.s\t%0,%1"
+  "TARGET_ZFBFMIN || TARGET_XANDESBFHCVT"
+{
+  if (TARGET_ZFBFMIN)
+return "fcvt.bf16.s\t%0,%1";
+  else
+return "nds.fcvt.bf16.s\t%0,%1";
+}
   [(set_attr "type" "fcvt")
(set_attr "mode" "BF")])
 
@@ -2052,8 +2057,13 @@
   [(set (match_operand:SF0 "register_operand" "=f")
(float_extend:SF
   (match_operand:BF 1 "register_operand" " f")))]
-  "TARGET_ZFBFMIN"
-  "fcvt.s.bf16\t%0,%1"
+  "TARGET_ZFBFMIN || TARGET_XANDESBFHCVT"
+{
+  if (TARGET_ZFBFMIN)
+return "fcvt.s.bf16\t%0,%1";
+  else
+return "nds.fcvt.s.bf16\t%0,%1";
+}
   [(set_attr "type" "fcvt")
(set_attr "mode" "SF")])
 
diff --git a/gcc/testsuite/gcc.target/riscv/xandes/xandesbfhcvt-1.c 
b/gcc/testsuite/gcc.t

[gcc r16-3550] libstdc++: Implement LWG4222 'expected' constructor from a single value missing a constraint

2025-09-03 Thread Jonathan Wakely via Libstdc++-cvs
https://gcc.gnu.org/g:589f3cd1831446485a6c602578177f5d9794d936

commit r16-3550-g589f3cd1831446485a6c602578177f5d9794d936
Author: Yihan Wang 
Date:   Sat Aug 16 16:43:05 2025 +0800

libstdc++: Implement LWG4222 'expected' constructor from a single value 
missing a constraint

libstdc++-v3/ChangeLog:

* include/std/expected (expected(U&&)): Add missing constraint
as per LWG 4222.
* testsuite/20_util/expected/lwg4222.cc: New test.

Signed-off-by: Yihan Wang 

Diff:
---
 libstdc++-v3/include/std/expected  |  1 +
 libstdc++-v3/testsuite/20_util/expected/lwg4222.cc | 39 ++
 2 files changed, 40 insertions(+)

diff --git a/libstdc++-v3/include/std/expected 
b/libstdc++-v3/include/std/expected
index 60f1565f15b9..4eaaab693e1e 100644
--- a/libstdc++-v3/include/std/expected
+++ b/libstdc++-v3/include/std/expected
@@ -474,6 +474,7 @@ namespace __expected
   template>
requires (!is_same_v, expected>)
  && (!is_same_v, in_place_t>)
+ && (!is_same_v, unexpect_t>)
  && is_constructible_v<_Tp, _Up>
  && (!__expected::__is_unexpected>)
  && __expected::__not_constructing_bool_from_expected<_Tp, _Up>
diff --git a/libstdc++-v3/testsuite/20_util/expected/lwg4222.cc 
b/libstdc++-v3/testsuite/20_util/expected/lwg4222.cc
new file mode 100644
index ..5c107792456b
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/expected/lwg4222.cc
@@ -0,0 +1,39 @@
+// { dg-do run { target c++23 } }
+
+// LWG 4222. 'expected' constructor from a single value missing a constraint
+
+#include 
+#include 
+#include 
+
+struct T {
+  explicit T(auto) {}
+};
+struct E {
+  E(int) {}
+};
+
+struct V {
+ explicit constexpr V(std::unexpect_t) {}
+};
+
+static_assert(!std::is_constructible_v, std::unexpect_t>);
+static_assert(!std::is_constructible_v, std::unexpect_t 
&>);
+static_assert(!std::is_constructible_v, std::unexpect_t 
&&>);
+static_assert(!std::is_constructible_v, const 
std::unexpect_t>);
+static_assert(!std::is_constructible_v, const 
std::unexpect_t &>);
+static_assert(!std::is_constructible_v, const 
std::unexpect_t &&>);
+
+constexpr bool test() {
+  std::expected e1(std::in_place, std::unexpect);
+  VERIFY( e1.has_value() );
+  std::expected e2(std::unexpect, std::unexpect);
+  VERIFY( !e2.has_value() );
+  return true;
+}
+
+int main() {
+  test();
+  static_assert(test());
+  return 0;
+}


[gcc r16-3551] Fortran: fix TRANSFER with rank 1 unlimited polymorphic SOURCE [PR121263]

2025-09-03 Thread Harald Anlauf via Gcc-cvs
https://gcc.gnu.org/g:692281a38773a70ae795b3b594f0c0f8fd83e5ef

commit r16-3551-g692281a38773a70ae795b3b594f0c0f8fd83e5ef
Author: Harald Anlauf 
Date:   Wed Sep 3 20:41:20 2025 +0200

Fortran: fix TRANSFER with rank 1 unlimited polymorphic SOURCE [PR121263]

PR fortran/121263

gcc/fortran/ChangeLog:

* trans-intrinsic.cc (gfc_conv_intrinsic_transfer): For an
unlimited polymorphic SOURCE to TRANSFER use saved descriptor
if possible.

gcc/testsuite/ChangeLog:

* gfortran.dg/transfer_class_5.f90: New test.

Diff:
---
 gcc/fortran/trans-intrinsic.cc |  7 +++-
 gcc/testsuite/gfortran.dg/transfer_class_5.f90 | 53 ++
 2 files changed, 59 insertions(+), 1 deletion(-)

diff --git a/gcc/fortran/trans-intrinsic.cc b/gcc/fortran/trans-intrinsic.cc
index 71556b1c4ef3..e720b42355f4 100644
--- a/gcc/fortran/trans-intrinsic.cc
+++ b/gcc/fortran/trans-intrinsic.cc
@@ -8651,7 +8651,12 @@ gfc_conv_intrinsic_transfer (gfc_se * se, gfc_expr * 
expr)
   argse.string_length);
   else if (arg->expr->ts.type == BT_CLASS)
{
- class_ref = TREE_OPERAND (argse.expr, 0);
+ if (UNLIMITED_POLY (source_expr)
+ && DECL_LANG_SPECIFIC (source_expr->symtree->n.sym->backend_decl))
+   class_ref = GFC_DECL_SAVED_DESCRIPTOR
+ (source_expr->symtree->n.sym->backend_decl);
+ else
+   class_ref = TREE_OPERAND (argse.expr, 0);
  tmp = gfc_class_vtab_size_get (class_ref);
  if (UNLIMITED_POLY (arg->expr))
tmp = gfc_resize_class_size_with_len (&argse.pre, class_ref, tmp);
diff --git a/gcc/testsuite/gfortran.dg/transfer_class_5.f90 
b/gcc/testsuite/gfortran.dg/transfer_class_5.f90
new file mode 100644
index ..4ce5eb9f31ef
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/transfer_class_5.f90
@@ -0,0 +1,53 @@
+! { dg-do run }
+! PR fortran/121263 - fix TRANSFER with rank 1 unlimited polymorhpic
+!
+! Based on original testcase by Chris Cox.
+
+module stdlib_hashmap_wrappers
+  implicit none
+contains
+  subroutine set_rank_one_key_int( key, value )
+integer, allocatable, intent(inout) :: key(:)
+class(*), intent(in):: value(:)
+key = transfer( value, key )
+  end subroutine
+
+  subroutine set_rank_one_key_cx ( key, value )
+complex, allocatable, intent(inout) :: key(:)
+class(*), intent(in):: value(:)
+key = transfer( value, key )
+  end subroutine
+
+  subroutine set_first_key_int   ( key, value )
+integer, intent(inout) :: key
+class(*), intent(in)   :: value(:)
+key = transfer( value(1), key )
+  end subroutine
+end module
+
+program p
+  use stdlib_hashmap_wrappers
+  implicit none
+  integer, allocatable :: a(:), b(:)
+  complex, allocatable :: c(:), d(:)
+  class(*),allocatable :: z(:)
+  integer :: m
+  a = [1, 2, 3, 4, 5]
+  c = cmplx (a, -a)
+  call set_rank_one_key_int (b, a)
+  call set_rank_one_key_cx  (d, c)
+  call set_first_key_int(m, a)
+! print *, b
+! print *, d
+  if (size (a) /= size (b)) stop 1
+  if (any  (a  /=   b)) stop 2
+  if (size (c) /= size (d)) stop 3
+  if (any  (c  /=   d)) stop 4
+  if (m /= 1) stop 5
+  deallocate (d)
+  z = c
+  d = transfer (z, d)
+  if (size (c) /= size (d)) stop 6
+  if (any  (c  /=   d)) stop 7
+  deallocate (a, b, c, d, z)
+end program p


[gcc r16-3557] testsuite, darwin: Suppress unwind frames in scantest-lto.c.

2025-09-03 Thread Iain D Sandoe via Gcc-cvs
https://gcc.gnu.org/g:6ce76052aeaa3370243909b62c87bfdcb243b885

commit r16-3557-g6ce76052aeaa3370243909b62c87bfdcb243b885
Author: Iain Sandoe 
Date:   Wed Sep 3 15:33:21 2025 +0100

testsuite, darwin: Suppress unwind frames in scantest-lto.c.

Currently, for Darwin unwind and EH frames are emitted without use
of .cfi_xxx instructions; the emitted frames also contain the
string 'ascii'.  For the purpose of this test, omit them.

PR testsuite/112728

gcc/testsuite/ChangeLog:

* gcc.dg/scantest-lto.c: Omit unwind frames.

Signed-off-by: Iain Sandoe 

Diff:
---
 gcc/testsuite/gcc.dg/scantest-lto.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/gcc/testsuite/gcc.dg/scantest-lto.c 
b/gcc/testsuite/gcc.dg/scantest-lto.c
index 46c21f20bfc9..9a6e816b1ffc 100644
--- a/gcc/testsuite/gcc.dg/scantest-lto.c
+++ b/gcc/testsuite/gcc.dg/scantest-lto.c
@@ -1,5 +1,6 @@
 /* { dg-do compile { target lto } }
 /* { dg-options "-O2 -flto" } */
+/* { dg-additional-options "-fno-unwind-tables 
-fno-asynchronous-unwind-tables" { target *-*-darwin* } } */
 
 void foo ()
 {


[gcc r16-3553] RISC-V: Add basic XAndes vendor extension support.

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

commit r16-3553-gfdcab349326c228617d143a3a4c9106712c2d58e
Author: Kuan-Lin Chen 
Date:   Wed Sep 3 16:38:52 2025 -0600

RISC-V: Add basic XAndes vendor extension support.

This patch add basic support for the following XAndes ISA extensions:

XANDESPERF
XANDESBFHCVT
XANDESVBFHCVT
XANDESVSINTLOAD
XANDESVPACKFPH
XANDESVDOT

gcc/ChangeLog:

* config/riscv/riscv-ext.def: Include riscv-ext-andes.def.
* config/riscv/riscv-ext.opt (riscv_xandes_subext): New variable.
(XANDESPERF) : New mask.
(XANDESBFHCVT): Ditto.
(XANDESVBFHCVT): Ditto.
(XANDESVSINTLOAD): Ditto.
(XANDESVPACKFPH): Ditto.
(XANDESVDOT): Ditto.
* config/riscv/t-riscv: Add riscv-ext-andes.def.
* doc/riscv-ext.texi: Regenerated.
* config/riscv/riscv-ext-andes.def: New file.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/xandes/xandes-predef-1.c: New test.
* gcc.target/riscv/xandes/xandes-predef-2.c: New test.
* gcc.target/riscv/xandes/xandes-predef-3.c: New test.
* gcc.target/riscv/xandes/xandes-predef-4.c: New test.
* gcc.target/riscv/xandes/xandes-predef-5.c: New test.
* gcc.target/riscv/xandes/xandes-predef-6.c: New test.

Co-author: Lino Hsing-Yu Peng (linop...@andestech.com)
Co-author: Kai Kai-Yi Weng (kaiw...@andestech.com).

Diff:
---
 gcc/config/riscv/riscv-ext-andes.def   | 100 +
 gcc/config/riscv/riscv-ext.def |   1 +
 gcc/config/riscv/riscv-ext.opt |  15 
 gcc/config/riscv/t-riscv   |   3 +-
 gcc/doc/riscv-ext.texi |  24 +
 .../gcc.target/riscv/xandes/xandes-predef-1.c  |  14 +++
 .../gcc.target/riscv/xandes/xandes-predef-2.c  |  14 +++
 .../gcc.target/riscv/xandes/xandes-predef-3.c  |  14 +++
 .../gcc.target/riscv/xandes/xandes-predef-4.c  |  14 +++
 .../gcc.target/riscv/xandes/xandes-predef-5.c  |  14 +++
 .../gcc.target/riscv/xandes/xandes-predef-6.c  |  14 +++
 11 files changed, 226 insertions(+), 1 deletion(-)

diff --git a/gcc/config/riscv/riscv-ext-andes.def 
b/gcc/config/riscv/riscv-ext-andes.def
new file mode 100644
index ..4226e3ed86fe
--- /dev/null
+++ b/gcc/config/riscv/riscv-ext-andes.def
@@ -0,0 +1,100 @@
+/* Andes extension definition file for RISC-V.
+   Copyright (C) 2025 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 3, or (at your option)
+any later version.
+
+GCC is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING3.  If not see
+.
+
+Please run `make riscv-regen` in build folder to make sure updated anything.
+
+Format of DEFINE_RISCV_EXT, please refer to riscv-ext.def.  */
+
+DEFINE_RISCV_EXT(
+  /* NAME */ xandesperf,
+  /* UPPERCASE_NAME */ XANDESPERF,
+  /* FULL_NAME */ "Andes performace extension",
+  /* DESC */ "",
+  /* URL */ ,
+  /* DEP_EXTS */ ({}),
+  /* SUPPORTED_VERSIONS */ ({{5, 0}}),
+  /* FLAG_GROUP */ xandes,
+  /* BITMASK_GROUP_ID */ BITMASK_NOT_YET_ALLOCATED,
+  /* BITMASK_BIT_POSITION*/ BITMASK_NOT_YET_ALLOCATED,
+  /* EXTRA_EXTENSION_FLAGS */ 0)
+
+DEFINE_RISCV_EXT(
+  /* NAME */ xandesbfhcvt,
+  /* UPPERCASE_NAME */ XANDESBFHCVT,
+  /* FULL_NAME */ "Andes bfloat16 conversion extension",
+  /* DESC */ "",
+  /* URL */ ,
+  /* DEP_EXTS */ ({}),
+  /* SUPPORTED_VERSIONS */ ({{5, 0}}),
+  /* FLAG_GROUP */ xandes,
+  /* BITMASK_GROUP_ID */ BITMASK_NOT_YET_ALLOCATED,
+  /* BITMASK_BIT_POSITION*/ BITMASK_NOT_YET_ALLOCATED,
+  /* EXTRA_EXTENSION_FLAGS */ 0)
+
+DEFINE_RISCV_EXT(
+  /* NAME */ xandesvbfhcvt,
+  /* UPPERCASE_NAME */ XANDESVBFHCVT,
+  /* FULL_NAME */ "Andes vector bfloat16 conversion extension",
+  /* DESC */ "",
+  /* URL */ ,
+  /* DEP_EXTS */ ({}),
+  /* SUPPORTED_VERSIONS */ ({{5, 0}}),
+  /* FLAG_GROUP */ xandes,
+  /* BITMASK_GROUP_ID */ BITMASK_NOT_YET_ALLOCATED,
+  /* BITMASK_BIT_POSITION*/ BITMASK_NOT_YET_ALLOCATED,
+  /* EXTRA_EXTENSION_FLAGS */ 0)
+
+DEFINE_RISCV_EXT(
+  /* NAME */ xandesvsintload,
+  /* UPPERCASE_NAME */ XANDESVSINTLOAD,
+  /* FULL_NAME */ "Andes vector INT4 load extension",
+  /* DESC */ "",
+  /* URL */ ,
+  /* DEP_EXTS */ ({}),
+  /* SUPPORTED_VERSIONS */ ({{5, 0}}),
+  /* FLAG_GROUP */ xandes,
+  /* BITMASK_GROUP_ID */ BITMASK_NOT_YET_ALLOCATED,
+  /* B

[gcc r16-3554] RISC-V: Add support for the XAndesperf ISA extension.

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

commit r16-3554-ge1fb7db6954d08860119f6b34db0c7d2490681de
Author: Kuan-Lin Chen 
Date:   Wed Sep 3 16:52:49 2025 -0600

RISC-V: Add support for the XAndesperf ISA extension.

This patch adds support for the XAndesperf ISA extension.
The 32-bit AndeStar V5 extension includes branch instructions,
load effective address instructions, and string processing
instructions for performance improvement.
New INSN patterns are added into the new file andes.md
as a seprated vender extension.

gcc/ChangeLog:

* config/riscv/constraints.md (Ou07): New constraint.
(ads_Bext): New constraint.
* config/riscv/iterators.md (ANYLE32): New iterator.
(sizen): New iterator.
(sh_limit): New iterator.
(sh_bit): New iterator.
(cs): New iterator.
* config/riscv/predicates.md (ads_branch_bbcs_operand): New 
predicate.
(ads_branch_bimm_operand): New predicate.
(ads_imm_extract_operand): New predicate.
(ads_extract_size_imm_si): New predicate.
(ads_extract_size_imm_di): New predicate.
(const_int5_operand): New predicate.
* config/riscv/riscv-builtins.cc:
Add new AVAIL andesperf32 and andesperf64.
Add new define RISCV_ATYPE_DI.
* config/riscv/riscv-ftypes.def: New DEF_RISCV_FTYPE.
* config/riscv/riscv.cc
(riscv_extend_cost): Cost for pattern 'bfo'.
(riscv_rtx_costs): Cost for XAndesperf extension.
* config/riscv/riscv.md: Add support for XAndesperf to patterns
zero_extendsidi2_internal, zero_extendhi2, extendsidi2_internal,
extend2, 3
and branch_on_bit.
* config/riscv/vector-iterators.md
(sz): Add sign_extract and zero_extract.
* config/riscv/andes.def: New file for vender Andes.
* config/riscv/andes.md: New file for vender Andes.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/riscv.exp: Add runtest for subdir xandes.
* gcc.target/riscv/xandes/xandesperf-1.c: New test.
* gcc.target/riscv/xandes/xandesperf-10.c: New test.
* gcc.target/riscv/xandes/xandesperf-2.c: New test.
* gcc.target/riscv/xandes/xandesperf-3.c: New test.
* gcc.target/riscv/xandes/xandesperf-4.c: New test.
* gcc.target/riscv/xandes/xandesperf-5.c: New test.
* gcc.target/riscv/xandes/xandesperf-6.c: New test.
* gcc.target/riscv/xandes/xandesperf-7.c: New test.
* gcc.target/riscv/xandes/xandesperf-8.c: New test.
* gcc.target/riscv/xandes/xandesperf-9.c: New test.

Diff:
---
 gcc/config/riscv/andes.def |  10 +
 gcc/config/riscv/andes.md  | 429 +
 gcc/config/riscv/constraints.md|  10 +
 gcc/config/riscv/iterators.md  |  15 +
 gcc/config/riscv/predicates.md |  42 ++
 gcc/config/riscv/riscv-builtins.cc |   6 +
 gcc/config/riscv/riscv-ftypes.def  |   1 +
 gcc/config/riscv/riscv.cc  |  32 ++
 gcc/config/riscv/riscv.md  |  17 +-
 gcc/config/riscv/vector-iterators.md   |   2 +-
 gcc/testsuite/gcc.target/riscv/riscv.exp   |   2 +
 .../gcc.target/riscv/xandes/xandesperf-1.c |  13 +
 .../gcc.target/riscv/xandes/xandesperf-10.c|  32 ++
 .../gcc.target/riscv/xandes/xandesperf-11.c|  32 ++
 .../gcc.target/riscv/xandes/xandesperf-2.c |  13 +
 .../gcc.target/riscv/xandes/xandesperf-3.c |  11 +
 .../gcc.target/riscv/xandes/xandesperf-4.c |  11 +
 .../gcc.target/riscv/xandes/xandesperf-5.c |  11 +
 .../gcc.target/riscv/xandes/xandesperf-6.c |  18 +
 .../gcc.target/riscv/xandes/xandesperf-7.c |  22 ++
 .../gcc.target/riscv/xandes/xandesperf-8.c |  26 ++
 .../gcc.target/riscv/xandes/xandesperf-9.c |  31 ++
 22 files changed, 779 insertions(+), 7 deletions(-)

diff --git a/gcc/config/riscv/andes.def b/gcc/config/riscv/andes.def
new file mode 100644
index ..e2d67b8b2f18
--- /dev/null
+++ b/gcc/config/riscv/andes.def
@@ -0,0 +1,10 @@
+// XANDESPERF
+/* Andes Performance Extension */
+RISCV_BUILTIN (nds_ffbsi, "nds_ffb_32", RISCV_BUILTIN_DIRECT, 
RISCV_SI_FTYPE_USI_USI, andesperf32),
+RISCV_BUILTIN (nds_ffbdi, "nds_ffb_64", RISCV_BUILTIN_DIRECT, 
RISCV_DI_FTYPE_UDI_UDI, andesperf64),
+RISCV_BUILTIN (nds_ffzmismsi, "nds_ffzmism_32", RISCV_BUILTIN_DIRECT, 
RISCV_SI_FTYPE_USI_USI, andesperf32),
+RISCV_BUILTIN (nds_ffzmismdi, "nds_ffzmism_64", RISCV_BUILTIN_DIRECT, 
RISCV_DI_FTYPE_UDI_UDI, andesperf64),
+RISCV_BUILTIN (nds_ffmismsi, "nds_ffmism_32", RISCV_BUILTIN_DIRECT, 
RISCV_SI_FTYPE_USI_USI, andesp

[gcc r14-11995] libstdc++: Fix -Wswitch warning in

2025-09-03 Thread Jonathan Wakely via Libstdc++-cvs
https://gcc.gnu.org/g:343f177943e2b0a9025fe7cc1b5e95c283248124

commit r14-11995-g343f177943e2b0a9025fe7cc1b5e95c283248124
Author: Jonathan Wakely 
Date:   Mon Sep 1 22:22:20 2025 +0100

libstdc++: Fix -Wswitch warning in 

This fixes a warning seen with -Wsystem-headers:

include/c++/14.3.0/bits/regex_compiler.h:191:11: warning: case value '0' 
not in enumerated type 'std::regex_constants::syntax_option_type' [-Wswitch]
  191 |   case _FlagT(0):
  |   ^~~~

There's no diagnostic on trunk since the flag_enum attribute was added
to the enum type in r15-3500-g1914ca8791ce4e.

libstdc++-v3/ChangeLog:

* include/bits/regex_compiler.h (_Compiler::_S_validate): Add
diagnostic pragma to disable -Wswitch warning.

Diff:
---
 libstdc++-v3/include/bits/regex_compiler.h | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/libstdc++-v3/include/bits/regex_compiler.h 
b/libstdc++-v3/include/bits/regex_compiler.h
index 5501d709e854..c6aaf4408531 100644
--- a/libstdc++-v3/include/bits/regex_compiler.h
+++ b/libstdc++-v3/include/bits/regex_compiler.h
@@ -188,8 +188,11 @@ namespace __detail
  case grep:
  case egrep:
return __f;
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wswitch" // do not warn about non-enumerator
  case _FlagT(0):
return __f | ECMAScript;
+#pragma GCC diagnostic pop
  default:
std::__throw_regex_error(_S_grammar, "conflicting grammar options");
  }


[gcc r14-11993] libstdc++: Check _GLIBCXX_USE_PTHREAD_MUTEX_CLOCKLOCK with #if [PR121496]

2025-09-03 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:3a730a2a8f124bfc3228dad33db355c78dde90ff

commit r14-11993-g3a730a2a8f124bfc3228dad33db355c78dde90ff
Author: Jonathan Wakely 
Date:   Tue Aug 19 18:02:53 2025 +0100

libstdc++: Check _GLIBCXX_USE_PTHREAD_MUTEX_CLOCKLOCK with #if [PR121496]

The change in r14-905-g3b7cb33033fbe6 to disable the use of
pthread_mutex_clocklock when TSan is active assumed that the
_GLIBCXX_USE_PTHREAD_MUTEX_CLOCKLOCK macro was always checked with #if
rather than #ifdef, which was not true.

This makes the checks use #if consistently.

libstdc++-v3/ChangeLog:

PR libstdc++/121496
* include/std/mutex (__timed_mutex_impl::_M_try_wait_until):
Change preprocessor condition to use #if instead of #ifdef.
(recursive_timed_mutex::_M_clocklock): Likewise.
* testsuite/30_threads/timed_mutex/121496.cc: New test.

Reviewed-by: Tomasz Kamiński 
(cherry picked from commit d1dec304453fa4874d16daaa15e6f477435edda4)

Diff:
---
 libstdc++-v3/include/std/mutex  |  4 ++--
 libstdc++-v3/testsuite/30_threads/timed_mutex/121496.cc | 14 ++
 2 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/libstdc++-v3/include/std/mutex b/libstdc++-v3/include/std/mutex
index e4b14c017201..729a7ee97937 100644
--- a/libstdc++-v3/include/std/mutex
+++ b/libstdc++-v3/include/std/mutex
@@ -188,7 +188,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
  return static_cast<_Derived*>(this)->_M_timedlock(__ts);
}
 
-#ifdef _GLIBCXX_USE_PTHREAD_MUTEX_CLOCKLOCK
+#if _GLIBCXX_USE_PTHREAD_MUTEX_CLOCKLOCK
   template
bool
_M_try_lock_until(const chrono::time_point
+#include 
+
+void
+test_pr121496(std::timed_mutex& m)
+{
+  (void) m.try_lock_until(std::chrono::steady_clock::time_point{});
+}


[gcc r14-11992] libstdc++: Fix std::numeric_limits<__float128>::max_digits10 [PR121374]

2025-09-03 Thread Jonathan Wakely via Libstdc++-cvs
https://gcc.gnu.org/g:d635e3298919d2be70c6931cfc158dd9a790e0f6

commit r14-11992-gd635e3298919d2be70c6931cfc158dd9a790e0f6
Author: Jonathan Wakely 
Date:   Tue Aug 19 17:29:12 2025 +0100

libstdc++: Fix std::numeric_limits<__float128>::max_digits10 [PR121374]

When I added this explicit specialization in r14-1433-gf150a084e25eaa I
used the wrong value for the number of mantissa digits (I used 112
instead of 113). Then when I refactored it in r14-1582-g6261d10521f9fd I
used the value calculated from the incorrect value (35 instead of 36).

libstdc++-v3/ChangeLog:

PR libstdc++/121374
* include/std/limits (numeric_limits<__float128>::max_digits10):
Fix value.
* testsuite/18_support/numeric_limits/128bit.cc: Check value.

(cherry picked from commit cf88ed5bf20c86ca38da19358ff79a34adb4d0b5)

Diff:
---
 libstdc++-v3/include/std/limits| 2 +-
 libstdc++-v3/testsuite/18_support/numeric_limits/128bit.cc | 5 +
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/libstdc++-v3/include/std/limits b/libstdc++-v3/include/std/limits
index 4b0698e47134..cfe033a849f5 100644
--- a/libstdc++-v3/include/std/limits
+++ b/libstdc++-v3/include/std/limits
@@ -2122,7 +2122,7 @@ __glibcxx_float_n(128)
   static _GLIBCXX_USE_CONSTEXPR int digits = 113;
   static _GLIBCXX_USE_CONSTEXPR int digits10 = 33;
 #if __cplusplus >= 201103L
-  static constexpr int max_digits10 = 35;
+  static constexpr int max_digits10 = 36;
 #endif
   static _GLIBCXX_USE_CONSTEXPR bool is_signed = true;
   static _GLIBCXX_USE_CONSTEXPR bool is_integer = false;
diff --git a/libstdc++-v3/testsuite/18_support/numeric_limits/128bit.cc 
b/libstdc++-v3/testsuite/18_support/numeric_limits/128bit.cc
index b13d83776ba3..bf12b65f91a5 100644
--- a/libstdc++-v3/testsuite/18_support/numeric_limits/128bit.cc
+++ b/libstdc++-v3/testsuite/18_support/numeric_limits/128bit.cc
@@ -4,6 +4,11 @@
 
 #if __SIZEOF_FLOAT128__
 __extension__ template class std::numeric_limits<__float128>;
+
+# if __cplusplus >= 201103L
+static_assert( std::numeric_limits<__float128>::max_digits10 == 36,
+  "PR libstdc++/121374" );
+# endif
 #endif
 
 #if __SIZEOF_INT128__


[gcc r14-11991] libstdc++: Use __promote_3 for std::hypot [PR121097]

2025-09-03 Thread Jonathan Wakely via Libstdc++-cvs
https://gcc.gnu.org/g:3d301adc99012d095a9291d9fb769ebd4481a5f1

commit r14-11991-g3d301adc99012d095a9291d9fb769ebd4481a5f1
Author: Jonathan Wakely 
Date:   Tue Jul 15 21:29:33 2025 +0100

libstdc++: Use __promote_3 for std::hypot [PR121097]

The __promoted_t alias is only defined when __cpp_fold_expressions is
defined, which might not be the case for some hypothetical C++17
compilers.

Change the 3-arg std::hypot to just use __gnu_cxx::__promote_3 which is
always available.

libstdc++-v3/ChangeLog:

PR libstdc++/121097
* include/c_global/cmath (hypot): Use __promote_3 instead of
__promoted.

Reviewed-by: Tomasz Kamiński 
(cherry picked from commit f4932c59df387a505de69a5a1015a03caa4ccf08)

Diff:
---
 libstdc++-v3/include/c_global/cmath | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libstdc++-v3/include/c_global/cmath 
b/libstdc++-v3/include/c_global/cmath
index 114b0693151e..4d669895e07e 100644
--- a/libstdc++-v3/include/c_global/cmath
+++ b/libstdc++-v3/include/c_global/cmath
@@ -3785,10 +3785,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   { return std::__hypot3(__x, __y, __z); }
 
   template
-__gnu_cxx::__promoted_t<_Tp, _Up, _Vp>
+typename __gnu_cxx::__promote_3<_Tp, _Up, _Vp>::__type
 hypot(_Tp __x, _Up __y, _Vp __z)
 {
-  using __type = __gnu_cxx::__promoted_t<_Tp, _Up, _Vp>;
+  using __type = typename __gnu_cxx::__promote_3<_Tp, _Up, _Vp>::__type;
   return std::__hypot3<__type>(__x, __y, __z);
 }


[gcc r14-11996] libstdc++: Add missing header to unordered_set/pr115285.cc test

2025-09-03 Thread Jonathan Wakely via Libstdc++-cvs
https://gcc.gnu.org/g:789c64455cb1e35c70f0736e018ad776add12e73

commit r14-11996-g789c64455cb1e35c70f0736e018ad776add12e73
Author: Jonathan Wakely 
Date:   Fri Nov 1 16:09:02 2024 +

libstdc++: Add missing  header to unordered_set/pr115285.cc test

libstdc++-v3/ChangeLog:

* testsuite/23_containers/unordered_set/pr115285.cc: Include
missing header for std::vector.

(cherry picked from commit a51d220377ab8117305567e888a942d127ef6a48)

Diff:
---
 libstdc++-v3/testsuite/23_containers/unordered_set/pr115285.cc | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libstdc++-v3/testsuite/23_containers/unordered_set/pr115285.cc 
b/libstdc++-v3/testsuite/23_containers/unordered_set/pr115285.cc
index 6c5cc24930ce..85954aed74b5 100644
--- a/libstdc++-v3/testsuite/23_containers/unordered_set/pr115285.cc
+++ b/libstdc++-v3/testsuite/23_containers/unordered_set/pr115285.cc
@@ -2,8 +2,9 @@
 
 // libstdc++/115285
 
-#include 
 #include 
+#include 
+#include 
 
 #include 


[gcc r14-11994] middle-end: Fix typo in gimple.h

2025-09-03 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:516c12e0e99be7280a94cb5ddd8edd5824b69459

commit r14-11994-g516c12e0e99be7280a94cb5ddd8edd5824b69459
Author: Benjamin Wu 
Date:   Sun Jul 13 17:25:02 2025 +0100

middle-end: Fix typo in gimple.h

gcc/ChangeLog:

* gimple.h (GTMA_DOES_GO_IRREVOCABLE): Fix typo.

(cherry picked from commit 356250630abd876ae592bc3d2b4cc171bc834b79)

Diff:
---
 gcc/gimple.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/gimple.h b/gcc/gimple.h
index 8a8ca109bbff..10b80ffe08e1 100644
--- a/gcc/gimple.h
+++ b/gcc/gimple.h
@@ -864,7 +864,7 @@ struct GTY((tag("GSS_ASSUME")))
tell the runtime that it should begin the transaction in
serial-irrevocable mode.  */
 #define GTMA_DOES_GO_IRREVOCABLE   (1u << 6)
-/* The transaction contains no instrumentation code whatsover, most
+/* The transaction contains no instrumentation code whatsoever, most
likely because it is guaranteed to go irrevocable upon entry.  */
 #define GTMA_HAS_NO_INSTRUMENTATION(1u << 7)


[gcc r16-3543] c++: constant non-dep init folding vs FIELD_DECL access [PR97740]

2025-09-03 Thread Patrick Palka via Gcc-cvs
https://gcc.gnu.org/g:3e2077d8c7a0acba2d54bd0666ae578fe114cd72

commit r16-3543-g3e2077d8c7a0acba2d54bd0666ae578fe114cd72
Author: Patrick Palka 
Date:   Wed Sep 3 10:10:00 2025 -0400

c++: constant non-dep init folding vs FIELD_DECL access [PR97740]

Here although the local templated variables x and y have the same
reduced constant value, only x's initializer {a.get()} is well-formed
as written since A::m has private access.  We correctly reject y's
initializer {&a.m} (at instantiation time), but we also reject x's
initializer because we happen to constant fold it ahead of time, which
means at instantiation time it's already represented as a COMPONENT_REF
to a FIELD_DECL, and so when substituting this COMPONENT_REF we naively
double check that the given FIELD_DECL is accessible, which fails.

This patch sidesteps around this particular issue by not checking access
when substituting a COMPONENT_REF to a FIELD_DECL.  If the target of a
COMPONENT_REF is already a FIELD_DECL (i.e. before substitution), then I
think we can assume access has been already checked appropriately.

PR c++/97740

gcc/cp/ChangeLog:

* pt.cc (tsubst_expr) : Don't check access
when the given member is already a FIELD_DECL.

gcc/testsuite/ChangeLog:

* g++.dg/cpp0x/constexpr-97740a.C: New test.
* g++.dg/cpp0x/constexpr-97740b.C: New test.

Reviewed-by: Jason Merrill 

Diff:
---
 gcc/cp/pt.cc  |  6 ++
 gcc/testsuite/g++.dg/cpp0x/constexpr-97740a.C | 18 ++
 gcc/testsuite/g++.dg/cpp0x/constexpr-97740b.C | 20 
 3 files changed, 44 insertions(+)

diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index 65de1cff0e64..365a6c55a837 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -22092,8 +22092,14 @@ tsubst_expr (tree t, tree args, tsubst_flags_t 
complain, tree in_decl)
  }
else if (TREE_CODE (member) == FIELD_DECL)
  {
+   /* Assume access of this FIELD_DECL has already been checked; we
+  don't recheck it to avoid bogus access errors when substituting
+  a reduced constant initializer (97740).  */
+   gcc_checking_assert (TREE_CODE (TREE_OPERAND (t, 1)) == FIELD_DECL);
+   push_deferring_access_checks (dk_deferred);
r = finish_non_static_data_member (member, object, NULL_TREE,
   complain);
+   pop_deferring_access_checks ();
if (REF_PARENTHESIZED_P (t))
  r = force_paren_expr (r);
RETURN (r);
diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-97740a.C 
b/gcc/testsuite/g++.dg/cpp0x/constexpr-97740a.C
new file mode 100644
index ..7cb65c5eb535
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-97740a.C
@@ -0,0 +1,18 @@
+// PR c++/97740
+// { dg-do compile { target c++11 } }
+
+struct A {
+  constexpr const int* get() const { return &m; }
+private:
+  int m;
+} a;
+
+struct B { const int* p; };
+
+template
+void f() {
+  constexpr B x = {a.get()}; // { dg-bogus "private" }
+  constexpr B y = {&a.m};// { dg-error "private" }
+}
+
+template void f();
diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-97740b.C 
b/gcc/testsuite/g++.dg/cpp0x/constexpr-97740b.C
new file mode 100644
index ..0ea767d94449
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-97740b.C
@@ -0,0 +1,20 @@
+// PR c++/97740
+// { dg-do compile { target c++14 } }
+
+struct A {
+  constexpr const int* get() const { return &m; }
+private:
+  int m;
+} a;
+
+struct B { const int* p; };
+
+template
+void f() {
+  [] (auto) {
+constexpr B x = {arg->get()}; // { dg-bogus "private" }
+constexpr B y = {&arg->m};// { dg-error "private" }
+  }(0);
+}
+
+template void f<&a>();


[gcc r16-3546] aarch64: PR target/121749: Use dg-assemble in testcase

2025-09-03 Thread Kyrylo Tkachov via Gcc-cvs
https://gcc.gnu.org/g:2b8256d0ce18ed4d00868c78f5128d32884ccfa1

commit r16-3546-g2b8256d0ce18ed4d00868c78f5128d32884ccfa1
Author: Kyrylo Tkachov 
Date:   Wed Sep 3 08:43:40 2025 -0700

aarch64: PR target/121749: Use dg-assemble in testcase

Committing as obvious.

Signed-off-by: Kyrylo Tkachov 

gcc/testsuite/

PR target/121749
* gcc.target/aarch64/simd/pr121749.c: Use dg-assemble directive.

Diff:
---
 gcc/testsuite/gcc.target/aarch64/simd/pr121749.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/testsuite/gcc.target/aarch64/simd/pr121749.c 
b/gcc/testsuite/gcc.target/aarch64/simd/pr121749.c
index c4e1a2d76cfb..b33245395b54 100644
--- a/gcc/testsuite/gcc.target/aarch64/simd/pr121749.c
+++ b/gcc/testsuite/gcc.target/aarch64/simd/pr121749.c
@@ -1,4 +1,4 @@
-/* { dg-do compile } */
+/* { dg-do assemble } */
 /* { dg-options "-O2" } */
 
 #include 


[gcc r16-3545] Increase default number of LTO partitions

2025-09-03 Thread Jan Hubicka via Gcc-cvs
https://gcc.gnu.org/g:7e2fdee3e29019b10251d85880053170154776de

commit r16-3545-g7e2fdee3e29019b10251d85880053170154776de
Author: Jan Hubicka 
Date:   Wed Sep 3 17:45:02 2025 +0200

Increase default number of LTO partitions

The number of LTO partitions should exceed number of CPUs (or 
hyper-threads) of
commonly used CPUs.  I think it is time to increase it again and as 
discussed
in the LTO and toplevel asm thread, doing so scales quite well. Tmp file 
usage
grows from 2.7 to 2.9MB which seems acceptable.  Overall build time on 
machine
with 256 hyperthreads is comparable.

Bootstrapped/regtested x86_64-linux, comitted.

gcc/ChangeLog:

* params.opt (-param=lto-partitions=): INcrease default value from 
128 to 512.

Diff:
---
 gcc/params.opt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/params.opt b/gcc/params.opt
index ac1b2c7eb262..dd53d830895f 100644
--- a/gcc/params.opt
+++ b/gcc/params.opt
@@ -462,7 +462,7 @@ Common Joined UInteger Var(param_min_partition_size) 
Init(1) Param
 Minimal size of a partition for LTO (in estimated instructions).
 
 -param=lto-partitions=
-Common Joined UInteger Var(param_lto_partitions) Init(128) IntegerRange(1, 
65536) Param
+Common Joined UInteger Var(param_lto_partitions) Init(512) IntegerRange(1, 
65536) Param
 Number of partitions the program should be split to.
 
 Enum


[gcc r16-3547] Do not auto-enable loop optimizations with AutoFDO

2025-09-03 Thread Jan Hubicka via Gcc-cvs
https://gcc.gnu.org/g:2c4fcab25fc0362359c87ab955b24c54aa41b46c

commit r16-3547-g2c4fcab25fc0362359c87ab955b24c54aa41b46c
Author: Jan Hubicka 
Date:   Wed Sep 3 17:55:54 2025 +0200

Do not auto-enable loop optimizations with AutoFDO

With -O2 we automatically enable several loop optimizations with 
-fprofile-use.
The rationale is that those optimizations at -O3 only mainly since they may
hurt performance or not pay back in code size when used blindly on all 
loops.
Profile feedback gives us data on number of iterations which is used by 
heuristics
controlling those optimizations.

Currently auto-FDO is not that good on determining number of iterations so 
I think we
do not want to enable them until we can prove that those are useful.
This is affecting primarily -O2 codegen.

Theoretically auto-FdO with lbr can be pretty good on estimating # of
iterations, but to make it useful we will need to implement multiplicity for
discriminators at least.

Bootstrapped/regtested x86_64-linux, comitted.

gcc/ChangeLog:

* opts.cc (enable_fdo_optimizations): Do not auto-enabele loop
optimizations with AutoFDO.

Diff:
---
 gcc/opts.cc | 45 -
 1 file changed, 28 insertions(+), 17 deletions(-)

diff --git a/gcc/opts.cc b/gcc/opts.cc
index 3ab993aea573..baba08488d4a 100644
--- a/gcc/opts.cc
+++ b/gcc/opts.cc
@@ -2097,11 +2097,10 @@ enable_fdo_optimizations (struct gcc_options *opts,
   SET_OPTION_IF_UNSET (opts, opts_set, flag_branch_probabilities, value);
   SET_OPTION_IF_UNSET (opts, opts_set, flag_profile_values, value);
 }
-  SET_OPTION_IF_UNSET (opts, opts_set, flag_unroll_loops, value);
-  SET_OPTION_IF_UNSET (opts, opts_set, flag_peel_loops, value);
-  SET_OPTION_IF_UNSET (opts, opts_set, flag_tracer, value);
   SET_OPTION_IF_UNSET (opts, opts_set, flag_value_profile_transformations,
   value);
+
+  /* Enable IPA optimizatins that makes effective use of profile data.  */
   SET_OPTION_IF_UNSET (opts, opts_set, flag_inline_functions, value);
   SET_OPTION_IF_UNSET (opts, opts_set, flag_ipa_cp, value);
   if (value)
@@ -2109,21 +2108,33 @@ enable_fdo_optimizations (struct gcc_options *opts,
   SET_OPTION_IF_UNSET (opts, opts_set, flag_ipa_cp_clone, 1);
   SET_OPTION_IF_UNSET (opts, opts_set, flag_ipa_bit_cp, 1);
 }
-  SET_OPTION_IF_UNSET (opts, opts_set, flag_predictive_commoning, value);
-  SET_OPTION_IF_UNSET (opts, opts_set, flag_split_loops, value);
-  SET_OPTION_IF_UNSET (opts, opts_set, flag_unswitch_loops, value);
+
   SET_OPTION_IF_UNSET (opts, opts_set, flag_gcse_after_reload, value);
-  SET_OPTION_IF_UNSET (opts, opts_set, flag_tree_loop_vectorize, value);
-  SET_OPTION_IF_UNSET (opts, opts_set, flag_tree_slp_vectorize, value);
-  SET_OPTION_IF_UNSET (opts, opts_set, flag_version_loops_for_strides, value);
-  SET_OPTION_IF_UNSET (opts, opts_set, flag_vect_cost_model,
-  VECT_COST_MODEL_DYNAMIC);
-  SET_OPTION_IF_UNSET (opts, opts_set, flag_tree_loop_distribute_patterns,
-  value);
-  SET_OPTION_IF_UNSET (opts, opts_set, flag_loop_interchange, value);
-  SET_OPTION_IF_UNSET (opts, opts_set, flag_unroll_jam, value);
-  SET_OPTION_IF_UNSET (opts, opts_set, flag_tree_loop_distribution, value);
-  SET_OPTION_IF_UNSET (opts, opts_set, flag_optimize_crc, value);
+  SET_OPTION_IF_UNSET (opts, opts_set, flag_tracer, value);
+
+  /* Loop optimizations uses profile feedback to determine their profitability
+ and thus it makes sense to enable them by default even at -O2.
+ Auto-profile, in its current form, is not very good on determining
+ iteration counts and thus only real profile feedback is used.  */
+  if (!autofdo)
+{
+  SET_OPTION_IF_UNSET (opts, opts_set, flag_unroll_loops, value);
+  SET_OPTION_IF_UNSET (opts, opts_set, flag_peel_loops, value);
+  SET_OPTION_IF_UNSET (opts, opts_set, flag_predictive_commoning, value);
+  SET_OPTION_IF_UNSET (opts, opts_set, flag_split_loops, value);
+  SET_OPTION_IF_UNSET (opts, opts_set, flag_unswitch_loops, value);
+  SET_OPTION_IF_UNSET (opts, opts_set, flag_tree_loop_vectorize, value);
+  SET_OPTION_IF_UNSET (opts, opts_set, flag_tree_slp_vectorize, value);
+  SET_OPTION_IF_UNSET (opts, opts_set, flag_version_loops_for_strides, 
value);
+  SET_OPTION_IF_UNSET (opts, opts_set, flag_vect_cost_model,
+  VECT_COST_MODEL_DYNAMIC);
+  SET_OPTION_IF_UNSET (opts, opts_set, flag_tree_loop_distribute_patterns,
+  value);
+  SET_OPTION_IF_UNSET (opts, opts_set, flag_loop_interchange, value);
+  SET_OPTION_IF_UNSET (opts, opts_set, flag_unroll_jam, value);
+  SET_OPTION_IF_UNSET (opts, opts_set, flag_tree_loop_distribution, value);
+  SET_OPTION_IF_UNSET (opts, opts_set, flag_optimize_crc, value);
+}
 }
 
 /* -f{,no-}sanitize{,-recover}

[gcc r16-3548] Dump profile_info in ipa-profile dump

2025-09-03 Thread Jan Hubicka via Gcc-cvs
https://gcc.gnu.org/g:bda76b479dc8492183dbf73236ff30805674f6f5

commit r16-3548-gbda76b479dc8492183dbf73236ff30805674f6f5
Author: Jan Hubicka 
Date:   Wed Sep 3 18:00:42 2025 +0200

Dump profile_info in ipa-profile dump

WPA currently does not print profile_info which might have been modified
by profile merging logic.  this patch adds dumping logic to ipa-profile 
pass.

Bootstrapped/regtested x86_64-linux, comitted.

gcc/ChangeLog:

* ipa-profile.cc (ipa_profile): Dump profile_info.

Diff:
---
 gcc/ipa-profile.cc | 12 +++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/gcc/ipa-profile.cc b/gcc/ipa-profile.cc
index c8b8529e38b7..d4725ce62626 100644
--- a/gcc/ipa-profile.cc
+++ b/gcc/ipa-profile.cc
@@ -773,7 +773,17 @@ ipa_profile (void)
   gcov_type threshold;
 
   if (dump_file)
-dump_histogram (dump_file, histogram);
+{
+  if (profile_info)
+   {
+ fprintf (dump_file,
+  "runs: %i sum_max: %" PRId64 " cutoff: %" PRId64"\n",
+  profile_info->runs, profile_info->sum_max, 
profile_info->cutoff);
+ fprintf (dump_file, "hot bb threshold: %" PRId64 "\n",
+  get_hot_bb_threshold ());
+   }
+  dump_histogram (dump_file, histogram);
+}
   for (i = 0; i < (int)histogram.length (); i++)
 {
   overall_time += ((widest_int)histogram[i]->count) * histogram[i]->time;


[gcc r16-3544] aarch64: PR target/121749: Use correct predicate for narrowing shift amounts

2025-09-03 Thread Kyrylo Tkachov via Gcc-cvs
https://gcc.gnu.org/g:cb508e54140687a50790059fac548d87515df6be

commit r16-3544-gcb508e54140687a50790059fac548d87515df6be
Author: Kyrylo Tkachov 
Date:   Tue Sep 2 00:43:14 2025 -0700

aarch64: PR target/121749: Use correct predicate for narrowing shift amounts

With g:d20b2ad845876eec0ee80a3933ad49f9f6c4ee30 the narrowing shift 
instructions
are now represented with standard RTL and more merging optimisations occur.
This exposed a wrong predicate for the shift amount operand.
The shift amount is the number of bits of the narrow destination, not the 
input
sources.
Correct this by using the vn_mode attribute when specifying the predicate, 
which
exists for this purpose.

I've spotted a few more narrowing shift patterns that need the restriction, 
so
they are updated as well.

Bootstrapped and tested on aarch64-none-linux-gnu.

Signed-off-by: Kyrylo Tkachov 

gcc/

PR target/121749
* config/aarch64/aarch64-simd.md (aarch64_shrn_n):
Use aarch64_simd_shift_imm_offset_ instead of
aarch64_simd_shift_imm_offset_ predicate.
(aarch64_shrn_n VQN define_expand): Likewise.
(*aarch64_rshrn_n_insn): Likewise.
(aarch64_rshrn_n): Likewise.
(aarch64_rshrn_n VQN define_expand): Likewise.
(aarch64_sqshrun_n_insn): Likewise.
(aarch64_sqshrun_n): Likewise.
(aarch64_sqshrun_n VQN define_expand): Likewise.
(aarch64_sqrshrun_n_insn): Likewise.
(aarch64_sqrshrun_n): Likewise.
(aarch64_sqrshrun_n): Likewise.
* config/aarch64/iterators.md (vn_mode): Handle DI, SI, HI modes.

gcc/testsuite/

PR target/121749
* gcc.target/aarch64/simd/pr121749.c: New test.

Diff:
---
 gcc/config/aarch64/aarch64-simd.md   | 22 +++---
 gcc/config/aarch64/iterators.md  |  3 ++-
 gcc/testsuite/gcc.target/aarch64/simd/pr121749.c | 11 +++
 3 files changed, 24 insertions(+), 12 deletions(-)

diff --git a/gcc/config/aarch64/aarch64-simd.md 
b/gcc/config/aarch64/aarch64-simd.md
index 8b75c3d7f6d5..c111dc2c7f7c 100644
--- a/gcc/config/aarch64/aarch64-simd.md
+++ b/gcc/config/aarch64/aarch64-simd.md
@@ -6731,7 +6731,7 @@
(SAT_TRUNC:
  (:SD_HSDI
(match_operand:SD_HSDI 1 "register_operand" "w")
-   (match_operand:SI 2 "aarch64_simd_shift_imm_offset_"]
+   (match_operand:SI 2 "aarch64_simd_shift_imm_offset_"]
   "TARGET_SIMD"
   "shrn\t%0, %1, %2"
   [(set_attr "type" "neon_shift_imm_narrow_q")]
@@ -6753,7 +6753,7 @@
(ALL_TRUNC:
  (:VQN
(match_operand:VQN 1 "register_operand")
-   (match_operand:SI 2 "aarch64_simd_shift_imm_offset_"]
+   (match_operand:SI 2 "aarch64_simd_shift_imm_offset_"]
   "TARGET_SIMD"
   {
 operands[2] = aarch64_simd_gen_const_vector_dup (mode,
@@ -6784,7 +6784,7 @@
  (:
(match_operand:SD_HSDI 1 "register_operand" "w"))
  (match_operand: 3 "aarch64_int_rnd_operand"))
-   (match_operand:SI 2 "aarch64_simd_shift_imm_offset_"]
+   (match_operand:SI 2 "aarch64_simd_shift_imm_offset_"]
   "TARGET_SIMD
&& aarch64_const_vec_rnd_cst_p (operands[3], operands[2])"
   "rshrn\t%0, %1, %2"
@@ -6799,7 +6799,7 @@
  (:
(match_operand:SD_HSDI 1 "register_operand"))
  (match_dup 3))
-   (match_operand:SI 2 "aarch64_simd_shift_imm_offset_"]
+   (match_operand:SI 2 "aarch64_simd_shift_imm_offset_"]
   "TARGET_SIMD"
   {
 /* Use this expander to create the rounding constant vector, which is
@@ -6819,7 +6819,7 @@
  (:
(match_operand:VQN 1 "register_operand"))
  (match_dup 3))
-   (match_operand:SI 2 "aarch64_simd_shift_imm_offset_"]
+   (match_operand:SI 2 "aarch64_simd_shift_imm_offset_"]
   "TARGET_SIMD"
   {
 if ( == TRUNCATE
@@ -6861,7 +6861,7 @@
  (smax:SD_HSDI
(ashiftrt:SD_HSDI
  (match_operand:SD_HSDI 1 "register_operand" "w")
- (match_operand:SI 2 "aarch64_simd_shift_imm_offset_"))
+ (match_operand:SI 2 "aarch64_simd_shift_imm_offset_"))
(const_int 0))
  (const_int )))]
   "TARGET_SIMD"
@@ -6872,7 +6872,7 @@
 (define_expand "aarch64_sqshrun_n"
   [(match_operand: 0 "register_operand")
(match_operand:SD_HSDI 1 "register_operand")
-   (match_operand:SI 2 "aarch64_simd_shift_imm_offset_")]
+   (match_operand:SI 2 "aarch64_simd_shift_imm_offset_")]
   "TARGET_SIMD"
   {
 rtx dst = gen_reg_rtx (mode);
@@ -6890,7 +6890,7 @@
(smax:VQN
  (ashiftrt:VQN
(match_operand:VQN 1 "register_operand")
-   (match_operand:SI 2 "aarch64_simd_shift_imm_offset_"))
+   (match_operand:SI 2 "

[gcc r16-3542] tree-optimization/121756 - handle irreducible regions when sinking

2025-09-03 Thread Richard Biener via Gcc-cvs
https://gcc.gnu.org/g:df64893e7082d7fae5d6863fd02371b37c78557f

commit r16-3542-gdf64893e7082d7fae5d6863fd02371b37c78557f
Author: Richard Biener 
Date:   Wed Sep 3 10:41:17 2025 +0200

tree-optimization/121756 - handle irreducible regions when sinking

The sinking code currently does not heuristically avoid placing
code into an irreducible region in the same way it avoids placing
into a deeper loop nest.  Critically for the PR we may not insert
a VDEF into a irreducible region that does not contain a virtual
definition.  The following adds the missing heuristic and also
a stop-gap for the VDEF issue - since we cannot determine
validity inside an irreducible region we have to reject any
VDEF movement with destination inside such region, even when
it originates there.  In particular irreducible sub-cycles are
not tracked separately and can cause issues.

I chose to not complicate the already partly incomplete assert
but prune it down to essentials.

PR tree-optimization/121756
* tree-ssa-sink.cc (select_best_block): Avoid irreducible
regions in otherwise same loop depth.
(statement_sink_location): When sinking a VDEF, never place
that into an irreducible region.

* gcc.dg/torture/pr121756.c: New testcase.

Diff:
---
 gcc/testsuite/gcc.dg/torture/pr121756.c | 30 ++
 gcc/tree-ssa-sink.cc| 17 +++--
 2 files changed, 41 insertions(+), 6 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/torture/pr121756.c 
b/gcc/testsuite/gcc.dg/torture/pr121756.c
new file mode 100644
index ..37c5c50e47ec
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr121756.c
@@ -0,0 +1,30 @@
+/* { dg-do compile } */
+
+int a, b, *c = &b;
+static void g(int i) {
+  int d = 0, e, f[] = {a}, j = a;
+  e = b;
+  if (e - i)
+return;
+  a = 0;
+h:
+  if (e) {
+e = j;
+if (f[3])
+  goto k;
+goto h;
+  }
+  while (1) {d = -1;
+while (1) {
+  if (d - 1 - j < 0)
+return;
+k:
+  if (f[1])
+break;
+}
+  }
+}
+int main() {
+  g(1);
+  return 0;
+}
diff --git a/gcc/tree-ssa-sink.cc b/gcc/tree-ssa-sink.cc
index 2244e89fbb7f..60dfe5282a72 100644
--- a/gcc/tree-ssa-sink.cc
+++ b/gcc/tree-ssa-sink.cc
@@ -245,6 +245,12 @@ select_best_block (basic_block early_bb,
   else if (bb_loop_depth (temp_bb) > bb_loop_depth (best_bb))
;
 
+  /* Likewise an irreducible region inside an otherwise same loop
+depth.  */
+  else if ((temp_bb->flags & BB_IRREDUCIBLE_LOOP)
+  && !(best_bb->flags & BB_IRREDUCIBLE_LOOP))
+   ;
+
   /* But sink the least distance, if the new candidate on the same
 loop depth is post-dominated by the current best block pick
 the new candidate.  */
@@ -265,11 +271,7 @@ select_best_block (basic_block early_bb,
 }
 
   gcc_checking_assert (best_bb == early_bb
-  || (!do_not_sink (stmt, early_bb, best_bb)
-  && ((bb_loop_depth (best_bb)
-   < bb_loop_depth (early_bb))
-  || !dominated_by_p (CDI_POST_DOMINATORS,
-  early_bb, best_bb;
+  || !do_not_sink (stmt, early_bb, best_bb));
 
   return best_bb;
 }
@@ -500,7 +502,10 @@ statement_sink_location (gimple *stmt, basic_block frombb,
 operand update, requiring inserting of a PHI node.  */
   || (gimple_vdef (stmt)
  && bestbb != sinkbb
- && !dominated_by_p (CDI_POST_DOMINATORS, bestbb, sinkbb)))
+ && !dominated_by_p (CDI_POST_DOMINATORS, bestbb, sinkbb))
+  /* Likewise avoid placing VDEFs into an irreducible region.  */
+  || (gimple_vdef (stmt)
+ && (bestbb->flags & BB_IRREDUCIBLE_LOOP)))
 return false;
 
   *togsi = gsi_after_labels (bestbb);


[gcc r16-3537] MAINTAINERS: Add myself as an aarch64 port reviewer

2025-09-03 Thread Alice Carlotti via Gcc-cvs
https://gcc.gnu.org/g:b905810be2ebd271d759d66cc2588e7b8180cc39

commit r16-3537-gb905810be2ebd271d759d66cc2588e7b8180cc39
Author: Alice Carlotti 
Date:   Fri Jul 4 16:45:52 2025 +0100

MAINTAINERS: Add myself as an aarch64 port reviewer

Changelog:

* MAINTAINERS: Add myself as an aarch64 port reviewer.

Diff:
---
 MAINTAINERS | 1 +
 1 file changed, 1 insertion(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index c127fa89e857..6473e933b27e 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -274,6 +274,7 @@ check in changes outside of the parts of the compiler they 
maintain.
 
 Reviewers
 
+aarch64 portAlice Carlotti  
 aarch64 portAlex Coplan 
 aarch64 portAndrew Pinski   

 arm port (MVE)  Christophe Lyon 


[gcc r16-3526] tree-optimization/121753 - ICE with pattern breaking reduction constraints

2025-09-03 Thread Richard Biener via Gcc-cvs
https://gcc.gnu.org/g:edeb5b8258382a58e1ce8e1e79e61386250d42b2

commit r16-3526-gedeb5b8258382a58e1ce8e1e79e61386250d42b2
Author: Richard Biener 
Date:   Tue Sep 2 10:16:28 2025 +0200

tree-optimization/121753 - ICE with pattern breaking reduction constraints

The recent change to vect_synth_mult_by_constant missed to handle
the synth_shift_p case for alg_shift, so we still changed c * 4
to c + c + c + c.  The following also amends alg_add_t2_m, alg_sub_t2_m,
alg_add_factor and alg_sub_factor appropriately.

PR tree-optimization/121753
* tree-vect-patterns.cc (vect_synth_mult_by_constant): Properly
bail when synth_shift_p and an alg_shift use.  Handle other
problematic cases.

Diff:
---
 gcc/tree-vect-patterns.cc | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/gcc/tree-vect-patterns.cc b/gcc/tree-vect-patterns.cc
index 64a49245..d0bf2f9e7990 100644
--- a/gcc/tree-vect-patterns.cc
+++ b/gcc/tree-vect-patterns.cc
@@ -4329,7 +4329,14 @@ vect_synth_mult_by_constant (vec_info *vinfo, tree op, 
tree val,
  case alg_add_t2_m:
  case alg_sub_t2_m:
op_uses++;
+   /* Fallthru.  */
+ case alg_shift:
+   if (synth_shift_p && alg.log[i])
+ return NULL;
break;
+ case alg_add_factor:
+ case alg_sub_factor:
+   return NULL;
  default:
break;
  }


[gcc r16-3524] RISC-V: Handle overlap in expand_vec_perm PR121742.

2025-09-03 Thread Robin Dapp via Gcc-cvs
https://gcc.gnu.org/g:f957d352bd6f240829226405e9be7960071d1b9c

commit r16-3524-gf957d352bd6f240829226405e9be7960071d1b9c
Author: Robin Dapp 
Date:   Mon Sep 1 11:41:34 2025 +0200

RISC-V: Handle overlap in expand_vec_perm PR121742.

In a two-source gather we unconditionally overwrite target with the
first gather's result already.  If op1 == target this clobbers the
source operand for the second gather.  This patch uses a temporary in
that case.

PR target/121742

gcc/ChangeLog:

* config/riscv/riscv-v.cc (expand_vec_perm): Use temporary if
op1 and target overlap.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/autovec/pr121742.c: New test.

Diff:
---
 gcc/config/riscv/riscv-v.cc| 11 +---
 .../gcc.target/riscv/rvv/autovec/pr121742.c| 30 ++
 2 files changed, 38 insertions(+), 3 deletions(-)

diff --git a/gcc/config/riscv/riscv-v.cc b/gcc/config/riscv/riscv-v.cc
index edfb4ff4ba60..9cbd4803cda2 100644
--- a/gcc/config/riscv/riscv-v.cc
+++ b/gcc/config/riscv/riscv-v.cc
@@ -3313,15 +3313,17 @@ expand_vec_perm (rtx target, rtx op0, rtx op1, rtx sel)
   mask_mode = get_mask_mode (data_mode);
   rtx mask = gen_reg_rtx (mask_mode);
   rtx max_sel = gen_const_vector_dup (sel_mode, nunits);
+  bool overlap = reg_overlap_mentioned_p (target, op1);
+  rtx tmp_target = overlap ? gen_reg_rtx (data_mode) : target;
 
   /* Step 1: generate a mask that should select everything >= nunits into the
* mask.  */
   expand_vec_cmp (mask, GEU, sel_mod, max_sel);
 
-  /* Step2: gather every op0 values indexed by sel into target,
+  /* Step2: gather every op0 values indexed by sel into TMP_TARGET,
we don't need to care about the result of the element
whose index >= nunits.  */
-  emit_vlmax_gather_insn (target, op0, sel_mod);
+  emit_vlmax_gather_insn (tmp_target, op0, sel_mod);
 
   /* Step3: shift the range from (nunits, max_of_mode] to
[0, max_of_mode - nunits].  */
@@ -3331,7 +,10 @@ expand_vec_perm (rtx target, rtx op0, rtx op1, rtx sel)
 
   /* Step4: gather those into the previously masked-out elements
of target.  */
-  emit_vlmax_masked_gather_mu_insn (target, op1, tmp, mask);
+  emit_vlmax_masked_gather_mu_insn (tmp_target, op1, tmp, mask);
+
+  if (overlap)
+emit_move_insn (tmp_target, target);
 }
 
 /* Implement TARGET_VECTORIZE_VEC_PERM_CONST for RVV.  */
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/autovec/pr121742.c 
b/gcc/testsuite/gcc.target/riscv/rvv/autovec/pr121742.c
new file mode 100644
index ..08491f8108a1
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/pr121742.c
@@ -0,0 +1,30 @@
+/* { dg-do run } */
+/* { dg-require-effective-target riscv_v_ok } */
+/* { dg-options "-march=rv64gcv -mabi=lp64d -O2" } */
+
+typedef unsigned long uint64_t;
+typedef unsigned int uint32_t;
+typedef unsigned char uint8_t;
+typedef uint8_t a __attribute__((vector_size(4)));
+int b, c;
+
+uint64_t d() {
+  a e = {5, 9, 1, 5};
+  a bla = {0, 0, 0, 0};
+  int *f = &b;
+  uint32_t g = 0;
+  int i = 0;
+  for (; i < 2; i++)
+for (c = 0; c <= 2; c++) {
+  *f ^= e[3] + 9;
+  e = __builtin_shufflevector(
+  ~__builtin_shufflevector(bla, e, 1, 4, 3, 4), e, 0, 1, 1, 7);
+}
+  return g;
+}
+
+int main() {
+  int j = d ();
+  if (b != 0)
+__builtin_abort ();
+}


[gcc r16-3535] libstdc++: Restore C++20 support for old std::string ABI

2025-09-03 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:381dbd4a9564525d930737a790c9b7d31dfc181f

commit r16-3535-g381dbd4a9564525d930737a790c9b7d31dfc181f
Author: Jonathan Wakely 
Date:   Tue Sep 2 17:04:13 2025 +0100

libstdc++: Restore C++20  support for old std::string ABI

The r16-3416-g806de30f51c8b9 change to use __cpp_lib_chrono in
preprocessor conditions broke support for  for freestanding and
the COW std::string ABI. That happened because __cpp_lib_chrono is only
defined to the C++20 value for hosted and for the new ABI, because the
full set of C++20 features are not defined for freestanding and tzdb is
not defined for the old ABI.

This introduces a new internal feature test macro that corresponds to
the features that are always supported (e.g. chrono::local_time,
chrono::year, chrono::weekday).

libstdc++-v3/ChangeLog:

* include/bits/version.def (chrono_cxx20): Define.
* include/bits/version.h: Regenerate.
* include/std/chrono: Check __glibcxx_chrono_cxx20 instead of
__cpp_lib_chrono for C++20 features that don't require the new
std::string ABI and/or can be used for freestanding.
* src/c++20/clock.cc: Adjust preprocessor condition.

Reviewed-by: Tomasz Kamiński 

Diff:
---
 libstdc++-v3/include/bits/version.def | 10 ++
 libstdc++-v3/include/bits/version.h   |  9 +
 libstdc++-v3/include/std/chrono   | 13 -
 libstdc++-v3/src/c++20/clock.cc   |  2 +-
 4 files changed, 28 insertions(+), 6 deletions(-)

diff --git a/libstdc++-v3/include/bits/version.def 
b/libstdc++-v3/include/bits/version.def
index 84c755da10e2..8707a123109f 100644
--- a/libstdc++-v3/include/bits/version.def
+++ b/libstdc++-v3/include/bits/version.def
@@ -594,6 +594,16 @@ ftms = {
   };
 };
 
+ftms = {
+  // Unofficial macro for C++20 chrono features supported for old string ABI.
+  name = chrono_cxx20;
+  values = {
+v = 201800;
+cxxmin = 20;
+no_stdname = yes;
+  };
+};
+
 ftms = {
   name = execution;
   values = {
diff --git a/libstdc++-v3/include/bits/version.h 
b/libstdc++-v3/include/bits/version.h
index 410e3205339d..c7569f42773c 100644
--- a/libstdc++-v3/include/bits/version.h
+++ b/libstdc++-v3/include/bits/version.h
@@ -665,6 +665,15 @@
 #endif /* !defined(__cpp_lib_chrono) && defined(__glibcxx_want_chrono) */
 #undef __glibcxx_want_chrono
 
+#if !defined(__cpp_lib_chrono_cxx20)
+# if (__cplusplus >= 202002L)
+#  define __glibcxx_chrono_cxx20 201800L
+#  if defined(__glibcxx_want_all) || defined(__glibcxx_want_chrono_cxx20)
+#  endif
+# endif
+#endif /* !defined(__cpp_lib_chrono_cxx20) && 
defined(__glibcxx_want_chrono_cxx20) */
+#undef __glibcxx_want_chrono_cxx20
+
 #if !defined(__cpp_lib_execution)
 # if (__cplusplus >= 201703L) && _GLIBCXX_HOSTED
 #  define __glibcxx_execution 201902L
diff --git a/libstdc++-v3/include/std/chrono b/libstdc++-v3/include/std/chrono
index d1a01fbdf0a8..f0207eaae8e0 100644
--- a/libstdc++-v3/include/std/chrono
+++ b/libstdc++-v3/include/std/chrono
@@ -53,11 +53,14 @@
 #if __cpp_lib_bitops >= 201907L
 # include  // __countr_zero
 #endif
-#if __cpp_lib_chrono >= 201803L && _GLIBCXX_HOSTED
+#ifdef __glibcxx_chrono_cxx20
+# include  // upper_bound
+# include  // begin/end for arrays
+#endif
+#if __cpp_lib_chrono >= 201803L // C++20 && HOSTED && USE_CXX11_ABI
 # include 
 # include 
 # include 
-# include  // upper_bound
 # include 
 # include 
 #endif
@@ -81,7 +84,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
*/
   namespace chrono
   {
-#if __cpp_lib_chrono >= 201803L
+#ifdef __glibcxx_chrono_cxx20
 /// @addtogroup chrono
 /// @{
 struct local_t { };
@@ -3319,7 +3322,7 @@ namespace __detail
 #endif // C++20
   } // namespace chrono
 
-#if __cpp_lib_chrono >= 201803L
+#ifdef __glibcxx_chrono_cxx20
   inline namespace literals
   {
   inline namespace chrono_literals
@@ -3348,7 +3351,7 @@ namespace __detail
 _GLIBCXX_END_NAMESPACE_VERSION
 } // namespace std
 
-#if __cpp_lib_chrono >= 201803L && _GLIBCXX_HOSTED
+#if defined __glibcxx_chrono_cxx20 && _GLIBCXX_HOSTED
 # include 
 #endif
 
diff --git a/libstdc++-v3/src/c++20/clock.cc b/libstdc++-v3/src/c++20/clock.cc
index 9d674b0b46a2..4af65046e1f8 100644
--- a/libstdc++-v3/src/c++20/clock.cc
+++ b/libstdc++-v3/src/c++20/clock.cc
@@ -35,7 +35,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
 namespace chrono
 {
-#if __cpp_lib_chrono >= 201803L && _GLIBCXX_HOSTED
+#if defined __glibcxx_chrono_cxx20 && _GLIBCXX_HOSTED
   // TODO use CLOCK_TAI on linux, add extension point.
   time_point
   tai_clock::now()


[gcc r16-3536] libstdc++: Make CTAD ignore pair(const T1&, const T2&) constructor [PR110853]

2025-09-03 Thread Jonathan Wakely via Libstdc++-cvs
https://gcc.gnu.org/g:0bb0d1d2880d562298eeec8eee4ab4e8ba943260

commit r16-3536-g0bb0d1d2880d562298eeec8eee4ab4e8ba943260
Author: Jonathan Wakely 
Date:   Tue Sep 2 22:30:46 2025 +0100

libstdc++: Make CTAD ignore pair(const T1&, const T2&) constructor 
[PR110853]

For the pair(T1, T2) explicit deduction type to decay its arguments as
intended, we need the pair(const T1&, const T2&) constructor to not be
used for CTAD. Otherwise we try to instantiate pair without
decaying, which is ill-formed for function lvalues.

Use std::type_identity_t to make the constructor unusable for an
implicit deduction guide.

libstdc++-v3/ChangeLog:

PR libstdc++/110853
* include/bits/stl_pair.h [C++20] (pair(const T1&, const T2&)):
Use std::type_identity_t for first parameter.
* testsuite/20_util/pair/cons/110853.cc: New test.

Reviewed-by: Patrick Palka 
Reviewed-by: Tomasz Kamiński 

Diff:
---
 libstdc++-v3/include/bits/stl_pair.h   |  2 +-
 libstdc++-v3/testsuite/20_util/pair/cons/110853.cc | 10 ++
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/libstdc++-v3/include/bits/stl_pair.h 
b/libstdc++-v3/include/bits/stl_pair.h
index 393f6a016196..2de7439ac6a3 100644
--- a/libstdc++-v3/include/bits/stl_pair.h
+++ b/libstdc++-v3/include/bits/stl_pair.h
@@ -445,7 +445,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
   /// Constructor accepting lvalues of `first_type` and `second_type`
   constexpr explicit(!_S_convertible())
-  pair(const _T1& __x, const _T2& __y)
+  pair(const type_identity_t<_T1>& __x, const _T2& __y)
   noexcept(_S_nothrow_constructible())
   requires (_S_constructible())
   : first(__x), second(__y)
diff --git a/libstdc++-v3/testsuite/20_util/pair/cons/110853.cc 
b/libstdc++-v3/testsuite/20_util/pair/cons/110853.cc
new file mode 100644
index ..57ebfb8d7daa
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/pair/cons/110853.cc
@@ -0,0 +1,10 @@
+// { dg-do compile { target c++17 } }
+// PR libstdc++/110853
+// Bad interaction between deduction guide with decay and constraints
+// (CTAD, std::pair and function lvalue)
+
+#include 
+
+void func() {}
+std::pair p(1, func);
+std::pair& r = p;


[gcc r16-3541] libstdc++: Fix std::get for std::pair with reference members [PR121745]

2025-09-03 Thread Jonathan Wakely via Libstdc++-cvs
https://gcc.gnu.org/g:c8a24f60b6874fca4fb3adb153f8d5f1dd72b951

commit r16-3541-gc8a24f60b6874fca4fb3adb153f8d5f1dd72b951
Author: Jonathan Wakely 
Date:   Mon Sep 1 18:12:27 2025 +0100

libstdc++: Fix std::get for std::pair with reference members [PR121745]

Make the std::get overloads for rvalues use std::forward(p.first)
not std::move(p.first), so that lvalue reference members are not
incorrectly converted to rvalues.

It might appear that std::move(p).first would also work, but the
language rules say that for std::pair that would produce T&
rather than the expected T&& (see the discussion in P2445R1 §8.2).

Additional tests are added to verify all combinations of reference
members, value categories, and const-qualification.

libstdc++-v3/ChangeLog:

PR libstdc++/121745
* include/bits/stl_pair.h (get): Use forward instead of move in
std::get overloads for rvalue pairs.
* testsuite/20_util/pair/astuple/get_by_type.cc: Check all value
categories and cv-qualification.

Reviewed-by: Tomasz Kamiński 

Diff:
---
 libstdc++-v3/include/bits/stl_pair.h   |  8 ++--
 .../testsuite/20_util/pair/astuple/get_by_type.cc  | 52 ++
 2 files changed, 56 insertions(+), 4 deletions(-)

diff --git a/libstdc++-v3/include/bits/stl_pair.h 
b/libstdc++-v3/include/bits/stl_pair.h
index 2de7439ac6a3..231d0bbd1f49 100644
--- a/libstdc++-v3/include/bits/stl_pair.h
+++ b/libstdc++-v3/include/bits/stl_pair.h
@@ -1315,12 +1315,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   template 
 constexpr _Tp&&
 get(pair<_Tp, _Up>&& __p) noexcept
-{ return std::move(__p.first); }
+{ return std::forward<_Tp>(__p.first); }
 
   template 
 constexpr const _Tp&&
 get(const pair<_Tp, _Up>&& __p) noexcept
-{ return std::move(__p.first); }
+{ return std::forward(__p.first); }
 
   template 
 constexpr _Tp&
@@ -1335,12 +1335,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   template 
 constexpr _Tp&&
 get(pair<_Up, _Tp>&& __p) noexcept
-{ return std::move(__p.second); }
+{ return std::forward<_Tp>(__p.second); }
 
   template 
 constexpr const _Tp&&
 get(const pair<_Up, _Tp>&& __p) noexcept
-{ return std::move(__p.second); }
+{ return std::forward(__p.second); }
 #endif // __glibcxx_tuples_by_type
 
 
diff --git a/libstdc++-v3/testsuite/20_util/pair/astuple/get_by_type.cc 
b/libstdc++-v3/testsuite/20_util/pair/astuple/get_by_type.cc
index 33ebf7a46b90..05a61c3f302c 100644
--- a/libstdc++-v3/testsuite/20_util/pair/astuple/get_by_type.cc
+++ b/libstdc++-v3/testsuite/20_util/pair/astuple/get_by_type.cc
@@ -33,3 +33,55 @@ void test01()
   const int&&  cpsecond __attribute__((unused)) =
 std::get(std::move(cp));
 }
+
+// PR libstdc++/121745 return of get(pair<_Up, _Tp>&& __p) may be ill-formed
+void
+test_pr121745(std::pair p)
+{
+  float& pfirst = std::get(std::move(p));
+  int& psecond  = std::get(std::move(p));
+
+  const auto& p2 = p;
+  float& p2first = std::get(std::move(p2));
+  int& p2second  = std::get(std::move(p2));
+}
+
+template
+using get_t = decltype(std::get(std::declval()));
+
+// Check that get(Pair) returns Ret
+template
+constexpr bool verify = std::is_same, Ret>::value;
+
+template
+void
+check()
+{
+  // Overloads for accessing first member
+  static_assert( verify&, T1&>,
+"T1& get(pair&)" );
+  static_assert( verify&, const T1&>,
+"const T1& get(const pair&)" );
+  static_assert( verify&&, T1&&>,
+"T1&& get(pair&&)" );
+  static_assert( verify&&, const T1&&>,
+"const T1&& get(const pair&&)" );
+
+  // Overloads for accessing second member
+  static_assert( verify&, T2&>,
+"T2& get(pair&)" );
+  static_assert( verify&, const T2&>,
+"const T2& get(const pair&)" );
+  static_assert( verify&&, T2&&>,
+"T2&& get(pair&&)" );
+  static_assert( verify&&, const T2&&>,
+"const T2&& get(const pair&&)" );
+}
+
+void
+test_all()
+{
+  check();
+  check();
+  check();
+}


[gcc r16-3538] tree-optimization/121758 - fix pattern stmt REDUC_IDX updating

2025-09-03 Thread Richard Biener via Gcc-cvs
https://gcc.gnu.org/g:41e2fe9be1ff5ef2eafd49b30882898d26b9bf36

commit r16-3538-g41e2fe9be1ff5ef2eafd49b30882898d26b9bf36
Author: Richard Biener 
Date:   Wed Sep 3 10:04:58 2025 +0200

tree-optimization/121758 - fix pattern stmt REDUC_IDX updating

The following fixes a corner case of pattern stmt STMT_VINFO_REDUC_IDX
updating which happens auto-magically.  When a 2nd pattern sequence
uses defs from inside a prior pattern sequence then the first guess
for the lookfor can be off.  This happens when for example widening
patterns use vect_get_internal_def, which looks into earlier patterns.

PR tree-optimization/121758
* tree-vect-patterns.cc (vect_mark_pattern_stmts): Try
harder to find a reduction continuation.

* gcc.dg/vect/pr121758.c: New testcase.

Diff:
---
 gcc/testsuite/gcc.dg/vect/pr121758.c | 15 +++
 gcc/tree-vect-patterns.cc| 30 --
 2 files changed, 39 insertions(+), 6 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/vect/pr121758.c 
b/gcc/testsuite/gcc.dg/vect/pr121758.c
new file mode 100644
index ..b27bc672588a
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/vect/pr121758.c
@@ -0,0 +1,15 @@
+/* { dg-do compile } */
+
+long g_2205, g_3005;
+int g_3320;
+void main()
+{
+  for (; g_2205; g_2205 += 1)
+{
+  g_3005 = 0;
+  for (; g_3005 <= 8; g_3005 += 1)
+   g_3320 &= 611 & (unsigned char)g_3005;
+}
+}
+
+/* { dg-final { scan-tree-dump-not "failed to update reduction index" "vect" } 
} */
diff --git a/gcc/tree-vect-patterns.cc b/gcc/tree-vect-patterns.cc
index d0bf2f9e7990..41ca0f085f0e 100644
--- a/gcc/tree-vect-patterns.cc
+++ b/gcc/tree-vect-patterns.cc
@@ -7074,14 +7074,32 @@ vect_mark_pattern_stmts (vec_info *vinfo,
{
  bool found = false;
  if (gimple_extract_op (s, &op))
-   for (unsigned i = 0; i < op.num_ops; ++i)
- if (op.ops[i] == lookfor)
+   {
+ for (unsigned i = 0; i < op.num_ops; ++i)
+   if (op.ops[i] == lookfor)
+ {
+   STMT_VINFO_REDUC_IDX (vinfo->lookup_stmt (s)) = i;
+   lookfor = gimple_get_lhs (s);
+   found = true;
+   break;
+ }
+ /* Try harder to find a mid-entry into an earlier pattern
+sequence.  This means that the initial 'lookfor' was
+bogus.  */
+ if (!found)
{
- STMT_VINFO_REDUC_IDX (vinfo->lookup_stmt (s)) = i;
- lookfor = gimple_get_lhs (s);
- found = true;
- break;
+ for (unsigned i = 0; i < op.num_ops; ++i)
+   if (TREE_CODE (op.ops[i]) == SSA_NAME)
+ if (auto def = vinfo->lookup_def (op.ops[i]))
+   if (vect_is_reduction (def))
+ {
+   STMT_VINFO_REDUC_IDX (vinfo->lookup_stmt (s)) = i;
+   lookfor = gimple_get_lhs (s);
+   found = true;
+   break;
+ }
}
+   }
  if (s == pattern_stmt)
{
  if (!found && dump_enabled_p ())


[gcc r16-3540] Remove vector type setting from vect_recog_cond_expr_convert_pattern

2025-09-03 Thread Richard Biener via Gcc-cvs
https://gcc.gnu.org/g:dd6fe9f5575ca01842e1809dd765bda7b1e8140e

commit r16-3540-gdd6fe9f5575ca01842e1809dd765bda7b1e8140e
Author: Richard Biener 
Date:   Thu Jul 24 11:13:12 2025 +0200

Remove vector type setting from vect_recog_cond_expr_convert_pattern

This pattern doesn't do any target support check so no need to set
a vector type.

* tree-vect-patterns.cc (vect_recog_cond_expr_convert_pattern):
Do not set any vector types.

Diff:
---
 gcc/tree-vect-patterns.cc | 8 +++-
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/gcc/tree-vect-patterns.cc b/gcc/tree-vect-patterns.cc
index f5c97242acb6..b39da1062c0e 100644
--- a/gcc/tree-vect-patterns.cc
+++ b/gcc/tree-vect-patterns.cc
@@ -1140,8 +1140,7 @@ vect_recog_cond_expr_convert_pattern (vec_info *vinfo,
{
  op2 = vect_recog_temp_ssa_var (type, NULL);
  gimple* nop_stmt = gimple_build_assign (op2, NOP_EXPR, match[2]);
- append_pattern_def_seq (vinfo, stmt_vinfo, nop_stmt,
- get_vectype_for_scalar_type (vinfo, type));
+ append_pattern_def_seq (vinfo, stmt_vinfo, nop_stmt);
}
 }
 
@@ -1150,11 +1149,10 @@ vect_recog_cond_expr_convert_pattern (vec_info *vinfo,
   temp = vect_recog_temp_ssa_var (type, NULL);
   cond_stmt = gimple_build_assign (temp, build3 (COND_EXPR, type, match[3],
 op1, op2));
-  append_pattern_def_seq (vinfo, stmt_vinfo, cond_stmt,
- get_vectype_for_scalar_type (vinfo, type));
+  append_pattern_def_seq (vinfo, stmt_vinfo, cond_stmt);
   new_lhs = vect_recog_temp_ssa_var (TREE_TYPE (lhs), NULL);
   pattern_stmt = gimple_build_assign (new_lhs, code, temp);
-  *type_out = STMT_VINFO_VECTYPE (stmt_vinfo);
+  *type_out = NULL_TREE;
 
   if (dump_enabled_p ())
 dump_printf_loc (MSG_NOTE, vect_location,


[gcc r16-3539] tree-optimization/121767 - modvar pattern breaking reductions

2025-09-03 Thread Richard Biener via Gcc-cvs
https://gcc.gnu.org/g:6acd5534ad3ab6208cda68fddb48eb73260d6508

commit r16-3539-g6acd5534ad3ab6208cda68fddb48eb73260d6508
Author: Richard Biener 
Date:   Wed Sep 3 11:04:49 2025 +0200

tree-optimization/121767 - modvar pattern breaking reductions

The a % b -> a - a / b pattern breaks reduction constraints, disable it
for reduction stmts.

PR tree-optimization/121767
* tree-vect-patterns.cc (vect_recog_mod_var_pattern): Disable
for reductions.

* gcc.dg/vect/pr121767.c: New testcase.

Diff:
---
 gcc/testsuite/gcc.dg/vect/pr121767.c | 9 +
 gcc/tree-vect-patterns.cc| 2 +-
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/gcc/testsuite/gcc.dg/vect/pr121767.c 
b/gcc/testsuite/gcc.dg/vect/pr121767.c
new file mode 100644
index ..3b52692a4b49
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/vect/pr121767.c
@@ -0,0 +1,9 @@
+/* { dg-do compile } */
+/* { dg-additional-options "-mcpu=neoverse-v2" { target aarch64-*-* } } */
+
+int foo (int x, int y, int n)
+{
+  for (int i = 0; i < n; ++i)
+x = x % y;
+  return x;
+}
diff --git a/gcc/tree-vect-patterns.cc b/gcc/tree-vect-patterns.cc
index 41ca0f085f0e..f5c97242acb6 100644
--- a/gcc/tree-vect-patterns.cc
+++ b/gcc/tree-vect-patterns.cc
@@ -5363,7 +5363,7 @@ vect_recog_mod_var_pattern (vec_info *vinfo,
   gimple *pattern_stmt, *def_stmt;
   enum tree_code rhs_code;
 
-  if (!is_gimple_assign (last_stmt))
+  if (!is_gimple_assign (last_stmt) || vect_is_reduction (stmt_vinfo))
 return NULL;
 
   rhs_code = gimple_assign_rhs_code (last_stmt);


[gcc r16-3549] [RISC-V][PR target/121213] Avoid unnecessary sign extension in amoswap sequence

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

commit r16-3549-gb790606e492d33e0cdb8159e38cb148d3526071b
Author: Austin Law 
Date:   Wed Sep 3 10:41:17 2025 -0600

[RISC-V][PR target/121213] Avoid unnecessary sign extension in amoswap 
sequence

This is Austin's work to remove the redundant sign extension seen in 
pr121213.

--

The .w form of amoswap will sign extend its result from 32 to 64 bits, thus 
any
explicit sign extension insn doing the same is redundant.

This uses Jivan's approach of allocating a DI temporary for an extended 
result
and using a promoted subreg extraction to get that result into the final
destination.

Tested with no regressions on riscv32-elf and riscv64-elf and bootstrapped 
on
the BPI and pioneer systems.

PR target/121213
gcc/
* config/riscv/sync.md (amo_atomic_exchange_extended):
Separate insn with sign extension for 64 bit targets.

gcc/testsuite
* gcc.target/riscv/amo/pr121213.c: Remove xfail.

Diff:
---
 gcc/config/riscv/sync.md  | 27 ++-
 gcc/testsuite/gcc.target/riscv/amo/pr121213.c |  2 +-
 2 files changed, 27 insertions(+), 2 deletions(-)

diff --git a/gcc/config/riscv/sync.md b/gcc/config/riscv/sync.md
index e47bb41adcc2..ab6f43066f10 100644
--- a/gcc/config/riscv/sync.md
+++ b/gcc/config/riscv/sync.md
@@ -376,7 +376,19 @@
(match_operand:SI 3 "const_int_operand")] ;; model
   "TARGET_ZAAMO || TARGET_ZALRSC"
   {
-if (TARGET_ZAAMO)
+if (TARGET_ZAAMO && TARGET_64BIT && mode == SImode)
+  {
+   rtx t = gen_reg_rtx (DImode);
+   emit_insn (gen_amo_atomic_exchange_extended (t,
+operands[1],
+operands[2],
+operands[3]));
+   t = gen_lowpart (SImode, t);
+   SUBREG_PROMOTED_VAR_P (t) = 1;
+   SUBREG_PROMOTED_SET (t, SRP_SIGNED);
+   emit_move_insn (operands[0], t);
+  }
+else if (TARGET_ZAAMO)
   emit_insn (gen_amo_atomic_exchange (operands[0], operands[1],
operands[2], operands[3]));
 else
@@ -398,6 +410,19 @@
   [(set_attr "type" "atomic")
(set (attr "length") (const_int 4))])
 
+(define_insn "amo_atomic_exchange_extended"
+  [(set (match_operand:DI 0 "register_operand" "=r")
+(sign_extend:DI (unspec_volatile:SI
+  [(match_operand:SI 1 "memory_operand" "+A")
+   (match_operand:SI 3 "const_int_operand")] ;; model
+  UNSPEC_SYNC_EXCHANGE)))
+   (set (match_dup 1)
+(match_operand:SI 2 "reg_or_0_operand" "rJ"))]
+  "TARGET_64BIT && TARGET_ZAAMO"
+  "amoswap.w%A3\t%0,%z2,%1"
+  [(set_attr "type" "atomic")
+   (set (attr "length") (const_int 4))])
+
 (define_insn "lrsc_atomic_exchange"
   [(set (match_operand:GPR 0 "register_operand" "=&r")
(unspec_volatile:GPR
diff --git a/gcc/testsuite/gcc.target/riscv/amo/pr121213.c 
b/gcc/testsuite/gcc.target/riscv/amo/pr121213.c
index 3b2d694f9914..6dd59c09462e 100644
--- a/gcc/testsuite/gcc.target/riscv/amo/pr121213.c
+++ b/gcc/testsuite/gcc.target/riscv/amo/pr121213.c
@@ -13,5 +13,5 @@ void test1(unsigned* lock) {
 
 /* { dg-final { scan-assembler-not "\tli" } } */
 /* { dg-final { scan-assembler-times "\tamoswap...aq\t\[axt\]\[0-9\],zero," 2 
} } */
-/* { dg-final { scan-assembler-not "\tsext" { xfail *-*-* } } } */
+/* { dg-final { scan-assembler-not "\tsext" } } */