This is in preparation to https://reviews.llvm.org/D23097 which uncovered some problems in the way AMDGPU uses the register scavenger in SIRegisterInfo::spillSGPR()/SIRegisterInfo::restoreSGPR().
- The current code does not use the register scavenger correctly:
- RS->isRegUsed() always reports true for m0 because it is a reserved register.
- Even if m0 was not reserved RS->isRegUsed() would give you information about the position where we are scavenging a register. This is not actually the position where the spill/reload will be inserted.
- Spilling m0 creates a new vreg. This is sketchy as that happens at a time when the register scavenger is already spilling/reloading to free registers for vreg assignment. If there is no free physreg at that place we end up in an endless loop (because m0 is always reported as reserved, see above). The existing tests are lucky to not hit the case with D23097 applied one is hit.
This changes the code to assume that m0 is available since it is
reserved so we shouldn't have any longer liveranges crossing potential
spill/reload places.