diff --git a/llvm/include/llvm/Transforms/Utils/PredicateInfo.h b/llvm/include/llvm/Transforms/Utils/PredicateInfo.h --- a/llvm/include/llvm/Transforms/Utils/PredicateInfo.h +++ b/llvm/include/llvm/Transforms/Utils/PredicateInfo.h @@ -169,7 +169,8 @@ /// accesses. class PredicateInfo { public: - PredicateInfo(Function &, DominatorTree &, AssumptionCache &); + PredicateInfo(Function &, DominatorTree &, AssumptionCache &, + bool UseDirectRenamedValue = false); ~PredicateInfo(); void verifyPredicateInfo() const; diff --git a/llvm/lib/Transforms/Utils/PredicateInfo.cpp b/llvm/lib/Transforms/Utils/PredicateInfo.cpp --- a/llvm/lib/Transforms/Utils/PredicateInfo.cpp +++ b/llvm/lib/Transforms/Utils/PredicateInfo.cpp @@ -271,6 +271,11 @@ // edges. DenseSet> EdgeUsesOnly; + // If set to true, the directly renamed value is used as OriginalOp, rather + // than the original IR value that has been renamed. This is only relevant for + // nested predicates of the same value. + bool UseDirectRenamedValue; + ValueInfo &getOrCreateValueInfo(Value *); const ValueInfo &getValueInfo(Value *) const; @@ -292,8 +297,9 @@ public: PredicateInfoBuilder(PredicateInfo &PI, Function &F, DominatorTree &DT, - AssumptionCache &AC) - : PI(PI), F(F), DT(DT), AC(AC) { + AssumptionCache &AC, bool UseDirectRenamedValue) + : PI(PI), F(F), DT(DT), AC(AC), + UseDirectRenamedValue(UseDirectRenamedValue) { // Push an empty operand info so that we can detect 0 as not finding one ValueInfos.resize(1); } @@ -600,6 +606,11 @@ RenameIter == RenameStack.begin() ? OrigOp : (RenameIter - 1)->Def; ValueDFS &Result = *RenameIter; auto *ValInfo = Result.PInfo; + // Update OriginalOp to latest entry on the rename stack. + if (UseDirectRenamedValue) + ValInfo->OriginalOp = (RenameStack.end() - Start) == RenameStack.begin() + ? OrigOp + : (RenameStack.end() - Start - 1)->Def; // For edge predicates, we can just place the operand in the block before // the terminator. For assume, we have to place it right before the assume // to ensure we dominate all of our uses. Always insert right before the @@ -794,9 +805,9 @@ } PredicateInfo::PredicateInfo(Function &F, DominatorTree &DT, - AssumptionCache &AC) + AssumptionCache &AC, bool UseDirectRenamedValue) : F(F) { - PredicateInfoBuilder Builder(*this, F, DT, AC); + PredicateInfoBuilder Builder(*this, F, DT, AC, UseDirectRenamedValue); Builder.buildPredicateInfo(); }