Skip to content

Commit 0326f92

Browse files
zhushengtao1bryanpkc
authored andcommitted
[flang1] Fix a parallel do bug
When the stride of parallel do is negative, flang will always exit loop. It is because check_loop_bound function always check the incr of a loop to avoid out of loop bound. It is not necessary since __kmp_for_static_init in openmp have do the same thing, and will change the stride to match the actual number of iterations. The function is only needed when SCHEDULE is enabled.
1 parent 4e6cb28 commit 0326f92

File tree

4 files changed

+56
-5
lines changed

4 files changed

+56
-5
lines changed

test/mp_correct/inc/do20.mk

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#
2+
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
3+
# See https://llvm.org/LICENSE.txt for license information.
4+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5+
#
6+
7+
$(TEST): run
8+
9+
build: $(SRC)/$(TEST).f90
10+
-$(RM) $(TEST).$(EXESUFFIX) core *.d *.mod FOR*.DAT FTN* ftn* fort.*
11+
@echo ------------------------------------ building test $@
12+
-$(FC) $(FFLAGS) $(SRC)/$(TEST).f90 -o $(TEST).$(OBJX)
13+
-$(FC) $(LDFLAGS) $(TEST).$(OBJX) $(LIBS) -o $(TEST).$(EXESUFFIX)
14+
15+
run:
16+
@echo ------------------------------------ executing test $(TEST)
17+
-$(RUN4) $(TEST).$(EXESUFFIX)
18+
19+
verify: ;

test/mp_correct/lit/do20.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#
2+
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
3+
# See https://llvm.org/LICENSE.txt for license information.
4+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5+
6+
# Shared lit script for each tests. Run bash commands that run tests with make.
7+
8+
# RUN: KEEP_FILES=%keep FLAGS=%flags TEST_SRC=%s MAKE_FILE_DIR=%S/.. bash %S/runmake | tee %t
9+
# RUN: cat %t | FileCheck %S/runmake

test/mp_correct/src/do20.f90

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
!* Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
2+
!* See https://llvm.org/LICENSE.txt for license information.
3+
!* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4+
5+
! simple parallel do, negative stride
6+
7+
program main
8+
call mmm(10, 1, -2)
9+
contains
10+
11+
subroutine mmm (m1, m2, m3)
12+
integer :: m, m1, m2, m3
13+
!$OMP PARALLEL DO
14+
do m = m1, m2, m3
15+
print *, "PASS"
16+
enddo
17+
!$OMP END PARALLEL DO
18+
end subroutine
19+
20+
end program
21+

tools/flang1/flang1exe/lowerilm.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1883,11 +1883,13 @@ llvm_omp_sched(int std, int ast, int dtype, int dotop, int dobottom, int dovar,
18831883
ilm = lower_sptr(odovar, VarBase);
18841884
lower_typestore(dtype, ilm, doinitilm);
18851885

1886-
plower("oL", "LABEL", dotop);
1887-
if (schedtype == 0x000 || chunkone) {
1888-
check_loop_bound(odovar, o_ub, o_ub, dost, dobottom, 0, incr_loop);
1889-
} else {
1890-
check_loop_bound(odovar, newend, o_ub, dost, dobottom, 1, incr_loop);
1886+
if (schedtype != 0) {
1887+
plower("oL", "LABEL", dotop);
1888+
if (chunkone) {
1889+
check_loop_bound(odovar, o_ub, o_ub, dost, dobottom, 0, incr_loop);
1890+
} else {
1891+
check_loop_bound(odovar, newend, o_ub, dost, dobottom, 1, incr_loop);
1892+
}
18911893
}
18921894

18931895
/* dovar = odovar */

0 commit comments

Comments
 (0)