Index: llvm/include/llvm/CodeGen/AntiDepBreaker.h =================================================================== --- llvm/include/llvm/CodeGen/AntiDepBreaker.h +++ llvm/include/llvm/CodeGen/AntiDepBreaker.h @@ -55,13 +55,20 @@ /// Finish anti-dep breaking for a basic block. virtual void FinishBlock() = 0; - /// Update DBG_VALUE if dependency breaker is updating + /// Update DBG_VALUE or DBG_PHI if dependency breaker is updating /// other machine instruction to use NewReg. void UpdateDbgValue(MachineInstr &MI, unsigned OldReg, unsigned NewReg) { - assert(MI.isDebugValue() && "MI is not DBG_VALUE!"); - if (MI.getDebugOperand(0).isReg() && - MI.getDebugOperand(0).getReg() == OldReg) - MI.getDebugOperand(0).setReg(NewReg); + if (MI.isDebugValue()) { + if (MI.getDebugOperand(0).isReg() && + MI.getDebugOperand(0).getReg() == OldReg) + MI.getDebugOperand(0).setReg(NewReg); + } else if (MI.isDebugPHI()) { + if (MI.getOperand(0).isReg() && + MI.getOperand(0).getReg() == OldReg) + MI.getOperand(0).setReg(NewReg); + } else { + llvm_unreachable("MI is not DBG_VALUE / DBG_PHI!"); + } } /// Update all DBG_VALUE instructions that may be affected by the dependency Index: llvm/lib/CodeGen/ScheduleDAGInstrs.cpp =================================================================== --- llvm/lib/CodeGen/ScheduleDAGInstrs.cpp +++ llvm/lib/CodeGen/ScheduleDAGInstrs.cpp @@ -807,14 +807,12 @@ DbgMI = nullptr; } - if (MI.isDebugValue() || MI.isDebugRef() || MI.isDebugPHI()) { + if (MI.isDebugValue() || MI.isDebugPHI()) { DbgMI = &MI; continue; } - if (MI.isDebugLabel()) - continue; - if (MI.isPseudoProbe()) + if (MI.isDebugLabel() || MI.isDebugRef() || MI.isPseudoProbe()) continue; SUnit *SU = MISUnitMap[&MI]; Index: llvm/test/CodeGen/X86/post-ra-sched-with-debug.mir =================================================================== --- llvm/test/CodeGen/X86/post-ra-sched-with-debug.mir +++ llvm/test/CodeGen/X86/post-ra-sched-with-debug.mir @@ -1,10 +1,12 @@ # RUN: llc -mtriple=x86_64-unknown-unknown -mcpu=btver2 -run-pass=post-RA-sched -o - %s | FileCheck %s +# RUN: llc -mtriple=x86_64-unknown-unknown -mcpu=btver2 -run-pass=post-RA-sched -o - %s -experimental-debug-variable-locations| FileCheck %s -# Test that multiple DBG_VALUE's following an instruction whose register needs -# to be changed during the post-RA scheduler pass are updated correctly. +# Test that multiple DBG_VALUE's and DBG_PHIs following an instruction whose +# register needs # to be changed during the post-RA scheduler pass are updated +# correctly. # Test case was derived from the output from the following command and -# the source code below: +# the source code below. DBG_PHIs added manually later: # # clang -S -emit-llvm -target x86_64 -march=btver2 -O2 -g -o - | # llc -stop-before=post-RA-sched -o - @@ -253,6 +255,8 @@ ; CHECK: [[REGISTER:\$r[a-z0-9]+]] = LEA64r {{\$r[a-z0-9]+}}, 1, $noreg, -20, $noreg ; CHECK-NEXT: DBG_VALUE [[REGISTER]], $noreg, ![[J_VAR]], !DIExpression(), debug-location ![[J_LOC]] ; CHECK-NEXT: DBG_VALUE [[REGISTER]], $noreg, ![[I_VAR]], !DIExpression(), debug-location ![[I_LOC]] + ; CHECK-NEXT: DBG_PHI [[REGISTER]], 0 + ; CHECK-NEXT: DBG_PHI [[REGISTER]], 1 frame-setup PUSH64r killed $rbp, implicit-def $rsp, implicit $rsp CFI_INSTRUCTION def_cfa_offset 16 @@ -288,10 +292,14 @@ $rcx = LEA64r $rbp, 1, $noreg, -20, $noreg DBG_VALUE $rcx, $noreg, !46, !17, debug-location !48 DBG_VALUE $rcx, $noreg, !39, !17, debug-location !44 + DBG_PHI $rcx, 0 + DBG_PHI $rcx, 1 DBG_VALUE $rbp, -20, !29, !17, debug-location !36 $rcx = CMOV64rr killed $rcx, killed $rdx, 5, implicit killed $eflags $rcx = OR64rr killed $rcx, killed $rsi, implicit-def dead $eflags $rdx = MOVSX64rm32 $rbx, 1, $noreg, 0, $noreg :: (load (s32), align 8) + DBG_INSTR_REF 1, 0, !46, !17, debug-location !48 + DBG_INSTR_REF 2, 0, !39, !17, debug-location !44 TEST32mr killed $rcx, 4, killed $rdx, 0, $noreg, killed $eax, implicit-def $eflags :: (load (s32)) JCC_1 %bb.2, 5, implicit $eflags JMP_1 %bb.3