[clang] [llvm] [X86][APX] Add copy instruction to LiveInterval of SrcReg (PR #191102)

Shengchen Kan via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 8 21:55:23 PDT 2026


================
@@ -7599,11 +7600,20 @@ MachineInstr *X86InstrInfo::foldMemoryOperandImpl(
 
       const TargetRegisterClass &RC = *MF.getRegInfo().getRegClass(SrcReg);
       Register NewSrc = MF.getRegInfo().createVirtualRegister(&RC);
-      BuildMI(*NewMI->getParent(), *NewMI, MI.getDebugLoc(),
-              get(TargetOpcode::COPY))
-          .addReg(NewSrc, RegState::Define)
-          .addReg(SrcReg);
+      MachineInstr *Copy = BuildMI(*NewMI->getParent(), *NewMI,
+                                   MI.getDebugLoc(), get(TargetOpcode::COPY))
+                               .addReg(NewSrc, RegState::Define)
+                               .addReg(SrcReg);
       NewMI->getOperand(1).setReg(NewSrc);
+
+      if (LIS) {
+        SlotIndex CopyIdx = LIS->InsertMachineInstrInMaps(*Copy);
+        SlotIndex Idx = LIS->getInstructionIndex(MI);
+        LiveInterval &LI = LIS->getInterval(SrcReg);
+        LiveRange::Segment *S = LI.getSegmentContaining(Idx);
----------------
KanRobert wrote:

Is it possible the SrcReg is killed in this instrruction so that the `getSegmentContaining` returns nullptr?

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


More information about the cfe-commits mailing list