[llvm-commits] [llvm] r53384 - /llvm/trunk/lib/VMCore/Constants.cpp

Chris Lattner sabre at nondot.org
Wed Jul 9 17:44:03 PDT 2008


Author: lattner
Date: Wed Jul  9 19:44:03 2008
New Revision: 53384

URL: http://llvm.org/viewvc/llvm-project?rev=53384&view=rev
Log:
SImplify ConstantVector::get a bit and make it turn a vector
of all undefs into a single undef value.

Modified:
    llvm/trunk/lib/VMCore/Constants.cpp

Modified: llvm/trunk/lib/VMCore/Constants.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Constants.cpp?rev=53384&r1=53383&r2=53384&view=diff

==============================================================================
--- llvm/trunk/lib/VMCore/Constants.cpp (original)
+++ llvm/trunk/lib/VMCore/Constants.cpp Wed Jul  9 19:44:03 2008
@@ -1498,16 +1498,26 @@
 
 Constant *ConstantVector::get(const VectorType *Ty,
                               const std::vector<Constant*> &V) {
-  // If this is an all-zero vector, return a ConstantAggregateZero object
-  if (!V.empty()) {
-    Constant *C = V[0];
-    if (!C->isNullValue())
-      return VectorConstants->getOrCreate(Ty, V);
+  assert(!V.empty() && "Vectors can't be empty");
+  // If this is an all-undef or alll-zero vector, return a
+  // ConstantAggregateZero or UndefValue.
+  Constant *C = V[0];
+  bool isZero = C->isNullValue();
+  bool isUndef = isa<UndefValue>(C);
+
+  if (isZero || isUndef) {
     for (unsigned i = 1, e = V.size(); i != e; ++i)
-      if (V[i] != C)
-        return VectorConstants->getOrCreate(Ty, V);
+      if (V[i] != C) {
+        isZero = isUndef = false;
+        break;
+      }
   }
-  return ConstantAggregateZero::get(Ty);
+  
+  if (isZero)
+    return ConstantAggregateZero::get(Ty);
+  if (isUndef)
+    return UndefValue::get(Ty);
+  return VectorConstants->getOrCreate(Ty, V);
 }
 
 Constant *ConstantVector::get(const std::vector<Constant*> &V) {





More information about the llvm-commits mailing list