Skip to content

Commit 2ef370b

Browse files
authored
[flang][openmp] Update copyHostAssociateVar to use hlfir.assign for HLFIR (#69441)
The code in `copyHostAssociateVar` is using `createSomeArrayAssignment` for arrays which is using the soon legacy expression lowering. Update the copy to use hlfir.assign instead. I used the temporary_lhs flag to mimic the current behavior, but maybe user defined assignment should be called when needed .This flag also prevents any finalizers to be called on the LHS if the LHS type has finalizers (which would occur otherwise in normal intrinsic assignment). Again, I am not sure what the OpenMP spec wants here. Also, I added special handling for ALLOCATABLE, the current code seems broken to me since it is basically copying the descriptor which would lead to memory leak given the TEMP was previously allocated with the shape of the variable in createHostAssociateVarClone. So copying the DATA instead seemed like the right thing to do.
1 parent 08d7d1e commit 2ef370b

File tree

6 files changed

+99
-52
lines changed

6 files changed

+99
-52
lines changed

flang/include/flang/Optimizer/Builder/HLFIRTools.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,11 @@ class Entity : public mlir::Value {
172172
return varIface ? varIface.isAllocatable() : false;
173173
}
174174

175+
bool isPointer() const {
176+
auto varIface = getIfVariableInterface();
177+
return varIface ? varIface.isPointer() : false;
178+
}
179+
175180
// Get the entity as an mlir SSA value containing all the shape, type
176181
// parameters and dynamic shape information.
177182
mlir::Value getBase() const { return *this; }

flang/lib/Lower/Bridge.cpp

Lines changed: 60 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -719,46 +719,88 @@ class FirConverter : public Fortran::lower::AbstractConverter {
719719
const Fortran::semantics::Symbol &hsym = sym.GetUltimate();
720720
Fortran::lower::SymbolBox hsb = lookupOneLevelUpSymbol(hsym);
721721
assert(hsb && "Host symbol box not found");
722-
fir::ExtendedValue hexv = symBoxToExtendedValue(hsb);
723722

724723
// 2) Fetch the copied one that will mask the original.
725724
Fortran::lower::SymbolBox sb = shallowLookupSymbol(sym);
726725
assert(sb && "Host-associated symbol box not found");
727726
assert(hsb.getAddr() != sb.getAddr() &&
728727
"Host and associated symbol boxes are the same");
729-
fir::ExtendedValue exv = symBoxToExtendedValue(sb);
730728

731729
// 3) Perform the assignment.
732730
mlir::OpBuilder::InsertPoint insPt = builder->saveInsertionPoint();
733731
if (copyAssignIP && copyAssignIP->isSet())
734732
builder->restoreInsertionPoint(*copyAssignIP);
735733
else
736-
builder->setInsertionPointAfter(fir::getBase(exv).getDefiningOp());
734+
builder->setInsertionPointAfter(sb.getAddr().getDefiningOp());
737735

738-
fir::ExtendedValue lhs, rhs;
736+
Fortran::lower::SymbolBox *lhs_sb, *rhs_sb;
739737
if (copyAssignIP && copyAssignIP->isSet() &&
740738
sym.test(Fortran::semantics::Symbol::Flag::OmpLastPrivate)) {
741739
// lastprivate case
742-
lhs = hexv;
743-
rhs = exv;
740+
lhs_sb = &hsb;
741+
rhs_sb = &sb;
744742
} else {
745-
lhs = exv;
746-
rhs = hexv;
743+
lhs_sb = &sb;
744+
rhs_sb = &hsb;
747745
}
748746

749747
mlir::Location loc = genLocation(sym.name());
750-
mlir::Type symType = genType(sym);
751748

752-
if (auto seqTy = symType.dyn_cast<fir::SequenceType>()) {
753-
Fortran::lower::StatementContext stmtCtx;
754-
Fortran::lower::createSomeArrayAssignment(*this, lhs, rhs, localSymbols,
755-
stmtCtx);
756-
stmtCtx.finalizeAndReset();
757-
} else if (hexv.getBoxOf<fir::CharBoxValue>()) {
758-
fir::factory::CharacterExprHelper{*builder, loc}.createAssign(lhs, rhs);
749+
if (lowerToHighLevelFIR()) {
750+
hlfir::Entity lhs{lhs_sb->getAddr()};
751+
hlfir::Entity rhs{rhs_sb->getAddr()};
752+
// Temporary_lhs is set to true in hlfir.assign below to avoid user
753+
// assignment to be used and finalization to be called on the LHS.
754+
// This may or may not be correct but mimics the current behaviour
755+
// without HLFIR.
756+
auto copyData = [&](hlfir::Entity l, hlfir::Entity r) {
757+
// Dereference RHS and load it if trivial scalar.
758+
r = hlfir::loadTrivialScalar(loc, *builder, r);
759+
builder->create<hlfir::AssignOp>(
760+
loc, r, l,
761+
/*isWholeAllocatableAssignment=*/false,
762+
/*keepLhsLengthInAllocatableAssignment=*/false,
763+
/*temporary_lhs=*/true);
764+
};
765+
if (lhs.isAllocatable()) {
766+
// Deep copy allocatable if it is allocated.
767+
// Note that when allocated, the RHS is already allocated with the LHS
768+
// shape for copy on entry in createHostAssociateVarClone.
769+
// For lastprivate, this assumes that the RHS was not reallocated in
770+
// the OpenMP region.
771+
lhs = hlfir::derefPointersAndAllocatables(loc, *builder, lhs);
772+
mlir::Value addr = hlfir::genVariableRawAddress(loc, *builder, lhs);
773+
mlir::Value isAllocated = builder->genIsNotNullAddr(loc, addr);
774+
builder->genIfThen(loc, isAllocated)
775+
.genThen([&]() {
776+
// Copy the DATA, not the descriptors.
777+
copyData(lhs, rhs);
778+
})
779+
.end();
780+
} else if (lhs.isPointer()) {
781+
// Set LHS target to the target of RHS (do not copy the RHS
782+
// target data into the LHS target storage).
783+
auto loadVal = builder->create<fir::LoadOp>(loc, rhs);
784+
builder->create<fir::StoreOp>(loc, loadVal, lhs);
785+
} else {
786+
// Non ALLOCATABLE/POINTER variable. Simple DATA copy.
787+
copyData(lhs, rhs);
788+
}
759789
} else {
760-
auto loadVal = builder->create<fir::LoadOp>(loc, fir::getBase(rhs));
761-
builder->create<fir::StoreOp>(loc, loadVal, fir::getBase(lhs));
790+
fir::ExtendedValue lhs = symBoxToExtendedValue(*lhs_sb);
791+
fir::ExtendedValue rhs = symBoxToExtendedValue(*rhs_sb);
792+
mlir::Type symType = genType(sym);
793+
if (auto seqTy = symType.dyn_cast<fir::SequenceType>()) {
794+
Fortran::lower::StatementContext stmtCtx;
795+
Fortran::lower::createSomeArrayAssignment(*this, lhs, rhs, localSymbols,
796+
stmtCtx);
797+
stmtCtx.finalizeAndReset();
798+
} else if (lhs.getBoxOf<fir::CharBoxValue>()) {
799+
fir::factory::CharacterExprHelper{*builder, loc}.createAssign(lhs, rhs);
800+
} else {
801+
auto loadVal = builder->create<fir::LoadOp>(loc, fir::getBase(rhs));
802+
builder->create<fir::StoreOp>(loc, loadVal, fir::getBase(lhs));
803+
}
762804
}
763805

764806
if (copyAssignIP && copyAssignIP->isSet() &&

flang/test/Lower/OpenMP/firstprivate-commonblock.f90

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@
1515
!CHECK: omp.parallel {
1616
!CHECK: %[[val_7:.*]] = fir.alloca f32 {bindc_name = "x", pinned, uniq_name = "_QFfirstprivate_commonEx"}
1717
!CHECK: %[[VAL_7_DECL:.*]]:2 = hlfir.declare %[[val_7]] {uniq_name = "_QFfirstprivate_commonEx"} : (!fir.ref<f32>) -> (!fir.ref<f32>, !fir.ref<f32>)
18-
!CHECK: %[[val_8:.*]] = fir.load %[[VAL_3_DECL]]#1 : !fir.ref<f32>
19-
!CHECK: fir.store %[[val_8]] to %[[VAL_7_DECL]]#1 : !fir.ref<f32>
18+
!CHECK: %[[val_8:.*]] = fir.load %[[VAL_3_DECL]]#0 : !fir.ref<f32>
19+
!CHECK: hlfir.assign %[[val_8]] to %[[VAL_7_DECL]]#0 temporary_lhs : f32, !fir.ref<f32>
2020
!CHECK: %[[val_9:.*]] = fir.alloca f32 {bindc_name = "y", pinned, uniq_name = "_QFfirstprivate_commonEy"}
2121
!CHECK: %[[VAL_9_DECL:.*]]:2 = hlfir.declare %[[val_9]] {uniq_name = "_QFfirstprivate_commonEy"} : (!fir.ref<f32>) -> (!fir.ref<f32>, !fir.ref<f32>)
22-
!CHECK: %[[val_10:.*]] = fir.load %[[VAL_6_DECL]]#1 : !fir.ref<f32>
23-
!CHECK: fir.store %[[val_10]] to %[[VAL_9_DECL]]#1 : !fir.ref<f32>
22+
!CHECK: %[[val_10:.*]] = fir.load %[[VAL_6_DECL]]#0 : !fir.ref<f32>
23+
!CHECK: hlfir.assign %[[val_10]] to %[[VAL_9_DECL]]#0 temporary_lhs : f32, !fir.ref<f32>
2424
!CHECK: omp.terminator
2525
!CHECK: }
2626
!CHECK: return

flang/test/Lower/OpenMP/lastprivate-commonblock.f90

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818
!CHECK: omp.wsloop for (%[[I:.*]]) : i32 = (%{{.*}}) to (%{{.*}}) inclusive step (%{{.*}}) {
1919
!CHECK: %[[LAST_ITER:.*]] = arith.cmpi eq, %[[I]], %{{.*}} : i32
2020
!CHECK: fir.if %[[LAST_ITER]] {
21-
!CHECK: %[[PRIVATE_X_VAL:.*]] = fir.load %[[PRIVATE_X_DECL]]#1 : !fir.ref<f32>
22-
!CHECK: fir.store %[[PRIVATE_X_VAL]] to %[[X_DECL]]#1 : !fir.ref<f32>
23-
!CHECK: %[[PRIVATE_Y_VAL:.*]] = fir.load %[[PRIVATE_Y_DECL]]#1 : !fir.ref<f32>
24-
!CHECK: fir.store %[[PRIVATE_Y_VAL]] to %[[Y_DECL]]#1 : !fir.ref<f32>
21+
!CHECK: %[[PRIVATE_X_VAL:.*]] = fir.load %[[PRIVATE_X_DECL]]#0 : !fir.ref<f32>
22+
!CHECK: hlfir.assign %[[PRIVATE_X_VAL]] to %[[X_DECL]]#0 temporary_lhs : f32, !fir.ref<f32>
23+
!CHECK: %[[PRIVATE_Y_VAL:.*]] = fir.load %[[PRIVATE_Y_DECL]]#0 : !fir.ref<f32>
24+
!CHECK: hlfir.assign %[[PRIVATE_Y_VAL]] to %[[Y_DECL]]#0 temporary_lhs : f32, !fir.ref<f32>
2525
!CHECK: }
2626
!CHECK: omp.yield
2727
!CHECK: }

flang/test/Lower/OpenMP/parallel-wsloop-firstpriv.f90

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ subroutine omp_do_firstprivate(a)
1515
! CHECK: %[[I_PVT_DECL:.*]]:2 = hlfir.declare %[[I_PVT_REF]] {uniq_name = "_QFomp_do_firstprivateEi"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
1616
! CHECK: %[[A_PVT_REF:.*]] = fir.alloca i32 {bindc_name = "a", pinned, uniq_name = "_QFomp_do_firstprivateEa"}
1717
! CHECK: %[[A_PVT_DECL:.*]]:2 = hlfir.declare %[[A_PVT_REF]] {uniq_name = "_QFomp_do_firstprivateEa"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
18-
! CHECK-NEXT: %[[LD:.*]] = fir.load %[[ARG0_DECL]]#1 : !fir.ref<i32>
19-
! CHECK-NEXT: fir.store %[[LD]] to %[[A_PVT_DECL]]#1 : !fir.ref<i32>
18+
! CHECK-NEXT: %[[LD:.*]] = fir.load %[[ARG0_DECL]]#0 : !fir.ref<i32>
19+
! CHECK-NEXT: hlfir.assign %[[LD]] to %[[A_PVT_DECL]]#0 temporary_lhs : i32, !fir.ref<i32>
2020
! CHECK: %[[LB:.*]] = arith.constant 1 : i32
2121
! CHECK-NEXT: %[[UB:.*]] = fir.load %[[A_PVT_DECL]]#0 : !fir.ref<i32>
2222
! CHECK-NEXT: %[[STEP:.*]] = arith.constant 1 : i32
@@ -45,12 +45,12 @@ subroutine omp_do_firstprivate2(a, n)
4545
! CHECK: %[[I_PVT_DECL:.*]]:2 = hlfir.declare %[[I_PVT_REF]] {uniq_name = "_QFomp_do_firstprivate2Ei"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
4646
! CHECK: %[[A_PVT_REF:.*]] = fir.alloca i32 {bindc_name = "a", pinned
4747
! CHECK: %[[A_PVT_DECL:.*]]:2 = hlfir.declare %[[A_PVT_REF]] {uniq_name = "_QFomp_do_firstprivate2Ea"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
48-
! CHECK: %[[LD:.*]] = fir.load %[[ARG0_DECL]]#1 : !fir.ref<i32>
49-
! CHECK: fir.store %[[LD]] to %[[A_PVT_DECL]]#1 : !fir.ref<i32>
48+
! CHECK: %[[LD:.*]] = fir.load %[[ARG0_DECL]]#0 : !fir.ref<i32>
49+
! CHECK: hlfir.assign %[[LD]] to %[[A_PVT_DECL]]#0 temporary_lhs : i32, !fir.ref<i32>
5050
! CHECK: %[[N_PVT_REF:.*]] = fir.alloca i32 {bindc_name = "n", pinned, uniq_name = "_QFomp_do_firstprivate2En"}
5151
! CHECK: %[[N_PVT_DECL:.*]]:2 = hlfir.declare %[[N_PVT_REF]] {uniq_name = "_QFomp_do_firstprivate2En"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
52-
! CHECK: %[[LD1:.*]] = fir.load %[[ARG1_DECL]]#1 : !fir.ref<i32>
53-
! CHECK: fir.store %[[LD1]] to %[[N_PVT_DECL]]#1 : !fir.ref<i32>
52+
! CHECK: %[[LD1:.*]] = fir.load %[[ARG1_DECL]]#0 : !fir.ref<i32>
53+
! CHECK: hlfir.assign %[[LD1]] to %[[N_PVT_DECL]]#0 temporary_lhs : i32, !fir.ref<i32>
5454

5555

5656
! CHECK: %[[LB:.*]] = fir.load %[[A_PVT_DECL]]#0 : !fir.ref<i32>

flang/test/Lower/OpenMP/sections.f90

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ end program sample
9090
!CHECK: omp.section {
9191
!CHECK: %[[PRIVATE_ALPHA:.*]] = fir.alloca f32 {bindc_name = "alpha", pinned, uniq_name = "_QFfirstprivateEalpha"}
9292
!CHECK: %[[PRIVATE_ALPHA_DECL:.*]]:2 = hlfir.declare %[[PRIVATE_ALPHA]] {uniq_name = "_QFfirstprivateEalpha"} : (!fir.ref<f32>) -> (!fir.ref<f32>, !fir.ref<f32>)
93-
!CHECK: %[[TEMP:.*]] = fir.load %[[ARG_DECL]]#1 : !fir.ref<f32>
94-
!CHECK: fir.store %[[TEMP]] to %[[PRIVATE_ALPHA_DECL]]#1 : !fir.ref<f32>
93+
!CHECK: %[[TEMP:.*]] = fir.load %[[ARG_DECL]]#0 : !fir.ref<f32>
94+
!CHECK: hlfir.assign %[[TEMP]] to %[[PRIVATE_ALPHA_DECL]]#0 temporary_lhs : f32, !fir.ref<f32>
9595
!CHECK: omp.terminator
9696
!CHECK: }
9797
!CHECK: omp.terminator
@@ -147,8 +147,8 @@ subroutine lastprivate()
147147
!CHECK: %[[RESULT:.*]] = arith.addi %[[TEMP]], %[[CONST]] : i32
148148
!CHECK: hlfir.assign %[[RESULT]] to %[[PRIVATE_X_DECL]]#0 : i32, !fir.ref<i32>
149149
!CHECK: fir.if %[[TRUE]] {
150-
!CHECK: %[[TEMP1:.*]] = fir.load %[[PRIVATE_X_DECL]]#1 : !fir.ref<i32>
151-
!CHECK: fir.store %[[TEMP1]] to %[[X_DECL]]#1 : !fir.ref<i32>
150+
!CHECK: %[[TEMP1:.*]] = fir.load %[[PRIVATE_X_DECL]]#0 : !fir.ref<i32>
151+
!CHECK: hlfir.assign %[[TEMP1]] to %[[X_DECL]]#0 temporary_lhs : i32, !fir.ref<i32>
152152
!CHECK: }
153153
!CHECK: omp.terminator
154154
!CHECK: }
@@ -163,8 +163,8 @@ subroutine lastprivate()
163163
!CHECK: omp.section {
164164
!CHECK: %[[PRIVATE_X:.*]] = fir.alloca i32 {bindc_name = "x", pinned, uniq_name = "_QFlastprivateEx"}
165165
!CHECK: %[[PRIVATE_X_DECL:.*]]:2 = hlfir.declare %[[PRIVATE_X]] {uniq_name = "_QFlastprivateEx"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
166-
!CHECK: %[[TEMP:.*]] = fir.load %[[X_DECL]]#1 : !fir.ref<i32>
167-
!CHECK: fir.store %[[TEMP]] to %[[PRIVATE_X_DECL]]#1 : !fir.ref<i32>
166+
!CHECK: %[[TEMP:.*]] = fir.load %[[X_DECL]]#0 : !fir.ref<i32>
167+
!CHECK: hlfir.assign %[[TEMP]] to %[[PRIVATE_X_DECL]]#0 temporary_lhs : i32, !fir.ref<i32>
168168
!CHECK: omp.barrier
169169
!CHECK: %[[CONST:.*]] = arith.constant 10 : i32
170170
!CHECK: %[[TEMP:.*]] = fir.load %[[PRIVATE_X_DECL]]#0 : !fir.ref<i32>
@@ -177,17 +177,17 @@ subroutine lastprivate()
177177
!CHECK: omp.section {
178178
!CHECK: %[[PRIVATE_X:.*]] = fir.alloca i32 {bindc_name = "x", pinned, uniq_name = "_QFlastprivateEx"}
179179
!CHECK: %[[PRIVATE_X_DECL:.*]]:2 = hlfir.declare %[[PRIVATE_X]] {uniq_name = "_QFlastprivateEx"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
180-
!CHECK: %[[TEMP:.*]] = fir.load %[[X_DECL]]#1 : !fir.ref<i32>
181-
!CHECK: fir.store %[[TEMP]] to %[[PRIVATE_X_DECL]]#1 : !fir.ref<i32>
180+
!CHECK: %[[TEMP:.*]] = fir.load %[[X_DECL]]#0 : !fir.ref<i32>
181+
!CHECK: hlfir.assign %[[TEMP]] to %[[PRIVATE_X_DECL]]#0 temporary_lhs : i32, !fir.ref<i32>
182182
!CHECK: omp.barrier
183183
!CHECK: %[[TRUE:.*]] = arith.constant true
184184
!CHECK: %[[TEMP:.*]] = fir.load %[[PRIVATE_X_DECL]]#0 : !fir.ref<i32>
185185
!CHECK: %[[CONST:.*]] = arith.constant 1 : i32
186186
!CHECK: %[[RESULT:.*]] = arith.addi %[[TEMP]], %[[CONST]] : i32
187187
!CHECK: hlfir.assign %[[RESULT]] to %[[PRIVATE_X_DECL]]#0 : i32, !fir.ref<i32>
188188
!CHECK: fir.if %[[TRUE]] {
189-
!CHECK: %[[TEMP:.*]] = fir.load %[[PRIVATE_X_DECL]]#1 : !fir.ref<i32>
190-
!CHECK: fir.store %[[TEMP]] to %[[X_DECL]]#1 : !fir.ref<i32>
189+
!CHECK: %[[TEMP:.*]] = fir.load %[[PRIVATE_X_DECL]]#0 : !fir.ref<i32>
190+
!CHECK: hlfir.assign %[[TEMP]] to %[[X_DECL]]#0 temporary_lhs : i32, !fir.ref<i32>
191191
!CHECK: }
192192
!CHECK: omp.terminator
193193
!CHECK: }
@@ -202,8 +202,8 @@ subroutine lastprivate()
202202
!CHECK: omp.section {
203203
!CHECK: %[[PRIVATE_X:.*]] = fir.alloca i32 {bindc_name = "x", pinned, uniq_name = "_QFlastprivateEx"}
204204
!CHECK: %[[PRIVATE_X_DECL:.*]]:2 = hlfir.declare %[[PRIVATE_X]] {uniq_name = "_QFlastprivateEx"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
205-
!CHECK: %[[TEMP:.*]] = fir.load %[[X_DECL]]#1 : !fir.ref<i32>
206-
!CHECK: fir.store %[[TEMP]] to %[[PRIVATE_X_DECL]]#1 : !fir.ref<i32>
205+
!CHECK: %[[TEMP:.*]] = fir.load %[[X_DECL]]#0 : !fir.ref<i32>
206+
!CHECK: hlfir.assign %[[TEMP]] to %[[PRIVATE_X_DECL]]#0 temporary_lhs : i32, !fir.ref<i32>
207207
!CHECK: omp.barrier
208208
!CHECK: %[[CONST:.*]] = arith.constant 10 : i32
209209
!CHECK: %[[TEMP:.*]] = fir.load %[[PRIVATE_X_DECL]]#0 : !fir.ref<i32>
@@ -216,17 +216,17 @@ subroutine lastprivate()
216216
!CHECK: omp.section {
217217
!CHECK: %[[PRIVATE_X:.*]] = fir.alloca i32 {bindc_name = "x", pinned, uniq_name = "_QFlastprivateEx"}
218218
!CHECK: %[[PRIVATE_X_DECL:.*]]:2 = hlfir.declare %[[PRIVATE_X]] {uniq_name = "_QFlastprivateEx"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
219-
!CHECK: %[[TEMP:.*]] = fir.load %[[X_DECL]]#1 : !fir.ref<i32>
220-
!CHECK: fir.store %[[TEMP]] to %[[PRIVATE_X_DECL]]#1 : !fir.ref<i32>
219+
!CHECK: %[[TEMP:.*]] = fir.load %[[X_DECL]]#0 : !fir.ref<i32>
220+
!CHECK: hlfir.assign %[[TEMP]] to %[[PRIVATE_X_DECL]]#0 temporary_lhs : i32, !fir.ref<i32>
221221
!CHECK: omp.barrier
222222
!CHECK: %[[TRUE:.*]] = arith.constant true
223223
!CHECK: %[[TEMP:.*]] = fir.load %[[PRIVATE_X_DECL]]#0 : !fir.ref<i32>
224224
!CHECK: %[[CONST:.*]] = arith.constant 1 : i32
225225
!CHECK: %[[RESULT:.*]] = arith.addi %[[TEMP]], %[[CONST]] : i32
226226
!CHECK: hlfir.assign %[[RESULT]] to %[[PRIVATE_X_DECL]]#0 : i32, !fir.ref<i32>
227227
!CHECK: fir.if %[[TRUE]] {
228-
!CHECK: %[[TEMP:.*]] = fir.load %[[PRIVATE_X_DECL]]#1 : !fir.ref<i32>
229-
!CHECK: fir.store %[[TEMP]] to %[[X_DECL]]#1 : !fir.ref<i32>
228+
!CHECK: %[[TEMP:.*]] = fir.load %[[PRIVATE_X_DECL]]#0 : !fir.ref<i32>
229+
!CHECK: hlfir.assign %[[TEMP]] to %[[X_DECL]]#0 temporary_lhs : i32, !fir.ref<i32>
230230
!CHECK: omp.barrier
231231
!CHECK: }
232232
!CHECK: omp.terminator
@@ -247,8 +247,8 @@ subroutine lastprivate()
247247
!CHECK: %[[CONST:.*]] = arith.constant 1 : i32
248248
!CHECK: %[[RESULT:.*]] = arith.addi %[[INNER_PRIVATE_X]], %[[CONST]] : i32
249249
!CHECK: hlfir.assign %[[RESULT]] to %[[PRIVATE_X_DECL]]#0 : i32, !fir.ref<i32>
250-
!CHECK: %[[LOADED_VALUE:.*]] = fir.load %[[PRIVATE_X_DECL]]#1 : !fir.ref<i32>
251-
!CHECK: fir.store %[[LOADED_VALUE]] to %[[X_DECL]]#1 : !fir.ref<i32>
250+
!CHECK: %[[LOADED_VALUE:.*]] = fir.load %[[PRIVATE_X_DECL]]#0 : !fir.ref<i32>
251+
!CHECK: hlfir.assign %[[LOADED_VALUE]] to %[[X_DECL]]#0 temporary_lhs : i32, !fir.ref<i32>
252252
!CHECK: omp.terminator
253253
!CHECK: }
254254
!CHECK: omp.terminator
@@ -290,8 +290,8 @@ subroutine unstructured_sections_privatization()
290290
!CHECK: omp.section {
291291
!CHECK: %[[PRIVATE_X:.*]] = fir.alloca f32 {bindc_name = "x", pinned, uniq_name = "_QFunstructured_sections_privatizationEx"}
292292
!CHECK: %[[PRIVATE_X_DECL:.*]]:2 = hlfir.declare %[[PRIVATE_X]] {uniq_name = "_QFunstructured_sections_privatizationEx"} : (!fir.ref<f32>) -> (!fir.ref<f32>, !fir.ref<f32>)
293-
!CHECK: %[[TEMP:.*]] = fir.load %[[X_DECL]]#1 : !fir.ref<f32>
294-
!CHECK: fir.store %[[TEMP]] to %[[PRIVATE_X_DECL]]#1 : !fir.ref<f32>
293+
!CHECK: %[[TEMP:.*]] = fir.load %[[X_DECL]]#0 : !fir.ref<f32>
294+
!CHECK: hlfir.assign %[[TEMP]] to %[[PRIVATE_X_DECL]]#0 temporary_lhs : f32, !fir.ref<f32>
295295
!CHECK: cf.br ^bb1
296296
!CHECK: ^bb1:
297297
!CHECK: %[[INNER_PRIVATE_X:.*]] = fir.load %[[PRIVATE_X_DECL]]#0 : !fir.ref<f32>

0 commit comments

Comments
 (0)