diff --git a/llvm/lib/Analysis/Lint.cpp b/llvm/lib/Analysis/Lint.cpp --- a/llvm/lib/Analysis/Lint.cpp +++ b/llvm/lib/Analysis/Lint.cpp @@ -235,6 +235,10 @@ // 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 --- a/llvm/test/Analysis/Lint/noalias-byval.ll +++ b/llvm/test/Analysis/Lint/noalias-byval.ll @@ -8,7 +8,7 @@ ; 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 --- /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)