[llvm] [NVTPX] Copy kernel arguments as byte array (PR #110356)
Michael Kuron via llvm-commits
llvm-commits at lists.llvm.org
Sat Sep 28 04:05:04 PDT 2024
https://github.com/mkuron created https://github.com/llvm/llvm-project/pull/110356
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
>From f5f37e904b115310e837df7fbc03acfa9c6f64a0 Mon Sep 17 00:00:00 2001
From: Michael Kuron <m.kuron at gmx.de>
Date: Sat, 28 Sep 2024 12:57:43 +0200
Subject: [PATCH] [NVTPX] Copy kernel arguments as byte array
Ensures that struct padding is not skipped, as it may contain actual
data if the struct is really a union.
Fixes #53710
---
llvm/lib/Target/NVPTX/NVPTXLowerArgs.cpp | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
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);
}
More information about the llvm-commits
mailing list