Skip to content

Commit 02bf2fd

Browse files
call lowering may not know register's type
1 parent 512208b commit 02bf2fd

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

llvm/lib/Target/SPIRV/SPIRVCallLowering.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -545,13 +545,23 @@ bool SPIRVCallLowering::lowerCall(MachineIRBuilder &MIRBuilder,
545545
Register ArgReg = Arg.Regs[0];
546546
ArgVRegs.push_back(ArgReg);
547547
SPIRVType *SpvType = GR->getSPIRVTypeForVReg(ArgReg);
548-
if (!SpvType) {
548+
// If Arg.Ty is an untyped pointer (i.e., ptr [addrspace(...)]) we should
549+
// wait with setting the type for the virtual register until pre-legalizer
550+
// step when we access @llvm.spv.assign.ptr.type.p...(...)'s info.
551+
if (!SpvType && !isUntypedPointerTy(Arg.Ty)) {
549552
SpvType = GR->getOrCreateSPIRVType(Arg.Ty, MIRBuilder);
550553
GR->assignSPIRVTypeToVReg(SpvType, ArgReg, MF);
551554
}
552555
if (!MRI->getRegClassOrNull(ArgReg)) {
553-
MRI->setRegClass(ArgReg, GR->getRegClass(SpvType));
554-
MRI->setType(ArgReg, GR->getRegType(SpvType));
556+
// Either we have SpvType created, or Arg.Ty is an untyped pointer and
557+
// we know its virtual register's class and type.
558+
MRI->setRegClass(ArgReg, SpvType ? GR->getRegClass(SpvType)
559+
: &SPIRV::pIDRegClass);
560+
MRI->setType(
561+
ArgReg,
562+
SpvType ? GR->getRegType(SpvType)
563+
: LLT::pointer(cast<PointerType>(Arg.Ty)->getAddressSpace(),
564+
GR->getPointerSize()));
555565
}
556566
}
557567
auto instructionSet = canUseOpenCL ? SPIRV::InstructionSet::OpenCL_std

0 commit comments

Comments
 (0)