This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Fix PR middle-end/35136


> > Hence the fix, bootstrapped/regtested on i586-suse-linux, OK for
> > mainline?
>
> Ok.

Although I still think that the change is the right thing to do, it ends up 
only papering over the problem, which is that IVOPTS takes the address of 
non-addressable objects, leading to wrong code.  More specifically:

&VIEW_CONVERT_EXPR<system__address>((system__aux_dec__TsaB) a_3(D))

There is already a counter-measure for this (may_be_nonaddressable_p) but it 
is both incomplete and invoked too early in find_interesting_uses_address.

Hence this second fix, lightly tested on i586-suse-linux.  Moreover Jakub said 
that he was concerned about changing force_gimple_operand at this point, so 
the patch also reverts the first fix.

OK for mainline if a full testing cycle successfully completes?


	PR middle-end/35136
	* gimplify.c (force_gimple_operand_bsi): Revert 2008-02-12 change.
        (force_gimple_operand): Likewise.
	* tree-ssa-loop-ivopts.c (may_be_nonaddressable_p): Add new cases
	for TARGET_MEM_REF and CONVERT_EXPR/NON_LVALUE_EXPR/NOP_EXPR.
	Also recurse on the operand for regular VIEW_CONVERT_EXPRs.
	(find_interesting_uses_address): Check addressability and alignment
	of the base expression only after substituting bases of IVs into it.


-- 
Eric Botcazou
Index: gimplify.c
===================================================================
--- gimplify.c	(revision 132267)
+++ gimplify.c	(working copy)
@@ -6629,14 +6629,6 @@ force_gimple_operand (tree expr, tree *s
 
   pop_gimplify_context (NULL);
 
-  if (*stmts && gimple_in_ssa_p (cfun))
-    {
-      tree_stmt_iterator tsi;
-
-      for (tsi = tsi_start (*stmts); !tsi_end_p (tsi); tsi_next (&tsi))
-	mark_symbols_for_renaming (tsi_stmt (tsi));
-    }
-
   return expr;
 }
 
@@ -6656,6 +6648,14 @@ force_gimple_operand_bsi (block_stmt_ite
   expr = force_gimple_operand (expr, &stmts, simple_p, var);
   if (stmts)
     {
+      if (gimple_in_ssa_p (cfun))
+	{
+	  tree_stmt_iterator tsi;
+
+	  for (tsi = tsi_start (stmts); !tsi_end_p (tsi); tsi_next (&tsi))
+	    mark_symbols_for_renaming (tsi_stmt (tsi));
+	}
+
       if (before)
 	bsi_insert_before (bsi, stmts, m);
       else
Index: tree-ssa-loop-ivopts.c
===================================================================
--- tree-ssa-loop-ivopts.c	(revision 132243)
+++ tree-ssa-loop-ivopts.c	(working copy)
@@ -1434,21 +1434,34 @@ may_be_nonaddressable_p (tree expr)
 {
   switch (TREE_CODE (expr))
     {
+    case TARGET_MEM_REF:
+      /* TARGET_MEM_REFs are translated directly to valid MEMs on the
+	 target, thus they are always addressable.  */
+      return false;
+
     case COMPONENT_REF:
       return DECL_NONADDRESSABLE_P (TREE_OPERAND (expr, 1))
 	     || may_be_nonaddressable_p (TREE_OPERAND (expr, 0));
 
-    case ARRAY_REF:
-    case ARRAY_RANGE_REF:
-      return may_be_nonaddressable_p (TREE_OPERAND (expr, 0));
-
     case VIEW_CONVERT_EXPR:
       /* This kind of view-conversions may wrap non-addressable objects
 	 and make them look addressable.  After some processing the
 	 non-addressability may be uncovered again, causing ADDR_EXPRs
 	 of inappropriate objects to be built.  */
-      return AGGREGATE_TYPE_P (TREE_TYPE (expr))
-	     && !AGGREGATE_TYPE_P (TREE_TYPE (TREE_OPERAND (expr, 0)));
+      if (AGGREGATE_TYPE_P (TREE_TYPE (expr))
+	  && !AGGREGATE_TYPE_P (TREE_TYPE (TREE_OPERAND (expr, 0))))
+	return true;
+
+      /* ... fall through ... */
+
+    case ARRAY_REF:
+    case ARRAY_RANGE_REF:
+      return may_be_nonaddressable_p (TREE_OPERAND (expr, 0));
+
+    case CONVERT_EXPR:
+    case NON_LVALUE_EXPR:
+    case NOP_EXPR:
+      return true;
 
     default:
       break;
@@ -1476,13 +1489,6 @@ find_interesting_uses_address (struct iv
   if (TREE_CODE (base) == BIT_FIELD_REF)
     goto fail;
 
-  if (may_be_nonaddressable_p (base))
-    goto fail;
-
-  if (STRICT_ALIGNMENT
-      && may_be_unaligned_p (base))
-    goto fail;
-
   base = unshare_expr (base);
 
   if (TREE_CODE (base) == TARGET_MEM_REF)
@@ -1536,6 +1542,16 @@ find_interesting_uses_address (struct iv
       gcc_assert (TREE_CODE (base) != ALIGN_INDIRECT_REF);
       gcc_assert (TREE_CODE (base) != MISALIGNED_INDIRECT_REF);
 
+      /* Check that the base expression is addressable.  This needs
+	 to be done after substituting bases of IVs into it.  */
+      if (may_be_nonaddressable_p (base))
+	goto fail;
+
+      /* Moreover, on strict alignment platforms, check that it is
+	 sufficiently aligned.  */
+      if (STRICT_ALIGNMENT && may_be_unaligned_p (base))
+	goto fail;
+
       base = build_fold_addr_expr (base);
 
       /* Substituting bases of IVs into the base expression might

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]