[llvm-branch-commits] [llvm] RegAlloc: Fix verifier error after failed allocation (PR #119690)

Paul Kirth via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Fri Dec 13 10:23:10 PST 2024


================
@@ -161,6 +163,40 @@ void RegAllocBase::postOptimization() {
   DeadRemats.clear();
 }
 
+void RegAllocBase::cleanupFailedVRegs() {
+  SmallSet<Register, 8> JunkRegs;
+
+  for (Register FailedReg : FailedVRegs) {
+    JunkRegs.insert(FailedReg);
+
+    MCRegister PhysReg = VRM->getPhys(FailedReg);
+    LiveInterval &FailedInterval = LIS->getInterval(FailedReg);
+
+    // The liveness information for the failed register and anything interfering
+    // with the physical register we arbitrarily chose is junk and needs to be
+    // deleted.
+    for (MCRegUnitIterator Units(PhysReg, TRI); Units.isValid(); ++Units) {
+      LiveIntervalUnion::Query &Q = Matrix->query(FailedInterval, *Units);
+      for (const LiveInterval *InterferingReg : Q.interferingVRegs())
+        JunkRegs.insert(InterferingReg->reg());
+    }
+  }
+
+  // TODO: Probably need to set undef on any physreg uses not associated with
+  // a virtual register.
----------------
ilovepi wrote:

Aren't there places where we lower things/expand pseudos using physical regs before RegAlloc? We do some weird things for stuff like TLSDESC  where ABI dictates we use particular registers. It's not a problem in this patch, but I want to understand better if we're doing things we shouldn't in the various lowerings and should consider addressing that.

https://github.com/llvm/llvm-project/pull/119690


More information about the llvm-branch-commits mailing list