diff options
Diffstat (limited to 'flang/lib/Optimizer/CodeGen/LowerRepackArrays.cpp')
| -rw-r--r-- | flang/lib/Optimizer/CodeGen/LowerRepackArrays.cpp | 34 |
1 files changed, 20 insertions, 14 deletions
diff --git a/flang/lib/Optimizer/CodeGen/LowerRepackArrays.cpp b/flang/lib/Optimizer/CodeGen/LowerRepackArrays.cpp index de97a0bbc184..2774382c22bf 100644 --- a/flang/lib/Optimizer/CodeGen/LowerRepackArrays.cpp +++ b/flang/lib/Optimizer/CodeGen/LowerRepackArrays.cpp @@ -250,6 +250,8 @@ PackArrayConversion::genRepackedBox(fir::FirOpBuilder &builder, fir::IfOp ifOp = builder.create<fir::IfOp>(loc, boxType, doPack, /*withElseRegion=*/true); + // Assume that the repacking is unlikely. + ifOp.setUnlikelyIfWeights(); // Return original box. builder.setInsertionPointToStart(&ifOp.getElseRegion().front()); @@ -322,20 +324,24 @@ UnpackArrayConversion::matchAndRewrite(fir::UnpackArrayOp op, auto isNotSame = builder.genPtrCompare(loc, mlir::arith::CmpIPredicate::ne, tempAddr, originalAddr); - builder.genIfThen(loc, isNotSame).genThen([&]() {}); - // Copy from temporary to the original. - if (!op.getNoCopy()) - fir::runtime::genShallowCopy(builder, loc, originalBox, tempBox, - /*resultIsAllocated=*/true); - - // Deallocate, if it was allocated in heap. - // Note that the stack attribute does not always mean - // that the allocation was actually done in stack memory. - // There are currently cases where we delegate the allocation - // to the runtime that uses heap memory, even when the stack - // attribute is set on fir.pack_array. - if (!op.getStack() || !canAllocateTempOnStack(originalBox)) - builder.create<fir::FreeMemOp>(loc, tempAddr); + builder.genIfThen(loc, isNotSame) + .genThen([&]() { + // Copy from temporary to the original. + if (!op.getNoCopy()) + fir::runtime::genShallowCopy(builder, loc, originalBox, tempBox, + /*resultIsAllocated=*/true); + + // Deallocate, if it was allocated in heap. + // Note that the stack attribute does not always mean + // that the allocation was actually done in stack memory. + // There are currently cases where we delegate the allocation + // to the runtime that uses heap memory, even when the stack + // attribute is set on fir.pack_array. + if (!op.getStack() || !canAllocateTempOnStack(originalBox)) + builder.create<fir::FreeMemOp>(loc, tempAddr); + }) + .getIfOp() + .setUnlikelyIfWeights(); }); rewriter.eraseOp(op); return mlir::success(); |
