From 9b1e00738c5ddba681e17e5cb7c260d9afc4c3a7 Mon Sep 17 00:00:00 2001 From: Philip Reames Date: Tue, 17 May 2022 20:34:19 -0700 Subject: [PATCH] [BasicAA] Remove unneeded special case for malloc/calloc This code pre-exists the generic handling for inaccessiblememonly. If we remove it and update one test with inaccessiblememonly, nothing else changes. Note that simply running O1 on that test would annotate malloc with the missing inaccessiblememonly. --- llvm/lib/Analysis/BasicAliasAnalysis.cpp | 14 -------------- llvm/test/Transforms/GVN/nonescaping-malloc.ll | 2 +- 2 files changed, 1 insertion(+), 15 deletions(-) diff --git a/llvm/lib/Analysis/BasicAliasAnalysis.cpp b/llvm/lib/Analysis/BasicAliasAnalysis.cpp index cfb3468..63d5842 100644 --- a/llvm/lib/Analysis/BasicAliasAnalysis.cpp +++ b/llvm/lib/Analysis/BasicAliasAnalysis.cpp @@ -994,20 +994,6 @@ ModRefInfo BasicAAResult::getModRefInfo(const CallBase *Call, } } - // If the call is malloc/calloc like, we can assume that it doesn't - // modify any IR visible value. This is only valid because we assume these - // routines do not read values visible in the IR. TODO: Consider special - // casing realloc and strdup routines which access only their arguments as - // well. Or alternatively, replace all of this with inaccessiblememonly once - // that's implemented fully. - if (isMallocOrCallocLikeFn(Call, &TLI)) { - // Be conservative if the accessed pointer may alias the allocation - - // fallback to the generic handling below. - if (getBestAAResults().alias(MemoryLocation::getBeforeOrAfter(Call), Loc, - AAQI) == AliasResult::NoAlias) - return ModRefInfo::NoModRef; - } - // Ideally, there should be no need to special case for memcpy/memove // intrinsics here since general machinery (based on memory attributes) should // already handle it just fine. Unfortunately, it doesn't due to deficiency in diff --git a/llvm/test/Transforms/GVN/nonescaping-malloc.ll b/llvm/test/Transforms/GVN/nonescaping-malloc.ll index fd61835..a2a7bda 100644 --- a/llvm/test/Transforms/GVN/nonescaping-malloc.ll +++ b/llvm/test/Transforms/GVN/nonescaping-malloc.ll @@ -35,7 +35,7 @@ entry: declare i64 @strlen(i8* nocapture) nounwind readonly -declare noalias i8* @malloc(i64) nounwind +declare noalias i8* @malloc(i64) nounwind inaccessiblememonly declare i32 @_ZN4llvm13StringMapImpl15LookupBucketForENS_9StringRefE(%"struct.llvm::StringMapImpl"*, i64, i64) -- 2.7.4