Allow getZeroExtend and getSignExtend to work with boolean inputs.
authorChris Lattner <sabre@nondot.org>
Sat, 1 Jan 2005 15:59:57 +0000 (15:59 +0000)
committerChris Lattner <sabre@nondot.org>
Sat, 1 Jan 2005 15:59:57 +0000 (15:59 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@19210 91177308-0d34-0410-b5e6-96231b3b80d8

lib/VMCore/Constants.cpp

index f09e3b94bb55046f56efa052391a6e3b44c20069..b5de27803366c936ce7076917aaeecfbf1f1de84 100644 (file)
@@ -1239,18 +1239,26 @@ Constant *ConstantExpr::getCast(Constant *C, const Type *Ty) {
 }
 
 Constant *ConstantExpr::getSignExtend(Constant *C, const Type *Ty) {
-  assert(C->getType()->isInteger() && Ty->isInteger() &&
+  assert(C->getType()->isIntegral() && Ty->isIntegral() &&
          C->getType()->getPrimitiveSize() <= Ty->getPrimitiveSize() &&
          "This is an illegal sign extension!");
-  C = ConstantExpr::getCast(C, C->getType()->getSignedVersion());
-  return ConstantExpr::getCast(C, Ty);
+  if (C->getType() != Type::BoolTy) {
+    C = ConstantExpr::getCast(C, C->getType()->getSignedVersion());
+    return ConstantExpr::getCast(C, Ty);
+  } else {
+    if (C == ConstantBool::True)
+      return ConstantIntegral::getAllOnesValue(Ty);
+    else
+      return ConstantIntegral::getNullValue(Ty);
+  }
 }
 
 Constant *ConstantExpr::getZeroExtend(Constant *C, const Type *Ty) {
-  assert(C->getType()->isInteger() && Ty->isInteger() &&
+  assert(C->getType()->isIntegral() && Ty->isIntegral() &&
          C->getType()->getPrimitiveSize() <= Ty->getPrimitiveSize() &&
          "This is an illegal zero extension!");
-  C = ConstantExpr::getCast(C, C->getType()->getUnsignedVersion());
+  if (C->getType() != Type::BoolTy)
+    C = ConstantExpr::getCast(C, C->getType()->getUnsignedVersion());
   return ConstantExpr::getCast(C, Ty);
 }