[PATCH] D91064: [MachineBasicBlock] Fix update of live intervals in splitAt

Carl Ritson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 9 19:12:37 PST 2020


critson updated this revision to Diff 304027.
critson added a comment.
Herald added a subscriber: MatzeB.

- Add tests, but these depend on D91066 <https://reviews.llvm.org/D91066>


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D91064/new/

https://reviews.llvm.org/D91064

Files:
  llvm/lib/CodeGen/MachineBasicBlock.cpp
  llvm/unittests/MI/LiveIntervalTest.cpp


Index: llvm/unittests/MI/LiveIntervalTest.cpp
===================================================================
--- llvm/unittests/MI/LiveIntervalTest.cpp
+++ llvm/unittests/MI/LiveIntervalTest.cpp
@@ -149,6 +149,19 @@
   LIS.handleMoveIntoNewBundle(*BundleStart, true);
 }
 
+/**
+ * Split block numbered \p BlockNum at instruction \p SplitAt using
+ * MachineBasicBlock::splitAt updating liveness intervals.
+ */
+static void testSplitAt(MachineFunction &MF, LiveIntervals &LIS,
+                        unsigned SplitAt, unsigned BlockNum) {
+  MachineInstr &SplitInstr = getMI(MF, SplitAt, BlockNum);
+  MachineBasicBlock &MBB = *SplitInstr.getParent();
+
+  // Split block and update live intervals
+  MBB.splitAt(SplitInstr, false, &LIS);
+}
+
 static void liveIntervalTest(StringRef MIRFunc, LiveIntervalTest T) {
   LLVMContext Context;
   std::unique_ptr<LLVMTargetMachine> TM = createTargetMachine();
@@ -608,6 +621,34 @@
   });
 }
 
+TEST(LiveIntervalTest, SplitAtOneInstruction) {
+  liveIntervalTest(R"MIR(
+    successors: %bb.1
+    %0 = IMPLICIT_DEF
+    S_BRANCH %bb.1
+  bb.1:
+    S_NOP 0
+)MIR", [](MachineFunction &MF, LiveIntervals &LIS) {
+    testSplitAt(MF, LIS, 1, 0);
+  });
+}
+
+TEST(LiveIntervalTest, SplitAtMultiInstruction) {
+  liveIntervalTest(R"MIR(
+    successors: %bb.1
+    %0 = IMPLICIT_DEF
+    S_NOP 0
+    S_NOP 0
+    S_NOP 0
+    S_NOP 0
+    S_BRANCH %bb.1
+  bb.1:
+    S_NOP 0
+)MIR", [](MachineFunction &MF, LiveIntervals &LIS) {
+    testSplitAt(MF, LIS, 0, 0);
+  });
+}
+
 int main(int argc, char **argv) {
   ::testing::InitGoogleTest(&argc, argv);
   initLLVM();
Index: llvm/lib/CodeGen/MachineBasicBlock.cpp
===================================================================
--- llvm/lib/CodeGen/MachineBasicBlock.cpp
+++ llvm/lib/CodeGen/MachineBasicBlock.cpp
@@ -984,7 +984,7 @@
     addLiveIns(*SplitBB, LiveRegs);
 
   if (LIS)
-    LIS->insertMBBInMaps(SplitBB, &MI);
+    LIS->insertMBBInMaps(SplitBB, &*SplitPoint);
 
   return SplitBB;
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D91064.304027.patch
Type: text/x-patch
Size: 2005 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201110/6a3a4667/attachment.bin>


More information about the llvm-commits mailing list