[PATCH] D128437: [fastregalloc] Fix bug when there is no register class.

LuoYuanke via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 23 06:02:13 PDT 2022


LuoYuanke created this revision.
Herald added subscribers: jsji, pengfei, hiraditya, qcolombet, MatzeB.
Herald added a project: All.
LuoYuanke requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

In global Isel there may be no register class for a virtual register. In
that case we can invoke MRI->getRegClass(). We should invoke
MRI->getRegClassOrNull() instead and check if it returns nullptr.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D128437

Files:
  llvm/lib/CodeGen/RegAllocFast.cpp
  llvm/lib/Target/X86/X86FastPreTileConfig.cpp
  llvm/test/DebugInfo/Generic/two-cus-from-same-file.ll


Index: llvm/test/DebugInfo/Generic/two-cus-from-same-file.ll
===================================================================
--- llvm/test/DebugInfo/Generic/two-cus-from-same-file.ll
+++ llvm/test/DebugInfo/Generic/two-cus-from-same-file.ll
@@ -5,6 +5,8 @@
 
 ; RUN: %llc_dwarf %s -o %t -filetype=obj -O0
 ; RUN: llvm-dwarfdump -debug-info %t | FileCheck %s
+; RUN: %llc_dwarf %s -o %t --global-isel -filetype=obj -O0
+; RUN: llvm-dwarfdump -debug-info %t | FileCheck %s
 
 ; ModuleID = 'test.bc'
 
Index: llvm/lib/Target/X86/X86FastPreTileConfig.cpp
===================================================================
--- llvm/lib/Target/X86/X86FastPreTileConfig.cpp
+++ llvm/lib/Target/X86/X86FastPreTileConfig.cpp
@@ -667,7 +667,10 @@
   bool HasVirtTileReg = false;
   for (unsigned I = 0, E = NumVirtRegs; I != E; ++I) {
     Register VirtReg = Register::index2VirtReg(I);
-    if (MRI->getRegClass(VirtReg)->getID() == X86::TILERegClassID) {
+    const TargetRegisterClass *RC = MRI->getRegClassOrNull(VirtReg);
+    if (!RC)
+      continue;
+    if (RC->getID() == X86::TILERegClassID) {
       HasVirtTileReg = true;
       break;
     }
Index: llvm/lib/CodeGen/RegAllocFast.cpp
===================================================================
--- llvm/lib/CodeGen/RegAllocFast.cpp
+++ llvm/lib/CodeGen/RegAllocFast.cpp
@@ -303,8 +303,12 @@
 
 bool RegAllocFast::shouldAllocateRegister(const Register Reg) const {
   assert(Register::isVirtualRegister(Reg));
-  const TargetRegisterClass &RC = *MRI->getRegClass(Reg);
-  return ShouldAllocateClass(*TRI, RC);
+  const TargetRegisterClass *RC = MRI->getRegClassOrNull(Reg);
+  // Follow the default behaviour to return true if there is no
+  // register class for the register. This may happen in gloal ISel.
+  if (!RC)
+    return true;
+  return ShouldAllocateClass(*TRI, *RC);
 }
 
 void RegAllocFast::setPhysRegState(MCPhysReg PhysReg, unsigned NewState) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D128437.439365.patch
Type: text/x-patch
Size: 1927 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220623/3e14101a/attachment.bin>


More information about the llvm-commits mailing list