platform/upstream/gcc.git
23 months agoc: C2x removal of unprototyped functions
Joseph Myers [Thu, 1 Sep 2022 19:10:59 +0000 (19:10 +0000)]
c: C2x removal of unprototyped functions

C2x has completely removed unprototyped functions, so that () now
means the same as (void) in both function declarations and
definitions, where previously that change had been made for
definitions only.  Implement this accordingly.

This is a change where GNU/Linux distribution builders might wish to
try builds with a -std=gnu2x default to start early on getting old
code fixed that still has () declarations for functions taking
arguments, in advance of GCC moving to -std=gnu2x as default maybe in
GCC 14 or 15; I don't know how much such code is likely to be in
current use.

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

gcc/c/
* c-decl.cc (grokparms): Handle () in a function declaration the
same as (void) for C2X.

gcc/testsuite/
* gcc.dg/c11-unproto-3.c, gcc.dg/c2x-unproto-3.c,
gcc.dg/c2x-unproto-4.c: New tests.
* gcc.dg/c2x-old-style-definition-6.c, gcc.dg/c2x-unproto-1.c,
gcc.dg/c2x-unproto-2.c: Update for removal of unprototyped
functions.

23 months agovect: Try to remove single-vector permutes from SLP graph
Richard Sandiford [Thu, 1 Sep 2022 18:22:13 +0000 (19:22 +0100)]
vect: Try to remove single-vector permutes from SLP graph

This patch extends the SLP layout optimisation pass so that it
tries to remove layout changes that are brought about by permutes
of existing vectors.  This fixes the bb-slp-pr54400.c regression on
x86_64 and also means that we can remove the permutes in cases like:

typedef float v4sf __attribute__((vector_size(sizeof(float)*4)));

float __attribute__((noipa))
f(v4sf v0, v4sf v1)
{
  return v0[0]*v1[0]+v0[1]*v1[1]+v0[2]*v1[2]+v0[3]*v1[3];
}

The new test is a simple adaption of bb-slp-pr54400.c, with the
same style of markup.

gcc/
* tree-vect-slp.cc (vect_build_slp_tree_2): When building a
VEC_PERM_EXPR of an existing vector, set the SLP_TREE_LANES
to the number of vector elements, if that's a known constant.
(vect_optimize_slp_pass::is_compatible_layout): Remove associated
comment about zero SLP_TREE_LANES.
(vect_optimize_slp_pass::start_choosing_layouts): Iterate over
all partition members when looking for potential layouts.
Handle existing permutes of fixed-length vectors.

gcc/testsuite/
* gcc.dg/vect/bb-slp-pr54400.c: Extend to aarch64.
* gcc.dg/vect/bb-slp-layout-18.c: New test.

23 months agoi386: Fix conversion of move to/from AX_REG into xchg [PR106707]
Uros Bizjak [Thu, 1 Sep 2022 18:20:06 +0000 (20:20 +0200)]
i386: Fix conversion of move to/from AX_REG into xchg [PR106707]

The conversion of a move pattern where both operands are AX_REG
should be prevented.

2022-09-01  Uroš Bizjak  <ubizjak@gmail.com>

gcc/ChangeLog:

PR target/106707
* config/i386/i386.md (moves to/from AX_REG into xchg peephole2):
Do not convert a move pattern where both operands are AX_REG.

gcc/testsuite/ChangeLog:

PR target/106707
* gcc.target/i386/pr106707.c: New test.

23 months agoConvert ranger uses of real_inf to dconst[n]inf.
Aldy Hernandez [Thu, 1 Sep 2022 14:44:29 +0000 (16:44 +0200)]
Convert ranger uses of real_inf to dconst[n]inf.

gcc/ChangeLog:

* range-op-float.cc (build_le): Convert to dconst*inf.
(build_ge): Same.
* value-range.cc (frange::set_signbit): Same.
(frange::normalize_kind): Same.
(range_tests_floats): Same.
* value-range.h (vrp_val_max): Same.
(vrp_val_min): Same.
(frange::set_varying): Same.

23 months agoAdd global REAL_VALUE_TYPE infinities to real.*.
Aldy Hernandez [Thu, 1 Sep 2022 14:07:18 +0000 (16:07 +0200)]
Add global REAL_VALUE_TYPE infinities to real.*.

We're starting to abuse the infinity endpoints in the frange code and
the associated range operators.  Building infinities are rather cheap,
and we could even inline them, but I think it's best to just not
recalculate them all the time.

I see about 20 uses of real_inf in the source code, not including the
backends.  And I'm about to add more :).

gcc/ChangeLog:

* emit-rtl.cc (init_emit_once): Initialize dconstinf and
dconstninf.
* real.h: Add dconstinf and dconstninf.

23 months agolibstdc++: Remove FIXME for ICE with remove_cvref_t in requires-expression
Jonathan Wakely [Thu, 1 Sep 2022 10:52:52 +0000 (11:52 +0100)]
libstdc++: Remove FIXME for ICE with remove_cvref_t in requires-expression

PR c++/99968 is fixed since GCC 12.1 so we can remove the workaround.

libstdc++-v3/ChangeLog:

* include/std/type_traits (is_scoped_enum): Remove workaround.

23 months agolibstdc++: Implement ranges::adjacent_transform_view from P2321R2
Patrick Palka [Thu, 1 Sep 2022 13:54:57 +0000 (09:54 -0400)]
libstdc++: Implement ranges::adjacent_transform_view from P2321R2

libstdc++-v3/ChangeLog:

* include/std/ranges (__detail::__unarize): Define.
(adjacent_view::_Iterator): Befriend adjacent_transform_view.
(adjacent_transform_view): Define.
(adjacent_transform_view::_Iterator): Define.
(adjacent_transform_view::_Sentinel): Define.
(views::__detail::__can_adjacent_transform_view): Define.
(views::_AdjacentTransform): Define.
(views::adjacent_transform): Define.
(views::pairwise_transform): Define.
* testsuite/std/ranges/adaptors/adjacent_transform/1.cc: New test.

23 months agoRemove cycle checking from compute_control_dep_chain
Richard Biener [Thu, 1 Sep 2022 11:28:08 +0000 (13:28 +0200)]
Remove cycle checking from compute_control_dep_chain

Now that we have DFS_BACK_EDGE marks we can simply avoid walking
those instead of repeatedly looking for a cycle on the current chain.

* gimple-predicate-analysis.cc (compute_control_dep_chain):
Remove cycle detection, instead avoid walking backedges.

23 months agoSome predicate analysis TLC
Richard Biener [Thu, 1 Sep 2022 11:52:51 +0000 (13:52 +0200)]
Some predicate analysis TLC

The following hides some internal details of compute_control_dep_chain.

* gimple-predicate-analysis.cc (compute_control_dep_chain):
New wrapping overload.
(uninit_analysis::init_use_preds): Simplify.
(uninit_analysis::init_from_phi_def): Likewise.

23 months agoc++: set TYPE_STRING_FLAG for char8_t
Jason Merrill [Wed, 24 Aug 2022 20:31:11 +0000 (16:31 -0400)]
c++: set TYPE_STRING_FLAG for char8_t

While looking at the DWARF handling of char8_t I wondered why we weren't
setting TREE_STRING_FLAG on it.  I hoped that setting that flag would be an
easy fix for PR102958, but it doesn't seem to be sufficicent.  But it still
seems correct.

I also tried setting the flag on char16_t and char32_t, but that broke
because braced_list_to_string assumes char-sized elements.  Since we don't
set the flag on wchar_t, I abandoned that idea.

gcc/c-family/ChangeLog:

* c-common.cc (c_common_nodes_and_builtins): Set TREE_STRING_FLAG on
char8_t.
(braced_list_to_string): Check for char-sized elements.

23 months agoImplement ranger folder for __builtin_signbit.
Aldy Hernandez [Wed, 31 Aug 2022 12:41:29 +0000 (14:41 +0200)]
Implement ranger folder for __builtin_signbit.

Now that we keep track of the signbit, we can use it to fold __builtin_signbit.

I am assuming I don't have try too hard to get the actual signbit
number and 1 will do.  Especially, since we're inconsistent in trunk whether
we fold the builtin or whether we calculate it at runtime.

abulafia:~$ cat a.c
float nzero = -0.0;

main(){
    printf("0x%x\n", __builtin_signbit(-0.0));
    printf("0x%x\n", __builtin_signbit(nzero));
}
abulafia:~$ gcc a.c -w && ./a.out
0x1
0x80000000

It is amazing that we've been failing to fold something as simple as
this:

if (x > 5.0)
  num = __builtin_signbit (x);

It does the right thing now :-P.

gcc/ChangeLog:

* gimple-range-fold.cc
(fold_using_range::range_of_builtin_int_call): Add case for
CFN_BUILT_IN_SIGNBIT.

gcc/testsuite/ChangeLog:

* gcc.dg/tree-ssa/vrp-float-signbit-1.c: New test.

23 months agoAdd signbit property to frange to better model signed zeros.
Aldy Hernandez [Wed, 31 Aug 2022 12:41:04 +0000 (14:41 +0200)]
Add signbit property to frange to better model signed zeros.

As discussed here:

https://gcc.gnu.org/pipermail/gcc-patches/2022-August/600656.html

This adds an frange property to keep track of the sign bit.  We keep
it updated at all times, but we don't use it make any decisions when
!HONOR_SIGNED_ZEROS.

With this property we can now query the range for the appropriate sign
with frange::get_signbit ().  Possible values are yes, no, and unknown.

gcc/ChangeLog:

* range-op-float.cc (foperator_equal::op1_range): Do not copy sign
bit.
(foperator_not_equal::op1_range): Same.
* value-query.cc (range_query::get_tree_range): Set sign bit.
* value-range-pretty-print.cc (vrange_printer::visit): Dump sign bit.
* value-range.cc (frange::set_signbit): New.
(frange::set): Adjust for sign bit.
(frange::normalize_kind): Same.
(frange::union_): Remove useless comment.
(frange::intersect): Same.
(frange::contains_p): Adjust for sign bit.
(frange::singleton_p): Same.
(frange::verify_range): Same.
(range_tests_signbit): New tests.
(range_tests_floats): Call range_tests_signbit.
* value-range.h (class frange_props): Add signbit
(class frange): Same.

23 months agolibstdc++: Optimize array traits
Jonathan Wakely [Wed, 31 Aug 2022 14:00:07 +0000 (15:00 +0100)]
libstdc++: Optimize array traits

Improve compile times by avoiding unnecessary class template
instantiations.

__is_array_known_bounds and __is_array_unknown_bounds can be defined
without instantiating extent, by providing partial specializations for
the true cases.

std::extent can avoid recursing down through a multidimensional array,
so it stops after providing the result. Previously extent<T[n][m], 0>
would instantiate extent<T[n], -1u> and extent<T, -2u> as well.

std::is_array_v can use partial specializations to avoid instantiating
std::is_array, and similarly for std::rank_v and std::extent_v.

std::is_bounded_array_v and std::is_unbounded_array_v can also use
partial specializations, and then the class templates can be defined in
terms of the variable templates. This makes sense for these traits,
because they are new in C++20 and so the variable templates are always
available, which isn't true in general for C++11 and C++14 traits.

libstdc++-v3/ChangeLog:

* include/std/type_traits (__is_array_known_bounds): Add partial
specialization instead of using std::extent.
(__is_array_unknown_bounds): Likewise.
(extent): Add partial specializations to stop recursion after
the result is found.
(is_array_v): Add partial specializations instead of
instantiating the class template.
(rank_v, extent_v): Likewise.
(is_bounded_array_v, is_unbounded_array_v): Likewise.
(is_bounded_array, is_unbounded_array): Define in terms of the
variable templates.

23 months agoFix up dump_printf_loc format attribute and adjust uses [PR106782]
Jakub Jelinek [Thu, 1 Sep 2022 09:07:44 +0000 (11:07 +0200)]
Fix up dump_printf_loc format attribute and adjust uses [PR106782]

As discussed on IRC, the r13-2299-g68c61c2daa1f bug only got missed
because dump_printf_loc had incorrect format attribute and therefore
almost no -Wformat=* checking was performed on it.
3, 0 are suitable for function with (whatever, whatever, const char *, va_list)
arguments, not for (whatever, whatever, const char *, ...), that one should
use 3, 4.

The following patch fixes that and adjusts all spots to fix warnings.
In many cases it is just through an ugly cast (for %G casts to gimple *
from gassign */gphi * and the like and for %p casts to void * from slp_node
etc.).
There are 3 spots where the mismatch was worse though, two using %u or %d
for unsigned HOST_WIDE_INT argument and one %T for enum argument (promoted
to int).

2022-09-01  Jakub Jelinek  <jakub@redhat.com>

PR other/106782
* dumpfile.h (dump_printf_loc): Use ATTRIBUTE_GCC_DUMP_PRINTF (3, 4)
instead of ATTRIBUTE_GCC_DUMP_PRINTF (3, 0).
* tree-parloops.cc (parloops_is_slp_reduction): Cast pointers to
derived types of gimple to gimple * to avoid -Wformat warnings.
* tree-vect-loop-manip.cc (vect_set_loop_condition,
vect_update_ivs_after_vectorizer): Likewise.
* tree-vect-stmts.cc (vectorizable_load): Likewise.
* tree-vect-patterns.cc (vect_split_statement,
vect_recog_mulhs_pattern, vect_recog_average_pattern,
vect_determine_precisions_from_range,
vect_determine_precisions_from_users): Likewise.
* gimple-loop-versioning.cc
(loop_versioning::analyze_term_using_scevs): Likewise.
* tree-vect-slp.cc (vect_build_slp_tree_1): Likewise.
(vect_build_slp_tree): Cast slp_tree to void * to avoid
-Wformat warnings.
(optimize_load_redistribution_1, vect_match_slp_patterns,
vect_build_slp_instance, vect_optimize_slp_pass::materialize,
vect_optimize_slp_pass::dump, vect_slp_convert_to_external,
vect_slp_analyze_node_operations, vect_bb_partition_graph): Likewise.
(vect_print_slp_tree): Likewise.  Also use
HOST_WIDE_INT_PRINT_UNSIGNED instead of %u.
* tree-vect-loop.cc (vect_determine_vectorization_factor,
vect_analyze_scalar_cycles_1, vect_analyze_loop_operations,
vectorizable_induction, vect_transform_loop): Cast pointers to derived
types of gimple to gimple * to avoid -Wformat warnings.
(vect_analyze_loop_2): Cast slp_tree to void * to avoid
-Wformat warnings.
(vect_estimate_min_profitable_iters): Use HOST_WIDE_INT_PRINT_UNSIGNED
instead of %d.
* tree-vect-slp-patterns.cc (vect_pattern_validate_optab): Use %G
instead of %T and STMT_VINFO_STMT (SLP_TREE_REPRESENTATIVE (node))
instead of SLP_TREE_DEF_TYPE (node).

23 months agolibcpp: Add -Winvalid-utf8 warning [PR106655]
Jakub Jelinek [Thu, 1 Sep 2022 07:48:01 +0000 (09:48 +0200)]
libcpp: Add -Winvalid-utf8 warning [PR106655]

The following patch introduces a new warning - -Winvalid-utf8 similarly
to what clang now has - to diagnose invalid UTF-8 byte sequences in
comments, but not just in those, but also in string/character literals
and outside of them.

The warning is on by default when explicit -finput-charset=UTF-8 is
used and C++23 compilation is requested and if -{,W}pedantic or
-pedantic-errors it is actually a pedwarn.

The reason it is on by default only for -finput-charset=UTF-8 is
that the sources often are UTF-8, but sometimes could be some ASCII
compatible single byte encoding where non-ASCII characters only
appear in comments.  So having the warning off by default
is IMO desirable.  The C++23 pedantic mode for when the source code
is UTF-8 is -std=c++23 -pedantic-errors -finput-charset=UTF-8.

2022-09-01  Jakub Jelinek  <jakub@redhat.com>

PR c++/106655
libcpp/
* include/cpplib.h (struct cpp_options): Implement C++23
P2295R6 - Support for UTF-8 as a portable source file encoding.
Add cpp_warn_invalid_utf8 and cpp_input_charset_explicit fields.
(enum cpp_warning_reason): Add CPP_W_INVALID_UTF8 enumerator.
* init.cc (cpp_create_reader): Initialize cpp_warn_invalid_utf8
and cpp_input_charset_explicit.
* charset.cc (_cpp_valid_utf8): Adjust function comment.
* lex.cc (UCS_LIMIT): Define.
(utf8_continuation): New const variable.
(utf8_signifier): Move earlier in the file.
(_cpp_warn_invalid_utf8, _cpp_handle_multibyte_utf8): New functions.
(_cpp_skip_block_comment): Handle -Winvalid-utf8 warning.
(skip_line_comment): Likewise.
(lex_raw_string, lex_string): Likewise.
(_cpp_lex_direct): Likewise.
gcc/
* doc/invoke.texi (-Winvalid-utf8): Document it.
gcc/c-family/
* c.opt (-Winvalid-utf8): New warning.
* c-opts.cc (c_common_handle_option) <case OPT_finput_charset_>:
Set cpp_opts->cpp_input_charset_explicit.
(c_common_post_options): If -finput-charset=UTF-8 is explicit
in C++23, enable -Winvalid-utf8 by default and if -pedantic
or -pedantic-errors, make it a pedwarn.
gcc/testsuite/
* c-c++-common/cpp/Winvalid-utf8-1.c: New test.
* c-c++-common/cpp/Winvalid-utf8-2.c: New test.
* c-c++-common/cpp/Winvalid-utf8-3.c: New test.
* g++.dg/cpp23/Winvalid-utf8-1.C: New test.
* g++.dg/cpp23/Winvalid-utf8-2.C: New test.
* g++.dg/cpp23/Winvalid-utf8-3.C: New test.
* g++.dg/cpp23/Winvalid-utf8-4.C: New test.
* g++.dg/cpp23/Winvalid-utf8-5.C: New test.
* g++.dg/cpp23/Winvalid-utf8-6.C: New test.
* g++.dg/cpp23/Winvalid-utf8-7.C: New test.
* g++.dg/cpp23/Winvalid-utf8-8.C: New test.
* g++.dg/cpp23/Winvalid-utf8-9.C: New test.
* g++.dg/cpp23/Winvalid-utf8-10.C: New test.
* g++.dg/cpp23/Winvalid-utf8-11.C: New test.
* g++.dg/cpp23/Winvalid-utf8-12.C: New test.

23 months agoMake frange selftests work on !HONOR_NANS systems.
Aldy Hernandez [Wed, 31 Aug 2022 12:31:12 +0000 (14:31 +0200)]
Make frange selftests work on !HONOR_NANS systems.

I'm just shuffling the FP self tests here, with no change to existing
functionality.

If we agree that explicit NANs in the source code with !HONOR_NANS
should behave any differently, I'm happy to address whatever needs
fixing, but for now I'd like to unblock the !HONOR_NANS build systems.

I have added an adaptation of a test Jakub suggested we handle in the PR:

void funk(int cond)
{
  float x;

  if (cond)
    x = __builtin_nan ("");
  else
    x = 1.24;

  bar(x);
}

For !HONOR_NANS, the range for the PHI of x_1 is the union of 1.24 and
NAN which is really 1.24 with a maybe NAN.  This reflects the IL-- the
presence of the actual NAN.  However, VRP will propagate this because
it sees the 1.24 and ignores the possibility of a NAN, per
!HONOR_NANS.  IMO, this is correct.  OTOH, for HONOR_NANS the unknown
NAN property keeps us from propagating the value.

Is there a reason we don't warn for calls to __builtin_nan when
!HONOR_NANS?  That makes no sense to me.

PR tree-optimization/106785

gcc/ChangeLog:

* value-range.cc (range_tests_nan): Adjust tests for !HONOR_NANS.
(range_tests_floats): Same.

gcc/testsuite/ChangeLog:

* gcc.dg/tree-ssa/vrp-float-nan-1.c: New test.

23 months agomiddle-end: Add MULT_EXPR recognition for cond scalar reduction
konglin1 [Thu, 1 Sep 2022 06:40:42 +0000 (14:40 +0800)]
middle-end: Add MULT_EXPR recognition for cond scalar reduction

gcc/ChangeLog:

* tree-if-conv.cc (is_cond_scalar_reduction): Add MULT_EXPR
recognition.

gcc/testsuite/ChangeLog:

* gcc.dg/tree-ssa/gen-vect-34.c: New test.
* gcc.dg/vect/vect-ifcvt-18.c: New test.

23 months agors6000/test: Fix typo in pr86731-fwrapv-longlong.c [PR106682]
Kewen Lin [Thu, 1 Sep 2022 05:27:11 +0000 (00:27 -0500)]
rs6000/test: Fix typo in pr86731-fwrapv-longlong.c [PR106682]

Commit r12-2266 updated the scanned assembly content from

  "{\mlvx\M|\mlxv\M|\mlxvd2x\M}"

to

  "{\mp?lxv\M|\mlxv\M|\mlxvd2x\M}"

for the test case pr86731-fwrapv-longlong.c unexpectedly.

It's meant to update "lxv" to "p?lxv", should leave the
"lvx" unchanged.  So fix the typo accordingly.

PR testsuite/106682

gcc/testsuite/ChangeLog:

* gcc.target/powerpc/pr86731-fwrapv-longlong.c: Fix typo.

23 months agors6000: Don't ICE when we disassemble an MMA variable [PR101322]
Peter Bergner [Thu, 1 Sep 2022 02:14:36 +0000 (21:14 -0500)]
rs6000: Don't ICE when we disassemble an MMA variable [PR101322]

When we expand an MMA disassemble built-in with C++ using a pointer that
is cast to a valid MMA type, the type isn't passed down to the expand
machinery and we end up using the base type of the pointer which leads to
an ICE.  This patch enforces we always use the correct MMA type regardless
of the pointer type being used.

2022-08-31  Peter Bergner  <bergner@linux.ibm.com>

gcc/
PR target/101322
* config/rs6000/rs6000-builtin.cc (rs6000_gimple_fold_mma_builtin):
Enforce the use of a valid MMA pointer type.

gcc/testsuite/
PR target/101322
* g++.target/powerpc/pr101322.C: New test.

23 months agoRISC-V: Add vector registers in TARGET_CONDITIONAL_REGISTER_USAGE
zhongjuzhe [Tue, 30 Aug 2022 06:27:52 +0000 (14:27 +0800)]
RISC-V: Add vector registers in TARGET_CONDITIONAL_REGISTER_USAGE

gcc/ChangeLog:

* config/riscv/riscv.cc (riscv_conditional_register_usage): Add vector
registers.

23 months agoRISC-V: Add csrr vlenb instruction.
zhongjuzhe [Tue, 30 Aug 2022 06:20:27 +0000 (14:20 +0800)]
RISC-V: Add csrr vlenb instruction.

gcc/ChangeLog:

* config/riscv/riscv.cc (riscv_const_insns): Add cost of poly_int.
(riscv_output_move): Add csrr vlenb assembly.
* config/riscv/riscv.md (move_type): Add csrr vlenb type.
(ext): New attribute.
(ext_enabled): Ditto.
(enabled): Ditto.

23 months agoRISC-V: Add RVV constraints.
zhongjuzhe [Tue, 30 Aug 2022 06:13:51 +0000 (14:13 +0800)]
RISC-V: Add RVV constraints.

gcc/ChangeLog:

* config/riscv/constraints.md (TARGET_VECTOR ? V_REGS : NO_REGS): Add
"vr" constraint.
(TARGET_VECTOR ? VD_REGS : NO_REGS): Add "vd" constraint.
(TARGET_VECTOR ? VM_REGS : NO_REGS): Add "vm" constraint.
(vp): Add poly constraint.

23 months agoRISC-V: Fix comment in riscv.h
zhongjuzhe [Tue, 30 Aug 2022 02:57:42 +0000 (10:57 +0800)]
RISC-V: Fix comment in riscv.h

gcc/ChangeLog:

* config/riscv/riscv.h (enum reg_class): Change vype to vtype.

23 months agoRISC-V: Fix riscv_vector_chunks configuration according to TARGET_MIN_VLEN
zhongjuzhe [Tue, 30 Aug 2022 01:50:24 +0000 (09:50 +0800)]
RISC-V: Fix riscv_vector_chunks configuration according to TARGET_MIN_VLEN

gcc/ChangeLog:

* config/riscv/riscv.cc (riscv_convert_vector_bits): Change
configuration according to TARGET_MIN_VLEN.
* config/riscv/riscv.h (UNITS_PER_FP_REG): Fix comment.

23 months agoDaily bump.
GCC Administrator [Thu, 1 Sep 2022 00:17:39 +0000 (00:17 +0000)]
Daily bump.

23 months agoc: C2x attributes fixes and updates
Joseph Myers [Wed, 31 Aug 2022 22:22:07 +0000 (22:22 +0000)]
c: C2x attributes fixes and updates

Implement some changes to the currently supported C2x standard
attributes that have been made to the specification since they were
first implemented in GCC, and some consequent changes:

* maybe_unused is now supported on labels.  In fact that was already
  accidentally supported in GCC as a result of sharing the
  implementation with __attribute__ ((unused)), but needed to be
  covered in the tests.

* As part of the support for maybe_unused on labels, its
  __has_c_attribute value changed.

* The issue of maybe_unused accidentally being already supported on
  labels showed up the lack of tests for other standard attributes
  being incorrectly applied to labels; add such tests.

* Use of fallthrough or nodiscard attributes on labels already
  properly resulted in a pedwarn.  For the deprecated attribute,
  however, there was only a warning, and the wording "'deprecated'
  attribute ignored for 'void'" included an unhelpful "for 'void'".
  Arrange for the case of the deprecated attribute on a label to be
  checked for separately and result in a pedwarn.  As with
  inappropriate uses of fallthrough (see commit
  6c80b1b56dec2691436f3e2676e3d1b105b01b89), it seems reasonable for
  this pedwarn to apply regardless of whether [[]] or __attribute__
  was used and regardless of whether C or C++ is being compiled.

* Attributes on case or default labels (the standard syntax supports
  attributes on all kinds of labels) were quietly ignored, whether or
  not appropriate for use in such a context, because they weren't
  passed to decl_attributes at all.  (Note where I'm changing the
  do_case prototype that such a function is actually only defined in
  the C front end, not for C++, despite the declaration being in
  c-common.h.)

* A recent change as part of the editorial review in preparation for
  the C2x CD ballot has changed the __has_c_attribute value for
  fallthrough to 201910 to reflect when that attribute was actually
  voted into the working draft.

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

gcc/c-family/
* c-attribs.cc (handle_deprecated_attribute): Check and pedwarn
for LABEL_DECL.
* c-common.cc (c_add_case_label): Add argument ATTRS.  Call
decl_attributes.
* c-common.h (do_case, c_add_case_label): Update declarations.
* c-lex.cc (c_common_has_attribute): For C, produce a result of
201910 for fallthrough and 202106 for maybe_unused.

gcc/c/
* c-parser.cc (c_parser_label): Pass attributes to do_case.
* c-typeck.cc (do_case): Add argument ATTRS.  Pass it to
c_add_case_label.

gcc/testsuite/
* gcc.dg/c2x-attr-deprecated-2.c, gcc.dg/c2x-attr-fallthrough-2.c,
gcc.dg/c2x-attr-maybe_unused-1.c, gcc.dg/c2x-attr-nodiscard-2.c:
Add tests of attributes on labels.
* gcc.dg/c2x-has-c-attribute-2.c: Update expected results for
maybe_unused and fallthrough.

23 months agolibstdc++: A few more minor <ranges> cleanups
Patrick Palka [Wed, 31 Aug 2022 20:45:30 +0000 (16:45 -0400)]
libstdc++: A few more minor <ranges> cleanups

libstdc++-v3/ChangeLog:

* include/bits/ranges_base.h (__advance_fn::operator()): Add
parentheses in assert condition to avoid -Wparentheses warning.
* include/std/ranges: (take_view::take_view): Uglify 'base'.
(take_while_view::take_while_view): Likewise.
(elements_view::elements_view): Likewise.
(views::_Zip::operator()): Adjust position of [[nodiscard]] for
compatibility with -fconcepts-ts.
(zip_transform_view::_Sentinel): Uglify 'OtherConst'.
(views::_ZipTransform::operator()): Adjust position of
[[nodiscard]] for compatibilty with -fconcepts-ts.

23 months agohpux removal: regenerate configure files
Martin Liska [Wed, 31 Aug 2022 20:23:33 +0000 (22:23 +0200)]
hpux removal: regenerate configure files

fixincludes/ChangeLog:

* configure: Regenerate.

libitm/ChangeLog:

* configure: Regenerate.

23 months ago32-bit PA-RISC with HP-UX: remove deprecated ports
Martin Liska [Thu, 25 Aug 2022 12:30:51 +0000 (14:30 +0200)]
32-bit PA-RISC with HP-UX: remove deprecated ports

ChangeLog:

* configure: Regenerate.
* configure.ac: Delete hpux9 and hpux10.

config/ChangeLog:

* mh-pa-hpux10: Removed.

contrib/ChangeLog:

* config-list.mk: Remove deprecated ports.

contrib/header-tools/ChangeLog:

* README: Remove deprecated ports.
* reduce-headers: Likewise.

gcc/ChangeLog:

* config.build: Remove deprecated ports.
* config.gcc: Likewise.
* config.host: Likewise.
* configure.ac: Likewise.
* configure: Regenerate.
* config/pa/pa-hpux10.h: Removed.
* config/pa/pa-hpux10.opt: Removed.
* config/pa/t-dce-thr: Removed.

gnattools/ChangeLog:

* configure.ac: Remove deprecated ports.
* configure: Regenerate.

libstdc++-v3/ChangeLog:

* configure: Regenerate.
* crossconfig.m4: Remove deprecated ports.

gcc/testsuite/ChangeLog:

* g++.dg/cpp0x/lambda/lambda-conv.C: Remove useless test.
* gcc.c-torture/execute/ieee/hugeval.x: Likewise.
* gcc.dg/torture/pr47917.c: Likewise.
* lib/target-supports.exp: Likewise.

libgcc/ChangeLog:

* config.host: Remove hppa.

libitm/ChangeLog:

* configure: Regenerate.

fixincludes/ChangeLog:

* configure: Regenerate.

23 months agotestsuite: Fix warning regression due to std::string changes [PR106795]
Jonathan Wakely [Wed, 31 Aug 2022 19:36:23 +0000 (20:36 +0100)]
testsuite: Fix warning regression due to std::string changes [PR106795]

std::string now has [[nodiscard]] attributes on most members, causing
-Wunused-result warnings for this test.

gcc/testsuite/ChangeLog:

PR testsuite/106795
* g++.dg/tree-ssa/empty-loop.C: Use -Wno-unused-result.

23 months agoSupport --disable-fixincludes.
Martin Liska [Wed, 31 Aug 2022 19:55:45 +0000 (21:55 +0200)]
Support --disable-fixincludes.

Always install limits.h and syslimits.h header files
to include folder.

When --disable-fixincludes is used, then no system header files
are fixed by the tools in fixincludes. Moreover, the fixincludes
tools are not built any longer.

gcc/ChangeLog:

* Makefile.in: Always install limits.h and syslimits.h to
include folder.
* configure.ac: Assign STMP_FIXINC blank if
--disable-fixincludes is used.
* configure: Regenerate.

23 months agolibstdc++: [_GLIBCXX_DEBUG] Review nullptr assertion diagnostics
François Dumont [Sun, 14 Aug 2022 15:11:02 +0000 (17:11 +0200)]
libstdc++: [_GLIBCXX_DEBUG] Review nullptr assertion diagnostics

Review null string checks to show:
_String != nullptr

rather than:
_String != 0

libstdc++-v3/ChangeLog:

* include/debug/debug.h: Use nullptr rather than '0' in checks in post-C++11.
* include/debug/string: Likewise.
* testsuite/21_strings/basic_string/operations/ends_with/char.cc: Use __gnu_test::string.
* testsuite/21_strings/basic_string/operations/ends_with/nonnull.cc: Likewise.
* testsuite/21_strings/basic_string/operations/ends_with/wchar_t.cc: Likewise.
* testsuite/21_strings/basic_string/operations/starts_with/wchar_t.cc: Likewise.
* testsuite/21_strings/basic_string/operations/starts_with/nonnull.cc: Likewise.
* testsuite/21_strings/basic_string/operations/starts_with/char.cc: Likewise..

23 months agolibstdc++: Implement ranges::adjacent_view from P2321R2
Patrick Palka [Wed, 31 Aug 2022 19:09:10 +0000 (15:09 -0400)]
libstdc++: Implement ranges::adjacent_view from P2321R2

libstdc++-v3/ChangeLog:

* include/std/ranges (adjacent_view): Define.
(enable_borrowed_range<adjacent_view>): Define.
(__detail::__repeated_tuple): Define.
(adjacent_view::_Iterator): Define.
(adjacent_view::_Sentinel): Define.
(views::__detail::__can_adjacent_view): Define.
(views::_Adjacent): Define.
(views::adjacent): Define.
(views::pairwise): Define.
* testsuite/std/ranges/adaptors/adjacent/1.cc: New test.

23 months agolibstdc++: [_GLIBCXX_DEBUG] Add backtrace generation on demand
François Dumont [Tue, 21 Jan 2020 18:33:15 +0000 (19:33 +0100)]
libstdc++: [_GLIBCXX_DEBUG] Add backtrace generation on demand

  Add _GLIBCXX_DEBUG_BACKTRACE macro to activate backtrace generation on
_GLIBCXX_DEBUG assertions. Prerequisite is to have configure the lib with:

--enable-libstdcxx-backtrace=yes

libstdc++-v3/ChangeLog:

* include/debug/formatter.h
[_GLIBCXX_HAVE_STACKTRACE](__glibcxx_backtrace_state): Declare.
[_GLIBCXX_HAVE_STACKTRACE](__glibcxx_backtrace_create_state): Declare.
[_GLIBCXX_HAVE_STACKTRACE](__glibcxx_backtrace_full_callback): Define.
[_GLIBCXX_HAVE_STACKTRACE](__glibcxx_backtrace_error_callback): Define.
[_GLIBCXX_HAVE_STACKTRACE](__glibcxx_backtrace_full_func): Define.
[_GLIBCXX_HAVE_STACKTRACE](__glibcxx_backtrace_full): Declare.
[_GLIBCXX_HAVE_STACKTRACE](_Error_formatter::_M_backtrace_state): New.
[_GLIBCXX_HAVE_STACKTRACE](_Error_formatter::_M_backtrace_full): New.
* src/c++11/debug.cc [_GLIBCXX_HAVE_STACKTRACE](print_backtrace): New.
(_Error_formatter::_M_error()): Adapt.
* src/libbacktrace/Makefile.am: Add backtrace.c.
* src/libbacktrace/Makefile.in: Regenerate.
* src/libbacktrace/backtrace-rename.h (backtrace_full): New.
* testsuite/23_containers/vector/debug/assign4_backtrace_neg.cc: New test.
* doc/xml/manual/debug_mode.xml: Document _GLIBCXX_DEBUG_BACKTRACE.
* doc/xml/manual/using.xml: Likewise.

23 months agoaarch64: Update sizeless tests for recent GNU C changes
Richard Sandiford [Wed, 31 Aug 2022 14:39:27 +0000 (15:39 +0100)]
aarch64: Update sizeless tests for recent GNU C changes

The tests for sizeless SVE types include checks that the types
are handled for initialisation purposes in the same way as scalars.
GNU C and C2x now allow scalars to be initialised using empty braces,
so this patch updates the SVE tests to match.

gcc/testsuite/
* gcc.target/aarch64/sve/acle/general-c/gnu_vectors_1.c: Update
tests for empty initializers.
* gcc.target/aarch64/sve/acle/general-c/gnu_vectors_2.c: Likewise.
* gcc.target/aarch64/sve/acle/general-c/sizeless-1.c: Likewise.
* gcc.target/aarch64/sve/acle/general-c/sizeless-2.c: Likewise.

23 months agoAvoid fatal fails in predicate::init_from_control_deps
Richard Biener [Wed, 31 Aug 2022 13:25:32 +0000 (15:25 +0200)]
Avoid fatal fails in predicate::init_from_control_deps

When processing USE predicates we can drop from the AND chain,
when procsssing DEF predicates we can drop from the OR chain.  Do
that instead of giving up completely.  This also removes cases
that should never trigger.

* gimple-predicate-analysis.cc (predicate::init_from_control_deps):
Assert the guard_bb isn't empty and has more than one successor.
Drop appropriate parts of the predicate when an edge fails to
register a predicate.
(predicate::dump): Dump empty predicate as TRUE.

23 months agolibstdc++: Add test for std::con/disjunction's short circuiting
Patrick Palka [Wed, 31 Aug 2022 14:04:54 +0000 (10:04 -0400)]
libstdc++: Add test for std::con/disjunction's short circuiting

libstdc++-v3/ChangeLog:

* testsuite/20_util/logical_traits/requirements/short_circuit.cc: New test.

23 months agolibstdc++: Add noexcept-specifier to std::reference_wrapper::operator()
Jonathan Wakely [Wed, 31 Aug 2022 12:57:34 +0000 (13:57 +0100)]
libstdc++: Add noexcept-specifier to std::reference_wrapper::operator()

This isn't required by the standard, but there's an LWG issue suggesting
to add it.

Also use __invoke_result instead of result_of, to match the spec in
recent standards.

libstdc++-v3/ChangeLog:

* include/bits/refwrap.h (reference_wrapper::operator()): Add
noexcept-specifier and use __invoke_result instead of result_of.
* testsuite/20_util/reference_wrapper/invoke-noexcept.cc: New test.

23 months agolibstdc++: Improve comments in std::reference_wrapper tests
Jonathan Wakely [Wed, 31 Aug 2022 12:44:45 +0000 (13:44 +0100)]
libstdc++: Improve comments in std::reference_wrapper tests

libstdc++-v3/ChangeLog:

* testsuite/20_util/reference_wrapper/invoke-2.cc: Improve
comments.
* testsuite/20_util/reference_wrapper/invoke-3.cc: Likewise.
* testsuite/20_util/reference_wrapper/invoke.cc: Likewise.

23 months agotree-optimization/90994 - fix uninit diagnostics with EH
Richard Biener [Wed, 31 Aug 2022 12:04:46 +0000 (14:04 +0200)]
tree-optimization/90994 - fix uninit diagnostics with EH

r12-3640-g94c12ffac234b2 sneaked in a hack to avoid the diagnostic
for the testcase in PR90994 which sees non-call EH control flow
confusing predicate analysis.  The following patch instead adjusts
the existing code handling EH to handle non-calls and do what I
think was intented.

PR tree-optimization/90994
* gimple-predicate-analysis.cc (predicate::init_from_control_deps):
Ignore exceptional control flow and skip the edge for the purpose of
predicate generation also for non-calls.

* g++.dg/torture/pr90994.C: New testcase.

23 months agoStream out endpoints for frange.
Aldy Hernandez [Wed, 31 Aug 2022 10:09:44 +0000 (12:09 +0200)]
Stream out endpoints for frange.

We only stream out the FP properties for global float ranges
(currently only NAN).  The following patch adds the endpoints as well.

gcc/ChangeLog:

* value-range-storage.cc (frange_storage_slot::set_frange): Save
endpoints.
(frange_storage_slot::get_frange): Restore endpoints.
* value-range-storage.h (class frange_storage_slot): Add endpoint
fields.

23 months agoremove unused function
Martin Liska [Wed, 31 Aug 2022 12:33:40 +0000 (14:33 +0200)]
remove unused function

PR tree-optimization/106789

gcc/ChangeLog:

* range-op-float.cc (default_frelop_fold_range): Remove the
  function.

23 months agofix clang warnings (-Winconsistent-missing-override)
Martin Liska [Wed, 31 Aug 2022 12:19:24 +0000 (14:19 +0200)]
fix clang warnings (-Winconsistent-missing-override)

gcc/ChangeLog:

* value-range.h: Add more override keywords.

23 months agofix -Winconsistent-missing-override clang warning
Martin Liska [Wed, 31 Aug 2022 12:12:48 +0000 (14:12 +0200)]
fix -Winconsistent-missing-override clang warning

Fixes:
gcc/value-range.h:357:16: warning: 'set_nonnegative' overrides
a member function but is not marked 'override' [-Winconsistent-missing-override]

gcc/ChangeLog:

* value-range.h: Add override.

23 months agotree-optimization/65244 - include asserts in predicates for uninit
Richard Biener [Tue, 30 Aug 2022 08:31:26 +0000 (10:31 +0200)]
tree-optimization/65244 - include asserts in predicates for uninit

When uninit computes the actual predicates from the control dependence
edges it currently skips those that are assert-like (where one edge
leads to a block which ends in a noreturn call).  That leads to
bogus uninit diagnostics when applied on the USE side.

PR tree-optimization/65244
* gimple-predicate-analysis.h (predicate::init_from_control_deps):
Add argument to specify whether the predicate is for the USE.
* gimple-predicate-analysis.cc (predicate::init_from_control_deps):
Also include predicates effective fallthru control edges when
the predicate is for the USE.

* gcc.dg/uninit-pr65244-2.c: New testcase.

23 months agotree-optimization/73550 - more switch handling improvements for uninit
Richard Biener [Wed, 31 Aug 2022 06:52:58 +0000 (08:52 +0200)]
tree-optimization/73550 - more switch handling improvements for uninit

The following makes predicate analysis handle case labels with
a non-singleton contiguous range.

PR tree-optimization/73550
* gimple-predicate-analysis.cc (predicate::init_from_control_deps):
Sanitize debug dumping.  Handle case labels with a CASE_HIGH.
(predicate::dump): Adjust for better readability.

23 months agolibstdc++: Add [[nodiscard]] attribute to <string> and <string_view>
Jonathan Wakely [Fri, 26 Aug 2022 15:22:21 +0000 (16:22 +0100)]
libstdc++: Add [[nodiscard]] attribute to <string> and <string_view>

libstdc++-v3/ChangeLog:

* include/bits/basic_string.h (basic_string): Add nodiscard
attribute to all relevant functions.
* include/std/string_view (basic_string_view): Likewise.
* testsuite/21_strings/basic_string/capacity/1.cc: Cast unused
results to void.
* testsuite/21_strings/basic_string/capacity/char/1.cc:
Likewise.
* testsuite/21_strings/basic_string/capacity/wchar_t/1.cc:
Likewise.
* testsuite/21_strings/basic_string/cons/char/self_move.cc:
Likewise.
* testsuite/21_strings/basic_string/element_access/char/1.cc:
Likewise.
* testsuite/21_strings/basic_string/element_access/char/21674.cc:
Likewise.
* testsuite/21_strings/basic_string/element_access/wchar_t/1.cc:
Likewise.
* testsuite/21_strings/basic_string/element_access/wchar_t/21674.cc:
Likewise.
* testsuite/21_strings/basic_string/lwg2758.cc: Likewise.
* testsuite/21_strings/basic_string/lwg2946.cc: Likewise.
* testsuite/21_strings/basic_string/operations/contains/nonnull.cc:
Add -Wno-unused-result to options.
* testsuite/21_strings/basic_string/operations/ends_with/nonnull.cc:
Likewise.
* testsuite/21_strings/basic_string/operations/starts_with/nonnull.cc:
Likewise.
* testsuite/21_strings/basic_string/operators/char/1.cc: Cast
unused results to void.
* testsuite/21_strings/basic_string/operators/wchar_t/1.cc:
Likewise.
* testsuite/21_strings/basic_string_view/capacity/1.cc:
Likewise.
* testsuite/21_strings/basic_string_view/element_access/char/1.cc:
Likewise.
* testsuite/21_strings/basic_string_view/element_access/char/2.cc:
Likewise.
* testsuite/21_strings/basic_string_view/element_access/wchar_t/1.cc:
Likewise.
* testsuite/21_strings/basic_string_view/element_access/wchar_t/2.cc:
Likewise.
* testsuite/21_strings/basic_string_view/operations/contains/nonnull.cc:
Likewise.
Add -Wno-unused-result to options.
* testsuite/21_strings/basic_string_view/operations/ends_with/nonnull.cc:
Likewise.
* testsuite/21_strings/basic_string_view/operations/starts_with/nonnull.cc:
Likewise.
* testsuite/27_io/basic_stringbuf/sputbackc/char/1.cc: Cast
unused results to void.
* testsuite/27_io/basic_stringbuf/sputbackc/wchar_t/1.cc:
Likewise.
* testsuite/27_io/basic_stringbuf/sungetc/char/1.cc: Likewise.
* testsuite/27_io/basic_stringbuf/sungetc/wchar_t/1.cc:
Likewise.

23 months agouninit testcase for PR65244
Richard Biener [Wed, 31 Aug 2022 09:05:33 +0000 (11:05 +0200)]
uninit testcase for PR65244

The PR65244 has an issue with code in init_from_control_deps
for which there's no direct testcase.  The following adds one.

PR tree-optimization/65244
* gcc.dg/uninit-pr65244-1.c: New testcase.

23 months agolibcpp: Make static checkers happy about makeuname2c [PR106778]
Jakub Jelinek [Wed, 31 Aug 2022 08:22:36 +0000 (10:22 +0200)]
libcpp: Make static checkers happy about makeuname2c [PR106778]

The assertion ensures that we point within the image and at a byte
we haven't touched yet (or at least that it isn't the first byte
of an already stored tree), some static checker was unhappy about
first checking that it is zero and only afterwards checking that it
is within bounds.

2022-08-31  Jakub Jelinek  <jakub@redhat.com>

PR preprocessor/106778
* makeuname2c.cc (write_nodes): Reverse order of && operands in
assert.

23 months agoomp-simd-clone: Unbreak bootstrap
Jakub Jelinek [Wed, 31 Aug 2022 08:20:54 +0000 (10:20 +0200)]
omp-simd-clone: Unbreak bootstrap

This patch fixes -Werror=sign-compare errors during stage2/stage3.

2022-08-30  Rainer Orth  <ro@CeBiTec.Uni-Bielefeld.DE>
    Jakub Jelinek  <jakub@redhat.com>

* omp-simd-clone.cc (simd_clone_adjust_return_type,
simd_clone_adjust_argument_types): Use known_eq (veclen, 0U)
instead of known_eq (veclen, 0) to avoid -Wsign-compare warnings.

23 months agovect: Fix stray argument in call to dump_printf_loc
Richard Sandiford [Wed, 31 Aug 2022 08:17:43 +0000 (09:17 +0100)]
vect: Fix stray argument in call to dump_printf_loc

One call to dump_printf_loc had a stray left-over argument
from an earlier version of the patch.  This went unnoticed
on aarch64-linux-gnu and x86_64-linux-gnu since the parameters
that actually mattered were passed in FPRs rather than GPRs,
but I assume this is the reason for the i686-linux-gnu failures
that Jakub hit.

gcc/
* tree-vect-slp.cc (vect_optimize_slp_pass::dump): Remove bogus
argument.

23 months agomiddle-end: Fix unexpected warnings for RISC-V port.
zhongjuzhe [Tue, 23 Aug 2022 07:06:31 +0000 (15:06 +0800)]
middle-end: Fix unexpected warnings for RISC-V port.

gcc/ChangeLog:

* tree-vect-loop-manip.cc (vect_gen_vector_loop_niters): Simply
initialize const_vf to 0.

23 months agocr16: remove leftover in config.gcc
Martin Liska [Wed, 31 Aug 2022 07:07:01 +0000 (09:07 +0200)]
cr16: remove leftover in config.gcc

gcc/ChangeLog:

* config.gcc: Remove cr16.

23 months agolibsanitizer: enable libubsan and libasan for loongarch64-*-linux*
Xi Ruoyao [Wed, 31 Aug 2022 05:46:22 +0000 (13:46 +0800)]
libsanitizer: enable libubsan and libasan for loongarch64-*-linux*

The LoongArch support for libubsan and libasan has been added in:

- https://reviews.llvm.org/D129371
- https://reviews.llvm.org/D129418

and we've merged them in r13-2269.  It's time to enable them.

No unexpected failures in GCC asan.exp and ubsan.exp tests.

libsanitizer/ChangeLog:

* configure.tgt: Allow loongarch64-*-linux*.

23 months agoDaily bump.
GCC Administrator [Wed, 31 Aug 2022 00:16:45 +0000 (00:16 +0000)]
Daily bump.

23 months agoUpdate gcc sv.po
Joseph Myers [Tue, 30 Aug 2022 22:03:47 +0000 (22:03 +0000)]
Update gcc sv.po

* sv.po: Update.

23 months agovec: Add array_slice constructors from non-const and gc vectors
Martin Jambor [Tue, 30 Aug 2022 16:50:35 +0000 (18:50 +0200)]
vec: Add array_slice constructors from non-const and gc vectors

This patch adds constructors of array_slice that are required to
create them from non-const (heap or auto) vectors or from GC vectors.

gcc/ChangeLog:

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

* vec.h (array_slice): Add constructors for non-const reference to
heap vector and pointers to heap vectors.

23 months agoImprove union of ranges containing NAN.
Aldy Hernandez [Tue, 30 Aug 2022 13:46:43 +0000 (15:46 +0200)]
Improve union of ranges containing NAN.

Previously [5,6] U NAN would just drop to VARYING.  With this patch,
the resulting range becomes [5,6] with the NAN bit set to unknown.

[I still have yet to decide what to do with intersections.  ISTM, the
intersection of a known NAN with anything else should be a NAN, but it
could also be undefined (the empty set).  I'll have to run some tests
and see.  Currently, we drop to VARYING cause well... it's always safe
to give up;-).]

gcc/ChangeLog:

* value-range.cc (early_nan_resolve): Change comment.
(frange::union_): Handle union when one side is a NAN.
(range_tests_nan): Add tests for NAN union.

23 months agoamdgcn: OpenMP SIMD routine support
Andrew Stubbs [Thu, 14 Jul 2022 10:31:31 +0000 (11:31 +0100)]
amdgcn: OpenMP SIMD routine support

Enable and configure SIMD clones for amdgcn.  This affects both the __simd__
function attribute, and the OpenMP "declare simd" directive.

Note that the masked SIMD variants are generated, but the middle end doesn't
actually support calling them yet.

gcc/ChangeLog:

* config/gcn/gcn.cc (gcn_simd_clone_compute_vecsize_and_simdlen): New.
(gcn_simd_clone_adjust): New.
(gcn_simd_clone_usable): New.
(TARGET_SIMD_CLONE_ADJUST): New.
(TARGET_SIMD_CLONE_COMPUTE_VECSIZE_AND_SIMDLEN): New.
(TARGET_SIMD_CLONE_USABLE): New.

gcc/testsuite/ChangeLog:

* gcc.dg/vect/vect-simd-clone-1.c: Add dg-warning.
* gcc.dg/vect/vect-simd-clone-2.c: Add dg-warning.
* gcc.dg/vect/vect-simd-clone-3.c: Add dg-warning.
* gcc.dg/vect/vect-simd-clone-4.c: Add dg-warning.
* gcc.dg/vect/vect-simd-clone-5.c: Add dg-warning.
* gcc.dg/vect/vect-simd-clone-8.c: Add dg-warning.

23 months agoomp-simd-clone: Allow fixed-lane vectors
Andrew Stubbs [Fri, 5 Aug 2022 12:28:50 +0000 (13:28 +0100)]
omp-simd-clone: Allow fixed-lane vectors

The vecsize_int/vecsize_float has an assumption that all arguments will use
the same bitsize, and vary the number of lanes according to the element size,
but this is inappropriate on targets where the number of lanes is fixed and
the bitsize varies (i.e. amdgcn).

With this change the vecsize can be left zero and the vectorization factor will
be the same for all types.

gcc/ChangeLog:

* doc/tm.texi: Regenerate.
* omp-simd-clone.cc (simd_clone_adjust_return_type): Allow zero
vecsize.
(simd_clone_adjust_argument_types): Likewise.
* target.def (compute_vecsize_and_simdlen): Document the new
vecsize_int and vecsize_float semantics.

23 months agoexpmed: Fix store_bit_field_1 subreg offset
Richard Sandiford [Tue, 30 Aug 2022 14:43:48 +0000 (15:43 +0100)]
expmed: Fix store_bit_field_1 subreg offset

store_bit_field_1 tries to convert a field assignment into a subreg
assignment.  Normally it must check that the field occupies a full
word (or more specifically, a full REGMODE_NATURAL_SIZE chunk),
so that writing to the subreg doesn't clobber any other fields.
But it can skip that check if the structure is known to be in
an undefined state.

The idea was that, in the undefined case, we could rely on
simplify_gen_subreg to do the check for a valid subreg, rather
than having to repeat the required endianness logic in the caller.

Before the addition of the undefined case, the code could use
regnum * regsize to get the byte offset, where regnum came from
checking that the start was word-aligned.  In the undefined case
we need to calculate the byte offset explicitly.

gcc/
* expmed.cc (store_bit_field_1): Fix byte offset calculation
for undefined structures.

23 months agoExtend SLP permutation optimisations
Richard Sandiford [Tue, 30 Aug 2022 14:43:47 +0000 (15:43 +0100)]
Extend SLP permutation optimisations

Currently SLP tries to force permute operations "down" the graph
from loads in the hope of reducing the total number of permutations
needed or (in the best case) removing the need for the permutations
entirely.  This patch tries to extend it as follows:

- Allow loads to take a different permutation from the one they
  started with, rather than choosing between "original permutation"
  and "no permutation".

- Allow changes in both directions, if the target supports the
  reverse permutation.

- Treat the placement of permutations as a two-way dataflow problem:
  after propagating information from leaves to roots (as now), propagate
  information back up the graph.

- Take execution frequency into account when optimising for speed,
  so that (for example) permutations inside loops have a higher
  cost than permutations outside loops.

- Try to reduce the total number of permutations when optimising for
  size, even if that increases the number of permutations on a given
  execution path.

See the big block comment above vect_optimize_slp_pass for
a detailed description.

The original motivation for doing this was to add a framework that would
allow other layout differences in future.  The two main ones are:

- Make it easier to represent predicated operations, including
  predicated operations with gaps.  E.g.:

     a[0] += 1;
     a[1] += 1;
     a[3] += 1;

  could be a single load/add/store for SVE.  We could handle this
  by representing a layout such as { 0, 1, _, 2 } or { 0, 1, _, 3 }
  (depending on what's being counted).  We might need to move
  elements between lanes at various points, like with permutes.

  (This would first mean adding support for stores with gaps.)

- Make it easier to switch between an even/odd and unpermuted layout
  when switching between wide and narrow elements.  E.g. if a widening
  operation produces an even vector and an odd vector, we should try
  to keep operations on the wide elements in that order rather than
  force them to be permuted back "in order".

To give some examples of what the patch does:

int f1(int *__restrict a, int *__restrict b, int *__restrict c,
       int *__restrict d)
{
  a[0] = (b[1] << c[3]) - d[1];
  a[1] = (b[0] << c[2]) - d[0];
  a[2] = (b[3] << c[1]) - d[3];
  a[3] = (b[2] << c[0]) - d[2];
}

continues to produce the same code as before when optimising for
speed: b, c and d are permuted at load time.  But when optimising
for size we instead permute c into the same order as b+d and then
permute the result of the arithmetic into the same order as a:

        ldr     q1, [x2]
        ldr     q0, [x1]
        ext     v1.16b, v1.16b, v1.16b, #8     // <------
        sshl    v0.4s, v0.4s, v1.4s
        ldr     q1, [x3]
        sub     v0.4s, v0.4s, v1.4s
        rev64   v0.4s, v0.4s                   // <------
        str     q0, [x0]
        ret

The following function:

int f2(int *__restrict a, int *__restrict b, int *__restrict c,
       int *__restrict d)
{
  a[0] = (b[3] << c[3]) - d[3];
  a[1] = (b[2] << c[2]) - d[2];
  a[2] = (b[1] << c[1]) - d[1];
  a[3] = (b[0] << c[0]) - d[0];
}

continues to push the reverse down to just before the store,
like the previous code did.

In:

int f3(int *__restrict a, int *__restrict b, int *__restrict c,
       int *__restrict d)
{
  for (int i = 0; i < 100; ++i)
    {
      a[0] = (a[0] + c[3]);
      a[1] = (a[1] + c[2]);
      a[2] = (a[2] + c[1]);
      a[3] = (a[3] + c[0]);
      c += 4;
    }
}

the loads of a are hoisted and the stores of a are sunk, so that
only the load from c happens in the loop.  When optimising for
speed, we prefer to have the loop operate on the reversed layout,
changing on entry and exit from the loop:

        mov     x3, x0
        adrp    x0, .LC0
        add     x1, x2, 1600
        ldr     q2, [x0, #:lo12:.LC0]
        ldr     q0, [x3]
        mov     v1.16b, v0.16b
        tbl     v0.16b, {v0.16b - v1.16b}, v2.16b    // <--------
        .p2align 3,,7
.L6:
        ldr     q1, [x2], 16
        add     v0.4s, v0.4s, v1.4s
        cmp     x2, x1
        bne     .L6
        mov     v1.16b, v0.16b
        adrp    x0, .LC0
        ldr     q2, [x0, #:lo12:.LC0]
        tbl     v0.16b, {v0.16b - v1.16b}, v2.16b    // <--------
        str     q0, [x3]
        ret

Similarly, for the very artificial testcase:

int f4(int *__restrict a, int *__restrict b, int *__restrict c,
       int *__restrict d)
{
  int a0 = a[0];
  int a1 = a[1];
  int a2 = a[2];
  int a3 = a[3];
  for (int i = 0; i < 100; ++i)
    {
      a0 ^= c[0];
      a1 ^= c[1];
      a2 ^= c[2];
      a3 ^= c[3];
      c += 4;
      for (int j = 0; j < 100; ++j)
{
  a0 += d[1];
  a1 += d[0];
  a2 += d[3];
  a3 += d[2];
  d += 4;
}
      b[0] = a0;
      b[1] = a1;
      b[2] = a2;
      b[3] = a3;
      b += 4;
    }
  a[0] = a0;
  a[1] = a1;
  a[2] = a2;
  a[3] = a3;
}

the a vector in the inner loop maintains the order { 1, 0, 3, 2 },
even though it's part of an SCC that includes the outer loop.
In other words, this is a motivating case for not assigning
permutes at SCC granularity.  The code we get is:

        ldr     q0, [x0]
        mov     x4, x1
        mov     x5, x0
        add     x1, x3, 1600
        add     x3, x4, 1600
        .p2align 3,,7
.L11:
        ldr     q1, [x2], 16
        sub     x0, x1, #1600
        eor     v0.16b, v1.16b, v0.16b
        rev64   v0.4s, v0.4s              // <---
        .p2align 3,,7
.L10:
        ldr     q1, [x0], 16
        add     v0.4s, v0.4s, v1.4s
        cmp     x0, x1
        bne     .L10
        rev64   v0.4s, v0.4s              // <---
        add     x1, x0, 1600
        str     q0, [x4], 16
        cmp     x3, x4
        bne     .L11
        str     q0, [x5]
        ret

bb-slp-layout-17.c is a collection of compile tests for problems
I hit with earlier versions of the patch.  The same prolems might
show up elsewhere, but it seemed worth having the test anyway.

In slp-11b.c we previously pushed the permutation of the in[i*4]
group down from the load to just before the store.  That didn't
reduce the number or frequency of the permutations (or increase
them either).  But separating the permute from the load meant
that we could no longer use load/store lanes.

Whether load/store lanes are a good idea here is another question.
If there were two sets of loads, and if we could use a single
permutation instead of one per load, then avoiding load/store
lanes should be a good thing even under the current abstract
cost model.  But I think under the current model we should
try to avoid splitting up potential load/store lanes groups
if there is no specific benefit to the split.

Preferring load/store lanes is still a source of missed optimisations
that we should fix one day...

gcc/
* params.opt (-param=vect-max-layout-candidates=): New parameter.
* doc/invoke.texi (vect-max-layout-candidates): Document it.
* tree-vectorizer.h (auto_lane_permutation_t): New typedef.
(auto_load_permutation_t): Likewise.
* tree-vect-slp.cc (vect_slp_node_weight): New function.
(slpg_layout_cost): New class.
(slpg_vertex): Replace perm_in and perm_out with partition,
out_degree, weight and out_weight.
(slpg_partition_info, slpg_partition_layout_costs): New classes.
(vect_optimize_slp_pass): Likewise, cannibalizing some part of
the previous vect_optimize_slp.
(vect_optimize_slp): Use it.

gcc/testsuite/
* lib/target-supports.exp (check_effective_target_vect_var_shift):
Return true for aarch64.
* gcc.dg/vect/bb-slp-layout-1.c: New test.
* gcc.dg/vect/bb-slp-layout-2.c: New test.
* gcc.dg/vect/bb-slp-layout-3.c: New test.
* gcc.dg/vect/bb-slp-layout-4.c: New test.
* gcc.dg/vect/bb-slp-layout-5.c: New test.
* gcc.dg/vect/bb-slp-layout-6.c: New test.
* gcc.dg/vect/bb-slp-layout-7.c: New test.
* gcc.dg/vect/bb-slp-layout-8.c: New test.
* gcc.dg/vect/bb-slp-layout-9.c: New test.
* gcc.dg/vect/bb-slp-layout-10.c: New test.
* gcc.dg/vect/bb-slp-layout-11.c: New test.
* gcc.dg/vect/bb-slp-layout-13.c: New test.
* gcc.dg/vect/bb-slp-layout-14.c: New test.
* gcc.dg/vect/bb-slp-layout-15.c: New test.
* gcc.dg/vect/bb-slp-layout-16.c: New test.
* gcc.dg/vect/bb-slp-layout-17.c: New test.
* gcc.dg/vect/slp-11b.c: XFAIL SLP test for load-lanes targets.

23 months agoAdd base hash traits for vectors
Richard Sandiford [Tue, 30 Aug 2022 14:43:47 +0000 (15:43 +0100)]
Add base hash traits for vectors

This patch adds a class that provides basic hash/equal functions
for vectors, based on corresponding traits for the element type.

gcc/
* hash-traits.h (vec_hash_base): New class.
(vec_free_hash_base): Likewise.

23 months agoRearrange unbounded_hashmap_traits
Richard Sandiford [Tue, 30 Aug 2022 14:43:47 +0000 (15:43 +0100)]
Rearrange unbounded_hashmap_traits

int_hash combines two kinds of operation:

(1) hashing and equality of integers
(2) using spare integer encodings to represent empty and deleted slots

(1) is really independent of (2), and could be useful in cases where
no spare integer encodings are available.  This patch adds a base class
(int_hash_base) for (1) and makes int_hash inherit from it.

If we follow a similar style for future hashes, we can make
unbounded_hashmap_traits take the "base" hash for the key
as a template parameter, rather than requiring every type of
key to have a separate derivative of unbounded_hashmap_traits.
A later patch applies this to vector keys.

No functional change intended.

gcc/
* hash-traits.h (int_hash_base): New struct, split out from...
(int_hash): ...this class, which now inherits from int_hash_base.
* hash-map-traits.h (unbounded_hashmap_traits): Take a template
parameter for the key that provides hash and equality functions.
(unbounded_int_hashmap_traits): Turn into a type alias of
unbounded_hashmap_traits.

23 months agoMake graphds_scc pass the node order back to callers
Richard Sandiford [Tue, 30 Aug 2022 14:43:46 +0000 (15:43 +0100)]
Make graphds_scc pass the node order back to callers

As a side-effect, graphds_scc constructs a vector in which all
nodes in an SCC are listed consecutively.  This can be useful
information, so that the patch adds an optional pass-back parameter
for it.  The interface is similar to the one for graphds_dfs.

gcc/
* graphds.cc (graphds_scc): Add a pass-back parameter for the
final node order.
* graphds.h (graphds_scc): Update prototype accordingly.

23 months agoSplit code out of vect_transform_slp_perm_load
Richard Sandiford [Tue, 30 Aug 2022 14:43:46 +0000 (15:43 +0100)]
Split code out of vect_transform_slp_perm_load

Similarly to the previous vectorizable_slp_permutation patch,
this one splits out the main part of vect_transform_slp_perm_load
so that a later patch can test a permutation without constructing
a node for it.

Also fixes a lingering use of STMT_VINFO_VECTYPE.

gcc/
* tree-vect-slp.cc (vect_transform_slp_perm_load_1): Split out from...
(vect_transform_slp_perm_load): ...here.  Use SLP_TREE_VECTYPE instead
of STMT_VINFO_VECTYPE.

23 months agoSplit code out of vectorizable_slp_permutation
Richard Sandiford [Tue, 30 Aug 2022 14:43:45 +0000 (15:43 +0100)]
Split code out of vectorizable_slp_permutation

A later patch needs to test whether the target supports a
lane_permutation_t without having to construct a full SLP
node to test that.  This patch splits out most of the work
of vectorizable_slp_permutation into a subroutine, so that
properties of the permutation can be passed explicitly without
disturbing the main interface.

The new subroutine still uses an slp_tree argument to get things
like the number of lanes and the vector type.  That's a bit clunky,
but it seemed like the least worst option.

gcc/
* tree-vect-slp.cc (vectorizable_slp_permutation_1): Split out from...
(vectorizable_slp_permutation): ...here.

23 months agovect: Tighten get_related_vectype_for_scalar_type
Richard Sandiford [Tue, 30 Aug 2022 14:43:45 +0000 (15:43 +0100)]
vect: Tighten get_related_vectype_for_scalar_type

Builds of glibc with SVE enabled have been failing since V1DI was added
to the aarch64 port.  The problem is that BB SLP starts the (hopeless)
attempt to use variable-length modes to vectorise a single-element
vector, and that now gets further than it did before.

Initially we tried getting a vector mode with 1 + 1X DI elements
(i.e. 1 DI per 128-bit vector chunk).  We don't provide such a mode --
it would be VNx1DI -- because it isn't a native SVE format.  We then
try just 1 DI, which previously failed but now succeeds.

There are numerous ways we could fix this.  Perhaps the most obvious
would be to skip variable-length modes for BB SLP.  However, I think
that'd just be kicking the can down the road, since eventually we want
to support BB SLP and VLA vectors using predication.

However, if we do use VLA vectors for BB SLP, the vector modes
we use should actually be variable length.  We don't want to use
variable-length vectors for some element types/group sizes and
fixed-length vectors for others, since it would be difficult
to handle the seams.

The same principle applies during loop vectorisation.  We can't
use a mixture of variable-length and fixed-length vectors for
the same loop because the relative unroll/vectorisation factors
would not be constant (compile-time) multiples of each other.

This patch therefore makes get_related_vectype_for_scalar_type
check that the provided number of units is interoperable with
the provided prevailing mode.  The function is generally quite
forgiving -- it does basic things like checking for scalarness
itself rather than expecting callers to do them -- so the new
check feels in keeping with that.

This seems to subsume the fix for PR96974.  I'm not sure it's
worth reverting that code to an assert though, so the patch just
drops the scan for the associated message.

gcc/
* tree-vect-stmts.cc (get_related_vectype_for_scalar_type): Check
that the requested number of units is interoperable with the requested
prevailing mode.

gcc/testsuite/
* gcc.target/aarch64/sve/slp_15.c: New test.
* g++.target/aarch64/sve/pr96974.C: Remove scan test.

23 months agoChange get_std_name_hint to use generated hash table
Ulrich Drepper [Tue, 30 Aug 2022 14:33:51 +0000 (16:33 +0200)]
Change get_std_name_hint to use generated hash table

The get_std_name_hint function so far uses linear search to locate
matching entries.  After adding more hint entries this might not be
appropriate anymore.  Therefore this patch also replaces the linear
array with a gperf-generated hash table.

contrib/ChangeLog

* gcc_update (files_and_dependencies): Add rule for
gcc/cp/std-name-hint.h.

gcc/cp/ChangeLog

* Make-lang.in: Add rule to rebuild std-name-hint.h from
std-name-hint.gperf.
* name-lookup.cc (get_std_name_hint): Remove hints array.
Use gperf-generated class std_name_hint_lookup.
Include "std-name-hint.h".
* std-name-hint.gperf: New file.
* std-name-hint.h: New file.  Generated from the .gperf file.

23 months agom32c-rtems: remove obsoleted port
Martin Liska [Thu, 25 Aug 2022 08:33:45 +0000 (10:33 +0200)]
m32c-rtems: remove obsoleted port

contrib/ChangeLog:

* config-list.mk: Remove the port.

gcc/ChangeLog:

* config.gcc: Remove the port.
* config/m32c/rtems.h: Removed.

libgcc/ChangeLog:

* config.host: Remove the port.

23 months agotree-optimization/73550 - apply MAX_NUM_CHAINS consistently
Richard Biener [Tue, 30 Aug 2022 12:37:23 +0000 (14:37 +0200)]
tree-optimization/73550 - apply MAX_NUM_CHAINS consistently

The MAX_NUM_CHAINS is applied once with <= and once with < which
results in the chains not limited but analyis dropped completely.
That's one issue in the PR.

PR tree-optimization/73550
* gimple-predicate-analysis.cc (predicate::init_from_control_deps):
Do not apply MAX_NUM_CHAINS again.

23 months agoImprove uninit pass dumping
Richard Biener [Tue, 30 Aug 2022 12:36:39 +0000 (14:36 +0200)]
Improve uninit pass dumping

This produces less redundancy and more complete info dumping
the control dependence chains.

* gimple-predicate-analysis.cc (format_edge_vec): Dump
both source and destination.
(dump_dep_chains): Remove.
(uninit_analysis::init_use_preds): Remove redundant
dumping of chains.

23 months agoc++: __has_builtin gives the wrong answer [PR106759]
Marek Polacek [Mon, 29 Aug 2022 20:54:05 +0000 (16:54 -0400)]
c++: __has_builtin gives the wrong answer [PR106759]

We've supported __is_nothrow_constructible since r11-4386, but
names_builtin_p didn't know about it, so it gave the wrong answer for
 #if __has_builtin(__is_nothrow_constructible)
 ...
 #endif

I've tested all C++-only built-ins and only two were missing.

PR c++/106759

gcc/cp/ChangeLog:

* cp-objcp-common.cc (names_builtin_p): Handle RID_IS_NOTHROW_ASSIGNABLE
and RID_IS_NOTHROW_CONSTRUCTIBLE.

gcc/testsuite/ChangeLog:

* g++.dg/ext/has-builtin-1.C: New test.

23 months agoForce a [NAN, NAN] range when the definite NAN property is set.
Aldy Hernandez [Tue, 30 Aug 2022 10:13:31 +0000 (12:13 +0200)]
Force a [NAN, NAN] range when the definite NAN property is set.

Setting the definite NAN property should also force a [NAN, NAN]
range, otherwise we'd have two ways of representing a NAN: with the
endpoints or with the property.  In the ranger world we avoid at all
costs having more than one representation for a range.

In doing this, I removed the FRANGE_PROP_ACCESSOR macro, since it
looks like setting a property may have repercurssions in the range
itself, so it's best for the client to definte its own setter.

gcc/ChangeLog:

* value-range-storage.cc (frange_storage_slot::get_frange): Use
frange_nan.
* value-range.cc (frange::set_nan): New.
(frange_nan): Move to header file.
(range_tests_nan): Adjust frange_nan callers to pass type.
New test.
* value-range.h (FRANGE_PROP_ACCESSOR): Remove.
(frange_nan): New.

23 months agoautomake: regenerate
Martin Liska [Tue, 30 Aug 2022 11:41:03 +0000 (13:41 +0200)]
automake: regenerate

gotools/ChangeLog:

* Makefile.in: Regenerate.

23 months agoautomake: regenerate
Martin Liska [Tue, 30 Aug 2022 11:25:54 +0000 (13:25 +0200)]
automake: regenerate

gotools/ChangeLog:

* Makefile.in: Regenerate.

libatomic/ChangeLog:

* testsuite/Makefile.in: Regenerate.

23 months agotree-optimization/67196 - normalize use predicates earlier
Richard Biener [Tue, 30 Aug 2022 09:47:49 +0000 (11:47 +0200)]
tree-optimization/67196 - normalize use predicates earlier

The following makes sure to have use predicates simplified and
normalized before doing uninit_analysis::overlap because that
otherwise cannot pick up all flag setting cases.  This fixes
half of the issue in PR67196 and conveniently resolves the
XFAIL in gcc.dg/uninit-pred-7_a.c.

PR tree-optimization/67196
* gimple-predicate-analysis.cc (uninit_analysis::is_use_guarded):
Simplify and normalize use prediates before first use.

* gcc.dg/uninit-pred-7_a.c: Un-XFAIL.

23 months agolibsanitizer: update LOCAL_PATCHES
Martin Liska [Tue, 30 Aug 2022 10:54:18 +0000 (12:54 +0200)]
libsanitizer: update LOCAL_PATCHES

libsanitizer/ChangeLog:

* LOCAL_PATCHES: Update.

23 months agolibsanitizer: Apply local patches
Martin Liska [Thu, 5 May 2022 10:52:44 +0000 (12:52 +0200)]
libsanitizer: Apply local patches

23 months agolibsanitizer: update build system
Martin Liska [Tue, 30 Aug 2022 09:47:38 +0000 (11:47 +0200)]
libsanitizer: update build system

libsanitizer/ChangeLog:

* sanitizer_common/Makefile.am: Remove sanitizer_openbsd.
* sanitizer_common/Makefile.in: Regenerate.

23 months agolibsanitizer: merge from master (84a71d5259c2682403cdbd8710592410a2f128ab)
Martin Liska [Tue, 30 Aug 2022 09:45:34 +0000 (11:45 +0200)]
libsanitizer: merge from master (84a71d5259c2682403cdbd8710592410a2f128ab)

23 months agoRemove GENERIC expr building from predicate analysis, improve dumps
Richard Biener [Tue, 30 Aug 2022 09:41:02 +0000 (11:41 +0200)]
Remove GENERIC expr building from predicate analysis, improve dumps

The following removes duplicate dumping and makes the predicate
dumping more readable.  That makes the GENERIC predicate build
routines unused which is also nice.

* gimple-predicate-analysis.cc (dump_pred_chain): Fix
parentizing and AND prepending.
(predicate::dump): Do not dump the GENERIC expanded
predicate, properly parentize and prepend ORs to the
piecewise predicate dump.
(build_pred_expr): Remove.

23 months agoImplement relational operators for frange with endpoints.
Aldy Hernandez [Tue, 30 Aug 2022 06:23:51 +0000 (08:23 +0200)]
Implement relational operators for frange with endpoints.

This is the implementation of the relational range operators for
frange.  These are the core operations that require specific FP domain
knowledge.

gcc/ChangeLog:

* range-op-float.cc (finite_operand_p): New.
(build_le): New.
(build_lt): New.
(build_ge): New.
(build_gt): New.
(foperator_equal::fold_range): New implementation with endpoints.
(foperator_equal::op1_range): Same.
(foperator_not_equal::fold_range): Same.
(foperator_not_equal::op1_range): Same.
(foperator_lt::fold_range): Same.
(foperator_lt::op1_range): Same.
(foperator_lt::op2_range): Same.
(foperator_le::fold_range): Same.
(foperator_le::op1_range): Same.
(foperator_le::op2_range): Same.
(foperator_gt::fold_range): Same.
(foperator_gt::op1_range): Same.
(foperator_gt::op2_range): Same.
(foperator_ge::fold_range): Same.
(foperator_ge::op1_range): Same.
(foperator_ge::op2_range): Same.

gcc/testsuite/ChangeLog:

* gcc.dg/tree-ssa/recip-3.c: Avoid premature optimization so test
has a chance to succeed.

23 months agoAdd support for floating point endpoints to frange.
Aldy Hernandez [Tue, 30 Aug 2022 06:23:33 +0000 (08:23 +0200)]
Add support for floating point endpoints to frange.

The current implementation of frange is just a type with some bits to
represent NAN and INF.  We can do better and represent endpoints to
ultimately solve longstanding PRs such as PR24021.  This patch adds
these endpoints.  In follow-up patches I will add support for a bare
bones PLUS_EXPR range-op-float entry to solve the PR.

I have chosen to use REAL_VALUE_TYPEs for the endpoints, since that's
what we use underneath the trees.  This will be somewhat analogous to
our eventual use of wide-ints in the irange.  No sense going through
added levels of indirection if we can avoid it.  That, plus real.*
already has a nice API for dealing with floats.

With this patch, ranges will be closed float point intervals, which
make the implementation simpler, since we don't have to keep track of
open/closed intervals.  This is conservative enough for use in the
ranger world, as we'd rather err on the side of more elements in a
range, than less.

For example, even though we cannot precisely represent the open
interval (3.0, 5.0) with this approach, it is perfectably reasonable
to represent it as [3.0, 5.0] since the closed interval is a super set
of the open one.  In the VRP/ranger world, it is always better to
err on the side of more information in a range, than not.  After all,
when we don't know anything about a range, we just use VARYING which
is a fancy term for a range spanning the entire domain.

Since REAL_VALUE_TYPEs have properly defined infinity and NAN
semantics, all the math can be made to work:

[-INF, 3.0] !NAN        => Numbers <= 3.0 (NAN cannot happen)
[3.0, 3.0]   => 3.0 or NAN.
[3.0, +INF]             => Numbers >= 3.0 (NAN is possible)
[-INF, +INF]            => VARYING (NAN is possible)
[-INF, +INF] !NAN       => Entire domain.  NAN cannot happen.

Also, since REAL_VALUE_TYPEs can represent the minimum and maximum
representable values of a TYPE_MODE, we can disambiguate between them
and negative and positive infinity (see get_max_float in real.cc).

This also makes the math all work.  For example, suppose we know
nothing about x and y (VARYING).  On the TRUE side of x > y, we can
deduce that:

        (a) x cannot be NAN
        (b) y cannot be NAN
        (c) y cannot be +INF.

(c) means that we can drop the upper bound of "y" from +INF to the
maximum representable value for its type.

Having endpoints with different representation for infinity and the
maximum representable values, means we can drop the +-INF properties
we currently have in the frange.

gcc/ChangeLog:

* range-op-float.cc (frange_set_nan): New.
(frange_drop_inf): New.
(frange_drop_ninf): New.
(foperator_equal::op1_range): Adjust for endpoints.
(foperator_lt::op1_range): Same.
(foperator_lt::op2_range): Same.
(foperator_gt::op1_range): Same.
(foperator_gt::op2_range): Same.
(foperator_unordered::op1_range): Same.
* value-query.cc (range_query::get_tree_range): Same.
* value-range-pretty-print.cc (vrange_printer::visit): Same.
* value-range-storage.cc (frange_storage_slot::get_frange): Same.
* value-range.cc (frange::set): Same.
(frange::normalize_kind): Same.
(frange::union_): Same.
(frange::intersect): Same.
(frange::operator=): Same.
(early_nan_resolve): New.
(frange::contains_p): New.
(frange::singleton_p): New.
(frange::set_nonzero): New.
(frange::nonzero_p): New.
(frange::set_zero): New.
(frange::zero_p): New.
(frange::set_nonnegative): New.
(frange_float): New.
(frange_nan): New.
(range_tests_nan): New.
(range_tests_signed_zeros): New.
(range_tests_floats): New.
(range_tests): New.
* value-range.h (frange::lower_bound): New.
(frange::upper_bound): New.
(vrp_val_min): Use real_inf with a sign instead of negating inf.
(frange::frange): New.
(frange::set_varying): Adjust for endpoints.
(real_max_representable): New.
(real_min_representable): New.

23 months agoA == 0 ? A : -A same as -A (when A is 0.0)
Aldy Hernandez [Mon, 29 Aug 2022 15:52:20 +0000 (17:52 +0200)]
A == 0 ? A : -A    same as -A (when A is 0.0)

The upcoming work for frange triggers a regression in
gcc.dg/tree-ssa/phi-opt-24.c.

For -O2 -fno-signed-zeros, we fail to transform the following into -A:

float f0(float A)
{
  //     A == 0? A : -A    same as -A
  if (A == 0)  return A;
  return -A;
}

This is because the abs/negative match.pd pattern here:

/* abs/negative simplifications moved from fold_cond_expr_with_comparison,
   Need to handle (A - B) case as fold_cond_expr_with_comparison does.
   Need to handle UN* comparisons.
   ...
   ...

Sees IL that has the 0.0 propagated.

Instead of:

  <bb 2> [local count: 1073741824]:
  if (A_2(D) == 0.0)
    goto <bb 4>; [34.00%]
  else
    goto <bb 3>; [66.00%]

  <bb 3> [local count: 708669601]:
  _3 = -A_2(D);

  <bb 4> [local count: 1073741824]:
  # _1 = PHI <A_2(D)(2), _3(3)>

It now sees:

  <bb 4> [local count: 1073741824]:
  # _1 = PHI <0.0(2), _3(3)>

which it leaves untouched, causing the if conditional to survive.

Changing integger_zerop to zerop fixes the problem.

I did not include a testcase, as it's just phi-opt-24.c which will get
triggered when I commit the frange with endpoints work.

gcc/ChangeLog:

* match.pd ((cmp @0 zerop) real_zerop (negate@1 @0)): Add variant
for real zero.

23 months agos390: fix build on 32-bit hosts
Martin Liska [Tue, 30 Aug 2022 08:46:26 +0000 (10:46 +0200)]
s390: fix build on 32-bit hosts

Fixes build on i686:

gcc/config/s390/s390.cc: In function 'bool s390_rtx_costs(rtx, machine_mode, int, int, int*, bool)':
gcc/config/s390/s390.cc:3728:63: error: cannot convert 'long int*' to 'long long int*'

gcc/ChangeLog:

* config/s390/s390.cc (s390_rtx_costs): Use proper type as
  argument.

23 months agoUse reachability analysis to improve uninit diagnostic
Richard Biener [Fri, 19 Aug 2022 13:11:14 +0000 (15:11 +0200)]
Use reachability analysis to improve uninit diagnostic

This patch does what the comment in uninit diagnostic suggests.
When the value-numbering run done without optimizing figures there's
a fallthru path, consider blocks on it as always executed.

* tree-ssa-uninit.cc (warn_uninitialized_vars): Pre-compute
the set of fallthru reachable blocks from function entry
and use that to determine wlims.always_executed.

23 months agotree-optimization/63660 - testcase for fixed PR
Richard Biener [Tue, 30 Aug 2022 08:04:15 +0000 (10:04 +0200)]
tree-optimization/63660 - testcase for fixed PR

This adds a testcase for the PR which was fixed with r13-2155-gbaa3ffb19c54fa

PR tree-optimization/63660
* gcc.dg/uninit-pr63660.c: New testcase.

23 months agotree-optimization/56654 - sort uninit candidates after RPO
Richard Biener [Mon, 29 Aug 2022 14:16:44 +0000 (16:16 +0200)]
tree-optimization/56654 - sort uninit candidates after RPO

The following sorts the immediate uses of a possibly uninitialized
SSA variable after their RPO order so we prefer warning for an
earlier occuring use rather than issueing the diagnostic for the
first uninitialized immediate use.

The sorting will inevitably be imperfect but it also allows us to
optimize the expensive predicate check for the case where there
are multiple uses in the same basic-block which is a nice side-effect.

PR tree-optimization/56654
* tree-ssa-uninit.cc (cand_cmp): New.
(find_uninit_use): First process all PHIs and collect candidate
stmts, then sort those after RPO.
(warn_uninitialized_phi): Pass on bb_to_rpo.
(execute_late_warn_uninitialized): Compute and pass on
reverse lookup of RPO number from basic block index.

23 months agoMake uninit PHI processing more consistent
Richard Biener [Mon, 29 Aug 2022 10:20:10 +0000 (12:20 +0200)]
Make uninit PHI processing more consistent

Currently the main working of the maybe-uninit pass is to scan over
all PHIs with possibly undefined arguments, diagnosing whether there's
a direct not guarded use.  For not guarded uses in PHIs those are queued for
later processing and to make the uninit analysis PHI def handling work,
mark the PHI def as possibly uninitialized.  But this happens only
for those PHI uses that happen to be seen before a direct not guarded
use and whether all arguments of a PHI node which are defined by a PHI
are properly marked as maybe uninitialized depends on the processing
order.

The following changes the uninit pass to perform an RPO walk over
the function, ensuring that PHI argument defs are visited before
the PHI node (besides backedge uses which we ignore already),
getting rid of the worklist.  It also makes sure to process all
PHI uses, but recording those that are properly guarded so they
are not treated as maybe undefined when processing the PHI use
later.

Overall this should make behavior more consistent, avoid some
false negative because of the previous early out and order issue,
and avoid some false positive because of the missed recording
of guarded PHI uses.

The patch correctly diagnoses an uninitalized use of 'regnum'
in store_bit_field_1 and also diagnoses an uninitialized use of
best_match::m_best_candidate_len in c-decl.cc which I've chosen to
silence by initializing m_best_candidate_len.  The warning is
a false positive but GCC cannot see that m_best_candidate_len is
initialized when m_best_candidate is not NULL so from this
perspective this was a false negative.  I've added
g++.dg/uninit-pred-5.C with a reduced testcase that nicely shows
how the previous behavior missed the diagnostic because the
worklist ended up visiting the PHI with the dependend uninit
value before visiting the PHIs producing it.

* gimple-predicate-analysis.h (uninit_analysis::operator()):
Remove.
* gimple-predicate-analysis.cc
(uninit_analysis::collect_phi_def_edges): Use phi_arg_set,
simplify a bit.
* tree-ssa-uninit.cc (defined_args): New global.
(compute_uninit_opnds_pos): Mask with the recorded set
of guarded maybe-uninitialized uses.
(uninit_undef_val_t::operator()): Remove.
(find_uninit_use): Process all PHI uses, recording the
guarded ones and marking the PHI result as uninitialized
consistently.
(warn_uninitialized_phi): Adjust.
(execute_late_warn_uninitialized): Get rid of the PHI worklist
and instead walk the function in RPO order.
* spellcheck.h (best_match::m_best_candidate_len): Initialize.

* g++.dg/uninit-pred-5.C: New testcase.

23 months agomiddle-end: fix min/max phiopts reduction [PR106744]
Tamar Christina [Tue, 30 Aug 2022 06:49:02 +0000 (07:49 +0100)]
middle-end: fix min/max phiopts reduction [PR106744]

This corrects the argument usage to use them in the order that they occur in
the comparisons in gimple.

gcc/ChangeLog:

PR tree-optimization/106744
* tree-ssa-phiopt.cc (minmax_replacement): Correct arguments.

gcc/testsuite/ChangeLog:

PR tree-optimization/106744
* gcc.dg/tree-ssa/minmax-10.c: Make runtime test.
* gcc.dg/tree-ssa/minmax-11.c: Likewise.
* gcc.dg/tree-ssa/minmax-12.c: Likewise.
* gcc.dg/tree-ssa/minmax-13.c: Likewise.
* gcc.dg/tree-ssa/minmax-14.c: Likewise.
* gcc.dg/tree-ssa/minmax-15.c: Likewise.
* gcc.dg/tree-ssa/minmax-16.c: Likewise.
* gcc.dg/tree-ssa/minmax-3.c: Likewise.
* gcc.dg/tree-ssa/minmax-4.c: Likewise.
* gcc.dg/tree-ssa/minmax-5.c: Likewise.
* gcc.dg/tree-ssa/minmax-6.c: Likewise.
* gcc.dg/tree-ssa/minmax-7.c: Likewise.
* gcc.dg/tree-ssa/minmax-8.c: Likewise.
* gcc.dg/tree-ssa/minmax-9.c: Likewise.

23 months agomiddle-end: intialize regnum in store_bit_field_1
Tamar Christina [Tue, 30 Aug 2022 06:48:21 +0000 (07:48 +0100)]
middle-end: intialize regnum in store_bit_field_1

This initializes regnum to 0 for when undefined_p.
0 is the right default as it's supposed to get the lowpart
when undefined.

gcc/ChangeLog:

* expmed.cc (store_bit_field_1): Initialize regnum to 0.

23 months agoDaily bump.
GCC Administrator [Tue, 30 Aug 2022 00:16:47 +0000 (00:16 +0000)]
Daily bump.

23 months agoc++: Fix C++11 attribute propagation [PR106712]
Marek Polacek [Fri, 26 Aug 2022 22:03:53 +0000 (18:03 -0400)]
c++: Fix C++11 attribute propagation [PR106712]

When we have

  [[noreturn]] int fn1 [[nodiscard]](), fn2();

"noreturn" should apply to both fn1 and fn2 but "nodiscard" only to fn1:
[dcl.pre]/3: "The attribute-specifier-seq appertains to each of
the entities declared by the declarators of the init-declarator-list."
[dcl.spec.general]: "The attribute-specifier-seq affects the type
only for the declaration it appears in, not other declarations involving
the same type."

As Ed Catmur correctly analyzed, this is because, for the test above,
we call start_decl with prefix_attributes=noreturn, but this line:

  attributes = attr_chainon (attributes, prefix_attributes);

results in attributes == prefix_attributes, because chainon sees
that attributes is null so it just returns prefix_attributes.  Then
in grokdeclarator we reach

  *attrlist = attr_chainon (*attrlist, declarator->std_attributes);

which modifies prefix_attributes so now it's "noreturn, nodiscard"
and so fn2 is wrongly marked nodiscard as well.  Fixed by reversing
the order of arguments to attr_chainon.  That way, we tack the prefix
attributes onto ->std_attributes, avoiding modifying prefix_attributes.

PR c++/106712

gcc/cp/ChangeLog:

* decl.cc (grokdeclarator): Reverse the order of arguments to
attr_chainon.

gcc/testsuite/ChangeLog:

* g++.dg/cpp0x/gen-attrs-77.C: New test.

23 months agobpf: handle anonymous members in CO-RE reloc [PR106745]
David Faust [Mon, 29 Aug 2022 18:21:52 +0000 (11:21 -0700)]
bpf: handle anonymous members in CO-RE reloc [PR106745]

The old method for computing a member index for a CO-RE relocation
relied on a name comparison, which could SEGV if the member in question
is itself part of an anonymous inner struct or union.

This patch changes the index computation to not rely on a name, while
maintaining the ability to account for other sibling fields which may
not have a representation in BTF.

gcc/ChangeLog:

PR target/106745
* config/bpf/coreout.cc (bpf_core_get_sou_member_index): Fix
computation of index for anonymous members.

gcc/testsuite/ChangeLog:

PR target/106745
* gcc.target/bpf/core-pr106745.c: New test.

23 months agobpf: define __bpf__ as well as __BPF__ as a target macro
Jose E. Marchesi [Mon, 29 Aug 2022 20:13:11 +0000 (22:13 +0200)]
bpf: define __bpf__ as well as __BPF__ as a target macro

LLVM defines both __bpf__ and __BPF_ as target macros.
GCC was defining only __BPF__.

This patch defines __bpf__ as a target macro for BPF.
Tested in bpf-unknown-none.

gcc/ChangeLog:

* config/bpf/bpf.cc (bpf_target_macros): Define __bpf__ as a
target macro.

23 months agox86: Handle V16BF in ix86_avx256_split_vector_move_misalign
H.J. Lu [Fri, 26 Aug 2022 17:26:06 +0000 (10:26 -0700)]
x86: Handle V16BF in ix86_avx256_split_vector_move_misalign

Handle E_V16BFmode in ix86_avx256_split_vector_move_misalign and add
V16BF to V_256H iterator.

gcc/

PR target/106748
* config/i386/i386-expand.cc
(ix86_avx256_split_vector_move_misalign): Handle E_V16BFmode.
* config/i386/sse.md (V_256H): Add V16BF.

gcc/testsuite/

PR target/106748
* gcc.target/i386/pr106748.c: New test.

23 months agoLoongArch: testsuite: refine __tls_get_addr tests with tls_native
Xi Ruoyao [Wed, 24 Aug 2022 11:34:47 +0000 (19:34 +0800)]
LoongArch: testsuite: refine __tls_get_addr tests with tls_native

If GCC is not built with a working linker for the target (developers
occansionally build such a "minimal" GCC for testing and debugging),
TLS will be emulated and __tls_get_addr won't be used.  Refine those
tests depending on __tls_get_addr with tls_native to avoid test
failures.

gcc/testsuite/ChangeLog:

* gcc.target/loongarch/func-call-medium-1.c: Refine test
depending on __tls_get_addr with { target tls_native }.
* gcc.target/loongarch/func-call-medium-2.c: Likewise.
* gcc.target/loongarch/func-call-medium-3.c: Likewise.
* gcc.target/loongarch/func-call-medium-4.c: Likewise.
* gcc.target/loongarch/func-call-medium-5.c: Likewise.
* gcc.target/loongarch/func-call-medium-6.c: Likewise.
* gcc.target/loongarch/func-call-medium-7.c: Likewise.
* gcc.target/loongarch/func-call-medium-8.c: Likewise.
* gcc.target/loongarch/tls-gd-noplt.c: Likewise.

23 months agos390: Change SET rtx_cost handling.
Robin Dapp [Thu, 3 Feb 2022 11:50:04 +0000 (12:50 +0100)]
s390: Change SET rtx_cost handling.

The IF_THEN_ELSE detection currently prevents us from properly costing
register-register moves which causes the lower-subreg pass to assume that
a VR-VR move is as expensive as two GPR-GPR moves.

This patch adds handling for SETs containing REGs as well as MEMs and is
inspired by the aarch64 implementation.

gcc/ChangeLog:

* config/s390/s390.cc (s390_address_cost): Declare.
(s390_hard_regno_nregs): Declare.
(s390_rtx_costs): Add handling for REG and MEM in SET.

gcc/testsuite/ChangeLog:

* gcc.target/s390/vector/vec-sum-across-no-lower-subreg-1.c: New test.

23 months agos390: Recognize reverse/element swap permute patterns.
Robin Dapp [Fri, 24 Jun 2022 13:17:08 +0000 (15:17 +0200)]
s390: Recognize reverse/element swap permute patterns.

This adds functions to recognize reverse/element swap permute patterns
for vler, vster as well as vpdi and rotate.

gcc/ChangeLog:

* config/s390/s390.cc (expand_perm_with_vpdi): Recognize swap pattern.
(is_reverse_perm_mask): New function.
(expand_perm_with_rot): Recognize reverse pattern.
(expand_perm_with_vstbrq): New function.
(expand_perm_with_vster): Use vler/vster for element reversal on z15.
(vectorize_vec_perm_const_1): Use.
(s390_vectorize_vec_perm_const): Add expand functions.
* config/s390/vx-builtins.md: Prefer vster over vler.

gcc/testsuite/ChangeLog:

* gcc.target/s390/vector/vperm-rev-z14.c: New test.
* gcc.target/s390/vector/vperm-rev-z15.c: New test.
* gcc.target/s390/zvector/vec-reve-store-byte.c: Adjust test
expectation.