[llvm-commits] [llvm] r149029 - /llvm/trunk/lib/VMCore/ConstantFold.cpp
Chris Lattner
sabre at nondot.org
Wed Jan 25 18:54:54 PST 2012
Author: lattner
Date: Wed Jan 25 20:54:54 2012
New Revision: 149029
URL: http://llvm.org/viewvc/llvm-project?rev=149029&view=rev
Log:
simplify by using ShuffleVectorInst::getMaskValue.
Modified:
llvm/trunk/lib/VMCore/ConstantFold.cpp
Modified: llvm/trunk/lib/VMCore/ConstantFold.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/ConstantFold.cpp?rev=149029&r1=149028&r2=149029&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/ConstantFold.cpp (original)
+++ llvm/trunk/lib/VMCore/ConstantFold.cpp Wed Jan 25 20:54:54 2012
@@ -787,24 +787,22 @@
// 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);
More information about the llvm-commits
mailing list