-
Notifications
You must be signed in to change notification settings - Fork 16.2k
[AMDGPU] Scavenge a VGPR to eliminate a frame index #166979
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2983,10 +2983,36 @@ bool SIRegisterInfo::eliminateFrameIndex(MachineBasicBlock::iterator MI, | |
| : RS->scavengeRegisterBackwards(AMDGPU::SReg_32_XM0RegClass, | ||
| MI, false, 0, !UseSGPR); | ||
|
|
||
| // TODO: for flat scratch another attempt can be made with a VGPR index | ||
| // if no SGPRs can be scavenged. | ||
| if ((!TmpSReg && !FrameReg) || (!TmpReg && !UseSGPR)) | ||
| if ((!TmpSReg && !FrameReg) || (!TmpReg && !UseSGPR)) { | ||
| int SVOpcode = AMDGPU::getFlatScratchInstSVfromSS(MI->getOpcode()); | ||
| if (ST.hasFlatScratchSVSMode() && SVOpcode != -1) { | ||
| Register TmpVGPR = RS->scavengeRegisterBackwards( | ||
| AMDGPU::VGPR_32RegClass, MI, false, 0, /*AllowSpill=*/true); | ||
|
|
||
| // Materialize the frame register. | ||
| auto MIB = | ||
| BuildMI(*MBB, MI, DL, TII->get(AMDGPU::V_MOV_B32_e32), TmpVGPR); | ||
| if (FrameReg) | ||
| MIB.addReg(FrameReg); | ||
| else | ||
| MIB.addImm(Offset); | ||
|
|
||
| // Add the offset to the frame register. | ||
| if (FrameReg && Offset) | ||
| BuildMI(*MBB, MI, DL, TII->get(AMDGPU::V_ADD_U32_e32), FrameReg) | ||
| .addReg(FrameReg, RegState::Kill) | ||
| .addImm(Offset); | ||
|
Comment on lines
+3001
to
+3004
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How is this valid? Frame reg is an SGPR, and this is writing to it with a VALU instruction. Offset is also an immediate, and cannot be used in src1 of V_ADD_U32_e32. |
||
|
|
||
| BuildMI(*MBB, MI, DL, TII->get(SVOpcode)) | ||
| .add(MI->getOperand(0)) // $vdata | ||
| .addReg(TmpVGPR) // $vaddr | ||
| .addImm(0) // Offset | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should try to split the constant offset component into the addressing mode, and separately add as required above |
||
| .add(*TII->getNamedOperand(*MI, AMDGPU::OpName::cpol)); | ||
| MI->eraseFromParent(); | ||
| return true; | ||
| } | ||
| report_fatal_error("Cannot scavenge register in FI elimination!"); | ||
| } | ||
|
|
||
| if (!TmpSReg) { | ||
| // Use frame register and restore it after. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a MIR test for this, there are many samples stressing spill pseudo situations