This is an archive of the discontinued LLVM Phabricator instance.

[flang] Avoid copyin/copyout if the actual argument is contiguous at runtime
ClosedPublic

Authored by clementval on Sep 1 2022, 1:24 AM.

Details

Summary

This patch adds contiguity check with the runtime to avoid copyin/copyout
in case the actual argument is actually contiguous.

Diff Detail

Event Timeline

clementval created this revision.Sep 1 2022, 1:24 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald Transcript
Herald added a subscriber: mehdi_amini. · View Herald Transcript
clementval requested review of this revision.Sep 1 2022, 1:24 AM
clementval added inline comments.Sep 1 2022, 1:29 AM
flang/lib/Lower/ConvertExpr.cpp
2852

Currently a single call to IsContiguous is made.

call runtime
if present
  if contiguous
    // no copy
  else
    copy
end


if present && !contiguous
  copyout

Would it make sense to nest it in the first if so it is not performed when an arg is not present or so on? It would require an extra call when the first condition is true but no call when it is false.

if present
  call runtime
  if contiguous
    no copy
  else
    copy
  end
end

if present
  call runtime
  if !contiguous
    copyout
  end
end

Logic looks good to me. One suggestion to maybe simplify the copy-out lowering code a bit.

flang/lib/Lower/ConvertExpr.cpp
2819

I do not think a new value here, you can still use "restrictCopyAndFreeAtRuntime" and leave the copy-out code unmodified if you compute restrictCopyAndFreeAtRuntime = isContiguous || restrictCopyAndFreeAtRuntime before building the CopyOut pairs.

clementval retitled this revision from [flang] Avoid copyin/copyout is the actual argument is contiguous at runtime to [flang] Avoid copyin/copyout if the actual argument is contiguous at runtime.Sep 1 2022, 3:53 AM
jeanPerier added inline comments.Sep 1 2022, 4:06 AM
flang/lib/Lower/ConvertExpr.cpp
2852

The runtime should not spend too much time on arguments that are not present since a nullptr descriptor should be passed. I am not sure doing the runtime call twice in the other cases wouldn't be a worse drawback.
So I think it is best to keep it the way you did it.

clementval updated this revision to Diff 457259.Sep 1 2022, 7:07 AM

Get rid of extra value in the CopyOutPair.

clementval marked 2 inline comments as done.Sep 1 2022, 7:26 AM
This revision is now accepted and ready to land.Sep 1 2022, 9:45 AM