[llvm] [flang-rt] Optimise ShallowCopy and elemental copies in Assign (PR #140569)
Slava Zakharin via llvm-commits
llvm-commits at lists.llvm.org
Mon May 19 14:04:54 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);
----------------
vzakhari wrote:
Unfortunately, we cannot use `ShallowCopy` as-is here, because `memmoveFct` may not match `memcpy` (e.g. see `Assign` usese in `flang-rt/lib/cuda/memory.cpp`).
I would recommend not touching `Assign` runtime just yet. We can start with optimizing the `ShallowCopy` and call it for the copy-in/copy-out in the compiler.
https://github.com/llvm/llvm-project/pull/140569
More information about the llvm-commits
mailing list