[gcc r15-5637] ipa: Move individual jump function copying to a separate function

2024-11-24 Thread Martin Jambor via Gcc-cvs
https://gcc.gnu.org/g:cc5779fcaf76aeee005f986eb1dc15205c696544

commit r15-5637-gcc5779fcaf76aeee005f986eb1dc15205c696544
Author: Martin Jambor 
Date:   Sun Nov 24 23:03:43 2024 +0100

ipa: Move individual jump function copying to a separate function

When reviewing various IPA bits and pieces I have falsely assumed
that jump function duplication misses copying important bits because
it relies on vec_safe_copy-ing all data in the vector of jump
functions and then just fixes up the few fields it needs to.

Perhaps more importantly, we do want a function to copy one individual
jump function to form jump functions for planned call-graph edges that
model transfer of control to OpenMP outlined regions through calls to
gomp functions.

Therefore, this patch introduces such function and makes
ipa_edge_args_sum_t::duplicate just allocate the new vectors and then
uses the new function to copy the data.

gcc/ChangeLog:

2024-11-01  Martin Jambor  

* ipa-prop.cc (ipa_duplicate_jump_function): New function.
(ipa_edge_args_sum_t::duplicate): Move individual jump function
copying to ipa_duplicate_jump_function.

Diff:
---
 gcc/ipa-prop.cc | 188 +---
 1 file changed, 111 insertions(+), 77 deletions(-)

diff --git a/gcc/ipa-prop.cc b/gcc/ipa-prop.cc
index cbc825670fe0..9070a45f6835 100644
--- a/gcc/ipa-prop.cc
+++ b/gcc/ipa-prop.cc
@@ -4503,99 +4503,96 @@ ipa_edge_args_sum_t::remove (cgraph_edge *cs, 
ipa_edge_args *args)
 }
 }
 
-/* Method invoked when an edge is duplicated.  Copy ipa_edge_args and adjust
-   reference count data strucutres accordingly.  */
+/* Copy information from SRC_JF to DST_JF which correstpond to call graph edges
+   SRC and DST.  */
 
-void
-ipa_edge_args_sum_t::duplicate (cgraph_edge *src, cgraph_edge *dst,
-   ipa_edge_args *old_args, ipa_edge_args 
*new_args)
+static void
+ipa_duplicate_jump_function (cgraph_edge *src, cgraph_edge *dst,
+ipa_jump_func *src_jf, ipa_jump_func *dst_jf)
 {
-  unsigned int i;
+  dst_jf->agg.items = vec_safe_copy (src_jf->agg.items);
+  dst_jf->agg.by_ref = src_jf->agg.by_ref;
 
-  new_args->jump_functions = vec_safe_copy (old_args->jump_functions);
-  if (old_args->polymorphic_call_contexts)
-new_args->polymorphic_call_contexts
-  = vec_safe_copy (old_args->polymorphic_call_contexts);
+  /* We can avoid calling ipa_set_jfunc_vr since it would only look up the
+ place in the hash_table where the source m_vr resides.  */
+  dst_jf->m_vr = src_jf->m_vr;
 
-  for (i = 0; i < vec_safe_length (old_args->jump_functions); i++)
+  if (src_jf->type == IPA_JF_CONST)
 {
-  struct ipa_jump_func *src_jf = ipa_get_ith_jump_func (old_args, i);
-  struct ipa_jump_func *dst_jf = ipa_get_ith_jump_func (new_args, i);
-
-  dst_jf->agg.items = vec_safe_copy (dst_jf->agg.items);
+  ipa_set_jf_cst_copy (dst_jf, src_jf);
+  struct ipa_cst_ref_desc *src_rdesc = jfunc_rdesc_usable (src_jf);
 
-  if (src_jf->type == IPA_JF_CONST)
+  if (!src_rdesc)
+   dst_jf->value.constant.rdesc = NULL;
+  else if (src->caller == dst->caller)
{
- struct ipa_cst_ref_desc *src_rdesc = jfunc_rdesc_usable (src_jf);
-
- if (!src_rdesc)
-   dst_jf->value.constant.rdesc = NULL;
- else if (src->caller == dst->caller)
-   {
- /* Creation of a speculative edge.  If the source edge is the one
-grabbing a reference, we must create a new (duplicate)
-reference description.  Otherwise they refer to the same
-description corresponding to a reference taken in a function
-src->caller is inlined to.  In that case we just must
-increment the refcount.  */
- if (src_rdesc->cs == src)
-   {
-  symtab_node *n = symtab_node_for_jfunc (src_jf);
-  gcc_checking_assert (n);
-  ipa_ref *ref
-= src->caller->find_reference (n, src->call_stmt,
-   src->lto_stmt_uid,
-   IPA_REF_ADDR);
-  gcc_checking_assert (ref);
-  dst->caller->clone_reference (ref, ref->stmt);
-
-  ipa_cst_ref_desc *dst_rdesc = ipa_refdesc_pool.allocate ();
-  dst_rdesc->cs = dst;
-  dst_rdesc->refcount = src_rdesc->refcount;
-  dst_rdesc->next_duplicate = NULL;
-  dst_jf->value.constant.rdesc = dst_rdesc;
-   }
- else
-   {
- src_rdesc->refcount++;
- dst_jf->value.constant.rdesc = src_rdesc;
-   }
-   }
- else if (src_rdesc->cs == src)
+ /* Creation of a sp

[gcc r13-9212] Fortran: Fix segfault in allocation of unlimited poly array [PR84869]

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

commit r13-9212-ge78a0cb8604cd3e0fdbc606ed5e7094b646ded02
Author: Paul Thomas 
Date:   Sun Nov 24 14:22:06 2024 +

Fortran: Fix segfault in allocation of unlimited poly array [PR84869]

2024-11-24  Paul Thomas  

gcc/fortran/ChangeLog

PR fortran/84869
* trans-expr.cc (trans_class_vptr_len_assignment): To access
the '_len' field, 're' must be unlimited polymorphic.

gcc/testsuite/
PR fortran/84869
* gfortran.dg/pr84869.f90: Comment out test of component refs.

(cherry picked from commit 911a870a6198a2fe50af8bbeb63de1dfaa90de0e)

Diff:
---
 gcc/fortran/trans-expr.cc |  2 +-
 gcc/testsuite/gfortran.dg/pr84869.f90 | 25 +
 2 files changed, 26 insertions(+), 1 deletion(-)

diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc
index 59a7ff8d8d06..df109bd40547 100644
--- a/gcc/fortran/trans-expr.cc
+++ b/gcc/fortran/trans-expr.cc
@@ -9856,7 +9856,7 @@ trans_class_vptr_len_assignment (stmtblock_t *block, 
gfc_expr * le,
  vptr_expr = NULL;
  se.expr = gfc_class_vptr_get (GFC_DECL_SAVED_DESCRIPTOR (
 re->symtree->n.sym->backend_decl));
- if (to_len)
+ if (to_len && UNLIMITED_POLY (re))
from_len = gfc_class_len_get (GFC_DECL_SAVED_DESCRIPTOR (
 re->symtree->n.sym->backend_decl));
}
diff --git a/gcc/testsuite/gfortran.dg/pr84869.f90 
b/gcc/testsuite/gfortran.dg/pr84869.f90
new file mode 100644
index ..fe40b6208047
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr84869.f90
@@ -0,0 +1,25 @@
+! { dg-do compile }
+!
+! Test the fix for PR84869, where line 19 segfaulted.
+!
+! Contributed by Gerhard Steinmetz  
+!
+program p
+   type t
+ integer :: i
+   end type
+   call s
+contains
+   function f()
+  class(t), allocatable :: f(:)
+  f = [(t(i), i = 1, 10)]
+   end
+   subroutine s
+  class(*), allocatable :: z(:)
+  allocate (z, source = f ()) ! Segfault in gfc_class_len_get.
+  select type (z)
+type is (t)
+  if (any (z%i /= [(i, i = 1,10)])) stop 1
+  end select
+   end
+end


[gcc r15-5639] Fix uninitialized operands[2] in vec_unpacks_hi_v4sf.

2024-11-24 Thread hongtao Liu via Gcc-cvs
https://gcc.gnu.org/g:ba4cf2e296d8d5950c3d356fa6b6efcad00d0189

commit r15-5639-gba4cf2e296d8d5950c3d356fa6b6efcad00d0189
Author: liuhongt 
Date:   Thu Nov 21 23:57:38 2024 -0800

Fix uninitialized operands[2] in vec_unpacks_hi_v4sf.

It could cause weired spill in RA when register pressure is high.

gcc/ChangeLog:

PR target/117562
* config/i386/sse.md (vec_unpacks_hi_v4sf): Initialize
operands[2] with CONST0_RTX.

Diff:
---
 gcc/config/i386/sse.md | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/gcc/config/i386/sse.md b/gcc/config/i386/sse.md
index 72acd5bde5e4..498a42d6e1e8 100644
--- a/gcc/config/i386/sse.md
+++ b/gcc/config/i386/sse.md
@@ -10424,7 +10424,10 @@
(match_dup 2)
(parallel [(const_int 0) (const_int 1)]]
   "TARGET_SSE2"
-  "operands[2] = gen_reg_rtx (V4SFmode);")
+{
+  operands[2] = gen_reg_rtx (V4SFmode);
+  emit_move_insn (operands[2], CONST0_RTX (V4SFmode));
+})
 
 (define_expand "vec_unpacks_hi_v8sf"
   [(set (match_dup 2)


[gcc r15-5640] Add target-independent store forwarding avoidance pass

2024-11-24 Thread Philipp Tomsich via Gcc-cvs
https://gcc.gnu.org/g:1d8de1e93ea00f7797f61cf8e05c47ca86f21f8c

commit r15-5640-g1d8de1e93ea00f7797f61cf8e05c47ca86f21f8c
Author: Konstantinos Eleftheriou 
Date:   Wed Oct 16 10:31:39 2024 +0200

Add target-independent store forwarding avoidance pass

This pass detects cases of expensive store forwarding and tries to
avoid them by reordering the stores and using suitable bit insertion
sequences.  For example it can transform this:

 strbw2, [x1, 1]
 ldr x0, [x1]  # Expensive store forwarding to larger load.

To:

 ldr x0, [x1]
 strbw2, [x1]
 bfi x0, x2, 0, 8

Assembly like this can appear with bitfields or type punning / unions.
On stress-ng when running the cpu-union microbenchmark the following
speedups have been observed.

  Neoverse-N1:  +29.4%
  Intel Coffeelake: +13.1%
  AMD 5950X:+17.5%

The transformation is rejected on cases that cause store_bit_field to
generate subreg expressions on different register classes.  Files
avoid-store-forwarding-4.c and avoid-store-forwarding-5.c contain such
cases and have been marked as XFAIL.

Due to biasing of its operands in store_bit_field, there is a special
handling for machines with BITS_BIG_ENDIAN != BYTES_BIG_ENDIAN. The
need for this was exosed by an issue exposed on the H8 architecture,
which uses big-endian ordering, but BITS_BIG_ENDIAN is false. In that
case, the START parameter of store_bit_field needs to be calculated
from the end of the destination register.

gcc/ChangeLog:

* Makefile.in (OBJS): Add avoid-store-forwarding.o.
* common.opt (favoid-store-forwarding): New option.
* common.opt.urls: Regenerate.
* doc/invoke.texi: New param store-forwarding-max-distance.
* doc/passes.texi: Document new pass.
* doc/tm.texi: Regenerate.
* doc/tm.texi.in: Document new pass.
* params.opt (store-forwarding-max-distance): New param.
* passes.def: Add pass_rtl_avoid_store_forwarding before
pass_early_remat.
* target.def (avoid_store_forwarding_p): New DEFHOOK.
* target.h (struct store_fwd_info): Declare.
* targhooks.cc (default_avoid_store_forwarding_p): New function.
* targhooks.h (default_avoid_store_forwarding_p): Declare.
* tree-pass.h (make_pass_rtl_avoid_store_forwarding): Declare.
* avoid-store-forwarding.cc: New file.
* avoid-store-forwarding.h: New file.
* timevar.def (TV_AVOID_STORE_FORWARDING): New timevar.

gcc/testsuite/ChangeLog:

* gcc.target/aarch64/avoid-store-forwarding-1.c: New test.
* gcc.target/aarch64/avoid-store-forwarding-2.c: New test.
* gcc.target/aarch64/avoid-store-forwarding-3.c: New test.
* gcc.target/aarch64/avoid-store-forwarding-4.c: New test.
* gcc.target/aarch64/avoid-store-forwarding-5.c: New test.
* gcc.target/x86_64/abi/callabi/avoid-store-forwarding-1.c: New 
test.
* gcc.target/x86_64/abi/callabi/avoid-store-forwarding-2.c: New 
test.

Co-authored-by: Philipp Tomsich 
Signed-off-by: Philipp Tomsich 
Signed-off-by: Konstantinos Eleftheriou 

Diff:
---
 gcc/Makefile.in|   1 +
 gcc/avoid-store-forwarding.cc  | 651 +
 gcc/avoid-store-forwarding.h   |  56 ++
 gcc/common.opt |   4 +
 gcc/common.opt.urls|   3 +
 gcc/doc/invoke.texi|   9 +
 gcc/doc/passes.texi|   8 +
 gcc/doc/tm.texi|   8 +
 gcc/doc/tm.texi.in |   2 +
 gcc/params.opt |   4 +
 gcc/passes.def |   1 +
 gcc/target.def |  10 +
 gcc/target.h   |   3 +
 gcc/targhooks.cc   |  27 +
 gcc/targhooks.h|   3 +
 .../gcc.target/aarch64/avoid-store-forwarding-1.c  |  27 +
 .../gcc.target/aarch64/avoid-store-forwarding-2.c  |  39 ++
 .../gcc.target/aarch64/avoid-store-forwarding-3.c  |  30 +
 .../gcc.target/aarch64/avoid-store-forwarding-4.c  |  26 +
 .../gcc.target/aarch64/avoid-store-forwarding-5.c  |  41 ++
 .../x86_64/abi/callabi/avoid-store-forwarding-1.c  |  28 +
 .../x86_64/abi/callabi/avoid-store-forwarding-2.c  |  39 ++
 gcc/timevar.def|   1 +
 gcc/tree-pass.h|   1 +
 24 files changed, 1022 insertions(+)

diff --git a/gcc/Makefile.in b/gcc/Makefile.in
index 0cbb3633e01e..ead8d2eb094c

[gcc r15-5641] pa: Remove pa_section_type_flags

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

commit r15-5641-ge1ac811d5a724e6714465ad951703d334248bc83
Author: Xi Ruoyao 
Date:   Sat Nov 2 20:20:32 2024 +0800

pa: Remove pa_section_type_flags

It's no longer needed since r15-4842 (when the target-independent code
started to handle the case).

gcc/ChangeLog:

* config/pa/pa.cc (pa_section_type_flags): Remove.
(TARGET_SECTION_TYPE_FLAGS): Remove.

Diff:
---
 gcc/config/pa/pa.cc | 22 --
 1 file changed, 22 deletions(-)

diff --git a/gcc/config/pa/pa.cc b/gcc/config/pa/pa.cc
index 941ef3a71287..776cb1ffa24a 100644
--- a/gcc/config/pa/pa.cc
+++ b/gcc/config/pa/pa.cc
@@ -198,7 +198,6 @@ static machine_mode pa_c_mode_for_floating_type (enum 
tree_index);
 static section *pa_function_section (tree, enum node_frequency, bool, bool);
 static bool pa_cannot_force_const_mem (machine_mode, rtx);
 static bool pa_legitimate_constant_p (machine_mode, rtx);
-static unsigned int pa_section_type_flags (tree, const char *, int);
 static bool pa_legitimate_address_p (machine_mode, rtx, bool,
 code_helper = ERROR_MARK);
 static bool pa_callee_copies (cumulative_args_t, const function_arg_info &);
@@ -407,8 +406,6 @@ static size_t n_deferred_plabels = 0;
 
 #undef TARGET_LEGITIMATE_CONSTANT_P
 #define TARGET_LEGITIMATE_CONSTANT_P pa_legitimate_constant_p
-#undef TARGET_SECTION_TYPE_FLAGS
-#define TARGET_SECTION_TYPE_FLAGS pa_section_type_flags
 #undef TARGET_LEGITIMATE_ADDRESS_P
 #define TARGET_LEGITIMATE_ADDRESS_P pa_legitimate_address_p
 
@@ -10900,25 +10897,6 @@ pa_legitimate_constant_p (machine_mode mode, rtx x)
   return true;
 }
 
-/* Implement TARGET_SECTION_TYPE_FLAGS.  */
-
-static unsigned int
-pa_section_type_flags (tree decl, const char *name, int reloc)
-{
-  unsigned int flags;
-
-  flags = default_section_type_flags (decl, name, reloc);
-
-  /* Function labels are placed in the constant pool.  This can
- cause a section conflict if decls are put in ".data.rel.ro"
- or ".data.rel.ro.local" using the __attribute__ construct.  */
-  if (strcmp (name, ".data.rel.ro") == 0
-  || strcmp (name, ".data.rel.ro.local") == 0)
-flags |= SECTION_WRITE | SECTION_RELRO;
-
-  return flags;
-}
-
 /* pa_legitimate_address_p recognizes an RTL expression that is a
valid memory address for an instruction.  The MODE argument is the
machine mode for the MEM expression that wants to use this address.


[gcc r15-5642] i386/testsuite: Do not append AVX10.2 option for check_effective_target

2024-11-24 Thread Haochen Jiang via Gcc-cvs
https://gcc.gnu.org/g:832e963a477268e023b0fae4e8c59d29be8e7f42

commit r15-5642-g832e963a477268e023b0fae4e8c59d29be8e7f42
Author: Haochen Jiang 
Date:   Fri Nov 22 14:32:16 2024 +0800

i386/testsuite: Do not append AVX10.2 option for check_effective_target

When -avx10.2 meet -march with AVX512 enabled, it will report warning
for vector size conflict. The warning will prevent the test to run on
GCC with arch native build on those platforms when
check_effective_target.

Remove AVX10.2 options since we are using inline asm ad it actually do
not need options. It will eliminate the warning.

gcc/testsuite/ChangeLog:

* lib/target-supports.exp (check_effective_target_avx10_2):
Remove AVX10.2 option.
(check_effective_target_avx10_2_512): Ditto.

Diff:
---
 gcc/testsuite/lib/target-supports.exp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/gcc/testsuite/lib/target-supports.exp 
b/gcc/testsuite/lib/target-supports.exp
index 187a7e2992c3..b8ac76d1702f 100644
--- a/gcc/testsuite/lib/target-supports.exp
+++ b/gcc/testsuite/lib/target-supports.exp
@@ -10808,7 +10808,7 @@ proc check_effective_target_avx10_2 { } {
  __asm__ volatile ("vcvtph2ibs\t%ymm5, %ymm6");
  __asm__ volatile ("vminmaxpd\t$123, %ymm4, %ymm5, %ymm6");
}
-} "-mavx10.2" ]
+} "" ]
 }
 
 # Return 1 if avx10.2-512 instructions can be compiled.
@@ -10823,7 +10823,7 @@ proc check_effective_target_avx10_2_512 { } {
  __asm__ volatile ("vcvtph2ibs\t%zmm5, %zmm6");
  __asm__ volatile ("vminmaxpd\t$123, %zmm4, %zmm5, %zmm6");
}
-} "-mavx10.2-512" ]
+} "" ]
 }
 
 # Return 1 if amx-avx512 instructions can be compiled.


[gcc r15-5633] gimplefe: Fix handling of ')'/'}' after a parse error [PR117741]

2024-11-24 Thread Andrew Pinski via Gcc-cvs
https://gcc.gnu.org/g:e9f3eb8493c66da143561d6b866c4b3204e42574

commit r15-5633-ge9f3eb8493c66da143561d6b866c4b3204e42574
Author: Andrew Pinski 
Date:   Sat Nov 23 13:42:47 2024 -0800

gimplefe: Fix handling of ')'/'}' after a parse error [PR117741]

The problem here is c_parser_skip_until_found stops at a closing nesting
delimiter without consuming it. So if we don't consume it in
c_parser_gimple_compound_statement, we would go into an infinite loop. The C
parser similar code in c_parser_statement_after_labels to handle this 
specific
case too.

PR c/117741

gcc/c/ChangeLog:

* gimple-parser.cc (c_parser_gimple_compound_statement): Handle
CPP_CLOSE_PAREN/CPP_CLOSE_SQUARE with an error and skipping the 
token.

gcc/testsuite/ChangeLog:

* gcc.dg/gimplefe-54.c: New test.

Signed-off-by: Andrew Pinski 

Diff:
---
 gcc/c/gimple-parser.cc | 10 ++
 gcc/testsuite/gcc.dg/gimplefe-54.c | 10 ++
 2 files changed, 20 insertions(+)

diff --git a/gcc/c/gimple-parser.cc b/gcc/c/gimple-parser.cc
index 81f3921c8760..4763cf23313b 100644
--- a/gcc/c/gimple-parser.cc
+++ b/gcc/c/gimple-parser.cc
@@ -664,6 +664,16 @@ c_parser_gimple_compound_statement (gimple_parser &parser, 
gimple_seq *seq)
break;
  }
 
+   case CPP_CLOSE_PAREN:
+   case CPP_CLOSE_SQUARE:
+ /* Avoid infinite loop in error recovery:
+c_parser_skip_until_found stops at a closing nesting
+delimiter without consuming it, but here we need to consume
+it to proceed further.  */
+ c_parser_error (parser, "expected statement");
+ c_parser_consume_token (parser);
+   break;
+
default:
 expr_stmt:
  c_parser_gimple_statement (parser, seq);
diff --git a/gcc/testsuite/gcc.dg/gimplefe-54.c 
b/gcc/testsuite/gcc.dg/gimplefe-54.c
new file mode 100644
index ..71a49ac39c28
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/gimplefe-54.c
@@ -0,0 +1,10 @@
+/* { dg-do compile } */
+/* { dg-options "-fgimple" } */
+
+/* PR c/117741 */
+/* Make sure after a parsing error we
+   don't go into an infinite loop. */
+
+int i;
+void __GIMPLE foo() {
+  i = ) /* { dg-error "" } */


[gcc r15-5634] opt.url: Regenerate the .opt.urls files

2024-11-24 Thread Andrew Pinski via Gcc-cvs
https://gcc.gnu.org/g:cc0f32274deccfbbf2a6dab5ae77e49ce6aeb66d

commit r15-5634-gcc0f32274deccfbbf2a6dab5ae77e49ce6aeb66d
Author: Andrew Pinski 
Date:   Sun Nov 24 11:58:54 2024 -0800

opt.url: Regenerate the .opt.urls files

Just regenerated them after the addition of msplit-bit-shift avr option.

Pushed as obvious.

gcc/ChangeLog:

* config/avr/avr.opt.urls: Regenerate.
* config/g.opt.urls: Regenerate.
* config/i386/nto.opt.urls: Regenerate.
* config/riscv/riscv.opt.urls: Regenerate.
* config/rx/rx.opt.urls: Regenerate.
* config/sol2.opt.urls: Regenerate.

Signed-off-by: Andrew Pinski 

Diff:
---
 gcc/config/avr/avr.opt.urls | 3 +++
 gcc/config/g.opt.urls   | 2 +-
 gcc/config/i386/nto.opt.urls| 2 +-
 gcc/config/riscv/riscv.opt.urls | 2 +-
 gcc/config/rx/rx.opt.urls   | 2 +-
 gcc/config/sol2.opt.urls| 2 +-
 6 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/gcc/config/avr/avr.opt.urls b/gcc/config/avr/avr.opt.urls
index 672821db79d5..63d5a694937e 100644
--- a/gcc/config/avr/avr.opt.urls
+++ b/gcc/config/avr/avr.opt.urls
@@ -44,6 +44,9 @@ UrlSuffix(gcc/AVR-Options.html#index-mrelax)
 maccumulate-args
 UrlSuffix(gcc/AVR-Options.html#index-maccumulate-args)
 
+msplit-bit-shift
+UrlSuffix(gcc/AVR-Options.html#index-msplit-bit-shift)
+
 mstrict-X
 UrlSuffix(gcc/AVR-Options.html#index-mstrict-X)
 
diff --git a/gcc/config/g.opt.urls b/gcc/config/g.opt.urls
index 4ffd5cbd2cf5..10ab02a6d631 100644
--- a/gcc/config/g.opt.urls
+++ b/gcc/config/g.opt.urls
@@ -1,5 +1,5 @@
 ; Autogenerated by regenerate-opt-urls.py from gcc/config/g.opt and generated 
HTML
 
 G
-UrlSuffix(gcc/System-V-Options.html#index-G-5)
+UrlSuffix(gcc/System-V-Options.html#index-G-6)
 
diff --git a/gcc/config/i386/nto.opt.urls b/gcc/config/i386/nto.opt.urls
index 37c07a5b88be..055e669d54b2 100644
--- a/gcc/config/i386/nto.opt.urls
+++ b/gcc/config/i386/nto.opt.urls
@@ -1,5 +1,5 @@
 ; Autogenerated by regenerate-opt-urls.py from gcc/config/i386/nto.opt and 
generated HTML
 
 G
-UrlSuffix(gcc/System-V-Options.html#index-G-5)
+UrlSuffix(gcc/System-V-Options.html#index-G-6)
 
diff --git a/gcc/config/riscv/riscv.opt.urls b/gcc/config/riscv/riscv.opt.urls
index 622cb6e7b444..294d6628e866 100644
--- a/gcc/config/riscv/riscv.opt.urls
+++ b/gcc/config/riscv/riscv.opt.urls
@@ -33,7 +33,7 @@ mcpu=
 UrlSuffix(gcc/RISC-V-Options.html#index-mcpu-8)
 
 msmall-data-limit=
-UrlSuffix(gcc/RISC-V-Options.html#index-msmall-data-limit-1)
+UrlSuffix(gcc/RISC-V-Options.html#index-msmall-data-limit)
 
 msave-restore
 UrlSuffix(gcc/RISC-V-Options.html#index-msave-restore)
diff --git a/gcc/config/rx/rx.opt.urls b/gcc/config/rx/rx.opt.urls
index 7af4bd249d82..62e2a23cba60 100644
--- a/gcc/config/rx/rx.opt.urls
+++ b/gcc/config/rx/rx.opt.urls
@@ -22,7 +22,7 @@ mlittle-endian-data
 UrlSuffix(gcc/RX-Options.html#index-mlittle-endian-data)
 
 msmall-data-limit=
-UrlSuffix(gcc/RX-Options.html#index-msmall-data-limit-2)
+UrlSuffix(gcc/RX-Options.html#index-msmall-data-limit-1)
 
 mrelax
 UrlSuffix(gcc/RX-Options.html#index-mrelax-7)
diff --git a/gcc/config/sol2.opt.urls b/gcc/config/sol2.opt.urls
index ef64d47d65ee..950bb860719a 100644
--- a/gcc/config/sol2.opt.urls
+++ b/gcc/config/sol2.opt.urls
@@ -1,7 +1,7 @@
 ; Autogenerated by regenerate-opt-urls.py from gcc/config/sol2.opt and 
generated HTML
 
 G
-UrlSuffix(gcc/System-V-Options.html#index-G-5)
+UrlSuffix(gcc/System-V-Options.html#index-G-6)
 
 mclear-hwcap
 UrlSuffix(gcc/Solaris-2-Options.html#index-mclear-hwcap)


[gcc r15-5635] i386: x86 can use x >> -y for x >> 32-y [PR36503]

2024-11-24 Thread Uros Bizjak via Gcc-cvs
https://gcc.gnu.org/g:1ff69000b50e8ac184e925af71e794e7c3d5d2a6

commit r15-5635-g1ff69000b50e8ac184e925af71e794e7c3d5d2a6
Author: Uros Bizjak 
Date:   Sun Nov 24 22:00:18 2024 +0100

i386: x86 can use x >> -y for x >> 32-y [PR36503]

x86 targets mask 32-bit shifts with a 5-bit mask (and 64-bit with 6-bit 
mask),
so they can use x >> -y instead of x >> 32-y.  This form is very common in
bitstream readers, where it's used to read the top N bits from a word.

The optimization converts:

movl$32, %ecx
subl%esi, %ecx
sall%cl, %eax

to:

negl%ecx
sall%cl, %eax

PR target/36503

gcc/ChangeLog:

* config/i386/i386.md (*ashl3_negcnt):
New define_insn_and_split pattern.
(*ashl3_negcnt_1): Ditto.
(*3_negcnt): Ditto.
(*3_negcnt_1): Ditto.

gcc/testsuite/ChangeLog:

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

Diff:
---
 gcc/config/i386/i386.md   | 112 ++
 gcc/testsuite/gcc.target/i386/pr36503-1.c |  20 ++
 gcc/testsuite/gcc.target/i386/pr36503-2.c |  19 +
 3 files changed, 151 insertions(+)

diff --git a/gcc/config/i386/i386.md b/gcc/config/i386/i386.md
index 1c1bf659fc25..399a6a81f9ca 100644
--- a/gcc/config/i386/i386.md
+++ b/gcc/config/i386/i386.md
@@ -15896,6 +15896,62 @@
   ""
   [(set_attr "isa" "*,bmi2")])
 
+(define_insn_and_split "*ashl3_negcnt"
+  [(set (match_operand:SWI48 0 "nonimmediate_operand")
+   (ashift:SWI48
+ (match_operand:SWI48 1 "nonimmediate_operand")
+ (subreg:QI
+   (minus
+ (match_operand 3 "const_int_operand")
+ (match_operand 2 "int248_register_operand" "c,r")) 0)))
+   (clobber (reg:CC FLAGS_REG))]
+  "ix86_binary_operator_ok (ASHIFT, mode, operands)
+   && INTVAL (operands[3]) ==  * BITS_PER_UNIT
+   && ix86_pre_reload_split ()"
+  "#"
+  "&& 1"
+  [(parallel
+ [(set (match_dup 4)
+  (neg:QI (match_dup 2)))
+  (clobber (reg:CC FLAGS_REG))])
+   (parallel
+ [(set (match_dup 0)
+  (ashift:SWI48 (match_dup 1)
+(match_dup 4)))
+  (clobber (reg:CC FLAGS_REG))])]
+{
+  operands[2] = force_reg (GET_MODE (operands[2]), operands[2]);
+  operands[2] = gen_lowpart (QImode, operands[2]);
+
+  operands[4] = gen_reg_rtx (QImode);
+}
+  [(set_attr "isa" "*,bmi2")])
+
+(define_insn_and_split "*ashl3_negcnt_1"
+  [(set (match_operand:SWI48 0 "nonimmediate_operand")
+   (ashift:SWI48
+ (match_operand:SWI48 1 "nonimmediate_operand")
+ (minus:QI
+   (match_operand:QI 3 "const_int_operand")
+   (match_operand:QI 2 "register_operand" "c,r"
+   (clobber (reg:CC FLAGS_REG))]
+  "ix86_binary_operator_ok (ASHIFT, mode, operands)
+   && INTVAL (operands[3]) ==  * BITS_PER_UNIT
+   && ix86_pre_reload_split ()"
+  "#"
+  "&& 1"
+  [(parallel
+ [(set (match_dup 4)
+  (neg:QI (match_dup 2)))
+  (clobber (reg:CC FLAGS_REG))])
+   (parallel
+ [(set (match_dup 0)
+  (ashift:SWI48 (match_dup 1)
+(match_dup 4)))
+  (clobber (reg:CC FLAGS_REG))])]
+  "operands[4] = gen_reg_rtx (QImode);"
+  [(set_attr "isa" "*,bmi2")])
+
 (define_insn "*bmi2_ashl3_1"
   [(set (match_operand:SWI48 0 "register_operand" "=r")
(ashift:SWI48 (match_operand:SWI48 1 "nonimmediate_operand" "rm")
@@ -16622,6 +16678,62 @@
   ""
   [(set_attr "isa" "*,bmi2")])
 
+(define_insn_and_split "*3_negcnt"
+  [(set (match_operand:SWI48 0 "nonimmediate_operand")
+   (any_shiftrt:SWI48
+ (match_operand:SWI48 1 "nonimmediate_operand")
+ (subreg:QI
+   (minus
+ (match_operand 3 "const_int_operand")
+ (match_operand 2 "int248_register_operand" "c,r")) 0)))
+   (clobber (reg:CC FLAGS_REG))]
+  "ix86_binary_operator_ok (, mode, operands)
+   && INTVAL (operands[3]) ==  * BITS_PER_UNIT
+   && ix86_pre_reload_split ()"
+  "#"
+  "&& 1"
+  [(parallel
+ [(set (match_dup 4)
+  (neg:QI (match_dup 2)))
+  (clobber (reg:CC FLAGS_REG))])
+   (parallel
+ [(set (match_dup 0)
+  (any_shiftrt:SWI48 (match_dup 1)
+ (match_dup 4)))
+  (clobber (reg:CC FLAGS_REG))])]
+{
+  operands[2] = force_reg (GET_MODE (operands[2]), operands[2]);
+  operands[2] = gen_lowpart (QImode, operands[2]);
+
+  operands[4] = gen_reg_rtx (QImode);
+}
+  [(set_attr "isa" "*,bmi2")])
+
+(define_insn_and_split "*3_negcnt_1"
+  [(set (match_operand:SWI48 0 "nonimmediate_operand")
+   (any_shiftrt:SWI48
+ (match_operand:SWI48 1 "nonimmediate_operand")
+ (minus:QI
+   (match_operand:QI 3 "const_int_operand")
+   (match_operand:QI 2 "register_operand" "c,r"
+   (clobber (reg:CC FLAGS_REG))]
+  "ix86_binary_operator_ok (, m

[gcc r15-5636] testsuite/x86: Add -mfpmath=sse to add_options_for_float16

2024-11-24 Thread Uros Bizjak via Gcc-cvs
https://gcc.gnu.org/g:04f0652c91435987e137a85013a601b8b51d5662

commit r15-5636-g04f0652c91435987e137a85013a601b8b51d5662
Author: Uros Bizjak 
Date:   Sun Nov 24 22:18:31 2024 +0100

testsuite/x86: Add -mfpmath=sse to add_options_for_float16

Add -mfpmath=sse to add_options_for_float16 to avoid error:
'-fexcess-precision=16' is not compatible with '-mfpmath=387'
when compiling gcc.dg/tree-ssa/pow_fold_1.c.

gcc/testsuite/ChangeLog:

* lib/target-supports.exp (add_options_for_float16): Add 
-mpfpmath=sse.

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

diff --git a/gcc/testsuite/lib/target-supports.exp 
b/gcc/testsuite/lib/target-supports.exp
index d550f288a0fa..187a7e2992c3 100644
--- a/gcc/testsuite/lib/target-supports.exp
+++ b/gcc/testsuite/lib/target-supports.exp
@@ -3985,7 +3985,7 @@ proc add_options_for_float16 { flags } {
return "$flags -mfp16-format=ieee"
 }
 if { [istarget i?86-*-*] || [istarget x86_64-*-*] } {
-   return "$flags -msse2"
+   return "$flags -msse2 -mfpmath=sse"
 }
 return "$flags"
 }


[gcc r14-10977] Fortran: Fix segfault in allocation of unlimited poly array [PR84869]

2024-11-24 Thread Paul Thomas via Gcc-cvs
https://gcc.gnu.org/g:911a870a6198a2fe50af8bbeb63de1dfaa90de0e

commit r14-10977-g911a870a6198a2fe50af8bbeb63de1dfaa90de0e
Author: Paul Thomas 
Date:   Sun Nov 24 14:22:06 2024 +

Fortran: Fix segfault in allocation of unlimited poly array [PR84869]

2024-11-24  Paul Thomas  

gcc/fortran/ChangeLog

PR fortran/84869
* trans-expr.cc (trans_class_vptr_len_assignment): To access
the '_len' field, 're' must be unlimited polymorphic.

gcc/testsuite/
PR fortran/84869
* gfortran.dg/pr84869.f90: Comment out test of component refs.

Diff:
---
 gcc/fortran/trans-expr.cc |  2 +-
 gcc/testsuite/gfortran.dg/pr84869.f90 | 25 +
 2 files changed, 26 insertions(+), 1 deletion(-)

diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc
index 80399fe3c4f7..c9275e7ba82c 100644
--- a/gcc/fortran/trans-expr.cc
+++ b/gcc/fortran/trans-expr.cc
@@ -10232,7 +10232,7 @@ trans_class_vptr_len_assignment (stmtblock_t *block, 
gfc_expr * le,
  vptr_expr = NULL;
  se.expr = gfc_class_vptr_get (GFC_DECL_SAVED_DESCRIPTOR (
 re->symtree->n.sym->backend_decl));
- if (to_len)
+ if (to_len && UNLIMITED_POLY (re))
from_len = gfc_class_len_get (GFC_DECL_SAVED_DESCRIPTOR (
 re->symtree->n.sym->backend_decl));
}
diff --git a/gcc/testsuite/gfortran.dg/pr84869.f90 
b/gcc/testsuite/gfortran.dg/pr84869.f90
new file mode 100644
index ..fe40b6208047
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr84869.f90
@@ -0,0 +1,25 @@
+! { dg-do compile }
+!
+! Test the fix for PR84869, where line 19 segfaulted.
+!
+! Contributed by Gerhard Steinmetz  
+!
+program p
+   type t
+ integer :: i
+   end type
+   call s
+contains
+   function f()
+  class(t), allocatable :: f(:)
+  f = [(t(i), i = 1, 10)]
+   end
+   subroutine s
+  class(*), allocatable :: z(:)
+  allocate (z, source = f ()) ! Segfault in gfc_class_len_get.
+  select type (z)
+type is (t)
+  if (any (z%i /= [(i, i = 1,10)])) stop 1
+  end select
+   end
+end


[gcc r13-9211] Fortran: Suppress failing part of testcase [PR109345]

2024-11-24 Thread Paul Thomas via Gcc-cvs
https://gcc.gnu.org/g:0794ca02b47935cd672f74815023d708e5e262e1

commit r13-9211-g0794ca02b47935cd672f74815023d708e5e262e1
Author: Paul Thomas 
Date:   Sun Nov 24 14:25:37 2024 +

Fortran: Suppress failing part of testcase [PR109345]

2024-11-24  Paul Thomas  

gcc/testsuite/
PR fortran/109345
* gfortran.dg/pr109345.f90: Comment out test of component refs.

Diff:
---
 gcc/testsuite/gfortran.dg/pr109345.f90 | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/gcc/testsuite/gfortran.dg/pr109345.f90 
b/gcc/testsuite/gfortran.dg/pr109345.f90
index cff9aaa987a0..5f59bef00078 100644
--- a/gcc/testsuite/gfortran.dg/pr109345.f90
+++ b/gcc/testsuite/gfortran.dg/pr109345.f90
@@ -31,7 +31,7 @@ program test
 ! Test component references
   call foo (str_t%str_array(1), .true.)
 ! Test component references and that array offset is correct.
-  call foo (str_t(2:3)%i)
+!  call foo (str_t(2:3)%i) ! Does not work in 13-branch
 
 contains
   subroutine foo (var, flag)
@@ -57,7 +57,7 @@ contains
  if (any (var /= str_array4(1))) stop 6
end if
do i = 1, size(var)
-! Elemental array references did not work.
+! Elemental array references did not work. (Does not work in 13-branch)
   if (var(i) /= var(1)) then
 if (present (flag)) stop 7
 if (trim (var(i)) /= trim (str_array4(i))) stop 8


[gcc r15-5629] Fortran: Fix segfault in allocation of unlimited poly array [PR85869]

2024-11-24 Thread Paul Thomas via Gcc-cvs
https://gcc.gnu.org/g:470ebd31843db58fc503ccef38b82d0da93c65e4

commit r15-5629-g470ebd31843db58fc503ccef38b82d0da93c65e4
Author: Paul Thomas 
Date:   Sun Nov 24 12:01:32 2024 +

Fortran: Fix segfault in allocation of unlimited poly array [PR85869]

2024-11-24  Paul Thomas  

gcc/fortran/ChangeLog

PR fortran/85869
* trans-expr.cc (trans_class_vptr_len_assignment): To access
the '_len' field, re must be unlimited polymorphic.

gcc/testsuite/
PR fortran/85869
* gfortran.dg/pr85869.f90: Comment out test of component refs.

Diff:
---
 gcc/fortran/trans-expr.cc |  3 ++-
 gcc/testsuite/gfortran.dg/pr85869.f90 | 25 +
 2 files changed, 27 insertions(+), 1 deletion(-)

diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc
index 7013dd3a4119..bc1d5a87307d 100644
--- a/gcc/fortran/trans-expr.cc
+++ b/gcc/fortran/trans-expr.cc
@@ -21,6 +21,7 @@ along with GCC; see the file COPYING3.  If not see
 
 /* trans-expr.cc-- generate GENERIC trees for gfc_expr.  */
 
+#define INCLUDE_MEMORY
 #include "config.h"
 #include "system.h"
 #include "coretypes.h"
@@ -10421,7 +10422,7 @@ trans_class_vptr_len_assignment (stmtblock_t *block, 
gfc_expr * le,
  vptr_expr = NULL;
  se.expr = gfc_class_vptr_get (GFC_DECL_SAVED_DESCRIPTOR (
 re->symtree->n.sym->backend_decl));
- if (to_len)
+ if (to_len && UNLIMITED_POLY (re))
from_len = gfc_class_len_get (GFC_DECL_SAVED_DESCRIPTOR (
 re->symtree->n.sym->backend_decl));
}
diff --git a/gcc/testsuite/gfortran.dg/pr85869.f90 
b/gcc/testsuite/gfortran.dg/pr85869.f90
new file mode 100644
index ..24caeb486f23
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr85869.f90
@@ -0,0 +1,25 @@
+! { dg-do compile }
+!
+! Test the fix for PR85869, where line 19 segfaulted.
+!
+! Contributed by Gerhard Steinmetz  
+!
+program p
+   type t
+ integer :: i
+   end type
+   call s
+contains
+   function f()
+  class(t), allocatable :: f(:)
+  f = [(t(i), i = 1, 10)]
+   end
+   subroutine s
+  class(*), allocatable :: z(:)
+  allocate (z, source = f ()) ! Segfault in gfc_class_len_get.
+  select type (z)
+type is (t)
+  if (any (z%i /= [(i, i = 1,10)])) stop 1
+  end select
+   end
+end


[gcc r15-5630] Fortran: Correct name of testcase [PR84869]

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

commit r15-5630-gaa09e32c4d4ebdd58f677a7ecbdcb93cce84823d
Author: Paul Thomas 
Date:   Sun Nov 24 14:01:21 2024 +

Fortran: Correct name of testcase [PR84869]

2024-11-24  Paul Thomas  

gcc/testsuite/
PR fortran/84869
* gfortran.dg/pr84869.f90: Copy of test below with number
   corrected.
* gfortran.dg/pr85869.f90: deleted.

Diff:
---
 gcc/testsuite/gfortran.dg/{pr85869.f90 => pr84869.f90} | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/testsuite/gfortran.dg/pr85869.f90 
b/gcc/testsuite/gfortran.dg/pr84869.f90
similarity index 89%
rename from gcc/testsuite/gfortran.dg/pr85869.f90
rename to gcc/testsuite/gfortran.dg/pr84869.f90
index 24caeb486f23..fe40b6208047 100644
--- a/gcc/testsuite/gfortran.dg/pr85869.f90
+++ b/gcc/testsuite/gfortran.dg/pr84869.f90
@@ -1,6 +1,6 @@
 ! { dg-do compile }
 !
-! Test the fix for PR85869, where line 19 segfaulted.
+! Test the fix for PR84869, where line 19 segfaulted.
 !
 ! Contributed by Gerhard Steinmetz  
 !


[gcc r15-5628] Fortran: Fix non_overridable typebound proc problems [PR84674/117730].

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

commit r15-5628-gdd6dbbb5111fba960ad0ee7999a225783e0ae80e
Author: Paul Thomas 
Date:   Sun Nov 24 08:50:58 2024 +

Fortran: Fix non_overridable typebound proc problems [PR84674/117730].

2024-11-24  Paul Thomas  

gcc/fortran/ChangeLog

PR fortran/117730
* class.cc (add_proc_comp): Only reject a non_overridable if it
has no overridden procedure and the component is already
present in the vtype.
PR fortran/84674
* resolve.cc (resolve_fl_derived): Do not build a vtable for a
derived type extension that is completely empty.

gcc/testsuite/ChangeLog

PR fortran/117730
* gfortran.dg/pr117730_a.f90: New test.
* gfortran.dg/pr117730_b.f90: New test.

PR fortran/84674
* gfortran.dg/pr84674.f90: New test.

Diff:
---
 gcc/fortran/class.cc |  5 +--
 gcc/fortran/resolve.cc   |  4 +++
 gcc/testsuite/gfortran.dg/pr117730_a.f90 | 50 +
 gcc/testsuite/gfortran.dg/pr117730_b.f90 | 47 +++
 gcc/testsuite/gfortran.dg/pr84674.f90| 55 
 5 files changed, 159 insertions(+), 2 deletions(-)

diff --git a/gcc/fortran/class.cc b/gcc/fortran/class.cc
index da09d210b4b5..59ac0d97e080 100644
--- a/gcc/fortran/class.cc
+++ b/gcc/fortran/class.cc
@@ -885,11 +885,12 @@ add_proc_comp (gfc_symbol *vtype, const char *name, 
gfc_typebound_proc *tb)
 {
   gfc_component *c;
 
-  if (tb->non_overridable && !tb->overridden)
-return;
 
   c = gfc_find_component (vtype, name, true, true, NULL);
 
+  if (tb->non_overridable && !tb->overridden && c)
+return;
+
   if (c == NULL)
 {
   /* Add procedure component.  */
diff --git a/gcc/fortran/resolve.cc b/gcc/fortran/resolve.cc
index b817192cd930..b1740cec3881 100644
--- a/gcc/fortran/resolve.cc
+++ b/gcc/fortran/resolve.cc
@@ -16287,6 +16287,10 @@ resolve_fl_derived (gfc_symbol *sym)
   && sym->ns->proc_name
   && sym->ns->proc_name->attr.flavor == FL_MODULE
   && sym->attr.access != ACCESS_PRIVATE
+  && !(sym->attr.extension
+  && sym->attr.zero_comp
+  && !sym->f2k_derived->tb_sym_root
+  && !sym->f2k_derived->tb_uop_root)
   && !(sym->attr.vtype || sym->attr.pdt_template))
 {
   gfc_symbol *vtab = gfc_find_derived_vtab (sym);
diff --git a/gcc/testsuite/gfortran.dg/pr117730_a.f90 
b/gcc/testsuite/gfortran.dg/pr117730_a.f90
new file mode 100644
index ..12e28214b02b
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr117730_a.f90
@@ -0,0 +1,50 @@
+! { dg-do compile }
+!
+! Test the fix for PR117730 in which the non_overrridable procedures in 'child'
+! were mixied up in the vtable for the extension 'child2' in pr117730_b.f90.
+! This resulted in 'this%calc()' in 'function child_get(this)' returning 
garbage
+! when 'this' was of dynamic type 'child2'.
+!
+! Contributed by   in comment 4 of PR84674.
+!
+module module1
+implicit none
+private
+public :: child
+
+type, abstract :: parent
+contains
+procedure, pass :: reset => parent_reset
+end type parent
+
+type, extends(parent), abstract :: child
+contains
+procedure, pass, non_overridable :: reset => child_reset
+procedure, pass, non_overridable :: get => child_get
+procedure(calc_i), pass, deferred :: calc
+end type child
+
+abstract interface
+pure function calc_i(this) result(value)
+import :: child
+class(child), intent(in) :: this
+integer :: value
+end function calc_i
+end interface
+
+contains
+pure subroutine parent_reset(this)
+class(parent), intent(inout) :: this
+end subroutine parent_reset
+
+pure subroutine child_reset(this)
+class(child), intent(inout) :: this
+end subroutine child_reset
+
+function child_get(this) result(value)
+class(child), intent(inout) :: this
+integer   :: value
+
+value = this%calc()
+end function child_get
+end module module1
diff --git a/gcc/testsuite/gfortran.dg/pr117730_b.f90 
b/gcc/testsuite/gfortran.dg/pr117730_b.f90
new file mode 100644
index ..09707882989e
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr117730_b.f90
@@ -0,0 +1,47 @@
+! { dg-do run }
+! { dg-compile-aux-modules "pr117730_a.f90" }
+! { dg-additional-sources pr117730_a.f90 }
+!
+! Test the fix for PR117730 in which the non_overrridable procedures in
+! pr117730_a.f90 were mixied up in the vtable for 'child2' below. This resulted
+! in 'this%calc()' in 'function child_get(this)' returning garbage.
+!
+! Contributed by   in comment 4 of PR84674.
+!
+module module2
+use module1, only: child
+
+implicit none
+private
+public :: child2
+
+type, extends(chi

[gcc r15-5632] Fix vectorization regressions on the SPARC

2024-11-24 Thread Eric Botcazou via Gcc-cvs
https://gcc.gnu.org/g:ab952929f7741998e3f28959c85e7abbf88ea79f

commit r15-5632-gab952929f7741998e3f28959c85e7abbf88ea79f
Author: Eric Botcazou 
Date:   Sun Nov 24 20:23:34 2024 +0100

Fix vectorization regressions on the SPARC

This fixes the vectorization regressions present on the SPARC by switching
from vcond[u] patterns to vec_cmp[u] + vcond_mask_ patterns.  While I was
at it, I merged the patterns for V4HI/V2SI and V8QI enabled with VIS 3/VIS 4
to follow the model of those enabled with VIS 4B, and standardized all the
mnemonics to the version documented in the Oracle SPARC architecture 2015.

gcc/
PR target/117715
* config/sparc/sparc-protos.h (sparc_expand_vcond): Rename to...
(sparc_expand_vcond_mask): ...this.
* config/sparc/sparc.cc (TARGET_VECTORIZE_GET_MASK_MODE): Define.
(sparc_vis_init_builtins): Adjust the CODE_FOR_* identifiers.
(sparc_get_mask_mode): New function.
(sparc_expand_vcond): Rename to...
(sparc_expand_vcond_mask): ...this and adjust.
* config/sparc/sparc.md (unspec): Remove UNSPEC_FCMP & UNSPEC_FUCMP
and rename UNSPEC_FPUCMPSHL into UNSPEC_FPCMPUSHL.
(fcmp_vis): Merge into...
(fpcmp8_vis): Merge into...
(fpcmp_vis): ...this.
(fucmp8_vis): Merge into...
(fpcmpu_vis): Merge into...
(fpcmpu_vis): ...this.
(vec_cmp): New expander.
(vec_cmpu): Likewise.
(vcond): Delete.
(vcondv8qiv8qi): Likewise.
(vcondu): Likewise.
(vconduv8qiv8qi): Likewise.
(vcond_mask_): New expander.
(fpcmpshl): Adjust.
(fpcmpushl): Likewise.
(fpcmpdeshl): Likewise.
(fpcmpurshl): Likewise.
* doc/md.texi (vcond_mask_len_): Fix pasto.

gcc/testsuite/
* gcc.target/sparc/20230328-1.c: Adjust to new mnemonics.
* gcc.target/sparc/20230328-4.c: Likewise.
* gcc.target/sparc/fcmp.c: Likewise.
* gcc.target/sparc/fucmp.c: Likewise.

Diff:
---
 gcc/config/sparc/sparc-protos.h |   2 +-
 gcc/config/sparc/sparc.cc   | 105 -
 gcc/config/sparc/sparc.md   | 173 
 gcc/doc/md.texi |   2 +-
 gcc/testsuite/gcc.target/sparc/20230328-1.c |   2 +-
 gcc/testsuite/gcc.target/sparc/20230328-4.c |   2 +-
 gcc/testsuite/gcc.target/sparc/fcmp.c   |  17 +--
 gcc/testsuite/gcc.target/sparc/fucmp.c  |   9 +-
 8 files changed, 141 insertions(+), 171 deletions(-)

diff --git a/gcc/config/sparc/sparc-protos.h b/gcc/config/sparc/sparc-protos.h
index bc306083e5f1..333f48e82da1 100644
--- a/gcc/config/sparc/sparc-protos.h
+++ b/gcc/config/sparc/sparc-protos.h
@@ -106,7 +106,7 @@ extern void sparc_expand_compare_and_swap (rtx op[]);
 extern void sparc_expand_vector_init (rtx, rtx);
 extern void sparc_expand_vec_perm_bmask(machine_mode, rtx);
 extern bool sparc_expand_conditional_move (machine_mode, rtx *);
-extern void sparc_expand_vcond (machine_mode, rtx *, int, int);
+extern void sparc_expand_vcond_mask (machine_mode, rtx *, int);
 unsigned int sparc_regmode_natural_size (machine_mode);
 #endif /* RTX_CODE */
 
diff --git a/gcc/config/sparc/sparc.cc b/gcc/config/sparc/sparc.cc
index 3935a97fac8b..f1944e510e50 100644
--- a/gcc/config/sparc/sparc.cc
+++ b/gcc/config/sparc/sparc.cc
@@ -719,6 +719,7 @@ static HOST_WIDE_INT sparc_constant_alignment (const_tree, 
HOST_WIDE_INT);
 static bool sparc_vectorize_vec_perm_const (machine_mode, machine_mode,
rtx, rtx, rtx,
const vec_perm_indices &);
+static opt_machine_mode sparc_get_mask_mode (machine_mode);
 static bool sparc_can_follow_jump (const rtx_insn *, const rtx_insn *);
 static HARD_REG_SET sparc_zero_call_used_regs (HARD_REG_SET);
 static machine_mode sparc_c_mode_for_floating_type (enum tree_index);
@@ -972,6 +973,9 @@ char sparc_hard_reg_printed[8];
 #undef TARGET_VECTORIZE_VEC_PERM_CONST
 #define TARGET_VECTORIZE_VEC_PERM_CONST sparc_vectorize_vec_perm_const
 
+#undef TARGET_VECTORIZE_GET_MASK_MODE
+#define TARGET_VECTORIZE_GET_MASK_MODE sparc_get_mask_mode
+
 #undef TARGET_CAN_FOLLOW_JUMP
 #define TARGET_CAN_FOLLOW_JUMP sparc_can_follow_jump
 
@@ -11271,40 +11275,40 @@ sparc_vis_init_builtins (void)
   /* Pixel compare.  */
   if (TARGET_ARCH64)
 {
-  def_builtin_const ("__builtin_vis_fcmple16", CODE_FOR_fcmple16di_vis,
+  def_builtin_const ("__builtin_vis_fcmple16", CODE_FOR_fpcmple16di_vis,
 SPARC_BUILTIN_FCMPLE16, di_ftype_v4hi_v4hi);
-  def_builtin_const ("__builtin_vis_fcmple32", CODE_FOR_fcmple32di_vis,
+  def_builtin_const ("__builtin_vis_fcmple32", CODE_FOR_fpcmple32di_vis,
 SPARC_BUILTIN_FCMPLE

[gcc r15-5631] Adjust error message for initialized variable in .bss

2024-11-24 Thread Eric Botcazou via Gcc-cvs
https://gcc.gnu.org/g:adb4f2329a6da903fffe33b48a03510c52d1a0b8

commit r15-5631-gadb4f2329a6da903fffe33b48a03510c52d1a0b8
Author: Eric Botcazou 
Date:   Sun Nov 24 15:15:54 2024 +0100

Adjust error message for initialized variable in .bss

The current message does not make sense with -fno-zero-initialized-in-bss.

gcc/
* doc/invoke.texi (-fno-zero-initialized-in-bss): Adjust for Ada.
* varasm.cc (get_variable_section): Adjust the error message for an
initialized variable in .bss to -fno-zero-initialized-in-bss.

gcc/testsuite/
* gnat.dg/specs/bss1.ads: New test.

Diff:
---
 gcc/doc/invoke.texi  |  2 +-
 gcc/testsuite/gnat.dg/specs/bss1.ads |  5 +
 gcc/varasm.cc| 11 ---
 3 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 44f0fd297b29..8141811b4531 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -13068,7 +13068,7 @@ rely on variables going to the data section---e.g., so 
that the
 resulting executable can find the beginning of that section and/or make
 assumptions based on that.
 
-The default is @option{-fzero-initialized-in-bss}.
+The default is @option{-fzero-initialized-in-bss} except in Ada.
 
 @opindex fthread-jumps
 @item -fthread-jumps
diff --git a/gcc/testsuite/gnat.dg/specs/bss1.ads 
b/gcc/testsuite/gnat.dg/specs/bss1.ads
new file mode 100644
index ..56f180297cfe
--- /dev/null
+++ b/gcc/testsuite/gnat.dg/specs/bss1.ads
@@ -0,0 +1,5 @@
+package Bss1 is
+
+  I : Integer := 0 with Linker_Section => ".bss"; -- { dg-error "no 
initializers" }
+
+end Bss1;
diff --git a/gcc/varasm.cc b/gcc/varasm.cc
index acc4b4a04194..dd67dd441c0f 100644
--- a/gcc/varasm.cc
+++ b/gcc/varasm.cc
@@ -1264,9 +1264,14 @@ get_variable_section (tree decl, bool prefer_noswitch_p)
   if ((sect->common.flags & SECTION_BSS)
  && !bss_initializer_p (decl, true))
{
- error_at (DECL_SOURCE_LOCATION (decl),
-   "only zero initializers are allowed in section %qs",
-   sect->named.name);
+ if (flag_zero_initialized_in_bss)
+   error_at (DECL_SOURCE_LOCATION (decl),
+ "only zero initializers are allowed in section %qs",
+ sect->named.name);
+ else
+   error_at (DECL_SOURCE_LOCATION (decl),
+ "no initializers are allowed in section %qs",
+ sect->named.name);
  DECL_INITIAL (decl) = error_mark_node;
}
   return sect;


[gcc r15-5644] asan: Support dynamic shadow offset

2024-11-24 Thread Kito Cheng via Gcc-cvs
https://gcc.gnu.org/g:63c68752768fd6d67c695e09c85e0e1ca59cd6d4

commit r15-5644-g63c68752768fd6d67c695e09c85e0e1ca59cd6d4
Author: Kito Cheng 
Date:   Fri Nov 15 12:14:54 2024 +0800

asan: Support dynamic shadow offset

AddressSanitizer has supported dynamic shadow offsets since 2016[1], but
GCC hasn't implemented this yet because targets using dynamic shadow
offsets, such as Fuchsia and iOS, are mostly unsupported in GCC.

However, RISC-V 64 switched to dynamic shadow offsets this year[2] because
virtual memory space support varies across different RISC-V cores, such as
Sv39, Sv48, and Sv57. We realized that the best way to handle this
situation is by using a dynamic shadow offset to obtain the offset at
runtime.

We introduce a new target hook, TARGET_ASAN_DYNAMIC_SHADOW_OFFSET_P, to
determine if the target is using a dynamic shadow offset, so this change
won't affect the static offset path. Additionally, TARGET_ASAN_SHADOW_OFFSET
continues to work even if TARGET_ASAN_DYNAMIC_SHADOW_OFFSET_P is non-zero,
ensuring that KASAN functions as expected.

This patch set has been verified on the Banana Pi F3, currently one of the
most popular RISC-V development boards. All AddressSanitizer-related tests
passed without introducing new regressions.

It was also verified on AArch64 and x86_64 with no regressions in
AddressSanitizer.

[1] 
https://github.com/llvm/llvm-project/commit/130a190bf08a3d955d9db24dac936159dc049e12
[2] 
https://github.com/llvm/llvm-project/commit/da0c8b275564f814a53a5c19497669ae2d99538d

gcc/ChangeLog:

* asan.cc (asan_dynamic_shadow_offset_p): New.
(asan_shadow_memory_dynamic_address): New.
(asan_local_shadow_memory_dynamic_address): New.
(get_asan_shadow_memory_dynamic_address_decl): New.
(asan_maybe_insert_dynamic_shadow_at_function_entry): New.
(asan_emit_stack_protection): Support dynamic shadow offset.
(build_shadow_mem_access): Ditto.
* asan.h (asan_maybe_insert_dynamic_shadow_at_function_entry): New.
* doc/tm.texi (TARGET_ASAN_DYNAMIC_SHADOW_OFFSET_P): New.
* doc/tm.texi.in (TARGET_ASAN_DYNAMIC_SHADOW_OFFSET_P): Ditto.
* sanopt.cc (pass_sanopt::execute): Handle dynamic shadow offset.
* target.def (asan_dynamic_shadow_offset_p): New.
* toplev.cc (process_options): Handle dynamic shadow offset.

Diff:
---
 gcc/asan.cc| 80 ++
 gcc/asan.h |  3 ++
 gcc/doc/tm.texi|  6 +++-
 gcc/doc/tm.texi.in |  2 ++
 gcc/sanopt.cc  |  4 +++
 gcc/target.def |  8 +-
 gcc/toplev.cc  |  3 +-
 7 files changed, 98 insertions(+), 8 deletions(-)

diff --git a/gcc/asan.cc b/gcc/asan.cc
index 087595bd9c70..a54ecf2b1ed5 100644
--- a/gcc/asan.cc
+++ b/gcc/asan.cc
@@ -457,6 +457,13 @@ asan_shadow_offset ()
   return asan_shadow_offset_value;
 }
 
+static bool
+asan_dynamic_shadow_offset_p ()
+{
+  return (asan_shadow_offset_value == 0)
+&& targetm.asan_dynamic_shadow_offset_p ();
+}
+
 /* Returns Asan shadow offset has been set.  */
 bool
 asan_shadow_offset_set_p ()
@@ -473,6 +480,55 @@ static GTY(()) tree shadow_ptr_types[3];
 /* Decl for __asan_option_detect_stack_use_after_return.  */
 static GTY(()) tree asan_detect_stack_use_after_return;
 
+static GTY (()) tree asan_shadow_memory_dynamic_address;
+
+/* Local copy for the asan_shadow_memory_dynamic_address within the
+   function.  */
+static GTY (()) tree asan_local_shadow_memory_dynamic_address;
+
+static tree
+get_asan_shadow_memory_dynamic_address_decl ()
+{
+  if (asan_shadow_memory_dynamic_address == NULL_TREE)
+{
+  tree id, decl;
+  id = get_identifier ("__asan_shadow_memory_dynamic_address");
+  decl
+   = build_decl (BUILTINS_LOCATION, VAR_DECL, id, pointer_sized_int_node);
+  SET_DECL_ASSEMBLER_NAME (decl, id);
+  TREE_ADDRESSABLE (decl) = 1;
+  DECL_ARTIFICIAL (decl) = 1;
+  DECL_IGNORED_P (decl) = 1;
+  DECL_EXTERNAL (decl) = 1;
+  TREE_STATIC (decl) = 1;
+  TREE_PUBLIC (decl) = 1;
+  TREE_USED (decl) = 1;
+  asan_shadow_memory_dynamic_address = decl;
+}
+
+  return asan_shadow_memory_dynamic_address;
+}
+
+void
+asan_maybe_insert_dynamic_shadow_at_function_entry (function *fun)
+{
+  asan_local_shadow_memory_dynamic_address = NULL_TREE;
+  if (!asan_dynamic_shadow_offset_p ())
+return;
+
+  gimple *g;
+
+  tree lhs = create_tmp_var (pointer_sized_int_node,
+"__local_asan_shadow_memory_dynamic_address");
+
+  g = gimple_build_assign (lhs, get_asan_shadow_memory_dynamic_address_decl 
());
+  gimple_set_location (g, fun->function_start_locus);
+  edge e = single_succ_edge (ENTRY_BLOCK_PTR_FOR_FN (cfun));
+  gsi_insert_on_edge_immediate (e, g);
+
+  asan_local_shadow_memory_dynamic_address = lhs;
+

[gcc r15-5645] RISC-V: Use dynamic shadow offset

2024-11-24 Thread Kito Cheng via Gcc-cvs
https://gcc.gnu.org/g:c84a8a274af3163a4042bcfd77dd1988bd1eb0ce

commit r15-5645-gc84a8a274af3163a4042bcfd77dd1988bd1eb0ce
Author: Kito Cheng 
Date:   Fri Nov 15 12:14:55 2024 +0800

RISC-V: Use dynamic shadow offset

Switch to dynamic offset so that we can support Sv39, Sv48, and Sv57 at
the same time without building multiple libasan versions!

[1] 
https://github.com/llvm/llvm-project/commit/da0c8b275564f814a53a5c19497669ae2d99538d

gcc/ChangeLog:

* config/riscv/riscv.cc (riscv_asan_shadow_offset): Use dynamic
offset for RV64.
(riscv_asan_dynamic_shadow_offset_p): New.
(TARGET_ASAN_DYNAMIC_SHADOW_OFFSET_P): New.

gcc/testsuite/ChangeLog:

* g++.dg/asan/asan_test.cc: Update the testcase for dynamic
offset.

Diff:
---
 gcc/config/riscv/riscv.cc  | 18 ++
 gcc/testsuite/g++.dg/asan/asan_test.cc |  3 +++
 2 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc
index 8f5b43e2c245..efdb1d332831 100644
--- a/gcc/config/riscv/riscv.cc
+++ b/gcc/config/riscv/riscv.cc
@@ -11226,11 +11226,18 @@ riscv_gpr_save_operation_p (rtx op)
 static unsigned HOST_WIDE_INT
 riscv_asan_shadow_offset (void)
 {
-  /* We only have libsanitizer support for RV64 at present.
+  /* This number must match ASAN_SHADOW_OFFSET_CONST in the file
+ libsanitizer/asan/asan_mapping.h, we use 0 here because RV64
+ using dynamic shadow offset, and RV32 isn't support yet.  */
+  return 0;
+}
+
+/* Implement TARGET_ASAN_DYNAMIC_SHADOW_OFFSET_P.  */
 
- This number must match ASAN_SHADOW_OFFSET_CONST in the file
- libsanitizer/asan/asan_mapping.h.  */
-  return TARGET_64BIT ? HOST_WIDE_INT_UC (0xd) : 0;
+static bool
+riscv_asan_dynamic_shadow_offset_p (void)
+{
+  return TARGET_64BIT;
 }
 
 /* Implement TARGET_MANGLE_TYPE.  */
@@ -13764,6 +13771,9 @@ riscv_use_by_pieces_infrastructure_p (unsigned 
HOST_WIDE_INT size,
 #undef TARGET_ASAN_SHADOW_OFFSET
 #define TARGET_ASAN_SHADOW_OFFSET riscv_asan_shadow_offset
 
+#undef TARGET_ASAN_DYNAMIC_SHADOW_OFFSET_P
+#define TARGET_ASAN_DYNAMIC_SHADOW_OFFSET_P riscv_asan_dynamic_shadow_offset_p
+
 #ifdef TARGET_BIG_ENDIAN_DEFAULT
 #undef  TARGET_DEFAULT_TARGET_FLAGS
 #define TARGET_DEFAULT_TARGET_FLAGS (MASK_BIG_ENDIAN)
diff --git a/gcc/testsuite/g++.dg/asan/asan_test.cc 
b/gcc/testsuite/g++.dg/asan/asan_test.cc
index 0d976801cf19..65580afd934b 100644
--- a/gcc/testsuite/g++.dg/asan/asan_test.cc
+++ b/gcc/testsuite/g++.dg/asan/asan_test.cc
@@ -932,6 +932,9 @@ TEST(AddressSanitizer, ShadowGapTest) {
 #else
 # if defined(__powerpc64__)
   char *addr = (char*)0x02400080;
+# elif defined(__riscv) && __riscv_xlen == 64
+  extern void *__asan_shadow_memory_dynamic_address;
+  char *addr = (char*)__asan_shadow_memory_dynamic_address + 0x1000;
 # else
   char *addr = (char*)0x1008;
 # endif


[gcc r15-5643] RISC-V: Minimal support for svvptc extension.

2024-11-24 Thread Kito Cheng via Gcc-cvs
https://gcc.gnu.org/g:e4f4b2dc08b6720acab563db48fd4b0427d2b0c6

commit r15-5643-ge4f4b2dc08b6720acab563db48fd4b0427d2b0c6
Author: Dongyan Chen 
Date:   Fri Nov 22 13:13:46 2024 +0800

RISC-V: Minimal support for svvptc extension.

This patch support svvptc extension[1].
To enable GCC to recognize and process svvptc extension correctly at 
compile time.

[1] https://github.com/riscv/riscv-svvptc

gcc/ChangeLog:

* common/config/riscv/riscv-common.cc: New extension.
* common/config/riscv/riscv-ext-bitmask.def (RISCV_EXT_BITMASK): 
Ditto.
* config/riscv/riscv.opt: New mask.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/arch-44.c: New test.

Diff:
---
 gcc/common/config/riscv/riscv-common.cc   | 2 ++
 gcc/common/config/riscv/riscv-ext-bitmask.def | 1 +
 gcc/config/riscv/riscv.opt| 2 ++
 gcc/testsuite/gcc.target/riscv/arch-44.c  | 5 +
 4 files changed, 10 insertions(+)

diff --git a/gcc/common/config/riscv/riscv-common.cc 
b/gcc/common/config/riscv/riscv-common.cc
index 49e8a41846ee..4c9a72d1180a 100644
--- a/gcc/common/config/riscv/riscv-common.cc
+++ b/gcc/common/config/riscv/riscv-common.cc
@@ -405,6 +405,7 @@ static const struct riscv_ext_version 
riscv_ext_version_table[] =
   {"svinval", ISA_SPEC_CLASS_NONE, 1, 0},
   {"svnapot", ISA_SPEC_CLASS_NONE, 1, 0},
   {"svpbmt",  ISA_SPEC_CLASS_NONE, 1, 0},
+  {"svvptc",  ISA_SPEC_CLASS_NONE, 1, 0},
 
   {"xcvmac", ISA_SPEC_CLASS_NONE, 1, 0},
   {"xcvalu", ISA_SPEC_CLASS_NONE, 1, 0},
@@ -1723,6 +1724,7 @@ static const riscv_ext_flag_table_t 
riscv_ext_flag_table[] =
 
   RISCV_EXT_FLAG_ENTRY ("svinval", x_riscv_sv_subext, MASK_SVINVAL),
   RISCV_EXT_FLAG_ENTRY ("svnapot", x_riscv_sv_subext, MASK_SVNAPOT),
+  RISCV_EXT_FLAG_ENTRY ("svvptc", x_riscv_sv_subext, MASK_SVVPTC),
 
   RISCV_EXT_FLAG_ENTRY ("ztso", x_riscv_ztso_subext, MASK_ZTSO),
 
diff --git a/gcc/common/config/riscv/riscv-ext-bitmask.def 
b/gcc/common/config/riscv/riscv-ext-bitmask.def
index ca5df1740f3f..a733533df98e 100644
--- a/gcc/common/config/riscv/riscv-ext-bitmask.def
+++ b/gcc/common/config/riscv/riscv-ext-bitmask.def
@@ -79,5 +79,6 @@ RISCV_EXT_BITMASK ("zcd", 1,  4)
 RISCV_EXT_BITMASK ("zcf",  1,  5)
 RISCV_EXT_BITMASK ("zcmop",1,  6)
 RISCV_EXT_BITMASK ("zawrs",1,  7)
+RISCV_EXT_BITMASK ("svvptc",   1,  8)
 
 #undef RISCV_EXT_BITMASK
diff --git a/gcc/config/riscv/riscv.opt b/gcc/config/riscv/riscv.opt
index d7fa47f70806..a6a61a83db1b 100644
--- a/gcc/config/riscv/riscv.opt
+++ b/gcc/config/riscv/riscv.opt
@@ -466,6 +466,8 @@ Mask(SVINVAL) Var(riscv_sv_subext)
 
 Mask(SVNAPOT) Var(riscv_sv_subext)
 
+Mask(SVVPTC) Var(riscv_sv_subext)
+
 TargetVariable
 int riscv_ztso_subext
 
diff --git a/gcc/testsuite/gcc.target/riscv/arch-44.c 
b/gcc/testsuite/gcc.target/riscv/arch-44.c
new file mode 100644
index ..80dc19a7083d
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/arch-44.c
@@ -0,0 +1,5 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv64gc_svvptc -mabi=lp64" } */
+int foo()
+{
+}


[gcc r15-5646] tree-optimization/115825 - improve unroll estimates for volatile accesses

2024-11-24 Thread Richard Biener via Gcc-cvs
https://gcc.gnu.org/g:d1cf0d7a0f27fdd55302785f19f07d1c3f162ba5

commit r15-5646-gd1cf0d7a0f27fdd55302785f19f07d1c3f162ba5
Author: Richard Biener 
Date:   Wed Jul 10 12:45:02 2024 +0200

tree-optimization/115825 - improve unroll estimates for volatile accesses

The loop unrolling code assumes that one third of all volatile accesses
can be possibly optimized away which is of course not true.  This leads
to excessive unrolling in some cases.  The following tracks the number
of stmts with side-effects as those are not eliminatable later and
only assumes one third of the other stmts can be further optimized.

This causes some fallout in the testsuite where we rely on unrolling
even when calls are involved.  I have XFAILed g++.dg/warn/Warray-bounds-20.C
but adjusted the others with a #pragma GCC unroll to mimic previous
behavior and retain what the testcase was testing.  I've also filed
PR117671 for the case where the size estimation fails to honor the
stmts we then remove by inserting __builtin_unreachable ().
For gcc.dg/tree-ssa/cunroll-2.c the estimate that the code doesn't
grow is clearly bogus and we have explicit code to reject unrolling
for bodies containing calls so I've adjusted the testcase accordingly.

PR tree-optimization/115825
* tree-ssa-loop-ivcanon.cc 
(loop_size::not_eliminatable_after_peeling):
New.
(loop_size::last_iteration_not_eliminatable_after_peeling): 
Likewise.
(tree_estimate_loop_size): Count stmts with side-effects as
not optimistically eliminatable.
(estimated_unrolled_size): Compute the number of stmts that can
be optimistically eliminated by followup transforms.
(try_unroll_loop_completely): Adjust.

* gcc.dg/tree-ssa/cunroll-17.c: New testcase.
* gcc.dg/tree-ssa/cunroll-2.c: Adjust to not expect unrolling.
* gcc.dg/pr94600-1.c: Force unrolling.
* c-c++-common/ubsan/unreachable-3.c: Likewise.
* g++.dg/warn/Warray-bounds-20.C: XFAIL cases we rely on
unrolling loops created by new expressions and not inlined
CTOR invocations.

Diff:
---
 gcc/testsuite/c-c++-common/ubsan/unreachable-3.c |  3 +-
 gcc/testsuite/g++.dg/warn/Warray-bounds-20.C |  6 ++--
 gcc/testsuite/gcc.dg/pr94600-1.c |  1 +
 gcc/testsuite/gcc.dg/tree-ssa/cunroll-17.c   | 11 
 gcc/testsuite/gcc.dg/tree-ssa/cunroll-2.c|  3 +-
 gcc/tree-ssa-loop-ivcanon.cc | 35 +++-
 6 files changed, 47 insertions(+), 12 deletions(-)

diff --git a/gcc/testsuite/c-c++-common/ubsan/unreachable-3.c 
b/gcc/testsuite/c-c++-common/ubsan/unreachable-3.c
index b7a0d1aa92bf..8831a1fb187c 100644
--- a/gcc/testsuite/c-c++-common/ubsan/unreachable-3.c
+++ b/gcc/testsuite/c-c++-common/ubsan/unreachable-3.c
@@ -14,8 +14,9 @@ struct snic {
 void snic_log_q_error(struct snic *snic)
 {
 unsigned int i;
+#pragma GCC unroll 1
 for (i = 0; i < snic->wq_count; i++)
-ioread32(&snic->wq[i]->error_status);
+  ioread32(&snic->wq[i]->error_status);
 }
 
 /* { dg-final { scan-tree-dump "__builtin___ubsan_handle_builtin_unreachable" 
"optimized" } } */
diff --git a/gcc/testsuite/g++.dg/warn/Warray-bounds-20.C 
b/gcc/testsuite/g++.dg/warn/Warray-bounds-20.C
index f4876d8a269d..5fc552930747 100644
--- a/gcc/testsuite/g++.dg/warn/Warray-bounds-20.C
+++ b/gcc/testsuite/g++.dg/warn/Warray-bounds-20.C
@@ -53,8 +53,8 @@ void warn_derived_ctor_access_new_alloc ()
 
 void warn_derived_ctor_access_new_array_decl ()
 {
-  char b[sizeof (D1) * 2];// { dg-message "at offset \\d+ into object 'b' 
of size 80" "LP64 note" { target lp64 } }
-  // { dg-message "at offset \\d+ into object 'b' 
of size 40" "LP64 note" { target ilp32 } .-1 }
+  char b[sizeof (D1) * 2];// { dg-message "at offset \\d+ into object 'b' 
of size 80" "LP64 note" { target { lp64 } xfail { lp64 } } }
+  // { dg-message "at offset \\d+ into object 'b' 
of size 40" "LP64 note" { target { ilp32 } xfail { ilp32 } } .-1 }
   char *p = b;
   ++p;
   D1 *q = new (p) D1[2];
@@ -63,7 +63,7 @@ void warn_derived_ctor_access_new_array_decl ()
 
 void warn_derived_ctor_access_new_array_alloc ()
 {
-  char *p = new char[sizeof (D1) * 2];// { dg-message "at offset 
\\d+ into object of size \\d+ allocated by '\[^\n\r]*operator new\[^\n\r]*" 
"note" }
+  char *p = new char[sizeof (D1) * 2];// { dg-message "at offset 
\\d+ into object of size \\d+ allocated by '\[^\n\r]*operator new\[^\n\r]*" 
"note" { xfail *-*-* } }
   ++p;
   D1 *q = new (p) D1[2];
   sink (q);
diff --git a/gcc/testsuite/gcc.dg/pr94600-1.c b/gcc/testsuite/gcc.dg/pr94600-1.c
index 149e4f35dbee..d5fb4d169c4c 100644
--- a/gcc/testsuite/gcc.dg/pr94600-1.c
+++ b/gcc/testsuite/gcc.dg/pr94600-1.c
@@ -31,6 +31,7 @@ foo