Closed
Description
default(private)
fails to privatize when used with parallel do. Reproducer:
program sample
integer :: x
x = 0
!$omp parallel do default(private) num_threads(50)
do i = 1, 50
x = x + 1
end do
!$omp end parallel do
print *, x
end program sample
As expected, gfortran prints x=0. However, LLVM flang prints a non-zero value (< 50). Use of an additional if(.false.)
ensures x=50.
A dump of --emit-fir
shows fir.store %10 to %1
%0 = fir.alloca i32 {bindc_name = "i", uniq_name = "_QFEi"}
%1 = fir.alloca i32 {bindc_name = "x", uniq_name = "_QFEx"}
%c0_i32 = arith.constant 0 : i32
fir.store %c0_i32 to %1 : !fir.ref<i32>
%c50_i32 = arith.constant 50 : i32
omp.parallel num_threads(%c50_i32 : i32) {
%8 = fir.alloca i32 {adapt.valuebyref, pinned}
%c1_i32 = arith.constant 1 : i32
%c50_i32_0 = arith.constant 50 : i32
%c1_i32_1 = arith.constant 1 : i32
omp.wsloop for (%arg0) : i32 = (%c1_i32) to (%c50_i32_0) inclusive step (%c1_i32_1) {
fir.store %arg0 to %8 : !fir.ref<i32>
%9 = fir.load %1 : !fir.ref<i32>
%c1_i32_2 = arith.constant 1 : i32
%10 = arith.addi %9, %c1_i32_2 : i32
**fir.store %10 to %1 : !fir.ref<i32>**
omp.yield
}
omp.terminator
}
Expected IR should be as follows:
%0 = fir.alloca i32 {bindc_name = "i", uniq_name = "_QFEi"}
%1 = fir.alloca i32 {bindc_name = "x", uniq_name = "_QFEx"}
%c0_i32 = arith.constant 0 : i32
fir.store %c0_i32 to %1 : !fir.ref<i32>
%c50_i32 = arith.constant 50 : i32
omp.parallel num_threads(%c50_i32 : i32) {
%8 = fir.alloca i32 {adapt.valuebyref, pinned}
**%9 = fir.alloca i32 {bindc_name = "x", pinned, uniq_name = "_QFEx"}**
%c1_i32 = arith.constant 1 : i32
%c50_i32_0 = arith.constant 50 : i32
%c1_i32_1 = arith.constant 1 : i32
omp.wsloop for (%arg0) : i32 = (%c1_i32) to (%c50_i32_0) inclusive step (%c1_i32_1) {
fir.store %arg0 to %8 : !fir.ref<i32>
%10 = fir.load %9 : !fir.ref<i32>
%c1_i32_2 = arith.constant 1 : i32
%11 = arith.addi %10, %c1_i32_2 : i32
**fir.store %11 to %9 : !fir.ref<i32>**
omp.yield
}
omp.terminator
}