Commit 9c49362f by Michael Matz Committed by Richard Biener

re PR middle-end/12392 (very long optimized compile)

2016-03-30  Michael Matz  <matz@suse.de>
	Richard Biener  <rguenther@suse.de>

	PR ipa/12392
	* ipa-polymorphic-call.c (struct type_change_info): Change
	speculative to an unsigned allowing to limit the work we do.
	(csftc_abort_walking_p): New inline function..
	(check_stmt_for_type_change): Limit the number of may-defs
	skipped for speculative devirtualization to
	max-speculative-devirt-maydefs.
	* params.def (max-speculative-devirt-maydefs): New param.
	* doc/invoke.texi (--param max-speculative-devirt-maydefs): Document.

Co-Authored-By: Richard Biener <rguenther@suse.de>

From-SVN: r234546
parent ff734e26
2016-03-30 Michael Matz <matz@suse.de>
Richard Biener <rguenther@suse.de>
PR ipa/12392
* ipa-polymorphic-call.c (struct type_change_info): Change
speculative to an unsigned allowing to limit the work we do.
(csftc_abort_walking_p): New inline function..
(check_stmt_for_type_change): Limit the number of may-defs
skipped for speculative devirtualization to
max-speculative-devirt-maydefs.
* params.def (max-speculative-devirt-maydefs): New param.
* doc/invoke.texi (--param max-speculative-devirt-maydefs): Document.
2016-03-30 Mike Stump <mrs@gcc.gnu.org> 2016-03-30 Mike Stump <mrs@gcc.gnu.org>
PR target/63890 PR target/63890
......
...@@ -9601,6 +9601,11 @@ Enable emission of special debug stores within HSA kernels which are ...@@ -9601,6 +9601,11 @@ Enable emission of special debug stores within HSA kernels which are
then read and reported by libgomp plugin. Generation of these stores then read and reported by libgomp plugin. Generation of these stores
is disabled by default, use @option{--param hsa-gen-debug-stores=1} to is disabled by default, use @option{--param hsa-gen-debug-stores=1} to
enable it. enable it.
@item max-speculative-devirt-maydefs
The maximum number of may-defs we analyze when looking for a must-def
specifying the dynamic type of an object that invokes a virtual call
we may be able to devirtualize speculatively.
@end table @end table
@end table @end table
......
...@@ -38,6 +38,7 @@ along with GCC; see the file COPYING3. If not see ...@@ -38,6 +38,7 @@ along with GCC; see the file COPYING3. If not see
#include "tree-dfa.h" #include "tree-dfa.h"
#include "gimple-pretty-print.h" #include "gimple-pretty-print.h"
#include "tree-into-ssa.h" #include "tree-into-ssa.h"
#include "params.h"
/* Return true when TYPE contains an polymorphic type and thus is interesting /* Return true when TYPE contains an polymorphic type and thus is interesting
for devirtualization machinery. */ for devirtualization machinery. */
...@@ -1094,14 +1095,15 @@ struct type_change_info ...@@ -1094,14 +1095,15 @@ struct type_change_info
tree known_current_type; tree known_current_type;
HOST_WIDE_INT known_current_offset; HOST_WIDE_INT known_current_offset;
/* Set to nonzero if we possibly missed some dynamic type changes and we
should consider the set to be speculative. */
unsigned speculative;
/* Set to true if dynamic type change has been detected. */ /* Set to true if dynamic type change has been detected. */
bool type_maybe_changed; bool type_maybe_changed;
/* Set to true if multiple types have been encountered. known_current_type /* Set to true if multiple types have been encountered. known_current_type
must be disregarded in that case. */ must be disregarded in that case. */
bool multiple_types_encountered; bool multiple_types_encountered;
/* Set to true if we possibly missed some dynamic type changes and we should
consider the set to be speculative. */
bool speculative;
bool seen_unanalyzed_store; bool seen_unanalyzed_store;
}; };
...@@ -1338,6 +1340,19 @@ record_known_type (struct type_change_info *tci, tree type, HOST_WIDE_INT offset ...@@ -1338,6 +1340,19 @@ record_known_type (struct type_change_info *tci, tree type, HOST_WIDE_INT offset
tci->type_maybe_changed = true; tci->type_maybe_changed = true;
} }
/* The maximum number of may-defs we visit when looking for a must-def
that changes the dynamic type in check_stmt_for_type_change. Tuned
after the PR12392 testcase which unlimited spends 40% time within
these alias walks and 8% with the following limit. */
static inline bool
csftc_abort_walking_p (unsigned speculative)
{
unsigned max = PARAM_VALUE (PARAM_MAX_SPECULATIVE_DEVIRT_MAYDEFS);
return speculative > max ? true : false;
}
/* Callback of walk_aliased_vdefs and a helper function for /* Callback of walk_aliased_vdefs and a helper function for
detect_type_change to check whether a particular statement may modify detect_type_change to check whether a particular statement may modify
the virtual table pointer, and if possible also determine the new type of the virtual table pointer, and if possible also determine the new type of
...@@ -1384,15 +1399,15 @@ check_stmt_for_type_change (ao_ref *ao ATTRIBUTE_UNUSED, tree vdef, void *data) ...@@ -1384,15 +1399,15 @@ check_stmt_for_type_change (ao_ref *ao ATTRIBUTE_UNUSED, tree vdef, void *data)
&size, &max_size, &reverse); &size, &max_size, &reverse);
if (size != max_size || max_size == -1) if (size != max_size || max_size == -1)
{ {
tci->speculative = true; tci->speculative++;
return false; return csftc_abort_walking_p (tci->speculative);
} }
if (op && TREE_CODE (op) == MEM_REF) if (op && TREE_CODE (op) == MEM_REF)
{ {
if (!tree_fits_shwi_p (TREE_OPERAND (op, 1))) if (!tree_fits_shwi_p (TREE_OPERAND (op, 1)))
{ {
tci->speculative = true; tci->speculative++;
return false; return csftc_abort_walking_p (tci->speculative);
} }
offset += tree_to_shwi (TREE_OPERAND (op, 1)) offset += tree_to_shwi (TREE_OPERAND (op, 1))
* BITS_PER_UNIT; * BITS_PER_UNIT;
...@@ -1402,8 +1417,8 @@ check_stmt_for_type_change (ao_ref *ao ATTRIBUTE_UNUSED, tree vdef, void *data) ...@@ -1402,8 +1417,8 @@ check_stmt_for_type_change (ao_ref *ao ATTRIBUTE_UNUSED, tree vdef, void *data)
; ;
else else
{ {
tci->speculative = true; tci->speculative++;
return false; return csftc_abort_walking_p (tci->speculative);
} }
op = walk_ssa_copies (op); op = walk_ssa_copies (op);
} }
...@@ -1438,8 +1453,8 @@ check_stmt_for_type_change (ao_ref *ao ATTRIBUTE_UNUSED, tree vdef, void *data) ...@@ -1438,8 +1453,8 @@ check_stmt_for_type_change (ao_ref *ao ATTRIBUTE_UNUSED, tree vdef, void *data)
fprintf (dump_file, " Function call may change dynamic type:"); fprintf (dump_file, " Function call may change dynamic type:");
print_gimple_stmt (dump_file, stmt, 0, 0); print_gimple_stmt (dump_file, stmt, 0, 0);
} }
tci->speculative = true; tci->speculative++;
return false; return csftc_abort_walking_p (tci->speculative);
} }
/* Check for inlined virtual table store. */ /* Check for inlined virtual table store. */
else if (noncall_stmt_may_be_vtbl_ptr_store (stmt)) else if (noncall_stmt_may_be_vtbl_ptr_store (stmt))
...@@ -1461,7 +1476,7 @@ check_stmt_for_type_change (ao_ref *ao ATTRIBUTE_UNUSED, tree vdef, void *data) ...@@ -1461,7 +1476,7 @@ check_stmt_for_type_change (ao_ref *ao ATTRIBUTE_UNUSED, tree vdef, void *data)
if (dump_file) if (dump_file)
fprintf (dump_file, " Unanalyzed store may change type.\n"); fprintf (dump_file, " Unanalyzed store may change type.\n");
tci->seen_unanalyzed_store = true; tci->seen_unanalyzed_store = true;
tci->speculative = true; tci->speculative++;
} }
else else
record_known_type (tci, type, offset); record_known_type (tci, type, offset);
...@@ -1646,7 +1661,7 @@ ipa_polymorphic_call_context::get_dynamic_type (tree instance, ...@@ -1646,7 +1661,7 @@ ipa_polymorphic_call_context::get_dynamic_type (tree instance,
tci.otr_type = otr_type; tci.otr_type = otr_type;
tci.type_maybe_changed = false; tci.type_maybe_changed = false;
tci.multiple_types_encountered = false; tci.multiple_types_encountered = false;
tci.speculative = false; tci.speculative = 0;
tci.seen_unanalyzed_store = false; tci.seen_unanalyzed_store = false;
walk_aliased_vdefs (&ao, gimple_vuse (stmt), check_stmt_for_type_change, walk_aliased_vdefs (&ao, gimple_vuse (stmt), check_stmt_for_type_change,
......
...@@ -1203,6 +1203,12 @@ DEFPARAM (PARAM_HSA_GEN_DEBUG_STORES, ...@@ -1203,6 +1203,12 @@ DEFPARAM (PARAM_HSA_GEN_DEBUG_STORES,
"hsa-gen-debug-stores", "hsa-gen-debug-stores",
"Level of hsa debug stores verbosity", "Level of hsa debug stores verbosity",
0, 0, 1) 0, 0, 1)
DEFPARAM (PARAM_MAX_SPECULATIVE_DEVIRT_MAYDEFS,
"max-speculative-devirt-maydefs",
"Maximum number of may-defs visited when devirtualizing "
"speculatively", 50, 0, 0)
/* /*
Local variables: Local variables:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment