@@ -821,7 +821,8 @@ class InstructionsState {
821821
822822 /// The main/alternate opcodes for the list of instructions.
823823 unsigned getOpcode() const {
824- return MainOp ? MainOp->getOpcode() : 0;
824+ assert(MainOp && "InstructionsState is invalid.");
825+ return MainOp->getOpcode();
825826 }
826827
827828 unsigned getAltOpcode() const {
@@ -1847,7 +1848,7 @@ class BoUpSLP {
18471848 InstructionsState S = getSameOpcode(Ops, TLI);
18481849 // Note: Only consider instructions with <= 2 operands to avoid
18491850 // complexity explosion.
1850- if (S.getOpcode () &&
1851+ if (S.getMainOp () &&
18511852 (S.getMainOp()->getNumOperands() <= 2 || !MainAltOps.empty() ||
18521853 !S.isAltShuffle()) &&
18531854 all_of(Ops, [&S](Value *V) {
@@ -2698,7 +2699,7 @@ class BoUpSLP {
26982699 OperandData &AltOp = getData(OpIdx, Lane);
26992700 InstructionsState OpS =
27002701 getSameOpcode({MainAltOps[OpIdx].front(), AltOp.V}, TLI);
2701- if (OpS.getOpcode () && OpS.isAltShuffle())
2702+ if (OpS.getMainOp () && OpS.isAltShuffle())
27022703 MainAltOps[OpIdx].push_back(AltOp.V);
27032704 }
27042705 }
@@ -3594,8 +3595,8 @@ class BoUpSLP {
35943595 // Gathered loads still gathered? Do not create entry, use the original one.
35953596 if (GatheredLoadsEntriesFirst.has_value() &&
35963597 EntryState == TreeEntry::NeedToGather &&
3597- S.getOpcode() == Instruction::Load && UserTreeIdx.EdgeIdx == UINT_MAX &&
3598- !UserTreeIdx.UserTE)
3598+ isa_and_present<LoadInst>(S.getMainOp()) &&
3599+ UserTreeIdx.EdgeIdx == UINT_MAX && !UserTreeIdx.UserTE)
35993600 return nullptr;
36003601 VectorizableTree.push_back(std::make_unique<TreeEntry>(VectorizableTree));
36013602 TreeEntry *Last = VectorizableTree.back().get();
@@ -8069,7 +8070,7 @@ void BoUpSLP::buildTree_rec(ArrayRef<Value *> VL, unsigned Depth,
80698070 }
80708071
80718072 // Check if this is a duplicate of another entry.
8072- if (S.getOpcode ()) {
8073+ if (S.getMainOp ()) {
80738074 if (TreeEntry *E = getTreeEntry(S.getMainOp())) {
80748075 LLVM_DEBUG(dbgs() << "SLP: \tChecking bundle: " << *S.getMainOp()
80758076 << ".\n");
@@ -8135,8 +8136,7 @@ void BoUpSLP::buildTree_rec(ArrayRef<Value *> VL, unsigned Depth,
81358136 all_of(VL, [&S](const Value *I) {
81368137 return match(I,
81378138 m_OneUse(m_ZExtOrSExt(m_OneUse(m_Load(m_Value()))))) &&
8138- cast<Instruction>(I)->getOpcode() ==
8139- S.getMainOp()->getOpcode();
8139+ cast<Instruction>(I)->getOpcode() == S.getOpcode();
81408140 })))) {
81418141 LLVM_DEBUG(dbgs() << "SLP: Gathering due to max recursion depth.\n");
81428142 if (TryToFindDuplicates(S))
@@ -8146,15 +8146,14 @@ void BoUpSLP::buildTree_rec(ArrayRef<Value *> VL, unsigned Depth,
81468146 }
81478147
81488148 // Don't handle scalable vectors
8149- if (S.getOpcode() == Instruction::ExtractElement &&
8150- isa<ScalableVectorType>(
8151- cast<ExtractElementInst>(S.getMainOp())->getVectorOperandType())) {
8152- LLVM_DEBUG(dbgs() << "SLP: Gathering due to scalable vector type.\n");
8153- if (TryToFindDuplicates(S))
8154- newTreeEntry(VL, std::nullopt /*not vectorized*/, S, UserTreeIdx,
8155- ReuseShuffleIndices);
8156- return;
8157- }
8149+ if (auto *EE = dyn_cast_if_present<ExtractElementInst>(S.getMainOp()))
8150+ if (isa<ScalableVectorType>(EE->getVectorOperandType())) {
8151+ LLVM_DEBUG(dbgs() << "SLP: Gathering due to scalable vector type.\n");
8152+ if (TryToFindDuplicates(S))
8153+ newTreeEntry(VL, std::nullopt /*not vectorized*/, S, UserTreeIdx,
8154+ ReuseShuffleIndices);
8155+ return;
8156+ }
81588157
81598158 // Don't handle vectors.
81608159 if (!SLPReVec && getValueType(VL.front())->isVectorTy()) {
@@ -8170,7 +8169,7 @@ void BoUpSLP::buildTree_rec(ArrayRef<Value *> VL, unsigned Depth,
81708169 // vectorize.
81718170 auto &&NotProfitableForVectorization = [&S, this,
81728171 Depth](ArrayRef<Value *> VL) {
8173- if (!S.getOpcode () || !S.isAltShuffle() || VL.size() > 2)
8172+ if (!S.getMainOp () || !S.isAltShuffle() || VL.size() > 2)
81748173 return false;
81758174 if (VectorizableTree.size() < MinTreeSize)
81768175 return false;
@@ -8225,7 +8224,7 @@ void BoUpSLP::buildTree_rec(ArrayRef<Value *> VL, unsigned Depth,
82258224 bool IsScatterVectorizeUserTE =
82268225 UserTreeIdx.UserTE &&
82278226 UserTreeIdx.UserTE->State == TreeEntry::ScatterVectorize;
8228- bool AreAllSameBlock = S.getOpcode () && allSameBlock(VL);
8227+ bool AreAllSameBlock = S.getMainOp () && allSameBlock(VL);
82298228 bool AreScatterAllGEPSameBlock =
82308229 (IsScatterVectorizeUserTE && VL.front()->getType()->isPointerTy() &&
82318230 VL.size() > 2 &&
@@ -8242,7 +8241,7 @@ void BoUpSLP::buildTree_rec(ArrayRef<Value *> VL, unsigned Depth,
82428241 sortPtrAccesses(VL, UserTreeIdx.UserTE->getMainOp()->getType(), *DL, *SE,
82438242 SortedIndices));
82448243 bool AreAllSameInsts = AreAllSameBlock || AreScatterAllGEPSameBlock;
8245- if (!AreAllSameInsts || (!S.getOpcode () && allConstant(VL)) || isSplat(VL) ||
8244+ if (!AreAllSameInsts || (!S.getMainOp () && allConstant(VL)) || isSplat(VL) ||
82468245 (isa_and_present<InsertElementInst, ExtractValueInst, ExtractElementInst>(
82478246 S.getMainOp()) &&
82488247 !all_of(VL, isVectorLikeInstWithConstOps)) ||
@@ -8255,7 +8254,7 @@ void BoUpSLP::buildTree_rec(ArrayRef<Value *> VL, unsigned Depth,
82558254 }
82568255
82578256 // Don't vectorize ephemeral values.
8258- if (S.getOpcode () && !EphValues.empty()) {
8257+ if (S.getMainOp () && !EphValues.empty()) {
82598258 for (Value *V : VL) {
82608259 if (EphValues.count(V)) {
82618260 LLVM_DEBUG(dbgs() << "SLP: The instruction (" << *V
@@ -8361,15 +8360,15 @@ void BoUpSLP::buildTree_rec(ArrayRef<Value *> VL, unsigned Depth,
83618360 newTreeEntry(VL, std::nullopt /*not vectorized*/, S, UserTreeIdx,
83628361 ReuseShuffleIndices);
83638362 NonScheduledFirst.insert(VL.front());
8364- if (S.getOpcode() == Instruction::Load &&
8363+ if (isa<LoadInst>(S.getMainOp()) &&
83658364 BS.ScheduleRegionSize < BS.ScheduleRegionSizeLimit)
83668365 registerNonVectorizableLoads(VL);
83678366 return;
83688367 }
83698368 LLVM_DEBUG(dbgs() << "SLP: We are able to schedule this bundle.\n");
83708369
8371- unsigned ShuffleOrOp = S.isAltShuffle() ?
8372- (unsigned) Instruction::ShuffleVector : S.getOpcode();
8370+ unsigned ShuffleOrOp =
8371+ S.isAltShuffle() ? (unsigned)Instruction::ShuffleVector : S.getOpcode();
83738372 auto CreateOperandNodes = [&](TreeEntry *TE, const auto &Operands) {
83748373 // Postpone PHI nodes creation
83758374 SmallVector<unsigned> PHIOps;
@@ -8378,7 +8377,7 @@ void BoUpSLP::buildTree_rec(ArrayRef<Value *> VL, unsigned Depth,
83788377 if (Op.empty())
83798378 continue;
83808379 InstructionsState S = getSameOpcode(Op, *TLI);
8381- if (S.getOpcode() != Instruction::PHI || S.isAltShuffle())
8380+ if (!isa_and_present<PHINode>(S.getMainOp()) || S.isAltShuffle())
83828381 buildTree_rec(Op, Depth + 1, {TE, I});
83838382 else
83848383 PHIOps.push_back(I);
@@ -9732,10 +9731,10 @@ void BoUpSLP::transformNodes() {
97329731 if (IsSplat)
97339732 continue;
97349733 InstructionsState S = getSameOpcode(Slice, *TLI);
9735- if (!S.getOpcode () || S.isAltShuffle() || !allSameBlock(Slice) ||
9736- (S.getOpcode() == Instruction::Load &&
9734+ if (!S.getMainOp () || S.isAltShuffle() || !allSameBlock(Slice) ||
9735+ (isa<LoadInst>(S.getMainOp()) &&
97379736 areKnownNonVectorizableLoads(Slice)) ||
9738- (S.getOpcode() != Instruction::Load && !has_single_bit(VF)))
9737+ (!isa<LoadInst>(S.getMainOp()) && !has_single_bit(VF)))
97399738 continue;
97409739 if (VF == 2) {
97419740 // Try to vectorize reduced values or if all users are vectorized.
@@ -9750,7 +9749,7 @@ void BoUpSLP::transformNodes() {
97509749 UserIgnoreList);
97519750 }))
97529751 continue;
9753- if (S.getOpcode() == Instruction::Load ) {
9752+ if (isa<LoadInst>(S.getMainOp()) ) {
97549753 OrdersType Order;
97559754 SmallVector<Value *> PointerOps;
97569755 LoadsState Res =
@@ -9767,7 +9766,7 @@ void BoUpSLP::transformNodes() {
97679766 }
97689767 continue;
97699768 }
9770- } else if (S.getOpcode() == Instruction::ExtractElement ||
9769+ } else if (isa<ExtractElementInst>(S.getMainOp()) ||
97719770 (TTI->getInstructionCost(S.getMainOp(), CostKind) <
97729771 TTI::TCC_Expensive &&
97739772 !CheckOperandsProfitability(
@@ -11049,7 +11048,8 @@ BoUpSLP::getEntryCost(const TreeEntry *E, ArrayRef<Value *> VectorizedVals,
1104911048 if (const TreeEntry *OpTE = getTreeEntry(V))
1105011049 return getCastContextHint(*OpTE);
1105111050 InstructionsState SrcState = getSameOpcode(E->getOperand(0), *TLI);
11052- if (SrcState.getOpcode() == Instruction::Load && !SrcState.isAltShuffle())
11051+ if (isa_and_present<LoadInst>(SrcState.getMainOp()) &&
11052+ !SrcState.isAltShuffle())
1105311053 return TTI::CastContextHint::GatherScatter;
1105411054 return TTI::CastContextHint::None;
1105511055 };
@@ -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.getOpcode () && VL.front()->getType()->isPointerTy()) {
14399+ if (!S.getMainOp () && 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.getOpcode ())
14404+ if (!S.getMainOp ())
1440514405 return nullptr;
1440614406 auto CheckSameVE = [&](const TreeEntry *VE) {
1440714407 return VE->isSame(VL) &&
@@ -18378,8 +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.getOpcode() &&
18382- S.getOpcode() != Instruction::Load &&
18381+ if ((!IsAllowedSize && S.getMainOp() && !isa<LoadInst>(S.getMainOp()) &&
1838318382 (!S.getMainOp()->isSafeToRemove() ||
1838418383 any_of(ValOps.getArrayRef(),
1838518384 [&](Value *V) {
@@ -18389,8 +18388,8 @@ SLPVectorizerPass::vectorizeStoreChain(ArrayRef<Value *> Chain, BoUpSLP &R,
1838918388 return !Stores.contains(U);
1839018389 }));
1839118390 }))) ||
18392- (ValOps.size() > Chain.size() / 2 && !S.getOpcode ())) {
18393- Size = (!IsAllowedSize && S.getOpcode ()) ? 1 : 2;
18391+ (ValOps.size() > Chain.size() / 2 && !S.getMainOp ())) {
18392+ Size = (!IsAllowedSize && S.getMainOp ()) ? 1 : 2;
1839418393 return false;
1839518394 }
1839618395 }
@@ -18413,7 +18412,7 @@ SLPVectorizerPass::vectorizeStoreChain(ArrayRef<Value *> Chain, BoUpSLP &R,
1841318412 R.computeMinimumValueSizes();
1841418413
1841518414 Size = R.getCanonicalGraphSize();
18416- if (S.getOpcode() == Instruction::Load )
18415+ if (isa_and_present<LoadInst>(S.getMainOp()) )
1841718416 Size = 2; // cut off masked gather small trees
1841818417 InstructionCost Cost = R.getTreeCost();
1841918418
@@ -18914,7 +18913,7 @@ bool SLPVectorizerPass::tryToVectorizeList(ArrayRef<Value *> VL, BoUpSLP &R,
1891418913 // Check that all of the parts are instructions of the same type,
1891518914 // we permit an alternate opcode via InstructionsState.
1891618915 InstructionsState S = getSameOpcode(VL, *TLI);
18917- if (!S.getOpcode ())
18916+ if (!S.getMainOp ())
1891818917 return false;
1891918918
1892018919 Instruction *I0 = S.getMainOp();
@@ -19726,16 +19725,16 @@ class HorizontalReduction {
1972619725 // Also check if the instruction was folded to constant/other value.
1972719726 auto *Inst = dyn_cast<Instruction>(RdxVal);
1972819727 if ((Inst && isVectorLikeInstWithConstOps(Inst) &&
19729- (!S.getOpcode () || !S.isOpcodeOrAlt(Inst))) ||
19730- (S.getOpcode () && !Inst))
19728+ (!S.getMainOp () || !S.isOpcodeOrAlt(Inst))) ||
19729+ (S.getMainOp () && !Inst))
1973119730 continue;
1973219731 Candidates.push_back(RdxVal);
1973319732 TrackedToOrig.try_emplace(RdxVal, OrigReducedVals[Cnt]);
1973419733 }
1973519734 bool ShuffledExtracts = false;
1973619735 // Try to handle shuffled extractelements.
19737- if (S.getOpcode() == Instruction::ExtractElement && !S.isAltShuffle( ) &&
19738- I + 1 < E) {
19736+ if (isa_and_present<ExtractElementInst>(S.getMainOp() ) &&
19737+ !S.isAltShuffle() && I + 1 < E) {
1973919738 SmallVector<Value *> CommonCandidates(Candidates);
1974019739 for (Value *RV : ReducedVals[I + 1]) {
1974119740 Value *RdxVal = TrackedVals.at(RV);
@@ -21130,7 +21129,7 @@ static bool compareCmp(Value *V, Value *V2, TargetLibraryInfo &TLI,
2113021129 return NodeI1->getDFSNumIn() < NodeI2->getDFSNumIn();
2113121130 }
2113221131 InstructionsState S = getSameOpcode({I1, I2}, TLI);
21133- if (S.getOpcode () && (IsCompatibility || !S.isAltShuffle()))
21132+ if (S.getMainOp () && (IsCompatibility || !S.isAltShuffle()))
2113421133 continue;
2113521134 if (IsCompatibility)
2113621135 return false;
@@ -21285,7 +21284,7 @@ bool SLPVectorizerPass::vectorizeChainsInBlock(BasicBlock *BB, BoUpSLP &R) {
2128521284 if (NodeI1 != NodeI2)
2128621285 return NodeI1->getDFSNumIn() < NodeI2->getDFSNumIn();
2128721286 InstructionsState S = getSameOpcode({I1, I2}, *TLI);
21288- if (S.getOpcode () && !S.isAltShuffle())
21287+ if (S.getMainOp () && !S.isAltShuffle())
2128921288 continue;
2129021289 return I1->getOpcode() < I2->getOpcode();
2129121290 }
0 commit comments