Skip to content

Commit ce5090d

Browse files
HanKuanChenalexey-bataev
authored andcommitted
[SLP] NFC. Refactor and add getAltInstrMask help function. (llvm#94709)
Co-authored-by: Alexey Bataev <[email protected]>
1 parent 5b6911c commit ce5090d

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -983,6 +983,17 @@ static void fixupOrderingIndices(MutableArrayRef<unsigned> Order) {
983983
}
984984
}
985985

986+
/// \returns a bitset for selecting opcodes. false for Opcode0 and true for
987+
/// Opcode1.
988+
SmallBitVector getAltInstrMask(ArrayRef<Value *> VL, unsigned Opcode0,
989+
unsigned Opcode1) {
990+
SmallBitVector OpcodeMask(VL.size(), false);
991+
for (unsigned Lane : seq<unsigned>(VL.size()))
992+
if (cast<Instruction>(VL[Lane])->getOpcode() == Opcode1)
993+
OpcodeMask.set(Lane);
994+
return OpcodeMask;
995+
}
996+
986997
namespace llvm {
987998

988999
static void inversePermutation(ArrayRef<unsigned> Indices,
@@ -5093,11 +5104,7 @@ void BoUpSLP::reorderTopToBottom() {
50935104
FixedVectorType::get(TE->Scalars[0]->getType(), TE->Scalars.size());
50945105
unsigned Opcode0 = TE->getOpcode();
50955106
unsigned Opcode1 = TE->getAltOpcode();
5096-
// The opcode mask selects between the two opcodes.
5097-
SmallBitVector OpcodeMask(TE->Scalars.size(), false);
5098-
for (unsigned Lane : seq<unsigned>(0, TE->Scalars.size()))
5099-
if (cast<Instruction>(TE->Scalars[Lane])->getOpcode() == Opcode1)
5100-
OpcodeMask.set(Lane);
5107+
SmallBitVector OpcodeMask(getAltInstrMask(TE->Scalars, Opcode0, Opcode1));
51015108
// If this pattern is supported by the target then we consider the order.
51025109
if (TTIRef.isLegalAltInstr(VecTy, Opcode0, Opcode1, OpcodeMask)) {
51035110
VFToOrderedEntries[TE->getVectorFactor()].insert(TE.get());
@@ -6009,11 +6016,7 @@ bool BoUpSLP::areAltOperandsProfitable(const InstructionsState &S,
60096016
ArrayRef<Value *> VL) const {
60106017
unsigned Opcode0 = S.getOpcode();
60116018
unsigned Opcode1 = S.getAltOpcode();
6012-
// The opcode mask selects between the two opcodes.
6013-
SmallBitVector OpcodeMask(VL.size(), false);
6014-
for (unsigned Lane : seq<unsigned>(0, VL.size()))
6015-
if (cast<Instruction>(VL[Lane])->getOpcode() == Opcode1)
6016-
OpcodeMask.set(Lane);
6019+
SmallBitVector OpcodeMask(getAltInstrMask(VL, Opcode0, Opcode1));
60176020
// If this pattern is supported by the target then consider it profitable.
60186021
if (TTI->isLegalAltInstr(FixedVectorType::get(S.MainOp->getType(), VL.size()),
60196022
Opcode0, Opcode1, OpcodeMask))
@@ -9744,11 +9747,7 @@ BoUpSLP::getEntryCost(const TreeEntry *E, ArrayRef<Value *> VectorizedVals,
97449747
// order.
97459748
unsigned Opcode0 = E->getOpcode();
97469749
unsigned Opcode1 = E->getAltOpcode();
9747-
// The opcode mask selects between the two opcodes.
9748-
SmallBitVector OpcodeMask(E->Scalars.size(), false);
9749-
for (unsigned Lane : seq<unsigned>(0, E->Scalars.size()))
9750-
if (cast<Instruction>(E->Scalars[Lane])->getOpcode() == Opcode1)
9751-
OpcodeMask.set(Lane);
9750+
SmallBitVector OpcodeMask(getAltInstrMask(E->Scalars, Opcode0, Opcode1));
97529751
// If this pattern is supported by the target then we consider the
97539752
// order.
97549753
if (TTIRef.isLegalAltInstr(VecTy, Opcode0, Opcode1, OpcodeMask)) {

0 commit comments

Comments
 (0)