diff --git a/llvm/include/llvm/Analysis/MemorySSA.h b/llvm/include/llvm/Analysis/MemorySSA.h --- a/llvm/include/llvm/Analysis/MemorySSA.h +++ b/llvm/include/llvm/Analysis/MemorySSA.h @@ -1272,11 +1272,11 @@ const_cast(Location.Ptr), OriginalAccess->getBlock()->getModule()->getDataLayout(), nullptr); - if (!Translator.translateValue(OriginalAccess->getBlock(), - DefIterator.getPhiArgBlock(), DT, true)) - if (Translator.getAddr() != CurrentPair.second.Ptr) - CurrentPair.second = - CurrentPair.second.getWithNewPtr(Translator.getAddr()); + if (Value *Addr = + Translator.translateValue(OriginalAccess->getBlock(), + DefIterator.getPhiArgBlock(), DT, true)) + if (Addr != CurrentPair.second.Ptr) + CurrentPair.second = CurrentPair.second.getWithNewPtr(Addr); // Mark size as unknown, if the location is not guaranteed to be // loop-invariant for any possible loop in the function. Setting the size diff --git a/llvm/include/llvm/Analysis/PHITransAddr.h b/llvm/include/llvm/Analysis/PHITransAddr.h --- a/llvm/include/llvm/Analysis/PHITransAddr.h +++ b/llvm/include/llvm/Analysis/PHITransAddr.h @@ -52,8 +52,7 @@ PHITransAddr(Value *Addr, const DataLayout &DL, AssumptionCache *AC) : Addr(Addr), DL(DL), AC(AC) { // If the address is an instruction, the whole thing is considered an input. - if (Instruction *I = dyn_cast(Addr)) - InstInputs.push_back(I); + addAsInput(Addr); } Value *getAddr() const { return Addr; } @@ -63,10 +62,9 @@ bool needsPHITranslationFromBlock(BasicBlock *BB) const { // We do need translation if one of our input instructions is defined in // this block. - for (unsigned i = 0, e = InstInputs.size(); i != e; ++i) - if (InstInputs[i]->getParent() == BB) - return true; - return false; + return any_of(InstInputs, [BB](const auto &InstInput) { + return InstInput->getParent() == BB; + }); } /// isPotentiallyPHITranslatable - If this needs PHI translation, return true @@ -76,10 +74,9 @@ /// translateValue - PHI translate the current address up the CFG from /// CurBB to Pred, updating our state to reflect any needed changes. If - /// 'MustDominate' is true, the translated value must dominate - /// PredBB. This returns true on failure and sets Addr to null. - bool translateValue(BasicBlock *CurBB, BasicBlock *PredBB, - const DominatorTree *DT, bool MustDominate); + /// 'MustDominate' is true, the translated value must dominate PredBB. + Value *translateValue(BasicBlock *CurBB, BasicBlock *PredBB, + const DominatorTree *DT, bool MustDominate); /// translateWithInsertion - PHI translate this value into the specified /// predecessor block, inserting a computation of the value if it is 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 @@ -1298,8 +1298,8 @@ // Get the PHI translated pointer in this predecessor. This can fail if // not translatable, in which case the getAddr() returns null. PHITransAddr &PredPointer = PredList.back().second; - PredPointer.translateValue(BB, Pred, &DT, /*MustDominate=*/false); - Value *PredPtrVal = PredPointer.getAddr(); + Value *PredPtrVal = + PredPointer.translateValue(BB, Pred, &DT, /*MustDominate=*/false); // Check to see if we have already visited this pred block with another // pointer. If so, we can't do this lookup. This failure can occur diff --git a/llvm/lib/Analysis/PHITransAddr.cpp b/llvm/lib/Analysis/PHITransAddr.cpp --- a/llvm/lib/Analysis/PHITransAddr.cpp +++ b/llvm/lib/Analysis/PHITransAddr.cpp @@ -77,11 +77,8 @@ } // Validate the operands of the instruction. - for (unsigned i = 0, e = I->getNumOperands(); i != e; ++i) - if (!verifySubExpr(I->getOperand(i), InstInputs)) - return false; - - return true; + return all_of(I->operands(), + [&](Value *Op) { return verifySubExpr(Op, InstInputs); }); } /// verify - Check internal consistency of this data structure. If the @@ -305,10 +302,10 @@ /// PHITranslateValue - PHI translate the current address up the CFG from /// CurBB to Pred, updating our state to reflect any needed changes. If -/// 'MustDominate' is true, the translated value must dominate -/// PredBB. This returns true on failure and sets Addr to null. -bool PHITransAddr::translateValue(BasicBlock *CurBB, BasicBlock *PredBB, - const DominatorTree *DT, bool MustDominate) { +/// 'MustDominate' is true, the translated value must dominate PredBB. +Value *PHITransAddr::translateValue(BasicBlock *CurBB, BasicBlock *PredBB, + const DominatorTree *DT, + bool MustDominate) { assert(DT || !MustDominate); assert(verify() && "Invalid PHITransAddr!"); if (DT && DT->isReachableFromEntry(PredBB)) @@ -323,7 +320,7 @@ if (!DT->dominates(Inst->getParent(), PredBB)) Addr = nullptr; - return Addr == nullptr; + return Addr; } /// PHITranslateWithInsertion - PHI translate this value into the specified