enhance basicaa to return "Mod" for a memcpy call when the
authorChris Lattner <sabre@nondot.org>
Tue, 30 Nov 2010 00:43:16 +0000 (00:43 +0000)
committerChris Lattner <sabre@nondot.org>
Tue, 30 Nov 2010 00:43:16 +0000 (00:43 +0000)
queried location doesn't overlap the source, and add a testcase.

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

lib/Analysis/BasicAliasAnalysis.cpp
test/Transforms/DeadStoreElimination/simple.ll

index 3e634240901f70b92bb586084e8c7d356863965b..74bee947a3db6bc3b5bc5af5bc3184ba216e202d 100644 (file)
@@ -687,10 +687,15 @@ BasicAliasAnalysis::getModRefInfo(ImmutableCallSite CS,
         Len = LenCI->getZExtValue();
       Value *Dest = II->getArgOperand(0);
       Value *Src = II->getArgOperand(1);
+      // If it can't overlap the source dest, then it doesn't modref the loc.
       if (isNoAlias(Location(Dest, Len), Loc)) {
         if (isNoAlias(Location(Src, Len), Loc))
           return NoModRef;
+        // If it can't overlap the dest, then worst case it reads the loc.
         Min = Ref;
+      } else if (isNoAlias(Location(Src, Len), Loc)) {
+        // If it can't overlap the source, then worst case it mutates the loc.
+        Min = Mod;
       }
       break;
     }
index c426c0a08b6e19449c3b3ab9d2779d83adf2e3b8..3237ae2d4f949b84a121d8773631bf56e7f9efac 100644 (file)
@@ -55,16 +55,27 @@ define void @test5(i32* %Q) {
 ; CHECK-NEXT: ret void
 }
 
-declare void @llvm.memset.i32(i8*, i8, i32, i32)
+declare void @llvm.memset.i64(i8*, i8, i64, i32)
+declare void @llvm.memcpy.i64(i8*, i8*, i64, i32)
 
 ; Should delete store of 10 even though memset is a may-store to P (P and Q may
 ; alias).
 define void @test6(i32 *%p, i8 *%q) {
   store i32 10, i32* %p, align 4       ;; dead.
-  call void @llvm.memset.i32(i8* %q, i8 42, i32 900, i32 1)
+  call void @llvm.memset.i64(i8* %q, i8 42, i64 900, i32 1)
   store i32 30, i32* %p, align 4
   ret void
 ; CHECK: @test6
 ; CHECK-NEXT: call void @llvm.memset
 }
 
+; Should delete store of 10 even though memcpy is a may-store to P (P and Q may
+; alias).
+define void @test7(i32 *%p, i8 *%q, i8* noalias %r) {
+  store i32 10, i32* %p, align 4       ;; dead.
+  call void @llvm.memcpy.i64(i8* %q, i8* %r, i64 900, i32 1)
+  store i32 30, i32* %p, align 4
+  ret void
+; CHECK: @test7
+; CHECK-NEXT: call void @llvm.memcpy
+}