public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Fix PR34123: ICE in loop interchange
@ 2007-12-16  8:56 Sebastian Pop
  2007-12-18 19:45 ` Daniel Berlin
  0 siblings, 1 reply; 3+ messages in thread
From: Sebastian Pop @ 2007-12-16  8:56 UTC (permalink / raw)
  To: GCC Patches, Daniel Berlin

[-- Attachment #1: Type: text/plain, Size: 2109 bytes --]

No regressions with this patch, but still the ltrans-7.f90 fails.
I will investigate this tomorrow.  Okay for the attached patch?

Sebastian

---------- Forwarded message ----------
From:  <spop@gcc12.fsffrance.org>
Date: Dec 15, 2007 9:37 PM
Subject: [regtest] Results for 859_pr34123.diff on x86_64-unknown-linux-gnu
To: sebpop@gmail.com


Checker: (2007_12_16_03_37_21): (cat /home/spop/state/testing/patched/report
there are no regressions with your patch.
Checker: (2007_12_16_03_37_21): tac)
Checker: (2007_12_16_03_37_21): FAILs with patched version:
Checker: (2007_12_16_03_37_21): (cat /home/spop/state/testing/patched/failed
gcc.sum gcc.dg/torture/builtin-pow-mpfr-1.c
gcc.sum gcc.dg/tree-prof/bb-reorg.c
gfortran.sum gfortran.dg/ltrans-7.f90
libmudflap.sum libmudflap.c++/fail24-frag.cxx
libmudflap.sum libmudflap.c++/pass27-frag.cxx
libmudflap.sum libmudflap.c++/pass28-frag.cxx
libmudflap.sum libmudflap.c++/pass31-frag.cxx
libmudflap.sum libmudflap.c++/pass41-frag.cxx
libmudflap.sum libmudflap.c++/pass55-frag.cxx
libmudflap.sum libmudflap.c++/pass57-frag.cxx
libstdc++.sum 22_locale/global_templates/standard_facet_hierarchies.cc
libstdc++.sum abi_check
Checker: (2007_12_16_03_37_21): tac)
Checker: (2007_12_16_03_37_21): FAILs with pristine version:
Checker: (2007_12_16_03_37_21): (cat /home/spop/state/trunk/130976/failed
gcc.sum gcc.dg/torture/builtin-pow-mpfr-1.c
gcc.sum gcc.dg/tree-prof/bb-reorg.c
gfortran.sum gfortran.dg/ltrans-7.f90
libmudflap.sum libmudflap.c++/fail24-frag.cxx
libmudflap.sum libmudflap.c++/pass27-frag.cxx
libmudflap.sum libmudflap.c++/pass28-frag.cxx
libmudflap.sum libmudflap.c++/pass31-frag.cxx
libmudflap.sum libmudflap.c++/pass41-frag.cxx
libmudflap.sum libmudflap.c++/pass55-frag.cxx
libmudflap.sum libmudflap.c++/pass57-frag.cxx
libstdc++.sum 22_locale/global_templates/standard_facet_hierarchies.cc
libstdc++.sum abi_check
Checker: (2007_12_16_03_37_21): tac)
Checker: (2007_12_16_03_37_21): The files used for the validation of
your patch are stored in /home/spop/state/patched/2007_12_16_03_37_21
on the tester machine.



-- 
Sebastian
AMD - GNU Tools

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 859_pr34123.diff --]
[-- Type: text/x-diff; name=859_pr34123.diff, Size: 8877 bytes --]

2007-12-15  Sebastian Pop  <sebastian.pop@amd.com>

	* lambda-code.c (can_duplicate_iv): New.
	(cannot_convert_modify_to_perfect_nest): New.
	(cannot_convert_bb_to_perfect_nest): New.
	(can_convert_to_perfect_nest): Split up.

email:sebpop@gmail.com
branch:trunk
revision:HEAD
configure:
make:
check:

Index: testsuite/gcc.dg/tree-ssa/pr34123.c
===================================================================
--- testsuite/gcc.dg/tree-ssa/pr34123.c	(revision 0)
+++ testsuite/gcc.dg/tree-ssa/pr34123.c	(revision 0)
@@ -0,0 +1,18 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -ftree-loop-linear" } */
+
+/* Testcase by Martin Michlmayr <tbm@cyrius.com> */
+
+static unsigned char sbox[256] = {
+};
+void MD2Transform (unsigned char state[16])
+{
+  unsigned char t = 0;
+  int i, j;
+  for (i = 0; i < 16; i++)
+    {
+      for (j = 0; j < 2; j++)
+        t = (state[j] ^= sbox[t]);
+      t += i;
+    }
+}
Index: lambda-code.c
===================================================================
--- lambda-code.c	(revision 130956)
+++ lambda-code.c	(working copy)
@@ -2177,7 +2177,128 @@ can_put_after_inner_loop (struct loop *l
   return true;
 }
 
+/* Return true when the induction variable IV is simple enough to be
+   re-synthesized.  */
 
+static bool
+can_duplicate_iv (tree iv, struct loop *loop)
+{
+  tree scev = instantiate_parameters
+    (loop, analyze_scalar_evolution (loop, iv));
+
+  if (!automatically_generated_chrec_p (scev))
+    {
+      tree step = evolution_part_in_loop_num (scev, loop->num);
+
+      if (step && step != chrec_dont_know && TREE_CODE (step) == INTEGER_CST)
+	return true;
+    }
+
+  return false;
+}
+
+/* If this is a scalar operation that can be put back into the inner
+   loop, or after the inner loop, through copying, then do so. This
+   works on the theory that any amount of scalar code we have to
+   reduplicate into or after the loops is less expensive that the win
+   we get from rearranging the memory walk the loop is doing so that
+   it has better cache behavior.  */
+
+static bool
+cannot_convert_modify_to_perfect_nest (tree stmt, struct loop *loop)
+{
+  
+  use_operand_p use_a, use_b;
+  imm_use_iterator imm_iter;
+  ssa_op_iter op_iter, op_iter1;
+  tree op0 = GIMPLE_STMT_OPERAND (stmt, 0);
+
+  /* The statement should not define a variable used in the inner
+     loop.  */
+  if (TREE_CODE (op0) == SSA_NAME
+      && !can_duplicate_iv (op0, loop))
+    FOR_EACH_IMM_USE_FAST (use_a, imm_iter, op0)
+      if (bb_for_stmt (USE_STMT (use_a))->loop_father
+	  == loop->inner)
+	return true;
+
+  FOR_EACH_SSA_USE_OPERAND (use_a, stmt, op_iter, SSA_OP_USE)
+    {
+      tree node, op = USE_FROM_PTR (use_a);
+
+      /* The variables should not be used in both loops.  */
+      if (!can_duplicate_iv (op, loop))
+	FOR_EACH_IMM_USE_FAST (use_b, imm_iter, op)
+	  if (bb_for_stmt (USE_STMT (use_b))->loop_father
+	      == loop->inner)
+	    return true;
+
+      /* The statement should not use the value of a scalar that was
+	 modified in the loop.  */
+      node = SSA_NAME_DEF_STMT (op);
+      if (TREE_CODE (node) == PHI_NODE)
+	FOR_EACH_PHI_ARG (use_b, node, op_iter1, SSA_OP_USE)
+	{
+	  tree arg = USE_FROM_PTR (use_b);
+
+	  if (TREE_CODE (arg) == SSA_NAME)
+	    {
+	      tree arg_stmt = SSA_NAME_DEF_STMT (arg);
+
+	      if (bb_for_stmt (arg_stmt)
+		  && (bb_for_stmt (arg_stmt)->loop_father
+		      == loop->inner))
+		return true;
+	    }
+	}
+    }
+
+  return false;
+}
+
+/* Return true when BB contains statements that can harm the transform
+   to a perfect loop nest.  */
+
+static bool
+cannot_convert_bb_to_perfect_nest (basic_block bb, struct loop *loop)
+{
+  block_stmt_iterator bsi;
+  tree exit_condition = get_loop_exit_condition (loop);
+
+  for (bsi = bsi_start (bb); !bsi_end_p (bsi); bsi_next (&bsi))
+    { 
+      tree stmt = bsi_stmt (bsi);
+
+      if (stmt == exit_condition
+	  || not_interesting_stmt (stmt)
+	  || stmt_is_bumper_for_loop (loop, stmt))
+	continue;
+
+      if (TREE_CODE (stmt) == GIMPLE_MODIFY_STMT)
+	{
+	  if (cannot_convert_modify_to_perfect_nest (stmt, loop))
+	    return true;
+
+	  if (can_duplicate_iv (GIMPLE_STMT_OPERAND (stmt, 0), loop))
+	    continue;
+
+	  if (can_put_in_inner_loop (loop->inner, stmt)
+	      || can_put_after_inner_loop (loop, stmt))
+	    continue;
+	}
+
+      /* If the bb of a statement we care about isn't dominated by the
+	 header of the inner loop, then we can't handle this case
+	 right now.  This test ensures that the statement comes
+	 completely *after* the inner loop.  */
+      if (!dominated_by_p (CDI_DOMINATORS,
+			   bb_for_stmt (stmt), 
+			   loop->inner->header))
+	return true;
+    }
+
+  return false;
+}
 
 /* Return TRUE if LOOP is an imperfect nest that we can convert to a
    perfect one.  At the moment, we only handle imperfect nests of
@@ -2187,117 +2308,22 @@ static bool
 can_convert_to_perfect_nest (struct loop *loop)
 {
   basic_block *bbs;
-  tree exit_condition, phi;
+  tree phi;
   size_t i;
-  block_stmt_iterator bsi;
-  basic_block exitdest;
 
   /* Can't handle triply nested+ loops yet.  */
   if (!loop->inner || loop->inner->inner)
     return false;
   
   bbs = get_loop_body (loop);
-  exit_condition = get_loop_exit_condition (loop);
   for (i = 0; i < loop->num_nodes; i++)
-    {
-      if (bbs[i]->loop_father == loop)
-	{
-	  for (bsi = bsi_start (bbs[i]); !bsi_end_p (bsi); bsi_next (&bsi))
-	    { 
-	      tree stmt = bsi_stmt (bsi);
-
-	      if (stmt == exit_condition
-		  || not_interesting_stmt (stmt)
-		  || stmt_is_bumper_for_loop (loop, stmt))
-		continue;
-
-	      /* If this is a scalar operation that can be put back
-	         into the inner loop, or after the inner loop, through
-		 copying, then do so. This works on the theory that
-		 any amount of scalar code we have to reduplicate
-		 into or after the loops is less expensive that the
-		 win we get from rearranging the memory walk
-		 the loop is doing so that it has better
-		 cache behavior.  */
-	      if (TREE_CODE (stmt) == GIMPLE_MODIFY_STMT)
-		{
-		  use_operand_p use_a, use_b;
-		  imm_use_iterator imm_iter;
-		  ssa_op_iter op_iter, op_iter1;
-		  tree op0 = GIMPLE_STMT_OPERAND (stmt, 0);
-		  tree scev = instantiate_parameters
-		    (loop, analyze_scalar_evolution (loop, op0));
-
-		  /* If the IV is simple, it can be duplicated.  */
-		  if (!automatically_generated_chrec_p (scev))
-		    {
-		      tree step = evolution_part_in_loop_num (scev, loop->num);
-		      if (step && step != chrec_dont_know 
-			  && TREE_CODE (step) == INTEGER_CST)
-			continue;
-		    }
-
-		  /* The statement should not define a variable used
-		     in the inner loop.  */
-		  if (TREE_CODE (op0) == SSA_NAME)
-		    FOR_EACH_IMM_USE_FAST (use_a, imm_iter, op0)
-		      if (bb_for_stmt (USE_STMT (use_a))->loop_father
-			  == loop->inner)
-			goto fail;
-
-		  FOR_EACH_SSA_USE_OPERAND (use_a, stmt, op_iter, SSA_OP_USE)
-		    {
-		      tree node, op = USE_FROM_PTR (use_a);
-
-		      /* The variables should not be used in both loops.  */
-		      FOR_EACH_IMM_USE_FAST (use_b, imm_iter, op)
-		      if (bb_for_stmt (USE_STMT (use_b))->loop_father
-			  == loop->inner)
-			goto fail;
-
-		      /* The statement should not use the value of a
-			 scalar that was modified in the loop.  */
-		      node = SSA_NAME_DEF_STMT (op);
-		      if (TREE_CODE (node) == PHI_NODE)
-			FOR_EACH_PHI_ARG (use_b, node, op_iter1, SSA_OP_USE)
-			  {
-			    tree arg = USE_FROM_PTR (use_b);
-
-			    if (TREE_CODE (arg) == SSA_NAME)
-			      {
-				tree arg_stmt = SSA_NAME_DEF_STMT (arg);
-
-				if (bb_for_stmt (arg_stmt)
-				    && (bb_for_stmt (arg_stmt)->loop_father
-					== loop->inner))
-				  goto fail;
-			      }
-			  }
-		    }
-
-		  if (can_put_in_inner_loop (loop->inner, stmt)
-		      || can_put_after_inner_loop (loop, stmt))
-		    continue;
-		}
-
-	      /* Otherwise, if the bb of a statement we care about isn't
-		 dominated by the header of the inner loop, then we can't
-		 handle this case right now.  This test ensures that the
-		 statement comes completely *after* the inner loop.  */
-	      if (!dominated_by_p (CDI_DOMINATORS,
-				   bb_for_stmt (stmt), 
-				   loop->inner->header))
-		goto fail;
-	    }
-	}
-    }
+    if (bbs[i]->loop_father == loop
+	&& cannot_convert_bb_to_perfect_nest (bbs[i], loop))
+      goto fail;
 
   /* We also need to make sure the loop exit only has simple copy phis in it,
-     otherwise we don't know how to transform it into a perfect nest right
-     now.  */
-  exitdest = single_exit (loop)->dest;
-  
-  for (phi = phi_nodes (exitdest); phi; phi = PHI_CHAIN (phi))
+     otherwise we don't know how to transform it into a perfect nest.  */
+  for (phi = phi_nodes (single_exit (loop)->dest); phi; phi = PHI_CHAIN (phi))
     if (PHI_NUM_ARGS (phi) != 1)
       goto fail;
   

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] Fix PR34123: ICE in loop interchange
  2007-12-16  8:56 [PATCH] Fix PR34123: ICE in loop interchange Sebastian Pop
@ 2007-12-18 19:45 ` Daniel Berlin
  0 siblings, 0 replies; 3+ messages in thread
From: Daniel Berlin @ 2007-12-18 19:45 UTC (permalink / raw)
  To: Sebastian Pop; +Cc: GCC Patches

Okay

On 12/16/07, Sebastian Pop <sebpop@gmail.com> wrote:
> No regressions with this patch, but still the ltrans-7.f90 fails.
> I will investigate this tomorrow.  Okay for the attached patch?
>
> Sebastian
>
> ---------- Forwarded message ----------
> From:  <spop@gcc12.fsffrance.org>
> Date: Dec 15, 2007 9:37 PM
> Subject: [regtest] Results for 859_pr34123.diff on x86_64-unknown-linux-gnu
> To: sebpop@gmail.com
>
>
> Checker: (2007_12_16_03_37_21): (cat /home/spop/state/testing/patched/report
> there are no regressions with your patch.
> Checker: (2007_12_16_03_37_21): tac)
> Checker: (2007_12_16_03_37_21): FAILs with patched version:
> Checker: (2007_12_16_03_37_21): (cat /home/spop/state/testing/patched/failed
> gcc.sum gcc.dg/torture/builtin-pow-mpfr-1.c
> gcc.sum gcc.dg/tree-prof/bb-reorg.c
> gfortran.sum gfortran.dg/ltrans-7.f90
> libmudflap.sum libmudflap.c++/fail24-frag.cxx
> libmudflap.sum libmudflap.c++/pass27-frag.cxx
> libmudflap.sum libmudflap.c++/pass28-frag.cxx
> libmudflap.sum libmudflap.c++/pass31-frag.cxx
> libmudflap.sum libmudflap.c++/pass41-frag.cxx
> libmudflap.sum libmudflap.c++/pass55-frag.cxx
> libmudflap.sum libmudflap.c++/pass57-frag.cxx
> libstdc++.sum 22_locale/global_templates/standard_facet_hierarchies.cc
> libstdc++.sum abi_check
> Checker: (2007_12_16_03_37_21): tac)
> Checker: (2007_12_16_03_37_21): FAILs with pristine version:
> Checker: (2007_12_16_03_37_21): (cat /home/spop/state/trunk/130976/failed
> gcc.sum gcc.dg/torture/builtin-pow-mpfr-1.c
> gcc.sum gcc.dg/tree-prof/bb-reorg.c
> gfortran.sum gfortran.dg/ltrans-7.f90
> libmudflap.sum libmudflap.c++/fail24-frag.cxx
> libmudflap.sum libmudflap.c++/pass27-frag.cxx
> libmudflap.sum libmudflap.c++/pass28-frag.cxx
> libmudflap.sum libmudflap.c++/pass31-frag.cxx
> libmudflap.sum libmudflap.c++/pass41-frag.cxx
> libmudflap.sum libmudflap.c++/pass55-frag.cxx
> libmudflap.sum libmudflap.c++/pass57-frag.cxx
> libstdc++.sum 22_locale/global_templates/standard_facet_hierarchies.cc
> libstdc++.sum abi_check
> Checker: (2007_12_16_03_37_21): tac)
> Checker: (2007_12_16_03_37_21): The files used for the validation of
> your patch are stored in /home/spop/state/patched/2007_12_16_03_37_21
> on the tester machine.
>
>
>
> --
> Sebastian
> AMD - GNU Tools
>
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH] Fix PR34123: ICE in loop interchange
@ 2007-12-15 21:58 Sebastian Pop
  0 siblings, 0 replies; 3+ messages in thread
From: Sebastian Pop @ 2007-12-15 21:58 UTC (permalink / raw)
  To: GCC Patches

[-- Attachment #1: Type: text/plain, Size: 342 bytes --]

Hi,

I've cleaned up a little bit the code in lambda-code.c by splitting
the complex logic in can_convert_to_perfect_nest into several
smaller functions that are now documented properly.
On i686-linux it passed the tree-ssa.exp and ltrans-7.f90
I'm going to regstrap this on amd64-linux.  Okay for trunk after?

Sebastian
-- 
AMD - GNU Tools

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 859_pr34123.diff --]
[-- Type: text/x-diff; name=859_pr34123.diff, Size: 8802 bytes --]

2007-12-15  Sebastian Pop  <sebastian.pop@amd.com>

	* lambda-code.c (can_duplicate_iv): New.
	(cannot_convert_modify_to_perfect_nest): New.
	(cannot_convert_bb_to_perfect_nest): New.
	(can_convert_to_perfect_nest): Split up.

Index: testsuite/gcc.dg/tree-ssa/pr34123.c
===================================================================
--- testsuite/gcc.dg/tree-ssa/pr34123.c	(revision 0)
+++ testsuite/gcc.dg/tree-ssa/pr34123.c	(revision 0)
@@ -0,0 +1,18 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -ftree-loop-linear" } */
+
+/* Testcase by Martin Michlmayr <tbm@cyrius.com> */
+
+static unsigned char sbox[256] = {
+};
+void MD2Transform (unsigned char state[16])
+{
+  unsigned char t = 0;
+  int i, j;
+  for (i = 0; i < 16; i++)
+    {
+      for (j = 0; j < 2; j++)
+        t = (state[j] ^= sbox[t]);
+      t += i;
+    }
+}
Index: lambda-code.c
===================================================================
--- lambda-code.c	(revision 130956)
+++ lambda-code.c	(working copy)
@@ -2177,7 +2177,128 @@ can_put_after_inner_loop (struct loop *l
   return true;
 }
 
+/* Return true when the induction variable IV is simple enough to be
+   re-synthesized.  */
 
+static bool
+can_duplicate_iv (tree iv, struct loop *loop)
+{
+  tree scev = instantiate_parameters
+    (loop, analyze_scalar_evolution (loop, iv));
+
+  if (!automatically_generated_chrec_p (scev))
+    {
+      tree step = evolution_part_in_loop_num (scev, loop->num);
+
+      if (step && step != chrec_dont_know && TREE_CODE (step) == INTEGER_CST)
+	return true;
+    }
+
+  return false;
+}
+
+/* If this is a scalar operation that can be put back into the inner
+   loop, or after the inner loop, through copying, then do so. This
+   works on the theory that any amount of scalar code we have to
+   reduplicate into or after the loops is less expensive that the win
+   we get from rearranging the memory walk the loop is doing so that
+   it has better cache behavior.  */
+
+static bool
+cannot_convert_modify_to_perfect_nest (tree stmt, struct loop *loop)
+{
+  
+  use_operand_p use_a, use_b;
+  imm_use_iterator imm_iter;
+  ssa_op_iter op_iter, op_iter1;
+  tree op0 = GIMPLE_STMT_OPERAND (stmt, 0);
+
+  /* The statement should not define a variable used in the inner
+     loop.  */
+  if (TREE_CODE (op0) == SSA_NAME
+      && !can_duplicate_iv (op0, loop))
+    FOR_EACH_IMM_USE_FAST (use_a, imm_iter, op0)
+      if (bb_for_stmt (USE_STMT (use_a))->loop_father
+	  == loop->inner)
+	return true;
+
+  FOR_EACH_SSA_USE_OPERAND (use_a, stmt, op_iter, SSA_OP_USE)
+    {
+      tree node, op = USE_FROM_PTR (use_a);
+
+      /* The variables should not be used in both loops.  */
+      if (!can_duplicate_iv (op, loop))
+	FOR_EACH_IMM_USE_FAST (use_b, imm_iter, op)
+	  if (bb_for_stmt (USE_STMT (use_b))->loop_father
+	      == loop->inner)
+	    return true;
+
+      /* The statement should not use the value of a scalar that was
+	 modified in the loop.  */
+      node = SSA_NAME_DEF_STMT (op);
+      if (TREE_CODE (node) == PHI_NODE)
+	FOR_EACH_PHI_ARG (use_b, node, op_iter1, SSA_OP_USE)
+	{
+	  tree arg = USE_FROM_PTR (use_b);
+
+	  if (TREE_CODE (arg) == SSA_NAME)
+	    {
+	      tree arg_stmt = SSA_NAME_DEF_STMT (arg);
+
+	      if (bb_for_stmt (arg_stmt)
+		  && (bb_for_stmt (arg_stmt)->loop_father
+		      == loop->inner))
+		return true;
+	    }
+	}
+    }
+
+  return false;
+}
+
+/* Return true when BB contains statements that can harm the transform
+   to a perfect loop nest.  */
+
+static bool
+cannot_convert_bb_to_perfect_nest (basic_block bb, struct loop *loop)
+{
+  block_stmt_iterator bsi;
+  tree exit_condition = get_loop_exit_condition (loop);
+
+  for (bsi = bsi_start (bb); !bsi_end_p (bsi); bsi_next (&bsi))
+    { 
+      tree stmt = bsi_stmt (bsi);
+
+      if (stmt == exit_condition
+	  || not_interesting_stmt (stmt)
+	  || stmt_is_bumper_for_loop (loop, stmt))
+	continue;
+
+      if (TREE_CODE (stmt) == GIMPLE_MODIFY_STMT)
+	{
+	  if (cannot_convert_modify_to_perfect_nest (stmt, loop))
+	    return true;
+
+	  if (can_duplicate_iv (GIMPLE_STMT_OPERAND (stmt, 0), loop))
+	    continue;
+
+	  if (can_put_in_inner_loop (loop->inner, stmt)
+	      || can_put_after_inner_loop (loop, stmt))
+	    continue;
+	}
+
+      /* If the bb of a statement we care about isn't dominated by the
+	 header of the inner loop, then we can't handle this case
+	 right now.  This test ensures that the statement comes
+	 completely *after* the inner loop.  */
+      if (!dominated_by_p (CDI_DOMINATORS,
+			   bb_for_stmt (stmt), 
+			   loop->inner->header))
+	return true;
+    }
+
+  return false;
+}
 
 /* Return TRUE if LOOP is an imperfect nest that we can convert to a
    perfect one.  At the moment, we only handle imperfect nests of
@@ -2187,117 +2308,22 @@ static bool
 can_convert_to_perfect_nest (struct loop *loop)
 {
   basic_block *bbs;
-  tree exit_condition, phi;
+  tree phi;
   size_t i;
-  block_stmt_iterator bsi;
-  basic_block exitdest;
 
   /* Can't handle triply nested+ loops yet.  */
   if (!loop->inner || loop->inner->inner)
     return false;
   
   bbs = get_loop_body (loop);
-  exit_condition = get_loop_exit_condition (loop);
   for (i = 0; i < loop->num_nodes; i++)
-    {
-      if (bbs[i]->loop_father == loop)
-	{
-	  for (bsi = bsi_start (bbs[i]); !bsi_end_p (bsi); bsi_next (&bsi))
-	    { 
-	      tree stmt = bsi_stmt (bsi);
-
-	      if (stmt == exit_condition
-		  || not_interesting_stmt (stmt)
-		  || stmt_is_bumper_for_loop (loop, stmt))
-		continue;
-
-	      /* If this is a scalar operation that can be put back
-	         into the inner loop, or after the inner loop, through
-		 copying, then do so. This works on the theory that
-		 any amount of scalar code we have to reduplicate
-		 into or after the loops is less expensive that the
-		 win we get from rearranging the memory walk
-		 the loop is doing so that it has better
-		 cache behavior.  */
-	      if (TREE_CODE (stmt) == GIMPLE_MODIFY_STMT)
-		{
-		  use_operand_p use_a, use_b;
-		  imm_use_iterator imm_iter;
-		  ssa_op_iter op_iter, op_iter1;
-		  tree op0 = GIMPLE_STMT_OPERAND (stmt, 0);
-		  tree scev = instantiate_parameters
-		    (loop, analyze_scalar_evolution (loop, op0));
-
-		  /* If the IV is simple, it can be duplicated.  */
-		  if (!automatically_generated_chrec_p (scev))
-		    {
-		      tree step = evolution_part_in_loop_num (scev, loop->num);
-		      if (step && step != chrec_dont_know 
-			  && TREE_CODE (step) == INTEGER_CST)
-			continue;
-		    }
-
-		  /* The statement should not define a variable used
-		     in the inner loop.  */
-		  if (TREE_CODE (op0) == SSA_NAME)
-		    FOR_EACH_IMM_USE_FAST (use_a, imm_iter, op0)
-		      if (bb_for_stmt (USE_STMT (use_a))->loop_father
-			  == loop->inner)
-			goto fail;
-
-		  FOR_EACH_SSA_USE_OPERAND (use_a, stmt, op_iter, SSA_OP_USE)
-		    {
-		      tree node, op = USE_FROM_PTR (use_a);
-
-		      /* The variables should not be used in both loops.  */
-		      FOR_EACH_IMM_USE_FAST (use_b, imm_iter, op)
-		      if (bb_for_stmt (USE_STMT (use_b))->loop_father
-			  == loop->inner)
-			goto fail;
-
-		      /* The statement should not use the value of a
-			 scalar that was modified in the loop.  */
-		      node = SSA_NAME_DEF_STMT (op);
-		      if (TREE_CODE (node) == PHI_NODE)
-			FOR_EACH_PHI_ARG (use_b, node, op_iter1, SSA_OP_USE)
-			  {
-			    tree arg = USE_FROM_PTR (use_b);
-
-			    if (TREE_CODE (arg) == SSA_NAME)
-			      {
-				tree arg_stmt = SSA_NAME_DEF_STMT (arg);
-
-				if (bb_for_stmt (arg_stmt)
-				    && (bb_for_stmt (arg_stmt)->loop_father
-					== loop->inner))
-				  goto fail;
-			      }
-			  }
-		    }
-
-		  if (can_put_in_inner_loop (loop->inner, stmt)
-		      || can_put_after_inner_loop (loop, stmt))
-		    continue;
-		}
-
-	      /* Otherwise, if the bb of a statement we care about isn't
-		 dominated by the header of the inner loop, then we can't
-		 handle this case right now.  This test ensures that the
-		 statement comes completely *after* the inner loop.  */
-	      if (!dominated_by_p (CDI_DOMINATORS,
-				   bb_for_stmt (stmt), 
-				   loop->inner->header))
-		goto fail;
-	    }
-	}
-    }
+    if (bbs[i]->loop_father == loop
+	&& cannot_convert_bb_to_perfect_nest (bbs[i], loop))
+      goto fail;
 
   /* We also need to make sure the loop exit only has simple copy phis in it,
-     otherwise we don't know how to transform it into a perfect nest right
-     now.  */
-  exitdest = single_exit (loop)->dest;
-  
-  for (phi = phi_nodes (exitdest); phi; phi = PHI_CHAIN (phi))
+     otherwise we don't know how to transform it into a perfect nest.  */
+  for (phi = phi_nodes (single_exit (loop)->dest); phi; phi = PHI_CHAIN (phi))
     if (PHI_NUM_ARGS (phi) != 1)
       goto fail;
   

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2007-12-18 19:10 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-12-16  8:56 [PATCH] Fix PR34123: ICE in loop interchange Sebastian Pop
2007-12-18 19:45 ` Daniel Berlin
  -- strict thread matches above, loose matches on Subject: below --
2007-12-15 21:58 Sebastian Pop

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).