diff options
Diffstat (limited to 'lib/Transforms/Scalar/JumpThreading.cpp')
| -rw-r--r-- | lib/Transforms/Scalar/JumpThreading.cpp | 19 | 
1 files changed, 16 insertions, 3 deletions
diff --git a/lib/Transforms/Scalar/JumpThreading.cpp b/lib/Transforms/Scalar/JumpThreading.cpp index 6b0377e0ecb39..1476f7850cf07 100644 --- a/lib/Transforms/Scalar/JumpThreading.cpp +++ b/lib/Transforms/Scalar/JumpThreading.cpp @@ -282,7 +282,7 @@ bool JumpThreading::runOnFunction(Function &F) {    auto AA = &getAnalysis<AAResultsWrapperPass>().getAAResults();    std::unique_ptr<BlockFrequencyInfo> BFI;    std::unique_ptr<BranchProbabilityInfo> BPI; -  bool HasProfileData = F.getEntryCount().hasValue(); +  bool HasProfileData = F.hasProfileData();    if (HasProfileData) {      LoopInfo LI{DominatorTree(F)};      BPI.reset(new BranchProbabilityInfo(F, LI, TLI)); @@ -307,8 +307,7 @@ PreservedAnalyses JumpThreadingPass::run(Function &F,    std::unique_ptr<BlockFrequencyInfo> BFI;    std::unique_ptr<BranchProbabilityInfo> BPI; -  bool HasProfileData = F.getEntryCount().hasValue(); -  if (HasProfileData) { +  if (F.hasProfileData()) {      LoopInfo LI{DominatorTree(F)};      BPI.reset(new BranchProbabilityInfo(F, LI, &TLI));      BFI.reset(new BlockFrequencyInfo(F, *BPI, LI)); @@ -1333,6 +1332,20 @@ bool JumpThreadingPass::SimplifyPartiallyRedundantLoad(LoadInst *LI) {    // code size.    BasicBlock *UnavailablePred = nullptr; +  // If the value is unavailable in one of predecessors, we will end up +  // inserting a new instruction into them. It is only valid if all the +  // instructions before LI are guaranteed to pass execution to its successor, +  // or if LI is safe to speculate. +  // TODO: If this logic becomes more complex, and we will perform PRE insertion +  // farther than to a predecessor, we need to reuse the code from GVN's PRE. +  // It requires domination tree analysis, so for this simple case it is an +  // overkill. +  if (PredsScanned.size() != AvailablePreds.size() && +      !isSafeToSpeculativelyExecute(LI)) +    for (auto I = LoadBB->begin(); &*I != LI; ++I) +      if (!isGuaranteedToTransferExecutionToSuccessor(&*I)) +        return false; +    // If there is exactly one predecessor where the value is unavailable, the    // already computed 'OneUnavailablePred' block is it.  If it ends in an    // unconditional branch, we know that it isn't a critical edge.  | 
