Skip to content

Commit 9adef10

Browse files
[Flang][OpenMP] Add convert to match the argument and result of update Op
Fixes #60873 Reviewed By: peixin Differential Revision: https://reviews.llvm.org/D144432
1 parent e5c9592 commit 9adef10

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

flang/lib/Lower/OpenMP.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1669,8 +1669,10 @@ static void genOmpAtomicUpdateStatement(
16691669

16701670
mlir::Value result = fir::getBase(converter.genExprValue(
16711671
*Fortran::semantics::GetExpr(assignmentStmtExpr), stmtCtx));
1672+
mlir::Value convertResult =
1673+
firOpBuilder.createConvert(currentLocation, varType, result);
16721674
// Insert the terminator: YieldOp.
1673-
firOpBuilder.create<mlir::omp::YieldOp>(currentLocation, result);
1675+
firOpBuilder.create<mlir::omp::YieldOp>(currentLocation, convertResult);
16741676
// Reset the insert point to before the terminator.
16751677
firOpBuilder.setInsertionPointToStart(&block);
16761678
}

flang/test/Lower/OpenMP/atomic-update.f90

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ program OmpAtomicUpdate
77
integer :: x, y, z
88
integer, pointer :: a, b
99
integer, target :: c, d
10+
integer(1) :: i1
11+
1012
a=>c
1113
b=>d
1214

@@ -21,6 +23,7 @@ program OmpAtomicUpdate
2123
!CHECK: fir.store %{{.*}} to %[[B_ADDR]] : !fir.ref<!fir.ptr<i32>>
2224
!CHECK: %[[C_ADDR:.*]] = fir.address_of(@_QFEc) : !fir.ref<i32>
2325
!CHECK: %[[D_ADDR:.*]] = fir.address_of(@_QFEd) : !fir.ref<i32>
26+
!CHECK: %[[I1:.*]] = fir.alloca i8 {bindc_name = "i1", uniq_name = "_QFEi1"}
2427
!CHECK: %[[X:.*]] = fir.alloca i32 {bindc_name = "x", uniq_name = "_QFEx"}
2528
!CHECK: %[[Y:.*]] = fir.alloca i32 {bindc_name = "y", uniq_name = "_QFEy"}
2629
!CHECK: %[[Z:.*]] = fir.alloca i32 {bindc_name = "z", uniq_name = "_QFEz"}
@@ -115,10 +118,22 @@ program OmpAtomicUpdate
115118
!CHECK: %[[RESULT:.*]] = arith.addi %[[LOADED_Y]], %[[ARG]] : i32
116119
!CHECK: omp.yield(%[[RESULT]] : i32)
117120
!CHECK: }
118-
!CHECK: return
119-
!CHECK: }
120121
!$omp atomic hint(omp_sync_hint_nonspeculative) seq_cst
121122
y = 10 + y
122123
!$omp atomic seq_cst update
123124
z = y + z
125+
126+
!CHECK: omp.atomic.update %[[I1]] : !fir.ref<i8> {
127+
!CHECK: ^bb0(%[[VAL:.*]]: i8):
128+
!CHECK: %[[CVT_VAL:.*]] = fir.convert %[[VAL]] : (i8) -> i32
129+
!CHECK: %[[C1_VAL:.*]] = arith.constant 1 : i32
130+
!CHECK: %[[ADD_VAL:.*]] = arith.addi %[[CVT_VAL]], %[[C1_VAL]] : i32
131+
!CHECK: %[[UPDATED_VAL:.*]] = fir.convert %[[ADD_VAL]] : (i32) -> i8
132+
!CHECK: omp.yield(%[[UPDATED_VAL]] : i8)
133+
!CHECK: }
134+
!$omp atomic
135+
i1 = i1 + 1
136+
!$omp end atomic
137+
!CHECK: return
138+
!CHECK: }
124139
end program OmpAtomicUpdate

0 commit comments

Comments
 (0)