@@ -157,6 +157,8 @@ using EqClassKey =
157
157
struct ChainElem {
158
158
Instruction *Inst;
159
159
APInt OffsetFromLeader;
160
+ ChainElem (Instruction *Inst, APInt OffsetFromLeader)
161
+ : Inst(std::move(Inst)), OffsetFromLeader(std::move(OffsetFromLeader)) {}
160
162
};
161
163
using Chain = SmallVector<ChainElem, 1 >;
162
164
@@ -187,7 +189,7 @@ constexpr unsigned StackAdjustedAlignment = 4;
187
189
Instruction *propagateMetadata (Instruction *I, const Chain &C) {
188
190
SmallVector<Value *, 8 > Values;
189
191
for (const ChainElem &E : C)
190
- Values.push_back (E.Inst );
192
+ Values.emplace_back (E.Inst );
191
193
return propagateMetadata (I, Values);
192
194
}
193
195
@@ -202,12 +204,12 @@ void reorder(Instruction *I) {
202
204
SmallPtrSet<Instruction *, 16 > InstructionsToMove;
203
205
SmallVector<Instruction *, 16 > Worklist;
204
206
205
- Worklist.push_back (I);
207
+ Worklist.emplace_back (I);
206
208
while (!Worklist.empty ()) {
207
209
Instruction *IW = Worklist.pop_back_val ();
208
210
int NumOperands = IW->getNumOperands ();
209
- for (int i = 0 ; i < NumOperands; i ++) {
210
- Instruction *IM = dyn_cast<Instruction>(IW->getOperand (i ));
211
+ for (int Idx = 0 ; Idx < NumOperands; Idx ++) {
212
+ Instruction *IM = dyn_cast<Instruction>(IW->getOperand (Idx ));
211
213
if (!IM || IM->getOpcode () == Instruction::PHI)
212
214
continue ;
213
215
@@ -220,15 +222,15 @@ void reorder(Instruction *I) {
220
222
221
223
if (!IM->comesBefore (I)) {
222
224
InstructionsToMove.insert (IM);
223
- Worklist.push_back (IM);
225
+ Worklist.emplace_back (IM);
224
226
}
225
227
}
226
228
}
227
229
228
230
// All instructions to move should follow I. Start from I, not from begin().
229
231
for (auto BBI = I->getIterator (), E = I->getParent ()->end (); BBI != E;) {
230
232
Instruction *IM = &*(BBI++);
231
- if (!InstructionsToMove.count (IM))
233
+ if (!InstructionsToMove.contains (IM))
232
234
continue ;
233
235
IM->moveBefore (I);
234
236
}
@@ -438,11 +440,11 @@ bool Vectorizer::run() {
438
440
assert (!BB->empty ());
439
441
440
442
SmallVector<BasicBlock::iterator, 8 > Barriers;
441
- Barriers.push_back (BB->begin ());
443
+ Barriers.emplace_back (BB->begin ());
442
444
for (Instruction &I : *BB)
443
445
if (!isGuaranteedToTransferExecutionToSuccessor (&I))
444
- Barriers.push_back (I.getIterator ());
445
- Barriers.push_back (BB->end ());
446
+ Barriers.emplace_back (I.getIterator ());
447
+ Barriers.emplace_back (BB->end ());
446
448
447
449
for (auto It = Barriers.begin (), End = std::prev (Barriers.end ()); It != End;
448
450
++It)
@@ -559,14 +561,14 @@ std::vector<Chain> Vectorizer::splitChainByMayAliasInstrs(Chain &C) {
559
561
560
562
std::vector<Chain> Chains;
561
563
SmallVector<ChainElem, 1 > NewChain;
562
- NewChain.push_back (*ChainBegin);
564
+ NewChain.emplace_back (*ChainBegin);
563
565
for (auto ChainIt = std::next (ChainBegin); ChainIt != ChainEnd; ++ChainIt) {
564
566
if (isSafeToMove<IsLoad>(ChainIt->Inst , NewChain.front ().Inst ,
565
567
ChainOffsets)) {
566
568
LLVM_DEBUG (dbgs () << " LSV: No intervening may-alias instrs; can merge "
567
569
<< *ChainIt->Inst << " into " << *ChainBegin->Inst
568
570
<< " \n " );
569
- NewChain.push_back (*ChainIt);
571
+ NewChain.emplace_back (*ChainIt);
570
572
} else {
571
573
LLVM_DEBUG (
572
574
dbgs () << " LSV: Found intervening may-alias instrs; cannot merge "
@@ -576,7 +578,7 @@ std::vector<Chain> Vectorizer::splitChainByMayAliasInstrs(Chain &C) {
576
578
dbgs () << " LSV: got nontrivial chain without aliasing instrs:\n " ;
577
579
dumpChain (NewChain);
578
580
});
579
- Chains.push_back (std::move (NewChain));
581
+ Chains.emplace_back (std::move (NewChain));
580
582
}
581
583
582
584
// Start a new chain.
@@ -588,7 +590,7 @@ std::vector<Chain> Vectorizer::splitChainByMayAliasInstrs(Chain &C) {
588
590
dbgs () << " LSV: got nontrivial chain without aliasing instrs:\n " ;
589
591
dumpChain (NewChain);
590
592
});
591
- Chains.push_back (std::move (NewChain));
593
+ Chains.emplace_back (std::move (NewChain));
592
594
}
593
595
return Chains;
594
596
};
@@ -689,7 +691,7 @@ std::vector<Chain> Vectorizer::splitChainByAlignment(Chain &C) {
689
691
});
690
692
691
693
bool IsLoadChain = isa<LoadInst>(C[0 ].Inst );
692
- auto getVectorFactor = [&](unsigned VF, unsigned LoadStoreSize,
694
+ auto GetVectorFactor = [&](unsigned VF, unsigned LoadStoreSize,
693
695
unsigned ChainSizeBytes, VectorType *VecTy) {
694
696
return IsLoadChain ? TTI.getLoadVectorFactor (VF, LoadStoreSize,
695
697
ChainSizeBytes, VecTy)
@@ -721,8 +723,8 @@ std::vector<Chain> Vectorizer::splitChainByAlignment(Chain &C) {
721
723
C[CBegin].OffsetFromLeader ;
722
724
if (Sz.sgt (VecRegBytes))
723
725
break ;
724
- CandidateChains.push_back (
725
- {CEnd, static_cast <unsigned >(Sz.getLimitedValue ())} );
726
+ CandidateChains.emplace_back (CEnd,
727
+ static_cast <unsigned >(Sz.getLimitedValue ()));
726
728
}
727
729
728
730
// Consider the longest chain first.
@@ -746,7 +748,7 @@ std::vector<Chain> Vectorizer::splitChainByAlignment(Chain &C) {
746
748
unsigned VF = 8 * VecRegBytes / VecElemBits;
747
749
748
750
// Check that TTI is happy with this vectorization factor.
749
- unsigned TargetVF = getVectorFactor (VF, VecElemBits,
751
+ unsigned TargetVF = GetVectorFactor (VF, VecElemBits,
750
752
VecElemBits * NumVecElems / 8 , VecTy);
751
753
if (TargetVF != VF && TargetVF < NumVecElems) {
752
754
LLVM_DEBUG (
@@ -840,7 +842,7 @@ std::vector<Chain> Vectorizer::splitChainByAlignment(Chain &C) {
840
842
// Hooray, we can vectorize this chain!
841
843
Chain &NewChain = Ret.emplace_back ();
842
844
for (unsigned I = CBegin; I <= CEnd; ++I)
843
- NewChain.push_back (C[I]);
845
+ NewChain.emplace_back (C[I]);
844
846
CBegin = CEnd; // Skip over the instructions we've added to the chain.
845
847
break ;
846
848
}
@@ -959,7 +961,7 @@ bool Vectorizer::vectorizeChain(Chain &C) {
959
961
Vec = Builder.CreateInsertElement (Vec, V, Builder.getInt32 (VecIdx++));
960
962
};
961
963
for (const ChainElem &E : C) {
962
- auto I = cast<StoreInst>(E.Inst );
964
+ auto * I = cast<StoreInst>(E.Inst );
963
965
if (FixedVectorType *VT =
964
966
dyn_cast<FixedVectorType>(getLoadStoreType (I))) {
965
967
for (int J = 0 , JE = VT->getNumElements (); J < JE; ++J) {
@@ -982,7 +984,7 @@ bool Vectorizer::vectorizeChain(Chain &C) {
982
984
propagateMetadata (VecInst, C);
983
985
984
986
for (const ChainElem &E : C)
985
- ToErase.push_back (E.Inst );
987
+ ToErase.emplace_back (E.Inst );
986
988
987
989
++NumVectorInstructions;
988
990
NumScalarsVectorized += C.size ();
@@ -1291,7 +1293,7 @@ std::optional<APInt> Vectorizer::getConstantOffsetSelects(
1291
1293
<< *ContextInst << " , Depth=" << Depth << " \n " );
1292
1294
std::optional<APInt> TrueDiff = getConstantOffset (
1293
1295
SelectA->getTrueValue (), SelectB->getTrueValue (), ContextInst, Depth);
1294
- if (!TrueDiff. has_value () )
1296
+ if (!TrueDiff)
1295
1297
return std::nullopt;
1296
1298
std::optional<APInt> FalseDiff =
1297
1299
getConstantOffset (SelectA->getFalseValue (), SelectB->getFalseValue (),
@@ -1308,7 +1310,7 @@ Vectorizer::collectEquivalenceClasses(BasicBlock::iterator Begin,
1308
1310
BasicBlock::iterator End) {
1309
1311
EquivalenceClassMap Ret;
1310
1312
1311
- auto getUnderlyingObject = [](const Value *Ptr) -> const Value * {
1313
+ auto GetUnderlyingObject = [](const Value *Ptr) -> const Value * {
1312
1314
const Value *ObjPtr = llvm::getUnderlyingObject (Ptr);
1313
1315
if (const auto *Sel = dyn_cast<SelectInst>(ObjPtr)) {
1314
1316
// The select's themselves are distinct instructions even if they share
@@ -1369,10 +1371,10 @@ Vectorizer::collectEquivalenceClasses(BasicBlock::iterator Begin,
1369
1371
(VecTy && TTI.getLoadVectorFactor (VF, TySize, TySize / 8 , VecTy) == 0 ))
1370
1372
continue ;
1371
1373
1372
- Ret[{getUnderlyingObject (Ptr), AS,
1374
+ Ret[{GetUnderlyingObject (Ptr), AS,
1373
1375
DL.getTypeSizeInBits (getLoadStoreType (&I)->getScalarType ()),
1374
1376
/* IsLoad=*/ LI != nullptr }]
1375
- .push_back (&I);
1377
+ .emplace_back (&I);
1376
1378
}
1377
1379
1378
1380
return Ret;
@@ -1434,15 +1436,14 @@ std::vector<Chain> Vectorizer::gatherChains(ArrayRef<Instruction *> Instrs) {
1434
1436
auto ChainIter = MRU.begin ();
1435
1437
for (size_t J = 0 ; J < MaxChainsToTry && ChainIter != MRU.end ();
1436
1438
++J, ++ChainIter) {
1437
- std::optional<APInt> Offset = getConstantOffset (
1438
- getLoadStorePointerOperand (ChainIter->first ),
1439
- getLoadStorePointerOperand (I),
1440
- /* ContextInst=*/
1441
- (ChainIter->first ->comesBefore (I) ? I : ChainIter->first ));
1442
- if (Offset.has_value ()) {
1439
+ if (std::optional<APInt> Offset = getConstantOffset (
1440
+ getLoadStorePointerOperand (ChainIter->first ),
1441
+ getLoadStorePointerOperand (I),
1442
+ /* ContextInst=*/
1443
+ (ChainIter->first ->comesBefore (I) ? I : ChainIter->first ))) {
1443
1444
// `Offset` might not have the expected number of bits, if e.g. AS has a
1444
1445
// different number of bits than opaque pointers.
1445
- ChainIter->second .push_back (ChainElem{ I, Offset.value ()} );
1446
+ ChainIter->second .emplace_back ( I, Offset.value ());
1446
1447
// Move ChainIter to the front of the MRU list.
1447
1448
MRU.remove (*ChainIter);
1448
1449
MRU.push_front (*ChainIter);
@@ -1454,7 +1455,7 @@ std::vector<Chain> Vectorizer::gatherChains(ArrayRef<Instruction *> Instrs) {
1454
1455
if (!MatchFound) {
1455
1456
APInt ZeroOffset (ASPtrBits, 0 );
1456
1457
InstrListElem *E = new (Allocator.Allocate ()) InstrListElem (I);
1457
- E->second .push_back (ChainElem{ I, ZeroOffset} );
1458
+ E->second .emplace_back ( I, ZeroOffset);
1458
1459
MRU.push_front (*E);
1459
1460
Chains.insert (E);
1460
1461
}
@@ -1465,7 +1466,7 @@ std::vector<Chain> Vectorizer::gatherChains(ArrayRef<Instruction *> Instrs) {
1465
1466
// Iterate over MRU rather than Chains so the order is deterministic.
1466
1467
for (auto &E : MRU)
1467
1468
if (E.second .size () > 1 )
1468
- Ret.push_back (std::move (E.second ));
1469
+ Ret.emplace_back (std::move (E.second ));
1469
1470
return Ret;
1470
1471
}
1471
1472
@@ -1509,9 +1510,8 @@ std::optional<APInt> Vectorizer::getConstantOffset(Value *PtrA, Value *PtrB,
1509
1510
return (OffsetB - OffsetA + Dist).sextOrTrunc (OrigBitWidth);
1510
1511
}
1511
1512
}
1512
- std::optional<APInt> Diff =
1513
- getConstantOffsetComplexAddrs (PtrA, PtrB, ContextInst, Depth);
1514
- if (Diff.has_value ())
1513
+ if (std::optional<APInt> Diff =
1514
+ getConstantOffsetComplexAddrs (PtrA, PtrB, ContextInst, Depth))
1515
1515
return (OffsetB - OffsetA + Diff->sext (OffsetB.getBitWidth ()))
1516
1516
.sextOrTrunc (OrigBitWidth);
1517
1517
return std::nullopt;
0 commit comments