[Greedy Regalloc] Right way to fix last chance recoloring

I’m trying to fix an issue [GreedyRA] Assert triggered: "Non-empty but used interval" · Issue #55827 · llvm/llvm-project · GitHub.
The shortly reason of this bug is that last chance use selectOrSplit to recolor live intervals interfering with a current live interval.
The problem appears when interval is split. It results machine instructions are fixed to use new registers appeared during split process. Original VR remains with no uses.

If overall recovering process fails then rollback happens. Specifically assignment for physical register (existed before starting the “last chance recoloring”) is returned back and we assign physical register to register which is actually dead now (no uses in IR). This already looks buggy.

The crash happens later when we evict this register by some reason and regalloc complains that register without uses have non-empy live interval but we want to add it to queue.

I see two promising ways to fix/workaround this issue.
The first one would be to disable split during last chance recoloring. In the current implementation he split itself cannot help in re-coloring due to split never results in immediate assignment to any physical register (If I do not miss anything) nd current live interval never becomes empty, so processing of this live interval fails and we do roll back. So split we did will not help to recover what is the sense to do it.
However if split will not happen in selectOrSplit it may be spilled and spill may do a live interval to be empty, so it can help. However skipping spilt and going directly to spill may degrade the quality of register allocation due to we will spill assigned physical register without any evidence whether last chance recoloring for this physical register will finish successfully (we need to handle all re-coloring candidates) and without evidence that recoloring for other physical register will fail (if it passes we are ok without spilling).

Another way to fix/workaround the issue is to handle correctly split in rollback. So if split happened we should restore the assignment to physical register not to original recoloring candidate but to intervals obtained from split process and remove them from new regs to avoid adding them to be added to the queue. This more corresponds to the current behavior - split will not help to recolor but we do not force spilling.

At the moment I’m not sure what the right way to fix it, any feedback is appriciated.
Personally I tend to the second way.

Thank you,
Serguei.

Additional problem with the second approach is that I do not see a way now to detect the relationship that register is split to these ones.