public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* openmp: Fix ICE on non-rectangular loop with known 0 iterations [PR97862]
@ 2020-11-18  8:44 Jakub Jelinek
  0 siblings, 0 replies; only message in thread
From: Jakub Jelinek @ 2020-11-18  8:44 UTC (permalink / raw)
  To: gcc-patches

Hi!

The loops in the testcase are non-rectangular and have 0 iterations
(the outer loop iterates, but the inner one never).  In this case we
just have the overall number of iterations computed (0), and don't have
factor and other values computed.  We never need to map logical iterations
to the individual iterations in that case, and we were crashing during
expansion of that code.

Bootstrapped/regtested on x86_64-linux and i686-linux, committed to trunk.

2020-11-18  Jakub Jelinek  <jakub@redhat.com>

	PR middle-end/97862
	* omp-expand.c (expand_omp_for_init_vars): Don't use the sqrt path
	if number of iterations is constant 0.

	* c-c++-common/gomp/pr97862.c: New test.

--- gcc/omp-expand.c.jj	2020-11-14 10:40:11.231409596 +0100
+++ gcc/omp-expand.c	2020-11-17 12:56:52.183888420 +0100
@@ -2514,7 +2514,8 @@ expand_omp_for_init_vars (struct omp_for
 	      && (TREE_CODE (fd->loop.n2) == INTEGER_CST
 		  || fd->first_inner_iterations)
 	      && (optab_handler (sqrt_optab, TYPE_MODE (double_type_node))
-		  != CODE_FOR_nothing))
+		  != CODE_FOR_nothing)
+	      && !integer_zerop (fd->loop.n2))
 	    {
 	      tree outer_n1 = fd->adjn1 ? fd->adjn1 : fd->loops[i - 1].n1;
 	      tree itype = TREE_TYPE (fd->loops[i].v);
--- gcc/testsuite/c-c++-common/gomp/pr97862.c.jj	2020-11-17 13:00:31.019380920 +0100
+++ gcc/testsuite/c-c++-common/gomp/pr97862.c	2020-11-17 13:04:05.602922138 +0100
@@ -0,0 +1,15 @@
+/* PR middle-end/97862 */
+
+void
+foo (void)
+{
+  int i, j;
+#pragma omp for collapse(2)
+  for (i = 0; i < 1; ++i)
+    for (j = 0; j < i; ++j)
+      ;
+#pragma omp for collapse(2)
+  for (i = 0; i < 20; i++)
+    for (j = 0; j < i - 19; j += 1)
+      ;
+}

	Jakub


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-11-18  8:44 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-18  8:44 openmp: Fix ICE on non-rectangular loop with known 0 iterations [PR97862] Jakub Jelinek

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