diff options
author | Chris Lattner <sabre@nondot.org> | 2012-01-26 02:54:54 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2012-01-26 02:54:54 +0000 |
commit | 71a494d6974f5105f008601a3e7c7474bf508139 (patch) | |
tree | 172d6404bd8f7ccc1adae7f952258dad4be92b67 /lib/VMCore | |
parent | 56243b89e7d5072d2d5498f806679d19ea483dac (diff) | |
download | external_llvm-71a494d6974f5105f008601a3e7c7474bf508139.zip external_llvm-71a494d6974f5105f008601a3e7c7474bf508139.tar.gz external_llvm-71a494d6974f5105f008601a3e7c7474bf508139.tar.bz2 |
simplify by using ShuffleVectorInst::getMaskValue.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@149029 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore')
-rw-r--r-- | lib/VMCore/ConstantFold.cpp | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/lib/VMCore/ConstantFold.cpp b/lib/VMCore/ConstantFold.cpp index abc019f..9c2919e 100644 --- a/lib/VMCore/ConstantFold.cpp +++ b/lib/VMCore/ConstantFold.cpp @@ -787,24 +787,22 @@ Constant *llvm::ConstantFoldShuffleVectorInstruction(Constant *V1, // Undefined shuffle mask -> undefined value. if (isa<UndefValue>(Mask)) return UndefValue::get(V1->getType()); - unsigned MaskNumElts = cast<VectorType>(Mask->getType())->getNumElements(); - unsigned SrcNumElts = cast<VectorType>(V1->getType())->getNumElements(); - Type *EltTy = cast<VectorType>(V1->getType())->getElementType(); + unsigned MaskNumElts = Mask->getType()->getVectorNumElements(); + unsigned SrcNumElts = V1->getType()->getVectorNumElements(); + Type *EltTy = V1->getType()->getVectorElementType(); // Loop over the shuffle mask, evaluating each element. SmallVector<Constant*, 32> Result; for (unsigned i = 0; i != MaskNumElts; ++i) { - Constant *InElt = Mask->getAggregateElement(i); - if (InElt == 0) return 0; - - if (isa<UndefValue>(InElt)) { + int Elt = ShuffleVectorInst::getMaskValue(Mask, i); + if (Elt == -1) { Result.push_back(UndefValue::get(EltTy)); continue; } - unsigned Elt = cast<ConstantInt>(InElt)->getZExtValue(); - if (Elt >= SrcNumElts*2) + Constant *InElt; + if (unsigned(Elt) >= SrcNumElts*2) InElt = UndefValue::get(EltTy); - else if (Elt >= SrcNumElts) + else if (unsigned(Elt) >= SrcNumElts) InElt = V2->getAggregateElement(Elt - SrcNumElts); else InElt = V1->getAggregateElement(Elt); |