Currently, the helpers to get fir::ExtendedValue out of hlfir::Entity use hlfir.declare second result (`#1`) in most cases. This is because this result is the same as the input and matches what FIR was getting before lowering to HLFIR. But this creates odd situations when both hlfir.declare are raw pointers and either result ends-up being used in the IR depending on whether the code was generated by a helper using fir::ExtendedValue, or via "pure HLFIR" helpers using the first result. This will typically prevent simple CSE and easy identification that two operation (e.g load/store) are touching the exact same memory location without using alias analysis or "manual detection" (looking for common hlfir.declare defining op). Hence, when hlfir.declare results are both raw pointers, use `#0` when producing `fir::ExtendedValue`. When `#0` is a fir.box, keep using `#1` because these are not the same. The only code change is in HLFIRTools.cpp and is pretty small, but there is a big test fallout of `#1` to `#0`.
121 lines
4.4 KiB
Fortran
121 lines
4.4 KiB
Fortran
! RUN: bbc -emit-hlfir -fopenmp %s -o - | FileCheck %s
|
|
! RUN: %flang_fc1 -emit-hlfir -fopenmp %s -o - | FileCheck %s
|
|
|
|
! --- Check that with shared(i) the variable outside the parallel section
|
|
! --- is updated.
|
|
! CHECK-LABEL: func.func @_QPomploop()
|
|
! CHECK: %[[ALLOC_I:.*]] = fir.alloca i32 {bindc_name = "i", uniq_name = "_QFomploopEi"}
|
|
! CHECK: %[[DECL_I:.*]]:2 = hlfir.declare %[[ALLOC_I]] {uniq_name = "_QFomploopEi"} :
|
|
! CHECK: omp.parallel {
|
|
! CHECK: omp.sections {
|
|
! CHECK: omp.section {
|
|
! CHECK: %[[RES:.*]]:2 = fir.do_loop %[[ARG0:.*]] = %{{.*}} to %{{.*}} step %{{.*}} iter_args(%[[ARG1:.*]] =
|
|
! CHECK: fir.store %[[ARG1]] to %[[DECL_I]]#0
|
|
! CHECK: %[[UPDATE_ITER:.*]] = arith.addi %[[ARG0]], %{{.*}}
|
|
! CHECK: %[[LOAD_I:.*]] = fir.load %[[DECL_I]]#0
|
|
! CHECK: %[[RES_I:.*]] = arith.addi %[[LOAD_I]], %{{.*}}
|
|
! CHECK: fir.result %[[UPDATE_ITER]], %[[RES_I]]
|
|
! CHECK: }
|
|
! CHECK: fir.store %[[RES]]#1 to %[[DECL_I]]#0
|
|
! CHECK: omp.terminator
|
|
! CHECK: }
|
|
! CHECK: omp.terminator
|
|
! CHECK: }
|
|
! CHECK: return
|
|
! CHECK: }
|
|
subroutine omploop
|
|
implicit none
|
|
integer :: i, j
|
|
i = 1
|
|
j = 0
|
|
!$omp parallel shared(i)
|
|
!$omp sections
|
|
do i=1,10
|
|
j = j + i
|
|
end do
|
|
!$omp end sections
|
|
!$omp end parallel
|
|
end subroutine
|
|
|
|
! --- Check that with default(shared) the variable outside the parallel section
|
|
! --- is NOT updated (i is private to the omp.parallel code)
|
|
! CHECK-LABEL: func.func @_QPomploop2()
|
|
! CHECK: %[[ALLOC_I:.*]] = fir.alloca i32 {bindc_name = "i", uniq_name = "_QFomploop2Ei"}
|
|
! CHECK: %[[DECL_I:.*]]:2 = hlfir.declare %[[ALLOC_I]] {uniq_name = "_QFomploop2Ei"} :
|
|
! CHECK: omp.parallel {
|
|
! CHECK: %[[ALLOC_PRIV_I:.*]] = fir.alloca i32 {bindc_name = "i", pinned}
|
|
! CHECK: %[[DECL_PRIV_I:.*]]:2 = hlfir.declare %[[ALLOC_PRIV_I]]
|
|
! CHECK: omp.sections {
|
|
! CHECK: omp.section {
|
|
! CHECK: %[[RES:.*]]:2 = fir.do_loop %[[ARG0:.*]] = %{{.*}} to %{{.*}} step %{{.*}} iter_args(%[[ARG1:.*]] =
|
|
! CHECK-NOT: fir.store %[[ARG1]] to %[[DECL_I]]#1
|
|
! CHECK: fir.store %[[ARG1]] to %[[DECL_PRIV_I]]#0
|
|
! CHECK: %[[UPDATE_ITER:.*]] = arith.addi %[[ARG0]], %{{.*}}
|
|
! CHECK: %[[LOAD_I:.*]] = fir.load %[[DECL_PRIV_I]]#0
|
|
! CHECK: %[[RES_I:.*]] = arith.addi %[[LOAD_I]], %{{.*}}
|
|
! CHECK: fir.result %[[UPDATE_ITER]], %[[RES_I]]
|
|
! CHECK: }
|
|
! CHECK: fir.store %[[RES]]#1 to %[[DECL_PRIV_I]]#0
|
|
! CHECK: omp.terminator
|
|
! CHECK: }
|
|
! CHECK: omp.terminator
|
|
! CHECK: }
|
|
! CHECK: return
|
|
! CHECK: }
|
|
subroutine omploop2
|
|
implicit none
|
|
integer :: i, j
|
|
i = 1
|
|
j = 0
|
|
!$omp parallel default(shared)
|
|
!$omp sections
|
|
do i=1,10
|
|
j = j + i
|
|
end do
|
|
!$omp end sections
|
|
!$omp end parallel
|
|
end subroutine
|
|
|
|
|
|
! --- Check that with no data-sharing the variable outside the parallel section
|
|
! --- is NOT updated (i is private to the omp.parallel code)
|
|
! CHECK-LABEL: func.func @_QPomploop3()
|
|
! CHECK: %[[ALLOC_I:.*]] = fir.alloca i32 {bindc_name = "i", uniq_name = "_QFomploop3Ei"}
|
|
! CHECK: %[[DECL_I:.*]]:2 = hlfir.declare %[[ALLOC_I]] {uniq_name = "_QFomploop3Ei"} :
|
|
! CHECK: omp.parallel {
|
|
! CHECK: %[[ALLOC_PRIV_I:.*]] = fir.alloca i32 {bindc_name = "i", pinned}
|
|
! CHECK: %[[DECL_PRIV_I:.*]]:2 = hlfir.declare %[[ALLOC_PRIV_I]]
|
|
! CHECK: omp.sections {
|
|
! CHECK: omp.section {
|
|
! CHECK: %[[RES:.*]]:2 = fir.do_loop %[[ARG0:.*]] = %{{.*}} to %{{.*}} step %{{.*}} iter_args(%[[ARG1:.*]] =
|
|
! CHECK-NOT: fir.store %[[ARG1]] to %[[DECL_I]]#1
|
|
! CHECK: fir.store %[[ARG1]] to %[[DECL_PRIV_I]]#0
|
|
! CHECK: %[[UPDATE_ITER:.*]] = arith.addi %[[ARG0]], %{{.*}}
|
|
! CHECK: %[[LOAD_I:.*]] = fir.load %[[DECL_PRIV_I]]#0
|
|
! CHECK: %[[RES_I:.*]] = arith.addi %[[LOAD_I]], %{{.*}}
|
|
! CHECK: fir.result %[[UPDATE_ITER]], %[[RES_I]]
|
|
! CHECK: }
|
|
! CHECK: fir.store %[[RES]]#1 to %[[DECL_PRIV_I]]#0
|
|
! CHECK: omp.terminator
|
|
! CHECK: }
|
|
! CHECK: omp.terminator
|
|
! CHECK: }
|
|
! CHECK: return
|
|
! CHECK: }
|
|
subroutine omploop3
|
|
implicit none
|
|
integer :: i, j
|
|
i = 1
|
|
j = 0
|
|
!$omp parallel
|
|
!$omp sections
|
|
do i=1,10
|
|
j = j + i
|
|
end do
|
|
!$omp end sections
|
|
!$omp end parallel
|
|
end subroutine
|
|
|
|
|
|
|