@@ -3356,7 +3356,7 @@ class ArrayExprLowering {
33563356 auto loc = getLoc ();
33573357 // Once the loop extents have been computed, which may require being inside
33583358 // some explicit loops, lazily allocate the expression on the heap.
3359- ccPrelude = [=](llvm::ArrayRef<mlir::Value> shape) -> mlir::Value {
3359+ ccPrelude = [=](llvm::ArrayRef<mlir::Value> shape) {
33603360 auto load = builder.create <fir::LoadOp>(loc, var);
33613361 auto eleTy = fir::unwrapRefType (load.getType ());
33623362 auto unknown = fir::SequenceType::getUnknownExtent ();
@@ -3365,15 +3365,14 @@ class ArrayExprLowering {
33653365 auto toTy = fir::HeapType::get (seqTy);
33663366 auto castTo = builder.createConvert (loc, toTy, load);
33673367 auto cmp = builder.genIsNull (loc, castTo);
3368- auto ifOp = builder.create <fir::IfOp>(loc, cmp, /* withElseRegion=*/ false );
3369- auto insPt = builder.saveInsertionPoint ();
3370- builder.setInsertionPointToStart (&ifOp.thenRegion ().front ());
3371- auto mem = builder.create <fir::AllocMemOp>(loc, seqTy, " .lazy.mask" ,
3372- llvm::None, shape);
3373- auto uncast = builder.createConvert (loc, load.getType (), mem);
3374- builder.create <fir::StoreOp>(loc, uncast, var);
3375- builder.restoreInsertionPoint (insPt);
3376- return mem;
3368+ builder.genIfThen (loc, cmp)
3369+ .genThen ([&]() {
3370+ auto mem = builder.create <fir::AllocMemOp>(loc, seqTy, " .lazy.mask" ,
3371+ llvm::None, shape);
3372+ auto uncast = builder.createConvert (loc, load.getType (), mem);
3373+ builder.create <fir::StoreOp>(loc, uncast, var);
3374+ })
3375+ .end ();
33773376 };
33783377 // Create a dummy array_load before the loop. We're storing to a lazy
33793378 // temporary, so there will be no conflict and no copy-in.
@@ -3603,7 +3602,7 @@ class ArrayExprLowering {
36033602 // Mask expressions are array expressions too.
36043603 for (const auto *e : implicitSpace->getExprs ())
36053604 if (e && !implicitSpace->isLowered (e)) {
3606- if (auto var = implicitSpace->lookupVariable (e)) {
3605+ if (auto var = implicitSpace->lookupMaskVariable (e)) {
36073606 // Allocate the mask buffer lazily.
36083607 auto tmp = Fortran::lower::createLazyArrayTempValue (
36093608 converter, *e, var, symMap, stmtCtx);
@@ -3660,10 +3659,8 @@ class ArrayExprLowering {
36603659 llvm::SmallVector<mlir::Value> ivars;
36613660 if (loopDepth > 0 ) {
36623661 // Generate the lazy mask allocation, if one was given.
3663- if (ccPrelude.hasValue ()) {
3664- [[maybe_unused]] auto allocMem = ccPrelude.getValue ()(shape);
3665- assert (allocMem && " mask buffer allocation failure" );
3666- }
3662+ if (ccPrelude.hasValue ())
3663+ ccPrelude.getValue ()(shape);
36673664
36683665 auto *startBlock = builder.getBlock ();
36693666 for (auto i : llvm::enumerate (llvm::reverse (loopUppers))) {
@@ -5540,8 +5537,7 @@ class ArrayExprLowering {
55405537 Fortran::lower::SymMap &symMap;
55415538 // / The continuation to generate code to update the destination.
55425539 llvm::Optional<CC> ccStoreToDest;
5543- llvm::Optional<std::function<mlir::Value(llvm::ArrayRef<mlir::Value>)>>
5544- ccPrelude;
5540+ llvm::Optional<std::function<void (llvm::ArrayRef<mlir::Value>)>> ccPrelude;
55455541 llvm::Optional<std::function<fir::ArrayLoadOp(llvm::ArrayRef<mlir::Value>)>>
55465542 ccLoadDest;
55475543 // / The destination is the loaded array into which the results will be
0 commit comments