@@ -1848,7 +1848,7 @@ class BoUpSLP {
1848
1848
InstructionsState S = getSameOpcode(Ops, TLI);
1849
1849
// Note: Only consider instructions with <= 2 operands to avoid
1850
1850
// complexity explosion.
1851
- if (S.getMainOp () &&
1851
+ if (S.valid () &&
1852
1852
(S.getMainOp()->getNumOperands() <= 2 || !MainAltOps.empty() ||
1853
1853
!S.isAltShuffle()) &&
1854
1854
all_of(Ops, [&S](Value *V) {
@@ -2699,7 +2699,7 @@ class BoUpSLP {
2699
2699
OperandData &AltOp = getData(OpIdx, Lane);
2700
2700
InstructionsState OpS =
2701
2701
getSameOpcode({MainAltOps[OpIdx].front(), AltOp.V}, TLI);
2702
- if (OpS.getMainOp () && OpS.isAltShuffle())
2702
+ if (OpS.valid () && OpS.isAltShuffle())
2703
2703
MainAltOps[OpIdx].push_back(AltOp.V);
2704
2704
}
2705
2705
}
@@ -3594,9 +3594,9 @@ class BoUpSLP {
3594
3594
"Need to vectorize gather entry?");
3595
3595
// Gathered loads still gathered? Do not create entry, use the original one.
3596
3596
if (GatheredLoadsEntriesFirst.has_value() &&
3597
- EntryState == TreeEntry::NeedToGather &&
3598
- isa_and_present<LoadInst>(S.getMainOp()) &&
3599
- UserTreeIdx.EdgeIdx == UINT_MAX && !UserTreeIdx.UserTE)
3597
+ EntryState == TreeEntry::NeedToGather && S.valid() &&
3598
+ S.getOpcode() == Instruction::Load && UserTreeIdx.EdgeIdx == UINT_MAX &&
3599
+ !UserTreeIdx.UserTE)
3600
3600
return nullptr;
3601
3601
VectorizableTree.push_back(std::make_unique<TreeEntry>(VectorizableTree));
3602
3602
TreeEntry *Last = VectorizableTree.back().get();
@@ -8062,15 +8062,15 @@ void BoUpSLP::buildTree_rec(ArrayRef<Value *> VL, unsigned Depth,
8062
8062
// Don't go into catchswitch blocks, which can happen with PHIs.
8063
8063
// Such blocks can only have PHIs and the catchswitch. There is no
8064
8064
// place to insert a shuffle if we need to, so just avoid that issue.
8065
- if (S.getMainOp () &&
8065
+ if (S.valid () &&
8066
8066
isa<CatchSwitchInst>(S.getMainOp()->getParent()->getTerminator())) {
8067
8067
LLVM_DEBUG(dbgs() << "SLP: bundle in catchswitch block.\n");
8068
8068
newTreeEntry(VL, std::nullopt /*not vectorized*/, S, UserTreeIdx);
8069
8069
return;
8070
8070
}
8071
8071
8072
8072
// Check if this is a duplicate of another entry.
8073
- if (S.getMainOp ()) {
8073
+ if (S.valid ()) {
8074
8074
if (TreeEntry *E = getTreeEntry(S.getMainOp())) {
8075
8075
LLVM_DEBUG(dbgs() << "SLP: \tChecking bundle: " << *S.getMainOp()
8076
8076
<< ".\n");
@@ -8131,7 +8131,7 @@ void BoUpSLP::buildTree_rec(ArrayRef<Value *> VL, unsigned Depth,
8131
8131
// a load), in which case peek through to include it in the tree, without
8132
8132
// ballooning over-budget.
8133
8133
if (Depth >= RecursionMaxDepth &&
8134
- !(S.getMainOp () && !S.isAltShuffle() && VL.size() >= 4 &&
8134
+ !(S.valid () && !S.isAltShuffle() && VL.size() >= 4 &&
8135
8135
(match(S.getMainOp(), m_Load(m_Value())) ||
8136
8136
all_of(VL, [&S](const Value *I) {
8137
8137
return match(I,
@@ -8169,7 +8169,7 @@ void BoUpSLP::buildTree_rec(ArrayRef<Value *> VL, unsigned Depth,
8169
8169
// vectorize.
8170
8170
auto &&NotProfitableForVectorization = [&S, this,
8171
8171
Depth](ArrayRef<Value *> VL) {
8172
- if (!S.getMainOp () || !S.isAltShuffle() || VL.size() > 2)
8172
+ if (!S.valid () || !S.isAltShuffle() || VL.size() > 2)
8173
8173
return false;
8174
8174
if (VectorizableTree.size() < MinTreeSize)
8175
8175
return false;
@@ -8224,7 +8224,7 @@ void BoUpSLP::buildTree_rec(ArrayRef<Value *> VL, unsigned Depth,
8224
8224
bool IsScatterVectorizeUserTE =
8225
8225
UserTreeIdx.UserTE &&
8226
8226
UserTreeIdx.UserTE->State == TreeEntry::ScatterVectorize;
8227
- bool AreAllSameBlock = S.getMainOp () && allSameBlock(VL);
8227
+ bool AreAllSameBlock = S.valid () && allSameBlock(VL);
8228
8228
bool AreScatterAllGEPSameBlock =
8229
8229
(IsScatterVectorizeUserTE && VL.front()->getType()->isPointerTy() &&
8230
8230
VL.size() > 2 &&
@@ -8241,7 +8241,7 @@ void BoUpSLP::buildTree_rec(ArrayRef<Value *> VL, unsigned Depth,
8241
8241
sortPtrAccesses(VL, UserTreeIdx.UserTE->getMainOp()->getType(), *DL, *SE,
8242
8242
SortedIndices));
8243
8243
bool AreAllSameInsts = AreAllSameBlock || AreScatterAllGEPSameBlock;
8244
- if (!AreAllSameInsts || (!S.getMainOp () && allConstant(VL)) || isSplat(VL) ||
8244
+ if (!AreAllSameInsts || (!S.valid () && allConstant(VL)) || isSplat(VL) ||
8245
8245
(isa_and_present<InsertElementInst, ExtractValueInst, ExtractElementInst>(
8246
8246
S.getMainOp()) &&
8247
8247
!all_of(VL, isVectorLikeInstWithConstOps)) ||
@@ -8254,7 +8254,7 @@ void BoUpSLP::buildTree_rec(ArrayRef<Value *> VL, unsigned Depth,
8254
8254
}
8255
8255
8256
8256
// Don't vectorize ephemeral values.
8257
- if (S.getMainOp () && !EphValues.empty()) {
8257
+ if (S.valid () && !EphValues.empty()) {
8258
8258
for (Value *V : VL) {
8259
8259
if (EphValues.count(V)) {
8260
8260
LLVM_DEBUG(dbgs() << "SLP: The instruction (" << *V
@@ -8313,7 +8313,7 @@ void BoUpSLP::buildTree_rec(ArrayRef<Value *> VL, unsigned Depth,
8313
8313
Instruction *VL0 = S.getMainOp();
8314
8314
BB = VL0->getParent();
8315
8315
8316
- if (S.getMainOp () &&
8316
+ if (S.valid () &&
8317
8317
(BB->isEHPad() || isa_and_nonnull<UnreachableInst>(BB->getTerminator()) ||
8318
8318
!DT->isReachableFromEntry(BB))) {
8319
8319
// Don't go into unreachable blocks. They may contain instructions with
@@ -8360,7 +8360,7 @@ void BoUpSLP::buildTree_rec(ArrayRef<Value *> VL, unsigned Depth,
8360
8360
newTreeEntry(VL, std::nullopt /*not vectorized*/, S, UserTreeIdx,
8361
8361
ReuseShuffleIndices);
8362
8362
NonScheduledFirst.insert(VL.front());
8363
- if (isa<LoadInst>(S.getMainOp()) &&
8363
+ if (S.getOpcode() == Instruction::Load &&
8364
8364
BS.ScheduleRegionSize < BS.ScheduleRegionSizeLimit)
8365
8365
registerNonVectorizableLoads(VL);
8366
8366
return;
@@ -8377,7 +8377,7 @@ void BoUpSLP::buildTree_rec(ArrayRef<Value *> VL, unsigned Depth,
8377
8377
if (Op.empty())
8378
8378
continue;
8379
8379
InstructionsState S = getSameOpcode(Op, *TLI);
8380
- if (!isa_and_present<PHINode>(S.getMainOp() ) || S.isAltShuffle())
8380
+ if ((!S.valid() || S.getOpcode() != Instruction::PHI ) || S.isAltShuffle())
8381
8381
buildTree_rec(Op, Depth + 1, {TE, I});
8382
8382
else
8383
8383
PHIOps.push_back(I);
@@ -9731,10 +9731,10 @@ void BoUpSLP::transformNodes() {
9731
9731
if (IsSplat)
9732
9732
continue;
9733
9733
InstructionsState S = getSameOpcode(Slice, *TLI);
9734
- if (!S.getMainOp () || S.isAltShuffle() || !allSameBlock(Slice) ||
9735
- (isa<LoadInst>(S.getMainOp()) &&
9734
+ if (!S.valid () || S.isAltShuffle() || !allSameBlock(Slice) ||
9735
+ (S.getOpcode() == Instruction::Load &&
9736
9736
areKnownNonVectorizableLoads(Slice)) ||
9737
- (!isa<LoadInst>(S.getMainOp()) && !has_single_bit(VF)))
9737
+ (S.getOpcode() != Instruction::Load && !has_single_bit(VF)))
9738
9738
continue;
9739
9739
if (VF == 2) {
9740
9740
// Try to vectorize reduced values or if all users are vectorized.
@@ -9749,7 +9749,7 @@ void BoUpSLP::transformNodes() {
9749
9749
UserIgnoreList);
9750
9750
}))
9751
9751
continue;
9752
- if (isa<LoadInst>(S.getMainOp()) ) {
9752
+ if (S.getOpcode() == Instruction::Load ) {
9753
9753
OrdersType Order;
9754
9754
SmallVector<Value *> PointerOps;
9755
9755
LoadsState Res =
@@ -9766,7 +9766,7 @@ void BoUpSLP::transformNodes() {
9766
9766
}
9767
9767
continue;
9768
9768
}
9769
- } else if (isa<ExtractElementInst>(S.getMainOp()) ||
9769
+ } else if (S.getOpcode() == Instruction::ExtractElement ||
9770
9770
(TTI->getInstructionCost(S.getMainOp(), CostKind) <
9771
9771
TTI::TCC_Expensive &&
9772
9772
!CheckOperandsProfitability(
@@ -11048,7 +11048,7 @@ BoUpSLP::getEntryCost(const TreeEntry *E, ArrayRef<Value *> VectorizedVals,
11048
11048
if (const TreeEntry *OpTE = getTreeEntry(V))
11049
11049
return getCastContextHint(*OpTE);
11050
11050
InstructionsState SrcState = getSameOpcode(E->getOperand(0), *TLI);
11051
- if (isa_and_present<LoadInst>( SrcState.getMainOp()) &&
11051
+ if (SrcState.valid() && SrcState.getOpcode() == Instruction::Load &&
11052
11052
!SrcState.isAltShuffle())
11053
11053
return TTI::CastContextHint::GatherScatter;
11054
11054
return TTI::CastContextHint::None;
@@ -14396,12 +14396,12 @@ BoUpSLP::TreeEntry *BoUpSLP::getMatchedVectorizedOperand(const TreeEntry *E,
14396
14396
ArrayRef<Value *> VL = E->getOperand(NodeIdx);
14397
14397
InstructionsState S = getSameOpcode(VL, *TLI);
14398
14398
// Special processing for GEPs bundle, which may include non-gep values.
14399
- if (!S.getMainOp () && VL.front()->getType()->isPointerTy()) {
14399
+ if (!S.valid () && VL.front()->getType()->isPointerTy()) {
14400
14400
const auto *It = find_if(VL, IsaPred<GetElementPtrInst>);
14401
14401
if (It != VL.end())
14402
14402
S = getSameOpcode(*It, *TLI);
14403
14403
}
14404
- if (!S.getMainOp ())
14404
+ if (!S.valid ())
14405
14405
return nullptr;
14406
14406
auto CheckSameVE = [&](const TreeEntry *VE) {
14407
14407
return VE->isSame(VL) &&
@@ -15061,7 +15061,7 @@ Value *BoUpSLP::vectorizeTree(TreeEntry *E, bool PostponedPHIs) {
15061
15061
auto *VecTy = getWidenedType(ScalarTy, E->Scalars.size());
15062
15062
if (E->isGather()) {
15063
15063
// Set insert point for non-reduction initial nodes.
15064
- if (E->getMainOp() && E->Idx == 0 && !UserIgnoreList)
15064
+ if (E->getMainOp() != nullptr && E->Idx == 0 && !UserIgnoreList)
15065
15065
setInsertPointAfterBundle(E);
15066
15066
Value *Vec = createBuildVector(E, ScalarTy, PostponedPHIs);
15067
15067
E->VectorizedValue = Vec;
@@ -18378,7 +18378,7 @@ SLPVectorizerPass::vectorizeStoreChain(ArrayRef<Value *> Chain, BoUpSLP &R,
18378
18378
hasFullVectorsOrPowerOf2(*TTI, ValOps.front()->getType(),
18379
18379
ValOps.size()) ||
18380
18380
(VectorizeNonPowerOf2 && has_single_bit(ValOps.size() + 1));
18381
- if ((!IsAllowedSize && S.getMainOp () && !isa<LoadInst>(S.getMainOp()) &&
18381
+ if ((!IsAllowedSize && S.valid () && S.getOpcode() != Instruction::Load &&
18382
18382
(!S.getMainOp()->isSafeToRemove() ||
18383
18383
any_of(ValOps.getArrayRef(),
18384
18384
[&](Value *V) {
@@ -18388,8 +18388,8 @@ SLPVectorizerPass::vectorizeStoreChain(ArrayRef<Value *> Chain, BoUpSLP &R,
18388
18388
return !Stores.contains(U);
18389
18389
}));
18390
18390
}))) ||
18391
- (ValOps.size() > Chain.size() / 2 && !S.getMainOp ())) {
18392
- Size = (!IsAllowedSize && S.getMainOp ()) ? 1 : 2;
18391
+ (ValOps.size() > Chain.size() / 2 && !S.valid ())) {
18392
+ Size = (!IsAllowedSize && S.valid ()) ? 1 : 2;
18393
18393
return false;
18394
18394
}
18395
18395
}
@@ -18412,7 +18412,7 @@ SLPVectorizerPass::vectorizeStoreChain(ArrayRef<Value *> Chain, BoUpSLP &R,
18412
18412
R.computeMinimumValueSizes();
18413
18413
18414
18414
Size = R.getCanonicalGraphSize();
18415
- if (isa_and_present<LoadInst>(S.getMainOp()) )
18415
+ if (S.valid() && S.getOpcode() == Instruction::Load )
18416
18416
Size = 2; // cut off masked gather small trees
18417
18417
InstructionCost Cost = R.getTreeCost();
18418
18418
@@ -18913,7 +18913,7 @@ bool SLPVectorizerPass::tryToVectorizeList(ArrayRef<Value *> VL, BoUpSLP &R,
18913
18913
// Check that all of the parts are instructions of the same type,
18914
18914
// we permit an alternate opcode via InstructionsState.
18915
18915
InstructionsState S = getSameOpcode(VL, *TLI);
18916
- if (!S.getMainOp ())
18916
+ if (!S.valid ())
18917
18917
return false;
18918
18918
18919
18919
Instruction *I0 = S.getMainOp();
@@ -19725,15 +19725,15 @@ class HorizontalReduction {
19725
19725
// Also check if the instruction was folded to constant/other value.
19726
19726
auto *Inst = dyn_cast<Instruction>(RdxVal);
19727
19727
if ((Inst && isVectorLikeInstWithConstOps(Inst) &&
19728
- (!S.getMainOp () || !S.isOpcodeOrAlt(Inst))) ||
19729
- (S.getMainOp () && !Inst))
19728
+ (!S.valid () || !S.isOpcodeOrAlt(Inst))) ||
19729
+ (S.valid () && !Inst))
19730
19730
continue;
19731
19731
Candidates.push_back(RdxVal);
19732
19732
TrackedToOrig.try_emplace(RdxVal, OrigReducedVals[Cnt]);
19733
19733
}
19734
19734
bool ShuffledExtracts = false;
19735
19735
// Try to handle shuffled extractelements.
19736
- if (isa_and_present<ExtractElementInst>(S.getMainOp()) &&
19736
+ if (S.valid() && S.getOpcode() == Instruction::ExtractElement &&
19737
19737
!S.isAltShuffle() && I + 1 < E) {
19738
19738
SmallVector<Value *> CommonCandidates(Candidates);
19739
19739
for (Value *RV : ReducedVals[I + 1]) {
@@ -21129,7 +21129,7 @@ static bool compareCmp(Value *V, Value *V2, TargetLibraryInfo &TLI,
21129
21129
return NodeI1->getDFSNumIn() < NodeI2->getDFSNumIn();
21130
21130
}
21131
21131
InstructionsState S = getSameOpcode({I1, I2}, TLI);
21132
- if (S.getMainOp () && (IsCompatibility || !S.isAltShuffle()))
21132
+ if (S.valid () && (IsCompatibility || !S.isAltShuffle()))
21133
21133
continue;
21134
21134
if (IsCompatibility)
21135
21135
return false;
@@ -21284,7 +21284,7 @@ bool SLPVectorizerPass::vectorizeChainsInBlock(BasicBlock *BB, BoUpSLP &R) {
21284
21284
if (NodeI1 != NodeI2)
21285
21285
return NodeI1->getDFSNumIn() < NodeI2->getDFSNumIn();
21286
21286
InstructionsState S = getSameOpcode({I1, I2}, *TLI);
21287
- if (S.getMainOp () && !S.isAltShuffle())
21287
+ if (S.valid () && !S.isAltShuffle())
21288
21288
continue;
21289
21289
return I1->getOpcode() < I2->getOpcode();
21290
21290
}
0 commit comments