[llvm] 03f9d0f - [TBAA] Model call accessing immutable type as readnone

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 14 01:11:26 PDT 2022


Author: Nikita Popov
Date: 2022-10-14T10:08:37+02:00
New Revision: 03f9d0ff220828c27d05ced69a13dcb24e0217c0

URL: https://github.com/llvm/llvm-project/commit/03f9d0ff220828c27d05ced69a13dcb24e0217c0
DIFF: https://github.com/llvm/llvm-project/commit/03f9d0ff220828c27d05ced69a13dcb24e0217c0.diff

LOG: [TBAA] Model call accessing immutable type as readnone

Accesses to constant memory are not observable and should be
reported as readnone, not readonly. This is consistent with what
we do for normal (non-call) instructions: For those, the TBAA
metadata will result in pointsToConstantMemory() returning true,
which will then result in a NoModRef result, not a Ref result.

Differential Revision: https://reviews.llvm.org/D135864

Added: 
    

Modified: 
    llvm/lib/Analysis/TypeBasedAliasAnalysis.cpp
    llvm/test/Analysis/TypeBasedAliasAnalysis/functionattrs.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Analysis/TypeBasedAliasAnalysis.cpp b/llvm/lib/Analysis/TypeBasedAliasAnalysis.cpp
index f5a451bee2bf5..d2d7044962de7 100644
--- a/llvm/lib/Analysis/TypeBasedAliasAnalysis.cpp
+++ b/llvm/lib/Analysis/TypeBasedAliasAnalysis.cpp
@@ -410,12 +410,11 @@ TypeBasedAAResult::getModRefBehavior(const CallBase *Call,
   if (!EnableTBAA)
     return AAResultBase::getModRefBehavior(Call, AAQI);
 
-  // If this is an "immutable" type, we can assume the call doesn't write
-  // to memory.
+  // If this is an "immutable" type, the access is not observable.
   if (const MDNode *M = Call->getMetadata(LLVMContext::MD_tbaa))
     if ((!isStructPathTBAA(M) && TBAANode(M).isTypeImmutable()) ||
         (isStructPathTBAA(M) && TBAAStructTagNode(M).isTypeImmutable()))
-      return FunctionModRefBehavior::readOnly();
+      return FunctionModRefBehavior::none();
 
   return AAResultBase::getModRefBehavior(Call, AAQI);
 }

diff  --git a/llvm/test/Analysis/TypeBasedAliasAnalysis/functionattrs.ll b/llvm/test/Analysis/TypeBasedAliasAnalysis/functionattrs.ll
index b34a1a57bfba2..6134f578895bc 100644
--- a/llvm/test/Analysis/TypeBasedAliasAnalysis/functionattrs.ll
+++ b/llvm/test/Analysis/TypeBasedAliasAnalysis/functionattrs.ll
@@ -21,8 +21,8 @@ define void @test0_no(i32* %p) nounwind {
   ret void
 }
 
-; Add the readonly attribute, since there's just a call to a function which 
-; TBAA says doesn't modify any memory.
+; Add the readnone attribute, since there's just a call to a function which
+; TBAA says only accesses constant memory.
 
 ; CHECK: define void @test1_yes(i32* nocapture %p) #2 {
 define void @test1_yes(i32* %p) nounwind {
@@ -74,7 +74,7 @@ declare void @llvm.memcpy.p0i8.p0i8.i64(i8*, i8*, i64, i1) nounwind
 
 ; CHECK: attributes #0 = { mustprogress nofree norecurse nosync nounwind readnone willreturn }
 ; CHECK: attributes #1 = { argmemonly mustprogress nofree norecurse nosync nounwind willreturn writeonly }
-; CHECK: attributes #2 = { nofree nounwind readonly }
+; CHECK: attributes #2 = { nofree nosync nounwind readnone }
 ; CHECK: attributes #3 = { nounwind }
 ; CHECK: attributes #4 = { mustprogress nofree nosync nounwind readnone willreturn }
 ; CHECK: attributes #5 = { argmemonly mustprogress nofree nosync nounwind willreturn }


        


More information about the llvm-commits mailing list