diff options
author | Chandler Carruth <chandlerc@gmail.com> | 2014-07-25 23:47:11 +0000 |
---|---|---|
committer | Chandler Carruth <chandlerc@gmail.com> | 2014-07-25 23:47:11 +0000 |
commit | 185cc18d4265b2822956c91ba65622d8256fdcec (patch) | |
tree | fb0f34f27b604f601514b502da4167c25a0f98ad /llvm/lib/Target/X86/Utils/X86ShuffleDecode.cpp | |
parent | c824458e81db8fdd0d0ca11f906d68ff406b6f9c (diff) | |
download | llvm-185cc18d4265b2822956c91ba65622d8256fdcec.zip llvm-185cc18d4265b2822956c91ba65622d8256fdcec.tar.gz llvm-185cc18d4265b2822956c91ba65622d8256fdcec.tar.bz2 |
[x86] Teach the X86 backend to print shuffle comments for PSHUFB
instructions which happen to have a constant mask.
Currently, this only handles a very narrow set of cases, but those
happen to be the cases that I care about for testing shuffles sanely.
This is a bit trickier than other shuffle instructions because we're
decoding constants out of the constant pool. The current MC layer makes
it completely impossible to inspect a constant pool entry, so we have to
do it at the MI level and attach the comment to the streamer on its way
out. So no joy for disassembling, but it does make test cases and asm
dumps *much* nicer.
Sorry for no test cases, but it didn't really seem that valuable to go
trolling through existing old test cases and updating them. I'll have
lots of testing of this in the upcoming patch for SSSE3 emission in the
new vector shuffle lowering code paths.
llvm-svn: 213986
Diffstat (limited to 'llvm/lib/Target/X86/Utils/X86ShuffleDecode.cpp')
-rw-r--r-- | llvm/lib/Target/X86/Utils/X86ShuffleDecode.cpp | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/llvm/lib/Target/X86/Utils/X86ShuffleDecode.cpp b/llvm/lib/Target/X86/Utils/X86ShuffleDecode.cpp index 5f2441c..869ef0e 100644 --- a/llvm/lib/Target/X86/Utils/X86ShuffleDecode.cpp +++ b/llvm/lib/Target/X86/Utils/X86ShuffleDecode.cpp @@ -13,6 +13,7 @@ //===----------------------------------------------------------------------===// #include "X86ShuffleDecode.h" +#include "llvm/IR/Constants.h" #include "llvm/CodeGen/MachineValueType.h" //===----------------------------------------------------------------------===// @@ -207,6 +208,38 @@ void DecodeVPERM2X128Mask(MVT VT, unsigned Imm, } } +/// \brief Decode PSHUFB masks stored in an LLVM Constant. +void DecodePSHUFBMask(const ConstantDataSequential *C, + SmallVectorImpl<int> &ShuffleMask) { + Type *MaskTy = C->getType(); + assert(MaskTy->isVectorTy() && "Expected a vector constant mask!"); + Type *EltTy = MaskTy->getVectorElementType(); + assert(EltTy->isIntegerTy(8) && "Expected i8 constant mask elements!"); + int NumElements = MaskTy->getVectorNumElements(); + // FIXME: Add support for AVX-512. + assert((NumElements == 16 || NumElements == 32) && + "Only 128-bit and 256-bit vectors supported!"); + assert((unsigned)NumElements == C->getNumElements() && + "Constant mask has a different number of elements!"); + + ShuffleMask.reserve(NumElements); + for (int i = 0; i < NumElements; ++i) { + // For AVX vectors with 32 bytes the base of the shuffle is the half of the + // vector we're inside. + int Base = i < 16 ? 0 : 16; + uint64_t Element = C->getElementAsInteger(i); + // If the high bit (7) of the byte is set, the element is zeroed. + if (Element & (1 << 7)) + ShuffleMask.push_back(SM_SentinelZero); + else { + int Index = Base + Element; + assert((Index >= 0 && Index < NumElements) || + "Out of bounds shuffle index for pshub instruction!"); + ShuffleMask.push_back(Index); + } + } +} + /// DecodeVPERMMask - this decodes the shuffle masks for VPERMQ/VPERMPD. /// No VT provided since it only works on 256-bit, 4 element vectors. void DecodeVPERMMask(unsigned Imm, SmallVectorImpl<int> &ShuffleMask) { |