Commit c0682840 authored by Bjorn Pettersson's avatar Bjorn Pettersson
Browse files

[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
parent a5925eee
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -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 &&
+1 −1
Original line number Diff line number Diff line
@@ -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:
+14 −0
Original line number Diff line number Diff line
; 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)