gcc/gcc/tree-sra.h
Martin Jambor 1e3312a25a
ICF&SRA: Make ICF and SRA agree on padding
PR 113359 shows that (at least with -fno-strict-aliasing) ICF can
unify two functions which copy an aggregate type of the same size but
then SRA, through its total scalarization, can copy the aggregate by
pieces, skipping paddding, but the padding was not the same in the two
original functions that ICF unified.

This patch enhances SRA with the ability to collect padding
information which then can be compared from within ICF.  Unfortunately
SRA uses OPTION_SET_P when determining its limits, so ICF needs to
switch cfuns at least once to figure it out too.

gcc/ChangeLog:

2024-03-27  Martin Jambor  <mjambor@suse.cz>

	PR ipa/113359
	* ipa-icf-gimple.h (func_checker): New members
	safe_for_total_scalarization_p, m_total_scalarization_limit_known_p
	and m_total_scalarization_limit.
	(func_checker::func_checker): Initialize new member variables.
	* ipa-icf-gimple.cc: Include tree-sra.h.
	(func_checker::func_checker): Initialize new member variables.
	(func_checker::safe_for_total_scalarization_p): New function.
	(func_checker::compare_operand): Use the new function.
	* tree-sra.h (sra_get_max_scalarization_size): Declare.
	(sra_total_scalarization_would_copy_same_data_p): Likewise.
	* tree-sra.cc (prepare_iteration_over_array_elts): New function.
	(class sra_padding_collecting): New.
	(sra_padding_collecting::record_padding): Likewise.
	(scalarizable_type_p): Rename to totally_scalarizable_type_p.  Add
	ability to record padding when requested.
	(totally_scalarize_subtree): Split out gathering information necessary
	to iterate over array elements to prepare_iteration_over_array_elts.
	Fix errornous early exit.
	(analyze_all_variable_accesses): Adjust the call to
	totally_scalarizable_type_p.  Move determining of total scalariation
	size limit...
	(sra_get_max_scalarization_size): ...here.
	(check_ts_and_push_padding_to_vec): New function.
	(sra_total_scalarization_would_copy_same_data_p): Likewise.

gcc/testsuite/ChangeLog:

2024-03-27  Martin Jambor  <mjambor@suse.cz>

	PR ipa/113359
	* gcc.dg/lto/pr113359-1_0.c: New.
	* gcc.dg/lto/pr113359-1_1.c: Likewise.
	* gcc.dg/lto/pr113359-2_0.c: Likewise.
	* gcc.dg/lto/pr113359-2_1.c: Likewise.
	* gcc.dg/lto/pr113359-3_0.c: Likewise.
	* gcc.dg/lto/pr113359-3_1.c: Likewise.
	* gcc.dg/lto/pr113359-4_0.c: Likewise.
	* gcc.dg/lto/pr113359-4_1.c: Likewise.
	* gcc.dg/lto/pr113359-5_0.c: Likewise.
	* gcc.dg/lto/pr113359-5_1.c: Likewise.
2024-04-08 18:54:21 +02:00

34 lines
1.2 KiB
C

/* Scalar Replacement of Aggregates (SRA) converts some structure
references into scalar references, exposing them to the scalar
optimizers.
Copyright (C) 2019-2024 Free Software Foundation, Inc.
This file is part of GCC.
GCC is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation; either version 3, or (at your option) any later
version.
GCC is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with GCC; see the file COPYING3. If not see
<http://www.gnu.org/licenses/>. */
bool type_internals_preclude_sra_p (tree type, const char **msg);
unsigned HOST_WIDE_INT sra_get_max_scalarization_size (void);
bool sra_total_scalarization_would_copy_same_data_p (tree t1, tree t2);
/* Return true iff TYPE is stdarg va_list type (which early SRA and IPA-SRA
should leave alone). */
inline bool
is_va_list_type (tree type)
{
return TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (va_list_type_node);
}