From 3bd79ba856a9691b68896ce0e1e3ff6ee700fedd Mon Sep 17 00:00:00 2001 From: Eli Friedman Date: Wed, 4 May 2011 20:48:42 +0000 Subject: [PATCH] Back out r130862; it appears to be breaking bootstrap. llvm-svn: 130867 --- llvm/lib/CodeGen/MachineCSE.cpp | 72 ++++++++++--------------- llvm/test/CodeGen/Thumb2/thumb2-cbnz.ll | 4 +- llvm/test/CodeGen/X86/cmp-redundant.ll | 22 -------- 3 files changed, 30 insertions(+), 68 deletions(-) delete mode 100644 llvm/test/CodeGen/X86/cmp-redundant.ll diff --git a/llvm/lib/CodeGen/MachineCSE.cpp b/llvm/lib/CodeGen/MachineCSE.cpp index ff7062da30e6..f97ccf65790f 100644 --- a/llvm/lib/CodeGen/MachineCSE.cpp +++ b/llvm/lib/CodeGen/MachineCSE.cpp @@ -82,8 +82,7 @@ namespace { MachineBasicBlock::const_iterator E) const ; bool hasLivePhysRegDefUses(const MachineInstr *MI, const MachineBasicBlock *MBB, - SmallSet &PhysRefs, - SmallVector &PhysDefs) const; + SmallSet &PhysRefs) const; bool PhysRegDefsReach(MachineInstr *CSMI, MachineInstr *MI, SmallSet &PhysRefs) const; bool isCSECandidate(MachineInstr *MI); @@ -190,8 +189,7 @@ MachineCSE::isPhysDefTriviallyDead(unsigned Reg, /// instruction does not uses a physical register. bool MachineCSE::hasLivePhysRegDefUses(const MachineInstr *MI, const MachineBasicBlock *MBB, - SmallSet &PhysRefs, - SmallVector &PhysDefs) const{ + SmallSet &PhysRefs) const { MachineBasicBlock::const_iterator I = MI; I = llvm::next(I); for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) { const MachineOperand &MO = MI->getOperand(i); @@ -208,7 +206,6 @@ bool MachineCSE::hasLivePhysRegDefUses(const MachineInstr *MI, if (MO.isDef() && (MO.isDead() || isPhysDefTriviallyDead(Reg, I, MBB->end()))) continue; - PhysDefs.push_back(Reg); PhysRefs.insert(Reg); for (const unsigned *Alias = TRI->getAliasSet(Reg); *Alias; ++Alias) PhysRefs.insert(*Alias); @@ -219,40 +216,35 @@ bool MachineCSE::hasLivePhysRegDefUses(const MachineInstr *MI, bool MachineCSE::PhysRegDefsReach(MachineInstr *CSMI, MachineInstr *MI, SmallSet &PhysRefs) const { - // Look backward from MI to find CSMI. + // For now conservatively returns false if the common subexpression is + // not in the same basic block as the given instruction. + MachineBasicBlock *MBB = MI->getParent(); + if (CSMI->getParent() != MBB) + return false; + MachineBasicBlock::const_iterator I = CSMI; I = llvm::next(I); + MachineBasicBlock::const_iterator E = MI; unsigned LookAheadLeft = LookAheadLimit; - MachineBasicBlock::const_reverse_iterator I(MI); - MachineBasicBlock::const_reverse_iterator E(MI->getParent()->rend()); while (LookAheadLeft) { - while (LookAheadLeft && I != E) { - // Skip over dbg_value's. - while (I != E && I->isDebugValue()) - ++I; - - if (&*I == CSMI) - return true; - - for (unsigned i = 0, e = I->getNumOperands(); i != e; ++i) { - const MachineOperand &MO = I->getOperand(i); - if (!MO.isReg() || !MO.isDef()) - continue; - unsigned MOReg = MO.getReg(); - if (TargetRegisterInfo::isVirtualRegister(MOReg)) - continue; - if (PhysRefs.count(MOReg)) - return false; - } - - --LookAheadLeft; + // Skip over dbg_value's. + while (I != E && I->isDebugValue()) ++I; + + if (I == E) + return true; + + for (unsigned i = 0, e = I->getNumOperands(); i != e; ++i) { + const MachineOperand &MO = I->getOperand(i); + if (!MO.isReg() || !MO.isDef()) + continue; + unsigned MOReg = MO.getReg(); + if (TargetRegisterInfo::isVirtualRegister(MOReg)) + continue; + if (PhysRefs.count(MOReg)) + return false; } - // Go back another BB; for now, only go back at most one BB. - MachineBasicBlock *CSBB = CSMI->getParent(); - MachineBasicBlock *BB = MI->getParent(); - if (!CSBB->isSuccessor(BB) || BB->pred_size() != 1) - return false; - I = CSBB->rbegin(); - E = CSBB->rend(); + + --LookAheadLeft; + ++I; } return false; @@ -403,8 +395,7 @@ bool MachineCSE::ProcessBlock(MachineBasicBlock *MBB) { // used, then it's not safe to replace it with a common subexpression. // It's also not safe if the instruction uses physical registers. SmallSet PhysRefs; - SmallVector DirectPhysRefs; - if (FoundCSE && hasLivePhysRegDefUses(MI, MBB, PhysRefs, DirectPhysRefs)) { + if (FoundCSE && hasLivePhysRegDefUses(MI, MBB, PhysRefs)) { FoundCSE = false; // ... Unless the CS is local and it also defines the physical register @@ -457,13 +448,6 @@ bool MachineCSE::ProcessBlock(MachineBasicBlock *MBB) { MRI->clearKillFlags(CSEPairs[i].second); } MI->eraseFromParent(); - if (!DirectPhysRefs.empty() && CSMI->getParent() != MBB) { - assert(CSMI->getParent()->isSuccessor(MBB)); - SmallVector::iterator PI = DirectPhysRefs.begin(), - PE = DirectPhysRefs.end(); - for (; PI != PE; ++PI) - MBB->addLiveIn(*PI); - } ++NumCSEs; if (!PhysRefs.empty()) ++NumPhysCSEs; diff --git a/llvm/test/CodeGen/Thumb2/thumb2-cbnz.ll b/llvm/test/CodeGen/Thumb2/thumb2-cbnz.ll index 0ca97647d545..10a4985d1736 100644 --- a/llvm/test/CodeGen/Thumb2/thumb2-cbnz.ll +++ b/llvm/test/CodeGen/Thumb2/thumb2-cbnz.ll @@ -21,8 +21,8 @@ bb7: ; preds = %bb3 bb9: ; preds = %bb7 ; CHECK: cmp r0, #0 -; CHECK-NOT: cmp -; CHECK: cbnz +; CHECK: cmp r0, #0 +; CHECK-NEXT: cbnz %0 = tail call double @floor(double %b) nounwind readnone ; [#uses=0] br label %bb11 diff --git a/llvm/test/CodeGen/X86/cmp-redundant.ll b/llvm/test/CodeGen/X86/cmp-redundant.ll deleted file mode 100644 index d30ea3edd68d..000000000000 --- a/llvm/test/CodeGen/X86/cmp-redundant.ll +++ /dev/null @@ -1,22 +0,0 @@ -; RUN: llc < %s -mtriple=x86_64-apple-darwin10 | FileCheck %s - -define i32 @cmp(i32* %aa, i32* %bb) nounwind readnone ssp { -entry: - %a = load i32* %aa - %b = load i32* %bb - %cmp = icmp sgt i32 %a, %b - br i1 %cmp, label %return, label %if.end -; CHECK: cmp: -; CHECK: cmpl -; CHECK: jg -if.end: ; preds = %entry -; CHECK-NOT: cmpl -; CHECK: cmov - %cmp4 = icmp slt i32 %a, %b - %. = select i1 %cmp4, i32 2, i32 111 - br label %return - -return: ; preds = %if.end, %entry - %retval.0 = phi i32 [ 1, %entry ], [ %., %if.end ] - ret i32 %retval.0 -}