summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Target/X86/Utils/X86ShuffleDecode.cpp
diff options
context:
space:
mode:
authorDavid Majnemer <david.majnemer@gmail.com>2015-01-11 07:29:51 +0000
committerDavid Majnemer <david.majnemer@gmail.com>2015-01-11 07:29:51 +0000
commit14141f941ab72c340915122bc777027806f7e1b2 (patch)
tree4dba7c232ea1a5ad10396441385610cb84f4363d /llvm/lib/Target/X86/Utils/X86ShuffleDecode.cpp
parent9317900590d93778bc62c185d5aef8ec86fb420d (diff)
downloadbcm5719-llvm-14141f941ab72c340915122bc777027806f7e1b2.tar.gz
bcm5719-llvm-14141f941ab72c340915122bc777027806f7e1b2.zip
Revert most of r225597
We can't rely on a DataLayout enlightened constant folder. llvm-svn: 225599
Diffstat (limited to 'llvm/lib/Target/X86/Utils/X86ShuffleDecode.cpp')
-rw-r--r--llvm/lib/Target/X86/Utils/X86ShuffleDecode.cpp77
1 files changed, 30 insertions, 47 deletions
diff --git a/llvm/lib/Target/X86/Utils/X86ShuffleDecode.cpp b/llvm/lib/Target/X86/Utils/X86ShuffleDecode.cpp
index 6d5ee4dc516..e4c58d42c5d 100644
--- a/llvm/lib/Target/X86/Utils/X86ShuffleDecode.cpp
+++ b/llvm/lib/Target/X86/Utils/X86ShuffleDecode.cpp
@@ -13,10 +13,7 @@
//===----------------------------------------------------------------------===//
#include "X86ShuffleDecode.h"
-#include "llvm/Analysis/ConstantFolding.h"
#include "llvm/IR/Constants.h"
-#include "llvm/IR/DataLayout.h"
-#include "llvm/IR/InstrTypes.h"
#include "llvm/CodeGen/MachineValueType.h"
//===----------------------------------------------------------------------===//
@@ -256,8 +253,7 @@ void DecodeVPERM2X128Mask(MVT VT, unsigned Imm,
}
}
-void DecodePSHUFBMask(const Constant *C, const DataLayout *TD,
- SmallVectorImpl<int> &ShuffleMask) {
+void DecodePSHUFBMask(const Constant *C, SmallVectorImpl<int> &ShuffleMask) {
Type *MaskTy = C->getType();
// It is not an error for the PSHUFB mask to not be a vector of i8 because the
// constant pool uniques constants by their bit representation.
@@ -266,56 +262,43 @@ void DecodePSHUFBMask(const Constant *C, const DataLayout *TD,
//
// <2 x i64> <i64 -9223372034707292160, i64 -9223372034707292160>
//
- // <4 x i32> <i32 -2147483648, i32 -2147483648, i32 -2147483648, i32
- // -2147483648>
+ // <4 x i32> <i32 -2147483648, i32 -2147483648,
+ // i32 -2147483648, i32 -2147483648>
unsigned MaskTySize = MaskTy->getPrimitiveSizeInBits();
- VectorType *DestTy = nullptr;
- if (MaskTySize == 128)
- DestTy = VectorType::get(Type::getInt8Ty(MaskTy->getContext()), 16);
- else if (MaskTySize == 256)
- DestTy = VectorType::get(Type::getInt8Ty(MaskTy->getContext()), 32);
-
- // FIXME: Add support for AVX-512.
- if (!DestTy)
+ if (MaskTySize != 128 && MaskTySize != 256) // FIXME: Add support for AVX-512.
return;
- if (DestTy != MaskTy) {
- if (!CastInst::castIsValid(Instruction::BitCast, const_cast<Constant *>(C),
- DestTy))
- return;
-
- C = ConstantFoldInstOperands(Instruction::BitCast, DestTy,
- const_cast<Constant *>(C), TD);
- MaskTy = DestTy;
- }
+ // This is a straightforward byte vector.
+ if (MaskTy->isVectorTy() && MaskTy->getVectorElementType()->isIntegerTy(8)) {
+ int NumElements = MaskTy->getVectorNumElements();
+ ShuffleMask.reserve(NumElements);
- int NumElements = MaskTy->getVectorNumElements();
- ShuffleMask.reserve(NumElements);
-
- for (int i = 0; i < NumElements; ++i) {
- // For AVX vectors with 32 bytes the base of the shuffle is the 16-byte
- // lane of the vector we're inside.
- int Base = i < 16 ? 0 : 16;
- Constant *COp = C->getAggregateElement(i);
- if (!COp) {
- ShuffleMask.clear();
- return;
- } else if (isa<UndefValue>(COp)) {
- ShuffleMask.push_back(SM_SentinelUndef);
- continue;
- }
- uint64_t Element = cast<ConstantInt>(COp)->getZExtValue();
- // If the high bit (7) of the byte is set, the element is zeroed.
- if (Element & (1 << 7))
- ShuffleMask.push_back(SM_SentinelZero);
- else {
- // Only the least significant 4 bits of the byte are used.
- int Index = Base + (Element & 0xf);
- ShuffleMask.push_back(Index);
+ for (int i = 0; i < NumElements; ++i) {
+ // For AVX vectors with 32 bytes the base of the shuffle is the 16-byte
+ // lane of the vector we're inside.
+ int Base = i < 16 ? 0 : 16;
+ Constant *COp = C->getAggregateElement(i);
+ if (!COp) {
+ ShuffleMask.clear();
+ return;
+ } else if (isa<UndefValue>(COp)) {
+ ShuffleMask.push_back(SM_SentinelUndef);
+ continue;
+ }
+ uint64_t Element = cast<ConstantInt>(COp)->getZExtValue();
+ // If the high bit (7) of the byte is set, the element is zeroed.
+ if (Element & (1 << 7))
+ ShuffleMask.push_back(SM_SentinelZero);
+ else {
+ // Only the least significant 4 bits of the byte are used.
+ int Index = Base + (Element & 0xf);
+ ShuffleMask.push_back(Index);
+ }
}
}
+ // TODO: Handle funny-looking vectors too.
}
void DecodePSHUFBMask(ArrayRef<uint64_t> RawMask,
OpenPOWER on IntegriCloud