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

Bjorn Pettersson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 11 10:42:28 PDT 2023


bjope created this revision.
bjope added reviewers: efriedma, fhahn, jdoerfert, nikic.
Herald added subscribers: jeroen.dobbelaere, StephenFan, hiraditya.
Herald added a project: All.
bjope requested review of this revision.
Herald added a project: LLVM.

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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157737

Files:
  llvm/lib/Analysis/Lint.cpp
  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 %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/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 (F->hasParamAttribute(ArgNo, Attribute::ReadNone))
+              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.549456.patch
Type: text/x-patch
Size: 1384 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230811/e6baddd3/attachment.bin>


More information about the llvm-commits mailing list