Skip to content

Commit 2b79051

Browse files
committed
InstructionsState getOpValue can be replaced by getMainOp
1 parent 9f648ec commit 2b79051

File tree

1 file changed

+23
-28
lines changed

1 file changed

+23
-28
lines changed

llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -808,16 +808,11 @@ namespace {
808808

809809
/// Main data required for vectorization of instructions.
810810
class InstructionsState {
811-
/// The very first instruction in the list with the main opcode.
812-
Value *OpValue = nullptr;
813-
814-
/// The main/alternate instruction.
811+
/// The main/alternate instruction. MainOp is also VL0.
815812
Instruction *MainOp = nullptr;
816813
Instruction *AltOp = nullptr;
817814

818815
public:
819-
Value *getOpValue() const { return OpValue; }
820-
821816
Instruction *getMainOp() const { return MainOp; }
822817

823818
Instruction *getAltOp() const { return AltOp; }
@@ -840,9 +835,9 @@ class InstructionsState {
840835
}
841836

842837
InstructionsState() = delete;
843-
InstructionsState(Value *OpValue, Instruction *MainOp, Instruction *AltOp)
844-
: OpValue(OpValue), MainOp(MainOp), AltOp(AltOp) {}
845-
static InstructionsState invalid() { return {nullptr, nullptr, nullptr}; }
838+
InstructionsState(Instruction *MainOp, Instruction *AltOp)
839+
: MainOp(MainOp), AltOp(AltOp) {}
840+
static InstructionsState invalid() { return {nullptr, nullptr}; }
846841
};
847842

848843
} // end anonymous namespace
@@ -1080,7 +1075,7 @@ static InstructionsState getSameOpcode(ArrayRef<Value *> VL,
10801075
return InstructionsState::invalid();
10811076
}
10821077

1083-
return InstructionsState(V, cast<Instruction>(V),
1078+
return InstructionsState(cast<Instruction>(V),
10841079
cast<Instruction>(VL[AltIndex]));
10851080
}
10861081

@@ -7551,7 +7546,7 @@ BoUpSLP::TreeEntry::EntryState BoUpSLP::getScalarsVectorizationState(
75517546

75527547
unsigned ShuffleOrOp =
75537548
S.isAltShuffle() ? (unsigned)Instruction::ShuffleVector : S.getOpcode();
7554-
auto *VL0 = cast<Instruction>(S.getOpValue());
7549+
Instruction *VL0 = S.getMainOp();
75557550
switch (ShuffleOrOp) {
75567551
case Instruction::PHI: {
75577552
// Too many operands - gather, most probably won't be vectorized.
@@ -8085,11 +8080,11 @@ void BoUpSLP::buildTree_rec(ArrayRef<Value *> VL, unsigned Depth,
80858080

80868081
// Check if this is a duplicate of another entry.
80878082
if (S.getOpcode()) {
8088-
if (TreeEntry *E = getTreeEntry(S.getOpValue())) {
8089-
LLVM_DEBUG(dbgs() << "SLP: \tChecking bundle: " << *S.getOpValue()
8083+
if (TreeEntry *E = getTreeEntry(S.getMainOp())) {
8084+
LLVM_DEBUG(dbgs() << "SLP: \tChecking bundle: " << *S.getMainOp()
80908085
<< ".\n");
80918086
if (GatheredLoadsEntriesFirst.has_value() || !E->isSame(VL)) {
8092-
auto It = MultiNodeScalars.find(S.getOpValue());
8087+
auto It = MultiNodeScalars.find(S.getMainOp());
80938088
if (It != MultiNodeScalars.end()) {
80948089
auto *TEIt = find_if(It->getSecond(),
80958090
[&](TreeEntry *ME) { return ME->isSame(VL); });
@@ -8102,16 +8097,16 @@ void BoUpSLP::buildTree_rec(ArrayRef<Value *> VL, unsigned Depth,
81028097
}
81038098
}
81048099
if (!E) {
8105-
if (!doesNotNeedToBeScheduled(S.getOpValue())) {
8100+
if (!doesNotNeedToBeScheduled(S.getMainOp())) {
81068101
LLVM_DEBUG(dbgs() << "SLP: Gathering due to partial overlap.\n");
81078102
if (TryToFindDuplicates(S))
81088103
newTreeEntry(VL, std::nullopt /*not vectorized*/, S, UserTreeIdx,
81098104
ReuseShuffleIndices);
81108105
return;
81118106
}
81128107
SmallPtrSet<const TreeEntry *, 4> Nodes;
8113-
Nodes.insert(getTreeEntry(S.getOpValue()));
8114-
for (const TreeEntry *E : MultiNodeScalars.lookup(S.getOpValue()))
8108+
Nodes.insert(getTreeEntry(S.getMainOp()));
8109+
for (const TreeEntry *E : MultiNodeScalars.lookup(S.getMainOp()))
81158110
Nodes.insert(E);
81168111
SmallPtrSet<Value *, 8> Values(VL.begin(), VL.end());
81178112
if (any_of(Nodes, [&](const TreeEntry *E) {
@@ -8134,7 +8129,7 @@ void BoUpSLP::buildTree_rec(ArrayRef<Value *> VL, unsigned Depth,
81348129
// used to properly draw the graph rather than for the actual
81358130
// vectorization.
81368131
E->UserTreeIndices.push_back(UserTreeIdx);
8137-
LLVM_DEBUG(dbgs() << "SLP: Perfect diamond merge at " << *S.getOpValue()
8132+
LLVM_DEBUG(dbgs() << "SLP: Perfect diamond merge at " << *S.getMainOp()
81388133
<< ".\n");
81398134
return;
81408135
}
@@ -8163,7 +8158,7 @@ void BoUpSLP::buildTree_rec(ArrayRef<Value *> VL, unsigned Depth,
81638158
// Don't handle scalable vectors
81648159
if (S.getOpcode() == Instruction::ExtractElement &&
81658160
isa<ScalableVectorType>(
8166-
cast<ExtractElementInst>(S.getOpValue())->getVectorOperandType())) {
8161+
cast<ExtractElementInst>(S.getMainOp())->getVectorOperandType())) {
81678162
LLVM_DEBUG(dbgs() << "SLP: Gathering due to scalable vector type.\n");
81688163
if (TryToFindDuplicates(S))
81698164
newTreeEntry(VL, std::nullopt /*not vectorized*/, S, UserTreeIdx,
@@ -8259,7 +8254,7 @@ void BoUpSLP::buildTree_rec(ArrayRef<Value *> VL, unsigned Depth,
82598254
bool AreAllSameInsts = AreAllSameBlock || AreScatterAllGEPSameBlock;
82608255
if (!AreAllSameInsts || (!S.getOpcode() && allConstant(VL)) || isSplat(VL) ||
82618256
(isa_and_present<InsertElementInst, ExtractValueInst, ExtractElementInst>(
8262-
S.getOpValue()) &&
8257+
S.getMainOp()) &&
82638258
!all_of(VL, isVectorLikeInstWithConstOps)) ||
82648259
NotProfitableForVectorization(VL)) {
82658260
LLVM_DEBUG(dbgs() << "SLP: Gathering due to C,S,B,O, small shuffle. \n");
@@ -8326,7 +8321,7 @@ void BoUpSLP::buildTree_rec(ArrayRef<Value *> VL, unsigned Depth,
83268321

83278322
// Check that all of the users of the scalars that we want to vectorize are
83288323
// schedulable.
8329-
auto *VL0 = cast<Instruction>(S.getOpValue());
8324+
Instruction *VL0 = S.getMainOp();
83308325
BB = VL0->getParent();
83318326

83328327
if (S.getMainOp() &&
@@ -14495,10 +14490,10 @@ BoUpSLP::TreeEntry *BoUpSLP::getMatchedVectorizedOperand(const TreeEntry *E,
1449514490
VE->isSame(TE->Scalars);
1449614491
}));
1449714492
};
14498-
TreeEntry *VE = getTreeEntry(S.getOpValue());
14493+
TreeEntry *VE = getTreeEntry(S.getMainOp());
1449914494
if (VE && CheckSameVE(VE))
1450014495
return VE;
14501-
auto It = MultiNodeScalars.find(S.getOpValue());
14496+
auto It = MultiNodeScalars.find(S.getMainOp());
1450214497
if (It != MultiNodeScalars.end()) {
1450314498
auto *I = find_if(It->getSecond(), [&](const TreeEntry *TE) {
1450414499
return TE != VE && CheckSameVE(TE);
@@ -16985,13 +16980,13 @@ BoUpSLP::BlockScheduling::tryScheduleBundle(ArrayRef<Value *> VL, BoUpSLP *SLP,
1698516980
const InstructionsState &S) {
1698616981
// No need to schedule PHIs, insertelement, extractelement and extractvalue
1698716982
// instructions.
16988-
if (isa<PHINode>(S.getOpValue()) ||
16989-
isVectorLikeInstWithConstOps(S.getOpValue()) || doesNotNeedToSchedule(VL))
16983+
if (isa<PHINode>(S.getMainOp()) ||
16984+
isVectorLikeInstWithConstOps(S.getMainOp()) || doesNotNeedToSchedule(VL))
1699016985
return nullptr;
1699116986

1699216987
// Initialize the instruction bundle.
1699316988
Instruction *OldScheduleEnd = ScheduleEnd;
16994-
LLVM_DEBUG(dbgs() << "SLP: bundle: " << *S.getOpValue() << "\n");
16989+
LLVM_DEBUG(dbgs() << "SLP: bundle: " << *S.getMainOp() << "\n");
1699516990

1699616991
auto TryScheduleBundleImpl = [this, OldScheduleEnd, SLP](bool ReSchedule,
1699716992
ScheduleData *Bundle) {
@@ -17072,7 +17067,7 @@ BoUpSLP::BlockScheduling::tryScheduleBundle(ArrayRef<Value *> VL, BoUpSLP *SLP,
1707217067
auto *Bundle = buildBundle(VL);
1707317068
TryScheduleBundleImpl(ReSchedule, Bundle);
1707417069
if (!Bundle->isReady()) {
17075-
cancelScheduling(VL, S.getOpValue());
17070+
cancelScheduling(VL, S.getMainOp());
1707617071
return std::nullopt;
1707717072
}
1707817073
return Bundle;
@@ -18988,7 +18983,7 @@ bool SLPVectorizerPass::tryToVectorizeList(ArrayRef<Value *> VL, BoUpSLP &R,
1898818983
if (!S.getOpcode())
1898918984
return false;
1899018985

18991-
auto *I0 = cast<Instruction>(S.getOpValue());
18986+
Instruction *I0 = S.getMainOp();
1899218987
// Make sure invalid types (including vector type) are rejected before
1899318988
// determining vectorization factor for scalar instructions.
1899418989
for (Value *V : VL) {

0 commit comments

Comments
 (0)