[llvm] [AA][ScopedNoAliasAA] Returns ModRef when an alias exists (PR #70159)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 24 21:33:58 PDT 2023
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-analysis
Author: DianQK (DianQK)
<details>
<summary>Changes</summary>
Fixes #<!-- -->70158.
---
Full diff: https://github.com/llvm/llvm-project/pull/70159.diff
2 Files Affected:
- (modified) llvm/lib/Analysis/ScopedNoAliasAA.cpp (+4-8)
- (added) llvm/test/Analysis/ScopedNoAliasAA/mod-ref.ll (+32)
``````````diff
diff --git a/llvm/lib/Analysis/ScopedNoAliasAA.cpp b/llvm/lib/Analysis/ScopedNoAliasAA.cpp
index 3815bdf49d59cea..619424873d54286 100644
--- a/llvm/lib/Analysis/ScopedNoAliasAA.cpp
+++ b/llvm/lib/Analysis/ScopedNoAliasAA.cpp
@@ -79,10 +79,8 @@ ModRefInfo ScopedNoAliasAAResult::getModRefInfo(const CallBase *Call,
return ModRefInfo::ModRef;
if (!mayAliasInScopes(Loc.AATags.Scope,
- Call->getMetadata(LLVMContext::MD_noalias)))
- return ModRefInfo::NoModRef;
-
- if (!mayAliasInScopes(Call->getMetadata(LLVMContext::MD_alias_scope),
+ Call->getMetadata(LLVMContext::MD_noalias)) &&
+ !mayAliasInScopes(Call->getMetadata(LLVMContext::MD_alias_scope),
Loc.AATags.NoAlias))
return ModRefInfo::NoModRef;
@@ -96,10 +94,8 @@ ModRefInfo ScopedNoAliasAAResult::getModRefInfo(const CallBase *Call1,
return ModRefInfo::ModRef;
if (!mayAliasInScopes(Call1->getMetadata(LLVMContext::MD_alias_scope),
- Call2->getMetadata(LLVMContext::MD_noalias)))
- return ModRefInfo::NoModRef;
-
- if (!mayAliasInScopes(Call2->getMetadata(LLVMContext::MD_alias_scope),
+ Call2->getMetadata(LLVMContext::MD_noalias)) &&
+ !mayAliasInScopes(Call2->getMetadata(LLVMContext::MD_alias_scope),
Call1->getMetadata(LLVMContext::MD_noalias)))
return ModRefInfo::NoModRef;
diff --git a/llvm/test/Analysis/ScopedNoAliasAA/mod-ref.ll b/llvm/test/Analysis/ScopedNoAliasAA/mod-ref.ll
new file mode 100644
index 000000000000000..d62f724c4539b42
--- /dev/null
+++ b/llvm/test/Analysis/ScopedNoAliasAA/mod-ref.ll
@@ -0,0 +1,32 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 3
+; RUN: opt -passes=gvn -S < %s | FileCheck %s
+
+declare void @use(i64)
+
+define i64 @foo(ptr noalias nocapture noundef align 8 dereferenceable(24) %p) {
+; CHECK-LABEL: define i64 @foo(
+; CHECK-SAME: ptr noalias nocapture noundef align 8 dereferenceable(24) [[P:%.*]]) {
+; CHECK-NEXT: [[P1:%.*]] = getelementptr inbounds i8, ptr [[P]], i64 16
+; CHECK-NEXT: [[V1:%.*]] = load i64, ptr [[P1]], align 8
+; CHECK-NEXT: call void @use(i64 [[V1]])
+; CHECK-NEXT: [[P2:%.*]] = getelementptr inbounds i8, ptr [[P]], i64 8
+; CHECK-NEXT: call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) [[P2]], i8 0, i64 16, i1 false), !alias.scope !0
+; CHECK-NEXT: ret i64 0
+;
+ %p1 = getelementptr inbounds i8, ptr %p, i64 16
+ %v1 = load i64, ptr %p1, align 8
+ call void @use(i64 %v1)
+ %p2 = getelementptr inbounds i8, ptr %p, i64 8
+ call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %p2, i8 0, i64 16, i1 false), !alias.scope !0
+ %v2 = load i64, ptr %p1, align 8, !noalias !0
+ ret i64 %v2
+}
+
+; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
+declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #0
+
+attributes #0 = { nocallback nofree nounwind willreturn memory(argmem: write) }
+
+!0 = !{!1}
+!1 = distinct !{!1, !2}
+!2 = distinct !{!2}
``````````
</details>
https://github.com/llvm/llvm-project/pull/70159
More information about the llvm-commits
mailing list