Jan Hubicka [Sat, 29 Jul 2023 06:18:18 +0000 (08:18 +0200)]
Fix profile update after vectorize loop versioning
Vectorizer while loop versioning produces a versioned loop
guarded with two conditionals of the form
if (cond1)
goto scalar_loop
else
goto next_bb
next_bb:
if (cond2)
godo scalar_loop
else
goto vector_loop
It wants the combined test to be prob (whch is set to likely)
and uses profile_probability::split to determine probability
of cond1 and cond2.
However spliting is turning:
if (cond)
goto lab; // ORIG probability
into
if (cond1)
goto lab; // FIRST = ORIG * CPROB probability
if (cond2)
goto lab; // SECOND probability
Which is or instead of and. As a result we get pretty low probabiility
of entering vectorized loop.
The fixes this by introducing sqrt to profile probability (which is correct
way to split this) and also adding pow that is needed elsewhere.
While loop versioning I now produce code as if there was only one combined
conditional and then update probability of conditional produced (containig
cond1). Later edge is split and new conditional is added. At that time
it is necessary to update probability of the BB containing second conditional
so everything matches.
gcc/ChangeLog:
* profile-count.cc (profile_probability::sqrt): New member function.
(profile_probability::pow): Likewise.
* profile-count.h: (profile_probability::sqrt): Declare
(profile_probability::pow): Likewise.
* tree-vect-loop-manip.cc (vect_loop_versioning): Fix profile update.
Harald Anlauf [Thu, 27 Jul 2023 19:30:26 +0000 (21:30 +0200)]
Fortran: do not pass hidden character length for TYPE(*) dummy [PR110825]
gcc/fortran/ChangeLog:
PR fortran/110825
* gfortran.texi: Clarify argument passing convention.
* trans-expr.cc (gfc_conv_procedure_call): Do not pass the character
length as hidden argument when the declared dummy argument is
assumed-type.
gcc/testsuite/ChangeLog:
PR fortran/110825
* gfortran.dg/assumed_type_18.f90: New test.
Cleanup profile updating code in unrolling and splitting
I have noticed that for all these three cases I need same update of
loop exit probability. While my earlier patch unified it for unrollers,
this patch makes it more general and also simplifies
tree-ssa-loop-split.cc.
I also refactored the code, since with all the special cases for
corrupted profile it gets relatively long.
I now also handle multiple loop exits in RTL unroller.
* cfgloopmanip.cc (loop_count_in): Break out from ...
(loop_exit_for_scaling): Break out from ...
(update_loop_exit_probability_scale_dom_bbs): Break out from ...;
add more sanity check and debug info.
(scale_loop_profile): ... here.
(create_empty_loop_on_edge): Fix whitespac.
* cfgloopmanip.h (update_loop_exit_probability_scale_dom_bbs): Declare.
* loop-unroll.cc (unroll_loop_constant_iterations): Use
update_loop_exit_probability_scale_dom_bbs.
* tree-ssa-loop-manip.cc (update_exit_probability_after_unrolling): Remove.
(tree_transform_and_unroll_loop): Use
update_loop_exit_probability_scale_dom_bbs.
* tree-ssa-loop-split.cc (split_loop): Use
update_loop_exit_probability_scale_dom_bbs.
Jan Hubicka [Fri, 28 Jul 2023 14:18:32 +0000 (16:18 +0200)]
loop-split improvements, part 3
extend tree-ssa-loop-split to understand test of the form
if (i==0)
and
if (i!=0)
which triggers only during the first iteration. Naturally we should
also be able to trigger last iteration or split into 3 cases if
the test indeed can fire in the middle of the loop.
Last iteration is bit trickier pattern matching so I want to do it
incrementally, but I implemented easy case using value range that handled
loops with constant iterations.
The testcase gets misupdated profile, I will also fix that incrementally.
gcc/ChangeLog:
PR middle-end/77689
* tree-ssa-loop-split.cc: Include value-query.h.
(split_at_bb_p): Analyze cases where EQ/NE can be turned
into LT/LE/GT/GE; return updated guard code.
(split_loop): Use guard code.
gcc/testsuite/ChangeLog:
PR middle-end/77689
* g++.dg/tree-ssa/loop-split-1.C: New test.
Roger Sayle [Fri, 28 Jul 2023 08:39:46 +0000 (09:39 +0100)]
PR rtl-optimization/110587: Reduce useless moves in compile-time hog.
This patch is one of a series of fixes for PR rtl-optimization/110587,
a compile-time regression with -O0, that attempts to address the underlying
cause. As noted previously, the pathological test case pr28071.c contains
a large number of useless register-to-register moves that can produce
quadratic behaviour (in LRA). These moves are generated during RTL
expansion in emit_group_load_1, where the middle-end attempts to simplify
the source before calling extract_bit_field. This is reasonable if the
source is a complex expression (from before the tree-ssa optimizers), or
a SUBREG, or a hard register, but it's not particularly useful to copy
a pseudo register into a new pseudo register. This patch eliminates that
redundancy.
The -fdump-tree-expand for pr28071.c compiled with -O0 currently contains
777K lines, with this patch it contains 717K lines, i.e. saving about 60K
lines (admittedly of debugging text output, but it makes the point).
2023-07-28 Roger Sayle <roger@nextmovesoftware.com>
Richard Biener <rguenther@suse.de>
gcc/ChangeLog
PR middle-end/28071
PR rtl-optimization/110587
* expr.cc (emit_group_load_1): Simplify logic for calling
force_reg on ORIG_SRC, to avoid making a copy if the source
is already in a pseudo register.
Jan Hubicka [Fri, 28 Jul 2023 07:48:34 +0000 (09:48 +0200)]
loop-split improvements, part 2
this patch fixes profile update in the first case of loop splitting.
The pass still gives up on very basic testcases:
__attribute__ ((noinline,noipa))
void test1 (int n)
{
if (n <= 0 || n > 100000)
return;
for (int i = 0; i <= n; i++)
{
if (i < n)
do_something ();
if (a[i])
do_something2();
}
}
Here I needed to do the conditoinal that enforces sane value range of n.
The reason is that it gives up on:
!number_of_iterations_exit (loop1, exit1, &niter, false, true)
and without the conditonal we get assumption that n>=0 and not INT_MAX.
I think from overflow we shold derive that INT_MAX test is not needed and since
the loop does nothing for n<0 it is also just an paranoia.
I am not sure how to fix this though :(. In general the pass does not really
need to compute iteration count. It only needs to know what direction the IVs
go so it can detect tests that fires in first part of iteration space.
Rich, any idea what the correct test should be?
In testcase:
for (int i = 0; i < 200; i++)
if (i < 150)
do_something ();
else
do_something2 ();
the old code did wrong update of the exit condition probabilities.
We know that first loop iterates 150 times and the second loop 50 times
and we get it by simply scaling loop body by the probability of inner test.
<bb 9> [count: 49975]: <- loop 2 should iterate 50 times but
we are slightly wrong
# i_3 = PHI <i_15(16), i_14(13)>
do_something2 ();
i_14 = i_3 + 1;
if (i_14 != 200)
goto <bb 13>; [98.00%]
else
goto <bb 7>; [2.00%]
<bb 13> [count: 48975]:
goto <bb 9>; [100.00%]
<bb 17> [count: 1000]: <- this test is always true becuase it is
reached form bb 3
# i_18 = PHI <i_7(3)>
if (i_18 != 200)
goto <bb 16>; [99.95%]
else
goto <bb 7>; [0.05%]
<bb 7> [count: 1000]:
return;
The reason why we are slightly wrong is the condtion in bb17 that
is always true but the pass does not konw it.
Rich any idea how to do that? I think connect_loops should work out
the cas where the loop exit conditon is never satisfied at the time
the splitted condition fails for first time.
So no mismatches for lsplit and ldist and also lsplit thinks it improves speed by
2.3% rather than regressig it by 57%.
Update is still not perfect since we do not work out that the second loop
never iterates.
Ifcft wrecks profile by desing since it insert conditonals with both arms 100%
that will be eliminated later after vect. It is not clear to me what happens
in vect though.
Bootstrapped/regtested x86_64-linux, comitted.
gcc/ChangeLog:
PR middle-end/106923
* tree-ssa-loop-split.cc (connect_loops): Change probability
of the test preconditioning second loop to very_likely.
(fix_loop_bb_probability): Handle correctly case where
on of the arms of the conditional is empty.
(split_loop): Fold the test guarding first condition to
see if it is constant true; Set correct entry block
probabilities of the split loops; determine correct loop
eixt probabilities.
gcc/testsuite/ChangeLog:
PR middle-end/106293
* gcc.dg/tree-prof/loop-split-1.c: New test.
* gcc.dg/tree-prof/loop-split-2.c: New test.
* gcc.dg/tree-prof/loop-split-3.c: New test.
Clément Chigot [Tue, 13 Jun 2023 08:51:17 +0000 (10:51 +0200)]
ada: Add an assert in Posix Interrupt_Wait
All functions but Interrupt_Wait in s-inmaop__posix are checking the
result of their syscalls with an assert. However, any return code of
sigwait different than 0 means that something went wrong for it.
From sigwait man:
> RETURN VALUE
> On success, sigwait() returns 0. On error, it returns a
> positive error number (listed in ERRORS).
gcc/ada/
* libgnarl/s-inmaop__posix.adb: Add assert after sigwait in
Interrupt_Wait
Javier Miranda [Sun, 9 Jul 2023 17:34:18 +0000 (17:34 +0000)]
ada: Fix unsupported dispatching constructor call
Add dummy build-in-place parameters when a BIP function does not
require the BIP parameters but it is a dispatching operation that
inherited them.
gcc/ada/
* einfo-utils.adb (Underlying_Type): Protect recursion call
against non-available attribute Etype.
* einfo.ads (Protected_Subprogram): Fix typo in documentation.
* exp_ch3.adb (BIP_Function_Call_Id): New subprogram.
(Expand_N_Object_Declaration): Improve code that evaluates if the
object is initialized with a BIP function call.
* exp_ch6.adb (Is_True_Build_In_Place_Function_Call): New
subprogram.
(Add_Task_Actuals_To_Build_In_Place_Call): Add dummy actuals if
the function does not require the BIP task actuals but it is a
dispatching operation that inherited them.
(Build_In_Place_Formal): Improve code to avoid never-ending loop
if the BIP formal is not found.
(Add_Dummy_Build_In_Place_Actuals): New subprogram.
(Expand_Call_Helper): Add calls to
Add_Dummy_Build_In_Place_Actuals.
(Expand_N_Extended_Return_Statement): Adjust assertion.
(Expand_Simple_Function_Return): Adjust assertion.
(Make_Build_In_Place_Call_In_Allocator): No action needed if the
called function inherited the BIP extra formals but it is not a
true BIP function.
(Make_Build_In_Place_Call_In_Assignment): Ditto.
* exp_intr.adb (Expand_Dispatching_Constructor_Call): Remove code
reporting unsupported case (since this patch adds support for it).
* sem_ch6.adb (Analyze_Subprogram_Body_Helper): Adding assertion
to ensure matching of BIP formals when setting the
Protected_Formal field of a protected subprogram to reference the
corresponding extra formal of the subprogram that implements it.
(Might_Need_BIP_Task_Actuals): New subprogram.
(Create_Extra_Formals): Improve code adding inherited extra
formals.
Pascal Obry [Mon, 26 Jun 2023 17:58:16 +0000 (19:58 +0200)]
ada: Add support for binding to a specific network interface controller.
gcc/ada/
* s-oscons-tmplt.c: Add support for SO_BINDTODEVICE constant.
* libgnat/g-socket.ads (Set_Socket_Option): Handle SO_BINDTODEVICE option.
(Get_Socket_Option): Handle SO_BINDTODEVICE option.
* libgnat/g-socket.adb: Likewise.
(Get_Socket_Option): Handle the case where IF_NAMESIZE is not defined
and so equal to -1.
This patch only affects the single-entry implementation of protected
objects.
Before this patch, there was a race condition where a task that
called an entry could put itself to sleep right after another task
had executed the entry as a proxy and signalled the not-yet-waiting
first task, which caused the first task to enter a deadlock.
Note that this race condition has been identified and fixed before
for the implementations of the run-time that live under hie/.
This patch reworks the locking sequence so that it is closer to the
one that's used in the multiple-entry implementation of protected
objects. The code for the multiple-entry implementation is spread
across multiple subprograms. To draw a parallel with the section
this patch modifies, one can read the following subprograms:
Piotr Trojanek [Tue, 11 Jul 2023 14:37:23 +0000 (16:37 +0200)]
ada: Add guard for detection of class-wide precondition subprograms
When skipping check on subprograms built for class-wide preconditions
we must deal with the current scope not being a subprogram, e.g. it
could be a declare-block.
gcc/ada/
* sem_res.adb (Resolve_Actuals): Add guard for the call to
Class_Preconditions_Subprogram.
Eric Botcazou [Tue, 11 Jul 2023 11:29:55 +0000 (13:29 +0200)]
ada: Fix memory explosion on aggregate of nested packed array type
It occurs at compile time on an aggregate of a 2-dimensional packed array
type whose component type is itself a packed array, because the compiler
is trying to pack the intermediate aggregate and ends up rewriting a bunch
of subcomponents. This optimization was originally devised for the case of
a scalar component type so the change adds this restriction.
gcc/ada/
* exp_aggr.adb (Is_Two_Dim_Packed_Array): Return true only if the
component type of the array is scalar.
Piotr Trojanek [Mon, 10 Jul 2023 13:02:43 +0000 (15:02 +0200)]
ada: Leave detection of missing return in functions to GNATprove
GNAT has a heuristic to warn about missing return statements in
functions. This warning was escalated to errors when operating in
GNATprove mode and SPARK_Mode was On. However, this heuristic was
imprecise and caused spurious errors. Also, it was applied after the
Push_Scope/End_Scope, so for functions acting as compilation units it
was using the wrong SPARK_Mode.
It is better to simply leave this detection to GNATprove.
gcc/ada/
* sem_ch6.adb (Check_Statement_Sequence): Only warn about missing return
statements and let GNATprove emit a check when needed.
Tom Tromey [Fri, 30 Jun 2023 15:31:40 +0000 (09:31 -0600)]
ada: Emit enums rather than defines for various constants
This patch changes xsnamest and gen_il-gen to emit various constants
as enums rather than a sequence of preprocessor defines. This enables
better debugging and somewhat better type safety.
Piotr Trojanek [Fri, 16 Jun 2023 07:16:19 +0000 (09:16 +0200)]
ada: Allow calls to Number_Formals when no formals are present
It is much simpler and safer for the routine Number_Formals to accept
subprogram entities that have no formals.
gcc/ada/
* einfo-utils.adb (Number_Formals): Change types in body.
* einfo-utils.ads (Number_Formals): Change type in spec.
* einfo.ads (Number_Formals): Change type in comment.
* sem_ch13.adb (Is_Property_Function): Fix style in a caller of
Number_Formals that was likely to crash because of missing guards.
Piotr Trojanek [Fri, 16 Jun 2023 06:34:27 +0000 (08:34 +0200)]
ada: Improve defense against illegal code in check for infinite loops
Fix crash occurring when attribute System'To_Address is used without
a WITH clause for package System.
gcc/ada/
* sem_warn.adb (Check_Infinite_Loop_Warning): Don't look at the type of
actual parameter when it has no type at all, e.g. because the entire
subprogram call is illegal.
RISC-V: Remove vxrm parameter for vsadd[u] and vssub[u]
Computation of `vsadd`, `vsaddu`, `vssub`, and `vssubu` do not need the
rounding mode, therefore the intrinsics of these instructions do not have
the parameter for rounding mode control.
gcc/ChangeLog:
* config/riscv/riscv-vector-builtins-bases.cc: remove rounding mode of
vsadd[u] and vssub[u].
* config/riscv/vector.md: Ditto.
Jan Hubicka [Fri, 28 Jul 2023 07:16:09 +0000 (09:16 +0200)]
loop-split improvements, part 1
while looking on profile misupdate on hmmer I noticed that loop splitting pass is not
able to handle the loop it has as an example it should apply on:
One transformation of loops like:
for (i = 0; i < 100; i++)
{
if (i < 50)
A;
else
B;
}
into:
for (i = 0; i < 50; i++)
{
A;
}
for (; i < 100; i++)
{
B;
}
The problem is that ivcanon turns the test into i != 100 and the pass
explicitly gives up on any loops ending with != test. It needs to know
the directoin of the induction variable in order to derive right conditions,
but that can be done also from step.
It turns out that there are no testcases for basic loop splitting. I will add
some with the profile update fix.
gcc/ChangeLog:
* tree-ssa-loop-split.cc (split_loop): Also support NE driven
loops when IV test is not overflowing.
David Faust [Thu, 27 Jul 2023 20:55:44 +0000 (13:55 -0700)]
bpf: ISA V4 sign-extending move and load insns [PR110782,PR110784]
BPF ISA V4 introduces sign-extending move and load operations. This
patch makes the BPF backend generate those instructions, when enabled
and useful.
A new option, -m[no-]smov gates generation of these instructions, and is
enabled by default for -mcpu=v4 and above. Tests for the new
instructions and documentation for the new options are included.
* gcc.target/bpf/sload-1.c: New test.
* gcc.target/bpf/sload-pseudoc-1.c: New test.
* gcc.target/bpf/smov-1.c: New test.
* gcc.target/bpf/smov-pseudoc-1.c: New test.
David Faust [Thu, 27 Jul 2023 20:49:59 +0000 (13:49 -0700)]
bpf: minor doc cleanup for command-line options
This patch makes some minor cleanups to eBPF options documented in
invoke.texi:
- Delete some vestigal docs for removed -mkernel option
- Add -mbswap and -msdiv to the option summary
- Note the negative versions of several options
- Note that -mcpu=v4 also enables -msdiv.
David Faust [Thu, 27 Jul 2023 17:56:29 +0000 (10:56 -0700)]
bpf: correct pseudo-C template for add3 and sub3
The pseudo-C output templates for these instructions were incorrectly
using operand 1 rather than operand 2 on the RHS, which led to some
very incorrect assembly generation with -masm=pseudoc.
gcc/
* config/bpf/bpf.md (add<AM:mode>3): Use %w2 instead of %w1
in pseudo-C dialect output template.
(sub<AM:mode>3): Likewise.
gcc/testsuite/
* gcc.target/bpf/alu-2.c: New test.
* gcc.target/bpf/alu-pseudoc-2.c: Likewise.
Jan Hubicka [Thu, 27 Jul 2023 18:06:37 +0000 (20:06 +0200)]
Fix profile update after RTL unrolling
This patch fixes profile update after RTL unroll, that is now done same way as
in tree one. We still produce (slightly) corrupted profile for multiple exit
loops I can try to fix incrementally.
I also updated testcases to look for profile mismatches so they do not creep
back in again.
gcc/ChangeLog:
* cfgloop.h (single_dom_exit): Declare.
* cfgloopmanip.h (update_exit_probability_after_unrolling): Declare.
* cfgrtl.cc (struct cfg_hooks): Fix comment.
* loop-unroll.cc (unroll_loop_constant_iterations): Update exit edge.
* tree-ssa-loop-ivopts.h (single_dom_exit): Do not declare it here.
* tree-ssa-loop-manip.cc (update_exit_probability_after_unrolling):
Break out from ...
(tree_transform_and_unroll_loop): ... here;
gcc/testsuite/ChangeLog:
* gcc.dg/tree-prof/peel-1.c: Test for profile mismatches.
* gcc.dg/tree-prof/unroll-1.c: Test for profile mismatches.
* gcc.dg/tree-ssa/peel1.c: Test for profile mismatches.
* gcc.dg/unroll-1.c: Test for profile mismatches.
* gcc.dg/unroll-3.c: Test for profile mismatches.
* gcc.dg/unroll-4.c: Test for profile mismatches.
* gcc.dg/unroll-5.c: Test for profile mismatches.
* gcc.dg/unroll-6.c: Test for profile mismatches.
OpenMP/Fortran: Extend reject code between target + teams [PR71065, PR110725]
The previous version failed to diagnose when the 'teams' was nested
more deeply inside the target region, e.g. inside a DO or some
block or structured block.
PR fortran/110725
PR middle-end/71065
gcc/fortran/ChangeLog:
* openmp.cc (resolve_omp_target): Minor cleanup.
* parse.cc (decode_omp_directive): Find TARGET statement
also higher in the stack.
Jonathan Wakely [Thu, 27 Jul 2023 13:07:09 +0000 (14:07 +0100)]
libstdc++: Fix std::format alternate form for floating-point [PR108046]
A decimal point was being added to the end of the string for {:#.0}
because the __expc character was not being set, for the _Pres_none
presentation type, so __s.find(__expc) didn't the 'e' in "1e+01" and so
we created "1e+01." by appending the radix char to the end.
This can be fixed by ensuring that __expc='e' is set for the _Pres_none
case. I realized we can also set __expc='P' and __expc='E' when needed,
to save a call to std::toupper later.
For the {:#.0g} format, __expc='e' was being set and so the 'e' was
found in "1e+10" but then __z = __prec - __sigfigs would wraparound to
SIZE_MAX. That meant we would decide not to add a radix char because the
number of extra characters to insert would be 1+SIZE_MAX i.e. zero.
This can be fixed by using __z == 0 when __prec == 0.
libstdc++-v3/ChangeLog:
PR libstdc++/108046
* include/std/format (__formatter_fp::format): Ensure __expc is
always set for all presentation types. Set __z correctly for
zero precision.
* testsuite/std/format/functions/format.cc: Check problem cases.
Jan Hubicka [Thu, 27 Jul 2023 14:17:59 +0000 (16:17 +0200)]
Fix profile update in tree_transform_and_unroll_loop
Fixe profile update in tree_transform_and_unroll_loop which is used
by predictive comming. I stared by attempt to fix
gcc.dg/tree-ssa/update-unroll-1.c I xfailed last week, but it turned to be
harder job.
Unrolling was never fixed for changes in duplicate_loop_body_to_header_edge
which is now smarter on getting profile right when some exists are eliminated.
A lot of manual profile can thus now be done using existing infrastructure.
I also noticed that scale_dominated_blocks_in_loop does job identical
to loop I wrote in scale_loop_profile and thus I commonized the implementaiton
and removed recursion.
I also extended duplicate_loop_body_to_header_edge to handle flat profiles same
way as we do in vectorizer. Without it we end up with less then 0 iteration
count in gcc.dg/tree-ssa/update-unroll-1.c (it is unrolled 32times but predicted
to iterated fewer times) and added missing code to update loop_info.
gcc/ChangeLog:
* cfgloopmanip.cc (scale_dominated_blocks_in_loop): Move here from
tree-ssa-loop-manip.cc and avoid recursion.
(scale_loop_profile): Use scale_dominated_blocks_in_loop.
(duplicate_loop_body_to_header_edge): Add DLTHE_FLAG_FLAT_PROFILE
flag.
* cfgloopmanip.h (DLTHE_FLAG_FLAT_PROFILE): Define.
(scale_dominated_blocks_in_loop): Declare.
* predict.cc (dump_prediction): Do not ICE on uninitialized probability.
(change_edge_frequency): Remove.
* predict.h (change_edge_frequency): Remove.
* tree-ssa-loop-manip.cc (scale_dominated_blocks_in_loop): Move to
cfgloopmanip.cc.
(niter_for_unrolled_loop): Remove.
(tree_transform_and_unroll_loop): Fix profile update.
gcc/testsuite/ChangeLog:
* gcc.dg/pr102385.c: Check for no profile mismatches.
* gcc.dg/pr96931.c: Check for no profile mismatches.
* gcc.dg/tree-ssa/predcom-1.c: Check for no profile mismatches.
* gcc.dg/tree-ssa/predcom-2.c: Check for no profile mismatches.
* gcc.dg/tree-ssa/predcom-3.c: Check for no profile mismatches.
* gcc.dg/tree-ssa/predcom-4.c: Check for no profile mismatches.
* gcc.dg/tree-ssa/predcom-5.c: Check for no profile mismatches.
* gcc.dg/tree-ssa/predcom-7.c: Check for one profile mismatch.
* gcc.dg/tree-ssa/predcom-8.c: Check for no profile mismatches.
* gcc.dg/tree-ssa/predcom-dse-1.c: Check for no profile mismatches.
* gcc.dg/tree-ssa/predcom-dse-10.c: Check for no profile mismatches.
* gcc.dg/tree-ssa/predcom-dse-11.c: Check for no profile mismatches.
* gcc.dg/tree-ssa/predcom-dse-12.c: Check for no profile mismatches.
* gcc.dg/tree-ssa/predcom-dse-2.c: Check for no profile mismatches.
* gcc.dg/tree-ssa/predcom-dse-3.c: Check for no profile mismatches.
* gcc.dg/tree-ssa/predcom-dse-4.c: Check for no profile mismatches.
* gcc.dg/tree-ssa/predcom-dse-5.c: Check for no profile mismatches.
* gcc.dg/tree-ssa/predcom-dse-6.c: Check for no profile mismatches.
* gcc.dg/tree-ssa/predcom-dse-7.c: Check for no profile mismatches.
* gcc.dg/tree-ssa/predcom-dse-8.c: Check for no profile mismatches.
* gcc.dg/tree-ssa/predcom-dse-9.c: Check for no profile mismatches.
* gcc.dg/tree-ssa/update-unroll-1.c: Unxfail.
Jan Hubicka [Thu, 27 Jul 2023 13:58:52 +0000 (15:58 +0200)]
Fix profile update in tree-ssa-loop-im.cc
This fixes two bugs in tree-ssa-loop-im.cc. First is that cap probability is not
reliable, but it is constructed with adjusted quality. Second is that sometimes
the conditional has wrong joiner BB count. This is visible on
testsuite/gcc.dg/pr102385.c however the testcase triggers another profile
update bug in pcom, so I will update it in followup patch.
gcc/ChangeLog:
* tree-ssa-loop-im.cc (execute_sm_if_changed): Turn cap probability
to guessed; fix count of new_bb.
Jan Hubicka [Thu, 27 Jul 2023 13:57:54 +0000 (15:57 +0200)]
Fix profile_count::apply_probability
profile_count::apply_probability misses check for uninitialized probability which leads
to completely random results on applying uninitialized probability to initialized scale.
This can make difference when i.e. inlining -fno-guess-branch-probability function
to -fguess-branch-probability one.
gcc/ChangeLog:
* profile-count.h (profile_count::apply_probability): Fix
handling of uninitialized probabilities, optimize scaling
by probability 1.
Richard Biener [Thu, 27 Jul 2023 11:08:32 +0000 (13:08 +0200)]
tree-optimization/91838 - fix FAIL of g++.dg/opt/pr91838.C
The following fixes the lack of simplification of a vector shift
by an out-of-bounds shift value. For scalars this is done both
by CCP and VRP but vectors are not handled there. This results
in PR91838 differences in outcome dependent on whether a vector
shift ISA is available and thus vector lowering does or does not
expose scalar shifts here.
The following adds a match.pd pattern to catch uniform out-of-bound
shifts, simplifying them to zero when not sanitizing shift amounts.
PR tree-optimization/91838
* gimple-match-head.cc: Include attribs.h and asan.h.
* generic-match-head.cc: Likewise.
* match.pd (([rl]shift @0 out-of-bounds) -> zero): New pattern.
Patrick Palka [Thu, 27 Jul 2023 13:10:07 +0000 (09:10 -0400)]
c++: constexpr empty subobject elision [PR110197]
Now that init_subob_ctx no longer sets new_ctx.ctor for a subobject of
empty type, it seems we need to ensure its callers also consistently
omit entries in the parent ctx->ctor for such subobjects. We also need
to allow cxx_eval_array_reference to synthesize an empty subobject even
if the array CONSTRUCTOR has CONSTRUCTOR_NO_CLEARING set.
PR c++/110197
gcc/cp/ChangeLog:
* constexpr.cc (cxx_eval_array_reference): Allow synthesizing an
empty subobject even if CONSTRUCTOR_NO_CLEARING is set.
(cxx_eval_bare_aggregate): Set 'no_slot' to true more generally
whenever new_ctx.ctor is set to NULL_TREE by init_subob_ctx,
i.e. whenever initializing an subobject of empty type.
(cxx_eval_vec_init_1): Define 'no_slot' as above and use it
accordingly.
gcc/testsuite/ChangeLog:
* g++.dg/cpp0x/constexpr-empty18.C: New test.
* g++.dg/cpp0x/constexpr-empty19.C: New test.
* gcc.target/riscv/rvv/autovec/partial/slp-9.c: Add more checks.
* gcc.target/riscv/rvv/rvv.exp: Add VLS modes tests.
* gcc.target/riscv/rvv/autovec/vls/def.h: New test.
* gcc.target/riscv/rvv/autovec/vls/mov-1.c: New test.
* gcc.target/riscv/rvv/autovec/vls/mov-10.c: New test.
* gcc.target/riscv/rvv/autovec/vls/mov-11.c: New test.
* gcc.target/riscv/rvv/autovec/vls/mov-12.c: New test.
* gcc.target/riscv/rvv/autovec/vls/mov-13.c: New test.
* gcc.target/riscv/rvv/autovec/vls/mov-14.c: New test.
* gcc.target/riscv/rvv/autovec/vls/mov-15.c: New test.
* gcc.target/riscv/rvv/autovec/vls/mov-16.c: New test.
* gcc.target/riscv/rvv/autovec/vls/mov-17.c: New test.
* gcc.target/riscv/rvv/autovec/vls/mov-2.c: New test.
* gcc.target/riscv/rvv/autovec/vls/mov-3.c: New test.
* gcc.target/riscv/rvv/autovec/vls/mov-4.c: New test.
* gcc.target/riscv/rvv/autovec/vls/mov-5.c: New test.
* gcc.target/riscv/rvv/autovec/vls/mov-6.c: New test.
* gcc.target/riscv/rvv/autovec/vls/mov-7.c: New test.
* gcc.target/riscv/rvv/autovec/vls/mov-8.c: New test.
* gcc.target/riscv/rvv/autovec/vls/mov-9.c: New test.
* gcc.target/riscv/rvv/autovec/vls/spill-1.c: New test.
* gcc.target/riscv/rvv/autovec/vls/spill-2.c: New test.
* gcc.target/riscv/rvv/autovec/vls/spill-3.c: New test.
* gcc.target/riscv/rvv/autovec/vls/spill-4.c: New test.
* gcc.target/riscv/rvv/autovec/vls/spill-5.c: New test.
* gcc.target/riscv/rvv/autovec/vls/spill-6.c: New test.
* gcc.target/riscv/rvv/autovec/vls/spill-7.c: New test.
Kewen Lin [Thu, 27 Jul 2023 02:43:09 +0000 (21:43 -0500)]
vect: Treat VMAT_ELEMENTWISE as scalar load in costing [PR110776]
PR110776 exposes one issue that we could query unaligned
load for vector type but actually no unaligned vector load
is supported there. The reason is that the costed load is
with single-lane vector type and its memory access type is
VMAT_ELEMENTWISE, we actually take it as scalar load and
set its alignment_support_scheme as dr_unaligned_supported.
To avoid the ICE as exposed, following Rich's suggestion,
this patch is to make VMAT_ELEMENTWISE be costed as scalar
load.
Co-authored-by: Richard Biener <rguenther@suse.de>
PR tree-optimization/110776
gcc/ChangeLog:
* tree-vect-stmts.cc (vectorizable_load): Always cost VMAT_ELEMENTWISE
as scalar load.
Patrick Palka [Wed, 26 Jul 2023 21:21:43 +0000 (17:21 -0400)]
c++: passing partially inst ttp as ttp [PR110566]
The previous fix doesn't work for partially instantiated ttps mainly
because most_general_template is a no-op for them. This patch fixes
this by giving such ttps a DECL_TEMPLATE_INFO (extending the r11-734-g2fb595f8348e16 fix) with which most_general_template can obtain
the original, unlowered ttp.
This patch additionally makes coerce_template_template_parms use the
correct amount of levels from the scope of a ttp argument.
PR c++/110566
PR c++/108179
gcc/cp/ChangeLog:
* pt.cc (reduce_template_parm_level): Set DECL_TEMPLATE_INFO
on the DECL_TEMPLATE_RESULT of the new ttp.
(add_defaults_to_ttp): Make a copy of the original ttp's
DECL_TEMPLATE_RESULT, and update this copy's DECL_TEMPLATE_INFO
as well.
(coerce_template_template_parms): Make sure 'scope_args' has
the right amount of levels for the ttp argument.
(most_general_template): Handle template template parameters.
(rewrite_template_parm): Set DECL_TEMPLATE_RESULT on the
DECL_TEMPLATE_RESULT of the new ttp.
gcc/testsuite/ChangeLog:
* g++.dg/cpp1z/class-deduction115.C: New test.
* g++.dg/template/ttp39.C: New test.
Patrick Palka [Wed, 26 Jul 2023 21:21:26 +0000 (17:21 -0400)]
c++: passing partially inst tmpl as ttp [PR110566]
Since the template arguments 'pargs' we pass to coerce_template_parms from
coerce_template_template_parms are always a full set, we need to make sure
we always pass the parameters of the most general template because if the
template is partially instantiated then the levels won't match up. In the
testcase below during said call to coerce_template_parms the parameters are
{X, Y}, both level 1 rather than 2, and the arguments are {{int}, {N, M}},
which results in a crash during auto deduction for parameters' types.
PR c++/110566
PR c++/108179
gcc/cp/ChangeLog:
* pt.cc (coerce_template_template_parms): Simplify by using
DECL_INNERMOST_TEMPLATE_PARMS and removing redundant asserts.
Always pass the parameters of the most general template to
coerce_template_parms.
[PATCH 2/5] [RISC-V] Generate Zicond instruction for basic semantics
This patch completes the recognition of the basic semantics
defined in the spec, namely:
Conditional zero, if condition is equal to zero
rd = (rs2 == 0) ? 0 : rs1
Conditional zero, if condition is non zero
rd = (rs2 != 0) ? 0 : rs1
gcc/ChangeLog:
* config/riscv/riscv.md: Include zicond.md
* config/riscv/zicond.md: New file.
gcc/testsuite/ChangeLog:
* gcc.target/riscv/zicond-primitiveSemantics.c: New test.
Co-authored-by: Philipp Tomsich <philipp.tomsich@vrull.eu> Co-authored-by: Raphael Zinsly <rzinsly@ventanamicro.com> Co-authored-by: Jeff Law <jlaw@ventanamicro.com>
Harald Anlauf [Wed, 26 Jul 2023 19:12:45 +0000 (21:12 +0200)]
Fortran: diagnose strings of non-constant length in DATA statements [PR68569]
gcc/fortran/ChangeLog:
PR fortran/68569
* resolve.cc (check_data_variable): Do not accept strings with
deferred length or non-constant length in a DATA statement.
Reject also substrings of string variables of non-constant length.
Carl Love [Wed, 26 Jul 2023 17:49:47 +0000 (13:49 -0400)]
rs6000, add argument to function find_instance
The function find_instance assumes it is called to check a built-in with
only two arguments. This patch extends the function by adding a parameter
specifying the number of built-in arguments to check.
Note, this patch was supposed to have been applied before commit:
gcc/ChangeLog:
* config/rs6000/rs6000-c.cc (find_instance): Add new parameter that
specifies the number of built-in arguments to check.
(altivec_resolve_overloaded_builtin): Update calls to find_instance
to pass the number of built-in arguments to be checked.
Marek Polacek [Tue, 25 Jul 2023 18:03:02 +0000 (14:03 -0400)]
c++: cp_parser_constant_expression cleanups
It's pointless to call *_rvalue_constant_expression when we're not using
the result. Also apply some drive-by cleanups.
gcc/cp/ChangeLog:
* parser.cc (cp_parser_constant_expression): Allow non_constant_p to be
nullptr even when allow_non_constant_p is true. Don't call
_rvalue_constant_expression when not necessary. Move local variable
declarations closer to their first use.
(cp_parser_static_assert): Don't pass a dummy down to
cp_parser_constant_expression.
Jason Merrill [Wed, 26 Jul 2023 14:39:34 +0000 (10:39 -0400)]
c++: member vs global template [PR106310]
For backward compatibility we still want to allow patterns like
this->A<T>::foo, but the template keyword in a qualified name is
specifically to specify that a dependent name is a template, so don't look
in the enclosing scope at all.
Also fix handling of dependent bases: if member lookup in the current
instantiation fails and we have dependent bases, the lookup is dependent.
We were already handling that for the case where lookup in the enclosing
scope also fails, but we also want it to affect that lookup itself.
PR c++/106310
gcc/cp/ChangeLog:
* parser.cc (cp_parser_template_name): Skip non-member
lookup after the template keyword.
(cp_parser_lookup_name): Pass down template_keyword_p.
David Faust [Mon, 24 Jul 2023 16:45:17 +0000 (09:45 -0700)]
bpf: add v3 atomic instructions
This patch adds support for the general atomic operations introduced in
eBPF v3. In addition to the existing atomic add instruction, this adds:
- Atomic and, or, xor
- Fetching versions of these operations (including add)
- Atomic exchange
- Atomic compare-and-exchange
To control emission of these instructions, a new target option
-m[no-]v3-atomics is added. This option is enabled by -mcpu=v3
and above.
Support for these instructions was recently added in binutils.
gcc/
* config/bpf/bpf.opt (mv3-atomics): New option.
* config/bpf/bpf.cc (bpf_option_override): Handle it here.
* config/bpf/bpf.h (enum_reg_class): Add R0 class.
(REG_CLASS_NAMES): Likewise.
(REG_CLASS_CONTENTS): Likewise.
(REGNO_REG_CLASS): Handle R0.
* config/bpf/bpf.md (UNSPEC_XADD): Rename to UNSPEC_AADD.
(UNSPEC_AAND): New unspec.
(UNSPEC_AOR): Likewise.
(UNSPEC_AXOR): Likewise.
(UNSPEC_AFADD): Likewise.
(UNSPEC_AFAND): Likewise.
(UNSPEC_AFOR): Likewise.
(UNSPEC_AFXOR): Likewise.
(UNSPEC_AXCHG): Likewise.
(UNSPEC_ACMPX): Likewise.
(atomic_add<mode>): Use UNSPEC_AADD and atomic type attribute.
Move to...
* config/bpf/atomic.md: ...Here. New file.
* config/bpf/constraints.md (t): New constraint for R0.
* doc/invoke.texi (eBPF Options): Document -mv3-atomics.
gcc/testsuite/
* gcc.target/bpf/atomic-cmpxchg-1.c: New test.
* gcc.target/bpf/atomic-cmpxchg-2.c: New test.
* gcc.target/bpf/atomic-fetch-op-1.c: New test.
* gcc.target/bpf/atomic-fetch-op-2.c: New test.
* gcc.target/bpf/atomic-fetch-op-3.c: New test.
* gcc.target/bpf/atomic-op-1.c: New test.
* gcc.target/bpf/atomic-op-2.c: New test.
* gcc.target/bpf/atomic-op-3.c: New test.
* gcc.target/bpf/atomic-xchg-1.c: New test.
* gcc.target/bpf/atomic-xchg-2.c: New test.
Jonathan Wakely [Wed, 26 Jul 2023 13:09:24 +0000 (14:09 +0100)]
libstdc++: Avoid bogus overflow warnings in std::vector<bool> [PR110807]
GCC thinks the allocation can alter the object being copied if it's
globally reachable, so doesn't realize that [x.begin(), x.end()) after
the allocation is the same as x.size() before it.
This causes a testsuite failure when testing with -D_GLIBCXX_DEBUG:
FAIL: 23_containers/vector/bool/swap.cc (test for excess errors)
A fix is to move the calls to x.begin() and x.end() to before the
allocation.
A similar problem exists in vector<bool>::_M_insert_range where *this is
globally reachable, as reported in PR libstdc++/110807. That can also be
fixed by moving calls to begin() and end() before the allocation.
libstdc++-v3/ChangeLog:
PR libstdc++/110807
* include/bits/stl_bvector.h (vector(const vector&)): Access
iterators before allocating.
* include/bits/vector.tcc (vector<bool>::_M_insert_range):
Likewise.
* testsuite/23_containers/vector/bool/110807.cc: New test.
Jonathan Wakely [Wed, 26 Jul 2023 13:05:58 +0000 (14:05 +0100)]
libstdc++: Add deprecated attribute to std::random_shuffle declarations
We already have these attributes on the definitions in <bits/stl_algo.h>
but they don't work due to PR c++/84542. Add the attributes to the
declarations in <bits/algorithmfwd.h> as well, and add a test.
Also reformat a comment that had too long lines.
Commit c5bd0e5870a introduced both these problems to fix.
Committed as obvious after ensuring that when running the testcase on
AArch64 it still fails before the original c5bd0e5870a commit and passes
after it.
The first argument of the vec_replace_unaligned built-in should always be
of type vector unsigned char, as specified in gcc/doc/extend.texi.
This patch fixes the builtin definitions and updates the test cases to use
the correct arguments. The original test file is renamed and a second test
file is added for a new test case.
gcc/ChangeLog:
* config/rs6000/rs6000-builtins.def: Rename
__builtin_altivec_vreplace_un_uv2di as __builtin_altivec_vreplace_un_udi
__builtin_altivec_vreplace_un_uv4si as __builtin_altivec_vreplace_un_usi
__builtin_altivec_vreplace_un_v2df as __builtin_altivec_vreplace_un_df
__builtin_altivec_vreplace_un_v2di as __builtin_altivec_vreplace_un_di
__builtin_altivec_vreplace_un_v4sf as __builtin_altivec_vreplace_un_sf
__builtin_altivec_vreplace_un_v4si as __builtin_altivec_vreplace_un_si.
Rename VREPLACE_UN_UV2DI as VREPLACE_UN_UDI, VREPLACE_UN_UV4SI as
VREPLACE_UN_USI, VREPLACE_UN_V2DF as VREPLACE_UN_DF,
VREPLACE_UN_V2DI as VREPLACE_UN_DI, VREPLACE_UN_V4SF as
VREPLACE_UN_SF, VREPLACE_UN_V4SI as VREPLACE_UN_SI.
Rename vreplace_un_v2di as vreplace_un_di, vreplace_un_v4si as
vreplace_un_si, vreplace_un_v2df as vreplace_un_df,
vreplace_un_v2di as vreplace_un_di, vreplace_un_v4sf as
vreplace_un_sf, vreplace_un_v4si as vreplace_un_si.
* config/rs6000/rs6000-c.cc (find_instance): Add case
RS6000_OVLD_VEC_REPLACE_UN.
* config/rs6000/rs6000-overload.def (__builtin_vec_replace_un):
Fix first argument type. Rename VREPLACE_UN_UV4SI as
VREPLACE_UN_USI, VREPLACE_UN_V4SI as VREPLACE_UN_SI,
VREPLACE_UN_UV2DI as VREPLACE_UN_UDI, VREPLACE_UN_V2DI as
VREPLACE_UN_DI, VREPLACE_UN_V4SF as VREPLACE_UN_SF,
VREPLACE_UN_V2DF as VREPLACE_UN_DF.
* config/rs6000/vsx.md (REPLACE_ELT): Rename the mode_iterator
REPLACE_ELT_V for vector modes.
(REPLACE_ELT): New scalar mode iterator.
(REPLACE_ELT_char): Add scalar attributes.
(vreplace_un_<mode>): Change iterator and mode attribute.
gcc/testsuite/ChangeLog:
* gcc.target/powerpc/vec-replace-word-runnable.c: Renam
vec-replace-word-runnable_1.c.
* gcc.target/powerpc/vec-replace-word-runnable_1.c
(dg-options): add -flax-vector-conversions.
(vec_replace_unaligned) Fix first argument type.
(vresult_uchar): Fix expected results.
(vec_replace_unaligned): Update for loop to check uchar results.
Remove extra spaces in if statements. Insert missing spaces in
for statements.
* gcc.target/powerpc/vec-replace-word-runnable_2.c: New test file.
David Malcolm [Wed, 26 Jul 2023 14:29:20 +0000 (10:29 -0400)]
analyzer: add symbol base class, moving region id to there [PR104940]
This patch introduces a "symbol" base class that region and svalue
both inherit from, generalizing the ID from the region class so it's
also used by svalues. This gives a way of sorting regions and svalues
into creation order, which I've found useful in my experiments with
adding SMT support (PR analyzer/104940).
OpenMP: Call cuMemcpy2D/cuMemcpy3D for nvptx for omp_target_memcpy_rect
When copying a 2D or 3D rectangular memmory block, the performance is
better when using CUDA's cuMemcpy2D/cuMemcpy3D instead of copying the
data one by one. That's what this commit does.
Additionally, it permits device-to-device copies, if neccessary using a
temporary variable on the host.
The testcase should use dg-additional-options istead of dg-options to
not overwrite default compile flags that include path for finding
the IEEE modules.
gcc/testsuite/ChangeLog:
* gfortran.dg/ieee/comparisons_3.F90: Use dg-additional-options
instead of dg-options.
The following patch makes sure to elide a redundant permute that
can be merged with existing splats represented as load permutations
as we now do for non-grouped SLP loads. This is the last bit
missing to fix this PR where the main fix was already done by r14-2117-gdd86a5a69cbda4
PR tree-optimization/106081
* tree-vect-slp.cc (vect_optimize_slp_pass::start_choosing_layouts):
Assign layout -1 to splats.
The test deliberately reads beyond bounds to exersize ubsan and the
return value may be anything, based on previous allocations. The OFF
test caters for it by ANDing the return with 0, do the same for the DYN
test.
gcc/testsuite/ChangeLog:
PR testsuite/110763
* gcc.dg/ubsan/object-size-dyn.c (dyn): New parameter RET.
(main): Use it.
This approach addresses issues with exceptions, as well as issues with
denormal/invalid values. An obvious exception to the rule is a division,
where the value != 0.0 should be loaded into the upper half of the
denominator to avoid division by zero exception.
The patch effectively tightens the solution from PR95046 by clearing upper
halves of all operand registers before every potentially trapping instruction.
The testcase:
The implementation emits V4SFmode operation, so we can remove all "emulated"
SSE2 V2SFmode trapping instructions and remove "emulated" SSE2 V2SFmode
alternatives from 3dNOW! insn patterns.
PR target/110762
gcc/ChangeLog:
* config/i386/i386.md (plusminusmult): New code iterator.
* config/i386/mmx.md (mmxdoublevecmode): New mode attribute.
(movq_<mode>_to_sse): New expander.
(<plusminusmult:insn>v2sf3): Macroize expander from addv2sf3,
subv2sf3 and mulv2sf3 using plusminusmult code iterator. Rewrite
as a wrapper around V4SFmode operation.
(mmx_addv2sf3): Change operand 1 and operand 2 predicates to
nonimmediate_operand.
(*mmx_addv2sf3): Remove SSE alternatives. Change operand 1 and
operand 2 predicates to nonimmediate_operand.
(mmx_subv2sf3): Change operand 2 predicate to nonimmediate_operand.
(mmx_subrv2sf3): Change operand 1 predicate to nonimmediate_operand.
(*mmx_subv2sf3): Remove SSE alternatives. Change operand 1 and
operand 2 predicates to nonimmediate_operand.
(mmx_mulv2sf3): Change operand 1 and operand 2 predicates to
nonimmediate_operand.
(*mmx_mulv2sf3): Remove SSE alternatives. Change operand 1 and
operand 2 predicates to nonimmediate_operand.
(divv2sf3): Rewrite as a wrapper around V4SFmode operation.
(<smaxmin:code>v2sf3): Ditto.
(mmx_<smaxmin:code>v2sf3): Change operand 1 and operand 2
predicates to nonimmediate_operand.
(*mmx_<smaxmin:code>v2sf3): Remove SSE alternatives. Change
operand 1 and operand 2 predicates to nonimmediate_operand.
(mmx_ieee_<ieee_maxmin>v2sf3): Ditto.
(sqrtv2sf2): Rewrite as a wrapper around V4SFmode operation.
(*mmx_haddv2sf3_low): Ditto.
(*mmx_hsubv2sf3_low): Ditto.
(vec_addsubv2sf3): Ditto.
(*mmx_maskcmpv2sf3_comm): Remove.
(*mmx_maskcmpv2sf3): Remove.
(vec_cmpv2sfv2si): Rewrite as a wrapper around V4SFmode operation.
(vcond<V2FI:mode>v2sf): Ditto.
(fmav2sf4): Ditto.
(fmsv2sf4): Ditto.
(fnmav2sf4): Ditto.
(fnmsv2sf4): Ditto.
(fix_truncv2sfv2si2): Ditto.
(fixuns_truncv2sfv2si2): Ditto.
(mmx_fix_truncv2sfv2si2): Remove SSE alternatives.
Change operand 1 predicate to nonimmediate_operand.
(floatv2siv2sf2): Rewrite as a wrapper around V4SFmode operation.
(floatunsv2siv2sf2): Ditto.
(mmx_floatv2siv2sf2): Remove SSE alternatives.
Change operand 1 predicate to nonimmediate_operand.
(nearbyintv2sf2): Rewrite as a wrapper around V4SFmode operation.
(rintv2sf2): Ditto.
(lrintv2sfv2si2): Ditto.
(ceilv2sf2): Ditto.
(lceilv2sfv2si2): Ditto.
(floorv2sf2): Ditto.
(lfloorv2sfv2si2): Ditto.
(btruncv2sf2): Ditto.
(roundv2sf2): Ditto.
(lroundv2sfv2si2): Ditto.
(*mmx_roundv2sf2): Remove.
Richard Biener [Wed, 26 Jul 2023 07:28:10 +0000 (09:28 +0200)]
tree-optimization/110799 - fix bug in code hoisting
Code hoisting part of GIMPLE PRE failed to adjust the TBAA behavior
of common loads in the case the alias set of the ref was the same
but the base alias set was not. It also failed to adjust the
base behavior, assuming it would match. The following plugs this
hole.
PR tree-optimization/110799
* tree-ssa-pre.cc (compute_avail): More thoroughly match
up TBAA behavior of redundant loads.
Jakub Jelinek [Wed, 26 Jul 2023 08:50:50 +0000 (10:50 +0200)]
range-op-float: Fix up -frounding-math frange_arithmetic +- handling [PR110755]
IEEE754 says that x + (-x) and x - x result in +0 in all rounding modes
but rounding towards negative infinity, in which case the result is -0
for all finite x. x + x and x - (-x) if it is zero retain sign of x.
Now, range_arithmetic implements the normal rounds to even rounding,
and as the addition or subtraction in those cases is exact, we don't do any
further rounding etc. and e.g. on the testcase below distilled from glibc
compute a range [+0, +INF], which is fine for -fno-rounding-math or
if we'd have a guarantee that those statements aren't executed with rounding
towards negative infinity.
I believe it is only +- which has this problematic behavior and I think
it is best to deal with it in frange_arithmetic; if we know -frounding-math
is on, it is x + (-x) or x - x and we are asked to round to negative
infinity (i.e. want low bound rather than high bound), change +0 result to
-0.
2023-07-26 Jakub Jelinek <jakub@redhat.com>
PR tree-optimization/110755
* range-op-float.cc (frange_arithmetic): Change +0 result to -0
for PLUS_EXPR or MINUS_EXPR if -frounding-math, inf is negative and
it is exact op1 + (-op1) or op1 - op1.
Kewen Lin [Wed, 26 Jul 2023 08:42:29 +0000 (03:42 -0500)]
rs6000: Correct vsx operands output for xxeval [PR110741]
PR110741 exposes one issue that we didn't use the correct
character for vsx operands in output operand substitution,
consequently it can map to the wrong registers which hold
some unexpected values.
PR target/110741
gcc/ChangeLog:
* config/rs6000/vsx.md (define_insn xxeval): Correct vsx
operands output with "x".
It looks like we missed out on bitmasks for unary operators because we
were using bit_value_binop exclusively. This patch hands off to
bit_value_unop when appropriate, thus allowing us to handle ABS and
BIT_NOT_EXPR, and others. Follow-up patches will add the tweaks for the
range-ops entries themselves.
c++: Track lifetimes in constant evaluation [PR70331,PR96630,PR98675]
This adds rudimentary lifetime tracking in C++ constexpr contexts,
allowing the compiler to report errors with using values after their
backing has gone out of scope. We don't yet handle other ways of
accessing values outside their lifetime (e.g. following explicit
destructor calls).
PR c++/96630
PR c++/98675
PR c++/70331
gcc/cp/ChangeLog:
* constexpr.cc (constexpr_global_ctx::is_outside_lifetime): New
function.
(constexpr_global_ctx::get_value): Don't return expired values.
(constexpr_global_ctx::get_value_ptr): Likewise.
(constexpr_global_ctx::remove_value): Mark value outside
lifetime.
(outside_lifetime_error): New function.
(cxx_eval_call_expression): No longer track save_exprs.
(cxx_eval_loop_expr): Likewise.
(cxx_eval_constant_expression): Add checks for outside lifetime
values. Remove local variables at end of bind exprs, and
temporaries after cleanup points.
gcc/testsuite/ChangeLog:
* g++.dg/cpp1y/constexpr-lifetime1.C: New test.
* g++.dg/cpp1y/constexpr-lifetime2.C: New test.
* g++.dg/cpp1y/constexpr-lifetime3.C: New test.
* g++.dg/cpp1y/constexpr-lifetime4.C: New test.
* g++.dg/cpp1y/constexpr-lifetime5.C: New test.
* g++.dg/cpp1y/constexpr-lifetime6.C: New test.
c++: Prevent dangling pointers from becoming nullptr in constexpr [PR110619]
Currently, when typeck discovers that a return statement will refer to a
local variable it rewrites to return a null pointer. This causes the
error messages for using the return value in a constant expression to be
unhelpful, especially for reference return values, and is also a visible
change to otherwise valid code (as in the linked PR).
The transformation is nonetheless important, however, both as a safety
guard against attackers being able to gain a handle to other data on the
stack, and to prevent duplicate warnings from later null-dereference
warning passes.
As such, this patch just delays the transformation until cp_genericize,
after constexpr function definitions have been generated.
PR c++/110619
gcc/cp/ChangeLog:
* cp-gimplify.cc (cp_genericize_r): Transform RETURN_EXPRs to
not return dangling pointers.
* cp-tree.h (RETURN_EXPR_LOCAL_ADDR_P): New flag.
(check_return_expr): Add a new parameter.
* semantics.cc (finish_return_stmt): Set flag on RETURN_EXPR
when referring to dangling pointer.
* typeck.cc (check_return_expr): Disable transformation of
dangling pointers, instead pass this information to caller.
c++: Improve location information in constant evaluation
This patch updates 'input_location' during constant evaluation to ensure
that errors in subexpressions that lack location information still
provide accurate diagnostics.
By itself this change causes some small regressions in diagnostic
quality for circumstances where errors used 'input_location' but the
location of the parent subexpression doesn't make sense, so this patch
also includes a small diagnostic improvement to fix the most egregious
case.
gcc/cp/ChangeLog:
* constexpr.cc (modifying_const_object_error): Find the source
location of the const object's declaration.
(cxx_eval_constant_expression): Update input_location to the
location of the currently evaluated expression, if possible.
David Faust [Tue, 25 Jul 2023 18:50:38 +0000 (11:50 -0700)]
bpf: don't print () in bpf_print_operand_address
Unfortunately, the pseudo-C dialect syntax used for some of the v3
atomic instructions clashes with unconditionally printing the
surrounding parentheses in bpf_print_operand_address.
Instead, place the parentheses in the output templates where needed.
gcc/
* config/bpf/bpf.cc (bpf_print_operand_address): Don't print
enclosing parentheses for pseudo-C dialect.
* config/bpf/bpf.md (zero_exdendhidi2): Add parentheses around
operands of pseudo-C dialect output templates where needed.
(zero_extendqidi2): Likewise.
(zero_extendsidi2): Likewise.
(*mov<MM:mode>): Likewise.
Andrew Pinski [Tue, 25 Jul 2023 21:50:33 +0000 (21:50 +0000)]
Fix 110803: use of plain char instead of signed char
So the problem here is that plain char can either be signed
or unsigned depending on the target (powerpc and aarch64 are
unsigned while most other targets are signed). So the testcase
gcc.c-torture/execute/pr109986.c was assuming plain char was signed
char which is wrong so it is better to just change the `char` to be
`signed char`.
Note gcc.c-torture/execute/pr109986.c includes gcc.dg/tree-ssa/pr109986.c
where the plain char was being used.
Committed as obvious after a quick test to make sure gcc.c-torture/execute/pr109986.c
now passes and gcc.dg/tree-ssa/pr109986.c still passes.
gcc/testsuite/ChangeLog:
PR testsuite/110803
* gcc.dg/tree-ssa/pr109986.c: Change plain char to be
`signed char`.
Marek Polacek [Tue, 25 Jul 2023 18:36:47 +0000 (14:36 -0400)]
c++: clear tf_partial et al in instantiate_template [PR108960]
In <https://gcc.gnu.org/pipermail/gcc-patches/2023-February/612929.html>
we concluded that we might clear all flags except tf_warning_or_error
when performing instantiate_template.