Page MenuHomePhabricator

RegScavenger: Fix !AllowSpill if no regs are available
Needs ReviewPublic

Authored by arsenm on Mar 26 2019, 1:47 PM.



Fixes option added in r354816.

Diff Detail

Event Timeline

arsenm created this revision.Mar 26 2019, 1:47 PM

I would have a slight preference for just:

diff --git a/llvm/lib/CodeGen/RegisterScavenging.cpp b/llvm/lib/CodeGen/RegisterScavenging.cpp
index bb19110e6d70..b9e30c579e65 100644
--- a/llvm/lib/CodeGen/RegisterScavenging.cpp
+++ b/llvm/lib/CodeGen/RegisterScavenging.cpp
@@ -554,6 +554,11 @@ unsigned RegScavenger::scavengeRegister(const TargetRegisterClass *RC,
   if (Available.any())
     Candidates = Available;

+  if (Candidates.none()) {
+    assert(!AllowSpill && "No candidates for scavenging");
+    return 0;
+  }
   // Find the register whose use is furthest away.
   MachineBasicBlock::iterator UseMI;
   unsigned SReg = findSurvivorReg(I, Candidates, 25, UseMI);

with maybe a comment on when this can happen.

Also maybe a MIR test with $reg = IMPLICIT_DEF instead of the inline asm would be nicer?

When I rebased the patches, I found I didn't hit this anymore on the testcase. It still looks like this could happen, so I'm going to try to break it again