diff options
| author | Evan Cheng <evan.cheng@apple.com> | 2007-08-02 05:29:38 +0000 |
|---|---|---|
| committer | Evan Cheng <evan.cheng@apple.com> | 2007-08-02 05:29:38 +0000 |
| commit | 358c3d1dac31258ba8af1e53646e17bfb4880ddb (patch) | |
| tree | c20606b20d1adf4e4c3f9cd85e0a87c42e5adfcf /llvm/lib/CodeGen/SelectionDAG | |
| parent | 824693c87a4244fed86c1aa8f26e905933e77739 (diff) | |
| download | bcm5719-llvm-358c3d1dac31258ba8af1e53646e17bfb4880ddb.tar.gz bcm5719-llvm-358c3d1dac31258ba8af1e53646e17bfb4880ddb.zip | |
Do not emit copies for physical register output if it's not used.
llvm-svn: 40722
Diffstat (limited to 'llvm/lib/CodeGen/SelectionDAG')
| -rw-r--r-- | llvm/lib/CodeGen/SelectionDAG/ScheduleDAG.cpp | 3 | ||||
| -rw-r--r-- | llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp | 27 |
2 files changed, 28 insertions, 2 deletions
diff --git a/llvm/lib/CodeGen/SelectionDAG/ScheduleDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/ScheduleDAG.cpp index 3738702dc8d..192b0767e36 100644 --- a/llvm/lib/CodeGen/SelectionDAG/ScheduleDAG.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/ScheduleDAG.cpp @@ -676,7 +676,8 @@ void ScheduleDAG::EmitNode(SDNode *Node, if (HasPhysRegOuts) { for (unsigned i = II.numDefs; i < NumResults; ++i) { unsigned Reg = II.ImplicitDefs[i - II.numDefs]; - EmitCopyFromReg(Node, i, Reg, VRBaseMap); + if (Node->hasAnyUseOfValue(i)) + EmitCopyFromReg(Node, i, Reg, VRBaseMap); } } } else { diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp index 4b7863d896c..7ac8ea81aa6 100644 --- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp @@ -3242,7 +3242,7 @@ bool SDNode::hasNUsesOfValue(unsigned NUses, unsigned Value) const { // If there is only one value, this is easy. if (getNumValues() == 1) return use_size() == NUses; - if (Uses.size() < NUses) return false; + if (use_size() < NUses) return false; SDOperand TheValue(const_cast<SDNode *>(this), Value); @@ -3265,6 +3265,31 @@ bool SDNode::hasNUsesOfValue(unsigned NUses, unsigned Value) const { } +/// hasAnyUseOfValue - Return true if there are any use of the indicated +/// value. This method ignores uses of other values defined by this operation. +bool SDNode::hasAnyUseOfValue(unsigned Value) const { + assert(Value < getNumValues() && "Bad value!"); + + if (use_size() == 0) return false; + + SDOperand TheValue(const_cast<SDNode *>(this), Value); + + SmallPtrSet<SDNode*, 32> UsersHandled; + + for (SDNode::use_iterator UI = Uses.begin(), E = Uses.end(); UI != E; ++UI) { + SDNode *User = *UI; + if (User->getNumOperands() == 1 || + UsersHandled.insert(User)) // First time we've seen this? + for (unsigned i = 0, e = User->getNumOperands(); i != e; ++i) + if (User->getOperand(i) == TheValue) { + return true; + } + } + + return false; +} + + /// isOnlyUse - Return true if this node is the only use of N. /// bool SDNode::isOnlyUse(SDNode *N) const { |

