diff options
-rw-r--r-- | lib/CodeGen/InlineSpiller.cpp | 28 | ||||
-rw-r--r-- | test/CodeGen/X86/crash.ll | 8 |
2 files changed, 32 insertions, 4 deletions
diff --git a/lib/CodeGen/InlineSpiller.cpp b/lib/CodeGen/InlineSpiller.cpp index db63b52638..2ab58a721b 100644 --- a/lib/CodeGen/InlineSpiller.cpp +++ b/lib/CodeGen/InlineSpiller.cpp @@ -1054,6 +1054,34 @@ foldMemoryOperand(ArrayRef<std::pair<MachineInstr*, unsigned> > Ops, : TII.foldMemoryOperand(MI, FoldOps, StackSlot); if (!FoldMI) return false; + + // Remove LIS for any dead defs in the original MI not in FoldMI. + for (MIBundleOperands MO(MI); MO.isValid(); ++MO) { + if (!MO->isReg()) + continue; + unsigned Reg = MO->getReg(); + if (!Reg || TargetRegisterInfo::isVirtualRegister(Reg) || + MRI.isReserved(Reg)) { + continue; + } + MIBundleOperands::PhysRegInfo RI = + MIBundleOperands(FoldMI).analyzePhysReg(Reg, &TRI); + if (MO->readsReg()) { + assert(RI.Reads && "Cannot fold physreg reader"); + continue; + } + if (RI.Defines) + continue; + // FoldMI does not define this physreg. Remove the LI segment. + assert(MO->isDead() && "Cannot fold physreg def"); + for (MCRegUnitIterator Units(Reg, &TRI); Units.isValid(); ++Units) { + if (LiveInterval *LI = LIS.getCachedRegUnit(*Units)) { + SlotIndex Idx = LIS.getInstructionIndex(MI).getRegSlot(); + if (VNInfo *VNI = LI->getVNInfoAt(Idx)) + LI->removeValNo(VNI); + } + } + } LIS.ReplaceMachineInstrInMaps(MI, FoldMI); MI->eraseFromParent(); diff --git a/test/CodeGen/X86/crash.ll b/test/CodeGen/X86/crash.ll index 852b642de6..c6eddc1693 100644 --- a/test/CodeGen/X86/crash.ll +++ b/test/CodeGen/X86/crash.ll @@ -1,5 +1,5 @@ -; RUN: llc -march=x86 < %s -verify-machineinstrs -; RUN: llc -march=x86-64 < %s -verify-machineinstrs +; RUN: llc -march=x86 < %s -verify-machineinstrs -precompute-phys-liveness +; RUN: llc -march=x86-64 < %s -verify-machineinstrs -precompute-phys-liveness ; PR6497 @@ -107,8 +107,8 @@ do.body92: ; preds = %if.then66 ret void } -!0 = metadata !{i32 633550} -!1 = metadata !{i32 634261} +!0 = metadata !{i32 633550} +!1 = metadata !{i32 634261} ; Crash during XOR optimization. |