From 6ed9ec6f65f69463d001fc382a1df37abeaa0056 Mon Sep 17 00:00:00 2001 From: Simon Pilgrim Date: Mon, 2 Oct 2017 10:12:51 +0000 Subject: [PATCH] [X86][SSE] Add createPackShuffleMask helper function. NFCI. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@314658 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Target/X86/X86ISelLowering.cpp | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/lib/Target/X86/X86ISelLowering.cpp b/lib/Target/X86/X86ISelLowering.cpp index 83fb1caa3bd..7e5e709aa3b 100644 --- a/lib/Target/X86/X86ISelLowering.cpp +++ b/lib/Target/X86/X86ISelLowering.cpp @@ -5444,6 +5444,24 @@ static bool getTargetShuffleMaskIndices(SDValue MaskNode, return true; } +/// Create a shuffle mask that matches the PACKSS/PACKUS truncation. +/// Note: This ignores saturation, so inputs must be checked first. +static void createPackShuffleMask(MVT VT, SmallVectorImpl &Mask, + bool Unary) { + assert(Mask.empty() && "Expected an empty shuffle mask vector"); + int NumElts = VT.getVectorNumElements(); + int NumLanes = VT.getSizeInBits() / 128; + int NumEltsPerLane = 128 / VT.getScalarSizeInBits(); + int Offset = Unary ? 0 : NumElts; + + for (unsigned Lane = 0; Lane != NumLanes; ++Lane) { + for (unsigned Elt = 0; Elt != NumEltsPerLane; Elt += 2) + Mask.push_back(Elt + (Lane * NumEltsPerLane)); + for (unsigned Elt = 0; Elt != NumEltsPerLane; Elt += 2) + Mask.push_back(Elt + (Lane * NumEltsPerLane) + Offset); + } +} + /// Calculates the shuffle mask corresponding to the target-specific opcode. /// If the mask could be calculated, returns it in \p Mask, returns the shuffle /// operands in \p Ops, and returns true. @@ -5953,21 +5971,12 @@ static bool getFauxShuffleMask(SDValue N, SmallVectorImpl &Mask, } bool IsUnary = (N0 == N1); - unsigned Offset = IsUnary ? 0 : NumElts; - unsigned NumLanes = VT.getSizeInBits() / 128; - unsigned NumEltsPerLane = NumElts / NumLanes; - unsigned HalfEltsPerLane = NumEltsPerLane / 2; Ops.push_back(N0); if (!IsUnary) Ops.push_back(N1); - for (unsigned Lane = 0; Lane != NumLanes; ++Lane) { - for (unsigned Elt = 0; Elt != HalfEltsPerLane; ++Elt) - Mask.push_back((Elt * 2) + (Lane * NumEltsPerLane)); - for (unsigned Elt = 0; Elt != HalfEltsPerLane; ++Elt) - Mask.push_back((Elt * 2) + (Lane * NumEltsPerLane) + Offset); - } + createPackShuffleMask(VT, Mask, IsUnary); return true; } case X86ISD::VSHLI: -- 2.50.0