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]

[patch] Fix -ftree-loop-distribution (PR tree-optimization/38997)


Hi,

Attached is a patch to fix an ICE that's triggered by
-ftree-loop-distribution.

Consider the attached testcase.

When the loop distributor tries to convert a[i][j] = 0 to a memset, it
tries to come up with the base address for memset as:

  &a[0][0] + (i * 64)

with '+' being a PLUS_EXPR instead of POINTER_PLUS_EXPR.  Later,
build2 becomes unhappy about a pointer addition with PLUS_EXPR and
triggers an ICE.

The patch fixes the problem by using POINTER_PLUS_EXPR instead.  Also,
the second operand of POINTER_PLUS_EXPR must be of sizetype, so I've
put fold_convert there.

Tested on x86_64-pc-linux-gnu.  OK to apply?

p.s.
If I understand correctly, even in stage 3, non-regression bug fixes
for a new pass and port are still accepted.  Is that correct?

Kazu Hirata

2009-01-28  Kazu Hirata  <kazu@codesourcery.com>

	PR tree-optimization/38997
	* tree-loop-distribution.c (generate_memset_zero): Use
	POINTER_PLUS_EXPR for a pointer addition.

2009-01-28  Kazu Hirata  <kazu@codesourcery.com>

	PR tree-optimization/38997
	* gcc.dg/tree-ssa/pr38997.c: New.

Index: gcc/testsuite/gcc.dg/tree-ssa/pr38997.c
===================================================================
--- gcc/testsuite/gcc.dg/tree-ssa/pr38997.c	(revision 0)
+++ gcc/testsuite/gcc.dg/tree-ssa/pr38997.c	(revision 0)
@@ -0,0 +1,16 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -ftree-loop-distribution" } */
+
+int a[8][8];
+int b[8];
+
+void
+foo (int i)
+{
+  int j;
+  for (j = 0; j < 8; j++)
+    {
+      a[i][j] = 0;
+      b[j] = j;
+    }
+}
Index: gcc/tree-loop-distribution.c
===================================================================
--- gcc/tree-loop-distribution.c	(revision 143737)
+++ gcc/tree-loop-distribution.c	(working copy)
@@ -256,10 +256,15 @@ generate_memset_zero (gimple stmt, tree 
   /* Test for a positive stride, iterating over every element.  */
   if (integer_zerop (fold_build2 (MINUS_EXPR, integer_type_node, DR_STEP (dr),
 				  TYPE_SIZE_UNIT (TREE_TYPE (op0)))))
-    addr_base = fold_build2 (PLUS_EXPR, TREE_TYPE (DR_BASE_ADDRESS (dr)),
-			     DR_BASE_ADDRESS (dr), 
-			     size_binop (PLUS_EXPR,
-					 DR_OFFSET (dr), DR_INIT (dr)));
+    {
+      tree offset = fold_convert (sizetype,
+				  size_binop (PLUS_EXPR,
+					      DR_OFFSET (dr),
+					      DR_INIT (dr)));
+      addr_base = fold_build2 (POINTER_PLUS_EXPR,
+			       TREE_TYPE (DR_BASE_ADDRESS (dr)),
+			       DR_BASE_ADDRESS (dr), offset);
+    }
 
   /* Test for a negative stride, iterating over every element.  */
   else if (integer_zerop (fold_build2 (PLUS_EXPR, integer_type_node,


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