[llvm-commits] CVS: llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Evan Cheng evan.cheng at apple.com
Sun Nov 5 01:31:29 PST 2006



Changes in directory llvm/lib/CodeGen/SelectionDAG:

DAGCombiner.cpp updated: 1.235 -> 1.236
---
Log message:

Added pre-indexed store support.

---
Diffs of the changes:  (+24 -10)

 DAGCombiner.cpp |   34 ++++++++++++++++++++++++----------
 1 files changed, 24 insertions(+), 10 deletions(-)


Index: llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
diff -u llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp:1.235 llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp:1.236
--- llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp:1.235	Fri Nov  3 01:21:16 2006
+++ llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp	Sun Nov  5 03:31:14 2006
@@ -175,9 +175,13 @@
     }
 
     bool CombineToIndexedLoadStore(SDNode *N) {
+      bool isLoad = true;
       SDOperand Ptr;
       if (LoadSDNode *LD  = dyn_cast<LoadSDNode>(N)) {
         Ptr = LD->getBasePtr();
+      } else if (StoreSDNode *ST  = dyn_cast<StoreSDNode>(N)) {
+        Ptr = ST->getBasePtr();
+        isLoad = false;
       } else
         return false;
 
@@ -234,10 +238,9 @@
             if (Use->isPredecessor(N))
               return false;
 
-            if (!OffIsAMImm)
+            if (!OffIsAMImm) {
               NumRealUses++;
-            // FIXME: Do we need a target hook here
-            else if (Use->getOpcode() == ISD::LOAD) {
+            } else if (Use->getOpcode() == ISD::LOAD) {
               if (cast<LoadSDNode>(Use)->getBasePtr().Val != Ptr.Val)
                 NumRealUses++;
             } else if (Use->getOpcode() == ISD::STORE) {
@@ -249,17 +252,23 @@
           if (NumRealUses == 0)
             return false;
 
-          SDOperand Result =
-            DAG.getIndexedLoad(SDOperand(N,0), BasePtr, Offset, AM);
+          SDOperand Result = isLoad
+            ? DAG.getIndexedLoad(SDOperand(N,0), BasePtr, Offset, AM)
+            : DAG.getIndexedStore(SDOperand(N,0), BasePtr, Offset, AM);
           ++NodesCombined;
           DEBUG(std::cerr << "\nReplacing.4 "; N->dump();
                 std::cerr << "\nWith: "; Result.Val->dump(&DAG);
                 std::cerr << '\n');
           std::vector<SDNode*> NowDead;
-          DAG.ReplaceAllUsesOfValueWith(SDOperand(N, 0), Result.getValue(0),
-                                        NowDead);
-          DAG.ReplaceAllUsesOfValueWith(SDOperand(N, 1), Result.getValue(2),
-                                        NowDead);
+          if (isLoad) {
+            DAG.ReplaceAllUsesOfValueWith(SDOperand(N, 0), Result.getValue(0),
+                                          NowDead);
+            DAG.ReplaceAllUsesOfValueWith(SDOperand(N, 1), Result.getValue(2),
+                                          NowDead);
+          } else {
+            DAG.ReplaceAllUsesOfValueWith(SDOperand(N, 0), Result.getValue(1),
+                                          NowDead);
+          }
 
           // Nodes can end up on the worklist more than once.  Make sure we do
           // not process a node that has been replaced.
@@ -269,7 +278,8 @@
           DAG.DeleteNode(N);
 
           // Replace the uses of Ptr with uses of the updated base value.
-          DAG.ReplaceAllUsesOfValueWith(Ptr, Result.getValue(1), NowDead);
+          DAG.ReplaceAllUsesOfValueWith(Ptr, Result.getValue(isLoad ? 1 : 0),
+                                        NowDead);
           removeFromWorkList(Ptr.Val);
           for (unsigned i = 0, e = NowDead.size(); i != e; ++i)
             removeFromWorkList(NowDead[i]);
@@ -2906,6 +2916,10 @@
     }
   }
   
+  // Try transforming N to an indexed store.
+  if (CombineToIndexedLoadStore(N))
+    return SDOperand(N, 0);
+
   return SDOperand();
 }
 






More information about the llvm-commits mailing list