[llvm] [NVPTX] add an optional early copy of byval arguments (PR #113384)

Artem Belevich via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 23 16:11:13 PDT 2024


================
@@ -734,3 +739,21 @@ bool NVPTXLowerArgs::runOnFunction(Function &F) {
 }
 
 FunctionPass *llvm::createNVPTXLowerArgsPass() { return new NVPTXLowerArgs(); }
+
+static bool copyFunctionByValArgs(Function &F) {
+  LLVM_DEBUG(dbgs() << "Creating a copy of byval args of " << F.getName()
+                    << "\n");
+  bool Changed = false;
+  for (Argument &Arg : F.args())
+    if (Arg.getType()->isPointerTy() && Arg.hasByValAttr()) {
+      copyByValParam(F, Arg);
----------------
Artem-B wrote:

It looks like the missing `cvta.param` is actually an improvement.
The early copy apparently obviates the need to use `cvta.param` (e.g. see `test_select` and `test_phi` in the diff above) because LLVM managed to speculatively hoist the loads above the conditional select of pointers, and turn it into select of values. No pointers -> no problems. :-) It may not be a universal improvement, but it works nicely in this case.

I've added the check to skip early-copying `__grid_constant__` arguments, so they will not be directly affected by the early copy. I do not think I'll be able to meaningfully test it, as there's no clang-compileable CUDA code that would use the attribute, so keeping its handling unchanged makes sense.

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


More information about the llvm-commits mailing list