Add ConstantExpr::get(Sign|Zero)Extend methods


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12648 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/VMCore/Constants.cpp b/lib/VMCore/Constants.cpp
index 6c6557d..3ed7008 100644
--- a/lib/VMCore/Constants.cpp
+++ b/lib/VMCore/Constants.cpp
@@ -1131,6 +1131,22 @@
   return ExprConstants.getOrCreate(Ty, Key);
 }
 
+Constant *ConstantExpr::getSignExtend(Constant *C, const Type *Ty) {
+  assert(C->getType()->isInteger() && Ty->isInteger() &&
+         C->getType()->getPrimitiveSize() <= Ty->getPrimitiveSize() &&
+         "This is an illegal sign extension!");
+  C = ConstantExpr::getCast(C, C->getType()->getSignedVersion());
+  return ConstantExpr::getCast(C, Ty);
+}
+
+Constant *ConstantExpr::getZeroExtend(Constant *C, const Type *Ty) {
+  assert(C->getType()->isInteger() && Ty->isInteger() &&
+         C->getType()->getPrimitiveSize() <= Ty->getPrimitiveSize() &&
+         "This is an illegal zero extension!");
+  C = ConstantExpr::getCast(C, C->getType()->getUnsignedVersion());
+  return ConstantExpr::getCast(C, Ty);
+}
+
 Constant *ConstantExpr::getTy(const Type *ReqTy, unsigned Opcode,
                               Constant *C1, Constant *C2) {
   if (Opcode == Instruction::Shl || Opcode == Instruction::Shr)