]> git.ipfire.org Git - thirdparty/gcc.git/log
thirdparty/gcc.git
15 months agoDaily bump.
GCC Administrator [Wed, 31 May 2023 00:17:14 +0000 (00:17 +0000)] 
Daily bump.

15 months agoEnhance NARROW FLOAT_EXPR vectorization by truncating integer to lower precision.
liuhongt [Wed, 22 Feb 2023 09:54:46 +0000 (17:54 +0800)] 
Enhance NARROW FLOAT_EXPR vectorization by truncating integer to lower precision.

Similar like WIDEN FLOAT_EXPR, when direct_optab is not existed, try
intermediate integer type whenever gimple ranger can tell it's safe.

.i.e.
When there's no direct optab for vector long long -> vector float, but
the value range of integer can be represented as int, try vector int
-> vector float if availble.

gcc/ChangeLog:

PR tree-optimization/108804
* tree-vect-patterns.cc (vect_get_range_info): Remove static.
* tree-vect-stmts.cc (vect_create_vectorized_demotion_stmts):
Add new parameter narrow_src_p.
(vectorizable_conversion): Enhance NARROW FLOAT_EXPR
vectorization by truncating to lower precision.
* tree-vectorizer.h (vect_get_range_info): New declare.

gcc/testsuite/ChangeLog:

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

15 months agotestsuite: add verify-sarif-file to some testcases that were missing it
David Malcolm [Tue, 30 May 2023 22:57:57 +0000 (18:57 -0400)] 
testsuite: add verify-sarif-file to some testcases that were missing it

gcc/testsuite/ChangeLog:
* gcc.dg/analyzer/malloc-sarif-1.c: Add missing verify-sarif-file
directive.
* gcc.dg/analyzer/sarif-pr107366.c: Likewise.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
15 months ago[libstdc++] [testsuite] xfail double-prec from_chars for x86_64 ldbl
Alexandre Oliva [Tue, 30 May 2023 21:32:32 +0000 (18:32 -0300)] 
[libstdc++] [testsuite] xfail double-prec from_chars for x86_64 ldbl

When long double is wider than double, but from_chars is implemented
in terms of double, tests that involve the full precision of long
double are expected to fail.  Mark them as such on x86_64-*-vxworks*.

for  libstdc++-v3/ChangeLog

* testsuite/20_util/from_chars/4.cc: Skip long double test06
on x86_64-vxworks.
* testsuite/20_util/to_chars/long_double.cc: Xfail run on
x86_64-vxworks.

15 months agotestsuite/52641: Fix more of implicit int=32 assumption fallout.
Georg-Johann Lay [Tue, 30 May 2023 20:04:57 +0000 (22:04 +0200)] 
testsuite/52641: Fix more of implicit int=32 assumption fallout.

gcc/testsuite/
PR testsuite/52641
* gcc.dg/torture/pr107451.c: Require int32plus.
* gcc.dg/torture/pr108574-3.c: Use __INT32_TYPE__ instead of int.
* gcc.dg/torture/pr109940.c: Use __INTPTR_TYPE__ instead of long.
* gcc.dg/torture/pr95248.c: Require size24plus.
* gcc.dg/torture/pr95295-3.c: Use var_* with at least 32 bits int.
* gcc.dg/torture/pr98640.c: Cast to __INT32_TYPE__ instead of int.
* gcc.dg/tree-ssa/pr103771.c: Use int with at least 32 bits.

15 months agoLRA: Update insn sp offset if its input reload changes SP
Vladimir N. Makarov [Tue, 30 May 2023 19:54:28 +0000 (15:54 -0400)] 
LRA: Update insn sp offset if its input reload changes SP

The patch fixes a bug when there is input reload changing SP.  The bug was
triggered by switching H8300 target to LRA.  The insn in question is

(insn 21 20 22 2 (set (mem/f:SI (pre_dec:SI (reg/f:SI 7 sp)) [3  S4 A32])
        (reg/f:SI 31)) "j.c":10:3 19 {*movsi}
     (expr_list:REG_DEAD (reg/f:SI 31)
        (expr_list:REG_ARGS_SIZE (const_int 4 [0x4])
            (nil))))

The memory address is reloaded but the SP offset for the original insn was not updated.

gcc/ChangeLog:

* lra-int.h (lra_update_sp_offset): Add the prototype.
* lra.cc (setup_sp_offset): Change the return type.  Use
lra_update_sp_offset.
* lra-eliminations.cc (lra_update_sp_offset): New function.
(lra_process_new_insns): Push the current insn to reprocess if the
input reload changes sp offset.

15 months agoi386: Fix misleading identation in i386-expand.cc [PR110041]
Uros Bizjak [Tue, 30 May 2023 18:38:20 +0000 (20:38 +0200)] 
i386: Fix misleading identation in i386-expand.cc [PR110041]

gcc/ChangeLog:

PR target/110041
* config/i386/i386-expand.cc (ix86_expand_vecop_qihi2):
Fix misleading identation.

15 months agojump: Change return type of predicate functions from int to bool
Uros Bizjak [Tue, 30 May 2023 14:33:40 +0000 (16:33 +0200)] 
jump: Change return type of predicate functions from int to bool

gcc/ChangeLog:

* rtl.h (comparison_dominates_p): Change return type from int to bool.
(condjump_p): Ditto.
(any_condjump_p): Ditto.
(any_uncondjump_p): Ditto.
(simplejump_p): Ditto.
(returnjump_p): Ditto.
(eh_returnjump_p): Ditto.
(onlyjump_p): Ditto.
(invert_jump_1): Ditto.
(invert_jump): Ditto.
(rtx_renumbered_equal_p): Ditto.
(redirect_jump_1): Ditto.
(redirect_jump): Ditto.
(condjump_in_parallel_p): Ditto.
* jump.cc (invert_exp_1): Adjust forward declaration.
(comparison_dominates_p): Change return type from int to bool
and adjust function body accordingly.
(simplejump_p): Ditto.
(condjump_p): Ditto.
(condjump_in_parallel_p): Ditto.
(any_uncondjump_p): Ditto.
(any_condjump_p): Ditto.
(returnjump_p): Ditto.
(eh_returnjump_p): Ditto.
(onlyjump_p): Ditto.
(redirect_jump_1): Ditto.
(redirect_jump): Ditto.
(invert_exp_1): Ditto.
(invert_jump_1): Ditto.
(invert_jump): Ditto.
(rtx_renumbered_equal_p): Ditto.

15 months agoMAINTAINERS: Add myself to write after approval
Jeevitha [Tue, 30 May 2023 16:02:37 +0000 (11:02 -0500)] 
MAINTAINERS: Add myself to write after approval

2023-05-30  Jeevitha Palanisamy  <jeevitha@linux.ibm.com>

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

15 months agotestsuite: make mve_intrinsic_type_overloads-int.c libc-agnostic
Christophe Lyon [Tue, 23 May 2023 14:30:53 +0000 (14:30 +0000)] 
testsuite: make mve_intrinsic_type_overloads-int.c libc-agnostic

Glibc defines int32_t as 'int' while newlib defines it as 'long int'.

Although these correspond to the same size, g++ complains when using the
'wrong' version:
  invalid conversion from 'long int*' to 'int32_t*' {aka 'int*'} [-fpermissive]
or
  invalid conversion from 'int*' to 'int32_t*' {aka 'long int*'} [-fpermissive]

when calling vst1q(int32*, int32x4_t) with a first parameter of type
'long int *' (resp. 'int *')

To make this test pass with any type of toolchain, this patch defines
'word_type' according to which libc is in use.

2023-05-23  Christophe Lyon  <christophe.lyon@linaro.org>

gcc/testsuite/
* gcc.target/arm/mve/intrinsics/mve_intrinsic_type_overloads-int.c:
Support both definitions of int32_t.

15 months agoAdd a != MIN/MAX_VALUE_CST ? CST-+1 : a to minmax_from_comparison
Andrew Pinski [Tue, 16 May 2023 21:26:41 +0000 (14:26 -0700)] 
Add a != MIN/MAX_VALUE_CST ? CST-+1 : a to minmax_from_comparison

This patch adds the support for match that was implemented for PR 87913 in phiopt.
It implements it by adding support to minmax_from_comparison for the check.
It uses the range information if available which allows to produce MIN/MAX expression
when comparing against the lower/upper bound of the range instead of lower/upper
of the type.

minmax-20.c is the new testcase which tests the ranges part.

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

gcc/ChangeLog:

* fold-const.cc (minmax_from_comparison): Add support for NE_EXPR.
* match.pd ((cond (cmp (convert1? x) c1) (convert2? x) c2) pattern):
Add ne as a possible cmp.
((a CMP b) ? minmax<a, c> : minmax<b, c> pattern): Likewise.

gcc/testsuite/ChangeLog:

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

15 months agoMATCH: Move `a <= CST1 ? MAX<a, CST2> : a` optimization to match
Andrew Pinski [Sun, 7 May 2023 18:39:03 +0000 (11:39 -0700)] 
MATCH: Move `a <= CST1 ? MAX<a, CST2> : a` optimization to match

This moves the `a <= CST1 ? MAX<a, CST2> : a` optimization
from phiopt to match. It just adds a new pattern to match.pd.

There is one more change needed before being able to remove
minmax_replacement from phiopt.

A few notes on the testsuite changes:
* phi-opt-5.c is now able to optimize at phiopt1 so remove
the xfail.
* pr66726-4.c can be optimized during fold before phiopt1
so need to change the scanning.
* pr66726-5.c needs two phiopt passes currently to optimize
to the right thing, it needed 2 phiopt passes before, the cast
from int to unsigned char is the reason.
* pr66726-6.c is what the original pr66726-4.c was testing
before the fold was able to optimize it.

OK? Bootstrapped and tested on x86_64-linux-gnu.

gcc/ChangeLog:

* match.pd (`(a CMP CST1) ? max<a,CST2> : a`): New
pattern.

gcc/testsuite/ChangeLog:

* gcc.dg/tree-ssa/phi-opt-5.c: Remove last xfail.
* gcc.dg/tree-ssa/pr66726-4.c: Change how scanning
works.
* gcc.dg/tree-ssa/pr66726-5.c: New test.
* gcc.dg/tree-ssa/pr66726-6.c: New test.

15 months agoFix ACLE data-intrinsics testcases
Christophe Lyon [Tue, 30 May 2023 13:45:13 +0000 (13:45 +0000)] 
Fix ACLE data-intrinsics testcases

data-intrinsics-assembly.c forces -march=armv6 using dg-add-options
arm_arch_v6, which implicitly adds -mfloat-abi=softfp.

However, for a toolchain configured for arm-linux-gnueabihf and
--with-arch=armv7-a, the testcase will fail when including arm_acle.h
(which includes stdint.h, which will fail to include the non-existing
gnu/stubs-soft.h).

Other effective-targets related to arm_acle.h would also pass because
they first try without -mfloat-abi=softfp, so it seems the
simplest/safest is to add { dg-require-effective-target arm_softfp_ok }
to make sure arm_arch_v6_ok's assumption is valid.

The patch also fixes what seems to be an oversight in
data-intrinsics-armv6.c: it requires arm_arch_v6_ok, but uses
arm_arch_v6t2: the patch makes it require arm_arch_v6t2_ok.

2023-05-30  Christophe Lyon  <christophe.lyon@linaro.org>

gcc/testsuite/
* gcc.target/arm/acle/data-intrinsics-armv6.c: Fix typo.
* gcc.target/arm/acle/data-intrinsics-assembly.c: Require
arm_softfp_ok.

15 months agolibstdc++: Correct NTTP and simd_mask ctor call
Matthias Kretz [Fri, 26 May 2023 10:23:44 +0000 (12:23 +0200)] 
libstdc++: Correct NTTP and simd_mask ctor call

Signed-off-by: Matthias Kretz <m.kretz@gsi.de>
libstdc++-v3/ChangeLog:

PR libstdc++/109822
* include/experimental/bits/simd.h (to_native): Use int NTTP
as specified in PTS2.
(to_compatible): Likewise. Add missing tag to call mask
generator ctor.
* testsuite/experimental/simd/pr109822_cast_functions.cc: New
test.

15 months agolibstdc++: Simplify calculation of expected value in simd test
Matthias Kretz [Thu, 25 May 2023 10:53:06 +0000 (12:53 +0200)] 
libstdc++: Simplify calculation of expected value in simd test

This avoids a failure on PR109964.

Signed-off-by: Matthias Kretz <m.kretz@gsi.de>
libstdc++-v3/ChangeLog:

* testsuite/experimental/simd/tests/integer_operators.cc:
Compute expected value differently to avoid getting turned into
a vector shift.

15 months agolibstdc++: Fix test assumptions on long and long double
Matthias Kretz [Thu, 25 May 2023 10:07:45 +0000 (12:07 +0200)] 
libstdc++: Fix test assumptions on long and long double

Expect that long might not fit into the long double mantissa bits.

Signed-off-by: Matthias Kretz <m.kretz@gsi.de>
libstdc++-v3/ChangeLog:

* testsuite/experimental/simd/tests/operator_cvt.cc: Make long
double <-> (u)long conversion tests conditional on sizeof(long
double) and sizeof(long).

15 months agoReplace a HWI_COMPUTABLE_MODE_P with wide-int in simplify-rtx.cc.
Roger Sayle [Tue, 30 May 2023 13:46:45 +0000 (14:46 +0100)] 
Replace a HWI_COMPUTABLE_MODE_P with wide-int in simplify-rtx.cc.

This patch enhances one of the optimizations in simplify_binary_operation_1
to allow it to simplify RTL expressions in modes wider than HOST_WIDE_INT
by replacing a use of HWI_COMPUTABLE_MODE_P and UINTVAL with wide_int.

The motivating example is a pending x86_64 backend patch that produces
the following RTL in combine:

(and:TI (zero_extend:TI (reg:DI 89))
        (const_wide_int 0x0ffffffffffffffff))

where the AND is redundant, as the mask, ~0LL, is DImode's MODE_MASK.
There's already an optimization that catches this for narrower modes,
transforming (and:HI (zero_extend:HI (reg:QI x)) (const_int 0xff))
into (zero_extend:HI (reg:QI x)), but this currently only handles
CONST_INT not CONST_WIDE_INT.  Fixed by upgrading this transformation
to use wide_int, specifically rtx_mode_t and wi::mask.

2023-05-30  Roger Sayle  <roger@nextmovesoftware.com>

gcc/ChangeLog
* simplify-rtx.cc (simplify_binary_operation_1) <AND>: Use wide-int
instead of HWI_COMPUTABLE_MODE_P and UINTVAL in transformation of
(and (extend X) C) as (zero_extend (and X C)), to also optimize
modes wider than HOST_WIDE_INT.

15 months agoPR target/107172: Avoid "unusual" MODE_CC comparisons in simplify-rtx.cc
Roger Sayle [Tue, 30 May 2023 13:40:50 +0000 (14:40 +0100)] 
PR target/107172: Avoid "unusual" MODE_CC comparisons in simplify-rtx.cc

I believe that a better (or supplementary) fix to PR target/107172 is to
avoid producing incorrect (but valid) RTL in
simplify_const_relational_operation when presented with questionable
(obviously invalid) expressions, such as those produced during combine.
Just as with the "first do no harm" clause with the Hippocratic Oath,
simplify-rtx (probably) shouldn't unintentionally transform invalid RTL
expressions, into incorrect (non-equivalent) but valid RTL that may be
inappropriately recognized by recog.

In this specific case, many GCC backends represent their flags register via
MODE_CC, whose representation is intentionally "opaque" to the middle-end.
The only use of MODE_CC comprehensible to the middle-end's RTL optimizers
is relational comparisons between the result of a COMPARE rtx (op0) and zero
(op1).  Any other uses of MODE_CC should be left alone, and some might argue
indicate representational issues in the backend.

In practice, CPUs occasionally have numerous instructions that affect the
flags register(s) other than comparisons [AVR's setc, powerpc's mtcrf,
x86's clc, stc and cmc and x86_64's ptest that sets C and Z flags in
non-obvious ways, c.f. PR target/109973].  Currently care has to be taken,
wrapping these in UNSPEC, to avoid combine inappropriately merging flags
setters with flags consumers (such as conditional jumps).  It's safer to
teach simplify_const_relational_operation not to modify expressions that
it doesn't understand/recognize.

2023-05-30  Roger Sayle  <roger@nextmovesoftware.com>

gcc/ChangeLog
PR target/107172
* simplify-rtx.cc (simplify_const_relational_operation): Return
early if we have a MODE_CC comparison that isn't a COMPARE against
const0_rtx.

15 months agoOpenMP: Improve C/C++ parsing error message [PR109999]
Tobias Burnus [Tue, 30 May 2023 10:49:09 +0000 (12:49 +0200)] 
OpenMP: Improve C/C++ parsing error message [PR109999]

Replace
  error: expected '#pragma omp' clause before ...
by the the more readable/clearer
  error: expected an OpenMP clause before ...

(And likewise for '#pragma acc' and OpenACC.)

PR c/109999

gcc/c/ChangeLog:

* c-parser.cc (c_parser_oacc_all_clauses,
c_parser_omp_all_clauses): Improve error wording.

gcc/cp/ChangeLog:

* parser.cc (cp_parser_oacc_all_clauses,
cp_parser_omp_all_clauses): Improve error wording.

gcc/testsuite/ChangeLog:

* c-c++-common/goacc/asyncwait-1.c: Update dg-error.
* c-c++-common/goacc/clauses-fail.c: Likewise.
* c-c++-common/goacc/data-2.c: Likewise.
* c-c++-common/gomp/declare-target-2.c: Likewise.
* c-c++-common/gomp/directive-1.c: Likewise.
* g++.dg/goacc/data-1.C: Likewise.

15 months agoRISC-V: Allow all const_vec_duplicates as constants.
Robin Dapp [Mon, 22 May 2023 18:41:59 +0000 (20:41 +0200)] 
RISC-V: Allow all const_vec_duplicates as constants.

As we can always broadcast an integer constant to a vector register
allow them in riscv_const_insns.  We need as many instructions as
it takes to generate the constant and one vmv.vx.

gcc/ChangeLog:

* config/riscv/riscv.cc (riscv_const_insns): Allow
const_vec_duplicates.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/autovec/vmv-imm-fixed-rv32.c: Add vmv.v.x
tests.
* gcc.target/riscv/rvv/autovec/vmv-imm-fixed-rv64.c: Dito.
* gcc.target/riscv/rvv/autovec/vmv-imm-run.c: Dito.
* gcc.target/riscv/rvv/autovec/vmv-imm-rv32.c: Dito.
* gcc.target/riscv/rvv/autovec/vmv-imm-rv64.c: Dito.
* gcc.target/riscv/rvv/autovec/vmv-imm-template.h: Dito.

15 months agoDetect bswap + rotate for byte permutation in pass_bswap.
liuhongt [Mon, 6 Mar 2023 07:35:37 +0000 (15:35 +0800)] 
Detect bswap + rotate for byte permutation in pass_bswap.

The patch doesn't handle:
  1. cast64_to_32,
  2. memory source with rsize < range.

gcc/ChangeLog:

PR middle-end/108938
* gimple-ssa-store-merging.cc (is_bswap_or_nop_p): New
function, cut from original find_bswap_or_nop function.
(find_bswap_or_nop): Add a new parameter, detect bswap +
rotate and save rotate result in the new parameter.
(bswap_replace): Add a new parameter to indicate rotate and
generate rotate stmt if needed.
(maybe_optimize_vector_constructor): Adjust for new rotate
parameter in the upper 2 functions.
(pass_optimize_bswap::execute): Ditto.
(imm_store_chain_info::output_merged_store): Ditto.

gcc/testsuite/ChangeLog:

* gcc.target/i386/pr108938-1.c: New test.
* gcc.target/i386/pr108938-2.c: New test.
* gcc.target/i386/pr108938-3.c: New test.
* gcc.target/i386/pr108938-load-1.c: New test.
* gcc.target/i386/pr108938-load-2.c: New test.

15 months agoaarch64: Convert ADDLP and ADALP patterns to standard RTL codes
Kyrylo Tkachov [Tue, 30 May 2023 09:41:02 +0000 (10:41 +0100)] 
aarch64: Convert ADDLP and ADALP patterns to standard RTL codes

This patch converts the patterns for the integer widen and pairwise-add instructions
to standard RTL operations. The pairwise addition withing a vector can be represented
as an addition of two vec_selects, one selecting the even elements, and one selecting odd.
Thus for the intrinsic vpaddlq_s8 we can generate:
(set (reg:V8HI 92)
        (plus:V8HI (vec_select:V8HI (sign_extend:V16HI (reg/v:V16QI 93 [ a ]))
                (parallel [
                        (const_int 0 [0])
                        (const_int 2 [0x2])
                        (const_int 4 [0x4])
                        (const_int 6 [0x6])
                        (const_int 8 [0x8])
                        (const_int 10 [0xa])
                        (const_int 12 [0xc])
                        (const_int 14 [0xe])
                    ]))
            (vec_select:V8HI (sign_extend:V16HI (reg/v:V16QI 93 [ a ]))
                (parallel [
                        (const_int 1 [0x1])
                        (const_int 3 [0x3])
                        (const_int 5 [0x5])
                        (const_int 7 [0x7])
                        (const_int 9 [0x9])
                        (const_int 11 [0xb])
                        (const_int 13 [0xd])
                        (const_int 15 [0xf])
                    ]))))

Similarly for the accumulating forms where there's an extra outer PLUS for the accumulation.
We already have the handy helper functions aarch64_stepped_int_parallel_p and
aarch64_gen_stepped_int_parallel defined in aarch64.cc that we can make use of to define
the right predicate for the VEC_SELECT PARALLEL.

This patch allows us to remove some code iterators and the UNSPEC definitions for SADDLP and UADDLP.
UNSPEC_UADALP and UNSPEC_SADALP are retained because they are used by SVE2 patterns still.

Bootstrapped and tested on aarch64-none-linux-gnu and aarch64_be-none-elf.

gcc/ChangeLog:

* config/aarch64/aarch64-simd.md (aarch64_<sur>adalp<mode>): Delete.
(aarch64_<su>adalp<mode>): New define_expand.
(*aarch64_<su>adalp<mode><vczle><vczbe>_insn): New define_insn.
(aarch64_<su>addlp<mode>): Convert to define_expand.
(*aarch64_<su>addlp<mode><vczle><vczbe>_insn): New define_insn.
* config/aarch64/iterators.md (UNSPEC_SADDLP, UNSPEC_UADDLP): Delete.
(ADALP): Likewise.
(USADDLP): Likewise.
* config/aarch64/predicates.md (vect_par_cnst_even_or_odd_half): Define.

15 months agoaarch64: Reimplement v(r)hadd and vhsub intrinsics with RTL codes
Kyrylo Tkachov [Tue, 30 May 2023 09:36:46 +0000 (10:36 +0100)] 
aarch64: Reimplement v(r)hadd and vhsub intrinsics with RTL codes

This patch reimplements the MD patterns for the UHADD,SHADD,UHSUB,SHSUB,URHADD,SRHADD instructions using
standard RTL operations rather than unspecs. The correct RTL representations involves widening
the inputs before adding them and halving, followed by a truncation back to the original mode.
An unfortunate wart in the patch is that we end up having very similar expanders for the intrinsics
through the aarch64_<su>h<ADDSUB:optab><mode> and aarch64_<su>rhadd<mode> names and the standard names
for the vector averaging optabs <su>avg<mode>3_floor and <su>avg<mode>3_ceil.
I'd like to reuse <su>avg<mode>3_ceil for the intrinsics builtin as well but our scheme
in aarch64-simd-builtins.def and aarch64-builtins.cc makes it awkward by only allowing mappings
of entries in aarch64-simd-builtins.def to:
   0 - CODE_FOR_aarch64_<name><mode>
   1-9 - CODE_FOR_<name><mode><1-9>
   10 - CODE_FOR_<name><mode>

whereas here we want a string after the <mode> i.e. CODE_FOR_uavg<mode>3_ceil.
This patch adds a bit of remapping logic in aarch64-builtins.cc before the construction of the
builtin info that remaps the CODE_FOR_* definitions in aarch64-simd-builtins.def to the
optab-derived ones. CODE_FOR_aarch64_srhaddv4si gets remapped to CODE_FOR_avgv4si3_ceil, for example.
It's a bit specific to this case, but this solution requires the least invasive changes while avoiding
having duplicate expanders just for the sake of a different pattern name.

Bootstrapped and tested on aarch64-none-linux-gnu and aarch64_be-none-elf.

gcc/ChangeLog:

* config/aarch64/aarch64-builtins.cc (VAR1): Move to after inclusion of
aarch64-builtin-iterators.h.  Add definition to remap shadd, uhadd,
srhadd, urhadd builtin codes for standard optab ones.
* config/aarch64/aarch64-simd.md (<u>avg<mode>3_floor): Rename to...
(<su_optab>avg<mode>3_floor): ... This.  Expand to RTL codes rather than
unspec.
(<u>avg<mode>3_ceil): Rename to...
(<su_optab>avg<mode>3_ceil): ... This.  Expand to RTL codes rather than
unspec.
(aarch64_<su>hsub<mode>): New define_expand.
(aarch64_<sur>h<addsub><mode><vczle><vczbe>): Split into...
(*aarch64_<su>h<ADDSUB:optab><mode><vczle><vczbe>_insn): ... This...
(*aarch64_<su>rhadd<mode><vczle><vczbe>_insn): ... And this.

15 months agoriscv: add work around for PR sanitizer/82501
Andreas Schwab [Mon, 29 May 2023 07:33:52 +0000 (09:33 +0200)] 
riscv: add work around for PR sanitizer/82501

gcc/testsuite/
PR sanitizer/82501
* c-c++-common/asan/pointer-compare-1.c: Disable use of small data
on RISC-V.

15 months agoriscv: update riscv_asan_shadow_offset
Andreas Schwab [Sun, 28 May 2023 10:08:22 +0000 (12:08 +0200)] 
riscv: update riscv_asan_shadow_offset

gcc/
PR target/110036
* config/riscv/riscv.cc (riscv_asan_shadow_offset): Update to
match libsanitizer.

15 months agostor-layout, aarch64: Express SRA intrinsics with RTL codes
Kyrylo Tkachov [Tue, 30 May 2023 08:56:29 +0000 (09:56 +0100)] 
stor-layout, aarch64: Express SRA intrinsics with RTL codes

This patch expresses the intrinsics for the SRA and RSRA instructions with
standard RTL codes rather than relying on UNSPECs.
These instructions perform a vector shift right plus accumulate with an
optional rounding constant addition for the RSRA variant.
There are a number of interesting points:

* The scalar-in-SIMD-registers variant for DImode SRA e.g. ssra d0, d1, #N
is left using the UNSPECs. Expressing it as a DImode plus+shift led to all
kinds of trouble as it started matching the existing define_insns for
"add x0, x0, asr #N" instructions and adding the SRA form as an extra
alternative required a significant amount of deduplication of iterators and
things still didn't work out well. I decided not to tackle that case in
this patch. It can be attempted later.

* For the RSRA variants that add a rounding constant (1 << (shift-1)) the
addition is notionally performed in a wider mode than the input types so that
overflow is handled properly. In RTL this can be represented with an appropriate
extend operation followed by a truncate back to the original modes.
However for 128-bit input modes such as V4SI we don't have appropriate modes
defined for this widening i.e. we'd need a V4DI mode to represent the
intermediate widened result.  This patch defines such modes for
V16HI,V8SI,V4DI,V2TI. These will come handy in the future too as we have
more Advanced SIMD instruction that have similar intermediate widening
semantics.

* The above new modes led to a problem with stor-layout.cc. The new modes only
exist for the sake of the RTL optimisers understanding the semantics of the
instruction but are not indended to be moved to and from register or memory,
assigned to types, used as TYPE_MODE or participate in auto-vectorisation.
This is expressed in aarch64 by aarch64_classify_vector_mode returning zero
for these new modes. However, the code in stor-layout.cc:<mode_for_vector>
explicitly doesn't check this when picking a TYPE_MODE due to modes being made
potentially available later through target switching (PR38240).
This led to these modes being picked as TYPE_MODE for declarations such as:
typedef int16_t vnx8hi __attribute__((vector_size (32))) when 256-bit
fixed-length SVE modes are available and vector_type_mode later struggling
to rectify this.
This issue is addressed with the new target hook
TARGET_VECTOR_MODE_SUPPORTED_ANY_TARGET_P that is intended to check if a
vector mode can be used in any legal target attribute configuration of the
port, as opposed to the existing TARGET_VECTOR_MODE_SUPPORTED_P that checks
only the initial target configuration. This allows a simple adjustment in
stor-layout.cc that still disqualifies these limited modes early on while
allowing consideration of modes that can be turned on in the future with
target attributes.

Bootstrapped and tested on aarch64-none-linux-gnu.

gcc/ChangeLog:

* config/aarch64/aarch64-modes.def (V16HI, V8SI, V4DI, V2TI): New modes.
* config/aarch64/aarch64-protos.h (aarch64_const_vec_rnd_cst_p):
Declare prototype.
(aarch64_const_vec_rsra_rnd_imm_p): Likewise.
* config/aarch64/aarch64-simd.md (*aarch64_simd_sra<mode>): Rename to...
(aarch64_<sra_op>sra_n<mode>_insn): ... This.
(aarch64_<sra_op>rsra_n<mode>_insn): New define_insn.
(aarch64_<sra_op>sra_n<mode>): New define_expand.
(aarch64_<sra_op>rsra_n<mode>): Likewise.
(aarch64_<sur>sra_n<mode>): Rename to...
(aarch64_<sur>sra_ndi): ... This.
* config/aarch64/aarch64.cc (aarch64_classify_vector_mode): Add
any_target_p argument.
(aarch64_extract_vec_duplicate_wide_int): Define.
(aarch64_const_vec_rsra_rnd_imm_p): Likewise.
(aarch64_const_vec_rnd_cst_p): Likewise.
(aarch64_vector_mode_supported_any_target_p): Likewise.
(TARGET_VECTOR_MODE_SUPPORTED_ANY_TARGET_P): Likewise.
* config/aarch64/iterators.md (UNSPEC_SRSRA, UNSPEC_URSRA): Delete.
(VSRA): Adjust for the above.
(sur): Likewise.
(V2XWIDE): New mode_attr.
(vec_or_offset): Likewise.
(SHIFTEXTEND): Likewise.
* config/aarch64/predicates.md (aarch64_simd_rsra_rnd_imm_vec): New
predicate.
* doc/tm.texi (TARGET_VECTOR_MODE_SUPPORTED_P): Adjust description to
clarify that it applies to current target options.
(TARGET_VECTOR_MODE_SUPPORTED_ANY_TARGET_P): Document.
* doc/tm.texi.in: Regenerate.
* stor-layout.cc (mode_for_vector): Check
vector_mode_supported_any_target_p when iterating through vector modes.
* target.def (TARGET_VECTOR_MODE_SUPPORTED_P): Adjust description to
clarify that it applies to current target options.
(TARGET_VECTOR_MODE_SUPPORTED_ANY_TARGET_P): Define.

15 months agoada: Fix wrong access for qualified aggregate with storage model
Eric Botcazou [Wed, 12 Apr 2023 17:18:24 +0000 (19:18 +0200)] 
ada: Fix wrong access for qualified aggregate with storage model

The previous fix to get_storage_model_access was incomplete and needs to be
extended to the node itself.

gcc/ada/

* gcc-interface/trans.cc (get_storage_model_access): Also strip any
type conversion in the node when unwinding the components.

15 months agoada: Fix internal error on qualified aggregate with storage model
Eric Botcazou [Fri, 7 Apr 2023 16:03:16 +0000 (18:03 +0200)] 
ada: Fix internal error on qualified aggregate with storage model

It comes from a small oversight in get_storage_model_access.

gcc/ada/

* gcc-interface/trans.cc (node_is_component): Remove parentheses.
(node_is_type_conversion): New predicate.
(get_atomic_access): Use it.
(get_storage_model_access): Likewise and look into the parent to
find a component if it returns true.
(present_in_lhs_or_actual_p): Likewise.

15 months agoada: Add missing guards for degenerate storage models
Eric Botcazou [Fri, 7 Apr 2023 13:51:16 +0000 (15:51 +0200)] 
ada: Add missing guards for degenerate storage models

gcc/ada/

* gcc-interface/trans.cc (Attribute_to_gnu) <Attr_Size>: Check that
the storage model has Copy_From before instantiating loads for it.
<Attr_Length>: Likewise.
<Attr_Bit_Position>: Likewise.
(gnat_to_gnu) <N_Indexed_Component>: Likewise.
<N_Slice>: Likewise.

15 months agoada: Fix incorrect copies being used with 'Address
Marc Poulhiès [Mon, 3 Apr 2023 14:36:13 +0000 (16:36 +0200)] 
ada: Fix incorrect copies being used with 'Address

When using 'Address on an object with a size clause, gigi would end up
creating a copy and using its address instead of the one of the original
object, leading to incorrect behavior. Remove the conversion (that
triggers the copy) when 'Address is applied to a declaration.

gcc/ada/

* gcc-interface/trans.cc (Attribute_to_gnu): Also strip conversion
in case of DECL.

15 months agoada: Fix bogus Storage_Error on dynamic array with static zero length
Eric Botcazou [Mon, 13 Mar 2023 22:01:54 +0000 (23:01 +0100)] 
ada: Fix bogus Storage_Error on dynamic array with static zero length

This works around the limitations present for the support of arrays in the
middle-end by clearing the TREE_OVERFLOW flag for arrays with zero length.

gcc/ada/

* gcc-interface/decl.cc (gnat_to_gnu_entity) <E_Array_Type>: Use a
local variable for the GNAT index type.
<E_Array_Subtype>: Likewise.  Call Is_Null_Range on the bounds and
force the zero on TYPE_SIZE and TYPE_SIZE_UNIT if it returns true.

15 months agoada: Fix minor issue with Mod operator
Eric Botcazou [Fri, 24 Feb 2023 15:14:30 +0000 (16:14 +0100)] 
ada: Fix minor issue with Mod operator

gcc/ada/

* gcc-interface/trans.cc (gnat_to_gnu) <N_Op_Mod>: Test the
precision of the operation rather than that of the result type.

15 months agoada: Minor generic tweaks left and and right
Eric Botcazou [Wed, 22 Feb 2023 16:22:11 +0000 (17:22 +0100)] 
ada: Minor generic tweaks left and and right

No functional changes.

gcc/ada/

* gcc-interface/decl.cc (gnat_to_gnu_entity) <E_Variable>: Replace
integer_zero_node with null_pointer_node for pointer types.
* gcc-interface/trans.cc (gnat_gimplify_expr) <NULL_EXPR>: Likewise.
* gcc-interface/utils.cc (maybe_pad_type): Do not attempt to make a
packable type from a fat pointer type.
* gcc-interface/utils2.cc (build_atomic_load): Use a local variable.
(build_atomic_store): Likewise.

15 months agoada: Make internal_error_function more robust
Eric Botcazou [Thu, 26 Jan 2023 23:05:37 +0000 (00:05 +0100)] 
ada: Make internal_error_function more robust

gcc/ada/

* gcc-interface/misc.cc (internal_error_function): Be prepared for
an input_location set to UNKNOWN_LOCATION.

15 months agoada: Adjust again the implementation of storage models
Eric Botcazou [Wed, 25 Jan 2023 14:59:19 +0000 (15:59 +0100)] 
ada: Adjust again the implementation of storage models

The code generator must now be prepared to translate assignment statements
to objects allocated with a storage model and that are not initialized yet.

gcc/ada/

* gcc-interface/trans.cc (Attribute_to_gnu) <Attr_Size>: Tweak.
(gnat_to_gnu) <N_Assignment_Statement>: Declare a local variable.
For a target with a storage model, use the Actual_Designated_Subtype
to compute the size if it is present.

15 months agoada: Simplify the implementation of storage models
Eric Botcazou [Tue, 24 Jan 2023 09:26:00 +0000 (10:26 +0100)] 
ada: Simplify the implementation of storage models

As the additional temporaries required by the semantics of nonnative storage
models are now created by the front-end, in particular for actual parameters
and assignment statements, the corresponding code in gigi can be removed.

gcc/ada/

* gcc-interface/trans.cc (Call_to_gnu): Remove code implementing the
by-copy semantics for actuals with nonnative storage models.
(gnat_to_gnu) <N_Assignment_Statement>: Remove code instantiating a
temporary for assignments between nonnative storage models.

15 months agoada: Make use of Cannot_Be_Superflat flag on N_Range nodes
Eric Botcazou [Wed, 18 Jan 2023 23:37:18 +0000 (00:37 +0100)] 
ada: Make use of Cannot_Be_Superflat flag on N_Range nodes

gcc/ada/

* gcc-interface/decl.cc (range_cannot_be_superflat): Return true
immediately if Cannot_Be_Superflat is set.
* gcc-interface/misc.cc (gnat_post_options): Do not override the
-Wstringop-overflow setting.

15 months agoada: Disable PIE mode during the build of the Ada front-end
Eric Botcazou [Fri, 6 Jan 2023 17:14:30 +0000 (18:14 +0100)] 
ada: Disable PIE mode during the build of the Ada front-end

This also removes some obsolete stuff.

gcc/ada/

* gcc-interface/Make-lang.in (ADA_CFLAGS): Move up.
(ALL_ADAFLAGS): Add $(NO_PIE_CFLAGS).
(ada/mdll.o): Remove.
(ada/mdll-fil.o): Likewise.
(ada/mdll-utl.o): Likewise.

15 months agoada: Fix storage model handling for dereference as lvalue and renamings
Marc Poulhiès [Tue, 20 Dec 2022 14:54:00 +0000 (15:54 +0100)] 
ada: Fix storage model handling for dereference as lvalue and renamings

Don't require storage access for explicit dereferences used as
lvalue (e.g. Some_Access.all'Address) or for renamings.

gcc/ada/

* gcc-interface/trans.cc (get_storage_model_access): Don't require
storage model access for dereference used as lvalue or renamings.

15 months agoada: Small cleanups and fixes in expansion of aggregates
Eric Botcazou [Mon, 17 Apr 2023 13:19:06 +0000 (15:19 +0200)] 
ada: Small cleanups and fixes in expansion of aggregates

This streamlines the handling of qualified expressions in the expansion of
aggregates and plugs a couple of loopholes that may cause memory leaks.

gcc/ada/

* exp_aggr.adb (Build_Array_Aggr_Code): Move the declaration of Typ
to the beginning.
(Initialize_Array_Component): Test the unqualified version of the
expression for the nested array case.
(Initialize_Ctrl_Array_Component): Do not duplicate the expression
here.  Do the pattern matching of the unqualified version of it.
(Gen_Assign): Call Unqualify to compute Expr_Q and use Expr_Q in
subsequent pattern matching.
(Initialize_Ctrl_Record_Component): Do the pattern matching of the
unqualified version of the aggregate.
(Build_Record_Aggr_Code): Call Unqualify.
(Convert_Aggr_In_Assignment): Likewise.
(Convert_Aggr_In_Object_Decl): Likewise.
(Component_OK_For_Backend): Likewise.
(Is_Delayed_Aggregate): Likewise.

15 months agoada: Fix wrong expansion of array aggregate with noncontiguous choices
Eric Botcazou [Wed, 12 Apr 2023 17:49:05 +0000 (19:49 +0200)] 
ada: Fix wrong expansion of array aggregate with noncontiguous choices

This extends an earlier fix done for the others choice of an array aggregate
to all the choices of the aggregate, since the same sharing issue may happen
when the choices are not contiguous.

gcc/ada/

* exp_aggr.adb (Build_Array_Aggr_Code.Get_Assoc_Expr): Duplicate the
expression here instead of...
(Build_Array_Aggr_Code): ...here.

15 months agoada: Fix internal error on array constant in expression function
Eric Botcazou [Fri, 14 Apr 2023 09:14:47 +0000 (11:14 +0200)] 
ada: Fix internal error on array constant in expression function

This happens when the peculiar check emitted by Check_Large_Modular_Array
is applied to an object whose actual subtype is an itype with dynamic size,
because the first reference to the itype in the expanded code may turn out
to be within the raise statement, which is problematic for the eloboration
of this itype by the code generator at library level.

gcc/ada/

* freeze.adb (Check_Large_Modular_Array): Fix head comment, use
Standard_Long_Long_Integer_Size directly and generate a reference
just before the raise statement if the Etype of the object is an
itype declared in an open scope.

15 months agoada: Fix fallout of recent fix for missing finalization
Eric Botcazou [Thu, 13 Apr 2023 21:11:38 +0000 (23:11 +0200)] 
ada: Fix fallout of recent fix for missing finalization

The original fix makes it possible to create transient scopes around return
statements in more cases, but it overlooks that transient scopes are reused
and, in particular, that they can be promoted to secondary stack management.

gcc/ada/

* exp_ch7.adb (Find_Enclosing_Transient_Scope): Return the index in
the scope table instead of the scope's entity.
(Establish_Transient_Scope): If an enclosing scope already exists,
do not set the Uses_Sec_Stack flag on it if the node to be wrapped
is a return statement which requires secondary stack management.

15 months agoada: Add System.Traceback.Symbolic.Module_Name support on AArch64 Linux
Joel Brobecker [Wed, 12 Apr 2023 15:03:55 +0000 (08:03 -0700)] 
ada: Add System.Traceback.Symbolic.Module_Name support on AArch64 Linux

This commit changes the runtime on aarch64-linux to use the Linux
version of s-tsmona.adb, so as to add support for this functionality
on aarch64-linux.

gcc/ada/

* Makefile.rtl: Use libgnat/s-tsmona__linux.adb on
aarch64-linux.  Link libgnat with -ldl, as the use of
s-tsmona__linux.adb requires it.

15 months agoada: Only build access-to-subprogram wrappers when expander is active
Piotr Trojanek [Tue, 11 Apr 2023 22:19:23 +0000 (00:19 +0200)] 
ada: Only build access-to-subprogram wrappers when expander is active

For access-to-subprogram types with Pre/Post aspects we create a wrapper
routine that evaluates these aspects. Spec of this wrapper was created
always, while its body was only created when expansion was enabled.

Now we only create these wrappers when expansion is enabled. In
particular, we don't create them in GNATprove mode; instead, GNATprove
picks the Pre/Post expressions directly from the aspects.

gcc/ada/

* exp_ch3.adb
(Build_Access_Subprogram_Wrapper_Body): Build wrapper body if requested
by routine that builds wrapper spec.
* sem_ch3.adb
(Analyze_Full_Type_Declaration): Only build wrapper when expander is
active.
(Build_Access_Subprogram_Wrapper):
Remove special-case for GNATprove.

15 months agoada: Fix minor issues in user's guide
Ronan Desplanques [Wed, 12 Apr 2023 13:01:45 +0000 (15:01 +0200)] 
ada: Fix minor issues in user's guide

gcc/ada/

* doc/gnat_ugn/building_executable_programs_with_gnat.rst: Fix minor issues.
* doc/gnat_ugn/the_gnat_compilation_model.rst: Fix minor issues.
* gnat_ugn.texi: Regenerate.

15 months agoada: Ensure Default_Stack_Size is greater than Minimum_Stack_Size
Johannes Kliemann [Tue, 4 Apr 2023 09:24:39 +0000 (11:24 +0200)] 
ada: Ensure Default_Stack_Size is greater than Minimum_Stack_Size

The Default_Stack_Size function does not check that the binder specified
default stack size is greater than the minimum stack size for the runtime.
This can result in tasks using default stack sizes less than the minimum
stack size because the Adjust_Storage_Size only adjusts storages sizes for
tasks that explicitly specify a storage size. To avoid this, the binder
specified default stack size is round up to the minimum stack size if
required.

gcc/ada/

* libgnat/s-parame.adb: Check that Default_Stack_Size >=
Minimum_Stack_size.
* libgnat/s-parame__rtems.adb: Ditto.
* libgnat/s-parame__vxworks.adb: Check that Default_Stack_Size >=
Minimum_Stack_size and use the proper Minimum_Stack_Size if
Stack_Check_Limits is enabled.

15 months agoada: Fix regression of secondary stack management in return statements
Eric Botcazou [Tue, 11 Apr 2023 23:16:20 +0000 (01:16 +0200)] 
ada: Fix regression of secondary stack management in return statements

This happens when the expression of the return statement is a call that does
not return on the same stack as the enclosing function.

gcc/ada/

* sem_res.adb (Resolve_Call): Restrict previous change to calls that
return on the same stack as the enclosing function.  Tidy up.

15 months agoada: Use generalized loop iteration in Put_Image routines
Eric Botcazou [Mon, 10 Apr 2023 08:12:13 +0000 (10:12 +0200)] 
ada: Use generalized loop iteration in Put_Image routines

gcc/ada/

* libgnat/a-cidlli.adb (Put_Image): Simplify.
* libgnat/a-coinve.adb (Put_Image): Likewise.

15 months agoada: Fix visibility error with DIC or Type_Invariant aspect on generic type
Eric Botcazou [Tue, 11 Apr 2023 10:15:22 +0000 (12:15 +0200)] 
ada: Fix visibility error with DIC or Type_Invariant aspect on generic type

The compiler fails to capture global references during the analysis of the
aspect on the generic type because it analyzes a copy of the expression.

gcc/ada/

* exp_util.adb (Build_DIC_Procedure_Body.Add_Own_DIC): When inside
a generic unit, preanalyze the expression directly.
(Build_Invariant_Procedure_Body.Add_Own_Invariants): Likewise.

15 months agoada: Fix coding style in init.c
Cedric Landet [Fri, 31 Mar 2023 12:51:15 +0000 (14:51 +0200)] 
ada: Fix coding style in init.c

The coding style rules require to avoid using FIXME comments. ??? is
preferred.

gcc/ada/

* init.c: Replace FIXME by ???

15 months agoHandle FMA friendly in reassoc pass
Lili Cui [Tue, 30 May 2023 05:47:47 +0000 (05:47 +0000)] 
Handle FMA friendly in reassoc pass

Make some changes in reassoc pass to make it more friendly to fma pass later.
Using FMA instead of mult + add reduces register pressure and insruction
retired.

There are mainly two changes
1. Put no-mult ops and mult ops alternately at the end of the queue, which is
conducive to generating more fma and reducing the loss of FMA when breaking
the chain.
2. Rewrite the rewrite_expr_tree_parallel function to try to build parallel
chains according to the given correlation width, keeping the FMA chance as
much as possible.

With the patch applied

On ICX:
507.cactuBSSN_r: Improved by 1.7% for multi-copy .
503.bwaves_r   : Improved by  0.60% for single copy .
507.cactuBSSN_r: Improved by  1.10% for single copy .
519.lbm_r      : Improved by  2.21% for single copy .
no measurable changes for other benchmarks.

On aarch64
507.cactuBSSN_r: Improved by 1.7% for multi-copy.
503.bwaves_r   : Improved by 6.00% for single-copy.
no measurable changes for other benchmarks.

TEST1:

float
foo (float a, float b, float c, float d, float *e)
{
   return  *e  + a * b + c * d ;
}

For "-Ofast -mfpmath=sse -mfma" GCC generates:
        vmulss  %xmm3, %xmm2, %xmm2
        vfmadd132ss     %xmm1, %xmm2, %xmm0
        vaddss  (%rdi), %xmm0, %xmm0
        ret

With this patch GCC generates:
        vfmadd213ss   (%rdi), %xmm1, %xmm0
        vfmadd231ss   %xmm2, %xmm3, %xmm0
        ret

TEST2:

for (int i = 0; i < N; i++)
{
  a[i] += b[i]* c[i] + d[i] * e[i] + f[i] * g[i] + h[i] * j[i] + k[i] * l[i] + m[i]* o[i] + p[i];
}

For "-Ofast -mfpmath=sse -mfma"  GCC generates:
vmovapd e(%rax), %ymm4
vmulpd  d(%rax), %ymm4, %ymm3
addq    $32, %rax
vmovapd c-32(%rax), %ymm5
vmovapd j-32(%rax), %ymm6
vmulpd  h-32(%rax), %ymm6, %ymm2
vmovapd a-32(%rax), %ymm6
vaddpd  p-32(%rax), %ymm6, %ymm0
vmovapd g-32(%rax), %ymm7
vfmadd231pd     b-32(%rax), %ymm5, %ymm3
vmovapd o-32(%rax), %ymm4
vmulpd  m-32(%rax), %ymm4, %ymm1
vmovapd l-32(%rax), %ymm5
vfmadd231pd     f-32(%rax), %ymm7, %ymm2
vfmadd231pd     k-32(%rax), %ymm5, %ymm1
vaddpd  %ymm3, %ymm0, %ymm0
vaddpd  %ymm2, %ymm0, %ymm0
vaddpd  %ymm1, %ymm0, %ymm0
vmovapd %ymm0, a-32(%rax)
cmpq    $8192, %rax
jne     .L4
vzeroupper
ret

with this patch applied GCC breaks the chain with width = 2 and generates 6 fma:

vmovapd a(%rax), %ymm2
vmovapd c(%rax), %ymm0
addq    $32, %rax
vmovapd e-32(%rax), %ymm1
vmovapd p-32(%rax), %ymm5
vmovapd g-32(%rax), %ymm3
vmovapd j-32(%rax), %ymm6
vmovapd l-32(%rax), %ymm4
vmovapd o-32(%rax), %ymm7
vfmadd132pd     b-32(%rax), %ymm2, %ymm0
vfmadd132pd     d-32(%rax), %ymm5, %ymm1
vfmadd231pd     f-32(%rax), %ymm3, %ymm0
vfmadd231pd     h-32(%rax), %ymm6, %ymm1
vfmadd231pd     k-32(%rax), %ymm4, %ymm0
vfmadd231pd     m-32(%rax), %ymm7, %ymm1
vaddpd  %ymm1, %ymm0, %ymm0
vmovapd %ymm0, a-32(%rax)
cmpq    $8192, %rax
jne     .L2
vzeroupper
ret

gcc/ChangeLog:

PR tree-optimization/98350
* tree-ssa-reassoc.cc
(rewrite_expr_tree_parallel): Rewrite this function.
(rank_ops_for_fma): New.
(reassociate_bb): Handle new function.

gcc/testsuite/ChangeLog:

PR tree-optimization/98350
* gcc.dg/pr98350-1.c: New test.
* gcc.dg/pr98350-2.c: Ditto.

15 months agortlanal: Change return type of predicate functions from int to bool
Uros Bizjak [Mon, 29 May 2023 14:36:38 +0000 (16:36 +0200)] 
rtlanal: Change return type of predicate functions from int to bool

gcc/ChangeLog:

* rtl.h (rtx_addr_can_trap_p): Change return type from int to bool.
(rtx_unstable_p): Ditto.
(reg_mentioned_p): Ditto.
(reg_referenced_p): Ditto.
(reg_used_between_p): Ditto.
(reg_set_between_p): Ditto.
(modified_between_p): Ditto.
(no_labels_between_p): Ditto.
(modified_in_p): Ditto.
(reg_set_p): Ditto.
(multiple_sets): Ditto.
(set_noop_p): Ditto.
(noop_move_p): Ditto.
(reg_overlap_mentioned_p): Ditto.
(dead_or_set_p): Ditto.
(dead_or_set_regno_p): Ditto.
(find_reg_fusage): Ditto.
(find_regno_fusage): Ditto.
(side_effects_p): Ditto.
(volatile_refs_p): Ditto.
(volatile_insn_p): Ditto.
(may_trap_p_1): Ditto.
(may_trap_p): Ditto.
(may_trap_or_fault_p): Ditto.
(computed_jump_p): Ditto.
(auto_inc_p): Ditto.
(loc_mentioned_in_p): Ditto.
* rtlanal.cc (computed_jump_p_1): Adjust forward declaration.
(rtx_unstable_p): Change return type from int to bool
and adjust function body accordingly.
(rtx_addr_can_trap_p): Ditto.
(reg_mentioned_p): Ditto.
(no_labels_between_p): Ditto.
(reg_used_between_p): Ditto.
(reg_referenced_p): Ditto.
(reg_set_between_p): Ditto.
(reg_set_p): Ditto.
(modified_between_p): Ditto.
(modified_in_p): Ditto.
(multiple_sets): Ditto.
(set_noop_p): Ditto.
(noop_move_p): Ditto.
(reg_overlap_mentioned_p): Ditto.
(dead_or_set_p): Ditto.
(dead_or_set_regno_p): Ditto.
(find_reg_fusage): Ditto.
(find_regno_fusage): Ditto.
(remove_node_from_insn_list): Ditto.
(volatile_insn_p): Ditto.
(volatile_refs_p): Ditto.
(side_effects_p): Ditto.
(may_trap_p_1): Ditto.
(may_trap_p): Ditto.
(may_trap_or_fault_p): Ditto.
(computed_jump_p): Ditto.
(auto_inc_p): Ditto.
(loc_mentioned_in_p): Ditto.
* combine.cc (can_combine_p): Update indirect function.

15 months agoRISC-V: Add floating-point to integer conversion RVV auto-vectorization support
Juzhe-Zhong [Tue, 30 May 2023 02:20:19 +0000 (10:20 +0800)] 
RISC-V: Add floating-point to integer conversion RVV auto-vectorization support

Even though we can't support floating-point operations which are
depending
on FRM yet, (for example vfadd support is blocked) since the RVV
intrinsic doc is not updated
and we can't support mode switching for this.

We can support floating-point to integer conversion now since it's not
depending on FRM and
we don't need mode switching support for this ('rtz' conversions
independent FRM).

Signed-off-by: Juzhe-Zhong <juzhe.zhong@rivai.ai>
gcc/ChangeLog:

* config/riscv/autovec.md (<optab><mode><vconvert>2): New pattern.
* config/riscv/iterators.md: New attribute.
* config/riscv/vector-iterators.md: New attribute.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/autovec/conversions/vfcvt_rtz-run.c: New test.
* gcc.target/riscv/rvv/autovec/conversions/vfcvt_rtz-rv32gcv.c: New test.
* gcc.target/riscv/rvv/autovec/conversions/vfcvt_rtz-rv64gcv.c: New test.
* gcc.target/riscv/rvv/autovec/conversions/vfcvt_rtz-template.h: New test.

15 months agoRISC-V: Fix warning in riscv.md
From: Juzhe-Zhong [Tue, 30 May 2023 02:16:09 +0000 (10:16 +0800)] 
RISC-V: Fix warning in riscv.md

Notice there is warning:
../../../riscv-gcc/gcc/config/riscv/riscv.md:1356:32: warning:
comparison between signed and unsigned integer expressions
[-Wsign-compare]
       if (INTVAL (operands[2]) == GET_MODE_MASK (HImode))
../../../riscv-gcc/gcc/config/riscv/riscv.md:1358:37: warning:
comparison between signed and unsigned integer expressions
[-Wsign-compare]
       else if (INTVAL (operands[2]) == GET_MODE_MASK (SImode))
../../../riscv-gcc/gcc/config/riscv/riscv.md: In function Ã¢â‚¬Ëœrtx_def*
gen_anddi3(rtx, rtx, rtx)’:
../../../riscv-gcc/gcc/config/riscv/riscv.md:1356:32: warning:
comparison between signed and unsigned integer expressions
[-Wsign-compare]
       if (INTVAL (operands[2]) == GET_MODE_MASK (HImode))
../../../riscv-gcc/gcc/config/riscv/riscv.md:1358:37: warning:
comparison between signed and unsigned integer expressions
[-Wsign-compare]
       else if (INTVAL (operands[2]) == GET_MODE_MASK (SImode))

Add unsigned conversion to fix this warning.

Signed-off-by: Juzhe-Zhong <juzhe.zhong@rivai.ai>
gcc/ChangeLog:

* config/riscv/riscv.md: Fix signed and unsigned comparison
warning.

15 months agoRISC-V: Add RVV FNMA auto-vectorization support
Juzhe-Zhong [Tue, 30 May 2023 02:13:43 +0000 (10:13 +0800)] 
RISC-V: Add RVV FNMA auto-vectorization support

Like FMA, Add FNMA (VNMSAC or VNMSUB) auto-vectorization support.

Signed-off-by: Juzhe-Zhong <juzhe.zhong@rivai.ai>
gcc/ChangeLog:

* config/riscv/autovec.md (fnma<mode>4): New pattern.
(*fnma<mode>): Ditto.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/autovec/ternop/ternop-4.c: New test.
* gcc.target/riscv/rvv/autovec/ternop/ternop-5.c: New test.
* gcc.target/riscv/rvv/autovec/ternop/ternop-6.c: New test.
* gcc.target/riscv/rvv/autovec/ternop/ternop_run-4.c: New test.
* gcc.target/riscv/rvv/autovec/ternop/ternop_run-5.c: New test.
* gcc.target/riscv/rvv/autovec/ternop/ternop_run-6.c: New test.

15 months agoDaily bump.
GCC Administrator [Tue, 30 May 2023 00:16:29 +0000 (00:16 +0000)] 
Daily bump.

15 months agoRISC-V: Optimize TARGET_XTHEADCONDMOV
Die Li [Mon, 29 May 2023 17:10:32 +0000 (11:10 -0600)] 
RISC-V: Optimize TARGET_XTHEADCONDMOV

This patch allows less instructions to be used when TARGET_XTHEADCONDMOV is enabled.

Provide an example from the existing testcases.

Testcase:
int ConEmv_imm_imm_reg(int x, int y){
  if (x == 1000) return 10;
  return y;
}

Cflags:
-O2 -march=rv64gc_xtheadcondmov -mabi=lp64d

before patch:
ConEmv_imm_imm_reg:
addi a5,a0,-1000
li a0,10
th.mvnez a0,zero,a5
th.mveqz a1,zero,a5
or a0,a0,a1
ret

after patch:
ConEmv_imm_imm_reg:
addi a5,a0,-1000
li a0,10
th.mvnez a0,a1,a5
ret

Signed-off-by: Die Li <lidie@eswincomputing.com>
gcc/ChangeLog:

* config/riscv/riscv.cc (riscv_expand_conditional_move_onesided):
Delete.
(riscv_expand_conditional_move):  Reuse the TARGET_SFB_ALU expand
process for TARGET_XTHEADCONDMOV

gcc/testsuite/ChangeLog:

* gcc.target/riscv/xtheadcondmov-indirect-rv32.c: Update the output.
* gcc.target/riscv/xtheadcondmov-indirect-rv64.c: Likewise.

15 months agoi386: Also require TARGET_AVX512BW to generate truncv16hiv16qi2 [PR110021]
Uros Bizjak [Mon, 29 May 2023 14:10:33 +0000 (16:10 +0200)] 
i386: Also require TARGET_AVX512BW to generate truncv16hiv16qi2 [PR110021]

gcc/ChangeLog:

PR target/110021
* config/i386/i386-expand.cc (ix86_expand_vecop_qihi2): Also require
TARGET_AVX512BW to generate truncv16hiv16qi2.

15 months agoRISC-V: Use extension instructions instead of bitwise "and"
Jivan Hakobyan [Mon, 29 May 2023 13:55:29 +0000 (07:55 -0600)] 
RISC-V: Use extension instructions instead of bitwise "and"

In the case where the target supports extension instructions,
it is preferable to use that instead of doing the same in other ways.
For the following case

void foo (unsigned long a, unsigned long* ptr) {
    ptr[0] = a & 0xffffffffUL;
    ptr[1] &= 0xffffffffUL;
}

GCC generates
foo:
        li      a5,-1
        srli    a5,a5,32
        and     a0,a0,a5
        sd      a0,0(a1)
        ld      a4,8(a1)
        and     a5,a4,a5
        sd      a5,8(a1)
        ret

but it will be profitable to generate this one

foo:
  zext.w a0,a0
  sd a0,0(a1)
  lwu a5,8(a1)
  sd a5,8(a1)
  ret

This patch fixes mentioned issue.
It supports HI -> DI, HI->SI and SI -> DI extensions.

gcc/ChangeLog:
* config/riscv/riscv.md (and<mode>3): New expander.
(*and<mode>3) New pattern.
* config/riscv/predicates.md (arith_operand_or_mode_mask): New
predicate.

gcc/testsuite/ChangeLog:
* gcc.target/riscv/and-extend-1.c: New test
* gcc.target/riscv/and-extend-2.c: New test

15 months agoRISC-V: Refactor comments and naming of riscv-v.cc.
Pan Li [Fri, 26 May 2023 11:26:24 +0000 (19:26 +0800)] 
RISC-V: Refactor comments and naming of riscv-v.cc.

This patch would like to remove unnecessary comments of some self
explained parameters and try a better name to avoid misleading.

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

* config/riscv/riscv-v.cc (emit_vlmax_insn): Remove unnecessary
comments and rename local variables.
(emit_nonvlmax_insn): Diito.
(emit_vlmax_merge_insn): Ditto.
(emit_vlmax_cmp_insn): Ditto.
(emit_vlmax_cmp_mu_insn): Ditto.
(emit_scalar_move_insn): Ditto.

Signed-off-by: Pan Li <pan2.li@intel.com>
15 months agoDaily bump.
GCC Administrator [Mon, 29 May 2023 11:15:05 +0000 (11:15 +0000)] 
Daily bump.

15 months agoRISC-V: Eliminate the magic number in riscv-v.cc
Pan Li [Fri, 26 May 2023 00:40:26 +0000 (08:40 +0800)] 
RISC-V: Eliminate the magic number in riscv-v.cc

This patch would like to remove the magic number in the riscv-v.cc, and
align the same value to one macro.

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

* config/riscv/riscv-v.cc (emit_vlmax_insn): Eliminate the
magic number.
(emit_nonvlmax_insn): Ditto.
(emit_vlmax_merge_insn): Ditto.
(emit_vlmax_cmp_insn): Ditto.
(emit_vlmax_cmp_mu_insn): Ditto.
(expand_vec_series): Ditto.

Signed-off-by: Pan Li <pan2.li@intel.com>
15 months agoRISC-V: Using merge approach to optimize repeating sequence in vec_init
Pan Li [Thu, 25 May 2023 02:58:49 +0000 (10:58 +0800)] 
RISC-V: Using merge approach to optimize repeating sequence in vec_init

This patch would like to optimize the VLS vector initialization like
repeating sequence. From the vslide1down to the vmerge with a simple
cost model, aka every instruction only has 1 cost.

Given code with -march=rv64gcv_zvl256b --param riscv-autovec-preference=fixed-vlmax
typedef int64_t vnx32di __attribute__ ((vector_size (256)));

__attribute__ ((noipa)) void
f_vnx32di (int64_t a, int64_t b, int64_t *out)
{
  vnx32di v = {
    a, b, a, b, a, b, a, b,
    a, b, a, b, a, b, a, b,
    a, b, a, b, a, b, a, b,
    a, b, a, b, a, b, a, b,
  };
  *(vnx32di *) out = v;
}

Before this patch:
vslide1down.vx (x31 times)

After this patch:
li a5,-1431654400
addi a5,a5,-1365
li a3,-1431654400
addi a3,a3,-1366
slli a5,a5,32
add a5,a5,a3
vsetvli a4,zero,e64,m8,ta,ma
vmv.v.x v8,a0
vmv.s.x v0,a5
vmerge.vxm v8,v8,a1,v0
vs8r.v v8,0(a2)

Since we dont't have SEW = 128 in vec_duplicate, we can't combine ab into
SEW = 128 element and then broadcast this big element.

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

gcc/ChangeLog:

* config/riscv/riscv-protos.h (enum insn_type): New type.
* config/riscv/riscv-v.cc (RVV_INSN_OPERANDS_MAX): New macro.
(rvv_builder::can_duplicate_repeating_sequence_p): Align the referenced
class member.
(rvv_builder::get_merged_repeating_sequence): Ditto.
(rvv_builder::repeating_sequence_use_merge_profitable_p): New function
to evaluate the optimization cost.
(rvv_builder::get_merge_scalar_mask): New function to get the merge
mask.
(emit_scalar_move_insn): New function to emit vmv.s.x.
(emit_vlmax_integer_move_insn): New function to emit vlmax vmv.v.x.
(emit_nonvlmax_integer_move_insn): New function to emit nonvlmax
vmv.v.x.
(get_repeating_sequence_dup_machine_mode): New function to get the dup
machine mode.
(expand_vector_init_merge_repeating_sequence): New function to perform
the optimization.
(expand_vec_init): Add this vector init optimization.
* config/riscv/riscv.h (BITS_PER_WORD): New macro.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/autovec/vls-vlmax/init-repeat-sequence-1.c: New test.
* gcc.target/riscv/rvv/autovec/vls-vlmax/init-repeat-sequence-2.c: New test.
* gcc.target/riscv/rvv/autovec/vls-vlmax/init-repeat-sequence-3.c: New test.
* gcc.target/riscv/rvv/autovec/vls-vlmax/init-repeat-sequence-4.c: New test.
* gcc.target/riscv/rvv/autovec/vls-vlmax/init-repeat-sequence-5.c: New test.
* gcc.target/riscv/rvv/autovec/vls-vlmax/init-repeat-sequence-run-1.c: New test.
* gcc.target/riscv/rvv/autovec/vls-vlmax/init-repeat-sequence-run-2.c: New test.
* gcc.target/riscv/rvv/autovec/vls-vlmax/init-repeat-sequence-run-3.c: New test.

Signed-off-by: Pan Li <pan2.li@intel.com>
15 months agoMAINTAINERS file: Replace spaces with tabs
Martin Jambor [Mon, 29 May 2023 09:51:28 +0000 (11:51 +0200)] 
MAINTAINERS file: Replace spaces with tabs

This change, separating Benjamin's name and email address with tabs
rather than spaces, makes contrib/check-MAINTAINERS.py script happy
about our MAINTAINERS file again.

ChangeLog:

2023-05-29  Martin Jambor  <mjambor@suse.cz>

* MAINTAINERS: Replace spaces with tabs.

15 months agoFix incorrect SLOC inherited by induction variable increment
Eric Botcazou [Mon, 29 May 2023 07:48:14 +0000 (09:48 +0200)] 
Fix incorrect SLOC inherited by induction variable increment

This extends the condition to more cases involving debug instructions.

gcc/
* tree-ssa-loop-manip.cc (create_iv): Try harder to find a SLOC to
put onto the increment when it is inserted after the position.

15 months agoFix artificial overflow during GENERIC folding
Eric Botcazou [Mon, 29 May 2023 07:45:57 +0000 (09:45 +0200)] 
Fix artificial overflow during GENERIC folding

The Ada compiler gives a bogus warning:
storage_offset1.ads:16:52: warning: Constraint_Error will be raised at run
time [enabled by default]

Ironically enough, this occurs because of an intermediate conversion to an
unsigned type which is supposed to hide overflows but is counter-productive
for constants because TREE_OVERFLOW is always set for them, so it ends up
setting a bogus TREE_OVERFLOW when converting back to the original type.

The fix simply redirects INTEGER_CSTs to the other, direct path without the
intermediate conversion to the unsigned type.

gcc/
* match.pd ((T)P - (T)(P + A) -> -(T) A): Avoid artificial overflow
on constants.

gcc/testsuite/
* gnat.dg/specs/storage_offset1.ads: New test.

15 months agoada: Define sigset for systems that does not suport sockets
Cedric Landet [Fri, 31 Mar 2023 12:24:46 +0000 (14:24 +0200)] 
ada: Define sigset for systems that does not suport sockets

In s-oscons-tmplt.c, sigset is defined inside the HAVE_SOCKETS bloc.
A platform could require sigset without supporting sockets.

gcc/ada/

* s-oscons-tmplt.c: move the definition of sigset out of the
HAVE_SOCKETS bloc.

15 months agoada: Set g-spogwa as a GNATRTL_SOCKETS_OBJS
Cedric Landet [Fri, 31 Mar 2023 12:05:37 +0000 (14:05 +0200)] 
ada: Set g-spogwa as a GNATRTL_SOCKETS_OBJS

g-spogwa.adb is the body of the procedure GNAT.Sockets.Poll.G_Wait.
This is a socket specific procedure. It should only be built for
systems that support sockets.

gcc/ada/

* Makefile.rtl: Move g-spogwa$(objext) from GNATRTL_NONTASKING_OBJS
to GNATRTL_SOCKETS_OBJS

15 months agoada: Fix spurious error on imported generic function with precondition
Eric Botcazou [Mon, 10 Apr 2023 08:15:59 +0000 (10:15 +0200)] 
ada: Fix spurious error on imported generic function with precondition

It occurs during the instantiation because the compiler forgets the context
of the generic declaration.

gcc/ada/

* freeze.adb (Wrap_Imported_Subprogram): Use Copy_Subprogram_Spec in
both cases to copy the spec of the subprogram.

15 months agoada: Fix memory leak in expression function returning Big_Integer
Eric Botcazou [Sat, 8 Apr 2023 16:29:16 +0000 (18:29 +0200)] 
ada: Fix memory leak in expression function returning Big_Integer

We fail to establish a transient scope around the return statement because
the function returns a controlled type, but this is no longer problematic
because controlled types are no longer returned on the secondary stack.

gcc/ada/

* exp_ch7.adb (Establish_Transient_Scope.Find_Transient_Context):
Bail out for a simple return statement only if the transient scope
and the function both require secondary stack management, or else
if the function is a thunk.
* sem_res.adb (Resolve_Call): Do not create a transient scope when
the call is the expression of a simple return statement.

15 months agoada: Use Code_Address attribute to determine subprogram addresses
Patrick Bernardi [Thu, 6 Apr 2023 20:55:01 +0000 (16:55 -0400)] 
ada: Use Code_Address attribute to determine subprogram addresses

The runtime used label addresses to determine the code address of
subprograms because the subprogram's canonical address on some targets
is a descriptor or a stub. Simplify the code by using the Code_Address
attribute instead, which is designed to return the code address of a
subprogram. This also works around a current GNAT-LLVM limitation where
the address of a label is incorrectly calculated when using -O1. As a
result, we can now build a-except.adb and g-debpoo.adb at -O1 again with
GNAT-LLVM.

gcc/ada/

* libgnat/a-excach.adb (Call_Chain): Replace
Code_Address_For_AAA/ZZZ functions with AAA/ZZZ'Code_Address.
* libgnat/a-except.adb (Code_Address_For_AAA/ZZZ): Delete.
(AAA/ZZZ): New null procedures.
* libgnat/g-debpoo.adb
(Code_Address_For_Allocate_End): Delete.
(Code_Address_For_Deallocate_End): Delete.
(Code_Address_For_Dereference_End): Delete.
(Allocate): Remove label and use Code_Address attribute to
determine subprogram addresses.
(Dellocate): Likewise.
(Dereference): Likewise.
(Allocate_End): Convert to null procedure.
(Dellocate_End): Likewise.
(Dereference_End): Likewise.

15 months agoada: Call idiomatic routine in Expand_Simple_Function_Return
Eric Botcazou [Sat, 8 Apr 2023 10:43:54 +0000 (12:43 +0200)] 
ada: Call idiomatic routine in Expand_Simple_Function_Return

In the primary stack case, Insert_Actions is invoked when the expression is
being rewritten, whereas Insert_List_Before_And_Analyze is invoked in the
secondary stack case.  The former is idiomatic, the latter is not.

gcc/ada/

* exp_ch6.adb (Expand_Simple_Function_Return): Call Insert_Actions
consistently when rewriting the expression.

15 months agoada: Fix wrong finalization for loop on indexed container
Eric Botcazou [Fri, 7 Apr 2023 17:17:20 +0000 (19:17 +0200)] 
ada: Fix wrong finalization for loop on indexed container

The problem is that a transient temporary created for the constant indexing
of the container is finalized almost immediately after its creation.

gcc/ada/

* exp_util.adb (Is_Finalizable_Transient.Is_Indexed_Container):
New predicate to detect a temporary created to hold the result of
a constant indexing on a container.
(Is_Finalizable_Transient.Is_Iterated_Container): Adjust a couple
of obsolete comments.
(Is_Finalizable_Transient): Return False if Is_Indexed_Container
returns True on the object.

15 months agoada: Fix bogus error on conditional expression with only user-defined literals
Eric Botcazou [Fri, 7 Apr 2023 07:16:12 +0000 (09:16 +0200)] 
ada: Fix bogus error on conditional expression with only user-defined literals

This implements the recursive resolution of conditional expressions whose
dependent expressions are (all) user-defined literals the same way it is
implemented for operators.

gcc/ada/

* sem_res.adb (Has_Applicable_User_Defined_Literal): Make it clear
that the predicate also checks the node itself.
(Try_User_Defined_Literal): Move current implementation to...
Deal only with literals, named numbers and conditional expressions
whose dependent expressions are literals or named numbers.
(Try_User_Defined_Literal_For_Operator): ...this.  Remove multiple
return False statements and put a single one at the end.
(Resolve): Call Try_User_Defined_Literal instead of directly
Has_Applicable_User_Defined_Literal for all nodes.  Call
Try_User_Defined_Literal_For_Operator for operator nodes.

15 months agoada: Fix crash on semi-recursive call in access-to-subprogram contract
Piotr Trojanek [Fri, 7 Apr 2023 11:55:09 +0000 (13:55 +0200)] 
ada: Fix crash on semi-recursive call in access-to-subprogram contract

Calls to access-to-subprogram from its own pre/post aspects are rejected
as illegal, e.g.:

   type F is access function (X : Natural) return Boolean with
     Pre => F.all (X);

but they caused an assertion failure in detection of recursive calls.

Now they are properly recognized as recursive, but the error is
suppressed, because it has been already posted at the call node.

gcc/ada/

* sem_res.adb (Invoked_With_Different_Arguments): Use Get_Called_Entity,
which properly deals with calls via an access-to-subprogram; fix
inconsistent use of a Call object declared in enclosing subprogram.

15 months agoada: Attach pre/post on access-to-subprogram to internal subprogram type
Piotr Trojanek [Sun, 2 Apr 2023 12:47:49 +0000 (14:47 +0200)] 
ada: Attach pre/post on access-to-subprogram to internal subprogram type

Aspects Pre/Post that annotate access-to-subprogram type were attached
to the source entity (whose kind is either E_Access_Subprogram_Type or
E_Access_Protected_Subprogram_Type). However, it is more convenient to
attach them to the internal entity (whose kind is E_Subprogram_Type), so
that both Pre/Post aspects and First_Formal/Next_Formal chain are
attached to the same entity, just like for ordinary subprograms.

The drawback of having the Post aspect attached to an internal entity is
that name in prefixes of attribute Result no longer match the name of
entity where this Post aspect is attached. However, currently there is
no code that relies on this matching and, in general, there are fewer
routines that deal with attribute Result so they are easier to adapt
than the code that queries the Pre/Post aspects.

gcc/ada/

* contracts.adb
(Add_Pre_Post_Condition): Attach pre/post aspects to E_Subprogram_Type
entity.
(Analyze_Entry_Or_Subprogram_Contract): Adapt to use full type
declaration for a contract attached to E_Subprogram_Type entity.
* sem_prag.adb
(Analyze_Pre_Post_Condition): Add pre/post aspects to the designed type.

15 months agoada: Remove redundant protection against empty lists
Piotr Trojanek [Mon, 20 Mar 2023 14:47:29 +0000 (15:47 +0100)] 
ada: Remove redundant protection against empty lists

Calls to First on No_List intentionally return Empty, so explicit guards
against No_List are unnecessary. Code cleanup; semantics is unaffected.

gcc/ada/

* sem_util.adb (Check_Function_Writable_Actuals): Remove guard against
a membership test with no alternatives; simplify with a membership test.

15 months agoada: Remove extra whitespace from FOR loops
Piotr Trojanek [Thu, 16 Mar 2023 12:33:29 +0000 (13:33 +0100)] 
ada: Remove extra whitespace from FOR loops

Whitespace cleanup.

gcc/ada/
* doc/gnat_ugn/gnat_and_program_execution.rst
(Some Useful Memory Pools): Remove extra whitespace from examples.
* sem_aggr.adb (Make_String_Into_Aggregate): Remove extra whitespace.
* gnat_ugn.texi: Regenerate.

15 months agoada: Cleanup detection of type support subprogram entities
Piotr Trojanek [Wed, 5 Apr 2023 21:55:30 +0000 (23:55 +0200)] 
ada: Cleanup detection of type support subprogram entities

Avoid repeated calls to Get_TSS_Name. Code cleanup related to handling
of dispatching operations in GNATprove; semantics is unaffected.

gcc/ada/

* exp_aggr.adb (Convert_Aggr_In_Allocator): Replace Get_TSS_Name
with a high-level Is_TSS.
* sem_ch6.adb (Check_Conformance): Replace DECLARE block and
nested IF with a call to Get_TSS_Name and a membership test.
(Has_Reliable_Extra_Formals): Refactor repeated calls to
Get_TSS_Name.
* sem_disp.adb (Check_Dispatching_Operation): Replace repeated
calls to Get_TSS_Name with a membership test.

15 months agoada: Fix wrong finalization for case expression in expression function
Eric Botcazou [Thu, 6 Apr 2023 22:26:19 +0000 (00:26 +0200)] 
ada: Fix wrong finalization for case expression in expression function

This happens when the case expression contains a single alternative.

gcc/ada/

* exp_ch5.adb (Expand_N_Case_Statement): Do not remove the statement
if it is the node to be wrapped by a transient scope.

15 months agoada: Fix internal error with pragma Compile_Time_{Warning,Error}
Eric Botcazou [Tue, 4 Apr 2023 17:25:11 +0000 (19:25 +0200)] 
ada: Fix internal error with pragma Compile_Time_{Warning,Error}

This happens when the pragmas are deferred to the back-end from an external
unit to the main unit that is generic, because the back-end does not compile
a main unit that is generic.

gcc/ada/

* sem_prag.adb (Process_Compile_Time_Warning_Or_Error): Do not defer
anything to the back-end when the main unit is generic.

15 months agoada: Fix small fallout of previous change
Eric Botcazou [Wed, 5 Apr 2023 21:53:18 +0000 (23:53 +0200)] 
ada: Fix small fallout of previous change

It may lead to an infinite recursion if no interpretation exists.

gcc/ada/

* sem_res.adb (Try_User_Defined_Literal): Restrict previous change
to non-leaf nodes.

15 months agoada: Fix remaining failures in Roman Numbers test
Eric Botcazou [Wed, 5 Apr 2023 18:43:54 +0000 (20:43 +0200)] 
ada: Fix remaining failures in Roman Numbers test

The test is inspired from the example of user-defined literals given in the
Ada 2022 RM.  Mixed Arabic numbers/Roman numbers computations are rejected
because the second resolution pass would try to resolve Arabic numbers only
as user-defined literals.

gcc/ada/

* sem_res.adb (Try_User_Defined_Literal): For arithmetic operators,
also accept operands whose type is covered by the resolution type.

15 months agoada: Fix memory leak in multi-dimensional array aggregate of Vector
Eric Botcazou [Tue, 4 Apr 2023 22:03:27 +0000 (00:03 +0200)] 
ada: Fix memory leak in multi-dimensional array aggregate of Vector

It comes from a superfluous adjustment for subarray components.

gcc/ada/

* exp_aggr.adb (Initialize_Array_Component): Fix condition detecting
the nested case that requires an adjustment.

15 months agoada: Fix wrong result for membership test of null in null-excluding access type
Eric Botcazou [Wed, 5 Apr 2023 18:34:43 +0000 (20:34 +0200)] 
ada: Fix wrong result for membership test of null in null-excluding access type

The result must be False as per the RM 4.5.2 (30.2/4) clause.

gcc/ada/

* exp_ch4.adb (Expand_N_In): Deal specifically with a null operand.

15 months agoada: Fix small fallout of previous change
Eric Botcazou [Wed, 5 Apr 2023 11:56:42 +0000 (13:56 +0200)] 
ada: Fix small fallout of previous change

The same guard must be added to Expand_Simple_Function_Return as the one
that was added to Analyze_Function_Return.

gcc/ada/

* exp_ch6.adb (Expand_Simple_Function_Return): Deal with a rewriting
of the simple return during the adjustment of its expression.

15 months agoada: Fix wrong finalization for call to BIP function in conditional expression
Eric Botcazou [Mon, 3 Apr 2023 08:53:30 +0000 (10:53 +0200)] 
ada: Fix wrong finalization for call to BIP function in conditional expression

This happens when the call is a dependent expression of the conditional
expression, and the conditional expression is either the expression of a
simple return statement or the return expression of an expression function.

The reason is that the special processing of "tail calls" for BIP functions,
i.e. calls that are the expression of simple return statements or the return
expression of expression functions, is not applied.

This change makes sure that it is applied by distributing the simple return
statements enclosing conditional expressions into the dependent expressions
of the conditional expressions in almost all cases.  As a side effect, this
elides a temporary in the nonlimited by-reference case, as well as a pair of
calls to Adjust/Finalize in the nonlimited controlled case.

gcc/ada/

* exp_ch4.adb (Expand_N_Case_Expression): Distribute simple return
statements enclosing the conditional expression into the dependent
expressions in almost all cases.
(Expand_N_If_Expression): Likewise.
(Process_Transient_In_Expression): Adjust to the above distribution.
* exp_ch6.adb (Expand_Ctrl_Function_Call): Deal with calls in the
dependent expressions of a conditional expression.
* sem_ch6.adb (Analyze_Function_Return): Deal with the rewriting of
a simple return statement during the resolution of its expression.

15 months agoada: Accept parameters of enclosing subprograms in exceptional cases
Piotr Trojanek [Tue, 4 Apr 2023 11:38:14 +0000 (13:38 +0200)] 
ada: Accept parameters of enclosing subprograms in exceptional cases

Rules about parameters of modes OUT and IN OUT in aspect
Exceptional_Cases only apply to the parameters of the current
subprogram.

gcc/ada/

* sem_res.adb (Resolve_Entity_Name): Refine rules for Exceptional_Cases.

15 months agoada: Fix crash on vector initialization
Marc Poulhiès [Mon, 27 Mar 2023 14:47:04 +0000 (16:47 +0200)] 
ada: Fix crash on vector initialization

Initializing a vector using

 Vec : V.Vector := [Some_Type'(Some_Abstract_Type with F => 0)];

may crash the compiler. The expander marks the N_Extension_Aggregate for
delayed expansion which never happens and incorrectly ends up in gigi.

The delayed expansion is needed for nested aggregates, which the
original code is testing for, but container aggregates are handled
differently.

Such assignments to container aggregates are later transformed into
procedure calls to the procedures named in the Aggregate aspect
definition, for which the delayed expansion is not required/expected.

gcc/ada/

* exp_aggr.adb (Convert_To_Assignments): Do not mark node for
delayed expansion if parent type has the Aggregate aspect.
* sem_util.adb (Is_Container_Aggregate): Move...
* sem_util.ads (Is_Container_Aggregate): ... here and make it
public.

15 months agoada: Allow attributes like First and Last to be read in Exceptional_Cases
Piotr Trojanek [Tue, 4 Apr 2023 07:49:26 +0000 (09:49 +0200)] 
ada: Allow attributes like First and Last to be read in Exceptional_Cases

Attributes that do not read data from the object can be safely used in
consequences of Exceptional_Cases regardless of the parameter passing
mode.

gcc/ada/

* sem_res.adb (Resolve_Entity_Name): Relax rules for Exceptional_Cases.

15 months agoada: Repair support for user-defined literals in arithmetic operators
Eric Botcazou [Mon, 3 Apr 2023 15:11:11 +0000 (17:11 +0200)] 
ada: Repair support for user-defined literals in arithmetic operators

It was partially broken to fix a regression in error reporting, because the
fix was applied to the first pass of resolution instead of the second pass,
as needs to be done for user-defined literals.

gcc/ada/

* sem_ch4.ads (Unresolved_Operator): New procedure.
* sem_ch4.adb (Has_Possible_Literal_Aspects): Rename into...
(Has_Possible_User_Defined_Literal): ...this.  Tidy up.
(Operator_Check): Accept again unresolved operators if they have a
possible user-defined literal as operand.  Factor out the handling
of the general error message into...
(Unresolved_Operator): ...this new procedure.
* sem_res.adb (Resolve): Be prepared for unresolved operators on
entry in Ada 2022 or later.  If they are still unresolved on exit,
call Unresolved_Operator to give the error message.
(Try_User_Defined_Literal): Tidy up.

15 months agoada: Default_Component_Value trumps Initialize/Normalize_Scalars
Steve Baird [Thu, 30 Mar 2023 20:22:01 +0000 (13:22 -0700)] 
ada: Default_Component_Value trumps Initialize/Normalize_Scalars

If the Default_Component_Value aspect is specified for an array type, then
specifying Initialize_Scalars or Normalize_Scalars should have no effect
on the default initialization of an object of the array type.

gcc/ada/

* exp_ch3.adb
(Expand_N_Object_Declaration.Default_Initialize_Object): Add test for
specified Default_Component_Value aspect when deciding whether
either Initialize_Scalars or Normalize_Scalars impacts default
initialization of an array object.

15 months agoada: Crash on aggregate for tagged record with discriminants
Javier Miranda [Mon, 3 Apr 2023 17:15:47 +0000 (17:15 +0000)] 
ada: Crash on aggregate for tagged record with discriminants

The frontend may crash processing an aggregate initializing
a derived tagged record type that has discriminants.

gcc/ada/

* sem_aggr.adb
(Resolve_Record_Aggregate): For aggregates of derived tagged
record types with discriminants, when collecting components
from ancestors, pass to subprogram Gather_Components the
parent type. Required to report errors on wrong aggregate
components.

15 months agoada: Reuse routine for getting from body entity to spec entity
Piotr Trojanek [Wed, 29 Mar 2023 14:41:44 +0000 (16:41 +0200)] 
ada: Reuse routine for getting from body entity to spec entity

Cleanup related to handling of access-to-subprogram types with Pre and
Post aspects. Behavior is unaffected.

gcc/ada/

* sem_util.adb (Check_Result_And_Post_State): Replace low-level
navigation with a high-level Unique_Entity.

15 months agoada: Fix retrieval of spec entity from entry body entity
Piotr Trojanek [Wed, 29 Mar 2023 14:21:01 +0000 (16:21 +0200)] 
ada: Fix retrieval of spec entity from entry body entity

When retrieving entities of subprogram spec we only handled functions
and procedures, but not entries. This had no consequences, because we
then only applied checks to functions, but still is worth a cleanup, so
the code is easier to adapt for access-to-subprogram entities as well.

gcc/ada/

* sem_util.adb (Check_Result_And_Post_State): Properly handle entry
bodies.

15 months agoada: Restore parent link for both lists and nodes in class-wide condition
Piotr Trojanek [Mon, 3 Apr 2023 14:54:39 +0000 (16:54 +0200)] 
ada: Restore parent link for both lists and nodes in class-wide condition

When preanalysing class-wide conditions, we restore "Function (Object)"
to its original "Object.Function" notation. This requires the Parent
links to be fixed. We did it for nodes; now we do it for lists as well.

This patch is enough to fix assertion failure in CCG and to make the
tree well-connected. Perhaps there is a more elegant solution, but that
remains to be investigated.

gcc/ada/

* contracts.adb (Fix_Parent): Fir part both for lists and nodes.

15 months agoada: Refining handling of inlining for CCG
Arnaud Charlet [Tue, 27 Sep 2022 08:57:00 +0000 (08:57 +0000)] 
ada: Refining handling of inlining for CCG

By marking relevant functions inline when -gnatn is used.

gcc/ada/

* sem_ch7.adb: Refine handling of inlining for CCG

15 months agoada: Fix spurious error on nested instantiations with generic renaming
Eric Botcazou [Sat, 1 Apr 2023 19:57:21 +0000 (21:57 +0200)] 
ada: Fix spurious error on nested instantiations with generic renaming

The problem is that the renaming slightly changes the form of a global
reference that was saved during the analysis of a generic package, and
that is sufficient to fool the code adjusting global references during
the instantiation.

gcc/ada/

* sem_ch12.adb (Copy_Generic_Node): Test the original node kind
for the sake of consistency.  For identifiers and other entity
names and operators, accept an expanded name as associated node.
Replace "or" with "or else" in condtion and fix its formatting.

15 months agoada: Tune message for missing 'Result in Contract_Cases
Piotr Trojanek [Fri, 31 Mar 2023 14:43:23 +0000 (16:43 +0200)] 
ada: Tune message for missing 'Result in Contract_Cases

Make the message consistent with the one for postcondition.

gcc/ada/

* sem_util.adb (Check_Result_And_Post_State): Tune message.