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 @@ -19,8 +19,6 @@ #include "llvm/ADT/SmallPtrSet.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/Statistic.h" -// #include "llvm/Analysis/AliasAnalysis.h" -#include "llvm/Analysis/ValueTracking.h" #include "llvm/Analysis/CaptureTracking.h" #include "llvm/Analysis/GlobalsModRef.h" #include "llvm/IR/Argument.h" @@ -704,7 +702,7 @@ // Already noalias. if (F.returnDoesNotAlias()) { - indicatePessimisticFixpoint(); + indicateOptimisticFixpoint(); return; } } @@ -720,29 +718,28 @@ if (!AARetValImpl) return ChangeStatus::CHANGED; - for (auto It = AARetValImpl->begin(); It != AARetValImpl->end(); ++It) { - Value *RV = It->first; - const SmallPtrSet ReturnInsts = It->second; + for (auto &It : *AARetValImpl) { + Value *RV = It.first; if (Constant *C = dyn_cast(RV)) if (C->isNullValue() || isa(C)) continue; - if (PointerMayBeCaptured(RV, false, false)) { + if (PointerMayBeCaptured(RV, false, /* StoreCaptures */ true)) { indicatePessimisticFixpoint(); return ChangeStatus::CHANGED; } - for (auto RI : ReturnInsts) { - ImmutableCallSite ICS(RI); - auto *NoAliasReturnedAA = A.getAAFor(*this, *RI); + ImmutableCallSite ICS(RV); + if(ICS && ICS.returnDoesNotAlias()) + continue; - if (ICS && - (!NoAliasReturnedAA || !NoAliasReturnedAA->isAssumedNoAlias()) && - !ICS.returnDoesNotAlias()) { - indicatePessimisticFixpoint(); - return ChangeStatus::CHANGED; - } + /// FIXME: Check ReturnInsts for RV, for escape queries. + auto *NoAliasAA = A.getAAFor(*this, *RV); + + if (!NoAliasAA || !NoAliasAA->isAssumedNoAlias()) { + indicatePessimisticFixpoint(); + return ChangeStatus::CHANGED; } } @@ -895,12 +892,13 @@ if (!ReturnType->isVoidTy()) { // Argument attribute "returned" --- Create Only one per function even // though it is an argument attribute. - if (!Whitelist || Whitelist->count(AAReturnedValues::ID)) + if (!Whitelist || Whitelist->count(AAReturnedValues::ID)) { registerAA(*new AAReturnedValuesImpl(F, InfoCache)); - // Every function with pointer return type might be marked noalias. - if (ReturnType->isPointerTy()) - registerAA(*new AANoAliasReturned(F, InfoCache)); + // Every function with pointer return type might be marked noalias. + if(ReturnType->isPointerTy()) + registerAA(*new AANoAliasReturned(F, InfoCache)); + } } // Walk all instructions to find more attribute opportunities and also diff --git a/llvm/test/Transforms/FunctionAttrs/noalias.ll b/llvm/test/Transforms/FunctionAttrs/noalias.ll --- a/llvm/test/Transforms/FunctionAttrs/noalias.ll +++ b/llvm/test/Transforms/FunctionAttrs/noalias.ll @@ -1,4 +1,4 @@ -; RUN: opt -S -attributor < %s | FileCheck %s +; RUN: opt -S -attributor -attributor-disable=false < %s | FileCheck %s ; TEST 1 - negative. diff --git a/llvm/test/Transforms/FunctionAttrs/nonnull.ll b/llvm/test/Transforms/FunctionAttrs/nonnull.ll --- a/llvm/test/Transforms/FunctionAttrs/nonnull.ll +++ b/llvm/test/Transforms/FunctionAttrs/nonnull.ll @@ -7,7 +7,6 @@ ; Return a pointer trivially nonnull (call return attribute) define i8* @test1() { ; CHECK: define nonnull i8* @test1 -; ATTRIBUTOR: define "noalias" i8* @test1 %ret = call i8* @ret_nonnull() ret i8* %ret } @@ -15,7 +14,6 @@ ; Return a pointer trivially nonnull (argument attribute) define i8* @test2(i8* nonnull %p) { ; CHECK: define nonnull i8* @test2 -; ATTRIBUTOR: define "noalias" i8* @test2 ret i8* %p } @@ -30,7 +28,6 @@ define i8* @test3() { ; CHECK: define nonnull i8* @test3 -; ATTRIBUTOR: define "noalias" i8* @test3 call i8* @scc_binder() %ret = call i8* @ret_nonnull() ret i8* %ret @@ -73,7 +70,6 @@ define i8* @test6() { entry: ; CHECK: define nonnull i8* @test6 -; ATTRIBUTOR: define "noalias" i8* @test6 %ret = call i8* @ret_nonnull() br label %loop loop: @@ -229,7 +225,6 @@ } ; CHECK: define nonnull i32* @gep1( -; ATTRIBUTOR: define "noalias" i32* @gep1( define i32* @gep1(i32* %p) { %q = getelementptr inbounds i32, i32* %p, i32 1 ret i32* %q @@ -238,13 +233,11 @@ define i32* @gep1_no_null_opt(i32* %p) #0 { ; Should't be able to derive nonnull based on gep. ; CHECK: define i32* @gep1_no_null_opt( -; ATTRIBUTOR: define "noalias" i32* @gep1_no_null_opt( %q = getelementptr inbounds i32, i32* %p, i32 1 ret i32* %q } ; CHECK: define i32 addrspace(3)* @gep2( -; ATTRIBUTOR: define "noalias" i32 addrspace(3)* @gep2( define i32 addrspace(3)* @gep2(i32 addrspace(3)* %p) { %q = getelementptr inbounds i32, i32 addrspace(3)* %p, i32 1 ret i32 addrspace(3)* %q