[PATCH] D44891: [RFC][Memory Dependency Analysis] Not clobber load value by store if the store value won't change load content

Shiva Chen via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Mar 25 23:05:48 PDT 2018


shiva0217 created this revision.
Herald added a reviewer: dberlin.

Remove redundant load "QueryInst" in following case:

  lw      a0, Addr1 <- LItoSI
  sw      a0, Addr2 <- SI
  lw      a0, Addr1 <- QueryInst

Originally, QueryInst can't remove by GVN due to Addr2 may alias to Addr1.
However, QueryInst and LItoSI load from the same address, so even if Addr2 alias
to Addr1, the value load from LItoSI could propagate to QueryInst.


Repository:
  rL LLVM

https://reviews.llvm.org/D44891

Files:
  lib/Analysis/MemoryDependenceAnalysis.cpp
  test/Analysis/MemoryDependenceAnalysis/memdep-remove-redundant-load.ll


Index: test/Analysis/MemoryDependenceAnalysis/memdep-remove-redundant-load.ll
===================================================================
--- /dev/null
+++ test/Analysis/MemoryDependenceAnalysis/memdep-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/Analysis/MemoryDependenceAnalysis.cpp
===================================================================
--- lib/Analysis/MemoryDependenceAnalysis.cpp
+++ lib/Analysis/MemoryDependenceAnalysis.cpp
@@ -651,6 +651,25 @@
         return MemDepResult::getDef(Inst);
       if (isInvariantLoad)
         continue;
+
+      // To remove QueryInst in following case:
+      //        lw      a0, Addr1 <- LItoSI
+      //        sw      a0, Addr2 <- SI
+      //        lw      a0, Addr1 <- QueryInst
+      //
+      // Originally, QueryInst can't remove by GVN due to Addr1 may alias
+      // with Addr2.
+      // However, QueryInst and LItoSI load from same address, so even Addr1
+      // alias to Addr2,the value load from LItoSI could propagate to QueryInst.
+      // MemLoc is the load address of QueryInst.
+      // LoadLoc is the load address of LItoSI.
+      if (LoadInst *LItoSI = dyn_cast<LoadInst>(SI->getValueOperand())) {
+        MemoryLocation LoadLoc = MemoryLocation::get(LItoSI);
+        AliasResult R = AA.alias(LoadLoc, MemLoc);
+        if (R == MustAlias)
+          continue;
+      }
+
       return MemDepResult::getClobber(Inst);
     }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D44891.139762.patch
Type: text/x-patch
Size: 1753 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180326/c8b6b0c2/attachment.bin>


More information about the llvm-commits mailing list