[llvm] [flang-rt] Optimise ShallowCopy and elemental copies in Assign (PR #140569)

Kajetan Puchalski via llvm-commits llvm-commits at lists.llvm.org
Mon May 19 14:40:13 PDT 2025


================
@@ -492,11 +492,21 @@ RT_API_ATTRS void Assign(Descriptor &to, const Descriptor &from,
         terminator.Crash("unexpected type code %d in blank padded Assign()",
             to.type().raw());
       }
-    } else { // elemental copies, possibly with character truncation
-      for (std::size_t n{toElements}; n-- > 0;
-           to.IncrementSubscripts(toAt), from.IncrementSubscripts(fromAt)) {
-        memmoveFct(to.Element<char>(toAt), from.Element<const char>(fromAt),
-            toElementBytes);
+    } else {
+      // We can't simply call ShallowCopy due to edge cases such as character
+      // truncation or assignments where the RHS is a scalar.
+      if (toElementBytes == fromElementBytes && to.IsContiguous()) {
+        if (to.rank() == 1 && from.rank() == 1) {
+          ShallowCopyDiscontiguousToContiguous<true>(to, from);
----------------
mrkajetanp wrote:

Do you know whether the copy-ins need more of the logic inside Assign to work properly outside of just the copy logic itself? Concern over that was the reason why I was changing it inside Assign rather than replacing the whole call to Assign.

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


More information about the llvm-commits mailing list