From 2e2f20a94926606269626a405c0fba54cf0f7ed1 Mon Sep 17 00:00:00 2001 From: Simon Pilgrim Date: Wed, 20 Jun 2018 14:26:28 +0000 Subject: [SLPVectorizer] Relax "alternate" opcode vectorisation to work with any SK_Select shuffle pattern D47985 saw the old SK_Alternate 'alternating' shuffle mask replaced with the SK_Select mask which accepts either input operand for each lane, equivalent to a vector select with a constant condition operand. This patch updates SLPVectorizer to make full use of this SK_Select shuffle pattern by removing the 'isOdd()' limitation. The AArch64 regression will be fixed by D48172. Differential Revision: https://reviews.llvm.org/D48174 llvm-svn: 335130 --- llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'llvm/lib') diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index dfa881aaa10..86e94f6d202 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -316,10 +316,6 @@ static unsigned getAltOpcode(unsigned Op) { } } -static bool isOdd(unsigned Value) { - return Value & 1; -} - static bool sameOpcodeOrAlt(unsigned Opcode, unsigned AltOpcode, unsigned CheckedOpcode) { return Opcode == CheckedOpcode || AltOpcode == CheckedOpcode; @@ -378,7 +374,7 @@ static InstructionsState getSameOpcode(ArrayRef VL) { unsigned AltOpcode = getAltOpcode(Opcode); for (int Cnt = 0, E = VL.size(); Cnt < E; Cnt++) { unsigned InstOpcode = cast(VL[Cnt])->getOpcode(); - if (InstOpcode != (isOdd(Cnt) ? AltOpcode : Opcode)) + if (!sameOpcodeOrAlt(Opcode, AltOpcode, InstOpcode)) return InstructionsState(VL[0], 0, false); } } @@ -3510,22 +3506,26 @@ Value *BoUpSLP::vectorizeTree(TreeEntry *E) { // Create shuffle to take alternate operations from the vector. // Also, gather up odd and even scalar ops to propagate IR flags to // each vector operation. - ValueList OddScalars, EvenScalars; + ValueList OpScalars, AltScalars; unsigned e = E->Scalars.size(); SmallVector Mask(e); for (unsigned i = 0; i < e; ++i) { - if (isOdd(i)) { + auto *OpInst = cast(E->Scalars[i]); + unsigned InstOpcode = OpInst->getOpcode(); + assert(sameOpcodeOrAlt(S.Opcode, AltOpcode, InstOpcode) && + "Unexpected main/alternate opcode"); + if (InstOpcode == AltOpcode) { Mask[i] = Builder.getInt32(e + i); - OddScalars.push_back(E->Scalars[i]); + AltScalars.push_back(E->Scalars[i]); } else { Mask[i] = Builder.getInt32(i); - EvenScalars.push_back(E->Scalars[i]); + OpScalars.push_back(E->Scalars[i]); } } Value *ShuffleMask = ConstantVector::get(Mask); - propagateIRFlags(V0, EvenScalars); - propagateIRFlags(V1, OddScalars); + propagateIRFlags(V0, OpScalars); + propagateIRFlags(V1, AltScalars); Value *V = Builder.CreateShuffleVector(V0, V1, ShuffleMask); if (Instruction *I = dyn_cast(V)) -- cgit v1.2.3