@@ -545,13 +545,23 @@ bool SPIRVCallLowering::lowerCall(MachineIRBuilder &MIRBuilder,
545
545
Register ArgReg = Arg.Regs [0 ];
546
546
ArgVRegs.push_back (ArgReg);
547
547
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 )) {
549
552
SpvType = GR->getOrCreateSPIRVType (Arg.Ty , MIRBuilder);
550
553
GR->assignSPIRVTypeToVReg (SpvType, ArgReg, MF);
551
554
}
552
555
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 ()));
555
565
}
556
566
}
557
567
auto instructionSet = canUseOpenCL ? SPIRV::InstructionSet::OpenCL_std
0 commit comments