diff --git a/llvm/include/llvm/Analysis/MemoryBuiltins.h b/llvm/include/llvm/Analysis/MemoryBuiltins.h --- a/llvm/include/llvm/Analysis/MemoryBuiltins.h +++ b/llvm/include/llvm/Analysis/MemoryBuiltins.h @@ -56,10 +56,6 @@ bool isAllocationFn(const Value *V, function_ref GetTLI); -/// Tests if a value is a call or invoke to a function that returns a -/// NoAlias pointer (including malloc/calloc/realloc/strdup-like functions). -bool isNoAliasFn(const Value *V, const TargetLibraryInfo *TLI); - /// Tests if a value is a call or invoke to a library function that /// allocates uninitialized memory (such as malloc). bool isMallocLikeFn(const Value *V, const TargetLibraryInfo *TLI); diff --git a/llvm/lib/Analysis/MemoryBuiltins.cpp b/llvm/lib/Analysis/MemoryBuiltins.cpp --- a/llvm/lib/Analysis/MemoryBuiltins.cpp +++ b/llvm/lib/Analysis/MemoryBuiltins.cpp @@ -222,11 +222,6 @@ return Result; } -static bool hasNoAliasAttr(const Value *V) { - const auto *CB = dyn_cast(V); - return CB && CB->hasRetAttr(Attribute::NoAlias); -} - /// Tests if a value is a call or invoke to a library function that /// allocates or reallocates memory (either malloc, calloc, realloc, or strdup /// like). @@ -238,15 +233,6 @@ return getAllocationData(V, AnyAlloc, GetTLI).hasValue(); } -/// Tests if a value is a call or invoke to a function that returns a -/// NoAlias pointer (including malloc/calloc/realloc/strdup-like functions). -bool llvm::isNoAliasFn(const Value *V, const TargetLibraryInfo *TLI) { - // it's safe to consider realloc as noalias since accessing the original - // pointer is undefined behavior - return isAllocationFn(V, TLI) || - hasNoAliasAttr(V); -} - /// Tests if a value is a call or invoke to a library function that /// allocates uninitialized memory (such as malloc). bool llvm::isMallocLikeFn(const Value *V, const TargetLibraryInfo *TLI) { diff --git a/llvm/lib/Analysis/MemoryDependenceAnalysis.cpp b/llvm/lib/Analysis/MemoryDependenceAnalysis.cpp --- a/llvm/lib/Analysis/MemoryDependenceAnalysis.cpp +++ b/llvm/lib/Analysis/MemoryDependenceAnalysis.cpp @@ -594,7 +594,7 @@ // turn into undef. Note that we can bypass the allocation itself when // looking for a clobber in many cases; that's an alias property and is // handled by BasicAA. - if (isa(Inst) || isNoAliasFn(Inst, &TLI)) { + if (isa(Inst) || isNoAliasCall(Inst)) { const Value *AccessPtr = getUnderlyingObject(MemLoc.Ptr); if (AccessPtr == Inst || BatchAA.isMustAlias(Inst, AccessPtr)) return MemDepResult::getDef(Inst); diff --git a/llvm/lib/Transforms/IPO/Attributor.cpp b/llvm/lib/Transforms/IPO/Attributor.cpp --- a/llvm/lib/Transforms/IPO/Attributor.cpp +++ b/llvm/lib/Transforms/IPO/Attributor.cpp @@ -209,7 +209,6 @@ return UndefValue::get(&Ty); if (isAllocationFn(&Obj, TLI)) return getInitialValueOfAllocation(&cast(Obj), TLI, &Ty); - auto *GV = dyn_cast(&Obj); if (!GV || !GV->hasLocalLinkage()) return nullptr; @@ -305,8 +304,6 @@ SmallVector PIs; SmallVector NewCopies; - const auto *TLI = - A.getInfoCache().getTargetLibraryInfoForFunction(*SI.getFunction()); for (Value *Obj : Objects) { LLVM_DEBUG(dbgs() << "Visit underlying object " << *Obj << "\n"); if (isa(Obj)) @@ -324,7 +321,7 @@ return false; } if (!isa(Obj) && !isa(Obj) && - !isNoAliasFn(Obj, TLI)) { + !isNoAliasCall(Obj)) { LLVM_DEBUG(dbgs() << "Underlying object is not supported yet: " << *Obj << "\n";); return false; diff --git a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp --- a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp +++ b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp @@ -5274,9 +5274,6 @@ continue; return false; } - if (!isa(Obj) && !isa(Obj) && - !isNoAliasFn(Obj, TLI)) - return false; Constant *InitialVal = AA::getInitialValueForObj(*Obj, *L.getType(), TLI); if (!InitialVal || !Union(*InitialVal)) return false; diff --git a/llvm/test/Transforms/GVN/malloc-load-removal.ll b/llvm/test/Transforms/GVN/malloc-load-removal.ll --- a/llvm/test/Transforms/GVN/malloc-load-removal.ll +++ b/llvm/test/Transforms/GVN/malloc-load-removal.ll @@ -5,7 +5,7 @@ target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128" target triple = "x86_64-apple-macosx10.8.0" -declare i8* @malloc(i64) nounwind +declare noalias i8* @malloc(i64) nounwind define noalias i8* @test1() nounwind uwtable ssp { entry: @@ -30,7 +30,7 @@ ; CHECK_NO_LIBCALLS: icmp } -declare i8* @_Znwm(i64) nounwind +declare noalias i8* @_Znwm(i64) nounwind define noalias i8* @test2() nounwind uwtable ssp { entry: @@ -55,7 +55,7 @@ ; CHECK_NO_LIBCALLS: icmp } -declare i8* @aligned_alloc(i64, i64) nounwind +declare noalias i8* @aligned_alloc(i64, i64) nounwind define noalias i8* @test3() nounwind uwtable ssp { entry: diff --git a/llvm/unittests/Analysis/MemoryBuiltinsTest.cpp b/llvm/unittests/Analysis/MemoryBuiltinsTest.cpp --- a/llvm/unittests/Analysis/MemoryBuiltinsTest.cpp +++ b/llvm/unittests/Analysis/MemoryBuiltinsTest.cpp @@ -36,14 +36,12 @@ CallInst::Create(AllocSizeFn, {ConstantInt::get(ArgTy, 100)})); const TargetLibraryInfo *TLI = nullptr; - EXPECT_FALSE(isNoAliasFn(Caller.get(), TLI)); EXPECT_FALSE(isMallocLikeFn(Caller.get(), TLI)); EXPECT_FALSE(isCallocLikeFn(Caller.get(), TLI)); EXPECT_FALSE(isAllocLikeFn(Caller.get(), TLI)); // FIXME: We might be able to treat allocsize functions as general allocation - // functions. For the moment, being conservative seems better (and we'd have - // to plumb stuff around `isNoAliasFn`). + // functions. EXPECT_FALSE(isAllocationFn(Caller.get(), TLI)); } }