Prevent a crash in debug dumps.
[oota-llvm.git] / lib / VMCore / Constants.cpp
index e15e68a73d56b17c4cb9d8a3ca2b0e35e0440a30..530f7ba61aa5a4ac568584c366aa9a6540d75c65 100644 (file)
@@ -551,7 +551,7 @@ public:
     Op<0>() = Agg;
   }
 
-  /// Indicies - These identify which value to extract.
+  /// Indices - These identify which value to extract.
   const SmallVector<unsigned, 4> Indices;
 
   /// Transparently provide more efficient getOperand methods.
@@ -577,7 +577,7 @@ public:
     Op<1>() = Val;
   }
 
-  /// Indicies - These identify the position for the insertion.
+  /// Indices - These identify the position for the insertion.
   const SmallVector<unsigned, 4> Indices;
 
   /// Transparently provide more efficient getOperand methods.
@@ -2305,9 +2305,10 @@ Constant *ConstantExpr::getInsertValueTy(const Type *ReqTy, Constant *Agg,
          "insertvalue indices invalid!");
   assert(Agg->getType() == ReqTy &&
          "insertvalue type invalid!");
-
   assert(Agg->getType()->isFirstClassType() &&
          "Non-first-class type for constant InsertValue expression");
+  if (Constant *FC = ConstantFoldInsertValueInstruction(Agg, Val, Idxs, NumIdx))
+    return FC;          // Fold a few common cases...
   // Look up the constant in the table first to ensure uniqueness
   std::vector<Constant*> ArgVec;
   ArgVec.push_back(Agg);
@@ -2336,10 +2337,12 @@ Constant *ConstantExpr::getExtractValueTy(const Type *ReqTy, Constant *Agg,
          "extractvalue indices invalid!");
   assert(Agg->getType()->isFirstClassType() &&
          "Non-first-class type for constant extractvalue expression");
+  if (Constant *FC = ConstantFoldExtractValueInstruction(Agg, Idxs, NumIdx))
+    return FC;          // Fold a few common cases...
   // Look up the constant in the table first to ensure uniqueness
   std::vector<Constant*> ArgVec;
   ArgVec.push_back(Agg);
-  SmallVector<unsigned, 4> Indices;
+  SmallVector<unsigned, 4> Indices(Idxs, Idxs + NumIdx);
   const ExprMapKeyType Key(Instruction::ExtractValue, ArgVec, 0, Indices);
   return ExprConstants->getOrCreate(ReqTy, Key);
 }