platform/upstream/gcc.git
21 months agopreprocessor: C2x identifier rules
Joseph Myers [Fri, 14 Oct 2022 23:07:50 +0000 (23:07 +0000)]
preprocessor: C2x identifier rules

C2x has, like C++, adopted rules for identifiers based directly on an
unversioned normative reference to Unicode.  Make libcpp follow those
rules for c2x / gnu2x standards (this involves bringing back a flag
separate from the C++ one for whether to use these identifier rules,
but this time enabled for all C++ language versions since that was the
conclusion adopted for C++ identifier handling).

There is one change here that affects C++.  I believe the new
normative requirement for NFC only applies to identifiers, not to the
use of identifier-continue characters in pp-numbers, where there is no
such requirement and so the diagnostic ought to be a warning not a
pedwarn in pp-numbers, and that this is the case for both C and C++.

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

libcpp/
* charset.cc (ucn_valid_in_identifier): Check xid_identifiers not
cplusplus to determine whether to use CXX23 and NXX23 flags.
* include/cpplib.h (struct cpp_options): Add xid_identifiers.
* init.cc (struct lang_flags, lang_defaults): Add xid_identifiers.
(cpp_set_lang): Set xid_identifiers.
* lex.cc (warn_about_normalization): Add parameter identifier.
Only pedwarn about non-NFC for identifiers, not pp-numbers.
(_cpp_lex_direct): Update calls to warn_about_normalization.

gcc/testsuite/
* gcc.dg/cpp/c2x-ucnid-1-utf8.c, gcc.dg/cpp/c2x-ucnid-1.c: New
tests.

21 months agoFortran: fix check of polymorphic elements in data transfers [PR100971]
Harald Anlauf [Sun, 9 Oct 2022 18:43:32 +0000 (20:43 +0200)]
Fortran: fix check of polymorphic elements in data transfers [PR100971]

gcc/fortran/ChangeLog:

PR fortran/100971
* resolve.cc (resolve_transfer): Extend check for permissibility
of polymorphic elements in a data transfer to arrays.

gcc/testsuite/ChangeLog:

PR fortran/100971
* gfortran.dg/der_io_5.f90: New test.

21 months agoImplement distinction between HONOR_SIGNED_ZEROS and MODE_HAS_SIGNED_ZEROS.
Aldy Hernandez [Fri, 14 Oct 2022 14:49:33 +0000 (16:49 +0200)]
Implement distinction between HONOR_SIGNED_ZEROS and MODE_HAS_SIGNED_ZEROS.

gcc/ChangeLog:

* value-range.cc (frange::set): Implement distinction between
HONOR_SIGNED_ZEROS and MODE_HAS_SIGNED_ZEROS.

21 months agoImplement range-op entry for __builtin_copysign.
Aldy Hernandez [Thu, 13 Oct 2022 15:51:29 +0000 (17:51 +0200)]
Implement range-op entry for __builtin_copysign.

copysign(MAGNITUDE, SIGN) is implemented as the absolute of MAGNITUDE,
with SIGN applied.  If the sign of "SIGN" cannot be determined, we
return a range of [-MAGNITUDE, +MAGNITUDE].

gcc/ChangeLog:

* gimple-range-op.cc (class cfn_copysign): New.
(gimple_range_op_handler::maybe_builtin_call): Add
CFN_BUILT_IN_COPYSIGN*.

21 months agogfortran.dg/c-interop/deferred-character-2.f90: Fix dg-do
Tobias Burnus [Fri, 14 Oct 2022 16:34:49 +0000 (18:34 +0200)]
gfortran.dg/c-interop/deferred-character-2.f90: Fix dg-do

gcc/testsuite/
* gfortran.dg/c-interop/deferred-character-2.f90: Use 'dg-do run'.

21 months agoCheck rvc_normal in real_isdenormal.
Aldy Hernandez [Fri, 14 Oct 2022 10:08:11 +0000 (12:08 +0200)]
Check rvc_normal in real_isdenormal.

[-Inf, -Inf] is being flushed to [-Inf, -0.0] because real_isdenormal
is being overly pessimistic.  It is missing a check for rvc_normal.
This doesn't cause problems in real.cc because all uses of
real_isdenormal are already on the rvc_normal path.  The uses in
value-range.cc however, are not.

This patch adds a check for rvc_normal.

gcc/ChangeLog:

* real.h (real_isdenormal): Check rvc_normal.
* value-range.cc (range_tests_floats): New test.

21 months agolibstdc++: Disable all emergency EH pool code if obj-count == 0
Jonathan Wakely [Wed, 12 Oct 2022 22:04:53 +0000 (23:04 +0100)]
libstdc++: Disable all emergency EH pool code if obj-count == 0

For a zero-sized static pool we can completely elide all code for the EH
pool.

We no longer need to adjust the static buffer size to ensure at least
one free_entry can be created in it, because we no longer use a static
buffer at all if obj_count == 0. If the buffer exists, obj_count >= 1
and the buffer will be much larger than sizeof(free_entry).

libstdc++-v3/ChangeLog:

* libsupc++/eh_alloc.cc [USE_POOL]: New macro.
[!USE_POOL] (__gnu_cxx::__freeres, pool): Do not define.
[_GLIBCXX_EH_POOL_STATIC] (pool::arena): Do not use std::max.
(__cxxabiv1::__cxa_allocate_exception) [!USE_POOL]: Do not use
pool.
(__cxxabiv1::__cxa_free_exception) [!USE_POOL]: Likewise.
(__cxxabiv1::__cxa_allocate_dependent_exception) [!USE_POOL]:
Likewise.
(__cxxabiv1::__cxa_free_dependent_exception) [!USE_POOL]:
Likewise.

21 months agolibstdc++: Simplify print_raw function for debug assertions
Jonathan Wakely [Wed, 12 Oct 2022 10:59:33 +0000 (11:59 +0100)]
libstdc++: Simplify print_raw function for debug assertions

Replace two uses of print_raw where it's clearer to just use fprintf
directly. Then the only remaining use of print_raw is as the print_func
argument of pretty_print. When called by pretty_print the count is
either a positive integer or -1, so we can simplify print_raw itself.

Remove the default argument, because it's never used. Remove the check
for nbc == 0, which never happens (but would be harmless if it did).
Replace the conditional expression with a single call to fprintf, using
INT_MAX as the maximum length.

libstdc++-v3/ChangeLog:

* src/c++11/debug.cc (print_raw): Simplify.
(print_word): Print indentation by calling fprintf directly.
(_Error_formatter::_M_error): Print unindented string by calling
fprintf directly.

21 months agoReplace CFN_BUILTIN_SIGNBIT* cases with CASE_FLT_FN.
Aldy Hernandez [Fri, 14 Oct 2022 13:02:06 +0000 (15:02 +0200)]
Replace CFN_BUILTIN_SIGNBIT* cases with CASE_FLT_FN.

gcc/ChangeLog:

* gimple-range-op.cc
(gimple_range_op_handler::maybe_builtin_call): Replace
CFN_BUILTIN_SIGNBIT* cases with CASE_FLT_FN.

21 months agoNormalize ranges over the range for both bounds when -ffinite-math-only.
Aldy Hernandez [Fri, 14 Oct 2022 10:07:40 +0000 (12:07 +0200)]
Normalize ranges over the range for both bounds when -ffinite-math-only.

[-Inf, +Inf] was being chopped correctly for -ffinite-math-only, but
[-Inf, -Inf] was not.  This was latent because a bug in
real_isdenormal is causing us to flush -Inf to zero.

gcc/ChangeLog:

* value-range.cc (frange::set): Normalize ranges for both bounds.

21 months agoDrop -0.0 in frange::set() for !HONOR_SIGNED_ZEROS.
Aldy Hernandez [Fri, 14 Oct 2022 10:06:56 +0000 (12:06 +0200)]
Drop -0.0 in frange::set() for !HONOR_SIGNED_ZEROS.

Similar to what we do for NANs when !HONOR_NANS and Inf when
flag_finite_math_only, we can remove -0.0 from the range at creation
time.

We were kinda sorta doing this because there is a bug in
real_isdenormal that is causing flush_denormals_to_zero to saturate
[x, -0.0] to [x, +0.0] when !HONOR_SIGNED_ZEROS.  Fixing this bug
(upcoming), causes us to leave -0.0 in places where we aren't
expecting it (the intersection code).

gcc/ChangeLog:

* value-range.cc (frange::set): Drop -0.0 for !HONOR_SIGNED_ZEROS.

21 months agoc++ modules: ICE with dynamic_cast [PR106304]
Patrick Palka [Fri, 14 Oct 2022 13:07:01 +0000 (09:07 -0400)]
c++ modules: ICE with dynamic_cast [PR106304]

The FUNCTION_DECL we build for __dynamic_cast has an empty DECL_CONTEXT
but trees_out::tree_node expects FUNCTION_DECLs to have non-empty
DECL_CONTEXT, thus we crash when streaming out the dynamic_cast in the
below testcase.

This patch naively fixes this by setting DECL_CONTEXT for __dynamic_cast
appropriately.  I suppose we should push it into the namespace too, like
we do for __cxa_atexit which is similarly lazily declared.

PR c++/106304

gcc/cp/ChangeLog:

* constexpr.cc (cxx_dynamic_cast_fn_p): Check for abi_node
instead of global_namespace.
* rtti.cc (build_dynamic_cast_1): Set DECL_CONTEXT and
DECL_SOURCE_LOCATION when building dynamic_cast_node.  Push
it into the namespace.

gcc/testsuite/ChangeLog:

* g++.dg/modules/pr106304_a.C: New test.
* g++.dg/modules/pr106304_b.C: New test.

21 months agoAdd cases for CFN_BUILT_IN_SIGNBIT[FL].
Aldy Hernandez [Thu, 13 Oct 2022 15:45:38 +0000 (17:45 +0200)]
Add cases for CFN_BUILT_IN_SIGNBIT[FL].

gcc/ChangeLog:

* gimple-range-op.cc
(gimple_range_op_handler::maybe_builtin_call): Add
CFN_BUILT_IN_SIGNBIT[FL]* entries.

21 months agotree-optimization/107254 - check and support live lanes from permutes
Richard Biener [Fri, 14 Oct 2022 09:14:59 +0000 (11:14 +0200)]
tree-optimization/107254 - check and support live lanes from permutes

The following fixes an omission from adding SLP permute nodes which
is live lanes originating from those.  We have to check that we
can extract the lane and have to actually code generate them.

PR tree-optimization/107254
* tree-vect-slp.cc (vect_slp_analyze_node_operations_1):
For permutes also analyze live lanes.
(vect_schedule_slp_node): For permutes also code generate
live lane extracts.

* gfortran.dg/vect/pr107254.f90: New testcase.

21 months agoFix PR target/107248
Eric Botcazou [Fri, 14 Oct 2022 09:52:04 +0000 (11:52 +0200)]
Fix PR target/107248

This is the infamous PR rtl-optimization/38644 rearing its ugly head for
leaf functions on SPARC more than a decade later...  Richard E.'s generic
solution has never been implemented so let's do as other RISC back-ends did.

gcc/
PR target/107248
* config/sparc/sparc.cc (sparc_expand_prologue): Emit a frame
blockage for leaf functions.
(sparc_flat_expand_prologue): Emit frame instead of full blockage.
(sparc_expand_epilogue): Emit a frame blockage for leaf functions.
(sparc_flat_expand_epilogue): Emit frame instead of full blockage.

21 months agolibstdc++: Use markdown in Doxygen comment
Jonathan Wakely [Wed, 12 Oct 2022 11:07:14 +0000 (12:07 +0100)]
libstdc++: Use markdown in Doxygen comment

This makes the comment easier to read in the source, without altering
the Doxygen output.

libstdc++-v3/ChangeLog:

* include/std/iostream: Use markdown in Doxygen comment.

21 months agogcov: test line count for label in then/else block
Jørgen Kvalsvik [Fri, 7 Oct 2022 11:29:20 +0000 (13:29 +0200)]
gcov: test line count for label in then/else block

Add a test to catch regression in line counts for labels on top of
then/else blocks. Only the 'goto <label>' should contribute to the line
counter for the label, not the if.

gcc/testsuite/ChangeLog:

* gcc.misc-tests/gcov-4.c: New testcase.

21 months agogcov: test switch/break line counts
Jørgen Kvalsvik [Tue, 4 Oct 2022 13:45:59 +0000 (15:45 +0200)]
gcov: test switch/break line counts

The coverage support will under some conditions decide to split edges to
accurately report coverage. By running the test suite with/without this
edge splitting a small diff shows up, addressed by this patch, which
should catch future regressions.

Removing the edge splitting:

$ diff --git a/gcc/profile.cc b/gcc/profile.cc
--- a/gcc/profile.cc
+++ b/gcc/profile.cc
@@ -1244,19 +1244,7 @@ branch_prob (bool thunk)
                Don't do that when the locuses match, so
                if (blah) goto something;
                is not computed twice.  */
-             if (last
-                 && gimple_has_location (last)
-                 && !RESERVED_LOCATION_P (e->goto_locus)
-                 && !single_succ_p (bb)
-                 && (LOCATION_FILE (e->goto_locus)
-                     != LOCATION_FILE (gimple_location (last))
-                     || (LOCATION_LINE (e->goto_locus)
-                         != LOCATION_LINE (gimple_location (last)))))
-               {
-                 basic_block new_bb = split_edge (e);
-                 edge ne = single_succ_edge (new_bb);
-                 ne->goto_locus = e->goto_locus;
-               }
+
        if ((e->flags & (EDGE_ABNORMAL | EDGE_ABNORMAL_CALL))
                && e->dest != EXIT_BLOCK_PTR_FOR_FN (cfun))
                need_exit_edge = 1;

Assuming the .gcov files from make chec-gcc RUNTESTFLAGS=gcov.exp are
kept:

$ diff -r no-split-edge with-split-edge | grep -C 2 -E "^[<>]\s\s"
diff -r sans-split-edge/gcc/gcov-4.c.gcov with-split-edge/gcc/gcov-4.c.gcov
   228c228
   <         -:  224:        break;
   ---
   >         1:  224:        break;
   231c231
   <         -:  227:        break;
   ---
   >     #####:  227:        break;
   237c237
   <         -:  233:        break;
   ---
   >         2:  233:        break;

gcc/testsuite/ChangeLog:

* g++.dg/gcov/gcov-1.C: Add line count check.
* gcc.misc-tests/gcov-4.c: Likewise.

21 months agomiddle-end, c++, i386, libgcc: std::bfloat16_t and __bf16 arithmetic support
Jakub Jelinek [Fri, 14 Oct 2022 07:37:01 +0000 (09:37 +0200)]
middle-end, c++, i386, libgcc: std::bfloat16_t and __bf16 arithmetic support

Here is a complete patch to add std::bfloat16_t support on
x86 (AArch64 and ARM left for later).  Almost no BFmode optabs
are added by the patch, so for binops/unops it extends to SFmode
first and then truncates back to BFmode.
For {HF,SF,DF,XF,TF}mode -> BFmode conversions libgcc has implementations
of all those conversions so that we avoid double rounding, for
BFmode -> {DF,XF,TF}mode conversions to avoid growing libgcc too much
it emits BFmode -> SFmode conversion first and then converts to the even
wider mode, neither step should be imprecise.
For BFmode -> HFmode, it first emits a precise BFmode -> SFmode conversion
and then SFmode -> HFmode, because neither format is subset or superset
of the other, while SFmode is superset of both.
expr.cc then contains a -ffast-math optimization of the BF -> SF and
SF -> BF conversions if we don't optimize for space (and for the latter
if -frounding-math isn't enabled either).
For x86, perhaps truncsfbf2 optab could be defined for TARGET_AVX512BF16
but IMNSHO should FAIL if !flag_finite_math || flag_rounding_math
|| !flag_unsafe_math_optimizations, because I think the insn doesn't
raise on sNaNs, hardcodes round to nearest and flushes denormals to zero.
By default (unless x86 -fexcess-precision=16) we use float excess
precision for BFmode, so truncate only on explicit casts and assignments.
The patch introduces a single __bf16 builtin - __builtin_nansf16b,
because (__bf16) __builtin_nansf ("") will drop the sNaN into qNaN,
and uses f16b suffix instead of bf16 because there would be ambiguity on
log vs. logb - __builtin_logbf16 could be either log with bf16 suffix
or logb with f16 suffix.  In other cases libstdc++ should mostly use
__builtin_*f for std::bfloat16_t overloads (we have a problem with
std::nextafter though but that one we have also for std::float16_t).

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

gcc/
* tree-core.h (enum tree_index): Add TI_BFLOAT16_TYPE.
* tree.h (bfloat16_type_node): Define.
* tree.cc (excess_precision_type): Promote bfloat16_type_mode
like float16_type_mode.
(build_common_tree_nodes): Initialize bfloat16_type_node if
BFmode is supported.
* expmed.h (maybe_expand_shift): Declare.
* expmed.cc (maybe_expand_shift): No longer static.
* expr.cc (convert_mode_scalar): Don't ICE on BF -> HF or HF -> BF
conversions.  If there is no optab, handle BF -> {DF,XF,TF,HF}
conversions as separate BF -> SF -> {DF,XF,TF,HF} conversions, add
-ffast-math generic implementation for BF -> SF and SF -> BF
conversions.
* builtin-types.def (BT_BFLOAT16, BT_FN_BFLOAT16_CONST_STRING): New.
* builtins.def (BUILT_IN_NANSF16B): New builtin.
* fold-const-call.cc (fold_const_call): Handle CFN_BUILT_IN_NANSF16B.
* config/i386/i386.cc (classify_argument): Handle E_BCmode.
(ix86_libgcc_floating_mode_supported_p): Also return true for BFmode
for -msse2.
(ix86_mangle_type): Mangle BFmode as DF16b.
(ix86_invalid_conversion, ix86_invalid_unary_op,
ix86_invalid_binary_op): Remove.
(TARGET_INVALID_CONVERSION, TARGET_INVALID_UNARY_OP,
TARGET_INVALID_BINARY_OP): Don't redefine.
* config/i386/i386-builtins.cc (ix86_bf16_type_node): Remove.
(ix86_register_bf16_builtin_type): Use bfloat16_type_node rather than
ix86_bf16_type_node, only create it if still NULL.
* config/i386/i386-builtin-types.def (BFLOAT16): Likewise.
* config/i386/i386.md (cbranchbf4, cstorebf4): New expanders.
gcc/c-family/
* c-cppbuiltin.cc (c_cpp_builtins): If bfloat16_type_node,
predefine __BFLT16_*__ macros and for C++23 also
__STDCPP_BFLOAT16_T__.  Predefine bfloat16_type_node related
macros for -fbuilding-libgcc.
* c-lex.cc (interpret_float): Handle CPP_N_BFLOAT16.
gcc/c/
* c-typeck.cc (convert_arguments): Don't promote __bf16 to
double.
gcc/cp/
* cp-tree.h (extended_float_type_p): Return true for
bfloat16_type_node.
* typeck.cc (cp_compare_floating_point_conversion_ranks): Set
extended{1,2} if mv{1,2} is bfloat16_type_node.  Adjust comment.
gcc/testsuite/
* lib/target-supports.exp (check_effective_target_bfloat16,
check_effective_target_bfloat16_runtime, add_options_for_bfloat16):
New.
* gcc.dg/torture/bfloat16-basic.c: New test.
* gcc.dg/torture/bfloat16-builtin.c: New test.
* gcc.dg/torture/bfloat16-builtin-issignaling-1.c: New test.
* gcc.dg/torture/bfloat16-complex.c: New test.
* gcc.dg/torture/builtin-issignaling-1.c: Allow to be includable
from bfloat16-builtin-issignaling-1.c.
* gcc.dg/torture/floatn-basic.h: Allow to be includable from
bfloat16-basic.c.
* gcc.target/i386/vect-bfloat16-typecheck_2.c: Adjust expected
diagnostics.
* gcc.target/i386/sse2-bfloat16-scalar-typecheck.c: Likewise.
* gcc.target/i386/vect-bfloat16-typecheck_1.c: Likewise.
* g++.target/i386/bfloat_cpp_typecheck.C: Likewise.
libcpp/
* include/cpplib.h (CPP_N_BFLOAT16): Define.
* expr.cc (interpret_float_suffix): Handle bf16 and BF16 suffixes for
C++.
libgcc/
* config/i386/t-softfp (softfp_extensions): Add bfsf.
(softfp_truncations): Add tfbf xfbf dfbf sfbf hfbf.
(CFLAGS-extendbfsf2.c, CFLAGS-truncsfbf2.c, CFLAGS-truncdfbf2.c,
CFLAGS-truncxfbf2.c, CFLAGS-trunctfbf2.c, CFLAGS-trunchfbf2.c): Add
-msse2.
* config/i386/libgcc-glibc.ver (GCC_13.0.0): Export
__extendbfsf2 and __trunc{s,d,x,t,h}fbf2.
* config/i386/sfp-machine.h (_FP_NANSIGN_B): Define.
* config/i386/64/sfp-machine.h (_FP_NANFRAC_B): Define.
* config/i386/32/sfp-machine.h (_FP_NANFRAC_B): Define.
* soft-fp/brain.h: New file.
* soft-fp/truncsfbf2.c: New file.
* soft-fp/truncdfbf2.c: New file.
* soft-fp/truncxfbf2.c: New file.
* soft-fp/trunctfbf2.c: New file.
* soft-fp/trunchfbf2.c: New file.
* soft-fp/truncbfhf2.c: New file.
* soft-fp/extendbfsf2.c: New file.
libiberty/
* cp-demangle.h (D_BUILTIN_TYPE_COUNT): Increment.
* cp-demangle.c (cplus_demangle_builtin_types): Add std::bfloat16_t
entry.
(cplus_demangle_type): Demangle DF16b.
* testsuite/demangle-expected (_Z3xxxDF16b): New test.

21 months agoc++: Excess precision for ? int : float or int == float [PR107097, PR82071, PR87390]
Jakub Jelinek [Fri, 14 Oct 2022 07:33:23 +0000 (09:33 +0200)]
c++: Excess precision for ? int : float or int == float [PR107097, PR82071, PR87390]

The following incremental patch implements the C11 behavior (for all C++
versions) for
cond ? int : float
cond ? float : int
int cmp float
float cmp int
where int is any integral type, float any floating point type with
excess precision and cmp ==, !=, >, <, >=, <= and <=>.

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

PR c/82071
PR c/87390
PR c++/107097
gcc/cp/
* cp-tree.h (cp_ep_convert_and_check): Remove.
* cvt.cc (cp_ep_convert_and_check): Remove.
* call.cc (build_conditional_expr): Use excess precision for ?: with
one arm floating and another integral.  Don't convert first to
semantic result type from integral types.
(convert_like_internal): Don't call cp_ep_convert_and_check, instead
just strip EXCESS_PRECISION_EXPR before calling cp_convert_and_check
or cp_convert.
* typeck.cc (cp_build_binary_op): Set may_need_excess_precision
for comparisons or SPACESHIP_EXPR with at least one operand integral.
Don't compute semantic_result_type if build_type is non-NULL.  Call
cp_convert_and_check instead of cp_ep_convert_and_check.
gcc/testsuite/
* gcc.target/i386/excess-precision-8.c: For C++ wrap abort and
exit declarations into extern "C" block.
* gcc.target/i386/excess-precision-10.c: Likewise.
* g++.target/i386/excess-precision-7.C: Remove.
* g++.target/i386/excess-precision-8.C: New test.
* g++.target/i386/excess-precision-9.C: Remove.
* g++.target/i386/excess-precision-10.C: New test.
* g++.target/i386/excess-precision-12.C: New test.

21 months agoc++: Implement excess precision support for C++ [PR107097, PR323]
Jakub Jelinek [Fri, 14 Oct 2022 07:28:57 +0000 (09:28 +0200)]
c++: Implement excess precision support for C++ [PR107097, PR323]

The following patch implements excess precision support for C++.
Like for C, it uses EXCESS_PRECISION_EXPR tree to say that its operand
is evaluated in excess precision and what the semantic type of the
expression is.
In most places I've followed what the C FE does in similar spots, so
e.g. for binary ops if one or both operands are already
EXCESS_PRECISION_EXPR, strip those away or for operations that might need
excess precision (+, -, *, /) check if the operands should use excess
precision and convert to that type and at the end wrap into
EXCESS_PRECISION_EXPR with the common semantic type.
This patch follows the C99 handling where it differs from C11 handling.

There are some cases which needed to be handled differently, the C FE can
just strip EXCESS_PRECISION_EXPR (replace it with its operand) when handling
explicit cast, but that IMHO isn't right for C++ - the discovery what exact
conversion should be used (e.g. if user conversion or standard or their
sequence) should be decided based on the semantic type (i.e. type of
EXCESS_PRECISION_EXPR), and that decision continues in convert_like* where
we pick the right user conversion, again, if say some class has ctor
from double and long double and we are on ia32 with standard excess
precision promoting float/double to long double, then we should pick the
ctor from double.  Or when some other class has ctor from just double,
and EXCESS_PRECISION_EXPR semantic type is float, we should choose the
user ctor from double, but actually just convert the long double excess
precision to double and not to float first.  We need to make sure
even identity conversion converts from excess precision to the semantic one
though, but if identity is chained with other conversions, we don't want
the identity next_conversion to drop to semantic precision only to widen
afterwards.

The existing testcases tweaks were for cases on i686-linux where excess
precision breaks those tests, e.g. if we have
  double d = 4.2;
  if (d == 4.2)
then it does the expected thing only with -fexcess-precision=fast,
because with -fexcess-precision=standard it is actually
  double d = 4.2;
  if ((long double) d == 4.2L)
where 4.2L is different from 4.2.  I've added -fexcess-precision=fast
to some tests and changed other tests to use constants that are exactly
representable and don't suffer from these excess precision issues.

There is one exception, pr68180.C looks like a bug in the patch which is
also present in the C FE (so I'd like to get it resolved incrementally
in both).  Reduced testcase:
typedef float __attribute__((vector_size (16))) float32x4_t;
float32x4_t foo(float32x4_t x, float y) { return x + y; }
with -m32 -std=c11 -Wno-psabi or -m32 -std=c++17 -Wno-psabi
it is rejected with:
pr68180.c:2:52: error: conversion of scalar ‘long double’ to vector ‘float32x4_t’ {aka ‘__vector(4) float’} involves truncation
but without excess precision (say just -std=c11 -Wno-psabi or -std=c++17 -Wno-psabi)
it is accepted.  Perhaps we should pass down the semantic type to
scalar_to_vector and use the semantic type rather than excess precision type
in the diagnostics.

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

PR middle-end/323
PR c++/107097
gcc/
* doc/invoke.texi (-fexcess-precision=standard): Mention that the
option now also works in C++.
gcc/c-family/
* c-common.def (EXCESS_PRECISION_EXPR): Remove comment part about
the tree being specific to C/ObjC.
* c-opts.cc (c_common_post_options): Handle flag_excess_precision
in C++ the same as in C.
* c-lex.cc (interpret_float): Set const_type to excess_precision ()
even for C++.
gcc/cp/
* parser.cc (cp_parser_primary_expression): Handle
EXCESS_PRECISION_EXPR with REAL_CST operand the same as REAL_CST.
* cvt.cc (cp_ep_convert_and_check): New function.
* call.cc (build_conditional_expr): Add excess precision support.
When type_after_usual_arithmetic_conversions returns error_mark_node,
use gcc_checking_assert that it is because of uncomparable floating
point ranks instead of checking all those conditions and make it
work also with complex types.
(convert_like_internal): Likewise.  Add NESTED_P argument, pass true
to recursive calls to convert_like.
(convert_like): Add NESTED_P argument, pass it through to
convert_like_internal.  For other overload pass false to it.
(convert_like_with_context): Pass false to NESTED_P.
(convert_arg_to_ellipsis): Add excess precision support.
(magic_varargs_p): For __builtin_is{finite,inf,inf_sign,nan,normal}
and __builtin_fpclassify return 2 instead of 1, document what it
means.
(build_over_call): Don't handle former magic 2 which is no longer
used, instead for magic 1 remove EXCESS_PRECISION_EXPR.
(perform_direct_initialization_if_possible): Pass false to NESTED_P
convert_like argument.
* constexpr.cc (cxx_eval_constant_expression): Handle
EXCESS_PRECISION_EXPR.
(potential_constant_expression_1): Likewise.
* pt.cc (tsubst_copy, tsubst_copy_and_build): Likewise.
* cp-tree.h (cp_ep_convert_and_check): Declare.
* cp-gimplify.cc (cp_fold): Handle EXCESS_PRECISION_EXPR.
* typeck.cc (cp_common_type): For COMPLEX_TYPEs, return error_mark_node
if recursive call returned it.
(convert_arguments): For magic 1 remove EXCESS_PRECISION_EXPR.
(cp_build_binary_op): Add excess precision support.  When
cp_common_type returns error_mark_node, use gcc_checking_assert that
it is because of uncomparable floating point ranks instead of checking
all those conditions and make it work also with complex types.
(cp_build_unary_op): Likewise.
(cp_build_compound_expr): Likewise.
(build_static_cast_1): Remove EXCESS_PRECISION_EXPR.
gcc/testsuite/
* gcc.target/i386/excess-precision-1.c: For C++ wrap abort and
exit declarations into extern "C" block.
* gcc.target/i386/excess-precision-2.c: Likewise.
* gcc.target/i386/excess-precision-3.c: Likewise.  Remove
check_float_nonproto and check_double_nonproto tests for C++.
* gcc.target/i386/excess-precision-7.c: For C++ wrap abort and
exit declarations into extern "C" block.
* gcc.target/i386/excess-precision-9.c: Likewise.
* g++.target/i386/excess-precision-1.C: New test.
* g++.target/i386/excess-precision-2.C: New test.
* g++.target/i386/excess-precision-3.C: New test.
* g++.target/i386/excess-precision-4.C: New test.
* g++.target/i386/excess-precision-5.C: New test.
* g++.target/i386/excess-precision-6.C: New test.
* g++.target/i386/excess-precision-7.C: New test.
* g++.target/i386/excess-precision-9.C: New test.
* g++.target/i386/excess-precision-11.C: New test.
* c-c++-common/dfp/convert-bfp-10.c: Add -fexcess-precision=fast
as dg-additional-options.
* c-c++-common/dfp/compare-eq-const.c: Likewise.
* g++.dg/cpp1z/constexpr-96862.C: Likewise.
* g++.dg/cpp1z/decomp12.C (main): Use 2.25 instead of 2.3 to
avoid excess precision differences.
* g++.dg/other/thunk1.C: Add -fexcess-precision=fast
as dg-additional-options.
* g++.dg/vect/pr64410.cc: Likewise.
* g++.dg/cpp1y/pr68180.C: Likewise.
* g++.dg/vect/pr89653.cc: Likewise.
* g++.dg/cpp0x/variadic-tuple.C: Likewise.
* g++.dg/cpp0x/nsdmi-union1.C: Use 4.25 instead of 4.2 to
avoid excess precision differences.
* g++.old-deja/g++.brendan/copy9.C: Add -fexcess-precision=fast
as dg-additional-options.
* g++.old-deja/g++.brendan/overload7.C: Likewise.

21 months agoc: C2x storage class specifiers in compound literals
Joseph Myers [Fri, 14 Oct 2022 02:18:45 +0000 (02:18 +0000)]
c: C2x storage class specifiers in compound literals

Implement the C2x feature of storage class specifiers in compound
literals.  Such storage class specifiers (static, register or
thread_local; also constexpr, but we don't yet have C2x constexpr
support implemented) can be used before the type name (not mixed with
type specifiers, unlike in declarations) and have the same semantics
and constraints as for declarations of named objects.  Also allow GNU
__thread to be used, given that thread_local can be.

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

gcc/c/
* c-decl.cc (build_compound_literal): Add parameter scspecs.
Handle storage class specifiers.
* c-parser.cc (c_token_starts_compound_literal)
(c_parser_compound_literal_scspecs): New.
(c_parser_postfix_expression_after_paren_type): Add parameter
scspecs.  Call pedwarn_c11 for use of storage class specifiers.
Update call to build_compound_literal.
(c_parser_cast_expression, c_parser_sizeof_expression)
(c_parser_alignof_expression): Handle storage class specifiers for
compound literals.  Update calls to
c_parser_postfix_expression_after_paren_type.
(c_parser_postfix_expression): Update syntax comment.
* c-tree.h (build_compound_literal): Update prototype.
* c-typeck.cc (c_mark_addressable): Diagnose taking address of
register compound literal.

gcc/testsuite/
* gcc.dg/c11-complit-1.c, gcc.dg/c11-complit-2.c,
gcc.dg/c11-complit-3.c, gcc.dg/c2x-complit-2.c,
gcc.dg/c2x-complit-3.c, gcc.dg/c2x-complit-4.c,
gcc.dg/c2x-complit-5.c, gcc.dg/c2x-complit-6.c,
gcc.dg/c2x-complit-7.c, gcc.dg/c90-complit-2.c,
gcc.dg/gnu2x-complit-1.c, gcc.dg/gnu2x-complit-2.c: New tests.

21 months agoDaily bump.
GCC Administrator [Fri, 14 Oct 2022 00:16:35 +0000 (00:16 +0000)]
Daily bump.

21 months agoFix bogus -Wstringop-overflow warning
Eric Botcazou [Thu, 13 Oct 2022 22:55:40 +0000 (00:55 +0200)]
Fix bogus -Wstringop-overflow warning

If you compile the testcase with -O2 -fno-inline -Wall, you get:

In function 'process_array3':
cc1: warning: 'process_array4' accessing 4 bytes in a region of size 3 [-
Wstringop-overflow=]
cc1: note: referencing argument 1 of type 'char[4]'
t.c:6:6: note: in a call to function 'process_array4'
    6 | void process_array4 (char a[4], int n)
      |      ^~~~~~~~~~~~~~
cc1: warning: 'process_array4' accessing 4 bytes in a region of size 3 [-
Wstringop-overflow=]
cc1: note: referencing argument 1 of type 'char[4]'
t.c:6:6: note: in a call to function 'process_array4'

That's because the ICF IPA pass has identified the two functions and turned
process_array3 into a wrapper of process_array4.

gcc/
* gimple-ssa-warn-access.cc (pass_waccess::check_call): Return
early for calls made from thunks.

gcc/testsuite/
* gcc.dg/Wstringop-overflow-89.c: New test.

21 months agoc++: trivial formatting cleanups
Jason Merrill [Tue, 29 Jun 2021 21:45:21 +0000 (17:45 -0400)]
c++: trivial formatting cleanups

Split out from the C++ contracts patch.

gcc/cp/ChangeLog:

* cp-tree.h: Fix whitespace.
* parser.h: Fix whitespace.
* decl.cc: Fix whitespace.
* parser.cc: Fix whitespace.
* pt.cc: Fix whitespace.

21 months agoanalyzer: fix ICE introduced in r13-3168 [PR107210]
David Malcolm [Thu, 13 Oct 2022 20:05:35 +0000 (16:05 -0400)]
analyzer: fix ICE introduced in r13-3168 [PR107210]

gcc/analyzer/ChangeLog:
PR analyzer/107210
* svalue.cc (constant_svalue::maybe_fold_bits_within): Only
attempt to extract individual bits when tree_fits_uhwi_p.

gcc/testsuite/ChangeLog:
PR analyzer/107210
* gfortran.dg/analyzer/pr107210.f90: New test.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
21 months agolibgomp: Add Fortran testcases for omp_in_explicit_task
Tobias Burnus [Thu, 13 Oct 2022 18:38:27 +0000 (20:38 +0200)]
libgomp: Add Fortran testcases for omp_in_explicit_task

Fortranized testcases of commits r13-3257-ga58a965eb73
and r13-3258-g0ec4e93fb9f.

libgomp/ChangeLog:

* testsuite/libgomp.fortran/task-7.f90: New test.
* testsuite/libgomp.fortran/task-8.f90: New test.
* testsuite/libgomp.fortran/task-in-explicit-1.f90: New test.
* testsuite/libgomp.fortran/task-in-explicit-2.f90: New test.
* testsuite/libgomp.fortran/task-in-explicit-3.f90: New test.
* testsuite/libgomp.fortran/task-reduction-17.f90: New test.
* testsuite/libgomp.fortran/task-reduction-18.f90: New test.

21 months agoFix emit_group_store regression on big-endian
Eric Botcazou [Wed, 12 Oct 2022 07:27:19 +0000 (09:27 +0200)]
Fix emit_group_store regression on big-endian

The recent optimization implemented for complex modes contains an oversight
for big-endian platforms: it uses a lowpart SUBREG when the integer modes
have different sizes, but this does not match the semantics of the PARALLELs
which have a bundled byte offset; this offset is always zero in the code
path and the lowpart is not at offset zero on big-endian platforms.

gcc/
* expr.cc (emit_group_stote): Fix handling of modes of different
sizes for big-endian targets in latest change and add commentary.

21 months agouse proper DECL_INITIAL for VTV
Martin Liska [Thu, 13 Oct 2022 13:39:08 +0000 (15:39 +0200)]
use proper DECL_INITIAL for VTV

gcc/cp/ChangeLog:

* vtable-class-hierarchy.cc (vtv_generate_init_routine): Emit
an artificial variable that would be put into .preinit_array
section.

gcc/ChangeLog:

* output.h (assemble_vtv_preinit_initializer): Remove.
* varasm.cc (assemble_vtv_preinit_initializer): Remove.

21 months agopropagate partial equivs in the cache.
Andrew MacLeod [Wed, 5 Oct 2022 14:42:07 +0000 (10:42 -0400)]
propagate partial equivs in the cache.

Adjust on-entry cache propagation to look for and propagate both full
and partial equivalences.

gcc/
PR tree-optimization/102540
PR tree-optimization/102872
* gimple-range-cache.cc (ranger_cache::fill_block_cache):
Handle partial equivs.
(ranger_cache::range_from_dom): Cleanup dump output.

gcc/testsuite/
* gcc.dg/pr102540.c: New.
* gcc.dg/pr102872.c: New.

21 months agoAdd partial equivalence recognition to cast and bitwise and.
Andrew MacLeod [Thu, 6 Oct 2022 19:01:24 +0000 (15:01 -0400)]
Add partial equivalence recognition to cast and bitwise and.

This provides the hooks that will register partial equivalencies for
casts and bitwise AND operations with the appropriate bit pattern.

* range-op.cc (operator_cast::lhs_op1_relation): New.
(operator_bitwise_and::lhs_op1_relation): New.

21 months agoAdd equivalence iterator to relation oracle.
Andrew MacLeod [Fri, 7 Oct 2022 16:55:32 +0000 (12:55 -0400)]
Add equivalence iterator to relation oracle.

Instead of looping over an exposed equivalence bitmap, provide iterators
to loop over equivalences, partial equivalences, or both.

* gimple-range-cache.cc (ranger_cache::fill_block_cache): Use
iterator.
* value-relation.cc
  (equiv_relation_iterator::equiv_relation_iterator): New.
(equiv_relation_iterator::next): New.
(equiv_relation_iterator::get_name): New.
* value-relation.h (class relation_oracle): Privatize some methods.
(class equiv_relation_iterator): New.
(FOR_EACH_EQUIVALENCE): New.
(FOR_EACH_PARTIAL_EQUIV): New.
(FOR_EACH_PARTIAL_AND_FULL_EQUIV): New.

21 months agoAdd partial equivalence support to the relation oracle.
Andrew MacLeod [Thu, 6 Oct 2022 19:00:52 +0000 (15:00 -0400)]
Add partial equivalence support to the relation oracle.

This provides enhancements to the equivalence oracle to also track
partial equivalences.  They are tracked similar to equivalences, except
it tracks a 'slice' of another ssa name.   8, 16, 32 and 64 bit slices are
tracked.  This will allow casts and mask of the same value to compare
equal.

* value-relation.cc (equiv_chain::dump): Don't print empty
equivalences.
(equiv_oracle::equiv_oracle): Allocate a partial equiv table.
(equiv_oracle::~equiv_oracle): Release the partial equiv table.
(equiv_oracle::add_partial_equiv): New.
(equiv_oracle::partial_equiv_set): New.
(equiv_oracle::partial_equiv): New.
(equiv_oracle::query_relation): Check for partial equivs too.
(equiv_oracle::dump): Also dump partial equivs.
(dom_oracle::register_relation): Handle partial equivs.
(dom_oracle::query_relation): Check for partial equivs.
* value-relation.h (enum relation_kind_t): Add partial equivs.
(relation_partial_equiv_p): New.
(relation_equiv_p): New.
(class pe_slice): New.
(class equiv_oracle): Add prototypes.
(pe_to_bits): New.
(bits_to_pe): New.
(pe_min): New.

21 months agoc++: ICE with VEC_INIT_EXPR and defarg [PR106925]
Marek Polacek [Tue, 11 Oct 2022 18:16:54 +0000 (14:16 -0400)]
c++: ICE with VEC_INIT_EXPR and defarg [PR106925]

Since r12-8066, in cxx_eval_vec_init we perform expand_vec_init_expr
while processing the default argument in this test.  At this point
start_preparsed_function hasn't yet set current_function_decl.
expand_vec_init_expr then leads to maybe_splice_retval_cleanup which
checks DECL_CONSTRUCTOR_P (current_function_decl) without checking that
c_f_d is non-null first.  It seems correct that c_f_d is null here, so
it seems to me that maybe_splice_retval_cleanup should check c_f_d as
in the following patch.

PR c++/106925

gcc/cp/ChangeLog:

* except.cc (maybe_splice_retval_cleanup): Check current_function_decl.
Make the bool const.

gcc/testsuite/ChangeLog:

* g++.dg/cpp0x/initlist-defarg3.C: New test.

21 months agotree-optimization/107247 - reduce SLP reduction accumulator
Richard Biener [Thu, 13 Oct 2022 12:56:01 +0000 (14:56 +0200)]
tree-optimization/107247 - reduce SLP reduction accumulator

The following makes sure to reduce a multi-vector SLP reduction
accumulator to a single vector using vector operations if
easily possible (if the number of lanes in the vector type is
a multiple of the number of scalar accumulators).

PR tree-optimization/107247
* tree-vect-loop.cc (vect_create_epilog_for_reduction):
Reduce multi vector SLP reduction accumulators.  Check
the adjusted number of accumulator vectors against
one for the re-use in the epilogue.

21 months agomachmode: Introduce GET_MODE_NEXT_MODE with previous GET_MODE_WIDER_MODE meaning...
Jakub Jelinek [Thu, 13 Oct 2022 14:22:21 +0000 (16:22 +0200)]
machmode: Introduce GET_MODE_NEXT_MODE with previous GET_MODE_WIDER_MODE meaning, add new GET_MODE_WIDER_MODE

On Wed, Oct 05, 2022 at 04:02:25PM -0400, Jason Merrill wrote:
> > > > @@ -5716,7 +5716,13 @@ emit_store_flag_1 (rtx target, enum rtx_
> > > >        {
> > > >         machine_mode optab_mode = mclass == MODE_CC ? CCmode : compare_mode;
> > > >         icode = optab_handler (cstore_optab, optab_mode);
> > > > -     if (icode != CODE_FOR_nothing)
> > > > +     if (icode != CODE_FOR_nothing
> > > > +        /* Don't consider [BH]Fmode as usable wider mode, as neither is
> > > > +           a subset or superset of the other.  */
> > > > +        && (compare_mode == mode
> > > > +            || !SCALAR_FLOAT_MODE_P (compare_mode)
> > > > +            || maybe_ne (GET_MODE_PRECISION (compare_mode),
> > > > +                         GET_MODE_PRECISION (mode))))
> > >
> > > Why do you need to do this here (and in prepare_cmp_insn, and similarly in
> > > can_compare_p)?  Shouldn't get_wider skip over modes that are not actually
> > > wider?
> >
> > I'm afraid too many places rely on all modes of a certain class to be
> > visible when walking from "narrowest" to "widest" mode, say
> > FOR_EACH_MODE_IN_CLASS/FOR_EACH_MODE/FOR_EACH_MODE_UNTIL/FOR_EACH_WIDER_MODE
> > etc. wouldn't work at all if GET_MODE_WIDER_MODE (BFmode) == SFmode
> > && GET_MODE_WIDER_MODE (HFmode) == SFmode.
>
> Yes, it seems they need to change now that their assumptions have been
> violated.  I suppose FOR_EACH_MODE_IN_CLASS would need to change to not use
> get_wider, and users of FOR_EACH_MODE/FOR_EACH_MODE_UNTIL need to decide
> whether they want an iteration that uses get_wider (likely with a new name)
> or not.

Here is a patch which does that.

Though I admit I didn't go carefully through all 24 GET_MODE_WIDER_MODE
uses, 54 FOR_EACH_MODE_IN_CLASS uses, 3 FOR_EACH_MODE uses, 24
FOR_EACH_MODE_FROM, 6 FOR_EACH_MODE_UNTIL and 15 FOR_EACH_WIDER_MODE uses.
It is more important to go through the GET_MODE_WIDER_MODE and
FOR_EACH_WIDER_MODE uses because the patch changes behavior for those,
the rest keep their previous meaning and so can be changed incrementally
if the other meaning is desirable to them (I've of course changed the 3
spots I had to change in the previous BFmode patch and whatever triggered
during the bootstraps).

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

* genmodes.cc (emit_mode_wider): Emit previous content of
mode_wider array into mode_next array and for mode_wider
emit always VOIDmode for !CLASS_HAS_WIDER_MODES_P classes,
otherwise skip through modes with the same precision.
* machmode.h (mode_next): Declare.
(GET_MODE_NEXT_MODE): New inline function.
(mode_iterator::get_next, mode_iterator::get_known_next): New
function templates.
(FOR_EACH_MODE_IN_CLASS): Use get_next instead of get_wider.
(FOR_EACH_MODE): Use get_known_next instead of get_known_wider.
(FOR_EACH_MODE_FROM): Use get_next instead of get_wider.
(FOR_EACH_WIDER_MODE_FROM): Define.
(FOR_EACH_NEXT_MODE): Define.
* expmed.cc (emit_store_flag_1): Use FOR_EACH_WIDER_MODE_FROM
instead of FOR_EACH_MODE_FROM.
* optabs.cc (prepare_cmp_insn): Likewise.  Remove redundant
!CLASS_HAS_WIDER_MODES_P check.
(prepare_float_lib_cmp): Use FOR_EACH_WIDER_MODE_FROM instead of
FOR_EACH_MODE_FROM.
* config/i386/i386-expand.cc (get_mode_wider_vector): Use
GET_MODE_NEXT_MODE instead of GET_MODE_WIDER_MODE.

21 months ago[AArch64] Improve bit tests [PR105773]
Wilco Dijkstra [Thu, 13 Oct 2022 13:41:55 +0000 (14:41 +0100)]
[AArch64] Improve bit tests [PR105773]

Since AArch64 sets all flags on logical operations, comparisons with zero
can be combined into an AND even if the condition is LE or GT. Add a new
CC_NZV mode used by ANDS/BICS/TST instructions.

gcc/
PR target/105773
* config/aarch64/aarch64.cc (aarch64_select_cc_mode): Allow
GT/LE for merging compare with zero into AND.
(aarch64_get_condition_code_1): Add CC_NZVmode support.
* config/aarch64/aarch64-modes.def: Add CC_NZV.
* config/aarch64/aarch64.md: Use CC_NZV in cmp+and patterns.

gcc/testsuite/
PR target/105773
* gcc.target/aarch64/ands_2.c: Test for ANDS.
* gcc.target/aarch64/bics_2.c: Test for BICS.
* gcc.target/aarch64/tst_2.c: Test for TST.
* gcc.target/aarch64/tst_imm_split_1.c: Fix test.

21 months agotree-optimization/107160 - avoid reusing multiple accumulators
Richard Biener [Thu, 13 Oct 2022 12:24:05 +0000 (14:24 +0200)]
tree-optimization/107160 - avoid reusing multiple accumulators

Epilogue vectorization is not set up to re-use a vectorized
accumulator consisting of more than one vector.  For non-SLP
we always reduce to a single but for SLP that isn't happening.
In such case we currenlty miscompile the epilog so avoid this.

PR tree-optimization/107160
* tree-vect-loop.cc (vect_create_epilog_for_reduction):
Do not register accumulator if we failed to reduce it
to a single vector.

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

21 months agoAdd op1_op2_relation for float operands.
Aldy Hernandez [Thu, 13 Oct 2022 06:08:26 +0000 (08:08 +0200)]
Add op1_op2_relation for float operands.

op1_op2_relation can be called for relops (bool = a < b) as well as
regular binary operators (z = a + b).  This patch adds the overloaded
method for floating point results.

gcc/ChangeLog:

* range-op-float.cc (range_operator_float::op1_op2_relation): New.
(class foperator_equal): Add using.
(class foperator_not_equal): Same.
(class foperator_lt): Same.
(class foperator_le): Same.
(class foperator_gt): Same.
(class foperator_ge): Same.
* range-op.cc (range_op_handler::op1_op2_relation): New.
* range-op.h (range_operator_float::op1_op2_relation): New.

21 months agodiagnose return statement in match.pd (with { ... } expressions
Richard Biener [Thu, 13 Oct 2022 10:59:09 +0000 (12:59 +0200)]
diagnose return statement in match.pd (with { ... } expressions

The expression in (with { ... } is used like a statement expression
which means control flow that leaves it is not allowed.  The following
explicitely diagnoses 'return' and fixes up the few cases that crept
into match.pd (oops).  Any such return will prematurely end matching
the current expression.

* genmatch.cc (parser::parse_c_expr): Diagnose 'return'.
* match.pd: Replace 'return' statements in with expressions
with appropriate variants.

21 months agoifcvt: Fix bitpos calculation in bitfield lowering [PR107229]
Andre Vieira [Thu, 13 Oct 2022 11:09:38 +0000 (12:09 +0100)]
ifcvt: Fix bitpos calculation in bitfield lowering [PR107229]

The bitposition calculation for the bitfield lowering in loop if conversion was
not taking DECL_FIELD_OFFSET into account, which meant that it would result in
wrong bitpositions for bitfields that did not end up having representations
starting at the beginning of the struct.

gcc/ChangeLog:

PR tree-optimization/107229
* tree-if-conv.cc (get_bitfield_rep): Fix bitposition calculation.

gcc/testsuite/ChangeLog:

* gcc.dg/vect/pr107229-1.c: New test.
* gcc.dg/vect/pr107229-2.c: New test.
* gcc.dg/vect/pr107229-3.c: New test.

21 months agoLoongArch: implement count_{leading,trailing}_zeros
Xi Ruoyao [Wed, 12 Oct 2022 14:06:07 +0000 (22:06 +0800)]
LoongArch: implement count_{leading,trailing}_zeros

LoongArch always support clz and ctz instructions, so we can always use
__builtin_{clz,ctz} for count_{leading,trailing}_zeros.  This improves
the code of libgcc, and also benefits Glibc once we merge longlong.h
there.

Bootstrapped and regtested on loongarch64-linux-gnu.

include/ChangeLog:

* longlong.h [__loongarch__] (count_leading_zeros): Define.
[__loongarch__] (count_trailing_zeros): Likewise.
[__loongarch__] (COUNT_LEADING_ZEROS_0): Likewise.

21 months agovect: Don't pattern match BITFIELD_REF's of non-integrals [PR107226]
Andre Vieira [Thu, 13 Oct 2022 09:34:27 +0000 (10:34 +0100)]
vect: Don't pattern match BITFIELD_REF's of non-integrals [PR107226]

The original patch supported matching the vect_recog_bitfield_ref_pattern for
BITFIELD_REF's where the first operand didn't have a INTEGRAL_TYPE_P type.
That means it would also match vectors, leading to regressions in targets that
supported vectorization of those.

gcc/ChangeLog:

PR tree-optimization/107226
* tree-vect-patterns.cc (vect_recog_bitfield_ref_pattern): Reject
BITFIELD_REF's with non integral typed first operands.

21 months agoLoongArch: Fixed a bug in the loongarch architecture of libitm package.
Lulu Cheng [Wed, 12 Oct 2022 03:02:11 +0000 (11:02 +0800)]
LoongArch: Fixed a bug in the loongarch architecture of libitm package.

Add a soft floating point condition to the register recovery part of the code.

libitm/ChangeLog:

* config/loongarch/sjlj.S: Add a soft floating point condition to the
register recovery part of the code.

21 months agoc: Do not use *_IS_IEC_60559 == 2
Joseph Myers [Thu, 13 Oct 2022 01:13:36 +0000 (01:13 +0000)]
c: Do not use *_IS_IEC_60559 == 2

A late change for C2x (addressing comments from the second round of
editorial review before the CD ballot, postdating the most recent
public working draft) removed the value 2 for *_IS_IEC_60559 (a new
<float.h> macro added in C2x).  Adjust the implementation accordingly
not to use this value.

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

gcc/
* ginclude/float.h (FLT_IS_IEC_60559, DBL_IS_IEC_60559)
(LDBL_IS_IEC_60559): Update comment.

gcc/c-family/
* c-cppbuiltin.cc (builtin_define_float_constants): Do not use
value 2 for *_IS_IEC_60559.

gcc/testsuite/
* gcc.dg/c2x-float-10.c: Do not expect value 2 for *_IS_IEC_60559.

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

21 months agopreprocessor: Fix tracking of system header state [PR60014,PR60723]
Lewis Hyatt [Thu, 6 Oct 2022 22:05:02 +0000 (18:05 -0400)]
preprocessor: Fix tracking of system header state [PR60014,PR60723]

The token_streamer class (which implements gcc mode -E and
-save-temps/-no-integrated-cpp) needs to keep track whether the last tokens
output were in a system header, so that it can generate line marker
annotations as necessary for a downstream consumer to reconstruct the
state. The logic for tracking it, which was added by r5-1863 to resolve
PR60723, has some edge case issues as revealed by the three new test
cases. The first, coming from the original PR60014, was incidentally fixed by
r9-1926 for unrelated reasons. The other two were still failing on master
prior to this commit. Such code paths were not realizable prior to r13-1544,
which made it possible for the token streamer to see CPP_PRAGMA tokens in more
contexts.

The two main issues being corrected here are:

1) print.prev_was_system_token needs to indicate whether the previous token
output was in a system location. However, it was not being set on every token,
only on those that triggered the main code path; specifically it was not
triggered on a CPP_PRAGMA token. Testcase 2 covers this case.

2) The token_streamer uses a variable "line_marker_emitted" to remember
whether a line marker has been emitted while processing a given token, so that
it wouldn't be done more than once in case multiple conditions requiring a
line marker are true. There was no reason for this to be a member variable
that retains its value from token to token, since it is just needed for
tracking the state locally while processing a single given token. The fact
that it could retain its value for a subsequent token is rather difficult to
observe, but testcase 3 demonstrates incorrect behavior resulting from
that. Moving this to a local variable also simplifies understanding the
control flow going forward.

gcc/c-family/ChangeLog:

PR preprocessor/60014
PR preprocessor/60723
* c-ppoutput.cc (class token_streamer): Remove member
line_marker_emitted to...
(token_streamer::stream): ...a local variable here. Set
print.prev_was_system_token on all code paths.

gcc/testsuite/ChangeLog:

PR preprocessor/60014
PR preprocessor/60723
* gcc.dg/cpp/pr60014-1.c: New test.
* gcc.dg/cpp/pr60014-1.h: New test.
* gcc.dg/cpp/pr60014-2.c: New test.
* gcc.dg/cpp/pr60014-2.h: New test.
* gcc.dg/cpp/pr60014-3.c: New test.
* gcc.dg/cpp/pr60014-3.h: New test.

21 months agolibstdc++: Add __gnu_debug::basic_string<>::compare overloads
François Dumont [Wed, 10 Aug 2022 17:35:41 +0000 (19:35 +0200)]
libstdc++: Add __gnu_debug::basic_string<>::compare overloads

Rather than adding those implementations we are adding a:
using _Base::compare;

so that any compare method not implemented at __gnu_debug::basic_string
level are injected from the base class.

Also review how __gnu_debug::basic_string is tested. Now require to define
_GLIBCXX_TEST_DEBUG_STRING when running 'make check-debug'.

libstdc++-v3/ChangeLog

* include/debug/string: Add using _Base::compare.
(__gnu_debug::basic_string<>::compare(const basic_string<>&)): Remove.
(__gnu_debug::basic_string<>::compare(size_type, size_type, const basic_string<>&)):
Remove.
(__gnu_debug::basic_string<>::compare(size_type, size_type, const basic_string<>&,
size_type, size_type)): Remove.
* testsuite/util/testsuite_string.h [_GLIBCXX_TEST_DEBUG_STRING]: Include <debug/string>.
* testsuite/21_strings/basic_string/operations/compare/char/1.cc: Include testsuite_string.h
and use __gnu_test::string.
* testsuite/21_strings/basic_string/operations/compare/char/13650.cc: Likewise.
* testsuite/21_strings/basic_string/operations/compare/char/2.cc: Likewise.
* testsuite/21_strings/basic_string/operations/rfind/char/1.cc: Likewise.
* testsuite/21_strings/basic_string/operations/rfind/char/2.cc: Likewise.
* testsuite/21_strings/basic_string/operations/rfind/char/3.cc: Likewise.
* testsuite/21_strings/basic_string/operations/compare/wchar_t/1.cc:
Include testsuite_string.h
and use __gnu_test::wstring.
* testsuite/21_strings/basic_string/operations/compare/wchar_t/13650.cc: Likewise.
* testsuite/21_strings/basic_string/operations/compare/wchar_t/2.cc: Likewise.

21 months agoc++: Remove maybe-rvalue OR in implicit move
Marek Polacek [Wed, 28 Sep 2022 14:37:34 +0000 (10:37 -0400)]
c++: Remove maybe-rvalue OR in implicit move

This patch removes the two-stage overload resolution when performing
implicit move, whereby the compiler does two separate overload resolutions:
one treating the operand as an rvalue, and then (if that resolution fails)
another one treating the operand as an lvalue.  In the standard this was
introduced via CWG 1579 and implemented in gcc in r251035.  In r11-2412,
we disabled the fallback OR in C++20 (but not in C++17).  Then C++23 P2266
removed the fallback overload resolution, and changed the implicit move rules
once again.  So we wound up with three different behaviors.

The two overload resolutions approach was complicated and quirky, so
users should transition to the newer model.  Removing the maybe-rvalue
OR also allows us to simplify our code, for instance, now we can get
rid of LOOKUP_PREFER_RVALUE altogether.

This change means that code that previously didn't compile in C++17 will
now compile, for example:

  struct S1 { S1(S1 &&); };
  struct S2 : S1 {};

  S1
  f (S2 s)
  {
    return s; // OK, derived-to-base, use S1::S1(S1&&)
  }

And conversely, code that used to work in C++17 may not compile anymore:

  struct W {
    W();
  };

  struct F {
    F(W&);
    F(W&&) = delete;
  };

  F fn ()
  {
    W w;
    return w; // use w as rvalue -> use of deleted function F::F(W&&)
  }

I plan to add a note to porting_to.html.

gcc/cp/ChangeLog:

* call.cc (standard_conversion): Remove LOOKUP_PREFER_RVALUE code.
(reference_binding): Honor clk_implicit_rval even pre-C++20.
(implicit_conversion_1): Remove LOOKUP_PREFER_RVALUE code.
(build_user_type_conversion_1): Likewise.
(convert_like_internal): Likewise.
(build_over_call): Likewise.
* cp-tree.h (LOOKUP_PREFER_RVALUE): Remove.
(LOOKUP_NO_NARROWING): Adjust definition.
* except.cc (build_throw): Don't perform two overload resolutions.
* typeck.cc (maybe_warn_pessimizing_move): Don't use
LOOKUP_PREFER_RVALUE.
(check_return_expr): Don't perform two overload resolutions.

gcc/testsuite/ChangeLog:

* g++.dg/cpp0x/Wredundant-move10.C: Adjust dg-warning.
* g++.dg/cpp0x/Wredundant-move7.C: Likewise.
* g++.dg/cpp0x/move-return2.C: Remove dg-error.
* g++.dg/cpp0x/move-return4.C: Likewise.
* g++.dg/cpp0x/ref-qual20.C: Adjust expected return value.
* g++.dg/cpp0x/move-return5.C: New test.

21 months agoAdd range-op entry for floating point NEGATE_EXPR.
Aldy Hernandez [Tue, 11 Oct 2022 15:23:42 +0000 (17:23 +0200)]
Add range-op entry for floating point NEGATE_EXPR.

gcc/ChangeLog:

* range-op-float.cc (class foperator_negate): New.
(floating_op_table::floating_op_table): Add NEGATE_EXPR
(range_op_float_tests): Add negate tests.

21 months agoFortran: check types of operands of arithmetic binary operations [PR107217]
Harald Anlauf [Tue, 11 Oct 2022 20:08:48 +0000 (22:08 +0200)]
Fortran: check types of operands of arithmetic binary operations [PR107217]

gcc/fortran/ChangeLog:

PR fortran/107217
* arith.cc (gfc_arith_plus): Compare consistency of types of operands.
(gfc_arith_minus): Likewise.
(gfc_arith_times): Likewise.
(gfc_arith_divide): Likewise.
(arith_power): Check that both operands are of numeric type.

gcc/testsuite/ChangeLog:

PR fortran/107217
* gfortran.dg/pr107217.f90: New test.

21 months agolibgomp: Fix up OpenMP 5.2 feature bullet
Jakub Jelinek [Wed, 12 Oct 2022 16:43:58 +0000 (18:43 +0200)]
libgomp: Fix up OpenMP 5.2 feature bullet

The previous bullet correctly mentions 5.2 added for Fortran
allocators directive which is a replacement of allocate directive
associated with ALLOCATE statement to differentiate it at parse time
from allocate directive as declarative one not associated with ALLOCATE
statement, but the deprecation bullet talks about non-existing allocator
directive.

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

* libgomp.texi (OpenMP 5.2): Fix up allocator -> allocate directive
in deprecation bullet.

21 months agolibgomp: Add omp_in_explicit_task support
Jakub Jelinek [Wed, 12 Oct 2022 16:39:20 +0000 (18:39 +0200)]
libgomp: Add omp_in_explicit_task support

This is pretty straightforward, if gomp_thread ()->task is NULL,
it can't be explicit task, otherwise if
gomp_thread ()->task->kind == GOMP_TASK_IMPLICIT, it is an implicit
task, otherwise explicit task.

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

* omp.h.in (omp_in_explicit_task): Declare.
* omp_lib.h.in (omp_in_explicit_task): Likewise.
* omp_lib.f90.in (omp_in_explicit_task): New interface.
* libgomp.map (OMP_5.2): New symbol version, export
omp_in_explicit_task and omp_in_explicit_task_.
* task.c (omp_in_explicit_task): New function.
* fortran.c (omp_in_explicit_task): Add ialias_redirect.
(omp_in_explicit_task_): New function.
* libgomp.texi (OpenMP 5.2): Mark omp_in_explicit_task as implemented.
* testsuite/libgomp.c-c++-common/task-in-explicit-1.c: New test.
* testsuite/libgomp.c-c++-common/task-in-explicit-2.c: New test.
* testsuite/libgomp.c-c++-common/task-in-explicit-3.c: New test.

21 months agolibgomp: Fix up creation of artificial teams
Jakub Jelinek [Wed, 12 Oct 2022 15:54:08 +0000 (17:54 +0200)]
libgomp: Fix up creation of artificial teams

When not in explicit parallel/target/teams construct, we in some cases create
an artificial parallel with a single thread (either to handle target nowait
or for task reduction purposes).  In those cases, it handled again artificially
created implicit task (created by gomp_new_icv for cases where we needed to write
to some ICVs), but as the testcases show, didn't take into account possibility
of this being done from explicit task(s).  The code would destroy/free the previous
task and replace it with the new implicit task.  If task is an explicit task
(when teams is NULL, all explicit tasks behave like if (0)), it is a pointer to
a local stack variable, so freeing it doesn't work, and additionally we shouldn't
lose the explicit tasks - the new implicit task should instead replace the
ancestor task which is the first implicit one.

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

* task.c (gomp_create_artificial_team): Fix up handling of invocations
from within explicit task.
* target.c (GOMP_target_ext): Likewise.
* testsuite/libgomp.c/task-7.c: New test.
* testsuite/libgomp.c/task-8.c: New test.
* testsuite/libgomp.c-c++-common/task-reduction-17.c: New test.
* testsuite/libgomp.c-c++-common/task-reduction-18.c: New test.

21 months agoc++: defer all consteval in default args [DR2631]
Jason Merrill [Sat, 8 Oct 2022 00:34:53 +0000 (20:34 -0400)]
c++: defer all consteval in default args [DR2631]

The proposed resolution of CWG2631 extends our current handling of
source_location::current to all consteval functions: default arguments
are not evaluated until they're used in a call, the same should apply to
evaluation of immediate invocations.  And similarly for default member
initializers.

Previously we folded source_location::current in cp_fold_r; now we fold all
consteval calls in default arguments/member initializers in bot_replace.

DR 2631

gcc/cp/ChangeLog:

* cp-tree.h (source_location_current_p): Remove.
* name-lookup.h (struct cp_binding_level): Remove
immediate_fn_ctx_p.
* call.cc (in_immediate_context): All default args
and DMI are potentially immediate context.
(immediate_invocation_p): Don't treat source_location specially.
(struct in_consteval_if_p_temp_override): Move to cp-tree.h.
* constexpr.cc (get_nth_callarg): Move to cp-tree.h.
* cp-gimplify.cc (cp_fold_r): Don't fold consteval.
* name-lookup.cc (begin_scope): Don't set immediate_fn_ctx_p.
* parser.cc (cp_parser_lambda_declarator_opt): Likewise.
(cp_parser_direct_declarator): Likewise.
* pt.cc (tsubst_default_argument): Open sk_function_parms level.
* tree.cc (source_location_current_p): Remove.
(bot_replace): Fold consteval here.
(break_out_target_exprs): Handle errors.

gcc/testsuite/ChangeLog:

* g++.dg/cpp2a/consteval-defarg3.C: New test.

21 months agolibstdc++: Implement ranges::repeat_view from P2474R2
Patrick Palka [Wed, 12 Oct 2022 15:14:11 +0000 (11:14 -0400)]
libstdc++: Implement ranges::repeat_view from P2474R2

libstdc++-v3/ChangeLog:

* include/std/ranges (repeat_view): Define.
(repeat_view::_Iterator): Define.
(views::__detail::__can_repeat_view): Define.
(views::__detail::__can_bounded_repeat_view): Define.
(views::_Repeat, views::repeat): Define.
* testsuite/std/ranges/repeat/1.cc: New test.

21 months agoRISC-V: Remove TUPLE size macro define. [NFC]
Ju-Zhe Zhong [Tue, 11 Oct 2022 06:23:33 +0000 (14:23 +0800)]
RISC-V: Remove TUPLE size macro define. [NFC]

gcc/ChangeLog:

* config/riscv/riscv-vector-builtins.h: Remove unused macro.

21 months agoRISC-V: Apply clang-format for riscv-vector-builtins.* [NFC]
Ju-Zhe Zhong [Tue, 11 Oct 2022 06:21:59 +0000 (14:21 +0800)]
RISC-V: Apply clang-format for riscv-vector-builtins.* [NFC]

gcc/ChangeLog:

* config/riscv/riscv-vector-builtins.cc (DEF_RVV_TYPE): Apply
clang-format.
(add_vector_type_attribute): Ditto.
* config/riscv/riscv-vector-builtins.def (DEF_RVV_TYPE): Apply
clang-format.
* config/riscv/riscv-vector-builtins.h (DEF_RVV_TYPE): Apply
clang-format.

21 months agoRISC-V: Refine register_builtin_types function. [NFC]
Ju-Zhe Zhong [Tue, 11 Oct 2022 06:15:21 +0000 (14:15 +0800)]
RISC-V: Refine register_builtin_types function. [NFC]

gcc/ChangeLog:

* config/riscv/riscv-vector-builtins.cc (builtin_types): Redefine
vector types.
(build_const_pointer): New function.
(register_builtin_type): Ditto.
(DEF_RVV_TYPE): Simplify macro.
(register_vector_type): Refine implementation.
* config/riscv/riscv-vector-builtins.h (rvv_builtin_types_t): New.

21 months agoRISC-V: Move function place to make it looks better. [NFC]
Ju-Zhe Zhong [Tue, 11 Oct 2022 04:48:20 +0000 (12:48 +0800)]
RISC-V: Move function place to make it looks better. [NFC]

gcc/ChangeLog:

* config/riscv/riscv-vector-builtins.h (class rvv_switcher): Move to
this to ....
* config/riscv/riscv-vector-builtins.cc (class rvv_switcher):
here.

21 months agoRemove AVX512_VP2INTERSECT from PTA_SAPPHIRERAPIDS
Cui,Lili [Thu, 29 Sep 2022 06:28:06 +0000 (14:28 +0800)]
Remove AVX512_VP2INTERSECT from PTA_SAPPHIRERAPIDS

gcc/ChangeLog:

* config/i386/driver-i386.cc (host_detect_local_cpu):
Move sapphirerapids out of AVX512_VP2INTERSECT.
* config/i386/i386.h: Remove AVX512_VP2INTERSECT from PTA_SAPPHIRERAPIDS
* doc/invoke.texi: Remove AVX512_VP2INTERSECT from SAPPHIRERAPIDS

21 months agoMAINTAINERS: Add myself for write after approval
Cui,Lili [Wed, 12 Oct 2022 07:43:28 +0000 (15:43 +0800)]
MAINTAINERS: Add myself for write after approval

ChangeLog:
* MAINTAINERS (Write After Approval): Add myself.

21 months agogcov: rename gcov_write_summary
Martin Liska [Tue, 11 Oct 2022 18:45:21 +0000 (20:45 +0200)]
gcov: rename gcov_write_summary

gcc/ChangeLog:

* gcov-io.cc (gcov_write_summary): Rename to ...
(gcov_write_object_summary): ... this.
* gcov-io.h (GCOV_TAG_OBJECT_SUMMARY_LENGTH): Rename from ...
(GCOV_TAG_SUMMARY_LENGTH): ... this.

libgcc/ChangeLog:

* libgcov-driver.c: Use new function.
* libgcov.h (gcov_write_summary): Rename to ...
(gcov_write_object_summary): ... this.

21 months agoregenerate configure files
Martin Liska [Wed, 12 Oct 2022 07:31:32 +0000 (09:31 +0200)]
regenerate configure files

Needed after a recent change.

gcc/ChangeLog:

* configure: Regenerate.

libatomic/ChangeLog:

* configure: Regenerate.

libbacktrace/ChangeLog:

* configure: Regenerate.

libcc1/ChangeLog:

* configure: Regenerate.

libffi/ChangeLog:

* configure: Regenerate.

libgfortran/ChangeLog:

* configure: Regenerate.

libgomp/ChangeLog:

* configure: Regenerate.

libitm/ChangeLog:

* configure: Regenerate.

libobjc/ChangeLog:

* configure: Regenerate.

liboffloadmic/ChangeLog:

* configure: Regenerate.
* plugin/configure: Regenerate.

libphobos/ChangeLog:

* configure: Regenerate.

libquadmath/ChangeLog:

* configure: Regenerate.

libsanitizer/ChangeLog:

* configure: Regenerate.

libssp/ChangeLog:

* configure: Regenerate.

libstdc++-v3/ChangeLog:

* configure: Regenerate.

libvtv/ChangeLog:

* configure: Regenerate.

lto-plugin/ChangeLog:

* configure: Regenerate.

zlib/ChangeLog:

* configure: Regenerate.

21 months agoAdd stubs for floating point range-op tests.
Aldy Hernandez [Tue, 11 Oct 2022 15:23:33 +0000 (17:23 +0200)]
Add stubs for floating point range-op tests.

gcc/ChangeLog:

* range-op-float.cc (frange_float): New.
(range_op_float_tests): New.
* range-op.cc (range_op_tests): Call range_op_float_tests.

21 months agoAdd method to query the sign of a NAN.
Aldy Hernandez [Tue, 11 Oct 2022 17:21:14 +0000 (19:21 +0200)]
Add method to query the sign of a NAN.

In writing some range-op entries I noticed we don't have a way to
query the sign of the NAN in a range, unless the range only contains
NAN, in which case you can just use frange::signbit_p.  This patch
adds a method that returns TRUE if there exists the possiblity of a
NAN and we know its sign.

gcc/ChangeLog:

* value-range.h (frange::nan_signbit_p): New.

21 months agoDisable tree to bool conversion in frange::update_nan.
Aldy Hernandez [Tue, 11 Oct 2022 17:20:47 +0000 (19:20 +0200)]
Disable tree to bool conversion in frange::update_nan.

We have a set_nan(type) method which can be confused with
update_nan(bool) because of the silent conversion of pointers to bool.
Currently, if you call update_nan(tree), you'll set the possibility of
NAN with a sign of true if tree is non-null.  This is prone to error
and this patch disallows this behavior.

gcc/ChangeLog:

* value-range.cc (frange::set_nonnegative): Pass bool to
update_nan.
* value-range.h: Disallow conversion to bool in update_nan().

21 months agoAdd an frange(type) constructor analogous to the irange version.
Aldy Hernandez [Tue, 11 Oct 2022 15:22:40 +0000 (17:22 +0200)]
Add an frange(type) constructor analogous to the irange version.

gcc/ChangeLog:

* value-range.h (frange::frange): Add constructor taking type.

21 months agoAdd default relation_kind to floating point range-op entries.
Aldy Hernandez [Tue, 11 Oct 2022 15:22:23 +0000 (17:22 +0200)]
Add default relation_kind to floating point range-op entries.

The methods from which these derive all have a default relation_kind.
This patch just adds the default, to make it easier to write unit
tests later.

gcc/ChangeLog:

* range-op-float.cc: Add relation_kind = VREL_VARYING to all
methods.

21 months agoLibvtv-test: Fix bug that scansarif.exp cannot be found in libvtv regression test.
Lulu Cheng [Tue, 27 Sep 2022 02:47:06 +0000 (10:47 +0800)]
Libvtv-test: Fix bug that scansarif.exp cannot be found in libvtv regression test.

SARIF support was added in r13-967 but libvtv wasn't updated.

libvtv/ChangeLog:

* testsuite/lib/libvtv-dg.exp: Add load_gcc_lib of scansarif.exp.

21 months agoDaily bump.
GCC Administrator [Wed, 12 Oct 2022 00:17:24 +0000 (00:17 +0000)]
Daily bump.

21 months agoEnable support for atomic primitives on SPARC/Linux
Eric Botcazou [Tue, 11 Oct 2022 22:38:04 +0000 (00:38 +0200)]
Enable support for atomic primitives on SPARC/Linux

The SPARC/Linux port is very similar to the SPARC/Solaris port nowadays so
it makes sense to copy the setting of the support for atomic primitives.

This fixes the single regression in the gnat.dg testsuite:
FAIL: gnat.dg/prot7.adb (test for excess errors)

gcc/ada/
* libgnat/system-linux-sparc.ads (Support_Atomic_Primitives): New
constant set to True.

21 months agoFortran: check types of source expressions before conversion [PR107215]
Harald Anlauf [Tue, 11 Oct 2022 18:37:42 +0000 (20:37 +0200)]
Fortran: check types of source expressions before conversion [PR107215]

gcc/fortran/ChangeLog:

PR fortran/107215
* arith.cc (gfc_int2int): Check validity of type of source expr.
(gfc_int2real): Likewise.
(gfc_int2complex): Likewise.
(gfc_real2int): Likewise.
(gfc_real2real): Likewise.
(gfc_complex2int): Likewise.
(gfc_complex2real): Likewise.
(gfc_complex2complex): Likewise.
(gfc_log2log): Likewise.
(gfc_log2int): Likewise.
(gfc_int2log): Likewise.

gcc/testsuite/ChangeLog:

PR fortran/107215
* gfortran.dg/pr107215.f90: New test.

21 months agolibstdc++: Fix bootstrap for --disable-threads build [PR107221]
Jonathan Wakely [Tue, 11 Oct 2022 19:19:08 +0000 (20:19 +0100)]
libstdc++: Fix bootstrap for --disable-threads build [PR107221]

The __scoped_lock type should be used unqualified so that we always
refer to pool::__scoped_lock, which might be the dummy fallback
implementation.

The __mutex and __scoped_lock types in <ext/concurrence.h> already work
fine without __GTHREADS being defined, but that header isn't included at
all unless _GLIBCXX_HOSTED != 0. The fallback implementation should be
used for ! _GLIBCXX_HOSTED instead of for !defined __GTHREADS.

libstdc++-v3/ChangeLog:

PR bootstrap/107221
* libsupc++/eh_alloc.cc (pool): Change preprocessor condition
for using __mutex from __GTHREADS to _GLIBCXX_HOSTED.
(pool::allocate): Remove namespace qualification to use
pool::__scoped_lock instead of __gnu_cxx::__scoped_lock.

21 months agoc++ modules: ICE with templated friend and std namespace [PR100134]
Patrick Palka [Tue, 11 Oct 2022 19:02:23 +0000 (15:02 -0400)]
c++ modules: ICE with templated friend and std namespace [PR100134]

The function depset::hash::add_binding_entity has an assert verifying
that if a namespace contains an exported entity, then the namespace must
have been opened in the module purview:

  if (data->hash->add_namespace_entities (decl, data->partitions))
    {
      /* It contains an exported thing, so it is exported.  */
      gcc_checking_assert (DECL_MODULE_PURVIEW_P (decl));
      DECL_MODULE_EXPORT_P (decl) = true;
    }

We're tripping over this assert in the below testcase because by
instantiating and exporting std::A<int>, we in turn define and export the
hidden friend std::f(A<int>) without ever having opened the enclosing
namespace std within the module purview, and thus DECL_MODULE_PURVIEW_P
for std is false.

It's important that the enclosing namespace is std here: if we use
a different namespace then the ICE disappears.  This probably has
something to do with us predefining std via push_namespace from
cxx_init_decl_processing (which makes it look like we've opened it
within the TU), whereas with another namespace we would instead lazily
create its NAMESPACE_DECL from add_imported_namespace.

Since templated friend functions are special in that they give us a way
to introduce a namespace-scope function without having to explicitly
open the namespace, this patch proposes to fix this ICE by propagating
DECL_MODULE_PURVIEW_P from the introduced function to the enclosing
namespace during tsubst_friend_function.

PR c++/100134

gcc/cp/ChangeLog:

* pt.cc (tsubst_friend_function): Propagate DECL_MODULE_PURVIEW_P
from the introduced namespace-scope function to the namespace.

gcc/testsuite/ChangeLog:

* g++.dg/modules/tpl-friend-8_a.H: New test.
* g++.dg/modules/tpl-friend-8_b.C: New test.

21 months agoc++ modules: lazy loading from within template [PR99377]
Patrick Palka [Tue, 11 Oct 2022 19:02:01 +0000 (15:02 -0400)]
c++ modules: lazy loading from within template [PR99377]

Here when lazily loading the binding for f due to its first use from the
template g, processing_template_decl is set which causes the call to
note_vague_linkage_fn from module_state::read_cluster to have no effect,
and thus we never push f onto deferred_fns and end up never emitting its
definition despite needing it.

The behavior of the lazy loading machinery shouldn't be sensitive to
whether we're inside a template, so to that end this patch makes us
clear processing_template_decl in the entrypoints lazy_load_binding and
lazy_load_pendings.

PR c++/99377

gcc/cp/ChangeLog:

* module.cc (lazy_load_binding): Clear processing_template_decl.
(lazy_load_pendings): Likewise.

gcc/testsuite/ChangeLog:

* g++.dg/modules/pr99377-2_a.C: New test.
* g++.dg/modules/pr99377-2_b.C: New test.

21 months agolibstdc++: Allow emergency EH alloc pool size to be tuned [PR68606]
Jonathan Wakely [Wed, 5 Oct 2022 20:21:54 +0000 (21:21 +0100)]
libstdc++: Allow emergency EH alloc pool size to be tuned [PR68606]

Implement a long-standing request to support tuning the size of the
emergency buffer for allocating exceptions after malloc fails, or to
disable that buffer entirely.

It's now possible to disable the dynamic allocation of the buffer and
use a fixed-size static buffer, via --enable-libstdcxx-static-eh-pool.
This is a built-time choice that is baked into libstdc++ and so affects
all code linked against that build of libstdc++.

The size of the pool can be set by --with-libstdcxx-eh-pool-obj-count=N
which is measured in units of sizeof(void*) not bytes. A given exception
type such as std::system_error depends on the target, so giving a size
in bytes wouldn't be portable across 16/32/64-bit targets.

When libstdc++ is configured to use a dynamic buffer, the size of that
buffer can now be tuned at runtime by setting the GLIBCXX_TUNABLES
environment variable (c.f. PR libstdc++/88264). The number of exceptions
to reserve space for is controlled by the "glibcxx.eh_pool.obj_count"
and "glibcxx.eh_pool.obj_size" tunables. The pool will be sized to be
able to allocate obj_count exceptions of size obj_size*sizeof(void*) and
obj_count "dependent" exceptions rethrown by std::rethrow_exception.

With the ability to tune the buffer size, we can reduce the default pool
size on 32-bit and 16-bit targets. Most users never need to throw 1kB
exceptions in parallel from hundreds of threads after malloc is OOM. The
users who do need that can use the tunables to select larger sizes.

The old defaults can be chosen at runtime by setting GLIBCXX_TUNABLES
to:
64-bit: glibcxx.eh_pool.obj_count=64:glibcxx.eh_pool.obj_size=112
32-bit: glibcxx.eh_pool.obj_count=32:glibcxx.eh_pool.obj_size=104

Or approximated by configuring with:
64-bit: --with-libstdcxx-eh-pool-obj-count=252
32-bit: --with-libstdcxx-eh-pool-obj-count=94

libstdc++-v3/ChangeLog:

PR libstdc++/68606
* Makefile.in: Regenerate.
* acinclude.m4 (GLIBCXX_EMERGENCY_EH_ALLOC): New macro.
* configure: Regenerate.
* configure.ac: Use GLIBCXX_EMERGENCY_EH_ALLOC.
* crossconfig.m4: Check for secure_getenv.
* doc/Makefile.in: Regenerate.
* doc/xml/manual/configure.xml: Document new configure options.
* doc/xml/manual/evolution.xml: Document addition of tunables.
* doc/xml/manual/using_exceptions.xml: Document emergency
buffer and tunables.
* doc/html/*: Regenerate.
* include/Makefile.in: Regenerate.
* libsupc++/Makefile.am: Use EH_POOL_FLAGS.
* libsupc++/Makefile.in: Regenerate.
* libsupc++/eh_alloc.cc (EMERGENCY_OBJ_SIZE): Define in units
of sizeof(void*) not including the ABI's exception header.
(EMERGENCY_OBJ_COUNT): Define as target-independent calculation
based on word size.
(MAX_OBJ_COUNT): Define macro for upper limit on pool size.
(pool) [_GLIBCXX_EH_POOL_STATIC]: Use fixed-size buffer.
(pool::buffer_size_in_bytes): New static member function.
(pool::pool): Parse GLIBCXX_TUNABLES environment variable to set
pool size at runtime.
(pool::in_pool): Use std::less<void*> for total order.
(__freeres) [_GLIBCXX_EH_POOL_STATIC]: Do nothing.
(__cxa_free_exception, __cxa_free_dependent_exception): Add
[[unlikely]] attributes.
* po/Makefile.in: Regenerate.
* python/Makefile.in: Regenerate.
* src/Makefile.in: Regenerate.
* src/c++11/Makefile.in: Regenerate.
* src/c++17/Makefile.in: Regenerate.
* src/c++20/Makefile.in: Regenerate.
* src/c++98/Makefile.in: Regenerate.
* src/filesystem/Makefile.in: Regenerate.
* src/libbacktrace/Makefile.in: Regenerate.
* testsuite/Makefile.in: Regenerate.

21 months agoAvoid calling tracer.trailer() twice.
Aldy Hernandez [Tue, 11 Oct 2022 14:00:33 +0000 (16:00 +0200)]
Avoid calling tracer.trailer() twice.

gcc/ChangeLog:

* gimple-range-gori.cc (gori_compute::logical_combine): Avoid
calling tracer.trailer().

21 months agoi386: Fix up RTL checking ICE [PR107185]
Jakub Jelinek [Tue, 11 Oct 2022 13:57:09 +0000 (15:57 +0200)]
i386: Fix up RTL checking ICE [PR107185]

On Tue, Oct 11, 2022 at 04:03:16PM +0800, liuhongt via Gcc-patches wrote:
> gcc/ChangeLog:
>
>       * config/i386/i386.md (*notxor<mode>_1): New post_reload
>       define_insn_and_split.
>       (*notxorqi_1): Ditto.

> --- a/gcc/config/i386/i386.md
> +++ b/gcc/config/i386/i386.md
> @@ -10826,6 +10826,39 @@ (define_insn "*<code><mode>_1"
>     (set_attr "type" "alu, alu, msklog")
>     (set_attr "mode" "<MODE>")])
>
> +(define_insn_and_split "*notxor<mode>_1"
> +  [(set (match_operand:SWI248 0 "nonimmediate_operand" "=rm,r,?k")
> +     (not:SWI248
> +       (xor:SWI248
> +         (match_operand:SWI248 1 "nonimmediate_operand" "%0,0,k")
> +         (match_operand:SWI248 2 "<general_operand>" "r<i>,<m>,k"))))
> +   (clobber (reg:CC FLAGS_REG))]
> +  "ix86_binary_operator_ok (XOR, <MODE>mode, operands)"
> +  "#"
> +  "&& reload_completed"
> +  [(parallel
> +    [(set (match_dup 0)
> +       (xor:SWI248 (match_dup 1) (match_dup 2)))
> +     (clobber (reg:CC FLAGS_REG))])
> +   (set (match_dup 0)
> +     (not:SWI248 (match_dup 1)))]
> +{
> +  if (MASK_REGNO_P (REGNO (operands[0])))

This causes --enable-checking=yes,rtl,extra regression on
gcc.dg/store_merging_13.c test on x86_64-linux:
.../gcc/testsuite/gcc.dg/store_merging_13.c: In function 'f13':
.../gcc/testsuite/gcc.dg/store_merging_13.c:189:1: internal compiler error: RTL check: expected code 'reg', have 'mem' in rhs_regno, at rtl.h:1932
0x7b0c8f rtl_check_failed_code1(rtx_def const*, rtx_code, char const*, int, char const*)
        ../../gcc/rtl.cc:916
0x8e74be rhs_regno
        ../../gcc/rtl.h:1932
0x9785fd rhs_regno
        ./genrtl.h:120
0x9785fd gen_split_260(rtx_insn*, rtx_def**)
        ../../gcc/config/i386/i386.md:10846
0x23596dc split_insns(rtx_def*, rtx_insn*)
        ../../gcc/config/i386/i386.md:16392
0xfccd5a try_split(rtx_def*, rtx_insn*, int)
        ../../gcc/emit-rtl.cc:3799
0x132e9d8 split_insn
        ../../gcc/recog.cc:3384
0x13359d5 split_all_insns()
        ../../gcc/recog.cc:3488
0x1335ae8 execute
        ../../gcc/recog.cc:4412
Please submit a full bug report, with preprocessed source (by using -freport-bug).
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.

Fixed thusly.

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

PR target/107185
* config/i386/i386.md (*notxor<mode>_1): Use MASK_REG_P (x) instead of
MASK_REGNO_P (REGNO (x)).

21 months agoImplement ABS_EXPR operator for frange.
Aldy Hernandez [Mon, 10 Oct 2022 12:56:42 +0000 (14:56 +0200)]
Implement ABS_EXPR operator for frange.

Implementing ABS_EXPR allows us to fold certain __builtin_inf calls
since they are expanded into calls to involving ABS_EXPR.

This is an adaptation of the integer version.

gcc/ChangeLog:

* range-op-float.cc (class foperator_abs): New.
(floating_op_table::floating_op_table): Add ABS_EXPR entry.

gcc/testsuite/ChangeLog:

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

21 months agoImplement op1_range operators for unordered comparisons.
Aldy Hernandez [Mon, 10 Oct 2022 14:58:29 +0000 (16:58 +0200)]
Implement op1_range operators for unordered comparisons.

gcc/ChangeLog:

* range-op-float.cc (foperator_unordered_le::op1_range): New.
(foperator_unordered_le::op2_range): New.
(foperator_unordered_gt::op1_range): New.
(foperator_unordered_gt::op2_range): New.
(foperator_unordered_ge::op1_range): New.
(foperator_unordered_ge::op2_range): New.
(foperator_unordered_equal::op1_range): New.

21 months agoShare common ordered comparison code with UN*_EXPR.
Aldy Hernandez [Mon, 10 Oct 2022 12:56:01 +0000 (14:56 +0200)]
Share common ordered comparison code with UN*_EXPR.

Most unordered comparisons can use the result from the ordered
version, if the operands are known not to be NAN or if the result is
true.

gcc/ChangeLog:

* range-op-float.cc (class foperator_unordered_lt): New.
(class foperator_relop_unknown): Remove
(class foperator_unordered_le): New.
(class foperator_unordered_gt): New.
(class foperator_unordered_ge): New.
(class foperator_unordered_equal): New.
(floating_op_table::floating_op_table): Replace all UN_EXPR
entries with their appropriate fop_unordered_* counterpart.

21 months agoMove TRUE case first in range-op.cc.
Aldy Hernandez [Tue, 11 Oct 2022 09:20:25 +0000 (11:20 +0200)]
Move TRUE case first in range-op.cc.

It's incredibly annoying that some of the BRS_TRUE cases come after
BRS_FALSE, if only because we're not consistent.  Having random
ordering increases the changes of thinkos when adapting the irange
code to floats.

gcc/ChangeLog:

* range-op.cc (operator_equal::op1_range): Move BRS_TRUE case up.
(operator_lt::op2_range): Same.
(operator_le::op2_range): Same.
(operator_gt::op2_range): Same.
(operator_ge::op2_range): Same.

21 months agolibiberty: Demangling 'M' prefixes
Nathan Sidwell [Fri, 30 Sep 2022 16:43:30 +0000 (09:43 -0700)]
libiberty: Demangling 'M' prefixes

The grammar for a lambda context can include <source-name> 'M', and we
were adding the component that generated to the substitution table
twice.  Just ignore the 'M' completely -- we'll already have done the
checks we need when we saw its predecessor.  A prefix cannot be the
last component of a nested name, so we do not need to check for that
case (although we could if we wanted to be more lenient).

libiberty/
* cp-demangle.c (d_prefix): 'M' components are not
(re-)added to the substitution table.
* testsuite/demangle-expected: Add tests.

21 months agotree-optimization/107212 - SLP reduction of reduction paths
Richard Biener [Tue, 11 Oct 2022 09:34:55 +0000 (11:34 +0200)]
tree-optimization/107212 - SLP reduction of reduction paths

The following fixes an issue with how we handle epilogue generation
for SLP reductions of reduction paths where the actual live lanes
are not "canonical".  We need to make sure to identify all live
lanes as reductions and thus have to iterate over all participating
SLP lanes when walking the reduction SSA use-def chain.  Also the
previous attempt likely to mitigate such issue in
vectorizable_live_operation is misguided and has to be removed.

PR tree-optimization/107212
* tree-vect-loop.cc (vectorizable_reduction): Make sure to
set STMT_VINFO_REDUC_DEF for all live lanes in a SLP
reduction.
(vectorizable_live_operation): Do not pun to the SLP
node representative for reduction epilogue generation.

* gcc.dg/vect/pr107212-1.c: New testcase.
* gcc.dg/vect/pr107212-2.c: Likewise.

21 months agoamdgcn: vector testsuite tweaks
Andrew Stubbs [Sat, 10 Sep 2022 22:47:19 +0000 (23:47 +0100)]
amdgcn: vector testsuite tweaks

The testsuite needs a few tweaks following my patches to add multiple vector
sizes for amdgcn.

gcc/testsuite/ChangeLog:

* gcc.dg/pr104464.c: Xfail on amdgcn.
* gcc.dg/signbit-2.c: Likewise.
* gcc.dg/signbit-5.c: Likewise.
* gcc.dg/vect/bb-slp-68.c: Likewise.
* gcc.dg/vect/bb-slp-cond-1.c: Change expectations on amdgcn.
* gcc.dg/vect/bb-slp-subgroups-3.c: Likewise.
* gcc.dg/vect/no-vfa-vect-depend-2.c: Change expectations for multiple
vector sizes.
* gcc.dg/vect/pr33953.c: Likewise.
* gcc.dg/vect/pr65947-12.c: Likewise.
* gcc.dg/vect/pr65947-13.c: Likewise.
* gcc.dg/vect/pr80631-2.c: Likewise.
* gcc.dg/vect/slp-reduc-4.c: Likewise.
* gcc.dg/vect/trapv-vect-reduc-4.c: Likewise.
* lib/target-supports.exp (available_vector_sizes): Add more sizes
for amdgcn.

21 months agoamdgcn: Add vector integer negate insn
Andrew Stubbs [Thu, 22 Sep 2022 11:48:30 +0000 (12:48 +0100)]
amdgcn: Add vector integer negate insn

Another example of the vectorizer needing explicit insns where the scalar
expander just works.

gcc/ChangeLog:

* config/gcn/gcn-valu.md (neg<mode>2): New define_expand.

21 months agoamdgcn: vec_init for multiple vector sizes
Andrew Stubbs [Wed, 11 Mar 2020 16:39:54 +0000 (16:39 +0000)]
amdgcn: vec_init for multiple vector sizes

Implements vec_init when the input is a vector of smaller vectors, or of
vector MEM types, or a smaller vector duplicated several times.

gcc/ChangeLog:

* config/gcn/gcn-valu.md (vec_init<V_ALL:mode><V_ALL_ALT:mode>): New.
* config/gcn/gcn.cc (GEN_VN): Add andvNsi3, subvNsi3.
(GEN_VNM): Add gathervNm_expr.
(GEN_VN_NOEXEC): Add vec_seriesvNsi.
(gcn_expand_vector_init): Add initialization of vectors from smaller
vectors.

21 months agoamdgcn: Add vec_extract for partial vectors
Andrew Stubbs [Mon, 29 Jun 2020 14:20:09 +0000 (15:20 +0100)]
amdgcn: Add vec_extract for partial vectors

Add vec_extract expanders for all valid pairs of vector types.

gcc/ChangeLog:

* config/gcn/gcn-protos.h (get_exec): Add prototypes for two variants.
* config/gcn/gcn-valu.md
(vec_extract<V_ALL:mode><V_ALL_ALT:mode>): New define_expand.
* config/gcn/gcn.cc (get_exec): Export the existing function. Add a
new overload variant.

21 months agoamdgcn: Resolve insn conditions at compile time
Andrew Stubbs [Thu, 26 Mar 2020 21:22:45 +0000 (21:22 +0000)]
amdgcn: Resolve insn conditions at compile time

GET_MODE_NUNITS isn't a compile time constant, so we end up with many
impossible insns in the machine description.  Adding MODE_VF allows the insns
to be eliminated completely.

gcc/ChangeLog:

* config/gcn/gcn-valu.md
(<cvt_name><VCVT_MODE:mode><VCVT_FMODE:mode>2<exec>): Use MODE_VF.
(<cvt_name><VCVT_FMODE:mode><VCVT_IMODE:mode>2<exec>): Likewise.
* config/gcn/gcn.h (MODE_VF): New macro.

21 months agoamdgcn: add multiple vector sizes
Andrew Stubbs [Mon, 3 Aug 2020 20:09:36 +0000 (21:09 +0100)]
amdgcn: add multiple vector sizes

The vectors sizes are simulated using implicit masking, but they make life
easier for the autovectorizer and SLP passes.

gcc/ChangeLog:

* config/gcn/gcn-modes.def (VECTOR_MODE): Add new modes
V32QI, V32HI, V32SI, V32DI, V32TI, V32HF, V32SF, V32DF,
V16QI, V16HI, V16SI, V16DI, V16TI, V16HF, V16SF, V16DF,
V8QI, V8HI, V8SI, V8DI, V8TI, V8HF, V8SF, V8DF,
V4QI, V4HI, V4SI, V4DI, V4TI, V4HF, V4SF, V4DF,
V2QI, V2HI, V2SI, V2DI, V2TI, V2HF, V2SF, V2DF.
(ADJUST_ALIGNMENT): Likewise.
* config/gcn/gcn-protos.h (gcn_full_exec): Delete.
(gcn_full_exec_reg): Delete.
(gcn_scalar_exec): Delete.
(gcn_scalar_exec_reg): Delete.
(vgpr_1reg_mode_p): Use inner mode to identify vector registers.
(vgpr_2reg_mode_p): Likewise.
(vgpr_vector_mode_p): Use VECTOR_MODE_P.
* config/gcn/gcn-valu.md (V_QI, V_HI, V_HF, V_SI, V_SF, V_DI, V_DF,
V_QIHI, V_1REG, V_INT_1REG, V_INT_1REG_ALT, V_FP_1REG, V_2REG, V_noQI,
V_noHI, V_INT_noQI, V_INT_noHI, V_ALL, V_ALL_ALT, V_INT, V_FP):
Add additional vector modes.
(V64_SI, V64_DI, V64_ALL, V64_FP): New iterators.
(scalar_mode, SCALAR_MODE, vnsi, VnSI, vndi, VnDI, sdwa):
Add additional vector mode mappings.
(mov<mode>): Implement vector length conversions.
(ldexp<mode>3<exec>): Use VnSI.
(frexp<mode>_exp2<exec>): Likewise.
(VCVT_MODE, VCVT_FMODE, VCVT_IMODE): Add additional vector modes.
(reduc_<reduc_op>_scal_<mode>): Use V64_ALL.
(fold_left_plus_<mode>): Use V64_FP.
(*<reduc_op>_dpp_shr_<mode>): Use V64_1REG.
(*<reduc_op>_dpp_shr_<mode>): Use V64_DI.
(*plus_carry_dpp_shr_<mode>): Use V64_INT_1REG.
(*plus_carry_in_dpp_shr_<mode>): Use V64_SI.
(*plus_carry_dpp_shr_<mode>): Use V64_DI.
(mov_from_lane63_<mode>): Use V64_2REG.
* config/gcn/gcn.cc (VnMODE): New function.
(gcn_can_change_mode_class): Support multiple vector sizes.
(gcn_modes_tieable_p): Likewise.
(gcn_operand_part): Likewise.
(gcn_scalar_exec): Delete function.
(gcn_scalar_exec_reg): Delete function.
(gcn_full_exec): Delete function.
(gcn_full_exec_reg): Delete function.
(gcn_inline_fp_constant_p): Support multiple vector sizes.
(gcn_fp_constant_p): Likewise.
(A): New macro.
(GEN_VN_NOEXEC): New macro.
(GEN_VNM_NOEXEC): New macro.
(GEN_VN): New macro.
(GEN_VNM): New macro.
(GET_VN_FN): New macro.
(CODE_FOR): New macro.
(CODE_FOR_OP): New macro.
(gen_mov_with_exec): Delete function.
(gen_duplicate_load): Delete function.
(gcn_expand_vector_init): Support multiple vector sizes.
(strided_constant): Likewise.
(gcn_addr_space_legitimize_address): Likewise.
(gcn_expand_scalar_to_vector_address): Likewise.
(gcn_expand_scaled_offsets): Likewise.
(gcn_secondary_reload): Likewise.
(gcn_valid_cvt_p): Likewise.
(gcn_expand_builtin_1): Likewise.
(gcn_make_vec_perm_address): Likewise.
(gcn_vectorize_vec_perm_const): Likewise.
(gcn_vector_mode_supported_p): Likewise.
(gcn_autovectorize_vector_modes): New hook.
(gcn_related_vector_mode): Support multiple vector sizes.
(gcn_expand_dpp_shr_insn): Add FIXME comment.
(gcn_md_reorg): Support multiple vector sizes.
(print_reg): Likewise.
(print_operand): Likewise.
(TARGET_VECTORIZE_AUTOVECTORIZE_VECTOR_MODES): New hook.

21 months agovect: Teach vectorizer how to handle bitfield accesses
Andre Vieira [Tue, 11 Oct 2022 09:49:27 +0000 (10:49 +0100)]
vect: Teach vectorizer how to handle bitfield accesses

gcc/ChangeLog:

* tree-if-conv.cc (if_convertible_loop_p_1): Move ordering of loop bb's from
here...
(tree_if_conversion): ... to here.  Also call bitfield lowering when
appropriate.
(version_loop_for_if_conversion): Adapt to enable loop versioning when we only
need to lower bitfields.
(ifcvt_split_critical_edges): Relax condition of expected loop form as this is
checked earlier.
(get_bitfield_rep): New function.
(lower_bitfield): Likewise.
(bitfields_to_lower_p): Likewise.
(need_to_lower_bitfields): New global boolean.
(need_to_ifcvt): Likewise.
* tree-vect-data-refs.cc (vect_find_stmt_data_reference): Improve diagnostic
message.
* tree-vect-patterns.cc (vect_recog_temp_ssa_var): Add default value for last
parameter.
(vect_recog_bitfield_ref_pattern): New.
(vect_recog_bit_insert_pattern): New.

gcc/testsuite/ChangeLog:

* gcc.dg/vect/vect-bitfield-read-1.c: New test.
* gcc.dg/vect/vect-bitfield-read-2.c: New test.
* gcc.dg/vect/vect-bitfield-read-3.c: New test.
* gcc.dg/vect/vect-bitfield-read-4.c: New test.
* gcc.dg/vect/vect-bitfield-read-5.c: New test.
* gcc.dg/vect/vect-bitfield-read-6.c: New test.
* gcc.dg/vect/vect-bitfield-write-1.c: New test.
* gcc.dg/vect/vect-bitfield-write-2.c: New test.
* gcc.dg/vect/vect-bitfield-write-3.c: New test.
* gcc.dg/vect/vect-bitfield-write-4.c: New test.
* gcc.dg/vect/vect-bitfield-write-5.c: New test.

21 months agoAdd define_insn_and_split to support general version of "kxnor".
liuhongt [Mon, 10 Oct 2022 03:31:48 +0000 (11:31 +0800)]
Add define_insn_and_split to support general version of "kxnor".

For genereal_reg_operand, it will be splitted into xor + not.
For mask_reg_operand, it will be splitted with UNSPEC_MASK_OP just
like what we did for other logic operations.

The patch will optimize xor+not to kxnor when possible.

gcc/ChangeLog:

PR target/107093
* config/i386/i386.md (*notxor<mode>_1): New post_reload
define_insn_and_split.
(*notxorqi_1): Ditto.

gcc/testsuite/ChangeLog:

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

21 months ago[PR107195] Set range to zero when nonzero mask is 0.
Aldy Hernandez [Mon, 10 Oct 2022 18:42:10 +0000 (20:42 +0200)]
[PR107195] Set range to zero when nonzero mask is 0.

When solving 0 = _15 & 1, we calculate _15 as:

[irange] int [-INF, -2][0, +INF] NONZERO 0xfffffffe

The known value of _15 is [0, 1] NONZERO 0x1 which is intersected with
the above, yielding:

[0, 1] NONZERO 0x0

This eventually gets copied to a _Bool [0, 1] NONZERO 0x0.

This is problematic because here we have a bool which is zero, but
returns false for irange::zero_p, since the latter does not look at
nonzero bits.  This causes logical_combine to assume the range is
not-zero, and all hell breaks loose.

I think we should just normalize a nonzero mask of 0 to [0, 0] at
creation, thus avoiding all this.

PR tree-optimization/107195

gcc/ChangeLog:

* value-range.cc (irange::set_range_from_nonzero_bits): Set range
to [0,0] when nonzero mask is 0.

gcc/testsuite/ChangeLog:

* gcc.dg/tree-ssa/pr107195-1.c: New test.
* gcc.dg/tree-ssa/pr107195-2.c: New test.

21 months agoGeneric configury support for shared libs on VxWorks
Olivier Hainque [Fri, 3 Dec 2021 17:50:56 +0000 (17:50 +0000)]
Generic configury support for shared libs on VxWorks

This change adds the configury bits to activate the build of
shared libs on VxWorks ports configured with --enable-shared,
for libraries variants where this is generally supported (rtp,
code model !large - currently not compatible with -fPIC).

Set lt_cv_deplibs_check_method in libtool.m4, so the build of
libraries know how to establish dependencies.  This is useful in
configurations such as aarch64 where proper support of LSE relies
on accurate dependency information between libstdc++ and libgcc_s
to begin with.

Regenerate configure scripts to reflect libtool.m4 change.

2022-10-09  Olivier Hainque  <hainque@adacore.com>

* libtool.m4 (*vxworks*): When enable_shared, set dynamic_linker
and friends for rtp !large. Assume the linker has the required
abilities and set lt_cv_deplibs_check_method.

gcc/
* config.gcc (*vxworks*): Add t-slibgcc fragment
if enable_shared.

libgcc/
* config.host (*vxworks*): When enable_shared, add
libgcc and crtstuff "shared" fragments for rtp except
large code model.
(aarch64*-wrs-vxworks7*): Remove t-slibgcc-libgcc from
the list of fragments.

2022-10-09  Olivier Hainque  <hainque@adacore.com>

gcc/
* configure: Regenerate.

libatomic/
* configure: Regenerate.

libbacktrace/
* configure: Regenerate.

libcc1/
* configure: Regenerate.

libffi/
* configure: Regenerate.

libgfortran/
* configure: Regenerate.

libgomp/
* configure: Regenerate.

libitm/
* configure: Regenerate.

libobjc/
* configure: Regenerate.

liboffloadmic/
* configure: Regenerate.

liboffloadmic/
* plugin/configure: Regenerate.

libphobos/
* configure: Regenerate.

libquadmath/
* configure: Regenerate.

libsanitizer/
* configure: Regenerate.

libssp/
* configure: Regenerate.

libstdc++-v3/
* configure: Regenerate.

libvtv/
* configure: Regenerate.

lto-plugin/
* configure: Regenerate.

zlib/
* configure: Regenerate.

21 months agoTigthen the addition of -lgcc_eh to vxworks_libgcc_spec
Olivier Hainque [Fri, 18 Feb 2022 22:44:53 +0000 (22:44 +0000)]
Tigthen the addition of -lgcc_eh to vxworks_libgcc_spec

This change refines VXWORKS_LIBGCC_SPEC wrt the inclusion
of -lgcc_eh.

Unless the compiler features support for dual sjlj and
table based eh, libgcc_eh.a is available only with multilib
variants for which we build a shared lib (mrtp on VxWorks).

Rework logic to handle absence of libgcc_s
for -mrtp -mcmodel=large, using a conditional expr kind of
spec.

The gthread support in libgcc_eh might resort to libgcc
functions on some targets, e.g. cas synchronisation routines
on aarch64. Arrange to append -lgcc also after -lgcc_eh
in VXWORKS_LIBGCC_SPEC.

2022-10-09  Olivier Hainque  <hainque@adacore.com>

gcc/
* config/vxworks.h (VX_LGCC_EH_SO0, VX_LGCC_EH_SO1): New
internal macros.
(VXWORKS_LIBGCC_SPEC): Use them and document.

21 months agoranger: add override keyword
Martin Liska [Tue, 11 Oct 2022 06:52:28 +0000 (08:52 +0200)]
ranger: add override keyword

Fixes the following clang warning:
gcc/gimple-range-op.cc:310:16: warning: 'fold_range' overrides a member function but is not marked 'override' [-Winconsistent-missing-override]

gcc/ChangeLog:

* gimple-range-op.cc: Add override keyword.

21 months agoFix PR107193.
Eugene Rozenfeld [Mon, 10 Oct 2022 21:10:31 +0000 (14:10 -0700)]
Fix PR107193.

The bug was introduced in f30e9fd33e56a5a721346ea6140722e1b193db42.
A variable (cur_locus_e) was incorrectly declared inside a loop.
I also moved two other declarations (last and locus) down to make
the code more clear.

Tested on x86_64-pc-linux-gnu.

gcc/ChangeLog:
PR debug/107193
* tree-cfg.cc (assign_discriminators): Move declaration of cur_locus_e
out of the loop.

21 months agoOptimize nested permutation to single VEC_PERM_EXPR [PR54346]
Liwei Xu [Fri, 23 Sep 2022 05:46:02 +0000 (13:46 +0800)]
Optimize nested permutation to single VEC_PERM_EXPR [PR54346]

        This patch implemented the optimization in PR 54346, which Merges

c = VEC_PERM_EXPR <a, b, VCST0>;
        d = VEC_PERM_EXPR <c, c, VCST1>;
                to
        d = VEC_PERM_EXPR <a, b, NEW_VCST>;

Bootstrapped and regtested on x86_64-pc-linux-gnu{-m32,}
        tree-ssa/forwprop-19.c fail to pass but I'm not sure whether it
        is ok to removed it.

gcc/ChangeLog:

PR tree-optimization/54346
* match.pd: Merge the index of VCST then generates the new vec_perm.

gcc/testsuite/ChangeLog:

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

Co-authored-by: liuhongt <hongtao.liu@intel.com>
21 months ago[PR rtl-optimization/107182] Clear EDGE_CROSSING for jump->ret optimization
Jeff Law [Tue, 11 Oct 2022 04:44:26 +0000 (00:44 -0400)]
[PR rtl-optimization/107182] Clear EDGE_CROSSING for jump->ret optimization

When turning a jump to a return into a return, we need to clear EDGE_CROSSING
of the fallthru edge to prevent a checking failure.

I considered not applying the transformation when the edge has EDGE_CROSSING
set, but it still seems like we ought to eliminate the unnecessary jump in
that case.

gcc/
PR rtl-optimization/107182
* cfgrtl.cc (fixup_reorder_chain): When optimizing a jump to a
return, clear EDGE_CROSSING on the appropriate edge.