platform/upstream/gcc.git
2 years agoc++: Remove ifdefed code
Nathan Sidwell [Wed, 22 Jun 2022 14:51:44 +0000 (07:51 -0700)]
c++: Remove ifdefed code

The only reason I chose to use DECL_UID on this hash table was to make
it stable against ASLR and perturbations due to other allocations.
It's not required for correctness, as the comment mentions the
equality fn uses pointer identity.

gcc/cp/
* module.cc (struct duplicate_hash): Remove.
(duplicate_hash_map): Adjust.

2 years agoubsan: default to trap on unreachable at -O0 and -Og [PR104642]
Jason Merrill [Fri, 10 Jun 2022 20:35:21 +0000 (16:35 -0400)]
ubsan: default to trap on unreachable at -O0 and -Og [PR104642]

When not optimizing, we can't do anything useful with unreachability in
terms of code performance, so we might as well improve debugging by turning
__builtin_unreachable into a trap.  I think it also makes sense to do this
when we're explicitly optimizing for the debugging experience.

In the PR richi suggested introducing an -funreachable-traps flag for this.
This functionality is already implemented as -fsanitize=unreachable
-fsanitize-trap=unreachable, and we want to share the implementation, but it
does seem useful to have a separate flag that isn't affected by the various
sanitization controls.  -fsanitize=unreachable takes priority over
-funreachable-traps if both are enabled.

Jakub observed that this would slow down -O0 by default from running the
sanopt pass, so this revision avoids the need for sanopt by rewriting calls
introduced by the compiler immediately, and calls written by the user at
fold time.  Many of the calls introduced by the compiler are also rewritten
immediately to ubsan calls when not trapping, which fixes ubsan-8b.C;
previously the call to f() was optimized away before sanopt.  But this early
rewriting isn't practical for uses of __builtin_unreachable in
devirtualization and such, so sanopt rewriting is still done for
non-trapping sanitize.

PR c++/104642

gcc/ChangeLog:

* common.opt: Add -funreachable-traps.
* doc/invoke.texi (-funreachable-traps): Document it.
* opts.cc (finish_options): Enable at -O0 or -Og.
* tree.cc (build_common_builtin_nodes): Add __builtin_trap.
(builtin_decl_unreachable, build_builtin_unreachable): New.
* tree.h: Declare them.
* ubsan.cc (sanitize_unreachable_fn): Factor out.
(ubsan_instrument_unreachable): Use
gimple_build_builtin_unreachable.
* ubsan.h (sanitize_unreachable_fn): Declare.
* gimple.cc (gimple_build_builtin_unreachable): New.
* gimple.h: Declare it.
* builtins.cc (expand_builtin_unreachable): Add assert.
(fold_builtin_0): Call build_builtin_unreachable.
* sanopt.cc: Don't run for just SANITIZE_RETURN
or SANITIZE_UNREACHABLE when trapping.
* cgraphunit.cc (walk_polymorphic_call_targets): Use new
unreachable functions.
* gimple-fold.cc (gimple_fold_call)
(gimple_get_virt_method_for_vtable)
* ipa-fnsummary.cc (redirect_to_unreachable)
* ipa-prop.cc (ipa_make_edge_direct_to_target)
(ipa_impossible_devirt_target)
* ipa.cc (walk_polymorphic_call_targets)
* tree-cfg.cc (pass_warn_function_return::execute)
(execute_fixup_cfg)
* tree-ssa-loop-ivcanon.cc (remove_exits_and_undefined_stmts)
(unloop_loops)
* tree-ssa-sccvn.cc (eliminate_dom_walker::eliminate_stmt):
Likewise.

gcc/cp/ChangeLog:

* constexpr.cc (cxx_eval_builtin_function_call): Handle
unreachable/trap earlier.
* cp-gimplify.cc (cp_maybe_instrument_return): Use
build_builtin_unreachable.

gcc/testsuite/ChangeLog:

* g++.dg/ubsan/return-8a.C: New test.
* g++.dg/ubsan/return-8b.C: New test.
* g++.dg/ubsan/return-8d.C: New test.
* g++.dg/ubsan/return-8e.C: New test.

2 years agodata-ref: Improve non-loop disambiguation [PR106019]
Richard Sandiford [Wed, 22 Jun 2022 10:27:15 +0000 (11:27 +0100)]
data-ref: Improve non-loop disambiguation [PR106019]

When dr_may_alias_p is called without a loop context, it tries
to use the tree-affine interface to calculate the difference
between the two addresses and use that difference to check whether
the gap between the accesses is known at compile time.  However, as the
example in the PR shows, this doesn't expand SSA_NAMEs and so can easily
be defeated by things like reassociation.

One fix would have been to use aff_combination_expand to expand the
SSA_NAMEs, but we'd then need some way of maintaining the associated
cache.  This patch instead reuses the innermost_loop_behavior fields
(which exist even when no loop context is provided).

It might still be useful to do the aff_combination_expand thing too,
if an example turns out to need it.

gcc/
PR tree-optimization/106019
* tree-data-ref.cc (dr_may_alias_p): Try using the
innermost_loop_behavior to disambiguate non-loop queries.

gcc/testsuite/
PR tree-optimization/106019
* gcc.dg/vect/bb-slp-pr106019.c: New test.

2 years agoRISC-V: Add -mtune=thead-c906 to the invoke docs
Palmer Dabbelt [Thu, 26 May 2022 02:30:55 +0000 (19:30 -0700)]
RISC-V: Add -mtune=thead-c906 to the invoke docs

gcc/ChangeLog

* doc/invoke.texi (RISC-V): Document -mtune=thead-c906.

2 years agolibstdc++: eh_globals: gthreads: reset _S_init before deleting key
Alexandre Oliva [Wed, 22 Jun 2022 02:11:02 +0000 (23:11 -0300)]
libstdc++: eh_globals: gthreads: reset _S_init before deleting key

Clear __eh_globals_init's _S_init in the dtor before deleting the
gthread key.

This ensures that, in case any code involved in deleting the key
interacts with eh_globals, the key that is being deleted won't be
used, and the non-thread-specific eh_globals fallback will.

for  libstdc++-v3/ChangeLog

* libsupc++/eh_globals.cc [!_GLIBCXX_HAVE_TLS]
(__eh_globals_init::~__eh_globals_init): Clear _S_init first.

2 years agolibstdc++: testsuite: call sched_yield for nonpreemptive targets
Alexandre Oliva [Wed, 22 Jun 2022 02:11:01 +0000 (23:11 -0300)]
libstdc++: testsuite: call sched_yield for nonpreemptive targets

As in the gcc testsuite, systems without preemptive multi-threading
require sched_yield calls to be placed at points in which a context
switch might be needed to enable the test to complete.

for  libstdc++-v3/ChangeLog

* testsuite/30_threads/this_thread/60421.cc (test02): Call
sched_yield.

2 years agolibstdc++: testsuite: require cmath for nexttowardl
Alexandre Oliva [Wed, 22 Jun 2022 02:11:00 +0000 (23:11 -0300)]
libstdc++: testsuite: require cmath for nexttowardl

nexttowardl is only expected to be available with C99 math, but
20_util/to_chars/long_double.cc uses it unconditionally.

State the cmath requirement in the test.

for  libstdc++-v3/ChangeLog

* testsuite/20_util/to_chars/long_double.cc: Require cmath.

2 years agolibstdc++: testsuite: work around bitset namespace pollution
Alexandre Oliva [Wed, 22 Jun 2022 02:11:00 +0000 (23:11 -0300)]
libstdc++: testsuite: work around bitset namespace pollution

rtems6 declares a global struct bitset in a header file included
indirectly by sys/types.h, that ambiguates the unqualified references
to bitset after "using namespace std" in the testsuite.

Work around the namespace pollution with using declarations of
std::bitset.

for  libstdc++-v3/ChangeLog

* testsuite/23_containers/bitset/cons/dr1325-2.cc: Work around
global struct bitset.
* testsuite/23_containers/bitset/ext/15361.cc: Likewise.
* testsuite/23_containers/bitset/input/1.cc: Likewise.
* testsuite/23_containers/bitset/to_string/1.cc: Likewise.
* testsuite/23_containers/bitset/to_string/dr396.cc: Likewise.

2 years agotestsuite: outputs.exp: cleanup before running tests
Alexandre Oliva [Wed, 22 Jun 2022 02:10:59 +0000 (23:10 -0300)]
testsuite: outputs.exp: cleanup before running tests

Use the just-added dry-run infrastructure to clean up files that may
have been left over by interrupted runs of outputs.exp, which used to
lead to spurious non-repeatable (self-fixing) failures.

for  gcc/testsuite/ChangeLog

* gcc.misc-tests/outputs.exp: Clean up left-overs first.

2 years agotestsuite: outputs.exp: test for skip_atsave more thoroughly
Alexandre Oliva [Wed, 22 Jun 2022 02:10:58 +0000 (23:10 -0300)]
testsuite: outputs.exp: test for skip_atsave more thoroughly

The presence of -I or -L flags in link command lines changes the
driver's, and thus the linker's behavior, WRT naming files with
command-line options.  With such flags, the driver creates .args.0 and
.args.1 files, whereas without them it's the linker (collect2, really)
that creates .ld1_args.

I've hit some fails on a target system that doesn't have -I or -L
flags in the board config file, but it does add some of them
implicitly with configured-in driver self specs.  Alas, the test in
outputs.exp doesn't catch that, so we proceed to run rather than
skip_atsave tests.

I've reworked the outest procedure to allow dry runs and to return
would-have-been pass/fail results as lists, so we can now test whether
certain files are created and use that to configure the actual test
runs.

for  gcc/testsuite/ChangeLog

* gcc.misc-tests/outputs.exp (outest): Introduce quiet mode,
create and return lists of passes and fails.  Use it to catch
skip_atsave cases where -L flags are implicitly added by
driver self specs.

2 years agoc++: testsuite: require lto_incremental in pr90990_0.C
Alexandre Oliva [Wed, 22 Jun 2022 02:10:58 +0000 (23:10 -0300)]
c++: testsuite: require lto_incremental in pr90990_0.C

Other LTO tests that use -r require the lto_incremental effective
target.  I suppose pr90990_0.C is missing it due to an oversight.
This patch arranges for this test to also be skipped on
non-lto_incremental targets.

for  gcc/testsuite/ChangeLog

* g++.dg/lto/pr90990_0.C: Require lto_incremental target.

2 years agoi386: Add syscall to enable AMX for latest kernels
Haochen Jiang [Thu, 16 Jun 2022 07:15:53 +0000 (00:15 -0700)]
i386: Add syscall to enable AMX for latest kernels

gcc/testsuite/ChangeLog:

* gcc.target/i386/amx-check.h (request_perm_xtile_data):
New function to check if AMX is usable and enable AMX.
(main): Run test if AMX is usable.

2 years agoxtensa: Fix buffer overflow
Takayuki 'January June' Suwa [Tue, 21 Jun 2022 19:51:32 +0000 (04:51 +0900)]
xtensa: Fix buffer overflow

Fortify buffer overflow message reported.
(see https://github.com/earlephilhower/esp-quick-toolchain/issues/36)

gcc/ChangeLog:

* config/xtensa/xtensa.md (bswapsi2_internal):
Enlarge the buffer that is obviously smaller than the template
string given to sprintf().

2 years agoDaily bump.
GCC Administrator [Wed, 22 Jun 2022 00:16:25 +0000 (00:16 +0000)]
Daily bump.

2 years agoPR target/105991: Recognize PLUS and XOR forms of rldimi in rs6000.md.
Roger Sayle [Tue, 21 Jun 2022 23:08:56 +0000 (00:08 +0100)]
PR target/105991: Recognize PLUS and XOR forms of rldimi in rs6000.md.

This patch addresses PR target/105991 where a change to prefer representing
shifts and adds at the tree-level as multiplications, causes problems for
the rldimi patterns in the powerpc backend.  The issue is that rs6000.md
models this pattern using IOR, and some variants that have the equivalent
PLUS or XOR in the RTL fail to match some *rotl<mode>4_insert patterns.
This is fixed in this patch by adding a define_insn_and_split to locally
canonicalize the PLUS and XOR forms to the backend's preferred IOR form.

An alternative fix might be for the RTL optimizers to define a canonical
form for these plus_xor_ior equivalent expressions, but the logical
choice might be plus (which may appear in an addressing mode), and such
a change may require a number of tweaks to update various backends
(i.e.  a more intrusive change than the one proposed here).

Many thanks for Marek Polacek for bootstrapping and regression testing
this change without problems.

2022-06-22  Roger Sayle  <roger@nextmovesoftware.com>
    Marek Polacek  <polacek@redhat.com>
    Segher Boessenkool  <segher@kernel.crashing.org>
    Kewen Lin  <linkw@linux.ibm.com>

gcc/ChangeLog
PR target/105991
* config/rs6000/rs6000.md (rotl<mode>3_insert_3): Check that
exact_log2 doesn't return -1 (or zero).
(plus_xor): New code iterator.
(*rotl<mode>3_insert_3_<code>): New define_insn_and_split.

gcc/testsuite/ChangeLog
PR target/105991
* gcc.target/powerpc/pr105991.c: New test case.

2 years agolibgomp: Fix up target-31.c test [PR106045]
Jakub Jelinek [Tue, 21 Jun 2022 15:51:08 +0000 (17:51 +0200)]
libgomp: Fix up target-31.c test [PR106045]

The i variable is used inside of the parallel in:
      #pragma omp simd safelen(32) private (v)
      for (i = 0; i < 64; i++)
        {
          v = 3 * i;
          ll[i] = u1 + v * u2[0] + u2[1] + x + y[0] + y[1] + v + h[0] + u3[i];
        }
where i is predetermined linear (so while inside of the body
it is safe, private per SIMD lane var) the final value is written to
the shared variable, and in:
      for (i = 0; i < 64; i++)
        if (ll[i] != u1 + 3 * i * u2[0] + u2[1] + x + y[0] + y[1] + 3 * i + 13 + 14 + i)
          #pragma omp atomic write
            err = 1;
which is a normal loop and so it isn't in any way privatized there.
So we have a data race, fixed by adding private (i) clause to the
parallel.

2022-06-21  Jakub Jelinek  <jakub@redhat.com>
    Paul Iannetta  <piannetta@kalrayinc.com>

PR libgomp/106045
* testsuite/libgomp.c/target-31.c: Add private (i) clause.

2 years agolibgo: #include <sys/types.h> when checking for loff_t
Ian Lance Taylor [Sun, 19 Jun 2022 01:19:28 +0000 (18:19 -0700)]
libgo: #include <sys/types.h> when checking for loff_t

PR go/106033

Fixes golang/go#53469

Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/413214

2 years agodoc: Document module language-linkage supported
Nathan Sidwell [Tue, 21 Jun 2022 13:23:11 +0000 (06:23 -0700)]
doc: Document module language-linkage supported

I missed we documented this as unimplemented, when I implemented it.

gcc/
* doc/invoke.texi (C++ Modules): Remove language-linkage
as missing feature.

2 years agomatch.pd: Remove "+ 0x80000000" in int comparisons [PR94899]
Arjun Shankar [Tue, 21 Jun 2022 10:12:11 +0000 (12:12 +0200)]
match.pd: Remove "+ 0x80000000" in int comparisons [PR94899]

Expressions of the form "X + CST < Y + CST" where:

* CST is an unsigned integer constant with only the MSB set, and
* X and Y's types have integer conversion ranks <= CST's

can be simplified to "(signed) X < (signed) Y".

This is because, assuming a 32-bit signed numbers,
(unsigned) INT_MIN + 0x80000000 is 0, and
(unsigned) INT_MAX + 0x80000000 is UINT_MAX.

i.e. the result increases monotonically with signed input.

This means:
((signed) X < (signed) Y) iff (X + 0x80000000 < Y + 0x80000000)

gcc/
PR tree-optimization/94899
* match.pd (X + C < Y + C -> (signed) X < (signed) Y, if C is
0x80000000): New simplification.
gcc/testsuite/
* gcc.dg/pr94899.c: New test.

2 years agoifcvt: Don't introduce trapping or faulting reads in noce_try_sign_mask [PR106032]
Jakub Jelinek [Tue, 21 Jun 2022 09:40:16 +0000 (11:40 +0200)]
ifcvt: Don't introduce trapping or faulting reads in noce_try_sign_mask [PR106032]

noce_try_sign_mask as documented will optimize
  if (c < 0)
    x = t;
  else
    x = 0;
into x = (c >> bitsm1) & t;
The optimization is done if either t is unconditional
(e.g. for
  x = t;
  if (c >= 0)
    x = 0;
) or if it is cheap.  We already check that t doesn't have side-effects,
but if t is conditional, we need to punt also if it may trap or fault,
as we make it unconditional.

I've briefly skimmed other noce_try* optimizations and didn't find one that
would suffer from the same problem.

2022-06-21  Jakub Jelinek  <jakub@redhat.com>

PR rtl-optimization/106032
* ifcvt.cc (noce_try_sign_mask): Punt if !t_unconditional, and
t may_trap_or_fault_p, even if it is cheap.

* gcc.c-torture/execute/pr106032.c: New test.

2 years agoexpand: Fix up expand_cond_expr_using_cmove [PR106030]
Jakub Jelinek [Tue, 21 Jun 2022 09:38:59 +0000 (11:38 +0200)]
expand: Fix up expand_cond_expr_using_cmove [PR106030]

If expand_cond_expr_using_cmove can't find a cmove optab for a particular
mode, it tries to promote the mode and perform the cmove in the promoted
mode.

The testcase in the patch ICEs on arm because in that case we pass temp which
has the promoted mode (SImode) as target to expand_operands where the
operands have the non-promoted mode (QImode).
Later on the function uses paradoxical subregs:
  if (GET_MODE (op1) != mode)
    op1 = gen_lowpart (mode, op1);

  if (GET_MODE (op2) != mode)
    op2 = gen_lowpart (mode, op2);
to change the operand modes.

The following patch fixes it by passing NULL_RTX as target if it has
promoted mode.

2022-06-21  Jakub Jelinek  <jakub@redhat.com>

PR middle-end/106030
* expr.cc (expand_cond_expr_using_cmove): Pass NULL_RTX instead of
temp to expand_operands if mode has been promoted.

* gcc.c-torture/compile/pr106030.c: New test.

2 years agoif-to-switch: Don't skip the first condition bb when find_conditions in if-to-switch...
Xionghu Luo [Thu, 9 Jun 2022 07:46:30 +0000 (15:46 +0800)]
if-to-switch: Don't skip the first condition bb when find_conditions in if-to-switch [PR105740]

The if condition is at last of first bb, so side effect statement in first BB
doesn't matter, then the first if condition could also be folded to switch
table.

gcc/ChangeLog:

PR target/105740
* gimple-if-to-switch.cc (find_conditions): Don't skip the first
condition bb.

gcc/testsuite/ChangeLog:

PR target/105740
* gcc.dg/tree-ssa/if-to-switch-11.c: New test.

Signed-off-by: Xionghu Luo <xionghuluo@tencent.com>
2 years agotree-object-size: Don't let error_mark_node escape for ADDR_EXPR [PR105736]
Siddhesh Poyarekar [Tue, 21 Jun 2022 06:45:07 +0000 (12:15 +0530)]
tree-object-size: Don't let error_mark_node escape for ADDR_EXPR [PR105736]

The addr_expr computation does not check for error_mark_node before
returning the size expression.  This used to work in the constant case
because the conversion to uhwi would end up causing it to return
size_unknown, but that won't work for the dynamic case.

Modify the control flow to explicitly return size_unknown if the offset
computation returns an error_mark_node.

gcc/ChangeLog:

PR tree-optimization/105736
* tree-object-size.cc (addr_object_size): Return size_unknown
when object offset computation returns an error.

gcc/testsuite/ChangeLog:

PR tree-optimization/105736
* gcc.dg/builtin-dynamic-object-size-0.c (TV4): New struct.
(val3): New variable.
(test_pr105736): New test.
(main): Call it.

Signed-off-by: Siddhesh Poyarekar <siddhesh@gotplt.org>
2 years agoDaily bump.
GCC Administrator [Tue, 21 Jun 2022 00:16:27 +0000 (00:16 +0000)]
Daily bump.

2 years agotestsuite, asan: Avoid color in asan test output.
Iain Sandoe [Sun, 19 Jun 2022 09:31:01 +0000 (10:31 +0100)]
testsuite, asan: Avoid color in asan test output.

The presence of the color markers in the some of the asan tests
appears to confuse the dg-output matching (possibly a platform
TCL or termios bug) on some Darwin platforms.

Since the color is not being tested, switch it off (makes the log
files easier to read too).  This fixes a large number of spurious
test fails on AVX512 Darwin19.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
gcc/testsuite/ChangeLog:

* lib/asan-dg.exp: Do not apply color to asan output when
under test.

2 years agoi386: Disallow sibcall for calling ifunc functions with PIC register
H.J. Lu [Tue, 14 Jun 2022 15:20:16 +0000 (08:20 -0700)]
i386: Disallow sibcall for calling ifunc functions with PIC register

Disallow siball when calling ifunc functions with PIC register so that
PIC register can be restored.

gcc/

PR target/105960
* config/i386/i386.cc (ix86_function_ok_for_sibcall): Return
false if PIC register is used when calling ifunc functions.

gcc/testsuite/

PR target/105960
* gcc.target/i386/pr105960.c: New test.

2 years agotestsuite, Darwin: Skip an unsupported test.
Iain Sandoe [Sun, 19 Jun 2022 09:28:05 +0000 (10:28 +0100)]
testsuite, Darwin: Skip an unsupported test.

Darwin does not support patchable function entries, skip the test
there.

gcc/testsuite/ChangeLog:

* g++.dg/modules/pr105169_a.C: Skip the test on Darwin.
* g++.dg/modules/pr105169_b.C: Likewise.

2 years agotestsuite, Darwin: Allow for two CTOR bodies in array61 test.
Iain Sandoe [Sun, 19 Jun 2022 09:21:28 +0000 (10:21 +0100)]
testsuite, Darwin: Allow for two CTOR bodies in array61 test.

For targets without alias support, we emit two essentially identical function
bodies into the gimple (complete and base CTORs). So this test needs to allow
for that when the target does not support aliases.  The target support alias
test does not seem to be usable in the context of a single scan-tree-dump so
the fix here uses the target designation.

Note that the array has 10 elements, so that if the test were failing (because
we were emitting 10 inits instead of a loop) the count would be expected to
exceed 2, on Darwin and 1 where there's alias support.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
gcc/testsuite/ChangeLog:

* g++.dg/init/array61.C: Allow for two CTOR bodies on Darwin, where
aliases are not currently supported.

2 years agoarm: more testsutie fallout for mve move-immediate changes
Richard Earnshaw [Mon, 20 Jun 2022 15:18:36 +0000 (16:18 +0100)]
arm: more testsutie fallout for mve move-immediate changes

Unfortunately, there is more fall-out in the testsuite for my changes
to use MVE move-immediate operations instead of literal pool loads.
Fixed as follows:

gcc/testsuite/ChangeLog:
* gcc.target/arm/simd/mve-vcmp-f32-2.c: Adjust expected output.
* gcc.target/arm/simd/pr100757.c: Likewise.
* gcc.target/arm/simd/pr100757-2.c: Likewise.
* gcc.target/arm/simd/pr100757-3.c: Likewise.
* gcc.target/arm/simd/pr100757-4.c: Likewise.

2 years agotestsuite: Add a missing USER_LABEL_PREFIX to a regex.
Iain Sandoe [Sun, 19 Jun 2022 09:16:26 +0000 (10:16 +0100)]
testsuite: Add a missing USER_LABEL_PREFIX to a regex.

Fixes this test on Darwin.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
gcc/testsuite/ChangeLog:

* g++.dg/modules/init-2_b.C: Add a missing USER_LABEL_PREFIX
to a regex.

2 years agotestsuite: Require init_priority target support in a test.
Iain Sandoe [Sun, 19 Jun 2022 09:12:47 +0000 (10:12 +0100)]
testsuite: Require init_priority target support in a test.

The attr-cdtor-1 test fails on targets without init priority since the
diagnostic emitted concerns the absence of support.  Disable the test
on such targets.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
gcc/testsuite/ChangeLog:

* c-c++-common/attr-cdtor-1.c: Requite init_priority support.

2 years agomiddle-end/106027 - fix types in needle folding
Richard Biener [Mon, 20 Jun 2022 11:40:50 +0000 (13:40 +0200)]
middle-end/106027 - fix types in needle folding

The fold_to_nonsharp_ineq_using_bound folding ends up creating invalid
typed IL which confuses later foldings.  The following fixes that.

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

PR middle-end/106027
* fold-const.cc (fold_to_nonsharp_ineq_using_bound): Use the
type of the prevailing comparison for the new comparison type.
(fold_binary_loc): Use proper types for the A < X && A + 1 > Y
to A < X && A >= Y folding.

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

2 years agovect: Respect slp decision when applying suggested uf [PR105940]
Kewen Lin [Mon, 20 Jun 2022 12:44:21 +0000 (07:44 -0500)]
vect: Respect slp decision when applying suggested uf [PR105940]

This follows Richi's suggestion in PR105940, it aims to avoid
inconsistent slp decision between when the suggested unroll
factor is worked out and when the suggested unroll factor is
applied.

If the previous slp decision is true when the suggested unroll
factor is worked out, when we are applying unroll factor we
don't need to start over with slp off if the analysis with slp
on fails.  On the other hand, if the previous slp decision is
false when the suggested unroll factor is worked out, when we
are applying unroll factor we can skip the slp handlings.

Function vect_is_simple_reduction saves reduction chains for
subsequent slp analyses, we have to disable this early otherwise
there is an ICE in vectorizable_reduction for below:

  if (REDUC_GROUP_FIRST_ELEMENT (stmt_info))
    gcc_assert (slp_node
&& REDUC_GROUP_FIRST_ELEMENT (stmt_info)
   == stmt_info);

PR tree-optimization/105940

gcc/ChangeLog:

* tree-vect-loop.cc (vect_analyze_loop_2): Add new parameter
slp_done_for_suggested_uf and adjust with it accordingly.
(vect_analyze_loop_1): Add new variable slp_done_for_suggested_uf,
pass it down to vect_analyze_loop_2 for the initial analysis and
applying suggested unroll factor.
(vect_is_simple_reduction): Add parameter slp and adjust with it.
(vect_analyze_scalar_cycles_1): Add parameter slp and pass down.
(vect_analyze_scalar_cycles): Likewise.

2 years agolto-plugin: support LDPT_GET_SYMBOLS_V3
Martin Liska [Mon, 14 Feb 2022 10:31:43 +0000 (11:31 +0100)]
lto-plugin: support LDPT_GET_SYMBOLS_V3

That supports skipping of an object file (LDPS_NO_SYMS).

lto-plugin/ChangeLog:

* lto-plugin.c (struct plugin_file_info): Add skip_file flag.
(write_resolution): Write resolution only if get_symbols != LDPS_NO_SYMS.
(all_symbols_read_handler): Ignore file if skip_file is true.
(onload): Handle LDPT_GET_SYMBOLS_V3.

2 years agoAdd operators / and * for profile_{count,probability}.
Martin Liska [Tue, 25 Jan 2022 18:16:06 +0000 (19:16 +0100)]
Add operators / and * for profile_{count,probability}.

gcc/ChangeLog:

* bb-reorder.cc (find_traces_1_round): Add operators / and * and
use them.
(better_edge_p): Likewise.
* cfgloop.cc (find_subloop_latch_edge_by_profile): Likewise.
* cfgloopmanip.cc (scale_loop_profile): Likewise.
* cfgrtl.cc (force_nonfallthru_and_redirect): Likewise.
* cgraph.cc (cgraph_edge::maybe_hot_p): Likewise.
* config/sh/sh.cc (expand_cbranchdi4): Likewise.
* dojump.cc (do_compare_rtx_and_jump): Likewise.
* final.cc (compute_alignments): Likewise.
* ipa-cp.cc (update_counts_for_self_gen_clones): Likewise.
(decide_about_value): Likewise.
* ipa-inline-analysis.cc (do_estimate_edge_time): Likewise.
* loop-unroll.cc (unroll_loop_runtime_iterations): Likewise.
* modulo-sched.cc (sms_schedule): Likewise.
* omp-expand.cc (extract_omp_for_update_vars): Likewise.
(expand_omp_ordered_sink): Likewise.
(expand_omp_for_ordered_loops): Likewise.
(expand_omp_for_static_nochunk): Likewise.
* predict.cc (maybe_hot_count_p): Likewise.
(probably_never_executed): Likewise.
(set_even_probabilities): Likewise.
(handle_missing_profiles): Likewise.
(expensive_function_p): Likewise.
* profile-count.h: Likewise.
* profile.cc (compute_branch_probabilities): Likewise.
* stmt.cc (emit_case_dispatch_table): Likewise.
* symtab-thunks.cc (expand_thunk): Likewise.
* tree-ssa-loop-manip.cc (tree_transform_and_unroll_loop): Likewise.
* tree-ssa-sink.cc (select_best_block): Likewise.
* tree-switch-conversion.cc (switch_decision_tree::analyze_switch_statement): Likewise.
(switch_decision_tree::balance_case_nodes): Likewise.
(switch_decision_tree::emit_case_nodes): Likewise.
* tree-vect-loop.cc (scale_profile_for_vect_loop): Likewise.

2 years agoRISC-V: Fix a bug that is the CMO builtins are missing parameter
yulong [Wed, 8 Jun 2022 02:19:21 +0000 (10:19 +0800)]
RISC-V: Fix a bug that is the CMO builtins are missing parameter

We changed builtins format about zicbom and zicboz subextensions and modified test cases.

diff with the previous version:
1.We modified the FUNCTION_TYPE from RISCV_VOID_FTYPE_SI/DI to RISCV_VOID_FTYPE_VOID_PTR.
2.We added a new RISCV_ATYPE_VOID_PTR in riscv-builtins.cc and a new DEF_RISCV_FTYPE (1, (VOID, VOID_PTR)) in riscv-ftypes.def.
3.We deleted DEF_RISCV_FTYPE (1, (VOID, SI/DI)).
4.We modified the input parameters of the test cases.

Thanks, Simon and Kito.

gcc/ChangeLog:

* config/riscv/riscv-builtins.cc (RISCV_ATYPE_VOID_PTR): New.
* config/riscv/riscv-cmo.def (RISCV_BUILTIN): Changed the FUNCTION_TYPE
of RISCV_BUILTIN.
* config/riscv/riscv-ftypes.def (0): Remove unused.
(1): New.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/cmo-zicbom-1.c: modified the input parameters.
* gcc.target/riscv/cmo-zicbom-2.c: modified the input parameters.
* gcc.target/riscv/cmo-zicboz-1.c: modified the input parameters.
* gcc.target/riscv/cmo-zicboz-2.c: modified the input parameters.

2 years agoDaily bump.
GCC Administrator [Mon, 20 Jun 2022 00:16:24 +0000 (00:16 +0000)]
Daily bump.

2 years agoxtensa: Fix RTL insn cost estimation about relaxed MOVI instructions
Takayuki 'January June' Suwa [Sun, 19 Jun 2022 19:13:56 +0000 (04:13 +0900)]
xtensa: Fix RTL insn cost estimation about relaxed MOVI instructions

These instructions will all be converted to L32R ones with litpool entries
by the assembler.

gcc/ChangeLog:

* config/xtensa/xtensa.cc (xtensa_is_insn_L32R_p):
Consider relaxed MOVI instructions as L32R.

2 years agoxtensa: Apply a few minor fixes
Takayuki 'January June' Suwa [Sun, 19 Jun 2022 19:12:48 +0000 (04:12 +0900)]
xtensa: Apply a few minor fixes

No functional changes.

gcc/ChangeLog:

* config/xtensa/xtensa.cc (xtensa_emit_move_sequence):
Use can_create_pseudo_p(), instead of using individual
reload_in_progress and reload_completed.
(xtensa_expand_block_set_small_loop): Use xtensa_simm8x256(),
the existing predicate function.
(xtensa_is_insn_L32R_p, gen_int_relational, xtensa_emit_sibcall):
Use the standard RTX code predicate macros such as MEM_P,
SYMBOL_REF_P and/or CONST_INT_P.
* config/xtensa/xtensa.md: Avoid using numeric literals to determine
if callee-saved register, at the split patterns for indirect sibcall
fixups.

2 years agoDaily bump.
GCC Administrator [Sun, 19 Jun 2022 00:16:23 +0000 (00:16 +0000)]
Daily bump.

2 years agoFortran: check POS and LEN arguments simplifying bit intrinsics [PR105986]
Harald Anlauf [Wed, 15 Jun 2022 20:20:09 +0000 (22:20 +0200)]
Fortran: check POS and LEN arguments simplifying bit intrinsics [PR105986]

gcc/fortran/ChangeLog:

PR fortran/105986
* simplify.cc (gfc_simplify_btest): Add check for POS argument.
(gfc_simplify_ibclr): Add check for POS argument.
(gfc_simplify_ibits): Add check for POS and LEN arguments.
(gfc_simplify_ibset): Add check for POS argument.

gcc/testsuite/ChangeLog:

PR fortran/105986
* gfortran.dg/check_bits_3.f90: New test.

2 years agoubsan: Add -fsanitize-trap= support
Jakub Jelinek [Sat, 18 Jun 2022 09:09:48 +0000 (11:09 +0200)]
ubsan: Add -fsanitize-trap= support

On Thu, Jun 16, 2022 at 09:32:02PM +0100, Jonathan Wakely wrote:
> It looks like clang has addressed this deficiency now:
>
> https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html#usage

Thanks, that is roughly what I'd implement anyway and apparently they have
it already since 2015, we've added the -fsanitize-undefined-trap-on-error
support back in 2014 and didn't change it since then.

As a small divergence from clang, I chose -fsanitize-undefined-trap-on-error
to be a (deprecated) alias for -fsanitize-trap aka -fsanitize-trap=all
rather thn -fsanitize-trap=undefined which seems to be what clang does,
because for a deprecated option it is IMHO more important backwards
compatibility with what gcc did over the past 8 years rather than clang
compatibility.
Some sanitizers (e.g. asan, lsan, tsan) don't support traps,
-fsanitize-trap=address etc. will be rejected (if enabled at the end of
command line), -fno-sanitize-trap= can be specified even for them.
This is similar behavior to -fsanitize-recover=.
One complication is vptr sanitization, which can't easily trap,
as the whole slow path of the checking is inside of libubsan.
Previously, -fsanitize=vptr -fsanitize-undefined-trap-on-error
silently ignored vptr sanitization.
This patch similarly to what clang does will accept
-fsanitize-trap=all or -fsanitize-trap=undefined which enable
the vptr bit as trapping and again that causes silent disabling
of vptr sanitization, while -fsanitize-trap=vptr is rejected
(already during option processing).

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

gcc/
* common.opt (flag_sanitize_trap): New variable.
(fsanitize-trap=, fsanitize-trap): New options.
(fsanitize-undefined-trap-on-error): Change into deprecated alias
for -fsanitize-trap=all.
* opts.h (struct sanitizer_opts_s): Add can_trap member.
* opts.cc (finish_options): Complain about unsupported
-fsanitize-trap= options.
(sanitizer_opts): Add can_trap values to all entries.
(get_closest_sanitizer_option): Ignore -fsanitize-trap=
options which have can_trap false.
(parse_sanitizer_options): Add support for -fsanitize-trap=.
For -fsanitize-trap=all, enable
SANITIZE_UNDEFINED | SANITIZE_UNDEFINED_NONDEFAULT.  Disallow
-fsanitize-trap=vptr here.
(common_handle_option): Handle OPT_fsanitize_trap_ and
OPT_fsanitize_trap.
* sanopt.cc (maybe_optimize_ubsan_null_ifn): Check
flag_sanitize_trap & SANITIZE_{NULL,ALIGNMENT} instead of
flag_sanitize_undefined_trap_on_error.
* gcc.cc (sanitize_spec_function): Use
flag_sanitize & ~flag_sanitize_trap instead of flag_sanitize
and drop use of flag_sanitize_undefined_trap_on_error in
"undefined" handling.
* ubsan.cc (ubsan_instrument_unreachable): Use
flag_sanitize_trap & SANITIZE_??? instead of
flag_sanitize_undefined_trap_on_error.
(ubsan_expand_bounds_ifn, ubsan_expand_null_ifn,
ubsan_expand_objsize_ifn, ubsan_expand_ptr_ifn,
ubsan_build_overflow_builtin, instrument_bool_enum_load,
ubsan_instrument_float_cast, instrument_nonnull_arg,
instrument_nonnull_return, instrument_builtin): Likewise.
* doc/invoke.texi (-fsanitize-trap=, -fsanitize-trap): Document.
(-fsanitize-undefined-trap-on-error): Document as deprecated
alias of -fsanitize-trap.
gcc/c-family/
* c-ubsan.cc (ubsan_instrument_division, ubsan_instrument_shift):
Use flag_sanitize_trap & SANITIZE_??? instead of
flag_sanitize_undefined_trap_on_error.  If 2 sanitizers are involved
and flag_sanitize_trap differs for them, emit __builtin_trap only
for the comparison where trap is requested.
(ubsan_instrument_vla, ubsan_instrument_return): Use
lag_sanitize_trap & SANITIZE_??? instead of
flag_sanitize_undefined_trap_on_error.
gcc/cp/
* cp-ubsan.cc (cp_ubsan_instrument_vptr_p): Use
flag_sanitize_trap & SANITIZE_VPTR instead of
flag_sanitize_undefined_trap_on_error.
gcc/testsuite/
* c-c++-common/ubsan/nonnull-4.c: Use -fsanitize-trap=all
instead of -fsanitize-undefined-trap-on-error.
* c-c++-common/ubsan/div-by-zero-4.c: Use
-fsanitize-trap=signed-integer-overflow instead of
-fsanitize-undefined-trap-on-error.
* c-c++-common/ubsan/overflow-add-4.c: Use -fsanitize-trap=undefined
instead of -fsanitize-undefined-trap-on-error.
* c-c++-common/ubsan/pr56956.c: Likewise.
* c-c++-common/ubsan/pr68142.c: Likewise.
* c-c++-common/ubsan/pr80932.c: Use
-fno-sanitize-trap=all -fsanitize-trap=shift,undefined
instead of -fsanitize-undefined-trap-on-error.
* c-c++-common/ubsan/align-8.c: Use -fsanitize-trap=alignment
instead of -fsanitize-undefined-trap-on-error.

2 years agovarasm: Fix up ICE in narrowing_initializer_constant_valid_p [PR105998]
Jakub Jelinek [Sat, 18 Jun 2022 09:07:13 +0000 (11:07 +0200)]
varasm: Fix up ICE in narrowing_initializer_constant_valid_p [PR105998]

The following testcase ICEs because there is NON_LVALUE_EXPR (location
wrapper) around a VAR_DECL and has TYPE_MODE V2SImode and
SCALAR_INT_TYPE_MODE on that ICEs.  Or for -m32 -march=i386 TYPE_MODE
is DImode, but SCALAR_INT_TYPE_MODE still uses the raw V2SImode and ICEs
too.

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

PR middle-end/105998
* varasm.cc (narrowing_initializer_constant_valid_p): Check
SCALAR_INT_MODE_P instead of INTEGRAL_MODE_P, also break on
! INTEGRAL_TYPE_P and do the same check also on op{0,1}'s type.

* c-c++-common/pr105998.c: New test.

2 years agoPR tree-optimization/105835: Two narrowing patterns for match.pd.
Roger Sayle [Sat, 18 Jun 2022 08:06:20 +0000 (09:06 +0100)]
PR tree-optimization/105835: Two narrowing patterns for match.pd.

This patch resolves PR tree-optimization/105835, which is a code quality
(dead code elimination) regression at -O1 triggered/exposed by a recent
change to canonicalize X&-Y as X*Y.  The new (shorter) form exposes some
missed optimization opportunities that can be handled by adding some
extra simplifications to match.pd.

One transformation is to simplify "(short)(x ? 65535 : 0)" into the
equivalent "x ? -1 : 0", or more accurately x ? (short)-1 : (short)0",
as INTEGER_CSTs record their type, and integer conversions can be
pushed inside COND_EXPRs reducing the number of gimple statements.

The other transformation is that (short)(X * 65535), where X is [0,1],
into the equivalent (short)X * -1, (or again (short)-1 where tree's
INTEGER_CSTs encode their type).  This is valid because multiplications
where one operand is [0,1] are guaranteed not to overflow, and hence
integer conversions can also be pushed inside these multiplications.

These narrowing conversion optimizations can be identified by range
analyses, such as EVRP, but these are only performed at -O2 and above,
which is why this regression is only visible with -O1.

2022-06-18  Roger Sayle  <roger@nextmovesoftware.com>

gcc/ChangeLog
PR tree-optimization/105835
* match.pd (convert (mult zero_one_valued_p@1 INTEGER_CST@2)):
Narrow integer multiplication by a zero_one_valued_p operand.
(convert (cond @1 INTEGER_CST@2 INTEGER_CST@3)): Push integer
conversions inside COND_EXPR where both data operands are
integer constants.

gcc/testsuite/ChangeLog
PR tree-optimization/105835
* gcc.dg/pr105835.c: New test case.

2 years agoxtensa: Defer storing integer constants into litpool until reload
Takayuki 'January June' Suwa [Fri, 17 Jun 2022 13:47:49 +0000 (22:47 +0900)]
xtensa: Defer storing integer constants into litpool until reload

Storing integer constants into litpool in the early stage of compilation
hinders some integer optimizations.  In fact, such integer constants are
not subject to the constant folding process.

For example:

    extern unsigned short value;
    extern void foo(void);
    void test(void) {
      if (value == 30001)
        foo();
    }

.literal_position
.literal .LC0, value
.literal .LC1, 30001
    test:
l32r a3, .LC0
l32r a2, .LC1
l16ui a3, a3, 0
extui a2, a2, 0, 16  // runtime zero-extension despite constant
bne a3, a2, .L1
j.l foo, a9
    .L1:
ret.n

This patch defers the placement of integer constants into litpool until
the start of reload:

.literal_position
.literal .LC0, value
.literal .LC1, 30001
    test:
l32r a3, .LC0
l32r a2, .LC1
l16ui a3, a3, 0
bne a3, a2, .L1
j.l foo, a9
    .L1:
ret.n

gcc/ChangeLog:

* config/xtensa/constraints.md (Y):
Change to include integer constants until reload begins.
* config/xtensa/predicates.md (move_operand): Ditto.
* config/xtensa/xtensa.cc (xtensa_emit_move_sequence):
Change to allow storing integer constants into litpool only after
reload begins.

2 years agoDaily bump.
GCC Administrator [Sat, 18 Jun 2022 00:16:19 +0000 (00:16 +0000)]
Daily bump.

2 years agolibgo: permit loff_t and off_t to be macros
Ian Lance Taylor [Tue, 14 Jun 2022 18:33:42 +0000 (11:33 -0700)]
libgo: permit loff_t and off_t to be macros

They are macros in musl libc, rather than typedefs, and -fgo-dump-spec
doesn't handle that case.

Based on patch by Sören Tempel.

Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/412075

2 years agoc++: Use fold_non_dependent_expr rather than maybe_constant_value in __builtin_shuffl...
Jakub Jelinek [Fri, 17 Jun 2022 15:40:49 +0000 (17:40 +0200)]
c++: Use fold_non_dependent_expr rather than maybe_constant_value in __builtin_shufflevector handling [PR106001]

In this case the STATIC_CAST_EXPR expressions in the call aren't
type nor value dependent, but maybe_constant_value still ICEs on those
when processing_template_decl.  Calling fold_non_dependent_expr on it
instead fixes the ICE and folds them to INTEGER_CSTs.

2022-06-17  Jakub Jelinek  <jakub@redhat.com>

PR c++/106001
* typeck.cc (build_x_shufflevector): Use fold_non_dependent_expr
instead of maybe_constant_value.

* g++.dg/ext/builtin-shufflevector-4.C: New test.

2 years agoalpha: Introduce target specific store_data_bypass_p function [PR105209]
Uros Bizjak [Fri, 17 Jun 2022 15:19:44 +0000 (17:19 +0200)]
alpha: Introduce target specific store_data_bypass_p function [PR105209]

This patch introduces alpha-specific version of store_data_bypass_p that
ignores TRAP_IF that would result in assertion failure (and internal
compiler error) in the generic store_data_bypass_p function.

While at it, also remove ev4_ist_c reservation, store_data_bypass_p
can handle the patterns with multiple sets since some time ago.

2022-06-17  Uroš Bizjak  <ubizjak@gmail.com>

gcc/ChangeLog:

PR target/105209
* config/alpha/alpha-protos.h (alpha_store_data_bypass_p): New.
* config/alpha/alpha.cc (alpha_store_data_bypass_p): New function.
(alpha_store_data_bypass_p_1): Ditto.
* config/alpha/ev4.md: Use alpha_store_data_bypass_p instead
of generic store_data_bypass_p.
(ev4_ist_c): Remove insn reservation.

gcc/testsuite/ChangeLog:

PR target/105209
* gcc.target/alpha/pr105209.c: New test.

2 years agoi386: Fix assert in ix86_function_arg [PR105970]
Uros Bizjak [Fri, 17 Jun 2022 15:01:31 +0000 (17:01 +0200)]
i386: Fix assert in ix86_function_arg [PR105970]

The mode of pointer argument should equal ptr_mode, not Pmode.

2022-06-17  Uroš Bizjak  <ubizjak@gmail.com>

gcc/ChangeLog:

PR target/105970
* config/i386/i386.cc (ix86_function_arg): Assert that
the mode of pointer argumet is equal to ptr_mode, not Pmode.

gcc/testsuite/ChangeLog:

PR target/105970
* gcc.target/i386/pr105970.c: New test.

2 years agoi386: Fix VPMOV splitter [PR105993]
Uros Bizjak [Fri, 17 Jun 2022 14:22:20 +0000 (16:22 +0200)]
i386: Fix VPMOV splitter [PR105993]

REGNO should not be used with register_operand before reload because
subregs of registers or even subregs of memory match the predicate.
The build with RTL checking enabled does not tolerate REGNO with
non-reg operand.
The patch splits the splitter into two related splitters and uses
(match_dup ...) RTXes instead of REGNO comparisons.

2022-06-17  Uroš Bizjak  <ubizjak@gmail.com>

gcc/ChangeLog:

PR target/105993
* config/i386/sse.md (vpmov splitter): Use (match_dup ...)
instead of REGNO comparisons in combine splitter.

gcc/testsuite/ChangeLog:

PR target/105993
* gcc.target/i386/pr105993.c: New test.

2 years agors6000: Fix some error messages for invalid conversions
Segher Boessenkool [Fri, 17 Jun 2022 14:07:37 +0000 (14:07 +0000)]
rs6000: Fix some error messages for invalid conversions

"* something" isn't a type.  "something *" is.

2022-06-17  Segher Boessenkool  <segher@kernel.crashing.org>

* config/rs6000/rs6000.cc (rs6000_invalid_conversion): Correct some
types.

2 years agoRISC-V: Supress warning for comparison of integer expressions of different signedness
Kito Cheng [Fri, 17 Jun 2022 13:57:35 +0000 (21:57 +0800)]
RISC-V: Supress warning for comparison of integer expressions of different signedness

gcc/ChangeLog:

* config/riscv/bitmanip.md: Supress warning.

2 years agoarm: fix checking ICE in arm_print_operand [PR106004]
Richard Earnshaw [Fri, 17 Jun 2022 13:25:51 +0000 (14:25 +0100)]
arm: fix checking ICE in arm_print_operand [PR106004]

Sigh, another instance where I incorrectly used XUINT instead of
UINTVAL.

I've also made the code here a little more robust (although I think
this case can't in fact be reached) if the 32-bit clear mask includes
bit 31.  This case, if reached, would print out an out-of-range value
based on the size of the compiler's HOST_WIDE_INT type due to
sign-extension.  We avoid this by masking the value after inversion.

gcc/ChangeLog:
PR target/106004
* config/arm/arm.cc (arm_print_operand, case 'V'): Use UINTVAL.
Clear bits in the mask above bit 31.

2 years agolibstdc++: Add missing #include <string> to new test
Jonathan Wakely [Fri, 17 Jun 2022 12:29:05 +0000 (13:29 +0100)]
libstdc++: Add missing #include <string> to new test

Somehow I pushed a different version of this test to the one I actually
tested.

libstdc++-v3/ChangeLog:

* testsuite/21_strings/basic_string/cons/char/105995.cc: Add
missing #include.

2 years agodocs: add missing table header
Martin Liska [Fri, 17 Jun 2022 11:33:35 +0000 (13:33 +0200)]
docs: add missing table header

libgomp/ChangeLog:

* libgomp.texi: Add table header for new features of
OpenMP 5.2.

2 years agoarm: mve: Don't force trivial vector literals to the pool
Richard Earnshaw [Fri, 17 Jun 2022 09:30:57 +0000 (10:30 +0100)]
arm: mve: Don't force trivial vector literals to the pool

A bug in the ordering of the operands in the mve_mov<mode> pattern
meant that all literal values were being pushed to the literal pool.
This patch fixes that and simplifies some of the logic slightly so
that we can use as simple switch statement.

For example:
void f (uint32_t *a)
{
  int i;
  for (i = 0; i < 100; i++)
    a[i] += 1;
}

Now compiles to:
        push    {lr}
        mov     lr, #25
        vmov.i32        q2, #0x1  @ v4si
        ...

instead of

        push    {lr}
        mov     lr, #25
        vldr.64 d4, .L6
        vldr.64 d5, .L6+8
...
.L7:
        .align  3
.L6:
        .word   1
        .word   1
        .word   1
        .word   1

gcc/ChangeLog:
* config/arm/mve.md (*mve_mov<mode>): Re-order constraints
to avoid spilling trivial literals to the constant pool.

gcc/testsuite/ChangeLog:
* gcc.target/arm/acle/cde-mve-full-assembly.c: Adjust expected
output.

2 years agoDaily bump.
GCC Administrator [Fri, 17 Jun 2022 00:16:23 +0000 (00:16 +0000)]
Daily bump.

2 years agogimple-ssa-warn-access.cc: add missing auto_diagnostic_group
David Malcolm [Thu, 16 Jun 2022 21:37:15 +0000 (17:37 -0400)]
gimple-ssa-warn-access.cc: add missing auto_diagnostic_group

Whilst working on SARIF output I noticed some places where followup notes
weren't being properly associated with their warnings in
gcc/gimple-ssa-warn-access.cc.

Fixed thusly.

gcc/ChangeLog:
* gimple-ssa-warn-access.cc (warn_string_no_nul): Add
auto_diagnostic_group to group any warning with its note.
(maybe_warn_for_bound): Likewise.
(check_access): Likewise.
(warn_dealloc_offset): Likewise.
(pass_waccess::maybe_warn_memmodel): Likewise.
(pass_waccess::maybe_check_dealloc_call): Likewise.
(pass_waccess::warn_invalid_pointer): Likewise.
(pass_waccess::check_dangling_stores): Likewise.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2 years agoc-decl: fix "inform" grouping and conditionalization
David Malcolm [Thu, 16 Jun 2022 21:36:38 +0000 (17:36 -0400)]
c-decl: fix "inform" grouping and conditionalization

Whilst working on SARIF output I noticed some places where followup notes
weren't being properly associated with their errors/warnings in c-decl.cc.

Whilst fixing those I noticed some places where we "inform" after a
"warning" without checking that the warning was actually emitted.

Fixed the various issues seen in gcc/c/c-decl.cc thusly.

gcc/c/ChangeLog:
* c-decl.cc (implicitly_declare): Add auto_diagnostic_group to
group the warning with any note.
(warn_about_goto): Likewise to group error or warning with note.
Bail out if the warning wasn't emitted, to avoid emitting orphan
notes.
(lookup_label_for_goto): Add auto_diagnostic_group to
group the error with the note.
(check_earlier_gotos): Likewise.
(c_check_switch_jump_warnings): Likewise for any error/warning.
Conditionalize emission of the notes.
(diagnose_uninitialized_cst_member): Likewise for warning,
conditionalizing emission of the note.
(grokdeclarator): Add auto_diagnostic_group to group the "array
type has incomplete element type" error with any note.
(parser_xref_tag): Add auto_diagnostic_group to group warnings
with their notes.  Conditionalize emission of notes.
(start_struct): Add auto_diagnostic_group to group the
"redefinition of" errors with any note.
(start_enum): Likewise for "redeclaration of %<enum %E%>" error.
(check_for_loop_decls): Likewise for pre-C99 error.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2 years agoanalyzer: associate -Wanalyzer-va-arg-type-mismatch with CWE-686
David Malcolm [Thu, 16 Jun 2022 21:35:16 +0000 (17:35 -0400)]
analyzer: associate -Wanalyzer-va-arg-type-mismatch with CWE-686

gcc/analyzer/ChangeLog:
* varargs.cc (va_arg_type_mismatch::emit): Associate the warning
with CWE-686 ("Function Call With Incorrect Argument Type").

gcc/testsuite/ChangeLog:
* gcc.dg/analyzer/stdarg-1.c
(__analyzer_called_by_test_type_mismatch_1): Verify that
-Wanalyzer-va-arg-type-mismatch is associated with CWE-686.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2 years agoanalyzer: associate -Wanalyzer-va-list-exhausted with CWE-685
David Malcolm [Thu, 16 Jun 2022 21:33:40 +0000 (17:33 -0400)]
analyzer: associate -Wanalyzer-va-list-exhausted with CWE-685

gcc/analyzer/ChangeLog:
* varargs.cc: Include "diagnostic-metadata.h".
(va_list_exhausted::emit): Associate the warning with
CWE-685 ("Function Call With Incorrect Number of Arguments").

gcc/testsuite/ChangeLog:
* gcc.dg/analyzer/stdarg-1.c
(__analyzer_called_by_test_not_enough_args): Verify that
-Wanalyzer-va-list-exhausted is associated with CWE-685.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2 years agoanalyzer: associate -Wanalyzer-double-fclose with CWE-1341
David Malcolm [Thu, 16 Jun 2022 21:27:08 +0000 (17:27 -0400)]
analyzer: associate -Wanalyzer-double-fclose with CWE-1341

gcc/analyzer/ChangeLog:
* sm-file.cc (double_fclose::emit): Associate the warning with
CWE-1341 ("Multiple Releases of Same Resource or Handle").

gcc/testsuite/ChangeLog:
* gcc.dg/analyzer/file-1.c (test_1): Verify that double-fclose is
associated with CWE-1341.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2 years agoopts: fix opts_set->x_flag_sanitize
Jason Merrill [Tue, 14 Jun 2022 21:56:08 +0000 (17:56 -0400)]
opts: fix opts_set->x_flag_sanitize

While working on PR104642 I noticed this wasn't getting set.

gcc/ChangeLog:

* opts.cc (common_handle_option) [OPT_fsanitize_]: Set
opts_set->x_flag_sanitize.

2 years agoflags: add comment
Jason Merrill [Tue, 14 Jun 2022 21:56:08 +0000 (17:56 -0400)]
flags: add comment

gcc/ChangeLog:

* flags.h (issue_strict_overflow_warning): Comment #endif.

2 years agocompiler: don't generate stubs for ambiguous direct interface methods
Mikhail Ablakatov [Thu, 12 May 2022 18:45:35 +0000 (21:45 +0300)]
compiler: don't generate stubs for ambiguous direct interface methods

Current implementation checks whether it has to generate a stub method for a
promoted method of an embedded struct field in Type::build_stub_methods(). If
the promoted method is ambiguous it's simply skipped. But struct types that
can fit in an interface value (e.g. structs that consist of a single pointer
field) get a second chance in Type::build_direct_iface_stub_methods().

This patch adds the same check used by Type::build_stub_methods() to
Type::build_direct_iface_stub_methods().

Fixes golang/go#52870

Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/405974

2 years agolibstdc++: Support constexpr global std::string for size < 15 [PR105995]
Jonathan Wakely [Thu, 16 Jun 2022 13:57:32 +0000 (14:57 +0100)]
libstdc++: Support constexpr global std::string for size < 15 [PR105995]

I don't think this is required by the standard, but it's easy to
support.

libstdc++-v3/ChangeLog:

PR libstdc++/105995
* include/bits/basic_string.h (_M_use_local_data): Initialize
the entire SSO buffer.
* testsuite/21_strings/basic_string/cons/char/105995.cc: New test.

2 years agolibstdc++: Apply r13-1096-g6abe341558abec change to vstring too [PR101482]
Jonathan Wakely [Thu, 16 Jun 2022 10:02:11 +0000 (11:02 +0100)]
libstdc++: Apply r13-1096-g6abe341558abec change to vstring too [PR101482]

As recently done for std::basic_string, __gnu_cxx::__versa_string
equality comparisons can check lengths first for any character type and
traits type, not only for std::char_traits<char>.

libstdc++-v3/ChangeLog:

PR libstdc++/101482
* include/ext/vstring.h (operator==): Always check lengths
before comparing.

2 years agoc++: Elide inactive initializer fns from init array
Nathan Sidwell [Thu, 16 Jun 2022 17:14:56 +0000 (10:14 -0700)]
c++: Elide inactive initializer fns from init array

There's no point adding no-op initializer fns (that a module might
have) to the static initializer list.  Also, we can add any objc
initializer call to a partial initializer function and simplify some
control flow.

gcc/cp/
* decl2.cc (finish_objects): Add startp parameter, adjust.
(generate_ctor_or_dtor_function): Detect empty fn, and don't
generate unnecessary code.  Remove objc startup here ...
(c_parse_final_cleanyps): ... do it here.

gcc/testsuite/
* g++.dg/modules/init-2_b.C: Add init check.
* g++.dg/modules/init-2_c.C: Add init check.

2 years agoClear invariant bit for inferred ranges.
Andrew MacLeod [Thu, 16 Jun 2022 16:44:33 +0000 (12:44 -0400)]
Clear invariant bit for inferred ranges.

The range of an invariant SSA (no outgoing edge range anywhere) is not tracked.
If an inferred range is registered, remove the invariant flag.

* gimple-range-cache.cc (ranger_cache::apply_inferred_ranges): If name
was invaraint before, clear the invariant bit.
* gimple-range-gori.cc (gori_map::set_range_invariant): Add a flag.
* gimple-range-gori.h (gori_map::set_range_invariant): Adjust prototype.

2 years agoPropagator should call value_of_stmt.
Andrew MacLeod [Thu, 31 Mar 2022 13:36:59 +0000 (09:36 -0400)]
Propagator should call value_of_stmt.

When evaluating the LHS of a stmt, its more efficent/better to call
value_of_stmt directly rather than value_of_expr.

* tree-ssa-propagate.cc (before_dom_children): Call value_of_stmt.

2 years agomatch.pd: Improve y == MIN || x < y optimization [PR105983]
Jakub Jelinek [Thu, 16 Jun 2022 12:37:06 +0000 (14:37 +0200)]
match.pd: Improve y == MIN || x < y optimization [PR105983]

On the following testcase, we only optimize bar where this optimization
is performed at GENERIC folding time, but on GIMPLE it doesn't trigger
anymore, as we actually don't see
  (bit_and (ne @1 min_value) (ge @0 @1))
but
  (bit_and (ne @1 min_value) (le @1 @0))
genmatch handles :c modifier not just on commutative operations, but
also comparisons and in that case it means it swaps the comparison.

2022-06-16  Jakub Jelinek  <jakub@redhat.com>

PR tree-optimization/105983
* match.pd (y == XXX_MIN || x < y -> x <= y - 1,
y != XXX_MIN && x >= y -> x > y - 1): Use :cs instead of :s
on non-equality comparisons.

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

2 years agomatch.pd: Fix up __builtin_mul_overflow_p signed type optimization [PR105984]
Jakub Jelinek [Thu, 16 Jun 2022 12:36:04 +0000 (14:36 +0200)]
match.pd: Fix up __builtin_mul_overflow_p signed type optimization [PR105984]

Earlier in the simplification pattern, we require that @0 has compatible
type to the type of IMAGPART_EXPR, but for @1 which is a non-zero constant
all we require is that it the constant fits into that type.
Later the code checks if the constant is negative, because when min / max
values are divided by negative divisor, lo will be higher than hi.
In the following testcase, @1 has unsigned char type, while @0 has
int type, so @1 which is 254 is wi::neg_p and we were swapping lo and hi,
even when @1 cast to int isn't negative.

We could use tree_int_cst_sgn (@1) < 0 as the check instead and it would
work both for narrower types of @1 and even same or wider ones, but
I've noticed we probably don't want to call fold_convert (TREE_TYPE (@0), @1)
twice and when we save that result in a temporary, we can just use wi::neg_p
on that temporary.

2022-06-16  Jakub Jelinek  <jakub@redhat.com>

PR tree-optimization/105984
* match.pd (__builtin_mul_overflow_p (x, cst, (stype) 0) ->
x > stype_max / cst || x < stype_min / cst): fold_convert @1
to TREE_TYPE (@0) just once and test for negative divisor
also on that folded constant instead of on @1.

* gcc.c-torture/execute/pr105984.c: New test.

2 years agoexpand: Fix up IFN_ATOMIC_{BIT*,*CMP_0} expansion [PR105951]
Jakub Jelinek [Thu, 16 Jun 2022 08:58:58 +0000 (10:58 +0200)]
expand: Fix up IFN_ATOMIC_{BIT*,*CMP_0} expansion [PR105951]

Both IFN_ATOMIC_BIT_TEST_AND_* and IFN_ATOMIC_*_FETCH_CMP_0 ifns
are matched if their corresponding optab is implemented for the particular
mode.  The fact that those optabs are implemented doesn't guarantee
they will succeed though, they can just FAIL in their expansion.
The expansion in that case uses expand_atomic_fetch_op as fallback, but
as has been reported and and can be reproduced on the testcases,
even those can fail and we didn't have any fallback after that.
For IFN_ATOMIC_BIT_TEST_AND_* we actually have such calls.  One is
done whenever we lost lhs of the ifn at some point in between matching
it in tree-ssa-ccp.cc and expansion.  The following patch for that case
just falls through and expands as if there was a lhs, creates a temporary
for it.  For the other expand_atomic_fetch_op call in the same expander
and for the only expand_atomic_fetch_op call in the other, this falls
back the hard way, by constructing a CALL_EXPR to the call from which
the ifn has been matched and expanding that.  Either it is lucky and manages
to expand inline, or it emits a libatomic API call.
So that we don't have to rediscover which builtin function to call in the
fallback, we record at tree-ssa-ccp.cc time gimple_call_fn (call) in
an extra argument to the ifn.

2022-06-16  Jakub Jelinek  <jakub@redhat.com>

PR middle-end/105951
* tree-ssa-ccp.cc (optimize_atomic_bit_test_and,
optimize_atomic_op_fetch_cmp_0): Remember gimple_call_fn (call)
as last argument to the internal functions.
* builtins.cc (expand_ifn_atomic_bit_test_and): Adjust for the
extra call argument to ifns.  If expand_atomic_fetch_op fails for the
lhs == NULL_TREE case, fall through into the optab code with
gen_reg_rtx (mode) as target.  If second expand_atomic_fetch_op
fails, construct a CALL_EXPR and expand that.
(expand_ifn_atomic_op_fetch_cmp_0): Adjust for the extra call argument
to ifns.  If expand_atomic_fetch_op fails, construct a CALL_EXPR and
expand that.

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

2 years agors6000: add V1TI into vector comparison expand [PR103316]
Haochen Gui [Mon, 30 May 2022 01:12:34 +0000 (09:12 +0800)]
rs6000: add V1TI into vector comparison expand [PR103316]

This patch adds V1TI mode into a new mode iterator used in vector comparison,shift and rotation expands.  It also merges some vector comparison, shift and rotation expands for V1T1 and other vector integer modes as they have the similar patterns.  The expands for V1TI only are removed.

gcc/
PR target/103316
* config/rs6000/rs6000-builtin.cc (rs6000_gimple_fold_builtin): Enable
gimple folding for RS6000_BIF_VCMPEQUT, RS6000_BIF_VCMPNET,
RS6000_BIF_CMPGE_1TI, RS6000_BIF_CMPGE_U1TI, RS6000_BIF_VCMPGTUT,
RS6000_BIF_VCMPGTST, RS6000_BIF_CMPLE_1TI, RS6000_BIF_CMPLE_U1TI.
* config/rs6000/vector.md (VEC_IC): New mode iterator.  Add support
for new Power10 V1TI instructions.
(vec_cmp<mode><mode>): Set mode iterator to VEC_IC.
(vec_cmpu<mode><mode>): Likewise.
(vector_nlt<mode>): Set mode iterator to VEC_IC.
(vector_nltv1ti): Remove.
(vector_gtu<mode>): Set mode iterator to VEC_IC.
(vector_gtuv1ti): Remove.
(vector_nltu<mode>): Set mode iterator to VEC_IC.
(vector_nltuv1ti): Remove.
(vector_geu<mode>): Set mode iterator to VEC_IC.
(vector_ngt<mode>): Likewise.
(vector_ngtv1ti): Remove.
(vector_ngtu<mode>): Set mode iterator to VEC_IC.
(vector_ngtuv1ti): Remove.
(vector_gtu_<mode>_p): Set mode iterator to VEC_IC.
(vector_gtu_v1ti_p): Remove.
(vrotl<mode>3): Set mode iterator to VEC_IC.  Emit insns for V1TI.
(vrotlv1ti3): Remove.
(vashr<mode>3): Set mode iterator to VEC_IC.  Emit insns for V1TI.
(vashrv1ti3): Remove.

gcc/testsuite/
PR target/103316
* gcc.target/powerpc/pr103316.c: New.
* gcc.target/powerpc/fold-vec-cmp-int128.c: New.

2 years agoclang: fix -Wunused-parameter warning
Martin Liska [Thu, 16 Jun 2022 06:48:39 +0000 (08:48 +0200)]
clang: fix -Wunused-parameter warning

Fixes:
gcc/cp/decl2.cc:158:54: warning: unused parameter 'entry' [-Wunused-parameter]

gcc/cp/ChangeLog:

* decl2.cc (struct priority_map_traits): Remove unused param.

2 years agogengtype: do not skip char after escape sequnce
Martin Liska [Wed, 4 May 2022 14:21:45 +0000 (16:21 +0200)]
gengtype: do not skip char after escape sequnce

Right now, when a \$x escape sequence occures, the
next character after $x is skipped, which is bogus.

The code has very low coverage right now.

gcc/ChangeLog:

* gengtype-state.cc (read_a_state_token): Do not skip extra
character after escaped sequence.

2 years agoopts: improve option suggestion
Martin Liska [Wed, 11 May 2022 14:07:25 +0000 (16:07 +0200)]
opts: improve option suggestion

In case where we have 2 equally good candidates like
-ftrivial-auto-var-init=
-Wtrivial-auto-var-init

for -ftrivial-auto-var-init, we should take the candidate that
has a difference in trailing sign symbol.

PR driver/105564

gcc/ChangeLog:

* spellcheck.cc (test_find_closest_string): Add new test.
* spellcheck.h (class best_match): Prefer a difference in
trailing sign symbol.

2 years agoRISC-V/testsuite: Fix pr105666.c under rv32
Jia-wei Chen [Wed, 8 Jun 2022 09:35:21 +0000 (17:35 +0800)]
RISC-V/testsuite: Fix pr105666.c under rv32

In rv32 regression test, this cases will report an error:

"cc1: error: ABI requires '-march=rv32'"

Add '-mabi' option will fix this.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/pr105666.c: New options.

2 years agoSimplify (B * v + C) * D -> BD* v + CD when B,C,D are all INTEGER_CST.
liuhongt [Tue, 31 May 2022 09:13:21 +0000 (17:13 +0800)]
Simplify (B * v + C) * D -> BD* v + CD when B,C,D are all INTEGER_CST.

Similar for (v + B) * C + D -> C * v + BCD.
Don't simplify it when there's overflow and overflow is UB for type v.

gcc/ChangeLog:

PR tree-optimization/53533
* match.pd: Simplify (B * v + C) * D -> BD * v + CD and
(v + B) * C + D -> C * v + BCD when B,C,D are all INTEGER_CST,
and there's no overflow or !TYPE_OVERFLOW_UNDEFINED.

gcc/testsuite/ChangeLog:

* gcc.target/i386/pr53533-1.c: New test.
* gcc.target/i386/pr53533-2.c: New test.
* gcc.target/i386/pr53533-3.c: New test.
* gcc.target/i386/pr53533-4.c: New test.
* gcc.target/i386/pr53533-5.c: New test.
* gcc.dg/vect/slp-11a.c: Adjust testcase.

2 years agoDaily bump.
GCC Administrator [Thu, 16 Jun 2022 00:16:44 +0000 (00:16 +0000)]
Daily bump.

2 years agoxtensa: Eliminate [DS]Cmode hard register clobber that is immediately followed by...
Takayuki 'January June' Suwa [Tue, 14 Jun 2022 03:53:04 +0000 (12:53 +0900)]
xtensa: Eliminate [DS]Cmode hard register clobber that is immediately followed by whole overwrite the register

RTL expansion of substitution to [DS]Cmode hard register includes obstructive
register clobber.

A simplest example:

    double _Complex test(double _Complex c) {
      return c;
    }

will be converted to:

    (set (reg:DF 42 [ c ]) (reg:DF 2 a2))
    (set (reg:DF 43 [ c+8 ]) (reg:DF 4 a4))
    (clobber (reg:DC 2 a2))
    (set (reg:DF 2 a2) (reg:DF 42 [ c ]))
    (set (reg:DF 4 a4) (reg:DF 43 [ c+8 ]))
    (use (reg:DC 2 a2))
    (return)

and then finally:

    test:
mov a8, a2
mov a9, a3
mov a6, a4
mov a7, a5
mov a2, a8
mov a3, a9
mov a4, a6
mov a5, a7
ret

As you see, it is so ridiculous.

This patch eliminates such clobber in order to prune away the wasted move
instructions by the optimizer:

    test:
ret

gcc/ChangeLog:

* config/xtensa/xtensa.md (DSC): New split pattern and mode iterator.

2 years agoxtensa: Eliminate unwanted reg-reg moves during DFmode input reloads
Takayuki 'January June' Suwa [Tue, 14 Jun 2022 03:39:49 +0000 (12:39 +0900)]
xtensa: Eliminate unwanted reg-reg moves during DFmode input reloads

When spilled DFmode registers are reloaded in, once loaded into a pair of
SImode regs and then copied from that regs.  Such unwanted reg-reg moves
seems not to be eliminated at the "cprop_hardreg" stage, despite no problem
in output reloads.

Luckily it is easy to resolve such inefficiencies, with the use of peephole2
pattern.

gcc/ChangeLog:

* config/xtensa/predicates.md (reload_operand):
New predicate.
* config/xtensa/xtensa.md: New peephole2 pattern.

2 years agoxtensa: Add some dedicated patterns that correspond to GIMPLE canonicalizations
Takayuki 'January June' Suwa [Tue, 14 Jun 2022 03:37:54 +0000 (12:37 +0900)]
xtensa: Add some dedicated patterns that correspond to GIMPLE canonicalizations

This patch offers better RTL representations against straightforward
derivations from some tree optimizers' canonicalized forms.

- rounding up to even, such as '(x + (x & 1))', is canonicalized to
  '((x + 1) & -2)', but the former is one instruction less than the latter
  in Xtensa ISA.
- signed greater or equal to zero as logical value '((signed)x >= 0)',
  is canonicalized to '((unsigned)(x ^ -1) >> 31)', but the equivalent
  '(((signed)x >> 31) + 1)' is one instruction less.

gcc/ChangeLog:

* config/xtensa/xtensa.md (*round_up_to_even):
New insn-and-split pattern.
(*signed_ge_zero): Ditto.

2 years agoxtensa: Add support for sibling call optimization
Takayuki 'January June' Suwa [Wed, 15 Jun 2022 12:21:21 +0000 (21:21 +0900)]
xtensa: Add support for sibling call optimization

This patch introduces support for sibling call optimization, when call0
ABI is in effect.

gcc/ChangeLog:

* config/xtensa/xtensa-protos.h (xtensa_prepare_expand_call,
xtensa_emit_sibcall): New prototypes.
(xtensa_expand_epilogue): Add new argument that specifies whether
or not sibling call.
* config/xtensa/xtensa.cc (TARGET_FUNCTION_OK_FOR_SIBCALL):
New macro definition.
(xtensa_prepare_expand_call): New function in order to share
the common code.
(xtensa_emit_sibcall, xtensa_function_ok_for_sibcall):
New functions.
(xtensa_expand_epilogue): Add new argument sibcall_p and use it
for sibling call handling.
* config/xtensa/xtensa.md (call, call_value):
Use xtensa_prepare_expand_call.
(call_internal, call_value_internal):
Add the condition in order to be disabled if sibling call.
(sibcall, sibcall_value, sibcall_epilogue): New expansions.
(sibcall_internal, sibcall_value_internal): New insn patterns,
and split ones in order to take care of the indirect sibcalls.

gcc/testsuite/ChangeLog:

* gcc.target/xtensa/sibcalls.c: New.

2 years agoxtensa: Document new -mextra-l32r-costs= Xtensa-specific option
Takayuki 'January June' Suwa [Tue, 14 Jun 2022 03:34:48 +0000 (12:34 +0900)]
xtensa: Document new -mextra-l32r-costs= Xtensa-specific option

gcc/ChangeLog:
* doc/invoke.texi: Document -mextra-l32r-costs= option.

2 years agoanalyzer: fix up paths for inlining (PR analyzer/105962)
David Malcolm [Wed, 15 Jun 2022 21:44:14 +0000 (17:44 -0400)]
analyzer: fix up paths for inlining (PR analyzer/105962)

-fanalyzer runs late compared to other code analysis tools, in that in
runs on the partially-optimized gimple-ssa representation.  I chose this
point to run in the hope of easy integration with LTO.

As PR analyzer/105962 notes, this means that function inlining can occur
before the -fanalyzer "sees" the user's code.  For example given:

void foo (void *p)
{
  __builtin_free (p);
}

void bar (void *q)
{
  foo (q);
  foo (q);
}

Below -O2, -fanalyzer shows the calls and returns:

inline-1.c: In function ‘foo’:
inline-1.c:3:3: warning: double-‘free’ of ‘p’ [CWE-415] [-Wanalyzer-double-free]
    3 |   __builtin_free (p);
      |   ^~~~~~~~~~~~~~~~~~
  ‘bar’: events 1-2
    |
    |    6 | void bar (void *q)
    |      |      ^~~
    |      |      |
    |      |      (1) entry to ‘bar’
    |    7 | {
    |    8 |   foo (q);
    |      |   ~~~~~~~
    |      |   |
    |      |   (2) calling ‘foo’ from ‘bar’
    |
    +--> ‘foo’: events 3-4
           |
           |    1 | void foo (void *p)
           |      |      ^~~
           |      |      |
           |      |      (3) entry to ‘foo’
           |    2 | {
           |    3 |   __builtin_free (p);
           |      |   ~~~~~~~~~~~~~~~~~~
           |      |   |
           |      |   (4) first ‘free’ here
           |
    <------+
    |
  ‘bar’: events 5-6
    |
    |    8 |   foo (q);
    |      |   ^~~~~~~
    |      |   |
    |      |   (5) returning to ‘bar’ from ‘foo’
    |    9 |   foo (q);
    |      |   ~~~~~~~
    |      |   |
    |      |   (6) passing freed pointer ‘q’ in call to ‘foo’ from ‘bar’
    |
    +--> ‘foo’: events 7-8
           |
           |    1 | void foo (void *p)
           |      |      ^~~
           |      |      |
           |      |      (7) entry to ‘foo’
           |    2 | {
           |    3 |   __builtin_free (p);
           |      |   ~~~~~~~~~~~~~~~~~~
           |      |   |
           |      |   (8) second ‘free’ here; first ‘free’ was at (4)
           |

but at -O2, -fanalyzer "sees" this gimple:

void bar (void * q)
{
  <bb 2> [local count: 1073741824]:
  __builtin_free (q_2(D));
  __builtin_free (q_2(D));
  return;
}

where "foo" has been inlined away, leading to this unhelpful output:

In function ‘foo’,
    inlined from ‘bar’ at inline-1.c:9:3:
inline-1.c:3:3: warning: double-‘free’ of ‘q’ [CWE-415] [-Wanalyzer-double-free]
    3 |   __builtin_free (p);
      |   ^~~~~~~~~~~~~~~~~~
  ‘bar’: events 1-2
    |
    |    3 |   __builtin_free (p);
    |      |   ^~~~~~~~~~~~~~~~~~
    |      |   |
    |      |   (1) first ‘free’ here
    |      |   (2) second ‘free’ here; first ‘free’ was at (1)

where the stack frame information in the execution path suggests that these
events are happening in "bar", in the top stack frame.

This is what the analyzer sees, but I find it hard to decipher such
output.  Hence, as a workaround for the fact that -fanalyzer runs so
late, this patch attempts to reconstruct the "true" stack frame
information, and to inject events showing inline calls, based on the
inlining chain information recorded in the location_t values for the events.

Doing so leads to this output at -O2 on the above example (with
-fdiagnostics-show-path-depths):

In function ‘foo’,
    inlined from ‘bar’ at inline-1.c:9:3:
inline-1.c:3:3: warning: double-‘free’ of ‘q’ [CWE-415] [-Wanalyzer-double-free]
    3 |   __builtin_free (p);
      |   ^~~~~~~~~~~~~~~~~~
  ‘bar’: events 1-2 (depth 1)
    |
    |    6 | void bar (void *q)
    |      |      ^~~
    |      |      |
    |      |      (1) entry to ‘bar’
    |    7 | {
    |    8 |   foo (q);
    |      |   ~
    |      |   |
    |      |   (2) inlined call to ‘foo’ from ‘bar’
    |
    +--> ‘foo’: event 3 (depth 2)
           |
           |    3 |   __builtin_free (p);
           |      |   ^~~~~~~~~~~~~~~~~~
           |      |   |
           |      |   (3) first ‘free’ here
           |
    <------+
    |
  ‘bar’: event 4 (depth 1)
    |
    |    9 |   foo (q);
    |      |   ^
    |      |   |
    |      |   (4) inlined call to ‘foo’ from ‘bar’
    |
    +--> ‘foo’: event 5 (depth 2)
           |
           |    3 |   __builtin_free (p);
           |      |   ^~~~~~~~~~~~~~~~~~
           |      |   |
           |      |   (5) second ‘free’ here; first ‘free’ was at (3)
           |

reconstructing the calls and returns.

The patch also adds a new option, -fno-analyzer-undo-inlining, which can
be used to disable this reconstruction, restoring the output listed
above (this time with -fdiagnostics-show-path-depths):

In function ‘foo’,
    inlined from ‘bar’ at inline-1.c:9:3:
inline-1.c:3:3: warning: double-‘free’ of ‘q’ [CWE-415] [-Wanalyzer-double-free]
    3 |   __builtin_free (p);
      |   ^~~~~~~~~~~~~~~~~~
  ‘bar’: events 1-2 (depth 1)
    |
    |    3 |   __builtin_free (p);
    |      |   ^~~~~~~~~~~~~~~~~~
    |      |   |
    |      |   (1) first ‘free’ here
    |      |   (2) second ‘free’ here; first ‘free’ was at (1)
    |

gcc/analyzer/ChangeLog:
PR analyzer/105962
* analyzer.opt (fanalyzer-undo-inlining): New option.
* checker-path.cc: Include "diagnostic-core.h" and
"inlining-iterator.h".
(event_kind_to_string): Handle EK_INLINED_CALL.
(class inlining_info): New class.
(checker_event::checker_event): Move here from checker-path.h.
Store original fndecl and depth, and calculate effective fndecl
and depth based on inlining information.
(checker_event::dump): Emit original depth as well as effective
depth when they differ; likewise for fndecl.
(region_creation_event::get_desc): Use m_effective_fndecl.
(inlined_call_event::get_desc): New.
(inlined_call_event::get_meaning): New.
(checker_path::inject_any_inlined_call_events): New.
* checker-path.h (enum event_kind): Add EK_INLINED_CALL.
(checker_event::checker_event): Make protected, and move
definition to checker-path.cc.
(checker_event::get_fndecl): Use effective fndecl.
(checker_event::get_stack_depth): Use effective stack depth.
(checker_event::get_logical_location): Use effective stack depth.
(checker_event::get_original_stack_depth): New.
(checker_event::m_fndecl): Rename to...
(checker_event::m_original_fndecl): ...this.
(checker_event::m_depth): Rename to...
(checker_event::m_original_depth): ...this.
(checker_event::m_effective_fndecl): New field.
(checker_event::m_effective_depth): New field.
(class inlined_call_event): New checker_event subclass.
(checker_path::inject_any_inlined_call_events): New decl.
* diagnostic-manager.cc: Include "inlining-iterator.h".
(diagnostic_manager::emit_saved_diagnostic): Call
checker_path::inject_any_inlined_call_events.
(diagnostic_manager::prune_for_sm_diagnostic): Handle
EK_INLINED_CALL.
* engine.cc (tainted_args_function_custom_event::get_desc): Use
effective fndecl.
* inlining-iterator.h: New file.

gcc/testsuite/ChangeLog:
PR analyzer/105962
* gcc.dg/analyzer/inlining-1-multiline.c: New test.
* gcc.dg/analyzer/inlining-1-no-undo.c: New test.
* gcc.dg/analyzer/inlining-1.c: New test.
* gcc.dg/analyzer/inlining-2-multiline.c: New test.
* gcc.dg/analyzer/inlining-2.c: New test.
* gcc.dg/analyzer/inlining-3-multiline.c: New test.
* gcc.dg/analyzer/inlining-3.c: New test.
* gcc.dg/analyzer/inlining-4-multiline.c: New test.
* gcc.dg/analyzer/inlining-4.c: New test.
* gcc.dg/analyzer/inlining-5-multiline.c: New test.
* gcc.dg/analyzer/inlining-5.c: New test.
* gcc.dg/analyzer/inlining-6-multiline.c: New test.
* gcc.dg/analyzer/inlining-6.c: New test.
* gcc.dg/analyzer/inlining-7-multiline.c: New test.
* gcc.dg/analyzer/inlining-7.c: New test.

gcc/ChangeLog:
PR analyzer/105962
* doc/invoke.texi: Add -fno-analyzer-undo-inlining.
* tree-diagnostic-path.cc (default_tree_diagnostic_path_printer):
Extend -fdiagnostics-path-format=separate-events so that with
-fdiagnostics-show-path-depths it prints fndecls as well as stack
depths.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2 years agovalue-relation.h: add 'final' and 'override' to relation_oracle vfunc impls
David Malcolm [Wed, 15 Jun 2022 21:42:17 +0000 (17:42 -0400)]
value-relation.h: add 'final' and 'override' to relation_oracle vfunc impls

gcc/ChangeLog:
* value-relation.h: Add "final" and "override" to relation_oracle
vfunc implementations as appropriate.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2 years agoanalyzer: show saved diagnostics as nodes in .eg.dot dumps
David Malcolm [Wed, 15 Jun 2022 21:40:33 +0000 (17:40 -0400)]
analyzer: show saved diagnostics as nodes in .eg.dot dumps

I've been using this tweak to the output of
-fdump-analyzer-exploded-graph in my working copies for a while;
the extra red nodes make it *much* easier to find the places where
diagnostics are being emitted (or rejected by the diagnostic_manager).

gcc/analyzer/ChangeLog:
* diagnostic-manager.cc (saved_diagnostic::dump_dot_id): New.
(saved_diagnostic::dump_as_dot_node): New.
* diagnostic-manager.h (saved_diagnostic::dump_dot_id): New decl.
(saved_diagnostic::dump_as_dot_node): New decl.
* engine.cc (exploded_node::dump_dot): Add nodes for saved
diagnostics.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2 years agoanalyzer: add more uninit test coverage
David Malcolm [Wed, 15 Jun 2022 21:39:42 +0000 (17:39 -0400)]
analyzer: add more uninit test coverage

gcc/testsuite/ChangeLog:
* gcc.dg/analyzer/uninit-1.c: Add test coverage of attempts
to jump through an uninitialized function pointer, and of attempts
to pass an uninitialized value to a function call.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2 years agod: Add `@no_sanitize' attribute to compiler and library.
Iain Buclaw [Wed, 15 Jun 2022 20:51:52 +0000 (22:51 +0200)]
d: Add `@no_sanitize' attribute to compiler and library.

The `@no_sanitize' attribute disables a particular sanitizer for this
function, analogous to `__attribute__((no_sanitize))'.  The library also
defines `@noSanitize' to be compatible with the LLVM D compiler's
`ldc.attributes'.

gcc/d/ChangeLog:

* d-attribs.cc (d_langhook_attribute_table): Add no_sanitize.
(d_handle_no_sanitize_attribute): New function.

libphobos/ChangeLog:

* libdruntime/gcc/attributes.d (no_sanitize): Define.
(noSanitize): Define.

gcc/testsuite/ChangeLog:

* gdc.dg/asan/attr_no_sanitize1.d: New test.
* gdc.dg/ubsan/attr_no_sanitize2.d: New test.

2 years agolibstdc++: [_Hashtable] Insert range of types convertible to value_type PR 105717
François Dumont [Tue, 15 Feb 2022 08:47:52 +0000 (09:47 +0100)]
libstdc++: [_Hashtable] Insert range of types convertible to value_type PR 105717

Fix insertion of range of instances convertible to value_type.

libstdc++-v3/ChangeLog:

PR libstdc++/105717
* include/bits/hashtable_policy.h (_ConvertToValueType): New.
* include/bits/hashtable.h (_Hashtable<>::_M_insert_unique_aux): New.
(_Hashtable<>::_M_insert(_Arg&&, const _NodeGenerator&, true_type)): Use latters.
(_Hashtable<>::_M_insert(_Arg&&, const _NodeGenerator&, false_type)): Likewise.
(_Hashtable(_InputIterator, _InputIterator, size_type, const _Hash&, const _Equal&,
const allocator_type&, true_type)): Use this.insert range.
(_Hashtable(_InputIterator, _InputIterator, size_type, const _Hash&, const _Equal&,
const allocator_type&, false_type)): Use _M_insert.
* testsuite/23_containers/unordered_map/cons/56112.cc: Check how many times conversion
is done.
* testsuite/23_containers/unordered_map/insert/105717.cc: New test.
* testsuite/23_containers/unordered_set/insert/105717.cc: New test.

2 years agod: Add `@visibility' and `@hidden' attributes.
Iain Buclaw [Wed, 15 Jun 2022 17:44:36 +0000 (19:44 +0200)]
d: Add `@visibility' and `@hidden' attributes.

The `@visibility' attribute is functionality the same as
`__attribute__((visibility))', and `@hidden' is a convenience alias to
`@visibility("hidden")' defined in the `gcc.attributes' module.

As the visibility of a symbol is also indirectly controlled by the
`export' keyword, the handling of this in the code generation pass has
been improved so that conflicts will be appropriately diagnosed.

gcc/d/ChangeLog:

* d-attribs.cc (d_langhook_attribute_table): Add visibility.
(insert_type_attribute): Use decl_attributes instead of
merge_attributes.
(insert_decl_attribute): Likewise.
(apply_user_attributes): Do nothing when no UDAs applied.
(d_handle_visibility_attribute): New function.
* d-gimplify.cc (d_gimplify_binary_expr): Adjust.
* d-tree.h (set_visibility_for_decl): Declare.
* decl.cc (get_symbol_decl): Move setting of visibility flags to...
(set_visibility_for_decl): ... here.  New function.
* types.cc (TypeVisitor::visit (TypeStruct *)): Call
set_visibility_for_decl().
(TypeVisitor::visit (TypeClass *)): Likewise.

gcc/testsuite/ChangeLog:

* gdc.dg/attr_visibility1.d: New test.
* gdc.dg/attr_visibility2.d: New test.
* gdc.dg/attr_visibility3.d: New test.

libphobos/ChangeLog:

* libdruntime/gcc/attributes.d (visibility): Define.
(hidden): Define.

2 years agotestsuite: AIX operator new
David Edelsohn [Tue, 14 Jun 2022 17:07:24 +0000 (13:07 -0400)]
testsuite: AIX operator new

The testcase relies on C++ "operator new", which requires AIX
runtime linking to override the symbol at runtime.

* g++.dg/cpp1z/aligned-new9.C: Skip on AIX.

2 years agoRevert recent internal-fn changes [PR105975]
Richard Sandiford [Wed, 15 Jun 2022 16:40:09 +0000 (17:40 +0100)]
Revert recent internal-fn changes [PR105975]

The recent internal-fn “clean-ups” triggered problems on nvptx
because some of the omp_simt_* patterns had modeless operands.
I wondered about adapting expand_fn_using_insn to cope with that,
but then the problem becomes: what should the mode of operand 0
be when there is no lhs?  The answer depends on the target insn.
For GOMP_SIMT_ENTER_ALLOC the answer was: use Pmode.
For GOMP_SIMT_ORDERED_PRED and others the answer was: elide the call.
(However, GOMP_SIMT_ORDERED_PRED doesn't seem to have ECF_* flags
that would normally allow it to be dropped at the gimple level.)

So these instructions seem to be special enough that they need
their own code after all.  This patch reverts the second patch
and most of the first.  The only part retained from the first
is splitting expand_fn_using_insn out of expand_direct_optab_fn,
since I think expand_fn_using_insn could still be useful in future.

gcc/
PR middle-end/105975
Revert everything apart from the expand_fn_using_insn and
expand_direct_optab_fn changes from:

* internal-fn.def (DEF_INTERNAL_INSN_FN): New macro.
(GOMP_SIMT_ENTER_ALLOC, GOMP_SIMT_EXIT, GOMP_SIMT_LANE)
(GOMP_SIMT_LAST_LANE, GOMP_SIMT_ORDERED_PRED, GOMP_SIMT_VOTE_ANY)
(GOMP_SIMT_XCHG_BFLY, GOMP_SIMT_XCHG_IDX): Use it.
* internal-fn.h (direct_internal_fn_info::directly_mapped): New
member variable.
(direct_internal_fn_info::vectorizable): Reduce to 1 bit.
(direct_internal_fn_p): Also return true for internal functions
that map directly to instructions defined target-insns.def.
(direct_internal_fn): Adjust comment accordingly.
* internal-fn.cc (direct_insn, optab1, optab2, vectorizable_optab1)
(vectorizable_optab2): New local macros.
(not_direct): Initialize directly_mapped.
(mask_load_direct, load_lanes_direct, mask_load_lanes_direct)
(gather_load_direct, len_load_direct, mask_store_direct)
(store_lanes_direct, mask_store_lanes_direct, vec_cond_mask_direct)
(vec_cond_direct, scatter_store_direct, len_store_direct)
(vec_set_direct, unary_direct, binary_direct, ternary_direct)
(cond_unary_direct, cond_binary_direct, cond_ternary_direct)
(while_direct, fold_extract_direct, fold_left_direct)
(mask_fold_left_direct, check_ptrs_direct): Use the macros above.
(expand_GOMP_SIMT_ENTER_ALLOC, expand_GOMP_SIMT_EXIT): Delete
(expand_GOMP_SIMT_LANE, expand_GOMP_SIMT_LAST_LANE): Likewise;
(expand_GOMP_SIMT_ORDERED_PRED, expand_GOMP_SIMT_VOTE_ANY): Likewise.
(expand_GOMP_SIMT_XCHG_BFLY, expand_GOMP_SIMT_XCHG_IDX): Likewise.
(direct_internal_fn_types): Handle functions that map to instructions
defined in target-insns.def.
(direct_internal_fn_types): Likewise.
(direct_internal_fn_supported_p): Likewise.
(internal_fn_expanders): Likewise.

(expand_fn_using_insn): New function,
split out and adapted from...
(expand_direct_optab_fn): ...here.
(expand_GOMP_SIMT_ENTER_ALLOC): Use it.
(expand_GOMP_SIMT_EXIT): Likewise.
(expand_GOMP_SIMT_LANE): Likewise.
(expand_GOMP_SIMT_LAST_LANE): Likewise.
(expand_GOMP_SIMT_ORDERED_PRED): Likewise.
(expand_GOMP_SIMT_VOTE_ANY): Likewise.
(expand_GOMP_SIMT_XCHG_BFLY): Likewise.
(expand_GOMP_SIMT_XCHG_IDX): Likewise.

2 years agoarm: big-endian issue in gen_cpymem_ldrd_strd [PR105981]
Richard Earnshaw [Wed, 15 Jun 2022 15:07:20 +0000 (16:07 +0100)]
arm: big-endian issue in gen_cpymem_ldrd_strd [PR105981]

The code in gen_cpymem_ldrd_strd has been incorrect for big-endian
since r230663.  The problem is that we use gen_lowpart, etc. to split
the 64-bit quantity, but fail to account for the fact that these
routines are really dealing with 64-bit /values/ and in big-endian the
ordering of the sub-registers changes.

To fix this, I've renamed the conceptually misnamed low_reg and hi_reg
as first_reg and second_reg, and then used different logic for
big-endian targets to initialize these values.  This makes the logic
clearer than trying to think about high bits and low bits.

gcc/ChangeLog:

PR target/105981
* config/arm/arm.cc (gen_cpymem_ldrd_strd): Rename low_reg and hi_reg
to first_reg and second_reg respectively.  Initialize them correctly
when generating big-endian code.

2 years agoc++: Use better module partition naming
Nathan Sidwell [Fri, 10 Jun 2022 18:57:38 +0000 (11:57 -0700)]
c++: Use better module partition naming

It turns out that 'implementation partition' is not a term used in the
std, and is confusing to users.  Let's use the better term 'internal
partition'.  While there, adjust header unit naming.

gcc/cp/
* module.cc (module_state::write_readme): Use less confusing
importable unit names.

2 years agoarm: fix thinko in arm_bfi_1_p() [PR105974]
Richard Earnshaw [Wed, 15 Jun 2022 12:42:23 +0000 (13:42 +0100)]
arm: fix thinko in arm_bfi_1_p() [PR105974]

I clearly wasn't thinking straight when I wrote the arm_bfi_1_p
function and used XUINT rather than UINTVAL when extracting CONST_INT
values.  It seemed to work in testing, but was incorrect and failed
RTL checking.

Fixed thusly:

gcc/ChangeLog:

PR target/105974
* config/arm/arm.cc (arm_bfi_1_p): Use UINTVAL instead of XUINT.

2 years agod: Set TYPE_ARTIFICIAL on internal TypeInfo types
Iain Buclaw [Wed, 15 Jun 2022 11:20:15 +0000 (13:20 +0200)]
d: Set TYPE_ARTIFICIAL on internal TypeInfo types

Prevents them from triggering warnings when compiling with `-Wpadded'.

gcc/d/ChangeLog:

* typeinfo.cc (make_internal_typeinfo): Set TYPE_ARTIFICIAL.

gcc/testsuite/ChangeLog:

* gdc.dg/Wpadded.d: New test.

2 years agotree-optimization/105971 - less surprising refs_may_alias_p_2
Richard Biener [Wed, 15 Jun 2022 09:27:31 +0000 (11:27 +0200)]
tree-optimization/105971 - less surprising refs_may_alias_p_2

When DSE asks whether __real a is using __imag a it gets a surprising
result when a is a FUNCTION_DECL.  The following makes sure this case
is less surprising to callers but keeping the bail-out for the
non-decl case where it is true that PTA doesn't track aliases to code
correctly.

2022-06-15  Richard Biener  <rguenther@suse.de>

PR tree-optimization/105971
* tree-ssa-alias.cc (refs_may_alias_p_2): Put bail-out for
FUNCTION_DECL and LABEL_DECL refs after decl-decl disambiguation
to leak less surprising alias results.

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