[llvm] c068284 - [Lint] Permit aliasing noalias and readnone arguments
Bjorn Pettersson via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 14 05:11:54 PDT 2023
Author: Bjorn Pettersson
Date: 2023-08-14T14:11:17+02:00
New Revision: c0682840877a21960f4c21a97b5f497d4ccc82d5
URL: https://github.com/llvm/llvm-project/commit/c0682840877a21960f4c21a97b5f497d4ccc82d5
DIFF: https://github.com/llvm/llvm-project/commit/c0682840877a21960f4c21a97b5f497d4ccc82d5.diff
LOG: [Lint] Permit aliasing noalias and readnone arguments
If an argument is readnone we know that it isn't dereferenced. Then
it should be OK if that argument alias with a noalias argument.
Differential Revision: https://reviews.llvm.org/D157737
Added:
llvm/test/Analysis/Lint/noalias-readnone.ll
Modified:
llvm/lib/Analysis/Lint.cpp
llvm/test/Analysis/Lint/noalias-byval.ll
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/Lint.cpp b/llvm/lib/Analysis/Lint.cpp
index ff022006df65ad..1ebc593016bc0d 100644
--- a/llvm/lib/Analysis/Lint.cpp
+++ b/llvm/lib/Analysis/Lint.cpp
@@ -235,6 +235,10 @@ void Lint::visitCallBase(CallBase &I) {
// If both arguments are readonly, they have no dependence.
if (Formal->onlyReadsMemory() && I.onlyReadsMemory(ArgNo))
continue;
+ // Skip readnone arguments since those are guaranteed not to be
+ // dereferenced anyway.
+ if (I.doesNotAccessMemory(ArgNo))
+ continue;
if (AI != BI && (*BI)->getType()->isPointerTy()) {
AliasResult Result = AA->alias(*AI, *BI);
Check(Result != AliasResult::MustAlias &&
diff --git a/llvm/test/Analysis/Lint/noalias-byval.ll b/llvm/test/Analysis/Lint/noalias-byval.ll
index 6850058c353652..95d70914085b7f 100644
--- a/llvm/test/Analysis/Lint/noalias-byval.ll
+++ b/llvm/test/Analysis/Lint/noalias-byval.ll
@@ -8,7 +8,7 @@ declare void @llvm.memcpy.p0.p0.i32(ptr nocapture writeonly, ptr nocapture reado
; Function Attrs: argmemonly nounwind
declare void @llvm.memset.p0.i32(ptr nocapture writeonly, i8, i32, i1) #0
-declare void @f1(ptr noalias nocapture sret(%s), ptr nocapture readnone)
+declare void @f1(ptr noalias nocapture sret(%s), ptr nocapture)
define void @f2() {
entry:
diff --git a/llvm/test/Analysis/Lint/noalias-readnone.ll b/llvm/test/Analysis/Lint/noalias-readnone.ll
new file mode 100644
index 00000000000000..ba6cb7c9ee8e7a
--- /dev/null
+++ b/llvm/test/Analysis/Lint/noalias-readnone.ll
@@ -0,0 +1,14 @@
+; RUN: opt < %s -passes=lint -disable-output 2>&1 | FileCheck --allow-empty %s
+
+declare void @foo1(ptr noalias, ptr readnone)
+
+define void @test1(ptr %a) {
+entry:
+ call void @foo1(ptr %a, ptr %a)
+ ret void
+}
+
+; Lint should not complain about passing %a to both arguments even if one is
+; noalias, since the second argument is readnone.
+; CHECK-NOT: Unusual: noalias argument aliases another argument
+; CHECK-NOT: call void @foo1(ptr %a, ptr %a)
More information about the llvm-commits
mailing list