[flang-commits] [flang] [flang] Optimize assignments of multidimensional arrays (PR #146408)

Slava Zakharin via flang-commits flang-commits at lists.llvm.org
Wed Jul 2 15:47:13 PDT 2025


================
@@ -786,13 +797,59 @@ llvm::LogicalResult BroadcastAssignBufferization::matchAndRewrite(
   mlir::Value shape = hlfir::genShape(loc, builder, lhs);
   llvm::SmallVector<mlir::Value> extents =
       hlfir::getIndexExtents(loc, builder, shape);
-  hlfir::LoopNest loopNest =
-      hlfir::genLoopNest(loc, builder, extents, /*isUnordered=*/true,
-                         flangomp::shouldUseWorkshareLowering(assign));
-  builder.setInsertionPointToStart(loopNest.body);
-  auto arrayElement =
-      hlfir::getElementAt(loc, builder, lhs, loopNest.oneBasedIndices);
-  builder.create<hlfir::AssignOp>(loc, rhs, arrayElement);
+
+  bool isArrayRef =
+      mlir::isa<fir::SequenceType>(fir::unwrapRefType(lhs.getType()));
+  if (lhs.isSimplyContiguous() && extents.size() > 1 &&
----------------
vzakhari wrote:

I believe `isSimplyContiguous` may also return true for `!fir.box<!fir.ptr<...`.  I do not think you need to explicitly handle all these different cases.  There is `hlfir::derefPointersAndAllocatables` call above.  If `lhs` is a box, you may use the box_addr operation to get the base address of the array, otherwise, `lhs` is the base address of the array already.

https://github.com/llvm/llvm-project/pull/146408


More information about the flang-commits mailing list