openmp: Avoid calling clear_type_padding_in_mask in the common case where there can't be any padding

We can use the clear_padding_type_may_have_padding_p function, which
is conservative for e.g. RECORD_TYPE/UNION_TYPE, but for the floating and
complex floating types is accurate.  clear_type_padding_in_mask is
more expensive because we need to allocate memory, fill it, call the function
which itself is more expensive and then analyze the memory, so for the
common case of float/double atomics or even long double on most targets
we can avoid that.

2021-10-12  Jakub Jelinek  <jakub@redhat.com>

gcc/
	* gimple-fold.h (clear_padding_type_may_have_padding_p): Declare.
	* gimple-fold.c (clear_padding_type_may_have_padding_p): No longer
	static.
gcc/c-family/
	* c-omp.c (c_finish_omp_atomic): Use
	clear_padding_type_may_have_padding_p.
This commit is contained in:
Jakub Jelinek 2021-10-12 09:37:25 +02:00
parent 4096bf82a0
commit 8e1fe3f779
3 changed files with 5 additions and 2 deletions

View File

@ -381,7 +381,9 @@ c_finish_omp_atomic (location_t loc, enum tree_code code,
bool clear_padding = false;
HOST_WIDE_INT non_padding_start = 0;
HOST_WIDE_INT non_padding_end = 0;
if (BITS_PER_UNIT == 8 && CHAR_BIT == 8)
if (BITS_PER_UNIT == 8
&& CHAR_BIT == 8
&& clear_padding_type_may_have_padding_p (cmptype))
{
HOST_WIDE_INT sz = int_size_in_bytes (cmptype), i;
gcc_assert (sz > 0);

View File

@ -4632,7 +4632,7 @@ clear_padding_real_needs_padding_p (tree type)
/* Return true if TYPE might contain any padding bits. */
static bool
bool
clear_padding_type_may_have_padding_p (tree type)
{
switch (TREE_CODE (type))

View File

@ -36,6 +36,7 @@ extern tree maybe_fold_and_comparisons (tree, enum tree_code, tree, tree,
enum tree_code, tree, tree);
extern tree maybe_fold_or_comparisons (tree, enum tree_code, tree, tree,
enum tree_code, tree, tree);
extern bool clear_padding_type_may_have_padding_p (tree);
extern void clear_type_padding_in_mask (tree, unsigned char *);
extern bool optimize_atomic_compare_exchange_p (gimple *);
extern void fold_builtin_atomic_compare_exchange (gimple_stmt_iterator *);