@@ -1848,7 +1848,7 @@ class BoUpSLP {
18481848 InstructionsState S = getSameOpcode(Ops, TLI);
18491849 // Note: Only consider instructions with <= 2 operands to avoid
18501850 // complexity explosion.
1851- if (S.getMainOp () &&
1851+ if (S.valid () &&
18521852 (S.getMainOp()->getNumOperands() <= 2 || !MainAltOps.empty() ||
18531853 !S.isAltShuffle()) &&
18541854 all_of(Ops, [&S](Value *V) {
@@ -2699,7 +2699,7 @@ class BoUpSLP {
26992699 OperandData &AltOp = getData(OpIdx, Lane);
27002700 InstructionsState OpS =
27012701 getSameOpcode({MainAltOps[OpIdx].front(), AltOp.V}, TLI);
2702- if (OpS.getMainOp () && OpS.isAltShuffle())
2702+ if (OpS.valid () && OpS.isAltShuffle())
27032703 MainAltOps[OpIdx].push_back(AltOp.V);
27042704 }
27052705 }
@@ -3594,9 +3594,9 @@ class BoUpSLP {
35943594 "Need to vectorize gather entry?");
35953595 // Gathered loads still gathered? Do not create entry, use the original one.
35963596 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)
36003600 return nullptr;
36013601 VectorizableTree.push_back(std::make_unique<TreeEntry>(VectorizableTree));
36023602 TreeEntry *Last = VectorizableTree.back().get();
@@ -8062,15 +8062,15 @@ void BoUpSLP::buildTree_rec(ArrayRef<Value *> VL, unsigned Depth,
80628062 // Don't go into catchswitch blocks, which can happen with PHIs.
80638063 // Such blocks can only have PHIs and the catchswitch. There is no
80648064 // place to insert a shuffle if we need to, so just avoid that issue.
8065- if (S.getMainOp () &&
8065+ if (S.valid () &&
80668066 isa<CatchSwitchInst>(S.getMainOp()->getParent()->getTerminator())) {
80678067 LLVM_DEBUG(dbgs() << "SLP: bundle in catchswitch block.\n");
80688068 newTreeEntry(VL, std::nullopt /*not vectorized*/, S, UserTreeIdx);
80698069 return;
80708070 }
80718071
80728072 // Check if this is a duplicate of another entry.
8073- if (S.getMainOp ()) {
8073+ if (S.valid ()) {
80748074 if (TreeEntry *E = getTreeEntry(S.getMainOp())) {
80758075 LLVM_DEBUG(dbgs() << "SLP: \tChecking bundle: " << *S.getMainOp()
80768076 << ".\n");
@@ -8131,7 +8131,7 @@ void BoUpSLP::buildTree_rec(ArrayRef<Value *> VL, unsigned Depth,
81318131 // a load), in which case peek through to include it in the tree, without
81328132 // ballooning over-budget.
81338133 if (Depth >= RecursionMaxDepth &&
8134- !(S.getMainOp () && !S.isAltShuffle() && VL.size() >= 4 &&
8134+ !(S.valid () && !S.isAltShuffle() && VL.size() >= 4 &&
81358135 (match(S.getMainOp(), m_Load(m_Value())) ||
81368136 all_of(VL, [&S](const Value *I) {
81378137 return match(I,
@@ -8169,7 +8169,7 @@ void BoUpSLP::buildTree_rec(ArrayRef<Value *> VL, unsigned Depth,
81698169 // vectorize.
81708170 auto &&NotProfitableForVectorization = [&S, this,
81718171 Depth](ArrayRef<Value *> VL) {
8172- if (!S.getMainOp () || !S.isAltShuffle() || VL.size() > 2)
8172+ if (!S.valid () || !S.isAltShuffle() || VL.size() > 2)
81738173 return false;
81748174 if (VectorizableTree.size() < MinTreeSize)
81758175 return false;
@@ -8224,7 +8224,7 @@ void BoUpSLP::buildTree_rec(ArrayRef<Value *> VL, unsigned Depth,
82248224 bool IsScatterVectorizeUserTE =
82258225 UserTreeIdx.UserTE &&
82268226 UserTreeIdx.UserTE->State == TreeEntry::ScatterVectorize;
8227- bool AreAllSameBlock = S.getMainOp () && allSameBlock(VL);
8227+ bool AreAllSameBlock = S.valid () && allSameBlock(VL);
82288228 bool AreScatterAllGEPSameBlock =
82298229 (IsScatterVectorizeUserTE && VL.front()->getType()->isPointerTy() &&
82308230 VL.size() > 2 &&
@@ -8241,7 +8241,7 @@ void BoUpSLP::buildTree_rec(ArrayRef<Value *> VL, unsigned Depth,
82418241 sortPtrAccesses(VL, UserTreeIdx.UserTE->getMainOp()->getType(), *DL, *SE,
82428242 SortedIndices));
82438243 bool AreAllSameInsts = AreAllSameBlock || AreScatterAllGEPSameBlock;
8244- if (!AreAllSameInsts || (!S.getMainOp () && allConstant(VL)) || isSplat(VL) ||
8244+ if (!AreAllSameInsts || (!S.valid () && allConstant(VL)) || isSplat(VL) ||
82458245 (isa_and_present<InsertElementInst, ExtractValueInst, ExtractElementInst>(
82468246 S.getMainOp()) &&
82478247 !all_of(VL, isVectorLikeInstWithConstOps)) ||
@@ -8254,7 +8254,7 @@ void BoUpSLP::buildTree_rec(ArrayRef<Value *> VL, unsigned Depth,
82548254 }
82558255
82568256 // Don't vectorize ephemeral values.
8257- if (S.getMainOp () && !EphValues.empty()) {
8257+ if (S.valid () && !EphValues.empty()) {
82588258 for (Value *V : VL) {
82598259 if (EphValues.count(V)) {
82608260 LLVM_DEBUG(dbgs() << "SLP: The instruction (" << *V
@@ -8313,7 +8313,7 @@ void BoUpSLP::buildTree_rec(ArrayRef<Value *> VL, unsigned Depth,
83138313 Instruction *VL0 = S.getMainOp();
83148314 BB = VL0->getParent();
83158315
8316- if (S.getMainOp () &&
8316+ if (S.valid () &&
83178317 (BB->isEHPad() || isa_and_nonnull<UnreachableInst>(BB->getTerminator()) ||
83188318 !DT->isReachableFromEntry(BB))) {
83198319 // Don't go into unreachable blocks. They may contain instructions with
@@ -8360,7 +8360,7 @@ void BoUpSLP::buildTree_rec(ArrayRef<Value *> VL, unsigned Depth,
83608360 newTreeEntry(VL, std::nullopt /*not vectorized*/, S, UserTreeIdx,
83618361 ReuseShuffleIndices);
83628362 NonScheduledFirst.insert(VL.front());
8363- if (isa<LoadInst>(S.getMainOp()) &&
8363+ if (S.getOpcode() == Instruction::Load &&
83648364 BS.ScheduleRegionSize < BS.ScheduleRegionSizeLimit)
83658365 registerNonVectorizableLoads(VL);
83668366 return;
@@ -8377,7 +8377,7 @@ void BoUpSLP::buildTree_rec(ArrayRef<Value *> VL, unsigned Depth,
83778377 if (Op.empty())
83788378 continue;
83798379 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())
83818381 buildTree_rec(Op, Depth + 1, {TE, I});
83828382 else
83838383 PHIOps.push_back(I);
@@ -9731,10 +9731,10 @@ void BoUpSLP::transformNodes() {
97319731 if (IsSplat)
97329732 continue;
97339733 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 &&
97369736 areKnownNonVectorizableLoads(Slice)) ||
9737- (!isa<LoadInst>(S.getMainOp()) && !has_single_bit(VF)))
9737+ (S.getOpcode() != Instruction::Load && !has_single_bit(VF)))
97389738 continue;
97399739 if (VF == 2) {
97409740 // Try to vectorize reduced values or if all users are vectorized.
@@ -9749,7 +9749,7 @@ void BoUpSLP::transformNodes() {
97499749 UserIgnoreList);
97509750 }))
97519751 continue;
9752- if (isa<LoadInst>(S.getMainOp()) ) {
9752+ if (S.getOpcode() == Instruction::Load ) {
97539753 OrdersType Order;
97549754 SmallVector<Value *> PointerOps;
97559755 LoadsState Res =
@@ -9766,7 +9766,7 @@ void BoUpSLP::transformNodes() {
97669766 }
97679767 continue;
97689768 }
9769- } else if (isa<ExtractElementInst>(S.getMainOp()) ||
9769+ } else if (S.getOpcode() == Instruction::ExtractElement ||
97709770 (TTI->getInstructionCost(S.getMainOp(), CostKind) <
97719771 TTI::TCC_Expensive &&
97729772 !CheckOperandsProfitability(
@@ -11048,7 +11048,7 @@ BoUpSLP::getEntryCost(const TreeEntry *E, ArrayRef<Value *> VectorizedVals,
1104811048 if (const TreeEntry *OpTE = getTreeEntry(V))
1104911049 return getCastContextHint(*OpTE);
1105011050 InstructionsState SrcState = getSameOpcode(E->getOperand(0), *TLI);
11051- if (isa_and_present<LoadInst>( SrcState.getMainOp()) &&
11051+ if (SrcState.valid() && SrcState.getOpcode() == Instruction::Load &&
1105211052 !SrcState.isAltShuffle())
1105311053 return TTI::CastContextHint::GatherScatter;
1105411054 return TTI::CastContextHint::None;
@@ -14396,12 +14396,12 @@ BoUpSLP::TreeEntry *BoUpSLP::getMatchedVectorizedOperand(const TreeEntry *E,
1439614396 ArrayRef<Value *> VL = E->getOperand(NodeIdx);
1439714397 InstructionsState S = getSameOpcode(VL, *TLI);
1439814398 // 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()) {
1440014400 const auto *It = find_if(VL, IsaPred<GetElementPtrInst>);
1440114401 if (It != VL.end())
1440214402 S = getSameOpcode(*It, *TLI);
1440314403 }
14404- if (!S.getMainOp ())
14404+ if (!S.valid ())
1440514405 return nullptr;
1440614406 auto CheckSameVE = [&](const TreeEntry *VE) {
1440714407 return VE->isSame(VL) &&
@@ -15061,7 +15061,7 @@ Value *BoUpSLP::vectorizeTree(TreeEntry *E, bool PostponedPHIs) {
1506115061 auto *VecTy = getWidenedType(ScalarTy, E->Scalars.size());
1506215062 if (E->isGather()) {
1506315063 // 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)
1506515065 setInsertPointAfterBundle(E);
1506615066 Value *Vec = createBuildVector(E, ScalarTy, PostponedPHIs);
1506715067 E->VectorizedValue = Vec;
@@ -18378,7 +18378,7 @@ SLPVectorizerPass::vectorizeStoreChain(ArrayRef<Value *> Chain, BoUpSLP &R,
1837818378 hasFullVectorsOrPowerOf2(*TTI, ValOps.front()->getType(),
1837918379 ValOps.size()) ||
1838018380 (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 &&
1838218382 (!S.getMainOp()->isSafeToRemove() ||
1838318383 any_of(ValOps.getArrayRef(),
1838418384 [&](Value *V) {
@@ -18388,8 +18388,8 @@ SLPVectorizerPass::vectorizeStoreChain(ArrayRef<Value *> Chain, BoUpSLP &R,
1838818388 return !Stores.contains(U);
1838918389 }));
1839018390 }))) ||
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;
1839318393 return false;
1839418394 }
1839518395 }
@@ -18412,7 +18412,7 @@ SLPVectorizerPass::vectorizeStoreChain(ArrayRef<Value *> Chain, BoUpSLP &R,
1841218412 R.computeMinimumValueSizes();
1841318413
1841418414 Size = R.getCanonicalGraphSize();
18415- if (isa_and_present<LoadInst>(S.getMainOp()) )
18415+ if (S.valid() && S.getOpcode() == Instruction::Load )
1841618416 Size = 2; // cut off masked gather small trees
1841718417 InstructionCost Cost = R.getTreeCost();
1841818418
@@ -18913,7 +18913,7 @@ bool SLPVectorizerPass::tryToVectorizeList(ArrayRef<Value *> VL, BoUpSLP &R,
1891318913 // Check that all of the parts are instructions of the same type,
1891418914 // we permit an alternate opcode via InstructionsState.
1891518915 InstructionsState S = getSameOpcode(VL, *TLI);
18916- if (!S.getMainOp ())
18916+ if (!S.valid ())
1891718917 return false;
1891818918
1891918919 Instruction *I0 = S.getMainOp();
@@ -19725,15 +19725,15 @@ class HorizontalReduction {
1972519725 // Also check if the instruction was folded to constant/other value.
1972619726 auto *Inst = dyn_cast<Instruction>(RdxVal);
1972719727 if ((Inst && isVectorLikeInstWithConstOps(Inst) &&
19728- (!S.getMainOp () || !S.isOpcodeOrAlt(Inst))) ||
19729- (S.getMainOp () && !Inst))
19728+ (!S.valid () || !S.isOpcodeOrAlt(Inst))) ||
19729+ (S.valid () && !Inst))
1973019730 continue;
1973119731 Candidates.push_back(RdxVal);
1973219732 TrackedToOrig.try_emplace(RdxVal, OrigReducedVals[Cnt]);
1973319733 }
1973419734 bool ShuffledExtracts = false;
1973519735 // Try to handle shuffled extractelements.
19736- if (isa_and_present<ExtractElementInst>(S.getMainOp()) &&
19736+ if (S.valid() && S.getOpcode() == Instruction::ExtractElement &&
1973719737 !S.isAltShuffle() && I + 1 < E) {
1973819738 SmallVector<Value *> CommonCandidates(Candidates);
1973919739 for (Value *RV : ReducedVals[I + 1]) {
@@ -21129,7 +21129,7 @@ static bool compareCmp(Value *V, Value *V2, TargetLibraryInfo &TLI,
2112921129 return NodeI1->getDFSNumIn() < NodeI2->getDFSNumIn();
2113021130 }
2113121131 InstructionsState S = getSameOpcode({I1, I2}, TLI);
21132- if (S.getMainOp () && (IsCompatibility || !S.isAltShuffle()))
21132+ if (S.valid () && (IsCompatibility || !S.isAltShuffle()))
2113321133 continue;
2113421134 if (IsCompatibility)
2113521135 return false;
@@ -21284,7 +21284,7 @@ bool SLPVectorizerPass::vectorizeChainsInBlock(BasicBlock *BB, BoUpSLP &R) {
2128421284 if (NodeI1 != NodeI2)
2128521285 return NodeI1->getDFSNumIn() < NodeI2->getDFSNumIn();
2128621286 InstructionsState S = getSameOpcode({I1, I2}, *TLI);
21287- if (S.getMainOp () && !S.isAltShuffle())
21287+ if (S.valid () && !S.isAltShuffle())
2128821288 continue;
2128921289 return I1->getOpcode() < I2->getOpcode();
2129021290 }
0 commit comments