Alice Carlotti [Mon, 13 Oct 2025 16:52:02 +0000 (17:52 +0100)]
aarch64: Sync aarch64-sys-regs.def with Binutils
This patch incorporates changes to this file in Binutils since March
2024 (excluding one patch that was already cherry-picked by
Ezra in July 2025). It includes:
- New system registers in the 2024 and 2025 architecture extensions.
- Updated feature requirements for most system register accessors.
- Removal of registers that were dropped from the architecture.
- Removal of the unnecessary F_ARCHEXT flag.
- Fixed encoding for pmsdsfr_el1.
The updated architecture feature requirements are only relevant when the
new `-menable-sysreg-checking' option is enabled.
Sebastian Pop [Fri, 25 Jul 2025 15:55:03 +0000 (17:55 +0200)]
tree-parloops: Enable runtime thread detection with -ftree-parallelize-loops
This patch adds runtime thread count detection to auto-parallelization.
-ftree-parallelize-loops option generates parallelized loops without
specifying a fixed thread count, deferring this decision to program execution
time where it is controlled by the OMP_NUM_THREADS environment variable.
Bootstrap and regression tested on aarch64-linux. Compiled SPEC HPC pot3d
https://www.spec.org/hpc2021/docs/benchmarks/628.pot3d_s.html with
-ftree-parallelize-loops and tested without having OMP_NUM_THREADS set in the
environment and with OMP_NUM_THREADS set to different values.
gcc/ChangeLog:
* doc/invoke.texi (ftree-parallelize-loops): Update.
* common.opt (ftree-parallelize-loops): Add alias that maps to
special value INT_MAX for runtime thread detection.
* tree-parloops.cc (create_parallel_loop): Use INT_MAX for runtime
detection. Call gimple_build_omp_parallel without building a
OMP_CLAUSE_NUM_THREADS clause.
(gen_parallel_loop): For auto-detection, use a conservative
estimate of 2 threads.
(parallelize_loops): Same.
Christophe Lyon [Thu, 2 Oct 2025 13:52:22 +0000 (13:52 +0000)]
arm: [MVE] Fix carry-in support for vadcq / vsbcq [PR122189]
The vadcq and vsbcq patterns had two problems:
- the adc / sbc part of the pattern did not mention the use of vfpcc
- the carry calcultation part should use a different unspec code
In addtion, the get_fpscr_nzcvqc and set_fpscr_nzcvqc were
over-cautious by using unspec_volatile when unspec is really what they
need. Making them unspec enables to remove redundant accesses to
FPSCR_nzcvqc.
Roger Sayle [Wed, 15 Oct 2025 10:21:18 +0000 (11:21 +0100)]
PR rtl-optimization/122266: Handle TImode in reg_num_sign_bit_copies_for_combine
This patch resolves PR rtl-optimization/122266 by changing the types
of the last_set_sign_bit_copies and sign_bit_copies fields in combine.cc's
reg_stat_type struct to be "unsigned short". This makes both types
consistent, and fixes the issue that on platforms where char is by
default signed, combine.cc can overflow when handling TImode values,
where sign_bit_copies can be 128 bits.
Conveniently, there are holes (caused by field alignment/padding) in the
reg_stat_type struct that allows us to upgrade to "unsigned short" without
increasing the total size of the struct. This should help reduce problems
in future handling OImode or XImode values, or possible issues with 256-bit
and 512-bit vector modes. Note that it's important to take care when
reordering the fields of this struct, as the (partial) ordering of fields
is significant: See the use of offsetof in combine.cc's init_reg_last.
2025-10-15 Roger Sayle <roger@nextmovesoftware.com>
gcc/ChangeLog
PR rtl-optimization/122266
* combine.cc (struct reg_stat_type): Change types of sign_bit_copies
and last_set_sign_bit_copies to unsigned short, to avoid overflows
on TImode (and wider) values.
gcc/testsuite/ChangeLog
PR rtl-optimization/122266
* gcc.target/i386/pr122266.c: New test case.
Jan Hubicka [Wed, 15 Oct 2025 07:49:21 +0000 (09:49 +0200)]
Cleanup max of profile_count
profile_count::max is not implemented same way as other arithmetics on
profile counts which generally require counts to be compatible and
returns minimum of qualities of input counts. Reason is that originally
it was used to compute statistics of whole callgraph profile so inliner
weights can be scaled to reasonable integers interprocedurally. It also
combines qulities weird way so the same counter could be used to
determine what quality of profile is available. That code had roundoff
error issues and was replaced by sreals.
Now max is mostly used to determine cfg->max_count which is used to
scale counts to reasonable integers intraprocedurally and is still being
used i.e. by IRA. There are also few places where max is used for
normal arithmetics when updating profile.
For computing max_count we need max to still be a bit special so max
(uninitialized, initialized) returns initialized rather then
uninitialized. Partial profiles are later handled specially.
This patch renames max to max_prefer_initialized to make it clear and updates
implementation to require compatible profiles. I checked this behaviour is good
for other places using it as well.
I also turned function to static, since a = a->max (b) looks odd.
gcc/ChangeLog:
* auto-profile.cc (scale_bb_profile): Use
profile_count::max_prefer_initialized.
(afdo_adjust_guessed_profile): Likewise.
* bb-reorder.cc (edge_order): Do not use max.
* cfghooks.cc (merge_blocks): Likewise.
* ipa-fnsummary.cc (param_change_prob): Likewise.
* ipa-inline-transform.cc (inline_transform): Likewise.
* predict.cc (update_max_bb_count): Likewise.
(estimate_bb_frequencies): Likewise.
(rebuild_frequencies): Likewise.
* tree-ssa-loop-unswitch.cc (struct unswitch_predicate): Likewise.
* profile-count.h (profile_count::max): Rename to
(profile_count::max_prefer_initialized): this; update handling
of qualities.
Patrick Palka [Tue, 14 Oct 2025 16:56:23 +0000 (12:56 -0400)]
c++: mem-initializer-id qualified name lookup is type-only [PR122192]
Since a mem-initializer needs to be able to initialize any base class,
lookup for which is type-only, we in turn need to make mem-initializer-id
qualified name lookup type-only too.
PR c++/122192
gcc/cp/ChangeLog:
* parser.cc (cp_parser_mem_initializer_id): Pass class_type
instead of typename_type to cp_parser_class_name in the
nested-name-specifier case.
gcc/testsuite/ChangeLog:
* g++.dg/template/dependent-base6.C: Verify mem-initializer-id
qualified name lookup is type-only too.
Reported-by: Vincent X Reviewed-by: Jason Merrill <jason@redhat.com>
Add tests to ensure that std::this_thread::sleep_for() and
std::this_thread::sleep_until() cope with being passed negative times
correctly. These tests prove that the functions don't suffer from
libstdc++/PR116586, and will stay that way.
libstdc++-v3/ChangeLog:
PR libstdc++/116586
* testsuite/30_threads/this_thread/sleep_for.cc: Add
test_negative() test.
* testsuite/30_threads/this_thread/sleep_until.cc: Make existing
test use both system_clock and steady_clock. Add test_negative()
test.
Mike Crowe [Sun, 14 Sep 2025 20:21:28 +0000 (21:21 +0100)]
libstdc++: Add std::binary_semaphore tests for negative timeouts [PR116586]
Add test cases to prove that negative timeouts are correctly handled by
std::binary_semaphore (which is just an alias for
std::counting_semaphore<1>). The tests exercise cases that aren't
problematic with the current code since system_clock is converted to
steady_clock before calling __platform_wait_until() is called but they
will protect against changes in the implementation reintroducing this
bug.
Jonathan Wakely [Thu, 9 Oct 2025 10:09:34 +0000 (11:09 +0100)]
libstdc++: Avoid overflow in timeout conversions [PR113327]
When converting from a coarse duration with a very large value, the
existing code scales that up to chrono::seconds which overflows the
chrono::seconds::rep type. For example, sleep_for(chrono::hours::max())
tries to calculate LLONG_MAX * 3600, which overflows to -3600 and so the
sleep returns immediately.
The solution in this commit is inspired by this_thread::sleep_for in
libc++ which compares the duration argument to
chrono::duration<long double>(nanoseconds::max()) and limits the
duration to nanoseconds::max(). Because we split the duration into
seconds and nanoseconds, we can use seconds::max() as our upper limit.
We might need to limit further if seconds::max() doesn't fit in the
type used for sleeping, which is one of std::time_t, unsigned int, or
chrono::milliseconds.
To fix this everywhere that uses timeouts, new functions are introduced
for converting from a chrono::duration or chrono::time_point to a
timespec (or __gthread_time_t which is just a timespec on Linux). These
functions provide one central place where we can avoid overflow and also
handle negative timeouts (as these produce errors when passed to OS
functions that do not accept absolute times before the epoch). All
negative durations are converted to zero, and negative time_points are
converted to the epoch.
The new __to_timeout_gthread_time_t function in <bits/std_mutex.h>
requires adding <bits/chrono.h> to that header, but that only affects
<syncstream>. All other consumers of <bits/std_mutex.h> were already
including <bits/chrono.h> for timeouts (e.g. <shared_mutex> and
<condition_variable>).
libstdc++-v3/ChangeLog:
PR libstdc++/113327
PR libstdc++/116586
PR libstdc++/119258
PR libstdc++/58931
* include/bits/chrono.h (__to_timeout_timespec): New overloaded
function templates for converting chrono types to timespec.
* include/bits/std_mutex.h (__to_timeout_gthread_time_t): New
function template for converting time_point to __gthread_time_t.
* include/bits/this_thread_sleep.h (sleep_for): Use
__to_timeout_timespec.
(__sleep_for): Remove namespace-scope declaration.
* include/std/condition_variable: Likewise.
* include/std/mutex: Likewise.
* include/std/shared_mutex: Likewise.
* src/c++11/thread.cc (limit): New helper function.
(__sleep_for): Use limit to prevent overflow when converting
chrono::seconds to time_t, unsigned, or chrono::milliseconds.
* src/c++20/atomic.cc: Use __to_timeout_timespec and
__to_timeout_gthread_time_t for timeouts.
* testsuite/30_threads/this_thread/113327.cc: New test.
Reviewed-by: Mike Crowe <mac@mcrowe.com> Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
Luc Grosheintz [Tue, 14 Oct 2025 15:16:55 +0000 (17:16 +0200)]
libstdc++: Remove unused local type alias <format>.
After r16-4421-g59cabe08b57a26 the local type alias _String isn't used
anymore and therefore causes warnings when building the tests with
`-Wall -Wextra`.
libstdc++-v3/ChangeLog:
* include/std/format (_M_format_range): Remove unused local type
alias _String.
Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>0 Signed-off-by: Luc Grosheintz <luc.grosheintz@gmail.com>
Jonathan Wakely [Wed, 8 Oct 2025 14:24:51 +0000 (15:24 +0100)]
libstdc++: Test specific feature test macros instead of __cplusplus
This changes the associative and unordered containers to check
__glibcxx_node_extract, __glibcxx_generic_associative_lookup, and
__glibcxx_generic_unordered_lookup instead of just checking the value of
__cplusplus.
Jonathan Wakely [Sat, 11 Oct 2025 10:22:38 +0000 (11:22 +0100)]
libstdc++: Ensure filesystem::path internals are sufficiently aligned [PR122255]
We need the memory allocated for a path::_List::_Impl to be at least
4-byte aligned, so that we can use the two least significant bits to
store a _Type value. Use __STDCPP_DEFAULT_NEW_ALIGNMENT__ to check that
in a static_assert. Also add a static_assert to check the memory will be
aligned suitably for the _Impl object itself. In practice both
assertions should pass as long as operator new guarantees to return
memory with at least 4-byte alignment, which seems to be true for malloc
on GCC's supported targets.
Allocation of path::_List::_Impl objects is refactored into a new
_Impl::create function so that the memory allocation is done in one
place, rather than being repeated in path::_List::_Impl::copy and
path::_List::reserve. If we late decide to use aligned-new to support
targets that fail the new static assertions we won't need to do that in
two different places. Calling operator delete already only happens in
one place, the _Impl_deleter.
The create function is actually implemented in terms of another new
function, create_unchecked. The overflow checks in create aren't needed
when copying an existing object, because we already checked its size
doesn't overflow.
Destroying the components is now done by a destructor, which the
_Impl_deleter invokes.
libstdc++-v3/ChangeLog:
PR libstdc++/122255
* src/c++17/fs_path.cc (path::_List::_Impl::~_Impl): Define
destructor.
(path::_List::_Impl::copy): Use create_unchecked.
(path::_List::_Impl): Add static assertions.
(path::_List::_Impl::create): New static member function.
(path::_List::_Impl::create_unchecked): Likewise.
(path::_List::_Impl_deleter::operator()): Use destructor.
(path::_List::reserve): Use create.
Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
Tomasz Kamiński [Tue, 8 Jul 2025 16:50:50 +0000 (18:50 +0200)]
libstdc++: Implement _Escaping_sink to avoid construction of string
This patch implements _Escaping_sink that stores characters in a local (stack)
buffer. When the buffer is full, the range of characters is escaped and written
to the underlying sink.
To support above, the __write_escaped_unicode_part function are defined.
It takes __str and __prev_esc by reference. The __prev_esc value is updated
based on the last character written. If the buffer ends with an incomplete
code point sequence, __str is left non-empty and last code points are not
written. _Escaping_sink then copies these characters to the front of the
buffer to reconstruct the full code point.
__formatter__str::_M_format_range now uses _Escaping_sink to escape any
non-continuous character sequences.
libstdc++-v3/ChangeLog:
* include/std/format (__format::__write_escape_seqs)
(__format::_Escaping_sink): Define.
(__format::__write_escaped_unicode_part): Extract from
__format::__write_escaped_unicode.
(__format::__write_escaped_unicode): Forward to
__write_escaped_unicode_part.
(__formatter_str::_M_format_range): Use _Escaping sink.
* testsuite/std/format/ranges/string.cc: New tests for
character which codepoints will be split in buffer and
escaping. Invoked test_padding.
Reviewed-by: Patrick Palka <ppalka@redhat.com> Reviewed-by: Jonathan Wakely <jwakely@redhat.com> Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
Richard Biener [Tue, 14 Oct 2025 12:13:56 +0000 (14:13 +0200)]
Remove REDUC_GROUP_* from public interface
The following removes REDUC_GROUP_* from the public vectorizer
interface and privatizes REDUC_GROUP_FIRST_ELEMENT which is now
only temporarily set during SLP discovery.
Tomasz Kamiński [Wed, 20 Aug 2025 13:56:21 +0000 (15:56 +0200)]
libstdc++: Make atomic<shared_ptr<T>>::wait sensitive to stored pointer only changes [PR118757]
Previously, atomic<shared_ptr<T>>::wait (and the weak_ptr version) was
equivalent to waiting directly on _M_val, which corresponds to the pointer
to the control block (_M_pi). Consequently, wakeups were not triggered if
the stored pointer value was changed to a pointer that uses the same control
block but stores pointer to a different object. Such a pointer can be
constructed using an aliasing constructor.
To address this, wait now uses a generic proxy wait
std::__atomic_wait_address function, which supports waiting until any
predicate is satisfied. The provided predicate now compares both the control
block (_M_pi) and the stored pointer (_M_ptr). Comparing the latter requires
locking the pointer.
Since this function operates on raw pointers, the type of _M_val was changed
from __atomic_base<uintptr_t> to uintptr_t. Invocations of the corresponding
member functions are now replaced with direct use of __atomic builtins.
PR libstdc++/118757
libstdc++-v3/ChangeLog:
* include/bits/shared_ptr_atomic.h (_Atomic_count::_M_wait_unlock):
Add parameter capturing reference to _M_ptr. Reimplement in terms
of __atomic_wait_address.
(_Atomic_count::~_Atomic_count, _Atomic_count::lock)
(_Atomic_count::unlock, _Atomic_count::_M_swap_unlock): Replace
invocation of atomic member funcitons with __atomic builtins.
(_Atomic_count::notify_one, _Atomic_count::notify_all):
Use __atomic_notify_address.
(_Sp_atomic::element_type): Define.
(_Sp_atomic::_M_val): Change type to uintptr_t.
(_Sp_atomic::wait): Pass _M_ptr to _M_wait_unlock.
* python/libstdcxx/v6/printers.py:
* testsuite/20_util/shared_ptr/atomic/pr118757.cc: New test.
* testsuite/20_util/weak_ptr/pr118757.cc: New test.
Reviewed-by: Jonathan Wakely <jwakely@redhat.com> Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
Tomasz Kamiński [Tue, 14 Oct 2025 09:06:35 +0000 (11:06 +0200)]
libstdc++: Fix required alignment computation for floating points [PR122267]
Before the r16-4349-g90dde804626f13 the required alignment of floating point,
and pointer specialization used __alignof__(_Vt) as required_alignment, and
mentioned commit changed them to alignof(_Vt). This values differs on i686
for double, as alignof(double) is 4, and __alignof__(double) is 8.
This patch restores the previous behavior.
PR libstdc++/122267
libstdc++-v3/ChangeLog:
* include/bits/atomic_base.h
(__atomic_ref_base<const _Tp>::_S_required_alignment):
Use __alignof__ instead of alignof.
Richard Biener [Thu, 9 Oct 2025 12:02:09 +0000 (14:02 +0200)]
Clean up confusing vectype/vectype1 mixups in vect_create_epilog_for_reduction
The following occured to me - hope it doesn't hide anything real.
* tree-vect-loop.cc (vect_create_epilog_for_reduction): Move
bitsize compute down to where it is used and consistently
use vectype1 for element extraction.
fails to vectorize because the size of row is different than the size of the
being shifted value.
The vectorizer has a pattern that should deal with such shifts in
vect_recog_vector_vector_shift_pattern however this pattern is using
vect_get_internal_def to get the definition of the shift operand.
This needlessly restricts the pattern to only internal_defs. The vectorizer
can deal with casts on any operand type so this restriction isn't needed and
this is dropped.
gcc/ChangeLog:
PR tree-optimization/121949
* tree-vect-patterns.cc (vect_recog_vector_vector_shift_pattern): Remove
restriction on internal_def.
gcc/testsuite/ChangeLog:
PR tree-optimization/121949
* gcc.dg/vect/pr121949_1.c: New test.
* gcc.dg/vect/pr121949_2.c: New test.
* gcc.dg/vect/pr121949_3.c: New test.
Jakub Jelinek [Tue, 14 Oct 2025 09:06:08 +0000 (11:06 +0200)]
obj-c/obj-c++: Enable more options in c-family for ObjC/ObjC++
On Mon, Oct 13, 2025 at 07:07:01AM +0100, Iain Sandoe wrote:
> * c.opt: Enable Wignored-attributes for Objective-C and
> Objective-C++.
I wrote a more complete version of this patch, here is it rebased
on top of your patch.
I see no reason for any of these options to be C C++ only rather than
C ObjC C++ ObjC++, or in some cases C++ only rather than C++ ObjC++.
The only cases where I think limiting to C only is desirable are
fgimple
C Var(flag_gimple) Init(0)
Enable parsing GIMPLE.
where I think we don't want to support ObjC for GIMPLE FE, and
lang-asm
C Undocumented RejectDriver
For everything else I believe people adding those options just didn't
think of ObjC or ObjC++.
2025-10-14 Jakub Jelinek <jakub@redhat.com>
* c.opt (Wflex-array-member-not-at-end, Wignored-qualifiers,
Wopenacc-parallelism, Wstrict-flex-arrays, Wsync-nand,
fstrict-flex-arrays, fstrict-flex-arrays=): Enable also for ObjC and
ObjC++ next to C and C++.
(Wmisleading-indentation, Wopenmp-simd): Likewise. Also change
LangEnabledBy from just C C++ to C ObjC C++ ObjC++.
(Wplacement-new, Wplacement-new=, fcontract-assumption-mode=,
fcontract-build-level=, fcontract-strict-declarations=,
fcontract-mode=, fcontract-continuation-mode=, fcontract-role=,
fcontract-semantic=, fcoroutines, flang-info-include-translate,
flang-info-include-translate-not, flang-info-include-translate=,
flang-info-module-cmi, flang-info-module-cmi=): Enable also
for ObjC++ next to C++.
Robin Dapp [Fri, 10 Oct 2025 16:39:01 +0000 (18:39 +0200)]
vect: Move slp_perm checking into get_load_store_type.
This moves the setting of slp_perm, checking of basic-block SLP gaps, as
well as the final check for perm_ok to get_load_store_type.
Also, slp_perm is moved to ls_data.
gcc/ChangeLog:
* tree-vect-stmts.cc (get_load_store_type): Add load-permutation
checks and setting of slp_perm.
(vectorizable_store): Remove perm_ok argument.
(vectorizable_load): Ditto and replace slp_perm by ls.slp_perm.
* tree-vectorizer.h (struct vect_load_store_data): Add slp_perm.
Richard Biener [Fri, 10 Oct 2025 12:09:32 +0000 (14:09 +0200)]
Rewrite reduction chain handling
The following moves us (almost) away from REDUC_GROUP_* to recognize
reduction chaings towards making this a SLP discovery artifact.
Reduction chains are now explicitly marked in the reduction info
and discovery is done during SLP discovery rather than during
analysis of scalar cycles. This gets rid of interactions with
patterns and it also allows to transparently fall back to non-chained
reductions even when there is a conversion involved. This also
spurred some major TLC in vectorizable_reduction.
What's still missing is to get rid of the last REDUC_GROUP_FIRST_ELEMENT
usage in SLP discovery - by not claiming we can handle the reduction
chain itself there. I'm leaving this for a followup (this was big
enough).
At least on x86-64 I now see XPASSes for gcc.dg/vect/vect-reduc-dot-s8b.c
and gcc.dg/vect/vect-reduc-pattern-2c.c. I have not done careful
analysis yet, will wait for the CI with that.
* tree-vectorizer.h (vect_reduc_info_s::is_reduc_chain): New.
(_loop_vec_info::reduction_chains): Remove.
(LOOP_VINFO_REDUCTION_CHAINS): Likewise.
* tree-vect-patterns.cc (vect_reassociating_reduction_p):
Do not special-case reduction group stmts.
* tree-vect-loop.cc (vect_is_simple_reduction): Remove
reduction chain handling.
(vect_analyze_scalar_cycles_1): Remove slp parameter and adjust.
(vect_analyze_scalar_cycles): Likewise.
(vect_fixup_reduc_chain): Remove.
(vect_fixup_scalar_cycles_with_patterns): Likewise.
(vect_analyze_loop_2): Adjust.
(vect_create_epilog_for_reduction): Check the reduction info
for whether this is a reduction chain.
(vect_transform_cycle_phi): Likewise.
(vectorizable_reduction): Likewise. Simplify code for all-SLP.
* tree-vect-slp.cc (vect_analyze_slp_reduc_chain): Simplify.
(vect_analyze_slp_reduction): New function, perform reduction
chain discovery here.
(vect_analyze_slp): Remove reduction chain handling.
Use vect_analyze_slp_reduction for possible reduction chain
processing.
Haochen Jiang [Tue, 14 Oct 2025 06:52:11 +0000 (14:52 +0800)]
i386: Remove AMX-TRANSPOSE support
AMX-TRANSPOSE is removed from ISE. Since there is no actual hardware, we
choose to directly remove it in GCC 16 and backport DMR enable part to
GCC 15.
Andrew Pinski [Mon, 13 Oct 2025 23:47:55 +0000 (16:47 -0700)]
phi-opt: Disable parts of it for -Og
While working on the cselim limited part of phiopt, I noticed
that the debugging experience for -Og case would cause jumping
execution in some cases. So this disables the store and operation
factoring parts for -Og since those 2 can cause the line information
of the debugging to be off.
Bootstrapped and tested on x86_64-linux-gnu.
gcc/ChangeLog:
* tree-ssa-phiopt.cc (pass_phiopt::execute): Disable
cselim-limited and factor out operations for -Og.
Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
Andrew Pinski [Mon, 13 Oct 2025 23:35:07 +0000 (16:35 -0700)]
cselim: Handle clobbers too [PR122178]
With the addition of cselim-limited in phiopt, factoring
out clobbers can be added easily. Now sink handles clobbers as
a store too. So this just moves that earlier.
This adds support there with a testcase to show it happens.
may_propagate_copy_into_asm has been returning true always since r0-118216-g01c59d23df7eef.
Many places that checks may_propagate_copy don't check
may_propagate_copy_into_asm for asm_expr. may_propagate_copy_into_stmt
does not check when you would have expected it to. So let's remove may_propagate_copy_into_asm
and remove the checks from substitute_and_fold_engine and dom.
Zhongyao Chen [Tue, 14 Oct 2025 02:55:40 +0000 (20:55 -0600)]
[PATCH v3] RISC-V: Implement RISC-V profile macro support
users can now write code like the following to adapt to the
current RISC-V profile selected at compile time:
```c
#ifdef __riscv_rva23u64
// Code specific to the rva23u64 profile
#endif
```
Changes from v2:
- clarify get_profile_name comment
gcc/
* common/config/riscv/riscv-common.cc (riscv_subset_list::get_profile_name):
New function.
* config/riscv/riscv-c.cc (riscv_cpu_cpp_builtins): Define
profile macro if a profile is detected.
* config/riscv/riscv-subset.h (riscv_subset_list::get_profile_name): Declare.
gcc/testsuite/
* gcc.target/riscv/predef-profiles-1.c: New test for __riscv_rvi20u64.
* gcc.target/riscv/predef-profiles-2.c: New test for __riscv_rvi20u32.
* gcc.target/riscv/predef-profiles-3.c: New test for __riscv_rva20u64.
* gcc.target/riscv/predef-profiles-4.c: New test for __riscv_rva22u64.
* gcc.target/riscv/predef-profiles-5.c: New test for __riscv_rva23u64.
* gcc.target/riscv/predef-profiles-6.c: New test for __riscv_rva23s64.
* gcc.target/riscv/predef-profiles-7.c: New test for __riscv_rvb23u64.
* gcc.target/riscv/predef-profiles-8.c: New test for __riscv_rvb23s64.
Shreya Munnangi [Mon, 13 Oct 2025 22:13:44 +0000 (16:13 -0600)]
[RISC-V][PR target/120811] Improving address reloads in LRA
In pr120811, we have cases where GCC is emitting an extra addi instruction
instead of using the 12-bit signed-immediate of ld.
addi t1, t1, 1
ld t1, 0(t1)
This problem occurs when fp -> sp+offset elimination results in an
out-of-range constant and we generate an address reload in LRA using
addsi/adddi expanders.
We've already adjusted the expanders to widen the set of valid operands to
allow more constants for the 2nd input operand. These expanders, rather than
constructing the constant into a register and using an add instruction, will
generate two addi instructions (or shNadd) during initial RTL generation.
We define a new pattern for cases where we need to access the current frame
and the offsets are too large. This gets reasonable code out of LRA in a form
fold-mem-offsets can handle, rather than having to wait for sched2 to do
the height reduction transformation and leaving in the unnecessary add
instruction in the RTL stream.
To avoid the two addi instructions being squashed back together in the
post-reload combine, we remove the adddi3_const_sum_of_two_s12 pattern.
We are seeing about 100 billion dynamic instructions saved which is about 5%
on cactuBSSN and a 2% improvement in performance on the BPI.
PR target/120811
gcc/
* config/riscv/riscv.cc (synthesize_add): Exchange constant terms when
generating addi pairs.
(synthesize_addsi): Similarly.
* config/riscv/riscv.md (addptr<mode>3): New define_expand.
(*add<mode>3_const_sum_of_two_s12): Remove pattern.
gcc/testsuite/
* gcc.target/riscv/add-synthesis-1.c: Adjust const to fit in range.
* gcc.target/riscv/pr120811.c: Add new test case.
* gcc.target/riscv/sum-of-two-s12-const-1.c: Adjust const to fit in range.
Jeff Law [Mon, 13 Oct 2025 20:33:10 +0000 (14:33 -0600)]
[RISC-V][PR target/120674] Avoid division by zero in dwarf emitter when vector is not enabled
This is a RISC-V specific failure in the dwarf2 emitter. When vector is not
enabled riscv_convert_vector_chunks sets the riscv_vector_chunks poly_int to
[1, 0].
riscv_dwarf_poly_indeterminite_value pulls out that 0 coefficient and uses that
as FACTOR triggering a divide by zero here:
> /* Add COEFF * ((REGNO / FACTOR) - BIAS) to the value:
> add COEFF * (REGNO / FACTOR) now and subtract
> COEFF * BIAS from the final constant part. */
> constant -= coeff * bias;
> add_loc_descr (&ret, new_reg_loc_descr (regno, 0));
> if (coeff % factor == 0)
> coeff /= factor;
> else
> {
> int amount = exact_log2 (factor);
> gcc_assert (amount >= 0);
> add_loc_descr (&ret, int_loc_descriptor (amount));
> add_loc_descr (&ret, new_loc_descr (DW_OP_shr, 0, 0));
> }
Per Robin's recommendation this patch adjusts
riscv_dwarf_poly_indeterminite_value to never set FACTOR to 0, but instead
detect this case and adjust its value to 1.
That fixes the ICE and looks good across the board in my tester. Waiting on
pre-commit CI, of course.
PR target/120674
gcc/
* config/riscv/riscv.cc (riscv_dwarf_poly_indeterminite_value): Do not
set FACTOR to zero, for that case use one instead.
Jakub Jelinek [Mon, 13 Oct 2025 19:36:47 +0000 (21:36 +0200)]
++: Fix up __PRETTY_FUNCTION__ for -fexec-charset= [PR122228]
When working on reflection, I've noticed that while we correctly translate
__FUNCTION__ content into the execution charset, for C++ we don't translate
__PRETTY_FUNCTION__ content and leave it in the SOURCE_CHARSET encoding:
Gaius Mulley [Mon, 13 Oct 2025 15:43:07 +0000 (16:43 +0100)]
PR modula2/122241: Lack of spellng hints with simple errors
Following on from the initial bug fix for PR modula2/122241
this patch provides spell check hints for unknown types, variables
and constants. The accuracy of the offending module end name
is also improved
gcc/m2/ChangeLog:
PR modula2/122241
* gm2-compiler/M2Quads.mod (BuildSizeFunction): Improve
error message.
(BuildTSizeFunction): Improve error message.
* gm2-compiler/P3Build.bnf (ProgramModule): New variable
namet.
Pass namet to P3EndBuildProgModule.
(ImplementationModule): New variable namet.
Pass namet to P3EndBuildImpModule.
(ModuleDeclaration): New variable namet.
Pass namet to P3EndBuildInnerModule.
(DefinitionModule): New variable namet.
Pass namet to P3EndBuildDefModule.
* gm2-compiler/P3SymBuild.def (P3EndBuildDefModule): New
parameter tokno.
(P3EndBuildImpModule): Ditto.
(P3EndBuildProgModule): Ditto.
(EndBuildInnerModule): Ditto.
* gm2-compiler/P3SymBuild.mod (P3EndBuildDefModule): New
parameter tokno.
Pass tokno to CheckForUnknownInModule.
(P3EndBuildImpModule): Ditto.
(P3EndBuildProgModule): Ditto.
(EndBuildInnerModule): Ditto.
* gm2-compiler/PCBuild.bnf (ProgramModule): New variable
namet.
Pass namet to PCEndBuildProgModule.
(ImplementationModule): New variable namet.
Pass namet to PCEndBuildImpModule.
(ModuleDeclaration): New variable namet.
Pass namet to PCEndBuildInnerModule.
(DefinitionModule): New variable namet.
Pass namet to PCEndBuildDefModule.
* gm2-compiler/PCSymBuild.def (PCEndBuildDefModule): New
parameter tokno.
(PCEndBuildImpModule): Ditto.
(PCEndBuildProgModule): Ditto.
(PCEndBuildInnerModule): Ditto.
* gm2-compiler/PCSymBuild.mod (PCEndBuildDefModule): New
parameter tokno.
Pass tokno to CheckForUnknownInModule.
(PCEndBuildImpModule): Ditto.
(PCEndBuildProgModule): Ditto.
(PCEndBuildInnerModule): Ditto.
* gm2-compiler/PHBuild.bnf (DefinitionModule): New variable
namet.
Pass namet to PHEndBuildDefModule.
(ModuleDeclaration): New variable namet.
Pass namet to PHEndBuildProgModule.
(ImplementationModule): New variable namet.
Pass namet to PHEndBuildImpModule.
(ModuleDeclaration): New variable namet.
Pass namet to PHEndBuildInnerModule.
(DefinitionModule): New variable namet.
Pass namet to PHEndBuildDefModule.
* gm2-compiler/SymbolTable.def (CheckForUnknownInModule): Add
tokno parameter.
* gm2-compiler/SymbolTable.mod (CheckForUnknownInModule): Add
tokno parameter.
Pass tokno to CheckForUnknowns.
(CheckForUnknowns): Reimplement.
gcc/testsuite/ChangeLog:
PR modula2/122241
* gm2/iso/fail/badconst.mod: New test.
* gm2/iso/fail/badtype.mod: New test.
* gm2/iso/fail/badvar.mod: New test.
Alex Coplan [Mon, 13 Oct 2025 13:41:09 +0000 (13:41 +0000)]
aarch64, testsuite: Add -fchecking to test options [PR121772]
I noticed while testing a backport of the PR121772 fix to GCC 13 that
the test wasn't triggering the ICE as expected with the unpatched
compiler.
This turned out to be because the ICE is a checking ICE, and we
configure by default with --enable-checking=release on the branches.
Additionally, I hadn't noticed when doing the backports to 15 and 14
since there we still ICE later on in emit_move_insn even if we don't
catch the invalid gimple with checking.
I'm not too sure why the 13 branch doesn't see the emit_move_insn ICE,
but it's somewhat irrelevant - the important thing is that adding
-fchecking to the options makes the test fail as expected with an
unpatched compiler (i.e. with a gimple checking failure), even on
release branches.
I considered applying this patch to just the release branches, but
figured that trunk will at some point itself become a release branch, so
it seems to make most sense just to apply it everywhere.
I've checked that the test still passes with this patch, and still fails
if I revert the PR121772 fix.
gcc/testsuite/ChangeLog:
PR tree-optimization/121772
* gcc.target/aarch64/torture/pr121772.c: Add -fchecking to
dg-options.
Pan Li [Sat, 11 Oct 2025 15:12:59 +0000 (23:12 +0800)]
Match: Add widen_mul based unsigned SAT_MUL after gimple_convert refactor
The build_and_insert_cast refactored to go the gimple_convert way, to
take care of the widen_mul. Thus, the gimple layout from uint64_t
widen_mul to uint128_t doesn't need additional cast like other types
(uint32_t, uint16_t, uint8_t) widen to uint128_t for mul. Thus, add
the simplifed pattern match for such forms of unsigned SAT_MUL.
The below test suites are passed for this patch:
1. The rv64gcv fully regression tests.
2. Fix rv64gcv SAT_MUL test failure of optimized .SAT_MUL check.
3. The x86 bootstrap tests.
4. The x86 fully regression tests.
gcc/ChangeLog:
* match.pd: Add simplifed pattern for widen_mul based unsigned
SAT_MUL.
Jan Hubicka [Mon, 13 Oct 2025 10:13:51 +0000 (12:13 +0200)]
Remove max_count computation from ipa-inline
Ipa inline computes max_count which used to be applied later to compute badness
before it was converted to sreal. Now it is only used in couple of places to see
if any IPA profile is presents at all. This patch replaces this by more specific
flag has_nonzero_ipa_profile.
Jonathan Wakely [Fri, 10 Oct 2025 22:56:43 +0000 (23:56 +0100)]
libstdc++: Fix reverse iteration in _Utf16_view
When iterating over a range of char16_t in reverse the _Utf_view was
incorrectly treating U+DC00 as a valid high surrogate that can precede
the low surrogate. But U+DC00 is a low surrogate, and so should not be
allowed before another low surrogate. The check should be u2 >= 0xDC00
rather than u2 > 0xDC00.
libstdc++-v3/ChangeLog:
* include/bits/unicode.h (_Utf_view::_M_read_reverse_utf16):
Fix check for high surrogate preceding low surrogate.
* testsuite/ext/unicode/view.cc: Check unpaired low surrogates.
Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
Robin Dapp [Fri, 5 Sep 2025 14:19:18 +0000 (16:19 +0200)]
vect: Handle grouped accesses via gather/scatter.
This patch adds gather/scatter handling for grouped access. The idea is
to e.g. replace an access (for uint8_t elements) like
arr[0]
arr[1]
arr[2]
arr[3]
arr[0 + step]
arr[1 + step]
...
by gather loads of uint32_t
arr[0..3]
arr[0 + step * 1..3 + step * 1]
arr[0 + step * 2..3 + step * 2]
...
where the offset vector is a simple series with step STEP.
If supported, such a gather can be implemented as a strided load.
If we have a masked access the transformation is not performed.
Masking could still be done after converting the data back to the
original vectype but it does not seem worth it for now.
PR target/118019
gcc/ChangeLog:
* internal-fn.cc (get_supported_else_vals): Exit at invalid
index.
(internal_strided_fn_supported_p): New funtion.
* internal-fn.h (internal_strided_fn_supported_p): Declare.
* tree-vect-stmts.cc (vector_vector_composition_type):
Add vector_only argument.
(vect_use_grouped_gather): New function.
(vect_get_store_rhs): Adjust docs of
vector_vector_composition_type.
(get_load_store_type): Try grouped gather.
(vectorizable_store): Use punned vectype.
(vectorizable_load): Ditto.
* tree-vectorizer.h (struct vect_load_store_data): Add punned
vectype.
gcc/testsuite/ChangeLog:
* gcc.target/riscv/rvv/autovec/pr118019-2.c: New test.
Avinash Jayakar [Mon, 13 Oct 2025 09:47:45 +0000 (15:17 +0530)]
match.pd: Do not canonicalize division by power 2 for {ROUND, CEIL}_DIV
Canonicalization of unsigned division by power of 2 only applies to
{TRUNC,FLOOR,EXACT}_DIV, therefore remove the same pattern for {CEIL,ROUND}_DIV,
which was added in a previous commit.
Jakub Jelinek [Mon, 13 Oct 2025 07:47:09 +0000 (09:47 +0200)]
openmp: Teach OpenMP declare variant append_args handling about TYPE_NO_NAMED_ARGS_STDARG_P
Since my recent patch, GCC for C++26 uses the TYPE_NO_NAMED_ARGS_STDARG_P
flag like C23 uses for (...) function types. The OpenMP declare variant
append_args handling does some very ugly hacks (modify TYPE_ARG_TYPES
temporarily instead of trying to create new function types) and had
to be tweaked to deal with that. This fixes
-FAIL: c-c++-common/gomp/append-args-7.c -std=c++26 scan-tree-dump-times gimple "f3 \\\\(obj1, obj2, 1, a, cp, d\\\\);" 1
-FAIL: c-c++-common/gomp/append-args-7.c -std=c++26 (test for excess errors)
2025-10-13 Jakub Jelinek <jakub@redhat.com>
* decl.cc (omp_declare_variant_finalize_one): If !nbase_args
and TREE_TYPE (decl) has TYPE_NO_NAMED_ARGS_STDARG_P bit set
and varg is NULL, temporarily set TYPE_NO_NAMED_ARGS_STDARG_P
on TREE_TYPE (variant).
Richard Biener [Mon, 13 Oct 2025 06:22:04 +0000 (08:22 +0200)]
Avoid bool pattern for vect_extern_defs
The following avoids applying the new bool pattern for binary bitwise
ops when the wrongly typed operand is external or constant as we
cannot handle in-loop conversions of externs.
* tree-vect-patterns.cc (integer_type_for_mask): Add optional
output dt argument.
(vect_recog_bool_pattern): Make sure to not apply the bitwise
binary pattern to an external operand.
Paul Thomas [Mon, 13 Oct 2025 06:55:18 +0000 (07:55 +0100)]
Fortran: Fix ICE in deallocating PDTs [PR121191]
2025-10-13 Paul Thomas <pault@gcc.gnu.org>
gcc/fortran
PR fortran/121191
* trans-array.cc (has_parameterized_comps): New function which
checks if a derived type has parameterized components.
( gfc_deallocate_pdt_comp): Use it to prevent deallocation of
PDTs if there are no parameterized components.
gcc/testsuite/
PR fortran/121191
* gfortran.dg/pdt_59.f03: New test.
Iain Sandoe [Mon, 13 Oct 2025 05:57:55 +0000 (06:57 +0100)]
Objective-C/C++: Enable Wignored-attributes.
r16-4373 altered headers so that Wignored-attributes was named in
a diagnostic push. This causes several Objective-C++ tests to fail
since the atomicity.h header is included there.
Since Objective-C/C++ are intended to be supersets of the base
language, there is no specific reason to exclude this warning there.
gcc/c-family/ChangeLog:
* c.opt: Enable Wignored-attributes for Objective-C and
Objective-C++.
Nathaniel Shead [Sun, 5 Oct 2025 10:30:56 +0000 (21:30 +1100)]
c++: Ensure mark_lvalue_use returns an lvalue [PR122163]
When processing a tentative capture of a rvalue reference, mark_use
folds it away to the referred-to entity. But this is an rvalue, and
when called from an lvalue context an rvalue reference should still be
an lvalue.
PR c++/122163
gcc/cp/ChangeLog:
* expr.cc (mark_use): When processing a reference, always return
an lvalue reference when !rvalue_p.
gcc/testsuite/ChangeLog:
* g++.dg/cpp0x/lambda/lambda-ref3.C: New test.
Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com> Reviewed-by: Jason Merrill <jason@redhat.com>
Paul Thomas [Sun, 12 Oct 2025 07:21:11 +0000 (08:21 +0100)]
Fortran: Fix some minor PDT parse errors [PR95543,PR103748]
2025-10-12 Paul Thomas <pault@gcc.gnu.org>
gcc/fortran
PR fortran/95543
PR fortran/103748
* decl.cc (insert_parameter_exprs): Guard param->expr before
using it.
(gfc_get_pdt_instance): Substitute paramaters in kind default
initializers.
(gfc_match_decl_type_spec): Emit an error if a type paramter
specification list appears in a variable declaraion with a
non-parameterized type.
* primary.cc (gfc_match_rvalue): Emit an error if a type spec
list is empty.
Gaius Mulley [Sat, 11 Oct 2025 17:34:25 +0000 (18:34 +0100)]
PR modula2/122241 Lack of spelling hints with simple errors
This patch introduces spell checking to Modula-2. Currently
it spell checks unknown symbols in pass 3. Unknowns found in
record fields, with statements, procedures and variable names
are checked.
* gm2/iso/fail/badfield.mod: New test.
* gm2/iso/fail/badfield2.mod: New test.
* gm2/iso/fail/badprocedure.mod: New test.
* gm2/iso/fail/badprocedure2.mod: New test.
* gm2/iso/fail/badset4.mod: New test.
The combine pass can generate an index like (and:DI (mult:DI (reg:DI)
(const_int scale)) (const_int mask)) when XTheadMemIdx is available.
LRA may pull it out, and thus a splitter is needed when Zba is not
available.
A similar splitter were introduced when XTheadMemIdx support was added,
but removed in commit 31c3c5d. The new splitter in this new patch is
based on the removed one.
PR target/119587
gcc/ChangeLog:
* config/riscv/thead.md (*th_memidx_operand): New splitter.
Georg-Johann Lay [Wed, 11 Dec 2024 10:57:46 +0000 (11:57 +0100)]
Allow target to chose address-space for artificial rodata.
This patch adds a new target hook TARGET_ADDR_SPACE_FOR_ARTIFICIAL_RODATA
that allows the backend to chose an address space other than the generic one.
This hook is only invoked when the compiler can make sure that:
- The object for which the hooks is being invoked will be located
in the desired address space, and
- All accesses to that object will be accesses appropriate for
that address space, and
- The object is read-only and is initialized at load time, and
- The hook invokations are independent of each other. This means
that this hook can be used to optimize code / data consumption.
(Rather than introducing an ABI change, which would be the case
when C++'s vtables were put in a different AS).
To date, there are only two candidates for such compiler generated
lookup tables: CSWTCH tables as generated by tree-switch-conversion.cc,
and CRC lookup tables generated by gimple-crc-optimization.cc.
gcc/
* coretypes.h (enum artificial_rodata): New enum type.
* doc/tm.texi: Rebuild.
* doc/tm.texi.in (TARGET_ADDR_SPACE_FOR_ARTIFICIAL_RODATA):
New hook.
* target.def (addr_sapce.for_artificial_rodata): New DEFHOOK.
* targhooks.cc (default_addr_space_convert): New function.
* targhooks.h (default_addr_space_convert): New prototype.
* tree-switch-conversion.cc (build_one_array) <value_type>:
Set type_quals address-space according to
targetm.addr_space.for_artificial_rodata().
Austin Law [Sat, 11 Oct 2025 03:32:14 +0000 (21:32 -0600)]
[RISC-V] Improve subword atomic patterns in sync.md
This is Austin's work to further clean up and improve sync.md.
While fixing the PR from a couple months back we noticed that many of the
patterns had operand predicates/constraints that were tighter than they needed
to be. For example, the subword atomics have mask and not_mask operands that
are used in AND/OR instructions. Those can legitimately accept a simm12 value.
So this patch adjust several patterns where we identified operands that could
be relaxed a little to improve the generated code in those cases.
This has been tested in my tester for riscv32-elf and riscv64-elf. It has also
bootstrapped and regression tested on the Pioneer and BPI.
Planning to push to the trunk later after verification of pre-commit CI.
Jonathan Wakely [Mon, 6 Oct 2025 14:51:28 +0000 (15:51 +0100)]
libstdc++: Fix warnings from std::make_unsigned<_Atomic_word> [PR122172]
GCC gives a -Wignored-attributes warning when a class template is
instantiated with a type that has an aligned(n) attribute. Specifically,
cris-elf uses 'typedef int __attribute_((__aligned(4))) _Atomic_word;'
and so compiling libstdc++ headers gives:
warning: ignoring attributes on template argument ‘int’ [-Wignored-attributes]
This commit reduces four occurrences of make_unsigned<_Atomic_word> into
two, one in bits/shared_ptr_base.h and one in ext/atomicity.h, and uses
diagnostic pragmas around the two remaining uses to avoid the warnings.
Because the unsigned type might have lost the alignment of _Atomic_word
that is needed for atomic ops (at least on cris-elf), the unsigned type
should only be used for plain non-atomic arithmetic. To prevent misuse,
it's defined as a private type in _Sp_counted_base, and is defined and
then undefined as a macro in ext/atomicity.h, so that it's not usable
after __exchange_and_add_single and __atomic_add_single have been
defined.
We also get a warning from instantiating __int_traits<_Atomic_word> in
shared_ptr_base.h which can be avoided by calculating the maximum signed
value from the maximum unsigned value.
libstdc++-v3/ChangeLog:
PR libstdc++/122172
* include/bits/shared_ptr_base.h (_Sp_counted_base): Define
_Unsigned_count_type for make_unsigned<_Atomic_word>.
Replace __int_traits<_Atomic_word> with equivalent expression.
* include/ext/atomicity.h (_GLIBCXX_UNSIGNED_ATOMIC_WORD):
Define macro for unsigned type to use for arithmetic.
(__exchange_and_add_single, __atomic_add_single): Use it.
Harald Anlauf [Fri, 10 Oct 2025 20:02:51 +0000 (22:02 +0200)]
Fortran: improve checking of procedures passed as actual argument [PR50377]
Procedures passed as actual argument require either an explicit interface
or must be declared EXTERNAL. Add a check and generate an error (default)
or a warning when -std=legacy is specified.
PR fortran/50377
gcc/fortran/ChangeLog:
* resolve.cc (resolve_actual_arglist): Check procedure actual
arguments.
gcc/testsuite/ChangeLog:
* gfortran.dg/pr41011.f: Fix invalid testcase.
* gfortran.dg/actual_procedure_2.f: New test.
David Faust [Fri, 10 Oct 2025 17:35:07 +0000 (10:35 -0700)]
bpf: fix cbranch miscompilation in CPUv1 [PR122141]
As diagnosed by Andrew in the linked PR, when reversing the branch
condition to work around lack of some cbranch instructions, we must
use swap_condition rather than reverse_condition.
PR target/122141
gcc/
* config/bpf/bpf.cc (bpf_expand_cbranch): Use swap_condition
rather than reverse_condition when reversing jump condition to
work around missing instructions in very old BPF ISAs.
Robert Dubner [Fri, 10 Oct 2025 15:35:44 +0000 (11:35 -0400)]
cobol: Convert to individual variable character-set encoding.
Prior to this "patch", the GCOBOL compiler was capable of producing binaries
that operated internally in either ASCII or EBCDIC. The COBOL specification,
however, allows for the concurrent presence of two encodings, known as
"alphanumeric" and "national".
In order to support this capability, we have chosen to establish an "encoding"
characteristic that gets carried along with every variable,
This change affected many parts of the COBOL front end compiler. If anybody
looks at any of the changes listed below, they will find they fall into two
classes:
1) Removing the dependence on a global ASCII vs EBCDIC determination.
2) Adding a dependence on a new ::encoding characteristic of the compile time
and run time cbl_field_t and cblc_field_t variable structures. Those
structures now contain the cbl_encoding_t ::encoding members, which drive the
use of the iconv(3) function in moving back and forth between variable
encodings.
Although the effort is not complete, these changes represent the bulk of what
needs to be done. With these changes in place, all of our current ASCII and
EBCDIC tests run properly.
Andrew Pinski [Thu, 11 Sep 2025 05:05:26 +0000 (22:05 -0700)]
forwprop: Add a simple DSE after a clobber
After copy propagation for aggregates patches we might end up with
now:
```
tmp = a;
b = a; // was b = tmp;
tmp = {CLOBBER};
```
To help out ESRA, it would be a good idea to remove the `tmp = a` statement as
there is no DSE between frowprop and ESRA. copy-prop-aggregate-sra-1.c is an example
where the removal of the copy helps ESRA.
This adds a simple DSE which is only designed to remove the `tmp = a` statement.
This shows up a few times in many C++ code including the code from the javascript
interpreter in ladybird, and in the "fake" testcase in PR 108653 and in the aarch64
specific PR 89967.
This is disabled for -Og as we don't do dse there either.
intent_optimize_10.f90 testcase needed to be updated as the constant
shows up in a debug statement now.
Changes since v1:
* v2: Add much more comments in the code instead of just relying on the commit message.
Count the maybe_use towards the aliasing lookup limit (increase the non-full walk limit to 4
to account for that).
Use direct comparison instead of operand_equal_p since we are comparing against a DECL.
Bootstrapped and tested on x86_64-linux-gnu.
gcc/ChangeLog:
* tree-ssa-forwprop.cc (do_simple_agr_dse): New function.
(pass_forwprop::execute): Call do_simple_agr_dse for clobbers.
gcc/testsuite/ChangeLog:
* gfortran.dg/intent_optimize_10.f90: Update so -g won't fail.
* gcc.dg/tree-ssa/copy-prop-aggregate-sra-1.c: New testcase.
Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
Patrick Palka [Fri, 10 Oct 2025 14:25:25 +0000 (10:25 -0400)]
c++: base-specifier name lookup is type-only [PR122192]
The r13-6098 change to make TYPENAME_TYPE no longer always ignore
non-type bindings needs another exception: base-specifiers that are
represented as TYPENAME_TYPE, for which lookup must be type-only (by
[class.derived.general]/2). This patch fixes this by giving such
TYPENAME_TYPEs a tag type of class_type rather than typename_type so
that we treat them like elaborated-type-specifiers (another type-only
lookup situation).
PR c++/122192
gcc/cp/ChangeLog:
* decl.cc (make_typename_type): Document base-specifier as
another type-only lookup case.
* parser.cc (cp_parser_class_name): Propagate tag_type to
make_typename_type instead of hardcoding typename_type.
(cp_parser_base_specifier): Pass class_type instead of
typename_type as tag_type to cp_parser_class_name.
This patch fixes cpu family model numbers for znver5 and uses the
correct cpuid bit for prefetchi which is different from Intel
(https://docs.amd.com/v/u/en-US/24594_3.37).
* common/config/i386/cpuinfo.h (get_amd_cpu): Fix znver5 family
model numbers.
(get_available_features): Set FEATURE_PREFETCHI for bit_AMD_PREFETCHI.
* config/i386/cpuid.h (bit_AMD_PREFETCHI): New Macro.
Pan Li [Wed, 8 Oct 2025 14:12:38 +0000 (22:12 +0800)]
RISC-V: Combine vec_duplicate + vwsubu.wv to vwsubu.wx on GR2VR cost
This patch would like to combine the vec_duplicate + vwsubu.wv to the
vwsubu.wx. From example as below code. The related pattern will depend
on the cost of vec_duplicate from GR2VR. Then the late-combine will
take action if the cost of GR2VR is zero, and reject the combination
if the GR2VR cost is greater than zero.
Assume we have asm code like below, GR2VR cost is 0.
After this patch:
11 beq a3,zero,.L8
...
14 .L3:
15 vsetvli a5,a3,e32,m1,ta,ma
...
20 vwsubu.wx v1,a2,v3
...
23 bne a3,zero,.L3
Unfortunately, and similar as vwaddu.vv, only widening from uint32_t to
uint64_t has the necessary zero-extend during combine, we loss the
extend op after expand for any other types.
gcc/ChangeLog:
* config/riscv/autovec-opt.md (*widen_wsubu_wx_<mode>): Add new
pattern to match vwsubu.wx.
s390x floating point minimum and maximum functions unfortunately do
not canonicalize NaNs. Hence, test pr105414.c fails since c476f554e3f. Fix this by only allowing fmin/fmax pattern if signaling
NaNs are disabled.
gcc/ChangeLog:
* config/s390/vector.md (fmax<mode>3): Restrict to no trapping
math.
(fmin<mode>3): Ditto.
Verify we don't have any vector temporaries in the IL at least until
ISEL which may introduce VEC_EXTRACTs on targets which support
non-constant indices (see PR116421).
As a pass I chose NRV for no particular reason except that it is
literally the last pass prior ISEL. At least at time of writing this.
gcc/testsuite/ChangeLog:
PR testsuite/116421
* c-c++-common/vector-subscript-4.c: Check for vectors prior
ISEL.
Christophe Lyon [Fri, 10 Oct 2025 11:26:38 +0000 (11:26 +0000)]
testsuite: Adjust vect-reduc-chain-1.c for SLP permute transform
Since r16-3847-g21d1bb1922f (Integrate SLP permute transform into
vect_transform_stmt), vect-reduc-chain-1.c was failing on aarch64
because the dump message changed.
Apply the same change as r16-3847-g21d1bb1922f applied to
vect-reduc-chain-2.c and vect-reduc-chain-3.c
Andrew Stubbs [Thu, 9 Oct 2025 12:52:29 +0000 (12:52 +0000)]
vect: Fix out-of-date VEC_STMT comments
The vec_stmt parameter was removed from these functions by Richi in July
(commit 5865c0b81, some were removed earlier), but the comments still talked
about it.
Complete the list of M3 cores (Ibiza, Palma and Lobos) and add the M4
cores (Donan and two types of Brava).
The values for chip IDs and the LITTLE.big variants have been taken from
lists in the XNU sources (xnu/osfmk/arm/cpuid.h) in xnu-11417.101.15.
gcc/ChangeLog:
* config/aarch64/aarch64-cores.def (AARCH64_CORE): Improve Apple
M3 and add Apple M4 cores.
* config/aarch64/aarch64-tune.md: Regenerate.
* doc/invoke.texi: Add apple-m4 core to the ones listed
for arch and tune selections.
Richard Biener [Fri, 10 Oct 2025 08:05:46 +0000 (10:05 +0200)]
Use gimple_build to perform conversion simplification
The following uses gimple_build to do the conversion simplification
in build_and_insert_cast instead of duplicating it there. Conveniently
when building directly into the IL all stmts are taken into account
for the simplification.
Robin Dapp [Thu, 9 Oct 2025 20:47:26 +0000 (22:47 +0200)]
arm: Fix support_vector_misalignment.
In gcc-16-4314-g5e9eecc6686 I meant to remove all uses of TYPE
in support_vector_misalignment but apparently forgot this one.
Fixing by using the inner mode's size.
gcc/ChangeLog:
* config/arm/arm.cc (arm_builtin_support_vector_misalignment):
Remove use of type.
Tobias Burnus [Fri, 10 Oct 2025 07:48:37 +0000 (09:48 +0200)]
libgomp: Add is_integrated_apu function to plugin/plugin-{gcn,nvptx}.c
The added function is currently '#if 0' but is planned to be used to enable
self mapping automatically. Prerequisite for auto self maps is still mapping
'declare target' variables (if any, in libgomp) or converting all
'declare target' variables to 'declare target link' in the compiler
(as required for 'omp requires self_maps').
The following fixes return stmt type verification by properly looking
at DECL_RESULT to decide whether that's by reference, not trying to
figure that from the actual argument.
PR tree-optimization/122225
* tree-cfg.cc (verify_gimple_return): Look at DECL_RESULT
for DECL_BY_REFERENCE.
This patch addresses several issues related to the additional specializations
for enable_nonlocking_formatter_optimization fomr P3235R3 proposal:
* LWG4399 [1]: Apply remove_cvref_t to tuple and pair elements when checking if
the direct printing optimization is enabled.
* LWG4398 [2]: Disable the direct printing optimization for the standard library
container adaptors: queue, priority_queue, and stack.
* LWG4400 [3]: Enable the direct printing optimization only for durations that
use standard arithmetic types. Conditionally enable it for hh_mm_ss
and time_points based on their underlying Duration template argument.
Jonathan Wakely [Wed, 21 Feb 2024 16:11:53 +0000 (16:11 +0000)]
libstdc++: Implement P3107R5 optimizations for std::print [PR121790]
The names of the vprint functions follow the convention from P3235R3.
This takes advantage of the additional permission proposed by P3107R5 so
that std::print can write directly to a FILE stream, rather than
formatting to an intermediate std::string temporary and then writing
that to the stream. The change is to write to a new _File_sink type
instead of a _Str_sink that populates a std::string. There are three
implementations of _File_sink.
For non-Glibc targets that support POSIX flockfile and putc_unlocked,
the stream will be locked and then formatted characters will be buffered
on the stack (instead of allocating a std::string) and copied to the
stream when the buffer fills up.
For Glibc, _File_sink will lock the stream but then if the file is
line-buffered or fully buffered, characters will be written directly
into the file's output buffer. This avoids two levels of buffering and
copying the characters from one to the other. For an unbuffered stream
(like stderr) the _File_sink buffer will still be used, to avoid the
overhead of lots of small writes to the stream. Because this version of
_File_sink accesses the stream's buffer directly it relies on
glibc-specific implementation details that are exposed in public
headers.
A fallback definition of _File_sink just wraps a _Str_sink so is
equivalent to the original code, and is used when flockfile isn't
available.
Both forms of std::println (taking a FILE* and a std::ostream) can be
implemented more efficiently by appending a newline to the format
string, to avoid formatting twice.
PR libstdc++/121790
libstdc++-v3/ChangeLog:
* acinclude.m4 (GLIBCXX_CHECK_STDIO_LOCKING): New macro to check
for std::print dependencies.
* config.h.in: Regenerate.
* configure: Regenerate.
* configure.ac: Use GLIBCXX_CHECK_STDIO_LOCKING.
* include/bits/formatfwd.h (enable_nonlocking_formatter_optimization):
Define new variable template.
* include/bits/version.def (print): Bump value.
* include/bits/version.h: Regenerate.
* include/std/format (enable_nonlocking_formatter_optimization):
Define specializations for variable template.
* include/std/ostream (print) [!_WIN32]: Do not use
vprint_unicode at all.
(println): Append newline to format string instead of formatting
twice.
* include/std/print (_File_sink): New class.
(vprint_nonunicode_locking): New function.
(vprint_unicode_locking): New function reusing previous code
from vprint_unicode.
(vprintf_unicode): Defer to vprint_nonunicode for Windows or to
vprint_unicode_locking otherwise.
(print): [!_WIN32]: Do no use vprint_unicode at all.
Check enable_nonlocking_formatter_optimization and defer to
either vprint_nonunicode_locking or vprint_nonunicode.
(println): Use vprint_unicode or format directly to a _File_sink
instead of formatting twice.
* testsuite/27_io/print/1.cc: Updated and added new tests.
* testsuite/std/format/formatter/nonlocking.cc: New tests.
Reviewed-by: Jonathan Wakely <jwakely@redhat.com> Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com> Co-authored-by: Tomasz Kamiński <tkaminsk@redhat.com>
libstdc++: Handle cv-qualified types in atomic and atomic_ref [PR115402]
Implements P3233R1 (DR for C++20/C++11, fixes LWG 4069 and 3508).
This commit implements std::atomic_ref<cv T> support (LWG3508) as DR for
C++20, by extractingparts of the __atomic_ref class (that atomic_ref inherits
from) into a further base class (__atomic_ref_base):
* __atomic_ref_base<const T> implements non-mutating (const) atomic API.
Single base class is used, and the difference in is_always_lock_free and
required_aligment values between types are handled by _S_is_always_lock_free,
_S_required_aligment helper functions.
* __atomic_ref_base<T> implements the common atomic APIs. The non-mutating
operations are handled by inherting from __atomic_ref_base<const T> partial
partial specialization. Tu support that __atomic_ref_base<const T> stores
mutable pointer to T, and performs const_cast in constructor.
* __atomic_ref<T, ....> inherits from __atomic_ref_base<T>, and implement
type-specific mutable APIs (fetch_add, -=, ...) and difference_type member
type.
* __atomic_ref<const T, ...> inherits from __atomic_ref_base<const T>
and adds different_type member, whose presence and denoted type depends
on T.
The __atomic_ref specialization selection is adjusted to handle cv-qualified
bool (add remove_cv_t) and pointer types. To handle the later, additional
constant template parameter is introduced.
The atomic wait and notify operations are currently not supported for volatile
types, to signal that static assert is added to corresponding methods of
atomic_ref.
At the same time, disable support for cv-qualified types in std::atomic
(for instance, std::atomic<volatile T> isn't meaningful; one should use
volatile std::atomic<T>), again as per the paper, resolving LWG4069 as DR
for C++11. This only affects atomic<volatile T>, as specialization
atomic with const-qualifed types was already producing an compile-time
error.
PR libstdc++/115402
libstdc++-v3/ChangeLog:
* include/bits/atomic_base.h (__atomic_ref_base<const _Tp>)
(__atomic_ref_base<_Tp>): Define by extracting common methods
from atomic_ref specializations.
(__atomic_ref<_Tp, In, Fp, Pt>): Inherit from __atomic_ref_base
and remove extracted method.
(__atomic_ref<const _Tp, In, Fp, Pt>): Define.
* include/std/atomic (std::atomic): Added an
* testsuite/29_atomics/atomic/requirements/types_neg.cc:
Add test for volatile qualified types.
* testsuite/29_atomics/atomic_ref/bool.cc: Move the content
to op_support.cc, add test for bool.
* testsuite/29_atomics/atomic_ref/op_support.cc: New test
expanded from atomic_ref/bool.cc.
* testsuite/29_atomics/atomic_ref/cv_qual.cc: New test.
* testsuite/29_atomics/atomic_ref/requirements_neg.cc: New test.
* testsuite/29_atomics/atomic_ref/deduction.cc: Add tests for
cv-qualified types.
* testsuite/29_atomics/atomic_ref/float.cc: Likewise.
* testsuite/29_atomics/atomic_ref/generic.cc: Likewise.
* testsuite/29_atomics/atomic_ref/integral.cc: Likewise.
* testsuite/29_atomics/atomic_ref/pointer.cc: Likewise.
* testsuite/29_atomics/atomic_ref/requirements.cc: Likewise.
* testsuite/29_atomics/atomic_ref/wait_notify.cc: Add tests for
const qualified types.
Reviewed-by: Jonathan Wakely <jwakely@redhat.com> Co-authored-by: Tomasz Kamiński <tkaminsk@redhat.com> Signed-off-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
Tomasz Kamiński [Thu, 9 Oct 2025 12:38:54 +0000 (14:38 +0200)]
libstdc++: Improve handling of !ok() weekday index in formatting [PR121929]
Previously, formatting a year_month_weekday with the weekday index equal to
0, 6, or 7 (which are !ok() values in the supported range) produced a
seemingly correct day output. For example %Y-%m-%d produced:
* 2024-09-06 for 2024y/September/Sunday[6] (2024-10-06)
* 2024-09-25 for 2024y/September/Sunday[0] (2023-08-25)
This patch changes how the internal _M_day value is computed for
year_month_weekday. Instead of converting to local_days then to year_month_day,
_M_day is now set as the number of days since ymd.year()/ymd.month()/0. If this
difference is negative (which occurs when index() is 0), _M_day is set to 0 to
avoid handling negative days of the month.
This change yields identical results for all ok() values. However, for !ok() dates,
it now consistently produces invalid dates, ensuring the formatted output clearly
reflects the !ok input state:
* 2024-09-36 for 2024y/September/Sunday[6]
* 2024-09-00 for 2024y/September/Sunday[0]
For consistency, _M_day is computed in the same manner for year_month_weekday_last.
Finally, for year_month_day_last, we fill _M_day directly with ymd.day().
This provides a more efficient implementation and avoids the need to compute
local_days for %Y-%m-%d, %F and similar specifiers.
PR libstdc++/121929
libstdc++-v3/ChangeLog:
* include/bits/chrono_io.h (_ChronoData::_M_fill_aux)
(_ChronoData::_M_fill_aux): Add comment documenting precondition.
(formatter<chrono::year_month_day, _CharT>::format): Compute
local_days inline.
(formatter<chrono::year_month_day_last, _CharT>::format)
(formatter<chrono::year_month_weekday, _CharT>::format)
(formatter<chrono::year_month_weekday_last, _CharT>::format):
Change how the _M_day field is computed.
* testsuite/std/time/year_month_weekday/io.cc: Adjust tests.
Reviewed-by: Jonathan Wakely <jwakely@redhat.com> Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>