[flang-commits] [flang] [flang][Lower] Treat directives with nested evaluations as constructs (PR #91614)
Mats Petersson via flang-commits
flang-commits at lists.llvm.org
Fri May 10 03:36:07 PDT 2024
Leporacanthicus wrote:
I think this fix is doing something good - it helps in SOME cases, but perhaps not "good enough". I'm not opposed to this going in... But a complete fix would be better, in my (and Kiran's) opinion.
It doesn't fix my original problem, I'm still seeing the STOP when it shouldn't for this code:
```
subroutine simple(x, yn)
implicit none
logical, intent(in) :: yn
integer, intent(in) :: x
integer :: i
real(8) :: E
E = 0d0
if (yn) then
!$omp parallel do private(i) reduction(+:E)
do i = 1, x
E = E + i
end do
!$omp end parallel do
else
stop 1
end if
print *, E
end subroutine simple
program p
integer :: xx
xx = 50
call simple(xx, .true.)
end program p
```
Compiler generates this MLIR (only the "interesting portion" shown here):
```
cf.cond_br %8, ^bb1, ^bb2
^bb1: // pred: ^bb0
omp.parallel {
%10 = fir.alloca i32 {adapt.valuebyref, pinned}
%11 = fir.declare %10 {uniq_name = "_QFsimpleEi"} : (!fir.ref<i32>) -> !fir.ref<i32>
%12 = fir.load %5 : !fir.ref<i32>
omp.wsloop reduction(@add_reduction_f64 %2 -> %arg2 : !fir.ref<f64>) {
omp.loop_nest (%arg3) : i32 = (%c1_i32) to (%12) inclusive step (%c1_i32) {
%13 = fir.declare %arg2 {uniq_name = "_QFsimpleEe"} : (!fir.ref<f64>) -> !fir.ref<f64>
fir.store %arg3 to %11 : !fir.ref<i32>
%14 = fir.load %13 : !fir.ref<f64>
%15 = fir.load %11 : !fir.ref<i32>
%16 = fir.convert %15 : (i32) -> f64
%17 = arith.addf %14, %16 fastmath<contract> : f64
fir.store %17 to %13 : !fir.ref<f64>
omp.yield
}
omp.terminator
}
omp.terminator
}
cf.br ^bb2
^bb2: // 2 preds: ^bb0, ^bb1
%9 = fir.call @_FortranAStopStatement(%c1_i32, %false, %false) fastmath<contract> : (i32, i1, i1) -> none
fir.unreachable
}
```
Not sure if it's because the parallel section has a do and/or a reduction inside it?
https://github.com/llvm/llvm-project/pull/91614
More information about the flang-commits
mailing list