[PATCH] D13992: [AliasAnalysis] Take into account readonly attribute for the function arguments

Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 28 09:44:13 PDT 2015


This revision was automatically updated to reflect the committed changes.
Closed by commit rL251525: [AliasAnalysis] Take into account readonly attribute for the function arguments (authored by igor.laevsky).

Changed prior to commit:
  http://reviews.llvm.org/D13992?vs=38612&id=38666#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D13992

Files:
  llvm/trunk/lib/Analysis/BasicAliasAnalysis.cpp
  llvm/trunk/test/Analysis/BasicAA/modref.ll

Index: llvm/trunk/test/Analysis/BasicAA/modref.ll
===================================================================
--- llvm/trunk/test/Analysis/BasicAA/modref.ll
+++ llvm/trunk/test/Analysis/BasicAA/modref.ll
@@ -190,6 +190,32 @@
   ; CHECK: ret i32 %Diff
 }
 
+; CHECK-LABEL: @test11(
+define i32 @test11(i32* %P, i32* %P2) {
+  %V1 = load i32, i32* %P
+  call i32 @func_argmemonly(i32* readonly %P2)
+  %V2 = load i32, i32* %P
+  %Diff = sub i32 %V1, %V2
+  ret i32 %Diff
+  ; CHECK-NOT: load
+  ; CHECK: ret i32 0
+}
+
+declare i32 @func_argmemonly_two_args(i32* %P, i32* %P2) argmemonly
+
+; CHECK-LABEL: @test12(
+define i32 @test12(i32* %P, i32* %P2, i32* %P3) {
+  %V1 = load i32, i32* %P
+  call i32 @func_argmemonly_two_args(i32* readonly %P2, i32* %P3)
+  %V2 = load i32, i32* %P
+  %Diff = sub i32 %V1, %V2
+  ret i32 %Diff
+  ; CHECK: load
+  ; CHECK: load
+  ; CHECK: sub
+  ; CHECK: ret i32 %Diff
+}
+
 declare void @llvm.memset.p0i8.i32(i8* nocapture, i8, i32, i32, i1) nounwind
 declare void @llvm.memset.p0i8.i8(i8* nocapture, i8, i8, i32, i1) nounwind
 declare void @llvm.memcpy.p0i8.p0i8.i8(i8* nocapture, i8* nocapture, i8, i32, i1) nounwind
Index: llvm/trunk/lib/Analysis/BasicAliasAnalysis.cpp
===================================================================
--- llvm/trunk/lib/Analysis/BasicAliasAnalysis.cpp
+++ llvm/trunk/lib/Analysis/BasicAliasAnalysis.cpp
@@ -616,6 +616,9 @@
   }
   // FIXME: Handle memset_pattern4 and memset_pattern8 also.
 
+  if (CS.paramHasAttr(ArgIdx + 1, Attribute::ReadOnly))
+    return MRI_Ref;
+
   return AAResultBase::getArgModRefInfo(CS, ArgIdx);
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D13992.38666.patch
Type: text/x-patch
Size: 1617 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20151028/b02f77b5/attachment.bin>


More information about the llvm-commits mailing list