aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2020-11-18 09:40:45 +0100
committerKwok Cheung Yeung <kcy@codesourcery.com>2021-02-09 10:09:02 -0800
commit7bfdb5a1c694cb9006e0478941e4443b230f5b98 (patch)
tree99a7c685c86141c868f179707fb0af957d88702a /gcc
parent88528328ea560230f728af97110e89396c8267d2 (diff)
openmp: Fix ICE on non-rectangular loop with known 0 iterations
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)
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog.omp9
-rw-r--r--gcc/omp-expand.c3
-rw-r--r--gcc/testsuite/ChangeLog.omp8
-rw-r--r--gcc/testsuite/c-c++-common/gomp/pr97862.c15
4 files changed, 34 insertions, 1 deletions
diff --git a/gcc/ChangeLog.omp b/gcc/ChangeLog.omp
index 94c0957318b..029e13d1855 100644
--- a/gcc/ChangeLog.omp
+++ b/gcc/ChangeLog.omp
@@ -1,6 +1,15 @@
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
2020-10-13 Jakub Jelinek <jakub@redhat.com>
* omp-low.c (add_taskreg_looptemp_clauses): For triangular loops
diff --git a/gcc/omp-expand.c b/gcc/omp-expand.c
index 71bf80308c9..e4a2f3a7d55 100644
--- a/gcc/omp-expand.c
+++ b/gcc/omp-expand.c
@@ -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);
diff --git a/gcc/testsuite/ChangeLog.omp b/gcc/testsuite/ChangeLog.omp
index 4108b4b6113..4aa93123e6a 100644
--- a/gcc/testsuite/ChangeLog.omp
+++ b/gcc/testsuite/ChangeLog.omp
@@ -1,6 +1,14 @@
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
2020-07-02 Jakub Jelinek <jakub@redhat.com>
* c-c++-common/gomp/loop-7.c: New test.
diff --git a/gcc/testsuite/c-c++-common/gomp/pr97862.c b/gcc/testsuite/c-c++-common/gomp/pr97862.c
new file mode 100644
index 00000000000..21aad3f5b29
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/gomp/pr97862.c
@@ -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)
+ ;
+}