[2/2] middle-end/112830 - avoid gimplifying non-default addr-space assign to memcpy

Message ID 20231204093538.661DF13588@imap2.dmz-prg2.suse.org
State New
Headers
Series [1/2,RFC] middle-end/112830 - memcpy expansion drops address-spaces |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gcc_build--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_gcc_build--master-arm success Testing passed
linaro-tcwg-bot/tcwg_gcc_check--master-aarch64 success Testing passed

Commit Message

Richard Biener Dec. 4, 2023, 9:35 a.m. UTC
  The following avoids turning aggregate copy or initialization involving
non-default address-spaces to memcpy or memset since they are not
prepared for that.

GIMPLE verification no longer(?) accepts WITH_SIZE_EXPR in aggregate
copies, the following re-allows that.

Sofar untested, will test on x86_64-unknown-linux-gnu.  This is
the variant I prefer.

Richard.

	PR middle-end/112830
	* gimplify.cc (gimplify_modify_expr): Avoid  turning aggregate
	copy or initialization non-default address-spaces to memcpy or
	memset.
	* tree-cfg.cc (verify_gimple_assign_single): Allow
	WITH_SIZE_EXPR as part of the RHS of an assignment.
---
 gcc/gimplify.cc | 11 +++++++----
 gcc/tree-cfg.cc | 16 ++++++++++------
 2 files changed, 17 insertions(+), 10 deletions(-)
  

Patch

diff --git a/gcc/gimplify.cc b/gcc/gimplify.cc
index 02f85e7109b..a1d5ee28cbe 100644
--- a/gcc/gimplify.cc
+++ b/gcc/gimplify.cc
@@ -6331,7 +6331,8 @@  gimplify_modify_expr (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p,
       && TYPE_SIZE_UNIT (TREE_TYPE (*from_p))
       && !poly_int_tree_p (TYPE_SIZE_UNIT (TREE_TYPE (*from_p)))
       && TREE_CODE (*from_p) == CONSTRUCTOR
-      && CONSTRUCTOR_NELTS (*from_p) == 0)
+      && CONSTRUCTOR_NELTS (*from_p) == 0
+      && ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (TREE_TYPE (*to_p))))
     {
       maybe_with_size_expr (from_p);
       gcc_assert (TREE_CODE (*from_p) == WITH_SIZE_EXPR);
@@ -6464,10 +6465,12 @@  gimplify_modify_expr (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p,
       tree from = TREE_OPERAND (*from_p, 0);
       tree size = TREE_OPERAND (*from_p, 1);
 
-      if (TREE_CODE (from) == CONSTRUCTOR)
+      if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (TREE_TYPE (*to_p)))
+	  || !ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (TREE_TYPE (from))))
+	;
+      else if (TREE_CODE (from) == CONSTRUCTOR)
 	return gimplify_modify_expr_to_memset (expr_p, size, want_value, pre_p);
-
-      if (is_gimple_addressable (from))
+      else if (is_gimple_addressable (from))
 	{
 	  *from_p = from;
 	  return gimplify_modify_expr_to_memcpy (expr_p, size, want_value,
diff --git a/gcc/tree-cfg.cc b/gcc/tree-cfg.cc
index a30a2de33a1..3917bee5a92 100644
--- a/gcc/tree-cfg.cc
+++ b/gcc/tree-cfg.cc
@@ -4673,6 +4673,16 @@  verify_gimple_assign_single (gassign *stmt)
       error ("%qs in gimple IL", code_name);
       return true;
 
+    case WITH_SIZE_EXPR:
+      if (!is_gimple_val (TREE_OPERAND (rhs1, 1)))
+	{
+	  error ("invalid WITH_SIZE_EXPR size argument in load");
+	  debug_generic_stmt (lhs);
+	  debug_generic_stmt (rhs1);
+	  return true;
+	}
+      rhs1 = TREE_OPERAND (rhs1, 0);
+      /* Fallthru.  */
     case COMPONENT_REF:
     case BIT_FIELD_REF:
     case ARRAY_REF:
@@ -4810,12 +4820,6 @@  verify_gimple_assign_single (gassign *stmt)
 	}
       return res;
 
-    case WITH_SIZE_EXPR:
-      error ("%qs RHS in assignment statement",
-	     get_tree_code_name (rhs_code));
-      debug_generic_expr (rhs1);
-      return true;
-
     case OBJ_TYPE_REF:
       /* FIXME.  */
       return res;