]> git.ipfire.org Git - thirdparty/gcc.git/commit
openmp: Adjust outer bounds of non-rect loops
authorJakub Jelinek <jakub@redhat.com>
Tue, 14 Jul 2020 08:31:59 +0000 (10:31 +0200)
committerKwok Cheung Yeung <kcy@codesourcery.com>
Tue, 9 Feb 2021 18:09:02 +0000 (10:09 -0800)
commit6da60f76333666e98955aa33624a7e95bffe58aa
treecf3d2de8d7f45fbb5f60e24def0380fe5be16b2b
parent8abe8a169150b717c8e1f7de8c1e0d29b9381806
openmp: Adjust outer bounds of non-rect loops

In loops like:
  #pragma omp parallel for collapse(2)
  for (i = -4; i < 8; i++)
    for (j = 3 * i; j > 2 * i; j--)
for some outer loop iterations there are no inner loop iterations at all,
the condition is false.  In order to use Summæ Potestate to count number
of iterations or to transform the logical iteration number to actual
iterator values using quadratic non-equation root discovery the outer
iterator range needs to be adjusted, such that the inner loop has at least
one iteration for each of the outer loop iterator value in the reduced
range.  Sometimes this adjustment is done at the start of the range,
at other times at the end.

This patch implements it during the compile time number of loop computation
(if all expressions are compile time constants).

2020-07-14  Jakub Jelinek  <jakub@redhat.com>

* omp-general.h (struct omp_for_data): Add adjn1 member.
* omp-general.c (omp_extract_for_data): For non-rect loop, punt on
count computing if n1, n2 or step are not INTEGER_CST earlier.
Narrow the outer iterator range if needed so that non-rect loop
has at least one iteration for each outer range iteration.  Compute
adjn1.
* omp-expand.c (expand_omp_for_init_vars): Use adjn1 if non-NULL
instead of the outer loop's n1.

* testsuite/libgomp.c/loop-21.c: New test.

(cherry picked from commit f418bd4b92a03ee0ec0fe4cfcd896e86e11ac2cf)
gcc/ChangeLog.omp
gcc/omp-expand.c
gcc/omp-general.c
gcc/omp-general.h
libgomp/ChangeLog.omp
libgomp/testsuite/libgomp.c/loop-21.c [new file with mode: 0644]