Try to fold each element of a vector. This is needed to maintain structural
authorNick Lewycky <nicholas@mxc.ca>
Wed, 3 Sep 2008 06:48:55 +0000 (06:48 +0000)
committerNick Lewycky <nicholas@mxc.ca>
Wed, 3 Sep 2008 06:48:55 +0000 (06:48 +0000)
equivalence.

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

lib/VMCore/ConstantFold.cpp

index 25c756ab6e5b78b41c774370abb9233e978650fd..93cfccf1f5e672f7f06ecf02e9a4ef392de2f8bf 100644 (file)
@@ -238,12 +238,8 @@ Constant *llvm::ConstantFoldCastInstruction(unsigned opc, const Constant *V,
       std::vector<Constant*> res;
       const VectorType *DestVecTy = cast<VectorType>(DestTy);
       const Type *DstEltTy = DestVecTy->getElementType();
-      for (unsigned i = 0, e = CV->getType()->getNumElements(); i != e; ++i) {
-        Constant *C = ConstantFoldCastInstruction(opc, CV->getOperand(i),
-                                                  DstEltTy);
-        if (!C) return 0;       // Can't fold operand.
-        res.push_back(C);
-      }
+      for (unsigned i = 0, e = CV->getType()->getNumElements(); i != e; ++i)
+        res.push_back(ConstantExpr::getCast(opc, CV->getOperand(i), DstEltTy));
       return ConstantVector::get(DestVecTy, res);
     }
     return 0; // Can't fold.
@@ -271,12 +267,8 @@ Constant *llvm::ConstantFoldCastInstruction(unsigned opc, const Constant *V,
       std::vector<Constant*> res;
       const VectorType *DestVecTy = cast<VectorType>(DestTy);
       const Type *DstEltTy = DestVecTy->getElementType();
-      for (unsigned i = 0, e = CV->getType()->getNumElements(); i != e; ++i) {
-        Constant *C = ConstantFoldCastInstruction(opc, CV->getOperand(i),
-                                                  DstEltTy);
-        if (!C) return 0;       // Can't fold operand.
-        res.push_back(C);
-      }
+      for (unsigned i = 0, e = CV->getType()->getNumElements(); i != e; ++i)
+        res.push_back(ConstantExpr::getCast(opc, CV->getOperand(i), DstEltTy));
       return ConstantVector::get(DestVecTy, res);
     }
     return 0;