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

Akshay Deodhar via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 23 14:23:52 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);
----------------
akshayrdeodhar wrote:

Right, the byvals which get written to will require an alloca anyway, regardless of whether they are lowered early or late. Byvals which are readonly don't need an alloca, but the standard optimization pipeline will be able to figure this out and eliminate them. 

Will allocas associated with `grid_constant` parameters, which *do* get lowered in EarlyByValCopy get eliminated though? (for example, if the pointer escapes to a device function, LLVM optimization passes probably will *not* eliminate the alloca, but writes to grid constant are undefined, and the alloca _should_ be eliminated)

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


More information about the llvm-commits mailing list