]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
openmp: Fix ICE on non-rectangular loop with known 0 iterations
authorJakub Jelinek <jakub@redhat.com>
Wed, 18 Nov 2020 08:40:45 +0000 (09:40 +0100)
committerKwok Cheung Yeung <kcy@codesourcery.com>
Tue, 9 Feb 2021 18:09:02 +0000 (10:09 -0800)
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.

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.

(cherry picked from commit ba009860aec4619f2424f5bdee812f14572dc3cc)

gcc/ChangeLog.omp
gcc/omp-expand.c
gcc/testsuite/ChangeLog.omp
gcc/testsuite/c-c++-common/gomp/pr97862.c [new file with mode: 0644]

index 94c0957318b2aad532715af1ded3196320f963c9..029e13d18552aa8644f32a459a2d0db45d9b765d 100644 (file)
@@ -1,3 +1,12 @@
+2021-02-09  Kwok Cheung Yeung  <kcy@codesourcery.com>
+
+       Backport from mainline
+       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.
+
 2021-02-09  Kwok Cheung Yeung  <kcy@codesourcery.com>
 
        Backport from mainline
index 71bf80308c97770b266c7c29cc3be987e493242c..e4a2f3a7d55117b01ecb4b05c7a35619e6ef559f 100644 (file)
@@ -2566,7 +2566,8 @@ expand_omp_for_init_vars (struct omp_for_data *fd, gimple_stmt_iterator *gsi,
              && (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);
index 4108b4b6113223a5b71aea25ef6160703326331a..4aa93123e6afbb9987723417044720364544bb1b 100644 (file)
@@ -1,3 +1,11 @@
+2021-02-09  Kwok Cheung Yeung  <kcy@codesourcery.com>
+
+       Backport from mainline
+       2020-11-18  Jakub Jelinek  <jakub@redhat.com>
+
+       PR middle-end/97862
+       * c-c++-common/gomp/pr97862.c: New test.
+
 2021-02-09  Kwok Cheung Yeung  <kcy@codesourcery.com>
 
        Backport from mainline
diff --git a/gcc/testsuite/c-c++-common/gomp/pr97862.c b/gcc/testsuite/c-c++-common/gomp/pr97862.c
new file mode 100644 (file)
index 0000000..21aad3f
--- /dev/null
@@ -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)
+      ;
+}