[RegisterBankInfo] Allow to set a register class when nothing else is set
authorQuentin Colombet <qcolombet@apple.com>
Thu, 22 Dec 2016 21:56:26 +0000 (21:56 +0000)
committerQuentin Colombet <qcolombet@apple.com>
Thu, 22 Dec 2016 21:56:26 +0000 (21:56 +0000)
This is going to be needed to be able to constraint register class on
target specific instruction while the RegBankSelect pass did not run
yet.

llvm-svn: 290375

llvm/lib/CodeGen/GlobalISel/RegisterBankInfo.cpp

index 34ec509..a6c93bc 100644 (file)
@@ -224,12 +224,11 @@ const TargetRegisterClass *RegisterBankInfo::constrainGenericRegister(
     return MRI.constrainRegClass(Reg, &RC);
 
   const RegisterBank *RB = RegClassOrBank.get<const RegisterBank *>();
-  assert(RB && "Generic register does not have a register bank");
-
   // Otherwise, all we can do is ensure the bank covers the class, and set it.
-  if (!RB->covers(RC))
+  if (RB && !RB->covers(RC))
     return nullptr;
 
+  // If nothing was set or the class is simply compatible, set it.
   MRI.setRegClass(Reg, &RC);
   return &RC;
 }