platform/upstream/gcc.git
20 months agoipa-visibility: Optimize TLS access [PR99619]
Artem Klimov [Wed, 6 Jul 2022 14:02:01 +0000 (17:02 +0300)]
ipa-visibility: Optimize TLS access [PR99619]

Fix PR99619, which asks to optimize TLS model based on visibility.
The fix is implemented as an IPA optimization: this allows to take
optimized visibility status into account (as well as avoid modifying
all language frontends).

2022-04-17  Artem Klimov  <jakmobius@gmail.com>

gcc/ChangeLog:

PR middle-end/99619
* ipa-visibility.cc (function_and_variable_visibility): Promote
TLS access model afer visibility optimizations.
* varasm.cc (have_optimized_refs): New helper.
(optimize_dyn_tls_for_decl_p): New helper. Use it ...
(decl_default_tls_model): ... here in place of 'optimize' check.

gcc/testsuite/ChangeLog:

PR middle-end/99619
* gcc.dg/tls/vis-attr-gd.c: New test.
* gcc.dg/tls/vis-attr-hidden-gd.c: New test.
* gcc.dg/tls/vis-attr-hidden.c: New test.
* gcc.dg/tls/vis-flag-hidden-gd.c: New test.
* gcc.dg/tls/vis-flag-hidden.c: New test.
* gcc.dg/tls/vis-pragma-hidden-gd.c: New test.
* gcc.dg/tls/vis-pragma-hidden.c: New test.

Co-Authored-By: Alexander Monakov <amonakov@gcc.gnu.org>
Signed-off-by: Artem Klimov <jakmobius@gmail.com>
20 months agoA false UNORDERED_<cond> means neither operand can be a NAN.
Aldy Hernandez [Wed, 19 Oct 2022 15:14:02 +0000 (17:14 +0200)]
A false UNORDERED_<cond> means neither operand can be a NAN.

The false side of UNORDERED_<cond> means neither operand can be a NAN.
Adjust all the op[12]_range entries for the UNORDERED operators such
that a known NAN on one operands means the other operands is
undefined.

gcc/ChangeLog:

* range-op-float.cc (foperator_unordered_le::op1_range): Adjust
false side with a NAN operand.
(foperator_unordered_le::op2_range): Same.
(foperator_unordered_gt::op1_range): Same.
(foperator_unordered_gt::op2_range): Same.
(foperator_unordered_ge::op1_range): Same.
(foperator_unordered_ge::op2_range): Same.
(foperator_unordered_equal::op1_range): Same.

20 months agoc++ modules: handle CONCEPT_DECL in node_template_info [PR102963]
Patrick Palka [Thu, 20 Oct 2022 15:33:39 +0000 (11:33 -0400)]
c++ modules: handle CONCEPT_DECL in node_template_info [PR102963]

Here node_template_info is overlooking that CONCEPT_DECL has TEMPLATE_INFO
too, which causes get_originating_module_decl for the CONCEPT_DECL to not
return the corresponding TEMPLATE_DECL, which leads to an ICE from
import_entity_index while pretty printing the CONCEPT_DECL's module
suffix as part of the static assert failure elaboration.

PR c++/102963

gcc/cp/ChangeLog:

* module.cc (node_template_info): Handle CONCEPT_DECL.

gcc/testsuite/ChangeLog:

* g++.dg/modules/concept-7_a.C: New test.
* g++.dg/modules/concept-7_b.C: New test.

20 months agovect: Fix vectype when widening container type in bitfield pattern [PR107326]
Andre Vieira [Thu, 20 Oct 2022 14:54:39 +0000 (15:54 +0100)]
vect: Fix vectype when widening container type in bitfield pattern [PR107326]

The 'vect_recog_bitfield_ref_pattern' was not correctly adapting the vectype
when widening the container.

gcc/ChangeLog:

PR tree-optimization/107326
* tree-vect-patterns.cc (vect_recog_bitfield_ref_pattern): Change
vectype when widening container.

gcc/testsuite/ChangeLog:

* gcc.dg/vect/pr107326.c: New test.
* gcc.dg/vect/vect-bitfield-read-7.c: New test.

20 months agolibstdc++: Redefine __from_chars_alnum_to_val's table
Patrick Palka [Thu, 20 Oct 2022 14:30:31 +0000 (10:30 -0400)]
libstdc++: Redefine __from_chars_alnum_to_val's table

After the C++23 constexpr <charconv> patch r13-3313-g378a0f1840e694 we
have some modules testsuite regressions:

  FAIL: g++.dg/modules/xtreme-header-4_b.C -std=c++2b (test for excess errors)
  FAIL: g++.dg/modules/xtreme-header_b.C -std=c++2b (test for excess errors)

Like with PR105297, the cause seems to be the deduced type of __table
resolving ahead of time to a local class type, which trips up modules.
And unfortunately that PR's minimal workaround of making __tables's
initializer value dependent doesn't help in this case.

So this patch works around this by avoiding using a local class for the
table type.  And I suppose we should use a static data member to define
the table once for all dialects (including C++14) instead of having to
define it twice in C++23 mode (once as a static local variable and again
as a variable template for sake of constexpr evaluation).

libstdc++-v3/ChangeLog:

* include/std/charconv (__detail::__from_chars_alnum_to_val_table):
Redefine as a class template containing the members type, value and
_S_make_table.  Don't use a local class as the table type.
(__detail::__table): Remove.
(__detail::__from_chars_alnum_to_val): Adjust after the above.

20 months agoDo not set NAN flags for VARYING ranges when !HONOR_NANS.
Aldy Hernandez [Thu, 20 Oct 2022 06:55:36 +0000 (08:55 +0200)]
Do not set NAN flags for VARYING ranges when !HONOR_NANS.

Since NANs can't appear in ranges for !HONOR_NANS, there's no reason
to set them in a VARYING range.

gcc/ChangeLog:

* value-range.h (frange::set_varying): Do not set NAN flags for
!HONOR_NANS.
* value-range.cc (frange::normalize_kind): Adjust for no NAN when
!HONOR_NANS.
(frange::verify_range): Same.
* range-op-float.cc (maybe_isnan): Remove flag_finite_math_only check.

20 months agoReplace finite_operands_p with maybe_isnan.
Aldy Hernandez [Wed, 19 Oct 2022 17:28:09 +0000 (19:28 +0200)]
Replace finite_operands_p with maybe_isnan.

The finite_operands_p function was incorrectly named, as it only
returned TRUE when !NAN.  This was leftover from the initial
implementation of frange.  Using the maybe_isnan() nomenclature is
more consistent and easier to understand.

gcc/ChangeLog:

* range-op-float.cc (finite_operand_p): Remove.
(finite_operands_p): Rename to...
(maybe_isnan): ...this.
(frelop_early_resolve): Use maybe_isnan instead of finite_operands_p.
(foperator_equal::fold_range): Same.
(foperator_equal::op1_range): Same.
(foperator_not_equal::fold_range): Same.
(foperator_lt::fold_range): Same.
(foperator_le::fold_range): Same.
(foperator_gt::fold_range): Same.
(foperator_ge::fold_range): Same.

20 months agotestsuite: Add some missing -Wno-psabi options
Jakub Jelinek [Thu, 20 Oct 2022 11:58:13 +0000 (13:58 +0200)]
testsuite: Add some missing -Wno-psabi options

The following testcases FAIL on i686-linux due to excess diagnostics
for -Wpsabi.

2022-10-20  Jakub Jelinek  <jakub@redhat.com>

* gcc.target/i386/pr107271.c: Add -Wno-psabi to dg-options.
* gcc.dg/debug/btf/btf-function-3.c: Likewise.

20 months agopasses: Fix a comment typo
Jakub Jelinek [Thu, 20 Oct 2022 11:55:35 +0000 (13:55 +0200)]
passes: Fix a comment typo

This patch fixes a single typo in comment.

2022-10-20  Jakub Jelinek  <jakub@redhat.com>

* passes.cc (pass_manager::register_pass): Fix a comment
typo - copmilation -> compilation.

20 months agolibgomp: Add offload_device_gcn check, add requires-4a.c test
Tobias Burnus [Thu, 20 Oct 2022 10:58:52 +0000 (12:58 +0200)]
libgomp: Add offload_device_gcn check, add requires-4a.c test

Duplicate libgomp.c-c++-common/requires-4.c (as ...-4a.c) but
with using a heap-allocated instead of static memory for a variable.

This change and the added offload_device_gcn check prepare for
pseudo-USM, where the device hardware cannot access all host
memory but only managed and pinned memory; for those, requires-4.c
will fail and the new check permits to add
  target { ! { offload_device_nvptx || offload_device_gcn } }
to requires-4.c; however, it has not been added yet as pseuo-USM
support is not yet on mainline. (Review is pending for the USM
patches.)

include/ChangeLog:

* gomp-constants.h (GOMP_DEVICE_HSA): Comment out unused define.

libgomp/ChangeLog:

* testsuite/lib/libgomp.exp (check_effective_target_offload_device_gcn):
New.
* testsuite/libgomp.c-c++-common/on_device_arch.h (device_arch_gcn,
on_device_arch_gcn): New.
* testsuite/libgomp.c-c++-common/requires-4a.c: New test; copied from
requires-4.c but using heap-allocated memory.

20 months agoAvoid PHI - PHI recurrence in vectorization
Richard Biener [Thu, 20 Oct 2022 09:04:21 +0000 (11:04 +0200)]
Avoid PHI - PHI recurrence in vectorization

The reported regression of libgomp loop-14.C shows that there isn't
generally a good reliable place to insert the permute upfront so
the following simply restricts recurrence vectorization to the cases
where the latch value isn't defined by a PHI.

* tree-vect-loop.cc (vect_phi_first_order_recurrence_p):
Disallow latch PHI defs.
(vectorizable_recurr): Revert previous change.

20 months agoAdd 'libgomp.oacc-c-c++-common/private-big-1.c' [PR105421]
Thomas Schwinge [Mon, 17 Oct 2022 22:13:47 +0000 (00:13 +0200)]
Add 'libgomp.oacc-c-c++-common/private-big-1.c' [PR105421]

After commit r13-3404-g7c55755d4c760de326809636531478fd7419e1e5
"amdgcn: Use FLAT addressing for all functions with pointer arguments [PR105421]",
"big" private data now works for GCN offloading, too.

PR target/105421
libgomp/
* testsuite/libgomp.oacc-c-c++-common/private-big-1.c: New.

20 months agoamdgcn: Use FLAT addressing for all functions with pointer arguments [PR105421]
Julian Brown [Fri, 14 Oct 2022 11:06:07 +0000 (11:06 +0000)]
amdgcn: Use FLAT addressing for all functions with pointer arguments [PR105421]

The GCN backend uses a heuristic to determine whether to use FLAT or
GLOBAL addressing in a particular (offload) function: namely, if a
function takes a pointer-to-scalar parameter, it is assumed that the
pointer may refer to "flat scratch" space, and thus FLAT addressing must
be used instead of GLOBAL.

I came up with this heuristic initially whilst working on support for
moving OpenACC gang-private variables into local-data share (scratch)
memory. The assumption that only scalar variables would be transformed in
that way turned out to be wrong.  For example, prior to the next patch in
the series, Fortran compiler-generated temporary structures were treated
as gang private and moved to LDS space, typically overflowing the region
allocated for such variables.  That will no longer happen after that
patch is applied, but there may be other cases of structs moving to LDS
space now or in the future that this patch may be needed for.

2022-10-14  Julian Brown  <julian@codesourcery.com>

PR target/105421
gcc/
* config/gcn/gcn.cc (gcn_detect_incoming_pointer_arg): Any pointer
argument forces FLAT addressing mode, not just
pointer-to-non-aggregate.

20 months agoMake 'autoreconf' work for 'gcc', 'libobjc'
Thomas Schwinge [Tue, 20 Sep 2022 12:27:05 +0000 (14:27 +0200)]
Make 'autoreconf' work for 'gcc', 'libobjc'

With that, we may then run plain 'autoreconf' for all of GCC's subpackages,
instead of for some of those (that don't use Automake) manually having to run
the applicable combination of 'aclocal', 'autoconf', 'autoheader'.

See also 'AC_CONFIG_MACRO_DIRS'/'AC_CONFIG_MACRO_DIR' usage elsewhere.

gcc/
* configure.ac (AC_CONFIG_MACRO_DIRS): Instantiate.
* configure: Regenerate.
libobjc/
* configure.ac (AC_CONFIG_MACRO_DIRS): Instantiate.
* configure: Regenerate.

20 months agoaarch64: Commonise some folding code
Richard Sandiford [Thu, 20 Oct 2022 09:37:35 +0000 (10:37 +0100)]
aarch64: Commonise some folding code

Add an aarch64_sve::gimple_folder helper for folding calls
to integer constants.  SME will make more use of this.

gcc/
* config/aarch64/aarch64-sve-builtins.h
(gimple_folder::fold_to_cstu): New member function.
* config/aarch64/aarch64-sve-builtins.cc
(gimple_folder::fold_to_cstu): Define.
* config/aarch64/aarch64-sve-builtins-base.cc
(svcnt_bhwd_impl::fold): Use it.

20 months agoaarch64: Use using directives to inherit constructors
Richard Sandiford [Thu, 20 Oct 2022 09:37:34 +0000 (10:37 +0100)]
aarch64: Use using directives to inherit constructors

Now that the codebase is C++11, we can use using directives
to inherit constructors from base classes.

gcc/
* config/aarch64/aarch64-sve-builtins-functions.h (quiet)
(rtx_code_function, rtx_code_function_rotated, unspec_based_function)
(unspec_based_function_rotated, unspec_based_function_exact_insn)
(unspec_based_fused_function, unspec_based_fused_lane_function):
Replace constructors with using directives.
* config/aarch64/aarch64-sve-builtins-base.cc (svcnt_bhwd_pat_impl)
(svcreate_impl, svdotprod_lane_impl, svget_impl, svld1_extend_impl)
(svld1_gather_extend_impl, svld234_impl, svldff1_gather_extend)
(svset_impl, svst1_scatter_truncate_impl, svst1_truncate_impl)
(svst234_impl, svundef_impl): Likewise.
* config/aarch64/aarch64-sve-builtins-sve2.cc
(svldnt1_gather_extend_impl, svmovl_lb_impl): Likewise.
(svstnt1_scatter_truncate_impl): Likewise.

20 months agoaarch64: Replace CONSTEXPR with constexpr
Richard Sandiford [Thu, 20 Oct 2022 09:37:34 +0000 (10:37 +0100)]
aarch64: Replace CONSTEXPR with constexpr

Move away from the pre-C++11 compatibility macro CONSTEXPR.

gcc/
* config/aarch64/aarch64-sve-builtins-base.cc: Replace CONSTEXPR
with constexpr throughout.
* config/aarch64/aarch64-sve-builtins-functions.h: Likewise.
* config/aarch64/aarch64-sve-builtins-shapes.cc: Likewise.
* config/aarch64/aarch64-sve-builtins-sve2.cc: Likewise.
* config/aarch64/aarch64-sve-builtins.cc: Likewise.

20 months agoaarch64: Prevent generation of /M BRKAS and BRKBS
Richard Sandiford [Thu, 20 Oct 2022 09:37:33 +0000 (10:37 +0100)]
aarch64: Prevent generation of /M BRKAS and BRKBS

Bit of a brown-paper-bag bug, but: GCC was generating
non-existent merging forms of BRKAS and BRKBS.  Those
instructions only support zero predication (although
BRKA and BRKB support both).

gcc/
* config/aarch64/aarch64-sve.md (*aarch64_brk<brk_op>_cc): Remove
merging alternative.
(*aarch64_brk<brk_op>_ptest): Likewise.

gcc/testsuite/
* gcc.target/aarch64/sve/acle/general/brka_1.c: Expect a separate
PTEST instruction.
* gcc.target/aarch64/sve/acle/general/brkb_1.c: Likewise.

20 months agoaarch64: Fix matching of BRKNS
Richard Sandiford [Thu, 20 Oct 2022 09:37:33 +0000 (10:37 +0100)]
aarch64: Fix matching of BRKNS

Unlike other flag-setting SVE instructions, BRKNS sets the flags
based on an all-true governing predicate, rather than the GP operand.

gcc/
* config/aarch64/iterators.md (SVE_BRKP): New iterator.
* config/aarch64/aarch64-sve.md (*aarch64_brkn_cc): New pattern.
(*aarch64_brkn_ptest): Likewise.
(*aarch64_brk<brk_op>_cc): Restrict to SVE_BRKP.
(*aarch64_brk<brk_op>_ptest): Likewise.

gcc/testsuite/
* gcc.target/aarch64/sve/acle/general/brkn_1.c: Expect separate
PTEST instructions.
* gcc.target/aarch64/sve/acle/general/brkn_2.c: New test.

20 months agoc/107305 - avoid ICEing with invalid GIMPLE input to the GIMPLE FE
Richard Biener [Wed, 19 Oct 2022 12:12:11 +0000 (14:12 +0200)]
c/107305 - avoid ICEing with invalid GIMPLE input to the GIMPLE FE

The GIMPLE FE was designed to defer semantic error checking to the
GIMPLE IL verifier.  But that can end up causing spurious ICEs
earlier and in fact it will report an internal error.  The following
tries to improve the situation by explicitely calling into the
verifier from the parser and intructing it to not ICE but instead
zap the parsed body after an error is discovered.

PR c/107305
PR c/107306
gcc/c/
* gimple-parser.cc (c_parser_parse_gimple_body): Verify
the parsed IL and zap the body on error.

gcc/
* tree-cfg.h (verify_gimple_in_seq): Add parameter to
indicate whether to emit an ICE.  Add return value.
(verify_gimple_in_cfg): Likewise.
* tree-cfg.cc (verify_gimple_in_seq): Likewise.
(verify_gimple_in_cfg): Likewise.

gcc/testsuite/
* gcc.dg/gimplefe-error-15.c: New testcase.

20 months agovect: Simplify first for shifted value generation [PR107240]
Kewen Lin [Thu, 20 Oct 2022 09:07:05 +0000 (04:07 -0500)]
vect: Simplify first for shifted value generation [PR107240]

As PR107240 shows, when both the value to be shifted and the
count used for shifting are constants, it can be simplified
to one constant value, and doesn't actually require to check
if the current target supports vector shift operations or not.

This patch uses a canonical way proposed by Richi to generate
the shifted value, if it can be simplified, the shift operation
would be gone, otherwise it's the same as before.

It can help to fix the failures of vect-bitfield-write-{2,3}.c
on Power.

PR tree-optimization/107240

2022-10-20  Richard Biener  <rguenther@suse.de>

gcc/ChangeLog:

* tree-vect-patterns.cc (vect_recog_bit_insert_pattern): Attempt to
simplify shifted value first.

20 months agoAdd C++ library interface data
Ulrich Drepper [Thu, 20 Oct 2022 08:50:23 +0000 (10:50 +0200)]
Add C++ library interface data

This patch adds a CSV file with information about the API of the
standard C++ library.  This information can be used in multiple ways.
So far there are two use cases:

- to generate the module export list for the standard C++ library
- to create the name hints to compiler emits when symbols in the
  std namespace are not found

Adding more uses can be easily done by potentially adding more columns
to the CSV file and adding to the Python script which generates the
output file.

contrib/
2022-10-18  Jonathan Wakely   <jwakely@redhat.com>
    Ulrich Drepper  <drepper@redhat.com>

* gcc_update: Add rule for gcc/cp/std-name-hint.gperf.

gcc/cp/
2022-10-18  Jonathan Wakely   <jwakely@redhat.com>
    Ulrich Drepper  <drepper@redhat.com>

* Make-lang.in: Add rules to generate std-name-hint.gperf.  Adjust
rule to generate std-name-hint.h to allow chain rule.
* std-name-hint.h: Regenerated.
* std-name-hint.gperf: This file is now generated.
* cxxapi-data.csv: New file.  CSV file with C++ API data.
* gen-cxxapi-file.py: New file.  Generate std-name-hint.gperf
and module export source (in future).

20 months agoAdd assume support to VRP.
Andrew MacLeod [Tue, 18 Oct 2022 20:29:49 +0000 (16:29 -0400)]
Add assume support to VRP.

This provides an assume_query class using rangers GORI module to
determine what ranges would be applied to any SSA NAMES in the function
if the return value were [1, 1].  Any parameter ranges are stored in
the SSA_NAME_RANGE_INFO field, and ranger's inferred range machinery is
then used to look these up and match them to assume call parameteres
in the bodies of other functions..

        PR c++/106654
gcc/
* gimple-range-gori.h (compute_operand_range): Make public.
* gimple-range-infer.cc (gimple_infer_range::check_assume_func): New.
(gimple_infer_range::gimple_infer_range): Check for assume calls.
* gimple-range-infer.h (check_assume_func): Add prototype.
* gimple-range.cc (assume_query::assume_range_p): New.
(assume_query::range_of_expr): New.
(assume_query::assume_query): New.
(assume_query::calculate_op): New.
(assume_query::calculate_phi): New.
(assume_query::check_taken_edge): New.
(assume_query::calculate_stmt): New.
(assume_query::dump): New.
* gimple-range.h (class assume_query): New.
* tree-vrp.cc (pass_assumptions::execute): Add processing.

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

20 months agoDaily bump.
GCC Administrator [Thu, 20 Oct 2022 00:17:52 +0000 (00:17 +0000)]
Daily bump.

20 months agoc: C2x %wN, %wfN format checking
Joseph Myers [Wed, 19 Oct 2022 21:55:27 +0000 (21:55 +0000)]
c: C2x %wN, %wfN format checking

C2x adds printf and scanf wN and wfN length modifiers (wN for
int_leastN_t / uint_leastN_t, also usable for intN_t and uintN_t which
are now required to be the same type as the "least" versions when both
are supported; wfN for int_fastN_t / uint_fastN_t).  Add corresponding
format checking support for those length modifiers, for all the
standard integer conversion speciciers plus the recommended integer
specifier %B.

Note that, as with the %b support, this only deals with format
checking, not other format handling elsewhere in the compiler (in
particular, it doesn't add any -Wformat-overflow support; cf. Frolov
Daniil's patch
<https://gcc.gnu.org/pipermail/gcc-patches/2022-September/600790.html>
adding such support for %b and %B, which I think is still pending
review).  And of course library support is a separate matter for each
library implementation (I hope to add corresponding glibc support in
due course).

None of the tables of format conversions for kinds of formats not
supporting the new length modifiers are updated; they don't need
updating because the entries not matching some length modifier listed
for that kind of format can never be accessed, and the tables
generally thus already only explicitly covered a sufficient initial
subsequence of the length modifiers, rather than listing a full 13
possibilities before this patch or 21 after it.  %w (as used for
HOST_WIDE_INT in GCC-internal formats) comes after the new modifiers
in the FMT_LEN_* enumeration, but that's not a problem because the
tables don't actually use FMT_LEN_w entries; rather, such entries get
rewritten at runtime once GCC knows the value of HOST_WIDE_INT in the
GCC it's compiling.

Bootstrapped with no regressions for x86_64-pc-linux-gnu.

gcc/c-family/
* c-format.h (enum format_lengths): Add FMT_LEN_w8, FMT_LEN_w16,
FMT_LEN_w32, FMT_LEN_w64, FMT_LEN_wf8, FMT_LEN_wf16, FMT_LEN_wf32
and FMT_LEN_wf64.
(NOARGUMENTS, NOLENGTHS): Update definitions.
(T_I8, T2X_I8, T_I16, T2X_I16, T_I32, T2X_I32, T_I64, T2X_I64)
(T_U8, T2X_U8, T_U16, T2X_U16, T_U32, T2X_U32, T_U64, T2X_U64)
(T_IF8, T2X_IF8, T_IF16, T2X_IF16, T_IF32, T2X_IF32, T_IF64)
(T2X_IF64, T_UF8, T2X_UF8, T_UF16, T2X_UF16, T_UF32, T2X_UF32)
(T_UF64, T2X_UF64): New macros.
* c-format.cc (printf_length_specs, scanf_length_specs): Add wN
and wfN length modifiers.
(print_char_table, scan_char_table): Add entries using wN and wfN
length modifiers.

gcc/testsuite/
* gcc.dg/format/format.h (int_least8_t, int_least16_t)
(int_least32_t, int_least64_t, uint_least8_t, uint_least16_t)
(uint_least32_t, uint_least64_t, int_fast8_t, int_fast16_t)
(int_fast32_t, int_fast64_t, uint_fast8_t, uint_fast16_t)
(uint_fast32_t, uint_fast64_t): New typedefs.
* gcc.dg/format/c11-printf-1.c, gcc.dg/format/c11-scanf-1.c,
gcc.dg/format/c2x-printf-1.c, gcc.dg/format/c2x-scanf-1.c,
gcc.dg/format/ext-9.c: Add tests using wN and wfN length
modifiers.

20 months agoAlways check result from build_<COND> in range-op-float.cc
Aldy Hernandez [Wed, 19 Oct 2022 15:05:39 +0000 (17:05 +0200)]
Always check result from build_<COND> in range-op-float.cc

A result of false from build_<COND> in range-ops means the result is
final and needs no further adjustments.  This patch documents this,
and changes all uses to check the result.  There should be no change
in functionality.

gcc/ChangeLog:

* range-op-float.cc (build_le): Document result.
(build_lt): Same.
(build_ge): Same.
(foperator_ge::op2_range): Check result of build_*.
(foperator_unordered_le::op1_range): Same.
(foperator_unordered_le::op2_range): Same.
(foperator_unordered_gt::op1_range): Same.
(foperator_unordered_gt::op2_range): Same.
(foperator_unordered_ge::op1_range): Same.
(foperator_unordered_ge::op2_range): Same.

20 months agoanalyzer: fix ICE on __builtin_ms_va_copy [PR105765]
David Malcolm [Wed, 19 Oct 2022 20:49:38 +0000 (16:49 -0400)]
analyzer: fix ICE on __builtin_ms_va_copy [PR105765]

gcc/analyzer/ChangeLog:
PR analyzer/105765
* varargs.cc (get_BT_VALIST_ARG): Rename to...
(get_va_copy_arg): ...this, and update logic for determining level
of indirection of va_copy's argument to use type of argument,
rather than looking at va_list_type_node, to correctly handle
__builtin_ms_va_copy.
(get_stateful_BT_VALIST_ARG): Rename to...
(get_stateful_va_copy_arg): ...this.
(va_list_state_machine::on_va_copy): Update for renaming.
(region_model::impl_call_va_copy): Likewise.

gcc/testsuite/ChangeLog:
PR analyzer/105765
* gcc.dg/analyzer/stdarg-1-ms_abi.c: New test, based on stdarg-1.c.
* gcc.dg/analyzer/stdarg-1-sysv_abi.c: Likewise.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
20 months agolibstdc++: Implement remaining P2474R2 changes to views::take/drop
Patrick Palka [Wed, 19 Oct 2022 19:43:13 +0000 (15:43 -0400)]
libstdc++: Implement remaining P2474R2 changes to views::take/drop

libstdc++-v3/ChangeLog:

* include/std/ranges (views::__detail::__is_repeat_view): Define
and later define a partial specialization.
(views::__detail::__take_of_repeat_view): Declare and later define.
(views::__detail::__drop_of_repeat_view): Likewise.
(views::_Take::operator()): Return a repeat_view if the argument
is a repeat_view as per P2474R2.
(views::_Drop::operator()): Likewise.
(repeat_view): Befriend __take/drop_of_repeat_view.
* testsuite/std/ranges/repeat/1.cc (test04): New test.

20 months agoc++: Mitigate -Wuseless-cast with classes [PR85043]
Marek Polacek [Tue, 18 Oct 2022 16:20:14 +0000 (12:20 -0400)]
c++: Mitigate -Wuseless-cast with classes [PR85043]

-Wuseless-cast (not part of -Wall/-Wextra) warns here:

  struct S { };
  void g (S&&);
  void f (S&& arg)
  {
    g (S(arg)); // warning: useless cast to type 'struct S'
  }

which is wrong: the code will not compile without the cast because
"arg" is an lvalue which cannot bind to S&&.

This patch disables the warning when an object that isn't a prvalue
is cast to a non-reference type.  Therefore we still warn about the
useless cast in "X(X{})".

PR c++/85043

gcc/cp/ChangeLog:

* typeck.cc (maybe_warn_about_useless_cast): Don't warn when
a glvalue is cast to a non-reference type.

gcc/ChangeLog:

* doc/invoke.texi: Update documentation of -Wuseless-cast.

gcc/testsuite/ChangeLog:

* g++.dg/warn/Wuseless-cast.C: Remove dg-warning.
* g++.dg/warn/Wuseless-cast3.C: New test.

20 months agotestsuite: Default make check-g++ vs. tests for newest C++ standard
Jakub Jelinek [Wed, 19 Oct 2022 16:55:46 +0000 (18:55 +0200)]
testsuite: Default make check-g++ vs. tests for newest C++ standard

When adding tests for upcoming C++ version, one always has a dilemma
whether to use explicit // { dg-options "-std=c++2b" }
or -std=gnu++2b and similar, then the test works in all modes, but it might
be forgotten later on to be converted into // { dg-do whatever { target c++23 } }
test so that when 23 is tested by default and say 26 or 29 appears too,
we test it also in those modes, or just go with
// { dg-do whatever { target c++23 } }
which has the disadvantage that it is skipped when testing by default and
one only tests it if he asks for the newer version.

The following patch changes it, such that it is safe to add
// { dg-do whatever { target c++23 } }
style tests and make those tested even in the default testing mode
(when GXX_TESTSUITE_STDS or check-c++-all etc. aren't used).
This is by searching for such dg-do lines and if there is an effective
target newer than the latest by default tested language version, it will
just use that language version instead of the default list.
Without this change, the test would be UNSUPPORTED in currently
all of 98 14 17 20 versions, with the patch it will be tested with a single
23 version.

2022-10-19  Jakub Jelinek  <jakub@redhat.com>

* lib/g++-dg.exp (g++-dg-runtest): When using defaulted
std_list, if test has { dg-do * { target c++23 } } directive,
use { 23 } with which the test will run instead of { 98 14 17 20 }
which would make it UNSUPPORTED in all cases.

20 months agolibstdc++: Fix typo in stride_view's operator- [PR107313]
Patrick Palka [Wed, 19 Oct 2022 17:03:25 +0000 (13:03 -0400)]
libstdc++: Fix typo in stride_view's operator- [PR107313]

PR libstdc++/107313

libstdc++-v3/ChangeLog:

* include/std/ranges (stride_view::_Iterator::operator-): Fix typo.
* testsuite/std/ranges/adaptors/stride/1.cc (test03): New test.

20 months agotestsuite: Fix up c2x-enum-1.c for 32-bit arches [PR107311]
Jakub Jelinek [Wed, 19 Oct 2022 16:49:03 +0000 (18:49 +0200)]
testsuite: Fix up c2x-enum-1.c for 32-bit arches [PR107311]

On Wed, Oct 19, 2022 at 02:57:59PM +0000, Joseph Myers wrote:
> I think the type checked for e5a should be conditional on __LONG_MAX__ >
> __INT_MAX__; everything else there should be OK regardless.

This patch does that.

2022-10-19  Jakub Jelinek  <jakub@redhat.com>

PR c/107311
* gcc.dg/c2x-enum-1.c (enum e5): Expect e5a type inside of
enum to be int rather than long if long isn't wider than int.

20 months agoUse Value_Range when applying inferred ranges.
Andrew MacLeod [Wed, 19 Oct 2022 13:21:22 +0000 (09:21 -0400)]
Use Value_Range when applying inferred ranges.

Applying an inferred range is using int_range_ma as the
temporary rather than the general purpose Value_Range.  This causes it
to trap if we have a non-integral inferred range.

* gimple-range-cache.cc (ranger_cache::range_from_dom): Use
  Value_Range not int_range_max.

20 months agolibstdc++/thread: Implement `_GLIBCXX_NPROCS` for Windows
LIU Hao [Sat, 1 Oct 2022 16:57:08 +0000 (00:57 +0800)]
libstdc++/thread: Implement `_GLIBCXX_NPROCS` for Windows

This makes `std::thread::hardware_concurrency()` return the number of
logical processors, instead of zero.

libstdc++-v3/ChangeLog:
* src/c++11/thread.cc (get_nprocs): Add new implementation
for native Windows targets

20 months ago[PR tree-optimization/107312] Make range_true_and_false work with 1-bit signed types.
Aldy Hernandez [Wed, 19 Oct 2022 12:27:46 +0000 (14:27 +0200)]
[PR tree-optimization/107312] Make range_true_and_false work with 1-bit signed types.

range_true_and_false() returns a range of [0,1], which for a 1-bit
signed integer gets passed to the irange setter as [0, -1].  These
endpoints are out of order and cause an ICE.  Through some dumb luck,
the legacy code swaps out of order endpoints, because old VRP would
sometimes pass endpoints reversed, depending on the setter to fix
them.  This swapping does not happen for non-legacy, hence the ICE.

The right thing to do (apart from killing legacy and 1-bit signed
integers ;-)), is to avoid passing out of order endpoints for 1-bit
signed integers.  For that matter, a range of [-1, 0] (signed) or
[0, 1] (unsigned) is just varying.

PR tree-optimization/107312

gcc/ChangeLog:

* range.h (range_true_and_false): Special case 1-bit signed types.
* value-range.cc (range_tests_misc): New test.

gcc/testsuite/ChangeLog:

* gcc.target/i386/pr107312.c: New test.

20 months agogcc: Add 'mcf' thread model support from mcfgthread
LIU Hao [Fri, 15 Apr 2022 16:46:23 +0000 (00:46 +0800)]
gcc: Add 'mcf' thread model support from mcfgthread

This patch adds the new thread model `mcf`, which implements mutexes
and condition variables with the mcfgthread library.

Source code for mcfgthread is available at <https://github.com/lhmouse/mcfgthread>.

config/ChangeLog:
* gthr.m4 (GCC_AC_THREAD_HEADER): Add new case for `mcf` thread
model

gcc/ChangeLog:
* config/i386/mingw-mcfgthread.h: New file
* config/i386/mingw32.h: Add builtin macro and default libraries
for mcfgthread when thread model is `mcf`
* config.gcc: Include 'i386/mingw-mcfgthread.h' when thread model
is `mcf`
* configure.ac: Recognize `mcf` as a valid thread model
* config.in: Regenerate
* configure: Regenerate

libatomic/ChangeLog:
* configure.tgt: Add new case for `mcf` thread model

libgcc/ChangeLog:
* config.host: Add new cases for `mcf` thread model
* config/i386/gthr-mcf.h: New file
* config/i386/t-mingw-mcfgthread: New file
* config/i386/t-slibgcc-cygming: Add mcfgthread for libgcc DLL
* configure: Regenerate

libstdc++-v3/ChangeLog:
* libsupc++/atexit_thread.cc (__cxa_thread_atexit): Use
implementation from mcfgthread if available
* libsupc++/guard.cc (__cxa_guard_acquire, __cxa_guard_release,
__cxa_guard_abort): Use implementations from mcfgthread if
available
* configure: Regenerate

20 months agopch: Fix streaming of strings with embedded null bytes
Lewis Hyatt [Fri, 14 Oct 2022 17:52:12 +0000 (13:52 -0400)]
pch: Fix streaming of strings with embedded null bytes

When a GTY'ed struct is streamed to PCH, any plain char* pointers it contains
(whether they live in GC-controlled memory or not) will be marked for PCH
output by the routine gt_pch_note_object in ggc-common.cc. This routine
special-cases plain char* strings, and in particular it uses strlen() to get
their length. Thus it does not handle strings with embedded null bytes, but it
is possible for something PCH cares about (such as a string literal token in a
macro definition) to contain such embedded nulls. To fix that up, add a new
GTY option "string_length" so that gt_pch_note_object can be informed the
actual length it ought to use, and use it in the relevant libcpp structs
(cpp_string and ht_identifier) accordingly.

gcc/ChangeLog:

* gengtype.cc (output_escaped_param): Add missing const.
(get_string_option): Add missing check for option type.
(walk_type): Support new "string_length" GTY option.
(write_types_process_field): Likewise.
* ggc-common.cc (gt_pch_note_object): Add optional length argument.
* ggc.h (gt_pch_note_object): Adjust prototype for new argument.
(gt_pch_n_S2): Declare...
* stringpool.cc (gt_pch_n_S2): ...new function.
* doc/gty.texi: Document new GTY((string_length)) option.

libcpp/ChangeLog:

* include/cpplib.h (struct cpp_string): Use new "string_length" GTY.
* include/symtab.h (struct ht_identifier): Likewise.

gcc/testsuite/ChangeLog:

* g++.dg/pch/pch-string-nulls.C: New test.
* g++.dg/pch/pch-string-nulls.Hs: New test.

20 months agoavr: remove useless @tie{} directives
Martin Liska [Wed, 19 Oct 2022 13:23:59 +0000 (15:23 +0200)]
avr: remove useless @tie{} directives

gcc/ChangeLog:

* doc/extend.texi: Remove useless @tie{} directives.

20 months agoSRA: Limit replacement creation for accesses propagated from LHSs
Martin Jambor [Wed, 19 Oct 2022 12:43:04 +0000 (14:43 +0200)]
SRA: Limit replacement creation for accesses propagated from LHSs

PR 107206 is fallout from the fix to PR 92706 where we started
propagating accesses across assignments also from LHS to RHS of
assignments so that we would not do harmful total scalarization of the
aggregates on the RHS.

But this can lead to new scalarization of these aggregates and in the
testcase of PR 107206 these can appear in superfluous uses of
un-initialized values and spurious warnings.

Fixed by making sure the the accesses created by propagation in this
direction are only used as a basis for replacements when the structure
would be totally scalarized anyway.

gcc/ChangeLog:

2022-10-18  Martin Jambor  <mjambor@suse.cz>

PR tree-optimization/107206
* tree-sra.cc (struct access): New field grp_result_of_prop_from_lhs.
(analyze_access_subtree): Do not create replacements for accesses with
this flag when not toally scalarizing.
(propagate_subaccesses_from_lhs): Set the new flag.

gcc/testsuite/ChangeLog:

2022-10-18  Martin Jambor  <mjambor@suse.cz>

PR tree-optimization/107206
* g++.dg/tree-ssa/pr107206.C: New test.

20 months agoIBM zSystems: Fix function_ok_for_sibcall [PR106355]
Stefan Schulze Frielinghaus [Wed, 19 Oct 2022 12:28:22 +0000 (14:28 +0200)]
IBM zSystems: Fix function_ok_for_sibcall [PR106355]

For a parameter with BLKmode we cannot use REG_NREGS in order to
determine the number of consecutive registers.  Streamlined this with
the implementation of s390_function_arg.

Fix some indentation whitespace, too.

gcc/ChangeLog:

PR target/106355
* config/s390/s390.cc (s390_call_saved_register_used): For a
parameter with BLKmode fix determining number of consecutive
registers.

gcc/testsuite/ChangeLog:

* gcc.target/s390/pr106355.h: Common code for new tests.
* gcc.target/s390/pr106355-1.c: New test.
* gcc.target/s390/pr106355-2.c: New test.
* gcc.target/s390/pr106355-3.c: New test.

20 months agoxtensa: Prepare the transition from Reload to LRA
Takayuki 'January June' Suwa [Wed, 19 Oct 2022 08:16:24 +0000 (17:16 +0900)]
xtensa: Prepare the transition from Reload to LRA

This patch provides the first step in the transition from Reload to LRA
in Xtensa.

gcc/ChangeLog:

* config/xtensa/xtensa-protos.h
(xtensa_split1_finished_p, xtensa_split_DI_reg_imm): New prototypes.
* config/xtensa/xtensa.cc
(xtensa_split1_finished_p, xtensa_split_DI_reg_imm, xtensa_lra_p):
New functions.
(TARGET_LRA_P): Replace the dummy hook with xtensa_lra_p.
(xt_true_regnum): Rework.
* config/xtensa/xtensa.h (CALL_REALLY_USED_REGISTERS):
Switch from CALL_USED_REGISTERS, and revise the comment.
* config/xtensa/constraints.md (Y):
Use !xtensa_split1_finished_p() instead of can_create_pseudo_p().
* config/xtensa/predicates.md (move_operand): Ditto.
* config/xtensa/xtensa.md: Add two new split patterns:
  - splits DImode immediate load into two SImode ones
  - puts out-of-constraint SImode constants into the constant pool
* config/xtensa/xtensa.opt (-mlra): New target-specific option
for testing purpose.

20 months agos390: Fix bootstrap error with checking and -m31.
Robin Dapp [Tue, 18 Oct 2022 10:27:37 +0000 (12:27 +0200)]
s390: Fix bootstrap error with checking and -m31.

For a while already we hit an ICE when bootstrapping with -m31 and
--enable-checking=all.

../../../../libgfortran/ieee/ieee_helper.c: In function 'ieee_class_helper_16':
../../../../libgfortran/ieee/ieee_helper.c:77:3: internal compiler error: RTL check: expected code 'reg', have 'subreg' in rhs_regno, at rtl.h:1932
   77 |   }
      |   ^
../../../../libgfortran/ieee/ieee_helper.c:87:1: note: in expansion of macro 'CLASSMACRO'
   87 | CLASSMACRO(16)
      | ^~~~~~~~~~

This patch fixes the problem by first checking for reload_completed
and also ensuring that REGNO is only called on reg operands rather
than subregs.

gcc/ChangeLog:

* config/s390/s390.md: Move reload_completed and check operands for REG_P.

20 months agoexpr: Fix ICE on BFmode -> SFmode conversion of constant [PR107262]
Jakub Jelinek [Wed, 19 Oct 2022 09:29:44 +0000 (11:29 +0200)]
expr: Fix ICE on BFmode -> SFmode conversion of constant [PR107262]

I forgot to handle the case where lowpart_subreg returns a VOIDmode
CONST_INT, in that case convert_mode_scalar obviously doesn't work.

The following patch fixes that.

2022-10-19  Jakub Jelinek  <jakub@redhat.com>

PR middle-end/107262
* expr.cc (convert_mode_scalar): For BFmode -> SFmode conversions
of constants, use simplify_unary_operation if fromi has VOIDmode
instead of recursive convert_mode_scalar.

* gcc.dg/pr107262.c: New test.

20 months agomatch.pd: Add 2 TYPE_OVERFLOW_SANITIZED checks [PR106990]
Jakub Jelinek [Wed, 19 Oct 2022 09:28:42 +0000 (11:28 +0200)]
match.pd: Add 2 TYPE_OVERFLOW_SANITIZED checks [PR106990]

As requested in the PR, this adds 2 TYPE_OVERFLOW_SANITIZED checks
and corresponding testcase.

2022-10-19  Jakub Jelinek  <jakub@redhat.com>

PR tree-optimization/106990
* match.pd ((~X - ~Y) -> Y - X, -x & 1 -> x & 1): Guard with
!TYPE_OVERFLOW_SANITIZED (type).

* c-c++-common/ubsan/pr106990.c: New test.

20 months agolibstdc++-v3: Implement {,b}float16_t nextafter and some fixes [PR106652]
Jakub Jelinek [Wed, 19 Oct 2022 09:25:03 +0000 (11:25 +0200)]
libstdc++-v3: Implement {,b}float16_t nextafter and some fixes [PR106652]

The following patch implements nextafter for std::{,b}float16_t,
though right now only without constexpr support, and adds a testcase for it.
The testcase unfortunately relevealed I've screwed up testing of my last
patch.  I've tested earlier version of the patch with
--target_board=unix/-std=c++23
but didn't test the final version with that RUNTESTFLAGS, so missed
an invalid call to std::sph_neumann (too many arguments) in the test.
And, I've made a typo in the guard for numeric_limits (the reason
for the guard is I wanted to avoid defining a large macro that nothing
will then use because the std::{,b}float*_t types are C++23 only) and
so numeric_limits wasn't specialized for the types at all but
testsuite/18_support/headers/limits/synopsis_cxx23.cc test didn't
detect that.
In the nextafter implementation I'm calling __builtin_nextafterf
to get various required side-effects for nextafter from 0/-0, or from max
to inf or from min to largest subnormal to avoid needing to set errno
inline, or use inline asm specific for each processor to force math
evaluation barriers.  Dunno if
  #ifdef __INT16_TYPE__
    using __float16_int_type = __INT16_TYPE__;
  #else
    using __float16_int_type = short int;
  #endif
isn't too ugly, perhaps we could just blindly use short int and hope
or even assert it has the same size as _Float16 or __gnu_cxx::__bfloat16_t?
Only aarch64, arm, csky, gcn, x86, nvptx and riscv support these types
and all of them have 16-bit short (I think the only target with some
other short size is avr with certain command line switches where both
short and int are 8-bit, but such mode isn't compatible with C and C++
requirements).

2022-10-19  Jakub Jelinek  <jakub@redhat.com>

PR c++/106652
* include/std/limits: Fix a typo, 202202L -> 202002L.
(numeric_limits::<_Float16>::radix, numeric_limits::<_Float32>::radix,
numeric_limits::<_Float64>::radix, numeric_limits::<_Float128>::radix,
numeric_limits::<__gnu_cxx::__bfloat16_t>::radix): Use __FLT_RADIX__
macro instead of type specific macros.
* include/c_global/cmath (nextafter(_Float16, _Float16)): New
overload.
(nextafter(__gnu_cxx::__bfloat16_t, __gnu_cxx::__bfloat16_t)):
Likewise.
* testsuite/26_numerics/headers/cmath/functions_std_c++23.cc
(test_functions): Uncomment nextafter test.  Fix up sph_neumann call.
* testsuite/26_numerics/headers/cmath/nextafter_c++23.cc: New test.

20 months agoi386: Fix up __bf16 handling on ia32
Jakub Jelinek [Wed, 19 Oct 2022 09:22:53 +0000 (11:22 +0200)]
i386: Fix up __bf16 handling on ia32

Last night's testing of the libstdc++ changes revealed a problem
in the __bf16 backend registration (while _Float16 seems ok).
The problem is that for both BFmode and HFmode we require TARGET_SSE2,
the generic code creates {,b}float16_type_node only if that is true
at the start of the TU and the builtins for the type are only
created in that case (many __builtin_*f16 for HFmode and __builtin_nansf16b
for BFmode).  Now, for _Float16 I've kept what the code did previously,
if float16_type_node from generic code is NULL, create ix86_float16_type_node
and register _Float16 for it, but for __bf16 I've changed it so that
if bfloat16_type_node from generic code is NULL,
ix86_register_bf16_builtin_type makes bfloat16_type_node non-NULL.
This has an unfortunate consequence though, __STDCPP_BFLOAT16_T__ is
predefined for C++23, __BFLT16_*__ macros are predefined as well, but
the type doesn't really work (errors whenever it is used) and the builtin
isn't defined.

The following patch fixes that by going with what we do for HFmode,
bfloat16_type_node stays as initialized by generic code and we have a local
type for backend use.  On the other side, nothing used ix86_bf16_ptr_type_node
so that is now dropped.

2022-10-19  Jakub Jelinek  <jakub@redhat.com>

* config/i386/i386-builtins.cc (ix86_bf16_ptr_type_node): Remove.
(ix86_bf16_type_node): New variable.
(ix86_register_bf16_builtin_type): If bfloat16_type_node is NULL
from generic code, set only ix86_bf16_type_node to a new REAL_TYPE
rather than bfloat16_type_node, otherwise set ix86_bf16_type_node
to bfloat16_type_node.  Register __bf16 on ix86_bf16_type_node
rather than bfloat16_type_node.  Don't initialize unused
ix86_bf16_ptr_type_node.
* config/i386/i386-builtin-types.def (BFLOAT16): Use
ix86_bf16_type_node rather than bfloat16_type_node.

20 months agotree-optimization/106781 - adjust cgraph lhs removal
Richard Biener [Wed, 19 Oct 2022 07:01:56 +0000 (09:01 +0200)]
tree-optimization/106781 - adjust cgraph lhs removal

The following matches up the cgraph code removing LHS of a noreturn
call with what fixup_noreturn_call does which gets along without
inserting a definition, fixing the ICE resulting from having no
place to actually insert that new def.

PR tree-optimization/106781
* cgraph.cc (cgraph_edge::redirect_call_stmt_to_callee): Copy
LHS removal from fixup_noreturn_call.

* gcc.dg/pr106781.c: New testcase.

20 months agolibsanitizer: regenerate configure
Martin Liska [Wed, 19 Oct 2022 06:44:20 +0000 (08:44 +0200)]
libsanitizer: regenerate configure

libsanitizer/ChangeLog:

* configure: Regenerate.

20 months agoCanonicalize vec_perm index to make the first index come from the first vector.
liuhongt [Tue, 18 Oct 2022 08:58:52 +0000 (16:58 +0800)]
Canonicalize vec_perm index to make the first index come from the first vector.

Fix unexpected non-canon form from gimple vector selector.

gcc/ChangeLog:

PR target/107271
* config/i386/i386-expand.cc (ix86_vec_perm_index_canon): New.
(expand_vec_perm_shufps_shufps): Call
ix86_vec_perm_index_canon

gcc/testsuite/ChangeLog:

* gcc.target/i386/pr107271.c: New test.

20 months agoDaily bump.
GCC Administrator [Wed, 19 Oct 2022 00:19:08 +0000 (00:19 +0000)]
Daily bump.

20 months agoc: Diagnose "enum tag;" after definition [PR107164]
Joseph Myers [Tue, 18 Oct 2022 23:25:47 +0000 (23:25 +0000)]
c: Diagnose "enum tag;" after definition [PR107164]

As noted in bug 101764, a declaration "enum tag;" is invalid in
standard C after a definition, as well as when no definition is
visible; we had a pedwarn-if-pedantic for the forward declaration
case, but were missing one for the other case.  Add that missing
diagnostic (if pedantic only).

(These diagnostics will need to be appropriately conditioned when
support is added for C2x enums with fixed underlying type, since "enum
tag : type;" is OK both before and after a definition.)

Bootstrapped with no regressions for x86_64-pc-linux-gnu.

PR c/107164

gcc/c/
* c-decl.cc (shadow_tag_warned): If pedantic, diagnose "enum tag;"
with previous declaration visible.

gcc/testsuite/
* gcc.dg/c99-tag-4.c, gcc.dg/c99-tag-5.c, gcc.dg/c99-tag-6.c: New
tests.

20 months agotestsuite: Only run -fcf-protection test on i?86/x86_64 [PR107213]
Marek Polacek [Tue, 11 Oct 2022 16:51:40 +0000 (12:51 -0400)]
testsuite: Only run -fcf-protection test on i?86/x86_64 [PR107213]

This test fails on non-i?86/x86_64 targets because on those targets
we get

  error: '-fcf-protection=full' is not supported for this target

so this patch limits where the test is run.

PR testsuite/107213

gcc/testsuite/ChangeLog:

* c-c++-common/pointer-to-fn1.c: Only run on i?86/x86_64.

20 months agolibiberty: Fix C89-isms in configure tests
Florian Weimer [Tue, 18 Oct 2022 14:58:48 +0000 (16:58 +0200)]
libiberty: Fix C89-isms in configure tests

libiberty/

* acinclude.m4 (ac_cv_func_strncmp_works): Add missing
int return type and parameter list to the definition of main.
Include <stdlib.h> and <string.h> for prototypes.
(ac_cv_c_stack_direction): Add missing
int return type and parameter list to the definitions of
main, find_stack_direction.  Include <stdlib.h> for exit
prototype.
* configure: Regenerate.

20 months agolibsanitizer: Avoid implicit function declaration in configure test
Florian Weimer [Tue, 18 Oct 2022 14:58:48 +0000 (16:58 +0200)]
libsanitizer: Avoid implicit function declaration in configure test

libsanitizer/

* configure.ac (sanitizer_supported): Include <unistd.h> for
syscall prototype.
* configure: Regenerate.

20 months agoc++ modules: stream non-trailing default targs [PR105045]
Patrick Palka [Tue, 18 Oct 2022 14:57:30 +0000 (10:57 -0400)]
c++ modules: stream non-trailing default targs [PR105045]

This fixes the below testcase in which we neglect to stream the default
argument for T only because the subsequent parameter U doesn't also have
a default argument.

PR c++/105045

gcc/cp/ChangeLog:

* module.cc (trees_out::tpl_parms_fini): Don't assume default
template arguments must be trailing.
(trees_in::tpl_parms_fini): Likewise.

gcc/testsuite/ChangeLog:

* g++.dg/modules/pr105045_a.C: New test.
* g++.dg/modules/pr105045_b.C: New test.

20 months agolibstdc++: Implement ranges::stride_view from P1899R3
Patrick Palka [Tue, 18 Oct 2022 14:51:52 +0000 (10:51 -0400)]
libstdc++: Implement ranges::stride_view from P1899R3

libstdc++-v3/ChangeLog:

* include/std/ranges (stride_view): Define.
(stride_view::_Iterator): Define.
(views::__detail::__can_stride_view): Define.
(views::_Stride, views::stride): Define.
* testsuite/std/ranges/adaptors/stride/1.cc: New test.

20 months agoc: C2x enums wider than int [PR36113]
Joseph Myers [Tue, 18 Oct 2022 14:07:27 +0000 (14:07 +0000)]
c: C2x enums wider than int [PR36113]

C2x has two enhancements to enumerations: allowing enumerations whose
values do not all fit in int (similar to an existing extension), and
allowing an underlying type to be specified (as in C++).  This patch
implements the first of those enhancements.

Apart from adjusting diagnostics to reflect this being a standard
feature, there are some semantics differences from the previous
extension:

* The standard feature gives all the values of such an enum the
  enumerated type (while keeping type int if that can represent all
  values of the enumeration), where previously GCC only gave those
  values outside the range of int the enumerated type.  This change
  was previously requested in PR 36113; it seems unlikely that people
  are depending on the detail of the previous extension that some
  enumerators had different types to others depending on whether their
  values could be represented as int, and this patch makes the change
  to types of enumerators unconditionally (if that causes problems in
  practice we could always make it conditional on C2x mode instead).

* The types *while the enumeration is being defined*, for enumerators
  that can't be represented as int, are now based more directly on the
  types of the expressions used, rather than a possibly different type
  with the right precision constructed using c_common_type_for_size.
  Again, this change is made unconditionally.

* Where overflow (or wraparound to 0, in the case of an unsigned type)
  when 1 is implicitly added to determine the value of the next
  enumerator was previously an error, it now results in a wider type
  with the same signedness (as the while-being-defined type of the
  previous enumerator) being chosen, if available.

When a type is chosen in such an overflow case, or when a type is
chosen for the underlying integer type of the enumeration, it's
possible that (unsigned) __int128 is chosen.  Although C2x allows for
such types wider than intmax_t to be considered extended integer
types, we don't have various features required to do so (integer
constant suffixes; sufficient library support would also be needed to
define the associated macros for printf/scanf conversions, and
<stdint.h> typedef names would need to be defined).  Thus, there are
also pedwarns for exceeding the range of intmax_t / uintmax_t, as
while in principle exceeding that range is OK, it's only OK in a
context where the relevant types meet the requirements for extended
integer types, which does not currently apply here.

Bootstrapped with no regressions for x86_64-pc-linux-gnu.  Also
manually checked diagnostics for c2x-enum-3.c with -m32 to confirm the
diagnostics in that { target { ! int128 } } test are as expected.

PR c/36113

gcc/c-family/
* c-common.cc (c_common_type_for_size): Add fallback to
widest_unsigned_literal_type_node or
widest_integer_literal_type_node for precision that may not
exactly match the precision of those types.

gcc/c/
* c-decl.cc (finish_enum): If any enumerators do not fit in int,
convert all to the type of the enumeration.  pedwarn if no integer
type fits all enumerators and default to
widest_integer_literal_type_node in that case.  Otherwise pedwarn
for type wider than intmax_t.
(build_enumerator): pedwarn for enumerators outside the range of
uintmax_t or intmax_t, and otherwise use pedwarn_c11 for
enumerators outside the range of int.  On overflow, attempt to
find a wider type that can hold the value of the next enumerator.
Do not convert value to type determined with
c_common_type_for_size.

gcc/testsuite/
* gcc.dg/c11-enum-1.c, gcc.dg/c11-enum-2.c, gcc.dg/c11-enum-3.c,
gcc.dg/c2x-enum-1.c, gcc.dg/c2x-enum-2.c, gcc.dg/c2x-enum-3.c,
gcc.dg/c2x-enum-4.c, gcc.dg/c2x-enum-5.c: New tests.
* gcc.dg/pr30260.c: Explicitly use -std=gnu11.  Update expected
diagnostics.
* gcc.dg/torture/pr25183.c: Update expected diagnostics.

20 months agoipa-cp: Better representation of aggregate values in call contexts
Martin Jambor [Tue, 18 Oct 2022 12:14:26 +0000 (14:14 +0200)]
ipa-cp: Better representation of aggregate values in call contexts

This patch extends the previous one by using the same data structure
to represent aggregate values in classes ipa_auto_call_arg_values and
ipa_call_arg_values.

This usually simplifies handling and makes allocations of memory much
cheaper because only a single vectore is needed, as opposed to vectors
with each element pointing at other vecs.  The only functions which
unfortunately are a bit more complec are estimate_local_effects in
ipa-cp.cc and ipa_call_context::equal_to but I hope not too much - the
latter could probably be shorteneed at the expense of readability.

The patch removes types ipa_agg_value ipa_agg_value_set which is no
longer used with it.  This means that we could replace the "_argagg_"
part of the types introduced by the previous patches with more
reasonable "_agg_" - possibly as a follow-up patch.

gcc/ChangeLog:

2022-08-26  Martin Jambor  <mjambor@suse.cz>

* ipa-prop.h (ipa_agg_value): Remove type.
(ipa_agg_value_set): Likewise.
(ipa_copy_agg_values): Remove function.
(ipa_release_agg_values): Likewise.
(ipa_auto_call_arg_values) Add a forward declaration.
(ipa_call_arg_values): Likewise.
(class ipa_argagg_value_list): New constructors, added member function
value_for_index_p.
(class ipa_auto_call_arg_values): Removed the destructor and member
function safe_aggval_at.  Use ipa_argagg_values for m_known_aggs.
(class ipa_call_arg_values): Removed member function safe_aggval_at.
Use ipa_argagg_values for m_known_aggs.
(ipa_get_indirect_edge_target): Removed declaration.
(ipa_find_agg_cst_for_param): Likewise.
(ipa_find_agg_cst_from_init): New declaration.
(ipa_agg_value_from_jfunc): Likewise.
(ipa_agg_value_set_from_jfunc): Removed declaration.
(ipa_push_agg_values_from_jfunc): New declaration.
* ipa-cp.cc (ipa_agg_value_from_node): Renamed to
ipa_agg_value_from_jfunc, made public.
(ipa_agg_value_set_from_jfunc): Removed.
(ipa_push_agg_values_from_jfunc): New function.
(ipa_get_indirect_edge_target_1): Removed known_aggs parameter, use
avs for this purpose too.
(ipa_get_indirect_edge_target): Removed the overload working on
ipa_auto_call_arg_values, use ipa_argagg_value_list in the remaining
one.
(devirtualization_time_bonus): Use ipa_argagg_value_list and
ipa_get_indirect_edge_target_1 instead of
ipa_get_indirect_edge_target.
(context_independent_aggregate_values): Removed function.
(gather_context_independent_values): Work on ipa_argagg_value_list.
(estimate_local_effects): Likewise, define some iterator variables
only in the construct where necessary.
(ipcp_discover_new_direct_edges): Adjust the call to
ipa_get_indirect_edge_target_1.
(push_agg_values_for_index_from_edge): Adjust the call
ipa_agg_value_from_node which has been renamed to
ipa_agg_value_from_jfunc.
* ipa-fnsummary.cc (evaluate_conditions_for_known_args): Work on
ipa_argagg_value_list.
(evaluate_properties_for_edge): Replace manual filling in aggregate
values with call to ipa_push_agg_values_from_jfunc.
(estimate_calls_size_and_time): Work on ipa_argagg_value_list.
(ipa_cached_call_context::duplicate_from): Likewise.
(ipa_cached_call_context::release): Likewise.
(ipa_call_context::equal_to): Likewise.
* ipa-prop.cc (ipa_find_agg_cst_from_init): Make public.
(ipa_find_agg_cst_for_param): Removed function.
(ipa_find_agg_cst_from_jfunc_items): New function.
(try_make_edge_direct_simple_call): Replace calls to
ipa_agg_value_set_from_jfunc and ipa_find_agg_cst_for_param with
ipa_find_agg_cst_from_init and ipa_find_agg_cst_from_jfunc_items.
(try_make_edge_direct_virtual_call): Replace calls to
ipa_agg_value_set_from_jfunc and ipa_find_agg_cst_for_param with
simple query of constant jump function and a call to
ipa_find_agg_cst_from_jfunc_items.
(ipa_auto_call_arg_values::~ipa_auto_call_arg_values): Removed.

20 months agoipa-cp: Better representation of aggregate values we clone for
Martin Jambor [Tue, 18 Oct 2022 12:14:26 +0000 (14:14 +0200)]
ipa-cp: Better representation of aggregate values we clone for

This patch replaces linked lists of ipa_agg_replacement_value with
vectors of similar structures called ipa_argagg_value and simplifies
how we compute them in the first place.  Having a vector should also
result in less overhead when allocating and because we keep it sorted,
it leads to logarithmic searches.

The slightly obnoxious "argagg" bit in the name can be changed into
"agg" after the next patch removes our current ipa_agg_value type.

The patch also introduces type ipa_argagg_value_list which serves as a
common view into a vector of ipa_argagg_value structures regardless
whether they are stored in GC memory (required for IPA-CP
transformation summary because we store trees) or in an auto_vec which
is hopefully usually only allocated on stack.

The calculation of aggreagete costant values for a given subsert of
callers is then rewritten to compute known constants for each
edge (some pruning to skip obviously not needed is still employed and
should not be really worse than what I am replacing) and these vectors
are there intersected, which can be done linearly since they are
sorted.  The patch also removes a lot of heap allocations of small
lists of aggregate values and replaces them with stack based
auto_vecs.

As Richard Sandiford suggested, I use std::lower_bound from
<algorithm> rather than re-implementing bsearch for array_slice.  The
patch depends on the patch which adds the ability to construct
array_slices from gc-allocated vectors.

gcc/ChangeLog:

2022-10-17  Martin Jambor  <mjambor@suse.cz>

* ipa-prop.h (IPA_PROP_ARG_INDEX_LIMIT_BITS): New.
(ipcp_transformation): Added forward declaration.
(ipa_argagg_value): New type.
(ipa_argagg_value_list): New type.
(ipa_agg_replacement_value): Removed type.
(ipcp_transformation): Switch from using ipa_agg_replacement_value
to ipa_argagg_value_list.
(ipa_get_agg_replacements_for_node): Removed.
(ipa_dump_agg_replacement_values): Removed declaration.
* ipa-cp.cc: Define INCLUDE_ALGORITHM.
(values_equal_for_ipcp_p): Moved up in the file.
(ipa_argagg_value_list::dump): New function.
(ipa_argagg_value_list::debug): Likewise.
(ipa_argagg_value_list::get_elt): Likewise.
(ipa_argagg_value_list::get_elt_for_index): Likewise.
(ipa_argagg_value_list::get_value): New overloaded functions.
(ipa_argagg_value_list::superset_of_p): New function.
(new ipa_argagg_value_list::push_adjusted_values): Likewise.
(push_agg_values_from_plats): Likewise.
(intersect_argaggs_with): Likewise.
(get_clone_agg_value): Removed.
(ipa_agg_value_from_node): Make last parameter const, use
ipa_argagg_value_list to search values coming from clones.
(ipa_get_indirect_edge_target_1): Use ipa_argagg_value_list to search
values coming from clones.
(ipcp_discover_new_direct_edges): Pass around a vector of
ipa_argagg_values rather than a link list of replacement values.
(cgraph_edge_brings_value_p): Use ipa_argagg_value_list to search
values coming from clones.
(create_specialized_node): Work with a vector of ipa_argagg_values
rather than a link list of replacement values.
(self_recursive_agg_pass_through_p): Make the pointer parameters
const.
(copy_plats_to_inter): Removed.
(intersect_with_plats): Likewise.
(agg_replacements_to_vector): Likewise.
(intersect_with_agg_replacements): Likewise.
(intersect_aggregates_with_edge): Likewise.
(push_agg_values_for_index_from_edge): Likewise.
(push_agg_values_from_edge): Likewise.
(find_aggregate_values_for_callers_subset): Rewrite.
(cgraph_edge_brings_all_agg_vals_for_node): Likewise.
(ipcp_val_agg_replacement_ok_p): Use ipa_argagg_value_list to search
aggregate values.
(decide_about_value): Work with a vector of ipa_argagg_values rather
than a link list of replacement values.
(decide_whether_version_node): Likewise.
(ipa_analyze_node): Check number of parameters, assert that there
are no descriptors when bailing out.
* ipa-prop.cc (ipa_set_node_agg_value_chain): Switch to a vector of
ipa_argagg_value.
(ipa_node_params_t::duplicate): Removed superfluous handling of
ipa_agg_replacement_values.  Name of src parameter removed because
it is no longer used.
(ipcp_transformation_t::duplicate): Replaced duplication of
ipa_agg_replacement_values with copying vector m_agg_values.
(ipa_dump_agg_replacement_values): Removed.
(write_ipcp_transformation_info): Stream the new data-structure
instead of the old.
(read_ipcp_transformation_info): Likewise.
(adjust_agg_replacement_values): Work with ipa_argagg_values instead
of linked lists of ipa_agg_replacement_values, copy the items and
truncate the vector as necessary to keep it sorted instead of marking
items as invalid.  Return one bool if CFG should be updated.
(ipcp_modif_dom_walker): Store ipcp_transformation instead of
linked list of ipa_agg_replacement_values.
(ipcp_modif_dom_walker::before_dom_children): Use
ipa_argagg_value_list instead of walking a list of
ipa_agg_replacement_values.
(ipcp_transform_function): Switch to the new data structure, adjust
dumping.

gcc/testsuite/ChangeLog:

2022-08-15  Martin Jambor  <mjambor@suse.cz>

* gcc.dg/ipa/ipcp-agg-11.c: Adjust dumps.
* gcc.dg/ipa/ipcp-agg-8.c: Likewise.

20 months agolibgcc: Quote variable in Makefile.in
Jonathan Wakely [Wed, 12 Oct 2022 11:35:00 +0000 (12:35 +0100)]
libgcc: Quote variable in Makefile.in

If the xgcc executable has not been built (or has been removed by 'make
clean') then the command to print the multilib dir fails, and so the
MULTIOSDIR variable is empty. That then causes:
/bin/sh: line 0: test: !=: unary operator expected

We can avoid it by quoting the variable.

libgcc/ChangeLog:

* Makefile.in: Quote variable.

20 months agotree-optimization/107302 - fix vec_perm placement for recurrence vect
Richard Biener [Tue, 18 Oct 2022 08:01:45 +0000 (10:01 +0200)]
tree-optimization/107302 - fix vec_perm placement for recurrence vect

The following fixes the VEC_PERM_EXPR placement when the latch
definition is a PHI node.

PR tree-optimization/107302
* tree-vect-loop.cc (vectorizable_recurrence): Fix vec_perm
placement for a PHI latch def.

* gcc.dg/vect/pr107302.c: New testcase.

20 months agoifcvt: Do not lower bitfields if we can't analyze dr's [PR107275]
Andre Vieira [Tue, 18 Oct 2022 09:51:09 +0000 (10:51 +0100)]
ifcvt: Do not lower bitfields if we can't analyze dr's [PR107275]

The ifcvt dead code elimination code was not built to deal with inline
assembly, loops with such would never be if-converted in the past since we can't
do data-reference analysis on them and vectorization would eventually fail.  For
this reason we now also do not lower bitfields if the data-reference analysis
fails, as we would not end up vectorizing it.  As a consequence this also fixes
this PR as the dead code elimination will not run for such cases and wrongfully
eliminate inline assembly statements.

gcc/ChangeLog:

PR tree-optimization/107275
* tree-if-conv.cc (if_convertible_loop_p_1): Move
find_data_references_in_loop call from here...
(if_convertible_loop_p): And move data-reference vector initialization
from here...
(tree_if_conversion):... to here.

gcc/testsuite/ChangeLog:

* gcc.dg/vect/pr107275.c: New test.

20 months agolibstdc++: Partial library support for std::float{16,32,64,128}_t and std::bfloat16_t
Jakub Jelinek [Tue, 18 Oct 2022 09:37:13 +0000 (11:37 +0200)]
libstdc++: Partial library support for std::float{16,32,64,128}_t and std::bfloat16_t

The following patch is partial support for std::float{16,32,64,128}_t
and std::bfloat16_t in libstdc++.
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p1467r9.html
says that <ostream>, <istream>, <charconv> and <complex>
need changes toom, but that isn't implemented so far.
In <cmath> the only thing missing I'm aware of is
std::nextafter std::float16_t and std::bfloat16_t overloads (I think
we probably need to implement that out of line somewhere, or inline? - might
need inline asm barriers) and std::nexttoward overloads (those are
intentional, you said there is a LWG issue about that).
Also, this patch has the glibc 2.26+ std::float128_t support for platforms
where long double isn't IEEE quad format temporarily disabled
because it depends on
https://gcc.gnu.org/pipermail/gcc-patches/2022-October/603665.html
changes which aren't in yet.

The patch also doesn't include any testcases to cover the <type_traits>
changes, it isn't clear to me where to put that.

2022-10-18  Jakub Jelinek  <jakub@redhat.com>

PR c++/106652
* include/std/stdfloat: New file.
* include/std/numbers (__glibcxx_numbers): Define and use it
for __float128 explicit instantiations as well as
_Float{16,32,64,128} and __gnu_cxx::__bfloat16_t.
* include/std/atomic (atomic<_Float16>, atomic<_Float32>,
atomic<_Float64>, atomic<_Float128>, atomic<__gnu_cxx::__bfloat16_t>):
New explicit instantiations.
* include/std/type_traits (__is_floating_point_helper<_Float16>,
__is_floating_point_helper<_Float32>,
__is_floating_point_helper<_Float64>,
__is_floating_point_helper<_Float128>,
__is_floating_point_helper<__gnu_cxx::__bfloat16_t>): Likewise.
* include/std/limits (__glibcxx_concat3_, __glibcxx_concat3,
__glibcxx_float_n): Define.
(numeric_limits<_Float16>, numeric_limits<_Float32>,
numeric_limits<_Float64>, numeric_limits<_Float128>,
numeric_limits<__gnu_cxx::__bfloat16_t>): New explicit instantiations.
* include/bits/std_abs.h (abs): New overloads for
_Float{16,32,64,128} and __gnu_cxx::__bfloat16_t.
* include/bits/c++config (_GLIBCXX_LDOUBLE_IS_IEEE_BINARY128): Define
if long double is IEEE quad.
(__gnu_cxx::__bfloat16_t): New using.
* include/c_global/cmath (acos, asin, atan, atan2, ceil, cos, cosh,
exp, fabs, floor, fmod, frexp, ldexp, log, log10, modf, pow, sin,
sinh, sqrt, tan, tanh, fpclassify, isfinite, isinf, isnan, isnormal,
signbit, isgreater, isgreaterequal, isless, islessequal,
islessgreater, isunordered, acosh, asinh, atanh, cbrt, copysign, erf,
erfc, exp2, expm1, fdim, fma, fmax, fmin, hypot, ilogb, lgamma,
llrint, llround, log1p, log2, logb, lrint, lround, nearbyint,
nextafter, remainder, rint, round, scalbln, scalbn, tgamma, trunc,
lerp): New overloads with _Float{16,32,64,128} or
__gnu_cxx::__bfloat16_t types.
* config/os/gnu-linux/os_defines.h (_GLIBCXX_HAVE_FLOAT128_MATH):
Prepare for definition if glibc 2.26 and later implements *f128 APIs
but comment out the actual definition for now.
* include/ext/type_traits.h (__promote<_Float16>, __promote<_Float32>,
__promote<_Float64>, __promote<_Float128>,
__promote<__gnu_cxx::__bfloat16_t>): New specializations.
* include/Makefile.am (std_headers): Add stdfloat.
* include/Makefile.in: Regenerated.
* include/precompiled/stdc++.h: Include stdfloat.
* testsuite/18_support/headers/stdfloat/types_std.cc: New test.
* testsuite/18_support/headers/limits/synopsis_cxx23.cc: New test.
* testsuite/26_numerics/headers/cmath/c99_classification_macros_c++23.cc:
New test.
* testsuite/26_numerics/headers/cmath/functions_std_c++23.cc: New test.
* testsuite/26_numerics/numbers/4.cc: New test.
* testsuite/29_atomics/atomic_float/requirements_cxx23.cc: New test.

20 months agomiddle-end IFN_ASSUME support [PR106654]
Jakub Jelinek [Tue, 18 Oct 2022 08:31:20 +0000 (10:31 +0200)]
middle-end IFN_ASSUME support [PR106654]

My earlier patches gimplify the simplest non-side-effects assumptions
into if (cond) ; else __builtin_unreachable (); and throw the rest
on the floor.
The following patch attempts to do something with the rest too.
For -O0, it throws the more complex assumptions on the floor,
we don't expect optimizations and the assumptions are there to allow
optimizations.  Otherwise arranges for the assumptions to be
visible in the IL as
  .ASSUME (_Z2f4i._assume.0, i_1(D));
call where there is an artificial function like:
bool _Z2f4i._assume.0 (int i)
{
  bool _2;

  <bb 2> [local count: 1073741824]:
  _2 = i_1(D) == 43;
  return _2;

}
with the semantics that there is UB unless the assumption function
would return true.

Aldy, could ranger handle this?  If it sees .ASSUME call,
walk the body of such function from the edge(s) to exit with the
assumption that the function returns true, so above set _2 [true, true]
and from there derive that i_1(D) [43, 43] and then map the argument
in the assumption function to argument passed to IFN_ASSUME (note,
args there are shifted by 1)?

During gimplification it actually gimplifies it into
  [[assume (D.2591)]]
    {
      {
        i = i + 1;
        D.2591 = i == 44;
      }
    }
which is a new GIMPLE_ASSUME statement wrapping a GIMPLE_BIND and
specifying a boolean_type_node variable which contains the result.
The GIMPLE_ASSUME then survives just a couple of passes and is lowered
during gimple lowering into an outlined separate function and
IFN_ASSUME call.  Variables declared inside of the
condition (both static and automatic) just change context, automatic
variables from the caller are turned into parameters (note, as the code
is never executed, I handle this way even non-POD types, we don't need to
bother pretending there would be user copy constructors etc. involved).

The assume_function artificial functions are then optimized until the
new assumptions pass which doesn't do much right now but I'd like to see
there the backwards ranger walk and filling up of SSA_NAME_RANGE_INFO
for the parameters.

There are a few further changes I'd like to do, like ignoring the
.ASSUME calls in inlining size estimations (but haven't figured out where
it is done), or for LTO arrange for the assume functions to be emitted
in all partitions that reference those (usually there will be just one,
unless code with the assumption got inlined, versioned etc.).

2022-10-18  Jakub Jelinek  <jakub@redhat.com>

PR c++/106654
gcc/
* gimple.def (GIMPLE_ASSUME): New statement kind.
* gimple.h (struct gimple_statement_assume): New type.
(is_a_helper <gimple_statement_assume *>::test,
is_a_helper <const gimple_statement_assume *>::test): New.
(gimple_build_assume): Declare.
(gimple_has_substatements): Return true for GIMPLE_ASSUME.
(gimple_assume_guard, gimple_assume_set_guard,
gimple_assume_guard_ptr, gimple_assume_body_ptr, gimple_assume_body):
New inline functions.
* gsstruct.def (GSS_ASSUME): New.
* gimple.cc (gimple_build_assume): New function.
(gimple_copy): Handle GIMPLE_ASSUME.
* gimple-pretty-print.cc (dump_gimple_assume): New function.
(pp_gimple_stmt_1): Handle GIMPLE_ASSUME.
* gimple-walk.cc (walk_gimple_op): Handle GIMPLE_ASSUME.
* omp-low.cc (WALK_SUBSTMTS): Likewise.
(lower_omp_1): Likewise.
* omp-oacc-kernels-decompose.cc (adjust_region_code_walk_stmt_fn):
Likewise.
* tree-cfg.cc (verify_gimple_stmt, verify_gimple_in_seq_2): Likewise.
* function.h (struct function): Add assume_function bitfield.
* gimplify.cc (gimplify_call_expr): If the assumption isn't
simple enough, expand it into GIMPLE_ASSUME wrapped block or
for -O0 drop it.
* gimple-low.cc: Include attribs.h.
(create_assumption_fn): New function.
(struct lower_assumption_data): New type.
(find_assumption_locals_r, assumption_copy_decl,
adjust_assumption_stmt_r, adjust_assumption_stmt_op,
lower_assumption): New functions.
(lower_stmt): Handle GIMPLE_ASSUME.
* tree-ssa-ccp.cc (pass_fold_builtins::execute): Remove
IFN_ASSUME calls.
* lto-streamer-out.cc (output_struct_function_base): Pack
assume_function bit.
* lto-streamer-in.cc (input_struct_function_base): And unpack it.
* cgraphunit.cc (cgraph_node::expand): Don't verify assume_function
has TREE_ASM_WRITTEN set and don't release its body.
(symbol_table::compile): Allow assume functions not to have released
body.
* internal-fn.cc (expand_ASSUME): Remove gcc_unreachable.
* passes.cc (execute_one_pass): For TODO_discard_function don't
release body of assume functions.
* cgraph.cc (cgraph_node::verify_node): Don't verify cgraph nodes
of PROP_assumptions_done functions.
* tree-pass.h (PROP_assumptions_done): Define.
(TODO_discard_function): Adjust comment.
(make_pass_assumptions): Declare.
* passes.def (pass_assumptions): Add.
* timevar.def (TV_TREE_ASSUMPTIONS): New.
* tree-inline.cc (remap_gimple_stmt): Handle GIMPLE_ASSUME.
* tree-vrp.cc (pass_data_assumptions): New variable.
(pass_assumptions): New class.
(make_pass_assumptions): New function.
gcc/cp/
* cp-tree.h (build_assume_call): Declare.
* parser.cc (cp_parser_omp_assumption_clauses): Use build_assume_call.
* cp-gimplify.cc (build_assume_call): New function.
(process_stmt_assume_attribute): Use build_assume_call.
* pt.cc (tsubst_copy_and_build): Likewise.
gcc/testsuite/
* g++.dg/cpp23/attr-assume5.C: New test.
* g++.dg/cpp23/attr-assume6.C: New test.
* g++.dg/cpp23/attr-assume7.C: New test.

20 months agotree-optimization/107301 - check if we can duplicate block before doing so
Richard Biener [Tue, 18 Oct 2022 07:38:03 +0000 (09:38 +0200)]
tree-optimization/107301 - check if we can duplicate block before doing so

Path isolation failed to do that.

PR tree-optimization/107301
* gimple-ssa-isolate-paths.cc (handle_return_addr_local_phi_arg):
Check whether we can duplicate the block.
(find_implicit_erroneous_behavior): Likewise.

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

20 months agoMove scanning pass of forwprop-19.c to dse1 for r13-3212-gb88adba751da63
Liwei Xu [Mon, 17 Oct 2022 03:08:55 +0000 (11:08 +0800)]
Move scanning pass of forwprop-19.c to dse1 for r13-3212-gb88adba751da63

gcc/testsuite/ChangeLog:

PR testsuite/107220
* gcc.dg/tree-ssa/forwprop-19.c: Move scanning pass from
forwprop1 to dse1, This fixs the test case fail.

21 months agoMerge partial relation precisions properly
Andrew MacLeod [Mon, 17 Oct 2022 23:00:49 +0000 (19:00 -0400)]
Merge partial relation precisions properly

When merging 2 groups of PE's, one group was simply being set to the
other instead of properly merging them.

PR tree-optimization/107273
gcc/
* value-relation.cc (equiv_oracle::add_partial_equiv): Merge
instead of copying precison of each member.

gcc/testsuite/
* gcc.dg/tree-ssa/pr107273-1.c: New.
* gcc.dg/tree-ssa/pr107273-2.c: New.

21 months agoDaily bump.
GCC Administrator [Tue, 18 Oct 2022 00:17:40 +0000 (00:17 +0000)]
Daily bump.

21 months agoFix bogus RTL on the H8.
Jeff Law [Mon, 17 Oct 2022 23:52:18 +0000 (19:52 -0400)]
Fix bogus RTL on the H8.

This patch actually fixes the bogus RTL seen in PR101697.

Basically we continue to use the insn condition to catch most of the problem
cases related to autoinc addressing modes.  This patch adds constraints which
can guide reload (and hopefully LRA) away from doing blind replacements during
register elimination that would ultimately result in bogus RTL.  The idea is
from Paul K. who has done something very similar on the pdp11.  I guess it
shouldn't be a big surprise that the H8 and pdp11 need the same kind of
handling given some of the similarities in their architectures.

gcc/
PR target/101697
* config/h8300/combiner.md: Replace '<' preincment constraint with
ZA/Z1..ZH/Z7 combinations.
* config/h8300/movepush.md: Similarly

21 months agoMore infrastructure to avoid bogus RTL on H8.
Jeff Law [Mon, 17 Oct 2022 23:42:27 +0000 (19:42 -0400)]
More infrastructure to avoid bogus RTL on H8.

Continuing the work to add constraints to avoid invalid RTL
with autoinc addressing modes.  Specifically this patch adds
the memory constraints similar to the pdp11.

gcc/

* config/h8300/constraints.md (Za..Zh): New constraints for
autoinc addresses using a specific register.
* config/h8300/h8300.cc (pre_incdec_with_reg): New function.
* config/h8300/h8300-protos.h (pre_incdec_with_reg): Add prototype.

21 months agoRemove accidential commits
Jeff Law [Mon, 17 Oct 2022 23:33:52 +0000 (17:33 -0600)]
Remove accidential commits

gcc/
* config/i386/cet.c: Remove accidental commit.
* config/i386/driver-mingw32.c: Likewise.
* config/i386/i386-builtins.c: Likewise.
* config/i386/i386-d.c:  Likewise.
* config/i386/i386-expand.c: Likewise.
* config/i386/i386-features.c: Likewise.
* config/i386/i386-options.c: Likewise.
* config/i386/t-cet: Likewise.
* config/i386/x86-tune-sched-atom.c: Likewise.
* config/i386/x86-tune-sched-bd.c: Likewise.
* config/i386/x86-tune-sched-core.c: Likewise.
* config/i386/x86-tune-sched.c: Likewise.

21 months agoEnable REE for H8
Jeff Law [Mon, 17 Oct 2022 23:28:00 +0000 (19:28 -0400)]
Enable REE for H8

I was looking at H8 assembly code recently and noticed we had unnecessary
extensions.  As it turns out we never enabled redundant extension elimination
on the H8.  This patch fixes that oversight (and was the trigger for the
failure fixed my the prior patch).

gcc/common

* common/config/h8300/h8300-common.cc (h8300_option_optimization_table):
Enable redundant extension elimination at -O2 and above.

21 months agoAdd missing splitter for H8
Jeff Law [Mon, 17 Oct 2022 23:19:25 +0000 (19:19 -0400)]
Add missing splitter for H8

While testing a minor optimization on the H8 my builds failed due to
failure to split a zero-extended memory load.    That particular pattern
is a bit special on the H8 in that it's split at assembly time primarily
to get the length computations correct.  Arguably that alternative should
go away completely, but I haven't really looked into that.

Anyway, with the final-asm split we obviously need to match a define_split
somewhere.  But none was ever written after adding CCZN optimizations.  So
if we had a zero extend of a memory operand and it was used to eliminate
a compare, then we'd abort at final asm time.

Regression tested (in conjunction with various other in-progress patches) on
H8 without regressions.

gcc/
* config/h8300/extensions.md (CCZN setting zero extended load): Add
missing splitter.

21 months agox86: Check corrupted return address when unwinding stack
H.J. Lu [Thu, 11 Aug 2022 23:21:23 +0000 (16:21 -0700)]
x86: Check corrupted return address when unwinding stack

If shadow stack is enabled, when unwinding stack, we count how many stack
frames we pop to reach the landing pad and adjust shadow stack by the same
amount.  When counting the stack frame, we compare the return address on
normal stack against the return address on shadow stack.  If they don't
match, return _URC_FATAL_PHASE2_ERROR for the corrupted return address on
normal stack.  Don't check the return address for

1. Non-catchable exception where exception_class == 0.  Process will be
terminated.
2. Zero return address which marks the outermost stack frame.
3. Signal stack frame since kernel puts a restore token on shadow stack.

* unwind-generic.h (_Unwind_Frames_Increment): Add the EXC
argument.
* unwind.inc (_Unwind_RaiseException_Phase2): Pass EXC to
_Unwind_Frames_Increment.
(_Unwind_ForcedUnwind_Phase2): Likewise.
* config/i386/shadow-stack-unwind.h (_Unwind_Frames_Increment):
Take the EXC argument.  Return _URC_FATAL_PHASE2_ERROR if the
return address on normal stack doesn't match the return address
on shadow stack.

21 months agoFortran: NULL pointer dereference in gfc_simplify_image_index [PR104330]
Steve Kargl [Mon, 17 Oct 2022 20:42:40 +0000 (22:42 +0200)]
Fortran: NULL pointer dereference in gfc_simplify_image_index [PR104330]

gcc/fortran/ChangeLog:

PR fortran/104330
* simplify.cc (gfc_simplify_image_index): Do not dereference NULL
pointer.

gcc/testsuite/ChangeLog:

PR fortran/104330
* gfortran.dg/pr104330.f90: New test.

21 months agoMake sure exported range for SSA post-dominates the DEF in set_global_ranges_from_unr...
Aldy Hernandez [Mon, 17 Oct 2022 16:56:24 +0000 (18:56 +0200)]
Make sure exported range for SSA post-dominates the DEF in set_global_ranges_from_unreachable_edges.

The problem here is that we're exporting a range for an SSA range that
happens on the other side of a __builtin_unreachable, but the SSA does
not post-dominate the definition point.  This is causing ivcanon to
unroll things incorrectly.

This was a snafu when converting the code from evrp.

PR tree-optimization/107293

gcc/ChangeLog:

* tree-ssa-dom.cc
(dom_opt_dom_walker::set_global_ranges_from_unreachable_edges):
Check that condition post-dominates the definition point.

gcc/testsuite/ChangeLog:

* gcc.dg/tree-ssa/pr107293.c: New test.

21 months agoFortran: handle bad array ctors with typespec [PR93483, PR107216, PR107219]
Harald Anlauf [Sat, 15 Oct 2022 19:56:56 +0000 (21:56 +0200)]
Fortran: handle bad array ctors with typespec [PR93483, PR107216, PR107219]

gcc/fortran/ChangeLog:

PR fortran/93483
PR fortran/107216
PR fortran/107219
* arith.cc (reduce_unary): Handled expressions are EXP_CONSTANT and
EXPR_ARRAY.  Do not attempt to reduce otherwise.
(reduce_binary_ac): Likewise.
(reduce_binary_ca): Likewise.
(reduce_binary_aa): Moved check for EXP_CONSTANT and EXPR_ARRAY
from here ...
(reduce_binary): ... to here.
(eval_intrinsic): Catch failed reductions.
* gfortran.h (GFC_INTRINSIC_OPS): New enum ARITH_NOT_REDUCED to keep
track of expressions that were not reduced by the arithmetic evaluation
code.

gcc/testsuite/ChangeLog:

PR fortran/93483
PR fortran/107216
PR fortran/107219
* gfortran.dg/array_constructor_56.f90: New test.
* gfortran.dg/array_constructor_57.f90: New test.

Co-authored-by: Mikael Morin <mikael@gcc.gnu.org>
21 months agoFortran: check type of operands of logical operations, comparisons [PR107272]
Harald Anlauf [Sun, 16 Oct 2022 18:32:27 +0000 (20:32 +0200)]
Fortran: check type of operands of logical operations, comparisons [PR107272]

gcc/fortran/ChangeLog:

PR fortran/107272
* arith.cc (gfc_arith_not): Operand must be of type BT_LOGICAL.
(gfc_arith_and): Likewise.
(gfc_arith_or): Likewise.
(gfc_arith_eqv): Likewise.
(gfc_arith_neqv): Likewise.
(gfc_arith_eq): Compare consistency of types of operands.
(gfc_arith_ne): Likewise.
(gfc_arith_gt): Likewise.
(gfc_arith_ge): Likewise.
(gfc_arith_lt): Likewise.
(gfc_arith_le): Likewise.

gcc/testsuite/ChangeLog:

PR fortran/107272
* gfortran.dg/pr107272.f90: New test.

21 months agoFortran: Fixes for kind=4 characters strings [PR107266]
Tobias Burnus [Mon, 17 Oct 2022 16:15:16 +0000 (18:15 +0200)]
Fortran: Fixes for kind=4 characters strings [PR107266]

PR fortran/107266

gcc/fortran/
* trans-expr.cc (gfc_conv_string_parameter): Use passed
type to honor character kind.
* trans-types.cc (gfc_sym_type): Honor character kind.
* trans-decl.cc (gfc_conv_cfi_to_gfc): Fix handling kind=4
character strings.

gcc/testsuite/
* gfortran.dg/char4_decl.f90: New test.
* gfortran.dg/char4_decl-2.f90: New test.

21 months agoc++ modules: streaming constexpr_fundef [PR101449]
Patrick Palka [Mon, 17 Oct 2022 15:14:36 +0000 (11:14 -0400)]
c++ modules: streaming constexpr_fundef [PR101449]

It looks like we currently avoid streaming the RESULT_DECL and PARM_DECLs
of a constexpr_fundef entry under the assumption that they're just copies
of the DECL_RESULT and DECL_ARGUMENTS of the FUNCTION_DECL.  Thus we can
just make new copies of DECL_RESULT and DECL_ARGUMENTS on stream in rather
than separately streaming them.

But the FUNCTION_DECL's DECL_RESULT and DECL_ARGUMENTS eventually get
genericized, whereas the constexpr_fundef entry consists of a copy of the
FUNCTION_DECL's pre-GENERIC trees.  And notably during genericization we
lower invisref parms (which entails changing their TREE_TYPE and setting
DECL_BY_REFERENCE), the lowered form of which the constexpr evaluator
doesn't expect to see, and so this copying approach causes us to ICE for
the below testcase.

This patch fixes this by faithfully streaming the RESULT_DECL and
PARM_DECLs of a constexpr_fundef entry, which seems to just work.

Nathan says[1]: Hm, the reason for the complexity was that I wanted to
recreate the tree graph where the fndecl came from one TU and the defn
came from another one -- we need the definition to refer to argument
decls from the already-read decl.  However, it seems that for constexpr
fns here, that is not needed, resulting in a significant simplification.

[1]: https://gcc.gnu.org/pipermail/gcc-patches/2022-October/603662.html

PR c++/101449

gcc/cp/ChangeLog:

* module.cc (trees_out::write_function_def): Stream the
parms and result of the constexpr_fundef entry.
(trees_in::read_function_def): Likewise.

gcc/testsuite/ChangeLog:

* g++.dg/modules/cexpr-3_a.C: New test.
* g++.dg/modules/cexpr-3_b.C: New test.

21 months ago[PR tree-optimization/105820] Add test.
Aldy Hernandez [Mon, 17 Oct 2022 13:32:35 +0000 (15:32 +0200)]
[PR tree-optimization/105820] Add test.

PR tree-optimization/105820

gcc/testsuite/ChangeLog:

* g++.dg/tree-ssa/pr105820.c: New test.

21 months agoDo not test for -Inf when flag_finite_math_only.
Aldy Hernandez [Mon, 17 Oct 2022 13:26:05 +0000 (15:26 +0200)]
Do not test for -Inf when flag_finite_math_only.

PR tree-optimization/107286

gcc/ChangeLog:

* value-range.cc (range_tests_floats): Do not test for -Inf when
flag_finite_math_only.

21 months agoAdd 3 floating NAN tests.
Aldy Hernandez [Mon, 10 Oct 2022 09:01:48 +0000 (11:01 +0200)]
Add 3 floating NAN tests.

x UNORD x should set NAN on the TRUE side.
The false side of x == x should set NAN.
The true side of x != x should set NAN.

gcc/testsuite/
* gcc.dg/tree-ssa/vrp-float-3a.c: New.
* gcc.dg/tree-ssa/vrp-float-4a.c: New.
* gcc.dg/tree-ssa/vrp-float-5a.c: New.

21 months agoAdd relation_trio class for range-ops.
Andrew MacLeod [Thu, 13 Oct 2022 22:03:58 +0000 (18:03 -0400)]
Add relation_trio class for range-ops.

There are 3 possible relations range-ops might care about, but only the one
most likely to be needed is supplied.   This patch provides a new class
relation_trio which allows 3 relations to be passed in a single word.

fold_range (), op1_range (), and op2_range () are adjusted to take a
relation_trio class instead of a relation_kind, then the routine can
extract which relation it wants to work with.

* gimple-range-fold.cc (fold_using_range::range_of_range_op):
Provide relation_trio class.
* gimple-range-gori.cc (gori_compute::refine_using_relation):
Provide relation_trio class.
(gori_compute::refine_using_relation): Ditto.
(gori_compute::compute_operand1_range): Provide lhs_op2 and
op1_op2 relations via relation_trio class.
(gori_compute::compute_operand2_range): Ditto.
* gimple-range-op.cc (gimple_range_op_handler::calc_op1): Use
relation_trio instead of relation_kind.
(gimple_range_op_handler::calc_op2): Ditto.
(*::fold_range): Ditto.
* gimple-range-op.h (gimple_range_op::calc_op1): Adjust prototypes.
(gimple_range_op::calc_op2): Adjust prototypes.
* range-op-float.cc (*::fold_range): Use relation_trio instead of
relation_kind.
(*::op1_range): Ditto.
(*::op2_range): Ditto.
* range-op.cc (*::fold_range): Use relation_trio instead of
relation_kind.
(*::op1_range): Ditto.
(*::op2_range): Ditto.
* range-op.h (class range_operator): Adjust prototypes.
(class range_operator_float): Ditto.
(class range_op_handler): Adjust prototypes.
(relop_early_resolve): Pickup op1_op2 relation from relation_trio.
* value-relation.cc (VREL_LAST): Adjust use to be one past the end of
the enum.
(relation_oracle::validate_relation): Use relation_trio in call
to fold_range.
* value-relation.h (enum relation_kind_t): Add VREL_LAST as
final element.
(class relation_trio): New.
(TRIO_VARYING, TRIO_SHIFT, TRIO_MASK): New.

21 months agoFix nan updating in range-ops.
Andrew MacLeod [Fri, 14 Oct 2022 13:29:23 +0000 (09:29 -0400)]
Fix nan updating in range-ops.

Calling clean_nan on an undefined type traps, set_varying first. Other
tweaks for correctness.

* range-op-float.cc (foperator_not_equal::op1_range): Check for
VREL_EQ after singleton.
(foperator_unordered::op1_range): Set VARYING before calling
clear_nan().
(foperator_ordered::op1_range): Set rather than clear NAN if both
operands are the same.

21 months agoDon't set useless relations.
Andrew MacLeod [Fri, 14 Oct 2022 18:31:02 +0000 (14:31 -0400)]
Don't set useless relations.

The oracle will not register nonssense/useless relations, class
value_relation shouldn't either.

* value-relation.cc (value_relation::dump): Change message.
* value-relation.h (value_relation::set_relation): If op1 is the
same as op2 do not create a relation.

21 months agoGCN: Restore build with GCC 4.8
Thomas Schwinge [Fri, 14 Oct 2022 22:10:29 +0000 (00:10 +0200)]
GCN: Restore build with GCC 4.8

For example, for "g++-4.8 (Ubuntu 4.8.4-2ubuntu1~14.04.4) 4.8.4", the recent
commit r13-3220-g45381d6f9f4e7b5c7b062f5ad8cc9788091c2d07
"amdgcn: add multiple vector sizes" broke the build:

    In file included from [...]/source-gcc/gcc/coretypes.h:458:0,
                     from [...]/source-gcc/gcc/config/gcn/gcn.cc:24:
    [...]/source-gcc/gcc/config/gcn/gcn.cc: In function ‘machine_mode VnMODE(int, machine_mode)’:
    ./insn-modes.h:42:71: error: temporary of non-literal type ‘scalar_int_mode’ in a constant expression
     #define QImode (scalar_int_mode ((scalar_int_mode::from_int) E_QImode))
                                                                           ^
    [...]/source-gcc/gcc/config/gcn/gcn.cc:405:10: note: in expansion of macro ‘QImode’
         case QImode:
              ^
    In file included from [...]/source-gcc/gcc/coretypes.h:478:0,
                     from [...]/source-gcc/gcc/config/gcn/gcn.cc:24:
    [...]/source-gcc/gcc/machmode.h:410:7: note: ‘scalar_int_mode’ is not literal because:
     class scalar_int_mode
           ^
    [...]/source-gcc/gcc/machmode.h:410:7: note:   ‘scalar_int_mode’ is not an aggregate, does not have a trivial default constructor, and has no constexpr constructor that is not a copy or move constructor
    [...]

Addressing this like simiar issues have been addressed in the past.

gcc/
* config/gcn/gcn.cc (VnMODE): Use 'case E_QImode:' instead of
'case QImode:', etc.

21 months agoTag 'gcc/gimple-expr.cc:mark_addressable_2' as 'static'
Thomas Schwinge [Wed, 15 Dec 2021 21:00:53 +0000 (22:00 +0100)]
Tag 'gcc/gimple-expr.cc:mark_addressable_2' as 'static'

Added in 2015 r229696 (commit 1b223a9f3489296c625bdb7cc764196d04fd9231)
"defer mark_addressable calls during expand till the end of expand",
it has never been used 'extern'ally.

gcc/
* gimple-expr.cc (mark_addressable_2): Tag as 'static'.

21 months agoFix nvptx-specific '-foffload-options' syntax in 'libgomp.c/reverse-offload-sm30.c'
Thomas Schwinge [Fri, 23 Sep 2022 09:29:50 +0000 (11:29 +0200)]
Fix nvptx-specific '-foffload-options' syntax in 'libgomp.c/reverse-offload-sm30.c'

That is, '-mptx=_' is only valid in '-foffload-options=nvptx-none', too.

Fix test case added in recent
commit r13-2625-g6b43f556f392a7165582aca36a19fe7389d995b2 "nvptx/mkoffload.cc:
Warn instead of error when reverse offload is not possible".

libgomp/
* testsuite/libgomp.c/reverse-offload-sm30.c: Fix nvptx-specific
'-foffload-options' syntax.

21 months agoVectorization of first-order recurrences
Richard Biener [Thu, 6 Oct 2022 11:56:09 +0000 (13:56 +0200)]
Vectorization of first-order recurrences

The following picks up the prototype by Ju-Zhe Zhong for vectorizing
first order recurrences.  That solves two TSVC missed optimization PRs.

There's a new scalar cycle def kind, vect_first_order_recurrence
and it's handling of the backedge value vectorization is complicated
by the fact that the vectorized value isn't the PHI but instead
a (series of) permute(s) shifting in the recurring value from the
previous iteration.  I've implemented this by creating both the
single vectorized PHI and the series of permutes when vectorizing
the scalar PHI but leave the backedge values in both unassigned.
The backedge values are (for the testcases) computed by a load
which is also the place after which the permutes are inserted.
That placement also restricts the cases we can handle (without
resorting to code motion).

I added both costing and SLP handling though SLP handling is
restricted to the case where a single vectorized PHI is enough.

Missing is epilogue handling - while prologue peeling would
be handled transparently by adjusting iv_phi_p the epilogue
case doesn't work with just inserting a scalar LC PHI since
that a) keeps the scalar load live and b) that loads is the
wrong one, it has to be the last, much like when we'd vectorize
the LC PHI as live operation.  Unfortunately LIVE
compute/analysis happens too early before we decide on
peeling.  When using fully masked loop vectorization the
vect-recurr-6.c works as expected though.

I have tested this on x86_64 for now, but since epilogue
handling is missing there's probably no practical cases.
My prototype WHILE_ULT AVX512 patch can handle vect-recurr-6.c
just fine but I didn't feel like running SPEC within SDE nor
is the WHILE_ULT patch complete enough.

PR tree-optimization/99409
PR tree-optimization/99394
* tree-vectorizer.h (vect_def_type::vect_first_order_recurrence): Add.
(stmt_vec_info_type::recurr_info_type): Likewise.
(vectorizable_recurr): New function.
* tree-vect-loop.cc (vect_phi_first_order_recurrence_p): New
function.
(vect_analyze_scalar_cycles_1): Look for first order
recurrences.
(vect_analyze_loop_operations): Handle them.
(vect_transform_loop): Likewise.
(vectorizable_recurr): New function.
(maybe_set_vectorized_backedge_value): Handle the backedge value
setting in the first order recurrence PHI and the permutes.
* tree-vect-stmts.cc (vect_analyze_stmt): Handle first order
recurrences.
(vect_transform_stmt): Likewise.
(vect_is_simple_use): Likewise.
(vect_is_simple_use): Likewise.
* tree-vect-slp.cc (vect_get_and_check_slp_defs): Likewise.
(vect_build_slp_tree_2): Likewise.
(vect_schedule_scc): Handle the backedge value setting in the
first order recurrence PHI and the permutes.

* gcc.dg/vect/vect-recurr-1.c: New testcase.
* gcc.dg/vect/vect-recurr-2.c: Likewise.
* gcc.dg/vect/vect-recurr-3.c: Likewise.
* gcc.dg/vect/vect-recurr-4.c: Likewise.
* gcc.dg/vect/vect-recurr-5.c: Likewise.
* gcc.dg/vect/vect-recurr-6.c: Likewise.
* gcc.dg/vect/tsvc/vect-tsvc-s252.c: Un-XFAIL.
* gcc.dg/vect/tsvc/vect-tsvc-s254.c: Likewise.
* gcc.dg/vect/tsvc/vect-tsvc-s291.c: Likewise.

Co-authored-by: Ju-Zhe Zhong <juzhe.zhong@rivai.ai>
21 months agolibgcc: Move cfa_how into potential padding in struct frame_state_reg_info
Florian Weimer [Mon, 17 Oct 2022 09:09:17 +0000 (11:09 +0200)]
libgcc: Move cfa_how into potential padding in struct frame_state_reg_info

On many architectures, there is a padding gap after the how array
member, and cfa_how can be moved there.  This reduces the size of the
struct and the amount of memory that uw_frame_state_for has to clear.

There is no measurable performance benefit from this on x86-64 (even
though the memset goes from 120 to 112 bytes), but it seems to be a
good idea to do anyway.

libgcc/

* unwind-dw2.h (struct frame_state_reg_info): Move cfa_how member
and reduce its size.

21 months agolibstdc++: Fix value of __cpp_lib_constexpr_charconv
Jonathan Wakely [Mon, 17 Oct 2022 08:38:02 +0000 (09:38 +0100)]
libstdc++: Fix value of __cpp_lib_constexpr_charconv

libstdc++-v3/ChangeLog:

* include/std/charconv (__cpp_lib_constexpr_charconv): Define to
correct value.
* include/std/version (__cpp_lib_constexpr_charconv): Likewise.
* testsuite/20_util/to_chars/constexpr.cc: Check correct value.
* testsuite/20_util/to_chars/version.cc: Likewise.

21 months agoRISC-V: Fix format[NFC]
Ju-Zhe Zhong [Mon, 17 Oct 2022 07:30:47 +0000 (15:30 +0800)]
RISC-V: Fix format[NFC]

gcc/ChangeLog:

* config/riscv/t-riscv: Change Tab into 2 space.

21 months agoRISC-V: Reorganize mangle_builtin_type.[NFC]
Ju-Zhe Zhong [Fri, 14 Oct 2022 23:02:36 +0000 (07:02 +0800)]
RISC-V: Reorganize mangle_builtin_type.[NFC]

Hi, this patch fixed my mistake in the previous commit patch.
Since "mangle_builtin_type" is a global function will be called in riscv.cc.
It's reasonable move it down and put them together stay with other global functions.

gcc/ChangeLog:

* config/riscv/riscv-vector-builtins.cc (mangle_builtin_type): Move down the function.

21 months agoelf: ELF toolchain --without-{headers, newlib} should provide stdint.h
Arsen Arsenovic [Mon, 17 Oct 2022 06:58:07 +0000 (08:58 +0200)]
elf: ELF toolchain --without-{headers, newlib} should provide stdint.h

stdint.h is considered a freestanding headers by C, and a valid stdint.h
is required for certain parts of libstdc++' configuration, so we should
simply provide one when we have no other way (i.e. newlib or
user-specified sysroot) of getting one.

* config.gcc: --target=*-elf --without-{newlib,headers} should
provide stdint.h.

21 months agoInitial Meteorlake Support
Hu, Lin1 [Fri, 16 Sep 2022 03:25:13 +0000 (11:25 +0800)]
Initial Meteorlake Support

gcc/ChangeLog:

* common/config/i386/cpuinfo.h:
(get_intel_cpu): Handle Meteorlake.
* common/config/i386/i386-common.cc:
(processor_alias_table): Add Meteorlake.

21 months agoInitial Raptorlake Support
Haochen Jiang [Fri, 16 Sep 2022 05:59:01 +0000 (13:59 +0800)]
Initial Raptorlake Support

gcc/ChangeLog:

* common/config/i386/cpuinfo.h:
(get_intel_cpu): Handle Raptorlake.
* common/config/i386/i386-common.cc:
(processor_alias_table): Add Raptorlake.

21 months agoDaily bump.
GCC Administrator [Mon, 17 Oct 2022 00:16:37 +0000 (00:16 +0000)]
Daily bump.

21 months agoAdd new constraints for upcoming autoinc fixes
Jeff Law [Sun, 16 Oct 2022 16:43:25 +0000 (12:43 -0400)]
Add new constraints for upcoming autoinc fixes

GCC does not allow a the operand of an autoinc addressing mode to
overlap with another soure operand in the same insn.  This is primarly
enforced with insn conditions.  However, cases can slip through LRA
and reload.  To address those scenarios we'll take an idea from the
pdp11 port for describing the restriction in constraints as well.

To implement that we need register classes and constraints which are
"all general purpose hardware registers except r0".  And similarly for
r1..r7(sp).

This patch adds those register classes and constraints, but does not
yet use them.

gcc/
* config/h8300/constraints.md (Z0..Z7): New register
constraints.
* config/h8300/h8300.h (reg_class): Add new classes.
(REG_CLASS_NAMES): Similarly.
(REG_CLASS_CONTENTS): Similarly.

21 months agoRename "z" constraint to "Zz" on the H8/300
Jeff Law [Sun, 16 Oct 2022 14:58:52 +0000 (10:58 -0400)]
Rename "z" constraint to "Zz" on the H8/300

I want to use Z as a multi-letter constraint.  So first we have to
adjust the existing use of Z.  This does not affect code generation.

gcc/
* config/h8300/constraints.md (Zz constraint): Renamed
from "z".
* config/h8300/movepush.md (movqi_h8sx, movhi_h8sx): Adjust
constraint to use Zz instead of Z.