[llvm] verify incremental prof updates (PR #188651)

Mircea Trofin via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 25 17:58:45 PDT 2026


https://github.com/mtrofin created https://github.com/llvm/llvm-project/pull/188651

None

>From 58bd81e6885cec1a37756a5fb549dd45a3ab2004 Mon Sep 17 00:00:00 2001
From: Mircea Trofin <mtrofin at google.com>
Date: Wed, 25 Mar 2026 17:55:57 -0700
Subject: [PATCH] verify incremental prof updates

---
 .../IncrementalUpdateProfileAnalysis.h        |  65 +++++++
 .../llvm/Transforms/Scalar/JumpThreading.h    |  29 +---
 llvm/lib/Analysis/CMakeLists.txt              |   1 +
 .../IncrementalUpdateProfileAnalysis.cpp      |  68 ++++++++
 llvm/lib/Passes/PassBuilder.cpp               |   1 +
 llvm/lib/Passes/PassRegistry.def              |   1 +
 llvm/lib/Transforms/Scalar/JumpThreading.cpp  | 161 +++++-------------
 llvm/test/Other/new-pm-defaults.ll            |   1 +
 llvm/test/Other/new-pm-lto-defaults.ll        |   1 +
 .../Other/new-pm-thinlto-postlink-defaults.ll |   1 +
 .../new-pm-thinlto-postlink-pgo-defaults.ll   |   1 +
 ...-pm-thinlto-postlink-samplepgo-defaults.ll |   1 +
 .../Other/new-pm-thinlto-prelink-defaults.ll  |   1 +
 .../new-pm-thinlto-prelink-pgo-defaults.ll    |   1 +
 ...w-pm-thinlto-prelink-samplepgo-defaults.ll |   1 +
 llvm/test/Transforms/JumpThreading/select.ll  |  36 ++--
 .../JumpThreading/static-profile.ll           |   9 +-
 .../Transforms/JumpThreading/thread-prob-1.ll |   2 +-
 .../Transforms/JumpThreading/thread-prob-2.ll |   4 +-
 .../Transforms/JumpThreading/thread-prob-3.ll |   4 +-
 .../Transforms/JumpThreading/thread-prob-4.ll |   4 +-
 .../Transforms/JumpThreading/thread-prob-5.ll |   4 +-
 .../Transforms/JumpThreading/thread-prob-6.ll |   4 +-
 .../Transforms/JumpThreading/thread-prob-7.ll |   2 +-
 .../Transforms/JumpThreading/thread-prob-8.ll |   9 +-
 .../JumpThreading/threading_prof1.ll          |   9 +-
 .../JumpThreading/threading_prof2.ll          |   5 +-
 .../JumpThreading/threading_prof3.ll          |   5 +-
 .../JumpThreading/update-edge-weight.ll       |   2 +-
 29 files changed, 241 insertions(+), 192 deletions(-)
 create mode 100644 llvm/include/llvm/Analysis/IncrementalUpdateProfileAnalysis.h
 create mode 100644 llvm/lib/Analysis/IncrementalUpdateProfileAnalysis.cpp

diff --git a/llvm/include/llvm/Analysis/IncrementalUpdateProfileAnalysis.h b/llvm/include/llvm/Analysis/IncrementalUpdateProfileAnalysis.h
new file mode 100644
index 0000000000000..6607291cbb038
--- /dev/null
+++ b/llvm/include/llvm/Analysis/IncrementalUpdateProfileAnalysis.h
@@ -0,0 +1,65 @@
+//===- IncrementalUpdateProfileAnalysis.h -----------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+
+#ifndef LLVM_ANALYSIS_INCREMENTALUPDATEPROFILEANALYSIS_H
+#define LLVM_ANALYSIS_INCREMENTALUPDATEPROFILEANALYSIS_H
+
+#include "llvm/Analysis/BlockFrequencyInfo.h"
+#include "llvm/Analysis/BranchProbabilityInfo.h"
+#include "llvm/IR/PassManager.h"
+
+namespace llvm {
+class IncrementalUpdateProfileAnalysis;
+
+class IncrementalProfDataVerifier {
+  BranchProbabilityInfo & BPI;
+  BlockFrequencyInfo & BFI;
+  Function &F;
+  FunctionAnalysisManager &FAM;
+
+  IncrementalProfDataVerifier(Function &F, FunctionAnalysisManager &FAM);
+  void verify();
+  static std::unique_ptr<IncrementalProfDataVerifier>
+  create(Function &F, FunctionAnalysisManager &FAM);
+  friend class IncrementalUpdateProfileAnalysis;
+
+public:
+
+  IncrementalProfDataVerifier(const IncrementalProfDataVerifier&) = delete;
+  IncrementalProfDataVerifier(IncrementalProfDataVerifier&&) = default;
+
+  BlockFrequencyInfo &bfi() { return BFI; }
+  BranchProbabilityInfo &bpi() { return BPI; }
+
+  bool invalidate(Function &, const PreservedAnalyses &PA,
+                  FunctionAnalysisManager::Invalidator &) {
+    verify();
+    // Check whether the analysis has been explicitly invalidated. Otherwise,
+    // it's stateless and remains preserved.
+    auto PAC = PA.getChecker<IncrementalUpdateProfileAnalysis>();
+    return !PAC.preservedWhenStateless();
+  }
+};
+
+class IncrementalUpdateProfileAnalysis
+    : public AnalysisInfoMixin<IncrementalUpdateProfileAnalysis> {
+
+public:
+  LLVM_ABI static AnalysisKey Key;
+  LLVM_ABI explicit IncrementalUpdateProfileAnalysis() {}
+
+  using Result = std::unique_ptr<IncrementalProfDataVerifier>;
+
+  LLVM_ABI Result run(Function &F, FunctionAnalysisManager &FAM) {
+    return IncrementalProfDataVerifier::create(F, FAM);
+  }
+};
+} // namespace llvm
+
+#endif // LLVM_ANALYSIS_INCREMENTALUPDATEPROFILEANALYSIS_H
diff --git a/llvm/include/llvm/Transforms/Scalar/JumpThreading.h b/llvm/include/llvm/Transforms/Scalar/JumpThreading.h
index 348cefb4360e4..5b75da0a4caaa 100644
--- a/llvm/include/llvm/Transforms/Scalar/JumpThreading.h
+++ b/llvm/include/llvm/Transforms/Scalar/JumpThreading.h
@@ -21,6 +21,7 @@
 #include "llvm/Analysis/BlockFrequencyInfo.h"
 #include "llvm/Analysis/BranchProbabilityInfo.h"
 #include "llvm/Analysis/DomTreeUpdater.h"
+#include "llvm/Analysis/IncrementalUpdateProfileAnalysis.h"
 #include "llvm/IR/ValueHandle.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/Transforms/Utils/ValueMapper.h"
@@ -84,8 +85,6 @@ class JumpThreadingPass : public PassInfoMixin<JumpThreadingPass> {
   LazyValueInfo *LVI = nullptr;
   AAResults *AA = nullptr;
   std::unique_ptr<DomTreeUpdater> DTU;
-  BlockFrequencyInfo *BFI = nullptr;
-  BranchProbabilityInfo *BPI = nullptr;
   bool ChangedSinceLastAnalysisUpdate = false;
   bool HasGuards = false;
 #ifndef LLVM_ENABLE_ABI_BREAKING_CHECKS
@@ -93,6 +92,7 @@ class JumpThreadingPass : public PassInfoMixin<JumpThreadingPass> {
 #else
   SmallPtrSet<const BasicBlock *, 16> LoopHeaders;
 #endif
+  IncrementalProfDataVerifier *PVer = nullptr;
 
   // JumpThreading must not processes blocks unreachable from entry. It's a
   // waste of compute time and can potentially lead to hangs.
@@ -179,10 +179,7 @@ class JumpThreadingPass : public PassInfoMixin<JumpThreadingPass> {
   BasicBlock *splitBlockPreds(BasicBlock *BB, ArrayRef<BasicBlock *> Preds,
                               const char *Suffix);
   void updateBlockFreqAndEdgeWeight(BasicBlock *PredBB, BasicBlock *BB,
-                                    BasicBlock *NewBB, BasicBlock *SuccBB,
-                                    BlockFrequencyInfo *BFI,
-                                    BranchProbabilityInfo *BPI,
-                                    bool HasProfile);
+                                    BasicBlock *NewBB, BasicBlock *SuccBB);
   /// Check if the block has profile metadata for its outgoing edges.
   bool doesBlockHaveProfileData(BasicBlock *BB);
 
@@ -195,26 +192,6 @@ class JumpThreadingPass : public PassInfoMixin<JumpThreadingPass> {
   template <typename AnalysisT>
   typename AnalysisT::Result *runExternalAnalysis();
 
-  /// Returns an existing instance of BPI if any, otherwise nullptr. By
-  /// "existing" we mean either cached result provided by FunctionAnalysisManger
-  /// or created by preceding call to 'getOrCreateBPI'.
-  BranchProbabilityInfo *getBPI();
-
-  /// Returns an existing instance of BFI if any, otherwise nullptr. By
-  /// "existing" we mean either cached result provided by FunctionAnalysisManger
-  /// or created by preceding call to 'getOrCreateBFI'.
-  BlockFrequencyInfo *getBFI();
-
-  /// Returns an existing instance of BPI if any, otherwise:
-  ///   if 'HasProfile' is true creates new instance through
-  ///   FunctionAnalysisManager, otherwise nullptr.
-  BranchProbabilityInfo *getOrCreateBPI(bool Force = false);
-
-  /// Returns an existing instance of BFI if any, otherwise:
-  ///   if 'HasProfile' is true creates new instance through
-  ///   FunctionAnalysisManager, otherwise nullptr.
-  BlockFrequencyInfo *getOrCreateBFI(bool Force = false);
-
   // Internal overload of evaluateOnPredecessorEdge().
   Constant *evaluateOnPredecessorEdge(BasicBlock *BB, BasicBlock *PredPredBB,
                                       Value *cond, const DataLayout &DL,
diff --git a/llvm/lib/Analysis/CMakeLists.txt b/llvm/lib/Analysis/CMakeLists.txt
index f3586c66cb056..75eb056a560bb 100644
--- a/llvm/lib/Analysis/CMakeLists.txt
+++ b/llvm/lib/Analysis/CMakeLists.txt
@@ -89,6 +89,7 @@ add_llvm_component_library(LLVMAnalysis
   IVDescriptors.cpp
   IVUsers.cpp
   ImportedFunctionsInliningStatistics.cpp
+  IncrementalUpdateProfileAnalysis.cpp
   IndirectCallPromotionAnalysis.cpp
   InlineCost.cpp
   InlineAdvisor.cpp
diff --git a/llvm/lib/Analysis/IncrementalUpdateProfileAnalysis.cpp b/llvm/lib/Analysis/IncrementalUpdateProfileAnalysis.cpp
new file mode 100644
index 0000000000000..923a1ef8c24de
--- /dev/null
+++ b/llvm/lib/Analysis/IncrementalUpdateProfileAnalysis.cpp
@@ -0,0 +1,68 @@
+//===- IncrementalUpdateProfileAnalysis.cpp -------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This is a wrapper of BFI and BPI that, on invalidation, optionally verifies
+// (which is time-consuming) that the BFI and BPI are equivalent to newly
+// created instances.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/Analysis/IncrementalUpdateProfileAnalysis.h"
+#include "llvm/Analysis/BlockFrequencyInfo.h"
+#include "llvm/Analysis/BranchProbabilityInfo.h"
+#include "llvm/Analysis/LoopInfo.h"
+#include "llvm/Analysis/PostDominators.h"
+#include "llvm/Analysis/TargetLibraryInfo.h"
+#include "llvm/Support/CommandLine.h"
+
+using namespace llvm;
+static cl::opt<bool> VerifyIncrementalProfileUpdate(
+    "verify-incremental-profile-update",
+    cl::desc("Verify that incremental profile updates match a recalculation"),
+#ifdef EXPENSIVE_CHECKS
+    cl::init(true),
+#else
+    cl::init(false),
+#endif
+    cl::Hidden);
+
+AnalysisKey IncrementalUpdateProfileAnalysis::Key;
+
+IncrementalProfDataVerifier::IncrementalProfDataVerifier(
+    Function &F, FunctionAnalysisManager &FAM)
+    : BPI(FAM.getResult<BranchProbabilityAnalysis>(F)),
+      BFI(FAM.getResult<BlockFrequencyAnalysis>(F)), F(F), FAM(FAM) {}
+
+std::unique_ptr<IncrementalProfDataVerifier>
+IncrementalProfDataVerifier::create(Function &F, FunctionAnalysisManager &FAM) {
+  if (auto EC = F.getEntryCount(); !EC || !EC->getCount())
+    return nullptr;
+  return std::unique_ptr<IncrementalProfDataVerifier>(
+      new IncrementalProfDataVerifier(F, FAM));
+}
+
+void IncrementalProfDataVerifier::verify() {
+  auto &Ctx = F.getContext();
+  auto &LI = FAM.getResult<LoopAnalysis>(F);
+  BranchProbabilityInfo NewBPI(F, LI, &FAM.getResult<TargetLibraryAnalysis>(F),
+                               &FAM.getResult<DominatorTreeAnalysis>(F),
+                               &FAM.getResult<PostDominatorTreeAnalysis>(F));
+  BlockFrequencyInfo NewBFI(F, NewBPI, LI);
+  for (auto &BB : F) {
+    if (BFI.getBlockFreq(&BB) != NewBFI.getBlockFreq(&BB))
+      Ctx.emitError("Incremental profile info failure for " + BB.getName() +
+                    " in " + F.getName());
+    if (succ_size(&BB) < 2)
+      continue;
+    for (auto *Dest : successors(&BB))
+      if (BPI.getEdgeProbability(&BB, Dest) !=
+          NewBPI.getEdgeProbability(&BB, Dest))
+        Ctx.emitError("Incremental profile info failure for " + BB.getName() +
+                      " -> " + Dest->getName() + " in " + F.getName());
+  }
+}
diff --git a/llvm/lib/Passes/PassBuilder.cpp b/llvm/lib/Passes/PassBuilder.cpp
index a23d64b491a79..d7894ddb35b2b 100644
--- a/llvm/lib/Passes/PassBuilder.cpp
+++ b/llvm/lib/Passes/PassBuilder.cpp
@@ -44,6 +44,7 @@
 #include "llvm/Analysis/HashRecognize.h"
 #include "llvm/Analysis/IR2Vec.h"
 #include "llvm/Analysis/IVUsers.h"
+#include "llvm/Analysis/IncrementalUpdateProfileAnalysis.h"
 #include "llvm/Analysis/InlineAdvisor.h"
 #include "llvm/Analysis/InstCount.h"
 #include "llvm/Analysis/KernelInfo.h"
diff --git a/llvm/lib/Passes/PassRegistry.def b/llvm/lib/Passes/PassRegistry.def
index c92d93d7ae396..e114da0474f42 100644
--- a/llvm/lib/Passes/PassRegistry.def
+++ b/llvm/lib/Passes/PassRegistry.def
@@ -361,6 +361,7 @@ FUNCTION_ANALYSIS("ephemerals", EphemeralValuesAnalysis())
 FUNCTION_ANALYSIS("func-properties", FunctionPropertiesAnalysis())
 FUNCTION_ANALYSIS("machine-function-info", MachineFunctionAnalysis(*TM))
 FUNCTION_ANALYSIS("gc-function", GCFunctionAnalysis())
+FUNCTION_ANALYSIS("incremental-profile", IncrementalUpdateProfileAnalysis())
 FUNCTION_ANALYSIS("last-run-tracking", LastRunTrackingAnalysis())
 FUNCTION_ANALYSIS("lazy-value-info", LazyValueAnalysis())
 FUNCTION_ANALYSIS("loops", LoopAnalysis())
diff --git a/llvm/lib/Transforms/Scalar/JumpThreading.cpp b/llvm/lib/Transforms/Scalar/JumpThreading.cpp
index 415136b612ac2..3d9179b029008 100644
--- a/llvm/lib/Transforms/Scalar/JumpThreading.cpp
+++ b/llvm/lib/Transforms/Scalar/JumpThreading.cpp
@@ -25,6 +25,7 @@
 #include "llvm/Analysis/ConstantFolding.h"
 #include "llvm/Analysis/GlobalsModRef.h"
 #include "llvm/Analysis/GuardUtils.h"
+#include "llvm/Analysis/IncrementalUpdateProfileAnalysis.h"
 #include "llvm/Analysis/InstructionSimplify.h"
 #include "llvm/Analysis/LazyValueInfo.h"
 #include "llvm/Analysis/Loads.h"
@@ -296,8 +297,8 @@ bool JumpThreadingPass::runImpl(Function &F_, FunctionAnalysisManager *FAM_,
   LVI = LVI_;
   AA = AA_;
   DTU = std::move(DTU_);
-  BFI = BFI_;
-  BPI = BPI_;
+  PVer = FAM->getResult<IncrementalUpdateProfileAnalysis>(*F).get();
+
   auto *GuardDecl = Intrinsic::getDeclarationIfExists(
       F->getParent(), Intrinsic::experimental_guard);
   HasGuards = GuardDecl && !GuardDecl->use_empty();
@@ -1043,8 +1044,8 @@ bool JumpThreadingPass::processBlock(BasicBlock *BB) {
                       << '\n');
     ++NumFolds;
     ConstantFoldTerminator(BB, true, nullptr, DTU.get());
-    if (auto *BPI = getBPI())
-      BPI->eraseBlock(BB);
+    if (PVer)
+      PVer->bpi().eraseBlock(BB);
     return true;
   }
 
@@ -1196,8 +1197,8 @@ bool JumpThreadingPass::processImpliedCondition(BasicBlock *BB) {
         FICond->eraseFromParent();
 
       DTU->applyUpdatesPermissive({{DominatorTree::Delete, BB, RemoveSucc}});
-      if (auto *BPI = getBPI())
-        BPI->eraseBlock(BB);
+      if (PVer)
+        PVer->bpi().eraseBlock(BB);
       return true;
     }
     CurrentBB = CurrentPred;
@@ -1669,8 +1670,8 @@ bool JumpThreadingPass::processThreadableEdges(Value *Cond, BasicBlock *BB,
       ++NumFolds;
       Term->eraseFromParent();
       DTU->applyUpdatesPermissive(Updates);
-      if (auto *BPI = getBPI())
-        BPI->eraseBlock(BB);
+      if (PVer)
+        PVer->bpi().eraseBlock(BB);
 
       // If the condition is now dead due to the removal of the old terminator,
       // erase it.
@@ -2272,11 +2273,6 @@ void JumpThreadingPass::threadThroughTwoBasicBlocks(BasicBlock *PredPredBB,
   LLVM_DEBUG(dbgs() << "  Threading through '" << PredBB->getName() << "' and '"
                     << BB->getName() << "'\n");
 
-  // Build BPI/BFI before any changes are made to IR.
-  bool HasProfile = doesBlockHaveProfileData(BB);
-  auto *BFI = getOrCreateBFI(HasProfile);
-  auto *BPI = getOrCreateBPI(BFI != nullptr);
-
   CondBrInst *CondBr = cast<CondBrInst>(BB->getTerminator());
   CondBrInst *PredBBBranch = cast<CondBrInst>(PredBB->getTerminator());
 
@@ -2286,11 +2282,10 @@ void JumpThreadingPass::threadThroughTwoBasicBlocks(BasicBlock *PredPredBB,
   NewBB->moveAfter(PredBB);
 
   // Set the block frequency of NewBB.
-  if (BFI) {
-    assert(BPI && "It's expected BPI to exist along with BFI");
-    auto NewBBFreq = BFI->getBlockFreq(PredPredBB) *
-                     BPI->getEdgeProbability(PredPredBB, PredBB);
-    BFI->setBlockFreq(NewBB, NewBBFreq);
+  if (PVer) {
+    auto NewBBFreq = PVer->bfi().getBlockFreq(PredPredBB) *
+                     PVer->bpi().getEdgeProbability(PredPredBB, PredBB);
+    PVer->bfi().setBlockFreq(NewBB, NewBBFreq);
   }
 
   // We are going to have to map operands from the original BB block to the new
@@ -2301,8 +2296,8 @@ void JumpThreadingPass::threadThroughTwoBasicBlocks(BasicBlock *PredPredBB,
                     PredPredBB);
 
   // Copy the edge probabilities from PredBB to NewBB.
-  if (BPI)
-    BPI->copyEdgeProbabilities(PredBB, NewBB);
+  if (PVer)
+    PVer->bpi().copyEdgeProbabilities(PredBB, NewBB);
 
   // Update the terminator of PredPredBB to jump to NewBB instead of PredBB.
   // This eliminates predecessors from PredPredBB, which requires us to simplify
@@ -2388,11 +2383,6 @@ void JumpThreadingPass::threadEdge(BasicBlock *BB,
   assert(!LoopHeaders.count(BB) && !LoopHeaders.count(SuccBB) &&
          "Don't thread across loop headers");
 
-  // Build BPI/BFI before any changes are made to IR.
-  bool HasProfile = doesBlockHaveProfileData(BB);
-  auto *BFI = getOrCreateBFI(HasProfile);
-  auto *BPI = getOrCreateBPI(BFI != nullptr);
-
   // And finally, do it!  Start by factoring the predecessors if needed.
   BasicBlock *PredBB;
   if (PredBBs.size() == 1)
@@ -2416,11 +2406,10 @@ void JumpThreadingPass::threadEdge(BasicBlock *BB,
   NewBB->moveAfter(PredBB);
 
   // Set the block frequency of NewBB.
-  if (BFI) {
-    assert(BPI && "It's expected BPI to exist along with BFI");
-    auto NewBBFreq =
-        BFI->getBlockFreq(PredBB) * BPI->getEdgeProbability(PredBB, BB);
-    BFI->setBlockFreq(NewBB, NewBBFreq);
+  if (PVer) {
+    auto NewBBFreq = PVer->bfi().getBlockFreq(PredBB) *
+                     PVer->bpi().getEdgeProbability(PredBB, BB);
+    PVer->bfi().setBlockFreq(NewBB, NewBBFreq);
   }
 
   // Copy all the instructions from BB to NewBB except the terminator.
@@ -2461,7 +2450,7 @@ void JumpThreadingPass::threadEdge(BasicBlock *BB,
   SimplifyInstructionsInBlock(NewBB, TLI);
 
   // Update the edge weight from BB to SuccBB, which should be less than before.
-  updateBlockFreqAndEdgeWeight(PredBB, BB, NewBB, SuccBB, BFI, BPI, HasProfile);
+  updateBlockFreqAndEdgeWeight(PredBB, BB, NewBB, SuccBB);
 
   // Threaded an edge!
   ++NumThreads;
@@ -2478,12 +2467,11 @@ BasicBlock *JumpThreadingPass::splitBlockPreds(BasicBlock *BB,
   // Collect the frequencies of all predecessors of BB, which will be used to
   // update the edge weight of the result of splitting predecessors.
   DenseMap<BasicBlock *, BlockFrequency> FreqMap;
-  auto *BFI = getBFI();
-  if (BFI) {
-    auto *BPI = getOrCreateBPI(true);
+  if (PVer) {
     for (auto *Pred : Preds)
-      FreqMap.insert(std::make_pair(
-          Pred, BFI->getBlockFreq(Pred) * BPI->getEdgeProbability(Pred, BB)));
+      FreqMap.insert(
+          std::make_pair(Pred, PVer->bfi().getBlockFreq(Pred) *
+                                   PVer->bpi().getEdgeProbability(Pred, BB)));
   }
 
   // In the case when BB is a LandingPad block we create 2 new predecessors
@@ -2503,11 +2491,11 @@ BasicBlock *JumpThreadingPass::splitBlockPreds(BasicBlock *BB,
     for (auto *Pred : predecessors(NewBB)) {
       Updates.push_back({DominatorTree::Delete, Pred, BB});
       Updates.push_back({DominatorTree::Insert, Pred, NewBB});
-      if (BFI) // Update frequencies between Pred -> NewBB.
+      if (PVer) // Update frequencies between Pred -> NewBB.
         NewBBFreq += FreqMap.lookup(Pred);
     }
-    if (BFI) // Apply the summed frequency to NewBB.
-      BFI->setBlockFreq(NewBB, NewBBFreq);
+    if (PVer) // Apply the summed frequency to NewBB.
+      PVer->bfi().setBlockFreq(NewBB, NewBBFreq);
   }
 
   DTU->applyUpdatesPermissive(Updates);
@@ -2528,31 +2516,22 @@ bool JumpThreadingPass::doesBlockHaveProfileData(BasicBlock *BB) {
 void JumpThreadingPass::updateBlockFreqAndEdgeWeight(BasicBlock *PredBB,
                                                      BasicBlock *BB,
                                                      BasicBlock *NewBB,
-                                                     BasicBlock *SuccBB,
-                                                     BlockFrequencyInfo *BFI,
-                                                     BranchProbabilityInfo *BPI,
-                                                     bool HasProfile) {
-  assert(((BFI && BPI) || (!BFI && !BFI)) &&
-         "Both BFI & BPI should either be set or unset");
-
-  if (!BFI) {
-    assert(!HasProfile &&
-           "It's expected to have BFI/BPI when profile info exists");
+                                                     BasicBlock *SuccBB) {
+  if (!PVer)
     return;
-  }
 
   // As the edge from PredBB to BB is deleted, we have to update the block
   // frequency of BB.
-  auto BBOrigFreq = BFI->getBlockFreq(BB);
-  auto NewBBFreq = BFI->getBlockFreq(NewBB);
+  auto BBOrigFreq = PVer->bfi().getBlockFreq(BB);
+  auto NewBBFreq = PVer->bfi().getBlockFreq(NewBB);
   auto BBNewFreq = BBOrigFreq - NewBBFreq;
-  BFI->setBlockFreq(BB, BBNewFreq);
+  PVer->bfi().setBlockFreq(BB, BBNewFreq);
 
   // Collect updated outgoing edges' frequencies from BB and use them to update
   // edge probabilities.
   SmallVector<uint64_t, 4> BBSuccFreq;
   for (auto It : enumerate(successors(BB))) {
-    auto BB2SuccBBFreq = BBOrigFreq * BPI->getEdgeProbability(BB, It.index());
+    auto BB2SuccBBFreq = BBOrigFreq * PVer->bpi().getEdgeProbability(BB, It.index());
     auto SuccFreq =
         (It.value() == SuccBB) ? BB2SuccBBFreq - NewBBFreq : BB2SuccBBFreq;
     BBSuccFreq.push_back(SuccFreq.getFrequency());
@@ -2574,7 +2553,7 @@ void JumpThreadingPass::updateBlockFreqAndEdgeWeight(BasicBlock *PredBB,
   }
 
   // Update edge probabilities in BPI.
-  BPI->setEdgeProbability(BB, BBSuccProbs);
+  PVer->bpi().setEdgeProbability(BB, BBSuccProbs);
 
   // Update the profile metadata as well.
   //
@@ -2610,7 +2589,7 @@ void JumpThreadingPass::updateBlockFreqAndEdgeWeight(BasicBlock *PredBB,
   // FIXME this locally as well so that BPI and BFI are consistent as well.  We
   // shouldn't make edges extremely likely or unlikely based solely on static
   // estimation.
-  if (BBSuccProbs.size() >= 2 && HasProfile) {
+  if (BBSuccProbs.size() >= 2) {
     SmallVector<uint32_t, 4> Weights;
     for (auto Prob : BBSuccProbs)
       Weights.push_back(Prob.getNumerator());
@@ -2757,8 +2736,8 @@ bool JumpThreadingPass::duplicateCondBranchOnPHIIntoPred(
 
   // Remove the unconditional branch at the end of the PredBB block.
   OldPredBranch->eraseFromParent();
-  if (auto *BPI = getBPI())
-    BPI->copyEdgeProbabilities(BB, PredBB);
+  if (PVer)
+    PVer->bpi().copyEdgeProbabilities(BB, PredBB);
   DTU->applyUpdatesPermissive(Updates);
 
   ++NumDupes;
@@ -2806,19 +2785,19 @@ void JumpThreadingPass::unfoldSelectInstr(BasicBlock *Pred, BasicBlock *BB,
     BP.emplace_back(BranchProbability::getBranchProbability(
         FalseWeight, TrueWeight + FalseWeight));
     // Update BPI if exists.
-    if (auto *BPI = getBPI())
-      BPI->setEdgeProbability(Pred, BP);
+    if (PVer)
+      PVer->bpi().setEdgeProbability(Pred, BP);
   }
   // Set the block frequency of NewBB.
-  if (auto *BFI = getBFI()) {
+  if (PVer) {
     if ((TrueWeight + FalseWeight) == 0) {
       TrueWeight = 1;
       FalseWeight = 1;
     }
     BranchProbability PredToNewBBProb = BranchProbability::getBranchProbability(
         TrueWeight, TrueWeight + FalseWeight);
-    auto NewBBFreq = BFI->getBlockFreq(Pred) * PredToNewBBProb;
-    BFI->setBlockFreq(NewBB, NewBBFreq);
+    auto NewBBFreq = PVer->bfi().getBlockFreq(Pred) * PredToNewBBProb;
+    PVer->bfi().setBlockFreq(NewBB, NewBBFreq);
   }
 
   // The select is now dead.
@@ -2998,8 +2977,6 @@ bool JumpThreadingPass::tryToUnfoldSelectInCurrBB(BasicBlock *BB) {
     NewPN->setDebugLoc(SI->getDebugLoc());
     SI->replaceAllUsesWith(NewPN);
 
-    auto *BPI = getBPI();
-    auto *BFI = getBFI();
     if (!ProfcheckDisableMetadataFixes && BranchWeights) {
       SmallVector<uint32_t, 2> BW;
       [[maybe_unused]] bool Extracted = extractBranchWeights(BranchWeights, BW);
@@ -3014,14 +2991,12 @@ bool JumpThreadingPass::tryToUnfoldSelectInCurrBB(BasicBlock *BB) {
           BranchProbability::getBranchProbability(BW[1], Denominator);
       SmallVector<BranchProbability, 2> BP = {TrueProb, FalseProb};
 
-      if (BPI)
-        BPI->setEdgeProbability(BB, BP);
-
-      if (BFI) {
-        auto BBOrigFreq = BFI->getBlockFreq(BB);
+      if (PVer) {
+        PVer->bpi().setEdgeProbability(BB, BP);
+        auto BBOrigFreq = PVer->bfi().getBlockFreq(BB);
         auto NewBBFreq = BBOrigFreq * TrueProb;
-        BFI->setBlockFreq(NewBB, NewBBFreq);
-        BFI->setBlockFreq(SplitBB, BBOrigFreq);
+        PVer->bfi().setBlockFreq(NewBB, NewBBFreq);
+        PVer->bfi().setBlockFreq(SplitBB, BBOrigFreq);
       }
     }
     SI->eraseFromParent();
@@ -3174,7 +3149,6 @@ PreservedAnalyses JumpThreadingPass::getPreservedAnalysis() const {
   PA.preserve<DominatorTreeAnalysis>();
 
   // TODO: We would like to preserve BPI/BFI. Enable once all paths update them.
-  // TODO: Would be nice to verify BPI/BFI consistency as well.
   return PA;
 }
 
@@ -3216,44 +3190,3 @@ typename AnalysisT::Result *JumpThreadingPass::runExternalAnalysis() {
 
   return Result;
 }
-
-BranchProbabilityInfo *JumpThreadingPass::getBPI() {
-  if (!BPI) {
-    assert(FAM && "Can't create BPI without FunctionAnalysisManager");
-    BPI = FAM->getCachedResult<BranchProbabilityAnalysis>(*F);
-  }
-  return BPI;
-}
-
-BlockFrequencyInfo *JumpThreadingPass::getBFI() {
-  if (!BFI) {
-    assert(FAM && "Can't create BFI without FunctionAnalysisManager");
-    BFI = FAM->getCachedResult<BlockFrequencyAnalysis>(*F);
-  }
-  return BFI;
-}
-
-// Important note on validity of BPI/BFI. JumpThreading tries to preserve
-// BPI/BFI as it goes. Thus if cached instance exists it will be updated.
-// Otherwise, new instance of BPI/BFI is created (up to date by definition).
-BranchProbabilityInfo *JumpThreadingPass::getOrCreateBPI(bool Force) {
-  auto *Res = getBPI();
-  if (Res)
-    return Res;
-
-  if (Force)
-    BPI = runExternalAnalysis<BranchProbabilityAnalysis>();
-
-  return BPI;
-}
-
-BlockFrequencyInfo *JumpThreadingPass::getOrCreateBFI(bool Force) {
-  auto *Res = getBFI();
-  if (Res)
-    return Res;
-
-  if (Force)
-    BFI = runExternalAnalysis<BlockFrequencyAnalysis>();
-
-  return BFI;
-}
diff --git a/llvm/test/Other/new-pm-defaults.ll b/llvm/test/Other/new-pm-defaults.ll
index 240a3ef3ee539..f7f6dca08ddc9 100644
--- a/llvm/test/Other/new-pm-defaults.ll
+++ b/llvm/test/Other/new-pm-defaults.ll
@@ -159,6 +159,7 @@
 ; CHECK-O23SZ-NEXT: Running pass: SpeculativeExecutionPass
 ; CHECK-O23SZ-NEXT: Running pass: JumpThreadingPass
 ; CHECK-O23SZ-NEXT: Running analysis: LazyValueAnalysis
+; CHECK-O23SZ-NEXT: Running analysis: IncrementalUpdateProfileAnalysis
 ; CHECK-O23SZ-NEXT: Running pass: CorrelatedValuePropagationPass
 ; CHECK-O23SZ-NEXT: Invalidating analysis: LazyValueAnalysis
 ; CHECK-JUMP-TABLE-TO-SWITCH-NEXT: Running pass: JumpTableToSwitchPass
diff --git a/llvm/test/Other/new-pm-lto-defaults.ll b/llvm/test/Other/new-pm-lto-defaults.ll
index 4eb4e4b4791c0..9ed57baf3b826 100644
--- a/llvm/test/Other/new-pm-lto-defaults.ll
+++ b/llvm/test/Other/new-pm-lto-defaults.ll
@@ -97,6 +97,7 @@
 ; CHECK-O23SZ-NEXT: Running analysis: ScalarEvolutionAnalysis on foo
 ; CHECK-O23SZ-NEXT: Running pass: JumpThreadingPass
 ; CHECK-O23SZ-NEXT: Running analysis: LazyValueAnalysis
+; CHECK-O23SZ-NEXT: Running analysis: IncrementalUpdateProfileAnalysis
 ; CHECK-O23SZ-NEXT: Running pass: SROAPass on foo
 ; CHECK-O23SZ-NEXT: Running pass: TailCallElimPass on foo
 ; CHECK-O23SZ-NEXT: Running pass: PostOrderFunctionAttrsPass on (foo)
diff --git a/llvm/test/Other/new-pm-thinlto-postlink-defaults.ll b/llvm/test/Other/new-pm-thinlto-postlink-defaults.ll
index 0d9a96a304432..c27bdaa4f1870 100644
--- a/llvm/test/Other/new-pm-thinlto-postlink-defaults.ll
+++ b/llvm/test/Other/new-pm-thinlto-postlink-defaults.ll
@@ -89,6 +89,7 @@
 ; CHECK-O23SZ-NEXT: Running pass: SpeculativeExecutionPass
 ; CHECK-O23SZ-NEXT: Running pass: JumpThreadingPass
 ; CHECK-O23SZ-NEXT: Running analysis: LazyValueAnalysis
+; CHECK-O23SZ-NEXT: Running analysis: IncrementalUpdateProfileAnalysis
 ; CHECK-O23SZ-NEXT: Running pass: CorrelatedValuePropagationPass
 ; CHECK-O23SZ-NEXT: Invalidating analysis: LazyValueAnalysis
 ; CHECK-O-NEXT: Running pass: SimplifyCFGPass
diff --git a/llvm/test/Other/new-pm-thinlto-postlink-pgo-defaults.ll b/llvm/test/Other/new-pm-thinlto-postlink-pgo-defaults.ll
index 703696b57135b..a6294708eec41 100644
--- a/llvm/test/Other/new-pm-thinlto-postlink-pgo-defaults.ll
+++ b/llvm/test/Other/new-pm-thinlto-postlink-pgo-defaults.ll
@@ -77,6 +77,7 @@
 ; CHECK-O23SZ-NEXT: Running pass: SpeculativeExecutionPass
 ; CHECK-O23SZ-NEXT: Running pass: JumpThreadingPass
 ; CHECK-O23SZ-NEXT: Running analysis: LazyValueAnalysis
+; CHECK-O23SZ-NEXT: Running analysis: IncrementalUpdateProfileAnalysis
 ; CHECK-O23SZ-NEXT: Running pass: CorrelatedValuePropagationPass
 ; CHECK-O23SZ-NEXT: Invalidating analysis: LazyValueAnalysis
 ; CHECK-O-NEXT: Running pass: SimplifyCFGPass
diff --git a/llvm/test/Other/new-pm-thinlto-postlink-samplepgo-defaults.ll b/llvm/test/Other/new-pm-thinlto-postlink-samplepgo-defaults.ll
index 569ba647f16f2..8b63797881990 100644
--- a/llvm/test/Other/new-pm-thinlto-postlink-samplepgo-defaults.ll
+++ b/llvm/test/Other/new-pm-thinlto-postlink-samplepgo-defaults.ll
@@ -86,6 +86,7 @@
 ; CHECK-O23SZ-NEXT: Running pass: SpeculativeExecutionPass
 ; CHECK-O23SZ-NEXT: Running pass: JumpThreadingPass
 ; CHECK-O23SZ-NEXT: Running analysis: LazyValueAnalysis
+; CHECK-O23SZ-NEXT: Running analysis: IncrementalUpdateProfileAnalysis
 ; CHECK-O23SZ-NEXT: Running pass: CorrelatedValuePropagationPass
 ; CHECK-O23SZ-NEXT: Invalidating analysis: LazyValueAnalysis
 ; CHECK-O-NEXT: Running pass: SimplifyCFGPass
diff --git a/llvm/test/Other/new-pm-thinlto-prelink-defaults.ll b/llvm/test/Other/new-pm-thinlto-prelink-defaults.ll
index b146ae15eca58..35f1fe854891a 100644
--- a/llvm/test/Other/new-pm-thinlto-prelink-defaults.ll
+++ b/llvm/test/Other/new-pm-thinlto-prelink-defaults.ll
@@ -121,6 +121,7 @@
 ; CHECK-O23SZ-NEXT: Running pass: SpeculativeExecutionPass
 ; CHECK-O23SZ-NEXT: Running pass: JumpThreadingPass
 ; CHECK-O23SZ-NEXT: Running analysis: LazyValueAnalysis
+; CHECK-O23SZ-NEXT: Running analysis: IncrementalUpdateProfileAnalysis
 ; CHECK-O23SZ-NEXT: Running pass: CorrelatedValuePropagationPass
 ; CHECK-O23SZ-NEXT: Invalidating analysis: LazyValueAnalysis
 ; CHECK-O-NEXT: Running pass: SimplifyCFGPass
diff --git a/llvm/test/Other/new-pm-thinlto-prelink-pgo-defaults.ll b/llvm/test/Other/new-pm-thinlto-prelink-pgo-defaults.ll
index b4a210ad9ab03..afed780b41848 100644
--- a/llvm/test/Other/new-pm-thinlto-prelink-pgo-defaults.ll
+++ b/llvm/test/Other/new-pm-thinlto-prelink-pgo-defaults.ll
@@ -119,6 +119,7 @@
 ; CHECK-O23SZ-NEXT: Running pass: SpeculativeExecutionPass
 ; CHECK-O23SZ-NEXT: Running pass: JumpThreadingPass
 ; CHECK-O23SZ-NEXT: Running analysis: LazyValueAnalysis
+; CHECK-O23SZ-NEXT: Running analysis: IncrementalUpdateProfileAnalysis
 ; CHECK-O23SZ-NEXT: Running pass: CorrelatedValuePropagationPass
 ; CHECK-O23SZ-NEXT: Invalidating analysis: LazyValueAnalysis
 ; CHECK-O-NEXT: Running pass: SimplifyCFGPass
diff --git a/llvm/test/Other/new-pm-thinlto-prelink-samplepgo-defaults.ll b/llvm/test/Other/new-pm-thinlto-prelink-samplepgo-defaults.ll
index 1efcb51fa61a6..c5ebf133d834e 100644
--- a/llvm/test/Other/new-pm-thinlto-prelink-samplepgo-defaults.ll
+++ b/llvm/test/Other/new-pm-thinlto-prelink-samplepgo-defaults.ll
@@ -91,6 +91,7 @@
 ; CHECK-O23SZ-NEXT: Running pass: SpeculativeExecutionPass
 ; CHECK-O23SZ-NEXT: Running pass: JumpThreadingPass
 ; CHECK-O23SZ-NEXT: Running analysis: LazyValueAnalysis
+; CHECK-O23SZ-NEXT: Running analysis: IncrementalUpdateProfileAnalysis
 ; CHECK-O23SZ-NEXT: Running pass: CorrelatedValuePropagationPass
 ; CHECK-O23SZ-NEXT: Invalidating analysis: LazyValueAnalysis
 ; CHECK-O-NEXT: Running pass: SimplifyCFGPass
diff --git a/llvm/test/Transforms/JumpThreading/select.ll b/llvm/test/Transforms/JumpThreading/select.ll
index 4ec55a66bb8ac..c2368f841f5a9 100644
--- a/llvm/test/Transforms/JumpThreading/select.ll
+++ b/llvm/test/Transforms/JumpThreading/select.ll
@@ -21,7 +21,7 @@ declare void @quux()
 ; booleans where at least one operand is true/false/undef.
 
 ;.
-; CHECK: @[[ANCHOR:[a-zA-Z0-9_$"\\.-]+]] = constant [3 x ptr] [ptr blockaddress(@test_indirectbr, [[L1:%.*]]), ptr inttoptr (i32 1 to ptr), ptr blockaddress(@test_indirectbr, [[L3:%.*]])]
+; CHECK-BPI: @anchor = constant [3 x ptr] [ptr blockaddress(@test_indirectbr, %L1), ptr inttoptr (i32 1 to ptr), ptr blockaddress(@test_indirectbr, %L3)]
 ;.
 define void @test_br(i1 %cond, i1 %value) nounwind {
 ; CHECK-LABEL: @test_br(
@@ -66,8 +66,8 @@ define void @test_switch(i1 %cond, i8 %value) nounwind {
 ; CHECK-NEXT:    call void @quux()
 ; CHECK-NEXT:    [[EXPR:%.*]] = select i1 [[COND]], i8 1, i8 [[VALUE:%.*]]
 ; CHECK-NEXT:    switch i8 [[EXPR]], label [[L3:%.*]] [
-; CHECK-NEXT:    i8 1, label [[L1]]
-; CHECK-NEXT:    i8 2, label [[L2:%.*]]
+; CHECK-NEXT:      i8 1, label [[L1]]
+; CHECK-NEXT:      i8 2, label [[L2:%.*]]
 ; CHECK-NEXT:    ]
 ; CHECK:       L1:
 ; CHECK-NEXT:    call void @foo()
@@ -192,8 +192,8 @@ define void @test_switch_cmp(i1 %cond, i32 %val, i8 %value) nounwind {
 ; CHECK:       0:
 ; CHECK-NEXT:    [[TMP1:%.*]] = phi i8 [ [[VALUE:%.*]], [[L0]] ]
 ; CHECK-NEXT:    switch i8 [[TMP1]], label [[L3:%.*]] [
-; CHECK-NEXT:    i8 1, label [[L1]]
-; CHECK-NEXT:    i8 2, label [[L2:%.*]]
+; CHECK-NEXT:      i8 1, label [[L1]]
+; CHECK-NEXT:      i8 2, label [[L2:%.*]]
 ; CHECK-NEXT:    ]
 ; CHECK:       L1:
 ; CHECK-NEXT:    call void @foo()
@@ -237,8 +237,8 @@ define void @test_switch_default(ptr nocapture %status) nounwind {
 ; CHECK-NEXT:  entry:
 ; CHECK-NEXT:    [[TMP0:%.*]] = load i32, ptr [[STATUS:%.*]], align 4
 ; CHECK-NEXT:    switch i32 [[TMP0]], label [[L2:%.*]] [
-; CHECK-NEXT:    i32 5061, label [[L2_THREAD:%.*]]
-; CHECK-NEXT:    i32 0, label [[L2]]
+; CHECK-NEXT:      i32 5061, label [[L2_THREAD:%.*]]
+; CHECK-NEXT:      i32 0, label [[L2]]
 ; CHECK-NEXT:    ]
 ; CHECK:       L2.thread:
 ; CHECK-NEXT:    store i32 10025, ptr [[STATUS]], align 4
@@ -290,7 +290,7 @@ define void @unfold1(double %x, double %y) nounwind !prof !1 {
 ; CHECK:       cond.end4:
 ; CHECK-NEXT:    [[COND5:%.*]] = phi double [ [[SUB]], [[ENTRY:%.*]] ], [ [[ADD]], [[COND_FALSE]] ]
 ; CHECK-NEXT:    [[CMP6:%.*]] = fcmp oeq double [[COND5]], 0.000000e+00
-; CHECK-NEXT:    br i1 [[CMP6]], label [[IF_THEN]], label [[IF_END:%.*]]
+; CHECK-NEXT:    br i1 [[CMP6]], label [[IF_THEN]], label [[IF_END:%.*]], !prof [[PROF2:![0-9]+]]
 ; CHECK:       if.then:
 ; CHECK-NEXT:    call void @foo()
 ; CHECK-NEXT:    br label [[IF_END]]
@@ -336,7 +336,7 @@ define void @unfold2(i32 %x, i32 %y) nounwind !prof !1 {
 ; CHECK:       cond.end4:
 ; CHECK-NEXT:    [[COND5:%.*]] = phi i32 [ [[ADD]], [[COND_FALSE]] ]
 ; CHECK-NEXT:    [[CMP6:%.*]] = icmp eq i32 [[COND5]], 0
-; CHECK-NEXT:    br i1 [[CMP6]], label [[IF_THEN]], label [[IF_END]]
+; CHECK-NEXT:    br i1 [[CMP6]], label [[IF_THEN]], label [[IF_END]], !prof [[PROF3:![0-9]+]]
 ; CHECK:       if.then:
 ; CHECK-NEXT:    call void @foo()
 ; CHECK-NEXT:    br label [[IF_END]]
@@ -560,10 +560,10 @@ define void @test_func(ptr nocapture readonly %a, ptr nocapture readonly %b, ptr
 ; CHECK:       if.end:
 ; CHECK-NEXT:    [[LOCAL_VAR_0:%.*]] = phi i32 [ [[TMP1]], [[FOR_BODY]] ]
 ; CHECK-NEXT:    switch i32 [[LOCAL_VAR_0]], label [[SW_DEFAULT]] [
-; CHECK-NEXT:    i32 2, label [[SW_BB]]
-; CHECK-NEXT:    i32 4, label [[SW_BB7]]
-; CHECK-NEXT:    i32 5, label [[SW_BB8:%.*]]
-; CHECK-NEXT:    i32 7, label [[SW_BB9:%.*]]
+; CHECK-NEXT:      i32 2, label [[SW_BB]]
+; CHECK-NEXT:      i32 4, label [[SW_BB7]]
+; CHECK-NEXT:      i32 5, label [[SW_BB8:%.*]]
+; CHECK-NEXT:      i32 7, label [[SW_BB9:%.*]]
 ; CHECK-NEXT:    ]
 ; CHECK:       sw.bb:
 ; CHECK-NEXT:    call void @foo()
@@ -669,8 +669,12 @@ if.end:
 !0 = !{!"branch_weights", i64 1073741824, i64 3221225472}
 !1 = !{!"function_entry_count", i64 1984}
 ;.
-; CHECK: attributes #[[ATTR0:[0-9]+]] = { nounwind }
+; CHECK-BPI: attributes #[[ATTR0:[0-9]+]] = { nounwind }
 ;.
-; CHECK: [[META0:![0-9]+]] = !{!"function_entry_count", i64 1984}
-; CHECK: [[PROF1]] = !{!"branch_weights", i64 1073741824, i64 3221225472}
+; CHECK-BPI: [[META0:![0-9]+]] = !{!"function_entry_count", i64 1984}
+; CHECK-BPI: [[PROF1]] = !{!"branch_weights", i64 1073741824, i64 3221225472}
+; CHECK-BPI: [[PROF2]] = !{!"branch_weights", i32 858993459, i32 1288490189}
+; CHECK-BPI: [[PROF3]] = !{!"branch_weights", i32 1431655764, i32 715827884}
 ;.
+;; NOTE: These prefixes are unused and the list is autogenerated. Do not add tests below this line:
+; CHECK-BPI: {{.*}}
diff --git a/llvm/test/Transforms/JumpThreading/static-profile.ll b/llvm/test/Transforms/JumpThreading/static-profile.ll
index f64e68943b985..5a3731ee26231 100644
--- a/llvm/test/Transforms/JumpThreading/static-profile.ll
+++ b/llvm/test/Transforms/JumpThreading/static-profile.ll
@@ -97,8 +97,7 @@ eq_1:
 check_2:
   %cond2 = icmp eq i32 %v, 2
   br i1 %cond2, label %eq_2, label %check_3
-; No metadata:
-; CHECK: br i1 %cond2, label %eq_2, label %check_3{{$}}
+; CHECK: br i1 %cond2, label %eq_2, label %check_3, !prof ![[PROF2:[0-9]+]]{{$}}
 
 eq_2:
   call void @bar()
@@ -111,8 +110,7 @@ eq_2:
 check_3:
   %condE = icmp eq i32 %v, 3
   br i1 %condE, label %exit, label %latch
-; No metadata:
-; CHECK: br i1 %condE, label %exit, label %latch{{$}}
+; CHECK: br i1 %condE, label %exit, label %latch, !prof ![[PROF2]]{{$}}
 
 latch:
   br label %check_1
@@ -122,7 +120,6 @@ exit:
 }
 
 !0 = !{!"function_entry_count", i64 120}
-; CHECK-NOT: branch_weights
 !1 = !{!"branch_weights", i32 119, i32 1}
 ; CHECK: !1 = !{!"branch_weights", i32 119, i32 1}
-; CHECK-NOT: branch_weights
+; CHECK: ![[PROF2]] = !{!"branch_weights", i32 -2147483648, i32 0}
diff --git a/llvm/test/Transforms/JumpThreading/thread-prob-1.ll b/llvm/test/Transforms/JumpThreading/thread-prob-1.ll
index e59539123d6ea..b25bf4c1b0843 100644
--- a/llvm/test/Transforms/JumpThreading/thread-prob-1.ll
+++ b/llvm/test/Transforms/JumpThreading/thread-prob-1.ll
@@ -1,4 +1,4 @@
-; RUN: opt -debug-only=branch-prob -passes=jump-threading -S %s 2>&1 | FileCheck %s
+; RUN: opt -debug-only=branch-prob -passes="require<branch-prob>,jump-threading" -S %s 2>&1 | FileCheck %s
 ; REQUIRES: asserts
 
 ; Make sure that we set the branch probability for the newly created
diff --git a/llvm/test/Transforms/JumpThreading/thread-prob-2.ll b/llvm/test/Transforms/JumpThreading/thread-prob-2.ll
index cbb8339597df0..e1ebb6d9b301b 100644
--- a/llvm/test/Transforms/JumpThreading/thread-prob-2.ll
+++ b/llvm/test/Transforms/JumpThreading/thread-prob-2.ll
@@ -1,12 +1,10 @@
 ; RUN: opt -debug-only=branch-prob -passes="require<branch-prob>,jump-threading" -S %s 2>&1 | FileCheck %s
-; RUN: opt -debug-only=branch-prob -passes=jump-threading -S %s 2>&1 | FileCheck %s --check-prefix=CHECK-NOBPI
 ; REQUIRES: asserts
 
 ; Make sure that we clear edge probabilities for bb.cond as we fold
 ; the conditional branch in it.
 
 ; CHECK: eraseBlock bb.cond
-; CHECK-NOBPI-NOT: eraseBlock bb.cond
 
 define i32 @foo(i1 %cond) !prof !0 {
 ; CHECK-LABEL: @foo
@@ -26,4 +24,4 @@ bb.12:
   ret i32 12
 }
 
-!0 = !{!"function_entry_count", i64 0}
+!0 = !{!"function_entry_count", i64 1}
diff --git a/llvm/test/Transforms/JumpThreading/thread-prob-3.ll b/llvm/test/Transforms/JumpThreading/thread-prob-3.ll
index 30afd8e6033b9..4683f428f875b 100644
--- a/llvm/test/Transforms/JumpThreading/thread-prob-3.ll
+++ b/llvm/test/Transforms/JumpThreading/thread-prob-3.ll
@@ -1,5 +1,4 @@
 ; RUN: opt -debug-only=branch-prob -passes="require<branch-prob>,jump-threading" -S %s 2>&1 | FileCheck %s
-; RUN: opt -debug-only=branch-prob -passes=jump-threading -S %s 2>&1 | FileCheck %s --check-prefix=CHECK-NOBPI
 ; REQUIRES: asserts
 
 ; Make sure that we set edge probabilities for bb2 as we
@@ -8,8 +7,7 @@
 ; CHECK-LABEL: ---- Branch Probability Info : foo
 ; CHECK:      set edge bb2 -> 0 successor probability to 0x80000000 / 0x80000000 = 100.00%
 ; CHECK-NEXT: set edge bb2 -> 1 successor probability to 0x00000000 / 0x80000000 = 0.00%
-; CHECK-NOBPI-NOT: ---- Branch Probability Info : foo
-define void @foo(i1 %f0, i1 %f1, i1 %f2) !prof !{!"function_entry_count", i64 0} {
+define void @foo(i1 %f0, i1 %f1, i1 %f2) !prof !{!"function_entry_count", i64 1} {
 ; CHECK-LABEL: @foo(
 bb1:
   br i1 %f0, label %bb3, label %bb2
diff --git a/llvm/test/Transforms/JumpThreading/thread-prob-4.ll b/llvm/test/Transforms/JumpThreading/thread-prob-4.ll
index fcdb51924b3e1..61836a2e25702 100644
--- a/llvm/test/Transforms/JumpThreading/thread-prob-4.ll
+++ b/llvm/test/Transforms/JumpThreading/thread-prob-4.ll
@@ -1,12 +1,10 @@
 ; RUN: opt -debug-only=branch-prob -passes="require<branch-prob>,jump-threading" -S %s 2>&1 | FileCheck %s
-; RUN: opt -debug-only=branch-prob -passes=jump-threading -S %s 2>&1 | FileCheck %s --check-prefix=CHECK-NOBPI
 ; REQUIRES: asserts
 
 ; Make sure that we clear edge probabilities for bb1 as we fold
 ; the conditional branch in it.
 
 ; CHECK: eraseBlock bb1
-; CHECK-NOBPI-NOT: eraseBlock bb1
 
 define i32 @foo(i32 %arg) !prof !0 {
 ; CHECK-LABEL: @foo
@@ -28,4 +26,4 @@ bb4:
   ret i32 4
 }
 
-!0 = !{!"function_entry_count", i64 0}
+!0 = !{!"function_entry_count", i64 1}
diff --git a/llvm/test/Transforms/JumpThreading/thread-prob-5.ll b/llvm/test/Transforms/JumpThreading/thread-prob-5.ll
index 95371e1e3b071..b8f3881b5c6ec 100644
--- a/llvm/test/Transforms/JumpThreading/thread-prob-5.ll
+++ b/llvm/test/Transforms/JumpThreading/thread-prob-5.ll
@@ -1,12 +1,10 @@
 ; RUN: opt -debug-only=branch-prob -passes="require<branch-prob>,jump-threading" -S %s 2>&1 | FileCheck %s
-; RUN: opt -debug-only=branch-prob -passes=jump-threading -S %s 2>&1 | FileCheck %s --check-prefix=CHECK-NOBPI
 ; REQUIRES: asserts
 
 ; Make sure that we clear edge probabilities for bb1 as we fold
 ; the conditional branch in it.
 
 ; CHECK: eraseBlock bb1
-; CHECK-NOBPI-NOT: eraseBlock bb1
 
 define void @foo(i32 %i, i32 %len) !prof !0 {
 ; CHECK-LABEL: @foo
@@ -27,4 +25,4 @@ bb3:
   ret void
 }
 
-!0 = !{!"function_entry_count", i64 0}
+!0 = !{!"function_entry_count", i64 1}
diff --git a/llvm/test/Transforms/JumpThreading/thread-prob-6.ll b/llvm/test/Transforms/JumpThreading/thread-prob-6.ll
index 6a0746a60e1e1..756179aca13b1 100644
--- a/llvm/test/Transforms/JumpThreading/thread-prob-6.ll
+++ b/llvm/test/Transforms/JumpThreading/thread-prob-6.ll
@@ -1,12 +1,10 @@
 ; RUN: opt -debug-only=branch-prob -passes="require<branch-prob>,jump-threading" -S %s 2>&1 | FileCheck %s
-; RUN: opt -debug-only=branch-prob -passes=jump-threading -S %s 2>&1 | FileCheck %s --check-prefix=CHECK-NOBPI
 ; REQUIRES: asserts
 
 ; Make sure that we clear edge probabilities for bb1 as we fold
 ; the conditional branch in it.
 
 ; CHECK: eraseBlock bb1
-; CHECK-NOBPI-NOT: eraseBlock bb1
 
 define i32 @foo() !prof !0 {
 ; CHECK-LABEL: @foo
@@ -21,4 +19,4 @@ bb3:
   ret i32 7
 }
 
-!0 = !{!"function_entry_count", i64 0}
+!0 = !{!"function_entry_count", i64 1}
diff --git a/llvm/test/Transforms/JumpThreading/thread-prob-7.ll b/llvm/test/Transforms/JumpThreading/thread-prob-7.ll
index 8c9d89871d00b..2e6775c590d49 100644
--- a/llvm/test/Transforms/JumpThreading/thread-prob-7.ll
+++ b/llvm/test/Transforms/JumpThreading/thread-prob-7.ll
@@ -1,5 +1,5 @@
 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --check-globals
-; RUN: opt -S -passes="jump-threading" < %s 2>&1 | FileCheck %s
+; RUN: opt -S -passes="require<branch-prob>,jump-threading" < %s 2>&1 | FileCheck %s
 
 declare void @foobar()
 
diff --git a/llvm/test/Transforms/JumpThreading/thread-prob-8.ll b/llvm/test/Transforms/JumpThreading/thread-prob-8.ll
index d23121ff8a928..efcd2fbcad4b8 100644
--- a/llvm/test/Transforms/JumpThreading/thread-prob-8.ll
+++ b/llvm/test/Transforms/JumpThreading/thread-prob-8.ll
@@ -1,4 +1,4 @@
-; RUN: opt -debug-only=branch-prob -passes=jump-threading -S %s 2>&1 | FileCheck %s
+; RUN: opt -debug-only=branch-prob -passes="require<branch-prob>,jump-threading" -S %s 2>&1 | FileCheck %s
 ; REQUIRES: asserts
 
 ; Make sure that edges' probabilities would not accumulate if they are
@@ -16,9 +16,9 @@
 ; CHECK: set edge L0 -> 1 successor probability to 0x33333333 / 0x80000000 = 40.00%
 ; CHECK: set edge L0 -> 2 successor probability to 0x1999999a / 0x80000000 = 20.00%
 ; CHECK: set edge L0 -> 3 successor probability to 0x1999999a / 0x80000000 = 20.00%
-; CHECK-NOT: !0 = !{!"branch_weights", i32 306783378, i32 613566757, i32 613566757, i32 613566757}
-; CHECK: !0 = !{!"branch_weights", i32 429496730, i32 858993459, i32 429496730, i32 429496730}
-define void @test_switch(i1 %cond, i8 %value) nounwind {
+; CHECK-NOT: !1 = !{!"branch_weights", i32 306783378, i32 613566757, i32 613566757, i32 613566757}
+; CHECK: !1 = !{!"branch_weights", i32 429496730, i32 858993459, i32 429496730, i32 429496730}
+define void @test_switch(i1 %cond, i8 %value) nounwind !prof !1 {
 entry:
   br i1 %cond, label %L0, label %L4
 L0:
@@ -39,3 +39,4 @@ L4:
   br label %L0
 }
 !0 = !{!"branch_weights", i32 1, i32 7, i32 1, i32 1}
+!1 = !{!"function_entry_count", i64 1}
diff --git a/llvm/test/Transforms/JumpThreading/threading_prof1.ll b/llvm/test/Transforms/JumpThreading/threading_prof1.ll
index 28f1abe2d0948..404e2c1e50e82 100644
--- a/llvm/test/Transforms/JumpThreading/threading_prof1.ll
+++ b/llvm/test/Transforms/JumpThreading/threading_prof1.ll
@@ -1,6 +1,6 @@
-; RUN: opt -passes=jump-threading -S < %s | FileCheck %s
+; RUN: opt -passes="require<branch-prob>,jump-threading" -S < %s | FileCheck %s
 
-define void @test() {
+define void @test() !prof !1 {
 ; CHECK-LABEL: @test()
 bb:
   %tmp = call i32 @a()
@@ -26,7 +26,7 @@ bb8:                                              ; preds = %bb7, %bb5
   ret void
 }
 
-define void @test_single_pred1() {
+define void @test_single_pred1() !prof !1 {
 ; CHECK-LABEL: @test_single_pred1()
 bb:
   %tmp = call i32 @a()
@@ -55,7 +55,7 @@ bb8:
   ret void
 }
 
-define void @test_single_pred2() {
+define void @test_single_pred2() !prof !1 {
 ; CHECK-LABEL: @test_single_pred2()
 bb:
   %tmp = call i32 @a()
@@ -96,3 +96,4 @@ declare i32 @b()
 !0 = !{!"branch_weights", i32 2146410443, i32 1073205}
 ;CHECK: ![[PROF1]] = !{!"branch_weights", i32 1073205, i32 2146410443}
 ;CHECK: ![[PROF2]] = !{!"branch_weights", i32 -2147483648, i32 0}
+!1 = !{!"function_entry_count", i64 1}
diff --git a/llvm/test/Transforms/JumpThreading/threading_prof2.ll b/llvm/test/Transforms/JumpThreading/threading_prof2.ll
index 8b217411cd1da..8830a01943db3 100644
--- a/llvm/test/Transforms/JumpThreading/threading_prof2.ll
+++ b/llvm/test/Transforms/JumpThreading/threading_prof2.ll
@@ -1,5 +1,5 @@
-; RUN: opt -passes=jump-threading -S < %s | FileCheck %s
-define void @test() {
+; RUN: opt -passes="require<branch-prob>,jump-threading" -S < %s | FileCheck %s
+define void @test() !prof !1 {
 bb:
   %tmp = call i32 @a()
   %tmp1 = icmp eq i32 %tmp, 1
@@ -39,3 +39,4 @@ declare i32 @b()
 !0 = !{!"branch_weights", i32 2146410443, i32 1073205}
 ;CHECK: ![[PROF1]] = !{!"branch_weights", i32 1073205, i32 2146410443}
 ;CHECK: ![[PROF2]] = !{!"branch_weights", i32 -2147483648, i32 0}
+!1 = !{!"function_entry_count", i64 1}
diff --git a/llvm/test/Transforms/JumpThreading/threading_prof3.ll b/llvm/test/Transforms/JumpThreading/threading_prof3.ll
index e7332018c4629..51096bd25ca3a 100644
--- a/llvm/test/Transforms/JumpThreading/threading_prof3.ll
+++ b/llvm/test/Transforms/JumpThreading/threading_prof3.ll
@@ -1,7 +1,7 @@
-; RUN: opt -passes=jump-threading -S < %s | FileCheck %s
+; RUN: opt -passes="require<branch-prob>,jump-threading" -S < %s | FileCheck %s
 
 ; Check that all zero branch weights do not cause a crash.
-define void @zero_branch_weights(i32 %tmp, i32 %tmp3) {
+define void @zero_branch_weights(i32 %tmp, i32 %tmp3) !prof !0 {
 bb:
   %tmp1 = icmp eq i32 %tmp, 1
   br i1 %tmp1, label %bb5, label %bb2
@@ -27,3 +27,4 @@ bb9:
 }
 
 ;CHECK: ![[PROF]] = !{!"branch_weights", i32 -2147483648, i32 0}
+!0 = !{!"function_entry_count", i64 1}
diff --git a/llvm/test/Transforms/JumpThreading/update-edge-weight.ll b/llvm/test/Transforms/JumpThreading/update-edge-weight.ll
index 6313a87993303..cbd1c05681533 100644
--- a/llvm/test/Transforms/JumpThreading/update-edge-weight.ll
+++ b/llvm/test/Transforms/JumpThreading/update-edge-weight.ll
@@ -1,4 +1,4 @@
-; RUN: opt -S -passes=jump-threading %s | FileCheck %s
+; RUN: opt -S -passes="require<branch-prob>,jump-threading" %s | FileCheck %s
 
 ; Test if edge weights are properly updated after jump threading.
 



More information about the llvm-commits mailing list