aboutsummaryrefslogtreecommitdiff
path: root/gcc
AgeCommit message (Collapse)AuthorFilesLines
2024-05-17ada: Replace spinlocks with fully-fledged locks in finalization collectionsEric Botcazou54-368/+723
This replaces spinlocks with fully-fledged locks in finalization collections because the former are deemed problematic with tasks that can be preempted. Because of the requirement to avoid dragging the tasking runtime when it is not necessary, the implementation goes through the usual soft links, with an additional hurdle that space must be reserved for the lock in any case since it is part of the ABI. This entails the introduction of the System.OS_Locks unit in the non-tasking runtime and the modification of the tasking runtime to also use this unit. This in turn requires a small adjustment: because of the presence of pre- and post-conditions in Interfaces.C and of the limitations of the RTSfind mechanism, the System.Finalization_Primitives unit must be preloaded, as what is done for the Ada.Strings.Text_Buffers unit. This effectively reverts the implementation to using the global task lock on bare board platforms. gcc/ada/ * Makefile.rtl (GNATRTL_NONTASKING_OBJS): Add s-oslock$(objext). (LIBGNAT_TARGET_PAIRS): Use s-oslock__dummy.ads by default. Set specific s-oslock.ads source file for all the platforms. * exp_ch7.ads (Preload_Finalization_Collection): New procedure. * exp_ch7.adb (Allows_Finalization_Collection): Return False if System.Finalization_Primitives has not been preloaded. (Preload_Finalization_Collection): New procedure. * opt.ads (Interface_Seen): New boolean variable. * s-oscons-tmplt.c: Use "N" string for pragma Style_Checks. * scng.adb (Scan): Set Interface_Seen upon seeing "interface". * sem_ch10.adb: Add clause for Exp_Ch7. (Analyze_Compilation_Unit): Call Preload_Finalization_Collection after the context of the unit is analyzed. * libgnarl/a-rttiev.adb: Add with clause for System.OS_Locks and alphabetize others. (Event_Queue_Lock): Adjust qualified name of subtype. * libgnarl/s-osinte__aix.ads: Add with clause for System.OS_Locks and change pthread_mutex_t into a local subtype. * libgnarl/s-osinte__android.ads: Likewise. * libgnarl/s-osinte__darwin.ads: Likewise. * libgnarl/s-osinte__dragonfly.ads: Likewise. * libgnarl/s-osinte__freebsd.ads: Likewise. * libgnarl/s-osinte__gnu.ads: Likewise. * libgnarl/s-osinte__hpux-dce.ads: Likewise. * libgnarl/s-osinte__hpux.ads: Add Likewise. * libgnarl/s-osinte__kfreebsd-gnu.ads: Likewise. * libgnarl/s-osinte__linux.ads: Likewise. * libgnarl/s-osinte__lynxos178e.ads: Likewise. * libgnarl/s-osinte__qnx.ads: Likewise. * libgnarl/s-osinte__rtems.ads: Likewise. * libgnarl/s-osinte__mingw.ads: Add with clause for System.OS_Locks and change CRITICAL_SECTION into a local subtype. Add declarations for imported procedures dealing with CRITICAL_SECTION. * libgnarl/s-osinte__solaris.ads: Add with clause for System.OS_Locks and change mutex_t into a local subtype. * libgnarl/s-osinte__vxworks.ads: Add missing blank line. * libgnarl/s-taprop.ads: Alphabetize clauses and package renamings. Use qualified name for RTS_Lock throughout. * libgnarl/s-taprop__dummy.adb: Add use clause for System.OS_Locks and alphabetize others. * libgnarl/s-taprop__hpux-dce.adb: Likewise. * libgnarl/s-taprop__linux.adb: Likewise. * libgnarl/s-taprop__posix.adb: Likewise. * libgnarl/s-taprop__qnx.adb: Likewise. * libgnarl/s-taprop__rtems.adb: Likewise. * libgnarl/s-taprop__solaris.adb: Likewise. * libgnarl/s-taprop__vxworks.adb: Likewise. * libgnarl/s-taprop__mingw.adb: Likewise. Remove declarations for imported procedures dealing with CRITICAL_SECTION. * libgnarl/s-tarest.adb: Add with clause for System.OS_Locks and alphabetize others. (Global_Task_Lock): Adjust qualified name of subtype. * libgnarl/s-tasini.adb: Add clause for System.OS_Locks. (Initialize_RTS_Lock): New procedure. (Finalize_RTS_Lock): Likewise. (Acquire_RTS_Lock): Likewise. (Release_RTS_Lock): Likewise. (Init_RTS): Add compile-time assertions for RTS_Lock types. Set the soft links for the RTS lock manipulation routines. * libgnarl/s-taspri__dummy.ads: Add with clause for System.OS_Locks. (RTS_Lock): Delete and adjust throughout accordingly. * libgnarl/s-taspri__hpux-dce.ads: Likewise. * libgnarl/s-taspri__lynxos.ads: Likewise. * libgnarl/s-taspri__mingw.ads: Likewise. * libgnarl/s-taspri__posix-noaltstack.ads: Likewise. * libgnarl/s-taspri__posix.ads: Likewise. * libgnarl/s-taspri__solaris.ads: Likewise. * libgnarl/s-taspri__vxworks.ads: Likewise. * libgnat/s-finpri.ads: Add clause for System.OS_Locks. (Finalization_Collection): Change type of Lock. * libgnat/s-finpri.adb (Initialize): Call Initialize_RTS_Lock. (Lock_Collection): Call Acquire_RTS_Lock. (Unlock_Collection): Call Release_RTS_Lock. * libgnat/s-oslock__dummy.ads: New file. * libgnat/s-oslock__hpux-dce.ads: Likewise. * libgnat/s-oslock__mingw.ads: Likewise. * libgnat/s-oslock__posix.ads: Likewise. * libgnat/s-oslock__solaris.ads: Likewise. * libgnat/s-oslock__vxworks.ads: Likewise. * libgnat/s-soflin.ads (Null_Set_Address): New null procedure. (Initialize_RTS_Lock): New soft link. (Finalize_RTS_Lock): Likewise. (Acquire_RTS_Lock): Likewise. (Release_RTS_Lock): Likewise. * exp_ch4.adb (Expand_N_Allocator): In the subtype indication case, call Apply_Predicate_Check on the resulting access value if need be.
2024-05-17ada: Document secondary usage of Materialize_Entity flagEric Botcazou1-2/+3
The flag is also used by the semantic analyzer. gcc/ada/ * einfo.ads (Materialize_Entity): Document secondary usage.
2024-05-17ada: Bug in computing local restrictions inherited from enclosing scopes.Steve Baird1-13/+19
In the function Local_Restrict.Active_Restriction, we traverse enclosing scopes looking for a relevant Local_Restrictions aspect specification. Fix a bug in this traversal. gcc/ada/ * local_restrict.adb (Active_Restriction): When traversing scopes, do not skip over a subprogram body.
2024-05-17ada: Factor out duplicated code in bodies of System.Task_Primitives.OperationsEric Botcazou5-129/+90
The duplication is present in some POSIX-like implementations (POSIX and RTEMS) while it has already been eliminated in others (Linux, QNX). The latter implementations are also slightly modified for consistency's sake. No functional changes. gcc/ada/ * libgnarl/s-taprop__dummy.adb (Initialize_Lock): Fix formatting. * libgnarl/s-taprop__linux.adb (RTS_Lock_Ptr): Delete. (Init_Mutex): Rename into... (Initialize_Lock): ...this. (Initialize_Lock [Lock]): Call above procedure. (Initialize_Lock [RTS_Lock]): Likewise. (Initialize_TCB): Likewise. * libgnarl/s-taprop__posix.adb (Initialize_Lock): New procedure factored out from the other two homonyms. (Initialize_Lock [Lock]): Call above procedure. (Initialize_Lock [RTS_Lock]): Likewise. * libgnarl/s-taprop__qnx.adb (RTS_Lock_Ptr): Delete. (Init_Mutex): Rename into... (Initialize_Lock): ...this. (Initialize_Lock [Lock]): Call above procedure. (Initialize_Lock [RTS_Lock]): Likewise. (Initialize_TCB): Likewise. * libgnarl/s-taprop__rtems.adb (Initialize_Lock): New procedure factored out from the other two homonyms. (Initialize_Lock [Lock]): Call above procedure. (Initialize_Lock [RTS_Lock]): Likewise.
2024-05-17ada: Fix for validity checking and conditional evaluation of 'OldPiotr Trojanek1-0/+8
Detection of expression that are "known on entry" (as defined in Ada 2022 RM 6.1.1(20/5)) was confused by validity checks when used from within expansion of attribute 'Old. gcc/ada/ * sem_util.adb (Is_Known_On_Entry): Handle constants introduced by validity checks.
2024-05-17ada: Do not query the modification time of a special file.Steve Baird1-2/+16
In Ada.Directories, the function Modification_Time raises Name_Error if it is called for a special file. So don't do that in Start_Search_Internal. gcc/ada/ * libgnat/a-direct.adb (Start_Search_Internal): Do not call Modification_Time for a special file; declare a Calendar.Time constant No_Time and use that instead.
2024-05-17ada: Disable Equivalent_Array_Aggregate optimization if predicates involvedSteve Baird1-0/+1
In most paths, the function Build_Equivalent_Record_Aggregate was already testing Has_Predicates for a given component type and conditionally returning an Empty result. This is also needed in the case of a scalar component type. Without it, we can build corrupt trees that fail use-before-definition detection checks in gigi. gcc/ada/ * exp_ch3.adb (Build_Equivalent_Record_Aggregate): Add Has_Predicates test for a scalar component to match what is already done for other kinds of components.
2024-05-17ada: Clarify code for aggregate warningsRonan Desplanques1-27/+25
This patch improves comments in code that emits warnings about particular situations involving aggregates. It also removes a conjunct in a condition that's useless because always true in the context of the test. gcc/ada/ * sem_aggr.adb (Resolve_Array_Aggregate): Improve comments and condition.
2024-05-17ada: Fix others error message locationRonan Desplanques1-24/+19
Before this patch, the compiler pointed at the wrong component association when reporting an illegal occurrence of "others" in an aggregate. This patch fixes this by keeping track of which choice contains the occurrence of "others" when resolving array aggregates. gcc/ada/ * sem_aggr.adb (Resolve_Array_Aggregate): Fix location of error message.
2024-05-17ada: Expose utility routine for processing of Depends contracts in SPARKPiotr Trojanek3-29/+28
Routine Is_Unconstrained_Or_Tagged_Item is now used both in the GNAT frontend (for checking legality of Depends clauses) and in the GNATprove backend (for representing implicit inputs in flow graphs). gcc/ada/ * sem_prag.adb (Is_Unconstrained_Or_Tagged_Item): Move to Sem_Util, so it can be used from GNATprove. * sem_util.ads (Is_Unconstrained_Or_Tagged_Item): Move from Sem_Prag; spec. * sem_util.adb (Is_Unconstrained_Or_Tagged_Item): Move from Sem_Prag; body.
2024-05-17ada: Couple of adjustments coming from aliasing considerationsEric Botcazou4-9/+71
The first adjustment is to the expansion of implementation types for array types with peculiar index types, for which the aliased property set on the component of the original type must be copied; the implicit base type also needs to be properly marked if the implementation type is constrained. The second adjustment is to selected types in the runtime, which need to be marked with pragma Universal_Aliasing because of their special usage. gcc/ada/ * exp_pakd.adb (Create_Packed_Array_Impl_Type): For non-bit-packed array types, propagate the aliased property of the component. (Install_PAT): Set fields on the implicit base type of an array. * libgnat/a-stream.ads (private part): Add pragma Universal_Aliasing for Stream_Element. * libgnat/g-alleve.ads: Add pragma Universal_Aliasing for all the vector types. * libgnat/g-alleve__hard.ads: Likewise.
2024-05-17ada: gnatbind: subprogram spec no longer existsBob Duff5-98/+141
If a subprogram spec S is present while compiling something that says "with S;", but the spec is absent while compiling the body of S, then gnatbind fails to detect the mismatch. The spec and body of S might have different parameter and result types. This patch fixes gnatbind to detect this case and give an error. gcc/ada/ * bcheck.adb (Check_Consistency_Of_Sdep): Split out new procedure. Add check for special case of subprogram spec that no longer exists. (Check_Consistency): Call Check_Consistency_Of_Sdep, except when Reified_Child_Spec is True. No need for "goto Continue" or "exit Sdep_Loop". * ali.ads (Subunit_Name, Unit_Name): Change the type to Unit_Name_Type. Add a comment pointing to the ALI file documentation, because it's in a somewhat-surprising place. * ali.adb (Scan_ALI): Subunit_Name and Unit_Name are now Unit_Name_Type. Remove comment explaining why Name_Find is used; Name_Find is the usual case. Do not remove the "%s" or "%b" from the Unit_Name. We need to be able to distinguish specs and bodies. This is also necessary to obey the invariant of Unit_Name_Type. * binde.adb (Write_Closure): Subunit_Name is now Unit_Name_Type. * clean.adb (Clean_Executables): Likewise.
2024-05-17ada: Update docs for Resolve_Null_Array_AggregateRonan Desplanques1-6/+6
The documentation comments for Sem_Aggr.Resolve_Null_Array_Aggregate suggested that this subprogram created a subtype, which it didn't. This patch replaces those comments with ones that better match the behavior. gcc/ada/ * sem_aggr.adb (Resolve_Null_Array_Aggregate): Update documentation comments.
2024-05-17ada: Fix containers' Reference_Preserving_Key functions' memory leaksSteve Baird7-3/+61
Fix memory leaks in containers' Reference_Preserving_Key functions Make the same change in each of 3 Ada.Containers child units: Ordered_Sets, Indefinite_Ordered_Sets, and Bounded_Ordered_Sets. The function Reference_Preserving_Key evaluates an allocator of type Key_Access whose storage was not being reclaimed. Update the Finalize procedure for type Reference_Control_Type to free that storage. But this change introduces a possible erroneous double-free situation if an object is copied (because the original and the copy will each be finalized at some point). So also introduce an Adjust procedure which allocates a copy of the allocated object. Another possible solution to this problem (which is not being implemented yet) is based on implementing AI22-0082. Also include a fix for a bug in Sem_Util.Has_Some_Controlled_Component that was discovered while working on this. gcc/ada/ * sem_util.adb (Has_Some_Controlled_Component): Fix a bug which causes (in some cases involving a Disable_Controlled aspect specification) Needs_Finalization to return different answers for one type depending on whether the function is called before or after the type is frozen. * libgnat/a-coorse.ads: Type Control_Reference_Type gets an Adjust procedure. * libgnat/a-cborse.ads: Likewise. * libgnat/a-ciorse.ads: Likewise * libgnat/a-coorse.adb: (Finalize): Reclaim allocated Key_Type object. (Adjust): New procedure; prevent sharing of non-null Key_Access values by allocating a copy. * libgnat/a-cborse.adb: Likewise. * libgnat/a-ciorse.adb: Likewise.
2024-05-17ada: correction to gnatbind-related cleanupsBob Duff1-3/+2
Correction to previous change; Asserts had been moved to before Buf was initialized. gcc/ada/ * uname.adb (Get_Unit_Name_String): Move Asserts after Buf is initialized.
2024-05-17ada: gnatbind-related cleanupsBob Duff3-45/+28
This patch cleans up some things noticed while working on gnatbind. No change in behavior yet. gcc/ada/ * ali-util.adb (Read_Withed_ALIs): Minor reformatting. * bindo-units.adb (Corresponding_Body): Add assert. (Corresponding_Spec): Likewise. * uname.adb: Clean up assertions, use available functions. Get_Spec_Name/Get_Body_Name can assert that N obeys the conventions for Unit_Name_Type (end in "%s" or "%b").
2024-05-17ada: Make raise-gcc.c compatible with ClangSebastian Poeplau1-0/+8
The Morello variant of Clang doesn't have __builtin_code_address_from_pointer; work around it where necessary. gcc/ada/ * raise-gcc.c: Work around __builtin_code_address_from_pointer if it is unavailable.
2024-05-17ada: Fix crash caused by missing New_Copy_treeMarc Poulhiès1-3/+6
Since a recent refactor ("Factor common processing in expansion of aggregates") where Initialize_Array_Component and Initialize_Record_Component are merged, the behavior has slightly changed. In the case of the expansion of an aggregate initialization where the number of 'others' components is <= 3, the initialization expression is not duplicated anymore, causing some incorrect multiple definition when said expression is later transformed with Expressions_With_Action that declares an object. The simple fix is to add the now missing New_Copy_Tree where the assignments are created. gcc/ada/ * exp_aggr.adb (Build_Array_Aggr_Code) <Gen_Loop>: Copy the initialization expression when unrolling the loop.
2024-05-17ada: Fix Constraint_Error on mutable assignmentBob Duff1-1/+2
For an assignment statement "X := Y;", where X is a formal parameter of a "late overriding" subprogram (i.e. it has no spec, and the body is overriding), and the subtype of X is an unconstrained record with defaulted discriminants, if the actual parameter passed to X is unconstrained, then X is unconstrained. This patch fixes a bug where X was incorrectly considered constrained, so that if Y's discriminants are different from X, Constraint_Error was raised. The bug was caused by the fact that an extra "constrained" formal parameter was missing in both caller and callee. gcc/ada/ * sem_disp.adb (Check_Dispatching_Operation): Call Create_Extra_Formals, so that the caller will have an extra "constrained" parameter, which will be checked on assignment in the callee, and will be passed in by the caller.
2024-05-17ada: Only record types with discriminants can be unconstrainedPiotr Trojanek1-7/+4
Remove redundant condition for detecting unconstrained record types. Code cleanup; behavior is unaffected. gcc/ada/ * sem_prag.adb (Is_Unconstrained_Or_Tagged_Item): Remove call to Has_Discriminants; combine ELSIF branches.
2024-05-17ada: Simplify code for private types with unknown discriminantsPiotr Trojanek2-6/+4
Private type entities have Is_Constrained set when they have no discriminants and no unknown discriminants; it is now set slightly later, but simpler (this change could only affect Process_Discriminants, but this flag should not be needed there). Also, we now reuse this flag to detect private types with discriminants. Code cleanup; behavior is unaffected. gcc/ada/ * sem_ch7.adb (New_Private_Type): Simplify setting of Is_Constrained flag. * sem_prag.adb (Is_Unconstrained_Or_Tagged_Item): Simplify detection of private types with no discriminant.
2024-05-17ada: Allow private items with unknown discriminants as Depends inputsPiotr Trojanek1-2/+4
Objects of private types with unknown discriminants are now allowed as inputs in the Depends contracts. gcc/ada/ * sem_prag.adb (Is_Unconstrained_Or_Tagged_Item): Allow objects of private types with unknown discriminants.
2024-05-17ada: Tune detection of unconstrained and tagged items in Depends contractPiotr Trojanek1-4/+4
The Tagged/Array/Record/Private types are mutually exclusive, so they can be examined like with a case statement (except for records with private extensions, but their handling is not affected by this change). gcc/ada/ * sem_prag.adb (Is_Unconstrained_Or_Tagged_Item): Tune repeated testing of type kinds.
2024-05-17ada: Fix probable copy/paste errorMarc Poulhiès3-10/+8
gcc/ada/ * doc/gnat_rm/implementation_defined_attributes.rst: Fix copy/paste. * gnat_rm.texi: Regenerate. * gnat_ugn.texi: Regenerate.
2024-05-17ada: Check subtype to avoid a precondition failureViljar Indus1-2/+3
gcc/ada/ * sem_ch3.adb (Analyze_Component_Declaration): Apply range checks only for Scalar_Types to ensure that they have the Scalar_Range attribute.
2024-05-17ada: Fix checking range constraints within composite typesViljar Indus1-0/+50
Subtype indications were never analyzed if they were within composite types. Analyze them explicitly within Analyze_Component_Declaration. gcc/ada/ * sem_ch3.adb (Analyze_Component_Declaration): Add Range_Checks for Subtype_Indications
2024-05-17ada: Remove superfluous Relocate_Node callsRonan Desplanques2-2/+2
This patch removes two calls to Relocate_Node that were not needed. This does not affect the behavior of the compiler. gcc/ada/ * exp_ch4.adb (Expand_N_Case_Expression): Remove call to Relocate_Node. * sem_attr.adb (Analyze_Attribute): Likewise.
2024-05-17ada: Small cleanup in aggregate expansion codeRonan Desplanques1-8/+8
This patch moves a statement outside of a loop because it didn't need to be inside that loop. The behavior of the program is not affected. gcc/ada/ * exp_aggr.adb (Flatten): Small cleanup.
2024-05-17ada: Add support for 'Object_Size to pragma Compile_Time_{Warning,Error}Eric Botcazou1-64/+65
With the same level as for 'Size, that is to say, full evaluation of the boolean expressions it may be contained in and handling of private types. gcc/ada/ * sem_attr.adb (Analyze_Attribute) <Attribute_Size>: Remove special processing for pragma Compile_Time_{Warning,Error}. (Eval_Attribute.Compile_Time_Known_Attribute): Set Is_Static on the resulting value if In_Compile_Time_Warning_Or_Error is set. (Eval_Attribute.Full_Type): New helper function. (Eval_Attribute): Call Full_Type for type attributes. Add handling of Object_Size and adjust that of Max_Size_In_Storage_Elements in the non-static case.
2024-05-17make -freg-struct-return visibly a negative alias of -fpcc-struct-returnAlexandre Oliva1-2/+2
The fact that both options accept negative forms suggests that maybe they aren't negative forms of each other. They are, but that isn't clear even by examining common.opt. Use NegativeAlias to make it abundantly clear. The 'Optimization' keyword next to freg-struct-return was the only thing that caused flag_pcc_struct_return to be a per-function flag, and ipa-inline relied on that. After making it an alias, the Optimization keyword was no longer operational. I'm not sure it was sensible or desirable for flag_pcc_struct_return to be a per-function setting, but this patch does not intend to change behavior. for gcc/ChangeLog * common.opt (freg-struct-return): Make it explicitly fpcc-struct-return's NegativeAlias. Copy Optimization... (freg-struct-return): ... here.
2024-05-17RISC-V: Cleanup some temporally files [NFC]Pan Li2-0/+0
Just notice some temporally files under gcc/config/riscv, deleted as useless. * Empty file j. * Vim swap file. gcc/ChangeLog: * config/riscv/.riscv.cc.swo: Removed. * config/riscv/j: Removed. Signed-off-by: Pan Li <pan2.li@intel.com>
2024-05-16Update gcc sv.poJoseph Myers1-329/+185
* sv.po: Update.
2024-05-16RISC-V: Enable vectorizable early exit testsuitePan Li3-1/+5
After we supported vectorizable early exit in RISC-V, we would like to enable the gcc vect test for vectorizable early test. The vect-early-break_124-pr114403.c failed to vectorize for now. Because that the __builtin_memcpy with 8 bytes failed to folded into int64 assignment during ccp1. We will improve that first and mark this as xfail for RISC-V. The below tests are passed for this patch: 1. The riscv fully regression tests. gcc/testsuite/ChangeLog: * gcc.dg/vect/slp-mask-store-1.c: Add pragma novector as it will have 2 times LOOP VECTORIZED in RISC-V. * gcc.dg/vect/vect-early-break_124-pr114403.c: Xfail for the riscv backend. * lib/target-supports.exp: Add RISC-V backend. Signed-off-by: Pan Li <pan2.li@intel.com>
2024-05-16RISC-V: Implement vectorizable early exit with vcond_mask_lenPan Li6-9/+175
After we support the loop lens for the vectorizable, we would like to implement the feature for the RISC-V target. Given below example: unsigned vect_a[1923]; unsigned vect_b[1923]; void test (unsigned limit, int n) { for (int i = 0; i < n; i++) { vect_b[i] = limit + i; if (vect_a[i] > limit) { ret = vect_b[i]; return ret; } vect_a[i] = limit; } } Before this patch: ... .L8: sw a3,0(a5) addiw a0,a0,1 addi a4,a4,4 addi a5,a5,4 beq a1,a0,.L2 .L4: sw a0,0(a4) lw a2,0(a5) bleu a2,a3,.L8 ret After this patch: ... .L5: vsetvli a5,a3,e8,mf4,ta,ma vmv1r.v v4,v2 vsetvli t4,zero,e32,m1,ta,ma vmv.v.x v1,a5 vadd.vv v2,v2,v1 vsetvli zero,a5,e32,m1,ta,ma vadd.vv v5,v4,v3 slli a6,a5,2 vle32.v v1,0(t1) vmsltu.vv v1,v3,v1 vcpop.m t4,v1 beq t4,zero,.L4 vmv.x.s a4,v4 .L3: ... The below tests are passed for this patch: 1. The riscv fully regression tests. gcc/ChangeLog: * config/riscv/autovec-opt.md(*vcond_mask_len_popcount_<VB_VLS:mode><P:mode>): New pattern of vcond_mask_len_popcount for vector bool mode. * config/riscv/autovec.md (vcond_mask_len_<mode>): New pattern of vcond_mask_len for vector bool mode. (cbranch<mode>4): New pattern for vector bool mode. * config/riscv/vector-iterators.md: Add new unspec UNSPEC_SELECT_MASK. * config/riscv/vector.md (@pred_popcount<VB:mode><P:mode>): Add VLS mode to popcount pattern. (@pred_popcount<VB_VLS:mode><P:mode>): Ditto. gcc/testsuite/ChangeLog: * gcc.target/riscv/rvv/autovec/early-break-1.c: New test. * gcc.target/riscv/rvv/autovec/early-break-2.c: New test. Signed-off-by: Pan Li <pan2.li@intel.com>
2024-05-16Fix points_to_local_or_readonly_memory_p wrt TARGET_MEM_REFJan Hubicka2-1/+41
TARGET_MEM_REF can be used to offset constant base into a memory object (to produce lea instruction). This confuses points_to_local_or_readonly_memory_p which treats the constant address as a base of the access. Bootstrapped/regtsted x86_64-linux, comitted. Honza gcc/ChangeLog: PR ipa/113787 * ipa-fnsummary.cc (points_to_local_or_readonly_memory_p): Do not look into TARGET_MEM_REFS with constant opreand 0. gcc/testsuite/ChangeLog: * gcc.c-torture/execute/pr113787.c: New test.
2024-05-16tree-optimization/13962 - handle ptr-ptr compares in ptrs_compare_unequalRichard Biener6-9/+51
Now that we handle pt.null conservatively we can implement the missing tracking of constant pool entries (aka STRING_CST) and handle ptr-ptr compares using points-to info in ptrs_compare_unequal. PR tree-optimization/13962 PR tree-optimization/96564 * tree-ssa-alias.h (pt_solution::const_pool): New flag. * tree-ssa-alias.cc (ptrs_compare_unequal): Handle pointer-pointer compares. (dump_points_to_solution): Dump the const_pool flag, fix guard of flag dumping. * gimple-pretty-print.cc (pp_points_to_solution): Likewise. * tree-ssa-structalias.cc (find_what_var_points_to): Set the const_pool flag for STRING. (pt_solution_ior_into): Handle the const_pool flag. (ipa_escaped_pt): Initialize it. * gcc.dg/tree-ssa/alias-39.c: New testcase. * g++.dg/vect/pr68145.cc: Use -fno-tree-pta to avoid UB to manifest in transforms no longer vectorizing this testcase for an ICE.
2024-05-16wrong code with points-to and volatileRichard Biener2-0/+21
The following fixes points-to analysis which ignores the fact that volatile qualified refs can result in any pointer. * tree-ssa-structalias.cc (get_constraint_for_1): For volatile referenced or decls use ANYTHING. * gcc.dg/tree-ssa/alias-38.c: New testcase.
2024-05-16Vect: Support loop len in vectorizable early exitPan Li3-2/+46
This patch adds early break auto-vectorization support for target which use length on partial vectorization. Consider this following example: unsigned vect_a[802]; unsigned vect_b[802]; void test (unsigned x, int n) { for (int i = 0; i < n; i++) { vect_b[i] = x + i; if (vect_a[i] > x) break; vect_a[i] = x; } } We use VCOND_MASK_LEN to simulate the generate (mask && i < len + bias). And then the IR of RVV looks like below: ... _87 = .SELECT_VL (ivtmp_85, POLY_INT_CST [32, 32]); _55 = (int) _87; ... mask_patt_6.13_69 = vect_cst__62 < vect__3.12_67; vec_len_mask_72 = .VCOND_MASK_LEN (mask_patt_6.13_69, { -1, ... }, \ {0, ... }, _87, 0); if (vec_len_mask_72 != { 0, ... }) goto <bb 6>; [5.50%] else goto <bb 7>; [94.50%] The below tests are passed for this patch: 1. The riscv fully regression tests. 2. The x86 bootstrap tests. 3. The x86 fully regression tests. gcc/ChangeLog: * tree-vect-loop.cc (vect_gen_loop_len_mask): New func to gen the loop len mask. * tree-vect-stmts.cc (vectorizable_early_exit): Invoke the vect_gen_loop_len_mask for 1 or more stmt(s). * tree-vectorizer.h (vect_gen_loop_len_mask): New func decl for vect_gen_loop_len_mask. Signed-off-by: Pan Li <pan2.li@intel.com>
2024-05-16Vect: Support new IFN SAT_ADD for unsigned vector intPan Li1-0/+52
For vectorize, we leverage the existing vect pattern recog to find the pattern similar to scalar and let the vectorizer to perform the rest part for standard name usadd<mode>3 in vector mode. The riscv vector backend have insn "Vector Single-Width Saturating Add and Subtract" which can be leveraged when expand the usadd<mode>3 in vector mode. For example: void vec_sat_add_u64 (uint64_t *out, uint64_t *x, uint64_t *y, unsigned n) { unsigned i; for (i = 0; i < n; i++) out[i] = (x[i] + y[i]) | (- (uint64_t)((uint64_t)(x[i] + y[i]) < x[i])); } Before this patch: void vec_sat_add_u64 (uint64_t *out, uint64_t *x, uint64_t *y, unsigned n) { ... _80 = .SELECT_VL (ivtmp_78, POLY_INT_CST [2, 2]); ivtmp_58 = _80 * 8; vect__4.7_61 = .MASK_LEN_LOAD (vectp_x.5_59, 64B, { -1, ... }, _80, 0); vect__6.10_65 = .MASK_LEN_LOAD (vectp_y.8_63, 64B, { -1, ... }, _80, 0); vect__7.11_66 = vect__4.7_61 + vect__6.10_65; mask__8.12_67 = vect__4.7_61 > vect__7.11_66; vect__12.15_72 = .VCOND_MASK (mask__8.12_67, { 18446744073709551615, ... }, vect__7.11_66); .MASK_LEN_STORE (vectp_out.16_74, 64B, { -1, ... }, _80, 0, vect__12.15_72); vectp_x.5_60 = vectp_x.5_59 + ivtmp_58; vectp_y.8_64 = vectp_y.8_63 + ivtmp_58; vectp_out.16_75 = vectp_out.16_74 + ivtmp_58; ivtmp_79 = ivtmp_78 - _80; ... } After this patch: void vec_sat_add_u64 (uint64_t *out, uint64_t *x, uint64_t *y, unsigned n) { ... _62 = .SELECT_VL (ivtmp_60, POLY_INT_CST [2, 2]); ivtmp_46 = _62 * 8; vect__4.7_49 = .MASK_LEN_LOAD (vectp_x.5_47, 64B, { -1, ... }, _62, 0); vect__6.10_53 = .MASK_LEN_LOAD (vectp_y.8_51, 64B, { -1, ... }, _62, 0); vect__12.11_54 = .SAT_ADD (vect__4.7_49, vect__6.10_53); .MASK_LEN_STORE (vectp_out.12_56, 64B, { -1, ... }, _62, 0, vect__12.11_54); ... } The below test suites are passed for this patch. * The riscv fully regression tests. * The x86 bootstrap tests. * The x86 fully regression tests. PR target/51492 PR target/112600 gcc/ChangeLog: * tree-vect-patterns.cc (gimple_unsigned_integer_sat_add): New func decl generated by match.pd match. (vect_recog_sat_add_pattern): New func impl to recog the pattern for unsigned SAT_ADD. Signed-off-by: Pan Li <pan2.li@intel.com>
2024-05-16Internal-fn: Support new IFN SAT_ADD for unsigned scalar intPan Li5-2/+88
This patch would like to add the middle-end presentation for the saturation add. Aka set the result of add to the max when overflow. It will take the pattern similar as below. SAT_ADD (x, y) => (x + y) | (-(TYPE)((TYPE)(x + y) < x)) Take uint8_t as example, we will have: * SAT_ADD (1, 254) => 255. * SAT_ADD (1, 255) => 255. * SAT_ADD (2, 255) => 255. * SAT_ADD (255, 255) => 255. Given below example for the unsigned scalar integer uint64_t: uint64_t sat_add_u64 (uint64_t x, uint64_t y) { return (x + y) | (- (uint64_t)((uint64_t)(x + y) < x)); } Before this patch: uint64_t sat_add_uint64_t (uint64_t x, uint64_t y) { long unsigned int _1; _Bool _2; long unsigned int _3; long unsigned int _4; uint64_t _7; long unsigned int _10; __complex__ long unsigned int _11; ;; basic block 2, loop depth 0 ;; pred: ENTRY _11 = .ADD_OVERFLOW (x_5(D), y_6(D)); _1 = REALPART_EXPR <_11>; _10 = IMAGPART_EXPR <_11>; _2 = _10 != 0; _3 = (long unsigned int) _2; _4 = -_3; _7 = _1 | _4; return _7; ;; succ: EXIT } After this patch: uint64_t sat_add_uint64_t (uint64_t x, uint64_t y) { uint64_t _7; ;; basic block 2, loop depth 0 ;; pred: ENTRY _7 = .SAT_ADD (x_5(D), y_6(D)); [tail call] return _7; ;; succ: EXIT } The below tests are passed for this patch: 1. The riscv fully regression tests. 3. The x86 bootstrap tests. 4. The x86 fully regression tests. PR target/51492 PR target/112600 gcc/ChangeLog: * internal-fn.cc (commutative_binary_fn_p): Add type IFN_SAT_ADD to the return true switch case(s). * internal-fn.def (SAT_ADD): Add new signed optab SAT_ADD. * match.pd: Add unsigned SAT_ADD match(es). * optabs.def (OPTAB_NL): Remove fixed-point limitation for us/ssadd. * tree-ssa-math-opts.cc (gimple_unsigned_integer_sat_add): New extern func decl generated in match.pd match. (match_saturation_arith): New func impl to match the saturation arith. (math_opts_dom_walker::after_dom_children): Try match saturation arith when IOR expr. Signed-off-by: Pan Li <pan2.li@intel.com>
2024-05-16Revert "Revert: "Enable prange support.""Aldy Hernandez13-31/+18
This reverts commit d7bb8eaade3cd3aa70715c8567b4d7b08098e699 and enables prange support again.
2024-05-16Cleanup prange sanity checks.Aldy Hernandez6-368/+25
The pointers_handled_p() code was a temporary sanity check, and not even a good one, since we have a cleaner way of checking type mismatches with operand_check_p. This patch removes all the code, and adds an explicit type check for relational operators, which are the main problem in PR114985. Adding this check makes it clear where the type mismatch is happening in IPA, even without prange. I've added code to skip the range folding if the types don't match what the operator expects. In order to reproduce the latent bug, just remove the operand_check_p calls. Tested on x86-64 and ppc64le with and without prange support. gcc/ChangeLog: PR tree-optimization/114985 * gimple-range-op.cc: Remove pointers_handled_p. * ipa-cp.cc (ipa_value_range_from_jfunc): Skip range folding if operands don't match. (propagate_vr_across_jump_function): Same. * range-op-mixed.h: Remove pointers_handled_p and tweak operand_check_p. * range-op-ptr.cc (range_operator::pointers_handled_p): Remove. (pointer_plus_operator::pointers_handled_p): Remove. (class operator_pointer_diff): Remove pointers_handled_p. (operator_pointer_diff::pointers_handled_p): Remove. (operator_identity::pointers_handled_p): Remove. (operator_cst::pointers_handled_p): Remove. (operator_cast::pointers_handled_p): Remove. (operator_min::pointers_handled_p): Remove. (operator_max::pointers_handled_p): Remove. (operator_addr_expr::pointers_handled_p): Remove. (operator_bitwise_and::pointers_handled_p): Remove. (operator_bitwise_or::pointers_handled_p): Remove. (operator_equal::pointers_handled_p): Remove. (operator_not_equal::pointers_handled_p): Remove. (operator_lt::pointers_handled_p): Remove. (operator_le::pointers_handled_p): Remove. (operator_gt::pointers_handled_p): Remove. (operator_ge::pointers_handled_p): Remove. * range-op.cc (TRAP_ON_UNHANDLED_POINTER_OPERATORS): Remove. (range_op_handler::lhs_op1_relation): Remove pointers_handled_p checks. (range_op_handler::lhs_op2_relation): Same. (range_op_handler::op1_op2_relation): Same. * range-op.h: Remove RO_* declarations.
2024-05-16Use a boolean type when folding conditionals in simplify_using_ranges.Aldy Hernandez1-2/+1
In adding some traps for PR114985 I noticed that the conditional folding code in simplify_using_ranges was using the wrong type. This cleans up the oversight. gcc/ChangeLog: PR tree-optimization/114985 * vr-values.cc (simplify_using_ranges::fold_cond_with_ops): Use boolean type when folding conditionals.
2024-05-16RISC-V: testsuite: Drop march-string in cmpmemsi/cpymemsi testsChristoph Müllner2-5/+2
The tests cmpmemsi-1.c and cpymemsi-1.c are execution ("dg-do run") tests, which does not have any restrictions for the enabled extensions. Further, no other listed options are required. Let's drop the options, so that the test can also be executed on non-f and non-d targets. However, we need to set options to the defaults without '-ansi', because the included test file uses the 'asm' keyword, which is not part of ANSI C. gcc/testsuite/ChangeLog: * gcc.target/riscv/cmpmemsi-1.c: Drop options. * gcc.target/riscv/cpymemsi-1.c: Likewise. Signed-off-by: Christoph Müllner <christoph.muellner@vrull.eu>
2024-05-16tree-optimization/79958 - make DSE track multiple pathsRichard Biener8-7/+116
DSE currently gives up when the path we analyze forks. This leads to multiple missed dead store elimination PRs. The following fixes this by recursing for each path and maintaining the visited bitmap to avoid visiting CFG re-merges multiple times. The overall cost is still limited by the same bound, it's just more likely we'll hit the limit now. The patch doesn't try to deal with byte tracking once a path forks but drops info on the floor and only handling fully dead stores in that case. PR tree-optimization/79958 PR tree-optimization/109087 PR tree-optimization/100314 PR tree-optimization/114774 * tree-ssa-dse.cc (dse_classify_store): New forwarder. (dse_classify_store): Add arguments cnt and visited, recurse to track multiple paths when we end up with multiple defs. * gcc.dg/tree-ssa/ssa-dse-48.c: New testcase. * gcc.dg/tree-ssa/ssa-dse-49.c: Likewise. * gcc.dg/tree-ssa/ssa-dse-50.c: Likewise. * gcc.dg/tree-ssa/ssa-dse-51.c: Likewise. * gcc.dg/graphite/pr80906.c: Avoid DSE of last data reference in loop. * g++.dg/ipa/devirt-24.C: Adjust for extra DSE. * g++.dg/warn/Wuninitialized-pr107919-1.C: Use more important -O2 optimization level, -O1 regresses.
2024-05-16ada: Remove obsolete reference in commentEric Botcazou1-4/+4
gcc/ada/ * exp_ch7.adb (Attach_Object_To_Master_Node): Remove reference to a transient object in comment.
2024-05-16ada: Reset scope of top level object declaration during unnestingMarc Poulhiès1-4/+27
When unnesting, the compiler gathers elaboration code and wraps it with a new dedicated procedure. While doing so, it resets the scopes of entities that are wrapped to point to this new procedure. This change also resets the scopes of N_Object_Declaration and N_Object_Renaming_Declaration nodes only if an elaboration procedure is needed. gcc/ada/ * exp_ch7.adb (Reset_Scopes_To_Block_Elab_Proc): also reset scope for object declarations.
2024-05-16ada: Redundant validity checksSteve Baird2-0/+8
In some cases with validity checking enabled via the -gnatVa option, the compiler generates validity checks that can (obviously) never fail. These include validity checks for (some) static expressions, and consecutive identical checks generated for a single read of an object. gcc/ada/ * checks.adb (Expr_Known_Valid): Return True for a static expression. * exp_util.adb (Adjust_Condition): No validity check needed for a condition if it is an expression for which a validity check has already been generated.
2024-05-16ada: Exception on Indefinite_Vector aggregate with loop_parameter_specificationGary Dismukes3-20/+11
Constraint_Error is raised on evaluation of a container aggregate with a loop_parameter_specification for the type Indefinite_Vector. This happens due to the Aggregate aspect for type Indefinite_Vector specifying the Empty_Vector constant for the type's Empty operation rather than using the type's primitive Empty function. This problem shows up as a recent regression relative to earlier compilers, evidently due to recent fixes in the container aggregate area, which uncovered this issue of the wrong specification in Ada.Containers.Indefinite_Vectors. The compiler incorrectly initializes the aggregate object using the Empty_Vector constant rather than invoking the New_Vector function to allocate the vector object with the appropriate number of elements, and subsequent calls to Replace_Element fail because the vector object is empty. In addition to correcting the Indefinite_Vectors generic package, checking is added to give an error for an attempt to specify the Empty operation as a constant rather than a function. (Also note that another AdaCore package that needs a similar correction is the VSS.Vector_Strings package.) gcc/ada/ * libgnat/a-coinve.ads (type Vector): In the Aggregate aspect for this type, the Empty operation is changed to denote the Empty function, rather than the Empty_Vector constant. * exp_aggr.adb (Expand_Container_Aggregate): Remove code for handling the case where the Empty_Subp denotes a constant object, which should never happen (and add an assertion that Empty_Subp must denote a function). * sem_ch13.adb (Valid_Empty): No longer allow the entity to be an E_Constant, and require the (optional) parameter of an Empty function to be of a signed integer type (rather than any integer type).
2024-05-16ada: Implement new experimental attribute 'SuperJustin Squirek8-467/+605
This patch implements (under -gnatX0) the 'Super attribute which can be applied to tagged objects in order to get a view conversion to their immediate parent. gcc/ada/ * doc/gnat_rm/implementation_defined_attributes.rst: Add entry for Super attribute. * accessibility.adb (Accessibility_Level): Add handling for Super. * exp_attr.adb (Expand_N_Attribute_Reference): Add entry for Super. * sem_attr.adb (Analyze_Attribute): Create a case to handle the semantic checking and expansion for Super. (Eval_Attribute): Add entry for Super. * sem_attr.ads: Add entry for Super. * sem_util.adb (Is_Aliased_View, Is_Variable): Add case to handle references to 'Super. * snames.ads-tmpl: Register Name_Super and Attribute_Super. * gnat_rm.texi: Regenerate.