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

Chris Lattner lattner at cs.uiuc.edu
Mon Jan 17 14:19:40 PST 2005



Changes in directory llvm/lib/CodeGen/SelectionDAG:

SelectionDAGISel.cpp updated: 1.24 -> 1.25
---
Log message:

Non-volatile loads can be freely reordered against each other.  This fixes
X86/reg-pressure.ll again, and allows us to do nice things in other cases.
For example, we now codegen this sort of thing:

int %loadload(int *%X, int* %Y) {
  %Z = load int* %Y
  %Y = load int* %X      ;; load between %Z and store
  %Q = add int %Z, 1
  store int %Q, int* %Y
  ret int %Y
}

Into this:

loadload:
        mov %EAX, DWORD PTR [%ESP + 4]
        mov %EAX, DWORD PTR [%EAX]
        mov %ECX, DWORD PTR [%ESP + 8]
        inc DWORD PTR [%ECX]
        ret

where we weren't able to form the 'inc [mem]' before.  This also lets the
instruction selector emit loads in any order it wants to, which can be good
for register pressure as well.



---
Diffs of the changes:  (+38 -4)

Index: llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
diff -u llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp:1.24 llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp:1.25
--- llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp:1.24	Mon Jan 17 13:43:36 2005
+++ llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp	Mon Jan 17 16:19:26 2005
@@ -187,6 +187,12 @@
 
   std::map<const Value*, SDOperand> NodeMap;
 
+  /// PendingLoads - Loads are not emitted to the program immediately.  We bunch
+  /// them up and then emit token factor nodes when possible.  This allows us to
+  /// get simple disambiguation between loads without worrying about alias
+  /// analysis.
+  std::vector<SDOperand> PendingLoads;
+
 public:
   // TLI - This is information that describes the available target features we
   // need for lowering.  This indicates when operations are unavailable,
@@ -208,7 +214,21 @@
   /// getRoot - Return the current virtual root of the Selection DAG.
   ///
   SDOperand getRoot() {
-    return DAG.getRoot();
+    if (PendingLoads.empty())
+      return DAG.getRoot();
+    
+    if (PendingLoads.size() == 1) {
+      SDOperand Root = PendingLoads[0];
+      DAG.setRoot(Root);
+      PendingLoads.clear();
+      return Root;
+    }
+
+    // Otherwise, we have to make a token factor node.
+    SDOperand Root = DAG.getNode(ISD::TokenFactor, MVT::Other, PendingLoads);
+    PendingLoads.clear();
+    DAG.setRoot(Root);
+    return Root;
   }
 
   void visit(Instruction &I) { visit(I.getOpcode(), I); }
@@ -590,8 +610,22 @@
 
 void SelectionDAGLowering::visitLoad(LoadInst &I) {
   SDOperand Ptr = getValue(I.getOperand(0));
-  SDOperand L = DAG.getLoad(TLI.getValueType(I.getType()), getRoot(), Ptr);
-  DAG.setRoot(setValue(&I, L).getValue(1));
+  
+  SDOperand Root;
+  if (I.isVolatile())
+    Root = getRoot();
+  else {
+    // Do not serialize non-volatile loads against each other.
+    Root = DAG.getRoot();
+  }
+
+  SDOperand L = DAG.getLoad(TLI.getValueType(I.getType()), Root, Ptr);
+  setValue(&I, L);
+
+  if (I.isVolatile())
+    DAG.setRoot(L.getValue(1));
+  else
+    PendingLoads.push_back(L.getValue(1));
 }
 
 
@@ -982,7 +1016,7 @@
 
   // Turn all of the unordered chains into one factored node.
   if (!UnorderedChains.empty()) {
-    UnorderedChains.push_back(DAG.getRoot());
+    UnorderedChains.push_back(SDL.getRoot());
     DAG.setRoot(DAG.getNode(ISD::TokenFactor, MVT::Other, UnorderedChains));
   }
 






More information about the llvm-commits mailing list