Can't move a load node if it's chain is not used.
authorJim Laskey <jlaskey@mac.com>
Tue, 26 Sep 2006 07:37:42 +0000 (07:37 +0000)
committerJim Laskey <jlaskey@mac.com>
Tue, 26 Sep 2006 07:37:42 +0000 (07:37 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@30609 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/SelectionDAG/DAGCombiner.cpp

index fbc4257263b91de7566dd8e7188f0e06d439c39e..93f8db12377d7f29311f069c88d791dcd7bb0b4a 100644 (file)
@@ -240,6 +240,10 @@ class VISIBILITY_HIDDEN DAGCombiner {
     SDOperand BuildUDIV(SDNode *N);
     SDNode *MatchRotate(SDOperand LHS, SDOperand RHS);
     
+    ///  hasChainUsers - Returns true if one of the users of a load node has the
+    ///  chain result as an operand.
+    bool hasChainUsers(SDNode *Load);
+    
     /// FindBaseOffset - Return true if we can determine base and offset
     /// information from a given pointer operand.  Provides base and offset as a
     /// result.
@@ -2640,7 +2644,7 @@ SDOperand DAGCombiner::visitLOAD(SDNode *N) {
       Chain.getOperand(1).getValueType() == N->getValueType(0))
     return CombineTo(N, Chain.getOperand(1), Chain);
   
-  if (CombinerAA) { 
+  if (CombinerAA && hasChainUsers(N)) { 
     // Walk up chain skipping non-aliasing memory nodes.
     SDOperand BetterChain = FindBetterChain(N, Chain);
     
@@ -3947,6 +3951,23 @@ SDOperand DAGCombiner::BuildUDIV(SDNode *N) {
   return S;
 }
 
+///  hasChainUsers - Returns true if one of the users of a load node has the
+///  chain result as an operand.
+bool DAGCombiner::hasChainUsers(SDNode *Load) {
+  // Don't even bother if the load only has one user (conservatively the value.)
+  if (!Load->hasOneUse()) {
+    SDOperand Chain(Load, 1);
+    
+    for (SDNode::use_iterator UI = Load->use_begin(), UE = Load->use_end();
+         UI != UE; ++UI) {
+      if ((*UI)->getOperand(0) == Chain)
+        return true;
+    }
+  }
+  
+  return false;
+}
+
 /// FindBaseOffset - Return true if we can determine base and offset information
 /// from a given pointer operand.  Provides base and offset as a result.
 bool DAGCombiner::FindBaseOffset(SDOperand Ptr,