aboutsummaryrefslogtreecommitdiff
path: root/gcc/tree-ssa-alias.c
AgeCommit message (Collapse)AuthorFilesLines
2021-02-28typos: Fix various typos - mainly misspelled reference* [PR99304]Jakub Jelinek1-5/+5
The PR is about a typo in handle_malloc_attribute diagnostic message, but grepping around I found many other cases and while fixing those I've noticed a couple of other typos. 2021-02-28 Jakub Jelinek <jakub@redhat.com> PR c/99304 * ipa.c (symbol_table::remove_unreachable_nodes): Fix a comment typo - referneced -> referenced. * tree.c (component_ref_size): Fix comment typo - refernce -> reference. * tree-ssa-alias.c (access_path_may_continue_p): Fix comment typo - traling -> trailing. (aliasing_component_refs_p): Fix comment typos - refernce -> reference and refernece -> reference and traling -> trailing. (nonoverlapping_refs_since_match_p): Fix comment typo - referneces -> references. * doc/invoke.texi (--param modref-max-bases): Fix a typo - referneces -> references. gcc/c-family/ * c-attribs.c (handle_malloc_attribute): Fix a typo in inform message - refernced -> referenced. Remove superfluous space before closing paren of function calls. gcc/lto/ * lto-symtab.c (lto_symtab_prevailing_virtual_decl): Fix comment typos - refernced -> referenced and devirtualizaiton -> devirtualization.
2021-01-04Update copyright years.Jakub Jelinek1-1/+1
2020-11-21Use OEP_MATCH_SIDE_EFFECTS in compare_ao_refsJan Hubicka1-4/+5
* tree-ssa-alias.c (ao_compare::compare_ao_refs, ao_compare::hash_ao_ref): Use OEP_MATCH_SIDE_EFFECTS.
2020-11-13Revert accidental commitJan Hubicka1-2/+0
* tree-ssa-alias.c (ao_ref_base_alias_ptr_type): Remove accidental commit. (ao_ref_alias_ptr_type): Remove accidental commit.
2020-11-13Improve handling of memory operands in ipa-icf 2/4Jan Hubicka1-1/+375
this patch iplements new class ao_compare that is derived from operand_compare and adds a method to compare and hash ao_refs. This is used by ICF to enable more merging. Comparsion is done as follows 1) Verify that the memory access will happen at the same address and will have same size. For constant addresses this is done by comparing ao_ref_base and offset/size For varable accesses it uses operand_equal_p but with OEP_ADDRESS (that does not match TBAA metadata) and then operand_equal_p on type size. 2) Compare alignments. I use get_object_alignment_1 like ipa-icf did before revamp to operand_equal_p in gcc 9. I noticed that return value is bitodd so added a comment 3) Match MR_DEPENDENCE_CLIQUE At this point the memory refrences are same except for TBAA information. We continue by checking 4) ref and base alias sets. Now if lto streaming is going to happen instead of comparing alias sets themselves we compare alias_ptr_types (the patch depends on the ao_ref_alias_ptr_tyep and ao_ref_base_alias_ptr_type acessors I sent yesterday) 5) See if accesses are view converted. If they are we are done since access path is not present 6) Compare the part of access path relevant for TBAA. I recall FRE relies on the fact that if base and ref types are same the access path is, but I do not thing this is 100% reliable especially with LTO alias sets. The access path comparsion logic is also useful for modref (for next stage1). Tracking the access paths improves quite noticeably disambiguation in C++ code by being able to distinquish different fields of same type within a struct. I had the comparsion logic in my tree for some time and it seems to work quite well. During cc1plus build we have some cases where we find mismatch after matching the base/ref alias sets. These are due to failed type merging: access path oracle in LTO uses TYPE_MAIN_VARIANTs. I implemented relatively basic hashing using base and offset. gcc/ChangeLog: * ipa-icf-gimple.c: Include tree-ssa-alias-compare.h. (find_checker::func_checker): Initialize m_tbaa. (func_checker::hash_operand): Use hash_ao_ref for memory accesses. (func_checker::compare_operand): Use compare_ao_refs for memory accesses. (func_checker::cmopare_gimple_assign): Do not check LHS types of memory stores. * ipa-icf-gimple.h (func_checker): Derive from ao_compare; add m_tbaa. * ipa-icf.c: Include tree-ssa-alias-compare.h. (sem_function::equals_private): Update call of func_checker::func_checker. * ipa-utils.h (lto_streaming_expected_p): New inline predicate. * tree-ssa-alias-compare.h: New file. * tree-ssa-alias.c: Include tree-ssa-alias-compare.h and bultins.h (view_converted_memref_p): New function. (types_equal_for_same_type_for_tbaa_p): New function. (ao_ref_alias_ptr_type, ao_ref_base_alias_ptr_type): New functions. (ao_compare::compare_ao_refs): New member function. (ao_compare::hash_ao_ref): New function * tree-ssa-alias.h (ao_ref_base_alias_ptr_type, ao_ref_alias_ptr_type): Declare. gcc/testsuite/ChangeLog: * c-c++-common/Wstringop-overflow-2.c: Disable ICF. * g++.dg/warn/Warray-bounds-8.C: Disable ICF.
2020-11-12Add support for copy specifiers in fnspecJan Hubicka1-13/+22
* attr-fnspec.h: Update topleve comment. (attr_fnspec::arg_direct_p): Accept 1...9. (attr_fnspec::arg_maybe_written_p): Reject 1...9. (attr_fnspec::arg_copied_to_arg_p): New member function. * builtins.c (builtin_fnspec): Update fnspec of block copy. * tree-ssa-alias.c (attr_fnspec::verify): Update.
2020-10-31Handle fnspec in local ipa-modrefJan Hubicka1-1/+3
* ipa-modref.c (modref_summary::dump): Dump writes_errno. (parm_map_for_arg): Break out from ... (merge_call_side_effects): ... here. (get_access_for_fnspec): New function. (process_fnspec): New function. (analyze_call): Use it. (analyze_stmt): Update. (analyze_function): Initialize writes_errno. (modref_summaries::duplicate): Duplicate writes_errno. * ipa-modref.h (struct modref_summary): Add writes_errno. * tree-ssa-alias.c (call_may_clobber_ref_p_1): Check errno.
2020-10-27Re-enable fnspec checking once fortran frontend is fixed.Jan Hubicka1-4/+1
* tree-ssa-alias.c (attr_fnspec::verify): Re-enabl checking.
2020-10-26Extend builtin fnspecsJan Hubicka1-418/+132
* attr-fnspec.h: Update toplevel comment. (attr_fnspec::attr_fnspec): New constructor. (attr_fnspec::arg_read_p, attr_fnspec::arg_written_p, attr_fnspec::arg_access_size_given_by_arg_p, attr_fnspec::arg_single_access_p attr_fnspec::loads_known_p attr_fnspec::stores_known_p, attr_fnspec::clobbers_errno_p): New member functions. (gimple_call_fnspec): Declare. (builtin_fnspec): Declare. * builtins.c: Include attr-fnspec.h (builtin_fnspec): New function. * builtins.def (BUILT_IN_MEMCPY): Do not specify RET1 fnspec. (BUILT_IN_MEMMOVE): Do not specify RET1 fnspec. (BUILT_IN_MEMSET): Do not specify RET1 fnspec. (BUILT_IN_STRCAT): Do not specify RET1 fnspec. (BUILT_IN_STRCPY): Do not specify RET1 fnspec. (BUILT_IN_STRNCAT): Do not specify RET1 fnspec. (BUILT_IN_STRNCPY): Do not specify RET1 fnspec. (BUILT_IN_MEMCPY_CHK): Do not specify RET1 fnspec. (BUILT_IN_MEMMOVE_CHK): Do not specify RET1 fnspec. (BUILT_IN_MEMSET_CHK): Do not specify RET1 fnspec. (BUILT_IN_STRCAT_CHK): Do not specify RET1 fnspec. (BUILT_IN_STRCPY_CHK): Do not specify RET1 fnspec. (BUILT_IN_STRNCAT_CHK): Do not specify RET1 fnspec. (BUILT_IN_STRNCPY_CHK): Do not specify RET1 fnspec. * gimple.c (gimple_call_fnspec): Return attr_fnspec. (gimple_call_arg_flags): Update. (gimple_call_return_flags): Update. * tree-ssa-alias.c (check_fnspec): New function. (ref_maybe_used_by_call_p_1): Use fnspec for builtin handling. (call_may_clobber_ref_p_1): Likewise. (attr_fnspec::verify): Update verifier. * calls.c (decl_fnspec): New function. (decl_return_flags): Use it.
2020-10-10Improve tree-ssa-alias dump files.Jan Hubicka1-12/+32
* tree-ssa-alias.c (ref_maybe_used_by_call_p_1): Improve debug dumps. (call_may_clobber_ref_p_1): Improve debug dumps.
2020-10-08Disable TBAA in some uses of call_may_clobber_ref_pJan Hubicka1-2/+2
* tree-nrv.c (dest_safe_for_nrv_p): Disable tbaa in call_may_clobber_ref_p and ref_maybe_used_by_stmt_p. * tree-tailcall.c (find_tail_calls): Likewise. * tree-ssa-alias.c (call_may_clobber_ref_p): Add tbaa_p parameter. * tree-ssa-alias.h (call_may_clobber_ref_p): Update prototype. * tree-ssa-sccvn.c (vn_reference_lookup_3): Pass data->tbaa_p to call_may_clobber_ref_p_1.
2020-10-08Fix handling of parm_offset in ipa-modref on 32bit targets.Jan Hubicka1-10/+16
* ipa-modref.c (get_access): Fix handling of offsets. * tree-ssa-alias.c (modref_may_conflict): Watch for overflows.
2020-10-08IPA MOD REF: add debug counter.Martin Liska1-0/+4
gcc/ChangeLog: * dbgcnt.def (DEBUG_COUNTER): Add ipa_mod_ref debug counter. * tree-ssa-alias.c (modref_may_conflict): Handle the counter.
2020-10-03Track access ranges in ipa-modrefJan Hubicka1-5/+33
this patch implements tracking of access ranges. This is only applied when base pointer is an arugment. Incrementally i will extend it to also track TBAA basetype so we can disambiguate ranges for accesses to same basetype (which makes is quite bit more effective). For this reason i track the access offset separately from parameter offset (the second track combined adjustments to the parameter). This is I think last feature I would like to add to the memory access summary this stage1. Further work will be needed to opitmize the summary and merge adjacent range/make collapsing more intelingent (so we do not lose track that often), but I wanted to keep basic patch simple. According to the cc1plus stats: Alias oracle query stats: refs_may_alias_p: 64108082 disambiguations, 74386675 queries ref_maybe_used_by_call_p: 142319 disambiguations, 65004781 queries call_may_clobber_ref_p: 23587 disambiguations, 29420 queries nonoverlapping_component_refs_p: 0 disambiguations, 38117 queries nonoverlapping_refs_since_match_p: 19489 disambiguations, 55748 must overlaps, 76044 queries aliasing_component_refs_p: 54763 disambiguations, 755876 queries TBAA oracle: 24184658 disambiguations 56823187 queries 16260329 are in alias set 0 10617146 queries asked about the same object 125 queries asked about the same alias set 0 access volatile 3960555 are dependent in the DAG 1800374 are aritificially in conflict with void * Modref stats: modref use: 10656 disambiguations, 47037 queries modref clobber: 1473322 disambiguations, 1961464 queries 5027242 tbaa queries (2.563005 per modref query) 649087 base compares (0.330920 per modref query) PTA query stats: pt_solution_includes: 977385 disambiguations, 13609749 queries pt_solutions_intersect: 1032703 disambiguations, 13187507 queries Which should still compare with https://gcc.gnu.org/pipermail/gcc-patches/2020-September/554930.html there is about 2% more load disambiguations and 3.6% more store that is not great, but the TBAA part helps noticeably more and also this should help with -fno-strict-aliasing. I plan to work on improving param tracking too. Bootstrapped/regtested x86_64-linux with the other changes, OK? 2020-10-02 Jan Hubicka <hubicka@ucw.cz> * ipa-modref-tree.c (test_insert_search_collapse): Update andling of accesses. (test_merge): Likewise. * ipa-modref-tree.h (struct modref_access_node): Add offset, size, max_size, parm_offset and parm_offset_known. (modref_access_node::useful_p): Constify. (modref_access_node::range_info_useful_p): New predicate. (modref_access_node::operator==): New. (struct modref_parm_map): New structure. (modref_tree::merge): Update for racking parameters) * ipa-modref.c (dump_access): Dump new fields. (get_access): Fill in new fields. (merge_call_side_effects): Update handling of parm map. (write_modref_records): Stream new fields. (read_modref_records): Stream new fields. (compute_parm_map): Update for new parm map. (ipa_merge_modref_summary_after_inlining): Update. (modref_propagate_in_scc): Update. * tree-ssa-alias.c (modref_may_conflict): Handle known ranges.
2020-10-02Perforate fnspec stringsJan Hubicka1-5/+12
gcc/ChangeLog: 2020-10-02 Jan Hubicka <hubicka@ucw.cz> * attr-fnspec.h: Update documentation. (attr_fnsec::return_desc_size): Set to 2 (attr_fnsec::arg_desc_size): Set to 2 * builtin-attrs.def (STR1): Update fnspec. * internal-fn.def (UBSAN_NULL): Update fnspec. (UBSAN_VPTR): Update fnspec. (UBSAN_PTR): Update fnspec. (ASAN_CHECK): Update fnspec. (GOACC_DIM_SIZE): Remove fnspec. (GOACC_DIM_POS): Remove fnspec. * tree-ssa-alias.c (attr_fnspec::verify): Update verification. gcc/fortran/ChangeLog: 2020-10-02 Jan Hubicka <hubicka@ucw.cz> * trans-decl.c (gfc_build_library_function_decl_with_spec): Verify fnspec. (gfc_build_intrinsic_function_decls): Update fnspecs. (gfc_build_builtin_function_decls): Update fnspecs. * trans-io.c (gfc_build_io_library_fndecls): Update fnspecs. * trans-types.c (create_fn_spec): Update fnspecs.
2020-10-02Commonize handling of attr-fnspecJan Hubicka1-0/+41
* attr-fnspec.h: New file. * calls.c (decl_return_flags): Use attr_fnspec. * gimple.c (gimple_call_arg_flags): Use attr_fnspec. (gimple_call_return_flags): Use attr_fnspec. * tree-into-ssa.c (pass_build_ssa::execute): Use attr_fnspec. * tree-ssa-alias.c (attr_fnspec::verify): New member fuction.
2020-10-02Break out ao_ref_init_from_ptr_and_range from ao_ref_init_from_ptr_and_sizeJan Hubicka1-12/+40
* tree-ssa-alias.c (ao_ref_init_from_ptr_and_range): Break out from ... (ao_ref_init_from_ptr_and_size): ... here.
2020-09-24Add access through parameter derference tracking to modrefJan Hubicka1-24/+51
re-add tracking of accesses which was unfinished in David's patch. At the moment I only implemented tracking of the fact that access is based on derefernece of the parameter (so we track THIS pointers). Patch does not implement IPA propagation since it needs bit more work which I will post shortly: ipa-fnsummary needs to track when parameter points to local memory, summaries needs to be merged when function is inlined (because jump functions are) and propagation needs to be turned into iterative dataflow on SCC components. Patch also adds documentation of -fipa-modref and params that was left uncommited in my branch :(. Even without this change it does lead to nice increase of disambiguations for cc1plus build. Alias oracle query stats: refs_may_alias_p: 62758323 disambiguations, 72935683 queries ref_maybe_used_by_call_p: 139511 disambiguations, 63654045 queries call_may_clobber_ref_p: 23502 disambiguations, 29242 queries nonoverlapping_component_refs_p: 0 disambiguations, 37654 queries nonoverlapping_refs_since_match_p: 19417 disambiguations, 55555 must overlaps, 75721 queries aliasing_component_refs_p: 54665 disambiguations, 752449 queries TBAA oracle: 21917926 disambiguations 53054678 queries 15763411 are in alias set 0 10162238 queries asked about the same object 124 queries asked about the same alias set 0 access volatile 3681593 are dependent in the DAG 1529386 are aritificially in conflict with void * Modref stats: modref use: 8311 disambiguations, 32527 queries modref clobber: 742126 disambiguations, 1036986 queries 1987054 tbaa queries (1.916182 per modref query) 125479 base compares (0.121004 per modref query) PTA query stats: pt_solution_includes: 968314 disambiguations, 13609584 queries pt_solutions_intersect: 1019136 disambiguations, 13147139 queries So compared to https://gcc.gnu.org/pipermail/gcc-patches/2020-September/554605.html we get 41% more use disambiguations (with similar number of queries) and 8% more clobber disambiguations. For tramp3d: Alias oracle query stats: refs_may_alias_p: 2052256 disambiguations, 2312703 queries ref_maybe_used_by_call_p: 7122 disambiguations, 2089118 queries call_may_clobber_ref_p: 234 disambiguations, 234 queries nonoverlapping_component_refs_p: 0 disambiguations, 4299 queries nonoverlapping_refs_since_match_p: 329 disambiguations, 10200 must overlaps, 10616 queries aliasing_component_refs_p: 857 disambiguations, 34555 queries TBAA oracle: 885546 disambiguations 1677080 queries 132105 are in alias set 0 469030 queries asked about the same object 0 queries asked about the same alias set 0 access volatile 190084 are dependent in the DAG 315 are aritificially in conflict with void * Modref stats: modref use: 426 disambiguations, 1881 queries modref clobber: 10042 disambiguations, 16202 queries 19405 tbaa queries (1.197692 per modref query) 2775 base compares (0.171275 per modref query) PTA query stats: pt_solution_includes: 313908 disambiguations, 526183 queries pt_solutions_intersect: 130510 disambiguations, 416084 queries Here uses decrease by 4 disambiguations and clobber improve by 3.5%. I think the difference is caused by fact that gcc has much more alias set 0 accesses originating from gimple and tree unions as I mentioned in original mail. After pushing out the IPA propagation I will re-add code to track offsets and sizes that further improve disambiguation. On tramp3d it enables a lot of DSE for structure fields not acessed by uninlined function. gcc/ * doc/invoke.texi: Document -fipa-modref, ipa-modref-max-bases, ipa-modref-max-refs, ipa-modref-max-accesses, ipa-modref-max-tests. * ipa-modref-tree.c (test_insert_search_collapse): Update. (test_merge): Update. (gt_ggc_mx): New function. * ipa-modref-tree.h (struct modref_access_node): New structure. (struct modref_ref_node): Add every_access and accesses array. (modref_ref_node::modref_ref_node): Update ctor. (modref_ref_node::search): New member function. (modref_ref_node::collapse): New member function. (modref_ref_node::insert_access): New member function. (modref_base_node::insert_ref): Do not collapse base if ref is 0. (modref_base_node::collapse): Copllapse also refs. (modref_tree): Add accesses. (modref_tree::modref_tree): Initialize max_accesses. (modref_tree::insert): Add access parameter. (modref_tree::cleanup): New member function. (modref_tree::merge): Add parm_map; merge accesses. (modref_tree::copy_from): New member function. (modref_tree::create_ggc): Add max_accesses. * ipa-modref.c (dump_access): New function. (dump_records): Dump accesses. (dump_lto_records): Dump accesses. (get_access): New function. (record_access): Record access. (record_access_lto): Record access. (analyze_call): Compute parm_map. (analyze_function): Update construction of modref records. (modref_summaries::duplicate): Likewise; use copy_from. (write_modref_records): Stream accesses. (read_modref_records): Sream accesses. (pass_ipa_modref::execute): Update call of merge. * params.opt (-param=modref-max-accesses): New. * tree-ssa-alias.c (alias_stats): Add modref_baseptr_tests. (dump_alias_stats): Update. (base_may_alias_with_dereference_p): New function. (modref_may_conflict): Check accesses. (ref_maybe_used_by_call_p_1): Update call to modref_may_conflict. (call_may_clobber_ref_p_1): Update call to modref_may_conflict.
2020-09-23Minor modref optimization and statistics fixJan Hubicka1-3/+3
this patch fixes bug in tracking memory stats and also I have noticed that while the pass takes care to stop traking things when things are obviously out of hand it still keeps summaries that have no useful info for loads or stores and also many summaries are just copying const/pure attributes. This patch thus also adds logic to detect if summary is useful and drop it early otherwise. This reduces number of queries to the oracle and saves memory/lto streaming. For cc1plus LTO build (configured with --disable-plugin --enable-checking=release --with-build-config=lto) I now get: Alias oracle query stats: refs_may_alias_p: 62488734 disambiguations, 72660949 queries ref_maybe_used_by_call_p: 128863 disambiguations, 63393551 queries call_may_clobber_ref_p: 16013 disambiguations, 21776 queries nonoverlapping_component_refs_p: 0 disambiguations, 37628 queries nonoverlapping_refs_since_match_p: 19397 disambiguations, 55370 must overlaps, 75516 queries aliasing_component_refs_p: 54741 disambiguations, 752198 queries TBAA oracle: 21632692 disambiguations 52565147 queries 15656420 are in alias set 0 10108172 queries asked about the same object 124 queries asked about the same alias set 0 access volatile 3640460 are dependent in the DAG 1527279 are aritificially in conflict with void * Modref stats: modref use: 5712 disambiguations, 31221 queries modref clobber: 684316 disambiguations, 1010000 queries 1779717 tbaa queries (1.762096 per modref query) PTA query stats: pt_solution_includes: 947334 disambiguations, 13601373 queries pt_solutions_intersect: 1011662 disambiguations, 13139565 queries The number of queries should change, but the number of disambiguations should not. However comparing with stats here https://gcc.gnu.org/pipermail/gcc-patches/2020-September/554309.html I see about 50% drop in clobber disambiguations. There is however same drop in other alias oracle stats. I suppose someting changed in meanwhile on mainline because I was basing that on older tree. I tried to proofread changes between mainline and branch and they seem all quite obvious. This is consistent with what I get on tramp3d: Alias oracle query stats: refs_may_alias_p: 2051320 disambiguations, 2312132 queries ref_maybe_used_by_call_p: 7058 disambiguations, 2088222 queries call_may_clobber_ref_p: 232 disambiguations, 232 queries nonoverlapping_component_refs_p: 0 disambiguations, 4339 queries nonoverlapping_refs_since_match_p: 329 disambiguations, 10200 must overlaps, 10616 queries aliasing_component_refs_p: 857 disambiguations, 34639 queries TBAA oracle: 886768 disambiguations 1670635 queries 131572 are in alias set 0 461689 queries asked about the same object 0 queries asked about the same alias set 0 access volatile 190291 are dependent in the DAG 315 are aritificially in conflict with void * Modref stats: modref use: 430 disambiguations, 1885 queries modref clobber: 9657 disambiguations, 16076 queries 19027 tbaa queries (1.183566 per modref query) PTA query stats: pt_solution_includes: 311756 disambiguations, 524179 queries pt_solutions_intersect: 129689 disambiguations, 415878 queries In both cases the number of disambiguations should be same (queries are not comparable). Bootstrapped/regtested x86_64-linux, comitted. gcc/ChangeLog: 2020-09-23 Jan Hubicka <hubicka@ucw.cz> * ipa-modref.c (modref_summary::lto_useful_p): New member function. (modref_summary::useful_p): New member function. (analyze_function): Drop useless summaries. (modref_write): Skip useless summaries. (pass_ipa_modref::execute): Drop useless summaries. * ipa-modref.h (struct GTY): Declare useful_p and lto_useful_p. * tree-ssa-alias.c (dump_alias_stats): Fix. (modref_may_conflict): Fix stats.
2020-09-20New modref/ipa_modref optimization passesJan Hubicka1-13/+160
2020-09-19 David Cepelik <d@dcepelik.cz> Jan Hubicka <hubicka@ucw.cz> * Makefile.in: Add ipa-modref.c and ipa-modref-tree.c. * alias.c: (reference_alias_ptr_type_1): Export. * alias.h (reference_alias_ptr_type_1): Declare. * common.opt (fipa-modref): New. * gengtype.c (open_base_files): Add ipa-modref-tree.h and ipa-modref.h * ipa-modref-tree.c: New file. * ipa-modref-tree.h: New file. * ipa-modref.c: New file. * ipa-modref.h: New file. * lto-section-in.c (lto_section_name): Add ipa_modref. * lto-streamer.h (enum lto_section_type): Add LTO_section_ipa_modref. * opts.c (default_options_table): Enable ipa-modref at -O1+. * params.opt (-param=modref-max-bases, -param=modref-max-refs, -param=modref-max-tests): New params. * passes.def: Schedule pass_modref and pass_ipa_modref. * timevar.def (TV_IPA_MODREF): New timevar. (TV_TREE_MODREF): New timevar. * tree-pass.h (make_pass_modref): Declare. (make_pass_ipa_modref): Declare. * tree-ssa-alias.c (dump_alias_stats): Include ipa-modref-tree.h and ipa-modref.h (alias_stats): Add modref_use_may_alias, modref_use_no_alias, modref_clobber_may_alias, modref_clobber_no_alias, modref_tests. (dump_alias_stats): Dump new stats. (nonoverlapping_array_refs_p): Fix formating. (modref_may_conflict): New function. (ref_maybe_used_by_call_p_1): Use it. (call_may_clobber_ref_p_1): Use it. (call_may_clobber_ref_p): Update. (stmt_may_clobber_ref_p_1): Update. * tree-ssa-alias.h (call_may_clobber_ref_p_1): Update.
2020-04-15middle-end/94539 - void * aliases every other pointerRichard Biener1-1/+10
This makes same_type_for_tbaa_p conservative in the same way get_alias_set is about void * which we allow to alias all other pointers. 2020-04-15 Richard Biener <rguenther@suse.de> PR middle-end/94539 * tree-ssa-alias.c (same_type_for_tbaa): Defer to alias_sets_conflict_p for pointers. * gcc.dg/alias-14.c: Make dg-do run.
2020-03-03tree-optimization/93946 - fix bogus redundant store removal in FRE, DSE and DOMRichard Biener1-0/+2
This fixes a common mistake in removing a store that looks redudnant but is not because it changes the dynamic type of the memory and thus makes a difference for following loads with TBAA. 2020-03-03 Richard Biener <rguenther@suse.de> PR tree-optimization/93946 * alias.h (refs_same_for_tbaa_p): Declare. * alias.c (refs_same_for_tbaa_p): New function. * tree-ssa-alias.c (ao_ref_alias_set): For a NULL ref return zero. * tree-ssa-scopedtables.h (avail_exprs_stack::lookup_avail_expr): Add output argument giving access to the hashtable entry. * tree-ssa-scopedtables.c (avail_exprs_stack::lookup_avail_expr): Likewise. * tree-ssa-dom.c: Include alias.h. (dom_opt_dom_walker::optimize_stmt): Validate TBAA state before removing redundant store. * tree-ssa-sccvn.h (vn_reference_s::base_set): New member. (ao_ref_init_from_vn_reference): Adjust prototype. (vn_reference_lookup_pieces): Likewise. (vn_reference_insert_pieces): Likewise. * tree-ssa-sccvn.c: Track base alias set in addition to alias set everywhere. (eliminate_dom_walker::eliminate_stmt): Also check base alias set when removing redundant stores. (visit_reference_op_store): Likewise. * dse.c (record_store): Adjust valdity check for redundant store removal. * gcc.dg/torture/pr93946-1.c: New testcase. * gcc.dg/torture/pr93946-2.c: Likewise.
2020-02-27middle-end: Fix wrong code caused by disagreemed between FRE and access path ↵Jan Hubicka1-51/+127
oracle [PR 92152] FRE is checking stores for equivalence based on their address, value and base+ref alias sets. Because ref alias set is not always the alias set of innermost type, but it may be one of refs in the access path (as decided by component_uses_parent_alias_set_from) it means that we can not really rely on the remaining part of access path to be meaningful in any way except for offset+size computation. The patch makes alias (which is used by FRE to validate transform) and tree-ssa-alias to share same logic for ending the access path relevant for TBAA. tree-ssa-alias previously ended access paths on VIEW_CONVERT_EXPR and BIT_FIELD_REF so it is not hard to wire in common predicate. However it led to additional issues (I tried to read the code quite carefully for possible extra fun, so I hope I found it all): 1) alias_component_refs_walk compares base and reference sizes to see if one access path may continue by another. This check can be confused by an union containing structure with zero sized array. In this case we no longer see the refernece to zero sized array and think that ref size is 0. In an access path there can be at most one (valid) trailing/zero sized array access, so the sizes in the access path are decreasing with the this exception. This is already handled by the logic, however the access is not expected to happen past the end of TBAA segment. I suppose this was kind of latent problem before because one can think of access path doing traling array past VIEW_CONVERT_EXPR, but since in C code we don't VCE and in non-C we don't do trailing arrays, we did not hit the problem. I fixed this by tracking if the trailing array references appearing after the end of TBAA access path and mostly punt in the second case (because we need to support kind of all type puning here). I do not think we can assume much of sanity here, in particular, we no longer know there is only one because FRE may mix things up. An exception is the walk that looks for occurence of basetype of path1 within TBAA relevant part of path2. Here we realy care about TBAA relevant parts of paths and thus do not need to give up. I broke out the logic into ends_tbaa_access_path_p to avoid duplication and to let me stick some detailed comments. This became much more complex than I originally imagined (still it is useful to make oracle both faster and more precise). Note that logic in aliasing_component_refs_walk is safe since it works on TBAA relevant segments of paths only. 2) nonoverlapping_refs_since_match_p is using TBAA only in the corner case that the paths got out of sync and re-synchronize of types of same size are found. I thus extended it to whole paths (not only TBAA relevant parts) and track if the TBAA part can be used by counting of number of TBAA relevant res on the stack. I have noticed that in one case we call nonoverlapping_refs_since_match_p before checking for view converting MEM_REFs and in others we check after. I think we want to just disable TBAA part if view convert is in there but still disambiguate. I will do this incrementaly. 3) nonoverlapping_component_refs_p uses TBAA so it needs to punt on end of TBAA path. It deals with no sizes and thus there is not the issue as in 1). I am also attaching one (most probably) valid C++ testcase (by Mark Williams) where we incorrectly disambiguated while the code is valid by the common initial sequence rule. This happens to be fixed by same patch. Here one access goes through union and follows by access path trhough one filed, while other access path start by different field of the union with common initial sequence. This made aliasing_component_refs_p to not find the overlapping type (because there is none) and disambiguate. Now we cut the first access path by the union reference and this makes us to find the path continuation in alias_component_refs_walk. If FRE is ever made more careful about access paths past the fist union reference (I think that would be good idea since unions are quite common in C++ and we throw away quite useful info) then we will need to teach access path oracle about the common initial sequence rule (which, as Mark pointed out, is part of both C and C++ standards). Only argument that can possibly invalidate this testcase is that I do not see that stadnard is clear about the situation where one access path contains the union but other starts after the union. Clearly if both start after the union reference we are right to disambiguate (since there is no union unvolved). If both starts before union then there is common initial sequence and by standard it is defined. This case works on current trunk because aliasing_component_refs_p resorts to base+offset after finding the match. But even that is more or less an accident I would say. I had to xfail three testcases. While alias-access-path ones are artificial and odd, 20030807-7 is derived from gcc and shows that we give up on disambiguations of tree_node union, so this patch disables useful transform in real world code. I am still planning to collect some data on the effect of this change to TBAA, but unless we want to reorganize FRE, I do not think there is better solution. gcc/ChangeLog: 2020-02-26 Jan Hubicka <hubicka@ucw.cz> PR middle-end/92152 * alias.c (ends_tbaa_access_path_p): Break out from ... (component_uses_parent_alias_set_from): ... here. * alias.h (ends_tbaa_access_path_p): Declare. * tree-ssa-alias.c (access_path_may_continue_p): Break out from ...; handle trailing arrays past end of tbaa access path. (aliasing_component_refs_p): ... here; likewise. (nonoverlapping_refs_since_match_p): Track TBAA segment of the access path; disambiguate also past end of it. (nonoverlapping_component_refs_p): Use only TBAA segment of the access path. gcc/testsuite/ChangeLog: 2020-02-26 Jan Hubicka <hubicka@ucw.cz> PR middle-end/92152 * gcc.dg/tree-ssa/alias-access-path-12.c: New testcase. * g++.dg/torture/pr92152.C: New testcase. * gcc.dg/torture/pr92152.c: New testcase. * gcc.dg/tree-ssa/20030807-7.c: xfail. * gcc.dg/tree-ssa/alias-access-path-4.c: xfail one case. * gcc.dg/tree-ssa/alias-access-path-5.c: xfail one case.
2020-02-21tree-optimization: fix access path oracle on mismatched array refs [PR93586]Jan Hubicka1-4/+38
nonoverlapping_array_refs_p is not supposed to give meaningful results when bases of ref1 and ref2 are not same or completely disjoint and here it is called on c[0][j_2][0] and c[0][1] so bases in sence of this functions are "c[0][j_2]" and "c[0]" which do partially overlap. nonoverlapping_array_refs however walks pair of array references and in this case it misses to note the fact that if it walked across first mismatched pair it is no longer safe to compare rest. The reason why it continues matching is because it hopes it will eventually get pair of COMPONENT_REFs from types of same size and use TBAA to conclude that their addresses must be either same or completely disjoint. This patch makes the loop to terminate early but popping all the remaining pairs so walking can continue. We could re-synchronize on arrays of same size with TBAA but this is bit fishy (because we try to support some sort of partial array overlaps) and hard to implement (because of zero sized arrays and VLAs) so I think it is not worth the effort. In addition I notied that the function is not !flag_strict_aliasing safe and added early exits on places we set seen_unmatched_ref_p since later we do not check that in: /* If we skipped array refs on type of different sizes, we can no longer be sure that there are not partial overlaps. */ if (seen_unmatched_ref_p && !operand_equal_p (TYPE_SIZE (type1), TYPE_SIZE (type2), 0)) { ++alias_stats .nonoverlapping_refs_since_match_p_may_alias; } PR tree-optimization/93586 * tree-ssa-alias.c (nonoverlapping_array_refs_p): Finish array walk after mismatched array refs; do not sure type size information to recover from unmatched referneces with !flag_strict_aliasing_p. * gcc.dg/torture/pr93586.c: New testcase.
2020-02-11PR tree-optimization/93683 - ICE on calloc with unused return value in ↵Martin Sebor1-0/+2
ao_ref_init_from_ptr_and_size gcc/testsuite/ChangeLog: PR tree-optimization/93683 * gcc.dg/tree-ssa/ssa-dse-39.c: New test. gcc/ChangeLog: PR tree-optimization/93683 * tree-ssa-alias.c (stmt_kills_ref_p): Avoid using LHS when not set.
2020-02-05Fix up comment typo.Jakub Jelinek1-1/+1
2020-02-05 Jakub Jelinek <jakub@redhat.com> * tree-ssa-alias.c (aliasing_matching_component_refs_p): Fix up function comment typo.
2020-01-01Update copyright years.Jakub Jelinek1-1/+1
From-SVN: r279813
2019-10-24ipa-reference.c (ipa_reference_optimization_summary_d): Rename ↵Jan Hubicka1-6/+10
statics_not_read and statics_not_written to statics_read and... * ipa-reference.c (ipa_reference_optimization_summary_d): Rename statics_not_read and statics_not_written to statics_read and statics_written respectively. (no_module_statics): New static var. (ipa_reference_get_not_read_global): Rename to ... (ipa_reference_get_read_global): ... this. (ipa_reference_get_not_written_global): Rename to ... (ipa_reference_get_written_global): ... this. (dump_static_vars_set_to_file): Dump no_module_statics. (copy_static_var_set): Add for propagation parameter. (ipa_init): Initialize no_module_statics. (ipa_ref_opt_summary_t::duplicate): Update. (ipa_ref_opt_summary_t::remove): Update. (propagate): Update. (write_node_summary_p): Look correctly for bitmap differences. (ipa_reference_write_optimization_summary): Update. (ipa_reference_read_optimization_summary): Update. * ipa-reference.h (ipa_reference_get_not_read_global): Rename to ... (ipa_reference_get_read_global): ... this. (ipa_reference_get_not_written_global): Rename to ... (ipa_reference_get_written_global): ... this. * tree-ssa-alias.c (ref_maybe_used_by_call_p_1): Update. (call_may_clobber_ref_p_1): Update. From-SVN: r277403
2019-10-20tree-ssa-alias.c (nonoverlapping_refs_since_match_p): Do not skip non-zero ↵Jan Hubicka1-6/+22
array accesses. * tree-ssa-alias.c (nonoverlapping_refs_since_match_p): Do not skip non-zero array accesses. * gcc.c-torture/execute/alias-access-path-2.c: New testcase. * gcc.dg/tree-ssa/alias-access-path-11.c: xfail. From-SVN: r277214
2019-10-01tree-ssa-alias.c (nonoverlapping_component_refs_since_match_p): Rename to ...Jan Hubicka1-63/+228
* tree-ssa-alias.c (nonoverlapping_component_refs_since_match_p): Rename to ... (nonoverlapping_refs_since_match_p): ... this; handle also ARRAY_REFs. (alias_stats): Update stats. (dump_alias_stats): Likewise. (cheap_array_ref_low_bound): New function. (aliasing_matching_component_refs_p): Add partial_overlap argument; pass it to nonoverlapping_refs_since_match_p. (aliasing_component_refs_walk): Update call of aliasing_matching_component_refs_p (nonoverlapping_array_refs_p): New function. (decl_refs_may_alias_p, indirect_ref_may_alias_decl_p, indirect_refs_may_alias_p): Update calls of nonoverlapping_refs_since_match_p. * gcc.dg/tree-ssa/alias-access-path-10.c: New testcase. * gcc.dg/tree-ssa/alias-access-path-11.c: New testcase. From-SVN: r276427
2019-09-16re PR tree-optimization/91756 (g++.dg/lto/alias-3 FAILs)Richard Biener1-11/+17
2019-09-16 Richard Biener <rguenther@suse.de> PR tree-optimization/91756 PR tree-optimization/87132 * tree-ssa-alias.h (enum translate_flags): New. (get_continuation_for_phi): Use it instead of simple bool flag. (walk_non_aliased_vuses): Likewise. * tree-ssa-alias.c (maybe_skip_until): Adjust. (get_continuation_for_phi): When looking across backedges only disallow valueization. (walk_non_aliased_vuses): Adjust. * tree-ssa-sccvn.c (vn_reference_lookup_3): Avoid valueization if requested. * gcc.dg/tree-ssa/ssa-fre-81.c: New testcase. From-SVN: r275747
2019-07-15tree-ssa-alias.c (aliasing_component_refs_walk): Initialize same_p to 0.Jan Hubicka1-1/+1
* tree-ssa-alias.c (aliasing_component_refs_walk): Initialize same_p to 0. From-SVN: r273495
2019-07-13tree-ssa-alias.c (component_ref_to_zero_sized_trailing_array_p): Break out ↵Jan Hubicka1-98/+107
from ... * tree-ssa-alias.c (component_ref_to_zero_sized_trailing_array_p): Break out from ... (aliasing_component_refs_walk): Break out from ... (aliasing_component_refs_p): ... here. From-SVN: r273469
2019-07-12tree-ssa-alias.c (same_tmr_indexing_p): Break out from ...Jan Hubicka1-23/+20
* tree-ssa-alias.c (same_tmr_indexing_p): Break out from ... (indirect_refs_may_alias_p): ... here. (nonoverlapping_component_refs_since_match_p): Support also non-trivial mem refs in the access paths. * gcc.dg/tree-ssa/alias-access-path-9.c: New testcase. From-SVN: r273451
2019-07-10tree-ssa-alias.c (nonoverlapping_component_refs_p_1): Break out from ...; ↵Jan Hubicka1-59/+147
work also on duplicated types. * tree-ssa-alias.c (nonoverlapping_component_refs_p_1): Break out from ...; work also on duplicated types. (nonoverlapping_component_refs_since_match): ... here (ncr_type_uid): Break out from ... (ncr_compar): ... here; look for TYPE_UID of canonical type if available. (nonoverlapping_component_refs_p): Use same_type_for_tbaa to match the types and nonoverlapping_component_refs_p_1 to disambiguate. * g++.dg/lto/alias-3_0.C: New file. * g++.dg/lto/alias-3_1.c: New file. From-SVN: r273322
2019-07-05re PR tree-optimization/91091 ([missed optimization] Missing optimization in ↵Richard Biener1-9/+10
unaliased pointers) 2019-07-05 Richard Biener <rguenther@suse.de> PR tree-optimization/91091 * tree-ssa-alias.h (get_continuation_for_phi): Add tbaa_p parameter. (walk_non_aliased_vuses): Likewise. * tree-ssa-alias.c (maybe_skip_until): Pass down tbaa_p. (get_continuation_for_phi): New tbaa_p parameter and pass it down. (walk_non_aliased_vuses): Likewise. * ipa-prop.c (determine_known_aggregate_parts): Adjust. * tree-ssa-pre.c (translate_vuse_through_block): Likewise. * tree-ssa-scopedtables.c (avail_exprs_stack::lookup_avail_expr): Likewise. * tree-ssa-sccvn.c (struct vn_walk_cb_data): Add tbaa_p flag. (adjust_offsets_for_equal_base_address): New function. (vn_reference_lookup_3): Use it to catch more base equivalences. Handle and pass down tbaa_p flag. (vn_reference_lookup_pieces): Adjust. (vn_reference_lookup): Remove alias-set altering, instead pass down false as tbaa_p. * gcc.dg/tree-ssa/pr91091-2.c: New testcase. * gcc.dg/tree-ssa/ssa-fre-70.c: Likewise. * gcc.dg/tree-ssa/ssa-fre-71.c: Likewise. * gcc.dg/tree-ssa/ssa-fre-72.c: Likewise. From-SVN: r273135
2019-07-05tree-ssa-alias.c (alias_stats): Add ↵Jan Hubicka1-10/+27
nonoverlapping_component_refs_since_match_p_must_overlap. * tree-ssa-alias.c (alias_stats): Add nonoverlapping_component_refs_since_match_p_must_overlap. (dump_alias_stats): Print it. (nonoverlapping_component_refs_since_match_p): Add early exit. (nonoverlapping_component_refs_p): Do not account early exit. From-SVN: r273133
2019-07-04tree-ssa-alias.c (nonoverlapping_component_refs_since_match_p): Fix check ↵Jan Hubicka1-6/+2
for match in the ref walk. * tree-ssa-alias.c (nonoverlapping_component_refs_since_match_p): Fix check for match in the ref walk. From-SVN: r273090
2019-07-04tree-ssa-alias.c (decl_refs_may_alias_p): Add size1 and size2 parameters; ↵Jan Hubicka1-8/+46
return early for must-alias. * tree-ssa-alias.c (decl_refs_may_alias_p): Add size1 and size2 parameters; return early for must-alias. (indirect_ref_may_alias_decl_p): Likewise; when establishing outer types match, try nonoverlapping_component_refs if must-alias is not obvious. (indirect_refs_may_alias_p): Likewise. (refs_may_alias_p_2): Likewise. * gcc.dg/tree-ssa/alias-access-path-3.c: New testcase. * gcc.dg/tree-ssa/alias-access-path-8.c: New testcase. From-SVN: r273079
2019-07-02tree-ssa-alias.c (aliasing_component_refs_p): Remove forgotten sanity check.Jan Hubicka1-2/+0
* tree-ssa-alias.c (aliasing_component_refs_p): Remove forgotten sanity check. From-SVN: r272927
2019-07-02tree-ssa-alias.c (nonoverlapping_component_refs_for_decl_p): Rename to ..Jan Hubicka1-97/+162
* tree-ssa-alias.c (nonoverlapping_component_refs_for_decl_p): Rename to .. (nonoverlapping_component_refs_since_match_p): ... this one; handle also non-decl bases; return -1 if search gave up. (alias_stats): Rename nonoverlapping_component_refs_of_decl_p_may_alias, nonoverlapping_component_refs_of_decl_p_no_alias to nonoverlapping_component_refs_since_match_p_may_alias, nonoverlapping_component_refs_since_match_p_no_alias. (dump_alias_stats): Update dumping. (aliasing_matching_component_refs_p): Break out from ...; dispatch to nonoverlapping_component_refs_for_decl_p and nonoverlapping_component_refs_since_match_p. (aliasing_component_refs_p): ... here; call nonoverlapping_component_refs_p in scenarios where we can not precisely determine base match. (decl_refs_may_alias_p): Use nonoverlapping_component_refs_since_match_p. (indirect_ref_may_alias_decl_p): Do not call nonoverlapping_component_refs_p. (indirect_refs_may_alias_p): Likewise. * gcc.dg/tree-ssa/alias-access-path-7.c: New testcase. From-SVN: r272926
2019-06-26re PR tree-optimization/90883 (Generated code is worse if returned struct is ↵Jeff Law1-2/+25
unnamed) PR tree-optimization/90883 * tree-ssa-alias.c (stmt_kills_ref_p): Handle BUILT_IN_CALLOC. * tree-ssa-dse.c: Update various comments to distinguish between dead and redundant stores. (initialize_ao_ref_for_dse): Handle BUILT_IN_CALLOC. (dse_optimize_redundant_stores): New function. (delete_dead_or_redundant_call): Renamed from delete_dead_call. Distinguish between dead and redundant calls in dump output. All callers updated. (delete_dead_or_redundant_assignment): Similarly for assignments. (dse_optimize_stmt): Handle _CHK variants. For statements which store 0 into multiple memory locations, try to prove a subsequent store is redundant. PR tree-optimization/90883 * g++.dg/tree-ssa/pr90883.C: New test. * gcc.dg/tree-ssa/ssa-dse-36.c: New test. From-SVN: r272717
2019-06-25tree-ssa-alias.c (indirect_ref_may_alias_decl_p): Check that base2_alias_set ↵Jan Hubicka1-3/+4
is non-zero before doing TBAA based disambiguation. * tree-ssa-alias.c (indirect_ref_may_alias_decl_p): Check that base2_alias_set is non-zero before doing TBAA based disambiguation. From-SVN: r272639
2019-06-24re PR tree-optimization/90930 (Excessive memory consumption)Richard Biener1-0/+1
2019-06-24 Richard Biener <rguenther@suse.de> PR tree-optimization/90930 PR tree-optimization/90316 * tree-ssa-alias.c (walk_non_aliased_vuses): Add missing decrement of limit. From-SVN: r272621
2019-06-22alias-access-path-6.c: New testcase.Jan Hubicka1-9/+6
* gcc.dg/tree-ssa/alias-access-path-6.c: New testcase. * tree-ssa-alias.c (nonoverlapping_component_refs_p): Do not give up on bitfields; continue searching for different refs appearing later. From-SVN: r272587
2019-06-20tree-ssa-alias.c (aliasing_component_refs_p): Remove ref2_is_decl parameter; ↵Jan Hubicka1-16/+7
it has no use in gimple memory model. * tree-ssa-alias.c (aliasing_component_refs_p): Remove ref2_is_decl parameter; it has no use in gimple memory model. (indirect_ref_may_alias_decl_p): Update. * gcc.c-torture/execute/alias-access-path-1.c: New testcase. From-SVN: r272510
2019-06-17re PR bootstrap/90873 (-Wmaybe-uninitialized warning in ↵Jan Hubicka1-1/+1
gcc/tree-ssa-forwprop.c breaks 32-bit bootstrap) PR bootstrap/90873. * tree-ssa-alias.c (indirect_ref_may_alias_decl_p): Fix TMR index check. From-SVN: r272390
2019-06-17tree-ssa-alias.c (aliasing_component_refs_p): Consider only the access path ↵Jan Hubicka1-17/+22
from base to first VIEW_CONVERT_EXPR or BIT_FIELD_REF. * tree-ssa-alias.c (aliasing_component_refs_p): Consider only the access path from base to first VIEW_CONVERT_EXPR or BIT_FIELD_REF. From-SVN: r272383
2019-06-17tree-ssa-alias.c (nonoverlapping_component_refs_p): Also truncate access ↵Jan Hubicka1-2/+4
path on BIT_FIELD_REFs. * tree-ssa-alias.c (nonoverlapping_component_refs_p): Also truncate access path on BIT_FIELD_REFs. From-SVN: r272380
2019-06-16tree-ssa-alias.c (indirect_ref_may_alias_decl_p, [...]): Revert accidental ↵Jan Hubicka1-9/+6
commits. * tree-ssa-alias.c (indirect_ref_may_alias_decl_p, indirect_refs_may_alias_p): Revert accidental commits. From-SVN: r272358