[PATCH] D29996: [DeadStoreElimination] Check function modref behavior before considering memory clobbered

Igor Laevsky via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 15 09:58:41 PST 2017


igor-laevsky created this revision.

Currently we assume that if function may write to memory and it has MRI_ModRef behaviour in relation to the requested memory location then it means that this function writes to the memory location. In fact it's possible that it only reads from it. For example we can achieve this by using readonly attribute on the function operand.


https://reviews.llvm.org/D29996

Files:
  lib/Transforms/Scalar/DeadStoreElimination.cpp
  test/Transforms/DeadStoreElimination/operand-bundles.ll


Index: test/Transforms/DeadStoreElimination/operand-bundles.ll
===================================================================
--- test/Transforms/DeadStoreElimination/operand-bundles.ll
+++ test/Transforms/DeadStoreElimination/operand-bundles.ll
@@ -41,3 +41,15 @@
   store i64 0, i64* %s
   ret void
 }
+
+declare noalias i8* @calloc(i64, i64)
+
+define void @test4() {
+; CHECK-LABEL: @test4
+  %local_obj = call i8* @calloc(i64 1, i64 4)
+  call void @foo() ["deopt" (i8* %local_obj)]
+  store i8 0, i8* %local_obj, align 4
+  ; CHECK-NOT: store i8 0, i8* %local_obj, align 4
+  call void @bar(i8* nocapture %local_obj)
+  ret void
+}
Index: lib/Transforms/Scalar/DeadStoreElimination.cpp
===================================================================
--- lib/Transforms/Scalar/DeadStoreElimination.cpp
+++ lib/Transforms/Scalar/DeadStoreElimination.cpp
@@ -551,7 +551,7 @@
       Instruction *I = &*BI;
       if (I->mayWriteToMemory() && I != SecondI) {
         auto Res = AA->getModRefInfo(I, MemLoc);
-        if (Res != MRI_NoModRef)
+        if (Res & MRI_Mod)
           return false;
       }
     }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D29996.88565.patch
Type: text/x-patch
Size: 1122 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170215/e380182b/attachment.bin>


More information about the llvm-commits mailing list