[llvm-commits] [llvm] r55694 - /llvm/trunk/lib/VMCore/ConstantFold.cpp

Nick Lewycky nicholas at mxc.ca
Tue Sep 2 23:48:55 PDT 2008


Author: nicholas
Date: Wed Sep  3 01:48:55 2008
New Revision: 55694

URL: http://llvm.org/viewvc/llvm-project?rev=55694&view=rev
Log:
Try to fold each element of a vector. This is needed to maintain structural
equivalence.

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=55694&r1=55693&r2=55694&view=diff

==============================================================================
--- llvm/trunk/lib/VMCore/ConstantFold.cpp (original)
+++ llvm/trunk/lib/VMCore/ConstantFold.cpp Wed Sep  3 01:48:55 2008
@@ -238,12 +238,8 @@
       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 @@
       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;





More information about the llvm-commits mailing list