From de7c1396f29b9bf7011912e7cfea9edad1efb492 Mon Sep 17 00:00:00 2001 From: Han-Kuan Chen Date: Wed, 26 Jun 2024 00:42:38 +0800 Subject: [SLP] NFC. Refactor and add getAltInstrMask help function. (#94709) Co-authored-by: Alexey Bataev --- llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp | 29 ++++++++++++------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index 494db04..08fcca6 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -983,6 +983,17 @@ static void fixupOrderingIndices(MutableArrayRef Order) { } } +/// \returns a bitset for selecting opcodes. false for Opcode0 and true for +/// Opcode1. +SmallBitVector getAltInstrMask(ArrayRef VL, unsigned Opcode0, + unsigned Opcode1) { + SmallBitVector OpcodeMask(VL.size(), false); + for (unsigned Lane : seq(VL.size())) + if (cast(VL[Lane])->getOpcode() == Opcode1) + OpcodeMask.set(Lane); + return OpcodeMask; +} + namespace llvm { static void inversePermutation(ArrayRef Indices, @@ -5093,11 +5104,7 @@ void BoUpSLP::reorderTopToBottom() { FixedVectorType::get(TE->Scalars[0]->getType(), TE->Scalars.size()); unsigned Opcode0 = TE->getOpcode(); unsigned Opcode1 = TE->getAltOpcode(); - // The opcode mask selects between the two opcodes. - SmallBitVector OpcodeMask(TE->Scalars.size(), false); - for (unsigned Lane : seq(0, TE->Scalars.size())) - if (cast(TE->Scalars[Lane])->getOpcode() == Opcode1) - OpcodeMask.set(Lane); + SmallBitVector OpcodeMask(getAltInstrMask(TE->Scalars, Opcode0, Opcode1)); // If this pattern is supported by the target then we consider the order. if (TTIRef.isLegalAltInstr(VecTy, Opcode0, Opcode1, OpcodeMask)) { VFToOrderedEntries[TE->getVectorFactor()].insert(TE.get()); @@ -6009,11 +6016,7 @@ bool BoUpSLP::areAltOperandsProfitable(const InstructionsState &S, ArrayRef VL) const { unsigned Opcode0 = S.getOpcode(); unsigned Opcode1 = S.getAltOpcode(); - // The opcode mask selects between the two opcodes. - SmallBitVector OpcodeMask(VL.size(), false); - for (unsigned Lane : seq(0, VL.size())) - if (cast(VL[Lane])->getOpcode() == Opcode1) - OpcodeMask.set(Lane); + SmallBitVector OpcodeMask(getAltInstrMask(VL, Opcode0, Opcode1)); // If this pattern is supported by the target then consider it profitable. if (TTI->isLegalAltInstr(FixedVectorType::get(S.MainOp->getType(), VL.size()), Opcode0, Opcode1, OpcodeMask)) @@ -9744,11 +9747,7 @@ BoUpSLP::getEntryCost(const TreeEntry *E, ArrayRef VectorizedVals, // order. unsigned Opcode0 = E->getOpcode(); unsigned Opcode1 = E->getAltOpcode(); - // The opcode mask selects between the two opcodes. - SmallBitVector OpcodeMask(E->Scalars.size(), false); - for (unsigned Lane : seq(0, E->Scalars.size())) - if (cast(E->Scalars[Lane])->getOpcode() == Opcode1) - OpcodeMask.set(Lane); + SmallBitVector OpcodeMask(getAltInstrMask(E->Scalars, Opcode0, Opcode1)); // If this pattern is supported by the target then we consider the // order. if (TTIRef.isLegalAltInstr(VecTy, Opcode0, Opcode1, OpcodeMask)) { -- cgit v1.1