public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* Re: [PATCH] tree-optimization/104716 - check if we can copy loop in loop distribution
@ 2022-03-01 14:25 Richard Biener
  0 siblings, 0 replies; 2+ messages in thread
From: Richard Biener @ 2022-03-01 14:25 UTC (permalink / raw)
  To: gcc-patches

On Tue, 1 Mar 2022, Richard Biener wrote:

> The following checks whether we can copy the loop before attempting
> to do so in loop distribution.  In the testcase there's a computed
> goto and thus abnormal edges which we cannot redirect.
> 
> Bootstrapped on x86_64-unknown-linux-gnu, testing in progress.

Wrong patch posted - I've pushed the following.

Richard.

From 54ef95cc4d1f3f2cde7c1f13250f889ffb81ca75 Mon Sep 17 00:00:00 2001
From: Richard Biener <rguenther@suse.de>
Date: Tue, 1 Mar 2022 09:24:26 +0100
Subject: [PATCH] tree-optimization/104716 - check if we can copy loop in loop
 distribution
To: gcc-patches@gcc.gnu.org

The following checks whether we can copy the loop before attempting
to do so in loop distribution.  In the testcase there's a computed
goto and thus abnormal edges which we cannot redirect.

2022-03-01  Richard Biener  <rguenther@suse.de>

	PR tree-optimization/104716
	* tree-loop-distribution.cc (find_seed_stmts_for_distribution):
	Check if we can copy the loop.

	* gfortran.dg/pr104716.f: New testcase.
---
 gcc/testsuite/gfortran.dg/pr104716.f | 31 ++++++++++++++++++++++++++++
 gcc/tree-loop-distribution.cc        |  9 +++++++-
 2 files changed, 39 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gfortran.dg/pr104716.f

diff --git a/gcc/testsuite/gfortran.dg/pr104716.f b/gcc/testsuite/gfortran.dg/pr104716.f
new file mode 100644
index 00000000000..97f899a9201
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr104716.f
@@ -0,0 +1,31 @@
+! { dg-do compile }
+! { dg-options "-std=legacy -O2 -ftree-loop-distribution -fno-move-loop-stores -fno-tree-dominator-opts" }
+
+      SUBROUTINE FOO()
+      
+      COMMON /WORK/ C2(2, 2)
+      
+      DIMENSION D11(2)
+
+      EQUIVALENCE (D11(1), C2(1, 1))
+
+      DO 40 I = 1, 2
+         DO 30 J = 1, 2
+            ASSIGN 10 TO ILBL
+            IF (C2(J, I) .NE. 0.0) THEN
+               ASSIGN 20 TO ILBL
+            ENDIF
+            GO TO ILBL
+ 10         CONTINUE
+ 20         CONTINUE
+            C2(J, I) = C2(J, I) + 1
+ 30      CONTINUE
+ 40   CONTINUE
+
+      DO 50 I = 1, 2
+         PRINT 90, I
+ 50   CONTINUE
+      
+      RETURN
+ 90   FORMAT(I5)
+      END
diff --git a/gcc/tree-loop-distribution.cc b/gcc/tree-loop-distribution.cc
index 8ee40d88816..db6e9096a86 100644
--- a/gcc/tree-loop-distribution.cc
+++ b/gcc/tree-loop-distribution.cc
@@ -3277,8 +3277,15 @@ find_seed_stmts_for_distribution (class loop *loop, vec<gimple *> *work_list)
 	  work_list->safe_push (stmt);
 	}
     }
+  bool res = work_list->length () > 0;
+  if (res && !can_copy_bbs_p (bbs, loop->num_nodes))
+    {
+      if (dump_file && (dump_flags & TDF_DETAILS))
+	fprintf (dump_file, "cannot copy loop %d.\n", loop->num);
+      res = false;
+    }
   free (bbs);
-  return work_list->length () > 0;
+  return res;
 }
 
 /* A helper function for generate_{rawmemchr,strlen}_builtin functions in order
-- 
2.34.1


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

* [PATCH] tree-optimization/104716 - check if we can copy loop in loop distribution
@ 2022-03-01  8:52 Richard Biener
  0 siblings, 0 replies; 2+ messages in thread
From: Richard Biener @ 2022-03-01  8:52 UTC (permalink / raw)
  To: gcc-patches

The following checks whether we can copy the loop before attempting
to do so in loop distribution.  In the testcase there's a computed
goto and thus abnormal edges which we cannot redirect.

Bootstrapped on x86_64-unknown-linux-gnu, testing in progress.

2022-03-01  Richard Biener  <rguenther@suse.de>

	PR tree-optimization/104716
	* tree-loop-distribution.cc (find_seed_stmts_for_distribution):
	Check if we can copy the loop.

	* gfortran.dg/pr104716.f: New testcase.
---
 gcc/testsuite/gfortran.dg/pr104716.f | 31 ++++++++++++++++++++++++++++
 gcc/tree-loop-distribution.cc        | 14 +++++++++++++
 2 files changed, 45 insertions(+)
 create mode 100644 gcc/testsuite/gfortran.dg/pr104716.f

diff --git a/gcc/testsuite/gfortran.dg/pr104716.f b/gcc/testsuite/gfortran.dg/pr104716.f
new file mode 100644
index 00000000000..97f899a9201
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr104716.f
@@ -0,0 +1,31 @@
+! { dg-do compile }
+! { dg-options "-std=legacy -O2 -ftree-loop-distribution -fno-move-loop-stores -fno-tree-dominator-opts" }
+
+      SUBROUTINE FOO()
+      
+      COMMON /WORK/ C2(2, 2)
+      
+      DIMENSION D11(2)
+
+      EQUIVALENCE (D11(1), C2(1, 1))
+
+      DO 40 I = 1, 2
+         DO 30 J = 1, 2
+            ASSIGN 10 TO ILBL
+            IF (C2(J, I) .NE. 0.0) THEN
+               ASSIGN 20 TO ILBL
+            ENDIF
+            GO TO ILBL
+ 10         CONTINUE
+ 20         CONTINUE
+            C2(J, I) = C2(J, I) + 1
+ 30      CONTINUE
+ 40   CONTINUE
+
+      DO 50 I = 1, 2
+         PRINT 90, I
+ 50   CONTINUE
+      
+      RETURN
+ 90   FORMAT(I5)
+      END
diff --git a/gcc/tree-loop-distribution.cc b/gcc/tree-loop-distribution.cc
index 8ee40d88816..c2ca746e237 100644
--- a/gcc/tree-loop-distribution.cc
+++ b/gcc/tree-loop-distribution.cc
@@ -3237,6 +3237,20 @@ find_seed_stmts_for_distribution (class loop *loop, vec<gimple *> *work_list)
 	  work_list->truncate (0);
 	  break;
 	}
+      edge_iterator ei;
+      edge e;
+      /* We cannot redirect abnormal edges so loop copying will fail.  */
+      FOR_EACH_EDGE (e, ei, bbs[i]->succs)
+	if (e->flags & EDGE_ABNORMAL)
+	  {
+	    if (dump_file && (dump_flags & TDF_DETAILS))
+	      fprintf (dump_file, "loop %d is the source of abnormal edges.\n",
+		       loop->num);
+	    work_list->truncate (0);
+	    break;
+	  }
+      if (e)
+	break;
       for (gphi_iterator gsi = gsi_start_phis (bbs[i]);
 	   !gsi_end_p (gsi); gsi_next (&gsi))
 	{
-- 
2.34.1

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

end of thread, other threads:[~2022-03-01 14:25 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-01 14:25 [PATCH] tree-optimization/104716 - check if we can copy loop in loop distribution Richard Biener
  -- strict thread matches above, loose matches on Subject: below --
2022-03-01  8:52 Richard Biener

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).