[llvm-branch-commits] [flang] [llvm] [flang] - Call _FortranAAssignSimple instead of _FortranAAssign for intrinsic-type array assignments (PR #213705)

Michael Klemm via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Wed Aug 5 07:47:35 PDT 2026


================
@@ -169,10 +192,29 @@ class AssignOpConversion : public mlir::OpRewritePattern<hlfir::AssignOp> {
       // reference.
       auto toMutableBox = builder.createTemporary(loc, to.getType());
       fir::StoreOp::create(builder, loc, to, toMutableBox);
-      if (assignOp.isTemporaryLHS())
+      if (assignOp.isTemporaryLHS()) {
         fir::runtime::genAssignTemporary(builder, loc, toMutableBox, from);
-      else
-        fir::runtime::genAssign(builder, loc, toMutableBox, from);
+      } else {
+        // Use simple path for non-allocatable arrays with trivial types
+        // CRITICAL: Only use Simple path when ranks match - scalar-to-array
+        // requires broadcasting CRITICAL: Only use Simple path for non-volatile
+        // - volatile needs memory ordering NOTE: Contiguity is now handled at
+        // runtime in AssignSimple
+        if (!useFortranAssignOnly && !lhs.isPolymorphic() &&
+            fir::isa_trivial(lhs.getFortranElementType()) &&
+            lhs.getRank() == rhs.getRank() &&
+            !fir::isa_volatile_type(lhs.getType()) &&
+            !cuf::getDataAttr(lhs.getDefiningOp())) {
+          // Simple intrinsic type array with matching ranks, non-volatile,
+          // non-polymorphic. AssignSimple handles both contiguous (fast
+          // memmove) and non-contiguous (element-wise)
+          fir::runtime::genAssignSimple(builder, loc, toMutableBox, from);
+        } else {
+          // Complex: polymorphic, derived type, rank mismatch
+          // (scalar-to-array), volatile
+          fir::runtime::genAssign(builder, loc, toMutableBox, from);
+        }
----------------
mjklemm wrote:

This seems like a copy of the previous code-gen path.  Maybe split into a lambda function to avoid code drift.

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


More information about the llvm-branch-commits mailing list