@@ -1182,7 +1182,7 @@ static void cloneInstructionsIntoPredecessorBlockAndUpdateSSAUses(
1182
1182
// only given the branch precondition.
1183
1183
// Similarly strip attributes on call parameters that may cause UB in
1184
1184
// location the call is moved to.
1185
- NewBonusInst->dropUBImplyingAttrsAndMetadata ();
1185
+ NewBonusInst->dropUBImplyingAttrsAndMetadata ({LLVMContext::MD_prof} );
1186
1186
1187
1187
NewBonusInst->insertInto (PredBlock, PTI->getIterator ());
1188
1188
auto Range = NewBonusInst->cloneDebugInfoFrom (&BonusInst);
@@ -1808,7 +1808,8 @@ static void hoistConditionalLoadsStores(
1808
1808
// !annotation: Not impact semantics. Keep it.
1809
1809
if (const MDNode *Ranges = I->getMetadata (LLVMContext::MD_range))
1810
1810
MaskedLoadStore->addRangeRetAttr (getConstantRangeFromMetadata (*Ranges));
1811
- I->dropUBImplyingAttrsAndUnknownMetadata ({LLVMContext::MD_annotation});
1811
+ I->dropUBImplyingAttrsAndUnknownMetadata (
1812
+ {LLVMContext::MD_annotation, LLVMContext::MD_prof});
1812
1813
// FIXME: DIAssignID is not supported for masked store yet.
1813
1814
// (Verifier::visitDIAssignIDMetadata)
1814
1815
at::deleteAssignmentMarkers (I);
@@ -3366,7 +3367,7 @@ bool SimplifyCFGOpt::speculativelyExecuteBB(BranchInst *BI,
3366
3367
if (!SpeculatedStoreValue || &I != SpeculatedStore) {
3367
3368
I.setDebugLoc (DebugLoc::getDropped ());
3368
3369
}
3369
- I.dropUBImplyingAttrsAndMetadata ();
3370
+ I.dropUBImplyingAttrsAndMetadata ({LLVMContext::MD_prof} );
3370
3371
3371
3372
// Drop ephemeral values.
3372
3373
if (EphTracker.contains (&I)) {
@@ -4404,10 +4405,12 @@ static bool mergeConditionalStoreToAddress(
4404
4405
4405
4406
// OK, we're going to sink the stores to PostBB. The store has to be
4406
4407
// conditional though, so first create the predicate.
4407
- Value *PCond = cast<BranchInst>(PFB->getSinglePredecessor ()->getTerminator ())
4408
- ->getCondition ();
4409
- Value *QCond = cast<BranchInst>(QFB->getSinglePredecessor ()->getTerminator ())
4410
- ->getCondition ();
4408
+ BranchInst *const PBranch =
4409
+ cast<BranchInst>(PFB->getSinglePredecessor ()->getTerminator ());
4410
+ BranchInst *const QBranch =
4411
+ cast<BranchInst>(QFB->getSinglePredecessor ()->getTerminator ());
4412
+ Value *const PCond = PBranch->getCondition ();
4413
+ Value *const QCond = QBranch->getCondition ();
4411
4414
4412
4415
Value *PPHI = ensureValueAvailableInSuccessor (PStore->getValueOperand (),
4413
4416
PStore->getParent ());
@@ -4418,19 +4421,29 @@ static bool mergeConditionalStoreToAddress(
4418
4421
IRBuilder<> QB (PostBB, PostBBFirst);
4419
4422
QB.SetCurrentDebugLocation (PostBBFirst->getStableDebugLoc ());
4420
4423
4421
- Value *PPred = PStore->getParent () == PTB ? PCond : QB.CreateNot (PCond);
4422
- Value *QPred = QStore->getParent () == QTB ? QCond : QB.CreateNot (QCond);
4424
+ InvertPCond = (PStore->getParent () == PTB) ^ InvertPCond;
4425
+ InvertQCond = (QStore->getParent () == QTB) ^ InvertQCond;
4426
+ Value *const PPred = InvertPCond ? PCond : QB.CreateNot (PCond);
4427
+ Value *const QPred = InvertQCond ? QCond : QB.CreateNot (QCond);
4423
4428
4424
- if (InvertPCond)
4425
- PPred = QB.CreateNot (PPred);
4426
- if (InvertQCond)
4427
- QPred = QB.CreateNot (QPred);
4428
4429
Value *CombinedPred = QB.CreateOr (PPred, QPred);
4429
4430
4430
4431
BasicBlock::iterator InsertPt = QB.GetInsertPoint ();
4431
4432
auto *T = SplitBlockAndInsertIfThen (CombinedPred, InsertPt,
4432
4433
/* Unreachable=*/ false ,
4433
4434
/* BranchWeights=*/ nullptr , DTU);
4435
+ if (hasBranchWeightMD (*PBranch) && hasBranchWeightMD (*QBranch)) {
4436
+ SmallVector<uint32_t , 2 > PWeights, QWeights;
4437
+ extractBranchWeights (*PBranch, PWeights);
4438
+ extractBranchWeights (*QBranch, QWeights);
4439
+ if (InvertPCond)
4440
+ std::swap (PWeights[0 ], PWeights[1 ]);
4441
+ if (InvertQCond)
4442
+ std::swap (QWeights[0 ], QWeights[1 ]);
4443
+ auto CombinedWeights = getDisjunctionWeights (PWeights, QWeights);
4444
+ setBranchWeights (T, CombinedWeights[0 ], CombinedWeights[1 ],
4445
+ /* IsExpected=*/ false );
4446
+ }
4434
4447
4435
4448
QB.SetInsertPoint (T);
4436
4449
StoreInst *SI = cast<StoreInst>(QB.CreateStore (QPHI, Address));
0 commit comments