[PATCH] D113044: [TwoAddressInstruction] Update LiveIntervals after rewriting INSERT_SUBREG to COPY

Jay Foad via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 2 12:31:05 PDT 2021


foad created this revision.
Herald added subscribers: mstorsjo, kerbowa, hiraditya, nhaehnle, jvesely, MatzeB.
foad requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Also add subranges to an existing live interval when introducing a new
subreg def.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D113044

Files:
  llvm/lib/CodeGen/TwoAddressInstructionPass.cpp
  llvm/test/CodeGen/AMDGPU/undefined-subreg-liverange.ll


Index: llvm/test/CodeGen/AMDGPU/undefined-subreg-liverange.ll
===================================================================
--- llvm/test/CodeGen/AMDGPU/undefined-subreg-liverange.ll
+++ llvm/test/CodeGen/AMDGPU/undefined-subreg-liverange.ll
@@ -1,5 +1,6 @@
 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
 ; RUN: llc -march=amdgcn -verify-machineinstrs < %s | FileCheck %s
+; RUN: llc -march=amdgcn -verify-machineinstrs -early-live-intervals < %s | FileCheck %s
 
 ; We may have subregister live ranges that are undefined on some paths. The
 ; verifier should not complain about this.
Index: llvm/lib/CodeGen/TwoAddressInstructionPass.cpp
===================================================================
--- llvm/lib/CodeGen/TwoAddressInstructionPass.cpp
+++ llvm/lib/CodeGen/TwoAddressInstructionPass.cpp
@@ -1740,6 +1740,34 @@
         mi->RemoveOperand(1);
         mi->setDesc(TII->get(TargetOpcode::COPY));
         LLVM_DEBUG(dbgs() << "\t\tconvert to:\t" << *mi);
+
+        // Update LiveIntervals.
+        if (LIS) {
+          Register Reg = mi->getOperand(0).getReg();
+          LiveInterval &LI = LIS->getInterval(Reg);
+          if (LI.hasSubRanges()) {
+            // The COPY no longer defines subregs of %reg except for
+            // %reg.subidx.
+            LaneBitmask LaneMask =
+                TRI->getSubRegIndexLaneMask(mi->getOperand(0).getSubReg());
+            SlotIndex Idx = LIS->getInstructionIndex(*mi);
+            for (auto &S : LI.subranges()) {
+              if ((S.LaneMask & LaneMask).none()) {
+                LiveRange::iterator UseSeg = S.FindSegmentContaining(Idx);
+                LiveRange::iterator DefSeg = std::next(UseSeg);
+                S.MergeValueNumberInto(DefSeg->valno, UseSeg->valno);
+              }
+            }
+
+            // The COPY no longer has a use of %reg.
+            LIS->shrinkToUses(&LI);
+          } else {
+            // The live interval for Reg did not have subranges but now it needs
+            // them because we have introduced a subreg def. Recompute it.
+            LIS->removeInterval(Reg);
+            LIS->createAndComputeVirtRegInterval(Reg);
+          }
+        }
       }
 
       // Clear TiedOperands here instead of at the top of the loop


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D113044.384188.patch
Type: text/x-patch
Size: 2296 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211102/e11ecc1c/attachment.bin>


More information about the llvm-commits mailing list