@@ -250,6 +250,8 @@ PackArrayConversion::genRepackedBox(fir::FirOpBuilder &builder,
250250
251251 fir::IfOp ifOp =
252252 builder.create <fir::IfOp>(loc, boxType, doPack, /* withElseRegion=*/ true );
253+ // Assume that the repacking is unlikely.
254+ ifOp.setUnlikelyIfWeights ();
253255
254256 // Return original box.
255257 builder.setInsertionPointToStart (&ifOp.getElseRegion ().front ());
@@ -322,20 +324,24 @@ UnpackArrayConversion::matchAndRewrite(fir::UnpackArrayOp op,
322324
323325 auto isNotSame = builder.genPtrCompare (loc, mlir::arith::CmpIPredicate::ne,
324326 tempAddr, originalAddr);
325- builder.genIfThen (loc, isNotSame).genThen ([&]() {});
326- // Copy from temporary to the original.
327- if (!op.getNoCopy ())
328- fir::runtime::genShallowCopy (builder, loc, originalBox, tempBox,
329- /* resultIsAllocated=*/ true );
330-
331- // Deallocate, if it was allocated in heap.
332- // Note that the stack attribute does not always mean
333- // that the allocation was actually done in stack memory.
334- // There are currently cases where we delegate the allocation
335- // to the runtime that uses heap memory, even when the stack
336- // attribute is set on fir.pack_array.
337- if (!op.getStack () || !canAllocateTempOnStack (originalBox))
338- builder.create <fir::FreeMemOp>(loc, tempAddr);
327+ builder.genIfThen (loc, isNotSame)
328+ .genThen ([&]() {
329+ // Copy from temporary to the original.
330+ if (!op.getNoCopy ())
331+ fir::runtime::genShallowCopy (builder, loc, originalBox, tempBox,
332+ /* resultIsAllocated=*/ true );
333+
334+ // Deallocate, if it was allocated in heap.
335+ // Note that the stack attribute does not always mean
336+ // that the allocation was actually done in stack memory.
337+ // There are currently cases where we delegate the allocation
338+ // to the runtime that uses heap memory, even when the stack
339+ // attribute is set on fir.pack_array.
340+ if (!op.getStack () || !canAllocateTempOnStack (originalBox))
341+ builder.create <fir::FreeMemOp>(loc, tempAddr);
342+ })
343+ .getIfOp ()
344+ .setUnlikelyIfWeights ();
339345 });
340346 rewriter.eraseOp (op);
341347 return mlir::success ();
0 commit comments