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

Message ID 20211012074928.GB304296@tucnak
State New
Headers show
Series
  • [committed] openmp: Avoid calling clear_type_padding_in_mask in the common case where there can't be any padding
Related show

Commit Message

Jeff Law via Gcc-patches Oct. 12, 2021, 7:49 a.m.
Hi!

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.

Bootstrapped/regtested on x86_64-linux and i686-linux, committed to trunk.

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.


	Jakub

Patch

--- gcc/gimple-fold.h.jj	2021-04-26 21:49:44.358846211 +0200
+++ gcc/gimple-fold.h	2021-10-11 22:31:03.505270575 +0200
@@ -36,6 +36,7 @@  extern tree maybe_fold_and_comparisons (
 					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 *);
--- gcc/gimple-fold.c.jj	2021-09-27 23:34:56.519266040 +0200
+++ gcc/gimple-fold.c	2021-10-11 22:30:40.734595135 +0200
@@ -4632,7 +4632,7 @@  clear_padding_real_needs_padding_p (tree
 
 /* 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))
--- gcc/c-family/c-omp.c.jj	2021-10-07 23:03:44.070935299 +0200
+++ gcc/c-family/c-omp.c	2021-10-11 22:32:06.586371445 +0200
@@ -381,7 +381,9 @@  c_finish_omp_atomic (location_t loc, enu
 	  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);