[PATCH] D157737: [Lint] Permit aliasing noalias and readnone arguments

Bjorn Pettersson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Aug 13 09:41:33 PDT 2023


bjope updated this revision to Diff 549711.
bjope added a comment.

Updated to use I.doesNotAccessMemory.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157737/new/

https://reviews.llvm.org/D157737

Files:
  llvm/lib/Analysis/Lint.cpp
  llvm/test/Analysis/Lint/noalias-byval.ll
  llvm/test/Analysis/Lint/noalias-readnone.ll


Index: llvm/test/Analysis/Lint/noalias-readnone.ll
===================================================================
--- /dev/null
+++ 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)
Index: llvm/test/Analysis/Lint/noalias-byval.ll
===================================================================
--- llvm/test/Analysis/Lint/noalias-byval.ll
+++ 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:
Index: llvm/lib/Analysis/Lint.cpp
===================================================================
--- llvm/lib/Analysis/Lint.cpp
+++ 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 &&


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D157737.549711.patch
Type: text/x-patch
Size: 1886 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230813/d76c688b/attachment.bin>


More information about the llvm-commits mailing list