]> git.ipfire.org Git - thirdparty/gcc.git/log
thirdparty/gcc.git
2 years agomiddle-end/61747 - conditional move expansion and constants
Richard Biener [Tue, 18 Jul 2023 11:19:11 +0000 (13:19 +0200)] 
middle-end/61747 - conditional move expansion and constants

When expanding a COND_EXPR or a VEC_COND_EXPR the x86 backend for
example tries to match FP min/max instructions.  But this only
works when it can see the equality of the comparison and selected
operands.  This breaks in both prepare_cmp_insn and vector_compare_rtx
where the former forces expensive constants to a register and the
latter performs legitimization.  The patch below fixes this in
the caller preserving former equalities.

PR middle-end/61747
* internal-fn.cc (expand_vec_cond_optab_fn): When the
value operands are equal to the original comparison operands
preserve that equality by re-using the comparison expansion.
* optabs.cc (emit_conditional_move): When the value operands
are equal to the comparison operands and would be forced to
a register by prepare_cmp_insn do so earlier, preserving the
equality.

* g++.target/i386/pr61747.C: New testcase.

2 years agoRISC-V: Align the pattern format in vector.md
Pan Li [Thu, 20 Jul 2023 06:29:47 +0000 (14:29 +0800)] 
RISC-V: Align the pattern format in vector.md

There are some format-unaligned pattern in vector.md, this patch
would like to align the format for these patterns.

Signed-off-by: Pan Li <pan2.li@intel.com>
gcc/ChangeLog:

* config/riscv/vector.md: Align pattern format.

2 years agotestsuite: Fix C++ UDL tests failing on 32-bit arch [PR103902]
Lewis Hyatt [Thu, 20 Jul 2023 02:07:54 +0000 (22:07 -0400)] 
testsuite: Fix C++ UDL tests failing on 32-bit arch [PR103902]

These tests need to use "size_t" rather than "unsigned long"
for the user-defined literal function arguments.

gcc/testsuite/ChangeLog:

PR preprocessor/103902
* g++.dg/cpp0x/udlit-extended-id-1.C: Change "unsigned long" to
"size_t" throughout.
* g++.dg/cpp0x/udlit-extended-id-3.C: Likewise.

2 years agoCorrect Granite Rapids{, D} documentation
Haochen Jiang [Thu, 20 Jul 2023 02:47:18 +0000 (10:47 +0800)] 
Correct Granite Rapids{, D} documentation

gcc/Changelog:

* doc/invoke.texi: Remove AVX512VP2INTERSECT in
Granite Rapids{, D} from documentation.

2 years agoRISC-V: Refactor RVV machine modes
Juzhe-Zhong [Wed, 19 Jul 2023 23:21:20 +0000 (07:21 +0800)] 
RISC-V: Refactor RVV machine modes

Current machine modes layout is hard to maintain && read && understand.

For a LMUL = 1 SI vector mode:
  1. VNx1SI mode when TARGET_MIN_VLEN = 32.
  2. VNx2SI mode when TARGET_MIN_VLEN = 64.
  3. VNx4SI mode when TARGET_MIN_VLEN = 128.

Such implementation produces redundant machine modes and thus redudant machine description patterns.

Now, this patch refactor machine modes into 3 follow formats:

  1. mask mode: RVVMF64BImode, RVVMF32BImode, ...., RVVM1BImode.
                RVVMF64BImode means such mask mode occupy 1/64 of a RVV M1 reg.
                RVVM1BImode size = LMUL = 1 reg.
  2. non-tuple vector modes:
                RVV<LMUL><BASE_MODE>: E.g. RVVMF8QImode = SEW = 8 && LMUL = MF8
  3. tuple vector modes:
                RVV<LMUL>x<NF><BASE_MODE>.

For example, for SEW = 16, LMUL = MF2 , int mode is always RVVMF4HImode, then adjust its size according to TARGET_MIN_VLEN.

Before this patch,  the machine description patterns: 17551
After this patch, the machine description patterns: 14132 =====> reduce 3K+ patterns.

Regression of gcc/g++ rv32/rv64 all passed.

Ok for trunk?

gcc/ChangeLog:

* config/riscv/autovec.md
(len_mask_gather_load<VNX16_QHSD:mode><VNX16_QHSDI:mode>):
Refactor RVV machine modes.
(len_mask_gather_load<VNX16_QHS:mode><VNX16_QHSI:mode>): Ditto.
(len_mask_gather_load<VNX32_QHS:mode><VNX32_QHSI:mode>): Ditto.
(len_mask_gather_load<VNX32_QH:mode><VNX32_QHI:mode>): Ditto.
(len_mask_gather_load<VNX64_QH:mode><VNX64_QHI:mode>): Ditto.
(len_mask_gather_load<mode><mode>): Ditto.
(len_mask_gather_load<VNX64_Q:mode><VNX64_Q:mode>): Ditto.
(len_mask_scatter_store<VNX16_QHSD:mode><VNX16_QHSDI:mode>): Ditto.
(len_mask_scatter_store<VNX32_QHS:mode><VNX32_QHSI:mode>): Ditto.
(len_mask_scatter_store<VNX16_QHS:mode><VNX16_QHSI:mode>): Ditto.
(len_mask_scatter_store<VNX64_QH:mode><VNX64_QHI:mode>): Ditto.
(len_mask_scatter_store<VNX32_QH:mode><VNX32_QHI:mode>): Ditto.
(len_mask_scatter_store<mode><mode>): Ditto.
(len_mask_scatter_store<VNX64_Q:mode><VNX64_Q:mode>): Ditto.
* config/riscv/riscv-modes.def (VECTOR_BOOL_MODE): Ditto.
(ADJUST_NUNITS): Ditto.
(ADJUST_ALIGNMENT): Ditto.
(ADJUST_BYTESIZE): Ditto.
(ADJUST_PRECISION): Ditto.
(RVV_MODES): Ditto.
(RVV_WHOLE_MODES): Ditto.
(RVV_FRACT_MODE): Ditto.
(RVV_NF8_MODES): Ditto.
(RVV_NF4_MODES): Ditto.
(VECTOR_MODES_WITH_PREFIX): Ditto.
(VECTOR_MODE_WITH_PREFIX): Ditto.
(RVV_TUPLE_MODES): Ditto.
(RVV_NF2_MODES): Ditto.
(RVV_TUPLE_PARTIAL_MODES): Ditto.
* config/riscv/riscv-v.cc (struct mode_vtype_group): Ditto.
(ENTRY): Ditto.
(TUPLE_ENTRY): Ditto.
(get_vlmul): Ditto.
(get_nf): Ditto.
(get_ratio): Ditto.
(preferred_simd_mode): Ditto.
(autovectorize_vector_modes): Ditto.
* config/riscv/riscv-vector-builtins.cc (DEF_RVV_TYPE): Ditto.
* config/riscv/riscv-vector-builtins.def (DEF_RVV_TYPE): Ditto.
(vbool64_t): Ditto.
(vbool32_t): Ditto.
(vbool16_t): Ditto.
(vbool8_t): Ditto.
(vbool4_t): Ditto.
(vbool2_t): Ditto.
(vbool1_t): Ditto.
(vint8mf8_t): Ditto.
(vuint8mf8_t): Ditto.
(vint8mf4_t): Ditto.
(vuint8mf4_t): Ditto.
(vint8mf2_t): Ditto.
(vuint8mf2_t): Ditto.
(vint8m1_t): Ditto.
(vuint8m1_t): Ditto.
(vint8m2_t): Ditto.
(vuint8m2_t): Ditto.
(vint8m4_t): Ditto.
(vuint8m4_t): Ditto.
(vint8m8_t): Ditto.
(vuint8m8_t): Ditto.
(vint16mf4_t): Ditto.
(vuint16mf4_t): Ditto.
(vint16mf2_t): Ditto.
(vuint16mf2_t): Ditto.
(vint16m1_t): Ditto.
(vuint16m1_t): Ditto.
(vint16m2_t): Ditto.
(vuint16m2_t): Ditto.
(vint16m4_t): Ditto.
(vuint16m4_t): Ditto.
(vint16m8_t): Ditto.
(vuint16m8_t): Ditto.
(vint32mf2_t): Ditto.
(vuint32mf2_t): Ditto.
(vint32m1_t): Ditto.
(vuint32m1_t): Ditto.
(vint32m2_t): Ditto.
(vuint32m2_t): Ditto.
(vint32m4_t): Ditto.
(vuint32m4_t): Ditto.
(vint32m8_t): Ditto.
(vuint32m8_t): Ditto.
(vint64m1_t): Ditto.
(vuint64m1_t): Ditto.
(vint64m2_t): Ditto.
(vuint64m2_t): Ditto.
(vint64m4_t): Ditto.
(vuint64m4_t): Ditto.
(vint64m8_t): Ditto.
(vuint64m8_t): Ditto.
(vfloat16mf4_t): Ditto.
(vfloat16mf2_t): Ditto.
(vfloat16m1_t): Ditto.
(vfloat16m2_t): Ditto.
(vfloat16m4_t): Ditto.
(vfloat16m8_t): Ditto.
(vfloat32mf2_t): Ditto.
(vfloat32m1_t): Ditto.
(vfloat32m2_t): Ditto.
(vfloat32m4_t): Ditto.
(vfloat32m8_t): Ditto.
(vfloat64m1_t): Ditto.
(vfloat64m2_t): Ditto.
(vfloat64m4_t): Ditto.
(vfloat64m8_t): Ditto.
* config/riscv/riscv-vector-switch.def (ENTRY): Ditto.
(TUPLE_ENTRY): Ditto.
* config/riscv/riscv-vsetvl.cc (change_insn): Ditto.
* config/riscv/riscv.cc (riscv_valid_lo_sum_p): Ditto.
(riscv_v_adjust_nunits): Ditto.
(riscv_v_adjust_bytesize): Ditto.
(riscv_v_adjust_precision): Ditto.
(riscv_convert_vector_bits): Ditto.
* config/riscv/riscv.h (riscv_v_adjust_nunits): Ditto.
* config/riscv/riscv.md: Ditto.
* config/riscv/vector-iterators.md: Ditto.
* config/riscv/vector.md
(@pred_indexed_<order>store<VNX16_QHSD:mode><VNX16_QHSDI:mode>): Ditto.
(@pred_indexed_<order>store<VNX16_QHS:mode><VNX16_QHSI:mode>): Ditto.
(@pred_indexed_<order>store<VNX32_QHS:mode><VNX32_QHSI:mode>): Ditto.
(@pred_indexed_<order>store<VNX32_QH:mode><VNX32_QHI:mode>): Ditto.
(@pred_indexed_<order>store<VNX64_QH:mode><VNX64_QHI:mode>): Ditto.
(@pred_indexed_<order>store<VNX64_Q:mode><VNX64_Q:mode>): Ditto.
(@pred_indexed_<order>store<VNX128_Q:mode><VNX128_Q:mode>): Ditto.
(@pred_indexed_<order>load<V1T:mode><V1I:mode>): Ditto.
(@pred_indexed_<order>load<V1T:mode><VNX1_QHSDI:mode>): Ditto.
(@pred_indexed_<order>load<V2T:mode><V2I:mode>): Ditto.
(@pred_indexed_<order>load<V2T:mode><VNX2_QHSDI:mode>): Ditto.
(@pred_indexed_<order>load<V4T:mode><V4I:mode>): Ditto.
(@pred_indexed_<order>load<V4T:mode><VNX4_QHSDI:mode>): Ditto.
(@pred_indexed_<order>load<V8T:mode><V8I:mode>): Ditto.
(@pred_indexed_<order>load<V8T:mode><VNX8_QHSDI:mode>): Ditto.
(@pred_indexed_<order>load<V16T:mode><V16I:mode>): Ditto.
(@pred_indexed_<order>load<V16T:mode><VNX16_QHSI:mode>): Ditto.
(@pred_indexed_<order>load<V32T:mode><V32I:mode>): Ditto.
(@pred_indexed_<order>load<V32T:mode><VNX32_QHI:mode>): Ditto.
(@pred_indexed_<order>load<V64T:mode><V64I:mode>): Ditto.
(@pred_indexed_<order>store<V1T:mode><V1I:mode>): Ditto.
(@pred_indexed_<order>store<V1T:mode><VNX1_QHSDI:mode>): Ditto.
(@pred_indexed_<order>store<V2T:mode><V2I:mode>): Ditto.
(@pred_indexed_<order>store<V2T:mode><VNX2_QHSDI:mode>): Ditto.
(@pred_indexed_<order>store<V4T:mode><V4I:mode>): Ditto.
(@pred_indexed_<order>store<V4T:mode><VNX4_QHSDI:mode>): Ditto.
(@pred_indexed_<order>store<V8T:mode><V8I:mode>): Ditto.
(@pred_indexed_<order>store<V8T:mode><VNX8_QHSDI:mode>): Ditto.
(@pred_indexed_<order>store<V16T:mode><V16I:mode>): Ditto.
(@pred_indexed_<order>store<V16T:mode><VNX16_QHSI:mode>): Ditto.
(@pred_indexed_<order>store<V32T:mode><V32I:mode>): Ditto.
(@pred_indexed_<order>store<V32T:mode><VNX32_QHI:mode>): Ditto.
(@pred_indexed_<order>store<V64T:mode><V64I:mode>): Ditto.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/autovec/gather-scatter/gather_load_run-7.c:
Adapt test.
* gcc.target/riscv/rvv/autovec/gather-scatter/gather_load_run-8.c:
Ditto.
* gcc.target/riscv/rvv/autovec/gather-scatter/mask_scatter_store-9.c:
Ditto.
* gcc.target/riscv/rvv/autovec/gather-scatter/mask_scatter_store_run-8.c
: Ditto.
* gcc.target/riscv/rvv/autovec/gather-scatter/scatter_store_run-8.c:
Ditto.

2 years agoDaily bump.
GCC Administrator [Thu, 20 Jul 2023 00:17:53 +0000 (00:17 +0000)] 
Daily bump.

2 years agolibstdc++: Do not define inaccurate from_chars for _Float128 [PR110077]
Jonathan Wakely [Wed, 19 Jul 2023 20:15:17 +0000 (21:15 +0100)] 
libstdc++: Do not define inaccurate from_chars for _Float128 [PR110077]

I think r14-1431-g7037e7b6e4ac41 was wrong to try to define the
_Float128 overload unconditionally. Not all targets need it, so defining
the lossy fallback using long double is not useful (and caused an ABI
change on Solaris x86).

Making the definition depend on USE_STRTOF128_FOR_FROM_CHARS again
partially reverts the change for PR 109921, however that should still be
fixed because the changes to make USE_STRTOF128_FOR_FROM_CHARS depend on
USE_STRTOD_FOR_FROM_CHARS are not reverted.

libstdc++-v3/ChangeLog:

PR libstdc++/110077
* src/c++17/floating_from_chars.cc (from_chars): Only define
_Float128 overload when using __strfromf128.

2 years agolibstdc++: Check for std::ratio in arithmetic and comparisons [PR110593]
Jonathan Wakely [Wed, 19 Jul 2023 17:18:46 +0000 (18:18 +0100)] 
libstdc++: Check for std::ratio in arithmetic and comparisons [PR110593]

The standard says that it should be ill-formed to use std::ratio_equal
etc. with types which are not specializations of std::ratio. This
implements that requirement.

We don't need to add assertions to every one of the class templates,
because many of them are implemented in terms of other ones. For
example, ratio_divide and ratio_subtract can rely on the assertions in
ratio_multiply and ratio_add respectively.

libstdc++-v3/ChangeLog:

PR libstdc++/110593
* include/bits/chrono.h (duration): Improve static assert
messages.
(__is_ratio): Move to ...
* include/std/ratio (__is_ratio): ... here.
(__is_ratio_v): New variable template and partial
specialization.
(__are_both_ratios): New function template.
(__ratio_multiply, ratio_equal, ratio_less, __ratio_add):
Add static assertion.
* testsuite/20_util/ratio/requirements/type_constraints.cc:
New test.
* testsuite/20_util/duration/requirements/typedefs_neg1.cc:
Adjust expected error.
* testsuite/20_util/duration/requirements/typedefs_neg2.cc:
Likewise.

2 years agoc++: Improve printing of base classes [PR110745]
Marek Polacek [Wed, 19 Jul 2023 20:50:00 +0000 (16:50 -0400)] 
c++: Improve printing of base classes [PR110745]

This patch changes

  warning: missing initializer for member 'D::<anonymous>' [-Wmissing-field-initializers]

to

  warning: missing initializer for member 'D::B' [-Wmissing-field-initializers]

PR c++/110745

gcc/cp/ChangeLog:

* error.cc (dump_simple_decl): Print base class name.

gcc/testsuite/ChangeLog:

* g++.dg/diagnostic/base.C: New test.

2 years agoanalyzer: fix ICE on division of tainted floating-point values [PR110700]
David Malcolm [Wed, 19 Jul 2023 21:55:09 +0000 (17:55 -0400)] 
analyzer: fix ICE on division of tainted floating-point values [PR110700]

gcc/analyzer/ChangeLog:
PR analyzer/110700
* region-model-manager.cc
(region_model_manager::get_or_create_int_cst): Assert that we have
an integral or pointer type.
* sm-taint.cc (taint_state_machine::check_for_tainted_divisor):
Don't check non-integral types.

gcc/testsuite/ChangeLog:
PR analyzer/110700
* gcc.dg/analyzer/taint-divisor-2.c: New test.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2 years agoc++: -Wmissing-field-initializers and empty class [PR110064]
Marek Polacek [Wed, 19 Jul 2023 17:31:52 +0000 (13:31 -0400)] 
c++: -Wmissing-field-initializers and empty class [PR110064]

Let's suppress -Wmissing-field-initializers for empty classes.

Here I don't think I need the usual COMPLETE_TYPE_P/dependent_type_p
checks.

PR c++/110064

gcc/cp/ChangeLog:

* typeck2.cc (process_init_constructor_record): Don't emit
-Wmissing-field-initializers for empty classes.

gcc/testsuite/ChangeLog:

* g++.dg/warn/Wmissing-field-initializers-3.C: New test.

2 years agoc++: deducing empty type vs non-type argument pack
Patrick Palka [Wed, 19 Jul 2023 20:11:38 +0000 (16:11 -0400)] 
c++: deducing empty type vs non-type argument pack

Within a template parameter list, a non-type template parameter pack is
represented as a PARM_DECL.  But in a couple of spots where we need to
deduce and create an empty argument pack, we test for TEMPLATE_PARM_INDEX
(within a template parameter list) instead of for PARM_DECL, and so we
end up creating a TYPE_ARGUMENT_PACK even in the non-type case.  This
patch fixes this (seemingly harmless) bug.

gcc/cp/ChangeLog:

* pt.cc (type_unification_real): Test for PARM_DECL instead
of TEMPLATE_PARM_INDEX to distinguish a type vs non-type
template parameter pack.
(type_targs_deducible_from): Likewise.

2 years agoc++: redundant targ coercion for var/alias tmpls
Patrick Palka [Wed, 19 Jul 2023 20:10:20 +0000 (16:10 -0400)] 
c++: redundant targ coercion for var/alias tmpls

When stepping through the variable/alias template specialization code
paths, I noticed we perform template argument coercion twice: first from
lookup_template_variable / instantiate_alias_template and again from
tsubst_decl (during instantiate_template).  It'd be nice to avoid this
redundant second coercion.

It turns out this coercion in tsubst_decl could be safely elided whenever
fully specializing a primary variable/alias template, because we can rely
on lookup_template_variable / instantiate_alias_template to already have
coerced the arguments.

The only other situation to consider seems to be when fully specializing
a partial variable template specialization (from instantiate_template),
in which case the passed 'args' are the (already coerced) arguments
relative to the partial template, and the resulting 'argvec' are the
(uncoerced) arguments relative to the primary template, so coercion is
still necessary.  But computing 'argvec' here is only really necessary
in order to look up (and insert into) the specializations table.  And
instantiate_template already performs a lookup, so if we just made it
register the resulting specialization too then we could avoid having to
compute 'argvec' when called from instantiate_template, which in turns
means we could avoid the coercion altogether.  This patch implements
this approach.

gcc/cp/ChangeLog:

* pt.cc (tsubst_function_decl): Add defaulted 'use_spec_table'
flag parameter.  Don't look up or insert into the specializations
table if 'use_spec_table' is false.
(tsubst_decl): Add defaulted 'use_spec_table' flag parameter.
Check for error_mark_node.
<case FUNCTION_DECL>: Pass 'use_spec_table' to
tsubst_function_decl.
<case TYPE/VAR_DECL>: Don't call coerce_template_parms.
Don't look up or insert into the specializations table if
'use_spec_table' is false.  Exit earlier if the substituted
type is erroneous and we're not complaining, and do so for
alias specializations as well.
(instantiate_template): Pass false as 'use_spec_table'
to tsubst_decl.  Call register_specialization afterwards.

2 years agoPR modula2/110284 Make-lang-in m2flex.o and m2pp.o
Gaius Mulley [Wed, 19 Jul 2023 20:01:53 +0000 (21:01 +0100)] 
PR modula2/110284 Make-lang-in m2flex.o and m2pp.o

This patch moves the rule c-family/m2pp.o from Make-lang.in into
Make-maintainer.in.  It also adds m2/gm2-gcc/rtegraph.o and
m2/gm2-compiler-boot/m2flex.o to m2_OBJS.  The object
m2/gm2-compiler-boot/m2flex.o is needed by cc1gm2 whereas
m2/gm2-compiler/m2flex.o is required by m2/stage2/cc1gm2
(which is only built in maintainer to allow debugging via m2
sources rather than the translated to C++ sources).

PR modula2/110284
* Make-lang.in (m2_OBJS): Add m2/gm2-gcc/rtegraph.o and
m2/gm2-compiler-boot/m2flex.o.
(c-family/m2pp.o): Remove.
* Make-maintainer.in (c-family/m2pp.o): Add.

Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>
2 years ago[LRA]: Check and update frame to stack pointer elimination after stack slot allocation
Vladimir N. Makarov [Wed, 19 Jul 2023 13:35:37 +0000 (09:35 -0400)] 
[LRA]: Check and update frame to stack pointer elimination after stack slot allocation

Avr is an interesting target which does not use stack pointer to
address stack slots.  The elimination of stack pointer to frame pointer
is impossible if there are stack slots.  During LRA works, the
stack slots can be allocated and used and the elimination can be done
anymore.  The situation can be complicated even more if some pseudos
were allocated to the frame pointer.

gcc/ChangeLog:

* lra-int.h (lra_update_fp2sp_elimination): New prototype.
(lra_asm_insn_error): New prototype.
* lra-spills.cc (remove_pseudos): Add check for pseudo slot memory
existence.
(lra_spill): Call lra_update_fp2sp_elimination.
* lra-eliminations.cc: Remove trailing spaces.
(elimination_fp2sp_occured_p): New static flag.
(lra_eliminate_regs_1): Set the flag up.
(update_reg_eliminate): Modify the assert for stack to frame
pointer elimination.
(lra_update_fp2sp_elimination): New function.
(lra_eliminate): Clear flag elimination_fp2sp_occured_p.

gcc/testsuite/ChangeLog:

* gcc.target/avr/lra-elim.c: New test.

2 years ago[modula2] Location improvement and bugfix when issuing parameter errors
Gaius Mulley [Wed, 19 Jul 2023 16:46:52 +0000 (17:46 +0100)] 
[modula2] Location improvement and bugfix when issuing parameter errors

This patch improves the accuracy of error messages mentioning a
parameter in M2Quads.mod (when handling builtins).  The error location
now points to the parameter rather than the function or procedure.

gcc/m2/ChangeLog:

* gm2-compiler/M2Quads.mod (BuildDifAdrFunction): Removed
unnecessary in error message.  Use vartok for location.
(BuildOddFunction): Use optok for location.
(BuildAbsFunction): Use vartok for location.  Bugfix set vartok.
(BuildCapFunction): Use optok for location.
(BuildOrdFunction): Use optok for location and correct format
specifier.
(BuildShiftFunction): Use vartok for location.
(BuildRotateFunction): Use vartok for location.
(BuildTruncFunction): Use vartok for location.
(BuildFloatFunction): Use vartok for location.
(BuildReFunction): Use vartok for location.
(BuildImFunction): Use vartok for location.
* gm2-compiler/M2SymInit.mod (trashParam): Remove commented code.

gcc/testsuite/ChangeLog:

* gm2/errors/fail/badabs.mod: New test.
* gm2/errors/fail/badenum.mod: New test.

Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>
2 years agoaarch64: Remove architecture dependencies from intrinsics
Andrew Carlotti [Tue, 7 Mar 2023 14:37:00 +0000 (14:37 +0000)] 
aarch64: Remove architecture dependencies from intrinsics

Many intrinsics currently depend on both an architecture version and a
feature, despite the corresponding instructions being available within
GCC at lower architecture versions.

LLVM has already removed these explicit architecture version
dependences; this patch does the same for GCC. Note that +fp16 does not
imply +simd, so we need to add an explicit +simd for the Neon fp16
intrinsics.

Binutils did not previously support all of these architecture+feature
combinations, but this problem is already reachable from GCC.  For
example, compiling the test gcc.target/aarch64/usadv16qi-dotprod.c
with -O3 -march=armv8-a+dotprod has resulted in an assembler error since
GCC 10.  This is fixed in Binutils 2.41.

This patch retains explicit architecture version dependencies for
features that do not currently have a separate feature flag.

gcc/ChangeLog:

* config/aarch64/aarch64.h (TARGET_MEMTAG): Remove armv8.5
dependency.
* config/aarch64/arm_acle.h: Remove unnecessary armv8.x
dependencies from target pragmas.
* config/aarch64/arm_fp16.h (target): Likewise.
* config/aarch64/arm_neon.h (target): Likewise.

gcc/testsuite/ChangeLog:

* gcc.target/aarch64/feature-bf16-backport.c: New test.
* gcc.target/aarch64/feature-dotprod-backport.c: New test.
* gcc.target/aarch64/feature-fp16-backport.c: New test.
* gcc.target/aarch64/feature-fp16-scalar-backport.c: New test.
* gcc.target/aarch64/feature-fp16fml-backport.c: New test.
* gcc.target/aarch64/feature-i8mm-backport.c: New test.
* gcc.target/aarch64/feature-memtag-backport.c: New test.
* gcc.target/aarch64/feature-sha3-backport.c: New test.
* gcc.target/aarch64/feature-sm4-backport.c: New test.

2 years ago[PATCH] Fix tree-opt/110252: wrong code due to phiopt using flow sensitive info durin...
Andrew Pinski [Fri, 14 Jul 2023 22:55:34 +0000 (15:55 -0700)] 
[PATCH] Fix tree-opt/110252: wrong code due to phiopt using flow sensitive info during match

Match will query ranger via tree_nonzero_bits/get_nonzero_bits for 2 and 3rd
operand of the COND_EXPR and phiopt tries to do create the COND_EXPR even if we moving
one statement. That one statement could have some flow sensitive information on it
based on the condition that is for the COND_EXPR but that might create wrong code
if the statement was moved out.

This is similar to the previous version of the patch except now we use
flow_sensitive_info_storage instead of manually doing the save/restore
and also handle all defs on a gimple statement rather than just for lhs
of the gimple statement. Oh and a few more testcases were added that
was failing before.

OK? Bootsrapped and tested on x86_64-linux-gnu with no regressions.

PR tree-optimization/110252

gcc/ChangeLog:

* tree-ssa-phiopt.cc (class auto_flow_sensitive): New class.
(auto_flow_sensitive::auto_flow_sensitive): New constructor.
(auto_flow_sensitive::~auto_flow_sensitive): New deconstructor.
(match_simplify_replacement): Temporarily
remove the flow sensitive info on the two statements that might
be moved.

gcc/testsuite/ChangeLog:

* gcc.dg/tree-ssa/phi-opt-25b.c: Updated as
__builtin_parity loses the nonzerobits info.
* gcc.c-torture/execute/pr110252-1.c: New test.
* gcc.c-torture/execute/pr110252-2.c: New test.
* gcc.c-torture/execute/pr110252-3.c: New test.
* gcc.c-torture/execute/pr110252-4.c: New test.

2 years agoAdd flow_sensitive_info_storage and use it in gimple-fold.
Andrew Pinski [Fri, 14 Jul 2023 22:14:59 +0000 (15:14 -0700)] 
Add flow_sensitive_info_storage and use it in gimple-fold.

This adds flow_sensitive_info_storage and uses it in
maybe_fold_comparisons_from_match_pd as mentioned in
https://gcc.gnu.org/pipermail/gcc-patches/2023-June/621817.html .
Since using it in maybe_fold_comparisons_from_match_pd was easy
and allowed me to test the storage earlier, I did it.

This also hides better how the flow sensitive information is
stored and only a single place needs to be updated if that
ever changes (again).

OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions.

gcc/ChangeLog:

* gimple-fold.cc (fosa_unwind): Replace `vrange_storage *`
with flow_sensitive_info_storage.
(follow_outer_ssa_edges): Update how to save off the flow
sensitive info.
(maybe_fold_comparisons_from_match_pd): Update restoring
of flow sensitive info.
* tree-ssanames.cc (flow_sensitive_info_storage::save): New method.
(flow_sensitive_info_storage::restore): New method.
(flow_sensitive_info_storage::save_and_clear): New method.
(flow_sensitive_info_storage::clear_storage): New method.
* tree-ssanames.h (class flow_sensitive_info_storage): New class.

2 years agoFix PR110726: a | (a == b) can sometimes produce wrong code
Andrew Pinski [Tue, 18 Jul 2023 21:11:46 +0000 (21:11 +0000)] 
Fix PR110726: a | (a == b) can sometimes produce wrong code

So I had missed/forgot that EQ_EXPR could have an non boolean
type for generic when I implemented r14-2556-g0407ae8a7732d9.
This patch adds check for one bit precision intergal type
which fixes the problem.

OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions.

PR tree-optimization/110726

gcc/ChangeLog:

* match.pd ((a|b)&(a==b),a|(a==b),(a&b)|(a==b)):
Add checks to make sure the type was one bit precision
intergal type.

gcc/testsuite/ChangeLog:

* gcc.c-torture/execute/bitops-1.c: New test.

2 years agolibstdc++: Fix formatting of negative chrono::hh_mm_ss
Jonathan Wakely [Wed, 19 Jul 2023 13:42:51 +0000 (14:42 +0100)] 
libstdc++: Fix formatting of negative chrono::hh_mm_ss

When formatting with an empty chrono spec ("{}") two minus signs were
being added to hh_mm_ss values. This is because the __is_neg flag was
checked to add one explicitly, and then the ostream operator added
another one.

We should only check the __is_neg flag for durations, because those are
the only types which are modified to be non-negative before calling
_M_format. We don't change hh_mm_ss values to be negative, because that
would require performing arithmetic on the hh_mm_ss members to sum them,
and then again to construct a new hh_mm_ss object with the positive
value.  Instead, we can just be careful about using the __is_neg flag
correctly.

To fix the bug, _M_format_to_ostream no longer checks the __is_neg flag
for non-durations, and _M_format doesn't set it for hh_mm_ss until after
the call to _M_format_to_ostream. We can also avoid setting it for types
that it doesn't apply to, by making the __print_sign lambda only inspect
it for duration and hh_mm_ss types.

libstdc++-v3/ChangeLog:

* include/bits/chrono_io.h (__formatter_chrono::_M_format):
Do not set __is_neg for hh_mm_ss before calling
_M_format_to_ostream. Change __print_sign lambda to only check
__is_neg for durations and hh_mm_ss types.
(__formatter_chrono::_M_format_to_ostream): Only check __is_neg
for duration types.
* testsuite/std/time/hh_mm_ss/io.cc: Check negative values.

2 years agolibstdc++: Fix locale-specific duration formatting [PR110719]
Jonathan Wakely [Wed, 19 Jul 2023 13:38:08 +0000 (14:38 +0100)] 
libstdc++: Fix locale-specific duration formatting [PR110719]

The r14-2640-gf4bce119f617dc commit only removed fractional seconds for
time points, but it needs to be done for durations and hh_mm_ss types
too.

libstdc++-v3/ChangeLog:

PR libstdc++/110719
* include/bits/chrono_io.h (__formatter_chrono::_S_floor_seconds):
Handle duration and hh_mm_ss.
* testsuite/20_util/duration/io.cc: Check locale-specific
formats.
* testsuite/std/time/hh_mm_ss/io.cc: Likewise.

2 years agoVECT: Add mask_len_fold_left_plus for in-order floating-point reduction
Ju-Zhe Zhong [Fri, 14 Jul 2023 23:45:00 +0000 (07:45 +0800)] 
VECT: Add mask_len_fold_left_plus for in-order floating-point reduction

Hi, Richard and Richi.

This patch adds mask_len_fold_left_plus pattern to support in-order floating-point
reduction for target support len loop control.

Consider this following case:
double
foo2 (double *__restrict a,
     double init,
     int *__restrict cond,
     int n)
{
    for (int i = 0; i < n; i++)
      if (cond[i])
        init += a[i];
    return init;
}

ARM SVE:

...
vec_mask_and_60 = loop_mask_54 & mask__23.33_57;
vect__ifc__35.37_64 = .VCOND_MASK (vec_mask_and_60, vect__8.36_61, { 0.0, ... });
_36 = .MASK_FOLD_LEFT_PLUS (init_20, vect__ifc__35.37_64, loop_mask_54);
...

For RVV, we want to see:
...
_36 = .MASK_LEN_FOLD_LEFT_PLUS (init_20, vect__ifc__35.37_64, control_mask, loop_len, bias);
...

gcc/ChangeLog:

* doc/md.texi: Add mask_len_fold_left_plus.
* internal-fn.cc (mask_len_fold_left_direct): Ditto.
(expand_mask_len_fold_left_optab_fn): Ditto.
(direct_mask_len_fold_left_optab_supported_p): Ditto.
* internal-fn.def (MASK_LEN_FOLD_LEFT_PLUS): Ditto.
* optabs.def (OPTAB_D): Ditto.

2 years ago[modula2] Variable analysis understands DISPOSE and NIL
Gaius Mulley [Wed, 19 Jul 2023 12:38:07 +0000 (13:38 +0100)] 
[modula2] Variable analysis understands DISPOSE and NIL

This patch allows the uninitialized variable analysis to detect pointer
through NIL and incorrectly reusing a pointer after a call to DISPOSE.

gcc/m2/ChangeLog:

* gm2-compiler/M2Quads.mod (BuildRealFuncProcCall): Set the trash
parameter value to NIL if DEALLOCATE is detected.
* gm2-compiler/M2SymInit.mod (CheckDeferredRecordAccess): Pass
tok to SetVarInitialized.  Pass tok to GetVarComponentInitialized.
(ComponentFindVar): Add tok parameter.  Check aliased pointer
against Nil and generate warning if necessary.
(deRefComponent): Add tok and sym parameters and pass them to
getContent.
(SetVarComponentInitialized): Add tok parameter.  Pass tok to
ComponentFindVar.  Pass tok and sym to deRefComponent.
(GetVarComponentInitialized): Add tok parameter.  Pass tok to
ComponentFindVar.  Pass tok to deRefComponent.
(SetVarInitialized): Add tok parameter.  Pass tok to
SetVarComponentInitialized.
(doGetVarInitialized): Add tok parameter.  Pass tok to
GetVarComponentInitialized.
(CheckXIndr): Pass lhs and lhstok to getContent.
(CheckIndrX): Pass rhs and rhstok to getContent.
(CheckBecomes): Pass destok to ComponentFindVar.  Pass des and
destok to deRefComponent.
(CheckAddr): Pass contenttok to GetVarInitialized.  Pass ptrtok
to SetVarInitialized.
(CheckReadBeforeInitQuad): Pass op1tok to SetVarInitialized for
op1 cases and op3tok for op3 cases.
(trashParam): Get operand tokens.  Pass op3tok to
SetVarInitialized.  Pass op3 and op3tok to getContent.
Alias ptr to NIL if procedure is DEALLOCATE.  Pass op3tok to
SetVarInitialized.
(IsDeallocate): New procedure function.
(DetectTrash): Use IsDeallocate.
(SetupLAlias): Allow exp to be Nil.
(getContent): Generate warning message if ptr is Nil.

gcc/testsuite/ChangeLog:

* gm2/switches/uninit-variable-checking/procedures/fail/testdispose.mod: New test.
* gm2/switches/uninit-variable-checking/procedures/fail/testdispose2.mod: New test.
* gm2/switches/uninit-variable-checking/procedures/fail/testnil.mod: New test.

Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>
2 years agotree-switch-conversion: Fix a comment typo
Jakub Jelinek [Wed, 19 Jul 2023 11:51:44 +0000 (13:51 +0200)] 
tree-switch-conversion: Fix a comment typo

I've noticed a comment typo, this patch fixes that.

2023-07-19  Jakub Jelinek  <jakub@redhat.com>

* tree-switch-conversion.h (class bit_test_cluster): Fix comment typo.

2 years agowide-int: Fix up wi::divmod_internal [PR110731]
Jakub Jelinek [Wed, 19 Jul 2023 11:48:53 +0000 (13:48 +0200)] 
wide-int: Fix up wi::divmod_internal [PR110731]

As the following testcase shows, wi::divmod_internal doesn't handle
correctly signed division with precision > 64 when the dividend (and likely
divisor as well) is the type's minimum and the precision isn't divisible
by 64.

A few lines above what the patch hunk changes is:
  /* Make the divisor and dividend positive and remember what we
     did.  */
  if (sgn == SIGNED)
    {
      if (wi::neg_p (dividend))
        {
          neg_dividend = -dividend;
          dividend = neg_dividend;
          dividend_neg = true;
        }
      if (wi::neg_p (divisor))
        {
          neg_divisor = -divisor;
          divisor = neg_divisor;
          divisor_neg = true;
        }
    }
i.e. we negate negative dividend or divisor and remember those.
But, after we do that, when unpacking those values into b_dividend and
b_divisor we need to always treat the wide_ints as UNSIGNED,
because divmod_internal_2 performs an unsigned division only.
Now, if precision <= 64, we don't reach here at all, earlier code
handles it.  If dividend or divisor aren't the most negative values,
the negation clears their most significant bit, so it doesn't really
matter if we unpack SIGNED or UNSIGNED.  And if precision is multiple
of HOST_BITS_PER_WIDE_INT, there is no difference in behavior, while
-0x80000000000000000000000000000000 negates to
-0x80000000000000000000000000000000 the unpacking of it as SIGNED
or UNSIGNED works the same.
In the testcase, we have signed precision 119 and the dividend is
val = { 0, 0xffc0000000000000 }, len = 2, precision = 119
both before and after negation.
Divisor is
val = { 2 }, len = 1, precision = 119
But we really want to divide 0x400000000000000000000000000000 by 2
unsigned and then negate at the end.
If it is unsigned precision 119 division
0x400000000000000000000000000000 by 2
dividend is
val = { 0, 0xffc0000000000000 }, len = 2, precision = 119
but as we unpack it UNSIGNED, it is unpacked into
0, 0, 0, 0x00400000

The following patch fixes it by always using UNSIGNED unpacking
because we've already negated negative values at that point if
sgn == SIGNED and so most negative constants should be treated as
positive.

2023-07-19  Jakub Jelinek  <jakub@redhat.com>

PR tree-optimization/110731
* wide-int.cc (wi::divmod_internal): Always unpack dividend and
divisor as UNSIGNED regardless of sgn.

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

2 years agolibstdc++: Avoid warning in std::format
Jonathan Wakely [Tue, 18 Jul 2023 21:14:32 +0000 (22:14 +0100)] 
libstdc++: Avoid warning in std::format

With -Wmaybe-uninitialized -Wsystem-headers there's a warning about
creating a string_view from an uninitalized array. Initializing the
first element of the array avoids the warning.

libstdc++-v3/ChangeLog:

* include/std/format (__write_padded): Initialize first element
of array to avoid a -Wmaybe-uninitialized warning.

2 years agolibstdc++: Implement correct locale-specific chrono formatting [PR110719]
Jonathan Wakely [Tue, 18 Jul 2023 11:46:07 +0000 (12:46 +0100)] 
libstdc++: Implement correct locale-specific chrono formatting [PR110719]

This fixes some TODOs in the C++20 <chrono> format support, where the
locale-specific output was incorrect or unimplemented. The approach
taken here is to either use the formatting locale's std::time_put facet
to do the formatting, or to remove subsecond precision from time points
so that locale-specific formats don't print fractional seconds. This
ensures that we are consistent with what the std::time_put facet would
print (which never includes fractional seconds) even if we actually
reimplement the formatting by hand instead of using the facet.

This also fixes a misplaced statement that allowed modifiers for %Z
which should have been on %z instead. There was also some ill-formed
code in an untested branch for formatting time zone names to wide
characters. A new test for zoned_time I/O has been added to exercise
that code properly.

libstdc++-v3/ChangeLog:

PR libstdc++/110719
* include/bits/chrono_io.h (__formatter_chrono::_M_parse): Fix
allowed modifiers for %z and %Z. Fix -Wparentheses and
-Wnarrowing warnings.
(__formatter_chrono::_M_format): Call new functions for %d, %e,
%H, %I, %m and %M.
(__formatter_chrono::_M_c): Use _S_floor_seconds to remove
subsecond precision.
(__formatter_chrono::_M_C_y_Y): Use _M_locale_fmt to handle
modifiers.
(__formatter_chrono::_M_e): Replace with _M_d_e and use
_M_locale_fmt.
(__formatter_chrono::_M_I): Replace with _M_H_I and use
_M_locale_fmt.
(__formatter_chrono::_M_m): New function.
(__formatter_chrono::_M_M): New function.
(__formatter_chrono::_M_r): Use _M_locale_fmt.
(__formatter_chrono::_M_S): Likewise.
(__formatter_chrono::_M_u_w): Likewise.
(__formatter_chrono::_M_U_V_W): Likewise.
(__formatter_chrono::_M_X): Use _S_floor_seconds.
(__formatter_chrono::_M_Z): Fix untested branch for wchar_t.
(__formatter_chrono::_S_altnum): Remove function.
(__formatter_chrono::_S_dd_zero_fill): Remove function.
(__formatter_chrono::_S_floor_seconds): New function.
(__formatter_chrono::_M_locale_fmt): New function.
* testsuite/std/time/clock/system/io.cc: Adjust expected output
for locale-specific formats and check modified formats.
* testsuite/std/time/clock/utc/io.cc: Likewise.
* testsuite/std/time/zoned_time/io.cc: New test.

2 years agotestsuite: Add 64-bit vector variant for bb-slp-pr95839.c
Maciej W. Rozycki [Wed, 19 Jul 2023 10:59:29 +0000 (11:59 +0100)] 
testsuite: Add 64-bit vector variant for bb-slp-pr95839.c

Add dual-single float vector test complementing bb-slp-pr95839.c.

gcc/testsuite/
* gcc.dg/vect/bb-slp-pr95839-v8.c: New test.

2 years agolibstdc++: Check for multiple modifiers in chrono format string [PR110708]
Jonathan Wakely [Tue, 18 Jul 2023 09:36:37 +0000 (10:36 +0100)] 
libstdc++: Check for multiple modifiers in chrono format string [PR110708]

The logic for handling modified chrono specs like %Ey was just
restarting the loop after each modifier, and not checking whether we'd
already seen a modifier.

libstdc++-v3/ChangeLog:

PR libstdc++/110708
* include/bits/chrono_io.h (__formatter_chrono::_M_parse): Only
allow a single modifier.
* testsuite/std/time/format.cc: Check multiple modifiers.

2 years agolibstdc++: Enable tests for std::stoi etc. unconditionally [PR110653]
Jonathan Wakely [Sat, 15 Jul 2023 19:58:22 +0000 (20:58 +0100)] 
libstdc++: Enable tests for std::stoi etc. unconditionally [PR110653]

Since the narrow string versions of std::stoi, std::stol, std::stoul,
std::stof and std::stod are now always defined, we don't need to check
dg-require-string-conversions in the relevant tests.

libstdc++-v3/ChangeLog:

PR libstdc++/110653
* testsuite/21_strings/basic_string/numeric_conversions/char/stod.cc:
Remove dg-require-string-conversions.
* testsuite/21_strings/basic_string/numeric_conversions/char/stof.cc:
Likewise.
* testsuite/21_strings/basic_string/numeric_conversions/char/stoi.cc:
Likewise.
* testsuite/21_strings/basic_string/numeric_conversions/char/stol.cc:
Likewise.
* testsuite/21_strings/basic_string/numeric_conversions/char/stoul.cc:
Likewise.

2 years agolibstdc++: Define std::stof fallback in terms of std::stod [PR110653]
Jonathan Wakely [Sat, 15 Jul 2023 19:41:28 +0000 (20:41 +0100)] 
libstdc++: Define std::stof fallback in terms of std::stod [PR110653]

For targets without std::strtof we can define std::stof by calling
std::stod and then checking if the result is out of range of float.

libstdc++-v3/ChangeLog:

PR libstdc++/110653
* include/bits/basic_string.h [!_GLIBCXX_HAVE_STRTOF] (stof):
Define in terms of std::stod.

2 years agolibstdc++: Check autoconf macros for strtof and strtold [PR110653]
Jonathan Wakely [Thu, 13 Jul 2023 09:44:57 +0000 (10:44 +0100)] 
libstdc++: Check autoconf macros for strtof and strtold [PR110653]

As well as the _GLIBCXX_USE_C99_STDLIB check, we also have a separate
check in linkage.m4 for just strtof and strtold. We can use that to
declare std::strtof and std::strtold in <cstdlib> for additional
targets. That allows us to enable std::stold on hpux11.11 which is
missing strtoll, strtoull and strtof, so doesn't define
_GLIBCXX_USE_C99_STDLIB. Although it doesn't help hpux11.11, we can
define std::stof for more targets this way too.

As with the previous commit for PR110653, this only affects the narrow
character overloads. std::stof and std::stold for wstring still requires
C99 <wchar.h> support.

libstdc++-v3/ChangeLog:

PR libstdc++/110653
* include/bits/basic_string.h [_GLIBCXX_HAVE_STRTOF] (stof):
Define.
[_GLIBCXX_HAVE_STRTOLD] (stold): Define.
* include/c_global/cstdlib [_GLIBCXX_HAVE_STRTOF] (strtof):
Declare in namespace std.
[_GLIBCXX_HAVE_STRTOLD] (strtold): Likewise.

2 years agoOpenMP/Fortran: Non-rectangular loops with constant steps other than 1 or -1 [PR107424]
Tobias Burnus [Wed, 19 Jul 2023 08:18:49 +0000 (10:18 +0200)] 
OpenMP/Fortran: Non-rectangular loops with constant steps other than 1 or -1 [PR107424]

Before this commit, gfortran produced with OpenMP for 'do i = 1,10,2'
the code
  for (count.0 = 0; count.0 < 5; count.0 = count.0 + 1)
    i = count.0 * 2 + 1;

While such an inner loop can be collapsed, a non-rectangular could not.
With this commit and for all constant loop steps, a simple loop such
as 'for (i = 1; i <= 10; i = i + 2)' is created. (Before only for the
constant steps of 1 and -1.)

The constant step permits to know the direction (increasing/decreasing)
that is required for the loop condition.

The new code is only valid if one assumes no overflow of the loop variable.
However, the Fortran standard can be read that this must be ensured by
the user. Namely, the Fortran standard requires (F2023, 10.1.5.2.4):
"The execution of any numeric operation whose result is not defined by
the arithmetic used by the processor is prohibited."

And, for DO loops, F2023's "11.1.7.4.3 The execution cycle" has the
following: The number of loop iterations handled by an iteration count,
which would permit code like 'do i = huge(i)-5, huge(i),4'. However,
in step (3), this count is not only decremented by one but also:
  "... The DO variable, if any, is incremented by the value of the
  incrementation parameter m3."
And for the example above, 'i' would be 'huge(i)+3' in the last
execution cycle, which exceeds the largest model number and should
render the example as invalid.

PR fortran/107424

gcc/fortran/ChangeLog:

* trans-openmp.cc (gfc_nonrect_loop_expr): Accept all
constant loop steps.
(gfc_trans_omp_do): Likewise; use sign to determine
loop direction.

libgomp/ChangeLog:

* libgomp.texi (Impl. Status 5.0): Add link to new PR110735.
* testsuite/libgomp.fortran/non-rectangular-loop-1.f90: Enable
commented tests.
* testsuite/libgomp.fortran/non-rectangular-loop-1a.f90: Remove
test file; tests are in non-rectangular-loop-1.f90.
* testsuite/libgomp.fortran/non-rectangular-loop-5.f90: Change
testcase to use a non-constant step to retain the 'sorry' test.
* testsuite/libgomp.fortran/non-rectangular-loop-6.f90: New test.

gcc/testsuite/ChangeLog:

* gfortran.dg/gomp/linear-2.f90: Update dump to remove
the additional count variable.

2 years agoRISC-V: Throw compilation error for unknown extensions
Lehua Ding [Thu, 13 Jul 2023 08:32:09 +0000 (16:32 +0800)] 
RISC-V: Throw compilation error for unknown extensions

This tiny patch add a check for extension starts with 'z' or 's' in `-march`
option. Currently this unknown extension will be passed to the assembler, which
then reports an error. With this patch, the compiler will throw a compilation
error if the extension starts with 'z' or 's' is not a standard sub-extension or
supervisor extension. Along with two extra changes. The first is to reduce
repeated errors, which are currently reported at least twice. The second is to
report as many mistakes as possible.

e.g.:

Run `riscv64-unknown-elf-gcc -march=rv64gvcw_zvl128_s123_x123 -mabi=lp64d a.c`
will throw these error:

riscv64-unknown-elf-gcc: error: '-march=rv64gcv_zvl128_s123': ISA string is not in canonical order. 'c'
riscv64-unknown-elf-gcc: error: '-march=rv64gcv_zvl128_s123': extension 'w' is unsupported standard single letter extension
riscv64-unknown-elf-gcc: error: '-march=rv64gcv_zvl128_s123': extension 'zvl128' start with `z` but is unsupported standard extension
riscv64-unknown-elf-gcc: error: '-march=rv64gcv_zvl128_s123': extension 's123' start with `s` but is unsupported standard supervisor extension
riscv64-unknown-elf-gcc: error: '-march=rv64gcv_zvl128_s123': extension 'x123' start with `x` but is unsupported non-standard extension

gcc/ChangeLog:

* common/config/riscv/riscv-common.cc (riscv_supported_std_ext): Init.
(standard_extensions_p): Add check.
(riscv_subset_list::add): Just return NULL if it failed before.
(riscv_subset_list::parse_std_ext): Continue parse when find a error
(riscv_subset_list::parse): Just return NULL if it failed before.
* config/riscv/riscv-subset.h (class riscv_subset_list): Add field.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/arch-2.c: Update -march.
* gcc.target/riscv/arch-3.c: Ditto.
* gcc.target/riscv/arch-5.c: Ditto.
* gcc.target/riscv/arch-8.c: Ditto.
* gcc.target/riscv/attribute-10.c: Ditto.
* gcc.target/riscv/attribute-18.c: Ditto.
* gcc.target/riscv/attribute-19.c: Ditto.
* gcc.target/riscv/attribute-8.c: Ditto.
* gcc.target/riscv/attribute-9.c: Ditto.
* gcc.target/riscv/pr102957.c: Ditto.
* gcc.target/riscv/arch-22.cc: New test.

2 years agox86: avoid maybe_gen_...()
Jan Beulich [Wed, 19 Jul 2023 08:11:49 +0000 (10:11 +0200)] 
x86: avoid maybe_gen_...()

In the (however unlikely) event that no insn can be found for the
requested mode, using maybe_gen_...() without (really) checking its
result for being a null rtx would lead to silent bad code generation.

gcc/

* config/i386/i386-expand.cc (ix86_expand_vector_init_duplicate):
Use gen_vec_set_0.
(ix86_expand_vector_extract): Use gen_vec_extract_lo /
gen_vec_extract_hi.
(expand_vec_perm_broadcast_1): Use gen_vec_interleave_high /
gen_vec_interleave_low. Rename local variable.

2 years agox86: slightly enhance "vec_dupv2df<mask_name>"
Jan Beulich [Wed, 19 Jul 2023 08:11:11 +0000 (10:11 +0200)] 
x86: slightly enhance "vec_dupv2df<mask_name>"

Introduce a new alternative permitting all 32 registers to be used as
source without AVX512VL, by broadcasting to the full 512 bits in that
case. (The insn would also permit all registers to be used as
destination, but V2DFmode doesn't.)

gcc/

* config/i386/sse.md (vec_dupv2df<mask_name>): Add new AVX512F
alternative. Move AVX512VL part of condition to new "enabled"
attribute.

2 years agoRISC-V: Fix testcase failed when default -mcmodel=medany
Lehua Ding [Tue, 18 Jul 2023 07:34:40 +0000 (15:34 +0800)] 
RISC-V: Fix testcase failed when default -mcmodel=medany

This patch fix testcase failed when I build RISC-V GCC with -mcmodel=medany
as default. If set to medany, stack_save_restore.c testcase will fail because of
the reduced use of s3 registers in assembly (thus calling __riscv_save/store_3
instead of __riscv_save/store_4). So relax assert from
`__riscv_save/restore_4` to `__riscv_save/restore_(3|4)` to let this
testcase not brittle on any -mcmodel and add another testcase that use
-march=rv64imafc.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/stack_save_restore.c: Moved to...
* gcc.target/riscv/stack_save_restore_2.c: ...here.
* gcc.target/riscv/stack_save_restore_1.c: New test.

2 years agolibcpp: Handle extended characters in user-defined literal suffix [PR103902]
Lewis Hyatt [Tue, 18 Jul 2023 21:16:08 +0000 (17:16 -0400)] 
libcpp: Handle extended characters in user-defined literal suffix [PR103902]

The PR complains that we do not handle UTF-8 in the suffix for a user-defined
literal, such as:

bool operator ""_π (unsigned long long);

In fact we don't handle any extended identifier characters there, whether
UTF-8, UCNs, or the $ sign. We do handle it fine if the optional space after
the "" tokens is included, since then the identifier is lexed in the
"normal" way as its own token. But when it is lexed as part of the string
token, this is handled in lex_string() with a one-off loop that is not aware
of extended characters.

This patch fixes it by adding a new function scan_cur_identifier() that can
be used to lex an identifier while in the middle of lexing another token.

BTW, the other place that has been mis-lexing identifiers is
lex_identifier_intern(), which is used to implement #pragma push_macro
and #pragma pop_macro. This does not support extended characters either.
I will add that in a subsequent patch, because it can't directly reuse the
new function, but rather needs to lex from a string instead of a cpp_buffer.

With scan_cur_identifier(), we do also correctly warn about bidi and
normalization issues in the extended identifiers comprising the suffix.

libcpp/ChangeLog:

PR preprocessor/103902
* lex.cc (identifier_diagnostics_on_lex): New function refactoring
some common code.
(lex_identifier_intern): Use the new function.
(lex_identifier): Don't run identifier diagnostics here, rather let
the call site do it when needed.
(_cpp_lex_direct): Adjust the call sites of lex_identifier ()
acccordingly.
(struct scan_id_result): New struct.
(scan_cur_identifier): New function.
(create_literal2): New function.
(lit_accum::create_literal2): New function.
(is_macro): Folded into new function...
(maybe_ignore_udl_macro_suffix): ...here.
(is_macro_not_literal_suffix): Folded likewise.
(lex_raw_string): Handle UTF-8 in UDL suffix via
scan_cur_identifier ().
(lex_string): Likewise.

gcc/testsuite/ChangeLog:

PR preprocessor/103902
* g++.dg/cpp0x/udlit-extended-id-1.C: New test.
* g++.dg/cpp0x/udlit-extended-id-2.C: New test.
* g++.dg/cpp0x/udlit-extended-id-3.C: New test.
* g++.dg/cpp0x/udlit-extended-id-4.C: New test.

2 years agoSupport type _Float16/__bf16 independent of SSE2.
liuhongt [Tue, 18 Apr 2023 06:53:04 +0000 (14:53 +0800)] 
Support type _Float16/__bf16 independent of SSE2.

Enable _Float16 and __bf16 all the time but issue errors when the
types are used in conversion, unary operation, binary operation,
parameter passing or value return when TARGET_SSE2 is not available.

Also undef macros which are used by libgcc/libstdc++ to check the
backend support of the _Float16/__bf16 types when TARGET_SSE2 is not
available.

gcc/ChangeLog:

PR target/109504
* config/i386/i386-builtins.cc
(ix86_register_float16_builtin_type): Remove TARGET_SSE2.
(ix86_register_bf16_builtin_type): Ditto.
* config/i386/i386-c.cc (ix86_target_macros): When TARGET_SSE2
isn't available, undef the macros which are used to check the
backend support of the _Float16/__bf16 types when building
libstdc++ and libgcc.
* config/i386/i386.cc (construct_container): Issue errors for
HFmode/BFmode when TARGET_SSE2 is not available.
(function_value_32): Ditto.
(ix86_scalar_mode_supported_p): Remove TARGET_SSE2 for HFmode/BFmode.
(ix86_libgcc_floating_mode_supported_p): Ditto.
(ix86_emit_support_tinfos): Adjust codes.
(ix86_invalid_conversion): Return diagnostic message string
when there's conversion from/to BF/HFmode w/o TARGET_SSE2.
(ix86_invalid_unary_op): New function.
(ix86_invalid_binary_op): Ditto.
(TARGET_INVALID_UNARY_OP): Define.
(TARGET_INVALID_BINARY_OP): Define.
* config/i386/immintrin.h [__SSE2__]: Remove for fp16/bf16
related instrinsics header files.
* config/i386/i386.h (VALID_SSE2_TYPE_MODE): New macro.

gcc/testsuite/ChangeLog:

* gcc.target/i386/pr109504.c: New test.
* gcc.target/i386/sse2-bfloat16-1.c: Adjust error info.
* gcc.target/i386/sse2-float16-1.c: Ditto.
* gcc.target/i386/sse2-float16-4.c: New test.
* gcc.target/i386/sse2-float16-5.c: New test.
* g++.target/i386/float16-1.C: Adjust error info.

libgcc/ChangeLog:

* config/i386/t-softfp: Add -msse2 to libbid HFtype related
files.

2 years agoDaily bump.
GCC Administrator [Wed, 19 Jul 2023 00:17:46 +0000 (00:17 +0000)] 
Daily bump.

2 years agoc++: Add tests for P2621, no UB in lexer [PR110340]
Marek Polacek [Tue, 18 Jul 2023 17:26:39 +0000 (13:26 -0400)] 
c++: Add tests for P2621, no UB in lexer [PR110340]

C++26 P2621 removes UB in the lexer and either makes the construct valid
or ill-formed.  We're already handling this correctly so this patch only
adds tests.

PR c++/110340

gcc/testsuite/ChangeLog:

* g++.dg/cpp/string-4.C: New test.
* g++.dg/cpp/ucn-2.C: New test.

2 years agotestsuite: fix dwarf2/utf-1.C with DWARF4
Marek Polacek [Wed, 5 Jul 2023 21:43:31 +0000 (17:43 -0400)] 
testsuite: fix dwarf2/utf-1.C with DWARF4

Running
$ make check-c++ RUNTESTFLAGS='--target_board=unix\{-gdwarf-5,-gdwarf-4\} dwarf2.exp=utf-1.C'
shows
FAIL: g++.dg/debug/dwarf2/utf-1.C  -std=gnu++20  scan-assembler-times DW_AT_encoding \\(0x10\\) 3
because with -gdwarf-4 the output is:

  .byte   0x10    # DW_AT_encoding

but with -gdwarf-5 the output is the expected:

                # DW_AT_encoding (0x10)

The difference is caused by the DWARF5 optimize_implicit_const
optimization:
<https://gcc.gnu.org/pipermail/gcc-patches/2016-October/459762.html>

I suppose we could do what testsuite/rust/debug/chartype.rs does
and just run the test with -gdwarf-4.

gcc/testsuite/ChangeLog:

* g++.dg/debug/dwarf2/utf-1.C: Use -gdwarf-4.  Adjust expected
output.

2 years agodwarf2: Change return type of predicate functions from int to bool
Uros Bizjak [Tue, 18 Jul 2023 16:46:46 +0000 (18:46 +0200)] 
dwarf2: Change return type of predicate functions from int to bool

Also change some internal variables and function arguments from int to bool.

gcc/ChangeLog:

* dwarf2asm.cc: Change FALSE to false.
* dwarf2cfi.cc (execute_dwarf2_frame): Change return type to void.
* dwarf2out.cc (matches_main_base): Change return type from
int to bool.  Change "last_match" variable to bool.
(dump_struct_debug): Change return type from int to bool.
Change "matches" and "result" function arguments to bool.
(is_pseudo_reg): Change return type from int to bool.
(is_tagged_type): Ditto.
(same_loc_p): Ditto.
(same_dw_val_p): Change return type from int to bool and adjust
function body accordingly.
(same_attr_p): Ditto.
(same_die_p): Ditto.
(is_type_die): Ditto.
(is_declaration_die): Ditto.
(should_move_die_to_comdat): Ditto.
(is_base_type): Ditto.
(is_based_loc): Ditto.
(local_scope_p): Ditto.
(class_scope_p): Ditto.
(class_or_namespace_scope_p): Ditto.
(is_tagged_type): Ditto.
(is_rust): Use void argument.
(is_nested_in_subprogram): Change return type from int to bool.
(contains_subprogram_definition): Ditto.
(gen_struct_or_union_type_die): Change "nested", "complete"
and "ns_decl" variables to bool.
(is_naming_typedef_decl): Change FALSE to false.

2 years agotree-ssa-loop-ch improvements, part 3
Jan Hubicka [Tue, 18 Jul 2023 15:47:50 +0000 (17:47 +0200)] 
tree-ssa-loop-ch improvements, part 3

Extend range query done by loop-ch to also support basic blocks
that are not headers of the loop.  This is easy to do, since we already
do path specific query so we only need to extend the path by headers we decided
to dulicate earlier.

This makes it possible to track situations where exit that is always false in
the first iteration (wihch is a common case) is not in the first iteration of
the loop.  Doing so lets us to update profile better and do better heuristics.
In particular I changed logic as follows
  1) should_duplicate_loop_header_p counts size of duplicated region.  When we
     know that a given conditional will be constant true or constant false either
     in the duplicated region, by range query, or in the loop body after
     duplication (since it is loop invariant), we do not account it to code size
     costs
  2) don't need account loop invariant compuations that will be duplicated
     as they will become fully invariant
     (maybe we want to have some cap for register pressure eventually?)
  3) optimize_size logic is now different.  Originally we started duplicating
     iff the first conditional was known to be true by ranger query, but then
     we used same limits as for -O2.

     I now simply lower limits to 0. This means that every conditional
     in duplicated sequence must be either loop invariant or constant when
     duplicated and we only duplicate statements computing loop invariants
     and those we account to 0 size anyway,

This makes code IMO more logical, but makes little difference in practice.
The problem is that in loop:

void test2();
void test(int n)
{
  for (int i = 0; n && i < 10; i++)
  test2();
}

We produce:
  <bb 4> [local count: 1073741824 freq: 9.090909]:
  # i_4 = PHI <0(2), i_9(3)>
  _1 = n_7(D) != 0;
  _2 = i_4 <= 9;
  _3 = _1 & _2;
  if (_3 != 0)
    goto <bb 3>; [89.00%]
  else
    goto <bb 5>; [11.00%]

and do not understand that the final conditional is a combination of a conditional
that is always true in first iteration and a conditional that is loop invariant.

This is also the case of
void test2();
void test(int n)
{
  for (int i = 0; n; i++)
    {
      if (i > 10)
        break;
      test2();
    }
}
Which we turn to the earlier case in ifcombine.

With disabled ifcombine things however works as exepcted.  This is something
I plan to handle incrementally.  However extending loop-ch and peeling passes
to understand such combined conditionals is still not good enough: at the time ifcombine
merged the two conditionals we lost profile information on how often n is 0,
so we can't recover correct profile or know what is expected number of iterations
after the transofrm.

gcc/ChangeLog:

* tree-ssa-loop-ch.cc (edge_range_query): Take loop argument; be ready
for queries not in headers.
(static_loop_exit): Add basic blck parameter; update use of
edge_range_query
(should_duplicate_loop_header_p): Add ranger and static_exits
parameter.  Do not account statements that will be optimized
out after duplicaiton in overall size. Add ranger query to
find static exits.
(update_profile_after_ch):  Take static_exits has set instead of
single eliminated_edge.
(ch_base::copy_headers): Do all analysis in the first pass;
remember invariant_exits and static_exits.

2 years agoc++: constexpr bit_cast with empty field
Jason Merrill [Fri, 14 Jul 2023 16:25:51 +0000 (12:25 -0400)] 
c++: constexpr bit_cast with empty field

The change to only cache constexpr calls that are
reduced_constant_expression_p tripped on bit-cast3.C, which failed that
predicate due to the presence of an empty field in the result of
native_interpret_aggregate, which reduced_constant_expression_p rejects to
avoid confusing output_constructor.

This patch proposes to skip such fields in native_interpret_aggregate, since
they aren't actually involved in the value representation.

gcc/ChangeLog:

* fold-const.cc (native_interpret_aggregate): Skip empty fields.

gcc/cp/ChangeLog:

* constexpr.cc (cxx_eval_bit_cast): Check that the result of
native_interpret_aggregate doesn't need more evaluation.

2 years ago[modula2] Uninitialized variable static analysis improvements
Gaius Mulley [Tue, 18 Jul 2023 15:31:49 +0000 (16:31 +0100)] 
[modula2] Uninitialized variable static analysis improvements

This patch fixes many limitations of the uninitialized static analysis.
NEW is understood, local variable pointers and non var parameters
will be tracked.

gcc/ChangeLog:

* doc/gm2.texi (Semantic checking): Change example testwithptr
to testnew6.

gcc/m2/ChangeLog:

* Make-lang.in: Minor formatting change.
* gm2-compiler/M2GCCDeclare.mod
(DeclareUnboundedProcedureParameters): Rename local variables.
(WalkUnboundedProcedureParameters): Rename local variables.
(DoVariableDeclaration): Avoid declaration of a variable if
it is on the heap (used by static analysis only).
* gm2-compiler/M2GenGCC.mod: Formatting.
* gm2-compiler/M2Quads.def (GetQuadTrash): New procedure function.
* gm2-compiler/M2Quads.mod (GetQuadTrash): New procedure function.
(QuadFrame): Add Trash field.
(BuildRealFuncProcCall): Detect ALLOCATE and DEALLOCATE and create
a heap variable for parameter 1 saving it as the trashed variable
for static analysis.
(GenQuadOTrash): New procedure.
(DisplayQuadRange): Bugfix.  Write the scope number.
* gm2-compiler/M2SymInit.mod: Rewritten to separate LValue
equivalence from LValue to RValue pairings.  Comprehensive
detection of variant record implemented.  Allow dereferencing
of pointers through LValue/RValue chains.
* gm2-compiler/SymbolTable.def (PutVarHeap): New procedure.
(IsVarHeap): New procedure function.
(ForeachParamSymDo): New procedure.
* gm2-compiler/SymbolTable.mod (PutVarHeap): New procedure.
(IsVarHeap): New procedure function.
(ForeachParamSymDo): New procedure.
(MakeVariableForParam): Reformatted.
(CheckForUnknownInModule): Reformatted.
(SymVar): Add field Heap.
(MakeVar): Assign Heap to FALSE.

gcc/testsuite/ChangeLog:

* gm2/switches/uninit-variable-checking/pass/assignparam.mod: New test.
* gm2/switches/uninit-variable-checking/pass/tiny.mod: New test.
* gm2/switches/uninit-variable-checking/procedures/fail/switches-uninit-variable-checking-procedures-fail.exp:
New test.
* gm2/switches/uninit-variable-checking/procedures/fail/testnew.mod: New test.
* gm2/switches/uninit-variable-checking/procedures/fail/testnew2.mod: New test.
* gm2/switches/uninit-variable-checking/procedures/fail/testnew3.mod: New test.
* gm2/switches/uninit-variable-checking/procedures/fail/testnew4.mod: New test.
* gm2/switches/uninit-variable-checking/procedures/fail/testnew5.mod: New test.
* gm2/switches/uninit-variable-checking/procedures/fail/testnew6.mod: New test.
* gm2/switches/uninit-variable-checking/procedures/fail/testptrptr.mod: New test.
* gm2/switches/uninit-variable-checking/procedures/pass/assignparam2.mod: New test.
* gm2/switches/uninit-variable-checking/procedures/pass/switches-uninit-variable-checking-procedures-pass.exp:
New test.
* gm2/switches/uninit-variable-checking/procedures/pass/testnew5.mod: New test.
* gm2/switches/uninit-variable-checking/procedures/pass/testnew6.mod: New test.
* gm2/switches/uninit-variable-checking/procedures/pass/testparamlvalue.mod: New test.
* gm2/switches/uninit-variable-checking/procedures/pass/testparamrvalue.mod: New test.
* gm2/switches/uninit-variable-checking/procedures/pass/testproc.mod: New test.
* gm2/switches/uninit-variable-checking/procedures/pass/testptrptr.mod: New test.

Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>
2 years agomiddle-end/105715 - missed RTL if-conversion with COND_EXPR expansion
Richard Biener [Tue, 18 Jul 2023 08:02:52 +0000 (10:02 +0200)] 
middle-end/105715 - missed RTL if-conversion with COND_EXPR expansion

When the COND_EXPR condition operand was split out to a separate stmt
it became subject to CSE with other condition evaluations.  This
unfortunately leads to TER no longer applying and in turn RTL
expansion of COND_EXPRs no longer seeing the condition and thus
failing to try conditional move expansion.  This can be seen with
gcc.target/i386/pr45685.c when built with -march=cascadelake which
then FAILs to produce the expected number of cmovs.

It can also be seen when we create more COND_EXPRs early like for
instruction selection of MIN/MAX operations that map to IEEE
a > b ? a : b expression semantics.

PR middle-end/105715
* gimple-isel.cc (gimple_expand_vec_exprs): Merge into...
(pass_gimple_isel::execute): ... this.  Duplicate
comparison defs of COND_EXPRs.

2 years agoc++: non-standalone surrogate call template
Patrick Palka [Tue, 18 Jul 2023 13:22:49 +0000 (09:22 -0400)] 
c++: non-standalone surrogate call template

I noticed we're accidentally prevented from considering a pointer- or
reference-to-function conversion function template if it's not the first
conversion function that's considered, which for the testcase below
results in us accepting the B call but not the A call despite the only
difference between A and B being their order of member declarations.
This patch fixes this so that the outcome of overload resolution doesn't
arbitrarily depend on declaration order here.

gcc/cp/ChangeLog:

* call.cc (add_template_conv_candidate): Don't check for
non-empty 'candidates' here.
(build_op_call): Check it here, before we've considered any
conversion functions.

gcc/testsuite/ChangeLog:

* g++.dg/overload/conv-op5.C: New test.

2 years agoc++: constrained surrogate call functions [PR110535]
Patrick Palka [Tue, 18 Jul 2023 13:21:40 +0000 (09:21 -0400)] 
c++: constrained surrogate call functions [PR110535]

We weren't checking constraints on pointer/reference-to-function conversion
functions during overload resolution, which caused us to ICE on the first
testcase and reject the second testcase.

PR c++/110535

gcc/cp/ChangeLog:

* call.cc (add_conv_candidate): Check constraints.

gcc/testsuite/ChangeLog:

* g++.dg/cpp2a/concepts-surrogate1.C: New test.
* g++.dg/cpp2a/concepts-surrogate2.C: New test.

2 years agoada: Use new typedefs in gcc-interface
Tom Tromey [Thu, 29 Jun 2023 15:56:59 +0000 (09:56 -0600)] 
ada: Use new typedefs in gcc-interface

This changes gcc-interface to use the typedefs that were recently
introduced in gnat.  This is another step toward switching the code
generator to emit enums rather than preprocessor defines.

In a couple of spots, a 'default' case is also added.  These avoid
warnings from -Wswitch when the typedefs are changed to be enums.

gcc/ada/

* gcc-interface/decl.cc (check_ok_for_atomic_type): Use Pragma_Id.
* gcc-interface/trans.cc (lvalue_required_p, Pragma_to_gnu): Use
Pragma_Id.
(get_type_length, Attribute_to_gnu, get_atomic_access): Use
Attribute_Id.

2 years agoada: Constraint_Error caused by 'Image applied to interface type
Javier Miranda [Sun, 9 Jul 2023 10:58:05 +0000 (10:58 +0000)] 
ada: Constraint_Error caused by 'Image applied to interface type

When the prefix of 'Image is used with a class-wide interface
type object, the frontend does not generate code to displace
the pointer to the underlying object to reference its base,
and this is required to invoke Ada.Tags.Wide_Wide_Expanded_Name.

gcc/ada/
* exp_imgv.adb (Rewrite_Object_Image): fix type of formal. Found
reading sources.
(Expand_Wide_Image_Attribute): ditto.
(Expand_Wide_Wide_Image_Attribute): ditto.
(Rewrite_Object_Image): ditto.
* exp_put_image.adb (Build_Image_Call): For class-wide interface
type prefix generate code to displace the pointer to the object to
reference the base of the underlying object.

2 years agoada: Avoid iterator conflicts in container aggregates
Viljar Indus [Thu, 6 Jul 2023 13:02:19 +0000 (16:02 +0300)] 
ada: Avoid iterator conflicts in container aggregates

Create temporary scope for the iterators defined in a
container aggregate so that it would not be put to the
same scope where the expression was used. This would
otherwise lead to multiple aggregates with iterators that have
the same name leading to a name conflict.

gcc/ada/

* sem_aggr.adb (Resolve_Iterated_Association): Add temporary scope
when analyzing the Iterator Specification. Use preanalysis instead
of Analysis to avoid polluting the tree.

2 years agoada: Apply correct element type for container aggregates
Viljar Indus [Wed, 5 Jul 2023 11:21:50 +0000 (14:21 +0300)] 
ada: Apply correct element type for container aggregates

When dealing with a container aggregate with an iterator
specification the iterator should take the value of the
element of the container instead of the key.

gcc/ada/

* sem_aggr.adb (Resolve_Iterated_Association): Use the element
type for the iterator in a container aggregate with an iterator
specification.

2 years agoada: Fix expanding container aggregates with Iterator specification
Viljar Indus [Wed, 5 Jul 2023 09:28:56 +0000 (12:28 +0300)] 
ada: Fix expanding container aggregates with Iterator specification

The compiler should use unnamed addition methods such as Append
when expanding a container aggregate with Iterator Specification.

gcc/ada/

* exp_aggr.adb (Expand_Container_Aggregate): Use the positional
addition method only when dealing with a container aggregate
without an Iterator Specification e.g. with a loop parameter
specification

2 years agoada: Improve error message for ambiguous subprogram call
Eric Botcazou [Wed, 5 Jul 2023 20:04:07 +0000 (22:04 +0200)] 
ada: Improve error message for ambiguous subprogram call

This restores the full listing of the types for the interpretations.

gcc/ada/

* sem_util.ads (Wrong_Type): Add Multiple parameter defaulting to
False and document it.
* sem_util.adb (Wrong_Type): Do not return early if an error has
already been posted on Expr and Multiple is True.
* sem_ch4.adb (Analyze_One_Call): Pass All_Errors_Mode as the
actual parameter for Multiple to Wrong_Type.

2 years agoada: Constraint_Error caused by interface conversion
Javier Miranda [Wed, 5 Jul 2023 17:27:14 +0000 (17:27 +0000)] 
ada: Constraint_Error caused by interface conversion

When the sources have a type conversion from an interface type
T2 to some ancestor interface type T1 (that is, T2 extends T1)
the tag check added by the compiler may fail at runtime.

gcc/ada/

* exp_disp.adb (Has_Dispatching_Constructor_Call): Removed.
(Expand_Interface_Conversion): Reverse patch.

2 years agoada: Tweak CPU affinity handling on Linux
Ronan Desplanques [Thu, 29 Jun 2023 08:00:44 +0000 (10:00 +0200)] 
ada: Tweak CPU affinity handling on Linux

Before this patch, the run-time assumed that not specifying a CPU
affinity mask when creating a thread was equivalent to specifying a
CPU affinity mask that included all CPUs.

As documented in the man pages for pthread_create and
pthread_setaffinity_np, this assumption is incorrect: a thread created
using pthread_create inherits the CPU affinity mask of the creating
thread by default. There was a comment in Set_Task_Affinity that
acknowledged this behavior, but the actual code made the erroneous
assumption mentioned above.

That assumption caused the run-time to behave incorrectly when tasks were
explicity assigned to Not_A_Specific_CPU: those tasks were assigned to
the same CPUs as their parents instead of being allowed to run on any
CPU. This patch fixes that behavior.

This patch has the negative effect of making the runtime issue
sched_setaffinity syscalls that are not necessary.

gcc/ada/

* libgnarl/s-taprop__linux.adb (Set_Task_Affinity, Create_Task): Tweak
handling of CPU affinities.

2 years agoada: Fix internal error on aggregates of self-referencing types
Eric Botcazou [Tue, 4 Jul 2023 17:24:07 +0000 (19:24 +0200)] 
ada: Fix internal error on aggregates of self-referencing types

The front-end contains a specific mechanism to deal with aggregates of
self-referencing types by means of the Has_Self_Reference flag, which is
supposed to be set during semantic analysis and used during expansion.

The problem is that the first part overlooks aggregates of derived types
which implicitly contain references to an ancestor type (the second part
uses a broader condition but it is effectively guarded by the first one).

This changes both parts to use the same condition based on the Is_Ancestor
predicate, which seems to implement the expected semantic in this case.

gcc/ada/
* sem_type.ads (Is_Ancestor): Remove mention of tagged type.
* exp_aggr.adb: Add with and use clauses for Sem_Type.
(Build_Record_Aggr_Code.Replace_Type): Call Is_Ancestor to spot
self-references to the type of the aggregate.
* sem_aggr.adb (Resolve_Record_Aggregate.Add_Discriminant_Values):
Likewise.

2 years agoada: Fix assertion failure introduced by latest change
Eric Botcazou [Wed, 5 Jul 2023 17:49:40 +0000 (19:49 +0200)] 
ada: Fix assertion failure introduced by latest change

The new processing is not properly guarded.

gcc/ada/

* sem_ch13.adb (Replace_Type_References_Generic.Visible_Component):
In the case of private discriminated types, explicitly check that we
have a private declaration before examining its discriminant part.

2 years agoada: Expose expected_throw attribute
Alexandre Oliva [Wed, 28 Jun 2023 04:36:52 +0000 (01:36 -0300)] 
ada: Expose expected_throw attribute

Mark exception-raising subprograms with expected_throw attribute.

Document the use of the attribute in Control Flow Redundancy.

Enable marking subprograms as expected_throw with Machine_Attribute
pragmas.

gcc/ada/

* libgnat/a-except.ads (Raise_Exception): Mark expected_throw.
(Reraise_Occurrence): Likewise.
(Raise_Exception_Always): Likewise.
(Raise_From_Controlled_Operation): Likewise.
(Reraise_Occurrence_Always): Likewise.
(Reraise_Occurrence_No_Defer): Likewise.
* libgnat/a-except.adb
(Exception_Propagation.Propagate_Exception): Likewise.
(Complete_And_Propagate_Occurrence): Likewise.
(Raise_Exception_No_Defer): Likewise.
(Raise_From_Signal_Handler): Likewise.
(Raise_With_Msg): Likewise.
(Raise_With_Location_And_Msg): Likewise.
(Raise_Constraint_Error): Likewise.
(Raise_Constraint_Error_Msg): Likewise.
(Raise_Program_Error): Likewise.
(Raise_Program_Error_Msg): Likewise.
(Raise_Storage_Error): Likewise.
(Raise_Storage_Error_Msg): Likewise.
(Reraise, Rcheck_*): Likewise.
* doc/gnat_rm/security_hardening_features.rst (Control Flow
Hardening): Note the influence of expected_throw.
* gnat_rm.texi: Regenerate.
* gnat_ugn.texi: Regenerate.
* gcc-interface/utils.cc (handle_expected_throw_attribute): New.
(gnat_internal_attribute_table): Add expected_throw.

2 years agoada: Refactor s-pack* units to remove multiple returns
Vasiliy Fofanov [Fri, 30 Jun 2023 12:22:47 +0000 (12:22 +0000)] 
ada: Refactor s-pack* units to remove multiple returns

The aim of this refactoring is to replace multiple returns from
branches of case and if statements by a single return statement
with a conditional expression. This is more readable and
maintainable, and also conformant with a Highly Recommended
design principle of ISO 26262-6.

gcc/ada/

* libgnat/s-pack03.adb: Update copyright year; refactor return statements.
* libgnat/s-pack05.adb: Likewise.
* libgnat/s-pack06.adb: Likewise.
* libgnat/s-pack07.adb: Likewise.
* libgnat/s-pack09.adb: Likewise.
* libgnat/s-pack10.adb: Likewise.
* libgnat/s-pack100.adb: Likewise.
* libgnat/s-pack101.adb: Likewise.
* libgnat/s-pack102.adb: Likewise.
* libgnat/s-pack103.adb: Likewise.
* libgnat/s-pack104.adb: Likewise.
* libgnat/s-pack105.adb: Likewise.
* libgnat/s-pack106.adb: Likewise.
* libgnat/s-pack107.adb: Likewise.
* libgnat/s-pack108.adb: Likewise.
* libgnat/s-pack109.adb: Likewise.
* libgnat/s-pack11.adb: Likewise.
* libgnat/s-pack110.adb: Likewise.
* libgnat/s-pack111.adb: Likewise.
* libgnat/s-pack112.adb: Likewise.
* libgnat/s-pack113.adb: Likewise.
* libgnat/s-pack114.adb: Likewise.
* libgnat/s-pack115.adb: Likewise.
* libgnat/s-pack116.adb: Likewise.
* libgnat/s-pack117.adb: Likewise.
* libgnat/s-pack118.adb: Likewise.
* libgnat/s-pack119.adb: Likewise.
* libgnat/s-pack12.adb: Likewise.
* libgnat/s-pack120.adb: Likewise.
* libgnat/s-pack121.adb: Likewise.
* libgnat/s-pack122.adb: Likewise.
* libgnat/s-pack123.adb: Likewise.
* libgnat/s-pack124.adb: Likewise.
* libgnat/s-pack125.adb: Likewise.
* libgnat/s-pack126.adb: Likewise.
* libgnat/s-pack127.adb: Likewise.
* libgnat/s-pack13.adb: Likewise.
* libgnat/s-pack14.adb: Likewise.
* libgnat/s-pack15.adb: Likewise.
* libgnat/s-pack17.adb: Likewise.
* libgnat/s-pack18.adb: Likewise.
* libgnat/s-pack19.adb: Likewise.
* libgnat/s-pack20.adb: Likewise.
* libgnat/s-pack21.adb: Likewise.
* libgnat/s-pack22.adb: Likewise.
* libgnat/s-pack23.adb: Likewise.
* libgnat/s-pack24.adb: Likewise.
* libgnat/s-pack25.adb: Likewise.
* libgnat/s-pack26.adb: Likewise.
* libgnat/s-pack27.adb: Likewise.
* libgnat/s-pack28.adb: Likewise.
* libgnat/s-pack29.adb: Likewise.
* libgnat/s-pack30.adb: Likewise.
* libgnat/s-pack31.adb: Likewise.
* libgnat/s-pack33.adb: Likewise.
* libgnat/s-pack34.adb: Likewise.
* libgnat/s-pack35.adb: Likewise.
* libgnat/s-pack36.adb: Likewise.
* libgnat/s-pack37.adb: Likewise.
* libgnat/s-pack38.adb: Likewise.
* libgnat/s-pack39.adb: Likewise.
* libgnat/s-pack40.adb: Likewise.
* libgnat/s-pack41.adb: Likewise.
* libgnat/s-pack42.adb: Likewise.
* libgnat/s-pack43.adb: Likewise.
* libgnat/s-pack44.adb: Likewise.
* libgnat/s-pack45.adb: Likewise.
* libgnat/s-pack46.adb: Likewise.
* libgnat/s-pack47.adb: Likewise.
* libgnat/s-pack48.adb: Likewise.
* libgnat/s-pack49.adb: Likewise.
* libgnat/s-pack50.adb: Likewise.
* libgnat/s-pack51.adb: Likewise.
* libgnat/s-pack52.adb: Likewise.
* libgnat/s-pack53.adb: Likewise.
* libgnat/s-pack54.adb: Likewise.
* libgnat/s-pack55.adb: Likewise.
* libgnat/s-pack56.adb: Likewise.
* libgnat/s-pack57.adb: Likewise.
* libgnat/s-pack58.adb: Likewise.
* libgnat/s-pack59.adb: Likewise.
* libgnat/s-pack60.adb: Likewise.
* libgnat/s-pack61.adb: Likewise.
* libgnat/s-pack62.adb: Likewise.
* libgnat/s-pack63.adb: Likewise.
* libgnat/s-pack65.adb: Likewise.
* libgnat/s-pack66.adb: Likewise.
* libgnat/s-pack67.adb: Likewise.
* libgnat/s-pack68.adb: Likewise.
* libgnat/s-pack69.adb: Likewise.
* libgnat/s-pack70.adb: Likewise.
* libgnat/s-pack71.adb: Likewise.
* libgnat/s-pack72.adb: Likewise.
* libgnat/s-pack73.adb: Likewise.
* libgnat/s-pack74.adb: Likewise.
* libgnat/s-pack75.adb: Likewise.
* libgnat/s-pack76.adb: Likewise.
* libgnat/s-pack77.adb: Likewise.
* libgnat/s-pack78.adb: Likewise.
* libgnat/s-pack79.adb: Likewise.
* libgnat/s-pack80.adb: Likewise.
* libgnat/s-pack81.adb: Likewise.
* libgnat/s-pack82.adb: Likewise.
* libgnat/s-pack83.adb: Likewise.
* libgnat/s-pack84.adb: Likewise.
* libgnat/s-pack85.adb: Likewise.
* libgnat/s-pack86.adb: Likewise.
* libgnat/s-pack87.adb: Likewise.
* libgnat/s-pack88.adb: Likewise.
* libgnat/s-pack89.adb: Likewise.
* libgnat/s-pack90.adb: Likewise.
* libgnat/s-pack91.adb: Likewise.
* libgnat/s-pack92.adb: Likewise.
* libgnat/s-pack93.adb: Likewise.
* libgnat/s-pack94.adb: Likewise.
* libgnat/s-pack95.adb: Likewise.
* libgnat/s-pack96.adb: Likewise.
* libgnat/s-pack97.adb: Likewise.
* libgnat/s-pack98.adb: Likewise.
* libgnat/s-pack99.adb: Likewise.

2 years agoada: Allow warnings with explain code
Yannick Moy [Fri, 30 Jun 2023 12:51:53 +0000 (14:51 +0200)] 
ada: Allow warnings with explain code

Change the way explain codes are handled to generate the command for the
user to get the explanations, as this was not working for warnings.

gcc/ada/

* errout.adb (Error_Msg_Internal): Remove call to
Prescan_Message on the special continuation for the explain code
command, as this does not play well with the setting of global
variables for the message (like its status as a warning or not).
Instead, set directly the global variables regarding content of
the message in terms of special characters.

2 years agoada: Fix Valid_Scalars attribute applied to types from limited with
Eric Botcazou [Sun, 2 Jul 2023 08:07:55 +0000 (10:07 +0200)] 
ada: Fix Valid_Scalars attribute applied to types from limited with

The attribute is wrongly computed as always True because, unlike for e.g.
private types, Validated_View does not look through the limited view.

gcc/ada/

* sem_util.ads (Validated_View): Document enhanced behavior.
* sem_util.adb (Validated_View): Return the nonlimited view, if any,
of types coming from a limited with.

2 years agoRISC-V: Dynamic adjust size of VLA vector according to TARGET_MIN_VLEN
Juzhe-Zhong [Tue, 18 Jul 2023 06:27:39 +0000 (14:27 +0800)] 
RISC-V: Dynamic adjust size of VLA vector according to TARGET_MIN_VLEN

This patch is to dynamic adjust size of VLA vectors according to TARGET_MIN_VLEN (-march=*zvl*b).

Currently, VNx16QImode is always [16,16] when TARGET_MINV_LEN >= 128.

We are going to add a bunch of VLS modes (V16QI,V32QI,....etc), these modes should always be considered
as having smaller size than VLA vectors.

For example, the V32QImode is LMUL = 1 VLS mode when TARGET_MIN_VLEN = 256
             and V16QImode is LMUL = 1 VLS mode when TARGET_MINV_LEN = 128.

Since a LMUL = 1 VLA mode VNx16QI is always [16,16] before this patch,
when TARGET_MIN_VLEN = 128, VNx16QImode ([16,16]) > V16QImode.
when TARGET_MIN_VLEN = 256, VNx16QImode ([16,16]) possible < V32QImode.

Then such inconsistency (TARGET_MIN_VLEN = 128, regno_reg_rtx[97] is VLA modes wheras it is VLS modes when TARGET_MIN_VLEN = 256).

This patch now adjust VLA vector size accurately according to TARGET_MIN_VLEN which make things more reasonable:

VNx16QI = [16,16] if TARGET_MIN_VLEN = 128.
VNx16QI = [32,32] if TARGET_MIN_VLEN = 256.
VNx16QI = [64,64] if TARGET_MIN_VLEN = 512.
VNx16QI = [128,128] if TARGET_MIN_VLEN = 1024.
VNx16QI = [256,256] if TARGET_MIN_VLEN = 2048.
VNx16QI = [512,512] if TARGET_MIN_VLEN = 4096.

gcc/ChangeLog:

* config/riscv/riscv-selftests.cc (run_poly_int_selftests): Add more selftests.
* config/riscv/riscv.cc (riscv_legitimize_poly_move): Dynamic adjust size of VLA vectors.
(riscv_convert_vector_bits): Ditto.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/autovec/zve32f_zvl1024b-1.c: New test.
* gcc.target/riscv/rvv/autovec/zve32f_zvl2048b-1.c: New test.
* gcc.target/riscv/rvv/autovec/zve32f_zvl256b-1.c: New test.
* gcc.target/riscv/rvv/autovec/zve32f_zvl4096b-1.c: New test.
* gcc.target/riscv/rvv/autovec/zve32f_zvl512b-1.c: New test.
* gcc.target/riscv/rvv/autovec/zve32x_zvl1024b-1.c: New test.
* gcc.target/riscv/rvv/autovec/zve32x_zvl2048b-1.c: New test.
* gcc.target/riscv/rvv/autovec/zve32x_zvl256b-1.c: New test.
* gcc.target/riscv/rvv/autovec/zve32x_zvl4096b-1.c: New test.
* gcc.target/riscv/rvv/autovec/zve32x_zvl512b-1.c: New test.
* gcc.target/riscv/rvv/autovec/zve64d_zvl1024b-1.c: New test.
* gcc.target/riscv/rvv/autovec/zve64d_zvl2048b-1.c: New test.
* gcc.target/riscv/rvv/autovec/zve64d_zvl256b-1.c: New test.
* gcc.target/riscv/rvv/autovec/zve64d_zvl4096b-1.c: New test.
* gcc.target/riscv/rvv/autovec/zve64d_zvl512b-1.c: New test.
* gcc.target/riscv/rvv/autovec/zve64f_zvl1024b-1.c: New test.
* gcc.target/riscv/rvv/autovec/zve64f_zvl2048b-1.c: New test.
* gcc.target/riscv/rvv/autovec/zve64f_zvl256b-1.c: New test.
* gcc.target/riscv/rvv/autovec/zve64f_zvl4096b-1.c: New test.
* gcc.target/riscv/rvv/autovec/zve64f_zvl512b-1.c: New test.
* gcc.target/riscv/rvv/autovec/zve64x_zvl1024b-1.c: New test.
* gcc.target/riscv/rvv/autovec/zve64x_zvl2048b-1.c: New test.
* gcc.target/riscv/rvv/autovec/zve64x_zvl256b-1.c: New test.
* gcc.target/riscv/rvv/autovec/zve64x_zvl4096b-1.c: New test.
* gcc.target/riscv/rvv/autovec/zve64x_zvl512b-1.c: New test.

2 years agoMAINTAINERS: Add myself as riscv port reviewer.
Ju-Zhe Zhong [Tue, 18 Jul 2023 09:32:04 +0000 (17:32 +0800)] 
MAINTAINERS: Add myself as riscv port reviewer.

ChangeLog:

* MAINTAINERS: Add myself as a reviewer for the riscv port.

2 years agoRISC-V: Enable SLP un-order reduction
Juzhe-Zhong [Tue, 18 Jul 2023 08:44:11 +0000 (16:44 +0800)] 
RISC-V: Enable SLP un-order reduction

This patch is to enable SLP un-order reduction autao-vectorization

Consider this following case:

int __attribute__((noipa))
add_loop (int *x, int n, int res)
{
  for (int i = 0; i < n; ++i)
    {
      res += x[i * 2];
      res += x[i * 2 + 1];
    }
  return res;
}

--param riscv-autovec-preference=scalable -fopt-info-vec-missed:
<source>:4:21: missed: couldn't vectorize loop
<source>:4:21: missed: unsupported SLP instances

After this patch:

add_loop:
ble a1,zero,.L5
csrr a6,vlenb
srli a4,a6,2
slli a1,a1,1
neg a7,a4
vsetvli t1,zero,e32,m1,ta,ma
vmv.v.i v2,0
vslide1up.vx v1,v2,a2   -----------> generated by VEC_SHL_INSERT
.L4:
mv a3,a1
mv a5,a1
bleu a1,a4,.L3
mv a5,a4
.L3:
vsetvli zero,a5,e32,m1,tu,ma
add a1,a1,a7
vle32.v v2,0(a0)
add a0,a0,a6
vadd.vv v1,v1,v2
bgtu a3,a4,.L4
vsetivli zero,1,e32,m1,ta,ma
vmv.v.i v2,0
vsetvli t1,zero,e32,m1,ta,ma
vredsum.vs v1,v1,v2
vmv.x.s a0,v1
ret
.L5:
mv a0,a2
ret

gcc/ChangeLog:

* config/riscv/autovec.md (vec_shl_insert_<mode>): New patterns.
* config/riscv/riscv-v.cc (shuffle_compress_patterns): Fix bugs.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/autovec/reduc/reduc-5.c: New test.
* gcc.target/riscv/rvv/autovec/reduc/reduc-6.c: New test.
* gcc.target/riscv/rvv/autovec/reduc/reduc-7.c: New test.
* gcc.target/riscv/rvv/autovec/reduc/reduc-8.c: New test.
* gcc.target/riscv/rvv/autovec/reduc/reduc-9.c: New test.
* gcc.target/riscv/rvv/autovec/reduc/reduc_run-5.c: New test.
* gcc.target/riscv/rvv/autovec/reduc/reduc_run-6.c: New test.
* gcc.target/riscv/rvv/autovec/reduc/reduc_run-7.c: New test.
* gcc.target/riscv/rvv/autovec/reduc/reduc_run-8.c: New test.
* gcc.target/riscv/rvv/autovec/reduc/reduc_run-9.c: New test.

2 years agoMAINTAINERS: Add myself as riscv port reviewer.
Robin Dapp [Tue, 18 Jul 2023 07:06:53 +0000 (09:06 +0200)] 
MAINTAINERS: Add myself as riscv port reviewer.

ChangeLog:

* MAINTAINERS: Add myself as a reviewer for the riscv port.

2 years agoRISC-V: Remove testcase that cannot be compiled because VLEN limitation
Lehua Ding [Tue, 18 Jul 2023 06:47:28 +0000 (14:47 +0800)] 
RISC-V: Remove testcase that cannot be compiled because VLEN limitation

Since the latter patch (https://gcc.gnu.org/pipermail/gcc-patches/2023-July/624689.html)
forbidden VLEN > 4096, the testcase attribute-20.c is no long need. This is obvious.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/attribute-20.c: Removed.

2 years agoIBM zSystems: Optimize vec_cmpge followed by vec_sel
Juergen Christ [Tue, 18 Jul 2023 06:30:14 +0000 (08:30 +0200)] 
IBM zSystems: Optimize vec_cmpge followed by vec_sel

A vec_cmpge produces a negation.  Replace this negation by swapping the two
selection choices of a vec_sel based on the result of the vec_cmpge.

gcc/ChangeLog:

* config/s390/vx-builtins.md: New vsel pattern.

gcc/testsuite/ChangeLog:

* gcc.target/s390/vector/vec-cmpge.c: New test.

Signed-off-by: Juergen Christ <jchrist@linux.ibm.com>
2 years agoTighten regexps in gcc.target/riscv/_Float16-zhinx-1.c .
Joern Rennecke [Tue, 18 Jul 2023 03:28:55 +0000 (04:28 +0100)] 
Tighten regexps in gcc.target/riscv/_Float16-zhinx-1.c .

The original "mv" regexp would match
.ascii  "\254\254\375\002e2N6\013\231,\354NDmvVP0]\304\312F!biZ\025\211"
in the .gnu.lto_foo1.0.32528183c9deec41 section.

gcc/testsuite/
* gcc.target/riscv/_Float16-zhinx-1.c: Tighten regexps.

2 years agoRemove # from <mask_codefor>one_cmpl<mode>2<mask_name> assemble output.
liuhongt [Mon, 17 Jul 2023 04:50:17 +0000 (12:50 +0800)] 
Remove # from <mask_codefor>one_cmpl<mode>2<mask_name> assemble output.

optimize_insn_for_speed () in assemble output is not aligned with
splitter condition, and it cause an ICE when building SPEC2017
blender_r.

libpng/pngread.c: In function ‘png_read_image’:
libpng/pngread.c:786:1: internal compiler error: in final_scan_insn_1, at final.cc:2813
  786 | }
      | ^
0x73ac3d final_scan_insn_1
../../gcc/final.cc:2813
0xb3420b final_scan_insn(rtx_insn*, _IO_FILE*, int, int, int*)
../../gcc/final.cc:2887
0xb344c4 final_1
../../gcc/final.cc:1979
0xb34f64 rest_of_handle_final
../../gcc/final.cc:4240
0xb34f64 execute
../../gcc/final.cc:4318

gcc/ChangeLog:

PR target/110438
* config/i386/sse.md (<mask_codefor>one_cmpl<mode>2<mask_name>):
Remove # from assemble output.

2 years agoAdd peephole to eliminate redundant comparison after cmpccxadd.
liuhongt [Mon, 10 Jul 2023 06:12:07 +0000 (14:12 +0800)] 
Add peephole to eliminate redundant comparison after cmpccxadd.

Similar like we did for cmpxchg, but extended to all
ix86_comparison_int_operator since cmpccxadd set EFLAGS exactly same
as CMP.

When operand order in compare insn is same as that in cmpccxadd,
compare insn can be eliminated directly.

When operand order is swapped in compare insn, only optimize cmpccxadd
+ cmpl + jcc/setcc to cmpccxadd + jcc/setcc when FLAGS_REG is dead
after jcc/setcc.

gcc/ChangeLog:

PR target/110591
* config/i386/sync.md (cmpccxadd_<mode>): Adjust the pattern
to explicitly set FLAGS_REG like *cmp<mode>_1, also add extra
3 define_peephole2 after the pattern.

gcc/testsuite/ChangeLog:

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

2 years agoRTL_SSA: Relax PHI_MODE in phi_setup
Ju-Zhe Zhong [Mon, 17 Jul 2023 14:42:09 +0000 (22:42 +0800)] 
RTL_SSA: Relax PHI_MODE in phi_setup

Hi, Richard.

RISC-V port needs to add a bunch VLS modes (V16QI,V32QI,V64QI,...etc)
There are sharing same REG_CLASS with VLA modes (VNx16QI,VNx32QI,...etc)

When I am adding those VLS modes, the RTL_SSA initialization in VSETVL PASS (inserted after RA) ICE:
rvv.c:13:1: internal compiler error: in partial_subreg_p, at rtl.h:3186
   13 | }
      | ^
0xf7a5b1 partial_subreg_p(machine_mode, machine_mode)
        ../../../riscv-gcc/gcc/rtl.h:3186
0x1407616 wider_subreg_mode(machine_mode, machine_mode)
        ../../../riscv-gcc/gcc/rtl.h:3252
0x2a2c6ff rtl_ssa::combine_modes(machine_mode, machine_mode)
        ../../../riscv-gcc/gcc/rtl-ssa/internals.inl:677
0x2a2b9a4 rtl_ssa::function_info::simplify_phi_setup(rtl_ssa::phi_info*, rtl_ssa::set_info**, bitmap_head*)
        ../../../riscv-gcc/gcc/rtl-ssa/functions.cc:146
0x2a2c142 rtl_ssa::function_info::simplify_phis()
        ../../../riscv-gcc/gcc/rtl-ssa/functions.cc:258
0x2a2b3f0 rtl_ssa::function_info::function_info(function*)
        ../../../riscv-gcc/gcc/rtl-ssa/functions.cc:51
0x1cebab9 pass_vsetvl::init()
        ../../../riscv-gcc/gcc/config/riscv/riscv-vsetvl.cc:4578
0x1cec150 pass_vsetvl::execute(function*)
        ../../../riscv-gcc/gcc/config/riscv/riscv-vsetvl.cc:4716

The reason is that we have V32QImode (size = [32,0]) which is the mode set as regno_reg_rtx[97]
When the PHI input def comes from ENTRY BLOCK (index =0), the def->mode () = V32QImode.
But the phi_mode = VNx2QI for example (I use VLA modes intrinsic write the codes).
Then combine_modes report ICE.

gcc/ChangeLog:

* rtl-ssa/internals.inl: Fix when mode1 and mode2 are not ordred.

2 years agoRISC-V: Fix RVV frm run test failure on RV32
Pan Li [Tue, 18 Jul 2023 02:45:27 +0000 (10:45 +0800)] 
RISC-V: Fix RVV frm run test failure on RV32

Refine the run test case to avoid interactive checking in RV32, by
separating each checks in different functions.

Signed-off-by: Pan Li <pan2.li@intel.com>
gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/base/float-point-frm-run-1.c: Fix run failure.

2 years agoRISC-V: Support basic floating-point dynamic rounding mode
Pan Li [Fri, 14 Jul 2023 02:14:07 +0000 (10:14 +0800)] 
RISC-V: Support basic floating-point dynamic rounding mode

This patch would like to support the basic floating-point dynamic
rounding modes for the RVV.

We implement the dynamic rounding mode by below steps.
1. Set entry to DYN and exit to DYN_EXIT.
2. Add one rtl variable into machine_function for backup/restore.
3. Backup frm value when entry.
4. Restore frm value when exit and prev mode is not DYN.
5. Restore frm when mode switching to DYN.
6. Set frm when mode switching to STATIC.

Take one flow to describe the scenarios.

           +-------------+
           | Entry (DYN) | <- frrm a5
           +-------------+
          /               \
    +-------+            +-----------+
    | VFADD | <- fsrm a5 | VFADD RTZ | <- fsrmi 1(RTZ)
    +-------+            +-----------+
          |                    |
    +-------+            +-----------+
    | VFADD |            | VFADD RTZ |
    +-------+            +-----------+
          |                       |
+-----------+                 +-------+
| VFADD RUP | <- fsrmi 3(RUP) | VFADD | <- fsrm a5
+-----------+                 +-------+
          |                  /
+-----------+               /
| VFADD RUP |              /
+-----------+             /
           \             /
            +-----------------+
            | Exit (DYN_EXIT) | <- fsrm a5
            +-----------------+

Please *NOTE* inline asm and call during the cfun will be implemented
in another PATCH(s).

Signed-off-by: Pan Li <pan2.li@intel.com>
Co-Authored-By: Juzhe-Zhong <juzhe.zhong@rivai.ai>
gcc/ChangeLog:

* config/riscv/riscv.cc (struct machine_function): Add new field.
(riscv_static_frm_mode_p): New function.
(riscv_emit_frm_mode_set): New function for emit FRM.
(riscv_emit_mode_set): Extract function for FRM.
(riscv_mode_needed): Fix the TODO.
(riscv_mode_entry): Initial dynamic frm RTL.
(riscv_mode_exit): Return DYN_EXIT.
* config/riscv/riscv.md: Add rdfrm.
* config/riscv/vector-iterators.md (unspecv): Add DYN_EXIT unspecv.
* config/riscv/vector.md (frm_modee): Add new mode dyn_exit.
(fsrm): Removed.
(fsrmsi_backup): New pattern for swap.
(fsrmsi_restore): New pattern for restore.
(fsrmsi_restore_exit): New pattern for restore exit.
(frrmsi): New pattern for backup.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/base/float-point-frm-insert-1.c: Adjust
test cases.
* gcc.target/riscv/rvv/base/float-point-frm-insert-10.c: Ditto.
* gcc.target/riscv/rvv/base/float-point-frm-insert-2.c: Ditto.
* gcc.target/riscv/rvv/base/float-point-frm-insert-3.c: Ditto.
* gcc.target/riscv/rvv/base/float-point-frm-insert-4.c: Ditto.
* gcc.target/riscv/rvv/base/float-point-frm-insert-5.c: Ditto.
* gcc.target/riscv/rvv/base/float-point-frm-insert-6.c: Ditto.
* gcc.target/riscv/rvv/base/float-point-frm-insert-7.c: Ditto.
* gcc.target/riscv/rvv/base/float-point-frm-insert-8.c: Ditto.
* gcc.target/riscv/rvv/base/float-point-frm-insert-9.c: Ditto.
* gcc.target/riscv/rvv/base/float-point-frm-run-1.c: Ditto.
* gcc.target/riscv/rvv/base/float-point-frm-run-2.c: Ditto.
* gcc.target/riscv/rvv/base/float-point-frm-run-3.c: Ditto.
* gcc.target/riscv/rvv/base/float-point-dynamic-frm-1.c: New test.
* gcc.target/riscv/rvv/base/float-point-dynamic-frm-10.c: New test.
* gcc.target/riscv/rvv/base/float-point-dynamic-frm-11.c: New test.
* gcc.target/riscv/rvv/base/float-point-dynamic-frm-12.c: New test.
* gcc.target/riscv/rvv/base/float-point-dynamic-frm-13.c: New test.
* gcc.target/riscv/rvv/base/float-point-dynamic-frm-14.c: New test.
* gcc.target/riscv/rvv/base/float-point-dynamic-frm-15.c: New test.
* gcc.target/riscv/rvv/base/float-point-dynamic-frm-16.c: New test.
* gcc.target/riscv/rvv/base/float-point-dynamic-frm-17.c: New test.
* gcc.target/riscv/rvv/base/float-point-dynamic-frm-18.c: New test.
* gcc.target/riscv/rvv/base/float-point-dynamic-frm-19.c: New test.
* gcc.target/riscv/rvv/base/float-point-dynamic-frm-2.c: New test.
* gcc.target/riscv/rvv/base/float-point-dynamic-frm-20.c: New test.
* gcc.target/riscv/rvv/base/float-point-dynamic-frm-21.c: New test.
* gcc.target/riscv/rvv/base/float-point-dynamic-frm-22.c: New test.
* gcc.target/riscv/rvv/base/float-point-dynamic-frm-23.c: New test.
* gcc.target/riscv/rvv/base/float-point-dynamic-frm-24.c: New test.
* gcc.target/riscv/rvv/base/float-point-dynamic-frm-25.c: New test.
* gcc.target/riscv/rvv/base/float-point-dynamic-frm-26.c: New test.
* gcc.target/riscv/rvv/base/float-point-dynamic-frm-27.c: New test.
* gcc.target/riscv/rvv/base/float-point-dynamic-frm-28.c: New test.
* gcc.target/riscv/rvv/base/float-point-dynamic-frm-29.c: New test.
* gcc.target/riscv/rvv/base/float-point-dynamic-frm-3.c: New test.
* gcc.target/riscv/rvv/base/float-point-dynamic-frm-30.c: New test.
* gcc.target/riscv/rvv/base/float-point-dynamic-frm-31.c: New test.
* gcc.target/riscv/rvv/base/float-point-dynamic-frm-32.c: New test.
* gcc.target/riscv/rvv/base/float-point-dynamic-frm-4.c: New test.
* gcc.target/riscv/rvv/base/float-point-dynamic-frm-5.c: New test.
* gcc.target/riscv/rvv/base/float-point-dynamic-frm-6.c: New test.
* gcc.target/riscv/rvv/base/float-point-dynamic-frm-7.c: New test.
* gcc.target/riscv/rvv/base/float-point-dynamic-frm-8.c: New test.
* gcc.target/riscv/rvv/base/float-point-dynamic-frm-9.c: New test.

2 years agoDaily bump.
GCC Administrator [Tue, 18 Jul 2023 00:17:34 +0000 (00:17 +0000)] 
Daily bump.

2 years agoextend.texi: index __auto_type
Arsen Arsenović [Mon, 17 Jul 2023 21:17:07 +0000 (23:17 +0200)] 
extend.texi: index __auto_type

gcc/ChangeLog:

* doc/extend.texi: Add @cindex on __auto_type.

2 years agoc++: only cache constexpr calls that are constant exprs
Jason Merrill [Thu, 13 Jul 2023 21:48:05 +0000 (17:48 -0400)] 
c++: only cache constexpr calls that are constant exprs

In reviewing Nathaniel's patch for PR70331, it occurred to me that instead
of looking for various specific problematic things in the result of a
constexpr call to decide whether to cache it, we should use
reduced_constant_expression_p.

The change to that function is to avoid crashing on uninitialized objects of
non-class type.

In a trial version of this patch I checked to see what cases this stopped
caching; most were instances of partially-initialized return values, which
seem fine to not cache.  Some were returning pointers to expiring local
variables, which we definitely want not to cache.  And one was bit-cast3.C,
which will be handled in a follow-up patch.

gcc/cp/ChangeLog:

* constexpr.cc (cxx_eval_call_expression): Only cache
reduced_constant_expression_p results.
(reduced_constant_expression_p): Handle CONSTRUCTOR of scalar type.
(cxx_eval_constant_expression): Fold vectors here.
(cxx_eval_bare_aggregate): Not here.

2 years agocombine-stack-adj: Change return type of predicate function from int to bool
Uros Bizjak [Mon, 17 Jul 2023 20:32:57 +0000 (22:32 +0200)] 
combine-stack-adj: Change return type of predicate function from int to bool

gcc/ChangeLog:

* combine-stack-adj.cc (stack_memref_p): Change return type from
int to bool and adjust function body accordingly.
(rest_of_handle_stack_adjustments): Change return type to void.

2 years agocombine: Change return type of predicate functions from int to bool
Uros Bizjak [Mon, 17 Jul 2023 20:13:52 +0000 (22:13 +0200)] 
combine: Change return type of predicate functions from int to bool

Also change some internal variables and function arguments from int to bool.

gcc/ChangeLog:

* combine.cc (struct reg_stat_type): Change last_set_invalid to bool.
(cant_combine_insn_p): Change return type from int to bool and adjust
function body accordingly.
(can_combine_p): Ditto.
(combinable_i3pat): Ditto.  Change "i1_not_in_src" and "i0_not_in_src"
function arguments from int to bool.
(contains_muldiv): Change return type from int to bool and adjust
function body accordingly.
(try_combine): Ditto. Change "new_direct_jump" pointer function
argument from int to bool.  Change "substed_i2", "substed_i1",
"substed_i0", "added_sets_0", "added_sets_1", "added_sets_2",
"i2dest_in_i2src", "i1dest_in_i1src", "i2dest_in_i1src",
"i0dest_in_i0src", "i1dest_in_i0src", "i2dest_in_i0src",
"i2dest_killed", "i1dest_killed", "i0dest_killed", "i1_feeds_i2_n",
"i0_feeds_i2_n", "i0_feeds_i1_n", "i3_subst_into_i2", "have_mult",
"swap_i2i3", "split_i2i3" and "changed_i3_dest" variables
from int to bool.
(subst): Change "in_dest", "in_cond" and "unique_copy" function
arguments from int to bool.
(combine_simplify_rtx): Change "in_dest" and "in_cond" function
arguments from int to bool.
(make_extraction): Change "unsignedp", "in_dest" and "in_compare"
function argument from int to bool.
(force_int_to_mode): Change "just_select" function argument
from int to bool.  Change "next_select" variable to bool.
(rtx_equal_for_field_assignment_p): Change return type from
int to bool and adjust function body accordingly.
(merge_outer_ops): Ditto.  Change "pcomp_p" pointer function
argument from int to bool.
(get_last_value_validate): Change return type from int to bool
and adjust function body accordingly.
(reg_dead_at_p): Ditto.
(reg_bitfield_target_p): Ditto.
(combine_instructions): Ditto.  Change "new_direct_jump"
variable to bool.
(can_combine_p): Change return type from int to bool
and adjust function body accordingly.
(likely_spilled_retval_p): Ditto.
(can_change_dest_mode): Change "added_sets" function argument
from int to bool.
(find_split_point): Change "unsignedp" variable to bool.
(simplify_if_then_else): Change "comparison_p" and "swapped"
variables to bool.
(simplify_set): Change "other_changed" variable to bool.
(expand_compound_operation): Change "unsignedp" variable to bool.
(force_to_mode): Change "just_select" function argument
from int to bool.  Change "next_select" variable to bool.
(extended_count): Change "unsignedp" function argument to bool.
(simplify_shift_const_1): Change "complement_p" variable to bool.
(simplify_comparison): Change "changed" variable to bool.
(rest_of_handle_combine): Change return type to void.

2 years agoFortran: intrinsics and deferred-length character arguments [PR95947,PR110658]
Harald Anlauf [Sun, 16 Jul 2023 20:17:27 +0000 (22:17 +0200)] 
Fortran: intrinsics and deferred-length character arguments [PR95947,PR110658]

gcc/fortran/ChangeLog:

PR fortran/95947
PR fortran/110658
* trans-expr.cc (gfc_conv_procedure_call): For intrinsic procedures
whose result characteristics depends on the first argument and which
can be of type character, the character length will not be deferred.

gcc/testsuite/ChangeLog:

PR fortran/95947
PR fortran/110658
* gfortran.dg/deferred_character_37.f90: New test.

2 years agoInclude insn-opinit.h in PLUGIN_H [PR110610]
Andre Vieira [Mon, 17 Jul 2023 16:00:54 +0000 (17:00 +0100)] 
Include insn-opinit.h in PLUGIN_H [PR110610]

This patch fixes PR110610 by including insn-opinit.h in the INTERNAL_FN_H list,
as insn-opinit.h is now required by internal-fn.h. This will lead to
insn-opinit.h being installed in the plugin directory.

gcc/ChangeLog:

PR plugins/110610
* Makefile.in (INTERNAL_FN_H): Add insn-opinit.h.

2 years agoira: Skip empty regclass when setting up reg class relations
Senthil Kumar Selvaraj [Mon, 17 Jul 2023 14:34:36 +0000 (20:04 +0530)] 
ira: Skip empty regclass when setting up reg class relations

ira.cc:setup_reg_class_relations sets up ira_reg_class_subset (among
other things). If reg class cl3 has no registers, then that empty set
is always hard_reg_set_subset_p of any other set, and this makes
ira_reg_class_subset[ALL_REGS][NO_REGS] equal to such a regclass,
rather than NO_REGS.

This breaks code (lra-constraints.cc:in_class_p/curr_insn_transform,
for e.g.) which uses NO_REGS to check for an empty regclass.

Why define an empty regclass? A regclass could be conditionally empty (via
TARGET_CONDITIONAL_REGISTER_USAGE) - for the avr target, ADDW_REGS and
NO_LD_REGS are empty for the avrtiny subarch, for example.

Fix by continuing the innermost loop if the corresponding reg class is empty.

gcc/ChangeLog:

* ira.cc (setup_reg_class_relations): Continue
if regclass cl3 is hard_reg_set_empty_p.

2 years agoRISC-V: Add TARGET_MIN_VLEN > 4096 check
Juzhe-Zhong [Mon, 17 Jul 2023 14:20:02 +0000 (22:20 +0800)] 
RISC-V: Add TARGET_MIN_VLEN > 4096 check

gcc/ChangeLog:

* config/riscv/riscv.cc (riscv_option_override): Add sorry check.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/base/zvl-unimplemented-1.c: New test.
* gcc.target/riscv/rvv/base/zvl-unimplemented-2.c: New test.

2 years agoOpenMP/Fortran: Parsing support for 'uses_allocators'
Tobias Burnus [Mon, 17 Jul 2023 13:13:44 +0000 (15:13 +0200)] 
OpenMP/Fortran: Parsing support for 'uses_allocators'

The 'uses_allocators' clause to the 'target' construct accepts predefined
allocators and can also be used to define a new allocator for a target region.
As predefined allocators in GCC do not require special handling, those can and
are ignored after parsing, such that this feature now works. On the other hand,
defining a new allocator will fail for now with a 'sorry, unimplemented'.

Note that both the OpenMP 5.0/5.1 and 5.2 syntax for uses_allocators
is supported by this commit.

2023-07-17  Tobias Burnus  <tobias@codesoucery.com>
    Chung-Lin Tang  <cltang@codesourcery.com>

gcc/fortran/ChangeLog:

* dump-parse-tree.cc (show_omp_namelist, show_omp_clauses): Dump
uses_allocators clause.
* gfortran.h (gfc_free_omp_namelist): Add memspace_sym to u union
and traits_sym to u2 union.
(OMP_LIST_USES_ALLOCATORS): New enum value.
(gfc_free_omp_namelist): Add 'bool free_mem_traits_space' arg.
* match.cc (gfc_free_omp_namelist): Likewise.
* openmp.cc (gfc_free_omp_clauses, gfc_match_omp_variable_list,
gfc_match_omp_to_link, gfc_match_omp_doacross_sink,
gfc_match_omp_clause_reduction, gfc_match_omp_allocate,
gfc_match_omp_flush): Update call.
(gfc_match_omp_clauses): Likewise. Parse uses_allocators clause.
(gfc_match_omp_clause_uses_allocators): New.
(enum omp_mask2): Add new OMP_CLAUSE_USES_ALLOCATORS.
(OMP_TARGET_CLAUSES): Accept it.
(resolve_omp_clauses): Resolve uses_allocators clause
* st.cc (gfc_free_statement): Update gfc_free_omp_namelist call.
* trans-openmp.cc (gfc_trans_omp_clauses): Handle
OMP_LIST_USES_ALLOCATORS; fail with sorry unless predefined allocator.
(gfc_split_omp_clauses): Handle uses_allocators.

libgomp/ChangeLog:

* testsuite/libgomp.fortran/uses_allocators_1.f90: New test.
* testsuite/libgomp.fortran/uses_allocators_2.f90: New test.

Co-authored-by: Chung-Lin Tang <cltang@codesourcery.com>
2 years agoRestore bootstrap by removing unused variable in tree-ssa-loop-ivcanon.cc
Martin Jambor [Mon, 17 Jul 2023 12:22:06 +0000 (14:22 +0200)] 
Restore bootstrap by removing unused variable in tree-ssa-loop-ivcanon.cc

This restores bootstrap by removing the variable causing:

  /home/mjambor/gcc/trunk/src/gcc/tree-ssa-loop-ivcanon.cc: In function ‘bool try_peel_loop(loop*, edge, tree, bool, long int)’:
  /home/mjambor/gcc/trunk/src/gcc/tree-ssa-loop-ivcanon.cc:1170:17: error: variable ‘entry_count’ set but not used [-Werror=unused-but-set-variable]
   1170 |   profile_count entry_count = profile_count::zero ();
        |                 ^~~~~~~~~~~
  cc1plus: all warnings being treated as errors

gcc/ChangeLog:

2023-07-17  Martin Jambor  <mjambor@suse.cz>

* tree-ssa-loop-ivcanon.cc (try_peel_loop): Remove unused variable
entry_count.

2 years agofortran: Pass pre-calculated class container argument [pr110618]
Mikael Morin [Mon, 17 Jul 2023 12:14:22 +0000 (14:14 +0200)] 
fortran: Pass pre-calculated class container argument [pr110618]

Pass already evaluated class container argument from
gfc_conv_procedure_call down to gfc_add_finalizer_call through
gfc_deallocate_scalar_with_status and gfc_deallocate_with_status,
to avoid repeatedly evaluating the same data reference expressions
in the generated code.

PR fortran/110618

gcc/fortran/ChangeLog:

* trans.h (gfc_deallocate_with_status): Add class container
argument.
(gfc_deallocate_scalar_with_status): Ditto.
* trans.cc (gfc_deallocate_with_status): Add class container
argument and pass it down to gfc_add_finalize_call.
(gfc_deallocate_scalar_with_status): Same.
* trans-array.cc (structure_alloc_comps): Update caller.
* trans-stmt.cc (gfc_trans_deallocate): Ditto.
* trans-expr.cc (gfc_conv_procedure_call): Ditto.  Pass
pre-evaluated class container argument if it's available.

gcc/testsuite/ChangeLog:

* gfortran.dg/intent_out_22.f90: New test.

2 years agofortran: Use pre-evaluated class container if available [PR110618]
Mikael Morin [Mon, 17 Jul 2023 12:14:18 +0000 (14:14 +0200)] 
fortran: Use pre-evaluated class container if available [PR110618]

Add the possibility to provide a pre-evaluated class container argument
to gfc_add_finalizer to avoid repeatedly evaluating data reference
expressions in the generated code.

PR fortran/110618

gcc/fortran/ChangeLog:

* trans.h (gfc_add_finalizer_call): Add class container argument.
* trans.cc (gfc_add_finalizer_call): Ditto.  Pass down new
argument to get_final_proc_ref, get_elem_size, get_var_desc,
and get_vptr.
(get_elem_size): Add class container argument.
Use provided class container if it's available.
(get_var_descr): Same.
(get_vptr): Same.
(get_final_proc_ref): Same.  Add boolean telling the class
container argument is used.  Set it.  Don't try to use
final_wrapper if class container argument was used.

2 years agofortran: Factor scalar descriptor generation
Mikael Morin [Mon, 17 Jul 2023 12:14:14 +0000 (14:14 +0200)] 
fortran: Factor scalar descriptor generation

The same scalar descriptor generation code is present twice, in the
case of derived type entities, and in the case of polymorphic
non-coarray entities.  Factor it in preparation for a future third case
that will also need the same code for scalar descriptor generation.

gcc/fortran/ChangeLog:

* trans.cc (get_var_descr): Factor scalar descriptor generation.

2 years agofortran: Outline virtual table pointer evaluation
Mikael Morin [Mon, 17 Jul 2023 12:14:08 +0000 (14:14 +0200)] 
fortran: Outline virtual table pointer evaluation

gcc/fortran/ChangeLog:

* trans.cc (get_vptr): New function.
(gfc_add_finalizer_call): Move virtual table pointer evaluation
to get_vptr.

2 years agofortran: Remove redundant argument in get_var_descr
Mikael Morin [Mon, 17 Jul 2023 12:14:03 +0000 (14:14 +0200)] 
fortran: Remove redundant argument in get_var_descr

get_var_descr get passed as argument both expr and expr->ts.
Remove the type argument which can be retrieved from the other
argument.

gcc/fortran/ChangeLog:

* trans.cc (get_var_descr): Remove argument ts.  Use var->ts
instead.
(gfc_add_finalizer_call): Update caller.

2 years agofortran: Inline variable definition
Mikael Morin [Mon, 17 Jul 2023 12:13:58 +0000 (14:13 +0200)] 
fortran: Inline variable definition

The variable has_finalizer is only used in one place, inline its
definition there.

gcc/fortran/ChangeLog:

* trans.cc (gfc_add_finalizer_call): Inline definition of
variable has_finalizer.  Merge nested conditions.

2 years agofortran: Push final procedure expr gen close to its one usage.
Mikael Morin [Mon, 17 Jul 2023 12:13:53 +0000 (14:13 +0200)] 
fortran: Push final procedure expr gen close to its one usage.

Final procedure pointer expression is generated in gfc_build_final_call
and only used in get_final_proc_ref.  Move the generation there.

gcc/fortran/ChangeLog:

* trans.cc (gfc_add_finalizer_call): Remove local variable
final_expr.  Pass down expr to get_final_proc_ref and move
final procedure expression generation down to its one usage
in get_final_proc_ref.
(get_final_proc_ref): Add argument expr.  Remove argument
final_wrapper.  Recreate final_wrapper from expr.

2 years agofortran: Push element size expression generation close to its usage
Mikael Morin [Mon, 17 Jul 2023 12:13:48 +0000 (14:13 +0200)] 
fortran: Push element size expression generation close to its usage

gfc_add_finalizer_call creates one expression which is only used
by the get_final_proc_ref function.  Move the expression generation
there.

gcc/fortran/ChangeLog:

* trans.cc (gfc_add_finalizer_call): Remove local variable
elem_size.  Pass expression to get_elem_size and move the
element size expression generation close to its usage there.
(get_elem_size): Add argument expr, remove class_size argument
and rebuild it from expr.  Remove ts argument and use the
type of expr instead.

2 years agofortran: Reuse final procedure pointer expression
Mikael Morin [Mon, 17 Jul 2023 12:13:44 +0000 (14:13 +0200)] 
fortran: Reuse final procedure pointer expression

Reuse twice the same final procedure pointer expression instead of
translating it twice.
Final procedure pointer expressions were translated twice, once for the
final procedure call, and once for the check for non-nullness (if
applicable).

gcc/fortran/ChangeLog:

* trans.cc (gfc_add_finalizer_call): Move pre and post code for
the final procedure pointer expression to the outer block.
Reuse the previously evaluated final procedure pointer
expression.

2 years agofortran: Add missing cleanup blocks
Mikael Morin [Mon, 17 Jul 2023 12:13:37 +0000 (14:13 +0200)] 
fortran: Add missing cleanup blocks

Move cleanup code for the data descriptor after the finalization code
as it makes more sense to have it after.
Other cleanup blocks should be empty (element size and final pointer
are just data references), but add them by the way, just in case.

gcc/fortran/ChangeLog:

* trans.cc (gfc_add_finalizer_call): Add post code for desc_se
after the finalizer call.  Add post code for final_se and
size_se as well.

2 years agofortran: Inline gfc_build_final_call
Mikael Morin [Mon, 17 Jul 2023 12:13:32 +0000 (14:13 +0200)] 
fortran: Inline gfc_build_final_call

Function gfc_build_final_call has been simplified, inline it.

gcc/fortran/ChangeLog:

* trans.cc (gfc_build_final_call): Inline...
(gfc_add_finalizer_call): ... to its one caller.

2 years agofortran: Outline data reference descriptor evaluation
Mikael Morin [Mon, 17 Jul 2023 12:13:26 +0000 (14:13 +0200)] 
fortran: Outline data reference descriptor evaluation

gcc/fortran/ChangeLog:

* trans.cc (get_var_descr): New function.
(gfc_build_final_call): Outline the data reference descriptor
evaluation code to get_var_descr.

2 years agofortran: Outline element size evaluation
Mikael Morin [Mon, 17 Jul 2023 12:13:19 +0000 (14:13 +0200)] 
fortran: Outline element size evaluation

gcc/fortran/ChangeLog:

* trans.cc (get_elem_size): New function.
(gfc_build_final_call): Outline the element size evaluation
to get_elem_size.