Skip to content

Commit c5978f1

Browse files
authored
[llvm][IR] Extend BranchWeightMetadata to track provenance of weights (#86609)
This patch implements the changes to LLVM IR discussed in https://discourse.llvm.org/t/rfc-update-branch-weights-metadata-to-allow-tracking-branch-weight-origins/75032 In this patch, we add an optional field to MD_prof metadata nodes for branch weights, which can be used to distinguish weights added from `llvm.expect*` intrinsics from those added via other methods, e.g. from profiles or inserted by the compiler. One of the major motivations, is for use with MisExpect diagnostics, which need to know if branch_weight metadata originates from an llvm.expect intrinsic. Without that information, we end up checking branch weights multiple times in the case if ThinLTO + SampleProfiling, leading to some inaccuracy in how we report MisExpect related diagnostics to users. Since we change the format of MD_prof metadata in a fundamental way, we need to update code handling branch weights in a number of places. We also update the lang ref for branch weights to reflect the change.
1 parent 3254f31 commit c5978f1

30 files changed

+169
-88
lines changed

clang/test/CodeGenCXX/attr-likelihood-if-vs-builtin-expect.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,5 +221,5 @@ void tu2(int &i) {
221221
}
222222
}
223223

224-
// CHECK: [[BW_LIKELY]] = !{!"branch_weights", i32 2000, i32 1}
225-
// CHECK: [[BW_UNLIKELY]] = !{!"branch_weights", i32 1, i32 2000}
224+
// CHECK: [[BW_LIKELY]] = !{!"branch_weights", !"expected", i32 2000, i32 1}
225+
// CHECK: [[BW_UNLIKELY]] = !{!"branch_weights", !"expected", i32 1, i32 2000}

llvm/docs/BranchWeightMetadata.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,14 @@ Supported Instructions
2828

2929
Metadata is only assigned to the conditional branches. There are two extra
3030
operands for the true and the false branch.
31+
We optionally track if the metadata was added by ``__builtin_expect`` or
32+
``__builtin_expect_with_probability`` with an optional field ``!"expected"``.
3133

3234
.. code-block:: none
3335
3436
!0 = !{
3537
!"branch_weights",
38+
[ !"expected", ]
3639
i32 <TRUE_BRANCH_WEIGHT>,
3740
i32 <FALSE_BRANCH_WEIGHT>
3841
}
@@ -47,6 +50,7 @@ is always case #0).
4750
4851
!0 = !{
4952
!"branch_weights",
53+
[ !"expected", ]
5054
i32 <DEFAULT_BRANCH_WEIGHT>
5155
[ , i32 <CASE_BRANCH_WEIGHT> ... ]
5256
}
@@ -60,6 +64,7 @@ Branch weights are assigned to every destination.
6064
6165
!0 = !{
6266
!"branch_weights",
67+
[ !"expected", ]
6368
i32 <LABEL_BRANCH_WEIGHT>
6469
[ , i32 <LABEL_BRANCH_WEIGHT> ... ]
6570
}
@@ -75,6 +80,7 @@ block and entry counts which may not be accurate with sampling.
7580
7681
!0 = !{
7782
!"branch_weights",
83+
[ !"expected", ]
7884
i32 <CALL_BRANCH_WEIGHT>
7985
}
8086
@@ -95,6 +101,7 @@ is used.
95101
96102
!0 = !{
97103
!"branch_weights",
104+
[ !"expected", ]
98105
i32 <INVOKE_NORMAL_WEIGHT>
99106
[ , i32 <INVOKE_UNWIND_WEIGHT> ]
100107
}

llvm/include/llvm/IR/MDBuilder.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,11 @@ class MDBuilder {
5959
//===------------------------------------------------------------------===//
6060

6161
/// Return metadata containing two branch weights.
62-
MDNode *createBranchWeights(uint32_t TrueWeight, uint32_t FalseWeight);
62+
/// @param TrueWeight the weight of the true branch
63+
/// @param FalseWeight the weight of the false branch
64+
/// @param Do these weights come from __builtin_expect*
65+
MDNode *createBranchWeights(uint32_t TrueWeight, uint32_t FalseWeight,
66+
bool IsExpected = false);
6367

6468
/// Return metadata containing two branch weights, with significant bias
6569
/// towards `true` destination.
@@ -70,7 +74,10 @@ class MDBuilder {
7074
MDNode *createUnlikelyBranchWeights();
7175

7276
/// Return metadata containing a number of branch weights.
73-
MDNode *createBranchWeights(ArrayRef<uint32_t> Weights);
77+
/// @param Weights the weights of all the branches
78+
/// @param Do these weights come from __builtin_expect*
79+
MDNode *createBranchWeights(ArrayRef<uint32_t> Weights,
80+
bool IsExpected = false);
7481

7582
/// Return metadata specifying that a branch or switch is unpredictable.
7683
MDNode *createUnpredictable();

llvm/include/llvm/IR/ProfDataUtils.h

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,17 @@ MDNode *getBranchWeightMDNode(const Instruction &I);
5555
/// Nullptr otherwise.
5656
MDNode *getValidBranchWeightMDNode(const Instruction &I);
5757

58+
/// Check if Branch Weight Metadata has an "expected" field from an llvm.expect*
59+
/// intrinsic
60+
bool hasBranchWeightOrigin(const Instruction &I);
61+
62+
/// Check if Branch Weight Metadata has an "expected" field from an llvm.expect*
63+
/// intrinsic
64+
bool hasBranchWeightOrigin(const MDNode *ProfileData);
65+
66+
/// Return the offset to the first branch weight data
67+
unsigned getBranchWeightOffset(const MDNode *ProfileData);
68+
5869
/// Extract branch weights from MD_prof metadata
5970
///
6071
/// \param ProfileData A pointer to an MDNode.
@@ -111,7 +122,11 @@ bool extractProfTotalWeight(const Instruction &I, uint64_t &TotalWeights);
111122

112123
/// Create a new `branch_weights` metadata node and add or overwrite
113124
/// a `prof` metadata reference to instruction `I`.
114-
void setBranchWeights(Instruction &I, ArrayRef<uint32_t> Weights);
125+
/// \param I the Instruction to set branch weights on.
126+
/// \param Weights an array of weights to set on instruction I.
127+
/// \param IsExpected were these weights added from an llvm.expect* intrinsic.
128+
void setBranchWeights(Instruction &I, ArrayRef<uint32_t> Weights,
129+
bool IsExpected);
115130

116131
/// Scaling the profile data attached to 'I' using the ratio of S/T.
117132
void scaleProfData(Instruction &I, uint64_t S, uint64_t T);

llvm/lib/CodeGen/CodeGenPrepare.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8866,7 +8866,8 @@ bool CodeGenPrepare::splitBranchCondition(Function &F, ModifyDT &ModifiedDT) {
88668866
scaleWeights(NewTrueWeight, NewFalseWeight);
88678867
Br1->setMetadata(LLVMContext::MD_prof,
88688868
MDBuilder(Br1->getContext())
8869-
.createBranchWeights(TrueWeight, FalseWeight));
8869+
.createBranchWeights(TrueWeight, FalseWeight,
8870+
hasBranchWeightOrigin(*Br1)));
88708871

88718872
NewTrueWeight = TrueWeight;
88728873
NewFalseWeight = 2 * FalseWeight;

llvm/lib/IR/Instruction.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1268,12 +1268,23 @@ Instruction *Instruction::cloneImpl() const {
12681268

12691269
void Instruction::swapProfMetadata() {
12701270
MDNode *ProfileData = getBranchWeightMDNode(*this);
1271-
if (!ProfileData || ProfileData->getNumOperands() != 3)
1271+
if (!ProfileData)
1272+
return;
1273+
unsigned FirstIdx = getBranchWeightOffset(ProfileData);
1274+
if (ProfileData->getNumOperands() != 2 + FirstIdx)
12721275
return;
12731276

1274-
// The first operand is the name. Fetch them backwards and build a new one.
1275-
Metadata *Ops[] = {ProfileData->getOperand(0), ProfileData->getOperand(2),
1276-
ProfileData->getOperand(1)};
1277+
unsigned SecondIdx = FirstIdx + 1;
1278+
SmallVector<Metadata *, 4> Ops;
1279+
// If there are more weights past the second, we can't swap them
1280+
if (ProfileData->getNumOperands() > SecondIdx + 1)
1281+
return;
1282+
for (unsigned Idx = 0; Idx < FirstIdx; ++Idx) {
1283+
Ops.push_back(ProfileData->getOperand(Idx));
1284+
}
1285+
// Switch the order of the weights
1286+
Ops.push_back(ProfileData->getOperand(SecondIdx));
1287+
Ops.push_back(ProfileData->getOperand(FirstIdx));
12771288
setMetadata(LLVMContext::MD_prof,
12781289
MDNode::get(ProfileData->getContext(), Ops));
12791290
}

llvm/lib/IR/Instructions.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5199,7 +5199,11 @@ void SwitchInstProfUpdateWrapper::init() {
51995199
if (!ProfileData)
52005200
return;
52015201

5202-
if (ProfileData->getNumOperands() != SI.getNumSuccessors() + 1) {
5202+
// FIXME: This check belongs in ProfDataUtils. Its almost equivalent to
5203+
// getValidBranchWeightMDNode(), but the need to use llvm_unreachable
5204+
// makes them slightly different.
5205+
if (ProfileData->getNumOperands() !=
5206+
SI.getNumSuccessors() + getBranchWeightOffset(ProfileData)) {
52035207
llvm_unreachable("number of prof branch_weights metadata operands does "
52045208
"not correspond to number of succesors");
52055209
}

llvm/lib/IR/MDBuilder.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ MDNode *MDBuilder::createFPMath(float Accuracy) {
3535
}
3636

3737
MDNode *MDBuilder::createBranchWeights(uint32_t TrueWeight,
38-
uint32_t FalseWeight) {
39-
return createBranchWeights({TrueWeight, FalseWeight});
38+
uint32_t FalseWeight, bool IsExpected) {
39+
return createBranchWeights({TrueWeight, FalseWeight}, IsExpected);
4040
}
4141

4242
MDNode *MDBuilder::createLikelyBranchWeights() {
@@ -49,15 +49,19 @@ MDNode *MDBuilder::createUnlikelyBranchWeights() {
4949
return createBranchWeights(1, (1U << 20) - 1);
5050
}
5151

52-
MDNode *MDBuilder::createBranchWeights(ArrayRef<uint32_t> Weights) {
52+
MDNode *MDBuilder::createBranchWeights(ArrayRef<uint32_t> Weights,
53+
bool IsExpected) {
5354
assert(Weights.size() >= 1 && "Need at least one branch weights!");
5455

55-
SmallVector<Metadata *, 4> Vals(Weights.size() + 1);
56+
unsigned int Offset = IsExpected ? 2 : 1;
57+
SmallVector<Metadata *, 4> Vals(Weights.size() + Offset);
5658
Vals[0] = createString("branch_weights");
59+
if (IsExpected)
60+
Vals[1] = createString("expected");
5761

5862
Type *Int32Ty = Type::getInt32Ty(Context);
5963
for (unsigned i = 0, e = Weights.size(); i != e; ++i)
60-
Vals[i + 1] = createConstant(ConstantInt::get(Int32Ty, Weights[i]));
64+
Vals[i + Offset] = createConstant(ConstantInt::get(Int32Ty, Weights[i]));
6165

6266
return MDNode::get(Context, Vals);
6367
}

llvm/lib/IR/Metadata.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1196,10 +1196,10 @@ MDNode *MDNode::mergeDirectCallProfMetadata(MDNode *A, MDNode *B,
11961196
StringRef AProfName = AMDS->getString();
11971197
StringRef BProfName = BMDS->getString();
11981198
if (AProfName == "branch_weights" && BProfName == "branch_weights") {
1199-
ConstantInt *AInstrWeight =
1200-
mdconst::dyn_extract<ConstantInt>(A->getOperand(1));
1201-
ConstantInt *BInstrWeight =
1202-
mdconst::dyn_extract<ConstantInt>(B->getOperand(1));
1199+
ConstantInt *AInstrWeight = mdconst::dyn_extract<ConstantInt>(
1200+
A->getOperand(getBranchWeightOffset(A)));
1201+
ConstantInt *BInstrWeight = mdconst::dyn_extract<ConstantInt>(
1202+
B->getOperand(getBranchWeightOffset(B)));
12031203
assert(AInstrWeight && BInstrWeight && "verified by LLVM verifier");
12041204
return MDNode::get(Ctx,
12051205
{MDHelper.createString("branch_weights"),

llvm/lib/IR/ProfDataUtils.cpp

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,6 @@ namespace {
4040
// We maintain some constants here to ensure that we access the branch weights
4141
// correctly, and can change the behavior in the future if the layout changes
4242

43-
// The index at which the weights vector starts
44-
constexpr unsigned WeightsIdx = 1;
45-
4643
// the minimum number of operands for MD_prof nodes with branch weights
4744
constexpr unsigned MinBWOps = 3;
4845

@@ -75,15 +72,16 @@ static void extractFromBranchWeightMD(const MDNode *ProfileData,
7572
assert(isBranchWeightMD(ProfileData) && "wrong metadata");
7673

7774
unsigned NOps = ProfileData->getNumOperands();
75+
unsigned WeightsIdx = getBranchWeightOffset(ProfileData);
7876
assert(WeightsIdx < NOps && "Weights Index must be less than NOps.");
7977
Weights.resize(NOps - WeightsIdx);
8078

8179
for (unsigned Idx = WeightsIdx, E = NOps; Idx != E; ++Idx) {
8280
ConstantInt *Weight =
8381
mdconst::dyn_extract<ConstantInt>(ProfileData->getOperand(Idx));
8482
assert(Weight && "Malformed branch_weight in MD_prof node");
85-
assert(Weight->getValue().getActiveBits() <= 32 &&
86-
"Too many bits for uint32_t");
83+
assert(Weight->getValue().getActiveBits() <= (sizeof(T) * 8) &&
84+
"Too many bits for MD_prof branch_weight");
8785
Weights[Idx - WeightsIdx] = Weight->getZExtValue();
8886
}
8987
}
@@ -123,6 +121,26 @@ bool hasValidBranchWeightMD(const Instruction &I) {
123121
return getValidBranchWeightMDNode(I);
124122
}
125123

124+
bool hasBranchWeightOrigin(const Instruction &I) {
125+
auto *ProfileData = I.getMetadata(LLVMContext::MD_prof);
126+
return hasBranchWeightOrigin(ProfileData);
127+
}
128+
129+
bool hasBranchWeightOrigin(const MDNode *ProfileData) {
130+
if (!isBranchWeightMD(ProfileData))
131+
return false;
132+
auto *ProfDataName = dyn_cast<MDString>(ProfileData->getOperand(1));
133+
// NOTE: if we ever have more types of branch weight provenance,
134+
// we need to check the string value is "expected". For now, we
135+
// supply a more generic API, and avoid the spurious comparisons.
136+
assert(ProfDataName == nullptr || ProfDataName->getString() == "expected");
137+
return ProfDataName != nullptr;
138+
}
139+
140+
unsigned getBranchWeightOffset(const MDNode *ProfileData) {
141+
return hasBranchWeightOrigin(ProfileData) ? 2 : 1;
142+
}
143+
126144
MDNode *getBranchWeightMDNode(const Instruction &I) {
127145
auto *ProfileData = I.getMetadata(LLVMContext::MD_prof);
128146
if (!isBranchWeightMD(ProfileData))
@@ -132,7 +150,9 @@ MDNode *getBranchWeightMDNode(const Instruction &I) {
132150

133151
MDNode *getValidBranchWeightMDNode(const Instruction &I) {
134152
auto *ProfileData = getBranchWeightMDNode(I);
135-
if (ProfileData && ProfileData->getNumOperands() == 1 + I.getNumSuccessors())
153+
auto Offset = getBranchWeightOffset(ProfileData);
154+
if (ProfileData &&
155+
ProfileData->getNumOperands() == Offset + I.getNumSuccessors())
136156
return ProfileData;
137157
return nullptr;
138158
}
@@ -191,7 +211,8 @@ bool extractProfTotalWeight(const MDNode *ProfileData, uint64_t &TotalVal) {
191211
return false;
192212

193213
if (ProfDataName->getString() == "branch_weights") {
194-
for (unsigned Idx = 1; Idx < ProfileData->getNumOperands(); Idx++) {
214+
unsigned Offset = getBranchWeightOffset(ProfileData);
215+
for (unsigned Idx = Offset; Idx < ProfileData->getNumOperands(); ++Idx) {
195216
auto *V = mdconst::dyn_extract<ConstantInt>(ProfileData->getOperand(Idx));
196217
assert(V && "Malformed branch_weight in MD_prof node");
197218
TotalVal += V->getValue().getZExtValue();
@@ -212,9 +233,10 @@ bool extractProfTotalWeight(const Instruction &I, uint64_t &TotalVal) {
212233
return extractProfTotalWeight(I.getMetadata(LLVMContext::MD_prof), TotalVal);
213234
}
214235

215-
void setBranchWeights(Instruction &I, ArrayRef<uint32_t> Weights) {
236+
void setBranchWeights(Instruction &I, ArrayRef<uint32_t> Weights,
237+
bool IsExpected) {
216238
MDBuilder MDB(I.getContext());
217-
MDNode *BranchWeights = MDB.createBranchWeights(Weights);
239+
MDNode *BranchWeights = MDB.createBranchWeights(Weights, IsExpected);
218240
I.setMetadata(LLVMContext::MD_prof, BranchWeights);
219241
}
220242

llvm/lib/IR/Verifier.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@
104104
#include "llvm/IR/Module.h"
105105
#include "llvm/IR/ModuleSlotTracker.h"
106106
#include "llvm/IR/PassManager.h"
107+
#include "llvm/IR/ProfDataUtils.h"
107108
#include "llvm/IR/Statepoint.h"
108109
#include "llvm/IR/Type.h"
109110
#include "llvm/IR/Use.h"
@@ -4808,8 +4809,10 @@ void Verifier::visitProfMetadata(Instruction &I, MDNode *MD) {
48084809

48094810
// Check consistency of !prof branch_weights metadata.
48104811
if (ProfName == "branch_weights") {
4812+
unsigned int Offset = getBranchWeightOffset(MD);
48114813
if (isa<InvokeInst>(&I)) {
4812-
Check(MD->getNumOperands() == 2 || MD->getNumOperands() == 3,
4814+
Check(MD->getNumOperands() == (1 + Offset) ||
4815+
MD->getNumOperands() == (2 + Offset),
48134816
"Wrong number of InvokeInst branch_weights operands", MD);
48144817
} else {
48154818
unsigned ExpectedNumOperands = 0;
@@ -4829,10 +4832,10 @@ void Verifier::visitProfMetadata(Instruction &I, MDNode *MD) {
48294832
CheckFailed("!prof branch_weights are not allowed for this instruction",
48304833
MD);
48314834

4832-
Check(MD->getNumOperands() == 1 + ExpectedNumOperands,
4835+
Check(MD->getNumOperands() == Offset + ExpectedNumOperands,
48334836
"Wrong number of operands", MD);
48344837
}
4835-
for (unsigned i = 1; i < MD->getNumOperands(); ++i) {
4838+
for (unsigned i = Offset; i < MD->getNumOperands(); ++i) {
48364839
auto &MDO = MD->getOperand(i);
48374840
Check(MDO, "second operand should not be null", MD);
48384841
Check(mdconst::dyn_extract<ConstantInt>(MDO),

llvm/lib/Transforms/IPO/SampleProfile.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1662,7 +1662,8 @@ void SampleProfileLoader::generateMDProfMetadata(Function &F) {
16621662
else if (OverwriteExistingWeights)
16631663
I.setMetadata(LLVMContext::MD_prof, nullptr);
16641664
} else if (!isa<IntrinsicInst>(&I)) {
1665-
setBranchWeights(I, {static_cast<uint32_t>(BlockWeights[BB])});
1665+
setBranchWeights(I, {static_cast<uint32_t>(BlockWeights[BB])},
1666+
/*IsExpected=*/false);
16661667
}
16671668
}
16681669
} else if (OverwriteExistingWeights || ProfileSampleBlockAccurate) {
@@ -1673,7 +1674,7 @@ void SampleProfileLoader::generateMDProfMetadata(Function &F) {
16731674
if (cast<CallBase>(I).isIndirectCall()) {
16741675
I.setMetadata(LLVMContext::MD_prof, nullptr);
16751676
} else {
1676-
setBranchWeights(I, {uint32_t(0)});
1677+
setBranchWeights(I, {uint32_t(0)}, /*IsExpected=*/false);
16771678
}
16781679
}
16791680
}
@@ -1756,7 +1757,7 @@ void SampleProfileLoader::generateMDProfMetadata(Function &F) {
17561757
if (MaxWeight > 0 &&
17571758
(!TI->extractProfTotalWeight(TempWeight) || OverwriteExistingWeights)) {
17581759
LLVM_DEBUG(dbgs() << "SUCCESS. Found non-zero weights.\n");
1759-
setBranchWeights(*TI, Weights);
1760+
setBranchWeights(*TI, Weights, /*IsExpected=*/false);
17601761
ORE->emit([&]() {
17611762
return OptimizationRemark(DEBUG_TYPE, "PopularDest", MaxDestInst)
17621763
<< "most popular destination for conditional branches at "

llvm/lib/Transforms/Instrumentation/ControlHeightReduction.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1878,7 +1878,7 @@ void CHR::fixupBranchesAndSelects(CHRScope *Scope,
18781878
static_cast<uint32_t>(CHRBranchBias.scale(1000)),
18791879
static_cast<uint32_t>(CHRBranchBias.getCompl().scale(1000)),
18801880
};
1881-
setBranchWeights(*MergedBR, Weights);
1881+
setBranchWeights(*MergedBR, Weights, /*IsExpected=*/false);
18821882
CHR_DEBUG(dbgs() << "CHR branch bias " << Weights[0] << ":" << Weights[1]
18831883
<< "\n");
18841884
}

llvm/lib/Transforms/Instrumentation/IndirectCallPromotion.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,8 @@ CallBase &llvm::pgo::promoteIndirectCall(CallBase &CB, Function *DirectCallee,
259259
promoteCallWithIfThenElse(CB, DirectCallee, BranchWeights);
260260

261261
if (AttachProfToDirectCall) {
262-
setBranchWeights(NewInst, {static_cast<uint32_t>(Count)});
262+
setBranchWeights(NewInst, {static_cast<uint32_t>(Count)},
263+
/*IsExpected=*/false);
263264
}
264265

265266
using namespace ore;

llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1474,7 +1474,8 @@ void PGOUseFunc::populateCoverage(IndexedInstrProfReader *PGOReader) {
14741474
for (auto *Succ : successors(&BB))
14751475
Weights.push_back((Coverage[Succ] || !Coverage[&BB]) ? 1 : 0);
14761476
if (Weights.size() >= 2)
1477-
llvm::setBranchWeights(*BB.getTerminator(), Weights);
1477+
llvm::setBranchWeights(*BB.getTerminator(), Weights,
1478+
/*IsExpected=*/false);
14781479
}
14791480

14801481
unsigned NumCorruptCoverage = 0;
@@ -2260,7 +2261,7 @@ void llvm::setProfMetadata(Module *M, Instruction *TI,
22602261

22612262
misexpect::checkExpectAnnotations(*TI, Weights, /*IsFrontend=*/false);
22622263

2263-
setBranchWeights(*TI, Weights);
2264+
setBranchWeights(*TI, Weights, /*IsExpected=*/false);
22642265
if (EmitBranchProbability) {
22652266
std::string BrCondStr = getBranchCondString(TI);
22662267
if (BrCondStr.empty())

0 commit comments

Comments
 (0)