Fix a latent bug exposed by my recent changes
authorChris Lattner <sabre@nondot.org>
Wed, 4 Aug 2004 18:50:09 +0000 (18:50 +0000)
committerChris Lattner <sabre@nondot.org>
Wed, 4 Aug 2004 18:50:09 +0000 (18:50 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@15498 91177308-0d34-0410-b5e6-96231b3b80d8

lib/VMCore/Constants.cpp

index f679f2350819a51ed6088dbdeedf685a9b613c37..b65758b7dd504f7aecef7f32b2b3fc246d154bfa 100644 (file)
@@ -1109,7 +1109,8 @@ Constant *ConstantExpr::getTy(const Type *ReqTy, unsigned Opcode,
   assert(C1->getType() == C2->getType() &&
          "Operand types in binary constant expression should match");
 
-  if (ReqTy == C1->getType())
+  if (ReqTy == C1->getType() || (Instruction::isRelational(Opcode) &&
+                                 ReqTy == Type::BoolTy))
     if (Constant *FC = ConstantFoldBinaryInstruction(Opcode, C1, C2))
       return FC;          // Fold a few common cases...
 
@@ -1118,6 +1119,13 @@ Constant *ConstantExpr::getTy(const Type *ReqTy, unsigned Opcode,
   return ExprConstants.getOrCreate(ReqTy, Key);
 }
 
+Constant *ConstantExpr::get(unsigned Opcode, Constant *C1, Constant *C2) {
+  if (Instruction::isRelational(Opcode))
+    return getTy(Type::BoolTy, Opcode, C1, C2);
+  else
+    return getTy(C1->getType(), Opcode, C1, C2);
+}
+
 Constant *ConstantExpr::getSelectTy(const Type *ReqTy, Constant *C,
                                     Constant *V1, Constant *V2) {
   assert(C->getType() == Type::BoolTy && "Select condition must be bool!");