From 9729f2a2b48a89891b86f8d9494ab3649c27f8ab Mon Sep 17 00:00:00 2001 From: Evan Cheng Date: Wed, 3 Mar 2010 23:59:08 +0000 Subject: [PATCH] Fix a logic error. An instruction that has a live physical register def cannot be CSE'ed, but it *can* be used to replace a common subexpression. llvm-svn: 97688 --- lib/CodeGen/MachineCSE.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/CodeGen/MachineCSE.cpp b/lib/CodeGen/MachineCSE.cpp index ea11bfbdb89..d542cc9969a 100644 --- a/lib/CodeGen/MachineCSE.cpp +++ b/lib/CodeGen/MachineCSE.cpp @@ -128,8 +128,6 @@ bool MachineCSE::ProcessBlock(MachineDomTreeNode *Node) { if (TII->isMoveInstr(*MI, SrcReg, DstReg, SrcSubIdx, DstSubIdx) || MI->isExtractSubreg() || MI->isInsertSubreg() || MI->isSubregToReg()) continue; - if (hasLivePhysRegDefUse(MI)) - continue; bool FoundCSE = VNT.count(MI); if (!FoundCSE) { @@ -138,6 +136,11 @@ bool MachineCSE::ProcessBlock(MachineDomTreeNode *Node) { FoundCSE = VNT.count(MI); } + // If the instruction defines a physical register and the value *may* be + // used, then it's not safe to replace it with a common subexpression. + if (FoundCSE && hasLivePhysRegDefUse(MI)) + FoundCSE = false; + if (!FoundCSE) { VNT.insert(MI, CurrVN++); Exps.push_back(MI);