diff --git a/llvm/lib/CodeGen/TwoAddressInstructionPass.cpp b/llvm/lib/CodeGen/TwoAddressInstructionPass.cpp --- a/llvm/lib/CodeGen/TwoAddressInstructionPass.cpp +++ b/llvm/lib/CodeGen/TwoAddressInstructionPass.cpp @@ -705,8 +705,17 @@ // exactly the same effect on liveness as the old instruction. This is much // more efficient than calling repairIntervalsInRange. bool SingleInst = std::next(MIS.begin(), 2) == MIS.end(); - if (LIS && SingleInst) - LIS->ReplaceMachineInstrInMaps(*mi, *NewMI); + if (LIS && SingleInst) { + SlotIndex Idx = LIS->ReplaceMachineInstrInMaps(*mi, *NewMI); + + // RegB was tied to RegA. If RegA is early-clobber then the live range of + // RegB would have ended at an early-clobber slot, but now they are not tied + // we need to update it to the normal register slot. + LiveInterval &LI = LIS->getInterval(RegB); + LiveRange::Segment *S = LI.getSegmentContaining(Idx); + if (S->end == Idx.getRegSlot(true)) + S->end = Idx.getRegSlot(); + } SmallVector OrigRegs; if (LIS && !SingleInst) { diff --git a/llvm/test/CodeGen/RISCV/rvv/vwadd.w-rv32.ll b/llvm/test/CodeGen/RISCV/rvv/vwadd.w-rv32.ll --- a/llvm/test/CodeGen/RISCV/rvv/vwadd.w-rv32.ll +++ b/llvm/test/CodeGen/RISCV/rvv/vwadd.w-rv32.ll @@ -1,6 +1,6 @@ ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py -; RUN: llc -mtriple=riscv32 -mattr=+experimental-v -verify-machineinstrs \ -; RUN: < %s | FileCheck %s +; RUN: llc -mtriple=riscv32 -mattr=+experimental-v -verify-machineinstrs < %s | FileCheck %s +; RUN: llc -mtriple=riscv32 -mattr=+experimental-v -verify-machineinstrs -early-live-intervals < %s | FileCheck %s declare @llvm.riscv.vwadd.w.nxv1i16.nxv1i8( , , diff --git a/llvm/test/CodeGen/RISCV/rvv/vwadd.w-rv64.ll b/llvm/test/CodeGen/RISCV/rvv/vwadd.w-rv64.ll --- a/llvm/test/CodeGen/RISCV/rvv/vwadd.w-rv64.ll +++ b/llvm/test/CodeGen/RISCV/rvv/vwadd.w-rv64.ll @@ -1,6 +1,6 @@ ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py -; RUN: llc -mtriple=riscv64 -mattr=+experimental-v -verify-machineinstrs \ -; RUN: < %s | FileCheck %s +; RUN: llc -mtriple=riscv64 -mattr=+experimental-v -verify-machineinstrs < %s | FileCheck %s +; RUN: llc -mtriple=riscv64 -mattr=+experimental-v -verify-machineinstrs -early-live-intervals < %s | FileCheck %s declare @llvm.riscv.vwadd.w.nxv1i16.nxv1i8( , ,