[PATCH] D136993: [test][AliasAnalysis] Add some baseline tests in preparation for getModRefInfoMask().

Patrick Walton via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 28 15:16:14 PDT 2022


pcwalton created this revision.
Herald added a subscriber: jeroen.dobbelaere.
Herald added a project: All.
pcwalton requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

This commit adds some tests in preparation for D136659 <https://reviews.llvm.org/D136659>, which allows alias
analysis to treat locally-invariant memory pointed to by readonly noalias
pointers the same as globally-invariant memory in some cases. The existing
behavior for these tests is marked as expected and will be changed when that
diff lands.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D136993

Files:
  llvm/test/Analysis/BasicAA/constant-memory.ll
  llvm/test/Transforms/InstCombine/memcpy-from-global.ll
  llvm/test/Transforms/InstCombine/store.ll


Index: llvm/test/Transforms/InstCombine/store.ll
===================================================================
--- llvm/test/Transforms/InstCombine/store.ll
+++ llvm/test/Transforms/InstCombine/store.ll
@@ -336,6 +336,16 @@
   ret void
 }
 
+; We can't delete stores to readonly noalias pointers yet.
+define void @store_to_readonly_noalias(ptr readonly noalias %0) {
+; CHECK-LABEL: @store_to_readonly_noalias(
+; CHECK-NEXT:    store i32 3, ptr [[TMP0:%.*]], align 4
+; CHECK-NEXT:    ret void
+;
+  store i32 3, ptr %0, align 4
+  ret void
+}
+
 !0 = !{!4, !4, i64 0}
 !1 = !{!"omnipotent char", !2}
 !2 = !{!"Simple C/C++ TBAA"}
Index: llvm/test/Transforms/InstCombine/memcpy-from-global.ll
===================================================================
--- llvm/test/Transforms/InstCombine/memcpy-from-global.ll
+++ llvm/test/Transforms/InstCombine/memcpy-from-global.ll
@@ -338,4 +338,20 @@
   ret float %r
 }
 
+declare void @boo(ptr readonly noalias noundef nocapture align 8) readonly
+
+; Tests that we can't eliminate allocas copied from readonly noalias pointers yet.
+define void @test12(ptr nocapture noundef readonly noalias align 8 dereferenceable(124) %arg) {
+; CHECK-LABEL: @test12(
+; CHECK-NEXT:    [[ALLOCA:%.*]] = alloca [[T:%.*]], align 8
+; CHECK-NEXT:    call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(124) [[ALLOCA]], ptr noundef nonnull align 8 dereferenceable(124) [[ARG:%.*]], i64 124, i1 false)
+; CHECK-NEXT:    call void @boo(ptr noalias nocapture noundef nonnull readonly align 8 [[ALLOCA]]) #[[ATTR3]]
+; CHECK-NEXT:    ret void
+;
+  %alloca = alloca %T, align 8
+  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull dereferenceable(12) %alloca, ptr noundef nonnull dereferenceable(12) %arg, i64 124, i1 false)
+  call void @boo(ptr readonly noalias noundef nonnull nocapture align 8 %alloca) readonly
+  ret void
+}
+
 attributes #0 = { null_pointer_is_valid }
Index: llvm/test/Analysis/BasicAA/constant-memory.ll
===================================================================
--- llvm/test/Analysis/BasicAA/constant-memory.ll
+++ llvm/test/Analysis/BasicAA/constant-memory.ll
@@ -4,6 +4,8 @@
 
 declare void @dummy()
 
+declare void @foo(ptr)
+
 ; FIXME: This could be NoModRef
 ; CHECK-LABEL: Function: basic
 ; CHECK: Just Ref: Ptr: i32* @c	<->  call void @dummy()
@@ -31,3 +33,23 @@
 exit:
   ret void
 }
+
+; Tests that readonly noalias doesn't imply !Mod yet.
+;
+; CHECK-LABEL: Function: readonly_noalias
+; CHECK: Both ModRef: Ptr: i32* %p <->  call void @foo(ptr %p)
+define void @readonly_noalias(ptr readonly noalias %p) {
+    call void @foo(ptr %p)
+    load i32, ptr %p
+    ret void
+}
+
+; Tests that readonly doesn't imply !Mod without noalias.
+;
+; CHECK-LABEL: Function: just_readonly
+; CHECK: Both ModRef: Ptr: i32* %p <->  call void @foo(ptr %p)
+define void @just_readonly(ptr readonly %p) {
+    call void @foo(ptr %p)
+    load i32, ptr %p
+    ret void
+}
\ No newline at end of file


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D136993.471668.patch
Type: text/x-patch
Size: 2996 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221028/54c32f69/attachment.bin>


More information about the llvm-commits mailing list