@@ -3186,36 +3186,35 @@ bool SIRegisterInfo::eliminateFrameIndex(MachineBasicBlock::iterator MI,
31863186 // Fallback: If we need an SGPR but cannot scavenge one and there is no
31873187 // frame register, try to convert the flat-scratch instruction to use a
31883188 // VGPR index (SS -> SV) and materialize the offset in a VGPR.
3189- if (!TmpSReg && !FrameReg && TII->isFLATScratch (*MI)) {
3189+ unsigned Opc = MI->getOpcode ();
3190+ int NewOpc = AMDGPU::getFlatScratchInstSVfromSS (Opc);
3191+ if (!TmpSReg && !FrameReg && TII->isFLATScratch (*MI) && NewOpc != -1 ) {
31903192 // Reuse an existing VGPR temp if available, otherwise scavenge one.
31913193 Register VTmp = (!UseSGPR && TmpReg)
31923194 ? TmpReg
31933195 : RS->scavengeRegisterBackwards (
3194- AMDGPU::VGPR_32RegClass, MI, false , 0 );
3196+ AMDGPU::VGPR_32RegClass, MI,
3197+ /* RestoreAfter=*/ false , /* SPAdj=*/ 0 );
31953198 if (VTmp) {
31963199 // Put the large offset into a VGPR and zero the immediate offset.
31973200 BuildMI (*MBB, MI, DL, TII->get (AMDGPU::V_MOV_B32_e32), VTmp)
31983201 .addImm (Offset);
31993202
3200- unsigned Opc = MI->getOpcode ();
3201- int NewOpc = AMDGPU::getFlatScratchInstSVfromSS (Opc);
3202- if (NewOpc != -1 ) {
3203- int OldSAddrIdx =
3204- AMDGPU::getNamedOperandIdx (Opc, AMDGPU::OpName::saddr);
3205- int NewVAddrIdx =
3206- AMDGPU::getNamedOperandIdx (NewOpc, AMDGPU::OpName::vaddr);
3207- if (OldSAddrIdx == NewVAddrIdx && OldSAddrIdx >= 0 ) {
3208- MI->setDesc (TII->get (NewOpc));
3209- // Replace former saddr (now vaddr) with the VGPR index.
3210- MI->getOperand (NewVAddrIdx).ChangeToRegister (VTmp, false );
3211- // Reset the immediate offset to 0 as it is now in vaddr.
3212- MachineOperand *OffOp =
3213- TII->getNamedOperand (*MI, AMDGPU::OpName::offset);
3214- assert (OffOp && " Flat scratch SV form must have offset operand" );
3215- OffOp->setImm (0 );
3216- return false ;
3217- }
3218- }
3203+ int OldSAddrIdx =
3204+ AMDGPU::getNamedOperandIdx (Opc, AMDGPU::OpName::saddr);
3205+ int NewVAddrIdx =
3206+ AMDGPU::getNamedOperandIdx (NewOpc, AMDGPU::OpName::vaddr);
3207+
3208+ assert (OldSAddrIdx >= 0 && NewVAddrIdx >= 0 &&
3209+ " Invalid address operand indexes" );
3210+ MI->setDesc (TII->get (NewOpc));
3211+ MI->getOperand (NewVAddrIdx).ChangeToRegister (VTmp, false );
3212+ MachineOperand *OffOp =
3213+ TII->getNamedOperand (*MI, AMDGPU::OpName::offset);
3214+
3215+ assert (OffOp && " Flat scratch SV form must have offset operand" );
3216+ OffOp->setImm (0 );
3217+ return false ;
32193218 }
32203219 }
32213220
0 commit comments