[llvm] [NVTPX] Copy kernel arguments as byte array (PR #110356)

via llvm-commits llvm-commits at lists.llvm.org
Sat Sep 28 04:05:58 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-backend-nvptx

Author: Michael Kuron (mkuron)

<details>
<summary>Changes</summary>

Ensures that struct padding is not skipped, as it may contain actual data if the struct is really a union.

The patch originated from a discussion on #<!-- -->53710, and @<!-- -->Artem-B suggested I post it as a pull request. This is my first LLVM code contribution, so I may need a bit of help creating a suitable test case.

Fixes #<!-- -->53710

---
Full diff: https://github.com/llvm/llvm-project/pull/110356.diff


1 Files Affected:

- (modified) llvm/lib/Target/NVPTX/NVPTXLowerArgs.cpp (+4-1) 


``````````diff
diff --git a/llvm/lib/Target/NVPTX/NVPTXLowerArgs.cpp b/llvm/lib/Target/NVPTX/NVPTXLowerArgs.cpp
index 082546c4dd72f8..bfeac304af61b9 100644
--- a/llvm/lib/Target/NVPTX/NVPTXLowerArgs.cpp
+++ b/llvm/lib/Target/NVPTX/NVPTXLowerArgs.cpp
@@ -626,8 +626,11 @@ void NVPTXLowerArgs::handleByValParam(const NVPTXTargetMachine &TM,
     // Be sure to propagate alignment to this load; LLVM doesn't know that NVPTX
     // addrspacecast preserves alignment.  Since params are constant, this load
     // is definitely not volatile.
+    const auto StructBytes = *AllocA->getAllocationSize(DL);
+    Type *ByteType = Type::getIntNTy(Func->getContext(), 8);
+    Type *OpaqueType = ArrayType::get(ByteType, StructBytes);
     LoadInst *LI =
-        new LoadInst(StructType, ArgInParam, Arg->getName(),
+        new LoadInst(OpaqueType, ArgInParam, Arg->getName(),
                      /*isVolatile=*/false, AllocA->getAlign(), FirstInst);
     new StoreInst(LI, AllocA, FirstInst);
   }

``````````

</details>


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


More information about the llvm-commits mailing list