[gcc r15-1877] libstdc++: Remove redundant 17_intro/headers tests

2024-07-06 Thread Jonathan Wakely via Libstdc++-cvs
https://gcc.gnu.org/g:3fc913104d2a8000bba169049e0fc143640c7793

commit r15-1877-g3fc913104d2a8000bba169049e0fc143640c7793
Author: Jonathan Wakely 
Date:   Fri Jul 5 20:06:01 2024 +0100

libstdc++: Remove redundant 17_intro/headers tests

We have several nearly identical tests under 17_intro/headers which only
differ in a -std option set using dg-options. Since the testsuite now
supports running tests with multiple -std options (and I test that
regularly) we don't need these duplicated tests. We can remove most of
them and let the testsuite decide which -std option to use.

In the all_attributes.cc case the content of the tests is slightly
different, but they can be combined into one test that defines macros
conditionally based on __cplusplus checks.

The stdc++.cc tests could also be combined this way, but for now I've
just kept one version for c++98 and one for all later standards.

For stdc++_multiple_inclusion.cc we can remove the body of the files and
just include stdc++.cc twice. This means we don't need to add includes
to both stdc++.cc and stdc++_multiple_inclusion.cc, we only need to
update one place.

libstdc++-v3/ChangeLog:

* testsuite/17_intro/headers/c++1998/all_attributes.cc: Add
attribute names from later standards and remove dg-options.
* testsuite/17_intro/headers/c++1998/stdc++.cc: Add c++98_only
target selector.
* testsuite/17_intro/headers/c++1998/stdc++_multiple_inclusion.cc:
Remove content and include stdc++.cc twice instead.
* testsuite/17_intro/headers/c++2011/stdc++.cc: Replace
dg-options with c++11 target selector.
* testsuite/17_intro/headers/c++2011/stdc++_multiple_inclusion.cc:
Remove content and include stdc++.cc twice instead.
* testsuite/17_intro/headers/c++2011/all_attributes.cc: Removed.
* testsuite/17_intro/headers/c++2011/all_no_exceptions.cc: Removed.
* testsuite/17_intro/headers/c++2011/all_no_rtti.cc: Removed.
* testsuite/17_intro/headers/c++2011/all_pedantic_errors.cc: 
Removed.
* testsuite/17_intro/headers/c++2011/charset.cc: Removed.
* testsuite/17_intro/headers/c++2011/operator_names.cc: Removed.
* testsuite/17_intro/headers/c++2014/all_attributes.cc: Removed.
* testsuite/17_intro/headers/c++2014/all_no_exceptions.cc: Removed.
* testsuite/17_intro/headers/c++2014/all_no_rtti.cc: Removed.
* testsuite/17_intro/headers/c++2014/all_pedantic_errors.cc: 
Removed.
* testsuite/17_intro/headers/c++2014/charset.cc: Removed.
* testsuite/17_intro/headers/c++2014/operator_names.cc: Removed.
* testsuite/17_intro/headers/c++2014/stdc++.cc: Removed.
* testsuite/17_intro/headers/c++2014/stdc++_multiple_inclusion.cc: 
Removed.
* testsuite/17_intro/headers/c++2017/all_attributes.cc: Removed.
* testsuite/17_intro/headers/c++2017/all_no_exceptions.cc: Removed.
* testsuite/17_intro/headers/c++2017/all_no_rtti.cc: Removed.
* testsuite/17_intro/headers/c++2017/all_pedantic_errors.cc: 
Removed.
* testsuite/17_intro/headers/c++2017/charset.cc: Removed.
* testsuite/17_intro/headers/c++2017/operator_names.cc: Removed.
* testsuite/17_intro/headers/c++2017/stdc++.cc: Removed.
* testsuite/17_intro/headers/c++2017/stdc++_multiple_inclusion.cc: 
Removed.
* testsuite/17_intro/headers/c++2020/all_attributes.cc: Removed.
* testsuite/17_intro/headers/c++2020/all_no_exceptions.cc: Removed.
* testsuite/17_intro/headers/c++2020/all_no_rtti.cc: Removed.
* testsuite/17_intro/headers/c++2020/all_pedantic_errors.cc: 
Removed.
* testsuite/17_intro/headers/c++2020/charset.cc: Removed.
* testsuite/17_intro/headers/c++2020/operator_names.cc: Removed.
* testsuite/17_intro/headers/c++2020/stdc++.cc: Removed.
* testsuite/17_intro/headers/c++2020/stdc++_multiple_inclusion.cc: 
Removed.

Diff:
---
 .../17_intro/headers/c++1998/all_attributes.cc |  20 +++-
 .../testsuite/17_intro/headers/c++1998/stdc++.cc   |   2 +-
 .../headers/c++1998/stdc++_multiple_inclusion.cc   |  53 +-
 .../17_intro/headers/c++2011/all_attributes.cc |  44 
 .../17_intro/headers/c++2011/all_no_exceptions.cc  |  21 
 .../17_intro/headers/c++2011/all_no_rtti.cc|  21 
 .../headers/c++2011/all_pedantic_errors.cc |  21 
 .../testsuite/17_intro/headers/c++2011/charset.cc  |   5 -
 .../17_intro/headers/c++2011/operator_names.cc |  30 --
 .../testsuite/17_intro/headers/c++2011/stdc++.cc   |   5 +-
 .../headers/c++2011/stdc++_multiple_inclusion.cc   | 100 +-
 .../17_intro/headers/c++2014/all_attributes.cc |  44 --

[gcc r15-1876] libstdc++: Use reserved form of [[__likely__]] in

2024-07-06 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:9f1cd51766f251aafe0f1b898892f79855892729

commit r15-1876-g9f1cd51766f251aafe0f1b898892f79855892729
Author: Jonathan Wakely 
Date:   Fri Jul 5 20:00:04 2024 +0100

libstdc++: Use reserved form of [[__likely__]] in 

We should not use [[unlikely]] before C++20, so use [[__unlikely__]]
instead.

libstdc++-v3/ChangeLog:

* include/std/variant (_Variant_storage::_M_reset): Use
__unlikely__ form of attribute instead of unlikely.

Diff:
---
 libstdc++-v3/include/std/variant | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libstdc++-v3/include/std/variant b/libstdc++-v3/include/std/variant
index 13ea1dd3849..3a23d9bc66d 100644
--- a/libstdc++-v3/include/std/variant
+++ b/libstdc++-v3/include/std/variant
@@ -492,7 +492,7 @@ namespace __variant
   constexpr void
   _M_reset()
   {
-   if (!_M_valid()) [[unlikely]]
+   if (!_M_valid()) [[__unlikely__]]
  return;
 
std::__do_visit([](auto&& __this_mem) mutable


[gcc r15-1875] libstdc++: Restore support for including in extern "C" [PR115797]

2024-07-06 Thread Jonathan Wakely via Libstdc++-cvs
https://gcc.gnu.org/g:dcc735aaeae1cc985a143ade883db748fb10554d

commit r15-1875-gdcc735aaeae1cc985a143ade883db748fb10554d
Author: Jonathan Wakely 
Date:   Fri Jul 5 18:39:50 2024 +0100

libstdc++: Restore support for including  in extern "C" [PR115797]

The r15-1857 change means that  is included by  for
C++17 and up, which breaks code including  inside an extern "C"
block. Although doing that is not allowed by the C++ standard, there's
lots of existing code which incorrectly thinks it's a good idea and so
we try to support it.

libstdc++-v3/ChangeLog:

PR libstdc++/115797
* include/std/type_traits: Ensure "C++" language linkage.
* testsuite/17_intro/headers/c++2011/linkage.cc: Replace
dg-options with c++11 target selector.

Diff:
---
 libstdc++-v3/include/std/type_traits   | 3 +++
 libstdc++-v3/testsuite/17_intro/headers/c++2011/linkage.cc | 3 +--
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/libstdc++-v3/include/std/type_traits 
b/libstdc++-v3/include/std/type_traits
index a31de2ee4ab..c39a3792537 100644
--- a/libstdc++-v3/include/std/type_traits
+++ b/libstdc++-v3/include/std/type_traits
@@ -62,6 +62,8 @@
 #define __glibcxx_want_void_t
 #include 
 
+extern "C++"
+{
 namespace std _GLIBCXX_VISIBILITY(default)
 {
 _GLIBCXX_BEGIN_NAMESPACE_VERSION
@@ -4111,6 +4113,7 @@ template
 
 _GLIBCXX_END_NAMESPACE_VERSION
 } // namespace std
+} // extern "C++"
 
 #endif  // C++11
 
diff --git a/libstdc++-v3/testsuite/17_intro/headers/c++2011/linkage.cc 
b/libstdc++-v3/testsuite/17_intro/headers/c++2011/linkage.cc
index c43384efbaa..1825801cec9 100644
--- a/libstdc++-v3/testsuite/17_intro/headers/c++2011/linkage.cc
+++ b/libstdc++-v3/testsuite/17_intro/headers/c++2011/linkage.cc
@@ -15,8 +15,7 @@
 // with this library; see the file COPYING3.  If not see
 // .
 
-// { dg-options "-std=gnu++11" }
-// { dg-do compile }
+// { dg-do compile { target c++11 } }
 
 // libstdc++/69386


[gcc r15-1874] [to-be-committed][v3][RISC-V] Handle bit manipulation of SImode values

2024-07-06 Thread Jeff Law via Gcc-cvs
https://gcc.gnu.org/g:273f16a125c4fab664683376ae04a9a31e7d6a22

commit r15-1874-g273f16a125c4fab664683376ae04a9a31e7d6a22
Author: Jeff Law 
Date:   Sat Jul 6 12:57:59 2024 -0600

[to-be-committed][v3][RISC-V] Handle bit manipulation of SImode values

Last patch in this round of bitmanip work...  At least I think I'm going to
pause here and switch gears to other projects that need attention 🙂

This patch introduces the ability to generate bitmanip instructions for rv64
when operating on SI objects when we know something about the range of the 
bit
position (due to masking of the position).

I've got note that the (7-pos % 8) bit position form was discovered by RAU 
in
500.perl.  I took that and expanded it to the simple (pos & mask) form as 
well
as covering bset, binv and bclr.

As far as the implementation is concerned

This turns the recently added define_splits into define_insn_and_split
constructs.  This allows combine to "see" enough RTL to realize a sign
extension is unnecessary.  Otherwise we get undesirable sign extensions for 
the
new testcases.

Second it adds new patterns for the logical operations.  Two patterns for
IOR/XOR and two patterns for AND.

I think a key concept to keep in mind is that once we determine a Zbs 
operation
is safe to perform on a SI value, we can rewrite the RTL in 64bit form.  If 
we
were ever to try and use range information at expand time for this stuff 
(and
we probably should investigate that), that's the path I'd suggest.

This is notably cleaner than my original implementation which actually kept 
the
more complex RTL form through final and emitted 2/3 instructions (mask the 
bit
position, then the bset/bclr/binv).

Tested in my tester, but waiting for pre-commit CI to report back before 
taking
further action.

gcc/
* config/riscv/bitmanip.md (bset splitters): Turn into 
define_and_splits.
Don't depend on combine splitting the "andn with constant" form.
(bset, binv, bclr with masked bit position): New patterns.

gcc/testsuite
* gcc.target/riscv/binv-for-simode-1.c: New test.
* gcc.target/riscv/bset-for-simode-1.c: New test.
* gcc.target/riscv/bclr-for-simode-1.c: New test.

Diff:
---
 gcc/config/riscv/bitmanip.md   | 135 ++---
 gcc/testsuite/gcc.target/riscv/bclr-for-simode-1.c |  25 
 gcc/testsuite/gcc.target/riscv/binv-for-simode-1.c |  24 
 gcc/testsuite/gcc.target/riscv/bset-for-simode-1.c |  24 
 4 files changed, 192 insertions(+), 16 deletions(-)

diff --git a/gcc/config/riscv/bitmanip.md b/gcc/config/riscv/bitmanip.md
index 3eedabffca0..f403ba8dbba 100644
--- a/gcc/config/riscv/bitmanip.md
+++ b/gcc/config/riscv/bitmanip.md
@@ -615,37 +615,140 @@
 ;; shift constant.  With the limited range we know the SImode sign
 ;; bit is never set, thus we can treat this as zero extending and
 ;; generate the bsetdi_2 pattern.
-(define_split
-  [(set (match_operand:DI 0 "register_operand")
+(define_insn_and_split ""
+  [(set (match_operand:DI 0 "register_operand" "=r")
(any_extend:DI
 (ashift:SI (const_int 1)
(subreg:QI
- (and:DI (not:DI (match_operand:DI 1 "register_operand"))
+ (and:DI (not:DI (match_operand:DI 1 "register_operand" 
"r"))
  (match_operand 2 "const_int_operand")) 0
-   (clobber (match_operand:DI 3 "register_operand"))]
+   (clobber (match_scratch:X 3 "=&r"))]
   "TARGET_64BIT
&& TARGET_ZBS
&& (TARGET_ZBB || TARGET_ZBKB)
&& (INTVAL (operands[2]) & 0x1f) != 0x1f"
-   [(set (match_dup 0) (and:DI (not:DI (match_dup 1)) (match_dup 2)))
-(set (match_dup 0) (zero_extend:DI (ashift:SI
-  (const_int 1)
-  (subreg:QI (match_dup 0) 0])
+  "#"
+  "&& reload_completed"
+   [(set (match_dup 3) (match_dup 2))
+(set (match_dup 3) (and:DI (not:DI (match_dup 1)) (match_dup 3)))
+(set (match_dup 0) (zero_extend:DI
+(ashift:SI (const_int 1) (match_dup 4]
+  { operands[4] = gen_lowpart (QImode, operands[3]); }
+  [(set_attr "type" "bitmanip")])
 
-(define_split
-  [(set (match_operand:DI 0 "register_operand")
-   (any_extend:DI
+(define_insn_and_split ""
+  [(set (match_operand:DI 0 "register_operand" "=r")
+(any_extend:DI
 (ashift:SI (const_int 1)
(subreg:QI
- (and:DI (match_operand:DI 1 "register_operand")
+ (and:DI (match_operand:DI 1 "register_operand" "r")
  (match_operand 2 "const_int_operand")) 0]
   "TARGET_64BIT
&& TARGET_ZBS
&& (INTVAL (operands[2]) & 0x1f) != 0x1f"
-   [(set (match_dup 0) (and:DI (match_dup 1) (match_dup 2)))
-(set (match

[gcc(refs/users/mikael/heads/cleanup_trans_preloop_setup_v01)] fortran: Move definition of variable closer to its usages

2024-07-06 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:cfcb4489798cfb9715e8cf92bb8eadcfe35dfd21

commit cfcb4489798cfb9715e8cf92bb8eadcfe35dfd21
Author: Mikael Morin 
Date:   Mon Nov 20 10:16:31 2023 +0100

fortran: Move definition of variable closer to its usages

No change of behaviour, this makes a variable easier to track.

gcc/fortran/ChangeLog:

* trans-array.cc (gfc_trans_preloop_setup): Use a separate variable
for iteration.  Use directly the value of variable I if it is known.
Move the definition of the variable to the branch where the
remaining uses are.

Diff:
---
 gcc/fortran/trans-array.cc | 31 +--
 1 file changed, 17 insertions(+), 14 deletions(-)

diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc
index 510f429ef8e..c34c97257a9 100644
--- a/gcc/fortran/trans-array.cc
+++ b/gcc/fortran/trans-array.cc
@@ -4294,7 +4294,6 @@ gfc_trans_preloop_setup (gfc_loopinfo * loop, int dim, 
int flag,
   gfc_ss *ss, *pss;
   gfc_loopinfo *ploop;
   gfc_array_ref *ar;
-  int i;
 
   /* This code will be executed before entering the scalarization loop
  for this dimension.  */
@@ -4340,19 +4339,10 @@ gfc_trans_preloop_setup (gfc_loopinfo * loop, int dim, 
int flag,
  pss = ss;
}
 
-  if (dim == loop->dimen - 1)
-   i = 0;
-  else
-   i = dim + 1;
-
-  /* For the time being, there is no loop reordering.  */
-  gcc_assert (i == ploop->order[i]);
-  i = ploop->order[i];
-
   if (dim == loop->dimen - 1 && loop->parent == NULL)
{
  stride = gfc_conv_array_stride (info->descriptor,
- innermost_ss (ss)->dim[i]);
+ innermost_ss (ss)->dim[0]);
 
  /* Calculate the stride of the innermost loop.  Hopefully this will
 allow the backend optimizers to do their stuff more effectively.
@@ -4364,7 +4354,7 @@ gfc_trans_preloop_setup (gfc_loopinfo * loop, int dim, 
int flag,
 base offset of the array.  */
  if (info->ref)
{
- for (i = 0; i < ar->dimen; i++)
+ for (int i = 0; i < ar->dimen; i++)
{
  if (ar->dimen_type[i] != DIMEN_ELEMENT)
continue;
@@ -4374,8 +4364,21 @@ gfc_trans_preloop_setup (gfc_loopinfo * loop, int dim, 
int flag,
}
}
   else
-   /* Add the offset for the previous loop dimension.  */
-   add_array_offset (pblock, ploop, ss, ar, pss->dim[i], i);
+   {
+ int i;
+
+ if (dim == loop->dimen - 1)
+   i = 0;
+ else
+   i = dim + 1;
+
+ /* For the time being, there is no loop reordering.  */
+ gcc_assert (i == ploop->order[i]);
+ i = ploop->order[i];
+
+ /* Add the offset for the previous loop dimension.  */
+ add_array_offset (pblock, ploop, ss, ar, pss->dim[i], i);
+   }
 
   /* Remember this offset for the second loop.  */
   if (dim == loop->temp_dim - 1 && loop->parent == NULL)


[gcc] Created branch 'mikael/heads/cleanup_trans_preloop_setup_v01' in namespace 'refs/users'

2024-07-06 Thread Mikael Morin via Gcc-cvs
The branch 'mikael/heads/cleanup_trans_preloop_setup_v01' was created in 
namespace 'refs/users' pointing to:

 cfcb4489798... fortran: Move definition of variable closer to its usages


[gcc(refs/users/mikael/heads/cleanup_advance_se_ss_chain_v01)] fortran: Remove useless nested end of scalarization chain handling

2024-07-06 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:c633926356155181081154c094010d672e715a4e

commit c633926356155181081154c094010d672e715a4e
Author: Mikael Morin 
Date:   Mon Nov 20 16:15:45 2023 +0100

fortran: Remove useless nested end of scalarization chain handling

Remove the special handling of end of nested scalarization chains, which
advanced the chain to an element of a parent chain when the current one
was reaching its end.

That handling was superfluous as nested chains correspond to nested
scalarizations of subexpressions and the scalarizations don't extend beyond
their associated subexpression and don't use any scalarisation element from
the parent expression.

No change in behaviour, as the GFC_SE struct is supposed to be at its final
state anyway when the last element from the chain has been consumed.

gcc/fortran/ChangeLog:

* trans-expr.cc (gfc_advance_se_ss_chain): Don't use an element
from the parent scalarization chain when the current chain reaches
its end.

Diff:
---
 gcc/fortran/trans-expr.cc | 11 +--
 1 file changed, 1 insertion(+), 10 deletions(-)

diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc
index 477c2720187..f0862db5f17 100644
--- a/gcc/fortran/trans-expr.cc
+++ b/gcc/fortran/trans-expr.cc
@@ -2052,7 +2052,6 @@ void
 gfc_advance_se_ss_chain (gfc_se * se)
 {
   gfc_se *p;
-  gfc_ss *ss;
 
   gcc_assert (se != NULL && se->ss != NULL && se->ss != gfc_ss_terminator);
 
@@ -2064,15 +2063,7 @@ gfc_advance_se_ss_chain (gfc_se * se)
   gcc_assert (p->parent == NULL || p->parent->ss == p->ss
  || p->parent->ss->nested_ss == p->ss);
 
-  /* If we were in a nested loop, the next scalarized expression can be
-on the parent ss' next pointer.  Thus we should not take the next
-pointer blindly, but rather go up one nest level as long as next
-is the end of chain.  */
-  ss = p->ss;
-  while (ss->next == gfc_ss_terminator && ss->parent != NULL)
-   ss = ss->parent;
-
-  p->ss = ss->next;
+  p->ss = p->ss->next;
 
   p = p->parent;
 }


[gcc] Created branch 'mikael/heads/cleanup_advance_se_ss_chain_v01' in namespace 'refs/users'

2024-07-06 Thread Mikael Morin via Gcc-cvs
The branch 'mikael/heads/cleanup_advance_se_ss_chain_v01' was created in 
namespace 'refs/users' pointing to:

 c6339263561... fortran: Remove useless nested end of scalarization chain h


[gcc r14-10385] RISC-V: fix internal error on global variable-length array

2024-07-06 Thread Eric Botcazou via Gcc-cvs
https://gcc.gnu.org/g:6c5ef4944e3858e7daf1ef75a3afa93a3ece37c5

commit r14-10385-g6c5ef4944e3858e7daf1ef75a3afa93a3ece37c5
Author: Eric Botcazou 
Date:   Sat Jul 6 11:56:19 2024 +0200

RISC-V: fix internal error on global variable-length array

This is an ICE in the RISC-V back-end calling tree_to_uhwi on the DECL_SIZE
of a global variable-length array.

gcc/
PR target/115591
* config/riscv/riscv.cc (riscv_valid_lo_sum_p): Add missing test on
tree_fits_uhwi_p before calling tree_to_uhwi.

gcc/testsuite/
* gnat.dg/array41.ads, gnat.dg/array41.adb: New test.

Diff:
---
 gcc/config/riscv/riscv.cc |  4 +++-
 gcc/testsuite/gnat.dg/array41.adb | 37 +
 gcc/testsuite/gnat.dg/array41.ads |  5 +
 3 files changed, 45 insertions(+), 1 deletion(-)

diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc
index 0f62b295b96..6fcb6fb4ad3 100644
--- a/gcc/config/riscv/riscv.cc
+++ b/gcc/config/riscv/riscv.cc
@@ -1397,7 +1397,9 @@ riscv_valid_lo_sum_p (enum riscv_symbol_type sym_type, 
machine_mode mode,
   align = (SYMBOL_REF_DECL (x)
   ? DECL_ALIGN (SYMBOL_REF_DECL (x))
   : 1);
-  size = (SYMBOL_REF_DECL (x) && DECL_SIZE (SYMBOL_REF_DECL (x))
+  size = (SYMBOL_REF_DECL (x)
+ && DECL_SIZE (SYMBOL_REF_DECL (x))
+ && tree_fits_uhwi_p (DECL_SIZE (SYMBOL_REF_DECL (x)))
  ? tree_to_uhwi (DECL_SIZE (SYMBOL_REF_DECL (x)))
  : 2*BITS_PER_WORD);
 }
diff --git a/gcc/testsuite/gnat.dg/array41.adb 
b/gcc/testsuite/gnat.dg/array41.adb
new file mode 100644
index 000..d0d5a69eeaf
--- /dev/null
+++ b/gcc/testsuite/gnat.dg/array41.adb
@@ -0,0 +1,37 @@
+-- { dg-do compile }
+
+with System.Storage_Elements;
+
+package body Array41 is
+
+   procedure Program_Initialization
+   with
+ Export,
+ Convention => Ada,
+ External_Name => "program_initialization";
+
+   procedure Program_Initialization is
+  use System.Storage_Elements;
+
+  Sdata : Storage_Element
+with Import, Convention => Asm, External_Name => "_sdata";
+  Edata : Storage_Element
+with Import, Convention => Asm, External_Name => "_edata";
+
+  Data_Size : constant Storage_Offset := Edata'Address - Sdata'Address;
+
+  --  Index from 1 so as to avoid subtracting 1 from the size
+  Data_In_Flash : constant Storage_Array (1 .. Data_Size)
+with Import, Convention => Asm, External_Name => "_sidata";
+
+  Data_In_Sram : Storage_Array (1 .. Data_Size)
+with Volatile, Import, Convention => Asm, External_Name => "_sdata";
+
+   begin
+  --  Copy rw data from flash to ram
+  for J in Data_In_Flash'Range loop
+ Data_In_Sram (J) := Data_In_Flash (J);
+  end loop;
+   end Program_Initialization;
+
+end Array41;
diff --git a/gcc/testsuite/gnat.dg/array41.ads 
b/gcc/testsuite/gnat.dg/array41.ads
new file mode 100644
index 000..50cde3cd819
--- /dev/null
+++ b/gcc/testsuite/gnat.dg/array41.ads
@@ -0,0 +1,5 @@
+package Array41 is
+
+  pragma Elaborate_Body;
+
+end Array41;


[gcc r15-1873] testsuite/52641 - Fix more sloppy tests.

2024-07-06 Thread Georg-Johann Lay via Gcc-cvs
https://gcc.gnu.org/g:bb16e3179e79e4307f1d834a02e63d0dfd817f67

commit r15-1873-gbb16e3179e79e4307f1d834a02e63d0dfd817f67
Author: Georg-Johann Lay 
Date:   Sat Jul 6 15:02:28 2024 +0200

testsuite/52641 - Fix more sloppy tests.

PR testsuite/52641
gcc/testsuite/
* gcc.dg/analyzer/torture/boxed-ptr-1.c: Requires size24plus.
* gcc.dg/analyzer/torture/pr102692.c: Use intptr_t instead of long.
* gcc.dg/ipa/pr102714.c: Use uintptr_t instead of unsigned long.
* gcc.dg/torture/pr115387-1.c: Same.
* gcc.dg/torture/pr113895-1.c : Same.
* gcc.dg/ipa/pr108007.c: Require int32plus.
* gcc.dg/ipa/pr109318.c: Same.
* gcc.dg/ipa/pr96040.c: Use size_t instead of unsigned long.
* gcc.dg/torture/pr113126.c: Use vectors of same dimension.
* gcc.dg/tree-ssa/builtin-sprintf-9.c: Requires double64.

* gcc.dg/spellcheck-inttypes.c [avr]: Avoid include of inttypes.h.
* gcc.dg/analyzer/torture/pr104159.c [avr]: Skip.
* gcc.dg/torture/pr84682-2.c [avr]: Skip.
* gcc.dg/wtr-conversion-1.c [avr]: Remove avr selector since
long double is a 64-bit type by now.

Diff:
---
 gcc/testsuite/gcc.dg/analyzer/torture/boxed-ptr-1.c | 1 +
 gcc/testsuite/gcc.dg/analyzer/torture/pr102692.c| 2 +-
 gcc/testsuite/gcc.dg/analyzer/torture/pr104159.c| 1 +
 gcc/testsuite/gcc.dg/ipa/pr102714.c | 6 +++---
 gcc/testsuite/gcc.dg/ipa/pr108007.c | 1 +
 gcc/testsuite/gcc.dg/ipa/pr109318.c | 1 +
 gcc/testsuite/gcc.dg/ipa/pr96040.c  | 4 ++--
 gcc/testsuite/gcc.dg/spellcheck-inttypes.c  | 7 +++
 gcc/testsuite/gcc.dg/torture/pr113126.c | 4 ++--
 gcc/testsuite/gcc.dg/torture/pr113895-1.c   | 1 +
 gcc/testsuite/gcc.dg/torture/pr115387-1.c   | 2 +-
 gcc/testsuite/gcc.dg/torture/pr84682-2.c| 1 +
 gcc/testsuite/gcc.dg/tree-ssa/builtin-sprintf-9.c   | 1 +
 gcc/testsuite/gcc.dg/wtr-conversion-1.c | 4 ++--
 14 files changed, 25 insertions(+), 11 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/analyzer/torture/boxed-ptr-1.c 
b/gcc/testsuite/gcc.dg/analyzer/torture/boxed-ptr-1.c
index 5bc7151a798..e25d0c31ea5 100644
--- a/gcc/testsuite/gcc.dg/analyzer/torture/boxed-ptr-1.c
+++ b/gcc/testsuite/gcc.dg/analyzer/torture/boxed-ptr-1.c
@@ -1,4 +1,5 @@
 /* { dg-skip-if "" { *-*-* } { "-fno-fat-lto-objects" } { "" } } */
+/* { dg-require-effective-target size24plus } */
 
 #include 
 #include "../analyzer-decls.h"
diff --git a/gcc/testsuite/gcc.dg/analyzer/torture/pr102692.c 
b/gcc/testsuite/gcc.dg/analyzer/torture/pr102692.c
index a6c6bc47896..a1b3bfed047 100644
--- a/gcc/testsuite/gcc.dg/analyzer/torture/pr102692.c
+++ b/gcc/testsuite/gcc.dg/analyzer/torture/pr102692.c
@@ -15,7 +15,7 @@ make_lisp_ptr (void *ptr, int type)
 static _Bool
 TAGGEDP (struct lisp *a, unsigned tag)
 {
-  return ! (((unsigned) (long) a - tag) & 7);
+  return ! (((unsigned) (__INTPTR_TYPE__) a - tag) & 7);
 }
 
 static _Bool
diff --git a/gcc/testsuite/gcc.dg/analyzer/torture/pr104159.c 
b/gcc/testsuite/gcc.dg/analyzer/torture/pr104159.c
index ad85d084b39..0c490bd39f2 100644
--- a/gcc/testsuite/gcc.dg/analyzer/torture/pr104159.c
+++ b/gcc/testsuite/gcc.dg/analyzer/torture/pr104159.c
@@ -1,4 +1,5 @@
 /* { dg-additional-options "-Wno-analyzer-use-of-uninitialized-value 
-Wno-psabi" } */
+/* { dg-skip-if "incompatible types" { "avr-*-*" } } */
 
 typedef int __attribute__((__vector_size__(4))) T;
 typedef unsigned __attribute__((__vector_size__(4))) U;
diff --git a/gcc/testsuite/gcc.dg/ipa/pr102714.c 
b/gcc/testsuite/gcc.dg/ipa/pr102714.c
index 65dd86f5c15..8ab77a61d75 100644
--- a/gcc/testsuite/gcc.dg/ipa/pr102714.c
+++ b/gcc/testsuite/gcc.dg/ipa/pr102714.c
@@ -54,16 +54,16 @@ static inline __attribute__((__gnu_inline__)) 
__attribute__((__unused__)) __attr
 
 static inline __attribute__((__gnu_inline__)) __attribute__((__unused__)) 
__attribute__((no_instrument_function)) struct xa_node *entry_to_node(void *ptr)
 {
- return (void *)((unsigned long)ptr & ~2UL);
+ return (void *)((__UINTPTR_TYPE__)ptr & ~(__UINTPTR_TYPE__)2);
 }
 
 static inline __attribute__((__gnu_inline__)) __attribute__((__unused__)) 
__attribute__((no_instrument_function)) bool radix_tree_is_internal_node(void 
*ptr)
 {
- return ((unsigned long)ptr & 3UL) ==
+ return ((__UINTPTR_TYPE__)ptr & 3UL) ==
 2UL;
 }
 
-static inline __attribute__((__gnu_inline__)) __attribute__((__unused__)) 
__attribute__((no_instrument_function)) void *xa_mk_internal(unsigned long v)
+static inline __attribute__((__gnu_inline__)) __attribute__((__unused__)) 
__attribute__((no_instrument_function)) void *xa_mk_internal(__UINTPTR_TYPE__ v)
 {
  return (void *)((v << 2) | 2);
 }
diff --git a/gcc/testsuite/gcc.dg/ipa/pr108007.c 
b/gcc/testsuite/gcc.dg/ipa/pr108007.c
index 77fc95975cf..5bd1c350963 100644
--- a/gcc/testsuite/gc

[gcc r15-1872] [committed] Fix various sh define_insn_and_split predicates

2024-07-06 Thread Jeff Law via Gcc-cvs
https://gcc.gnu.org/g:cb9badea8be5396afe90f4c497e9f333cce1cb3f

commit r15-1872-gcb9badea8be5396afe90f4c497e9f333cce1cb3f
Author: Jeff Law 
Date:   Sat Jul 6 06:35:54 2024 -0600

[committed] Fix various sh define_insn_and_split predicates

The sh4-linux-gnu port has failed to bootstrap since the introduction of 
late
combine due to failures to split certain insns.

This is caused by incorrect predicates in various define_insn_and_split
patterns.  Essentially the insn's predicate is something like "TARGET_SH1".
The split predicate is "&& can_create_pseudos_p ()".  So these patterns will
match post-reload, but be un-splittable.  So at assembly output time, we get
the failure as the output template is "#".

This patch fixes the most obvious & egregious cases by bringing the split
condition into the insn's predicate and leaving "&& 1" as the split 
condition.
That's enough to get sh4-linux-gnu bootstrapping again and I'm hoping it 
does
the same for sh4eb-linux-gnu.

Pushing to the trunk.

gcc/
* config/sh/sh.md (adddi3): Only allow matching when we can
still create new pseudos.
(subdi3, *rotcl, *rotcr, *rotcr_neg_t, negdi2): Likewise.
(abs2, negabs2, negdi_cond): Likewise.
(*swapbisi2_and_shl8, *swapbhisi2, *movsi_index_disp_load): 
Likewise.
(*movhi_index_disp_load, *movindex_disp_store): Likewise.
(*mov_t_msb_neg, *negt_msb, clipu_one): Likewise.

Diff:
---
 gcc/config/sh/sh.md | 100 ++--
 1 file changed, 50 insertions(+), 50 deletions(-)

diff --git a/gcc/config/sh/sh.md b/gcc/config/sh/sh.md
index 9491b49e55b..3e978254ab0 100644
--- a/gcc/config/sh/sh.md
+++ b/gcc/config/sh/sh.md
@@ -1542,9 +1542,9 @@
(plus:DI (match_operand:DI 1 "arith_reg_operand")
 (match_operand:DI 2 "arith_reg_operand")))
(clobber (reg:SI T_REG))]
-  "TARGET_SH1"
+  "TARGET_SH1 && can_create_pseudo_p ()"
   "#"
-  "&& can_create_pseudo_p ()"
+  "&& 1"
   [(const_int 0)]
 {
   emit_insn (gen_clrt ());
@@ -1934,9 +1934,9 @@
(minus:DI (match_operand:DI 1 "arith_reg_operand")
  (match_operand:DI 2 "arith_reg_operand")))
(clobber (reg:SI T_REG))]
-  "TARGET_SH1"
+  "TARGET_SH1 && can_create_pseudo_p ()"
   "#"
-  "&& can_create_pseudo_p ()"
+  "&& 1"
   [(const_int 0)]
 {
   emit_insn (gen_clrt ());
@@ -3174,9 +3174,9 @@
(and:SI (match_operand:SI 3 "arith_reg_or_t_reg_operand")
(const_int 1
(clobber (reg:SI T_REG))]
-  "TARGET_SH1"
+  "TARGET_SH1 && can_create_pseudo_p ()"
   "#"
-  "&& can_create_pseudo_p ()"
+  "&& 1"
   [(const_int 0)]
 {
   gcc_assert (INTVAL (operands[2]) > 0);
@@ -3259,9 +3259,9 @@
   (match_operand:SI 2 "const_int_operand"))
(match_operand 3 "treg_set_expr")))
(clobber (reg:SI T_REG))]
-  "TARGET_SH1"
+  "TARGET_SH1 && can_create_pseudo_p ()"
   "#"
-  "&& can_create_pseudo_p ()"
+  "&& 1"
   [(parallel [(set (match_dup 0)
   (ior:SI (ashift:SI (match_dup 1) (match_dup 2))
   (and:SI (match_dup 3) (const_int 1
@@ -3278,9 +3278,9 @@
(ashift:SI (match_operand:SI 2 "arith_reg_operand")
   (match_operand:SI 3 "const_int_operand"
(clobber (reg:SI T_REG))]
-  "TARGET_SH1"
+  "TARGET_SH1 && can_create_pseudo_p ()"
   "#"
-  "&& can_create_pseudo_p ()"
+  "&& 1"
   [(parallel [(set (match_dup 0)
   (ior:SI (ashift:SI (match_dup 2) (match_dup 3))
   (and:SI (match_dup 1) (const_int 1
@@ -3293,9 +3293,9 @@
(lshiftrt:SI (match_operand:SI 3 "arith_reg_operand")
 (const_int 31
(clobber (reg:SI T_REG))]
-  "TARGET_SH1"
+  "TARGET_SH1 && can_create_pseudo_p ()"
   "#"
-  "&& can_create_pseudo_p ()"
+  "&& 1"
   [(parallel [(set (match_dup 0)
   (ior:SI (ashift:SI (match_dup 1) (match_dup 2))
   (and:SI (reg:SI T_REG) (const_int 1
@@ -3312,9 +3312,9 @@
(ashift:SI (match_operand:SI 1 "arith_reg_operand")
   (match_operand:SI 2 "const_int_operand"
(clobber (reg:SI T_REG))]
-  "TARGET_SH1"
+  "TARGET_SH1 && can_create_pseudo_p ()"
   "#"
-  "&& can_create_pseudo_p ()"
+  "&& 1"
   [(parallel [(set (match_dup 0)
   (ior:SI (ashift:SI (match_dup 1) (match_dup 2))
   (and:SI (reg:SI T_REG) (const_int 1
@@ -3332,9 +3332,9 @@
 (const_int 1)
 (match_operand 4 "const_int_operand"
(clobber (reg:SI T_REG))]
-  "TARGET_SH1"
+  "TARGET_SH1 && can_create_pseudo_p ()"
   "#"
-  "&& can_create_pseudo_p ()"
+  "&& 1"
   [(parallel [(set (match_dup 0)
   (ior:SI (ashift:SI (match_dup 1) (match_du

[gcc r15-1871] AVR: Create more opportunities for -mfuse-add optimization.

2024-07-06 Thread Georg-Johann Lay via Gcc-cvs
https://gcc.gnu.org/g:96559be74bfa355507472fc020c95c14587c227f

commit r15-1871-g96559be74bfa355507472fc020c95c14587c227f
Author: Georg-Johann Lay 
Date:   Fri Jul 5 23:49:43 2024 +0200

AVR: Create more opportunities for -mfuse-add optimization.

avr_split_tiny_move() was only run for AVR_TINY because it has no PLUS
addressing modes.  Same applies to the X register on ordinary cores, and
also to the Z register when used with [E]LPM.  For example, without this 
patch

long long addLL (long long *a, long long *b)
{
  return *a + *b;
}

compiles with "-mmcu=atmgea128 -Os -dp" to:

...
movw r26,r24 ;  80  [c=4 l=1]  *movhi/0
movw r30,r22 ;  81  [c=4 l=1]  *movhi/0
ld r18,X ;  82  [c=4 l=1]  movqi_insn/3
adiw r26,1   ;  83  [c=4 l=3]  movqi_insn/3
ld r19,X
sbiw r26,1
adiw r26,2   ;  84  [c=4 l=3]  movqi_insn/3
ld r20,X
sbiw r26,2
adiw r26,3   ;  85  [c=4 l=3]  movqi_insn/3
ld r21,X
sbiw r26,3
adiw r26,4   ;  86  [c=4 l=3]  movqi_insn/3
ld r22,X
sbiw r26,4
adiw r26,5   ;  87  [c=4 l=3]  movqi_insn/3
ld r23,X
sbiw r26,5
adiw r26,6   ;  88  [c=4 l=3]  movqi_insn/3
ld r24,X
sbiw r26,6
adiw r26,7   ;  89  [c=4 l=2]  movqi_insn/3
ld r25,X
ld r10,Z ;  90  [c=4 l=1]  movqi_insn/3
...

whereas with this patch it becomes:

...
movw r26,r24 ;  80  [c=4 l=1]  *movhi/0
movw r30,r22 ;  81  [c=4 l=1]  *movhi/0
ld r18,X+;  140 [c=4 l=1]  movqi_insn/3
ld r19,X+;  142 [c=4 l=1]  movqi_insn/3
ld r20,X+;  144 [c=4 l=1]  movqi_insn/3
ld r21,X+;  146 [c=4 l=1]  movqi_insn/3
ld r22,X+;  148 [c=4 l=1]  movqi_insn/3
ld r23,X+;  150 [c=4 l=1]  movqi_insn/3
ld r24,X+;  152 [c=4 l=1]  movqi_insn/3
ld r25,X ;  109 [c=4 l=1]  movqi_insn/3
ld r10,Z ;  111 [c=4 l=1]  movqi_insn/3
...

gcc/
* config/avr/avr.md: Also split with avr_split_tiny_move()
for non-AVR_TINY.
* config/avr/avr.cc (avr_split_tiny_move): Don't change memory
references with base regs that can do PLUS addressing.
(avr_out_lpm_no_lpmx) [POST_INC]: Don't output final ADIW when the
address register is unused after.
gcc/testsuite/
* gcc.target/avr/torture/fuse-add.c: New test.

Diff:
---
 gcc/config/avr/avr.cc   | 39 
 gcc/config/avr/avr.md   |  3 +-
 gcc/testsuite/gcc.target/avr/torture/fuse-add.c | 59 +
 3 files changed, 80 insertions(+), 21 deletions(-)

diff --git a/gcc/config/avr/avr.cc b/gcc/config/avr/avr.cc
index f048bf5fd41..d299fceb782 100644
--- a/gcc/config/avr/avr.cc
+++ b/gcc/config/avr/avr.cc
@@ -4471,28 +4471,21 @@ avr_out_lpm_no_lpmx (rtx_insn *insn, rtx *xop, int 
*plen)
   gcc_assert (REG_Z == REGNO (XEXP (addr, 0))
  && n_bytes <= 4);
 
-  if (regno_dest == LPM_REGNO)
-   avr_asm_len ("%4lpm"  CR_TAB
-"adiw %2,1", xop, plen, 2);
-  else
-   avr_asm_len ("%4lpm"  CR_TAB
-"mov %A0,%3" CR_TAB
-"adiw %2,1", xop, plen, 3);
+  for (int i = 0; i < n_bytes; ++i)
+   {
+ rtx reg = simplify_gen_subreg (QImode, dest, GET_MODE (dest), i);
 
-  if (n_bytes >= 2)
-   avr_asm_len ("%4lpm"  CR_TAB
-"mov %B0,%3" CR_TAB
-"adiw %2,1", xop, plen, 3);
+ if (i > 0)
+   avr_asm_len ("adiw %2,1", xop, plen, 1);
 
-  if (n_bytes >= 3)
-   avr_asm_len ("%4lpm"  CR_TAB
-"mov %C0,%3" CR_TAB
-"adiw %2,1", xop, plen, 3);
+ avr_asm_len ("%4lpm", xop, plen, 1);
 
-  if (n_bytes >= 4)
-   avr_asm_len ("%4lpm"  CR_TAB
-"mov %D0,%3" CR_TAB
-"adiw %2,1", xop, plen, 3);
+ if (REGNO (reg) != LPM_REGNO)
+   avr_asm_len ("mov %0,r0", ®, plen, 1);
+   }
+
+  if (! _reg_unused_after (insn, xop[2], false))
+   avr_asm_len ("adiw %2,1", xop, plen, 1);
 
   break; /* POST_INC */
 
@@ -6685,6 +6678,14 @@ avr_split_tiny_move (rtx_insn * /*insn*/, rtx *xop)
   if (REGNO (base) > REG_Z)
 return false;
 
+  if (! AVR_TINY
+  // Only keep base registers that can't do PLUS addressing.
+  && ((REGNO (base) != REG_X
+  && ADDR_SPACE_GENERIC_P (MEM_ADDR_SPACE (mem)))
+ || avr_load_libgcc_p (mem)
+ || avr_mem_memx_p (mem)))
+return false;
+
   bool volatile_p = MEM_VOLATILE_P (mem);
   bool mem_volatile_p = false;
   if (frame_pointer_needed
diff --git a/gcc/config/avr/avr.md b/gcc/config/avr/avr.

[gcc r15-1870] RISC-V: fix internal error on global variable-length array

2024-07-06 Thread Eric Botcazou via Gcc-cvs
https://gcc.gnu.org/g:8bc5561c43b195e1638e5acace8b41b3f7512be3

commit r15-1870-g8bc5561c43b195e1638e5acace8b41b3f7512be3
Author: Eric Botcazou 
Date:   Sat Jul 6 11:56:19 2024 +0200

RISC-V: fix internal error on global variable-length array

This is an ICE in the RISC-V back-end calling tree_to_uhwi on the DECL_SIZE
of a global variable-length array.

gcc/
PR target/115591
* config/riscv/riscv.cc (riscv_valid_lo_sum_p): Add missing test on
tree_fits_uhwi_p before calling tree_to_uhwi.

gcc/testsuite/
* gnat.dg/array41.ads, gnat.dg/array41.adb: New test.

Diff:
---
 gcc/config/riscv/riscv.cc |  4 +++-
 gcc/testsuite/gnat.dg/array41.adb | 37 +
 gcc/testsuite/gnat.dg/array41.ads |  5 +
 3 files changed, 45 insertions(+), 1 deletion(-)

diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc
index 9bba5da016e..38ed773c222 100644
--- a/gcc/config/riscv/riscv.cc
+++ b/gcc/config/riscv/riscv.cc
@@ -1702,7 +1702,9 @@ riscv_valid_lo_sum_p (enum riscv_symbol_type sym_type, 
machine_mode mode,
   align = (SYMBOL_REF_DECL (x)
   ? DECL_ALIGN (SYMBOL_REF_DECL (x))
   : 1);
-  size = (SYMBOL_REF_DECL (x) && DECL_SIZE (SYMBOL_REF_DECL (x))
+  size = (SYMBOL_REF_DECL (x)
+ && DECL_SIZE (SYMBOL_REF_DECL (x))
+ && tree_fits_uhwi_p (DECL_SIZE (SYMBOL_REF_DECL (x)))
  ? tree_to_uhwi (DECL_SIZE (SYMBOL_REF_DECL (x)))
  : 2*BITS_PER_WORD);
 }
diff --git a/gcc/testsuite/gnat.dg/array41.adb 
b/gcc/testsuite/gnat.dg/array41.adb
new file mode 100644
index 000..d0d5a69eeaf
--- /dev/null
+++ b/gcc/testsuite/gnat.dg/array41.adb
@@ -0,0 +1,37 @@
+-- { dg-do compile }
+
+with System.Storage_Elements;
+
+package body Array41 is
+
+   procedure Program_Initialization
+   with
+ Export,
+ Convention => Ada,
+ External_Name => "program_initialization";
+
+   procedure Program_Initialization is
+  use System.Storage_Elements;
+
+  Sdata : Storage_Element
+with Import, Convention => Asm, External_Name => "_sdata";
+  Edata : Storage_Element
+with Import, Convention => Asm, External_Name => "_edata";
+
+  Data_Size : constant Storage_Offset := Edata'Address - Sdata'Address;
+
+  --  Index from 1 so as to avoid subtracting 1 from the size
+  Data_In_Flash : constant Storage_Array (1 .. Data_Size)
+with Import, Convention => Asm, External_Name => "_sidata";
+
+  Data_In_Sram : Storage_Array (1 .. Data_Size)
+with Volatile, Import, Convention => Asm, External_Name => "_sdata";
+
+   begin
+  --  Copy rw data from flash to ram
+  for J in Data_In_Flash'Range loop
+ Data_In_Sram (J) := Data_In_Flash (J);
+  end loop;
+   end Program_Initialization;
+
+end Array41;
diff --git a/gcc/testsuite/gnat.dg/array41.ads 
b/gcc/testsuite/gnat.dg/array41.ads
new file mode 100644
index 000..50cde3cd819
--- /dev/null
+++ b/gcc/testsuite/gnat.dg/array41.ads
@@ -0,0 +1,5 @@
+package Array41 is
+
+  pragma Elaborate_Body;
+
+end Array41;