@@ -983,6 +983,17 @@ static void fixupOrderingIndices(MutableArrayRef<unsigned> Order) {
983
983
}
984
984
}
985
985
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
+
986
997
namespace llvm {
987
998
988
999
static void inversePermutation(ArrayRef<unsigned> Indices,
@@ -5093,11 +5104,7 @@ void BoUpSLP::reorderTopToBottom() {
5093
5104
FixedVectorType::get(TE->Scalars[0]->getType(), TE->Scalars.size());
5094
5105
unsigned Opcode0 = TE->getOpcode();
5095
5106
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));
5101
5108
// If this pattern is supported by the target then we consider the order.
5102
5109
if (TTIRef.isLegalAltInstr(VecTy, Opcode0, Opcode1, OpcodeMask)) {
5103
5110
VFToOrderedEntries[TE->getVectorFactor()].insert(TE.get());
@@ -6009,11 +6016,7 @@ bool BoUpSLP::areAltOperandsProfitable(const InstructionsState &S,
6009
6016
ArrayRef<Value *> VL) const {
6010
6017
unsigned Opcode0 = S.getOpcode();
6011
6018
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));
6017
6020
// If this pattern is supported by the target then consider it profitable.
6018
6021
if (TTI->isLegalAltInstr(FixedVectorType::get(S.MainOp->getType(), VL.size()),
6019
6022
Opcode0, Opcode1, OpcodeMask))
@@ -9744,11 +9747,7 @@ BoUpSLP::getEntryCost(const TreeEntry *E, ArrayRef<Value *> VectorizedVals,
9744
9747
// order.
9745
9748
unsigned Opcode0 = E->getOpcode();
9746
9749
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));
9752
9751
// If this pattern is supported by the target then we consider the
9753
9752
// order.
9754
9753
if (TTIRef.isLegalAltInstr(VecTy, Opcode0, Opcode1, OpcodeMask)) {
0 commit comments