[llvm] [llvm][CodeGen] Fix the issue caused by live interval checking in window scheduler (PR #123184)

Hua Tian via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 16 23:11:24 PST 2025


================
@@ -645,14 +645,17 @@ void WindowScheduler::expand() {
 
 void WindowScheduler::updateLiveIntervals() {
   SmallVector<Register, 128> UsedRegs;
-  for (MachineInstr &MI : *MBB)
+  for (MachineInstr &MI : *MBB) {
     for (const MachineOperand &MO : MI.operands()) {
       if (!MO.isReg() || MO.getReg() == 0)
         continue;
       Register Reg = MO.getReg();
       if (!is_contained(UsedRegs, Reg))
         UsedRegs.push_back(Reg);
     }
+    // Remove the residual slot index of newly cloned MI.
+    Context->LIS->RemoveMachineInstrFromMaps(MI);
----------------
huaatian wrote:

My earlier explanation might have been a bit unclear, sorry about that.
In the window scheduling algorithm, it is necessary to move the original MIs from the MBB and then place some newly cloned ones into it. If the scheduling fails, the original MIs need to be placed back into the MBB.
Each time after all MIs are placed into the MBB, we need to call updateLiveIntervals。Here are the specific codes for inserting MIs into MBB:
![image](https://github.com/user-attachments/assets/fd2d33a2-cc6c-49d2-8ff3-4d38d0b7e9b2)
![image](https://github.com/user-attachments/assets/d66d0096-3143-45ef-997e-63fc157cfe22)
![image](https://github.com/user-attachments/assets/e645391c-d967-4491-9be2-5fa637c63124)
Therefore, we place `RemoveMachineInstrFromMaps` in the `updateLiveIntervals`, calling it before the `repairIntervalsInRange`.

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


More information about the llvm-commits mailing list