diff options
author | Mon P Wang <wangmp@apple.com> | 2008-11-10 04:46:22 +0000 |
---|---|---|
committer | Mon P Wang <wangmp@apple.com> | 2008-11-10 04:46:22 +0000 |
commit | aeb06d246254e4829a49164a11eacced9a43d9d4 (patch) | |
tree | 4b957844db686ae68329005faa6762317429037f /lib/VMCore/ConstantFold.cpp | |
parent | a64f463fb90c66406033e3fd1dc912b648bad328 (diff) | |
download | external_llvm-aeb06d246254e4829a49164a11eacced9a43d9d4.zip external_llvm-aeb06d246254e4829a49164a11eacced9a43d9d4.tar.gz external_llvm-aeb06d246254e4829a49164a11eacced9a43d9d4.tar.bz2 |
Added support for the following definition of shufflevector
<result> = shufflevector <n x <ty>> <v1>, <n x <ty>> <v2>, <m x i32> <mask>
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@58964 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore/ConstantFold.cpp')
-rw-r--r-- | lib/VMCore/ConstantFold.cpp | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/lib/VMCore/ConstantFold.cpp b/lib/VMCore/ConstantFold.cpp index d84eb2d..9fa41b3 100644 --- a/lib/VMCore/ConstantFold.cpp +++ b/lib/VMCore/ConstantFold.cpp @@ -424,24 +424,25 @@ Constant *llvm::ConstantFoldShuffleVectorInstruction(const Constant *V1, const Constant *Mask) { // Undefined shuffle mask -> undefined value. if (isa<UndefValue>(Mask)) return UndefValue::get(V1->getType()); - - unsigned NumElts = cast<VectorType>(V1->getType())->getNumElements(); + + unsigned MaskNumElts = cast<VectorType>(Mask->getType())->getNumElements(); + unsigned SrcNumElts = cast<VectorType>(V1->getType())->getNumElements(); const Type *EltTy = cast<VectorType>(V1->getType())->getElementType(); - + // Loop over the shuffle mask, evaluating each element. SmallVector<Constant*, 32> Result; - for (unsigned i = 0; i != NumElts; ++i) { + for (unsigned i = 0; i != MaskNumElts; ++i) { Constant *InElt = GetVectorElement(Mask, i); if (InElt == 0) return 0; - + if (isa<UndefValue>(InElt)) InElt = UndefValue::get(EltTy); else if (ConstantInt *CI = dyn_cast<ConstantInt>(InElt)) { unsigned Elt = CI->getZExtValue(); - if (Elt >= NumElts*2) + if (Elt >= SrcNumElts*2) InElt = UndefValue::get(EltTy); - else if (Elt >= NumElts) - InElt = GetVectorElement(V2, Elt-NumElts); + else if (Elt >= SrcNumElts) + InElt = GetVectorElement(V2, Elt - SrcNumElts); else InElt = GetVectorElement(V1, Elt); if (InElt == 0) return 0; @@ -451,7 +452,7 @@ Constant *llvm::ConstantFoldShuffleVectorInstruction(const Constant *V1, } Result.push_back(InElt); } - + return ConstantVector::get(&Result[0], Result.size()); } |