Fix ConstantFoldShuffleVectorInstruction to properly handle the case
authorChris Lattner <sabre@nondot.org>
Mon, 30 Jan 2012 05:34:13 +0000 (05:34 +0000)
committerChris Lattner <sabre@nondot.org>
Mon, 30 Jan 2012 05:34:13 +0000 (05:34 +0000)
when the result type has a different # elements than the input vectors.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@149221 91177308-0d34-0410-b5e6-96231b3b80d8

lib/VMCore/ConstantFold.cpp

index 36bd4aba4b1c8be4f50f62610308f0b073195f88..f73e7a76d1a59797ad5dd87c62928c1ebe53683a 100644 (file)
@@ -794,15 +794,17 @@ Constant *llvm::ConstantFoldInsertElementInstruction(Constant *Val,
 Constant *llvm::ConstantFoldShuffleVectorInstruction(Constant *V1,
                                                      Constant *V2,
                                                      Constant *Mask) {
+  unsigned MaskNumElts = Mask->getType()->getVectorNumElements();
+  Type *EltTy = V1->getType()->getVectorElementType();
+
   // Undefined shuffle mask -> undefined value.
-  if (isa<UndefValue>(Mask)) return UndefValue::get(V1->getType());
+  if (isa<UndefValue>(Mask))
+    return UndefValue::get(VectorType::get(EltTy, MaskNumElts));
 
   // Don't break the bitcode reader hack.
   if (isa<ConstantExpr>(Mask)) return 0;
   
-  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;