Skip to content

Commit 44bb5c0

Browse files
[WIP]
1 parent 728895e commit 44bb5c0

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,6 @@ void SPIRVEmitIntrinsics::insertPtrCastInstr(Instruction *I) {
290290
Value *Pointer;
291291
Type *ExpectedElementType;
292292
unsigned OperandToReplace;
293-
bool AllowCastingToChar = false;
294293

295294
StoreInst *SI = dyn_cast<StoreInst>(I);
296295
if (SI && F->getCallingConv() == CallingConv::SPIR_KERNEL &&
@@ -308,7 +307,6 @@ void SPIRVEmitIntrinsics::insertPtrCastInstr(Instruction *I) {
308307
Pointer = Arg;
309308
ExpectedElementType = IntegerType::getInt8Ty(F->getContext());
310309
OperandToReplace = 0;
311-
AllowCastingToChar = true;
312310
} else if (SI) {
313311
Pointer = SI->getPointerOperand();
314312
ExpectedElementType = SI->getValueOperand()->getType();
@@ -390,10 +388,20 @@ void SPIRVEmitIntrinsics::insertPtrCastInstr(Instruction *I) {
390388
}
391389

392390
// Do not emit spv_ptrcast if it would cast to the default pointer element
393-
// type (i8) of the same address space.
394-
if (ExpectedElementType->isIntegerTy(8) && !AllowCastingToChar)
391+
// type (i8) of the same address space. In case of OpenCL kernels, make sure
392+
// i8 is the pointer element type defined for the given kernel argument.
393+
if (ExpectedElementType->isIntegerTy(8) &&
394+
F->getCallingConv() != CallingConv::SPIR_KERNEL)
395395
return;
396396

397+
Argument *Arg = dyn_cast<Argument>(Pointer);
398+
if (ExpectedElementType->isIntegerTy(8) &&
399+
F->getCallingConv() == CallingConv::SPIR_KERNEL && Arg) {
400+
MDString *ArgType = getOCLKernelArgType(*Arg->getParent(), Arg->getArgNo());
401+
if (ArgType && ArgType->getString().starts_with("uchar*"))
402+
return;
403+
}
404+
397405
// If this would be the first spv_ptrcast, the pointer's defining instruction
398406
// requires spv_assign_ptr_type and does not already have one, do not emit
399407
// spv_ptrcast and emit spv_assign_ptr_type instead.

0 commit comments

Comments
 (0)