Skip to content

Commit

Permalink
[Lint] Permit aliasing noalias and readnone arguments
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bjope committed Aug 14, 2023
1 parent a5925ee commit c068284
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
4 changes: 4 additions & 0 deletions llvm/lib/Analysis/Lint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/Analysis/Lint/noalias-byval.ll
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
14 changes: 14 additions & 0 deletions llvm/test/Analysis/Lint/noalias-readnone.ll
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit c068284

Please sign in to comment.