Skip to content
Snippets Groups Projects
Commit 602c6cfc authored by Jan Hubicka's avatar Jan Hubicka
Browse files

Improve handling of memory operands in ipa-icf 2/4

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.
parent a1fdc16d
No related branches found
No related tags found
No related merge requests found
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment