Skip to content

Commit eafa150

Browse files
authored
[flang][OpenMP] Enable lastprivate on simd (#93786)
This PR enables the lowering of lastprivate when defined on simd construct
1 parent 4547d60 commit eafa150

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

flang/lib/Lower/OpenMP/DataSharingProcessor.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,12 +190,12 @@ void DataSharingProcessor::insertLastPrivateCompare(mlir::Operation *op) {
190190
for (const omp::Clause &clause : clauses) {
191191
if (clause.id != llvm::omp::OMPC_lastprivate)
192192
continue;
193-
// TODO: Add lastprivate support for simd construct
194-
if (mlir::isa<mlir::omp::WsloopOp>(op)) {
193+
if (mlir::isa<mlir::omp::WsloopOp>(op) ||
194+
mlir::isa<mlir::omp::SimdOp>(op)) {
195195
// Update the original variable just before exiting the worksharing
196196
// loop. Conversion as follows:
197197
//
198-
// omp.wsloop { omp.wsloop {
198+
// omp.wsloop / omp.simd { omp.wsloop / omp.simd {
199199
// omp.loop_nest { omp.loop_nest {
200200
// ... ...
201201
// store ===> store

flang/test/Lower/OpenMP/simd.f90

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,3 +241,36 @@ subroutine simd_with_nontemporal_clause(n)
241241
end do
242242
!$OMP END SIMD
243243
end subroutine
244+
245+
!CHECK-LABEL: func.func @_QPlastprivate_with_simd() {
246+
subroutine lastprivate_with_simd
247+
248+
!CHECK: %[[VAR_SUM:.*]] = fir.alloca f32 {bindc_name = "sum", uniq_name = "_QFlastprivate_with_simdEsum"}
249+
!CHECK: %[[VAR_SUM_DECLARE:.*]]:2 = hlfir.declare %[[VAR_SUM]] {{.*}}
250+
!CHECK: %[[VAR_SUM_PINNED:.*]] = fir.alloca f32 {bindc_name = "sum", pinned, uniq_name = "_QFlastprivate_with_simdEsum"}
251+
!CHECK: %[[VAR_SUM_PINNED_DECLARE:.*]]:2 = hlfir.declare %[[VAR_SUM_PINNED]] {{.*}}
252+
253+
implicit none
254+
integer :: i
255+
real :: sum
256+
257+
258+
!CHECK: omp.simd {
259+
!CHECK: omp.loop_nest (%[[ARG:.*]]) : i32 = ({{.*}} to ({{.*}}) inclusive step ({{.*}}) {
260+
!CHECK: %[[ADD_RESULT:.*]] = arith.addi {{.*}}
261+
!CHECK: %[[ADD_RESULT_CONVERT:.*]] = fir.convert %[[ADD_RESULT]] : (i32) -> f32
262+
!CHECK: hlfir.assign %[[ADD_RESULT_CONVERT]] to %[[VAR_SUM_PINNED_DECLARE]]#0 : f32, !fir.ref<f32>
263+
!CHECK: %[[SELECT_RESULT:.*]] = arith.select {{.*}}, {{.*}}, {{.*}} : i1
264+
!CHECK: fir.if %[[SELECT_RESULT]] {
265+
!CHECK: %[[LOADED_SUM:.*]] = fir.load %[[VAR_SUM_PINNED_DECLARE]]#0 : !fir.ref<f32>
266+
!CHECK: hlfir.assign %[[LOADED_SUM]] to %[[VAR_SUM_DECLARE]]#0 : f32, !fir.ref<f32>
267+
!CHECK: }
268+
!CHECK: omp.yield
269+
!CHECK: }
270+
!CHECK: omp.terminator
271+
!CHECK: }
272+
!$omp simd lastprivate(sum)
273+
do i = 1, 100
274+
sum = i + 1
275+
end do
276+
end subroutine

0 commit comments

Comments
 (0)