now that loads are in their own table, we can implement
authorChris Lattner <sabre@nondot.org>
Mon, 3 Jan 2011 03:46:34 +0000 (03:46 +0000)
committerChris Lattner <sabre@nondot.org>
Mon, 3 Jan 2011 03:46:34 +0000 (03:46 +0000)
store->load forwarding.  This allows EarlyCSE to zap 600 more
loads from 176.gcc.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@122732 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/EarlyCSE.cpp
test/Transforms/EarlyCSE/basic.ll

index a899640d0adcc135155d6fef7acb0930e758542c..06c1b9111187cf04addfab439021c095f623e82f 100644 (file)
@@ -380,8 +380,19 @@ bool EarlyCSE::processNode(DomTreeNode *Node) {
     // Okay, this isn't something we can CSE at all.  Check to see if it is
     // something that could modify memory.  If so, our available memory values
     // cannot be used so bump the generation count.
-    if (Inst->mayWriteToMemory())
+    if (Inst->mayWriteToMemory()) {
       ++CurrentGeneration;
+     
+      // Okay, we just invalidated anything we knew about loaded values.  Try to
+      // salvage *something* by remembering that the stored value is a live
+      // version of the pointer.  It is safe to forward from volatile stores to
+      // non-volatile loads, so we don't have to check for volatility of the
+      // store.
+      if (StoreInst *SI = dyn_cast<StoreInst>(Inst)) {
+        AvailableLoads->insert(SI->getPointerOperand(),
+         std::pair<Value*, unsigned>(SI->getValueOperand(), CurrentGeneration));
+      }
+    }
   }
   
   unsigned LiveOutGeneration = CurrentGeneration;
index 6d772599b3616d4e1397648f5d91b5304e047b38..5599a1c0b7b1802bad75f22fb7056414f7587cab 100644 (file)
@@ -87,3 +87,12 @@ define i32 @test5(i32 *%P) {
   ret i32 %Diff
   ; CHECK: ret i32 0
 }
+
+;; Trivial Store->load forwarding
+; CHECK: @test6
+define i32 @test6(i32 *%P) {
+  store i32 42, i32* %P
+  %V1 = load i32* %P
+  ret i32 %V1
+  ; CHECK: ret i32 42
+}