Add a comment to describe why vector shuffles are legalized to custom DAG nodes.
[oota-llvm.git] / lib / VMCore / Constants.cpp
index 89578fb8972e40c7da28b508340cef430c8ad4e1..0bff5786b8355000b769d2efc85fc8e38c539f55 100644 (file)
@@ -605,9 +605,21 @@ Constant* ConstantVector::get(Constant* const* Vals, unsigned NumVals) {
   return get(std::vector<Constant*>(Vals, Vals+NumVals));
 }
 
+Constant* ConstantExpr::getNSWAdd(Constant* C1, Constant* C2) {
+  Constant *C = getAdd(C1, C2);
+  // Set nsw attribute, assuming constant folding didn't eliminate the
+  // Add.
+  if (AddOperator *Add = dyn_cast<AddOperator>(C))
+    Add->setHasNoSignedOverflow(true);
+  return C;
+}
+
 Constant* ConstantExpr::getExactSDiv(Constant* C1, Constant* C2) {
   Constant *C = getSDiv(C1, C2);
-  cast<SDivOperator>(C)->setIsExact(true);
+  // Set exact attribute, assuming constant folding didn't eliminate the
+  // SDiv.
+  if (SDivOperator *SDiv = dyn_cast<SDivOperator>(C))
+    SDiv->setIsExact(true);
   return C;
 }
 
@@ -1442,14 +1454,11 @@ Constant *ConstantExpr::getGetElementPtr(Constant *C, Value* const *Idxs,
 Constant *ConstantExpr::getInBoundsGetElementPtr(Constant *C,
                                                  Value* const *Idxs,
                                                  unsigned NumIdx) {
-  // Get the result type of the getelementptr!
-  const Type *Ty =
-    GetElementPtrInst::getIndexedType(C->getType(), Idxs, Idxs+NumIdx);
-  assert(Ty && "GEP indices invalid!");
-  unsigned As = cast<PointerType>(C->getType())->getAddressSpace();
-  Constant *Result = getGetElementPtrTy(PointerType::get(Ty, As), C,
-                                        Idxs, NumIdx);
-  cast<GEPOperator>(Result)->setIsInBounds(true);
+  Constant *Result = getGetElementPtr(C, Idxs, NumIdx);
+  // Set in bounds attribute, assuming constant folding didn't eliminate the
+  // GEP.
+  if (GEPOperator *GEP = dyn_cast<GEPOperator>(Result))
+    GEP->setIsInBounds(true);
   return Result;
 }