[Help]: How to update the live ranges after deleting a machine instruction?


I’m trying to delete a redundant instruction (machine Non-SSA) and I’m having trouble updating the live ranges.

Consider the example,

bb.191 (%ir-block.1008):
; predecessors: %bb.183, %bb.188, %bb.190
successors: %bb.192(0x50000000), %bb.194(0x30000000); %bb.192(62.50%), %bb.194(37.50%)

%231:fr64 = FsFLD0SD

JLE_1 %bb.194, implicit killed $eflags
JMP_1 %bb.192

bb.192 (%ir-block.1023):
; predecessors: %bb.191
successors: %bb.193(0x80000000); %bb.193(100.00%)

%231:fr64 = FsFLD0SD

bb.193 (%ir-block.1024):
; predecessors: %bb.192, %bb.193
successors: %bb.194(0x04000000), %bb.193(0x7c000000); %bb.194(3.12%), %bb.193(96.88%)

%231:fr64 = nnan ninf nsz arcp contract afn reassoc VADDSDrr %231:fr64(tied-def 0), %1270:fr64, %1269:fr64

The definition for virtual register (%231) in bb.192 is redundant as the same instruction is present in bb.191.
I want to delete the redundant instruction in bb.192 so that all the uses of this definition, now point to the definition in bb.191.
How to update the Live Ranges in this case?
The redundancy is evident only during the Register Coalescing and hence my fix includes marking the instruction in bb.192 as dead and then deleting it.
I was expecting that the API “eliminateDeadDefs” in LiveRangeUpdater would handle updating the live ranges, but apparently something is wrong.
Probably “eliminateDeadDefs” is not intended for this purpose.
I was not able to find any other API which would tell me that the uses of deleted instruction (in bb.192) will now use the definition in bb.191.
Any pointers/solutions would be really helpful.


Hi Abhilash,

I am only half surprised that eliminateDeadDefs does not do what you want.

This method is expected to be called on live-ranges that are dead, i.e., that don’t have any connection to uses.
In a nutshell, this method removes the live-range of the definition and shrinks the live-ranges of the values used by this definition.

At this point, you have two options:

  • Update the interval by hand (look at LiveIntervals::handleMove for some inspiration)
  • Unmark the LiveIntervals pass as preserved in your pass and rely on it being recomputed