From c45288e06bfe7d0b0e74eff350d280fa6c944373 Mon Sep 17 00:00:00 2001 From: Evan Cheng Date: Mon, 27 Apr 2009 20:42:46 +0000 Subject: [PATCH] Fix PR4076. Correctly create live interval of physical register with two-address update. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@70245 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/LiveIntervalAnalysis.cpp | 30 ++-- .../X86/2009-04-27-LiveIntervalsBug.ll | 165 ++++++++++++++++++ 2 files changed, 185 insertions(+), 10 deletions(-) create mode 100644 test/CodeGen/X86/2009-04-27-LiveIntervalsBug.ll diff --git a/lib/CodeGen/LiveIntervalAnalysis.cpp b/lib/CodeGen/LiveIntervalAnalysis.cpp index 7ef6abc4b45..d2927ed4801 100644 --- a/lib/CodeGen/LiveIntervalAnalysis.cpp +++ b/lib/CodeGen/LiveIntervalAnalysis.cpp @@ -612,14 +612,24 @@ void LiveIntervals::handlePhysicalRegisterDef(MachineBasicBlock *MBB, DOUT << " killed"; end = getUseIndex(baseIndex) + 1; goto exit; - } else if (mi->modifiesRegister(interval.reg, tri_)) { - // Another instruction redefines the register before it is ever read. - // Then the register is essentially dead at the instruction that defines - // it. Hence its interval is: - // [defSlot(def), defSlot(def)+1) - DOUT << " dead"; - end = start + 1; - goto exit; + } else { + int DefIdx = mi->findRegisterDefOperandIdx(interval.reg, false, tri_); + if (DefIdx != -1) { + if (mi->isRegTiedToUseOperand(DefIdx)) { + // Two-address instruction. + end = getDefIndex(baseIndex); + if (mi->getOperand(DefIdx).isEarlyClobber()) + end = getUseIndex(baseIndex); + } else { + // Another instruction redefines the register before it is ever read. + // Then the register is essentially dead at the instruction that defines + // it. Hence its interval is: + // [defSlot(def), defSlot(def)+1) + DOUT << " dead"; + end = start + 1; + } + goto exit; + } } baseIndex += InstrSlots::NUM; @@ -663,14 +673,14 @@ void LiveIntervals::handleRegisterDef(MachineBasicBlock *MBB, MI->getOpcode() == TargetInstrInfo::SUBREG_TO_REG || tii_->isMoveInstr(*MI, SrcReg, DstReg, SrcSubReg, DstSubReg)) CopyMI = MI; - handlePhysicalRegisterDef(MBB, MI, MIIdx, MO, + handlePhysicalRegisterDef(MBB, MI, MIIdx, MO, getOrCreateInterval(MO.getReg()), CopyMI); // Def of a register also defines its sub-registers. for (const unsigned* AS = tri_->getSubRegisters(MO.getReg()); *AS; ++AS) // If MI also modifies the sub-register explicitly, avoid processing it // more than once. Do not pass in TRI here so it checks for exact match. if (!MI->modifiesRegister(*AS)) - handlePhysicalRegisterDef(MBB, MI, MIIdx, MO, + handlePhysicalRegisterDef(MBB, MI, MIIdx, MO, getOrCreateInterval(*AS), 0); } } diff --git a/test/CodeGen/X86/2009-04-27-LiveIntervalsBug.ll b/test/CodeGen/X86/2009-04-27-LiveIntervalsBug.ll new file mode 100644 index 00000000000..0fb000c3a07 --- /dev/null +++ b/test/CodeGen/X86/2009-04-27-LiveIntervalsBug.ll @@ -0,0 +1,165 @@ +; RUN: llvm-as < %s | llc -mtriple=i386-unknown-linux-gnu | grep cmpxchgl | not grep eax +; PR4076 + + type { i8, i8, i8 } ; type %0 + type { i32, i8** } ; type %1 + type { %3* } ; type %2 + type { %4 } ; type %3 + type { %5 } ; type %4 + type { %6, i32, %7 } ; type %5 + type { i8* } ; type %6 + type { i32, [12 x i8] } ; type %7 + type { %9 } ; type %8 + type { %10, %11*, i8 } ; type %9 + type { %11* } ; type %10 + type { i32, %6, i8*, %12, %13*, i8, i32, %28, %29, i32, %30, i32, i32, i32, i8*, i8*, i8, i8 } ; type %11 + type { %13* } ; type %12 + type { %14, i32, %13*, %21 } ; type %13 + type { %15, %16 } ; type %14 + type { i32 (...)** } ; type %15 + type { %17, i8* (i32)*, void (i8*)*, i8 } ; type %16 + type { i32 (...)**, i8*, i8*, i8*, i8*, i8*, i8*, %18 } ; type %17 + type { %19* } ; type %18 + type { i32, %20**, i32, %20**, i8** } ; type %19 + type { i32 (...)**, i32 } ; type %20 + type { %22, %25*, i8, i8, %17*, %26*, %27*, %27* } ; type %21 + type { i32 (...)**, i32, i32, i32, i32, i32, %23*, %24, [8 x %24], i32, %24*, %18 } ; type %22 + type { %23*, void (i32, %22*, i32)*, i32, i32 } ; type %23 + type { i8*, i32 } ; type %24 + type { i32 (...)**, %21 } ; type %25 + type { %20, i32*, i8, i32*, i32*, i16*, i8, [256 x i8], [256 x i8], i8 } ; type %26 + type { %20 } ; type %27 + type { void (%9*)*, i32 } ; type %28 + type { %15* } ; type %29 + type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i8* } ; type %30 +@AtomicOps_Internalx86CPUFeatures = external global %0 ; <%0*> [#uses=1] +internal constant [19 x i8] c"xxxxxxxxxxxxxxxxxx\00" ; <[19 x i8]*>:0 [#uses=1] +internal constant [47 x i8] c"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\00" ; <[47 x i8]*>:1 [#uses=1] + +define i8** @func6(i8 zeroext, i32, i32, %1*) nounwind { +;