How to extend live interval to some instruction?

Using RISCV.

The problem

I want to extend the live intervals for registers used in store instructions to an arbitrary instruction of the function that the register is in.

For example, if I have this:

li a0, 42
sw a0, 0(sp)
li a0, 1
ret

I want to extend the live interval for a0 to ret such that the second load immediate uses a different register (i.e. doesn’t overwrite a0).

li a0, 42
sw a0, 0(sp)
li a1, 1
ret

What I tried

I used a MachineFunctionPass, created in RISCVPassConfig::addPreRegAlloc().
For each store instruction, save the live interval of the first operand register to a list:

Register Reg = MI.getOperand(0).getReg();
LiveInterval &LI = LIS->getInterval(Reg);
IntervalsVector.push_back(&LI);

When I reach the desired instruction, loop over the saved list and extend all intervals:

/* Get SlotIndex of current instruction. */
SlotIndex index = LIS->getInstructionIndex(MI).getRegSlot();

for (LiveInterval* LI : Intervals)
{
      /* Check if interval is actually extended. */
      if (LI->find(index) == LI->end())
      {
            /* Extend interval to index of current instruction. */
            LIS->extendToIndices(*LI, {index});
      }
}

Unfortunately, this doesn’t actually change the register I want to a1. I am sure the pass is running and calling extendToIndices.