diff --git a/llvm/lib/Target/X86/X86InstrInfo.cpp b/llvm/lib/Target/X86/X86InstrInfo.cpp --- a/llvm/lib/Target/X86/X86InstrInfo.cpp +++ b/llvm/lib/Target/X86/X86InstrInfo.cpp @@ -1249,6 +1249,8 @@ if (LV) { // Update live variables. LV->getVarInfo(InRegLEA).Kills.push_back(NewMI); + if (InRegLEA2) + LV->getVarInfo(InRegLEA2).Kills.push_back(NewMI); LV->getVarInfo(OutRegLEA).Kills.push_back(ExtMI); if (IsKill) LV->replaceKillInstruction(Src, MI, *InsMI); @@ -1337,6 +1339,7 @@ bool Is64Bit = Subtarget.is64Bit(); bool Is8BitOp = false; + unsigned NumRegOperands = 2; unsigned MIOpc = MI.getOpcode(); switch (MIOpc) { default: llvm_unreachable("Unreachable!"); @@ -1385,6 +1388,9 @@ MIB.add(ImplicitOp); NewMI = MIB; + // Add kills if classifyLEAReg created a new register. + if (LV && SrcReg != Src.getReg()) + LV->getVarInfo(SrcReg).Kills.push_back(NewMI); break; } case X86::SHL8ri: @@ -1416,6 +1422,10 @@ MIB.add(ImplicitOp); NewMI = addOffset(MIB, 1); + + // Add kills if classifyLEAReg created a new register. + if (LV && SrcReg != Src.getReg()) + LV->getVarInfo(SrcReg).Kills.push_back(NewMI); break; } case X86::DEC64r: @@ -1438,6 +1448,9 @@ NewMI = addOffset(MIB, -1); + // Add kills if classifyLEAReg created a new register. + if (LV && SrcReg != Src.getReg()) + LV->getVarInfo(SrcReg).Kills.push_back(NewMI); break; } case X86::DEC8r: @@ -1485,8 +1498,15 @@ MIB.add(ImplicitOp2); NewMI = addRegReg(MIB, SrcReg, isKill, SrcReg2, isKill2); - if (LV && Src2.isKill()) - LV->replaceKillInstruction(SrcReg2, MI, *NewMI); + + // Add kills if classifyLEAReg created a new register. + if (LV) { + if (SrcReg2 != Src2.getReg()) + LV->getVarInfo(SrcReg2).Kills.push_back(NewMI); + if (SrcReg != SrcReg2 && SrcReg != Src.getReg()) + LV->getVarInfo(SrcReg).Kills.push_back(NewMI); + } + NumRegOperands = 3; break; } case X86::ADD8rr: @@ -1525,6 +1545,10 @@ MIB.add(ImplicitOp); NewMI = addOffset(MIB, MI.getOperand(2)); + + // Add kills if classifyLEAReg created a new register. + if (LV && SrcReg != Src.getReg()) + LV->getVarInfo(SrcReg).Kills.push_back(NewMI); break; } case X86::ADD8ri: @@ -1729,6 +1753,7 @@ .add(MI.getOperand(2)) .add(Src) .add(MI.getOperand(3)); + NumRegOperands = 4; break; } } @@ -1736,10 +1761,11 @@ if (!NewMI) return nullptr; if (LV) { // Update live variables - if (Src.isKill()) - LV->replaceKillInstruction(Src.getReg(), MI, *NewMI); - if (Dest.isDead()) - LV->replaceKillInstruction(Dest.getReg(), MI, *NewMI); + for (unsigned I = 0; I < NumRegOperands; ++I) { + MachineOperand &Op = MI.getOperand(I); + if (Op.isDead() || Op.isKill()) + LV->replaceKillInstruction(Op.getReg(), MI, *NewMI); + } } MachineBasicBlock &MBB = *MI.getParent();