From: Hal Finkel Date: Wed, 28 Oct 2015 22:13:41 +0000 (+0000) Subject: Revert "r251451 - [AliasSetTracker] Use mod/ref information for UnknownInstr" X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=5b601e1cf00ca679106d273c0b053e6a8c17584f;p=oota-llvm.git Revert "r251451 - [AliasSetTracker] Use mod/ref information for UnknownInstr" It looks like this broke the stage 2 builder: http://lab.llvm.org:8080/green/job/clang-stage2-configure-Rlto/6989/ Original commit message: AliasSetTracker does not need to convert the access mode to ModRefAccess if the new visited UnknownInst has only 'REF' modrefinfo to existing pointers in the sets. Patch by Andrew Zhogin! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@251562 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/Analysis/AliasSetTracker.h b/include/llvm/Analysis/AliasSetTracker.h index e0a557ac9f5..37fd69b081c 100644 --- a/include/llvm/Analysis/AliasSetTracker.h +++ b/include/llvm/Analysis/AliasSetTracker.h @@ -124,7 +124,12 @@ class AliasSet : public ilist_node { /// memory (and not any particular access), whether it modifies or references /// the memory, or whether it does both. The lattice goes from "NoAccess" to /// either RefAccess or ModAccess, then to ModRefAccess as necessary. - typedef ModRefInfo AccessLattice; + enum AccessLattice { + NoAccess = 0, + RefAccess = 1, + ModAccess = 2, + ModRefAccess = RefAccess | ModAccess + }; unsigned Access : 2; /// The kind of alias relationship between pointers of the set. @@ -155,8 +160,8 @@ class AliasSet : public ilist_node { public: /// Accessors... - bool isRef() const { return Access & MRI_Ref; } - bool isMod() const { return Access & MRI_Mod; } + bool isRef() const { return Access & RefAccess; } + bool isMod() const { return Access & ModAccess; } bool isMustAlias() const { return Alias == SetMustAlias; } bool isMayAlias() const { return Alias == SetMayAlias; } @@ -221,7 +226,7 @@ private: friend struct ilist_sentinel_traits; AliasSet() : PtrList(nullptr), PtrListEnd(&PtrList), Forward(nullptr), RefCount(0), - Access(MRI_NoModRef), Alias(SetMustAlias), Volatile(false) { + Access(NoAccess), Alias(SetMustAlias), Volatile(false) { } AliasSet(const AliasSet &AS) = delete; @@ -249,9 +254,9 @@ private: void removeFromTracker(AliasSetTracker &AST); void addPointer(AliasSetTracker &AST, PointerRec &Entry, uint64_t Size, - const AAMDNodes &AAInfo, ModRefInfo MR, + const AAMDNodes &AAInfo, bool KnownMustAlias = false); - void addUnknownInst(Instruction *I, AliasAnalysis &AA, ModRefInfo MR); + void addUnknownInst(Instruction *I, AliasAnalysis &AA); void removeUnknownInst(AliasSetTracker &AST, Instruction *I) { bool WasEmpty = UnknownInsts.empty(); for (size_t i = 0, e = UnknownInsts.size(); i != e; ++i) @@ -268,18 +273,10 @@ private: public: /// aliasesPointer - Return true if the specified pointer "may" (or must) /// alias one of the members in the set. - /// MRcommon - if Ptr is aliased by existing UnknownInsts, - /// then not-null MRcommon will be set to the worst ModRefInfo met - /// + /// bool aliasesPointer(const Value *Ptr, uint64_t Size, const AAMDNodes &AAInfo, - AliasAnalysis &AA, ModRefInfo* MRcommon = nullptr) const; - /// aliasesUnknownInst - Return true if the specified UnknownInst - /// has not-null ModRefInfo (not MRI_NoModRef) with some - /// pointer or UnknownInst already existing in AliasSet - /// MRcommon - not-null MRcommon will be set to the worst ModRefInfo met - /// - bool aliasesUnknownInst(const Instruction *Inst, AliasAnalysis &AA, - ModRefInfo* MRcommon = nullptr) const; + AliasAnalysis &AA) const; + bool aliasesUnknownInst(const Instruction *Inst, AliasAnalysis &AA) const; }; inline raw_ostream& operator<<(raw_ostream &OS, const AliasSet &AS) { @@ -437,11 +434,9 @@ private: return AS; } AliasSet *findAliasSetForPointer(const Value *Ptr, uint64_t Size, - const AAMDNodes &AAInfo, - ModRefInfo* MRcommonPtr = nullptr); + const AAMDNodes &AAInfo); - AliasSet *findAliasSetForUnknownInst(Instruction *Inst, - ModRefInfo* MRcommonPtr = nullptr); + AliasSet *findAliasSetForUnknownInst(Instruction *Inst); }; inline raw_ostream& operator<<(raw_ostream &OS, const AliasSetTracker &AST) { diff --git a/lib/Analysis/AliasSetTracker.cpp b/lib/Analysis/AliasSetTracker.cpp index a1f57089492..3094049b3cc 100644 --- a/lib/Analysis/AliasSetTracker.cpp +++ b/lib/Analysis/AliasSetTracker.cpp @@ -95,7 +95,7 @@ void AliasSet::removeFromTracker(AliasSetTracker &AST) { void AliasSet::addPointer(AliasSetTracker &AST, PointerRec &Entry, uint64_t Size, const AAMDNodes &AAInfo, - ModRefInfo MR, bool KnownMustAlias) { + bool KnownMustAlias) { assert(!Entry.hasAliasSet() && "Entry already in set!"); // Check to see if we have to downgrade to _may_ alias. @@ -112,9 +112,6 @@ void AliasSet::addPointer(AliasSetTracker &AST, PointerRec &Entry, assert(Result != NoAlias && "Cannot be part of must set!"); } - // upgrading access if existing UnknownInst has ModRef with new pointer - Access |= MR; - Entry.setAliasSet(this); Entry.updateSizeAndAAInfo(Size, AAInfo); @@ -126,34 +123,20 @@ void AliasSet::addPointer(AliasSetTracker &AST, PointerRec &Entry, addRef(); // Entry points to alias set. } -void AliasSet::addUnknownInst(Instruction *I, AliasAnalysis &AA, - ModRefInfo MR) { +void AliasSet::addUnknownInst(Instruction *I, AliasAnalysis &AA) { if (UnknownInsts.empty()) addRef(); UnknownInsts.emplace_back(I); if (!I->mayWriteToMemory()) { Alias = SetMayAlias; - Access |= MRI_Ref; + Access |= RefAccess; return; } + // FIXME: This should use mod/ref information to make this not suck so bad Alias = SetMayAlias; - Access |= MR; -} - -namespace { - /// returns true if there is no request of worst ModRefInfo - /// (MRcommonPtr is null) - /// or when achieved maximum ModRefInfo (MRI_ModRef). - bool processMR(ModRefInfo MR, ModRefInfo* MRcommonPtr, ModRefInfo& MRcommon) { - MRcommon = ModRefInfo(MRcommon | MR); - return !MRcommonPtr || (MRcommon == MRI_ModRef); - } - bool fillExitMR(ModRefInfo* MRcommonPtr, ModRefInfo& MRcommon) { - if (MRcommonPtr) *MRcommonPtr = MRcommon; - return MRcommon != MRI_NoModRef; - } + Access = ModRefAccess; } /// aliasesPointer - Return true if the specified pointer "may" (or must) @@ -161,8 +144,7 @@ namespace { /// bool AliasSet::aliasesPointer(const Value *Ptr, uint64_t Size, const AAMDNodes &AAInfo, - AliasAnalysis &AA, - ModRefInfo* MRcommonPtr) const { + AliasAnalysis &AA) const { if (Alias == SetMustAlias) { assert(UnknownInsts.empty() && "Illegal must alias set!"); @@ -182,44 +164,35 @@ bool AliasSet::aliasesPointer(const Value *Ptr, uint64_t Size, MemoryLocation(I.getPointer(), I.getSize(), I.getAAInfo()))) return true; - // to gather worst ModRefInfo - ModRefInfo MRcommon = MRI_NoModRef; - // Check the unknown instructions... if (!UnknownInsts.empty()) { for (unsigned i = 0, e = UnknownInsts.size(); i != e; ++i) - if (processMR(AA.getModRefInfo(UnknownInsts[i], - MemoryLocation(Ptr, Size, AAInfo)), MRcommonPtr, MRcommon)) - return fillExitMR(MRcommonPtr, MRcommon); + if (AA.getModRefInfo(UnknownInsts[i], + MemoryLocation(Ptr, Size, AAInfo)) != MRI_NoModRef) + return true; } - return fillExitMR(MRcommonPtr, MRcommon); + return false; } bool AliasSet::aliasesUnknownInst(const Instruction *Inst, - AliasAnalysis &AA, - ModRefInfo* MRcommonPtr) const { + AliasAnalysis &AA) const { if (!Inst->mayReadOrWriteMemory()) return false; - // to gather worst ModRefInfo - ModRefInfo MRcommon = MRI_NoModRef; - for (unsigned i = 0, e = UnknownInsts.size(); i != e; ++i) { ImmutableCallSite C1(getUnknownInst(i)), C2(Inst); - if (!C1 || !C2 || - processMR(AA.getModRefInfo(C1, C2), MRcommonPtr, MRcommon) || - processMR(AA.getModRefInfo(C2, C1), MRcommonPtr, MRcommon)) - return fillExitMR(MRcommonPtr, MRcommon); + if (!C1 || !C2 || AA.getModRefInfo(C1, C2) != MRI_NoModRef || + AA.getModRefInfo(C2, C1) != MRI_NoModRef) + return true; } - for (iterator I = begin(), E = end(); I != E; ++I) { - ModRefInfo MR = AA.getModRefInfo( - Inst, MemoryLocation(I.getPointer(), I.getSize(), I.getAAInfo())); - if (processMR(MR, MRcommonPtr, MRcommon)) - return fillExitMR(MRcommonPtr, MRcommon); - } - return fillExitMR(MRcommonPtr, MRcommon); + for (iterator I = begin(), E = end(); I != E; ++I) + if (AA.getModRefInfo(Inst, MemoryLocation(I.getPointer(), I.getSize(), + I.getAAInfo())) != MRI_NoModRef) + return true; + + return false; } void AliasSetTracker::clear() { @@ -241,15 +214,11 @@ void AliasSetTracker::clear() { /// AliasSet *AliasSetTracker::findAliasSetForPointer(const Value *Ptr, uint64_t Size, - const AAMDNodes &AAInfo, - ModRefInfo* MRcommonPtr) { + const AAMDNodes &AAInfo) { AliasSet *FoundSet = nullptr; for (iterator I = begin(), E = end(); I != E;) { iterator Cur = I++; - ModRefInfo MR = MRI_NoModRef; - if (Cur->Forward || !Cur->aliasesPointer(Ptr, Size, AAInfo, AA, &MR)) - continue; - *MRcommonPtr = ModRefInfo(*MRcommonPtr | MR); + if (Cur->Forward || !Cur->aliasesPointer(Ptr, Size, AAInfo, AA)) continue; if (!FoundSet) { // If this is the first alias set ptr can go into. FoundSet = &*Cur; // Remember it. @@ -279,15 +248,12 @@ bool AliasSetTracker::containsUnknown(const Instruction *Inst) const { return false; } -AliasSet *AliasSetTracker::findAliasSetForUnknownInst(Instruction *Inst, - ModRefInfo* MRcommonPtr) { +AliasSet *AliasSetTracker::findAliasSetForUnknownInst(Instruction *Inst) { AliasSet *FoundSet = nullptr; for (iterator I = begin(), E = end(); I != E;) { iterator Cur = I++; - ModRefInfo MR = MRI_NoModRef; - if (Cur->Forward || !Cur->aliasesUnknownInst(Inst, AA, &MR)) + if (Cur->Forward || !Cur->aliasesUnknownInst(Inst, AA)) continue; - *MRcommonPtr = ModRefInfo(*MRcommonPtr | MR); if (!FoundSet) // If this is the first alias set ptr can go into. FoundSet = &*Cur; // Remember it. else if (!Cur->Forward) // Otherwise, we must merge the sets. @@ -313,23 +279,22 @@ AliasSet &AliasSetTracker::getAliasSetForPointer(Value *Pointer, uint64_t Size, return *Entry.getAliasSet(*this)->getForwardedTarget(*this); } - ModRefInfo MR = MRI_NoModRef; - if (AliasSet *AS = findAliasSetForPointer(Pointer, Size, AAInfo, &MR)) { + if (AliasSet *AS = findAliasSetForPointer(Pointer, Size, AAInfo)) { // Add it to the alias set it aliases. - AS->addPointer(*this, Entry, Size, AAInfo, MR); + AS->addPointer(*this, Entry, Size, AAInfo); return *AS; } if (New) *New = true; // Otherwise create a new alias set to hold the loaded pointer. AliasSets.push_back(new AliasSet()); - AliasSets.back().addPointer(*this, Entry, Size, AAInfo, MRI_NoModRef); + AliasSets.back().addPointer(*this, Entry, Size, AAInfo); return AliasSets.back(); } bool AliasSetTracker::add(Value *Ptr, uint64_t Size, const AAMDNodes &AAInfo) { bool NewPtr; - addPointer(Ptr, Size, AAInfo, MRI_NoModRef, NewPtr); + addPointer(Ptr, Size, AAInfo, AliasSet::NoAccess, NewPtr); return NewPtr; } @@ -340,7 +305,7 @@ bool AliasSetTracker::add(LoadInst *LI) { AAMDNodes AAInfo; LI->getAAMetadata(AAInfo); - AliasSet::AccessLattice Access = MRI_Ref; + AliasSet::AccessLattice Access = AliasSet::RefAccess; bool NewPtr; const DataLayout &DL = LI->getModule()->getDataLayout(); AliasSet &AS = addPointer(LI->getOperand(0), @@ -356,7 +321,7 @@ bool AliasSetTracker::add(StoreInst *SI) { AAMDNodes AAInfo; SI->getAAMetadata(AAInfo); - AliasSet::AccessLattice Access = MRI_Mod; + AliasSet::AccessLattice Access = AliasSet::ModAccess; bool NewPtr; const DataLayout &DL = SI->getModule()->getDataLayout(); Value *Val = SI->getOperand(0); @@ -373,7 +338,7 @@ bool AliasSetTracker::add(VAArgInst *VAAI) { bool NewPtr; addPointer(VAAI->getOperand(0), MemoryLocation::UnknownSize, AAInfo, - MRI_ModRef, NewPtr); + AliasSet::ModRefAccess, NewPtr); return NewPtr; } @@ -384,15 +349,14 @@ bool AliasSetTracker::addUnknown(Instruction *Inst) { if (!Inst->mayReadOrWriteMemory()) return true; // doesn't alias anything - ModRefInfo MR = MRI_NoModRef; - AliasSet *AS = findAliasSetForUnknownInst(Inst, &MR); + AliasSet *AS = findAliasSetForUnknownInst(Inst); if (AS) { - AS->addUnknownInst(Inst, AA, MR); + AS->addUnknownInst(Inst, AA); return false; } AliasSets.push_back(new AliasSet()); AS = &AliasSets.back(); - AS->addUnknownInst(Inst, AA, MR); + AS->addUnknownInst(Inst, AA); return true; } @@ -592,7 +556,7 @@ void AliasSetTracker::copyValue(Value *From, Value *To) { I = PointerMap.find_as(From); AliasSet *AS = I->second->getAliasSet(*this); AS->addPointer(*this, Entry, I->second->getSize(), - I->second->getAAInfo(), MRI_NoModRef, + I->second->getAAInfo(), true); } @@ -606,10 +570,10 @@ void AliasSet::print(raw_ostream &OS) const { OS << " AliasSet[" << (const void*)this << ", " << RefCount << "] "; OS << (Alias == SetMustAlias ? "must" : "may") << " alias, "; switch (Access) { - case MRI_NoModRef: OS << "No access "; break; - case MRI_Ref: OS << "Ref "; break; - case MRI_Mod: OS << "Mod "; break; - case MRI_ModRef: OS << "Mod/Ref "; break; + case NoAccess: OS << "No access "; break; + case RefAccess: OS << "Ref "; break; + case ModAccess: OS << "Mod "; break; + case ModRefAccess: OS << "Mod/Ref "; break; default: llvm_unreachable("Bad value for Access!"); } if (isVolatile()) OS << "[volatile] "; diff --git a/test/Transforms/LICM/licm_call_referenced_ptr.ll b/test/Transforms/LICM/licm_call_referenced_ptr.ll deleted file mode 100644 index a7a40131adc..00000000000 --- a/test/Transforms/LICM/licm_call_referenced_ptr.ll +++ /dev/null @@ -1,40 +0,0 @@ -; RUN: opt < %s -basicaa -licm -S | FileCheck %s - -declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture, i8* nocapture, i64, i32, i1) nounwind - -define i8 @"main"() { -entry: - %A = alloca [64 x i8] - %B = alloca [4 x i8] - %A0 = getelementptr [64 x i8], [64 x i8]* %A, i32 0, i32 0 - %B0 = getelementptr [4 x i8], [4 x i8]* %B, i32 0, i32 0 - %B1 = getelementptr [4 x i8], [4 x i8]* %B, i32 0, i32 1 - %B2 = getelementptr [4 x i8], [4 x i8]* %B, i32 0, i32 2 - %B3 = getelementptr [4 x i8], [4 x i8]* %B, i32 0, i32 3 - store i8 0, i8* %A0 - store i8 32, i8* %B0 - store i8 73, i8* %B1 - store i8 74, i8* %B2 - store i8 75, i8* %B3 - br label %loop_begin - -loop_begin: -; CHECK: loop_begin: -; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* %A0, i8* %B0, i64 4, i32 4, i1 false) - - %b_val = load i8, i8* %B0 - - ; *B is invariant in loop and limit_val must be hoisted - %limit_val_1 = mul i8 %b_val, 3 - %limit_val = add i8 %limit_val_1, 67 - - call void @llvm.memcpy.p0i8.p0i8.i64(i8* %A0, i8* %B0, i64 4, i32 4, i1 false) - - %exitcond = icmp ugt i8 164, %limit_val - br i1 %exitcond, label %after_loop, label %loop_begin - -after_loop: - %b_val_result = load i8, i8* %B0 - ret i8 %b_val_result -} -