[gcc r15-2129] i386: Fix testcases generating invalid asm

2024-07-18 Thread Haochen Jiang via Gcc-cvs
https://gcc.gnu.org/g:4b58697cecbd72fd7db5a0fcdf7af8deb3be2b14

commit r15-2129-g4b58697cecbd72fd7db5a0fcdf7af8deb3be2b14
Author: Haochen Jiang 
Date:   Wed Jul 17 16:26:35 2024 +0800

i386: Fix testcases generating invalid asm

For compile test, we should generate valid asm except for special purposes.
Fix the compile test that generates invalid asm.

gcc/testsuite/ChangeLog:

* gcc.target/i386/apx-egprs-names.c: Use ax for short and
al for char instead of eax.
* gcc.target/i386/avx512bw-kandnq-1.c: Do not run the test
under -m32 since kmovq with register is invalid. Use long
long to use 64 bit register instead of 32 bit register for
kmovq.
* gcc.target/i386/avx512bw-kandq-1.c: Ditto.
* gcc.target/i386/avx512bw-knotq-1.c: Ditto.
* gcc.target/i386/avx512bw-korq-1.c: Ditto.
* gcc.target/i386/avx512bw-kshiftlq-1.c: Ditto.
* gcc.target/i386/avx512bw-kshiftrq-1.c: Ditto.
* gcc.target/i386/avx512bw-kxnorq-1.c: Ditto.
* gcc.target/i386/avx512bw-kxorq-1.c: Ditto.

Diff:
---
 gcc/testsuite/gcc.target/i386/apx-egprs-names.c | 8 
 gcc/testsuite/gcc.target/i386/avx512bw-kandnq-1.c   | 6 +++---
 gcc/testsuite/gcc.target/i386/avx512bw-kandq-1.c| 6 +++---
 gcc/testsuite/gcc.target/i386/avx512bw-knotq-1.c| 4 ++--
 gcc/testsuite/gcc.target/i386/avx512bw-korq-1.c | 6 +++---
 gcc/testsuite/gcc.target/i386/avx512bw-kshiftlq-1.c | 4 ++--
 gcc/testsuite/gcc.target/i386/avx512bw-kshiftrq-1.c | 4 ++--
 gcc/testsuite/gcc.target/i386/avx512bw-kxnorq-1.c   | 6 +++---
 gcc/testsuite/gcc.target/i386/avx512bw-kxorq-1.c| 6 +++---
 9 files changed, 25 insertions(+), 25 deletions(-)

diff --git a/gcc/testsuite/gcc.target/i386/apx-egprs-names.c 
b/gcc/testsuite/gcc.target/i386/apx-egprs-names.c
index f0517e47c334..917ef5054951 100644
--- a/gcc/testsuite/gcc.target/i386/apx-egprs-names.c
+++ b/gcc/testsuite/gcc.target/i386/apx-egprs-names.c
@@ -10,8 +10,8 @@ void foo ()
   register int b __asm ("r30");
   register short c __asm ("r29");
   register char d __asm ("r28");
-  __asm__ __volatile__ ("mov %0, %%rax" : : "r" (a) : "rax");
-  __asm__ __volatile__ ("mov %0, %%eax" : : "r" (b) : "eax");
-  __asm__ __volatile__ ("mov %0, %%eax" : : "r" (c) : "eax");
-  __asm__ __volatile__ ("mov %0, %%eax" : : "r" (d) : "eax");
+  __asm__ __volatile__ ("movq %0, %%rax" : : "r" (a) : "rax");
+  __asm__ __volatile__ ("movl %0, %%eax" : : "r" (b) : "eax");
+  __asm__ __volatile__ ("movw %0, %%ax" : : "r" (c) : "ax");
+  __asm__ __volatile__ ("movb %0, %%al" : : "r" (d) : "al");
 }
diff --git a/gcc/testsuite/gcc.target/i386/avx512bw-kandnq-1.c 
b/gcc/testsuite/gcc.target/i386/avx512bw-kandnq-1.c
index e8b7a5f9aa21..f9f03c90782f 100644
--- a/gcc/testsuite/gcc.target/i386/avx512bw-kandnq-1.c
+++ b/gcc/testsuite/gcc.target/i386/avx512bw-kandnq-1.c
@@ -1,4 +1,4 @@
-/* { dg-do compile } */
+/* { dg-do compile { target { ! ia32 } } } */
 /* { dg-options "-mavx512bw -O2" } */
 /* { dg-final { scan-assembler-times "kandnq\[ 
\\t\]+\[^\{\n\]*%k\[0-7\](?:\n|\[ \\t\]+#)" 1 } } */
 
@@ -10,8 +10,8 @@ avx512bw_test ()
   __mmask64 k1, k2, k3;
   volatile __m512i x = _mm512_setzero_si512 ();
 
-  __asm__( "kmovq %1, %0" : "=k" (k1) : "r" (1) );
-  __asm__( "kmovq %1, %0" : "=k" (k2) : "r" (2) );
+  __asm__( "kmovq %1, %0" : "=k" (k1) : "r" (1ULL) );
+  __asm__( "kmovq %1, %0" : "=k" (k2) : "r" (2ULL) );
 
   k3 = _kandn_mask64 (k1, k2);
   x = _mm512_mask_add_epi8 (x, k3, x, x);
diff --git a/gcc/testsuite/gcc.target/i386/avx512bw-kandq-1.c 
b/gcc/testsuite/gcc.target/i386/avx512bw-kandq-1.c
index a1aaed67c66c..6ad836087adc 100644
--- a/gcc/testsuite/gcc.target/i386/avx512bw-kandq-1.c
+++ b/gcc/testsuite/gcc.target/i386/avx512bw-kandq-1.c
@@ -1,4 +1,4 @@
-/* { dg-do compile } */
+/* { dg-do compile { target { ! ia32 } } } */
 /* { dg-options "-mavx512bw -O2" } */
 /* { dg-final { scan-assembler-times "kandq\[ 
\\t\]+\[^\{\n\]*%k\[0-7\](?:\n|\[ \\t\]+#)" 1 } } */
 
@@ -10,8 +10,8 @@ avx512bw_test ()
   __mmask64 k1, k2, k3;
   volatile __m512i x = _mm512_setzero_epi32();
 
-  __asm__( "kmovq %1, %0" : "=k" (k1) : "r" (1) );
-  __asm__( "kmovq %1, %0" : "=k" (k2) : "r" (2) );
+  __asm__( "kmovq %1, %0" : "=k" (k1) : "r" (1ULL) );
+  __asm__( "kmovq %1, %0" : "=k" (k2) : "r" (2ULL) );
 
   k3 = _kand_mask64 (k1, k2);
   x = _mm512_mask_add_epi8 (x, k3, x, x);
diff --git a/gcc/testsuite/gcc.target/i386/avx512bw-knotq-1.c 
b/gcc/testsuite/gcc.target/i386/avx512bw-knotq-1.c
index deb657957600..341bbc038479 100644
--- a/gcc/testsuite/gcc.target/i386/avx512bw-knotq-1.c
+++ b/gcc/testsuite/gcc.target/i386/avx512bw-knotq-1.c
@@ -1,4 +1,4 @@
-/* { dg-do compile } */
+/* { dg-do compile { target { ! ia32 } } } */
 /* { dg-options "-mavx512bw -O2" } */
 /* { dg-final { scan-assembler-times "knotq\[ 
\\t\]+\[^\{\n\]*%k\[0-7\](?:\n|\[ \\t\]+#)" 1 } } */
 
@@ -10,7 +10,7 @@ av

[gcc r15-2130] testsuite: Fix up builtin-clear-padding-3.c for -funsigned-char

2024-07-18 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:958ee138748fae4371e453eb9b357f576abbe83e

commit r15-2130-g958ee138748fae4371e453eb9b357f576abbe83e
Author: Jakub Jelinek 
Date:   Thu Jul 18 09:22:10 2024 +0200

testsuite: Fix up builtin-clear-padding-3.c for -funsigned-char

As reported on gcc-regression, this test FAILs on aarch64, but my
r15-2090 change didn't change anything on the generated assembly,
just added the forgotten dg-do run directive to the test, so the
test has been failing forever, just we didn't know it.

I can actually reproduce it on x86_64 with -funsigned-char too,
s2.b.a has int type and -1 is stored to it, so we should compare
it against -1 rather than (char) -1; the latter is appropriate for
testing char fields into which we've stored -1.

2024-07-18  Jakub Jelinek  

* c-c++-common/torture/builtin-clear-padding-3.c (main): Compare
s2.b.a against -1 rather than (char) -1.

Diff:
---
 gcc/testsuite/c-c++-common/torture/builtin-clear-padding-3.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/testsuite/c-c++-common/torture/builtin-clear-padding-3.c 
b/gcc/testsuite/c-c++-common/torture/builtin-clear-padding-3.c
index 27bf8f6dd734..2c673169e134 100644
--- a/gcc/testsuite/c-c++-common/torture/builtin-clear-padding-3.c
+++ b/gcc/testsuite/c-c++-common/torture/builtin-clear-padding-3.c
@@ -34,7 +34,7 @@ main ()
   foo (&s1, 0);
   foo (&s2, 0);
   __builtin_clear_padding (&s2);
-  if (s2.b.a != (char) -1)
+  if (s2.b.a != -1)
 __builtin_abort ();
   __builtin_clear_padding (&s2.b.a);
   __builtin_memset (&s2.b.a + 1, 0, sizeof (union U) - sizeof (s2.b.a));


[gcc r15-2131] Fortran: Use char* for deferred length character arrays [PR82904]

2024-07-18 Thread Andre Vehreschild via Gcc-cvs
https://gcc.gnu.org/g:0231b076dc98eb02e3289b21ace1757782e3917b

commit r15-2131-g0231b076dc98eb02e3289b21ace1757782e3917b
Author: Andre Vehreschild 
Date:   Wed Jul 10 14:37:37 2024 +0200

Fortran: Use char* for deferred length character arrays [PR82904]

Randomly during compiling the pass IPA: inline would ICE.  This was
caused by a saved deferred length string.  The length variable was not
set, but the variable was used in the array's declaration.  Now using a
character pointer to prevent this.

PR fortran/82904

gcc/fortran/ChangeLog:

* trans-types.cc (gfc_sym_type): Use type `char*` for saved
deferred length char arrays.
* trans.cc (get_array_span): Get `.span` also for `char*` typed
arrays, i.e. for those that have INTEGER_TYPE instead of
ARRAY_TYPE.

gcc/testsuite/ChangeLog:

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

Diff:
---
 gcc/fortran/trans-types.cc  |  6 --
 gcc/fortran/trans.cc|  4 +++-
 gcc/testsuite/gfortran.dg/deferred_character_38.f90 | 20 
 3 files changed, 27 insertions(+), 3 deletions(-)

diff --git a/gcc/fortran/trans-types.cc b/gcc/fortran/trans-types.cc
index f7b80a9761c4..01ce54f0ac0a 100644
--- a/gcc/fortran/trans-types.cc
+++ b/gcc/fortran/trans-types.cc
@@ -2334,8 +2334,10 @@ gfc_sym_type (gfc_symbol * sym, bool is_bind_c)
  || ((sym->attr.result || sym->attr.value)
  && sym->ns->proc_name
  && sym->ns->proc_name->attr.is_bind_c)
- || (sym->ts.deferred && (!sym->ts.u.cl
-  || !sym->ts.u.cl->backend_decl))
+ || (sym->ts.deferred
+ && (!sym->ts.u.cl
+ || !sym->ts.u.cl->backend_decl
+ || sym->attr.save))
  || (sym->attr.dummy
  && sym->attr.value
  && gfc_length_one_character_type_p (&sym->ts
diff --git a/gcc/fortran/trans.cc b/gcc/fortran/trans.cc
index 1067e032621b..d4c54093cbc3 100644
--- a/gcc/fortran/trans.cc
+++ b/gcc/fortran/trans.cc
@@ -398,7 +398,9 @@ get_array_span (tree type, tree decl)
 return gfc_conv_descriptor_span_get (decl);
 
   /* Return the span for deferred character length array references.  */
-  if (type && TREE_CODE (type) == ARRAY_TYPE && TYPE_STRING_FLAG (type))
+  if (type
+  && (TREE_CODE (type) == ARRAY_TYPE || TREE_CODE (type) == INTEGER_TYPE)
+  && TYPE_STRING_FLAG (type))
 {
   if (TREE_CODE (decl) == PARM_DECL)
decl = build_fold_indirect_ref_loc (input_location, decl);
diff --git a/gcc/testsuite/gfortran.dg/deferred_character_38.f90 
b/gcc/testsuite/gfortran.dg/deferred_character_38.f90
new file mode 100644
index ..d5a6c0e50136
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/deferred_character_38.f90
@@ -0,0 +1,20 @@
+! { dg-do run }
+
+! Check for PR fortran/82904
+! Contributed by G.Steinmetz  
+
+! This test checks that 'IPA pass: inline' passes.
+! The initial version of the testcase contained coarrays, which does not work
+! yet.
+
+program p
+   save
+   character(:), allocatable :: x
+   character(:), allocatable :: y
+   allocate (character(3) :: y)
+   allocate (x, source='abc')
+   y = x
+
+   if (y /= 'abc') stop 1
+end
+


[gcc r15-2132] Implement a -ftrapping-math/-fsignaling-nans TODO in match.pd.

2024-07-18 Thread Roger Sayle via Gcc-cvs
https://gcc.gnu.org/g:030186cabe8128e752619e101768cf8823a42c38

commit r15-2132-g030186cabe8128e752619e101768cf8823a42c38
Author: Roger Sayle 
Date:   Thu Jul 18 08:27:36 2024 +0100

Implement a -ftrapping-math/-fsignaling-nans TODO in match.pd.

I've been investigating some (float)i == CST optimizations for match.pd,
and noticed there's already a TODO comment in match.pd that's relatively
easy to implement.  When CST is a NaN, we only need to worry about
exceptions with flag_trapping_math, and equality/inequality tests for
sNaN only behave differently to qNaN with -fsignaling-nans.  These
issues are related to PR 57371 and PR 106805 in bugzilla.

2024-07-18  Roger Sayle  

gcc/ChangeLog
* match.pd ((FTYPE) N CMP CST): Only worry about exceptions with
flag_trapping_math, and about signaling NaNs with HONOR_SNANS.

gcc/testsuite/ChangeLog
* c-c++-common/pr57371-4.c: Update comment.
* c-c++-common/pr57371-5.c: Add missing testcases from pr57371-4.c
and update for -fno-signaling-nans -fno-trapping-math.

Diff:
---
 gcc/match.pd   | 14 ++--
 gcc/testsuite/c-c++-common/pr57371-4.c |  4 +---
 gcc/testsuite/c-c++-common/pr57371-5.c | 42 +++---
 3 files changed, 47 insertions(+), 13 deletions(-)

diff --git a/gcc/match.pd b/gcc/match.pd
index 5cb399b87180..6818856991c6 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -6862,13 +6862,13 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
tree itype = TREE_TYPE (@0);
format_helper fmt (REAL_MODE_FORMAT (TYPE_MODE (TREE_TYPE (@1;
const REAL_VALUE_TYPE *cst = TREE_REAL_CST_PTR (@1);
-   /* Be careful to preserve any potential exceptions due to
- NaNs.  qNaNs are ok in == or != context.
- TODO: relax under -fno-trapping-math or
- -fno-signaling-nans.  */
-   bool exception_p
- = real_isnan (cst) && (cst->signalling
-   || (cmp != EQ_EXPR && cmp != NE_EXPR));
+   /* Be careful to preserve any potential exceptions due to NaNs.
+ qNaNs are ok in == or != context.  */
+   bool exception_p = real_isnan (cst)
+ && flag_trapping_math
+ && ((cmp != EQ_EXPR && cmp != NE_EXPR)
+ || (cst->signalling
+ && HONOR_SNANS (TREE_TYPE (@1;
  }
  /* TODO: allow non-fitting itype and SNaNs when
-fno-trapping-math.  */
diff --git a/gcc/testsuite/c-c++-common/pr57371-4.c 
b/gcc/testsuite/c-c++-common/pr57371-4.c
index f43f7c22419a..b0e539de4b9f 100644
--- a/gcc/testsuite/c-c++-common/pr57371-4.c
+++ b/gcc/testsuite/c-c++-common/pr57371-4.c
@@ -2,9 +2,7 @@
 /* { dg-options "-O -fsignaling-nans -fdump-tree-original" } */
 
 /* We can not get rid of comparison in tests below because of
-   pending NaN exceptions.
-
-   TODO: avoid under -fno-trapping-math.  */
+   pending NaN exceptions.  */
 
 #define QNAN __builtin_nanf ("0")
 #define SNAN __builtin_nansf ("0")
diff --git a/gcc/testsuite/c-c++-common/pr57371-5.c 
b/gcc/testsuite/c-c++-common/pr57371-5.c
index 8e18b0a73138..77decbe5dff5 100644
--- a/gcc/testsuite/c-c++-common/pr57371-5.c
+++ b/gcc/testsuite/c-c++-common/pr57371-5.c
@@ -2,11 +2,10 @@
 /* { dg-options "-O -fno-signaling-nans -fno-trapping-math 
-fdump-tree-original" } */
 
 /* We can not get rid of comparison in tests below because of
-   pending NaN exceptions.
-
-   TODO: avoid under -fno-trapping-math.  */
+   pending NaN exceptions.  */
 
 #define QNAN __builtin_nanf ("0")
+#define SNAN __builtin_nansf ("0")
 
 void nonfinite(unsigned short x) {
   {
@@ -33,6 +32,43 @@ void nonfinite(unsigned short x) {
 /* { dg-final { scan-tree-dump "nonfinite_4 = 0" "original" } } */
   }
 
+  {
+volatile int nonfinite_5;
+nonfinite_5 = (float) x > SNAN;
+/* { dg-final { scan-tree-dump "nonfinite_5 = 0" "original" } } */
+  }
+
+  {
+volatile int nonfinite_6;
+nonfinite_6 = (float) x >= SNAN;
+/* { dg-final { scan-tree-dump "nonfinite_6 = 0" "original" } } */
+  }
+
+  {
+volatile int nonfinite_7;
+nonfinite_7 = (float) x < SNAN;
+/* { dg-final { scan-tree-dump "nonfinite_7 = 0" "original" } } */
+  }
+
+  {
+volatile int nonfinite_8;
+nonfinite_8 = (float) x <= SNAN;
+/* { dg-final { scan-tree-dump "nonfinite_8 = 0" "original" } } */
+  }
+
+  {
+volatile int nonfinite_9;
+nonfinite_9 = (float) x == SNAN;
+/* { dg-final { scan-tree-dump "nonfinite_9 = 0" "original" } } */
+  }
+
+  {
+volatile int nonfinite_10;
+nonfinite_10 = (float) x != SNAN;
+/* { dg-final { scan-tree-dump "nonfinite_10 = 1" "original" } } *
+ */
+  }
+
   {
 volatile int nonfinite_11;
 nonfinite_11 = (float) x == QNAN;


[gcc r14-10454] testsuite: Fix up builtin-clear-padding-3.c for -funsigned-char

2024-07-18 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:0fbad21b0705f748076a715d0b756996f4cadcc8

commit r14-10454-g0fbad21b0705f748076a715d0b756996f4cadcc8
Author: Jakub Jelinek 
Date:   Thu Jul 18 09:22:10 2024 +0200

testsuite: Fix up builtin-clear-padding-3.c for -funsigned-char

As reported on gcc-regression, this test FAILs on aarch64, but my
r15-2090 change didn't change anything on the generated assembly,
just added the forgotten dg-do run directive to the test, so the
test has been failing forever, just we didn't know it.

I can actually reproduce it on x86_64 with -funsigned-char too,
s2.b.a has int type and -1 is stored to it, so we should compare
it against -1 rather than (char) -1; the latter is appropriate for
testing char fields into which we've stored -1.

2024-07-18  Jakub Jelinek  

* c-c++-common/torture/builtin-clear-padding-3.c (main): Compare
s2.b.a against -1 rather than (char) -1.

(cherry picked from commit 958ee138748fae4371e453eb9b357f576abbe83e)

Diff:
---
 gcc/testsuite/c-c++-common/torture/builtin-clear-padding-3.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/testsuite/c-c++-common/torture/builtin-clear-padding-3.c 
b/gcc/testsuite/c-c++-common/torture/builtin-clear-padding-3.c
index 27bf8f6dd734..2c673169e134 100644
--- a/gcc/testsuite/c-c++-common/torture/builtin-clear-padding-3.c
+++ b/gcc/testsuite/c-c++-common/torture/builtin-clear-padding-3.c
@@ -34,7 +34,7 @@ main ()
   foo (&s1, 0);
   foo (&s2, 0);
   __builtin_clear_padding (&s2);
-  if (s2.b.a != (char) -1)
+  if (s2.b.a != -1)
 __builtin_abort ();
   __builtin_clear_padding (&s2.b.a);
   __builtin_memset (&s2.b.a + 1, 0, sizeof (union U) - sizeof (s2.b.a));


[gcc r15-2133] tree-optimization/104515 - store motion and clobbers

2024-07-18 Thread Richard Biener via Gcc-cvs
https://gcc.gnu.org/g:8c67dc40459e3d72e8169b099cc8c5dbdb759da3

commit r15-2133-g8c67dc40459e3d72e8169b099cc8c5dbdb759da3
Author: Richard Biener 
Date:   Wed Jul 17 10:22:47 2024 +0200

tree-optimization/104515 - store motion and clobbers

The following addresses an old regression when end-of-object/storage
clobbers were introduced.  In particular when there's an end-of-object
clobber in a loop but no corresponding begin-of-object we can still
perform store motion of may-aliased refs when we re-issue the
end-of-object/storage on the exits but elide it from the loop.  This
should be the safest way to deal with this considering stack-slot
sharing and it should not cause missed dead store eliminations given
DSE can now follow multiple paths in case there are multiple exits.

Note when the clobber is re-materialized only on one exit but not
on anther we are erroring on the side of removing the clobber on
such path.  This should be OK (removing clobbers is always OK).

Note there's no corresponding code to handle begin-of-object/storage
during the hoisting part of loads that are part of a store motion
optimization, so this only enables stored-only store motion or cases
without such clobber inside the loop.

PR tree-optimization/104515
* tree-ssa-loop-im.cc (execute_sm_exit): Add clobbers_to_prune
parameter and handle re-materializing of clobbers.
(sm_seq_valid_bb): end-of-storage/object clobbers are OK inside
an ordered sequence of stores.
(sm_seq_push_down): Refuse to push down clobbers.
(hoist_memory_references): Prune clobbers from the loop body
we re-materialized on an exit.

* g++.dg/opt/pr104515.C: New testcase.

Diff:
---
 gcc/testsuite/g++.dg/opt/pr104515.C | 18 
 gcc/tree-ssa-loop-im.cc | 86 ++---
 2 files changed, 89 insertions(+), 15 deletions(-)

diff --git a/gcc/testsuite/g++.dg/opt/pr104515.C 
b/gcc/testsuite/g++.dg/opt/pr104515.C
new file mode 100644
index ..f5455a45aa63
--- /dev/null
+++ b/gcc/testsuite/g++.dg/opt/pr104515.C
@@ -0,0 +1,18 @@
+// { dg-do compile { target c++11 } }
+// { dg-options "-O2 -fdump-tree-lim2-details" }
+
+using T = int;
+struct Vec {
+  T* end;
+};
+void pop_back_many(Vec& v, unsigned n)
+{
+  for (unsigned i = 0; i < n; ++i) {
+--v.end;
+//  The end-of-object clobber prevented store motion of v
+v.end->~T();
+  }
+}
+
+// { dg-final { scan-tree-dump "Executing store motion of v" "lim2" } }
+// { dg-final { scan-tree-dump "Re-issueing dependent" "lim2" } }
diff --git a/gcc/tree-ssa-loop-im.cc b/gcc/tree-ssa-loop-im.cc
index 61c6339bc351..c53efbb8d597 100644
--- a/gcc/tree-ssa-loop-im.cc
+++ b/gcc/tree-ssa-loop-im.cc
@@ -2368,7 +2368,8 @@ struct seq_entry
 static void
 execute_sm_exit (class loop *loop, edge ex, vec &seq,
 hash_map &aux_map, sm_kind kind,
-edge &append_cond_position, edge &last_cond_fallthru)
+edge &append_cond_position, edge &last_cond_fallthru,
+bitmap clobbers_to_prune)
 {
   /* Sink the stores to exit from the loop.  */
   for (unsigned i = seq.length (); i > 0; --i)
@@ -2377,15 +2378,35 @@ execute_sm_exit (class loop *loop, edge ex, 
vec &seq,
   if (seq[i-1].second == sm_other)
{
  gcc_assert (kind == sm_ord && seq[i-1].from != NULL_TREE);
- if (dump_file && (dump_flags & TDF_DETAILS))
+ gassign *store;
+ if (ref->mem.ref == error_mark_node)
{
- fprintf (dump_file, "Re-issueing dependent store of ");
- print_generic_expr (dump_file, ref->mem.ref);
- fprintf (dump_file, " from loop %d on exit %d -> %d\n",
-  loop->num, ex->src->index, ex->dest->index);
+ tree lhs = gimple_assign_lhs (ref->accesses_in_loop[0].stmt);
+ if (dump_file && (dump_flags & TDF_DETAILS))
+   {
+ fprintf (dump_file, "Re-issueing dependent ");
+ print_generic_expr (dump_file, unshare_expr (seq[i-1].from));
+ fprintf (dump_file, " of ");
+ print_generic_expr (dump_file, lhs);
+ fprintf (dump_file, " from loop %d on exit %d -> %d\n",
+  loop->num, ex->src->index, ex->dest->index);
+   }
+ store = gimple_build_assign (unshare_expr (lhs),
+  unshare_expr (seq[i-1].from));
+ bitmap_set_bit (clobbers_to_prune, seq[i-1].first);
+   }
+ else
+   {
+ if (dump_file && (dump_flags & TDF_DETAILS))
+   {
+ fprintf (dump_file, "Re-issueing dependent store of ");
+ print_generic_expr (dump_file, ref->mem.ref);
+ fprintf (dump_file, " from loop %d on 

[gcc r15-2134] gimple-fold: consistent dump of builtin call simplifications

2024-07-18 Thread Richard Biener via Gcc-cvs
https://gcc.gnu.org/g:cee56fe0ba757cae17dcc4be216cea88be76e740

commit r15-2134-gcee56fe0ba757cae17dcc4be216cea88be76e740
Author: Rubin Gerritsen 
Date:   Tue Jul 16 21:11:24 2024 +0200

gimple-fold: consistent dump of builtin call simplifications

Previously only simplifications of the `__st[xrp]cpy_chk`
were dumped. Now all call replacement simplifications are
dumped.

Examples of statements with corresponding dumpfile entries:

`printf("mystr\n");`:
  optimized: simplified printf to __builtin_puts
`printf("%c", 'a');`:
  optimized: simplified printf to __builtin_putchar
`printf("%s\n", "mystr");`:
  optimized: simplified printf to __builtin_puts

The below test suites passed for this patch
* The x86 bootstrap test.
* Manual testing with some small example code manually
  examining dump logs, outputting the lines mentioned above.

gcc/ChangeLog:

* gimple-fold.cc (dump_transformation): Moved definition.
(replace_call_with_call_and_fold): Calls dump_transformation.
(gimple_fold_builtin_stxcpy_chk): Removes call to
dump_transformation, now in replace_call_with_call_and_fold.
(gimple_fold_builtin_stxncpy_chk): Removes call to
dump_transformation, now in replace_call_with_call_and_fold.

Signed-off-by: Rubin Gerritsen 

Diff:
---
 gcc/gimple-fold.cc | 22 ++
 1 file changed, 10 insertions(+), 12 deletions(-)

diff --git a/gcc/gimple-fold.cc b/gcc/gimple-fold.cc
index ed9508e4c912..c20102f73f59 100644
--- a/gcc/gimple-fold.cc
+++ b/gcc/gimple-fold.cc
@@ -802,6 +802,15 @@ gimplify_and_update_call_from_tree (gimple_stmt_iterator 
*si_p, tree expr)
   gsi_replace_with_seq_vops (si_p, stmts);
 }
 
+/* Print a message in the dump file recording transformation of FROM to TO.  */
+
+static void
+dump_transformation (gcall *from, gcall *to)
+{
+  if (dump_enabled_p ())
+dump_printf_loc (MSG_OPTIMIZED_LOCATIONS, from, "simplified %T to %T\n",
+gimple_call_fn (from), gimple_call_fn (to));
+}
 
 /* Replace the call at *GSI with the gimple value VAL.  */
 
@@ -835,6 +844,7 @@ static void
 replace_call_with_call_and_fold (gimple_stmt_iterator *gsi, gimple *repl)
 {
   gimple *stmt = gsi_stmt (*gsi);
+  dump_transformation (as_a  (stmt), as_a  (repl));
   gimple_call_set_lhs (repl, gimple_call_lhs (stmt));
   gimple_set_location (repl, gimple_location (stmt));
   gimple_move_vops (repl, stmt);
@@ -3090,16 +3100,6 @@ gimple_fold_builtin_memory_chk (gimple_stmt_iterator 
*gsi,
   return true;
 }
 
-/* Print a message in the dump file recording transformation of FROM to TO.  */
-
-static void
-dump_transformation (gcall *from, gcall *to)
-{
-  if (dump_enabled_p ())
-dump_printf_loc (MSG_OPTIMIZED_LOCATIONS, from, "simplified %T to %T\n",
-gimple_call_fn (from), gimple_call_fn (to));
-}
-
 /* Fold a call to the __st[rp]cpy_chk builtin.
DEST, SRC, and SIZE are the arguments to the call.
IGNORE is true if return value can be ignored.  FCODE is the BUILT_IN_*
@@ -3189,7 +3189,6 @@ gimple_fold_builtin_stxcpy_chk (gimple_stmt_iterator *gsi,
 return false;
 
   gcall *repl = gimple_build_call (fn, 2, dest, src);
-  dump_transformation (stmt, repl);
   replace_call_with_call_and_fold (gsi, repl);
   return true;
 }
@@ -3235,7 +3234,6 @@ gimple_fold_builtin_stxncpy_chk (gimple_stmt_iterator 
*gsi,
 return false;
 
   gcall *repl = gimple_build_call (fn, 3, dest, src, len);
-  dump_transformation (stmt, repl);
   replace_call_with_call_and_fold (gsi, repl);
   return true;
 }


[gcc r15-2135] Fortran: Suppress bogus used uninitialized warnings [PR108889].

2024-07-18 Thread Paul Thomas via Gcc-cvs
https://gcc.gnu.org/g:c3aa339ea50f050caf7ed2e497f5499ec2d7b9cc

commit r15-2135-gc3aa339ea50f050caf7ed2e497f5499ec2d7b9cc
Author: Paul Thomas 
Date:   Thu Jul 18 08:51:35 2024 +0100

Fortran: Suppress bogus used uninitialized warnings [PR108889].

2024-07-18  Paul Thomas  

gcc/fortran
PR fortran/108889
* gfortran.h: Add bit field 'allocated_in_scope' to gfc_symbol.
* trans-array.cc (gfc_array_allocate): Set 'allocated_in_scope'
after allocation if not a component reference.
(gfc_alloc_allocatable_for_assignment): If 'allocated_in_scope'
not set, not a component ref and not allocated, set the array
bounds and offset to give zero length in all dimensions. Then
set allocated_in_scope.

gcc/testsuite/
PR fortran/108889
* gfortran.dg/pr108889.f90: New test.

Diff:
---
 gcc/fortran/gfortran.h |  4 
 gcc/fortran/trans-array.cc | 43 ++
 gcc/testsuite/gfortran.dg/pr108889.f90 | 43 ++
 3 files changed, 90 insertions(+)

diff --git a/gcc/fortran/gfortran.h b/gcc/fortran/gfortran.h
index ed1213a41cbb..c1fb896f587e 100644
--- a/gcc/fortran/gfortran.h
+++ b/gcc/fortran/gfortran.h
@@ -1950,6 +1950,10 @@ typedef struct gfc_symbol
   /* Set if this should be passed by value, but is not a VALUE argument
  according to the Fortran standard.  */
   unsigned pass_as_value:1;
+  /* Set if an allocatable array variable has been allocated in the current
+ scope. Used in the suppression of uninitialized warnings in reallocation
+ on assignment.  */
+  unsigned allocated_in_scope:1;
 
   /* Reference counter, used for memory management.
 
diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc
index 140d933e45d4..6d3b63b026c6 100644
--- a/gcc/fortran/trans-array.cc
+++ b/gcc/fortran/trans-array.cc
@@ -6580,6 +6580,8 @@ gfc_array_allocate (gfc_se * se, gfc_expr * expr, tree 
status, tree errmsg,
   else
   gfc_add_expr_to_block (&se->pre, set_descriptor);
 
+  expr->symtree->n.sym->allocated_in_scope = 1;
+
   return true;
 }
 
@@ -11060,6 +11062,8 @@ gfc_alloc_allocatable_for_assignment (gfc_loopinfo 
*loop,
   stmtblock_t realloc_block;
   stmtblock_t alloc_block;
   stmtblock_t fblock;
+  stmtblock_t loop_pre_block;
+  gfc_ref *ref;
   gfc_ss *rss;
   gfc_ss *lss;
   gfc_array_info *linfo;
@@ -11260,6 +11264,45 @@ gfc_alloc_allocatable_for_assignment (gfc_loopinfo 
*loop,
 array1, build_int_cst (TREE_TYPE (array1), 0));
   cond_null= gfc_evaluate_now (cond_null, &fblock);
 
+  /* If the data is null, set the descriptor bounds and offset. This suppresses
+ the maybe used uninitialized warning and forces the use of malloc because
+ the size is zero in all dimensions. Note that this block is only executed
+ if the lhs is unallocated and is only applied once in any namespace.
+ Component references are not subject to the warnings.  */
+  for (ref = expr1->ref; ref; ref = ref->next)
+if (ref->type == REF_COMPONENT)
+  break;
+
+  if (!expr1->symtree->n.sym->allocated_in_scope && !ref)
+{
+  gfc_start_block (&loop_pre_block);
+  for (n = 0; n < expr1->rank; n++)
+   {
+ gfc_conv_descriptor_lbound_set (&loop_pre_block, desc,
+ gfc_rank_cst[n],
+ gfc_index_one_node);
+ gfc_conv_descriptor_ubound_set (&loop_pre_block, desc,
+ gfc_rank_cst[n],
+ gfc_index_zero_node);
+ gfc_conv_descriptor_stride_set (&loop_pre_block, desc,
+ gfc_rank_cst[n],
+ gfc_index_zero_node);
+   }
+
+  tmp = gfc_conv_descriptor_offset (desc);
+  gfc_add_modify (&loop_pre_block, tmp, gfc_index_zero_node);
+
+  tmp = fold_build2_loc (input_location, EQ_EXPR,
+logical_type_node, array1,
+build_int_cst (TREE_TYPE (array1), 0));
+  tmp = build3_v (COND_EXPR, tmp,
+ gfc_finish_block (&loop_pre_block),
+ build_empty_stmt (input_location));
+  gfc_prepend_expr_to_block (&loop->pre, tmp);
+
+  expr1->symtree->n.sym->allocated_in_scope = 1;
+}
+
   tmp = build3_v (COND_EXPR, cond_null,
  build1_v (GOTO_EXPR, jump_label1),
  build_empty_stmt (input_location));
diff --git a/gcc/testsuite/gfortran.dg/pr108889.f90 
b/gcc/testsuite/gfortran.dg/pr108889.f90
new file mode 100644
index ..7fd4e3882a48
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr108889.f90
@@ -0,0 +1,43 @@
+! { dg-do compile }
+! { dg-options "-Wall -fdump-tree-original" }
+!
+! Contributed by Tobias Burnus  
+!
+program main
+  implicit none
+
+  type :: 

[gcc r15-2136] testsuite: Add dg-do run to more tests

2024-07-18 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:e217e7dbdc1040e7ee160796e9ca1ef12a0dd1cb

commit r15-2136-ge217e7dbdc1040e7ee160796e9ca1ef12a0dd1cb
Author: Sam James 
Date:   Thu Jul 18 10:00:17 2024 +0200

testsuite: Add dg-do run to more tests

All of these are for wrong-code bugs.  Confirmed to be used before but
with no execution.

2024-07-18  Sam James  

PR c++/53288
PR c++/57437
PR c/65345
PR libstdc++/88101
PR tree-optimization/96369
PR tree-optimization/102124
PR tree-optimization/108692
* c-c++-common/pr96369.c: Add dg-do run directive.
* gcc.dg/torture/pr102124.c: Ditto.
* gcc.dg/pr108692.c: Ditto.
* gcc.dg/atomic/pr65345-4.c: Ditto.
* g++.dg/cpp0x/lambda/lambda-return1.C: Ditto.
* g++.dg/init/lifetime4.C: Ditto.
* g++.dg/torture/builtin-clear-padding-1.C: Ditto.
* g++.dg/torture/builtin-clear-padding-2.C: Ditto.
* g++.dg/torture/builtin-clear-padding-3.C: Ditto.
* g++.dg/torture/builtin-clear-padding-4.C: Ditto.
* g++.dg/torture/builtin-clear-padding-5.C: Ditto.

Diff:
---
 gcc/testsuite/c-c++-common/pr96369.c   | 2 +-
 gcc/testsuite/g++.dg/cpp0x/lambda/lambda-return1.C | 1 +
 gcc/testsuite/g++.dg/init/lifetime4.C  | 2 +-
 gcc/testsuite/g++.dg/torture/builtin-clear-padding-1.C | 1 +
 gcc/testsuite/g++.dg/torture/builtin-clear-padding-2.C | 1 +
 gcc/testsuite/g++.dg/torture/builtin-clear-padding-3.C | 1 +
 gcc/testsuite/g++.dg/torture/builtin-clear-padding-4.C | 1 +
 gcc/testsuite/g++.dg/torture/builtin-clear-padding-5.C | 1 +
 gcc/testsuite/gcc.dg/atomic/pr65345-4.c| 1 +
 gcc/testsuite/gcc.dg/pr108692.c| 2 +-
 gcc/testsuite/gcc.dg/torture/pr102124.c| 1 +
 11 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/gcc/testsuite/c-c++-common/pr96369.c 
b/gcc/testsuite/c-c++-common/pr96369.c
index 8c468d9fec2f..ec58a3fc6c92 100644
--- a/gcc/testsuite/c-c++-common/pr96369.c
+++ b/gcc/testsuite/c-c++-common/pr96369.c
@@ -1,4 +1,4 @@
-/* { dg-do compile } */
+/* { dg-do run } */
 /* { dg-options "-O" } */
 
 int main()
diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-return1.C 
b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-return1.C
index 4b353b64c37e..df533e9a87cc 100644
--- a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-return1.C
+++ b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-return1.C
@@ -1,4 +1,5 @@
 // PR c++/57437
+// { dg-do run } */
 // { dg-require-effective-target c++11 }
 
 struct A {
diff --git a/gcc/testsuite/g++.dg/init/lifetime4.C 
b/gcc/testsuite/g++.dg/init/lifetime4.C
index 4106af7070cc..3e4825fff52f 100644
--- a/gcc/testsuite/g++.dg/init/lifetime4.C
+++ b/gcc/testsuite/g++.dg/init/lifetime4.C
@@ -1,5 +1,5 @@
 // PR c++/53288
-// { dg-do compile { target c++11 } }
+// { dg-do run { target c++11 } }
 
 struct B {
B(int data) : _data(data) { }
diff --git a/gcc/testsuite/g++.dg/torture/builtin-clear-padding-1.C 
b/gcc/testsuite/g++.dg/torture/builtin-clear-padding-1.C
index 625a047ab1c7..f62dedc6fa6d 100644
--- a/gcc/testsuite/g++.dg/torture/builtin-clear-padding-1.C
+++ b/gcc/testsuite/g++.dg/torture/builtin-clear-padding-1.C
@@ -1,4 +1,5 @@
 /* PR libstdc++/88101 */
+/* { dg-do run } */
 
 struct S {} s1, s2;
 struct T : public S { char a; short b; char c; } t1, t2;
diff --git a/gcc/testsuite/g++.dg/torture/builtin-clear-padding-2.C 
b/gcc/testsuite/g++.dg/torture/builtin-clear-padding-2.C
index 19cc78f66104..3cb55cff8d3e 100644
--- a/gcc/testsuite/g++.dg/torture/builtin-clear-padding-2.C
+++ b/gcc/testsuite/g++.dg/torture/builtin-clear-padding-2.C
@@ -1,4 +1,5 @@
 /* PR libstdc++/88101 */
+/* { dg-do run } */
 
 #include 
 
diff --git a/gcc/testsuite/g++.dg/torture/builtin-clear-padding-3.C 
b/gcc/testsuite/g++.dg/torture/builtin-clear-padding-3.C
index d528196bf2dc..fe81e095e082 100644
--- a/gcc/testsuite/g++.dg/torture/builtin-clear-padding-3.C
+++ b/gcc/testsuite/g++.dg/torture/builtin-clear-padding-3.C
@@ -1,4 +1,5 @@
 /* PR libstdc++/88101 */
+/* { dg-do run } */
 
 struct D { int a; int : 24; int b : 8; };
 struct E {};
diff --git a/gcc/testsuite/g++.dg/torture/builtin-clear-padding-4.C 
b/gcc/testsuite/g++.dg/torture/builtin-clear-padding-4.C
index 5936cdf876b2..88bd6bac65ec 100644
--- a/gcc/testsuite/g++.dg/torture/builtin-clear-padding-4.C
+++ b/gcc/testsuite/g++.dg/torture/builtin-clear-padding-4.C
@@ -1,4 +1,5 @@
 // PR middle-end/101586
+// { dg-do run }
 
 struct A { char a; };
 struct B : virtual A {};
diff --git a/gcc/testsuite/g++.dg/torture/builtin-clear-padding-5.C 
b/gcc/testsuite/g++.dg/torture/builtin-clear-padding-5.C
index b5f019147816..0795011077aa 100644
--- a/gcc/testsuite/g++.dg/torture/builtin-clear-padding-5.C
+++ b/gcc/testsuite/g++.dg/torture/builtin-clear-padding-5.C
@@ -1,4 +1,5 @@
 // PR tree-optimization/102586
+// { dg-do run }
 // { d

[gcc r11-11582] testsuite: Fix up builtin-clear-padding-3.c for -funsigned-char

2024-07-18 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:39f89e0daf6933fc888b79aa15f358b145c212ee

commit r11-11582-g39f89e0daf6933fc888b79aa15f358b145c212ee
Author: Jakub Jelinek 
Date:   Thu Jul 18 09:22:10 2024 +0200

testsuite: Fix up builtin-clear-padding-3.c for -funsigned-char

As reported on gcc-regression, this test FAILs on aarch64, but my
r15-2090 change didn't change anything on the generated assembly,
just added the forgotten dg-do run directive to the test, so the
test has been failing forever, just we didn't know it.

I can actually reproduce it on x86_64 with -funsigned-char too,
s2.b.a has int type and -1 is stored to it, so we should compare
it against -1 rather than (char) -1; the latter is appropriate for
testing char fields into which we've stored -1.

2024-07-18  Jakub Jelinek  

* c-c++-common/torture/builtin-clear-padding-3.c (main): Compare
s2.b.a against -1 rather than (char) -1.

(cherry picked from commit 958ee138748fae4371e453eb9b357f576abbe83e)

Diff:
---
 gcc/testsuite/c-c++-common/torture/builtin-clear-padding-3.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/testsuite/c-c++-common/torture/builtin-clear-padding-3.c 
b/gcc/testsuite/c-c++-common/torture/builtin-clear-padding-3.c
index 27bf8f6dd734..2c673169e134 100644
--- a/gcc/testsuite/c-c++-common/torture/builtin-clear-padding-3.c
+++ b/gcc/testsuite/c-c++-common/torture/builtin-clear-padding-3.c
@@ -34,7 +34,7 @@ main ()
   foo (&s1, 0);
   foo (&s2, 0);
   __builtin_clear_padding (&s2);
-  if (s2.b.a != (char) -1)
+  if (s2.b.a != -1)
 __builtin_abort ();
   __builtin_clear_padding (&s2.b.a);
   __builtin_memset (&s2.b.a + 1, 0, sizeof (union U) - sizeof (s2.b.a));


[gcc r15-2137] Fortran: Fix Explicit cobounds of a procedures parameter not respected [PR78466]

2024-07-18 Thread Andre Vehreschild via Gcc-cvs
https://gcc.gnu.org/g:18f3b223b97011c2eab71c8e48c3a38a12ff8f65

commit r15-2137-g18f3b223b97011c2eab71c8e48c3a38a12ff8f65
Author: Andre Vehreschild 
Date:   Thu Dec 31 10:40:30 2020 +0100

Fortran: Fix Explicit cobounds of a procedures parameter not respected 
[PR78466]

Explicit cobounds of class array procedure parameters were not taken
into account.  Furthermore were different cobounds in distinct
procedure parameter lists mixed up, i.e. the last definition was taken
for all.  The bounds are now regenerated when tree's and expr's bounds
do not match.

PR fortran/78466
PR fortran/80774

gcc/fortran/ChangeLog:

* array.cc (gfc_compare_array_spec): Take cotype into account.
* class.cc (gfc_build_class_symbol): Coarrays are also arrays.
* gfortran.h (IS_CLASS_COARRAY_OR_ARRAY): New macro to detect
regular and coarray class arrays.
* interface.cc (compare_components): Take codimension into
account.
* resolve.cc (resolve_symbol): Improve error message.
* simplify.cc (simplify_bound_dim): Remove duplicate.
* trans-array.cc (gfc_trans_array_cobounds): Coarrays are also
arrays.
(gfc_trans_array_bounds): Same.
(gfc_trans_dummy_array_bias): Same.
(get_coarray_as): Get the as having a non-zero codim.
(is_explicit_coarray): Detect explicit coarrays.
(gfc_conv_expr_descriptor): Create a new descriptor for explicit
coarrays.
* trans-decl.cc (gfc_build_qualified_array): Coarrays are also
arrays.
(gfc_build_dummy_array_decl): Same.
(gfc_get_symbol_decl): Same.
(gfc_trans_deferred_vars): Same.
* trans-expr.cc (class_scalar_coarray_to_class): Get the
descriptor from the correct location.
(gfc_conv_variable): Pick up the descriptor when needed.
* trans-types.cc (gfc_is_nodesc_array): Coarrays are also
arrays.
(gfc_get_nodesc_array_type): Indentation fix only.
(cobounds_match_decl): Match a tree's bounds to the expr's
bounds and return true, when they match.
(gfc_get_derived_type): Create a new type tree/descriptor, when
the cobounds of the existing declaration and expr to not
match.  This happends for class arrays in parameter list, when
there are different cobound declarations.

gcc/testsuite/ChangeLog:

* gfortran.dg/coarray/poly_run_1.f90: Activate old test code.
* gfortran.dg/coarray/poly_run_2.f90: Activate test.  It was
stopping before and passing without an error.

Diff:
---
 gcc/fortran/array.cc |  3 +
 gcc/fortran/class.cc |  8 ++-
 gcc/fortran/gfortran.h   |  5 ++
 gcc/fortran/interface.cc |  7 +++
 gcc/fortran/resolve.cc   |  3 +-
 gcc/fortran/simplify.cc  |  2 -
 gcc/fortran/trans-array.cc   | 53 -
 gcc/fortran/trans-decl.cc| 20 ---
 gcc/fortran/trans-expr.cc| 34 +++
 gcc/fortran/trans-types.cc   | 74 
 gcc/testsuite/gfortran.dg/coarray/poly_run_1.f90 | 33 +--
 gcc/testsuite/gfortran.dg/coarray/poly_run_2.f90 | 28 ++---
 12 files changed, 207 insertions(+), 63 deletions(-)

diff --git a/gcc/fortran/array.cc b/gcc/fortran/array.cc
index e9934f1491b2..79c774d59a0b 100644
--- a/gcc/fortran/array.cc
+++ b/gcc/fortran/array.cc
@@ -1017,6 +1017,9 @@ gfc_compare_array_spec (gfc_array_spec *as1, 
gfc_array_spec *as2)
   if (as1->type != as2->type)
 return 0;
 
+  if (as1->cotype != as2->cotype)
+return 0;
+
   if (as1->type == AS_EXPLICIT)
 for (i = 0; i < as1->rank + as1->corank; i++)
   {
diff --git a/gcc/fortran/class.cc b/gcc/fortran/class.cc
index abe89630be3c..b9dcc0a3d98c 100644
--- a/gcc/fortran/class.cc
+++ b/gcc/fortran/class.cc
@@ -709,8 +709,12 @@ gfc_build_class_symbol (gfc_typespec *ts, symbol_attribute 
*attr,
  work on the declared type. All array type other than deferred shape or
  assumed rank are added to the function namespace to ensure that they
  are properly distinguished.  */
-  if (attr->dummy && !attr->codimension && (*as)
-  && !((*as)->type == AS_DEFERRED || (*as)->type == AS_ASSUMED_RANK))
+  if (attr->dummy && (*as)
+  && ((!attr->codimension
+  && !((*as)->type == AS_DEFERRED || (*as)->type == AS_ASSUMED_RANK))
+ || (attr->codimension
+ && !((*as)->cotype == AS_DEFERRED
+  || (*as)->cotype == AS_ASSUMED_RANK
 {
   char *sname;
   ns = gfc_current_ns;
diff --git a/gcc/fortran/gfortran.h b/gcc/fo

[gcc r15-2138] Doc: Add Standard-Names ustrunc and sstrunc for integer modes

2024-07-18 Thread Pan Li via Gcc-cvs
https://gcc.gnu.org/g:ebac11afbcb7a52536da5f04fc524b870f5d76e0

commit r15-2138-gebac11afbcb7a52536da5f04fc524b870f5d76e0
Author: Pan Li 
Date:   Thu Jul 18 11:30:38 2024 +0800

Doc: Add Standard-Names ustrunc and sstrunc for integer modes

This patch would like to add the doc for the Standard-Names
ustrunc and sstrunc,  include both the scalar and vector integer
modes.

gcc/ChangeLog:

* doc/md.texi: Add Standard-Names ustrunc and sstrunc.

Signed-off-by: Pan Li 

Diff:
---
 gcc/doc/md.texi | 12 
 1 file changed, 12 insertions(+)

diff --git a/gcc/doc/md.texi b/gcc/doc/md.texi
index 7f4335e0aac1..ecb7f34f1b92 100644
--- a/gcc/doc/md.texi
+++ b/gcc/doc/md.texi
@@ -5543,6 +5543,18 @@ means of constraints requiring operands 1 and 0 to be 
the same location.
 @itemx @samp{and@var{m}3}, @samp{ior@var{m}3}, @samp{xor@var{m}3}
 Similar, for other arithmetic operations.
 
+@cindex @code{ustrunc@var{m}@var{n}2} instruction pattern
+@item @samp{ustrunc@var{m}@var{n}2}
+Truncate the operand 1, and storing the result in operand 0.  There will
+be saturation during the trunction.  The result will be saturated to the
+maximal value of operand 0 type if there is overflow when truncation.  The
+operand 1 must have mode @var{n},  and the operand 0 must have mode @var{m}.
+Both scalar and vector integer modes are allowed.
+
+@cindex @code{sstrunc@var{m}@var{n}2} instruction pattern
+@item @samp{sstrunc@var{m}@var{n}2}
+Similar but for signed.
+
 @cindex @code{andc@var{m}3} instruction pattern
 @item @samp{andc@var{m}3}
 Like @code{and@var{m}3}, but it uses bitwise-complement of operand 2


[gcc r14-10455] PR tree-optimization/113673: Avoid load merging when potentially trapping.

2024-07-18 Thread Richard Biener via Gcc-cvs
https://gcc.gnu.org/g:0f593e4cd82eeced5d7666ae6752f238c7dbd7f6

commit r14-10455-g0f593e4cd82eeced5d7666ae6752f238c7dbd7f6
Author: Roger Sayle 
Date:   Mon Jun 24 15:34:03 2024 +0100

PR tree-optimization/113673: Avoid load merging when potentially trapping.

This patch fixes PR tree-optimization/113673, a P2 ice-on-valid regression
caused by load merging of (ptr[0]<<8)+ptr[1] when -ftrapv has been
specified.  When the operator is | or ^ this is safe, but for addition
of signed integer types, a trap may be generated/required, so merging this
idiom into a single non-trapping instruction is inappropriate, confusing
the compiler by transforming a basic block with an exception edge into one
without.

This revision implements Richard Biener's feedback to add an early check
for stmt_can_throw_internal (cfun, stmt) to prevent transforming in the
presence of any statement that could trap, not just overflow on addition.
The one other tweak included in this patch is to mark the local function
find_bswap_or_nop_load as static ensuring that it isn't called from outside
this file, and guaranteeing that it is dominated by stmt_can_throw_internal
checking.

2024-06-24  Roger Sayle  
Richard Biener  

gcc/ChangeLog
PR tree-optimization/113673
* gimple-ssa-store-merging.cc (find_bswap_or_nop_load): Make static.
(find_bswap_or_nop_1): Avoid transformations (load merging) when
stmt_can_throw_internal indicates that a statement can trap.

gcc/testsuite/ChangeLog
PR tree-optimization/113673
* g++.dg/pr113673.C: New test case.

(cherry picked from commit d8b05aef77443e1d3d8f3f5d2c56ac49a503fee3)

Diff:
---
 gcc/gimple-ssa-store-merging.cc |  6 --
 gcc/testsuite/g++.dg/pr113673.C | 14 ++
 2 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/gcc/gimple-ssa-store-merging.cc b/gcc/gimple-ssa-store-merging.cc
index cb0cb5f42f65..7dba4a7a781f 100644
--- a/gcc/gimple-ssa-store-merging.cc
+++ b/gcc/gimple-ssa-store-merging.cc
@@ -363,7 +363,7 @@ init_symbolic_number (struct symbolic_number *n, tree src)
the answer. If so, REF is that memory source and the base of the memory area
accessed and the offset of the access from that base are recorded in N.  */
 
-bool
+static bool
 find_bswap_or_nop_load (gimple *stmt, tree ref, struct symbolic_number *n)
 {
   /* Leaf node is an array or component ref. Memorize its base and
@@ -610,7 +610,9 @@ find_bswap_or_nop_1 (gimple *stmt, struct symbolic_number 
*n, int limit)
   gimple *rhs1_stmt, *rhs2_stmt, *source_stmt1;
   enum gimple_rhs_class rhs_class;
 
-  if (!limit || !is_gimple_assign (stmt))
+  if (!limit
+  || !is_gimple_assign (stmt)
+  || stmt_can_throw_internal (cfun, stmt))
 return NULL;
 
   rhs1 = gimple_assign_rhs1 (stmt);
diff --git a/gcc/testsuite/g++.dg/pr113673.C b/gcc/testsuite/g++.dg/pr113673.C
new file mode 100644
index ..11489777f5b9
--- /dev/null
+++ b/gcc/testsuite/g++.dg/pr113673.C
@@ -0,0 +1,14 @@
+/* { dg-do compile } */
+/* { dg-options "-Os -fnon-call-exceptions -ftrapv" } */
+
+struct s { ~s(); };
+void
+h (unsigned char *data, int c)
+{
+  s a1;
+  while (c)
+{
+  int m = *data++ << 8;
+  m += *data++;
+}
+}


[gcc r14-10456] Fix points_to_local_or_readonly_memory_p wrt TARGET_MEM_REF

2024-07-18 Thread Richard Biener via Gcc-cvs
https://gcc.gnu.org/g:0b7ec50ae2959153650c0b3dc134c8872ff9fcfc

commit r14-10456-g0b7ec50ae2959153650c0b3dc134c8872ff9fcfc
Author: Jan Hubicka 
Date:   Thu May 16 15:33:55 2024 +0200

Fix points_to_local_or_readonly_memory_p wrt TARGET_MEM_REF

TARGET_MEM_REF can be used to offset constant base into a memory object (to
produce lea instruction).  This confuses 
points_to_local_or_readonly_memory_p
which treats the constant address as a base of the access.

Bootstrapped/regtsted x86_64-linux, comitted.
Honza

gcc/ChangeLog:

PR ipa/113787
* ipa-fnsummary.cc (points_to_local_or_readonly_memory_p): Do not
look into TARGET_MEM_REFS with constant opreand 0.

gcc/testsuite/ChangeLog:

* gcc.c-torture/execute/pr113787.c: New test.

(cherry picked from commit 96d53252aefcbc2fe419c4c3b4bcd3fc03d4d187)

Diff:
---
 gcc/ipa-fnsummary.cc   |  4 ++-
 gcc/testsuite/gcc.c-torture/execute/pr113787.c | 38 ++
 2 files changed, 41 insertions(+), 1 deletion(-)

diff --git a/gcc/ipa-fnsummary.cc b/gcc/ipa-fnsummary.cc
index dff40cd8aa51..f2937df0292d 100644
--- a/gcc/ipa-fnsummary.cc
+++ b/gcc/ipa-fnsummary.cc
@@ -2644,7 +2644,9 @@ points_to_local_or_readonly_memory_p (tree t)
return true;
   return !ptr_deref_may_alias_global_p (t, false);
 }
-  if (TREE_CODE (t) == ADDR_EXPR)
+  if (TREE_CODE (t) == ADDR_EXPR
+  && (TREE_CODE (TREE_OPERAND (t, 0)) != TARGET_MEM_REF
+ || TREE_CODE (TREE_OPERAND (TREE_OPERAND (t, 0), 0)) != INTEGER_CST))
 return refs_local_or_readonly_memory_p (TREE_OPERAND (t, 0));
   return false;
 }
diff --git a/gcc/testsuite/gcc.c-torture/execute/pr113787.c 
b/gcc/testsuite/gcc.c-torture/execute/pr113787.c
new file mode 100644
index ..702b6c35fc68
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/execute/pr113787.c
@@ -0,0 +1,38 @@
+void foo(int x, int y, int z, int d, int *buf)
+{
+  for(int i = z; i < y-z; ++i)
+for(int j = 0; j < d; ++j)
+  /* buf[x(i+1) + j] = buf[x(i+1)-j-1] */
+  buf[i*x+(x-z+j)] = buf[i*x+(x-z-1-j)];
+}
+
+void bar(int x, int y, int z, int d, int *buf)
+{
+  for(int i = 0; i < d; ++i)
+for(int j = z; j < x-z; ++j)
+  /* buf[j+(y+i)*x] = buf[j+(y-1-i)*x] */
+  buf[j+(y-z+i)*x] = buf[j+(y-z-1-i)*x];
+}
+
+__attribute__((noipa))
+void baz(int x, int y, int d, int *buf)
+{
+  foo(x, y, 0, d, buf);
+  bar(x, y, 0, d, buf);
+}
+
+int main(void)
+{
+  int a[] = { 1, 2, 3 };
+  baz (1, 2, 1, a);
+  /* foo does:
+ buf[1] = buf[0];
+ buf[2] = buf[1];
+
+ bar does:
+ buf[2] = buf[1]; (no-op)
+ so we should have { 1, 1, 1 }.  */
+  for (int i = 0; i < 3; i++)
+if (a[i] != 1)
+  __builtin_abort ();
+}


[gcc r14-10457] analyzer: fix ICE seen with -fsanitize=undefined [PR114899]

2024-07-18 Thread Richard Biener via Gcc-cvs
https://gcc.gnu.org/g:b0452ed2fdc8bd9d5e911b6ea3166e4cd4be5256

commit r14-10457-gb0452ed2fdc8bd9d5e911b6ea3166e4cd4be5256
Author: David Malcolm 
Date:   Wed May 15 18:40:56 2024 -0400

analyzer: fix ICE seen with -fsanitize=undefined [PR114899]

gcc/analyzer/ChangeLog:
PR analyzer/114899
* access-diagram.cc
(written_svalue_spatial_item::get_label_string): Bulletproof
against SSA_NAME_VAR being null.

gcc/testsuite/ChangeLog:
PR analyzer/114899
* c-c++-common/analyzer/out-of-bounds-diagram-pr114899.c: New test.

Signed-off-by: David Malcolm 
(cherry picked from commit 1779e22150b917e28e959623c819ef943fab02df)

Diff:
---
 gcc/analyzer/access-diagram.cc|  3 ++-
 .../analyzer/out-of-bounds-diagram-pr114899.c | 15 +++
 2 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/gcc/analyzer/access-diagram.cc b/gcc/analyzer/access-diagram.cc
index 500480b68328..8d7461fe381d 100644
--- a/gcc/analyzer/access-diagram.cc
+++ b/gcc/analyzer/access-diagram.cc
@@ -1632,7 +1632,8 @@ protected:
 if (rep_tree)
   {
if (TREE_CODE (rep_tree) == SSA_NAME)
- rep_tree = SSA_NAME_VAR (rep_tree);
+ if (tree var = SSA_NAME_VAR (rep_tree))
+   rep_tree = var;
switch (TREE_CODE (rep_tree))
  {
  default:
diff --git 
a/gcc/testsuite/c-c++-common/analyzer/out-of-bounds-diagram-pr114899.c 
b/gcc/testsuite/c-c++-common/analyzer/out-of-bounds-diagram-pr114899.c
new file mode 100644
index ..14ba540d4ec2
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/analyzer/out-of-bounds-diagram-pr114899.c
@@ -0,0 +1,15 @@
+/* Verify we don't ICE generating out-of-bounds diagram.  */
+
+/* { dg-additional-options " -fsanitize=undefined 
-fdiagnostics-text-art-charset=unicode" } */
+
+int * a() {
+  int *b = (int *)__builtin_malloc(sizeof(int));
+  int *c = b - 1;
+  ++*c;
+  return b;
+}
+
+/* We don't care about the exact diagram, just that we don't ICE.  */
+
+/* { dg-allow-blank-lines-in-output 1 } */
+/* { dg-prune-output ".*" } */


[gcc r14-10459] c++: ICE with __has_unique_object_representations [PR115476]

2024-07-18 Thread Richard Biener via Gcc-cvs
https://gcc.gnu.org/g:c314867fc06d475e3c2ace32032e0d72e3915b55

commit r14-10459-gc314867fc06d475e3c2ace32032e0d72e3915b55
Author: Marek Polacek 
Date:   Mon Jun 17 17:53:12 2024 -0400

c++: ICE with __has_unique_object_representations [PR115476]

Here we started to ICE with r13-25: in check_trait_type, for "X[]" we
return true here:

  if (kind == 1 && TREE_CODE (type) == ARRAY_TYPE && !TYPE_DOMAIN (type))
return true; // Array of unknown bound. Don't care about completeness.

and then end up crashing in record_has_unique_obj_representations:

4836  if (cur != wi::to_offset (sz))

because sz is null.


https://eel.is/c++draft/type.traits#tab:meta.unary.prop-row-47-column-3-sentence-1
says that the preconditions for __has_unique_object_representations are:
"T shall be a complete type, cv void, or an array of unknown bound" and
that "For an array type T, the same result as
has_unique_object_representations_v>" so T[]
should be treated as T.  So we should use kind==2 for the trait.

PR c++/115476

gcc/cp/ChangeLog:

* semantics.cc (finish_trait_expr)
: Move below to call
check_trait_type with kind==2.

gcc/testsuite/ChangeLog:

* g++.dg/cpp1z/has-unique-obj-representations4.C: New test.

(cherry picked from commit fc382a373e6824bb998007d1dcb0805b0cf4b8e8)

Diff:
---
 gcc/cp/semantics.cc  |  2 +-
 .../g++.dg/cpp1z/has-unique-obj-representations4.C   | 16 
 2 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc
index ec741c0b203d..edb8947e4c2f 100644
--- a/gcc/cp/semantics.cc
+++ b/gcc/cp/semantics.cc
@@ -12744,7 +12744,6 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, 
tree type1, tree type2)
 case CPTK_HAS_NOTHROW_COPY:
 case CPTK_HAS_TRIVIAL_COPY:
 case CPTK_HAS_TRIVIAL_DESTRUCTOR:
-case CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS:
   if (!check_trait_type (type1))
return error_mark_node;
   break;
@@ -12754,6 +12753,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, 
tree type1, tree type2)
 case CPTK_IS_STD_LAYOUT:
 case CPTK_IS_TRIVIAL:
 case CPTK_IS_TRIVIALLY_COPYABLE:
+case CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS:
   if (!check_trait_type (type1, /* kind = */ 2))
return error_mark_node;
   break;
diff --git a/gcc/testsuite/g++.dg/cpp1z/has-unique-obj-representations4.C 
b/gcc/testsuite/g++.dg/cpp1z/has-unique-obj-representations4.C
new file mode 100644
index ..d6949dc7005e
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1z/has-unique-obj-representations4.C
@@ -0,0 +1,16 @@
+// PR c++/115476
+// { dg-do compile { target c++11 } }
+
+struct X;
+static_assert(__has_unique_object_representations(X), "");   // { dg-error 
"invalid use of incomplete type" }
+static_assert(__has_unique_object_representations(X[]), "");  // { dg-error 
"invalid use of incomplete type" }
+static_assert(__has_unique_object_representations(X[1]), "");  // { dg-error 
"invalid use of incomplete type" }
+static_assert(__has_unique_object_representations(X[][1]), "");  // { dg-error 
"invalid use of incomplete type" }
+
+struct X {
+  int x;
+};
+static_assert(__has_unique_object_representations(X), "");
+static_assert(__has_unique_object_representations(X[]), "");
+static_assert(__has_unique_object_representations(X[1]), "");
+static_assert(__has_unique_object_representations(X[][1]), "");


[gcc r14-10458] i386: PR target/115351: RTX costs for *concatditi3 and *insvti_highpart.

2024-07-18 Thread Richard Biener via Gcc-cvs
https://gcc.gnu.org/g:a4c9ade72885f9cf72c873d110545e4e3c2c7805

commit r14-10458-ga4c9ade72885f9cf72c873d110545e4e3c2c7805
Author: Roger Sayle 
Date:   Fri Jun 7 14:03:20 2024 +0100

i386: PR target/115351: RTX costs for *concatditi3 and *insvti_highpart.

This patch addresses PR target/115351, which is a code quality regression
on x86 when passing floating point complex numbers.  The ABI considers
these arguments to have TImode, requiring interunit moves to place the
FP values (which are actually passed in SSE registers) into the upper
and lower parts of a TImode pseudo, and then similar moves back again
before they can be used.

The cause of the regression is that changes in how TImode initialization
is represented in RTL now prevents the RTL optimizers from eliminating
these redundant moves.  The specific cause is that the *concatditi3
pattern, (zext(hi)<<64)|zext(lo), has an inappropriately high (default)
rtx_cost, preventing fwprop1 from propagating it.  This pattern just
sets the hipart and lopart of a double-word register, typically two
instructions (less if reload can allocate things appropriately) but
the current ix86_rtx_costs actually returns INSN_COSTS(13), i.e. 52.

propagating insn 5 into insn 6, replacing:
(set (reg:TI 110)
(ior:TI (and:TI (reg:TI 110)
(const_wide_int 0x0))
(ashift:TI (zero_extend:TI (subreg:DI (reg:DF 112 [ zD.2796+8 ]) 0))
(const_int 64 [0x40]
successfully matched this instruction to *concatditi3_3:
(set (reg:TI 110)
(ior:TI (ashift:TI (zero_extend:TI (subreg:DI (reg:DF 112 [ zD.2796+8 
]) 0))
(const_int 64 [0x40]))
(zero_extend:TI (subreg:DI (reg:DF 111 [ zD.2796 ]) 0
change not profitable (cost 50 -> cost 52)

This issue is resolved by having ix86_rtx_costs return more reasonable
values for these (place-holder) patterns.

2024-06-07  Roger Sayle  

gcc/ChangeLog
PR target/115351
* config/i386/i386.cc (ix86_rtx_costs): Provide estimates for
the *concatditi3 and *insvti_highpart patterns, about two insns.

gcc/testsuite/ChangeLog
PR target/115351
* g++.target/i386/pr115351.C: New test case.

(cherry picked from commit fb3e4c549d16d5050e10114439ad77149f33c597)

Diff:
---
 gcc/config/i386/i386.cc  | 43 
 gcc/testsuite/g++.target/i386/pr115351.C | 19 ++
 2 files changed, 62 insertions(+)

diff --git a/gcc/config/i386/i386.cc b/gcc/config/i386/i386.cc
index 3827e2b61fe4..35a282433892 100644
--- a/gcc/config/i386/i386.cc
+++ b/gcc/config/i386/i386.cc
@@ -21865,6 +21865,49 @@ ix86_rtx_costs (rtx x, machine_mode mode, int 
outer_code_i, int opno,
}
  *total = ix86_vec_cost (mode, cost->sse_op);
}
+  else if (TARGET_64BIT
+  && mode == TImode
+  && GET_CODE (XEXP (x, 0)) == ASHIFT
+  && GET_CODE (XEXP (XEXP (x, 0), 0)) == ZERO_EXTEND
+  && GET_MODE (XEXP (XEXP (XEXP (x, 0), 0), 0)) == DImode
+  && CONST_INT_P (XEXP (XEXP (x, 0), 1))
+  && INTVAL (XEXP (XEXP (x, 0), 1)) == 64
+  && GET_CODE (XEXP (x, 1)) == ZERO_EXTEND
+  && GET_MODE (XEXP (XEXP (x, 1), 0)) == DImode)
+   {
+ /* *concatditi3 is cheap.  */
+ rtx op0 = XEXP (XEXP (XEXP (x, 0), 0), 0);
+ rtx op1 = XEXP (XEXP (x, 1), 0);
+ *total = (SUBREG_P (op0) && GET_MODE (SUBREG_REG (op0)) == DFmode)
+  ? COSTS_N_INSNS (1)/* movq.  */
+  : set_src_cost (op0, DImode, speed);
+ *total += (SUBREG_P (op1) && GET_MODE (SUBREG_REG (op1)) == DFmode)
+   ? COSTS_N_INSNS (1)/* movq.  */
+   : set_src_cost (op1, DImode, speed);
+ return true;
+   }
+  else if (TARGET_64BIT
+  && mode == TImode
+  && GET_CODE (XEXP (x, 0)) == AND
+  && REG_P (XEXP (XEXP (x, 0), 0))
+  && CONST_WIDE_INT_P (XEXP (XEXP (x, 0), 1))
+  && CONST_WIDE_INT_NUNITS (XEXP (XEXP (x, 0), 1)) == 2
+  && CONST_WIDE_INT_ELT (XEXP (XEXP (x, 0), 1), 0) == -1
+  && CONST_WIDE_INT_ELT (XEXP (XEXP (x, 0), 1), 1) == 0
+  && GET_CODE (XEXP (x, 1)) == ASHIFT
+  && GET_CODE (XEXP (XEXP (x, 1), 0)) == ZERO_EXTEND
+  && GET_MODE (XEXP (XEXP (XEXP (x, 1), 0), 0)) == DImode
+  && CONST_INT_P (XEXP (XEXP (x, 1), 1))
+  && INTVAL (XEXP (XEXP (x, 1), 1)) == 64)
+   {
+ /* *insvti_highpart is cheap.  */
+ rtx op = XEXP (XEXP (XEXP (x, 1), 0), 0);
+ *total = COSTS_N_INSNS (1) + 1;
+ *total += (SUBREG_P (op) && GET_MODE (SUBREG_REG (op)) == DFmode)
+   ? COSTS_N_INSNS (1)/* movq. 

[gcc r15-2139] middle-end/115641 - invalid address construction

2024-07-18 Thread Richard Biener via Gcc-cvs
https://gcc.gnu.org/g:3670c70c561656a19f6bff36dd229f18120af127

commit r15-2139-g3670c70c561656a19f6bff36dd229f18120af127
Author: Richard Biener 
Date:   Thu Jul 18 13:35:33 2024 +0200

middle-end/115641 - invalid address construction

fold_truth_andor_1 via make_bit_field_ref builds an address of
a CALL_EXPR which isn't valid GENERIC and later causes an ICE.
The following simply avoids the folding for f ().a != 1 || f ().b != 2
as it is a premature optimization anyway.  The alternative would
have been to build a TARGET_EXPR around the call.  To get this far
f () has to be const as otherwise the two calls are not semantically
equivalent for the optimization.

PR middle-end/115641
* fold-const.cc (decode_field_reference): If the inner
reference isn't something we can take the address of, fail.

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

Diff:
---
 gcc/fold-const.cc   |  3 +++
 gcc/testsuite/gcc.dg/torture/pr115641.c | 29 +
 2 files changed, 32 insertions(+)

diff --git a/gcc/fold-const.cc b/gcc/fold-const.cc
index 710d697c0217..6179a09f9c0a 100644
--- a/gcc/fold-const.cc
+++ b/gcc/fold-const.cc
@@ -5003,6 +5003,9 @@ decode_field_reference (location_t loc, tree *exp_, 
HOST_WIDE_INT *pbitsize,
   || *pbitsize < 0
   || offset != 0
   || TREE_CODE (inner) == PLACEHOLDER_EXPR
+  /* We eventually want to build a larger reference and need to take
+the address of this.  */
+  || (!REFERENCE_CLASS_P (inner) && !DECL_P (inner))
   /* Reject out-of-bound accesses (PR79731).  */
   || (! AGGREGATE_TYPE_P (TREE_TYPE (inner))
  && compare_tree_int (TYPE_SIZE (TREE_TYPE (inner)),
diff --git a/gcc/testsuite/gcc.dg/torture/pr115641.c 
b/gcc/testsuite/gcc.dg/torture/pr115641.c
new file mode 100644
index ..65fb09ca64fc
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr115641.c
@@ -0,0 +1,29 @@
+/* { dg-do run } */
+
+typedef struct {
+  char hours, day, month;
+  short year;
+} T;
+
+T g (void)
+{
+  T now;
+  now.hours = 1;
+  now.day = 2;
+  now.month = 3;
+  now.year = 4;
+  return now;
+}
+
+__attribute__((const)) T f (void)
+{
+  T virk = g ();
+  return virk;
+}
+
+int main ()
+{
+  if (f ().hours != 1 || f ().day != 2 || f ().month != 3 || f ().year != 4)
+__builtin_abort ();
+  return 0;
+}


[gcc r15-2140] Do not use caller-saved registers for COMDAT functions

2024-07-18 Thread Jonathan Yong via Gcc-cvs
https://gcc.gnu.org/g:5080840d8fbf25a321dd27543a1462d393d338bc

commit r15-2140-g5080840d8fbf25a321dd27543a1462d393d338bc
Author: LIU Hao 
Date:   Mon Jul 15 16:55:52 2024 +0800

Do not use caller-saved registers for COMDAT functions

A reference to a COMDAT function may be resolved to another definition
outside the current translation unit, so it's not eligible for `-fipa-ra`.

In `decl_binds_to_current_def_p()` there is already a check for weak
symbols. This commit checks for COMDAT functions that are not implemented
as weak symbols, for example, on *-*-mingw32.

gcc/ChangeLog:

PR rtl-optimization/115049
* varasm.cc (decl_binds_to_current_def_p): Add a check for COMDAT
declarations too, like weak ones.

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

diff --git a/gcc/varasm.cc b/gcc/varasm.cc
index beb88709033f..4426e7ce6c65 100644
--- a/gcc/varasm.cc
+++ b/gcc/varasm.cc
@@ -7813,6 +7813,8 @@ decl_binds_to_current_def_p (const_tree decl)
  for all other declaration types.  */
   if (DECL_WEAK (decl))
 return false;
+  if (DECL_COMDAT_GROUP (decl))
+return false;
   if (DECL_COMMON (decl)
   && (DECL_INITIAL (decl) == NULL
  || (!in_lto_p && DECL_INITIAL (decl) == error_mark_node)))


[gcc r14-10460] Do not use caller-saved registers for COMDAT functions

2024-07-18 Thread Jonathan Yong via Gcc-cvs
https://gcc.gnu.org/g:747c4b58573ea00419f64293a61537eb69f43307

commit r14-10460-g747c4b58573ea00419f64293a61537eb69f43307
Author: LIU Hao 
Date:   Mon Jul 15 16:55:52 2024 +0800

Do not use caller-saved registers for COMDAT functions

A reference to a COMDAT function may be resolved to another definition
outside the current translation unit, so it's not eligible for `-fipa-ra`.

In `decl_binds_to_current_def_p()` there is already a check for weak
symbols. This commit checks for COMDAT functions that are not implemented
as weak symbols, for example, on *-*-mingw32.

gcc/ChangeLog:

PR rtl-optimization/115049
* varasm.cc (decl_binds_to_current_def_p): Add a check for COMDAT
declarations too, like weak ones.

(cherry picked from commit 5080840d8fbf25a321dd27543a1462d393d338bc)

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

diff --git a/gcc/varasm.cc b/gcc/varasm.cc
index 747f74ba1c00..b67a0b524dbf 100644
--- a/gcc/varasm.cc
+++ b/gcc/varasm.cc
@@ -7805,6 +7805,8 @@ decl_binds_to_current_def_p (const_tree decl)
  for all other declaration types.  */
   if (DECL_WEAK (decl))
 return false;
+  if (DECL_COMDAT_GROUP (decl))
+return false;
   if (DECL_COMMON (decl)
   && (DECL_INITIAL (decl) == NULL
  || (!in_lto_p && DECL_INITIAL (decl) == error_mark_node)))


[gcc r12-10623] alpha: Fix duplicate !tlsgd!62 assemble error [PR115526]

2024-07-18 Thread Uros Bizjak via Gcc-cvs
https://gcc.gnu.org/g:c5a26fc24b0af61498fae65ccad69d51d63d2a8b

commit r12-10623-gc5a26fc24b0af61498fae65ccad69d51d63d2a8b
Author: Uros Bizjak 
Date:   Wed Jul 17 18:11:26 2024 +0200

alpha: Fix duplicate !tlsgd!62 assemble error [PR115526]

Add missing "cannot_copy" attribute to instructions that have to
stay in 1-1 correspondence with another insn.

PR target/115526

gcc/ChangeLog:

* config/alpha/alpha.md (movdi_er_high_g): Add cannot_copy 
attribute.
(movdi_er_tlsgd): Ditto.
(movdi_er_tlsldm): Ditto.
(call_value_osf_): Ditto.

gcc/testsuite/ChangeLog:

* gcc.target/alpha/pr115526.c: New test.

(cherry picked from commit 0841fd4c42ab053be951b7418233f0478282d020)

Diff:
---
 gcc/config/alpha/alpha.md | 10 +--
 gcc/testsuite/gcc.target/alpha/pr115526.c | 46 +++
 2 files changed, 53 insertions(+), 3 deletions(-)

diff --git a/gcc/config/alpha/alpha.md b/gcc/config/alpha/alpha.md
index 442953fe50e1..b6795e1d2638 100644
--- a/gcc/config/alpha/alpha.md
+++ b/gcc/config/alpha/alpha.md
@@ -3933,7 +3933,8 @@
   else
 return "ldq %0,%2(%1)\t\t!literal!%3";
 }
-  [(set_attr "type" "ldsym")])
+  [(set_attr "type" "ldsym")
+   (set_attr "cannot_copy" "true")])
 
 (define_split
   [(set (match_operand:DI 0 "register_operand")
@@ -3957,7 +3958,8 @@
 return "lda %0,%2(%1)\t\t!tlsgd";
   else
 return "lda %0,%2(%1)\t\t!tlsgd!%3";
-})
+}
+  [(set_attr "cannot_copy" "true")])
 
 (define_insn "movdi_er_tlsldm"
   [(set (match_operand:DI 0 "register_operand" "=r")
@@ -3970,7 +3972,8 @@
 return "lda %0,%&(%1)\t\t!tlsldm";
   else
 return "lda %0,%&(%1)\t\t!tlsldm!%2";
-})
+}
+  [(set_attr "cannot_copy" "true")])
 
 (define_insn "*movdi_er_gotdtp"
   [(set (match_operand:DI 0 "register_operand" "=r")
@@ -5939,6 +5942,7 @@
   "HAVE_AS_TLS"
   "ldq $27,%1($29)\t\t!literal!%2\;jsr $26,($27),%1\t\t!lituse_!%2\;ldah 
$29,0($26)\t\t!gpdisp!%*\;lda $29,0($29)\t\t!gpdisp!%*"
   [(set_attr "type" "jsr")
+   (set_attr "cannot_copy" "true")
(set_attr "length" "16")])
 
 ;; We must use peep2 instead of a split because we need accurate life
diff --git a/gcc/testsuite/gcc.target/alpha/pr115526.c 
b/gcc/testsuite/gcc.target/alpha/pr115526.c
new file mode 100644
index ..2f57903fec34
--- /dev/null
+++ b/gcc/testsuite/gcc.target/alpha/pr115526.c
@@ -0,0 +1,46 @@
+/* PR target/115526 */
+/* { dg-do assemble } */
+/* { dg-options "-O2 -Wno-attributes -fvisibility=hidden -fPIC -mcpu=ev4" } */
+
+struct _ts {
+  struct _dtoa_state *interp;
+};
+struct Bigint {
+  int k;
+} *_Py_dg_strtod_bs;
+struct _dtoa_state {
+  struct Bigint p5s;
+  struct Bigint *freelist[];
+};
+extern _Thread_local struct _ts _Py_tss_tstate;
+typedef struct Bigint Bigint;
+int pow5mult_k;
+long _Py_dg_strtod_ndigits;
+void PyMem_Free();
+void Bfree(Bigint *v) {
+  if (v)
+{
+  if (v->k)
+   PyMem_Free();
+  else {
+   struct _dtoa_state *interp = _Py_tss_tstate.interp;
+   interp->freelist[v->k] = v;
+  }
+}
+}
+static Bigint *pow5mult(Bigint *b) {
+  for (;;) {
+if (pow5mult_k & 1) {
+  Bfree(b);
+  if (b == 0)
+return 0;
+}
+if (!(pow5mult_k >>= 1))
+  break;
+  }
+  return 0;
+}
+void _Py_dg_strtod() {
+  if (_Py_dg_strtod_ndigits)
+pow5mult(_Py_dg_strtod_bs);
+}


[gcc r15-2141] eh: ICE with std::initializer_list and ASan [PR115865]

2024-07-18 Thread Marek Polacek via Gcc-cvs
https://gcc.gnu.org/g:1e60a6abfece40c7bf55d6ca0a439078d3f5159a

commit r15-2141-g1e60a6abfece40c7bf55d6ca0a439078d3f5159a
Author: Marek Polacek 
Date:   Thu Jul 11 15:57:43 2024 -0400

eh: ICE with std::initializer_list and ASan [PR115865]

Here we ICE with -fsanitize=address on

  std::initializer_list x = { 1, 2, 3 };

since r14-8681, which removed .ASAN_MARK calls on TREE_STATIC variables.
That means that lower_try_finally now instead of

  try
{
  .ASAN_MARK (UNPOISON, &C.0, 12);
  x = {};
  x._M_len = 3;
  x._M_array = &C.0;
}
  finally
{
  .ASAN_MARK (POISON, &C.0, 12);
}

gets:

  try
{
  x = {};
  x._M_len = 3;
  x._M_array = &C.0;
}
  finally
{

}

and we ICE on the empty finally in lower_try_finally_onedest while
getting get_eh_else.

PR c++/115865

gcc/ChangeLog:

* tree-eh.cc (get_eh_else): Check that the result of
gimple_seq_first_stmt is non-null.

gcc/testsuite/ChangeLog:

* g++.dg/asan/initlist2.C: New test.

Co-authored-by: Jakub Jelinek  

Diff:
---
 gcc/testsuite/g++.dg/asan/initlist2.C | 16 
 gcc/tree-eh.cc|  2 +-
 2 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/gcc/testsuite/g++.dg/asan/initlist2.C 
b/gcc/testsuite/g++.dg/asan/initlist2.C
new file mode 100644
index ..bce5410be339
--- /dev/null
+++ b/gcc/testsuite/g++.dg/asan/initlist2.C
@@ -0,0 +1,16 @@
+// PR c++/115865
+// { dg-do compile }
+// { dg-options "-fsanitize=address" }
+
+typedef decltype(sizeof(char)) size_t;
+
+namespace std {
+template  class initializer_list {
+  int *_M_array;
+  size_t _M_len;
+};
+}
+
+int main() {
+  std::initializer_list x = { 1, 2, 3 };
+}
diff --git a/gcc/tree-eh.cc b/gcc/tree-eh.cc
index a776ad5c92ba..9609bdc0d9b7 100644
--- a/gcc/tree-eh.cc
+++ b/gcc/tree-eh.cc
@@ -950,7 +950,7 @@ static inline geh_else *
 get_eh_else (gimple_seq finally)
 {
   gimple *x = gimple_seq_first_stmt (finally);
-  if (gimple_code (x) == GIMPLE_EH_ELSE)
+  if (x && gimple_code (x) == GIMPLE_EH_ELSE)
 {
   gcc_assert (gimple_seq_singleton_p (finally));
   return as_a  (x);


[gcc r15-2142] libatomic: Improve cpuid usage in __libat_feat1_init

2024-07-18 Thread Uros Bizjak via Gcc-cvs
https://gcc.gnu.org/g:f7d01e080a54ea94586c8847857e5aef17906519

commit r15-2142-gf7d01e080a54ea94586c8847857e5aef17906519
Author: Uros Bizjak 
Date:   Thu Jul 18 16:58:09 2024 +0200

libatomic: Improve cpuid usage in __libat_feat1_init

Check the result of __get_cpuid and process FEAT1_REGISTER only when
__get_cpuid returns success.  Use __cpuid instead of nested __get_cpuid.

libatomic/ChangeLog:

* config/x86/init.c (__libat_feat1_init): Check the result of
__get_cpuid and process FEAT1_REGISTER only when __get_cpuid
returns success.  Use __cpuid instead of nested __get_cpuid.

Diff:
---
 libatomic/config/x86/init.c | 28 +++-
 1 file changed, 15 insertions(+), 13 deletions(-)

diff --git a/libatomic/config/x86/init.c b/libatomic/config/x86/init.c
index a75be3f175c3..26168d468324 100644
--- a/libatomic/config/x86/init.c
+++ b/libatomic/config/x86/init.c
@@ -33,21 +33,23 @@ __libat_feat1_init (void)
 {
   unsigned int eax, ebx, ecx, edx;
   FEAT1_REGISTER = 0;
-  __get_cpuid (1, &eax, &ebx, &ecx, &edx);
-#ifdef __x86_64__
-  if ((FEAT1_REGISTER & (bit_AVX | bit_CMPXCHG16B))
-  == (bit_AVX | bit_CMPXCHG16B))
+  if (__get_cpuid (1, &eax, &ebx, &ecx, &edx))
 {
-  /* Intel SDM guarantees that 16-byte VMOVDQA on 16-byte aligned address
-is atomic, and AMD is going to do something similar soon.
-We don't have a guarantee from vendors of other CPUs with AVX,
-like Zhaoxin and VIA.  */
-  unsigned int ecx2 = 0;
-  __get_cpuid (0, &eax, &ebx, &ecx2, &edx);
-  if (ecx2 != signature_INTEL_ecx && ecx2 != signature_AMD_ecx)
-   FEAT1_REGISTER &= ~bit_AVX;
-}
+#ifdef __x86_64__
+  if ((FEAT1_REGISTER & (bit_AVX | bit_CMPXCHG16B))
+ == (bit_AVX | bit_CMPXCHG16B))
+   {
+ /* Intel SDM guarantees that 16-byte VMOVDQA on 16-byte aligned
+address is atomic, and AMD is going to do something similar soon.
+We don't have a guarantee from vendors of other CPUs with AVX,
+like Zhaoxin and VIA.  */
+ unsigned int ecx2;
+ __cpuid (0, eax, ebx, ecx2, edx);
+ if (ecx2 != signature_INTEL_ecx && ecx2 != signature_AMD_ecx)
+   FEAT1_REGISTER &= ~bit_AVX;
+   }
 #endif
+}
   /* See the load in load_feat1.  */
   __atomic_store_n (&__libat_feat1, FEAT1_REGISTER, __ATOMIC_RELAXED);
   return FEAT1_REGISTER;


[gcc r14-10461] eh: ICE with std::initializer_list and ASan [PR115865]

2024-07-18 Thread Marek Polacek via Gcc-cvs
https://gcc.gnu.org/g:493035c8780cd510a680a791d0c7f94368164352

commit r14-10461-g493035c8780cd510a680a791d0c7f94368164352
Author: Marek Polacek 
Date:   Thu Jul 11 15:57:43 2024 -0400

eh: ICE with std::initializer_list and ASan [PR115865]

Here we ICE with -fsanitize=address on

  std::initializer_list x = { 1, 2, 3 };

since r14-8681, which removed .ASAN_MARK calls on TREE_STATIC variables.
That means that lower_try_finally now instead of

  try
{
  .ASAN_MARK (UNPOISON, &C.0, 12);
  x = {};
  x._M_len = 3;
  x._M_array = &C.0;
}
  finally
{
  .ASAN_MARK (POISON, &C.0, 12);
}

gets:

  try
{
  x = {};
  x._M_len = 3;
  x._M_array = &C.0;
}
  finally
{

}

and we ICE on the empty finally in lower_try_finally_onedest while
getting get_eh_else.

PR c++/115865

gcc/ChangeLog:

* tree-eh.cc (get_eh_else): Check that the result of
gimple_seq_first_stmt is non-null.

gcc/testsuite/ChangeLog:

* g++.dg/asan/initlist2.C: New test.

Co-authored-by: Jakub Jelinek  
(cherry picked from commit 1e60a6abfece40c7bf55d6ca0a439078d3f5159a)

Diff:
---
 gcc/testsuite/g++.dg/asan/initlist2.C | 16 
 gcc/tree-eh.cc|  2 +-
 2 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/gcc/testsuite/g++.dg/asan/initlist2.C 
b/gcc/testsuite/g++.dg/asan/initlist2.C
new file mode 100644
index ..bce5410be339
--- /dev/null
+++ b/gcc/testsuite/g++.dg/asan/initlist2.C
@@ -0,0 +1,16 @@
+// PR c++/115865
+// { dg-do compile }
+// { dg-options "-fsanitize=address" }
+
+typedef decltype(sizeof(char)) size_t;
+
+namespace std {
+template  class initializer_list {
+  int *_M_array;
+  size_t _M_len;
+};
+}
+
+int main() {
+  std::initializer_list x = { 1, 2, 3 };
+}
diff --git a/gcc/tree-eh.cc b/gcc/tree-eh.cc
index a776ad5c92ba..9609bdc0d9b7 100644
--- a/gcc/tree-eh.cc
+++ b/gcc/tree-eh.cc
@@ -950,7 +950,7 @@ static inline geh_else *
 get_eh_else (gimple_seq finally)
 {
   gimple *x = gimple_seq_first_stmt (finally);
-  if (gimple_code (x) == GIMPLE_EH_ELSE)
+  if (x && gimple_code (x) == GIMPLE_EH_ELSE)
 {
   gcc_assert (gimple_seq_singleton_p (finally));
   return as_a  (x);


[gcc r15-2143] rs6000, update effective target for tests builtins-10*.c and vec_perm-runnable-i128.c

2024-07-18 Thread Carl Love via Gcc-cvs
https://gcc.gnu.org/g:c19237614b42ddae80a9a24e0b282cecc8aefb86

commit r15-2143-gc19237614b42ddae80a9a24e0b282cecc8aefb86
Author: Carl Love 
Date:   Fri Jul 12 13:37:36 2024 -0500

rs6000, update effective target for tests builtins-10*.c and 
vec_perm-runnable-i128.c

The tests:

  tests builtins-10-runnable.c
  tests builtins-10.c
  vec_perm-runnable-i128.c

use __int128 types that are not supported on all platforms.  Update the
tests to check int128 effective target to avoid unsupported type errors
on unsupported platforms.

gcc/testsuite/ChangeLog:
* gcc.target/powerpc/builtins-10-runnable.c: Add
target int128.
* gcc.target/powerpc/builtins-10.c: Add
target int128.
* gcc.target/powerpc/vec_perm-runnable-i128.c: Add
target int128.

Diff:
---
 gcc/testsuite/gcc.target/powerpc/builtins-10-runnable.c   | 2 +-
 gcc/testsuite/gcc.target/powerpc/builtins-10.c| 2 +-
 gcc/testsuite/gcc.target/powerpc/vec_perm-runnable-i128.c | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/gcc/testsuite/gcc.target/powerpc/builtins-10-runnable.c 
b/gcc/testsuite/gcc.target/powerpc/builtins-10-runnable.c
index dede08358e13..e2d3c9908521 100644
--- a/gcc/testsuite/gcc.target/powerpc/builtins-10-runnable.c
+++ b/gcc/testsuite/gcc.target/powerpc/builtins-10-runnable.c
@@ -1,4 +1,4 @@
-/* { dg-do run } */
+/* { dg-do run { target int128 } } */
 /* { dg-require-effective-target vmx_hw } */
 /* { dg-options "-maltivec -O2 " } */
 
diff --git a/gcc/testsuite/gcc.target/powerpc/builtins-10.c 
b/gcc/testsuite/gcc.target/powerpc/builtins-10.c
index b00f53cfc628..007892e2731a 100644
--- a/gcc/testsuite/gcc.target/powerpc/builtins-10.c
+++ b/gcc/testsuite/gcc.target/powerpc/builtins-10.c
@@ -1,4 +1,4 @@
-/* { dg-do compile } */
+/* { dg-do compile { target int128 } } */
 /* { dg-options "-O2 -maltivec" } */
 /* { dg-require-effective-target powerpc_altivec } */
 /* { dg-final { scan-assembler-times "xxsel" 6 } } */
diff --git a/gcc/testsuite/gcc.target/powerpc/vec_perm-runnable-i128.c 
b/gcc/testsuite/gcc.target/powerpc/vec_perm-runnable-i128.c
index 0e0d77bcb845..df1bf873cfc9 100644
--- a/gcc/testsuite/gcc.target/powerpc/vec_perm-runnable-i128.c
+++ b/gcc/testsuite/gcc.target/powerpc/vec_perm-runnable-i128.c
@@ -1,4 +1,4 @@
-/* { dg-do run } */
+/* { dg-do run { target  int128 } } */
 /* { dg-require-effective-target vmx_hw } */
 /* { dg-options "-maltivec -O2 " } */


[gcc r15-2144] rs6000: Fix .machine cpu selection w/ altivec [PR97367]

2024-07-18 Thread Peter Bergner via Gcc-cvs
https://gcc.gnu.org/g:6962835bca3e6bef0f6ceae84a7814138b08b8a5

commit r15-2144-g6962835bca3e6bef0f6ceae84a7814138b08b8a5
Author: René Rebe 
Date:   Fri Jul 12 21:17:08 2024 +

rs6000: Fix .machine cpu selection w/ altivec [PR97367]

There are various non-IBM CPUs with altivec, so we cannot use that
flag to determine which .machine cpu to use, so ignore it.
Emit an additional ".machine altivec" if Altivec is enabled so
that the assembler doesn't require an explicit -maltivec option
to assemble any Altivec instructions for those targets where
the ".machine cpu" is insufficient to enable Altivec.  For example,
-mcpu=G5 emits a ".machine power4".

2024-07-18  René Rebe  
Peter Bergner  

gcc/
PR target/97367
* config/rs6000/rs6000.cc (rs6000_machine_from_flags): Do not 
consider
OPTION_MASK_ALTIVEC.
(emit_asm_machine): For Altivec compiles, emit a ".machine altivec".

gcc/testsuite/
PR target/97367
* gcc.target/powerpc/pr97367.c: New test.

Signed-off-by: René Rebe 

Diff:
---
 gcc/config/rs6000/rs6000.cc|  5 -
 gcc/testsuite/gcc.target/powerpc/pr97367.c | 13 +
 2 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/gcc/config/rs6000/rs6000.cc b/gcc/config/rs6000/rs6000.cc
index 2c0a7fc8cefa..5ed64b1e6866 100644
--- a/gcc/config/rs6000/rs6000.cc
+++ b/gcc/config/rs6000/rs6000.cc
@@ -5896,7 +5896,8 @@ rs6000_machine_from_flags (void)
   HOST_WIDE_INT flags = rs6000_isa_flags;
 
   /* Disable the flags that should never influence the .machine selection.  */
-  flags &= ~(OPTION_MASK_PPC_GFXOPT | OPTION_MASK_PPC_GPOPT | 
OPTION_MASK_ISEL);
+  flags &= ~(OPTION_MASK_PPC_GFXOPT | OPTION_MASK_PPC_GPOPT | OPTION_MASK_ISEL
+| OPTION_MASK_ALTIVEC);
 
   if ((flags & (ISA_3_1_MASKS_SERVER & ~ISA_3_0_MASKS_SERVER)) != 0)
 return "power10";
@@ -5921,6 +5922,8 @@ void
 emit_asm_machine (void)
 {
   fprintf (asm_out_file, "\t.machine %s\n", rs6000_machine);
+  if (TARGET_ALTIVEC)
+fprintf (asm_out_file, "\t.machine altivec\n");
 }
 #endif
 
diff --git a/gcc/testsuite/gcc.target/powerpc/pr97367.c 
b/gcc/testsuite/gcc.target/powerpc/pr97367.c
new file mode 100644
index ..ef269a5f9134
--- /dev/null
+++ b/gcc/testsuite/gcc.target/powerpc/pr97367.c
@@ -0,0 +1,13 @@
+/* PR target/97367 */
+/* { dg-options "-mdejagnu-cpu=G5" } */
+
+/* Verify we emit a ".machine power4" and ".machine altivec" rather
+   than a ".machine power7".  */
+
+int dummy (void)
+{
+  return 0;
+}
+
+/* { dg-final { scan-assembler {\.machine power4\M} } } */
+/* { dg-final { scan-assembler {\.machine altivec\M} } } */


[gcc r15-2145] libbacktrace: use __has_attribute for fallthrough

2024-07-18 Thread Ian Lance Taylor via Gcc-cvs
https://gcc.gnu.org/g:248e8530dd0298e9bbe099c651d5d9c4d2a0c0f9

commit r15-2145-g248e8530dd0298e9bbe099c651d5d9c4d2a0c0f9
Author: Ian Lance Taylor 
Date:   Thu Jul 18 11:34:09 2024 -0700

libbacktrace: use __has_attribute for fallthrough

Also convert some FALLTHROUGH comments to ATTRIBUTE_FALLTHROUGH.

* internal.h: Use __has_attribute to check for fallthrough
attribute.
* elf.c (elf_zstd_decompress): Use ATTRIBUTE_FALLTHROUGH rather
than a FALLTHROUGH comment.

Diff:
---
 libbacktrace/elf.c  | 14 +++---
 libbacktrace/internal.h |  5 +
 2 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/libbacktrace/elf.c b/libbacktrace/elf.c
index e8d67feab6d3..0040479143d6 100644
--- a/libbacktrace/elf.c
+++ b/libbacktrace/elf.c
@@ -4848,25 +4848,25 @@ elf_zstd_decompress (const unsigned char *pin, size_t 
sin,
  {
  case 8:
*pout++ = *plit++;
-   /* FALLTHROUGH */
+   ATTRIBUTE_FALLTHROUGH;
  case 7:
*pout++ = *plit++;
-   /* FALLTHROUGH */
+   ATTRIBUTE_FALLTHROUGH;
  case 6:
*pout++ = *plit++;
-   /* FALLTHROUGH */
+   ATTRIBUTE_FALLTHROUGH;
  case 5:
*pout++ = *plit++;
-   /* FALLTHROUGH */
+   ATTRIBUTE_FALLTHROUGH;
  case 4:
*pout++ = *plit++;
-   /* FALLTHROUGH */
+   ATTRIBUTE_FALLTHROUGH;
  case 3:
*pout++ = *plit++;
-   /* FALLTHROUGH */
+   ATTRIBUTE_FALLTHROUGH;
  case 2:
*pout++ = *plit++;
-   /* FALLTHROUGH */
+   ATTRIBUTE_FALLTHROUGH;
  case 1:
*pout++ = *plit++;
break;
diff --git a/libbacktrace/internal.h b/libbacktrace/internal.h
index a119cda692fd..fe2abe50b0f3 100644
--- a/libbacktrace/internal.h
+++ b/libbacktrace/internal.h
@@ -56,6 +56,11 @@ POSSIBILITY OF SUCH DAMAGE.  */
 # endif
 #endif
 
+#ifdef __has_attribute
+# if __has_attribute(fallthrough)
+#  define ATTRIBUTE_FALLTHROUGH __attribute__ ((fallthrough))
+# endif
+#endif
 #ifndef ATTRIBUTE_FALLTHROUGH
 # if (GCC_VERSION >= 7000)
 #  define ATTRIBUTE_FALLTHROUGH __attribute__ ((__fallthrough__))


[gcc r15-2146] c++: implement DR1363 and DR1496 for __is_trivial [PR85723]

2024-07-18 Thread Marek Polacek via Gcc-cvs
https://gcc.gnu.org/g:9690fb3a43e5cf26a5fb853283d4200df312a640

commit r15-2146-g9690fb3a43e5cf26a5fb853283d4200df312a640
Author: Marek Polacek 
Date:   Tue Jun 18 16:49:24 2024 -0400

c++: implement DR1363 and DR1496 for __is_trivial [PR85723]

is_trivial was introduced in

which split POD into is_trivial and is_standard_layout.

Later came CWG 1363.  Since

  struct A {
A() = default;
A(int = 42) {}
  };

cannot be default-initialized, it should not be trivial, so the definition
of what is a trivial class changed.

Similarly, CWG 1496 concluded that

  struct B {
B() = delete;
  }:

should not be trivial either.

P0848 adjusted the definition further to say "eligible".  That means
that

  template
  struct C {
C() requires false = default;
  };

should not be trivial, either, since C::C() is not eligible.

Bug 85723 reports that we implement none of the CWGs.

I chose to fix this by using type_has_non_deleted_trivial_default_ctor
which uses locate_ctor which uses build_new_method_call, which would
be used by default-initialization as well.  With that, all __is_trivial
problems I could find in the Bugzilla are fixed, except for PR96288,
which may need changes to trivially-copyable, so I'm not messing with
that now.

I hope this has no ABI implications.  There's effort undergoing to
remove "trivial class" from the core language as it's not really
meaningful.  So the impact of this change should be pretty low except
to fix a few libstdc++ problems.

PR c++/108769
PR c++/58074
PR c++/115522
PR c++/85723

gcc/cp/ChangeLog:

* class.cc (type_has_non_deleted_trivial_default_ctor): Fix 
formatting.
* tree.cc (trivial_type_p): Instead of TYPE_HAS_TRIVIAL_DFLT, use
type_has_non_deleted_trivial_default_ctor.

gcc/testsuite/ChangeLog:

* g++.dg/warn/Wclass-memaccess.C: Add dg-warning.
* g++.dg/ext/is_trivial1.C: New test.
* g++.dg/ext/is_trivial2.C: New test.
* g++.dg/ext/is_trivial3.C: New test.
* g++.dg/ext/is_trivial4.C: New test.
* g++.dg/ext/is_trivial5.C: New test.
* g++.dg/ext/is_trivial6.C: New test.

Diff:
---
 gcc/cp/class.cc  |  3 +-
 gcc/cp/tree.cc   |  4 ++-
 gcc/testsuite/g++.dg/ext/is_trivial1.C   | 14 
 gcc/testsuite/g++.dg/ext/is_trivial2.C   | 20 
 gcc/testsuite/g++.dg/ext/is_trivial3.C   | 15 +
 gcc/testsuite/g++.dg/ext/is_trivial4.C   | 10 ++
 gcc/testsuite/g++.dg/ext/is_trivial5.C   |  8 +
 gcc/testsuite/g++.dg/ext/is_trivial6.C   | 49 
 gcc/testsuite/g++.dg/warn/Wclass-memaccess.C |  2 ++
 9 files changed, 123 insertions(+), 2 deletions(-)

diff --git a/gcc/cp/class.cc b/gcc/cp/class.cc
index 0ce361eb88e5..718601756ddc 100644
--- a/gcc/cp/class.cc
+++ b/gcc/cp/class.cc
@@ -5918,7 +5918,8 @@ type_has_virtual_destructor (tree type)
 /* True iff class TYPE has a non-deleted trivial default
constructor.  */
 
-bool type_has_non_deleted_trivial_default_ctor (tree type)
+bool
+type_has_non_deleted_trivial_default_ctor (tree type)
 {
   return TYPE_HAS_TRIVIAL_DFLT (type) && locate_ctor (type);
 }
diff --git a/gcc/cp/tree.cc b/gcc/cp/tree.cc
index dfd4a3a948b1..0e32d908b060 100644
--- a/gcc/cp/tree.cc
+++ b/gcc/cp/tree.cc
@@ -4637,7 +4637,9 @@ trivial_type_p (const_tree t)
   t = strip_array_types (CONST_CAST_TREE (t));
 
   if (CLASS_TYPE_P (t))
-return (TYPE_HAS_TRIVIAL_DFLT (t)
+/* A trivial class is a class that is trivially copyable and has one or
+   more eligible default constructors, all of which are trivial.  */
+return (type_has_non_deleted_trivial_default_ctor (CONST_CAST_TREE (t))
&& trivially_copyable_p (t));
   else
 return scalarish_type_p (t);
diff --git a/gcc/testsuite/g++.dg/ext/is_trivial1.C 
b/gcc/testsuite/g++.dg/ext/is_trivial1.C
new file mode 100644
index ..60ce48edfe9e
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ext/is_trivial1.C
@@ -0,0 +1,14 @@
+// PR c++/108769
+// { dg-do compile { target c++20 } }
+
+template 
+struct S {
+S() requires false = default;
+};
+static_assert(!__is_trivial(S));
+
+template 
+struct R {
+R() requires true = default;
+};
+static_assert(__is_trivial(R));
diff --git a/gcc/testsuite/g++.dg/ext/is_trivial2.C 
b/gcc/testsuite/g++.dg/ext/is_trivial2.C
new file mode 100644
index ..e7ecc74831a6
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ext/is_trivial2.C
@@ -0,0 +1,20 @@
+// PR c++/58074
+// { dg-do compile { target c++11 } }
+
+struct Trivial
+{
+  Trivial() = delete;
+};
+
+struct NonTrivi

[gcc r15-2147] libatomic: Handle AVX+CX16 ZHAOXIN like Intel for 16b atomic [PR104688]

2024-07-18 Thread Uros Bizjak via Gcc-cvs
https://gcc.gnu.org/g:9846b0916c1a9b9f3e9df4657670ef4419617134

commit r15-2147-g9846b0916c1a9b9f3e9df4657670ef4419617134
Author: mayshao 
Date:   Thu Jul 18 22:43:00 2024 +0200

libatomic: Handle AVX+CX16 ZHAOXIN like Intel for 16b atomic [PR104688]

PR target/104688

libatomic/ChangeLog:

* config/x86/init.c (__libat_feat1_init): Don't clear
bit_AVX on ZHAOXIN CPUs.

Diff:
---
 libatomic/config/x86/init.c | 10 +++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/libatomic/config/x86/init.c b/libatomic/config/x86/init.c
index 26168d468324..c6ce997a5af4 100644
--- a/libatomic/config/x86/init.c
+++ b/libatomic/config/x86/init.c
@@ -41,11 +41,15 @@ __libat_feat1_init (void)
{
  /* Intel SDM guarantees that 16-byte VMOVDQA on 16-byte aligned
 address is atomic, and AMD is going to do something similar soon.
-We don't have a guarantee from vendors of other CPUs with AVX,
-like Zhaoxin and VIA.  */
+Zhaoxin also guarantees this.  We don't have a guarantee
+from vendors of other CPUs with AVX, like VIA.  */
+ unsigned int family = (eax >> 8) & 0x0f;
  unsigned int ecx2;
  __cpuid (0, eax, ebx, ecx2, edx);
- if (ecx2 != signature_INTEL_ecx && ecx2 != signature_AMD_ecx)
+ if (ecx2 != signature_INTEL_ecx
+ && ecx2 != signature_AMD_ecx
+ && !(ecx2 == signature_CENTAUR_ecx && family > 6)
+ && ecx2 != signature_SHANGHAI_ecx)
FEAT1_REGISTER &= ~bit_AVX;
}
 #endif


[gcc] Created branch 'meissner/heads/work172' in namespace 'refs/users'

2024-07-18 Thread Michael Meissner via Gcc-cvs
The branch 'meissner/heads/work172' was created in namespace 'refs/users' 
pointing to:

 9846b0916c1a... libatomic: Handle AVX+CX16 ZHAOXIN like Intel for 16b atomi


[gcc(refs/users/meissner/heads/work172)] Add ChangeLog.meissner and REVISION.

2024-07-18 Thread Michael Meissner via Libstdc++-cvs
https://gcc.gnu.org/g:17ac65e3c71f1cadcb631ee5d1ff4ababf02e4b7

commit 17ac65e3c71f1cadcb631ee5d1ff4ababf02e4b7
Author: Michael Meissner 
Date:   Thu Jul 18 19:00:48 2024 -0400

Add ChangeLog.meissner and REVISION.

2024-07-18  Michael Meissner  

gcc/

* REVISION: New file for branch.
* ChangeLog.meissner: New file.

gcc/c-family/

* ChangeLog.meissner: New file.

gcc/c/

* ChangeLog.meissner: New file.

gcc/cp/

* ChangeLog.meissner: New file.

gcc/fortran/

* ChangeLog.meissner: New file.

gcc/testsuite/

* ChangeLog.meissner: New file.

libgcc/

* ChangeLog.meissner: New file.

Diff:
---
 gcc/ChangeLog.meissner   | 6 ++
 gcc/REVISION | 1 +
 gcc/c-family/ChangeLog.meissner  | 6 ++
 gcc/c/ChangeLog.meissner | 6 ++
 gcc/cp/ChangeLog.meissner| 6 ++
 gcc/fortran/ChangeLog.meissner   | 6 ++
 gcc/testsuite/ChangeLog.meissner | 6 ++
 libgcc/ChangeLog.meissner| 6 ++
 libstdc++-v3/ChangeLog.meissner  | 6 ++
 9 files changed, 49 insertions(+)

diff --git a/gcc/ChangeLog.meissner b/gcc/ChangeLog.meissner
new file mode 100644
index ..88cfb0b5a5b0
--- /dev/null
+++ b/gcc/ChangeLog.meissner
@@ -0,0 +1,6 @@
+ Branch work172, baseline 
+
+2024-07-18   Michael Meissner  
+
+   Clone branch
+
diff --git a/gcc/REVISION b/gcc/REVISION
new file mode 100644
index ..9343afd15407
--- /dev/null
+++ b/gcc/REVISION
@@ -0,0 +1 @@
+work172 branch
diff --git a/gcc/c-family/ChangeLog.meissner b/gcc/c-family/ChangeLog.meissner
new file mode 100644
index ..88cfb0b5a5b0
--- /dev/null
+++ b/gcc/c-family/ChangeLog.meissner
@@ -0,0 +1,6 @@
+ Branch work172, baseline 
+
+2024-07-18   Michael Meissner  
+
+   Clone branch
+
diff --git a/gcc/c/ChangeLog.meissner b/gcc/c/ChangeLog.meissner
new file mode 100644
index ..88cfb0b5a5b0
--- /dev/null
+++ b/gcc/c/ChangeLog.meissner
@@ -0,0 +1,6 @@
+ Branch work172, baseline 
+
+2024-07-18   Michael Meissner  
+
+   Clone branch
+
diff --git a/gcc/cp/ChangeLog.meissner b/gcc/cp/ChangeLog.meissner
new file mode 100644
index ..88cfb0b5a5b0
--- /dev/null
+++ b/gcc/cp/ChangeLog.meissner
@@ -0,0 +1,6 @@
+ Branch work172, baseline 
+
+2024-07-18   Michael Meissner  
+
+   Clone branch
+
diff --git a/gcc/fortran/ChangeLog.meissner b/gcc/fortran/ChangeLog.meissner
new file mode 100644
index ..88cfb0b5a5b0
--- /dev/null
+++ b/gcc/fortran/ChangeLog.meissner
@@ -0,0 +1,6 @@
+ Branch work172, baseline 
+
+2024-07-18   Michael Meissner  
+
+   Clone branch
+
diff --git a/gcc/testsuite/ChangeLog.meissner b/gcc/testsuite/ChangeLog.meissner
new file mode 100644
index ..88cfb0b5a5b0
--- /dev/null
+++ b/gcc/testsuite/ChangeLog.meissner
@@ -0,0 +1,6 @@
+ Branch work172, baseline 
+
+2024-07-18   Michael Meissner  
+
+   Clone branch
+
diff --git a/libgcc/ChangeLog.meissner b/libgcc/ChangeLog.meissner
new file mode 100644
index ..88cfb0b5a5b0
--- /dev/null
+++ b/libgcc/ChangeLog.meissner
@@ -0,0 +1,6 @@
+ Branch work172, baseline 
+
+2024-07-18   Michael Meissner  
+
+   Clone branch
+
diff --git a/libstdc++-v3/ChangeLog.meissner b/libstdc++-v3/ChangeLog.meissner
new file mode 100644
index ..88cfb0b5a5b0
--- /dev/null
+++ b/libstdc++-v3/ChangeLog.meissner
@@ -0,0 +1,6 @@
+ Branch work172, baseline 
+
+2024-07-18   Michael Meissner  
+
+   Clone branch
+


[gcc] Created branch 'meissner/heads/work172-dmf' in namespace 'refs/users'

2024-07-18 Thread Michael Meissner via Gcc-cvs
The branch 'meissner/heads/work172-dmf' was created in namespace 'refs/users' 
pointing to:

 17ac65e3c71f... Add ChangeLog.meissner and REVISION.


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

2024-07-18 Thread Michael Meissner via Gcc-cvs
https://gcc.gnu.org/g:473e41582f5dfa6f5f4ee9e03b18bd5114eb4863

commit 473e41582f5dfa6f5f4ee9e03b18bd5114eb4863
Author: Michael Meissner 
Date:   Thu Jul 18 19:13:26 2024 -0400

Add ChangeLog.dmf and update REVISION.

2024-07-18  Michael Meissner  

gcc/

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

Diff:
---
 gcc/ChangeLog.dmf | 6 ++
 gcc/REVISION  | 2 +-
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/gcc/ChangeLog.dmf b/gcc/ChangeLog.dmf
new file mode 100644
index ..cfa143035a16
--- /dev/null
+++ b/gcc/ChangeLog.dmf
@@ -0,0 +1,6 @@
+ Branch work172-dmf, baseline 
+
+2024-07-18   Michael Meissner  
+
+   Clone branch
+
diff --git a/gcc/REVISION b/gcc/REVISION
index 9343afd15407..6f66f84fd5da 100644
--- a/gcc/REVISION
+++ b/gcc/REVISION
@@ -1 +1 @@
-work172 branch
+work172-dmf branch


[gcc] Created branch 'meissner/heads/work172-vpair' in namespace 'refs/users'

2024-07-18 Thread Michael Meissner via Gcc-cvs
The branch 'meissner/heads/work172-vpair' was created in namespace 'refs/users' 
pointing to:

 17ac65e3c71f... Add ChangeLog.meissner and REVISION.


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

2024-07-18 Thread Michael Meissner via Gcc-cvs
https://gcc.gnu.org/g:43d27e034c3bb7e62dd110daac7410946e468e0c

commit 43d27e034c3bb7e62dd110daac7410946e468e0c
Author: Michael Meissner 
Date:   Thu Jul 18 19:14:25 2024 -0400

Add ChangeLog.vpair and update REVISION.

2024-07-18  Michael Meissner  

gcc/

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

Diff:
---
 gcc/ChangeLog.vpair | 6 ++
 gcc/REVISION| 2 +-
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/gcc/ChangeLog.vpair b/gcc/ChangeLog.vpair
new file mode 100644
index ..bf76f0b1278e
--- /dev/null
+++ b/gcc/ChangeLog.vpair
@@ -0,0 +1,6 @@
+ Branch work172-vpair, baseline 
+
+2024-07-18   Michael Meissner  
+
+   Clone branch
+
diff --git a/gcc/REVISION b/gcc/REVISION
index 9343afd15407..b5a7d541515e 100644
--- a/gcc/REVISION
+++ b/gcc/REVISION
@@ -1 +1 @@
-work172 branch
+work172-vpair branch


[gcc] Created branch 'meissner/heads/work172-tar' in namespace 'refs/users'

2024-07-18 Thread Michael Meissner via Gcc-cvs
The branch 'meissner/heads/work172-tar' was created in namespace 'refs/users' 
pointing to:

 17ac65e3c71f... Add ChangeLog.meissner and REVISION.


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

2024-07-18 Thread Michael Meissner via Gcc-cvs
https://gcc.gnu.org/g:c9780fe1de77b080a002c3094319055df191b541

commit c9780fe1de77b080a002c3094319055df191b541
Author: Michael Meissner 
Date:   Thu Jul 18 19:15:19 2024 -0400

Add ChangeLog.tar and update REVISION.

2024-07-18  Michael Meissner  

gcc/

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

Diff:
---
 gcc/ChangeLog.tar | 6 ++
 gcc/REVISION  | 2 +-
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/gcc/ChangeLog.tar b/gcc/ChangeLog.tar
new file mode 100644
index ..d010564dde31
--- /dev/null
+++ b/gcc/ChangeLog.tar
@@ -0,0 +1,6 @@
+ Branch work172-tar, baseline 
+
+2024-07-18   Michael Meissner  
+
+   Clone branch
+
diff --git a/gcc/REVISION b/gcc/REVISION
index 9343afd15407..0db322e2a259 100644
--- a/gcc/REVISION
+++ b/gcc/REVISION
@@ -1 +1 @@
-work172 branch
+work172-tar branch


[gcc] Created branch 'meissner/heads/work172-bugs' in namespace 'refs/users'

2024-07-18 Thread Michael Meissner via Gcc-cvs
The branch 'meissner/heads/work172-bugs' was created in namespace 'refs/users' 
pointing to:

 17ac65e3c71f... Add ChangeLog.meissner and REVISION.


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

2024-07-18 Thread Michael Meissner via Gcc-cvs
https://gcc.gnu.org/g:fef03352a9599cc48ff9288ce6d8e4de66808ad2

commit fef03352a9599cc48ff9288ce6d8e4de66808ad2
Author: Michael Meissner 
Date:   Thu Jul 18 19:16:11 2024 -0400

Add ChangeLog.bugs and update REVISION.

2024-07-18  Michael Meissner  

gcc/

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

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

diff --git a/gcc/ChangeLog.bugs b/gcc/ChangeLog.bugs
new file mode 100644
index ..d924970ab528
--- /dev/null
+++ b/gcc/ChangeLog.bugs
@@ -0,0 +1,6 @@
+ Branch work172-bugs, baseline 
+
+2024-07-18   Michael Meissner  
+
+   Clone branch
+
diff --git a/gcc/REVISION b/gcc/REVISION
index 9343afd15407..a983d5efd42d 100644
--- a/gcc/REVISION
+++ b/gcc/REVISION
@@ -1 +1 @@
-work172 branch
+work172-bugs branch


[gcc] Created branch 'meissner/heads/work172-test' in namespace 'refs/users'

2024-07-18 Thread Michael Meissner via Gcc-cvs
The branch 'meissner/heads/work172-test' was created in namespace 'refs/users' 
pointing to:

 17ac65e3c71f... Add ChangeLog.meissner and REVISION.


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

2024-07-18 Thread Michael Meissner via Gcc-cvs
https://gcc.gnu.org/g:a602ce0fee0366f03d86872d52d54e1d17d5116c

commit a602ce0fee0366f03d86872d52d54e1d17d5116c
Author: Michael Meissner 
Date:   Thu Jul 18 19:17:04 2024 -0400

Add ChangeLog.test and update REVISION.

2024-07-18  Michael Meissner  

gcc/

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

Diff:
---
 gcc/ChangeLog.test | 6 ++
 gcc/REVISION   | 2 +-
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/gcc/ChangeLog.test b/gcc/ChangeLog.test
new file mode 100644
index ..cdb16a03a886
--- /dev/null
+++ b/gcc/ChangeLog.test
@@ -0,0 +1,6 @@
+ Branch work172-test, baseline 
+
+2024-07-18   Michael Meissner  
+
+   Clone branch
+
diff --git a/gcc/REVISION b/gcc/REVISION
index 9343afd15407..3f4898aba6b0 100644
--- a/gcc/REVISION
+++ b/gcc/REVISION
@@ -1 +1 @@
-work172 branch
+work172-test branch


[gcc] Created branch 'meissner/heads/work172-orig' in namespace 'refs/users'

2024-07-18 Thread Michael Meissner via Gcc-cvs
The branch 'meissner/heads/work172-orig' was created in namespace 'refs/users' 
pointing to:

 9846b0916c1a... libatomic: Handle AVX+CX16 ZHAOXIN like Intel for 16b atomi


[gcc(refs/users/meissner/heads/work172-orig)] Add REVISION.

2024-07-18 Thread Michael Meissner via Gcc-cvs
https://gcc.gnu.org/g:e824b5573b8eaef4acd107d4f3d643c735c138c7

commit e824b5573b8eaef4acd107d4f3d643c735c138c7
Author: Michael Meissner 
Date:   Thu Jul 18 19:28:52 2024 -0400

Add REVISION.

2024-07-18  Michael Meissner  

gcc/

* REVISION: New file for branch.

Diff:
---
 gcc/REVISION | 1 +
 1 file changed, 1 insertion(+)

diff --git a/gcc/REVISION b/gcc/REVISION
new file mode 100644
index ..6e81346dac4d
--- /dev/null
+++ b/gcc/REVISION
@@ -0,0 +1 @@
+work172-orig branch


[gcc r15-2149] Match: Only allow single use of MIN_EXPR for SAT_TRUNC form 2 [PR115863]

2024-07-18 Thread Pan Li via Gcc-cvs
https://gcc.gnu.org/g:02cc8494745c4235890ad58e93b5acce5a89a775

commit r15-2149-g02cc8494745c4235890ad58e93b5acce5a89a775
Author: Pan Li 
Date:   Thu Jul 18 20:16:34 2024 +0800

Match: Only allow single use of MIN_EXPR for SAT_TRUNC form 2 [PR115863]

The SAT_TRUNC form 2 has below pattern matching.
From:
  _18 = MIN_EXPR ;
  iftmp.0_11 = (unsigned int) _18;

To:
  _18 = MIN_EXPR ;
  iftmp.0_11 = .SAT_TRUNC (left_8);

But if there is another use of _18 like below,  the transform to the
.SAT_TRUNC may have no earnings.  For example:

From:
  _18 = MIN_EXPR ; // op_0 def
  iftmp.0_11 = (unsigned int) _18; // op_0
  stream.avail_out = iftmp.0_11;
  left_37 = left_8 - _18;  // op_0 use

To:
  _18 = MIN_EXPR ; // op_0 def
  iftmp.0_11 = .SAT_TRUNC (left_8);
  stream.avail_out = iftmp.0_11;
  left_37 = left_8 - _18;  // op_0 use

Pattern recog to .SAT_TRUNC cannot eliminate MIN_EXPR as above.  Then the
backend (for example x86/riscv) will have additional 2-3 more insns
after pattern recog besides the MIN_EXPR.  Thus,  keep the normal truncation
as is should be the better choose.

The below testsuites are passed for this patch:
1. The rv64gcv fully regression tests.
2. The x86 bootstrap tests.
3. The x86 fully regression tests.

PR target/115863

gcc/ChangeLog:

* match.pd: Add single_use check for .SAT_TRUNC form 2.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Pan Li 

Diff:
---
 gcc/match.pd   | 15 ++--
 gcc/testsuite/gcc.target/i386/pr115863-1.c | 37 ++
 2 files changed, 50 insertions(+), 2 deletions(-)

diff --git a/gcc/match.pd b/gcc/match.pd
index 6818856991c6..cf359b0ec0f0 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -3252,10 +3252,21 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
 
 /* Unsigned saturation truncate, case 2, sizeof (WT) > sizeof (NT).
SAT_U_TRUNC = (NT)(MIN_EXPR (X, 255)).  */
+/* If Op_0 def is MIN_EXPR and not single_use.  Aka below pattern:
+
+ _18 = MIN_EXPR ; // op_0 def
+ iftmp.0_11 = (unsigned int) _18; // op_0
+ stream.avail_out = iftmp.0_11;
+ left_37 = left_8 - _18;  // op_0 use
+
+   Transfer to .SAT_TRUNC will have MIN_EXPR still live.  Then the backend
+   (for example x86/riscv) will have 2-3 more insns generation for .SAT_TRUNC
+   besides the MIN_EXPR.  Thus,  keep the normal truncation as is should be
+   the better choose.  */
 (match (unsigned_integer_sat_trunc @0)
- (convert (min @0 INTEGER_CST@1))
+ (convert (min@2 @0 INTEGER_CST@1))
  (if (INTEGRAL_TYPE_P (type) && TYPE_UNSIGNED (type)
-  && TYPE_UNSIGNED (TREE_TYPE (@0)))
+  && TYPE_UNSIGNED (TREE_TYPE (@0)) && single_use (@2))
  (with
   {
unsigned itype_precision = TYPE_PRECISION (TREE_TYPE (@0));
diff --git a/gcc/testsuite/gcc.target/i386/pr115863-1.c 
b/gcc/testsuite/gcc.target/i386/pr115863-1.c
new file mode 100644
index ..a672f62cec54
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr115863-1.c
@@ -0,0 +1,37 @@
+/* PR target/115863 */
+/* { dg-do compile } */
+/* { dg-options "-O3 -fdump-rtl-expand-details" } */
+
+#include 
+
+typedef struct z_stream_s {
+uint32_t avail_out;
+} z_stream;
+
+typedef z_stream *z_streamp;
+
+extern int deflate (z_streamp strmp);
+
+int compress2 (uint64_t *destLen)
+{
+  z_stream stream;
+  int err;
+  const uint32_t max = (uint32_t)(-1);
+  uint64_t left;
+
+  left = *destLen;
+
+  stream.avail_out = 0;
+
+  do {
+if (stream.avail_out == 0) {
+stream.avail_out = left > (uint64_t)max ? max : (uint32_t)left;
+left -= stream.avail_out;
+}
+err = deflate(&stream);
+} while (err == 0);
+
+  return err;
+}
+
+/* { dg-final { scan-rtl-dump-not ".SAT_TRUNC " "expand" } } */


[gcc r15-2150] c++: Hash placeholder constraint in ctp_hasher

2024-07-18 Thread Jason Merrill via Gcc-cvs
https://gcc.gnu.org/g:0f8261eae068850c8c48400159fc0a5b540d4d53

commit r15-2150-g0f8261eae068850c8c48400159fc0a5b540d4d53
Author: Seyed Sajad Kahani 
Date:   Thu Jul 18 16:01:32 2024 +0100

c++: Hash placeholder constraint in ctp_hasher

This patch addresses a difference between the hash function and the equality
function for canonical types of template parameters (ctp_hasher). The 
equality
function uses comptypes (typeck.cc) (with COMPARE_STRUCTURAL) and checks
constraint equality for two auto nodes (typeck.cc:1586), while the hash
function ignores it (pt.cc:4528). This leads to hash collisions that can be
avoided by using `hash_placeholder_constraint` (constraint.cc:1150).

Note that due to the proper handling of hash collisions (hash-table.h:1059),
there is no test case that can distinguish the current implementation from 
the
proposed one.

* constraint.cc (hash_placeholder_constraint): Rename to
iterative_hash_placeholder_constraint.
(iterative_hash_placeholder_constraint): Rename from
hash_placeholder_constraint and add the initial val argument.
* cp-tree.h (hash_placeholder_constraint): Rename to
iterative_hash_placeholder_constraint.
(iterative_hash_placeholder_constraint): Renamed from
hash_placeholder_constraint and add the initial val argument.
* pt.cc (struct ctp_hasher): Updated to use
iterative_hash_placeholder_constraint in the case of a valid 
placeholder
constraint.
(auto_hash::hash): Reflect the renaming of 
hash_placeholder_constraint to
iterative_hash_placeholder_constraint.

Diff:
---
 gcc/cp/cp-tree.h | 2 +-
 gcc/cp/constraint.cc | 4 ++--
 gcc/cp/pt.cc | 9 +++--
 3 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index c6f102564ce0..609d8941cf72 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -8581,7 +8581,7 @@ extern tree_pair finish_type_constraints  (tree, tree, 
tsubst_flags_t);
 extern tree build_constrained_parameter (tree, tree, tree = NULL_TREE);
 extern void placeholder_extract_concept_and_args (tree, tree&, tree&);
 extern bool equivalent_placeholder_constraints  (tree, tree);
-extern hashval_t hash_placeholder_constraint   (tree);
+extern hashval_t iterative_hash_placeholder_constraint (tree, hashval_t);
 extern bool deduce_constrained_parameter(tree, tree&, tree&);
 extern tree resolve_constraint_check(tree);
 extern tree check_function_concept  (tree);
diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc
index 5472cc51b8ad..afd5435cc3ed 100644
--- a/gcc/cp/constraint.cc
+++ b/gcc/cp/constraint.cc
@@ -1689,13 +1689,13 @@ equivalent_placeholder_constraints (tree c1, tree c2)
 /* Return a hash value for the placeholder ATOMIC_CONSTR C.  */
 
 hashval_t
-hash_placeholder_constraint (tree c)
+iterative_hash_placeholder_constraint (tree c, hashval_t val)
 {
   tree t, a;
   placeholder_extract_concept_and_args (c, t, a);
 
   /* Like hash_tmpl_and_args, but skip the first argument.  */
-  hashval_t val = iterative_hash_object (DECL_UID (t), 0);
+  val = iterative_hash_object (DECL_UID (t), val);
 
   for (int i = TREE_VEC_LENGTH (a)-1; i > 0; --i)
 val = iterative_hash_template_arg (TREE_VEC_ELT (a, i), val);
diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index 057797f213f5..108e929b8ee6 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -4500,7 +4500,12 @@ struct ctp_hasher : ggc_ptr_hash
 val = iterative_hash_object (TEMPLATE_TYPE_LEVEL (t), val);
 val = iterative_hash_object (TEMPLATE_TYPE_IDX (t), val);
 if (TREE_CODE (t) == TEMPLATE_TYPE_PARM)
-  val = iterative_hash_template_arg (CLASS_PLACEHOLDER_TEMPLATE (t), val);
+  {
+   val
+ = iterative_hash_template_arg (CLASS_PLACEHOLDER_TEMPLATE (t), val);
+   if (tree c = NON_ERROR (PLACEHOLDER_TYPE_CONSTRAINTS (t)))
+ val = iterative_hash_placeholder_constraint (c, val);
+  }
 if (TREE_CODE (t) == BOUND_TEMPLATE_TEMPLATE_PARM)
   val = iterative_hash_template_arg (TYPE_TI_ARGS (t), val);
 --comparing_specializations;
@@ -29581,7 +29586,7 @@ auto_hash::hash (tree t)
   if (tree c = NON_ERROR (PLACEHOLDER_TYPE_CONSTRAINTS (t)))
 /* Matching constrained-type-specifiers denote the same template
parameter, so hash the constraint.  */
-return hash_placeholder_constraint (c);
+return iterative_hash_placeholder_constraint (c, 0);
   else
 /* But unconstrained autos are all separate, so just hash the pointer.  */
 return iterative_hash_object (t, 0);


[gcc r11-11584] Update ChangeLog and version files for release

2024-07-18 Thread Richard Biener via Gcc-cvs
https://gcc.gnu.org/g:5cc4c42a0d4de08715c2eef8715ad5b2e92a23b6

commit r11-11584-g5cc4c42a0d4de08715c2eef8715ad5b2e92a23b6
Author: Richard Biener 
Date:   Fri Jul 19 05:53:33 2024 +

Update ChangeLog and version files for release

Diff:
---
 ChangeLog | 4 
 c++tools/ChangeLog| 4 
 config/ChangeLog  | 4 
 contrib/ChangeLog | 4 
 contrib/header-tools/ChangeLog| 4 
 contrib/reghunt/ChangeLog | 4 
 contrib/regression/ChangeLog  | 4 
 fixincludes/ChangeLog | 4 
 gcc/BASE-VER  | 2 +-
 gcc/ChangeLog | 4 
 gcc/ada/ChangeLog | 4 
 gcc/analyzer/ChangeLog| 4 
 gcc/brig/ChangeLog| 4 
 gcc/c-family/ChangeLog| 4 
 gcc/c/ChangeLog   | 4 
 gcc/cp/ChangeLog  | 4 
 gcc/d/ChangeLog   | 4 
 gcc/fortran/ChangeLog | 4 
 gcc/go/ChangeLog  | 4 
 gcc/jit/ChangeLog | 4 
 gcc/lto/ChangeLog | 4 
 gcc/objc/ChangeLog| 4 
 gcc/objcp/ChangeLog   | 4 
 gcc/po/ChangeLog  | 4 
 gcc/testsuite/ChangeLog   | 4 
 gnattools/ChangeLog   | 4 
 gotools/ChangeLog | 4 
 include/ChangeLog | 4 
 intl/ChangeLog| 4 
 libada/ChangeLog  | 4 
 libatomic/ChangeLog   | 4 
 libbacktrace/ChangeLog| 4 
 libcc1/ChangeLog  | 4 
 libcody/ChangeLog | 4 
 libcpp/ChangeLog  | 4 
 libcpp/po/ChangeLog   | 4 
 libdecnumber/ChangeLog| 4 
 libffi/ChangeLog  | 4 
 libgcc/ChangeLog  | 4 
 libgcc/config/avr/libf7/ChangeLog | 4 
 libgcc/config/libbid/ChangeLog| 4 
 libgfortran/ChangeLog | 4 
 libgomp/ChangeLog | 4 
 libhsail-rt/ChangeLog | 4 
 libiberty/ChangeLog   | 4 
 libitm/ChangeLog  | 4 
 libobjc/ChangeLog | 4 
 liboffloadmic/ChangeLog   | 4 
 libphobos/ChangeLog   | 4 
 libquadmath/ChangeLog | 4 
 libsanitizer/ChangeLog| 4 
 libssp/ChangeLog  | 4 
 libstdc++-v3/ChangeLog| 4 
 libvtv/ChangeLog  | 4 
 lto-plugin/ChangeLog  | 4 
 maintainer-scripts/ChangeLog  | 4 
 zlib/ChangeLog| 4 
 57 files changed, 225 insertions(+), 1 deletion(-)

diff --git a/ChangeLog b/ChangeLog
index 48d69d2bf1c4..ccc548944b16 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2024-07-19  Release Manager
+
+   * GCC 11.5.0 released.
+
 2023-05-29  Release Manager
 
* GCC 11.4.0 released.
diff --git a/c++tools/ChangeLog b/c++tools/ChangeLog
index 46505bf853b6..a4cfdae87fdb 100644
--- a/c++tools/ChangeLog
+++ b/c++tools/ChangeLog
@@ -1,3 +1,7 @@
+2024-07-19  Release Manager
+
+   * GCC 11.5.0 released.
+
 2023-05-29  Release Manager
 
* GCC 11.4.0 released.
diff --git a/config/ChangeLog b/config/ChangeLog
index 28b8a737fb3e..6bf7fc63c7a8 100644
--- a/config/ChangeLog
+++ b/config/ChangeLog
@@ -1,3 +1,7 @@
+2024-07-19  Release Manager
+
+   * GCC 11.5.0 released.
+
 2023-05-29  Release Manager
 
* GCC 11.4.0 released.
diff --git a/contrib/ChangeLog b/contrib/ChangeLog
index 73ecfe5ddc7a..bb0f18e30f97 100644
--- a/contrib/ChangeLog
+++ b/contrib/ChangeLog
@@ -1,3 +1,7 @@
+2024-07-19  Release Manager
+
+   * GCC 11.5.0 released.
+
 2023-05-29  Release Manager
 
* GCC 11.4.0 released.
diff --git a/contrib/header-tools/ChangeLog b/contrib/header-tools/ChangeLog
index c6bf489533e0..e64c34b9792c 100644
--- a/contrib/header-tools/ChangeLog
+++ b/contrib/header-tools/ChangeLog
@@ -1,3 +1,7 @@
+2024-07-19  Release Manager
+
+   * GCC 11.5.0 released.
+
 2023-05-29  Release Manager
 
* GCC 11.4.0 released.
diff --git a/contrib/reghunt/ChangeLog b/contrib/reghunt/ChangeLog
index 8c438a39a115..c5aab3bc981b 100644
--- a/contrib/reghunt/ChangeLog
+++ b/contrib/reghunt/ChangeLog
@@ -1,3 +1,7 @@
+2024-07-19  Release Manager
+
+   * GCC 11.5.0 released.
+
 2023-05-29  Release Manager
 
* GCC 11.4.0 released.
diff --git a/contrib/regression/ChangeLog b/contrib/regression/ChangeLog
index 5412df7fab59..ad7c629493fb 100644
--- a/contrib/regression/ChangeLog
+++ b/contrib/regression/ChangeLog
@@ -1,3 +1,7 @@
+2024-07-19  Release Manager
+
+   * GCC 11.5.0 released.
+
 2023-05-29  Release Manager
 
* GCC 11.4.0 released.
diff --git a/fixincludes/ChangeLog b/fixincludes/ChangeLog
index aa3cdfbd4ec9..f22552738ab2 100644
--- a/fixincludes/ChangeLog
+

[gcc] Created tag 'releases/gcc-11.5.0'

2024-07-18 Thread Richard Biener via Gcc-cvs
The signed tag 'releases/gcc-11.5.0' was created pointing to:

 5cc4c42a0d4d... Update ChangeLog and version files for release

Tagger: Richard Biener 
Date: Fri Jul 19 05:53:40 2024 +

GCC 11.5.0 release


[gcc r14-10463] [RISC-V] add implied extension repeatly until stable

2024-07-18 Thread Kito Cheng via Gcc-cvs
https://gcc.gnu.org/g:b218c425328cd54994f717aaaca757b852df6aa9

commit r14-10463-gb218c425328cd54994f717aaaca757b852df6aa9
Author: Fei Gao 
Date:   Fri Jul 5 09:56:30 2024 +

[RISC-V] add implied extension repeatly until stable

Call handle_implied_ext repeatly until there's no
new subset added into the subset list.

gcc/ChangeLog:

* common/config/riscv/riscv-common.cc 
(riscv_subset_list::riscv_subset_list):
init m_subset_num to 0.
(riscv_subset_list::add): increase m_subset_num once a subset added.
(riscv_subset_list::finalize): call handle_implied_ext repeatly
until no change in m_subset_num.
* config/riscv/riscv-subset.h: add m_subset_num member.

Signed-off-by: Fei Gao 
(cherry picked from commit 682731d11f9c02b24358d1af1e2bf6fca0221ee7)

Diff:
---
 gcc/common/config/riscv/riscv-common.cc | 14 +++---
 gcc/config/riscv/riscv-subset.h |  3 +++
 2 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/gcc/common/config/riscv/riscv-common.cc 
b/gcc/common/config/riscv/riscv-common.cc
index 5212f67faad4..3f5ff0b171a2 100644
--- a/gcc/common/config/riscv/riscv-common.cc
+++ b/gcc/common/config/riscv/riscv-common.cc
@@ -458,7 +458,8 @@ riscv_subset_t::riscv_subset_t ()
 }
 
 riscv_subset_list::riscv_subset_list (const char *arch, location_t loc)
-  : m_arch (arch), m_loc (loc), m_head (NULL), m_tail (NULL), m_xlen (0)
+  : m_arch (arch), m_loc (loc), m_head (NULL), m_tail (NULL), m_xlen (0),
+m_subset_num (0)
 {
 }
 
@@ -709,6 +710,7 @@ riscv_subset_list::add (const char *subset, int 
major_version,
   return;
 }
 
+  m_subset_num++;
   riscv_subset_t *s = new riscv_subset_t ();
   riscv_subset_t *itr;
 
@@ -1472,9 +1474,15 @@ void
 riscv_subset_list::finalize ()
 {
   riscv_subset_t *subset;
+  unsigned pre_subset_num;
 
-  for (subset = m_head; subset != NULL; subset = subset->next)
-handle_implied_ext (subset->name.c_str ());
+  do
+{
+  pre_subset_num = m_subset_num;
+  for (subset = m_head; subset != NULL; subset = subset->next)
+   handle_implied_ext (subset->name.c_str ());
+}
+  while (pre_subset_num != m_subset_num);
 
   gcc_assert (check_implied_ext ());
 
diff --git a/gcc/config/riscv/riscv-subset.h b/gcc/config/riscv/riscv-subset.h
index c2d213c1734f..4d2bf9d9201c 100644
--- a/gcc/config/riscv/riscv-subset.h
+++ b/gcc/config/riscv/riscv-subset.h
@@ -65,6 +65,9 @@ private:
   /* Allow adding the same extension more than once.  */
   bool m_allow_adding_dup;
 
+  /* Number of subsets. */
+  unsigned m_subset_num;
+
   riscv_subset_list (const char *, location_t);
 
   const char *parsing_subset_version (const char *, const char *, unsigned *,


[gcc r14-10464] RISC-V: Use tu policy for first-element vec_set [PR115725].

2024-07-18 Thread Kito Cheng via Gcc-cvs
https://gcc.gnu.org/g:2d7dda84730e0e364b3b1776d387c9ceb85385ea

commit r14-10464-g2d7dda84730e0e364b3b1776d387c9ceb85385ea
Author: Robin Dapp 
Date:   Mon Jul 1 13:37:17 2024 +0200

RISC-V: Use tu policy for first-element vec_set [PR115725].

This patch changes the tail policy for vmv.s.x from ta to tu.
By default the bug does not show up with qemu because qemu's
current vmv.s.x implementation always uses the tail-undisturbed
policy.  With a local qemu version that overwrites the tail
with ones when the tail-agnostic policy is specified, the bug
shows.

gcc/ChangeLog:

* config/riscv/autovec.md: Add TU policy.
* config/riscv/riscv-protos.h (enum insn_type): Define
SCALAR_MOVE_MERGED_OP_TU.

gcc/testsuite/ChangeLog:

PR target/115725

* gcc.target/riscv/rvv/autovec/vls-vlmax/vec_set-1.c: Adjust
test expectation.
* gcc.target/riscv/rvv/autovec/vls-vlmax/vec_set-2.c: Ditto.
* gcc.target/riscv/rvv/autovec/vls-vlmax/vec_set-3.c: Ditto.
* gcc.target/riscv/rvv/autovec/vls-vlmax/vec_set-4.c: Ditto.

(cherry picked from commit acc3b703c05debc6276451f9daae5d0ffc797eac)

Diff:
---
 gcc/config/riscv/autovec.md  |  3 ++-
 gcc/config/riscv/riscv-protos.h  |  4 
 .../gcc.target/riscv/rvv/autovec/vls-vlmax/vec_set-1.c   | 12 
 .../gcc.target/riscv/rvv/autovec/vls-vlmax/vec_set-2.c   | 12 
 .../gcc.target/riscv/rvv/autovec/vls-vlmax/vec_set-3.c   | 12 
 .../gcc.target/riscv/rvv/autovec/vls-vlmax/vec_set-4.c   | 12 
 6 files changed, 22 insertions(+), 33 deletions(-)

diff --git a/gcc/config/riscv/autovec.md b/gcc/config/riscv/autovec.md
index aa1ae0fe075b..43f538f114cc 100644
--- a/gcc/config/riscv/autovec.md
+++ b/gcc/config/riscv/autovec.md
@@ -1341,7 +1341,8 @@
 {
   rtx ops[] = {operands[0], operands[0], operands[1]};
   riscv_vector::emit_nonvlmax_insn (code_for_pred_broadcast (mode),
-   riscv_vector::SCALAR_MOVE_MERGED_OP, 
ops, CONST1_RTX (Pmode));
+   riscv_vector::SCALAR_MOVE_MERGED_OP_TU,
+   ops, CONST1_RTX (Pmode));
 }
   else
 {
diff --git a/gcc/config/riscv/riscv-protos.h b/gcc/config/riscv/riscv-protos.h
index 5d46a29d8b70..822a72a4c1ac 100644
--- a/gcc/config/riscv/riscv-protos.h
+++ b/gcc/config/riscv/riscv-protos.h
@@ -508,6 +508,10 @@ enum insn_type : unsigned int
   SCALAR_MOVE_MERGED_OP = HAS_DEST_P | HAS_MASK_P | USE_ONE_TRUE_MASK_P
  | HAS_MERGE_P | TDEFAULT_POLICY_P | MDEFAULT_POLICY_P
  | UNARY_OP_P,
+
+  SCALAR_MOVE_MERGED_OP_TU = HAS_DEST_P | HAS_MASK_P | USE_ONE_TRUE_MASK_P
+ | HAS_MERGE_P | TU_POLICY_P | MDEFAULT_POLICY_P
+ | UNARY_OP_P,
 };
 
 enum vlmul_type
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/autovec/vls-vlmax/vec_set-1.c 
b/gcc/testsuite/gcc.target/riscv/rvv/autovec/vls-vlmax/vec_set-1.c
index ecb160933d60..99b0f625c835 100644
--- a/gcc/testsuite/gcc.target/riscv/rvv/autovec/vls-vlmax/vec_set-1.c
+++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/vls-vlmax/vec_set-1.c
@@ -64,14 +64,10 @@ typedef double vnx2df __attribute__((vector_size (16)));
 TEST_ALL1 (VEC_SET)
 TEST_ALL_VAR1 (VEC_SET_VAR1)
 
-/* { dg-final { scan-assembler-times 
{vset[i]*vli\s+[a-z0-9,]+,\s*e8,\s*m1,\s*ta,\s*ma} 1 } } */
-/* { dg-final { scan-assembler-times 
{vset[i]*vli\s+[a-z0-9,]+,\s*e8,\s*m1,\s*tu,\s*ma} 5 } } */
-/* { dg-final { scan-assembler-times 
{vset[i]*vli\s+[a-z0-9,]+,\s*e16,\s*m1,\s*ta,\s*ma} 2 } } */
-/* { dg-final { scan-assembler-times 
{vset[i]*vli\s+[a-z0-9,]+,\s*e16,\s*m1,\s*tu,\s*ma} 6 } } */
-/* { dg-final { scan-assembler-times 
{vset[i]*vli\s+[a-z0-9,]+,\s*e32,\s*m1,\s*ta,\s*ma} 2 } } */
-/* { dg-final { scan-assembler-times 
{vset[i]*vli\s+[a-z0-9,]+,\s*e32,\s*m1,\s*tu,\s*ma} 6 } } */
-/* { dg-final { scan-assembler-times 
{vset[i]*vli\s+[a-z0-9,]+,\s*e64,\s*m1,\s*ta,\s*ma} 2 } } */
-/* { dg-final { scan-assembler-times 
{vset[i]*vli\s+[a-z0-9,]+,\s*e64,\s*m1,\s*tu,\s*ma} 4 } } */
+/* { dg-final { scan-assembler-times 
{vset[i]*vli\s+[a-z0-9,]+,\s*e8,\s*m1,\s*tu,\s*ma} 6 } } */
+/* { dg-final { scan-assembler-times 
{vset[i]*vli\s+[a-z0-9,]+,\s*e16,\s*m1,\s*tu,\s*ma} 8 } } */
+/* { dg-final { scan-assembler-times 
{vset[i]*vli\s+[a-z0-9,]+,\s*e32,\s*m1,\s*tu,\s*ma} 8 } } */
+/* { dg-final { scan-assembler-times 
{vset[i]*vli\s+[a-z0-9,]+,\s*e64,\s*m1,\s*tu,\s*ma} 6 } } */
 
 /* { dg-final { scan-assembler-times {\tvmv.v.x} 13 } } */
 /* { dg-final { scan-assembler-times {\tvfmv.v.f} 8 } } */
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/autovec/vls-vlmax/vec_set-2.c 
b/gcc/testsuite/gcc.target/riscv/rvv/autovec/vls-vlmax/vec_set-2.c
index 194abff77ccc..64a40308eb

[gcc r14-10465] [PATCH] RISC-V: Fix unrecognizable pattern in riscv_expand_conditional_move()

2024-07-18 Thread Kito Cheng via Gcc-cvs
https://gcc.gnu.org/g:c32995c4453fa4e04d27fda1597e31e6664f5eb4

commit r14-10465-gc32995c4453fa4e04d27fda1597e31e6664f5eb4
Author: Artemiy Volkov 
Date:   Sun Jun 23 14:54:00 2024 -0600

[PATCH] RISC-V: Fix unrecognizable pattern in 
riscv_expand_conditional_move()

Presently, the code fragment:

int x[5];

void
d(int a, int b, int c) {
  for (int i = 0; i < 5; i++)
x[i] = (a != b) ? c : a;
}

causes an ICE when compiled with -O2 -march=rv32i_zicond:

test.c: In function 'd':
test.c: error: unrecognizable insn:
   11 | }
  | ^
(insn 8 5 9 2 (set (reg:SI 139 [ iftmp.0_2 ])
(if_then_else:SI (ne:SI (reg/v:SI 136 [ a ])
(reg/v:SI 137 [ b ]))
(reg/v:SI 136 [ a ])
(reg/v:SI 138 [ c ]))) -1
 (nil))
during RTL pass: vregs

This happens because, as part of one of the optimizations in
riscv_expand_conditional_move(), an if_then_else is generated with both
comparands being register operands, resulting in an unmatchable insn since
Zicond patterns require constant 0 as the second comparand.  Fix this by 
adding
a extra check before performing this optimization.

The code snippet mentioned above is also included in this patch as a new 
Zicond
testcase.

gcc/ChangeLog:

* config/riscv/riscv.cc (riscv_expand_conditional_move): Add a
CONST0_RTX check.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/zicond-ice-5.c: New test.

(cherry picked from commit eb647daa87b466d0a71246fad302cd81bfce9be5)

Diff:
---
 gcc/config/riscv/riscv.cc |  3 ++-
 gcc/testsuite/gcc.target/riscv/zicond-ice-5.c | 11 +++
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc
index 8e920412e6f4..1c72a3f616a4 100644
--- a/gcc/config/riscv/riscv.cc
+++ b/gcc/config/riscv/riscv.cc
@@ -4739,8 +4739,9 @@ riscv_expand_conditional_move (rtx dest, rtx op, rtx 
cons, rtx alt)
   /* reg, reg  */
   else if (REG_P (cons) && REG_P (alt))
{
- if ((code == EQ && rtx_equal_p (cons, op0))
+ if (((code == EQ && rtx_equal_p (cons, op0))
   || (code == NE && rtx_equal_p (alt, op0)))
+ && op1 == CONST0_RTX (mode))
{
  rtx cond = gen_rtx_fmt_ee (code, GET_MODE (op0), op0, op1);
  alt = force_reg (mode, alt);
diff --git a/gcc/testsuite/gcc.target/riscv/zicond-ice-5.c 
b/gcc/testsuite/gcc.target/riscv/zicond-ice-5.c
new file mode 100644
index ..ac6049c9ae5a
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/zicond-ice-5.c
@@ -0,0 +1,11 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv64gc_zicond -mabi=lp64d" { target { rv64 } } } */
+/* { dg-options "-march=rv32gc_zicond -mabi=ilp32f" { target { rv32 } } } */
+
+int x[5];
+
+void
+d(int a, int b, int c) {
+  for (int i = 0; i < 5; i++)
+x[i] = (a != b) ? c : a;
+}


[gcc r14-10469] RISC-V: Bugfix ICE for RVV intrinisc vfw on _Float16 scalar

2024-07-18 Thread Kito Cheng via Gcc-cvs
https://gcc.gnu.org/g:68ef0c321a7df5899e1fbc3e20e75cce4233d6f7

commit r14-10469-g68ef0c321a7df5899e1fbc3e20e75cce4233d6f7
Author: Pan Li 
Date:   Sat May 11 15:25:28 2024 +0800

RISC-V: Bugfix ICE for RVV intrinisc vfw on _Float16 scalar

For the vfw vx format RVV intrinsic, the scalar type _Float16 also
requires the zvfh extension.  Unfortunately,  we only check the
vector tree type and miss the scalar _Float16 type checking.  For
example:

vfloat32mf2_t test_vfwsub_wf_f32mf2(vfloat32mf2_t vs2, _Float16 rs1, size_t 
vl)
{
  return __riscv_vfwsub_wf_f32mf2(vs2, rs1, vl);
}

It should report some error message like zvfh extension is required
instead of ICE for unreg insn.

This patch would like to make up such kind of validation for _Float16
in the RVV intrinsic API.  It will report some error like below when
there is no zvfh enabled.

error: built-in function '__riscv_vfwsub_wf_f32mf2(vs2,  rs1,  vl)'
  requires the zvfhmin or zvfh ISA extension

Passed the rv64gcv fully regression tests, included c/c++/fortran.

PR target/114988

gcc/ChangeLog:

* config/riscv/riscv-vector-builtins.cc
(validate_instance_type_required_extensions): New func impl to
validate the intrinisc func type ops.
(expand_builtin): Validate instance type before expand.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/base/pr114988-1.c: New test.
* gcc.target/riscv/rvv/base/pr114988-2.c: New test.

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

Diff:
---
 gcc/config/riscv/riscv-vector-builtins.cc  | 51 ++
 .../gcc.target/riscv/rvv/base/pr114988-1.c |  9 
 .../gcc.target/riscv/rvv/base/pr114988-2.c |  9 
 3 files changed, 69 insertions(+)

diff --git a/gcc/config/riscv/riscv-vector-builtins.cc 
b/gcc/config/riscv/riscv-vector-builtins.cc
index 192a6c230d1c..3fdb4400d70d 100644
--- a/gcc/config/riscv/riscv-vector-builtins.cc
+++ b/gcc/config/riscv/riscv-vector-builtins.cc
@@ -4632,6 +4632,54 @@ gimple_fold_builtin (unsigned int code, 
gimple_stmt_iterator *gsi, gcall *stmt)
   return gimple_folder (rfn.instance, rfn.decl, gsi, stmt).fold ();
 }
 
+static bool
+validate_instance_type_required_extensions (const rvv_type_info type,
+   tree exp)
+{
+  uint64_t exts = type.required_extensions;
+
+  if ((exts & RVV_REQUIRE_ELEN_FP_16) &&
+!TARGET_VECTOR_ELEN_FP_16_P (riscv_vector_elen_flags))
+{
+  error_at (EXPR_LOCATION (exp),
+   "built-in function %qE requires the "
+   "zvfhmin or zvfh ISA extension",
+   exp);
+  return false;
+}
+
+  if ((exts & RVV_REQUIRE_ELEN_FP_32) &&
+!TARGET_VECTOR_ELEN_FP_32_P (riscv_vector_elen_flags))
+{
+  error_at (EXPR_LOCATION (exp),
+   "built-in function %qE requires the "
+   "zve32f, zve64f, zve64d or v ISA extension",
+   exp);
+  return false;
+}
+
+  if ((exts & RVV_REQUIRE_ELEN_FP_64) &&
+!TARGET_VECTOR_ELEN_FP_64_P (riscv_vector_elen_flags))
+{
+  error_at (EXPR_LOCATION (exp),
+   "built-in function %qE requires the zve64d or v ISA extension",
+   exp);
+  return false;
+}
+
+  if ((exts & RVV_REQUIRE_ELEN_64) &&
+!TARGET_VECTOR_ELEN_64_P (riscv_vector_elen_flags))
+{
+  error_at (EXPR_LOCATION (exp),
+   "built-in function %qE requires the "
+   "zve64x, zve64f, zve64d or v ISA extension",
+   exp);
+  return false;
+}
+
+  return true;
+}
+
 /* Expand a call to the RVV function with subcode CODE.  EXP is the call
expression and TARGET is the preferred location for the result.
Return the value of the lhs.  */
@@ -4649,6 +4697,9 @@ expand_builtin (unsigned int code, tree exp, rtx target)
   return target;
 }
 
+  if (!validate_instance_type_required_extensions (rfn.instance.type, exp))
+return target;
+
   return function_expander (rfn.instance, rfn.decl, exp, target).expand ();
 }
 
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/base/pr114988-1.c 
b/gcc/testsuite/gcc.target/riscv/rvv/base/pr114988-1.c
new file mode 100644
index ..b8474804c880
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/base/pr114988-1.c
@@ -0,0 +1,9 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv64gcv -mabi=lp64d -O3" } */
+
+#include "riscv_vector.h"
+
+vfloat32mf2_t test_vfwsub_wf_f32mf2(vfloat32mf2_t vs2, _Float16 rs1, size_t vl)
+{
+  return __riscv_vfwsub_wf_f32mf2(vs2, rs1, vl); /* { dg-error {built-in 
function '__riscv_vfwsub_wf_f32mf2\(vs2,  rs1,  vl\)' requires the zvfhmin or 
zvfh ISA extension} } */
+}
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/base/pr114988-2.c 
b/gcc/testsuite/gcc.target/riscv/rvv/base/

[gcc r14-10471] RISC-V: Add -X to link spec

2024-07-18 Thread Kito Cheng via Gcc-cvs
https://gcc.gnu.org/g:3a7e796b48b9d8e37ec142abd9c20b1847535f7e

commit r14-10471-g3a7e796b48b9d8e37ec142abd9c20b1847535f7e
Author: Fangrui Song 
Date:   Fri Apr 26 18:14:33 2024 -0700

RISC-V: Add -X to link spec

--discard-locals (-X) instructs the linker to remove local .L* symbols,
which occur a lot due to label differences for linker relaxation. The
arm port has a similar need and passes -X to ld.

In contrast, the RISC-V port does not pass -X to ld and rely on the
default --discard-locals in GNU ld's riscv port. The arm way is more
conventional (compiler driver instead of the linker customizes the
default linker behavior) and works with lld.

gcc/ChangeLog:

* config/riscv/elf.h (LINK_SPEC): Add -X.
* config/riscv/freebsd.h (LINK_SPEC): Add -X.
* config/riscv/linux.h (LINK_SPEC): Add -X.

(cherry picked from commit 50c218e3ffe57860591a987ecf44fcc0abb31f2c)

Diff:
---
 gcc/config/riscv/elf.h | 1 +
 gcc/config/riscv/freebsd.h | 1 +
 gcc/config/riscv/linux.h   | 1 +
 3 files changed, 3 insertions(+)

diff --git a/gcc/config/riscv/elf.h b/gcc/config/riscv/elf.h
index f533764d9f86..c97f13c0ccad 100644
--- a/gcc/config/riscv/elf.h
+++ b/gcc/config/riscv/elf.h
@@ -20,6 +20,7 @@ along with GCC; see the file COPYING3.  If not see
 #define LINK_SPEC "\
 -melf" XLEN_SPEC DEFAULT_ENDIAN_SPEC "riscv \
 %{mno-relax:--no-relax} \
+-X \
 %{mbig-endian:-EB} \
 %{mlittle-endian:-EL} \
 %{shared}"
diff --git a/gcc/config/riscv/freebsd.h b/gcc/config/riscv/freebsd.h
index bd08a9852850..5dd4d51c42bc 100644
--- a/gcc/config/riscv/freebsd.h
+++ b/gcc/config/riscv/freebsd.h
@@ -44,6 +44,7 @@ along with GCC; see the file COPYING3.  If not see
   %{p:%nconsider using `-pg' instead of `-p' with gprof (1)}   \
   %{v:-V}  \
   %{assert*} %{R*} %{rpath*} %{defsym*}\
+  -X   \
   %{mbig-endian:-EB}   \
   %{mlittle-endian:-EL}\
   %{shared:-Bshareable %{h*} %{soname*}}   \
diff --git a/gcc/config/riscv/linux.h b/gcc/config/riscv/linux.h
index 15851f653bc6..3c356227134d 100644
--- a/gcc/config/riscv/linux.h
+++ b/gcc/config/riscv/linux.h
@@ -50,6 +50,7 @@ along with GCC; see the file COPYING3.  If not see
 #define LINK_SPEC "\
 -melf" XLEN_SPEC DEFAULT_ENDIAN_SPEC "riscv" LD_EMUL_SUFFIX " \
 %{mno-relax:--no-relax} \
+-X \
 %{mbig-endian:-EB} \
 %{mlittle-endian:-EL} \
 %{shared} \


[gcc r15-2152] c++: Add [dcl.init.aggr] examples to testsuite

2024-07-18 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:cea6473e48b4cfbf16f7b4a804f1562f8da8f25b

commit r15-2152-gcea6473e48b4cfbf16f7b4a804f1562f8da8f25b
Author: Jakub Jelinek 
Date:   Fri Jul 19 08:53:47 2024 +0200

c++: Add [dcl.init.aggr] examples to testsuite

When working on the #embed optimization support, I went recently through
all of reshape_init_r* and today I read in detail all the P3106R1 changes
and I believe we implement it that way for years.
To double check that, I've added tests with the current [dcl.init.aggr]
examples but tested in all the languages from C++98 to C++26, of course
guarded as needed for constructs which require newer versions of C++.
The examples come in two tests, one is a runtime test for the non-erroneous
examples, the other is a compile time test for the diagnostics.
The former one includes mostly intact examples with runtime checking (both
to test what is written in the section exactly and to test at least
something with C++98) and then when useful also adds constexpr tests with
static_asserts for C++11 and later.

Tested on x86_64-linux and i686-linux with
GXX_TESTSUITE_STDS=98,11,14,17,20,23,26 make check-g++ 
RUNTESTFLAGS='dg.exp=aggr-init*.C'

Also tested on GCC 11 branch with
GXX_TESTSUITE_STDS=98,11,14,17,20,2b make check-g++ 
RUNTESTFLAGS='dg.exp=aggr-init*.C'
where just the " is a GCC extension" part of one error is left out,
otherwise it passes the same, ditto with clang 14 (of course with different
diagnostics, but verified it emits diagnostics on the right lines), so I
believe we can claim implementation of this DR paper, either in all versions
or at least in GCC 11+.

2024-07-19  Jakub Jelinek  

PR c++/114460
* g++.dg/cpp26/aggr-init1.C: New test.
* g++.dg/cpp26/aggr-init2.C: New test.

Diff:
---
 gcc/testsuite/g++.dg/cpp26/aggr-init1.C | 341 
 gcc/testsuite/g++.dg/cpp26/aggr-init2.C |  67 +++
 2 files changed, 408 insertions(+)

diff --git a/gcc/testsuite/g++.dg/cpp26/aggr-init1.C 
b/gcc/testsuite/g++.dg/cpp26/aggr-init1.C
new file mode 100644
index ..a692462caf69
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp26/aggr-init1.C
@@ -0,0 +1,341 @@
+// P3106R1 - Clarifying rules for brace elision in aggregate initialization
+// Examples from C++26 [dcl.init.aggr]
+// { dg-do run }
+
+extern "C" void abort ();
+
+namespace N1 {
+#if __cpp_designated_initializers >= 201707L
+  struct C {
+union {
+  int a;
+  const char* p;
+};
+int x;
+  } c = { .a = 1, .x = 3 };
+  constexpr C c2 = { .a = 1, .x = 3 };
+  static_assert (c2.a == 1 && c2.x == 3, "");
+#endif
+
+  bool
+  test ()
+  {
+#if __cpp_designated_initializers >= 201707L
+return c.a == 1 && c.x == 3;
+#else
+return true;
+#endif
+  }
+}
+
+namespace N2 {
+  struct A {
+int x;
+struct B {
+  int i;
+  int j;
+} b;
+  } a = { 1, { 2, 3 } };
+
+#if __cplusplus >= 201703L
+  struct base1 { int b1, b2 = 42; };
+  struct base2 {
+base2 () { b3 = 42; }
+int b3;
+  };
+  struct derived : base1, base2 {
+int d;
+  };
+
+  derived d1 { { 1, 2 }, {}, 4 };
+  derived d2 { {}, {}, 4 };
+#endif
+
+  bool
+  test ()
+  {
+return a.x == 1 && a.b.i == 2 && a.b.j == 3
+#if __cplusplus >= 201703L
+  && d1.b1 == 1 && d1.b2 == 2 && d1.b3 == 42 && d1.d == 4
+  && d2.b1 == 0 && d2.b2 == 42 && d2.b3 == 42 && d2.d == 4
+#endif
+  ;
+  }
+
+#if __cplusplus >= 201703L
+  constexpr A a2 = { 1, { 2, 3 } };
+  static_assert (a2.x == 1 && a2.b.i == 2 && a2.b.j == 3, "");
+
+  struct base3 {
+#if __cplusplus >= 202002L
+constexpr base3 () { b3 = 42; }
+#else
+constexpr base3 () : b3 (42) {}
+#endif
+int b3;
+  };
+  struct derived2 : base1, base3 {
+int d;
+  };
+  constexpr derived2 d3 { { 1, 2}, {}, 4};
+  constexpr derived2 d4 { {}, {}, 4 };
+  static_assert (d3.b1 == 1 && d3.b2 == 2 && d3.b3 == 42 && d3.d == 4, "");
+  static_assert (d4.b1 == 0 && d4.b2 == 42 && d4.b3 == 42 && d4.d == 4, "");
+#endif
+}
+
+namespace N3 {
+#if __cplusplus >= 201402L
+  struct S { int a; const char *b; int c; int d = b[a]; };
+  S ss = { 1, "asdf" };
+  constexpr S ss2 = { 1, "asdf" };
+  static_assert (ss2.a == 1 && ss2.b[0] == 'a' && ss2.b[3] == 'f' && ss2.c == 
0 && ss2.d == 's', "");
+
+#if __cpp_designated_initializers >= 201707L
+  struct string { int s = -42; };
+  struct A {
+string a;
+int b = 42;
+int c = -1;
+  };
+  static_assert (A { .c = 21 }.a.s == -42 && A { .c = 21 }.b == 42 && A { .c = 
21 }.c == 21, "");
+#endif
+#endif
+
+  bool
+  test ()
+  {
+#if __cplusplus >= 201402L
+return ss.a == 1 && __builtin_strcmp (ss.b, "asdf") == 0 && ss.c == 0 && 
ss.d == 's';
+#else
+return true;
+#endif
+  }
+}
+
+namespace N4 {
+  int x[] = { 1, 3, 5 };
+
+  bool
+  test ()
+  {
+return sizeof (x) == 3 * sizeof (int) && x[0] == 1 && x[1] == 3 && x[2] == 
5;
+  }