[llvm] [AA][ScopedNoAliasAA] Returns ModRef when an alias exists (PR #70159)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 24 21:32:50 PDT 2023
https://github.com/DianQK created https://github.com/llvm/llvm-project/pull/70159
Fixes #70158.
>From 8c21058a7392daeac19e9a663863d2c345b5e637 Mon Sep 17 00:00:00 2001
From: DianQK <dianqk at dianqk.net>
Date: Wed, 25 Oct 2023 11:57:57 +0800
Subject: [PATCH 1/2] [AA] Pre-commit for ModRef on ScopedNoAliasAA
---
llvm/test/Analysis/ScopedNoAliasAA/mod-ref.ll | 32 +++++++++++++++++++
1 file changed, 32 insertions(+)
create mode 100644 llvm/test/Analysis/ScopedNoAliasAA/mod-ref.ll
diff --git a/llvm/test/Analysis/ScopedNoAliasAA/mod-ref.ll b/llvm/test/Analysis/ScopedNoAliasAA/mod-ref.ll
new file mode 100644
index 000000000000000..852790daecd455e
--- /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 [[V1]]
+;
+ %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}
>From c171b07fea3f8c9ce51866b284e9324ce37e4212 Mon Sep 17 00:00:00 2001
From: DianQK <dianqk at dianqk.net>
Date: Wed, 25 Oct 2023 10:41:34 +0800
Subject: [PATCH 2/2] [AA][ScopedNoAliasAA] Returns ModRef when an alias exists
---
llvm/lib/Analysis/ScopedNoAliasAA.cpp | 12 ++++--------
llvm/test/Analysis/ScopedNoAliasAA/mod-ref.ll | 2 +-
2 files changed, 5 insertions(+), 9 deletions(-)
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
index 852790daecd455e..d62f724c4539b42 100644
--- a/llvm/test/Analysis/ScopedNoAliasAA/mod-ref.ll
+++ b/llvm/test/Analysis/ScopedNoAliasAA/mod-ref.ll
@@ -11,7 +11,7 @@ define i64 @foo(ptr noalias nocapture noundef align 8 dereferenceable(24) %p) {
; 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 [[V1]]
+; CHECK-NEXT: ret i64 0
;
%p1 = getelementptr inbounds i8, ptr %p, i64 16
%v1 = load i64, ptr %p1, align 8
More information about the llvm-commits
mailing list