[gcc r15-4849] c++: Adjust docs and option descriptions for the publishing of C++23

2024-11-01 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:d949b94ea0c4206c5188a38aa045729cfc149386

commit r15-4849-gd949b94ea0c4206c5188a38aa045729cfc149386
Author: Jakub Jelinek 
Date:   Fri Nov 1 19:50:28 2024 +0100

c++: Adjust docs and option descriptions for the publishing of C++23

Now that C++23 has been finally published, the following patch attempts
to mention it in the option descriptions and documentation.
Given that it has been published about 1.5 years after being finalized
and has the 14882:2024 document number pair rather than :2023, I wasn't
sure when exactly to use 2023 (as informal name) and when 2024 (as year
of publishing), so I've tried to use 2024 in standards.texi which talks
more formally about the standards and a note that it has been published
in 2024 when it is talked about more informally.
I remember at least one older edition has been published in January too,
but the ISO pages pretend it was published still in December of the previous
year, in this case it doesn't.

2024-11-01  Jakub Jelinek  

gcc/
* doc/standards.texi (C++ Language): Mention also the 2024
revision and -std=gnu++23 option.
* doc/invoke.texi (-std=): Adjust description of c++23, c++2b,
gnu++23 and gnu++2b now that ISO C++ 14882:2024 is published.
gcc/c-family/
* c.opt (std=c++2b, std=c++23, std=gnu++2b, std=gnu++23): Adjust
description now that ISO C++ 14882:2024 is published.

Diff:
---
 gcc/c-family/c.opt |  8 
 gcc/doc/invoke.texi| 22 --
 gcc/doc/standards.texi | 12 ++--
 3 files changed, 26 insertions(+), 16 deletions(-)

diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt
index e2c01083aec2..9b9f5e744f66 100644
--- a/gcc/c-family/c.opt
+++ b/gcc/c-family/c.opt
@@ -2558,11 +2558,11 @@ Conform to the ISO 2020 C++ standard (experimental and 
incomplete support).
 
 std=c++2b
 C++ ObjC++ Alias(std=c++23) Undocumented
-Conform to the ISO 2023 C++ draft standard (experimental and incomplete 
support).
+Conform to the ISO 2023 C++ standard (published in 2024; experimental and 
incomplete support).
 
 std=c++23
 C++ ObjC++
-Conform to the ISO 2023 C++ draft standard (experimental and incomplete 
support).
+Conform to the ISO 2023 C++ standard (published in 2024; experimental and 
incomplete support).
 
 std=c++2c
 C++ ObjC++ Alias(std=c++26)
@@ -2660,11 +2660,11 @@ Conform to the ISO 2020 C++ standard with GNU 
extensions (experimental and incom
 
 std=gnu++2b
 C++ ObjC++ Alias(std=gnu++23) Undocumented
-Conform to the ISO 2023 C++ draft standard with GNU extensions (experimental 
and incomplete support).
+Conform to the ISO 2023 C++ standard with GNU extensions (published in 2024; 
experimental and incomplete support).
 
 std=gnu++23
 C++ ObjC++
-Conform to the ISO 2023 C++ draft standard with GNU extensions (experimental 
and incomplete support).
+Conform to the ISO 2023 C++ standard with GNU extensions (published in 2024; 
experimental and incomplete support).
 
 std=gnu++2c
 C++ ObjC++ Alias(std=gnu++26)
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 455a0b1e7afe..fd6c0c447096 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -2566,17 +2566,19 @@ Support is experimental, and could change in 
incompatible ways in
 future releases.
 The name @samp{gnu++2a} is deprecated.
 
-@item c++2b
-@itemx c++23
-The next revision of the ISO C++ standard, planned for
-2023.  Support is highly experimental, and will almost certainly
-change in incompatible ways in future releases.
+@item c++23
+@itemx c++2b
+The 2023 ISO C++ standard plus amendments (published in 2024).
+Support is experimental, and could change in incompatible ways in
+future releases.
+The name @samp{c++2b} is deprecated.
 
-@item gnu++2b
-@itemx gnu++23
-GNU dialect of @option{-std=c++2b}.  Support is highly experimental,
-and will almost certainly change in incompatible ways in future
-releases.
+@item gnu++23
+@itemx gnu++2b
+GNU dialect of @option{-std=c++23}.
+Support is experimental, and could change in incompatible ways in
+future releases.
+The name @samp{gnu++2b} is deprecated.
 
 @item c++2c
 @itemx c++26
diff --git a/gcc/doc/standards.texi b/gcc/doc/standards.texi
index 4ef28e910d77..7e9b5891c181 100644
--- a/gcc/doc/standards.texi
+++ b/gcc/doc/standards.texi
@@ -204,7 +204,7 @@ information concerning the history of C that is available 
online, see
 @section C++ Language
 
 GCC supports the original ISO C++ standard published in 1998,
-and the 2011, 2014, 2017 and mostly 2020 revisions.
+and the 2011, 2014, 2017 and mostly 2020 and 2024 revisions.
 
 The original ISO C++ standard was published as the ISO standard (ISO/IEC
 14882:1998) and amended by a Technical Corrigenda published in 2003
@@ -245,6 +245,13 @@ new specification.  For further details see
 @uref{https://gcc.gnu.org/projects/@/cxx-status.html#cxx20}.
 To select this standard in GCC, use the option @optio

[gcc(refs/users/meissner/heads/work182-vpair)] Update vector-pair documentation.

2024-11-01 Thread Michael Meissner via Gcc-cvs
https://gcc.gnu.org/g:79fa9480b141fe1736e77e218537067af329900b

commit 79fa9480b141fe1736e77e218537067af329900b
Author: Michael Meissner 
Date:   Sat Nov 2 01:16:58 2024 -0400

Update vector-pair documentation.

2024-11-02  Michael Meissner  

* doc/extend.texi (PowerPC Vector Pair Support): Add
vpair_f{32,64}_swap_odd_even.  Remove sub-nodes.

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

diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi
index dd23cf0aadfb..2cce4dd9e34b 100644
--- a/gcc/doc/extend.texi
+++ b/gcc/doc/extend.texi
@@ -24753,9 +24753,6 @@ that will operate on units of 4 64-bit floating point 
values, and
 @code{vector_pair_f32_t} for operating on units of 8 32-bit floating
 point values.
 
-@node PowerPC Vector Pair Support for 64-bit floating point
-@subsection PowerPC Vector Pair Support for 64-bit floating point.
-
 The following functions are provided for operating on vector pairs
 that consist of 4 64-bit floating point values:
 
@@ -24790,9 +24787,6 @@ void vpair_f64_nfms (vector_pair_f64_t *, 
vector_pair_f64_t *,
  vector_pair_f64_t *, vector_pair_f64_t *);
 @end smallexample
 
-@node PowerPC Vector Pair Support for 32-bit floating point
-@subsection PowerPC Vector Pair Support for 32-bit floating point.
-
 The following functions are provided for operating on vector pairs
 that consist of 8 32-bit floating point values:
 
@@ -24827,6 +24821,14 @@ void vpair_f32_nfms (vector_pair_f32_t *, 
vector_pair_f32_t *,
  vector_pair_f32_t *, vector_pair_f32_t *);
 @end smallexample
 
+The following functions are provided for operating on vector pairs
+that swap the even and odd elements.
+
+@smallexample
+void vpair_f32_swap_odd_even (vector_pair_f32_t *, vector_pair_f32_t *);
+void vpair_f64_swap_odd_even (vector_pair_f64_t *, vector_pair_f64_t *);
+@end smallexample
+
 @node PRU Built-in Functions
 @subsection PRU Built-in Functions


[gcc(refs/users/meissner/heads/work182-vpair)] Update ChangeLog.*

2024-11-01 Thread Michael Meissner via Gcc-cvs
https://gcc.gnu.org/g:73af466f705a0659413455c6c12817f532a9b9fb

commit 73af466f705a0659413455c6c12817f532a9b9fb
Author: Michael Meissner 
Date:   Sat Nov 2 01:22:17 2024 -0400

Update ChangeLog.*

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

diff --git a/gcc/ChangeLog.vpair b/gcc/ChangeLog.vpair
index f1784c9f8bfd..ef25593bf11b 100644
--- a/gcc/ChangeLog.vpair
+++ b/gcc/ChangeLog.vpair
@@ -1,3 +1,12 @@
+ Branch work182-vpair, patch #302 
+
+Update vector-pair documentation.
+
+2024-11-02  Michael Meissner  
+
+   * doc/extend.texi (PowerPC Vector Pair Support): Add
+   vpair_f{32,64}_swap_odd_even.  Remove sub-nodes.
+
  Branch work182-vpair, patch #301 
 
 Add vector pair swap even and odd.


[gcc(refs/users/meissner/heads/work182-vpair)] Vector pair support.

2024-11-01 Thread Michael Meissner via Gcc-cvs
https://gcc.gnu.org/g:663ae8fb6671c73931aea80c4e25aeca3412481e

commit 663ae8fb6671c73931aea80c4e25aeca3412481e
Author: Michael Meissner 
Date:   Sat Nov 2 01:27:19 2024 -0400

Vector pair support.

This patch adds a new include file (vector-pair.h) that adds support so that
users writing high performance libraries can change their code to allow the
generation of the vector pair load and store instructions on power10.

The intention is that if the library authors need to write special loops 
that
go over arrays that they could modify their code to use the functions 
provided
to change loops that can take advantage of the higher bandwidth for load 
vector
pair and store instructions.

This particular patch just adds a new include file (vector-pair.h) that
provides a bunch of functions that on a power10 system would use the vector
pair load operation, 2 floating point operations, and a vector pair store.  
It
does not add any new types, modes, or built-in function.

I have additional patches that can add built-in functions that the 
functions in
vector-pair.h could utilize so that the compiler can optimize and combine
operations.  I may submit those patches in the future, but I would like to
provide this patch to allow the library writer to optimize their code.

I've measured the performance of these new functions on a power10.  For 
default
unrolling, the percentage of change for the 3 methods over the normal vector
loop method:

116%Vector-pair.h function, default unroll
 93%Vector pair split built-in & 2 vector stores, default unroll
 86%Vector pair split & combine built-ins, default unroll

Using explicit 2 way unrolling the numbers are:

114%Vector-pair.h function, unroll 2
106%Vector pair split built-in & 2 vector stores, unroll 2
 98%Vector pair split & combine built-ins, unroll 2

These new functions provided in vector-pair.h use the vector pair load/store
instructions, and don't generate extra vector moves.  Using the existing
vector pair disassemble and assemble built-ins generate extra vector moves
which can hinder performance.

If I compile the loop code for power9, there is a minor speed up for default
unrolling and more of an improvement using the framework provided in the
vector-pair.h for explicit unrolling by 2:

101%Vector-pair.h function, default unroll for power9
107%Vector-pair.h function, unroll 2 for power9

Of course this is a synthetic benchmark run on a quiet power10 system.  
Results
would vary for real code on real systems.  However, I feel adding these
functions can allow the writers of high performance libraries to better
optimize their code.

As an example, if the library wants to code a simple fused multiply-add 
loop,
they might write the code as follows:

#include 
#include 
#include 

void
fma_vector (double * __restrict__ r,
const double * __restrict__ a,
const double * __restrict__ b,
size_t n)
{
  vector double * __restrict__ vr = (vector double * __restrict__)r;
  const vector double * __restrict__ va = (const vector double * 
__restrict__)a;
  const vector double * __restrict__ vb = (const vector double * 
__restrict__)b;
  size_t num_elements = sizeof (vector double) / sizeof (double);
  size_t nv = n / num_elements;
  size_t i;

  for (i = 0; i < nv; i++)
vr[i] = __builtin_vsx_xvmadddp (va[i], vb[i], vr[i]);

  for (i = nv * num_elements; i < n; i++)
r[i] = fma (a[i], b[i], r[i]);
}

The inner loop would look like:

.L3:
lxvx 0,3,9
lxvx 12,4,9
addi 10,9,16
addi 2,2,-2
lxvx 11,5,9
xvmaddadp 0,12,11
lxvx 12,4,10
lxvx 11,5,10
stxvx 0,3,9
lxvx 0,3,10
addi 9,9,32
xvmaddadp 0,12,11
stxvx 0,3,10
bdnz .L3

Now if you code the loop to use __builtin_vsx_disassemble_pair to do a 
vector
pair load, but then do 2 vector stores:

#include 
#include 
#include 

void
fma_mma_ld (double * __restrict__ r,
const double * __restrict__ a,
const double * __restrict__ b,
size_t n)
{
  __vector_pair * __restrict__ vp_r 

[gcc(refs/users/meissner/heads/work182-vpair)] Revert changes

2024-11-01 Thread Michael Meissner via Gcc-cvs
https://gcc.gnu.org/g:305526e98f5455d09fbe86bc8052830f37555452

commit 305526e98f5455d09fbe86bc8052830f37555452
Author: Michael Meissner 
Date:   Sat Nov 2 01:24:11 2024 -0400

Revert changes

Diff:
---
 gcc/config.gcc |   2 +-
 gcc/config/rs6000/rs6000-c.cc  |   8 +-
 gcc/config/rs6000/vector-pair.h| 573 -
 gcc/doc/extend.texi| 100 
 gcc/testsuite/gcc.target/powerpc/vpair-1.c | 150 --
 gcc/testsuite/gcc.target/powerpc/vpair-2.c | 150 --
 gcc/testsuite/gcc.target/powerpc/vpair-3-not-p10.c |  15 -
 gcc/testsuite/gcc.target/powerpc/vpair-3-p10.c |  14 -
 gcc/testsuite/gcc.target/powerpc/vpair-3.h | 461 -
 gcc/testsuite/gcc.target/powerpc/vpair-4-not-p10.c |  15 -
 gcc/testsuite/gcc.target/powerpc/vpair-4-p10.c |  14 -
 gcc/testsuite/gcc.target/powerpc/vpair-4.h | 461 -
 12 files changed, 3 insertions(+), 1960 deletions(-)

diff --git a/gcc/config.gcc b/gcc/config.gcc
index 84121b455905..d552d01b4390 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -537,7 +537,7 @@ powerpc*-*-*)
extra_headers="${extra_headers} pmmintrin.h tmmintrin.h smmintrin.h"
extra_headers="${extra_headers} nmmintrin.h immintrin.h x86gprintrin.h"
extra_headers="${extra_headers} ppu_intrinsics.h spu2vmx.h vec_types.h 
si2vmx.h"
-   extra_headers="${extra_headers} amo.h vector-pair.h"
+   extra_headers="${extra_headers} amo.h"
case x$with_cpu in

xpowerpc64|xdefault64|x6[23]0|x970|xG5|xpower[3456789]|xpower1[01]|xpower6x|xrs64a|xcell|xa2|xe500mc64|xe5500|xe6500|xfuture)
cpu_is_64bit=yes
diff --git a/gcc/config/rs6000/rs6000-c.cc b/gcc/config/rs6000/rs6000-c.cc
index 77bee8fc8786..82826f96a8e7 100644
--- a/gcc/config/rs6000/rs6000-c.cc
+++ b/gcc/config/rs6000/rs6000-c.cc
@@ -590,13 +590,9 @@ rs6000_target_modify_macros (bool define_p, HOST_WIDE_INT 
flags,
   if (rs6000_cpu == PROCESSOR_CELL)
 rs6000_define_or_undefine_macro (define_p, "__PPU__");
 
-  /* Tell the user if we support the MMA instructions.  Also tell vector-pair.h
- that we have the vector pair built-in function support.  */
+  /* Tell the user if we support the MMA instructions.  */
   if ((flags & OPTION_MASK_MMA) != 0)
-{
-  rs6000_define_or_undefine_macro (define_p, "__MMA__");
-  rs6000_define_or_undefine_macro (define_p, "__VPAIR__");
-}
+rs6000_define_or_undefine_macro (define_p, "__MMA__");
   /* Whether pc-relative code is being generated.  */
   if ((flags & OPTION_MASK_PCREL) != 0)
 rs6000_define_or_undefine_macro (define_p, "__PCREL__");
diff --git a/gcc/config/rs6000/vector-pair.h b/gcc/config/rs6000/vector-pair.h
deleted file mode 100644
index 848c876beffc..
--- a/gcc/config/rs6000/vector-pair.h
+++ /dev/null
@@ -1,573 +0,0 @@
-/* PowerPC vector pair include file.
-   Copyright (C) 2024 Free Software Foundation, Inc.
-   Contributed by Aldy Hernandez (al...@redhat.com).
-   Rewritten by Paolo Bonzini (bonz...@gnu.org).
-
-   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.
-
-   Under Section 7 of GPL version 3, you are granted additional
-   permissions described in the GCC Runtime Library Exception, version
-   3.1, as published by the Free Software Foundation.
-
-   You should have received a copy of the GNU General Public License and
-   a copy of the GCC Runtime Library Exception along with this program;
-   see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
-   .  */
-
-/* Provide support for vector pairs, even on systems that do not have native
-   support for loading and storing pairs of vectors.  */
-
-#ifndef _VECTOR_PAIR_H
-#define _VECTOR_PAIR_H 1
-
-/* Union of the various vector pair types.  */
-union __vpair_union {
-
-#ifdef __MMA__
-  __vector_pair__vpair;
-#endif
-
-  vector double__vp_f64[2];
-  vector float __vp_f32[2];
-  vector unsigned char __vp_uc[2];
-};
-
-typedef union __vpair_unionvector_pair_f64_t;
-typedef union __vpair_unionvector_pair_f32_t;
-
-#if !__VPAIR_BUILTIN__ && !__VPAIR_ASM__ && !__VPAIR_NOP10__
-#if __MMA__
-#define __VPAIR_ASM__  1
-
-#else
-#define __VPAIR_NOP10__1
-#endif
-#endif
-
-/* Macros to simplify creation of the various operations.
- *
- * The __VPAIR_FP_{UNARY,BINARY,FMA} macros are the base macros, and takes:
- * R: 

[gcc(refs/users/meissner/heads/work182-vpair)] Update ChangeLog.*

2024-11-01 Thread Michael Meissner via Gcc-cvs
https://gcc.gnu.org/g:2cecf1305e78932919dff0c3bf01ae7c89e2d30e

commit 2cecf1305e78932919dff0c3bf01ae7c89e2d30e
Author: Michael Meissner 
Date:   Sat Nov 2 01:29:48 2024 -0400

Update ChangeLog.*

Diff:
---
 gcc/ChangeLog.vpair | 35 +--
 1 file changed, 5 insertions(+), 30 deletions(-)

diff --git a/gcc/ChangeLog.vpair b/gcc/ChangeLog.vpair
index ef25593bf11b..41b40a924234 100644
--- a/gcc/ChangeLog.vpair
+++ b/gcc/ChangeLog.vpair
@@ -1,34 +1,5 @@
  Branch work182-vpair, patch #302 
 
-Update vector-pair documentation.
-
-2024-11-02  Michael Meissner  
-
-   * doc/extend.texi (PowerPC Vector Pair Support): Add
-   vpair_f{32,64}_swap_odd_even.  Remove sub-nodes.
-
- Branch work182-vpair, patch #301 
-
-Add vector pair swap even and odd.
-
-This patch adds 2 additional functions:
-
-   vpair_f32_swap_odd_even
-   vpair_f64_swap_odd_even
-
-This swaps the odd and even elements in a vector pair.  The intention is for
-libraries that are doing complex multiply to be able to swap the real and
-imaginary elements to do the multiply operation.
-
-2024-11-01  Michael Meissner  
-
-gcc/
-
-   * config/rs6000/vector-pair.h (vpair_f32_swap_odd_even): New function.
-   (vpair_f64_swap_odd_even): Likewise.
-
- Branch work182-vpair, patch #300 
-
 Vector pair support.
 
 This patch adds a new include file (vector-pair.h) that adds support so that
@@ -418,7 +389,7 @@ With an explicit #pragma GCC unroll 2, the code generated 
would be:
bdnz .L93
 
 
-2024-11-01  Michael Meissner  
+2024-11-02  Michael Meissner  
 
 gcc/
 
@@ -438,6 +409,10 @@ gcc/testsuite/
* gcc.target/powerpc/vpair-4-p10.c: Likewise.
* gcc.target/powerpc/vpair-4.h: Likewise.
 
+ Branch work182-vpair, patch #302 was reverted 

+ Branch work182-vpair, patch #301 was reverted 

+ Branch work182-vpair, patch #300 was reverted 

+
  Branch work182-vpair, baseline 
 
 Add ChangeLog.vpair and update REVISION.


[gcc r15-4845] testsuite: Fix up builtin-prefetch-1.c tests

2024-11-01 Thread Xi Ruoyao via Gcc-cvs
https://gcc.gnu.org/g:e8689ac75faca61a0251d1098dbafa8c637ec489

commit r15-4845-ge8689ac75faca61a0251d1098dbafa8c637ec489
Author: Xi Ruoyao 
Date:   Sat Nov 2 00:05:44 2024 +0800

testsuite: Fix up builtin-prefetch-1.c tests

How can you use "read-shared" as an identifier?  It's not allowed by all
C standard versions.

gcc/testsuite/ChangeLog:

* gcc.c-torture/execute/builtin-prefetch-1.c (rws): Use
"read_shared" instead of "read-shared" as the identifier for
enum value.
* gcc.dg/builtin-prefetch-1.c (rws): Likewise.

Diff:
---
 gcc/testsuite/gcc.c-torture/execute/builtin-prefetch-1.c | 2 +-
 gcc/testsuite/gcc.dg/builtin-prefetch-1.c| 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/gcc/testsuite/gcc.c-torture/execute/builtin-prefetch-1.c 
b/gcc/testsuite/gcc.c-torture/execute/builtin-prefetch-1.c
index 03620c6ea6b1..07b490dc1a67 100644
--- a/gcc/testsuite/gcc.c-torture/execute/builtin-prefetch-1.c
+++ b/gcc/testsuite/gcc.c-torture/execute/builtin-prefetch-1.c
@@ -15,7 +15,7 @@ void exit (int);
 #define READ_ACCESS 0
 
 enum locality { none, low, moderate, high };
-enum rws { read, write, read-shared };
+enum rws { read, write, read_shared };
 
 int arr[10];
 
diff --git a/gcc/testsuite/gcc.dg/builtin-prefetch-1.c 
b/gcc/testsuite/gcc.dg/builtin-prefetch-1.c
index 7f75353795f3..aadbf144cfe6 100644
--- a/gcc/testsuite/gcc.dg/builtin-prefetch-1.c
+++ b/gcc/testsuite/gcc.dg/builtin-prefetch-1.c
@@ -8,7 +8,7 @@
 extern void exit (int);
 
 enum locality { none, low, moderate, high, bogus };
-enum rws { read, write, read-shared };
+enum rws { read, write, read_shared };
 
 int arr[10];


[gcc r15-4837] Fix -mod(unsigned, unsigned).

2024-11-01 Thread Thomas Kテカnig via Gcc-cvs
https://gcc.gnu.org/g:9646a4cdc6266ab403ceeb6a40b93e72b0166941

commit r15-4837-g9646a4cdc6266ab403ceeb6a40b93e72b0166941
Author: Thomas Koenig 
Date:   Fri Nov 1 10:02:30 2024 +0100

Fix -mod(unsigned, unsigned).

gcc/fortran/ChangeLog:

* resolve.cc (resolve_operator): Also handle BT_UNSIGNED.

gcc/testsuite/ChangeLog:

* gfortran.dg/unsigned_38.f90: Add -pedantic and adjust error
message.
* gfortran.dg/unsigned_40.f90: New test.

Diff:
---
 gcc/fortran/resolve.cc|  3 ++-
 gcc/testsuite/gfortran.dg/unsigned_38.f90 |  4 ++--
 gcc/testsuite/gfortran.dg/unsigned_40.f90 | 19 +++
 3 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/gcc/fortran/resolve.cc b/gcc/fortran/resolve.cc
index b14d3e776ab7..51e0af410c1c 100644
--- a/gcc/fortran/resolve.cc
+++ b/gcc/fortran/resolve.cc
@@ -4253,7 +4253,8 @@ resolve_operator (gfc_expr *e)
 case INTRINSIC_UMINUS:
   if (op1->ts.type == BT_INTEGER
  || op1->ts.type == BT_REAL
- || op1->ts.type == BT_COMPLEX)
+ || op1->ts.type == BT_COMPLEX
+ || op1->ts.type == BT_UNSIGNED)
{
  e->ts = op1->ts;
  break;
diff --git a/gcc/testsuite/gfortran.dg/unsigned_38.f90 
b/gcc/testsuite/gfortran.dg/unsigned_38.f90
index d549483b269a..ac1cfb33aac3 100644
--- a/gcc/testsuite/gfortran.dg/unsigned_38.f90
+++ b/gcc/testsuite/gfortran.dg/unsigned_38.f90
@@ -1,6 +1,6 @@
 ! { dg-do compile }
-! { dg-options "-funsigned" }
+! { dg-options "-funsigned -pedantic" }
 program main
   unsigned, parameter :: u = 7u
-  print *,mod(-(u+1u),u) ! { dg-error "Operand of unary numeric operator" }
+  print *,mod(-(u+1u),u) ! { dg-error "Negation of unsigned expression" }
 end program main
diff --git a/gcc/testsuite/gfortran.dg/unsigned_40.f90 
b/gcc/testsuite/gfortran.dg/unsigned_40.f90
new file mode 100644
index ..129fc883f177
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/unsigned_40.f90
@@ -0,0 +1,19 @@
+! { dg-do run }
+! { dg-options "-funsigned" }
+program memain
+  use iso_fortran_env, only : uint8
+  call test1
+  call test2
+contains
+  subroutine test1
+unsigned(uint8) :: nface, nmax
+nface = 12u_1
+nmax = - mod(-nface+1u,nface)
+if (nmax /= 251u_1) error stop 1
+  end subroutine test1
+  subroutine test2
+unsigned(uint8), parameter :: nface = 12u_1
+unsigned(uint8), parameter :: nmax = - mod(-nface+1u,nface)
+if (nmax /= 251u_1) error stop 11
+  end subroutine test2
+end program memain


[gcc r15-4846] i386: Do not allow pointer conversion for CMPccXADD intrin under -O0

2024-11-01 Thread Haochen Jiang via Gcc-cvs
https://gcc.gnu.org/g:c5a36c4e591e41efe3e4d892ff62831d801752d3

commit r15-4846-gc5a36c4e591e41efe3e4d892ff62831d801752d3
Author: Haochen Jiang 
Date:   Fri Nov 1 15:59:47 2024 +0800

i386: Do not allow pointer conversion for CMPccXADD intrin under -O0

The pointer conversion to wider type under macro would not consider
whether the higher bit is cleaned or not. It will lead to unexpected
cmp result.

After this change, it will throw an incompatible pointer type error just
like -O2 does currently.

gcc/ChangeLog:

* config/i386/cmpccxaddintrin.h (_cmpccxadd_epi32): Do not do
type conversion for pointer.
(_cmpccxadd_epi64): Ditto.

gcc/testsuite/ChangeLog:

* gcc.target/i386/cmpccxadd-1b.c: New test.

Diff:
---
 gcc/config/i386/cmpccxaddintrin.h|  6 +++---
 gcc/testsuite/gcc.target/i386/cmpccxadd-1b.c | 15 +++
 2 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/gcc/config/i386/cmpccxaddintrin.h 
b/gcc/config/i386/cmpccxaddintrin.h
index 39f368ffc082..9349fb00c1ba 100644
--- a/gcc/config/i386/cmpccxaddintrin.h
+++ b/gcc/config/i386/cmpccxaddintrin.h
@@ -72,11 +72,11 @@ _cmpccxadd_epi64 (long long *__A, long long __B, long long 
__C,
 }
 #else
 #define _cmpccxadd_epi32(A,B,C,D) \
-  __builtin_ia32_cmpccxadd ((int *) (A), (int) (B), (int) (C), \
+  __builtin_ia32_cmpccxadd ((A), (int) (B), (int) (C), \
(_CMPCCX_ENUM) (D))
 #define _cmpccxadd_epi64(A,B,C,D) \
-  __builtin_ia32_cmpccxadd64 ((long long *) (A), (long long) (B), \
- (long long) (C), (_CMPCCX_ENUM) (D))
+  __builtin_ia32_cmpccxadd64 ((A), (long long) (B), (long long) (C), \
+ (_CMPCCX_ENUM) (D))
 #endif
 
 #ifdef __DISABLE_CMPCCXADD__
diff --git a/gcc/testsuite/gcc.target/i386/cmpccxadd-1b.c 
b/gcc/testsuite/gcc.target/i386/cmpccxadd-1b.c
new file mode 100644
index ..7d20325da50f
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/cmpccxadd-1b.c
@@ -0,0 +1,15 @@
+/* { dg-do compile { target { ! ia32 } } } */
+/* { dg-options "-O0 -mcmpccxadd" } */
+#include 
+
+short *a;
+int b, c;
+int *d;
+long long e, f;
+
+void extern
+cmpccxadd_test(void)
+{
+  b = _cmpccxadd_epi32 (a, b, c, _CMPCCX_O); /* { dg-error "incompatible 
pointer type" } */
+  e = _cmpccxadd_epi64 (d, e, f, _CMPCCX_O); /* { dg-error "incompatible 
pointer type" } */
+}


[gcc r15-4847] Use IN_RANGE in prefetch builtin

2024-11-01 Thread Haochen Jiang via Gcc-cvs
https://gcc.gnu.org/g:79a75b1f551821687e1ce27a82ee39b802ace2b4

commit r15-4847-g79a75b1f551821687e1ce27a82ee39b802ace2b4
Author: Haochen Jiang 
Date:   Fri Nov 1 16:42:12 2024 +0800

Use IN_RANGE in prefetch builtin

These are the last minute changes that should apply to MOVRS patch but
disappeared in patch.

Using IN_RANGE will avoid second usage of INTVAL for prefetch check.

gcc/ChangeLog:

* builtins.cc (expand_builtin_prefetch): Use IN_RANGE to
avoid second usage of INTVAL.

Diff:
---
 gcc/builtins.cc | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/gcc/builtins.cc b/gcc/builtins.cc
index 504b31f84b51..b8684411ea87 100644
--- a/gcc/builtins.cc
+++ b/gcc/builtins.cc
@@ -1297,7 +1297,7 @@ expand_builtin_prefetch (tree exp)
   else
 op1 = expand_normal (arg1);
   /* Argument 1 must be 0, 1 or 2.  */
-  if (INTVAL (op1) < 0 || INTVAL (op1) > 2)
+  if (IN_RANGE (INTVAL (op1), 0, 2))
 {
   warning (0, "invalid second argument to %<__builtin_prefetch%>;"
   " using zero");
@@ -1315,7 +1315,7 @@ expand_builtin_prefetch (tree exp)
   else
 op2 = expand_normal (arg2);
   /* Argument 2 must be 0, 1, 2, or 3.  */
-  if (INTVAL (op2) < 0 || INTVAL (op2) > 3)
+  if (IN_RANGE (INTVAL (op2), 0, 3))
 {
   warning (0, "invalid third argument to %<__builtin_prefetch%>; using 
zero");
   op2 = const0_rtx;


[gcc r14-10864] i386: Do not allow pointer conversion for CMPccXADD intrin under -O0

2024-11-01 Thread Haochen Jiang via Gcc-cvs
https://gcc.gnu.org/g:82bfb6c5ba6d1f84472271f367221988cd50f478

commit r14-10864-g82bfb6c5ba6d1f84472271f367221988cd50f478
Author: Haochen Jiang 
Date:   Fri Nov 1 15:59:47 2024 +0800

i386: Do not allow pointer conversion for CMPccXADD intrin under -O0

The pointer conversion to wider type under macro would not consider
whether the higher bit is cleaned or not. It will lead to unexpected
cmp result.

After this change, it will throw an incompatible pointer type error just
like -O2 does currently.

gcc/ChangeLog:

* config/i386/cmpccxaddintrin.h (_cmpccxadd_epi32): Do not do
type conversion for pointer.
(_cmpccxadd_epi64): Ditto.

gcc/testsuite/ChangeLog:

* gcc.target/i386/cmpccxadd-1b.c: New test.

Diff:
---
 gcc/config/i386/cmpccxaddintrin.h|  6 +++---
 gcc/testsuite/gcc.target/i386/cmpccxadd-1b.c | 15 +++
 2 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/gcc/config/i386/cmpccxaddintrin.h 
b/gcc/config/i386/cmpccxaddintrin.h
index 39f368ffc082..9349fb00c1ba 100644
--- a/gcc/config/i386/cmpccxaddintrin.h
+++ b/gcc/config/i386/cmpccxaddintrin.h
@@ -72,11 +72,11 @@ _cmpccxadd_epi64 (long long *__A, long long __B, long long 
__C,
 }
 #else
 #define _cmpccxadd_epi32(A,B,C,D) \
-  __builtin_ia32_cmpccxadd ((int *) (A), (int) (B), (int) (C), \
+  __builtin_ia32_cmpccxadd ((A), (int) (B), (int) (C), \
(_CMPCCX_ENUM) (D))
 #define _cmpccxadd_epi64(A,B,C,D) \
-  __builtin_ia32_cmpccxadd64 ((long long *) (A), (long long) (B), \
- (long long) (C), (_CMPCCX_ENUM) (D))
+  __builtin_ia32_cmpccxadd64 ((A), (long long) (B), (long long) (C), \
+ (_CMPCCX_ENUM) (D))
 #endif
 
 #ifdef __DISABLE_CMPCCXADD__
diff --git a/gcc/testsuite/gcc.target/i386/cmpccxadd-1b.c 
b/gcc/testsuite/gcc.target/i386/cmpccxadd-1b.c
new file mode 100644
index ..7d20325da50f
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/cmpccxadd-1b.c
@@ -0,0 +1,15 @@
+/* { dg-do compile { target { ! ia32 } } } */
+/* { dg-options "-O0 -mcmpccxadd" } */
+#include 
+
+short *a;
+int b, c;
+int *d;
+long long e, f;
+
+void extern
+cmpccxadd_test(void)
+{
+  b = _cmpccxadd_epi32 (a, b, c, _CMPCCX_O); /* { dg-error "incompatible 
pointer type" } */
+  e = _cmpccxadd_epi64 (d, e, f, _CMPCCX_O); /* { dg-error "incompatible 
pointer type" } */
+}


[gcc r13-9162] i386: Do not allow pointer conversion for CMPccXADD intrin under -O0

2024-11-01 Thread Haochen Jiang via Gcc-cvs
https://gcc.gnu.org/g:100751c7905d6866540ca243135629994d3fd032

commit r13-9162-g100751c7905d6866540ca243135629994d3fd032
Author: Haochen Jiang 
Date:   Fri Nov 1 15:59:47 2024 +0800

i386: Do not allow pointer conversion for CMPccXADD intrin under -O0

The pointer conversion to wider type under macro would not consider
whether the higher bit is cleaned or not. It will lead to unexpected
cmp result.

After this change, it will throw an incompatible pointer type error just
like -O2 does currently.

gcc/ChangeLog:

* config/i386/cmpccxaddintrin.h (_cmpccxadd_epi32): Do not do
type conversion for pointer.
(_cmpccxadd_epi64): Ditto.

gcc/testsuite/ChangeLog:

* gcc.target/i386/cmpccxadd-1b.c: New test.

Diff:
---
 gcc/config/i386/cmpccxaddintrin.h|  6 +++---
 gcc/testsuite/gcc.target/i386/cmpccxadd-1b.c | 15 +++
 2 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/gcc/config/i386/cmpccxaddintrin.h 
b/gcc/config/i386/cmpccxaddintrin.h
index c458a9d2f52b..2df647e7c220 100644
--- a/gcc/config/i386/cmpccxaddintrin.h
+++ b/gcc/config/i386/cmpccxaddintrin.h
@@ -72,11 +72,11 @@ _cmpccxadd_epi64 (long long *__A, long long __B, long long 
__C,
 }
 #else
 #define _cmpccxadd_epi32(A,B,C,D) \
-  __builtin_ia32_cmpccxadd ((int *) (A), (int) (B), (int) (C), \
+  __builtin_ia32_cmpccxadd ((A), (int) (B), (int) (C), \
(_CMPCCX_ENUM) (D))
 #define _cmpccxadd_epi64(A,B,C,D) \
-  __builtin_ia32_cmpccxadd64 ((long long *) (A), (long long) (B), \
- (long long) (C), (_CMPCCX_ENUM) (D))
+  __builtin_ia32_cmpccxadd64 ((A), (long long) (B), (long long) (C), \
+ (_CMPCCX_ENUM) (D))
 #endif
 
 #ifdef __DISABLE_CMPCCXADD__
diff --git a/gcc/testsuite/gcc.target/i386/cmpccxadd-1b.c 
b/gcc/testsuite/gcc.target/i386/cmpccxadd-1b.c
new file mode 100644
index ..7d20325da50f
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/cmpccxadd-1b.c
@@ -0,0 +1,15 @@
+/* { dg-do compile { target { ! ia32 } } } */
+/* { dg-options "-O0 -mcmpccxadd" } */
+#include 
+
+short *a;
+int b, c;
+int *d;
+long long e, f;
+
+void extern
+cmpccxadd_test(void)
+{
+  b = _cmpccxadd_epi32 (a, b, c, _CMPCCX_O); /* { dg-error "incompatible 
pointer type" } */
+  e = _cmpccxadd_epi64 (d, e, f, _CMPCCX_O); /* { dg-error "incompatible 
pointer type" } */
+}


[gcc r15-4842] Always set SECTION_RELRO for or .data.rel.ro{, .local} [PR116887]

2024-11-01 Thread Xi Ruoyao via Gcc-cvs
https://gcc.gnu.org/g:c8d35f2ecbf124bdd164dbb1c36de9d90695843b

commit r15-4842-gc8d35f2ecbf124bdd164dbb1c36de9d90695843b
Author: Xi Ruoyao 
Date:   Fri Oct 11 02:44:27 2024 +0800

Always set SECTION_RELRO for or .data.rel.ro{,.local} [PR116887]

At least two ports (hppa and loongarch) need to set SECTION_RELRO for
.data.rel.ro{,.local} in section_type_flags (PR52999 and PR116887), and
I cannot see a reason not to just set it in the generic code.

With this applied we can also remove the hppa-specific
pa_section_type_flags in a future patch.

gcc/ChangeLog:

PR target/116887
* varasm.cc (default_section_type_flags): Always set
SECTION_RELRO if name is .data.rel.ro{,.local}.

gcc/testsuite/ChangeLog:

PR target/116887
* gcc.dg/pr116887.c: New test.

Diff:
---
 gcc/testsuite/gcc.dg/pr116887.c | 23 +++
 gcc/varasm.cc   | 10 --
 2 files changed, 27 insertions(+), 6 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/pr116887.c b/gcc/testsuite/gcc.dg/pr116887.c
new file mode 100644
index ..b7255e09a18a
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr116887.c
@@ -0,0 +1,23 @@
+/* { dg-do compile } */
+/* { dg-options "-fpic" } */
+
+struct link_map
+{
+  struct link_map *l_next;
+};
+struct rtld_global
+{
+  struct link_map *_ns_loaded;
+  char buf[4096];
+  struct link_map _dl_rtld_map;
+};
+extern struct rtld_global _rtld_global;
+static int _dlfo_main __attribute__ ((section (".data.rel.ro"), used));
+void
+_dlfo_process_initial (int ns)
+{
+  for (struct link_map *l = _rtld_global._ns_loaded; l != ((void *)0);
+   l = l->l_next)
+if (l == &_rtld_global._dl_rtld_map)
+  asm ("");
+}
diff --git a/gcc/varasm.cc b/gcc/varasm.cc
index deefbac5b7b2..0712b4860294 100644
--- a/gcc/varasm.cc
+++ b/gcc/varasm.cc
@@ -6884,6 +6884,9 @@ default_section_type_flags (tree decl, const char *name, 
int reloc)
 
   if (decl && TREE_CODE (decl) == FUNCTION_DECL)
 flags = SECTION_CODE;
+  else if (strcmp (name, ".data.rel.ro") == 0
+  || strcmp (name, ".data.rel.ro.local") == 0)
+flags = SECTION_WRITE | SECTION_RELRO;
   else if (decl)
 {
   enum section_category category
@@ -6897,12 +6900,7 @@ default_section_type_flags (tree decl, const char *name, 
int reloc)
flags = SECTION_WRITE;
 }
   else
-{
-  flags = SECTION_WRITE;
-  if (strcmp (name, ".data.rel.ro") == 0
- || strcmp (name, ".data.rel.ro.local") == 0)
-   flags |= SECTION_RELRO;
-}
+flags = SECTION_WRITE;
 
   if (decl && DECL_P (decl) && DECL_COMDAT_GROUP (decl))
 flags |= SECTION_LINKONCE;


[gcc r15-4840] Use LC_ALL=C when running selftests [PR117361]

2024-11-01 Thread David Malcolm via Gcc-cvs
https://gcc.gnu.org/g:8e95e064ea73d46b50a68b0104c18685251d326d

commit r15-4840-g8e95e064ea73d46b50a68b0104c18685251d326d
Author: David Malcolm 
Date:   Fri Nov 1 12:22:47 2024 -0400

Use LC_ALL=C when running selftests [PR117361]

gcc/ChangeLog:
PR bootstrap/117361
* Makefile.in (GCC_FOR_SELFTESTS): New.

gcc/c/ChangeLog:
PR bootstrap/117361
* Make-lang.in (s-selftest-c): Use GCC_FOR_SELFTESTS.
(selftest-c-gdb): Likewise.
(selftest-c-valgrind): Likewise.

gcc/cp/ChangeLog:
PR bootstrap/117361
* Make-lang.in (s-selftest-c++): Use GCC_FOR_SELFTESTS.
(selftest-c++-gdb): Likewise.
(selftest-c++-valgrind): Likewise.

gcc/rust/ChangeLog:
PR bootstrap/117361
* Make-lang.in (s-selftest-rust): Use GCC_FOR_SELFTESTS.
(selftest-rust-gdb): Likewise.
(selftest-rust-valgrind): Likewise.

Signed-off-by: David Malcolm 

Diff:
---
 gcc/Makefile.in   | 3 +++
 gcc/c/Make-lang.in| 6 +++---
 gcc/cp/Make-lang.in   | 6 +++---
 gcc/rust/Make-lang.in | 6 +++---
 4 files changed, 12 insertions(+), 9 deletions(-)

diff --git a/gcc/Makefile.in b/gcc/Makefile.in
index b4d34cc0b42e..2b80cdc046d9 100644
--- a/gcc/Makefile.in
+++ b/gcc/Makefile.in
@@ -487,6 +487,9 @@ T_STDINT_GCC_H = $(srcdir)/ginclude/stdint-gcc.h
 # Don't use this as a dependency--use $(GCC_PASSES).
 GCC_FOR_TARGET = $(STAGE_CC_WRAPPER) ./xgcc -B./ -B$(build_tooldir)/bin/ 
-isystem $(build_tooldir)/include -isystem $(build_tooldir)/sys-include 
-L$(objdir)/../ld $(TFLAGS)
 
+# The GCC to use when running selftests
+GCC_FOR_SELFTESTS = LC_ALL=C $(GCC_FOR_TARGET)
+
 # Set if the compiler was configured with --with-build-sysroot.
 SYSROOT_CFLAGS_FOR_TARGET = @SYSROOT_CFLAGS_FOR_TARGET@
 
diff --git a/gcc/c/Make-lang.in b/gcc/c/Make-lang.in
index 905ab9e79f74..e7082a935635 100644
--- a/gcc/c/Make-lang.in
+++ b/gcc/c/Make-lang.in
@@ -150,13 +150,13 @@ C_SELFTEST_DEPS = cc1$(exeext) $(SELFTEST_DEPS)
 
 # Run the C selftests:
 s-selftest-c: $(C_SELFTEST_DEPS)
-   $(GCC_FOR_TARGET) $(C_SELFTEST_FLAGS)
+   $(GCC_FOR_SELFTESTS) $(C_SELFTEST_FLAGS)
$(STAMP) $@
 
 # Convenience methods for running C selftests under gdb:
 .PHONY: selftest-c-gdb
 selftest-c-gdb: $(C_SELFTEST_DEPS)
-   $(GCC_FOR_TARGET) $(C_SELFTEST_FLAGS) \
+   $(GCC_FOR_SELFTESTS) $(C_SELFTEST_FLAGS) \
  -wrapper gdb,--args
 
 .PHONY: selftest-gdb
@@ -165,7 +165,7 @@ selftest-gdb: selftest-c-gdb
 # Convenience methods for running C selftests under valgrind:
 .PHONY: selftest-c-valgrind
 selftest-c-valgrind: $(C_SELFTEST_DEPS)
-   $(GCC_FOR_TARGET) $(C_SELFTEST_FLAGS) \
+   $(GCC_FOR_SELFTESTS) $(C_SELFTEST_FLAGS) \
  -wrapper valgrind,--leak-check=full
 
 .PHONY: selftest-valgrind
diff --git a/gcc/cp/Make-lang.in b/gcc/cp/Make-lang.in
index e792ea4ddf36..fb7ae59d9d4c 100644
--- a/gcc/cp/Make-lang.in
+++ b/gcc/cp/Make-lang.in
@@ -252,19 +252,19 @@ CPP_SELFTEST_FLAGS = -xc++ $(SELFTEST_FLAGS)
 
 # Run the C++ selftests
 s-selftest-c++: $(CPP_SELFTEST_DEPS)
-   $(GCC_FOR_TARGET) $(CPP_SELFTEST_FLAGS)
+   $(GCC_FOR_SELFTESTS) $(CPP_SELFTEST_FLAGS)
$(STAMP) $@
 
 # Convenience method for running C++ selftests under gdb:
 .PHONY: selftest-c++-gdb
 selftest-c++-gdb: $(CPP_SELFTEST_DEPS)
-   $(GCC_FOR_TARGET) $(CPP_SELFTEST_FLAGS) \
+   $(GCC_FOR_SELFTESTS) $(CPP_SELFTEST_FLAGS) \
  -wrapper gdb,--args
 
 # Convenience method for running C++ selftests under valgrind:
 .PHONY: selftest-c++-valgrind
 selftest-c++-valgrind: $(CPP_SELFTEST_DEPS)
-   $(GCC_FOR_TARGET) $(CPP_SELFTEST_FLAGS) \
+   $(GCC_FOR_SELFTESTS) $(CPP_SELFTEST_FLAGS) \
  -wrapper valgrind,--leak-check=full
 
 # 'make check' in gcc/ looks for check-c++, as do all toplevel C++-related
diff --git a/gcc/rust/Make-lang.in b/gcc/rust/Make-lang.in
index aed9a998c80a..69178557059e 100644
--- a/gcc/rust/Make-lang.in
+++ b/gcc/rust/Make-lang.in
@@ -338,19 +338,19 @@ RUST_SELFTEST_DEPS = crab1$(exeext) $(SELFTEST_DEPS)
 
 # Run the rust selftests
 s-selftest-rust: $(RUST_SELFTEST_DEPS)
-   $(GCC_FOR_TARGET) $(RUST_SELFTEST_FLAGS)
+   $(GCC_FOR_SELFTESTS) $(RUST_SELFTEST_FLAGS)
$(STAMP) $@
 
 # Convenience methods for running rust selftests under gdb:
 .PHONY: selftest-rust-gdb
 selftest-rust-gdb: $(RUST_SELFTEST_DEPS)
-   $(GCC_FOR_TARGET) $(RUST_SELFTEST_FLAGS) \
+   $(GCC_FOR_SELFTESTS) $(RUST_SELFTEST_FLAGS) \
  -wrapper gdb,--args
 
 # Convenience methods for running rust selftests under valgrind:
 .PHONY: selftest-rust-valgrind
 selftest-rust-valgrind: $(RUST_SELFTEST_DEPS)
-   $(GCC_FOR_TARGET) $(RUST_SELFTEST_FLAGS) \
+   $(GCC_FOR_SELFTESTS) $(RUST_SELFTEST_FLAGS) \
  -wrapper valgrind,--leak-check=full
 
 # Install info documentation for the front end, if it is present in the source 
directory. This t

[gcc r15-4841] analyzer: fix -Wunused-parameter warning [PR117373]

2024-11-01 Thread David Malcolm via Gcc-cvs
https://gcc.gnu.org/g:36a92c3829ba7a2683c3b095356b9ed08978420a

commit r15-4841-g36a92c3829ba7a2683c3b095356b9ed08978420a
Author: David Malcolm 
Date:   Fri Nov 1 12:22:53 2024 -0400

analyzer: fix -Wunused-parameter warning [PR117373]

gcc/analyzer/ChangeLog:
PR analyzer/117373
* infinite-loop.cc
(infinite_loop_diagnostic::describe_final_event): Fix
-Wunused-parameter warning

Signed-off-by: David Malcolm 

Diff:
---
 gcc/analyzer/infinite-loop.cc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/analyzer/infinite-loop.cc b/gcc/analyzer/infinite-loop.cc
index 4abfb3cdc59c..ac589ed5dbdf 100644
--- a/gcc/analyzer/infinite-loop.cc
+++ b/gcc/analyzer/infinite-loop.cc
@@ -223,7 +223,7 @@ public:
 
   bool
   describe_final_event (pretty_printer &pp,
-   const evdesc::final_event &ev) final override
+   const evdesc::final_event &) final override
   {
 pp_string (&pp, "infinite loop here");
 return true;


[gcc r15-4843] c++: Add testcase for now fixed issue [PR101887]

2024-11-01 Thread Simon Martin via Gcc-cvs
https://gcc.gnu.org/g:fe919da3c395d2214ffc81ad4f51f8344ad5a5c1

commit r15-4843-gfe919da3c395d2214ffc81ad4f51f8344ad5a5c1
Author: Simon Martin 
Date:   Thu Oct 31 15:41:11 2024 +0100

c++: Add testcase for now fixed issue [PR101887]

The testcase in PR101887 has been working since the fix for PR104846,
via r12-7599-gac8310dd122172.

This patch simply adds the case to the testsuite.

PR c++/101887

gcc/testsuite/ChangeLog:

* g++.dg/init/delete5.C: Add testcase from PR c++/101887.

Diff:
---
 gcc/testsuite/g++.dg/init/delete5.C | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/gcc/testsuite/g++.dg/init/delete5.C 
b/gcc/testsuite/g++.dg/init/delete5.C
index 3555f43bbb09..3fff93d846ec 100644
--- a/gcc/testsuite/g++.dg/init/delete5.C
+++ b/gcc/testsuite/g++.dg/init/delete5.C
@@ -1,8 +1,9 @@
 // PR c++/104846
+// PR c++/101887
 // { dg-do compile { target c++14 } }
 
 struct S {
   auto operator delete (void *) {} // { dg-error ".operator delete. must 
return type .void'" }
+  auto operator delete (void*, __SIZE_TYPE__); // { dg-error ".operator 
delete. must return type .void'" }
   auto operator delete[] (void *) {} // { dg-error ".operator delete. must 
return type .void'" }
 };
-


[gcc r15-4844] LoongArch: testsuite: Add -O for jump-table-annotate.c

2024-11-01 Thread Xi Ruoyao via Gcc-cvs
https://gcc.gnu.org/g:caf6b6fdfdaa1d0d78b8d740aa0e0646ca182a2a

commit r15-4844-gcaf6b6fdfdaa1d0d78b8d740aa0e0646ca182a2a
Author: Xi Ruoyao 
Date:   Sat Nov 2 01:26:47 2024 +0800

LoongArch: testsuite: Add -O for jump-table-annotate.c

Without optimization, GCC does not emit a jump table for the test case.

I'm not sure if the test case has been wrong in the first place or
something has changed in these months...

gcc/testsuite/ChangeLog:

* gcc.target/loongarch/jump-table-annotate.c
(dg-additional-options): Add -O.

Diff:
---
 gcc/testsuite/gcc.target/loongarch/jump-table-annotate.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/testsuite/gcc.target/loongarch/jump-table-annotate.c 
b/gcc/testsuite/gcc.target/loongarch/jump-table-annotate.c
index 9d58e60e39a3..1895f6f03b8c 100644
--- a/gcc/testsuite/gcc.target/loongarch/jump-table-annotate.c
+++ b/gcc/testsuite/gcc.target/loongarch/jump-table-annotate.c
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-additional-options "-mannotate-tablejump" } */
+/* { dg-additional-options "-O -mannotate-tablejump" } */
 
 extern void asdf(int);
 void foo(int x) {


[gcc r15-4838] libstdc++: Remove stray whitespace in #endif

2024-11-01 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:063196e3933ddbe6c662f4996f68567d348a99f1

commit r15-4838-g063196e3933ddbe6c662f4996f68567d348a99f1
Author: Jonathan Wakely 
Date:   Fri Nov 1 12:25:07 2024 +

libstdc++: Remove stray whitespace in #endif

This isn't nested within another #if group so shouldn't be indented like
this.

libstdc++-v3/ChangeLog:

* libsupc++/typeinfo: Remove whitespace in #endif

Diff:
---
 libstdc++-v3/libsupc++/typeinfo | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libstdc++-v3/libsupc++/typeinfo b/libstdc++-v3/libsupc++/typeinfo
index 71066eb1e465..721268cb3fa3 100644
--- a/libstdc++-v3/libsupc++/typeinfo
+++ b/libstdc++-v3/libsupc++/typeinfo
@@ -212,7 +212,7 @@ namespace std
 return false;
 #endif
   }
-# endif
+#endif
 
 
   /**


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

2024-11-01 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:a51d220377ab8117305567e888a942d127ef6a48

commit r15-4839-ga51d220377ab8117305567e888a942d127ef6a48
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.

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 r15-4848] c++: Attempt to implement C++26 P3034R1 - Module Declarations Shouldn't be Macros [PR114461]

2024-11-01 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:1ae24f7e0bdbdeaef9265a053a737af11f8393d2

commit r15-4848-g1ae24f7e0bdbdeaef9265a053a737af11f8393d2
Author: Jakub Jelinek 
Date:   Fri Nov 1 19:42:28 2024 +0100

c++: Attempt to implement C++26 P3034R1 - Module Declarations Shouldn't be 
Macros [PR114461]

This is an attempt to implement the https://wg21.link/p3034r1 paper,
but I'm afraid the wording in the paper is bad for multiple reasons.
I think I understand the intent, that the module name and partition
if any shouldn't come from macros so that they can be scanned for
without preprocessing, but on the other side doesn't want to disable
macro expansion in pp-module altogether, because e.g. the optional
attribute in module-declaration would be nice to come from macros
as which exact attribute is needed might need to be decided based on
preprocessor checks.
The paper added https://eel.is/c++draft/cpp.module#2
which uses partly the wording from https://eel.is/c++draft/cpp.module#1

The first issue I see is that using that "defined as an object-like macro"
from there means IMHO something very different in those 2 paragraphs.
As per https://eel.is/c++draft/cpp.pre#7.sentence-1 preprocessing tokens
in preprocessing directives aren't subject to macro expansion unless
otherwise stated, and so the export and module tokens aren't expanded
and so the requirement that they aren't defined as an object-like macro
makes perfect sense.  The problem with the new paragraph is that
https://eel.is/c++draft/cpp.module#3.sentence-1 says that the rest of
the tokens are macro expanded and after macro expansion none of the
tokens can be defined as an object-like macro, if they would be, they'd
be expanded to that.  So, I think either the wording needs to change
such that not all preprocessing tokens after module are macro expanded,
only those which are after the pp-module-name and if any pp-module-partition
tokens, or all tokens after module are macro expanded but none of the 
tokens in
pp-module-name and pp-module-partition if any must come from macro
expansion.  The patch below implements it as if the former would be
specified (but see later), so essentially scans the preprocessing tokens
after module without expansion, if the first one is an identifier, it
disables expansion for it and then if followed by . or : expects another
such identifier (again with disabled expansion), but stops after second
: is seen.

Second issue is that while the global-module-fragment start is fine, matches
the syntax of the new paragraph where the pp-tokens[opt] aren't present,
there is also private-module-fragment in the syntax where module is
followed by : private ; and in that case the colon doesn't match the
pp-module-name grammar and appears now to be invalid.  I think the
https://eel.is/c++draft/cpp.module#2
paragraph needs to change so that it allows also that pp-tokens of
a pp-module may also be : pp-tokens[opt] (and in that case, I think
the colon shouldn't come from a macro and private and/or ; can).

Third issue is that there are too many pp-tokens in
https://eel.is/c++draft/cpp.module , one is all the tokens between
module keyword and the semicolon and one is the optional extra tokens
after pp-module-partition (if any, if missing, after pp-module).
Perhaps introducing some other non-terminal would help talking about it?
So in "where the pp-tokens (if any) shall not begin with a ( preprocessing
token" it isn't obvious which pp-tokens it is talking about (my assumption
is the latter) and also whether ( can't appear there just before macro
expansion or also after expansion.  The patch expects only before expansion,
so
 #define F ();
 export module foo F
would be valid during preprocessing but obviously invalid during
compilation, but
 #define foo(n) n;
 export module foo (3)
would be invalid already during preprocessing.

The last issue applies only if the first issue is resolved to allow
expansion of tokens after : if first token, or after pp-module-partition
if present or after pp-module-name if present.  When non-preprocessing
scanner sees
 export module foo.bar:baz.qux;
it knows nothing can come from preprocessing macros and is ok, but if it
sees
 export module foo.bar:baz qux
then it can't know whether it will be
 export module foo.bar:baz;
or
 export module foo.bar:baz [[]];
or
 export module foo.bar:baz.freddy.garply;
because qux could be validly a macro, which expands to ; or [[]];
or .freddy.garply; etc.  So, either the non-preprocessing scanner would
need to note it as possible export of foo.bar:baz* module partitions
and preprocess if it needs to know the details or just compile, or if that
is not ok, the wording would need to 

[gcc(refs/users/aoliva/heads/testme)] introduce ifcombine_replace_cond

2024-11-01 Thread Alexandre Oliva via Gcc-cvs
https://gcc.gnu.org/g:668d14d5bff534a05450673feaa6182cb66a40d3

commit 668d14d5bff534a05450673feaa6182cb66a40d3
Author: Alexandre Oliva 
Date:   Thu Oct 24 05:25:26 2024 -0300

introduce ifcombine_replace_cond

Refactor ifcombine_ifandif, moving the common code from the various
paths that apply the combined condition to a new function.


for  gcc/ChangeLog

* tree-ssa-ifcombine.cc (ifcombine_replace_cond): Factor out
of...
(ifcombine_ifandif): ... this.  Leave it for the above to
gimplify and invert the condition.

Diff:
---
 gcc/tree-ssa-ifcombine.cc | 137 ++
 1 file changed, 65 insertions(+), 72 deletions(-)

diff --git a/gcc/tree-ssa-ifcombine.cc b/gcc/tree-ssa-ifcombine.cc
index 0a2ba970548c..6dcf5e6efe1d 100644
--- a/gcc/tree-ssa-ifcombine.cc
+++ b/gcc/tree-ssa-ifcombine.cc
@@ -399,6 +399,51 @@ update_profile_after_ifcombine (basic_block inner_cond_bb,
   outer2->probability = profile_probability::never ();
 }
 
+/* Replace the conditions in INNER_COND with COND.
+   Replace OUTER_COND with a constant.  */
+
+static bool
+ifcombine_replace_cond (gcond *inner_cond, bool inner_inv,
+   gcond *outer_cond, bool outer_inv,
+   tree cond, bool must_canon, tree cond2)
+{
+  bool result_inv = inner_inv;
+
+  gcc_checking_assert (!cond2);
+
+  if (result_inv)
+cond = fold_build1 (TRUTH_NOT_EXPR, TREE_TYPE (cond), cond);
+
+  if (tree tcanon = canonicalize_cond_expr_cond (cond))
+cond = tcanon;
+  else if (must_canon)
+return false;
+
+{
+  if (!is_gimple_condexpr_for_cond (cond))
+   {
+ gimple_stmt_iterator gsi = gsi_for_stmt (inner_cond);
+ cond = force_gimple_operand_gsi_1 (&gsi, cond,
+is_gimple_condexpr_for_cond,
+NULL, true, GSI_SAME_STMT);
+   }
+  gimple_cond_set_condition_from_tree (inner_cond, cond);
+  update_stmt (inner_cond);
+
+  /* Leave CFG optimization to cfg_cleanup.  */
+  gimple_cond_set_condition_from_tree (outer_cond,
+  outer_inv
+  ? boolean_false_node
+  : boolean_true_node);
+  update_stmt (outer_cond);
+}
+
+  update_profile_after_ifcombine (gimple_bb (inner_cond),
+ gimple_bb (outer_cond));
+
+  return true;
+}
+
 /* If-convert on a and pattern with a common else block.  The inner
if is specified by its INNER_COND_BB, the outer by OUTER_COND_BB.
inner_inv, outer_inv indicate whether the conditions are inverted.
@@ -408,7 +453,6 @@ static bool
 ifcombine_ifandif (basic_block inner_cond_bb, bool inner_inv,
   basic_block outer_cond_bb, bool outer_inv)
 {
-  bool result_inv = inner_inv;
   gimple_stmt_iterator gsi;
   tree name1, name2, bit1, bit2, bits1, bits2;
 
@@ -446,26 +490,13 @@ ifcombine_ifandif (basic_block inner_cond_bb, bool 
inner_inv,
   t2 = fold_build2 (BIT_AND_EXPR, TREE_TYPE (name1), name1, t);
   t2 = force_gimple_operand_gsi (&gsi, t2, true, NULL_TREE,
 true, GSI_SAME_STMT);
-  t = fold_build2 (result_inv ? NE_EXPR : EQ_EXPR,
-  boolean_type_node, t2, t);
-  t = canonicalize_cond_expr_cond (t);
-  if (!t)
-   return false;
-  if (!is_gimple_condexpr_for_cond (t))
-   {
- gsi = gsi_for_stmt (inner_cond);
- t = force_gimple_operand_gsi_1 (&gsi, t, is_gimple_condexpr_for_cond,
- NULL, true, GSI_SAME_STMT);
-   }
-  gimple_cond_set_condition_from_tree (inner_cond, t);
-  update_stmt (inner_cond);
 
-  /* Leave CFG optimization to cfg_cleanup.  */
-  gimple_cond_set_condition_from_tree (outer_cond,
-   outer_inv ? boolean_false_node : boolean_true_node);
-  update_stmt (outer_cond);
+  t = fold_build2 (EQ_EXPR, boolean_type_node, t2, t);
 
-  update_profile_after_ifcombine (inner_cond_bb, outer_cond_bb);
+  if (!ifcombine_replace_cond (inner_cond, inner_inv,
+  outer_cond, outer_inv,
+  t, true, NULL_TREE))
+   return false;
 
   if (dump_file)
{
@@ -485,9 +516,8 @@ ifcombine_ifandif (basic_block inner_cond_bb, bool 
inner_inv,
  In that case remove the outer test and change the inner one to
  test for name & (bits1 | bits2) != 0.  */
   else if (recognize_bits_test (inner_cond, &name1, &bits1, !inner_inv)
-  && recognize_bits_test (outer_cond, &name2, &bits2, !outer_inv))
+  && recognize_bits_test (outer_cond, &name2, &bits2, !outer_inv))
 {
-  gimple_stmt_iterator gsi;
   tree t;
 
   if ((TREE_CODE (name1) == SSA_NAME
@@ -530,33 +560,14 @@ ifcombine_ifandif (basic_block inner_cond_bb, boo

[gcc(refs/users/aoliva/heads/testme)] extend ifcombine_replace_cond to handle noncontiguous ifcombine

2024-11-01 Thread Alexandre Oliva via Gcc-cvs
https://gcc.gnu.org/g:48872a21ea0b9bc44a2c98acc4567d32ac2255d0

commit 48872a21ea0b9bc44a2c98acc4567d32ac2255d0
Author: Alexandre Oliva 
Date:   Thu Oct 24 05:25:30 2024 -0300

extend ifcombine_replace_cond to handle noncontiguous ifcombine

Prepare to handle noncontiguous ifcombine, introducing logic to modify
the outer condition when needed.  There are two cases worth
mentioning:

- when blocks are noncontiguous, we have to place the combined
  condition in the outer block to avoid pessimizing carefully crafted
  short-circuited tests;

- even when blocks are contiguous, we prepare for situations in which
  the combined condition has two tests, one to be placed in outer and
  the other in inner.  This circumstance will not come up when
  noncontiguous ifcombine is first enabled, but it will when
  an improved fold_truth_andor is integrated with ifcombine.

Combining the condition from inner into outer may require moving SSA
DEFs used in the inner condition, and the changes implement this as
well.


for  gcc/ChangeLog

* tree-ssa-ifcombine.cc: Include bitmap.h.
(ifcombine_mark_ssa_name): New.
(struct ifcombine_mark_ssa_name_t): New.
(ifcombine_mark_ssa_name_walk): New.
(ifcombine_replace_cond): Prepare to handle noncontiguous and
split-condition ifcombine.

Diff:
---
 gcc/tree-ssa-ifcombine.cc | 175 --
 1 file changed, 170 insertions(+), 5 deletions(-)

diff --git a/gcc/tree-ssa-ifcombine.cc b/gcc/tree-ssa-ifcombine.cc
index b5b72be29bbf..42b6055121c1 100644
--- a/gcc/tree-ssa-ifcombine.cc
+++ b/gcc/tree-ssa-ifcombine.cc
@@ -42,6 +42,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "tree-ssa.h"
 #include "attribs.h"
 #include "asan.h"
+#include "bitmap.h"
 
 #ifndef LOGICAL_OP_NON_SHORT_CIRCUIT
 #define LOGICAL_OP_NON_SHORT_CIRCUIT \
@@ -460,17 +461,57 @@ update_profile_after_ifcombine (basic_block inner_cond_bb,
 }
 }
 
-/* Replace the conditions in INNER_COND with COND.
-   Replace OUTER_COND with a constant.  */
+/* Set NAME's bit in USED if OUTER dominates it.  */
+
+static void
+ifcombine_mark_ssa_name (bitmap used, tree name, basic_block outer)
+{
+  if (SSA_NAME_IS_DEFAULT_DEF (name))
+return;
+
+  gimple *def = SSA_NAME_DEF_STMT (name);
+  basic_block bb = gimple_bb (def);
+  if (!dominated_by_p (CDI_DOMINATORS, bb, outer))
+return;
+
+  bitmap_set_bit (used, SSA_NAME_VERSION (name));
+}
+
+/* Data structure passed to ifcombine_mark_ssa_name.  */
+struct ifcombine_mark_ssa_name_t
+{
+  /* SSA_NAMEs that have been referenced.  */
+  bitmap used;
+  /* Dominating block of DEFs that might need moving.  */
+  basic_block outer;
+};
+
+/* Mark in DATA->used any SSA_NAMEs used in *t.  */
+
+static tree
+ifcombine_mark_ssa_name_walk (tree *t, int *, void *data_)
+{
+  ifcombine_mark_ssa_name_t *data = (ifcombine_mark_ssa_name_t *)data_;
+
+  if (*t && TREE_CODE (*t) == SSA_NAME)
+ifcombine_mark_ssa_name (data->used, *t, data->outer);
+
+  return NULL;
+}
+
+/* Replace the conditions in INNER_COND and OUTER_COND with COND and COND2.
+   COND and COND2 are computed for insertion at INNER_COND, with OUTER_COND
+   replaced with a constant, but if there are intervening blocks, it's best to
+   adjust COND for insertion at OUTER_COND, placing COND2 at INNER_COND.  */
 
 static bool
 ifcombine_replace_cond (gcond *inner_cond, bool inner_inv,
gcond *outer_cond, bool outer_inv,
tree cond, bool must_canon, tree cond2)
 {
-  bool result_inv = inner_inv;
-
-  gcc_checking_assert (!cond2);
+  bool outer_p = cond2 || (single_pred (gimple_bb (inner_cond))
+  != gimple_bb (outer_cond));
+  bool result_inv = outer_p ? outer_inv : inner_inv;
 
   if (result_inv)
 cond = fold_build1 (TRUTH_NOT_EXPR, TREE_TYPE (cond), cond);
@@ -480,6 +521,130 @@ ifcombine_replace_cond (gcond *inner_cond, bool inner_inv,
   else if (must_canon)
 return false;
 
+  if (outer_p)
+{
+  {
+   auto_bitmap used;
+   basic_block outer_bb = gimple_bb (outer_cond);
+
+   bitmap_tree_view (used);
+
+   /* Mark SSA DEFs that are referenced by cond and may thus need to be
+  moved to outer.  */
+   {
+ ifcombine_mark_ssa_name_t data = { used, outer_bb };
+ walk_tree (&cond, ifcombine_mark_ssa_name_walk, &data, NULL);
+   }
+
+   if (!bitmap_empty_p (used))
+ {
+   /* Iterate up from inner_cond, moving DEFs identified as used by
+  cond, and marking USEs in the DEFs for moving as well.  */
+   gimple_stmt_iterator gsins = gsi_for_stmt (outer_cond);
+   for (basic_block bb = gimple_bb (inner_cond);
+bb != outer_bb; bb = single_pred (bb))
+ {
+   for (gimple_stmt_iterator gsitr = gsi_last_bb (bb);

[gcc(refs/users/aoliva/heads/testme)] adjust update_profile_after_ifcombine for noncontiguous ifcombine

2024-11-01 Thread Alexandre Oliva via Gcc-cvs
https://gcc.gnu.org/g:8aef26ff84fcbd73144b3fde05e15049fd53bc47

commit 8aef26ff84fcbd73144b3fde05e15049fd53bc47
Author: Alexandre Oliva 
Date:   Thu Oct 24 05:25:28 2024 -0300

adjust update_profile_after_ifcombine for noncontiguous ifcombine

Prepare for ifcombining noncontiguous blocks, adding (still unused)
logic to the ifcombine profile updater to handle such cases.


for  gcc/ChangeLog

* tree-ssa-ifcombine.cc (known_succ_p): New.
(update_profile_after_ifcombine): Handle noncontiguous blocks.

Diff:
---
 gcc/tree-ssa-ifcombine.cc | 109 --
 1 file changed, 85 insertions(+), 24 deletions(-)

diff --git a/gcc/tree-ssa-ifcombine.cc b/gcc/tree-ssa-ifcombine.cc
index 6dcf5e6efe1d..b5b72be29bbf 100644
--- a/gcc/tree-ssa-ifcombine.cc
+++ b/gcc/tree-ssa-ifcombine.cc
@@ -49,6 +49,21 @@ along with GCC; see the file COPYING3.  If not see
 false) >= 2)
 #endif
 
+/* Return FALSE iff the COND_BB ends with a conditional whose result is not a
+   known constant.  */
+
+static bool
+known_succ_p (basic_block cond_bb)
+{
+  gcond *cond = safe_dyn_cast  (*gsi_last_bb (cond_bb));
+
+  if (!cond)
+return true;
+
+  return (CONSTANT_CLASS_P (gimple_cond_lhs (cond))
+ && CONSTANT_CLASS_P (gimple_cond_rhs (cond)));
+}
+
 /* This pass combines COND_EXPRs to simplify control flow.  It
currently recognizes bit tests and comparisons in chains that
represent logical and or logical or of two COND_EXPRs.
@@ -356,14 +371,28 @@ recognize_bits_test (gcond *cond, tree *name, tree *bits, 
bool inv)
 }
 
 
-/* Update profile after code in outer_cond_bb was adjusted so
-   outer_cond_bb has no condition.  */
+/* Update profile after code in either outer_cond_bb or inner_cond_bb was
+   adjusted so that it has no condition.  */
 
 static void
 update_profile_after_ifcombine (basic_block inner_cond_bb,
basic_block outer_cond_bb)
 {
-  edge outer_to_inner = find_edge (outer_cond_bb, inner_cond_bb);
+  /* In the following we assume that inner_cond_bb has single predecessor.  */
+  gcc_assert (single_pred_p (inner_cond_bb));
+
+  basic_block outer_to_inner_bb = inner_cond_bb;
+  profile_probability prob = profile_probability::always ();
+  for (;;)
+{
+  basic_block parent = single_pred (outer_to_inner_bb);
+  prob *= find_edge (parent, outer_to_inner_bb)->probability;
+  if (parent == outer_cond_bb)
+   break;
+  outer_to_inner_bb = parent;
+}
+
+  edge outer_to_inner = find_edge (outer_cond_bb, outer_to_inner_bb);
   edge outer2 = (EDGE_SUCC (outer_cond_bb, 0) == outer_to_inner
 ? EDGE_SUCC (outer_cond_bb, 1)
 : EDGE_SUCC (outer_cond_bb, 0));
@@ -374,29 +403,61 @@ update_profile_after_ifcombine (basic_block inner_cond_bb,
 std::swap (inner_taken, inner_not_taken);
   gcc_assert (inner_taken->dest == outer2->dest);
 
-  /* In the following we assume that inner_cond_bb has single predecessor.  */
-  gcc_assert (single_pred_p (inner_cond_bb));
-
-  /* Path outer_cond_bb->(outer2) needs to be merged into path
- outer_cond_bb->(outer_to_inner)->inner_cond_bb->(inner_taken)
- and probability of inner_not_taken updated.  */
-
-  inner_cond_bb->count = outer_cond_bb->count;
+  if (outer_to_inner_bb == inner_cond_bb
+  && known_succ_p (outer_cond_bb))
+{
+  /* Path outer_cond_bb->(outer2) needs to be merged into path
+outer_cond_bb->(outer_to_inner)->inner_cond_bb->(inner_taken)
+and probability of inner_not_taken updated.  */
+
+  inner_cond_bb->count = outer_cond_bb->count;
+
+  /* Handle special case where inner_taken probability is always. In this
+case we know that the overall outcome will be always as well, but
+combining probabilities will be conservative because it does not know
+that outer2->probability is inverse of
+outer_to_inner->probability.  */
+  if (inner_taken->probability == profile_probability::always ())
+   ;
+  else
+   inner_taken->probability = outer2->probability
+ + outer_to_inner->probability * inner_taken->probability;
+  inner_not_taken->probability = profile_probability::always ()
+   - inner_taken->probability;
 
-  /* Handle special case where inner_taken probability is always. In this case
- we know that the overall outcome will be always as well, but combining
- probabilities will be conservative because it does not know that
- outer2->probability is inverse of outer_to_inner->probability.  */
-  if (inner_taken->probability == profile_probability::always ())
-;
+  outer_to_inner->probability = profile_probability::always ();
+  outer2->probability = profile_probability::never ();
+}
+  else if (known_succ_p (inner_cond_bb))
+{
+  /* Path inner_cond_bb->(inner_taken) needs to be merged into path
+outer_cond_bb->(outer2).  We've accumulated

[gcc(refs/users/aoliva/heads/testme)] check ifcombine bitmap count

2024-11-01 Thread Alexandre Oliva via Gcc-cvs
https://gcc.gnu.org/g:590d8e0955031bbdf5bda1f81eaf0a782cef226b

commit 590d8e0955031bbdf5bda1f81eaf0a782cef226b
Author: Alexandre Oliva 
Date:   Sat Nov 2 00:42:23 2024 -0300

check ifcombine bitmap count

Diff:
---
 gcc/tree-ssa-ifcombine.cc | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/gcc/tree-ssa-ifcombine.cc b/gcc/tree-ssa-ifcombine.cc
index ac4811e42e08..3527354106d8 100644
--- a/gcc/tree-ssa-ifcombine.cc
+++ b/gcc/tree-ssa-ifcombine.cc
@@ -547,7 +547,7 @@ ifcombine_replace_cond (gcond *inner_cond, bool inner_inv,
auto_bitmap used;
basic_block outer_bb = gimple_bb (outer_cond);
 
-   bitmap_tree_view (used);
+   /* bitmap_tree_view (used); */
 
/* Mark SSA DEFs that are referenced by cond and may thus need to be
   moved to outer.  */
@@ -558,6 +558,7 @@ ifcombine_replace_cond (gcond *inner_cond, bool inner_inv,
 
if (!bitmap_empty_p (used))
  {
+   gcc_checking_assert (bitmap_count_bits (used) < 5);
/* Iterate up from inner_cond, moving DEFs identified as used by
   cond, and marking USEs in the DEFs for moving as well.  */
gimple_stmt_iterator gsins = gsi_for_stmt (outer_cond);


[gcc(refs/users/aoliva/heads/testme)] handle TRUTH_ANDIF cond exprs in ifcombine_replace_cond

2024-11-01 Thread Alexandre Oliva via Gcc-cvs
https://gcc.gnu.org/g:0902a711b665a66a7ce813f00fa26ab8a534581e

commit 0902a711b665a66a7ce813f00fa26ab8a534581e
Author: Alexandre Oliva 
Date:   Thu Oct 24 15:35:40 2024 -0300

handle TRUTH_ANDIF cond exprs in ifcombine_replace_cond

The upcoming move of fold_truth_andor to ifcombine brings with it the
possibility of TRUTH_ANDIF cond exprs.  Handle them by splitting the
cond so as to best use both BB insertion points, but only if they're
contiguous.


for  gcc/ChangeLog

* tree-ssa-ifcombine.c (ifcombine_replace_cond): Support
TRUTH_ANDIF cond exprs.

Diff:
---
 gcc/tree-ssa-ifcombine.cc | 11 +++
 1 file changed, 11 insertions(+)

diff --git a/gcc/tree-ssa-ifcombine.cc b/gcc/tree-ssa-ifcombine.cc
index b791bc0155c2..ac4811e42e08 100644
--- a/gcc/tree-ssa-ifcombine.cc
+++ b/gcc/tree-ssa-ifcombine.cc
@@ -518,6 +518,17 @@ ifcombine_replace_cond (gcond *inner_cond, bool inner_inv,
gcond *outer_cond, bool outer_inv,
tree cond, bool must_canon, tree cond2)
 {
+  /* Split cond into cond2 if they're contiguous.  ??? We might be able to
+ handle ORIF as well, inverting both conditions, but it's not clear that
+ this would be enough, and it never comes up.  */
+  if (!cond2
+  && TREE_CODE (cond) == TRUTH_ANDIF_EXPR
+  && single_pred (gimple_bb (inner_cond)) == gimple_bb (outer_cond))
+{
+  cond2 = TREE_OPERAND (cond, 1);
+  cond = TREE_OPERAND (cond, 0);
+}
+
   bool outer_p = cond2 || (single_pred (gimple_bb (inner_cond))
   != gimple_bb (outer_cond));
   bool result_inv = outer_p ? outer_inv : inner_inv;


[gcc(refs/users/aoliva/heads/testme)] ifcombine across noncontiguous blocks

2024-11-01 Thread Alexandre Oliva via Gcc-cvs
https://gcc.gnu.org/g:d1c6e0b8062eb8667fecf933d3c7ff15f875c65b

commit d1c6e0b8062eb8667fecf933d3c7ff15f875c65b
Author: Alexandre Oliva 
Date:   Thu Oct 24 05:25:33 2024 -0300

ifcombine across noncontiguous blocks

Rework ifcombine to support merging conditions from noncontiguous
blocks.  This depends on earlier preparation changes.

The function that attempted to ifcombine a block with its immediate
predecessor, tree_ssa_ifcombine_bb, now loops over dominating blocks
eligible for ifcombine, attempting to combine with them.

The function that actually drives the combination of a pair of blocks,
tree_ssa_ifcombine_bb_1, now takes an additional parameter: the
successor of outer that leads to inner.

The function that recognizes if_then_else patterns is modified to
enable testing without distinguishing between then and else, or to
require nondegenerate conditions, that aren't worth combining with.


for  gcc/ChangeLog

* tree-ssa-ifcombine.cc (recognize_if_then_else): Support
relaxed then/else testing; require nondegenerate condition
otherwise.
(tree_ssa_ifcombine_bb_1): Add outer_succ_bb parm, use it
instead of inner_cond_bb.  Adjust callers.
(tree_ssa_ifcombine_bb): Loop over dominating outer blocks
eligible for ifcombine.
(pass_tree_ifcombine::execute): Noted potential need for
changes to the post-combine logic.

Diff:
---
 gcc/tree-ssa-ifcombine.cc | 152 +-
 1 file changed, 123 insertions(+), 29 deletions(-)

diff --git a/gcc/tree-ssa-ifcombine.cc b/gcc/tree-ssa-ifcombine.cc
index 42b6055121c1..b791bc0155c2 100644
--- a/gcc/tree-ssa-ifcombine.cc
+++ b/gcc/tree-ssa-ifcombine.cc
@@ -85,25 +85,34 @@ known_succ_p (basic_block cond_bb)
is left to CFG cleanup and DCE.  */
 
 
-/* Recognize a if-then-else CFG pattern starting to match with the
-   COND_BB basic-block containing the COND_EXPR.  The recognized
-   then end else blocks are stored to *THEN_BB and *ELSE_BB.  If
-   *THEN_BB and/or *ELSE_BB are already set, they are required to
-   match the then and else basic-blocks to make the pattern match.
-   Returns true if the pattern matched, false otherwise.  */
+/* Recognize a if-then-else CFG pattern starting to match with the COND_BB
+   basic-block containing the COND_EXPR.  If !SUCCS_ANY, the condition must not
+   resolve to a constant for a match.  Returns true if the pattern matched,
+   false otherwise.  In case of a !SUCCS_ANY match, the recognized then end
+   else blocks are stored to *THEN_BB and *ELSE_BB.  If *THEN_BB and/or
+   *ELSE_BB are already set, they are required to match the then and else
+   basic-blocks to make the pattern match.  If SUCCS_ANY, *THEN_BB and *ELSE_BB
+   will not be filled in, and they will be found to match even if reversed.  */
 
 static bool
 recognize_if_then_else (basic_block cond_bb,
-   basic_block *then_bb, basic_block *else_bb)
+   basic_block *then_bb, basic_block *else_bb,
+   bool succs_any = false)
 {
   edge t, e;
 
-  if (EDGE_COUNT (cond_bb->succs) != 2)
+  if (EDGE_COUNT (cond_bb->succs) != 2
+  || (!succs_any && known_succ_p (cond_bb)))
 return false;
 
   /* Find the then/else edges.  */
   t = EDGE_SUCC (cond_bb, 0);
   e = EDGE_SUCC (cond_bb, 1);
+
+  if (succs_any)
+return ((t->dest == *then_bb && e->dest == *else_bb)
+   || (t->dest == *else_bb && e->dest == *then_bb));
+
   if (!(t->flags & EDGE_TRUE_VALUE))
 std::swap (t, e);
   if (!(t->flags & EDGE_TRUE_VALUE)
@@ -888,19 +897,21 @@ ifcombine_ifandif (basic_block inner_cond_bb, bool 
inner_inv,
 /* Helper function for tree_ssa_ifcombine_bb.  Recognize a CFG pattern and
dispatch to the appropriate if-conversion helper for a particular
set of INNER_COND_BB, OUTER_COND_BB, THEN_BB and ELSE_BB.
-   PHI_PRED_BB should be one of INNER_COND_BB, THEN_BB or ELSE_BB.  */
+   PHI_PRED_BB should be one of INNER_COND_BB, THEN_BB or ELSE_BB.
+   OUTER_SUCC_BB is the successor of OUTER_COND_BB on the path towards
+   INNER_COND_BB.  */
 
 static bool
 tree_ssa_ifcombine_bb_1 (basic_block inner_cond_bb, basic_block outer_cond_bb,
 basic_block then_bb, basic_block else_bb,
-basic_block phi_pred_bb)
+basic_block phi_pred_bb, basic_block outer_succ_bb)
 {
   /* The && form is characterized by a common else_bb with
  the two edges leading to it mergable.  The latter is
  guaranteed by matching PHI arguments in the else_bb and
  the inner cond_bb having no side-effects.  */
   if (phi_pred_bb != else_bb
-  && recognize_if_then_else (outer_cond_bb, &inner_cond_bb, &else_bb)
+  && recognize_if_then_else (outer_cond_bb, &outer_succ_bb, &else_bb)
   && same_phi_args_p (outer_cond_bb, phi_pred_bb, el

[gcc/aoliva/heads/testme] (8 commits) check ifcombine bitmap count

2024-11-01 Thread Alexandre Oliva via Gcc-cvs
The branch 'aoliva/heads/testme' was updated to point to:

 590d8e095503... check ifcombine bitmap count

It previously pointed to:

 9fee52ae3e79... [testsuite] disable PIE on ia32 on more tests

Diff:

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

  9fee52a... [testsuite] disable PIE on ia32 on more tests
  4358705... [testsuite] fix auto-init-8.c on ia32 PIC expectations
  633c9b0... [testsuite] fix pr70321.c PIC expectations
  44091b3... [PR83782] ifunc: back-propagate ifunc_resolver to aliases


Summary of changes (added commits):
---

  590d8e0... check ifcombine bitmap count
  0902a71... handle TRUTH_ANDIF cond exprs in ifcombine_replace_cond
  d1c6e0b... ifcombine across noncontiguous blocks
  48872a2... extend ifcombine_replace_cond to handle noncontiguous ifcom
  8aef26f... adjust update_profile_after_ifcombine for noncontiguous ifc
  668d14d... introduce ifcombine_replace_cond
  74aeb80... drop redundant ifcombine_ifandif parm
  5a40cc2... allow vuses in ifcombine blocks


[gcc(refs/users/aoliva/heads/testme)] allow vuses in ifcombine blocks

2024-11-01 Thread Alexandre Oliva via Gcc-cvs
https://gcc.gnu.org/g:5a40cc2b90452e5307493fc58f6730efd9981a7a

commit 5a40cc2b90452e5307493fc58f6730efd9981a7a
Author: Alexandre Oliva 
Date:   Thu Oct 24 05:25:21 2024 -0300

allow vuses in ifcombine blocks

Disallowing vuses in blocks for ifcombine is too strict, and it
prevents usefully moving fold_truth_andor into ifcombine.  That
tree-level folder has long ifcombined loads, absent other relevant
side effects.


for  gcc/ChangeLog

* tree-ssa-ifcombine.c (bb_no_side_effects_p): Allow vuses,
but not vdefs.

Diff:
---
 gcc/tree-ssa-ifcombine.cc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/tree-ssa-ifcombine.cc b/gcc/tree-ssa-ifcombine.cc
index 6a3bc99190d9..ed20a231951a 100644
--- a/gcc/tree-ssa-ifcombine.cc
+++ b/gcc/tree-ssa-ifcombine.cc
@@ -129,7 +129,7 @@ bb_no_side_effects_p (basic_block bb)
   enum tree_code rhs_code;
   if (gimple_has_side_effects (stmt)
  || gimple_could_trap_p (stmt)
- || gimple_vuse (stmt)
+ || gimple_vdef (stmt)
  /* We need to rewrite stmts with undefined overflow to use
 unsigned arithmetic but cannot do so for signed division.  */
  || ((ass = dyn_cast  (stmt))


[gcc(refs/users/aoliva/heads/testme)] drop redundant ifcombine_ifandif parm

2024-11-01 Thread Alexandre Oliva via Gcc-cvs
https://gcc.gnu.org/g:74aeb8018a0356f0b3f5b87c3a0b27e7e662e47d

commit 74aeb8018a0356f0b3f5b87c3a0b27e7e662e47d
Author: Alexandre Oliva 
Date:   Thu Oct 24 05:25:24 2024 -0300

drop redundant ifcombine_ifandif parm

In preparation to changes that may modify both inner and outer
conditions in ifcombine, drop the redundant parameter result_inv, that
is always identical to inner_inv.


for  gcc/ChangeLog

* tree-ssa-ifcombine.cc (ifcombine_ifandif): Drop redundant
result_inv parm.  Adjust all callers.

Diff:
---
 gcc/tree-ssa-ifcombine.cc | 18 +++---
 1 file changed, 7 insertions(+), 11 deletions(-)

diff --git a/gcc/tree-ssa-ifcombine.cc b/gcc/tree-ssa-ifcombine.cc
index ed20a231951a..0a2ba970548c 100644
--- a/gcc/tree-ssa-ifcombine.cc
+++ b/gcc/tree-ssa-ifcombine.cc
@@ -401,14 +401,14 @@ update_profile_after_ifcombine (basic_block inner_cond_bb,
 
 /* If-convert on a and pattern with a common else block.  The inner
if is specified by its INNER_COND_BB, the outer by OUTER_COND_BB.
-   inner_inv, outer_inv and result_inv indicate whether the conditions
-   are inverted.
+   inner_inv, outer_inv indicate whether the conditions are inverted.
Returns true if the edges to the common else basic-block were merged.  */
 
 static bool
 ifcombine_ifandif (basic_block inner_cond_bb, bool inner_inv,
-  basic_block outer_cond_bb, bool outer_inv, bool result_inv)
+  basic_block outer_cond_bb, bool outer_inv)
 {
+  bool result_inv = inner_inv;
   gimple_stmt_iterator gsi;
   tree name1, name2, bit1, bit2, bits1, bits2;
 
@@ -693,8 +693,7 @@ tree_ssa_ifcombine_bb_1 (basic_block inner_cond_bb, 
basic_block outer_cond_bb,
   
 ...
*/
-  return ifcombine_ifandif (inner_cond_bb, false, outer_cond_bb, false,
-   false);
+  return ifcombine_ifandif (inner_cond_bb, false, outer_cond_bb, false);
 }
 
   /* And a version where the outer condition is negated.  */
@@ -711,8 +710,7 @@ tree_ssa_ifcombine_bb_1 (basic_block inner_cond_bb, 
basic_block outer_cond_bb,
   
 ...
*/
-  return ifcombine_ifandif (inner_cond_bb, false, outer_cond_bb, true,
-   false);
+  return ifcombine_ifandif (inner_cond_bb, false, outer_cond_bb, true);
 }
 
   /* The || form is characterized by a common then_bb with the
@@ -731,8 +729,7 @@ tree_ssa_ifcombine_bb_1 (basic_block inner_cond_bb, 
basic_block outer_cond_bb,
   
 ...
*/
-  return ifcombine_ifandif (inner_cond_bb, true, outer_cond_bb, true,
-   true);
+  return ifcombine_ifandif (inner_cond_bb, true, outer_cond_bb, true);
 }
 
   /* And a version where the outer condition is negated.  */
@@ -748,8 +745,7 @@ tree_ssa_ifcombine_bb_1 (basic_block inner_cond_bb, 
basic_block outer_cond_bb,
   
 ...
*/
-  return ifcombine_ifandif (inner_cond_bb, true, outer_cond_bb, false,
-   true);
+  return ifcombine_ifandif (inner_cond_bb, true, outer_cond_bb, false);
 }
 
   return false;


[gcc/aoliva/heads/testme] check ifcombine bitmap count

2024-11-01 Thread Alexandre Oliva via Gcc-cvs
The branch 'aoliva/heads/testme' was updated to point to:

 858cf33bbac2... check ifcombine bitmap count

It previously pointed to:

 590d8e095503... check ifcombine bitmap count

Diff:

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

  590d8e0... check ifcombine bitmap count


Summary of changes (added commits):
---

  858cf33... check ifcombine bitmap count


[gcc(refs/users/aoliva/heads/testme)] check ifcombine bitmap count

2024-11-01 Thread Alexandre Oliva via Gcc-cvs
https://gcc.gnu.org/g:858cf33bbac224b5b65ebfbb4a5d8668b4223d2b

commit 858cf33bbac224b5b65ebfbb4a5d8668b4223d2b
Author: Alexandre Oliva 
Date:   Sat Nov 2 00:42:23 2024 -0300

check ifcombine bitmap count

Diff:
---
 gcc/tree-ssa-ifcombine.cc | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/gcc/tree-ssa-ifcombine.cc b/gcc/tree-ssa-ifcombine.cc
index ac4811e42e08..31b28e78acb9 100644
--- a/gcc/tree-ssa-ifcombine.cc
+++ b/gcc/tree-ssa-ifcombine.cc
@@ -547,7 +547,7 @@ ifcombine_replace_cond (gcond *inner_cond, bool inner_inv,
auto_bitmap used;
basic_block outer_bb = gimple_bb (outer_cond);
 
-   bitmap_tree_view (used);
+   /* bitmap_tree_view (used); */
 
/* Mark SSA DEFs that are referenced by cond and may thus need to be
   moved to outer.  */
@@ -558,6 +558,7 @@ ifcombine_replace_cond (gcond *inner_cond, bool inner_inv,
 
if (!bitmap_empty_p (used))
  {
+   gcc_checking_assert (bitmap_count_bits (used) <= 2);
/* Iterate up from inner_cond, moving DEFs identified as used by
   cond, and marking USEs in the DEFs for moving as well.  */
gimple_stmt_iterator gsins = gsi_for_stmt (outer_cond);
@@ -626,6 +627,7 @@ ifcombine_replace_cond (gcond *inner_cond, bool inner_inv,
gsi_insert_before (&gsins, a, GSI_NEW_STMT);
  }
  }
+   gcc_checking_assert (bitmap_count_bits (used) < 5);
  }
   }


[gcc(refs/users/meissner/heads/work182-vpair)] Vector pair support.

2024-11-01 Thread Michael Meissner via Gcc-cvs
https://gcc.gnu.org/g:9808c36bc0a262084fec2a20f93ee6beaee8aa52

commit 9808c36bc0a262084fec2a20f93ee6beaee8aa52
Author: Michael Meissner 
Date:   Fri Nov 1 20:01:55 2024 -0400

Vector pair support.

This patch adds a new include file (vector-pair.h) that adds support so that
users writing high performance libraries can change their code to allow the
generation of the vector pair load and store instructions on power10.

The intention is that if the library authors need to write special loops 
that
go over arrays that they could modify their code to use the functions 
provided
to change loops that can take advantage of the higher bandwidth for load 
vector
pair and store instructions.

This particular patch just adds a new include file (vector-pair.h) that
provides a bunch of functions that on a power10 system would use the vector
pair load operation, 2 floating point operations, and a vector pair store.  
It
does not add any new types, modes, or built-in function.

I have additional patches that can add built-in functions that the 
functions in
vector-pair.h could utilize so that the compiler can optimize and combine
operations.  I may submit those patches in the future, but I would like to
provide this patch to allow the library writer to optimize their code.

I've measured the performance of these new functions on a power10.  For 
default
unrolling, the percentage of change for the 3 methods over the normal vector
loop method:

116%Vector-pair.h function, default unroll
 93%Vector pair split built-in & 2 vector stores, default unroll
 86%Vector pair split & combine built-ins, default unroll

Using explicit 2 way unrolling the numbers are:

114%Vector-pair.h function, unroll 2
106%Vector pair split built-in & 2 vector stores, unroll 2
 98%Vector pair split & combine built-ins, unroll 2

These new functions provided in vector-pair.h use the vector pair load/store
instructions, and don't generate extra vector moves.  Using the existing
vector pair disassemble and assemble built-ins generate extra vector moves
which can hinder performance.

If I compile the loop code for power9, there is a minor speed up for default
unrolling and more of an improvement using the framework provided in the
vector-pair.h for explicit unrolling by 2:

101%Vector-pair.h function, default unroll for power9
107%Vector-pair.h function, unroll 2 for power9

Of course this is a synthetic benchmark run on a quiet power10 system.  
Results
would vary for real code on real systems.  However, I feel adding these
functions can allow the writers of high performance libraries to better
optimize their code.

As an example, if the library wants to code a simple fused multiply-add 
loop,
they might write the code as follows:

#include 
#include 
#include 

void
fma_vector (double * __restrict__ r,
const double * __restrict__ a,
const double * __restrict__ b,
size_t n)
{
  vector double * __restrict__ vr = (vector double * __restrict__)r;
  const vector double * __restrict__ va = (const vector double * 
__restrict__)a;
  const vector double * __restrict__ vb = (const vector double * 
__restrict__)b;
  size_t num_elements = sizeof (vector double) / sizeof (double);
  size_t nv = n / num_elements;
  size_t i;

  for (i = 0; i < nv; i++)
vr[i] = __builtin_vsx_xvmadddp (va[i], vb[i], vr[i]);

  for (i = nv * num_elements; i < n; i++)
r[i] = fma (a[i], b[i], r[i]);
}

The inner loop would look like:

.L3:
lxvx 0,3,9
lxvx 12,4,9
addi 10,9,16
addi 2,2,-2
lxvx 11,5,9
xvmaddadp 0,12,11
lxvx 12,4,10
lxvx 11,5,10
stxvx 0,3,9
lxvx 0,3,10
addi 9,9,32
xvmaddadp 0,12,11
stxvx 0,3,10
bdnz .L3

Now if you code the loop to use __builtin_vsx_disassemble_pair to do a 
vector
pair load, but then do 2 vector stores:

#include 
#include 
#include 

void
fma_mma_ld (double * __restrict__ r,
const double * __restrict__ a,
const double * __restrict__ b,
size_t n)
{
  __vector_pair * __restrict__ vp_r 

[gcc(refs/users/meissner/heads/work182-vpair)] Add vector pair swap even and odd.

2024-11-01 Thread Michael Meissner via Gcc-cvs
https://gcc.gnu.org/g:108cea1059bc3ed41dd0c256fbc833ab5f96d158

commit 108cea1059bc3ed41dd0c256fbc833ab5f96d158
Author: Michael Meissner 
Date:   Sat Nov 2 00:11:55 2024 -0400

Add vector pair swap even and odd.

This patch adds 2 additional functions:

vpair_f32_swap_odd_even
vpair_f64_swap_odd_even

This swaps the odd and even elements in a vector pair.  The intention is for
libraries that are doing complex multiply to be able to swap the real and
imaginary elements to do the multiply operation.

2024-11-01  Michael Meissner  

gcc/

* config/rs6000/vector-pair.h (vpair_f32_swap_odd_even): New 
function.
(vpair_f64_swap_odd_even): Likewise.

Diff:
---
 gcc/config/rs6000/vector-pair.h| 54 ++
 gcc/testsuite/gcc.target/powerpc/vpair-1.c | 13 +--
 gcc/testsuite/gcc.target/powerpc/vpair-2.c | 13 +--
 gcc/testsuite/gcc.target/powerpc/vpair-3.h | 26 ++
 gcc/testsuite/gcc.target/powerpc/vpair-4.h | 26 ++
 5 files changed, 128 insertions(+), 4 deletions(-)

diff --git a/gcc/config/rs6000/vector-pair.h b/gcc/config/rs6000/vector-pair.h
index ceb28c4e974c..848c876beffc 100644
--- a/gcc/config/rs6000/vector-pair.h
+++ b/gcc/config/rs6000/vector-pair.h
@@ -516,4 +516,58 @@ vpair_f32_nfms (vector_pair_f32_t   *__r,
   "xvnmsubasp",
   __builtin_vsx_xvnmsubsp);
 }
+
+
+/* Swap even/odd operations.  */
+
+static inline void
+vpair_f32_swap_odd_even (vector_pair_f32_t   *__r,
+const vector_pair_f32_t *__a)
+{
+  vector unsigned long long __rotate = { 32, 32 };
+
+#if __MMA__ && !__VPAIR_NOP10__
+  /* Power10 vector pair support.  */
+  __asm__ ("vrld %0,%1,%2\n\tvrld %L0,%L1,%2"
+  : "=v" (__r->__vpair)
+  : "v"  (__a->__vpair), "v" (__rotate));
+
+#else
+  /* vector pair not available.  */
+  vector unsigned long long *__r_ll = (vector unsigned long long *)__r;
+  vector unsigned long long *__a_ll = (vector unsigned long long *)__a;
+  __r_ll[0] = __builtin_vec_vrld (__a_ll[0], __rotate);
+  __r_ll[1] = __builtin_vec_vrld (__a_ll[1], __rotate);
+#endif /* power10/not power10.  */
+}
+
+
+static inline void
+vpair_f64_swap_odd_even (vector_pair_f64_t   *__r,
+const vector_pair_f64_t *__a)
+{
+#if __MMA__ && !__VPAIR_NOP10__
+#if __VPAIR__USE_FPR__ || !__GNUC__ || (!__linux__ && !__ELF__)
+
+  /* Use vector pair and use %0 and %L0 on traditional FPR registers.  */
+  __asm__ ("xxpermdi %0,%1,%1,2\n\txxpermdi %L0,%L1,%L1,2"
+  : "=d" (__r->__vpair)
+  : "d"  (__a->__vpair));
+
+#else
+  /* Use vector pair and use %x0 and %x0+ on all VSX registers.  */
+  __asm__ ("xxpermdi %x0,%x1,%x1,2\n\txxpermdi %x0+1,%x1+1,%x1+1,2"
+  : "=wa" (__r->__vpair)
+  : "wa"  (__a->__vpair));
+#endif
+
+#else
+  /* vector pair not available.  */
+  __r->__vp_f64[0]
+= __builtin_vsx_xxpermdi_2df (__a->__vp_f64[0], __a->__vp_f64[0], 2);
+  __r->__vp_f64[1]
+= __builtin_vsx_xxpermdi_2df (__a->__vp_f64[1], __a->__vp_f64[1], 2);
+#endif
+}
+
 #endif /* _VECTOR_PAIR_H.  */
diff --git a/gcc/testsuite/gcc.target/powerpc/vpair-1.c 
b/gcc/testsuite/gcc.target/powerpc/vpair-1.c
index 55772cc44e31..f56e99a1d044 100644
--- a/gcc/testsuite/gcc.target/powerpc/vpair-1.c
+++ b/gcc/testsuite/gcc.target/powerpc/vpair-1.c
@@ -124,8 +124,16 @@ test_nfms (vector_pair_f64_t *dest,
   vpair_f64_nfms (dest, x, y, z);
 }
 
-/* { dg-final { scan-assembler-times {\mlxvp\M}   26 } } */
-/* { dg-final { scan-assembler-times {\mstxvp\M}  13 } } */
+void
+test_swap (vector_pair_f64_t *dest,
+  vector_pair_f64_t *x)
+{
+  /* 1 lxvp, 2 xxpermdi, 1 stxvp.  */
+  vpair_f64_swap_odd_even (dest, x);
+}
+
+/* { dg-final { scan-assembler-times {\mlxvp\M}   27 } } */
+/* { dg-final { scan-assembler-times {\mstxvp\M}  14 } } */
 /* { dg-final { scan-assembler-times {\mxvabsdp\M} 2 } } */
 /* { dg-final { scan-assembler-times {\mxvadddp\M} 2 } } */
 /* { dg-final { scan-assembler-times {\mxvmadd.dp\M}   2 } } */
@@ -139,3 +147,4 @@ test_nfms (vector_pair_f64_t *dest,
 /* { dg-final { scan-assembler-times {\mxvnmsub.dp\M}  2 } } */
 /* { dg-final { scan-assembler-times {\mxvsqrtdp\M}2 } } */
 /* { dg-final { scan-assembler-times {\mxvsubdp\M} 2 } } */
+/* { dg-final { scan-assembler-times {\mxxpermdi\M}2 } } */
diff --git a/gcc/testsuite/gcc.target/powerpc/vpair-2.c 
b/gcc/testsuite/gcc.target/powerpc/vpair-2.c
index 3030b0b33380..0f84a74e94a1 100644
--- a/gcc/testsuite/gcc.target/powerpc/vpair-2.c
+++ b/gcc/testsuite/gcc.target/powerpc/vpair-2.c
@@ -124,8 +124,17 @@ test_nfms (vector_pair_f32_t *dest,
   vpair_f32_nfms (dest, x, y, z);
 }
 
-/* { dg-final { scan-assembler-times {\mlxvp\M}   26 } } */
-/* { dg-final { scan-assembler-times {\mstxvp\M}  13 } } */
+void
+test_swap (vector_pair_f32_t *dest,
+  vector

[gcc(refs/users/meissner/heads/work182-vpair)] Update ChangeLog.*

2024-11-01 Thread Michael Meissner via Gcc-cvs
https://gcc.gnu.org/g:9c11f6ac98da4015339d22c9c9bd881e686261c0

commit 9c11f6ac98da4015339d22c9c9bd881e686261c0
Author: Michael Meissner 
Date:   Sat Nov 2 00:13:58 2024 -0400

Update ChangeLog.*

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

diff --git a/gcc/ChangeLog.vpair b/gcc/ChangeLog.vpair
index f810ba622b7a..f1784c9f8bfd 100644
--- a/gcc/ChangeLog.vpair
+++ b/gcc/ChangeLog.vpair
@@ -1,5 +1,445 @@
+ Branch work182-vpair, patch #301 
+
+Add vector pair swap even and odd.
+
+This patch adds 2 additional functions:
+
+   vpair_f32_swap_odd_even
+   vpair_f64_swap_odd_even
+
+This swaps the odd and even elements in a vector pair.  The intention is for
+libraries that are doing complex multiply to be able to swap the real and
+imaginary elements to do the multiply operation.
+
+2024-11-01  Michael Meissner  
+
+gcc/
+
+   * config/rs6000/vector-pair.h (vpair_f32_swap_odd_even): New function.
+   (vpair_f64_swap_odd_even): Likewise.
+
+ Branch work182-vpair, patch #300 
+
+Vector pair support.
+
+This patch adds a new include file (vector-pair.h) that adds support so that
+users writing high performance libraries can change their code to allow the
+generation of the vector pair load and store instructions on power10.
+
+The intention is that if the library authors need to write special loops that
+go over arrays that they could modify their code to use the functions provided
+to change loops that can take advantage of the higher bandwidth for load vector
+pair and store instructions.
+
+This particular patch just adds a new include file (vector-pair.h) that
+provides a bunch of functions that on a power10 system would use the vector
+pair load operation, 2 floating point operations, and a vector pair store.  It
+does not add any new types, modes, or built-in function.
+
+I have additional patches that can add built-in functions that the functions in
+vector-pair.h could utilize so that the compiler can optimize and combine
+operations.  I may submit those patches in the future, but I would like to
+provide this patch to allow the library writer to optimize their code.
+
+I've measured the performance of these new functions on a power10.  For default
+unrolling, the percentage of change for the 3 methods over the normal vector
+loop method:
+
+   116%Vector-pair.h function, default unroll
+93%Vector pair split built-in & 2 vector stores, default unroll
+86%Vector pair split & combine built-ins, default unroll
+
+Using explicit 2 way unrolling the numbers are:
+
+   114%Vector-pair.h function, unroll 2
+   106%Vector pair split built-in & 2 vector stores, unroll 2
+98%Vector pair split & combine built-ins, unroll 2
+
+These new functions provided in vector-pair.h use the vector pair load/store
+instructions, and don't generate extra vector moves.  Using the existing
+vector pair disassemble and assemble built-ins generate extra vector moves
+which can hinder performance.
+
+If I compile the loop code for power9, there is a minor speed up for default
+unrolling and more of an improvement using the framework provided in the
+vector-pair.h for explicit unrolling by 2:
+
+   101%Vector-pair.h function, default unroll for power9
+   107%Vector-pair.h function, unroll 2 for power9
+
+Of course this is a synthetic benchmark run on a quiet power10 system.  Results
+would vary for real code on real systems.  However, I feel adding these
+functions can allow the writers of high performance libraries to better
+optimize their code.
+
+As an example, if the library wants to code a simple fused multiply-add loop,
+they might write the code as follows:
+
+   #include 
+   #include 
+   #include 
+
+   void
+   fma_vector (double * __restrict__ r,
+   const double * __restrict__ a,
+   const double * __restrict__ b,
+   size_t n)
+   {
+ vector double * __restrict__ vr = (vector double * __restrict__)r;
+ const vector double * __restrict__ va = (const vector double * 
__restrict__)a;
+ const vector double * __restrict__ vb = (const vector double * 
__restrict__)b;
+ size_t num_elements = sizeof (vector double) / sizeof (double);
+ size_t nv = n / num_elements;
+ size_t i;
+
+ for (i = 0; i < nv; i++)
+   vr[i] = __builtin_vsx_xvmadddp (va[i], vb[i], vr[i]);
+
+ for (i = nv * num_elements; i < n; i++)
+   r[i] = fma (a[i], b[i], r[i]);
+   }
+
+The inner loop would look like:
+
+   .L3:
+   lxvx 0,3,9
+   lxvx 12,4,9
+   addi 10,9,16
+   addi 2,2,-2
+   lxvx 11,5,9
+   xvmaddadp 0,12,11
+   lxvx 12,4,10
+   lxvx 11,5,10

[gcc r15-4853] libstdc++: Add P1206R7 from_range members to std::list and std::forward_list [PR111055]

2024-11-01 Thread Jonathan Wakely via Libstdc++-cvs
https://gcc.gnu.org/g:7a4fced2b122bde47fed2d99fb8e3cf197f9c46f

commit r15-4853-g7a4fced2b122bde47fed2d99fb8e3cf197f9c46f
Author: Jonathan Wakely 
Date:   Tue Oct 8 21:15:18 2024 +0100

libstdc++: Add P1206R7 from_range members to std::list and 
std::forward_list [PR111055]

This is another piece of P1206R7, adding new members to std::list and
std::forward_list.

libstdc++-v3/ChangeLog:

PR libstdc++/111055
* include/bits/forward_list.h
(forward_list(from_range, R&&, const Alloc&), assign_range)
(prepend_range, insert_range_after): Define.
* include/bits/stl_list.h (list(from_range, R&&, const Alloc&))
(assign_range, prepend_range, append_range, insert_range):
Define.
* include/debug/forward_list
(forward_list(from_range, R&&, const Alloc&), assign_range)
(prepend_range, insert_range_after): Define.
* include/debug/list (list(from_range, R&&, const Alloc&))
(assign_range, prepend_range, append_range, insert_range):
Define.
* testsuite/23_containers/forward_list/cons/from_range.cc: New
test.
* testsuite/23_containers/forward_list/modifiers/assign_range.cc:
New test.
* 
testsuite/23_containers/forward_list/modifiers/insert_range_after.cc:
New test.
* testsuite/23_containers/forward_list/modifiers/prepend_range.cc:
New test.
* testsuite/23_containers/list/cons/from_range.cc: New test.
* testsuite/23_containers/list/modifiers/append_range.cc: New
test.
* testsuite/23_containers/list/modifiers/assign/assign_range.cc:
New test.
* testsuite/23_containers/list/modifiers/insert/insert_range.cc:
New test.
* testsuite/23_containers/list/modifiers/prepend_range.cc: New
test.

Reviewed-by: Patrick Palka 

Diff:
---
 libstdc++-v3/include/bits/forward_list.h   | 121 +++
 libstdc++-v3/include/bits/stl_list.h   | 128 +
 libstdc++-v3/include/debug/forward_list|  63 ++
 libstdc++-v3/include/debug/list|  56 +
 .../23_containers/forward_list/cons/from_range.cc  | 100 
 .../forward_list/modifiers/assign_range.cc |  97 
 .../forward_list/modifiers/insert_range_after.cc   |  93 +++
 .../forward_list/modifiers/prepend_range.cc|  86 ++
 .../23_containers/list/cons/from_range.cc  | 100 
 .../23_containers/list/modifiers/append_range.cc   |  86 ++
 .../list/modifiers/assign/assign_range.cc  |  99 
 .../list/modifiers/insert/insert_range.cc  |  98 
 .../23_containers/list/modifiers/prepend_range.cc  |  86 ++
 13 files changed, 1213 insertions(+)

diff --git a/libstdc++-v3/include/bits/forward_list.h 
b/libstdc++-v3/include/bits/forward_list.h
index eee773c02121..c9238cef96fa 100644
--- a/libstdc++-v3/include/bits/forward_list.h
+++ b/libstdc++-v3/include/bits/forward_list.h
@@ -42,6 +42,10 @@
 #include 
 #include 
 #include 
+#if __glibcxx_ranges_to_container // C++ >= 23
+# include  // ranges::begin, ranges::distance etc.
+# include  // ranges::subrange
+#endif
 
 namespace std _GLIBCXX_VISIBILITY(default)
 {
@@ -564,6 +568,30 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
: _Base(_Node_alloc_type(__al))
{ _M_range_initialize(__first, __last); }
 
+#if __glibcxx_ranges_to_container // C++ >= 23
+  /**
+   * @brief Construct a forward_list from a range.
+   * @param __rg An input range with elements that are convertible to
+   * the forward_list's value_type.
+   * @param __a An allocator.
+   *
+   * @since C++23
+   */
+  template<__detail::__container_compatible_range<_Tp> _Rg>
+   forward_list(from_range_t, _Rg&& __rg, const _Alloc& __a = _Alloc())
+   : _Base(_Node_alloc_type(__a))
+   {
+ _Node_base* __to = &this->_M_impl._M_head;
+ auto __first = ranges::begin(__rg);
+ const auto __last = ranges::end(__rg);
+ for (; __first != __last; ++__first)
+   {
+ __to->_M_next = this->_M_create_node(*__first);
+ __to = __to->_M_next;
+   }
+   }
+#endif // ranges_to_container
+
   /**
*  @brief  The %forward_list copy constructor.
*  @param  __list  A %forward_list of identical element and allocator
@@ -675,6 +703,39 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
  _M_assign(__first, __last, __assignable());
}
 
+#if __glibcxx_ranges_to_container // C++ >= 23
+  /**
+   * @brief Assign a range to a forward_list.
+   * @since C++23
+   */
+  template<__detail::__container_compatible_range<_Tp> _Rg

[gcc r15-4854] libstdc++: Minor comment improvements in

2024-11-01 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:db798ee38a3f81eff207e889c36c727bb370112c

commit r15-4854-gdb798ee38a3f81eff207e889c36c727bb370112c
Author: Jonathan Wakely 
Date:   Fri Nov 1 12:46:26 2024 +

libstdc++: Minor comment improvements in 

libstdc++-v3/ChangeLog:

* include/bits/hashtable.h: Improve comments.

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

diff --git a/libstdc++-v3/include/bits/hashtable.h 
b/libstdc++-v3/include/bits/hashtable.h
index f1a5490b5ff3..47321a9cb135 100644
--- a/libstdc++-v3/include/bits/hashtable.h
+++ b/libstdc++-v3/include/bits/hashtable.h
@@ -1019,7 +1019,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   iterator
   erase(const_iterator);
 
-  // LWG 2059.
+  // _GLIBCXX_RESOLVE_LIB_DEFECTS
+  // 2059. C++0x ambiguity problem with map::erase
   iterator
   erase(iterator __it)
   { return erase(const_iterator(__it)); }
@@ -1041,7 +1042,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   // DR 1189.
   // reserve, if present, comes from _Rehash_base.
 
-#if __glibcxx_node_extract // >= C++17
+#if __glibcxx_node_extract // >= C++17 && HOSTED
   /// Re-insert an extracted node into a container with unique keys.
   insert_return_type
   _M_reinsert_node(node_type&& __nh)


[gcc r15-4855] libstdc++: Check feature test macros in unordered containers

2024-11-01 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:1a5bdeb1128ecfa4ce233218d02ccbb88ce0d8a8

commit r15-4855-g1a5bdeb1128ecfa4ce233218d02ccbb88ce0d8a8
Author: Jonathan Wakely 
Date:   Fri Nov 1 10:50:02 2024 +

libstdc++: Check feature test macros in unordered containers

Replace some `__cplusplus > 201402L` preprocessor checks with more
expressive checks for the appropriate feature test macros.

libstdc++-v3/ChangeLog:

* include/bits/unordered_map.h: Check __glibcxx_node_extract and
__glibcxx_unordered_map_try_emplace instead of __cplusplus.
* include/bits/unordered_set.h: Check __glibcxx_node_extract
instead of __cplusplus.

Diff:
---
 libstdc++-v3/include/bits/unordered_map.h | 28 ++--
 libstdc++-v3/include/bits/unordered_set.h | 24 
 2 files changed, 26 insertions(+), 26 deletions(-)

diff --git a/libstdc++-v3/include/bits/unordered_map.h 
b/libstdc++-v3/include/bits/unordered_map.h
index 8607944d5653..3b472534c660 100644
--- a/libstdc++-v3/include/bits/unordered_map.h
+++ b/libstdc++-v3/include/bits/unordered_map.h
@@ -137,7 +137,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
   typedef typename _Hashtable::difference_type difference_type;
   ///@}
 
-#if __cplusplus > 201402L
+#ifdef __glibcxx_node_extract // >= C++17 && HOSTED
   using node_type = typename _Hashtable::node_type;
   using insert_return_type = typename _Hashtable::insert_return_type;
 #endif
@@ -426,7 +426,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
emplace_hint(const_iterator __pos, _Args&&... __args)
{ return _M_h.emplace_hint(__pos, std::forward<_Args>(__args)...); }
 
-#if __cplusplus > 201402L
+#ifdef __glibcxx_node_extract // >= C++17 && HOSTED
   /// Extract a node.
   node_type
   extract(const_iterator __pos)
@@ -449,7 +449,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
   iterator
   insert(const_iterator, node_type&& __nh)
   { return _M_h._M_reinsert_node(std::move(__nh)).position; }
-#endif // C++17
+#endif // node_extract
 
 #ifdef __glibcxx_unordered_map_try_emplace // C++ >= 17 && HOSTED
   /**
@@ -636,7 +636,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
   { _M_h.insert(__l); }
 
 
-#if __cplusplus > 201402L
+#ifdef __glibcxx_unordered_map_try_emplace // >= C++17 && HOSTED
   /**
*  @brief Attempts to insert a std::pair into the %unordered_map.
*  @param __kKey to use for finding a possibly existing pair in
@@ -728,7 +728,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
__ret.first->second = std::forward<_Obj>(__obj);
  return __ret.first;
}
-#endif
+#endif // unordered_map_try_emplace
 
   ///@{
   /**
@@ -813,7 +813,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
   noexcept( noexcept(_M_h.swap(__x._M_h)) )
   { _M_h.swap(__x._M_h); }
 
-#if __cplusplus > 201402L
+#ifdef __glibcxx_node_extract // >= C++17 && HOSTED
   template
friend class std::_Hash_merge_helper;
 
@@ -842,7 +842,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
void
merge(unordered_multimap<_Key, _Tp, _H2, _P2, _Alloc>&& __source)
{ merge(__source); }
-#endif // C++17
+#endif // node_extract
 
   // observers.
 
@@ -1283,7 +1283,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
   typedef typename _Hashtable::difference_type difference_type;
   ///@}
 
-#if __cplusplus > 201402L
+#ifdef __glibcxx_node_extract // >= C++17 && HOSTED
   using node_type = typename _Hashtable::node_type;
 #endif
 
@@ -1648,7 +1648,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
   insert(initializer_list __l)
   { _M_h.insert(__l); }
 
-#if __cplusplus > 201402L
+#ifdef __glibcxx_node_extract // >= C++17 && HOSTED
   /// Extract a node.
   node_type
   extract(const_iterator __pos)
@@ -1671,7 +1671,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
   iterator
   insert(const_iterator __hint, node_type&& __nh)
   { return _M_h._M_reinsert_node_multi(__hint, std::move(__nh)); }
-#endif // C++17
+#endif // node_extract
 
   ///@{
   /**
@@ -1756,7 +1756,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
   noexcept( noexcept(_M_h.swap(__x._M_h)) )
   { _M_h.swap(__x._M_h); }
 
-#if __cplusplus > 201402L
+#ifdef __glibcxx_node_extract // >= C++17 && HOSTED
   template
friend class std::_Hash_merge_helper;
 
@@ -1787,7 +1787,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
void
merge(unordered_map<_Key, _Tp, _H2, _P2, _Alloc>&& __source)
{ merge(__source); }
-#endif // C++17
+#endif // node_extract
 
   // observers.
 
@@ -2169,7 +2169,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
 
 _GLIBCXX_END_NAMESPACE_CONTAINER
 
-#if __cplusplus > 201402L
+#ifdef __glibcxx_node_extract // >= C++17 && HOSTED
   // Allow std::unordered_map access to internals of compatible maps.
   template
@@ -2217,7 +2217,7 @@ _GLIBCXX_END_NAMESPACE_CONTAINER
   _S_get_table(unordered_multimap<_Key, _Val, _Hash2, _Eq2, _Alloc>&

[gcc r15-4851] Reimplement 'assume' processing pass.

2024-11-01 Thread Andrew Macleod via Gcc-cvs
https://gcc.gnu.org/g:62420dbd105bbc4fe732881875c5c85aa55b6069

commit r15-4851-g62420dbd105bbc4fe732881875c5c85aa55b6069
Author: Andrew MacLeod 
Date:   Mon Oct 28 10:19:27 2024 -0400

Reimplement 'assume' processing pass.

Rework the assume pass to work properly and fail conservatively when it
does.  Also move it to its own file.

PR tree-optimization/117287
gcc/
* Makefile.in (IBJS): Add tree-assume.o
* gimple-range.cc (assume_query::assume_range_p): Remove.
(assume_query::range_of_expr): Remove.
(assume_query::assume_query): Move to tree-assume.cc.
(assume_query::~assume_query): Remove.
(assume_query::calculate_op): Move to tree-assume.cc.
(assume_query::calculate_phi): Likewise.
(assume_query::check_taken_edge): Remove.
(assume_query::calculate_stmt): Move to tree-assume.cc.
(assume_query::dump): Remove.
* gimple-range.h (class assume_query): Move to tree-assume.cc
* tree-assume.cc: New
* tree-vrp.cc (struct pass_data_assumptions): Move to 
tree-assume.cc.
(class pass_assumptions): Likewise.
(make_pass_assumptions): Likewise.

gcc/testsuite/
* g++.dg/cpp23/pr117287-attr.C: New.

Diff:
---
 gcc/Makefile.in|   1 +
 gcc/gimple-range.cc| 194 ---
 gcc/gimple-range.h |  17 --
 gcc/testsuite/g++.dg/cpp23/pr117287-attr.C |  38 +++
 gcc/tree-assume.cc | 369 +
 gcc/tree-vrp.cc|  60 -
 6 files changed, 408 insertions(+), 271 deletions(-)

diff --git a/gcc/Makefile.in b/gcc/Makefile.in
index 2b80cdc046d9..eb5782104114 100644
--- a/gcc/Makefile.in
+++ b/gcc/Makefile.in
@@ -1703,6 +1703,7 @@ OBJS = \
sanopt.o \
sancov.o \
simple-diagnostic-path.o \
+   tree-assume.o \
tree-call-cdce.o \
tree-cfg.o \
tree-cfgcleanup.o \
diff --git a/gcc/gimple-range.cc b/gcc/gimple-range.cc
index f6aa27399a2d..00e1a3c4ad53 100644
--- a/gcc/gimple-range.cc
+++ b/gcc/gimple-range.cc
@@ -700,200 +700,6 @@ disable_ranger (struct function *fun)
   fun->x_range_query = NULL;
 }
 
-// 
-
-// If there is a non-varying value associated with NAME, return true and the
-// range in R.
-
-bool
-assume_query::assume_range_p (vrange &r, tree name)
-{
-  if (global.get_range (r, name))
-return !r.varying_p ();
-  return false;
-}
-
-// Query used by GORI to pick up any known value on entry to a block.
-
-bool
-assume_query::range_of_expr (vrange &r, tree expr, gimple *stmt)
-{
-  if (!gimple_range_ssa_p (expr))
-return get_tree_range (r, expr, stmt);
-
-  if (!global.get_range (r, expr))
-r.set_varying (TREE_TYPE (expr));
-  return true;
-}
-
-// If the current function returns an integral value, and has a single return
-// statement, it will calculate any SSA_NAMES it can determine ranges for
-// assuming the function returns 1.
-
-assume_query::assume_query ()
-{
-  create_gori (0, param_vrp_switch_limit);
-  basic_block exit_bb = EXIT_BLOCK_PTR_FOR_FN (cfun);
-  if (single_pred_p (exit_bb))
-{
-  basic_block bb = single_pred (exit_bb);
-  gimple_stmt_iterator gsi = gsi_last_nondebug_bb (bb);
-  if (gsi_end_p (gsi))
-   return;
-  gimple *s = gsi_stmt (gsi);
-  if (!is_a (s))
-   return;
-  greturn *gret = as_a (s);
-  tree op = gimple_return_retval (gret);
-  if (!gimple_range_ssa_p (op))
-   return;
-  tree lhs_type = TREE_TYPE (op);
-  if (!irange::supports_p (lhs_type))
-   return;
-
-  unsigned prec = TYPE_PRECISION (lhs_type);
-  int_range<2> lhs_range (lhs_type, wi::one (prec), wi::one (prec));
-  global.set_range (op, lhs_range);
-
-  gimple *def = SSA_NAME_DEF_STMT (op);
-  if (!def || gimple_get_lhs (def) != op)
-   return;
-  fur_stmt src (gret, this);
-  calculate_stmt (def, lhs_range, src);
-}
-}
-
-assume_query::~assume_query ()
-{
-  destroy_gori ();
-}
-
-// Evaluate operand OP on statement S, using the provided LHS range.
-// If successful, set the range in the global table, then visit OP's def stmt.
-
-void
-assume_query::calculate_op (tree op, gimple *s, vrange &lhs, fur_source &src)
-{
-  value_range op_range (TREE_TYPE (op));
-  if (gori ().compute_operand_range (op_range, s, lhs, op, src)
-  && !op_range.varying_p ())
-{
-  // Set the global range, merging if there is already a range.
-  global.merge_range (op, op_range);
-  gimple *def_stmt = SSA_NAME_DEF_STMT (op);
-  if (def_stmt && gimple_get_lhs (def_stmt) == op)
-   calculate_stmt (def_stmt, op_range, src);
-}
-}
-
-// Evaluate PHI statement, using the provided LHS range.
-// Check each constan

[gcc r15-4858] analyzer: use std::unique_ptr in "to_json" functions

2024-11-01 Thread David Malcolm via Gcc-cvs
https://gcc.gnu.org/g:0cb6078ca83f545bfe54b4064181dca6f81ce45d

commit r15-4858-g0cb6078ca83f545bfe54b4064181dca6f81ce45d
Author: David Malcolm 
Date:   Fri Nov 1 21:40:47 2024 -0400

analyzer: use std::unique_ptr in "to_json" functions

No functional change intended.

gcc/analyzer/ChangeLog:
* analyzer.cc: Include "make-unique.h".  Convert "to_json"
functions to use std::unique_ptr.
* call-string.cc: Likewise.
* constraint-manager.cc: Likewise.
* diagnostic-manager.cc: Likewise.
* engine.cc: Likewise.
* program-point.cc: Likewise.
* program-state.cc: Likewise.
* ranges.cc: Likewise.
* region-model.cc: Likewise.
* region.cc: Likewise.
* svalue.cc: Likewise.
* sm.cc: Likewise.
* store.cc: Likewise.
* supergraph.cc: Likewise.
* analyzer.h: Convert "to_json" functions to return
std::unique_ptr.
* call-string.h: Likewise.
* constraint-manager.h: Likewise.
(bounded_range::set_json_attr): Pass "obj" by reference.
* diagnostic-manager.h: Convert "to_json" functions to return
std::unique_ptr.
* exploded-graph.h: Likewise.
* program-point.h: Likewise.
* program-state.h: Likewise.
* ranges.h: Likewise.
* region-model.h: Likewise.
* region.h: Likewise.
* sm.h: Likewise.
* store.h: Likewise.
* supergraph.h: Likewise.
* svalue.h: Likewise.

Signed-off-by: David Malcolm 

Diff:
---
 gcc/analyzer/analyzer.cc   | 21 
 gcc/analyzer/analyzer.h|  8 +++
 gcc/analyzer/call-string.cc|  9 +++
 gcc/analyzer/call-string.h |  2 +-
 gcc/analyzer/constraint-manager.cc | 49 +++---
 gcc/analyzer/constraint-manager.h  | 14 +--
 gcc/analyzer/diagnostic-manager.cc | 12 +-
 gcc/analyzer/diagnostic-manager.h  |  4 ++--
 gcc/analyzer/engine.cc | 32 -
 gcc/analyzer/exploded-graph.h  | 10 
 gcc/analyzer/program-point.cc  |  5 ++--
 gcc/analyzer/program-point.h   |  2 +-
 gcc/analyzer/program-state.cc  | 21 
 gcc/analyzer/program-state.h   |  7 +++---
 gcc/analyzer/ranges.cc |  7 +++---
 gcc/analyzer/ranges.h  |  4 ++--
 gcc/analyzer/region-model.cc   |  8 +++
 gcc/analyzer/region-model.h|  4 ++--
 gcc/analyzer/region.cc |  5 ++--
 gcc/analyzer/region.h  |  2 +-
 gcc/analyzer/sm.cc | 13 +-
 gcc/analyzer/sm.h  |  4 ++--
 gcc/analyzer/store.cc  | 26 ++--
 gcc/analyzer/store.h   | 10 
 gcc/analyzer/supergraph.cc | 21 
 gcc/analyzer/supergraph.h  |  6 ++---
 gcc/analyzer/svalue.cc |  4 ++--
 gcc/analyzer/svalue.h  |  2 +-
 28 files changed, 161 insertions(+), 151 deletions(-)

diff --git a/gcc/analyzer/analyzer.cc b/gcc/analyzer/analyzer.cc
index 0f998e3f66f7..f77dcd76c5cd 100644
--- a/gcc/analyzer/analyzer.cc
+++ b/gcc/analyzer/analyzer.cc
@@ -32,6 +32,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "tree-pretty-print.h"
 #include "diagnostic-event-id.h"
 #include "tree-dfa.h"
+#include "make-unique.h"
 
 #if ENABLE_ANALYZER
 
@@ -223,15 +224,15 @@ get_diagnostic_tree_for_gassign (const gassign 
*assign_stmt)
This is intended for debugging the analyzer rather than serialization and
thus is a string (or null, for NULL_TREE).  */
 
-json::value *
+std::unique_ptr
 tree_to_json (tree node)
 {
   if (!node)
-return new json::literal (json::JSON_NULL);
+return ::make_unique (json::JSON_NULL);
 
   pretty_printer pp;
   dump_generic_node (&pp, node, 0, TDF_VOPS|TDF_MEMSYMS, false);
-  return new json::string (pp_formatted_text (&pp));
+  return ::make_unique (pp_formatted_text (&pp));
 }
 
 /* Generate a JSON value for EVENT_ID.
@@ -239,41 +240,41 @@ tree_to_json (tree node)
thus is a string matching those seen in event messags (or null,
for unknown).  */
 
-json::value *
+std::unique_ptr
 diagnostic_event_id_to_json (const diagnostic_event_id_t &event_id)
 {
   if (event_id.known_p ())
 {
   pretty_printer pp;
   pp_printf (&pp, "%@", &event_id);
-  return new json::string (pp_formatted_text (&pp));
+  return ::make_unique (pp_formatted_text (&pp));
 }
   else
-return new json::literal (json::JSON_NULL);
+return ::make_unique (json::JSON_NULL);
 }
 
 /* Generate a JSON value for OFFSET.
This is intended for debugging the analyzer rather than serialization and
thus is a string.  */
 
-json::value *
+std::unique_ptr
 bit_offset_to_json (const bit_offset_t &offset)
 {
   pretty_prin

[gcc r15-4856] builtins: Fix expand_builtin_prefetch [PR117407]

2024-11-01 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:115ab8d7ad33a7f500460dc5af28f6912ddfb91c

commit r15-4856-g115ab8d7ad33a7f500460dc5af28f6912ddfb91c
Author: Jakub Jelinek 
Date:   Fri Nov 1 23:03:48 2024 +0100

builtins: Fix expand_builtin_prefetch [PR117407]

On Fri, Nov 01, 2024 at 04:47:35PM +0800, Haochen Jiang wrote:
> * builtins.cc (expand_builtin_prefetch): Use IN_RANGE to
>   avoid second usage of INTVAL.

I doubt this has been actually tested.

> --- a/gcc/builtins.cc
> +++ b/gcc/builtins.cc
> @@ -1297,7 +1297,7 @@ expand_builtin_prefetch (tree exp)
>else
>  op1 = expand_normal (arg1);
>/* Argument 1 must be 0, 1 or 2.  */
> -  if (INTVAL (op1) < 0 || INTVAL (op1) > 2)
> +  if (IN_RANGE (INTVAL (op1), 0, 2))
>  {
>warning (0, "invalid second argument to %<__builtin_prefetch%>;"
>  " using zero");
> @@ -1315,7 +1315,7 @@ expand_builtin_prefetch (tree exp)
>else
>  op2 = expand_normal (arg2);
>/* Argument 2 must be 0, 1, 2, or 3.  */
> -  if (INTVAL (op2) < 0 || INTVAL (op2) > 3)
> +  if (IN_RANGE (INTVAL (op2), 0, 3))
>  {
>warning (0, "invalid third argument to %<__builtin_prefetch%>; 
using zero");
>op2 = const0_rtx;

because it inverts the tests, previously it was warning when op1 wasn't
0, 1, 2, now it warns when it is 0, 1 or 2, previously it was warning
when op2 wasn't 0, 1, 2 or 3, now it warns when it is 0, 1, 2, or 3.

Fixed thusly.

2024-11-01  Jakub Jelinek  

PR bootstrap/117407
* builtins.cc (expand_builtin_prefetch): Use !IN_RANGE rather
than IN_RANGE.

Diff:
---
 gcc/builtins.cc | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/gcc/builtins.cc b/gcc/builtins.cc
index b8684411ea87..0d90c2ad5f86 100644
--- a/gcc/builtins.cc
+++ b/gcc/builtins.cc
@@ -1297,7 +1297,7 @@ expand_builtin_prefetch (tree exp)
   else
 op1 = expand_normal (arg1);
   /* Argument 1 must be 0, 1 or 2.  */
-  if (IN_RANGE (INTVAL (op1), 0, 2))
+  if (!IN_RANGE (INTVAL (op1), 0, 2))
 {
   warning (0, "invalid second argument to %<__builtin_prefetch%>;"
   " using zero");
@@ -1315,7 +1315,7 @@ expand_builtin_prefetch (tree exp)
   else
 op2 = expand_normal (arg2);
   /* Argument 2 must be 0, 1, 2, or 3.  */
-  if (IN_RANGE (INTVAL (op2), 0, 3))
+  if (!IN_RANGE (INTVAL (op2), 0, 3))
 {
   warning (0, "invalid third argument to %<__builtin_prefetch%>; using 
zero");
   op2 = const0_rtx;


[gcc r15-4859] [committed] Make LRA default for ft32 and remove -mlra option

2024-11-01 Thread Jeff Law via Gcc-cvs
https://gcc.gnu.org/g:4a5a63596dd82d20fd1cc11a69ec1e4729225645

commit r15-4859-g4a5a63596dd82d20fd1cc11a69ec1e4729225645
Author: Jeff Law 
Date:   Fri Nov 1 20:28:07 2024 -0600

[committed] Make LRA default for ft32 and remove -mlra option

I was looking to clean up an old patch I'm carrying in my tester.  My first
thought was that ft32 was likely going to be deprecated because it wasn't 
using
LRA -- which in turn would mean the patch in question could just be removed.

But then I checked, ft32 has an LRA option and if turned on it gets the 
exact
same test results as with reload.  While the port mentions a failure with
sieve.c, that's been there since the port was introduced in 2015.

It's working well enough that I think just converting it is the right thing 
to
do.  The testsuite patch which precipitated this one will follow separately.
I've kept the -mlra option for compatibility sake, but it's ignored.

Pushing to the trunk.

gcc/
* config/ft32/ft32.cc (ft32_lra_p): Remove.
(TARGET_LRA_P): Likewise.
* config/ft32/ft32.opt: Make -mlra ignored.
* doc/invoke.texi: Adjust documentation for -mlra on ft32.

Diff:
---
 gcc/config/ft32/ft32.cc  | 13 -
 gcc/config/ft32/ft32.opt |  4 ++--
 gcc/doc/invoke.texi  |  3 +--
 3 files changed, 3 insertions(+), 17 deletions(-)

diff --git a/gcc/config/ft32/ft32.cc b/gcc/config/ft32/ft32.cc
index 3c6e5fb1f6ca..80345dcdd7eb 100644
--- a/gcc/config/ft32/ft32.cc
+++ b/gcc/config/ft32/ft32.cc
@@ -831,19 +831,6 @@ ft32_target_case_values_threshold (void)
   ft32_addr_space_legitimate_address_p
 
 
-// Enabling LRA gives the infamous
-//internal compiler error: Max. number of generated reload insns per insn 
is achieved (90)
-// errors e.g. when compiling sieve.c
-
-static bool
-ft32_lra_p (void)
-{
-  return ft32_lra_flag;
-}
-
-#undef TARGET_LRA_P
-#define TARGET_LRA_P ft32_lra_p
-
 static bool
 reg_ok_for_base_p (rtx r, bool strict)
 {
diff --git a/gcc/config/ft32/ft32.opt b/gcc/config/ft32/ft32.opt
index cecc54845e30..419c82a7102e 100644
--- a/gcc/config/ft32/ft32.opt
+++ b/gcc/config/ft32/ft32.opt
@@ -23,8 +23,8 @@ Target Mask(SIM)
 Target the software simulator.
 
 mlra
-Target Var(ft32_lra_flag) Init(0) Save
-Use LRA instead of reload.
+Target RejectNegative Ignore
+Ignored, but preserved for backward compatibility.
 
 mnodiv
 Target Mask(NODIV)
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index fd6c0c447096..8d92d46eca16 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -25998,8 +25998,7 @@ I/O functions are needed.
 
 @opindex mlra
 @item -mlra
-Enable Local Register Allocation.  This is still experimental for FT32,
-so by default the compiler uses standard reload.
+Does nothing.  Preserved for backward compatibility.
 
 @opindex mnodiv
 @item -mnodiv


[gcc r15-4860] [committed] ft32 doesn't support trampolines.

2024-11-01 Thread Jeff Law via Gcc-cvs
https://gcc.gnu.org/g:6a2e8913df605e62f20833a6e688ea1950147edc

commit r15-4860-g6a2e8913df605e62f20833a6e688ea1950147edc
Author: Jeff Law 
Date:   Fri Nov 1 20:31:11 2024 -0600

[committed] ft32 doesn't support trampolines.

The ft32 has never supported trampolines, but the target supports bits 
weren't
appropriately updated.

Fixed thusly.

gcc/testsuite
* lib/target-supports.exp (check_effective_target_trampolines): ft32
does not support trampolines.

Diff:
---
 gcc/testsuite/lib/target-supports.exp | 1 +
 1 file changed, 1 insertion(+)

diff --git a/gcc/testsuite/lib/target-supports.exp 
b/gcc/testsuite/lib/target-supports.exp
index c45cc50e0ad8..75703ddca608 100644
--- a/gcc/testsuite/lib/target-supports.exp
+++ b/gcc/testsuite/lib/target-supports.exp
@@ -639,6 +639,7 @@ proc check_effective_target_trampolines { } {
 if { [istarget avr-*-*]
 || [istarget msp430-*-*]
 || [istarget nvptx-*-*]
+|| [istarget ft32-*-*]
 || [istarget pru-*-*]
 || [istarget bpf-*-*] } {
return 0;


[gcc r15-4852] Update bitwise_or op_range.

2024-11-01 Thread Andrew Macleod via Gcc-cvs
https://gcc.gnu.org/g:253fe0f6269516e37b3ef12a0d18e539b3cabd62

commit r15-4852-g253fe0f6269516e37b3ef12a0d18e539b3cabd62
Author: Andrew MacLeod 
Date:   Thu Oct 31 14:07:00 2024 -0400

Update bitwise_or op_range.

If the LHS of a bitwise OR is positive, then so are both operands when
using op1_range or op2_range.

gcc/
* range-op.cc (operator_bitwise_or::op1_range): If LHS is signed
positive, so are both operands.

gcc/testsuite
* g++.dg/cpp23/attr-assume-opt.C (f2b): Alternate flow test.

Diff:
---
 gcc/range-op.cc  | 13 ++
 gcc/testsuite/g++.dg/cpp23/attr-assume-opt.C | 37 +++-
 2 files changed, 49 insertions(+), 1 deletion(-)

diff --git a/gcc/range-op.cc b/gcc/range-op.cc
index 58734cddd2fd..5a1eb59f3cd4 100644
--- a/gcc/range-op.cc
+++ b/gcc/range-op.cc
@@ -3822,6 +3822,19 @@ operator_bitwise_or::op1_range (irange &r, tree type,
   r.set_zero (type);
   return true;
 }
+
+  //   if (A < 0 && B < 0)
+  // Sometimes gets translated to
+  //   _1 = A | B
+  //   if (_1 < 0))
+  // It is useful for ranger to recognize a positive LHS means the RHS
+  // operands are also positive when dealing with the ELSE range..
+  if (TYPE_SIGN (type) == SIGNED && wi::ge_p (lhs.lower_bound (), 0, SIGNED))
+{
+  unsigned prec = TYPE_PRECISION (type);
+  r.set (type, wi::zero (prec), wi::max_value (prec, SIGNED));
+  return true;
+}
   r.set_varying (type);
   return true;
 }
diff --git a/gcc/testsuite/g++.dg/cpp23/attr-assume-opt.C 
b/gcc/testsuite/g++.dg/cpp23/attr-assume-opt.C
index 88d5e78dbbae..e61ba7a27e0f 100644
--- a/gcc/testsuite/g++.dg/cpp23/attr-assume-opt.C
+++ b/gcc/testsuite/g++.dg/cpp23/attr-assume-opt.C
@@ -38,5 +38,40 @@ f3 (int x, int y, int z)
   return 1;
 }
 
+// This is the same as f2, except there is more complicated flow and 
+// required a range-op update to bitwise or.
+
+void barn(int x);
+// assume (x+12 == 14 && y >= 0 && y + 10 < 13 && z + 4 >= 4 && z - 2 < 18)
+// in different order and form with function calls to cause branches.
+bool assume_func (int x, int y, int z)
+{
+  if (z - 2 >= 18)
+return false;
+  if (x+12 != 14)
+return false;
+  barn (x);
+  if (y < 0)
+return false;
+  if (z + 4 < 4)
+return false;
+  barn (y);
+  if (y + 10 >= 13)
+return false;
+  barn (z);
+  return true;
+}
+
+int
+f2b (int x, int y, int z)
+{
+  [[assume (assume_func (x, y, z))]];
+  unsigned q = x + y + z;
+  if (q*2 > 46)
+return 0;
+  return 1;
+}
+
+
 /* { dg-final { scan-tree-dump-times "return 0" 0 "vrp2" } } */
-/* { dg-final { scan-tree-dump-times "return 1" 3 "vrp2" } } */
+/* { dg-final { scan-tree-dump-times "return 1" 4 "vrp2" } } */


[gcc r15-4850] Make fur_edge accessible.

2024-11-01 Thread Andrew Macleod via Gcc-cvs
https://gcc.gnu.org/g:fe22e18c1b00f4d95aec6d40333aecd1e9c700c7

commit r15-4850-gfe22e18c1b00f4d95aec6d40333aecd1e9c700c7
Author: Andrew MacLeod 
Date:   Thu Oct 31 15:44:15 2024 -0400

Make fur_edge accessible.

Move the decl of fur_edge out of the source file into the header file.

* gimple-range-fold.cc (class fur_edge): Relocate from here.
(fur_edge::fur_edge): Also move to:
* gimple-range-fold.h (class fur_edge): Relocate to here.
(fur_edge::fur_edge): Likewise.

Diff:
---
 gcc/gimple-range-fold.cc | 20 
 gcc/gimple-range-fold.h  | 14 ++
 2 files changed, 14 insertions(+), 20 deletions(-)

diff --git a/gcc/gimple-range-fold.cc b/gcc/gimple-range-fold.cc
index 82dd363f2eca..a4063b718f6f 100644
--- a/gcc/gimple-range-fold.cc
+++ b/gcc/gimple-range-fold.cc
@@ -109,26 +109,6 @@ fur_source::register_relation (edge e ATTRIBUTE_UNUSED,
 {
 }
 
-// This version of fur_source will pick a range up off an edge.
-
-class fur_edge : public fur_source
-{
-public:
-  fur_edge (edge e, range_query *q = NULL);
-  virtual bool get_operand (vrange &r, tree expr) override;
-  virtual bool get_phi_operand (vrange &r, tree expr, edge e) override;
-private:
-  edge m_edge;
-};
-
-// Instantiate an edge based fur_source.
-
-inline
-fur_edge::fur_edge (edge e, range_query *q) : fur_source (q)
-{
-  m_edge = e;
-}
-
 // Get the value of EXPR on edge m_edge.
 
 bool
diff --git a/gcc/gimple-range-fold.h b/gcc/gimple-range-fold.h
index 37c49596c332..109510853a2d 100644
--- a/gcc/gimple-range-fold.h
+++ b/gcc/gimple-range-fold.h
@@ -150,6 +150,20 @@ public:
  tree op2) override;
 };
 
+
+// This version of fur_source will pick a range up off an edge.
+
+class fur_edge : public fur_source
+{
+public:
+  fur_edge (edge e, range_query *q = NULL) : fur_source (q)
+{ m_edge = e; }
+  virtual bool get_operand (vrange &r, tree expr) override;
+  virtual bool get_phi_operand (vrange &r, tree expr, edge e) override;
+private:
+  edge m_edge;
+};
+
 // This class uses ranges to fold a gimple statement producing a range for
 // the LHS.  The source of all operands is supplied via the fur_source class
 // which provides a range_query as well as a source location and any other


[gcc r13-9160] Fortran: Prevent unwanted finalization with -w option [PR112459]

2024-11-01 Thread Paul Thomas via Gcc-cvs
https://gcc.gnu.org/g:e4276844d09f648ba010a890ce7a5bdce17abc41

commit r13-9160-ge4276844d09f648ba010a890ce7a5bdce17abc41
Author: Paul Thomas 
Date:   Sat Dec 16 13:59:45 2023 +

Fortran: Prevent unwanted finalization with -w option [PR112459]

2023-12-16  Paul Thomas  

gcc/fortran
PR fortran/112459
* trans-array.cc (gfc_trans_array_constructor_value): Replace
gfc_notification_std with explicit logical expression that
selects F2003/2008 and excludes -std=default/gnu.
* trans-expr.cc (gfc_conv_expr): Ditto.

gcc/testsuite/
PR fortran/112459
* gfortran.dg/pr112459.f90: New test.

(cherry picked from commit 9a1105b770df9a9b485705398abbb74b5c487a25)

Diff:
---
 gcc/fortran/trans-array.cc |  4 +++-
 gcc/fortran/trans-expr.cc  |  4 +++-
 gcc/testsuite/gfortran.dg/pr112459.f90 | 37 ++
 3 files changed, 43 insertions(+), 2 deletions(-)

diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc
index eecb342f32af..fa432505c254 100644
--- a/gcc/fortran/trans-array.cc
+++ b/gcc/fortran/trans-array.cc
@@ -2310,7 +2310,9 @@ gfc_trans_array_constructor_value (stmtblock_t * pblock,
  Corrigenda 1 TO 4 for fortran 2008 (f08/0011).
 
  Transmit finalization of this constructor through 'finalblock'. */
-  if (!gfc_notification_std (GFC_STD_F2018_DEL) && finalblock != NULL
+  if ((gfc_option.allow_std & (GFC_STD_F2008 | GFC_STD_F2003))
+  && !(gfc_option.allow_std & GFC_STD_GNU)
+  && finalblock != NULL
   && gfc_may_be_finalized (ts)
   && ctr > 0 && desc != NULL_TREE
   && GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (desc)))
diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc
index 7e3c38e5f92d..46348d7df456 100644
--- a/gcc/fortran/trans-expr.cc
+++ b/gcc/fortran/trans-expr.cc
@@ -9561,7 +9561,9 @@ gfc_conv_expr (gfc_se * se, gfc_expr * expr)
 executable construct containing the reference. This, in fact,
 was later deleted by the Combined Techical Corrigenda 1 TO 4 for
 fortran 2008 (f08/0011).  */
-  if (!gfc_notification_std (GFC_STD_F2018_DEL) && expr->must_finalize
+  if ((gfc_option.allow_std & (GFC_STD_F2008 | GFC_STD_F2003))
+ && !(gfc_option.allow_std & GFC_STD_GNU)
+ && expr->must_finalize
  && gfc_may_be_finalized (expr->ts))
{
  gfc_warning (0, "The structure constructor at %C has been"
diff --git a/gcc/testsuite/gfortran.dg/pr112459.f90 
b/gcc/testsuite/gfortran.dg/pr112459.f90
new file mode 100644
index ..7db243c224a2
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr112459.f90
@@ -0,0 +1,37 @@
+! { dg-do compile }
+! { dg-options "-w -fdump-tree-original" }
+!
+! Contributed by Sebastian Bardeau  
+!
+module mymod
+  type mysubtype
+integer(kind=4), allocatable :: a(:)
+  end type mysubtype
+  type :: mytype
+integer :: i
+type(mysubtype) :: sub
+  contains
+final :: mytype_final
+  end type mytype
+contains
+  subroutine mysubtype_final(sub)
+type(mysubtype), intent(inout) :: sub
+print *,'MYSUBTYPE>FINAL'
+if (allocated(sub%a)) deallocate(sub%a)
+  end subroutine mysubtype_final
+  subroutine mytype_final(typ)
+type(mytype), intent(inout) :: typ
+print *,"MYTYPE>FINAL"
+call mysubtype_final(typ%sub)
+  end subroutine mytype_final
+end module mymod
+!
+program myprog
+  use mymod
+  type(mytype), pointer :: c
+  print *,"Before allocation"
+  allocate(c)
+  print *,"After allocation"
+end program myprog
+! Final subroutines were called with std=gnu and -w = > 14 "_final"s.
+! { dg-final { scan-tree-dump-times "_final" 12 "original" } }


[gcc r15-4831] Support Intel AMX-TRANSPOSE

2024-11-01 Thread Haochen Jiang via Gcc-cvs
https://gcc.gnu.org/g:9f2f36a7db9070a9d6e1f0fb736a12217651d169

commit r15-4831-g9f2f36a7db9070a9d6e1f0fb736a12217651d169
Author: Haochen Jiang 
Date:   Fri Nov 1 10:04:38 2024 +0800

Support Intel AMX-TRANSPOSE

gcc/ChangeLog:

* common/config/i386/cpuinfo.h (get_available_features):
Detect AMX-TRANSPOSE.
* common/config/i386/i386-common.cc
(OPTION_MASK_ISA2_AMX_TRANSPOSE_SET,
OPTION_MASK_ISA2_AMX_TRANSPOSE_UNSET): New.
(ix86_handle_option): Handle -mamx-transpose.
* common/config/i386/i386-cpuinfo.h (enum processor_features):
Add FEATURE_AMX_TRANSPOSE.
* common/config/i386/i386-isas.h: Add ISA_NAME_TABLE_ENTRY for
amx-transpose.
* config.gcc: Add amxtransposeintrin.h.
* config/i386/cpuid.h (bit_AMX_TRANSPOSE): New.
* config/i386/i386-c.cc (ix86_target_macros_internal): Define
__AMX_TRANSPOSE__.
* config/i386/i386-isa.def (AMX_TRANSPOSE): Add
DEF_PTA(AMX_TRANSPOSE).
* config/i386/i386-options.cc (ix86_valid_target_attribute_inner_p):
Handle amx-transpose.
* config/i386/i386.opt: Add option -mamx-transpose.
* config/i386/i386.opt.urls: Regenerated.
* config/i386/immintrin.h: Include amxtransposeintrin.h.
* doc/extend.texi: Document amx-transpose.
* doc/invoke.texi: Document -mamx-transpose.
* doc/sourcebuild.texi: Document target amx-transpose.
* config/i386/amxtransposeintrin.h: New file.

gcc/testsuite/ChangeLog:

* g++.dg/other/i386-2.C: Add -mamx-transpose.
* g++.dg/other/i386-3.C: Ditto.
* gcc.target/i386/amx-check.h: Add new check for amx-transpose.
(__tilepair): New.
(zero_pair_tile_src): New.
(check_pair_tile_register): New.
* gcc.target/i386/funcspec-56.inc: Add new target attribute.
* gcc.target/i386/amx-helper.h: Add amx-transpose support.
(init_pair_tile_src): New function.
* gcc.target/i386/sse-12.c: Add -mamx-tranpose.
* gcc.target/i386/sse-13.c: Ditto.
* gcc.target/i386/sse-14.c: Ditto.
* gcc.target/i386/sse-22.c: Add amx-transpose.
* gcc.target/i386/sse-23.c: Ditto.
* lib/target-supports.exp (check_effective_target_amx_transposed): 
New.
* gcc.target/i386/amxtranspose-asmatt-1.c: New test.
* gcc.target/i386/amxtranspose-asmintel-1.c: Ditto.
* gcc.target/i386/amxtranspose-2rpntlvw-2.c: Ditto.
* gcc.target/i386/amxtranspose-conjtcmmimfp16ps-2.c: Ditto.
* gcc.target/i386/amxtranspose-conjtfp16-2.c: Ditto.
* gcc.target/i386/amxtranspose-tcmmimfp16ps-2.c: Ditto.
* gcc.target/i386/amxtranspose-tcmmrlfp16ps-2.c: Ditto.
* gcc.target/i386/amxtranspose-tdpbf16ps-2.c: Ditto.
* gcc.target/i386/amxtranspose-tdpfp16ps-2.c: Ditto.
* gcc.target/i386/amxtranspose-tmmultf32ps-2.c: Ditto.
* gcc.target/i386/amxtranspose-transposed-2.c: Ditto.

Diff:
---
 gcc/common/config/i386/cpuinfo.h   |   2 +
 gcc/common/config/i386/i386-common.cc  |  19 ++-
 gcc/common/config/i386/i386-cpuinfo.h  |   1 +
 gcc/common/config/i386/i386-isas.h |   2 +
 gcc/config.gcc |   3 +-
 gcc/config/i386/amxtransposeintrin.h   | 177 +
 gcc/config/i386/cpuid.h|   1 +
 gcc/config/i386/i386-c.cc  |   2 +
 gcc/config/i386/i386-isa.def   |   1 +
 gcc/config/i386/i386-options.cc|   4 +-
 gcc/config/i386/i386.opt   |   4 +
 gcc/config/i386/i386.opt.urls  |   3 +
 gcc/config/i386/immintrin.h|   2 +
 gcc/doc/extend.texi|   5 +
 gcc/doc/invoke.texi|  11 +-
 gcc/doc/sourcebuild.texi   |   3 +
 gcc/testsuite/g++.dg/other/i386-2.C|   2 +-
 gcc/testsuite/g++.dg/other/i386-3.C|   2 +-
 gcc/testsuite/gcc.target/i386/amx-check.h  |  38 +
 gcc/testsuite/gcc.target/i386/amx-helper.h |  40 -
 .../gcc.target/i386/amxtranspose-2rpntlvw-2.c  |  41 +
 .../gcc.target/i386/amxtranspose-asmatt-1.c|  39 +
 .../gcc.target/i386/amxtranspose-asmintel-1.c  |  35 
 .../i386/amxtranspose-conjtcmmimfp16ps-2.c |  55 +++
 .../gcc.target/i386/amxtranspose-conjtfp16-2.c |  48 ++
 .../gcc.target/i386/amxtranspose-tcmmimfp16ps-2.c  |  55 +++
 .../gcc.target/i386/amxtranspose-tcmmrlfp16ps-2.c  |  55 +++
 .../gcc.target/i386/amxtranspose-tdpbf16ps-2.c |  53 ++
 .../gcc.

[gcc r15-4835] Fortran: Fix problems with substring selectors in ASSOCIATE [PR115700]

2024-11-01 Thread Paul Thomas via Gcc-cvs
https://gcc.gnu.org/g:7f93910a8b5d606ad742a3594750f0c2b20d8bda

commit r15-4835-g7f93910a8b5d606ad742a3594750f0c2b20d8bda
Author: Paul Thomas 
Date:   Fri Nov 1 07:45:00 2024 +

Fortran: Fix problems with substring selectors in ASSOCIATE [PR115700]

2024-11-01  Paul Thomas  

gcc/fortran
PR fortran/115700
* resolve.cc (resolve_assoc_var): Extract a substring reference
with missing as well as non-constant start or end.

gcc/testsuite/
PR fortran/115700
* gfortran.dg/associate_69.f90: Activate commented out tests.
* gfortran.dg/associate_70.f90: Test correct functioning of
references in associate_69.f90 tests.

Diff:
---
 gcc/fortran/resolve.cc |  8 ++---
 gcc/testsuite/gfortran.dg/associate_69.f90 | 23 +-
 gcc/testsuite/gfortran.dg/associate_70.f90 | 50 +-
 3 files changed, 54 insertions(+), 27 deletions(-)

diff --git a/gcc/fortran/resolve.cc b/gcc/fortran/resolve.cc
index 8045deddd8ad..b14d3e776ab7 100644
--- a/gcc/fortran/resolve.cc
+++ b/gcc/fortran/resolve.cc
@@ -9883,10 +9883,10 @@ resolve_assoc_var (gfc_symbol* sym, bool resolve_target)
   gfc_ref *ref;
   for (ref = target->ref; ref; ref = ref->next)
if (ref->type == REF_SUBSTRING
-   && ((ref->u.ss.start
-&& ref->u.ss.start->expr_type != EXPR_CONSTANT)
-   || (ref->u.ss.end
-   && ref->u.ss.end->expr_type != EXPR_CONSTANT)))
+   && (ref->u.ss.start == NULL
+   || ref->u.ss.start->expr_type != EXPR_CONSTANT
+   || ref->u.ss.end == NULL
+   || ref->u.ss.end->expr_type != EXPR_CONSTANT))
  break;
 
   if (!sym->ts.u.cl)
diff --git a/gcc/testsuite/gfortran.dg/associate_69.f90 
b/gcc/testsuite/gfortran.dg/associate_69.f90
index 28f488bb2746..35db417867d4 100644
--- a/gcc/testsuite/gfortran.dg/associate_69.f90
+++ b/gcc/testsuite/gfortran.dg/associate_69.f90
@@ -2,10 +2,14 @@
 ! { dg-options "-Og -Wuninitialized -Wmaybe-uninitialized 
-fdump-tree-optimized" }
 !
 ! PR fortran/115700 - Bogus warning for associate with assumed-length 
character array
+! This testcase checks for the suppression of the bogus error and associate_70 
for
+! correct results.
 !
 subroutine mvce(x)
   implicit none
   character(len=*), dimension(:), intent(in)  :: x
+  integer :: i
+  i = len(x)
 
   associate (tmp1 => x)
 if (len (tmp1) /= len (x)) stop 1
@@ -19,15 +23,18 @@ subroutine mvce(x)
 if (len (tmp3) /= len (x)) stop 3
   end associate
 
-! The following associate blocks still produce bogus warnings:
+  associate (tmp4 => x(:)(1:))
+if (len (tmp4) /= len (x)) stop 4
+  end associate
 
-! associate (tmp4 => x(:)(1:))
-!   if (len (tmp4) /= len (x)) stop 4
-! end associate
-!
-! associate (tmp5 => x(1:)(1:))
-!   if (len (tmp5) /= len (x)) stop 5
-! end associate
+  associate (tmp5 => x(1:)(1:))
+if (len (tmp5) /= len (x)) stop 5
+  end associate
+
+  associate (temp6 => x(:)(1:i/2))
+if (len (temp6) /= i/2) stop 6
+  end associate
 end
 
 ! { dg-final { scan-tree-dump-not " \\.tmp" "optimized" } }
+! { dg-final { scan-tree-dump-times " \\.temp6" 7 "optimized" } }
diff --git a/gcc/testsuite/gfortran.dg/associate_70.f90 
b/gcc/testsuite/gfortran.dg/associate_70.f90
index b8916f4c70fd..ddb38b84c4b3 100644
--- a/gcc/testsuite/gfortran.dg/associate_70.f90
+++ b/gcc/testsuite/gfortran.dg/associate_70.f90
@@ -3,37 +3,57 @@
 !
 ! Test fix for PR115700 comment 5, in which ‘.tmp1’ is used uninitialized and
 ! both normal and scalarized array references did not work correctly.
+! This testcase checks for correct results and associate_69 for suppression
+! of the bogus error.
 !
 ! Contributed by Harald Anlauf  
 !
   character(4), dimension(3) :: chr = ['abcd', 'efgh', 'ijkl']
   call mvce (chr)
   if (any (chr /= ['ABcd', 'EFgh', 'IJkl'])) stop 1
+
 contains
   subroutine mvce(x)
 implicit none
-character(len=*), dimension(:), intent(inOUT), target :: x
+character(len=*), dimension(:), intent(inOUT) :: x
 integer :: i
 i = len(x)
 
-! This was broken
-associate (tmp1 => x(:)(1:i/2))
-  if (len (tmp1) /= i/2) stop 2
-  if (tmp1(2) /= 'ef') stop 3
-  if (any (tmp1 /= ['ab', 'ef', 'ij'])) stop 4
-  tmp1 = ['AB','EF','IJ']
+associate (tmp1 => x)
+  if (len (tmp1) /= len (x)) stop 2
+  tmp1(2)(3:4) = '12'
+end associate
+if (any (x /= ['abcd', 'ef12', 'ijkl'])) stop 3
+
+associate (tmp2 => x(1:))
+  if (len (tmp2) /= len (x)) stop 4
+  tmp2(2)(1:2) = '34'
+end associate
+if (any (x /= ['abcd', '3412', 'ijkl'])) stop 5
+
+associate (tmp3 => x(1:)(:))
+  if (len (tmp3) /= len (x)) stop 6
+  tmp3(3)(3:4) = '56'
+end associate
+if (any (x /= ['abcd', '3412', 'ij56'])) stop 7
+
+associate (tmp4 => x(:)(1:))
+  if (len (tmp4) /= len (x)) stop 8
+  tmp4(3)(1:2) = '78'

[gcc r12-10796] Fortran: Fix ICE with structure constructor in data statement [PR79685]

2024-11-01 Thread Paul Thomas via Gcc-cvs
https://gcc.gnu.org/g:5210bf4d494d6ea60722193c7eb97827e73f5295

commit r12-10796-g5210bf4d494d6ea60722193c7eb97827e73f5295
Author: Paul Thomas 
Date:   Fri Oct 25 17:59:03 2024 +0100

Fortran: Fix ICE with structure constructor in data statement [PR79685]

2024-10-25  Paul Thomas  

gcc/fortran
PR fortran/79685
* decl.cc (match_data_constant): Find the symtree instead of
the symbol so the use renamed symbols are found. Pass this and
the derived type to gfc_match_structure_constructor.
* match.h: Update prototype of gfc_match_structure_contructor.
* primary.cc (gfc_match_structure_constructor): Remove call to
gfc_get_ha_sym_tree and use caller supplied symtree instead.

gcc/testsuite/
PR fortran/79685
* gfortran.dg/use_rename_13.f90: New test.

(cherry picked from commit 6cb1da72cac166bd3b005c0430557b68b9761da5)

Diff:
---
 gcc/fortran/decl.cc |  7 --
 gcc/fortran/match.h |  2 +-
 gcc/fortran/primary.cc  |  8 +++
 gcc/testsuite/gfortran.dg/use_rename_13.f90 | 37 +
 4 files changed, 46 insertions(+), 8 deletions(-)

diff --git a/gcc/fortran/decl.cc b/gcc/fortran/decl.cc
index d98f98d7ec61..8c101b0daf79 100644
--- a/gcc/fortran/decl.cc
+++ b/gcc/fortran/decl.cc
@@ -376,6 +376,7 @@ match_data_constant (gfc_expr **result)
   gfc_expr *expr;
   match m;
   locus old_loc;
+  gfc_symtree *symtree;
 
   m = gfc_match_literal_constant (&expr, 1);
   if (m == MATCH_YES)
@@ -435,9 +436,11 @@ match_data_constant (gfc_expr **result)
   if (m != MATCH_YES)
 return m;
 
-  if (gfc_find_symbol (name, NULL, 1, &sym))
+  if (gfc_find_sym_tree (name, NULL, 1, &symtree))
 return MATCH_ERROR;
 
+  sym = symtree->n.sym;
+
   if (sym && sym->attr.generic)
 dt_sym = gfc_find_dt_in_generic (sym);
 
@@ -451,7 +454,7 @@ match_data_constant (gfc_expr **result)
   return MATCH_ERROR;
 }
   else if (dt_sym && gfc_fl_struct (dt_sym->attr.flavor))
-return gfc_match_structure_constructor (dt_sym, result);
+return gfc_match_structure_constructor (dt_sym, symtree, result);
 
   /* Check to see if the value is an initialization array expression.  */
   if (sym->value->expr_type == EXPR_ARRAY)
diff --git a/gcc/fortran/match.h b/gcc/fortran/match.h
index 495c93e0b5ce..d22733568581 100644
--- a/gcc/fortran/match.h
+++ b/gcc/fortran/match.h
@@ -296,7 +296,7 @@ match gfc_match_bind_c_stmt (void);
 match gfc_match_bind_c (gfc_symbol *, bool);
 
 /* primary.cc.  */
-match gfc_match_structure_constructor (gfc_symbol *, gfc_expr **);
+match gfc_match_structure_constructor (gfc_symbol *, gfc_symtree *, gfc_expr 
**);
 match gfc_match_variable (gfc_expr **, int);
 match gfc_match_equiv_variable (gfc_expr **);
 match gfc_match_actual_arglist (int, gfc_actual_arglist **, bool = false);
diff --git a/gcc/fortran/primary.cc b/gcc/fortran/primary.cc
index 4f8bd129ee94..328e92b5aefe 100644
--- a/gcc/fortran/primary.cc
+++ b/gcc/fortran/primary.cc
@@ -3380,18 +3380,16 @@ gfc_convert_to_structure_constructor (gfc_expr *e, 
gfc_symbol *sym, gfc_expr **c
 
 
 match
-gfc_match_structure_constructor (gfc_symbol *sym, gfc_expr **result)
+gfc_match_structure_constructor (gfc_symbol *sym, gfc_symtree *symtree,
+gfc_expr **result)
 {
   match m;
   gfc_expr *e;
-  gfc_symtree *symtree;
   bool t = true;
 
-  gfc_get_ha_sym_tree (sym->name, &symtree);
-
   e = gfc_get_expr ();
-  e->symtree = symtree;
   e->expr_type = EXPR_FUNCTION;
+  e->symtree = symtree;
   e->where = gfc_current_locus;
 
   gcc_assert (gfc_fl_struct (sym->attr.flavor)
diff --git a/gcc/testsuite/gfortran.dg/use_rename_13.f90 
b/gcc/testsuite/gfortran.dg/use_rename_13.f90
new file mode 100644
index ..97f26f42f762
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/use_rename_13.f90
@@ -0,0 +1,37 @@
+! { dg-do compile }
+!
+! Test the fix for pr79685, which failed as in the comments below.
+!
+! Contributed by Juergen Reuter  
+!
+module omega_color
+  implicit none
+
+  type omega_color_factor
+ integer :: i
+  end type
+
+  type(omega_color_factor), parameter :: op = omega_color_factor (199)
+
+end module
+
+module foo
+  use omega_color, ocf => omega_color_factor, ocfp => op
+  implicit none
+
+  type(ocf) :: table_color_factors1 = ocf(42)
+  type(ocf) :: table_color_factors2
+  type(ocf) :: table_color_factors3 (2)
+  type(ocf) :: table_color_factors4
+  data table_color_factors2 / ocf(99) /! This failed in 
gfc_match_structure_constructor.
+  data table_color_factors3 / ocf(1), ocf(2) / ! ditto.
+  data table_color_factors4 / ocfp /
+end module
+
+  use foo
+  if (table_color_factors1%i .ne. 42) stop 1
+  if (table_color_factors2%i .ne. 99) stop 2
+  if (any (table_color_factors3%i .ne. [1,2])) stop 3
+  if (table_color_factors4%i .ne. 199) stop 4
+end
+


[gcc r14-10863] Fortran: Fix ICE with structure constructor in data statement [PR79685]

2024-11-01 Thread Paul Thomas via Gcc-cvs
https://gcc.gnu.org/g:9a5ee8da09b705fc2a4197453789db0749387db3

commit r14-10863-g9a5ee8da09b705fc2a4197453789db0749387db3
Author: Paul Thomas 
Date:   Fri Oct 25 17:59:03 2024 +0100

Fortran: Fix ICE with structure constructor in data statement [PR79685]

2024-10-25  Paul Thomas  

gcc/fortran
PR fortran/79685
* decl.cc (match_data_constant): Find the symtree instead of
the symbol so the use renamed symbols are found. Pass this and
the derived type to gfc_match_structure_constructor.
* match.h: Update prototype of gfc_match_structure_contructor.
* primary.cc (gfc_match_structure_constructor): Remove call to
gfc_get_ha_sym_tree and use caller supplied symtree instead.

gcc/testsuite/
PR fortran/79685
* gfortran.dg/use_rename_13.f90: New test.

(cherry picked from commit 6cb1da72cac166bd3b005c0430557b68b9761da5)

Diff:
---
 gcc/fortran/decl.cc |  7 --
 gcc/fortran/match.h |  2 +-
 gcc/fortran/primary.cc  |  8 +++
 gcc/testsuite/gfortran.dg/use_rename_13.f90 | 37 +
 4 files changed, 46 insertions(+), 8 deletions(-)

diff --git a/gcc/fortran/decl.cc b/gcc/fortran/decl.cc
index b8308aeee550..119c9dffa033 100644
--- a/gcc/fortran/decl.cc
+++ b/gcc/fortran/decl.cc
@@ -376,6 +376,7 @@ match_data_constant (gfc_expr **result)
   gfc_expr *expr;
   match m;
   locus old_loc;
+  gfc_symtree *symtree;
 
   m = gfc_match_literal_constant (&expr, 1);
   if (m == MATCH_YES)
@@ -436,9 +437,11 @@ match_data_constant (gfc_expr **result)
   if (m != MATCH_YES)
 return m;
 
-  if (gfc_find_symbol (name, NULL, 1, &sym))
+  if (gfc_find_sym_tree (name, NULL, 1, &symtree))
 return MATCH_ERROR;
 
+  sym = symtree->n.sym;
+
   if (sym && sym->attr.generic)
 dt_sym = gfc_find_dt_in_generic (sym);
 
@@ -452,7 +455,7 @@ match_data_constant (gfc_expr **result)
   return MATCH_ERROR;
 }
   else if (dt_sym && gfc_fl_struct (dt_sym->attr.flavor))
-return gfc_match_structure_constructor (dt_sym, result);
+return gfc_match_structure_constructor (dt_sym, symtree, result);
 
   /* Check to see if the value is an initialization array expression.  */
   if (sym->value->expr_type == EXPR_ARRAY)
diff --git a/gcc/fortran/match.h b/gcc/fortran/match.h
index b09921357fd1..e84ec913f78c 100644
--- a/gcc/fortran/match.h
+++ b/gcc/fortran/match.h
@@ -300,7 +300,7 @@ match gfc_match_bind_c_stmt (void);
 match gfc_match_bind_c (gfc_symbol *, bool);
 
 /* primary.cc.  */
-match gfc_match_structure_constructor (gfc_symbol *, gfc_expr **);
+match gfc_match_structure_constructor (gfc_symbol *, gfc_symtree *, gfc_expr 
**);
 match gfc_match_variable (gfc_expr **, int);
 match gfc_match_equiv_variable (gfc_expr **);
 match gfc_match_actual_arglist (int, gfc_actual_arglist **, bool = false);
diff --git a/gcc/fortran/primary.cc b/gcc/fortran/primary.cc
index c4821030ebb5..478fbe2be61e 100644
--- a/gcc/fortran/primary.cc
+++ b/gcc/fortran/primary.cc
@@ -3520,18 +3520,16 @@ gfc_convert_to_structure_constructor (gfc_expr *e, 
gfc_symbol *sym, gfc_expr **c
 
 
 match
-gfc_match_structure_constructor (gfc_symbol *sym, gfc_expr **result)
+gfc_match_structure_constructor (gfc_symbol *sym, gfc_symtree *symtree,
+gfc_expr **result)
 {
   match m;
   gfc_expr *e;
-  gfc_symtree *symtree;
   bool t = true;
 
-  gfc_get_ha_sym_tree (sym->name, &symtree);
-
   e = gfc_get_expr ();
-  e->symtree = symtree;
   e->expr_type = EXPR_FUNCTION;
+  e->symtree = symtree;
   e->where = gfc_current_locus;
 
   gcc_assert (gfc_fl_struct (sym->attr.flavor)
diff --git a/gcc/testsuite/gfortran.dg/use_rename_13.f90 
b/gcc/testsuite/gfortran.dg/use_rename_13.f90
new file mode 100644
index ..97f26f42f762
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/use_rename_13.f90
@@ -0,0 +1,37 @@
+! { dg-do compile }
+!
+! Test the fix for pr79685, which failed as in the comments below.
+!
+! Contributed by Juergen Reuter  
+!
+module omega_color
+  implicit none
+
+  type omega_color_factor
+ integer :: i
+  end type
+
+  type(omega_color_factor), parameter :: op = omega_color_factor (199)
+
+end module
+
+module foo
+  use omega_color, ocf => omega_color_factor, ocfp => op
+  implicit none
+
+  type(ocf) :: table_color_factors1 = ocf(42)
+  type(ocf) :: table_color_factors2
+  type(ocf) :: table_color_factors3 (2)
+  type(ocf) :: table_color_factors4
+  data table_color_factors2 / ocf(99) /! This failed in 
gfc_match_structure_constructor.
+  data table_color_factors3 / ocf(1), ocf(2) / ! ditto.
+  data table_color_factors4 / ocfp /
+end module
+
+  use foo
+  if (table_color_factors1%i .ne. 42) stop 1
+  if (table_color_factors2%i .ne. 99) stop 2
+  if (any (table_color_factors3%i .ne. [1,2])) stop 3
+  if (table_color_factors4%i .ne. 199) stop 4
+end
+


[gcc r13-9161] Fortran: Fix ICE with structure constructor in data statement [PR79685]

2024-11-01 Thread Paul Thomas via Gcc-cvs
https://gcc.gnu.org/g:5904017a5e2887ca094b0bb8eb9761435d2a53d1

commit r13-9161-g5904017a5e2887ca094b0bb8eb9761435d2a53d1
Author: Paul Thomas 
Date:   Fri Oct 25 17:59:03 2024 +0100

Fortran: Fix ICE with structure constructor in data statement [PR79685]

2024-10-25  Paul Thomas  

gcc/fortran
PR fortran/79685
* decl.cc (match_data_constant): Find the symtree instead of
the symbol so the use renamed symbols are found. Pass this and
the derived type to gfc_match_structure_constructor.
* match.h: Update prototype of gfc_match_structure_contructor.
* primary.cc (gfc_match_structure_constructor): Remove call to
gfc_get_ha_sym_tree and use caller supplied symtree instead.

gcc/testsuite/
PR fortran/79685
* gfortran.dg/use_rename_13.f90: New test.

(cherry picked from commit 6cb1da72cac166bd3b005c0430557b68b9761da5)

Diff:
---
 gcc/fortran/decl.cc |  7 --
 gcc/fortran/match.h |  2 +-
 gcc/fortran/primary.cc  |  8 +++
 gcc/testsuite/gfortran.dg/use_rename_13.f90 | 37 +
 4 files changed, 46 insertions(+), 8 deletions(-)

diff --git a/gcc/fortran/decl.cc b/gcc/fortran/decl.cc
index 19321685e550..016b8367af86 100644
--- a/gcc/fortran/decl.cc
+++ b/gcc/fortran/decl.cc
@@ -376,6 +376,7 @@ match_data_constant (gfc_expr **result)
   gfc_expr *expr;
   match m;
   locus old_loc;
+  gfc_symtree *symtree;
 
   m = gfc_match_literal_constant (&expr, 1);
   if (m == MATCH_YES)
@@ -436,9 +437,11 @@ match_data_constant (gfc_expr **result)
   if (m != MATCH_YES)
 return m;
 
-  if (gfc_find_symbol (name, NULL, 1, &sym))
+  if (gfc_find_sym_tree (name, NULL, 1, &symtree))
 return MATCH_ERROR;
 
+  sym = symtree->n.sym;
+
   if (sym && sym->attr.generic)
 dt_sym = gfc_find_dt_in_generic (sym);
 
@@ -452,7 +455,7 @@ match_data_constant (gfc_expr **result)
   return MATCH_ERROR;
 }
   else if (dt_sym && gfc_fl_struct (dt_sym->attr.flavor))
-return gfc_match_structure_constructor (dt_sym, result);
+return gfc_match_structure_constructor (dt_sym, symtree, result);
 
   /* Check to see if the value is an initialization array expression.  */
   if (sym->value->expr_type == EXPR_ARRAY)
diff --git a/gcc/fortran/match.h b/gcc/fortran/match.h
index 4430aff001ce..279cb462501b 100644
--- a/gcc/fortran/match.h
+++ b/gcc/fortran/match.h
@@ -298,7 +298,7 @@ match gfc_match_bind_c_stmt (void);
 match gfc_match_bind_c (gfc_symbol *, bool);
 
 /* primary.cc.  */
-match gfc_match_structure_constructor (gfc_symbol *, gfc_expr **);
+match gfc_match_structure_constructor (gfc_symbol *, gfc_symtree *, gfc_expr 
**);
 match gfc_match_variable (gfc_expr **, int);
 match gfc_match_equiv_variable (gfc_expr **);
 match gfc_match_actual_arglist (int, gfc_actual_arglist **, bool = false);
diff --git a/gcc/fortran/primary.cc b/gcc/fortran/primary.cc
index a1b6b74765aa..7093ded9d6d1 100644
--- a/gcc/fortran/primary.cc
+++ b/gcc/fortran/primary.cc
@@ -3388,18 +3388,16 @@ gfc_convert_to_structure_constructor (gfc_expr *e, 
gfc_symbol *sym, gfc_expr **c
 
 
 match
-gfc_match_structure_constructor (gfc_symbol *sym, gfc_expr **result)
+gfc_match_structure_constructor (gfc_symbol *sym, gfc_symtree *symtree,
+gfc_expr **result)
 {
   match m;
   gfc_expr *e;
-  gfc_symtree *symtree;
   bool t = true;
 
-  gfc_get_ha_sym_tree (sym->name, &symtree);
-
   e = gfc_get_expr ();
-  e->symtree = symtree;
   e->expr_type = EXPR_FUNCTION;
+  e->symtree = symtree;
   e->where = gfc_current_locus;
 
   gcc_assert (gfc_fl_struct (sym->attr.flavor)
diff --git a/gcc/testsuite/gfortran.dg/use_rename_13.f90 
b/gcc/testsuite/gfortran.dg/use_rename_13.f90
new file mode 100644
index ..97f26f42f762
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/use_rename_13.f90
@@ -0,0 +1,37 @@
+! { dg-do compile }
+!
+! Test the fix for pr79685, which failed as in the comments below.
+!
+! Contributed by Juergen Reuter  
+!
+module omega_color
+  implicit none
+
+  type omega_color_factor
+ integer :: i
+  end type
+
+  type(omega_color_factor), parameter :: op = omega_color_factor (199)
+
+end module
+
+module foo
+  use omega_color, ocf => omega_color_factor, ocfp => op
+  implicit none
+
+  type(ocf) :: table_color_factors1 = ocf(42)
+  type(ocf) :: table_color_factors2
+  type(ocf) :: table_color_factors3 (2)
+  type(ocf) :: table_color_factors4
+  data table_color_factors2 / ocf(99) /! This failed in 
gfc_match_structure_constructor.
+  data table_color_factors3 / ocf(1), ocf(2) / ! ditto.
+  data table_color_factors4 / ocfp /
+end module
+
+  use foo
+  if (table_color_factors1%i .ne. 42) stop 1
+  if (table_color_factors2%i .ne. 99) stop 2
+  if (any (table_color_factors3%i .ne. [1,2])) stop 3
+  if (table_color_factors4%i .ne. 199) stop 4
+end
+


[gcc r15-4836] openmp: Return error_mark_node from tsubst_attribute for errneous varid

2024-11-01 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:7fdb66f0db6275118986ed8d77c94d6cfe5155c2

commit r15-4836-g7fdb66f0db6275118986ed8d77c94d6cfe5155c2
Author: Jakub Jelinek 
Date:   Fri Nov 1 11:57:32 2024 +0100

openmp: Return error_mark_node from tsubst_attribute for errneous varid

We incorrectly accept some invalid declare variant cases as if declare
variant wasn't there, in particular if a function template has some 
dependent
arguments and variant name lookup fails, because that is during
fn_type_unification with complain=tf_none, it just sets it to 
error_mark_node
and doesn't complain further, because it doesn't know the substitution 
failed
(we don't return error_mark_node from tsubst_attribute, just create 
TREE_LIST
with error_mark_node TREE_PURPOSE).

The following patch fixes it by returning error_mark_node in that case, then
fn_type_unification caller can see it failed and can redo it with explain_p
so that errors are reported.

2024-11-01  Jakub Jelinek  

* pt.cc (tsubst_attribute): For "omp declare variant base" attribute
if varid is error_mark_node, set val to error_mark_node rather than
creating a TREE_LIST with error_mark_node TREE_PURPOSE.

* g++.dg/gomp/declare-variant-10.C: New test.

Diff:
---
 gcc/cp/pt.cc   |  5 ++-
 gcc/testsuite/g++.dg/gomp/declare-variant-10.C | 56 ++
 2 files changed, 60 insertions(+), 1 deletion(-)

diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index 15d6d82f32fb..334dbb3c39aa 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -12163,7 +12163,10 @@ tsubst_attribute (tree t, tree *decl_p, tree args,
}
  OMP_TSS_TRAIT_SELECTORS (tss) = nreverse (selectors);
}
-  val = tree_cons (varid, ctx, chain);
+  if (varid == error_mark_node)
+   val = error_mark_node;
+  else
+   val = tree_cons (varid, ctx, chain);
 }
   /* If the first attribute argument is an identifier, don't
  pass it through tsubst.  Attributes like mode, format,
diff --git a/gcc/testsuite/g++.dg/gomp/declare-variant-10.C 
b/gcc/testsuite/g++.dg/gomp/declare-variant-10.C
new file mode 100644
index ..282cbc7ad785
--- /dev/null
+++ b/gcc/testsuite/g++.dg/gomp/declare-variant-10.C
@@ -0,0 +1,56 @@
+// { dg-do compile }
+
+#pragma omp declare variant (f1) match(user={condition(1)})// { dg-error 
"'f1' was not declared in this scope; did you mean 'f2'\\\?" }
+void
+f2 (int)
+{
+}
+
+void f3 (int);
+
+#pragma omp declare variant (f3) match(user={condition(1)})// { dg-error 
"variant 'void f3\\\(int\\\)' and base 'void f4\\\(long int\\\)' have 
incompatible types" }
+void
+f4 (long)
+{
+}
+
+#pragma omp declare variant (f5) match(user={condition(1)})// { dg-error 
"there are no arguments to 'f5' that depend on a template parameter, so a 
declaration of 'f5' must be available" }
+template 
+void
+f6 (int)
+{
+}
+
+template 
+void f7 (int);
+
+#pragma omp declare variant (f7) match(user={condition(1)})// { dg-error 
"no matching function for call to 'f7\\\(long int\\\)'" }
+template 
+void
+f8 (long)
+{
+}
+
+#pragma omp declare variant (f9) match(user={condition(1)})
+template 
+void
+f10 (T)// { 
dg-error "'f9' was not declared in this scope; did you mean 'f8'\\\?" }
+{
+}
+
+template 
+void f11 (T, int);
+
+#pragma omp declare variant (f11) match(user={condition(1)})   // { dg-error 
"variant 'void f11\\\(T, int\\\) \\\[with T = int\\\]' and base 'void f12\\\(T, 
long int\\\) \\\[with T = int\\\]' have incompatible types" }
+template 
+void
+f12 (T, long)
+{
+}
+
+void
+test ()
+{
+  f10 (0); // { dg-error 
"no matching function for call to 'f10\\\(int\\\)'" }
+  f12 (0, 0L);
+}