[llvm] [MergeFunctions] Preserve instruction-level profile metadata during merging (PR #208009)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 7 07:33:19 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-transforms
Author: Alok Kumar Sharma (alokkrsharma)
<details>
<summary>Changes</summary>
Merge branch weights and value profile metadata when equivalent functions are folded. Instruction-level branch weights and value profiles are scaled to absolute counts using BlockFrequencyInfo before being aggregated.
---
Patch is 31.73 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/208009.diff
3 Files Affected:
- (modified) llvm/include/llvm/Transforms/IPO/MergeFunctions.h (+4-2)
- (modified) llvm/lib/Transforms/IPO/MergeFunctions.cpp (+272-16)
- (added) llvm/test/Transforms/MergeFunc/merge-functions-prof-metadata.ll (+460)
``````````diff
diff --git a/llvm/include/llvm/Transforms/IPO/MergeFunctions.h b/llvm/include/llvm/Transforms/IPO/MergeFunctions.h
index 75399d3297a05..218bd0702e1d2 100644
--- a/llvm/include/llvm/Transforms/IPO/MergeFunctions.h
+++ b/llvm/include/llvm/Transforms/IPO/MergeFunctions.h
@@ -28,9 +28,11 @@ class MergeFunctionsPass : public OptionalPassInfoMixin<MergeFunctionsPass> {
public:
LLVM_ABI PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
- LLVM_ABI static bool runOnModule(Module &M);
+ LLVM_ABI static bool runOnModule(Module &M,
+ FunctionAnalysisManager *FAM = nullptr);
LLVM_ABI static DenseMap<Function *, Function *>
- runOnFunctions(ArrayRef<Function *> F);
+ runOnFunctions(ArrayRef<Function *> F,
+ FunctionAnalysisManager *FAM = nullptr);
};
} // end namespace llvm
diff --git a/llvm/lib/Transforms/IPO/MergeFunctions.cpp b/llvm/lib/Transforms/IPO/MergeFunctions.cpp
index c4e56855ea2fb..c78bb2b0f357f 100644
--- a/llvm/lib/Transforms/IPO/MergeFunctions.cpp
+++ b/llvm/lib/Transforms/IPO/MergeFunctions.cpp
@@ -89,14 +89,21 @@
//===----------------------------------------------------------------------===//
#include "llvm/Transforms/IPO/MergeFunctions.h"
+#include "llvm/ADT/APInt.h"
#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/DenseMap.h"
+#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/Statistic.h"
+#include "llvm/Analysis/BlockFrequencyInfo.h"
+#include "llvm/Analysis/BranchProbabilityInfo.h"
+#include "llvm/Analysis/LoopInfo.h"
#include "llvm/IR/Argument.h"
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/DebugInfoMetadata.h"
#include "llvm/IR/DebugLoc.h"
#include "llvm/IR/DerivedTypes.h"
+#include "llvm/IR/Dominators.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/GlobalValue.h"
#include "llvm/IR/IRBuilder.h"
@@ -104,16 +111,21 @@
#include "llvm/IR/Instruction.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/IntrinsicInst.h"
+#include "llvm/IR/Metadata.h"
#include "llvm/IR/Module.h"
+#include "llvm/IR/PassManager.h"
+#include "llvm/IR/ProfDataUtils.h"
#include "llvm/IR/StructuralHash.h"
#include "llvm/IR/Type.h"
#include "llvm/IR/Use.h"
#include "llvm/IR/User.h"
#include "llvm/IR/Value.h"
#include "llvm/IR/ValueHandle.h"
+#include "llvm/ProfileData/InstrProf.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Debug.h"
+#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/MathExtras.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Transforms/IPO.h"
@@ -121,7 +133,10 @@
#include "llvm/Transforms/Utils/ModuleUtils.h"
#include <algorithm>
#include <cassert>
+#include <cstddef>
+#include <cstdint>
#include <iterator>
+#include <memory>
#include <optional>
#include <set>
#include <utility>
@@ -198,10 +213,13 @@ class MergeFunctions {
}
template <typename FuncContainer> bool run(FuncContainer &Functions);
- DenseMap<Function *, Function *> runOnFunctions(ArrayRef<Function *> F);
+ DenseMap<Function *, Function *>
+ runOnFunctions(ArrayRef<Function *> F, FunctionAnalysisManager *AM = nullptr);
SmallPtrSet<GlobalValue *, 4> &getUsed();
+ void setFunctionAnalysisManager(FunctionAnalysisManager *AM) { FAM = AM; }
+
private:
// The function comparison operator is provided here so that FunctionNodes do
// not need to become larger with another pointer.
@@ -257,6 +275,10 @@ class MergeFunctions {
/// again.
void mergeTwoFunctions(Function *F, Function *G);
+ const BlockFrequencyInfo &getBFI(Function &F);
+
+ void mergeProfMetadataInto(Function *F, Function *G);
+
/// Fill PDIUnrelatedWL with instructions from the entry block that are
/// unrelated to parameter related debug info.
/// \param PDVRUnrelatedWL The equivalent non-intrinsic debug records.
@@ -287,7 +309,9 @@ class MergeFunctions {
// If needed, replace G with an alias to F if possible, or a thunk to F if
// profitable. Returns false if neither is the case. If \p G is not needed
// (i.e. it is discardable and not used), \p G is removed directly.
- bool writeThunkOrAliasIfNeeded(Function *F, Function *G);
+ // \p MergeProfile must be true when G's profile should be preserved, it is
+ // merged into F before G is erased or rewritten.
+ bool writeThunkOrAliasIfNeeded(Function *F, Function *G, bool MergeProfile);
/// Replace function F with function G in the function tree.
void replaceFunctionInTree(const FunctionNode &FN, Function *G);
@@ -305,20 +329,36 @@ class MergeFunctions {
/// Deleted-New functions mapping
DenseMap<Function *, Function *> DelToNewMap;
+
+ FunctionAnalysisManager *FAM = nullptr;
+
+ struct CachedProfileAnalyses {
+ DominatorTree DT;
+ LoopInfo LI;
+ BranchProbabilityInfo BPI;
+ BlockFrequencyInfo BFI;
+
+ CachedProfileAnalyses(Function &F)
+ : DT(F), LI(DT), BPI(F, LI, nullptr, &DT), BFI(F, BPI, LI) {}
+ };
+ DenseMap<const Function *, std::unique_ptr<CachedProfileAnalyses>> CachedBFI;
};
} // end anonymous namespace
PreservedAnalyses MergeFunctionsPass::run(Module &M,
ModuleAnalysisManager &AM) {
- if (!MergeFunctionsPass::runOnModule(M))
+ auto &FAM = AM.getResult<FunctionAnalysisManagerModuleProxy>(M).getManager();
+ if (!MergeFunctionsPass::runOnModule(M, &FAM))
return PreservedAnalyses::all();
return PreservedAnalyses::none();
}
SmallPtrSet<GlobalValue *, 4> &MergeFunctions::getUsed() { return Used; }
-bool MergeFunctionsPass::runOnModule(Module &M) {
+bool MergeFunctionsPass::runOnModule(Module &M, FunctionAnalysisManager *FAM) {
MergeFunctions MF;
+ if (FAM)
+ MF.setFunctionAnalysisManager(FAM);
SmallVector<GlobalValue *, 4> UsedV;
collectUsedGlobalVariables(M, UsedV, /*CompilerUsed=*/false);
collectUsedGlobalVariables(M, UsedV, /*CompilerUsed=*/true);
@@ -327,9 +367,10 @@ bool MergeFunctionsPass::runOnModule(Module &M) {
}
DenseMap<Function *, Function *>
-MergeFunctionsPass::runOnFunctions(ArrayRef<Function *> F) {
+MergeFunctionsPass::runOnFunctions(ArrayRef<Function *> F,
+ FunctionAnalysisManager *FAM) {
MergeFunctions MF;
- return MF.runOnFunctions(F);
+ return MF.runOnFunctions(F, FAM);
}
#ifndef NDEBUG
@@ -493,7 +534,10 @@ template <typename FuncContainer> bool MergeFunctions::run(FuncContainer &M) {
}
DenseMap<Function *, Function *>
-MergeFunctions::runOnFunctions(ArrayRef<Function *> F) {
+MergeFunctions::runOnFunctions(ArrayRef<Function *> F,
+ FunctionAnalysisManager *AM) {
+ if (AM)
+ setFunctionAnalysisManager(AM);
[[maybe_unused]] bool MergeResult = this->run(F);
assert(MergeResult == !DelToNewMap.empty());
return this->DelToNewMap;
@@ -858,21 +902,36 @@ void MergeFunctions::writeAlias(Function *F, Function *G) {
// If needed, replace G with an alias to F if possible, or a thunk to F if
// profitable. Returns false if neither is the case. If \p G is not needed (i.e.
-// it is discardable and unused), \p G is removed directly.
-bool MergeFunctions::writeThunkOrAliasIfNeeded(Function *F, Function *G) {
- if (G->isDiscardableIfUnused() && G->use_empty() && !MergeFunctionsPDI) {
+// it is discardable and unused), \p G is removed directly. If \p MergeProfile
+// is set, G's profile metadata is merged into F.
+bool MergeFunctions::writeThunkOrAliasIfNeeded(Function *F, Function *G,
+ bool MergeProfile) {
+ bool ShouldErase =
+ G->isDiscardableIfUnused() && G->use_empty() && !MergeFunctionsPDI;
+ bool ShouldAlias = canCreateAliasFor(G);
+ bool ShouldThunk = canCreateThunkFor(F);
+
+ if (!ShouldErase && !ShouldAlias && !ShouldThunk)
+ return false;
+
+ if (MergeProfile)
+ mergeProfMetadataInto(F, G);
+
+ if (ShouldErase) {
G->eraseFromParent();
return true;
}
- if (canCreateAliasFor(G)) {
+
+ if (ShouldAlias) {
writeAlias(F, G);
return true;
}
- if (canCreateThunkFor(F)) {
+ if (ShouldThunk) {
writeThunk(F, G);
return true;
}
- return false;
+
+ llvm_unreachable("Erase, alias or thunk must apply");
}
/// Returns true if \p F is either weak_odr or linkonce_odr.
@@ -880,6 +939,199 @@ static bool isODR(const Function *F) {
return F->hasWeakODRLinkage() || F->hasLinkOnceODRLinkage();
}
+static uint64_t getBlockCountForMerging(const BlockFrequencyInfo *BFI,
+ const BasicBlock *BB,
+ std::optional<uint64_t> EC) {
+ if (BFI) {
+ if (auto Count = BFI->getBlockProfileCount(BB, /*AllowSynthetic=*/true))
+ return *Count;
+ // BFI present but no count for this block, fall through to EC.
+ }
+ if (EC)
+ return *EC;
+ return 1;
+}
+
+// The branch/value profile weights are relative within a function. Before
+// merge we need to normalize weights to absolute counts.
+// (weight * BlockCount / TotalWeight)
+static uint64_t scaleToBlockCount(uint64_t Weight, uint64_t TotalWeight,
+ uint64_t BlockCount) {
+ if (Weight == 0 || TotalWeight == 0 || BlockCount == 0)
+ return 0;
+ APInt Num(128, BlockCount);
+ Num *= APInt(128, Weight);
+ APInt Den(128, TotalWeight);
+ Num = (Num + Den.lshr(1)).udiv(Den);
+ return Num.getLimitedValue();
+}
+
+// Combine the scaled branch_weights of corresponding instructions of F and G.
+static void mergeBranchWeightsOnInstructions(Instruction *FI,
+ const Instruction *GI,
+ const BlockFrequencyInfo *BfiF,
+ const BlockFrequencyInfo *BfiG,
+ std::optional<uint64_t> FEC,
+ std::optional<uint64_t> GEC) {
+ SmallVector<uint32_t, 8> FWeights, GWeights;
+ bool HasF = extractBranchWeights(*FI, FWeights);
+ bool HasG = extractBranchWeights(*GI, GWeights);
+ if (!HasF && !HasG)
+ return;
+
+ uint64_t BlockCountF = getBlockCountForMerging(BfiF, FI->getParent(), FEC);
+ uint64_t BlockCountG = getBlockCountForMerging(BfiG, GI->getParent(), GEC);
+
+ uint64_t TotalF = 0, TotalG = 0;
+ if (HasF)
+ extractProfTotalWeight(*FI, TotalF);
+ if (HasG)
+ extractProfTotalWeight(*GI, TotalG);
+
+ size_t NumWeights = std::max(HasF ? FWeights.size() : size_t{0},
+ HasG ? GWeights.size() : size_t{0});
+ SmallVector<uint64_t, 8> MergedWeights;
+ MergedWeights.reserve(NumWeights);
+ for (size_t I = 0; I < NumWeights; ++I) {
+ uint64_t FW = (HasF && I < FWeights.size()) ? FWeights[I] : 0;
+ uint64_t GW = (HasG && I < GWeights.size()) ? GWeights[I] : 0;
+ uint64_t AbsF = HasF ? scaleToBlockCount(FW, TotalF, BlockCountF) : 0;
+ uint64_t AbsG = HasG ? scaleToBlockCount(GW, TotalG, BlockCountG) : 0;
+ MergedWeights.push_back(SaturatingAdd(AbsF, AbsG));
+ }
+
+ bool IsExpected = hasBranchWeightOrigin(*FI) || hasBranchWeightOrigin(*GI);
+ setFittedBranchWeights(*FI, MergedWeights, IsExpected);
+}
+
+// Accumulate scaled value profile counts of Instruction I into Merged.
+static void addScaledValueProfile(const Instruction &I, InstrProfValueKind Kind,
+ uint64_t BlockCount,
+ DenseMap<uint64_t, uint64_t> &Merged) {
+ uint64_t Total = 0;
+ SmallVector<InstrProfValueData, 4> VDs =
+ getValueProfDataFromInst(I, Kind, /*MaxNumValueData=*/UINT32_MAX, Total);
+ if (VDs.empty() || Total == 0)
+ return;
+ for (const InstrProfValueData &VD : VDs) {
+ uint64_t Abs = scaleToBlockCount(VD.Count, Total, BlockCount);
+ Merged[VD.Value] = SaturatingAdd(Merged[VD.Value], Abs);
+ }
+}
+
+// Merge (union) scaled value profiles of F and G.
+static void mergeValueProfileOnInstructions(Instruction *FI,
+ const Instruction *GI,
+ const BlockFrequencyInfo *BfiF,
+ const BlockFrequencyInfo *BfiG,
+ std::optional<uint64_t> FEC,
+ std::optional<uint64_t> GEC) {
+ MDNode *ProfF = FI->getMetadata(LLVMContext::MD_prof);
+ MDNode *ProfG = GI->getMetadata(LLVMContext::MD_prof);
+ bool HasF = ProfF && isValueProfileMD(ProfF);
+ bool HasG = ProfG && isValueProfileMD(ProfG);
+ if (!HasF && !HasG)
+ return;
+
+ auto *KindF =
+ HasF ? mdconst::dyn_extract<ConstantInt>(ProfF->getOperand(1)) : nullptr;
+ auto *KindG =
+ HasG ? mdconst::dyn_extract<ConstantInt>(ProfG->getOperand(1)) : nullptr;
+ if (HasF && HasG && KindF && KindG &&
+ KindF->getZExtValue() != KindG->getZExtValue()) {
+ FI->setMetadata(LLVMContext::MD_prof, nullptr);
+ return;
+ }
+
+ const ConstantInt *KindCI = KindF ? KindF : KindG;
+ if (!KindCI) {
+ FI->setMetadata(LLVMContext::MD_prof, nullptr);
+ return;
+ }
+
+ InstrProfValueKind Kind =
+ static_cast<InstrProfValueKind>(KindCI->getZExtValue());
+
+ DenseMap<uint64_t, uint64_t> Merged;
+ uint64_t BCF = getBlockCountForMerging(BfiF, FI->getParent(), FEC);
+ uint64_t BCG = getBlockCountForMerging(BfiG, GI->getParent(), GEC);
+ if (HasF)
+ addScaledValueProfile(*FI, Kind, BCF, Merged);
+ if (HasG)
+ addScaledValueProfile(*GI, Kind, BCG, Merged);
+
+ if (Merged.empty())
+ return;
+
+ SmallVector<InstrProfValueData, 8> VDs;
+ VDs.reserve(Merged.size());
+ uint64_t Sum = 0;
+ for (auto &[Value, Count] : Merged) {
+ VDs.push_back({Value, Count});
+ Sum = SaturatingAdd(Sum, Count);
+ }
+ llvm::sort(VDs, [](const InstrProfValueData &A, const InstrProfValueData &B) {
+ return A.Count > B.Count;
+ });
+ annotateValueSite(*FI->getFunction()->getParent(), *FI, VDs, Sum, Kind,
+ VDs.size());
+}
+
+const BlockFrequencyInfo &MergeFunctions::getBFI(Function &F) {
+ if (FAM)
+ return FAM->getResult<BlockFrequencyAnalysis>(F);
+ auto &Entry = CachedBFI[&F];
+ if (!Entry)
+ Entry = std::make_unique<CachedProfileAnalyses>(F);
+ return Entry->BFI;
+}
+
+void MergeFunctions::mergeProfMetadataInto(Function *F, Function *G) {
+ std::optional<uint64_t> FEC = F->getEntryCount();
+ std::optional<uint64_t> GEC = G->getEntryCount();
+ const BlockFrequencyInfo *BfiF = &getBFI(*F);
+ const BlockFrequencyInfo *BfiG = &getBFI(*G);
+
+ SmallVector<std::pair<BasicBlock *, const BasicBlock *>, 8> BBWorklist;
+ SmallPtrSet<const BasicBlock *, 32> VisitedBBs;
+
+ BBWorklist.emplace_back(&F->getEntryBlock(), &G->getEntryBlock());
+ VisitedBBs.insert(BBWorklist.back().first);
+
+ while (!BBWorklist.empty()) {
+ auto [BBF, BBG] = BBWorklist.pop_back_val();
+
+ for (auto [FI, GI] : llvm::zip(*BBF, *BBG)) {
+ MDNode *ProfF = FI.getMetadata(LLVMContext::MD_prof);
+ MDNode *ProfG = GI.getMetadata(LLVMContext::MD_prof);
+ if ((ProfF && isValueProfileMD(ProfF)) ||
+ (ProfG && isValueProfileMD(ProfG)))
+ mergeValueProfileOnInstructions(&FI, &GI, BfiF, BfiG, FEC, GEC);
+ if (isa<SelectInst>(FI))
+ mergeBranchWeightsOnInstructions(&FI, &GI, BfiF, BfiG, FEC, GEC);
+ }
+
+ Instruction *TermF = BBF->getTerminator();
+ const Instruction *TermG = BBG->getTerminator();
+ mergeBranchWeightsOnInstructions(TermF, TermG, BfiF, BfiG, FEC, GEC);
+ for (unsigned I = 0, E = TermF->getNumSuccessors(); I != E; ++I) {
+ if (!VisitedBBs.insert(TermF->getSuccessor(I)).second)
+ continue;
+ BBWorklist.emplace_back(TermF->getSuccessor(I), TermG->getSuccessor(I));
+ }
+ }
+
+ if (FAM) {
+ PreservedAnalyses PA = PreservedAnalyses::all();
+ PA.abandon<BranchProbabilityAnalysis>();
+ PA.abandon<BlockFrequencyAnalysis>();
+ FAM->invalidate(*F, PA);
+ } else {
+ CachedBFI.erase(F);
+ CachedBFI.erase(G);
+ }
+}
+
static void mergeEntryCountsInto(Function *F, std::optional<uint64_t> FC,
std::optional<uint64_t> GC) {
if (!FC && !GC)
@@ -935,10 +1187,13 @@ void MergeFunctions::mergeTwoFunctions(Function *F, Function *G) {
const MaybeAlign NewFAlign = NewF->getAlign();
const MaybeAlign GAlign = G->getAlign();
- writeThunkOrAliasIfNeeded(F, G);
+ // Merge !prof, while G still has its body.
+ writeThunkOrAliasIfNeeded(F, G, /*MergeProfile*/ true);
if (FEC)
NewF->setEntryCount(*FEC);
- writeThunkOrAliasIfNeeded(F, NewF);
+ // NewF becomes thunk/alias to the shared body F, it has no profile to be
+ // merged.
+ writeThunkOrAliasIfNeeded(F, NewF, /*MergeProfile*/ false);
if (NewFAlign || GAlign)
F->setAlignment(std::max(NewFAlign.valueOrOne(), GAlign.valueOrOne()));
@@ -975,13 +1230,14 @@ void MergeFunctions::mergeTwoFunctions(Function *F, Function *G) {
// stop here and delete G. There's no need for a thunk. (See note on
// MergeFunctionsPDI above).
if (G->isDiscardableIfUnused() && G->use_empty() && !MergeFunctionsPDI) {
+ mergeProfMetadataInto(F, G);
mergeEntryCountsInto(F, FEC, GEC);
G->eraseFromParent();
++NumFunctionsMerged;
return;
}
- if (writeThunkOrAliasIfNeeded(F, G)) {
+ if (writeThunkOrAliasIfNeeded(F, G, /*MergeProfile*/ true)) {
mergeEntryCountsInto(F, FEC, GEC);
++NumFunctionsMerged;
}
diff --git a/llvm/test/Transforms/MergeFunc/merge-functions-prof-metadata.ll b/llvm/test/Transforms/MergeFunc/merge-functions-prof-metadata.ll
new file mode 100644
index 0000000000000..278ded8693662
--- /dev/null
+++ b/llvm/test/Transforms/MergeFunc/merge-functions-prof-metadata.ll
@@ -0,0 +1,460 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --include-generated-funcs --version 6
+; RUN: opt -S -passes=mergefunc < %s | FileCheck %s
+
+; Check mergefunc combines branch/value profile data.
+
+define internal i32 @bw_asym_a(i32 %x) !prof !1 {
+entry:
+ %cmp = icmp slt i32 %x, 0
+ br i1 %cmp, label %then, label %else, !prof !2
+
+then:
+ ret i32 1
+
+else:
+ ret i32 0
+}
+
+define internal i32 @bw_asym_b(i32 %x) !prof !3 {
+entry:
+ %cmp = icmp slt i32 %x, 0
+ br i1 %cmp, label %then, label %else, !prof !4
+
+then:
+ ret i32 1
+
+else:
+ ret i32 0
+}
+
+define internal i32 @bw_sym_a(i32 %x) !prof !5 {
+entry:
+ %cmp = icmp ne i32 %x, 0
+ br i1 %cmp, label %then, label %else, !prof !6
+
+then:
+ ret i32 4
+
+else:
+ ret i32 5
+}
+
+define internal i32 @bw_sym_b(i32 %x) !prof !7 {
+entry:
+ %cmp = icmp ne i32 %x, 0
+ br i1 %cmp, label %then, label %else, !prof !8
+
+then:
+ ret i32 4
+
+else:
+ ret i32 5
+}
+
+define internal i32 @bw_g_only_a(i32 %x) !prof !24 {
+entry:
+ %cmp = icmp sgt i32 %x, 0
+ br i1 %cmp, label %then, label %else
+
+then:
+ ret i32 7
+
+else:
+ ret i32 8
+}
+
+define internal i32 @bw_g_only_b(i32 %x) !prof !25 {
+entry:
+ %cmp = icmp sgt i32 %x, 0
+ br i1 %cmp, label %then, label %else, !prof !26
+
+then:
+ ret i32 7
+
+else:
+ ret i32 8
+}
+
+define internal i32 @select_bw_a(i32 %x) !prof !9 {
+entry:
+ %cmp = icmp slt i32 %x, 0
+ %sel = select i1 %cmp, i32 1, i32 0, !prof !10
+ ret i32 %sel
+}
+
+define internal i32 @select_bw_b(i32 %x) !prof !11 {
+entry:
+ %cmp = icmp slt i32 %x, 0
+ %sel = select i1 %cmp, i32 1, i32 0, !prof !12
+ ret i32 %sel
+}
+
+define internal i32 @vp_sym_a(ptr %fn) !prof !13 {
+entry:
+ %fn_val = load ptr, ptr %fn
+ %r = call i32 %fn_val(), !prof !14
+ ret i32 %r
+}
+
+define internal i32 @vp_sym_b(ptr %fn) !prof !15 {
+entry:
+ %fn_val = load ptr, ptr %fn
+ %r = call i32 %fn_val(), !prof !16
+ ret i32 %r
+}
+
+; add i32 1 keeps @vp_asym_* distinct from @vp_sym_*.
+define internal i32 @vp_asym_a(ptr %fn) !prof !17 {
+entry:
+ %fn_val = load ptr, ptr %fn
+ %r = call i32 %fn_val(), !prof !18
+ %adj = add i32 %r, 1
+ ret i32 %adj
+}
+
+define internal i32 @vp_asym_b(ptr %fn) !prof !19 {
+entry:
+ %fn_val = load ptr, ptr %fn
+ %r = call i32 %fn_val()
+ %adj = add i32 %r, 1
+ ret i32 %adj
+}
+
+define internal i32 @vp_g_only_a(ptr %fn) !prof !27 {
+entry:
+ %fn_val = load ptr, ptr %fn
+ %r = call i32 %fn_val()
+ %adj = add i32 %r, 3
+ ret i32 %adj
+}
+
+define internal i32 @vp_g_only_b(ptr %fn) !prof !28 {
+entry:
+ %fn_val = load ptr, ptr %fn
+ %r = call i32 %fn_val(), !prof !29
+ %adj...
[truncated]
``````````
</details>
https://github.com/llvm/llvm-project/pull/208009
More information about the llvm-commits
mailing list