Skip to content

Commit

Permalink
[Flang][OpenMP] Add convert to match the argument and result of updat…
Browse files Browse the repository at this point in the history
…e Op

Fixes #60873

Reviewed By: peixin

Differential Revision: https://reviews.llvm.org/D144432
  • Loading branch information
kiranchandramohan committed Feb 21, 2023
1 parent e5c9592 commit 9adef10
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
4 changes: 3 additions & 1 deletion flang/lib/Lower/OpenMP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1669,8 +1669,10 @@ static void genOmpAtomicUpdateStatement(

mlir::Value result = fir::getBase(converter.genExprValue(
*Fortran::semantics::GetExpr(assignmentStmtExpr), stmtCtx));
mlir::Value convertResult =
firOpBuilder.createConvert(currentLocation, varType, result);
// Insert the terminator: YieldOp.
firOpBuilder.create<mlir::omp::YieldOp>(currentLocation, result);
firOpBuilder.create<mlir::omp::YieldOp>(currentLocation, convertResult);
// Reset the insert point to before the terminator.
firOpBuilder.setInsertionPointToStart(&block);
}
Expand Down
19 changes: 17 additions & 2 deletions flang/test/Lower/OpenMP/atomic-update.f90
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ program OmpAtomicUpdate
integer :: x, y, z
integer, pointer :: a, b
integer, target :: c, d
integer(1) :: i1

a=>c
b=>d

Expand All @@ -21,6 +23,7 @@ program OmpAtomicUpdate
!CHECK: fir.store %{{.*}} to %[[B_ADDR]] : !fir.ref<!fir.ptr<i32>>
!CHECK: %[[C_ADDR:.*]] = fir.address_of(@_QFEc) : !fir.ref<i32>
!CHECK: %[[D_ADDR:.*]] = fir.address_of(@_QFEd) : !fir.ref<i32>
!CHECK: %[[I1:.*]] = fir.alloca i8 {bindc_name = "i1", uniq_name = "_QFEi1"}
!CHECK: %[[X:.*]] = fir.alloca i32 {bindc_name = "x", uniq_name = "_QFEx"}
!CHECK: %[[Y:.*]] = fir.alloca i32 {bindc_name = "y", uniq_name = "_QFEy"}
!CHECK: %[[Z:.*]] = fir.alloca i32 {bindc_name = "z", uniq_name = "_QFEz"}
Expand Down Expand Up @@ -115,10 +118,22 @@ program OmpAtomicUpdate
!CHECK: %[[RESULT:.*]] = arith.addi %[[LOADED_Y]], %[[ARG]] : i32
!CHECK: omp.yield(%[[RESULT]] : i32)
!CHECK: }
!CHECK: return
!CHECK: }
!$omp atomic hint(omp_sync_hint_nonspeculative) seq_cst
y = 10 + y
!$omp atomic seq_cst update
z = y + z

!CHECK: omp.atomic.update %[[I1]] : !fir.ref<i8> {
!CHECK: ^bb0(%[[VAL:.*]]: i8):
!CHECK: %[[CVT_VAL:.*]] = fir.convert %[[VAL]] : (i8) -> i32
!CHECK: %[[C1_VAL:.*]] = arith.constant 1 : i32
!CHECK: %[[ADD_VAL:.*]] = arith.addi %[[CVT_VAL]], %[[C1_VAL]] : i32
!CHECK: %[[UPDATED_VAL:.*]] = fir.convert %[[ADD_VAL]] : (i32) -> i8
!CHECK: omp.yield(%[[UPDATED_VAL]] : i8)
!CHECK: }
!$omp atomic
i1 = i1 + 1
!$omp end atomic
!CHECK: return
!CHECK: }
end program OmpAtomicUpdate

0 comments on commit 9adef10

Please sign in to comment.