@@ -2745,17 +2745,20 @@ void SITargetLowering::allocatePreloadKernArgSGPRs(
27452745 // Arg is preloaded into the previous SGPR.
27462746 if (ArgLoc.getLocVT().getStoreSize() < 4 && Alignment < 4) {
27472747 assert(InIdx >= 1 && "No previous SGPR");
2748- auto [It, Inserted] =
2749- Info.getArgInfo().PreloadKernArgs.try_emplace(InIdx);
2750- assert(Inserted && "Preload kernel argument allocated twice.");
2751- KernArgPreloadDescriptor &PreloadDesc = It->second;
2752-
2753- const KernArgPreloadDescriptor &PrevDesc =
2754- Info.getArgInfo().PreloadKernArgs[InIdx - 1];
2748+ auto &PreloadKernArgs = Info.getArgInfo().PreloadKernArgs;
2749+ PreloadKernArgs.grow(InIdx);
2750+ KernArgPreloadDescriptor &PreloadDesc = PreloadKernArgs[InIdx];
2751+ assert(!PreloadDesc.IsValid &&
2752+ "Preload kernel argument allocated twice.");
2753+
2754+ const KernArgPreloadDescriptor &PrevDesc = PreloadKernArgs[InIdx - 1];
2755+ assert(PrevDesc.IsValid &&
2756+ "Previous preload kernel argument not allocated.");
27552757 PreloadDesc.Regs.push_back(PrevDesc.Regs[0]);
27562758
27572759 PreloadDesc.OrigArgIdx = Arg.getArgNo();
27582760 PreloadDesc.PartIdx = InIdx;
2761+ PreloadDesc.IsValid = true;
27592762 if (Arg.hasAttribute("amdgpu-hidden-argument"))
27602763 mapHiddenArgToPreloadIndex(Info.getArgInfo(), ArgOffset,
27612764 ImplicitArgOffset, InIdx);
@@ -3183,7 +3186,9 @@ SDValue SITargetLowering::LowerFormalArguments(
31833186 }
31843187
31853188 SDValue NewArg;
3186- if (Arg.isOrigArg() && Info->getArgInfo().PreloadKernArgs.count(i)) {
3189+ auto &PreloadKernArgs = Info->getArgInfo().PreloadKernArgs;
3190+ if (Arg.isOrigArg() && PreloadKernArgs.inBounds(i) &&
3191+ PreloadKernArgs[i].IsValid) {
31873192 if (MemVT.getStoreSize() < 4 && Alignment < 4) {
31883193 // In this case the argument is packed into the previous preload SGPR.
31893194 int64_t AlignDownOffset = alignDown(Offset, 4);
@@ -3193,8 +3198,7 @@ SDValue SITargetLowering::LowerFormalArguments(
31933198 const SIMachineFunctionInfo *Info =
31943199 MF.getInfo<SIMachineFunctionInfo>();
31953200 MachineRegisterInfo &MRI = DAG.getMachineFunction().getRegInfo();
3196- Register Reg =
3197- Info->getArgInfo().PreloadKernArgs.find(i)->getSecond().Regs[0];
3201+ Register Reg = Info->getArgInfo().PreloadKernArgs[i].Regs[0];
31983202
31993203 assert(Reg);
32003204 Register VReg = MRI.getLiveInVirtReg(Reg);
@@ -3214,7 +3218,7 @@ SDValue SITargetLowering::LowerFormalArguments(
32143218 MF.getInfo<SIMachineFunctionInfo>();
32153219 MachineRegisterInfo &MRI = DAG.getMachineFunction().getRegInfo();
32163220 const SmallVectorImpl<MCRegister> &PreloadRegs =
3217- Info->getArgInfo().PreloadKernArgs.find(i)->getSecond() .Regs;
3221+ Info->getArgInfo().PreloadKernArgs[i] .Regs;
32183222
32193223 SDValue Copy;
32203224 if (PreloadRegs.size() == 1) {
0 commit comments