Do not emit copies for physical register output if it's not used.
authorEvan Cheng <evan.cheng@apple.com>
Thu, 2 Aug 2007 05:29:38 +0000 (05:29 +0000)
committerEvan Cheng <evan.cheng@apple.com>
Thu, 2 Aug 2007 05:29:38 +0000 (05:29 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@40722 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/CodeGen/SelectionDAGNodes.h
lib/CodeGen/SelectionDAG/ScheduleDAG.cpp
lib/CodeGen/SelectionDAG/SelectionDAG.cpp

index ce7dda402806775f5f379e5309e46fdebed41b3d..3502e895019769bd79acf465234d97bc97f4e681 100644 (file)
@@ -858,6 +858,10 @@ public:
   /// operation.
   bool 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 hasAnyUseOfValue(unsigned Value) const;
+
   /// isOnlyUse - Return true if this node is the only use of N.
   ///
   bool isOnlyUse(SDNode *N) const;
index 3738702dc8d1222f75b1fb51be6c703ea380ecfc..192b0767e363243eaf98144d02bd8a6c91847ef6 100644 (file)
@@ -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 {
index 4b7863d896c8c6b95c0838b373011cef73e5490d..7ac8ea81aa6e77581bf04d0863439c53e2ecaf3c 100644 (file)
@@ -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 {