[PATCH] D44891: [RFC][GVN] Remove redundant load by GVN

Shiva Chen via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 29 02:27:42 PDT 2018


shiva0217 updated this revision to Diff 140195.
shiva0217 retitled this revision from "[RFC][Memory Dependency Analysis] Not clobber load value by store if the store value won't change load content" to "[RFC][GVN] Remove redundant load by GVN".
shiva0217 edited the summary of this revision.
shiva0217 added a comment.

Hi @dberlin. Thanks for your comments. I update the patch as your suggestion.
Currently, I implement in GVN.cpp: GVN::AnalyzeLoadAvailability.
Is that the place you expect to implement?


Repository:
  rL LLVM

https://reviews.llvm.org/D44891

Files:
  lib/Transforms/Scalar/GVN.cpp
  test/Transforms/GVN/remove-redundant-load.ll


Index: test/Transforms/GVN/remove-redundant-load.ll
===================================================================
--- /dev/null
+++ test/Transforms/GVN/remove-redundant-load.ll
@@ -0,0 +1,11 @@
+; RUN: opt -S -memdep -gvn -basicaa < %s | FileCheck %s
+; CHECK-LABEL: @test(
+; CHECK: %1 = load i32, i32* %Addr1
+; CHECK: store i32 %1, i32* %Addr2
+; CHECK: ret i32 %1
+define i32 @test(i32* %Addr1, i32* %Addr2) {
+ %1 = load i32, i32* %Addr1
+ store i32 %1, i32* %Addr2
+ %2 = load i32, i32* %Addr1
+ ret i32 %2
+}
Index: lib/Transforms/Scalar/GVN.cpp
===================================================================
--- lib/Transforms/Scalar/GVN.cpp
+++ lib/Transforms/Scalar/GVN.cpp
@@ -882,6 +882,25 @@
       }
     }
 
+    // To remove LI in following case:
+    //     load  a0, Addr1 <- LItoSI
+    //     store a0, Addr2 <- DepSI
+    //     load  a0, Addr1 <- LI
+    // If LI and LItoSI load from same address, the value load from LItoSI
+    // could propagate to LI even if Addr1 alias to Addr2.
+    if (StoreInst *DepSI = dyn_cast<StoreInst>(DepInfo.getInst())) {
+      if (Address && !LI->isAtomic() && !LI->isVolatile()) {
+        if (LoadInst *LItoSI = dyn_cast<LoadInst>(DepSI->getValueOperand())) {
+          if (!LItoSI->isAtomic() && !LItoSI->isVolatile() &&
+              (LItoSI->getPointerOperand() == LI->getPointerOperand() &&
+              (LItoSI != LI))) {
+            Res = AvailableValue::get(DepSI->getValueOperand(), 0);
+            return true;
+	  }
+        }
+      }
+    }
+
     // Check to see if we have something like this:
     //    load i32* P
     //    load i8* (P+1)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D44891.140195.patch
Type: text/x-patch
Size: 1634 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180329/94f0f07f/attachment.bin>


More information about the llvm-commits mailing list