diff options
Diffstat (limited to 'contrib/llvm/lib/Target/X86/X86ShuffleDecodeConstantPool.cpp')
-rw-r--r-- | contrib/llvm/lib/Target/X86/X86ShuffleDecodeConstantPool.cpp | 78 |
1 files changed, 48 insertions, 30 deletions
diff --git a/contrib/llvm/lib/Target/X86/X86ShuffleDecodeConstantPool.cpp b/contrib/llvm/lib/Target/X86/X86ShuffleDecodeConstantPool.cpp index 1111552..2cebb76 100644 --- a/contrib/llvm/lib/Target/X86/X86ShuffleDecodeConstantPool.cpp +++ b/contrib/llvm/lib/Target/X86/X86ShuffleDecodeConstantPool.cpp @@ -14,7 +14,7 @@ #include "X86ShuffleDecodeConstantPool.h" #include "Utils/X86ShuffleDecode.h" -#include "llvm/ADT/SmallBitVector.h" +#include "llvm/ADT/APInt.h" #include "llvm/CodeGen/MachineValueType.h" #include "llvm/IR/Constants.h" @@ -25,7 +25,7 @@ namespace llvm { static bool extractConstantMask(const Constant *C, unsigned MaskEltSizeInBits, - SmallBitVector &UndefElts, + APInt &UndefElts, SmallVectorImpl<uint64_t> &RawMask) { // It is not an error for shuffle masks to not be a vector of // MaskEltSizeInBits because the constant pool uniques constants by their @@ -49,6 +49,33 @@ static bool extractConstantMask(const Constant *C, unsigned MaskEltSizeInBits, unsigned CstEltSizeInBits = CstTy->getScalarSizeInBits(); unsigned NumCstElts = CstTy->getVectorNumElements(); + assert((CstSizeInBits % MaskEltSizeInBits) == 0 && + "Unaligned shuffle mask size"); + + unsigned NumMaskElts = CstSizeInBits / MaskEltSizeInBits; + UndefElts = APInt(NumMaskElts, 0); + RawMask.resize(NumMaskElts, 0); + + // Fast path - if the constants match the mask size then copy direct. + if (MaskEltSizeInBits == CstEltSizeInBits) { + assert(NumCstElts == NumMaskElts && "Unaligned shuffle mask size"); + for (unsigned i = 0; i != NumMaskElts; ++i) { + Constant *COp = C->getAggregateElement(i); + if (!COp || (!isa<UndefValue>(COp) && !isa<ConstantInt>(COp))) + return false; + + if (isa<UndefValue>(COp)) { + UndefElts.setBit(i); + RawMask[i] = 0; + continue; + } + + auto *Elt = cast<ConstantInt>(COp); + RawMask[i] = Elt->getValue().getZExtValue(); + } + return true; + } + // Extract all the undef/constant element data and pack into single bitsets. APInt UndefBits(CstSizeInBits, 0); APInt MaskBits(CstSizeInBits, 0); @@ -57,39 +84,30 @@ static bool extractConstantMask(const Constant *C, unsigned MaskEltSizeInBits, if (!COp || (!isa<UndefValue>(COp) && !isa<ConstantInt>(COp))) return false; + unsigned BitOffset = i * CstEltSizeInBits; + if (isa<UndefValue>(COp)) { - APInt EltUndef = APInt::getLowBitsSet(CstSizeInBits, CstEltSizeInBits); - UndefBits |= EltUndef.shl(i * CstEltSizeInBits); + UndefBits.setBits(BitOffset, BitOffset + CstEltSizeInBits); continue; } - APInt EltBits = cast<ConstantInt>(COp)->getValue(); - EltBits = EltBits.zextOrTrunc(CstSizeInBits); - MaskBits |= EltBits.shl(i * CstEltSizeInBits); + MaskBits.insertBits(cast<ConstantInt>(COp)->getValue(), BitOffset); } // Now extract the undef/constant bit data into the raw shuffle masks. - assert((CstSizeInBits % MaskEltSizeInBits) == 0 && - "Unaligned shuffle mask size"); - - unsigned NumMaskElts = CstSizeInBits / MaskEltSizeInBits; - UndefElts = SmallBitVector(NumMaskElts, false); - RawMask.resize(NumMaskElts, 0); - for (unsigned i = 0; i != NumMaskElts; ++i) { - APInt EltUndef = UndefBits.lshr(i * MaskEltSizeInBits); - EltUndef = EltUndef.zextOrTrunc(MaskEltSizeInBits); + unsigned BitOffset = i * MaskEltSizeInBits; + APInt EltUndef = UndefBits.extractBits(MaskEltSizeInBits, BitOffset); // Only treat the element as UNDEF if all bits are UNDEF, otherwise // treat it as zero. if (EltUndef.isAllOnesValue()) { - UndefElts[i] = true; + UndefElts.setBit(i); RawMask[i] = 0; continue; } - APInt EltBits = MaskBits.lshr(i * MaskEltSizeInBits); - EltBits = EltBits.zextOrTrunc(MaskEltSizeInBits); + APInt EltBits = MaskBits.extractBits(MaskEltSizeInBits, BitOffset); RawMask[i] = EltBits.getZExtValue(); } @@ -104,8 +122,8 @@ void DecodePSHUFBMask(const Constant *C, SmallVectorImpl<int> &ShuffleMask) { "Unexpected vector size."); // The shuffle mask requires a byte vector. - SmallBitVector UndefElts; - SmallVector<uint64_t, 32> RawMask; + APInt UndefElts; + SmallVector<uint64_t, 64> RawMask; if (!extractConstantMask(C, 8, UndefElts, RawMask)) return; @@ -145,8 +163,8 @@ void DecodeVPERMILPMask(const Constant *C, unsigned ElSize, assert((ElSize == 32 || ElSize == 64) && "Unexpected vector element size."); // The shuffle mask requires elements the same size as the target. - SmallBitVector UndefElts; - SmallVector<uint64_t, 8> RawMask; + APInt UndefElts; + SmallVector<uint64_t, 16> RawMask; if (!extractConstantMask(C, ElSize, UndefElts, RawMask)) return; @@ -180,7 +198,7 @@ void DecodeVPERMIL2PMask(const Constant *C, unsigned M2Z, unsigned ElSize, assert((MaskTySize == 128 || MaskTySize == 256) && "Unexpected vector size."); // The shuffle mask requires elements the same size as the target. - SmallBitVector UndefElts; + APInt UndefElts; SmallVector<uint64_t, 8> RawMask; if (!extractConstantMask(C, ElSize, UndefElts, RawMask)) return; @@ -231,8 +249,8 @@ void DecodeVPPERMMask(const Constant *C, SmallVectorImpl<int> &ShuffleMask) { "Unexpected vector size."); // The shuffle mask requires a byte vector. - SmallBitVector UndefElts; - SmallVector<uint64_t, 32> RawMask; + APInt UndefElts; + SmallVector<uint64_t, 16> RawMask; if (!extractConstantMask(C, 8, UndefElts, RawMask)) return; @@ -286,8 +304,8 @@ void DecodeVPERMVMask(const Constant *C, unsigned ElSize, "Unexpected vector element size."); // The shuffle mask requires elements the same size as the target. - SmallBitVector UndefElts; - SmallVector<uint64_t, 8> RawMask; + APInt UndefElts; + SmallVector<uint64_t, 64> RawMask; if (!extractConstantMask(C, ElSize, UndefElts, RawMask)) return; @@ -314,8 +332,8 @@ void DecodeVPERMV3Mask(const Constant *C, unsigned ElSize, "Unexpected vector element size."); // The shuffle mask requires elements the same size as the target. - SmallBitVector UndefElts; - SmallVector<uint64_t, 8> RawMask; + APInt UndefElts; + SmallVector<uint64_t, 64> RawMask; if (!extractConstantMask(C, ElSize, UndefElts, RawMask)) return; |