Implement review feedback for the ConstantBool->ConstantInt merge. Chris
authorReid Spencer <rspencer@reidspencer.com>
Fri, 12 Jan 2007 04:24:46 +0000 (04:24 +0000)
committerReid Spencer <rspencer@reidspencer.com>
Fri, 12 Jan 2007 04:24:46 +0000 (04:24 +0000)
recommended that getBoolValue be replaced with getZExtValue and that
get(bool) be replaced by get(const Type*, uint64_t). This implements
those changes.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@33110 91177308-0d34-0410-b5e6-96231b3b80d8

27 files changed:
include/llvm/Constants.h
lib/Analysis/BasicAliasAnalysis.cpp
lib/Analysis/ConstantRange.cpp
lib/Analysis/ScalarEvolution.cpp
lib/Bytecode/Reader/Reader.cpp
lib/Bytecode/Writer/Writer.cpp
lib/CodeGen/AsmPrinter.cpp
lib/CodeGen/MachineDebugInfo.cpp
lib/ExecutionEngine/ExecutionEngine.cpp
lib/ExecutionEngine/JIT/JIT.cpp
lib/Support/ConstantRange.cpp
lib/Target/CBackend/CBackend.cpp
lib/Transforms/IPO/GlobalOpt.cpp
lib/Transforms/Instrumentation/RSProfiling.cpp
lib/Transforms/Scalar/CondPropagate.cpp
lib/Transforms/Scalar/CorrelatedExprs.cpp
lib/Transforms/Scalar/InstructionCombining.cpp
lib/Transforms/Scalar/LoopUnswitch.cpp
lib/Transforms/Scalar/SCCP.cpp
lib/Transforms/Utils/CloneFunction.cpp
lib/Transforms/Utils/CodeExtractor.cpp
lib/Transforms/Utils/Local.cpp
lib/Transforms/Utils/SimplifyCFG.cpp
lib/VMCore/AsmWriter.cpp
lib/VMCore/ConstantFold.cpp
lib/VMCore/Constants.cpp
tools/llvm2cpp/CppWriter.cpp

index 337a62c5118bda728727462f0bd467dfcea0bfb3..dd85b43bc7ac558acf75984ce0b62ac51342ecb4 100644 (file)
@@ -85,10 +85,6 @@ public:
     return F = new ConstantInt(false);
   }
 
     return F = new ConstantInt(false);
   }
 
-  /// @brief Static factory method for getting a ConstantInt instance which
-  /// stands for a bool value.
-  static ConstantInt *get(bool Value) { return Value ? getTrue() : getFalse();}
-
   /// Return a ConstantInt with the specified value for the specified type. The
   /// value V will be canonicalized to a uint64_t but accessing it with either
   /// getSExtValue() or getZExtValue() (ConstantInt) will yield the correct
   /// Return a ConstantInt with the specified value for the specified type. The
   /// value V will be canonicalized to a uint64_t but accessing it with either
   /// getSExtValue() or getZExtValue() (ConstantInt) will yield the correct
@@ -96,22 +92,6 @@ public:
   /// @brief Get a ConstantInt for a specific value.
   static ConstantInt *get(const Type *Ty, int64_t V);
 
   /// @brief Get a ConstantInt for a specific value.
   static ConstantInt *get(const Type *Ty, int64_t V);
 
-  /// Returns the opposite value of this ConstantInt. 
-  /// @brief Get inverse value.
-  inline ConstantInt *inverted() const {
-    static ConstantInt *CI = 0;
-    if (CI) return CI; 
-    return CI = new ConstantInt(getType(), 
-                                Val ^ (getType() == Type::Int1Ty ? 1 : -1));
-  }
-
-  /// @returns the value of this ConstantInt only if it's a boolean type.
-  /// @brief return the boolean value of this constant.
-  inline bool getBoolValue() const { 
-    assert(getType() == Type::Int1Ty && "Should be a boolean constant!");
-    return static_cast<bool>(getZExtValue()); 
-  }
-
   /// This static method returns true if the type Ty is big enough to 
   /// represent the value V. This can be used to avoid having the get method 
   /// assert when V is larger than Ty can represent. Note that there are two
   /// This static method returns true if the type Ty is big enough to 
   /// represent the value V. This can be used to avoid having the get method 
   /// assert when V is larger than Ty can represent. Note that there are two
@@ -136,8 +116,7 @@ public:
   /// to true.
   /// @returns true iff this constant's bits are all set to true.
   /// @brief Determine if the value is all ones.
   /// to true.
   /// @returns true iff this constant's bits are all set to true.
   /// @brief Determine if the value is all ones.
-  virtual bool isAllOnesValue() const { 
-    if (getType() == Type::Int1Ty) return getBoolValue() == true;
+  bool isAllOnesValue() const { 
     return getSExtValue() == -1; 
   }
 
     return getSExtValue() == -1; 
   }
 
@@ -146,8 +125,7 @@ public:
   /// @returns true iff this is the largest value that may be represented 
   /// by this type.
   /// @brief Determine if the value is maximal.
   /// @returns true iff this is the largest value that may be represented 
   /// by this type.
   /// @brief Determine if the value is maximal.
-  virtual bool isMaxValue(bool isSigned) const {
-    if (getType() == Type::Int1Ty) return getBoolValue() == true;
+  bool isMaxValue(bool isSigned) const {
     if (isSigned) {
       int64_t V = getSExtValue();
       if (V < 0) return false;    // Be careful about wrap-around on 'long's
     if (isSigned) {
       int64_t V = getSExtValue();
       if (V < 0) return false;    // Be careful about wrap-around on 'long's
@@ -162,8 +140,7 @@ public:
   /// @returns true if this is the smallest value that may be represented by 
   /// this type.
   /// @brief Determine if the value is minimal.
   /// @returns true if this is the smallest value that may be represented by 
   /// this type.
   /// @brief Determine if the value is minimal.
-  virtual bool isMinValue(bool isSigned) const {
-    if (getType() == Type::Int1Ty) return getBoolValue() == false;
+  bool isMinValue(bool isSigned) const {
     if (isSigned) {
       int64_t V = getSExtValue();
       if (V > 0) return false;    // Be careful about wrap-around on 'long's
     if (isSigned) {
       int64_t V = getSExtValue();
       if (V > 0) return false;    // Be careful about wrap-around on 'long's
index ebe4cec60e4c53a83785374651529d062a0d1b0a..d49898a401cc33bd28a923d5fce35dab6546349b 100644 (file)
@@ -586,7 +586,7 @@ BasicAliasAnalysis::CheckGEPInstructions(
               Constant *Compare = ConstantExpr::getICmp(ICmpInst::ICMP_SGT, 
                                                         G1OC, G2OC);
               if (ConstantInt *CV = dyn_cast<ConstantInt>(Compare)) {
               Constant *Compare = ConstantExpr::getICmp(ICmpInst::ICMP_SGT, 
                                                         G1OC, G2OC);
               if (ConstantInt *CV = dyn_cast<ConstantInt>(Compare)) {
-                if (CV->getBoolValue())   // If they are comparable and G2 > G1
+                if (CV->getZExtValue())   // If they are comparable and G2 > G1
                   std::swap(GEP1Ops, GEP2Ops);  // Make GEP1 < GEP2
                 break;
               }
                   std::swap(GEP1Ops, GEP2Ops);  // Make GEP1 < GEP2
                 break;
               }
index 6c2dce03aa5733fa5523de40d895be84a1bebb5d..7a344201dd3e4125b612200494f55daae73eb2e2 100644 (file)
@@ -64,7 +64,7 @@ static ConstantInt *getMinValue(const Type *Ty, bool isSigned = false) {
 }
 static ConstantInt *Next(ConstantInt *CI) {
   if (CI->getType() == Type::Int1Ty)
 }
 static ConstantInt *Next(ConstantInt *CI) {
   if (CI->getType() == Type::Int1Ty)
-    return ConstantInt::get(!CI->getBoolValue());
+    return ConstantInt::get(Type::Int1Ty, !CI->getZExtValue());
 
   Constant *Result = ConstantExpr::getAdd(CI,
                                           ConstantInt::get(CI->getType(), 1));
 
   Constant *Result = ConstantExpr::getAdd(CI,
                                           ConstantInt::get(CI->getType(), 1));
@@ -75,14 +75,14 @@ static bool LT(ConstantInt *A, ConstantInt *B, bool isSigned) {
   Constant *C = ConstantExpr::getICmp(
     (isSigned ? ICmpInst::ICMP_SLT : ICmpInst::ICMP_ULT), A, B);
   assert(isa<ConstantInt>(C) && "Constant folding of integrals not impl??");
   Constant *C = ConstantExpr::getICmp(
     (isSigned ? ICmpInst::ICMP_SLT : ICmpInst::ICMP_ULT), A, B);
   assert(isa<ConstantInt>(C) && "Constant folding of integrals not impl??");
-  return cast<ConstantInt>(C)->getBoolValue();
+  return cast<ConstantInt>(C)->getZExtValue();
 }
 
 static bool LTE(ConstantInt *A, ConstantInt *B, bool isSigned) {
   Constant *C = ConstantExpr::getICmp(
     (isSigned ? ICmpInst::ICMP_SLE : ICmpInst::ICMP_ULE), A, B);
   assert(isa<ConstantInt>(C) && "Constant folding of integrals not impl??");
 }
 
 static bool LTE(ConstantInt *A, ConstantInt *B, bool isSigned) {
   Constant *C = ConstantExpr::getICmp(
     (isSigned ? ICmpInst::ICMP_SLE : ICmpInst::ICMP_ULE), A, B);
   assert(isa<ConstantInt>(C) && "Constant folding of integrals not impl??");
-  return cast<ConstantInt>(C)->getBoolValue();
+  return cast<ConstantInt>(C)->getZExtValue();
 }
 
 static bool GT(ConstantInt *A, ConstantInt *B, bool isSigned) { 
 }
 
 static bool GT(ConstantInt *A, ConstantInt *B, bool isSigned) { 
index ad16acc9b4009fe98b6bd1d5be1ffdbc7488a6b9..27c9e622ca85fad5025fe40177d3f8fc1dc18580 100644 (file)
@@ -1722,7 +1722,7 @@ ComputeLoadConstantCompareIterationCount(LoadInst *LI, Constant *RHS,
     // Evaluate the condition for this iteration.
     Result = ConstantExpr::getICmp(predicate, Result, RHS);
     if (!isa<ConstantInt>(Result)) break;  // Couldn't decide for sure
     // Evaluate the condition for this iteration.
     Result = ConstantExpr::getICmp(predicate, Result, RHS);
     if (!isa<ConstantInt>(Result)) break;  // Couldn't decide for sure
-    if (cast<ConstantInt>(Result)->getBoolValue() == false) {
+    if (cast<ConstantInt>(Result)->getZExtValue() == false) {
 #if 0
       cerr << "\n***\n*** Computed loop count " << *ItCst
            << "\n*** From global " << *GV << "*** BB: " << *L->getHeader()
 #if 0
       cerr << "\n***\n*** Computed loop count " << *ItCst
            << "\n*** From global " << *GV << "*** BB: " << *L->getHeader()
@@ -1932,7 +1932,7 @@ ComputeIterationCountExhaustively(const Loop *L, Value *Cond, bool ExitWhen) {
     // Couldn't symbolically evaluate.
     if (!CondVal || CondVal->getType() != Type::Int1Ty) return UnknownValue;
 
     // Couldn't symbolically evaluate.
     if (!CondVal || CondVal->getType() != Type::Int1Ty) return UnknownValue;
 
-    if (CondVal->getBoolValue() == ExitWhen) {
+    if (CondVal->getZExtValue() == ExitWhen) {
       ConstantEvolutionLoopExitValue[PN] = PHIVal;
       ++NumBruteForceTripCountsComputed;
       return SCEVConstant::get(ConstantInt::get(Type::Int32Ty, IterationNum));
       ConstantEvolutionLoopExitValue[PN] = PHIVal;
       ++NumBruteForceTripCountsComputed;
       return SCEVConstant::get(ConstantInt::get(Type::Int32Ty, IterationNum));
@@ -2204,7 +2204,7 @@ SCEVHandle ScalarEvolutionsImpl::HowFarToZero(SCEV *V, const Loop *L) {
       if (ConstantInt *CB =
           dyn_cast<ConstantInt>(ConstantExpr::getICmp(ICmpInst::ICMP_ULT, 
                                    R1->getValue(), R2->getValue()))) {
       if (ConstantInt *CB =
           dyn_cast<ConstantInt>(ConstantExpr::getICmp(ICmpInst::ICMP_ULT, 
                                    R1->getValue(), R2->getValue()))) {
-        if (CB->getBoolValue() == false)
+        if (CB->getZExtValue() == false)
           std::swap(R1, R2);   // R1 is the minimum root now.
 
         // We can only use this value if the chrec ends up with an exact zero
           std::swap(R1, R2);   // R1 is the minimum root now.
 
         // We can only use this value if the chrec ends up with an exact zero
@@ -2429,7 +2429,7 @@ SCEVHandle SCEVAddRecExpr::getNumIterationsInRange(ConstantRange Range,
       if (ConstantInt *CB =
           dyn_cast<ConstantInt>(ConstantExpr::getICmp(ICmpInst::ICMP_ULT, 
                                    R1->getValue(), R2->getValue()))) {
       if (ConstantInt *CB =
           dyn_cast<ConstantInt>(ConstantExpr::getICmp(ICmpInst::ICMP_ULT, 
                                    R1->getValue(), R2->getValue()))) {
-        if (CB->getBoolValue() == false)
+        if (CB->getZExtValue() == false)
           std::swap(R1, R2);   // R1 is the minimum root now.
 
         // Make sure the root is not off by one.  The returned iteration should
           std::swap(R1, R2);   // R1 is the minimum root now.
 
         // Make sure the root is not off by one.  The returned iteration should
index b3869fb773a0a9e09cae7c44ddcce36c4b3ea52c..787d000c231697c2933866d5e63564e47bebf977 100644 (file)
@@ -1403,7 +1403,7 @@ Value *BytecodeReader::ParseConstantPoolValue(unsigned TypeID) {
     unsigned Val = read_vbr_uint();
     if (Val != 0 && Val != 1)
       error("Invalid boolean value read.");
     unsigned Val = read_vbr_uint();
     if (Val != 0 && Val != 1)
       error("Invalid boolean value read.");
-    Result = ConstantInt::get(Val == 1);
+    Result = ConstantInt::get(Type::Int1Ty, Val == 1);
     if (Handler) Handler->handleConstantValue(Result);
     break;
   }
     if (Handler) Handler->handleConstantValue(Result);
     break;
   }
index 7acd2094c5da5b4a2ce29646c840a58ce8229de6..9a04428007901b8b93d0ca7c370b8e14eecccc38 100644 (file)
@@ -322,7 +322,7 @@ void BytecodeWriter::outputConstant(const Constant *CPV) {
 
   switch (CPV->getType()->getTypeID()) {
   case Type::Int1TyID:    // Boolean Types
 
   switch (CPV->getType()->getTypeID()) {
   case Type::Int1TyID:    // Boolean Types
-    if (cast<ConstantInt>(CPV)->getBoolValue())
+    if (cast<ConstantInt>(CPV)->getZExtValue())
       output_vbr(1U);
     else
       output_vbr(0U);
       output_vbr(1U);
     else
       output_vbr(0U);
index fed85b3e502356cfff61f01bd193dc79e39f1bb8..d7a134e46df656303d90d3f09e6ad5940e20e33f 100644 (file)
@@ -390,7 +390,7 @@ void AsmPrinter::EmitConstantValueOnly(const Constant *CV) {
     O << "0";
   else if (const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) {
     if (CI->getType() == Type::Int1Ty) {
     O << "0";
   else if (const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) {
     if (CI->getType() == Type::Int1Ty) {
-      assert(CI->getBoolValue());
+      assert(CI->getZExtValue());
       O << "1";
     } else O << CI->getSExtValue();
   } else if (const GlobalValue *GV = dyn_cast<GlobalValue>(CV)) {
       O << "1";
     } else O << CI->getSExtValue();
   } else if (const GlobalValue *GV = dyn_cast<GlobalValue>(CV)) {
index 2ebd64bf35080ede27a4d0d0a81d06fbca39e2d4..0a6d3acb9cb4dd1b60eba614ba407868129bb70c 100644 (file)
@@ -211,7 +211,7 @@ public:
   }
   virtual void Apply(bool &Field) {
     Constant *C = CI->getOperand(I++);
   }
   virtual void Apply(bool &Field) {
     Constant *C = CI->getOperand(I++);
-    Field = cast<ConstantInt>(C)->getBoolValue();
+    Field = cast<ConstantInt>(C)->getZExtValue();
   }
   virtual void Apply(std::string &Field) {
     Constant *C = CI->getOperand(I++);
   }
   virtual void Apply(std::string &Field) {
     Constant *C = CI->getOperand(I++);
@@ -276,7 +276,7 @@ public:
     Elements.push_back(ConstantInt::get(Type::Int64Ty, uint64_t(Field)));
   }
   virtual void Apply(bool &Field) {
     Elements.push_back(ConstantInt::get(Type::Int64Ty, uint64_t(Field)));
   }
   virtual void Apply(bool &Field) {
-    Elements.push_back(ConstantInt::get(Field));
+    Elements.push_back(ConstantInt::get(Type::Int1Ty, Field));
   }
   virtual void Apply(std::string &Field) {
       Elements.push_back(SR.getString(Field));
   }
   virtual void Apply(std::string &Field) {
       Elements.push_back(SR.getString(Field));
index 3c388d32f3668d31c406517e60c744940e3d8143..e5f9ea1f40e71e0328532b996f9865f854ca23d4 100644 (file)
@@ -399,7 +399,7 @@ GenericValue ExecutionEngine::getConstantValue(const Constant *C) {
   switch (C->getType()->getTypeID()) {
 #define GET_CONST_VAL(TY, CTY, CLASS, GETMETH) \
   case Type::TY##TyID: Result.TY##Val = (CTY)cast<CLASS>(C)->GETMETH(); break
   switch (C->getType()->getTypeID()) {
 #define GET_CONST_VAL(TY, CTY, CLASS, GETMETH) \
   case Type::TY##TyID: Result.TY##Val = (CTY)cast<CLASS>(C)->GETMETH(); break
-    GET_CONST_VAL(Int1  , bool          , ConstantInt, getBoolValue);
+    GET_CONST_VAL(Int1  , bool          , ConstantInt, getZExtValue);
     GET_CONST_VAL(Int8  , unsigned char , ConstantInt, getZExtValue);
     GET_CONST_VAL(Int16 , unsigned short, ConstantInt, getZExtValue);
     GET_CONST_VAL(Int32 , unsigned int  , ConstantInt, getZExtValue);
     GET_CONST_VAL(Int8  , unsigned char , ConstantInt, getZExtValue);
     GET_CONST_VAL(Int16 , unsigned short, ConstantInt, getZExtValue);
     GET_CONST_VAL(Int32 , unsigned int  , ConstantInt, getZExtValue);
index f6ced0a2518007bbaa4bf037485a0fc10415b5d6..13ee7199d9f908d3abc9a539a6f94abc89bafc73 100644 (file)
@@ -191,7 +191,7 @@ GenericValue JIT::runFunction(Function *F,
     const GenericValue &AV = ArgValues[i];
     switch (ArgTy->getTypeID()) {
     default: assert(0 && "Unknown argument type for function call!");
     const GenericValue &AV = ArgValues[i];
     switch (ArgTy->getTypeID()) {
     default: assert(0 && "Unknown argument type for function call!");
-    case Type::Int1TyID:   C = ConstantInt::get(AV.Int1Val); break;
+    case Type::Int1TyID:   C = ConstantInt::get(ArgTy, AV.Int1Val); break;
     case Type::Int8TyID:   C = ConstantInt::get(ArgTy, AV.Int8Val);  break;
     case Type::Int16TyID:  C = ConstantInt::get(ArgTy, AV.Int16Val);  break;
     case Type::Int32TyID:  C = ConstantInt::get(ArgTy, AV.Int32Val);    break;
     case Type::Int8TyID:   C = ConstantInt::get(ArgTy, AV.Int8Val);  break;
     case Type::Int16TyID:  C = ConstantInt::get(ArgTy, AV.Int16Val);  break;
     case Type::Int32TyID:  C = ConstantInt::get(ArgTy, AV.Int32Val);    break;
index 6c2dce03aa5733fa5523de40d895be84a1bebb5d..7a344201dd3e4125b612200494f55daae73eb2e2 100644 (file)
@@ -64,7 +64,7 @@ static ConstantInt *getMinValue(const Type *Ty, bool isSigned = false) {
 }
 static ConstantInt *Next(ConstantInt *CI) {
   if (CI->getType() == Type::Int1Ty)
 }
 static ConstantInt *Next(ConstantInt *CI) {
   if (CI->getType() == Type::Int1Ty)
-    return ConstantInt::get(!CI->getBoolValue());
+    return ConstantInt::get(Type::Int1Ty, !CI->getZExtValue());
 
   Constant *Result = ConstantExpr::getAdd(CI,
                                           ConstantInt::get(CI->getType(), 1));
 
   Constant *Result = ConstantExpr::getAdd(CI,
                                           ConstantInt::get(CI->getType(), 1));
@@ -75,14 +75,14 @@ static bool LT(ConstantInt *A, ConstantInt *B, bool isSigned) {
   Constant *C = ConstantExpr::getICmp(
     (isSigned ? ICmpInst::ICMP_SLT : ICmpInst::ICMP_ULT), A, B);
   assert(isa<ConstantInt>(C) && "Constant folding of integrals not impl??");
   Constant *C = ConstantExpr::getICmp(
     (isSigned ? ICmpInst::ICMP_SLT : ICmpInst::ICMP_ULT), A, B);
   assert(isa<ConstantInt>(C) && "Constant folding of integrals not impl??");
-  return cast<ConstantInt>(C)->getBoolValue();
+  return cast<ConstantInt>(C)->getZExtValue();
 }
 
 static bool LTE(ConstantInt *A, ConstantInt *B, bool isSigned) {
   Constant *C = ConstantExpr::getICmp(
     (isSigned ? ICmpInst::ICMP_SLE : ICmpInst::ICMP_ULE), A, B);
   assert(isa<ConstantInt>(C) && "Constant folding of integrals not impl??");
 }
 
 static bool LTE(ConstantInt *A, ConstantInt *B, bool isSigned) {
   Constant *C = ConstantExpr::getICmp(
     (isSigned ? ICmpInst::ICMP_SLE : ICmpInst::ICMP_ULE), A, B);
   assert(isa<ConstantInt>(C) && "Constant folding of integrals not impl??");
-  return cast<ConstantInt>(C)->getBoolValue();
+  return cast<ConstantInt>(C)->getZExtValue();
 }
 
 static bool GT(ConstantInt *A, ConstantInt *B, bool isSigned) { 
 }
 
 static bool GT(ConstantInt *A, ConstantInt *B, bool isSigned) { 
index f945036a74b03b04fac6d0e883317053eb36cbb7..23465c5f6e4d5d5091e47e319246981266883fd2 100644 (file)
@@ -829,7 +829,7 @@ void CWriter::printConstant(Constant *CPV) {
   if (ConstantInt *CI = dyn_cast<ConstantInt>(CPV)) {
     const Type* Ty = CI->getType();
     if (Ty == Type::Int1Ty)
   if (ConstantInt *CI = dyn_cast<ConstantInt>(CPV)) {
     const Type* Ty = CI->getType();
     if (Ty == Type::Int1Ty)
-      Out << (CI->getBoolValue() ? '1' : '0') ;
+      Out << (CI->getZExtValue() ? '1' : '0') ;
     else {
       Out << "((";
       printPrimitiveType(Out, Ty, false) << ')';
     else {
       Out << "((";
       printPrimitiveType(Out, Ty, false) << ')';
index ce30477c872d8edd26901cdb0cf185ecdcfba9b5..86657c2c0e51c0e8e9f1cf0992263ee3e869aec2 100644 (file)
@@ -1161,7 +1161,7 @@ static void ShrinkGlobalToBoolean(GlobalVariable *GV, Constant *OtherVal) {
       // Only do this if we weren't storing a loaded value.
       Value *StoreVal;
       if (StoringOther || SI->getOperand(0) == InitVal)
       // Only do this if we weren't storing a loaded value.
       Value *StoreVal;
       if (StoringOther || SI->getOperand(0) == InitVal)
-        StoreVal = ConstantInt::get(StoringOther);
+        StoreVal = ConstantInt::get(Type::Int1Ty, StoringOther);
       else {
         // Otherwise, we are storing a previously loaded copy.  To do this,
         // change the copy from copying the original value to just copying the
       else {
         // Otherwise, we are storing a previously loaded copy.  To do this,
         // change the copy from copying the original value to just copying the
@@ -1803,7 +1803,7 @@ static bool EvaluateFunction(Function *F, Constant *&RetVal,
           // Cannot determine.
           if (!Cond || Cond->getType() != Type::Int1Ty) 
             return false;  
           // Cannot determine.
           if (!Cond || Cond->getType() != Type::Int1Ty) 
             return false;  
-          NewBB = BI->getSuccessor(!Cond->getBoolValue());          
+          NewBB = BI->getSuccessor(!Cond->getZExtValue());          
         }
       } else if (SwitchInst *SI = dyn_cast<SwitchInst>(CurInst)) {
         ConstantInt *Val =
         }
       } else if (SwitchInst *SI = dyn_cast<SwitchInst>(CurInst)) {
         ConstantInt *Val =
index 5c0aa36361023887dc52b9d5b6ce7559e1d4319d..c0a7a0569b3cc14674ea3f623205aa4032c63969 100644 (file)
@@ -460,7 +460,7 @@ void ProfilerRS::ProcessBackEdge(BasicBlock* src, BasicBlock* dst, Function& F)
   //b:
   new BranchInst(cast<BasicBlock>(Translate(dst)), bbC);
   new BranchInst(dst, cast<BasicBlock>(Translate(dst)), 
   //b:
   new BranchInst(cast<BasicBlock>(Translate(dst)), bbC);
   new BranchInst(dst, cast<BasicBlock>(Translate(dst)), 
-                ConstantInt::get(true), bbCp);
+                ConstantInt::get(Type::Int1Ty, true), bbCp);
   //c:
   {
     TerminatorInst* iB = src->getTerminator();
   //c:
   {
     TerminatorInst* iB = src->getTerminator();
@@ -516,7 +516,7 @@ bool ProfilerRS::runOnFunction(Function& F) {
     TerminatorInst* T = F.getEntryBlock().getTerminator();
     ReplaceInstWithInst(T, new BranchInst(T->getSuccessor(0),
                               cast<BasicBlock>(Translate(T->getSuccessor(0))),
     TerminatorInst* T = F.getEntryBlock().getTerminator();
     ReplaceInstWithInst(T, new BranchInst(T->getSuccessor(0),
                               cast<BasicBlock>(Translate(T->getSuccessor(0))),
-                                         ConstantInt::get(true)));
+                                        ConstantInt::get(Type::Int1Ty, true)));
     
     //do whatever is needed now that the function is duplicated
     c->PrepFunction(&F);
     
     //do whatever is needed now that the function is duplicated
     c->PrepFunction(&F);
index 65e8c8d1ded5dc3b1311e0f151fbc67106c9b8c7..253535e3a5e1c3e7398fe4d489eaaa11a0a0aa24 100644 (file)
@@ -139,7 +139,7 @@ void CondProp::SimplifyPredecessors(BranchInst *BI) {
       // ultimate destination.
       bool PHIGone = PN->getNumIncomingValues() == 2;
       RevectorBlockTo(PN->getIncomingBlock(i-1),
       // ultimate destination.
       bool PHIGone = PN->getNumIncomingValues() == 2;
       RevectorBlockTo(PN->getIncomingBlock(i-1),
-                      BI->getSuccessor(CB->getBoolValue() == 0));
+                      BI->getSuccessor(CB->getZExtValue() == 0));
       ++NumBrThread;
 
       // If there were two predecessors before this simplification, the PHI node
       ++NumBrThread;
 
       // If there were two predecessors before this simplification, the PHI node
index 09d5c07060405d91a5ec8aa879a75cfd9bdfe864..00055b4586486670a9d604de734de17190ad92ae 100644 (file)
@@ -472,7 +472,7 @@ bool CEE::ForwardCorrelatedEdgeDestination(TerminatorInst *TI, unsigned SuccNo,
     } else if (CmpInst *CI = dyn_cast<CmpInst>(I)) {
       Relation::KnownResult Res = getCmpResult(CI, NewRI);
       if (Res == Relation::Unknown) return false;
     } else if (CmpInst *CI = dyn_cast<CmpInst>(I)) {
       Relation::KnownResult Res = getCmpResult(CI, NewRI);
       if (Res == Relation::Unknown) return false;
-      PropagateEquality(CI, ConstantInt::get(Res), NewRI);
+      PropagateEquality(CI, ConstantInt::get(Type::Int1Ty, Res), NewRI);
     } else {
       assert(isa<BranchInst>(*I) && "Unexpected instruction type!");
     }
     } else {
       assert(isa<BranchInst>(*I) && "Unexpected instruction type!");
     }
@@ -488,7 +488,7 @@ bool CEE::ForwardCorrelatedEdgeDestination(TerminatorInst *TI, unsigned SuccNo,
 
     // Forward to the successor that corresponds to the branch we will take.
     ForwardSuccessorTo(TI, SuccNo, 
 
     // Forward to the successor that corresponds to the branch we will take.
     ForwardSuccessorTo(TI, SuccNo, 
-                       BI->getSuccessor(!CB->getBoolValue()), NewRI);
+                       BI->getSuccessor(!CB->getZExtValue()), NewRI);
     return true;
   }
 
     return true;
   }
 
@@ -841,7 +841,7 @@ void CEE::PropagateEquality(Value *Op0, Value *Op1, RegionInfo &RI) {
         // is true, this means that both operands to the OR are known to be true
         // as well.
         //
         // is true, this means that both operands to the OR are known to be true
         // as well.
         //
-        if (CB->getBoolValue() && Inst->getOpcode() == Instruction::And) {
+        if (CB->getZExtValue() && Inst->getOpcode() == Instruction::And) {
           PropagateEquality(Inst->getOperand(0), CB, RI);
           PropagateEquality(Inst->getOperand(1), CB, RI);
         }
           PropagateEquality(Inst->getOperand(0), CB, RI);
           PropagateEquality(Inst->getOperand(1), CB, RI);
         }
@@ -850,24 +850,26 @@ void CEE::PropagateEquality(Value *Op0, Value *Op1, RegionInfo &RI) {
         // is false, this means that both operands to the OR are know to be false
         // as well.
         //
         // is false, this means that both operands to the OR are know to be false
         // as well.
         //
-        if (!CB->getBoolValue() && Inst->getOpcode() == Instruction::Or) {
+        if (!CB->getZExtValue() && Inst->getOpcode() == Instruction::Or) {
           PropagateEquality(Inst->getOperand(0), CB, RI);
           PropagateEquality(Inst->getOperand(1), CB, RI);
         }
 
           PropagateEquality(Inst->getOperand(0), CB, RI);
           PropagateEquality(Inst->getOperand(1), CB, RI);
         }
 
-        // If we know that this instruction is a NOT instruction, we know that the
-        // operand is known to be the inverse of whatever the current value is.
+        // If we know that this instruction is a NOT instruction, we know that 
+        // the operand is known to be the inverse of whatever the current 
+        // value is.
         //
         if (BinaryOperator *BOp = dyn_cast<BinaryOperator>(Inst))
           if (BinaryOperator::isNot(BOp))
             PropagateEquality(BinaryOperator::getNotArgument(BOp),
         //
         if (BinaryOperator *BOp = dyn_cast<BinaryOperator>(Inst))
           if (BinaryOperator::isNot(BOp))
             PropagateEquality(BinaryOperator::getNotArgument(BOp),
-                              ConstantInt::get(!CB->getBoolValue()), RI);
+                              ConstantInt::get(Type::Int1Ty, 
+                                               !CB->getZExtValue()), RI);
 
         // If we know the value of a FCmp instruction, propagate the information
         // about the relation into this region as well.
         //
         if (FCmpInst *FCI = dyn_cast<FCmpInst>(Inst)) {
 
         // If we know the value of a FCmp instruction, propagate the information
         // about the relation into this region as well.
         //
         if (FCmpInst *FCI = dyn_cast<FCmpInst>(Inst)) {
-          if (CB->getBoolValue()) {  // If we know the condition is true...
+          if (CB->getZExtValue()) {  // If we know the condition is true...
             // Propagate info about the LHS to the RHS & RHS to LHS
             PropagateRelation(FCI->getPredicate(), FCI->getOperand(0),
                               FCI->getOperand(1), RI);
             // Propagate info about the LHS to the RHS & RHS to LHS
             PropagateRelation(FCI->getPredicate(), FCI->getOperand(0),
                               FCI->getOperand(1), RI);
@@ -888,7 +890,7 @@ void CEE::PropagateEquality(Value *Op0, Value *Op1, RegionInfo &RI) {
         // about the relation into this region as well.
         //
         if (ICmpInst *ICI = dyn_cast<ICmpInst>(Inst)) {
         // about the relation into this region as well.
         //
         if (ICmpInst *ICI = dyn_cast<ICmpInst>(Inst)) {
-          if (CB->getBoolValue()) { // If we know the condition is true...
+          if (CB->getZExtValue()) { // If we know the condition is true...
             // Propagate info about the LHS to the RHS & RHS to LHS
             PropagateRelation(ICI->getPredicate(), ICI->getOperand(0),
                               ICI->getOperand(1), RI);
             // Propagate info about the LHS to the RHS & RHS to LHS
             PropagateRelation(ICI->getPredicate(), ICI->getOperand(0),
                               ICI->getOperand(1), RI);
@@ -994,7 +996,7 @@ void CEE::IncorporateInstruction(Instruction *Inst, RegionInfo &RI) {
     // See if we can figure out a result for this instruction...
     Relation::KnownResult Result = getCmpResult(CI, RI);
     if (Result != Relation::Unknown) {
     // See if we can figure out a result for this instruction...
     Relation::KnownResult Result = getCmpResult(CI, RI);
     if (Result != Relation::Unknown) {
-      PropagateEquality(CI, ConstantInt::get(Result != 0), RI);
+      PropagateEquality(CI, ConstantInt::get(Type::Int1Ty, Result != 0), RI);
     }
   }
 }
     }
   }
 }
@@ -1068,7 +1070,7 @@ bool CEE::SimplifyBasicBlock(BasicBlock &BB, const RegionInfo &RI) {
         DEBUG(cerr << "Replacing icmp with " << Result
                    << " constant: " << *CI);
 
         DEBUG(cerr << "Replacing icmp with " << Result
                    << " constant: " << *CI);
 
-        CI->replaceAllUsesWith(ConstantInt::get((bool)Result));
+        CI->replaceAllUsesWith(ConstantInt::get(Type::Int1Ty, (bool)Result));
         // The instruction is now dead, remove it from the program.
         CI->getParent()->getInstList().erase(CI);
         ++NumCmpRemoved;
         // The instruction is now dead, remove it from the program.
         CI->getParent()->getInstList().erase(CI);
         ++NumCmpRemoved;
@@ -1122,7 +1124,7 @@ Relation::KnownResult CEE::getCmpResult(CmpInst *CI,
       if (Constant *Result = ConstantFoldInstruction(CI)) {
         // Wow, this is easy, directly eliminate the ICmpInst.
         DEBUG(cerr << "Replacing cmp with constant fold: " << *CI);
       if (Constant *Result = ConstantFoldInstruction(CI)) {
         // Wow, this is easy, directly eliminate the ICmpInst.
         DEBUG(cerr << "Replacing cmp with constant fold: " << *CI);
-        return cast<ConstantInt>(Result)->getBoolValue()
+        return cast<ConstantInt>(Result)->getZExtValue()
           ? Relation::KnownTrue : Relation::KnownFalse;
       }
     } else {
           ? Relation::KnownTrue : Relation::KnownFalse;
       }
     } else {
index bf4f5f3e235be6851631cb529502d366c815fc98..c039b3999a3bdd3ec69a9bfcc11a6a84b40222fb 100644 (file)
@@ -2965,7 +2965,7 @@ Instruction *InstCombiner::InsertRangeTest(Value *V, Constant *Lo, Constant *Hi,
                                            bool isSigned, bool Inside, 
                                            Instruction &IB) {
   assert(cast<ConstantInt>(ConstantExpr::getICmp((isSigned ? 
                                            bool isSigned, bool Inside, 
                                            Instruction &IB) {
   assert(cast<ConstantInt>(ConstantExpr::getICmp((isSigned ? 
-            ICmpInst::ICMP_SLE:ICmpInst::ICMP_ULE), Lo, Hi))->getBoolValue() &&
+            ICmpInst::ICMP_SLE:ICmpInst::ICMP_ULE), Lo, Hi))->getZExtValue() &&
          "Lo is not <= Hi in range emission code!");
     
   if (Inside) {
          "Lo is not <= Hi in range emission code!");
     
   if (Inside) {
@@ -3264,7 +3264,7 @@ Instruction *InstCombiner::visitAnd(BinaryOperator &I) {
             ICmpInst::ICMP_SGT : ICmpInst::ICMP_UGT;
           Constant *Cmp = ConstantExpr::getICmp(GT, LHSCst, RHSCst);
           ICmpInst *LHS = cast<ICmpInst>(Op0);
             ICmpInst::ICMP_SGT : ICmpInst::ICMP_UGT;
           Constant *Cmp = ConstantExpr::getICmp(GT, LHSCst, RHSCst);
           ICmpInst *LHS = cast<ICmpInst>(Op0);
-          if (cast<ConstantInt>(Cmp)->getBoolValue()) {
+          if (cast<ConstantInt>(Cmp)->getZExtValue()) {
             std::swap(LHS, RHS);
             std::swap(LHSCst, RHSCst);
             std::swap(LHSCC, RHSCC);
             std::swap(LHS, RHS);
             std::swap(LHSCst, RHSCst);
             std::swap(LHSCC, RHSCC);
@@ -3723,7 +3723,7 @@ Instruction *InstCombiner::visitOr(BinaryOperator &I) {
             ICmpInst::ICMP_SGT : ICmpInst::ICMP_UGT;
           Constant *Cmp = ConstantExpr::getICmp(GT, LHSCst, RHSCst);
           ICmpInst *LHS = cast<ICmpInst>(Op0);
             ICmpInst::ICMP_SGT : ICmpInst::ICMP_UGT;
           Constant *Cmp = ConstantExpr::getICmp(GT, LHSCst, RHSCst);
           ICmpInst *LHS = cast<ICmpInst>(Op0);
-          if (cast<ConstantInt>(Cmp)->getBoolValue()) {
+          if (cast<ConstantInt>(Cmp)->getZExtValue()) {
             std::swap(LHS, RHS);
             std::swap(LHSCst, RHSCst);
             std::swap(LHSCC, RHSCC);
             std::swap(LHS, RHS);
             std::swap(LHSCst, RHSCst);
             std::swap(LHSCC, RHSCC);
@@ -4152,7 +4152,8 @@ Instruction *InstCombiner::FoldGEPICmp(User *GEPLHS, Value *RHS,
             EmitIt = false;  // This is indexing into a zero sized array?
           } else if (isa<ConstantInt>(C))
             return ReplaceInstUsesWith(I, // No comparison is needed here.
             EmitIt = false;  // This is indexing into a zero sized array?
           } else if (isa<ConstantInt>(C))
             return ReplaceInstUsesWith(I, // No comparison is needed here.
-                                 ConstantInt::get(Cond == ICmpInst::ICMP_NE));
+                                 ConstantInt::get(Type::Int1Ty, 
+                                                  Cond == ICmpInst::ICMP_NE));
         }
 
         if (EmitIt) {
         }
 
         if (EmitIt) {
@@ -4176,7 +4177,8 @@ Instruction *InstCombiner::FoldGEPICmp(User *GEPLHS, Value *RHS,
         return InVal;
       else
         // No comparison is needed here, all indexes = 0
         return InVal;
       else
         // No comparison is needed here, all indexes = 0
-        ReplaceInstUsesWith(I, ConstantInt::get(Cond == ICmpInst::ICMP_EQ));
+        ReplaceInstUsesWith(I, ConstantInt::get(Type::Int1Ty, 
+                                                Cond == ICmpInst::ICMP_EQ));
     }
 
     // Only lower this if the icmp is the only user of the GEP or if we expect
     }
 
     // Only lower this if the icmp is the only user of the GEP or if we expect
@@ -4253,7 +4255,8 @@ Instruction *InstCombiner::FoldGEPICmp(User *GEPLHS, Value *RHS,
 
       if (NumDifferences == 0)   // SAME GEP?
         return ReplaceInstUsesWith(I, // No comparison is needed here.
 
       if (NumDifferences == 0)   // SAME GEP?
         return ReplaceInstUsesWith(I, // No comparison is needed here.
-                                 ConstantInt::get(Cond == ICmpInst::ICMP_EQ));
+                                   ConstantInt::get(Type::Int1Ty, 
+                                                    Cond == ICmpInst::ICMP_EQ));
       else if (NumDifferences == 1) {
         Value *LHSV = GEPLHS->getOperand(DiffOperand);
         Value *RHSV = GEPRHS->getOperand(DiffOperand);
       else if (NumDifferences == 1) {
         Value *LHSV = GEPLHS->getOperand(DiffOperand);
         Value *RHSV = GEPRHS->getOperand(DiffOperand);
@@ -4281,7 +4284,8 @@ Instruction *InstCombiner::visitFCmpInst(FCmpInst &I) {
 
   // fcmp pred X, X
   if (Op0 == Op1)
 
   // fcmp pred X, X
   if (Op0 == Op1)
-    return ReplaceInstUsesWith(I, ConstantInt::get(isTrueWhenEqual(I)));
+    return ReplaceInstUsesWith(I, ConstantInt::get(Type::Int1Ty, 
+                                                   isTrueWhenEqual(I)));
 
   if (isa<UndefValue>(Op1))                  // fcmp pred X, undef -> undef
     return ReplaceInstUsesWith(I, UndefValue::get(Type::Int1Ty));
 
   if (isa<UndefValue>(Op1))                  // fcmp pred X, undef -> undef
     return ReplaceInstUsesWith(I, UndefValue::get(Type::Int1Ty));
@@ -4333,7 +4337,8 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) {
 
   // icmp X, X
   if (Op0 == Op1)
 
   // icmp X, X
   if (Op0 == Op1)
-    return ReplaceInstUsesWith(I, ConstantInt::get(isTrueWhenEqual(I)));
+    return ReplaceInstUsesWith(I, ConstantInt::get(Type::Int1Ty, 
+                                                   isTrueWhenEqual(I)));
 
   if (isa<UndefValue>(Op1))                  // X icmp undef -> undef
     return ReplaceInstUsesWith(I, UndefValue::get(Type::Int1Ty));
 
   if (isa<UndefValue>(Op1))                  // X icmp undef -> undef
     return ReplaceInstUsesWith(I, UndefValue::get(Type::Int1Ty));
@@ -4343,7 +4348,8 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) {
   if (GlobalValue *GV0 = dyn_cast<GlobalValue>(Op0))
     if (GlobalValue *GV1 = dyn_cast<GlobalValue>(Op1))
       if (!GV0->hasExternalWeakLinkage() || !GV1->hasExternalWeakLinkage())
   if (GlobalValue *GV0 = dyn_cast<GlobalValue>(Op0))
     if (GlobalValue *GV1 = dyn_cast<GlobalValue>(Op1))
       if (!GV0->hasExternalWeakLinkage() || !GV1->hasExternalWeakLinkage())
-        return ReplaceInstUsesWith(I, ConstantInt::get(!isTrueWhenEqual(I)));
+        return ReplaceInstUsesWith(I, ConstantInt::get(Type::Int1Ty,
+                                                       !isTrueWhenEqual(I)));
 
   // icmp <global/alloca*/null>, <global/alloca*/null> - Global/Stack value
   // addresses never equal each other!  We already know that Op0 != Op1.
 
   // icmp <global/alloca*/null>, <global/alloca*/null> - Global/Stack value
   // addresses never equal each other!  We already know that Op0 != Op1.
@@ -4351,7 +4357,8 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) {
        isa<ConstantPointerNull>(Op0)) &&
       (isa<GlobalValue>(Op1) || isa<AllocaInst>(Op1) ||
        isa<ConstantPointerNull>(Op1)))
        isa<ConstantPointerNull>(Op0)) &&
       (isa<GlobalValue>(Op1) || isa<AllocaInst>(Op1) ||
        isa<ConstantPointerNull>(Op1)))
-    return ReplaceInstUsesWith(I, ConstantInt::get(!isTrueWhenEqual(I)));
+    return ReplaceInstUsesWith(I, ConstantInt::get(Type::Int1Ty, 
+                                                   !isTrueWhenEqual(I)));
 
   // icmp's with boolean values can always be turned into bitwise operations
   if (Ty == Type::Int1Ty) {
 
   // icmp's with boolean values can always be turned into bitwise operations
   if (Ty == Type::Int1Ty) {
@@ -4691,7 +4698,7 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) {
               ConstantExpr::getShl(ConstantExpr::getLShr(CI, ShAmt), ShAmt);
             if (Comp != CI) {// Comparing against a bit that we know is zero.
               bool IsICMP_NE = I.getPredicate() == ICmpInst::ICMP_NE;
               ConstantExpr::getShl(ConstantExpr::getLShr(CI, ShAmt), ShAmt);
             if (Comp != CI) {// Comparing against a bit that we know is zero.
               bool IsICMP_NE = I.getPredicate() == ICmpInst::ICMP_NE;
-              Constant *Cst = ConstantInt::get(IsICMP_NE);
+              Constant *Cst = ConstantInt::get(Type::Int1Ty, IsICMP_NE);
               return ReplaceInstUsesWith(I, Cst);
             }
 
               return ReplaceInstUsesWith(I, Cst);
             }
 
@@ -4735,7 +4742,7 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) {
 
             if (Comp != CI) {// Comparing against a bit that we know is zero.
               bool IsICMP_NE = I.getPredicate() == ICmpInst::ICMP_NE;
 
             if (Comp != CI) {// Comparing against a bit that we know is zero.
               bool IsICMP_NE = I.getPredicate() == ICmpInst::ICMP_NE;
-              Constant *Cst = ConstantInt::get(IsICMP_NE);
+              Constant *Cst = ConstantInt::get(Type::Int1Ty, IsICMP_NE);
               return ReplaceInstUsesWith(I, Cst);
             }
 
               return ReplaceInstUsesWith(I, Cst);
             }
 
@@ -4957,7 +4964,8 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) {
           if (Constant *BOC = dyn_cast<Constant>(BO->getOperand(1))) {
             Constant *NotCI = ConstantExpr::getNot(CI);
             if (!ConstantExpr::getAnd(BOC, NotCI)->isNullValue())
           if (Constant *BOC = dyn_cast<Constant>(BO->getOperand(1))) {
             Constant *NotCI = ConstantExpr::getNot(CI);
             if (!ConstantExpr::getAnd(BOC, NotCI)->isNullValue())
-              return ReplaceInstUsesWith(I, ConstantInt::get(isICMP_NE));
+              return ReplaceInstUsesWith(I, ConstantInt::get(Type::Int1Ty, 
+                                                             isICMP_NE));
           }
           break;
 
           }
           break;
 
@@ -4967,7 +4975,8 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) {
             // comparison can never succeed!
             if (!ConstantExpr::getAnd(CI,
                                       ConstantExpr::getNot(BOC))->isNullValue())
             // comparison can never succeed!
             if (!ConstantExpr::getAnd(CI,
                                       ConstantExpr::getNot(BOC))->isNullValue())
-              return ReplaceInstUsesWith(I, ConstantInt::get(isICMP_NE));
+              return ReplaceInstUsesWith(I, ConstantInt::get(Type::Int1Ty,
+                                                             isICMP_NE));
 
             // If we have ((X & C) == C), turn it into ((X & C) != 0).
             if (CI == BOC && isOneBitSet(CI))
 
             // If we have ((X & C) == C), turn it into ((X & C) != 0).
             if (CI == BOC && isOneBitSet(CI))
@@ -6182,7 +6191,7 @@ Instruction *InstCombiner::commonIntCastTransforms(CastInst &CI) {
           if (Op1CV && (Op1CV != (KnownZero^TypeMask))) {
             // (X&4) == 2 --> false
             // (X&4) != 2 --> true
           if (Op1CV && (Op1CV != (KnownZero^TypeMask))) {
             // (X&4) == 2 --> false
             // (X&4) != 2 --> true
-            Constant *Res = ConstantInt::get(isNE);
+            Constant *Res = ConstantInt::get(Type::Int1Ty, isNE);
             Res = ConstantExpr::getZExt(Res, CI.getType());
             return ReplaceInstUsesWith(CI, Res);
           }
             Res = ConstantExpr::getZExt(Res, CI.getType());
             return ReplaceInstUsesWith(CI, Res);
           }
@@ -6553,7 +6562,7 @@ Instruction *InstCombiner::visitSelectInst(SelectInst &SI) {
   // select true, X, Y  -> X
   // select false, X, Y -> Y
   if (ConstantInt *C = dyn_cast<ConstantInt>(CondVal))
   // select true, X, Y  -> X
   // select false, X, Y -> Y
   if (ConstantInt *C = dyn_cast<ConstantInt>(CondVal))
-    return ReplaceInstUsesWith(SI, C->getBoolValue() ? TrueVal : FalseVal);
+    return ReplaceInstUsesWith(SI, C->getZExtValue() ? TrueVal : FalseVal);
 
   // select C, X, X -> X
   if (TrueVal == FalseVal)
 
   // select C, X, X -> X
   if (TrueVal == FalseVal)
@@ -6574,7 +6583,7 @@ Instruction *InstCombiner::visitSelectInst(SelectInst &SI) {
     ConstantInt *C;
     if ((C = dyn_cast<ConstantInt>(TrueVal)) && 
         C->getType() == Type::Int1Ty) {
     ConstantInt *C;
     if ((C = dyn_cast<ConstantInt>(TrueVal)) && 
         C->getType() == Type::Int1Ty) {
-      if (C->getBoolValue()) {
+      if (C->getZExtValue()) {
         // Change: A = select B, true, C --> A = or B, C
         return BinaryOperator::createOr(CondVal, FalseVal);
       } else {
         // Change: A = select B, true, C --> A = or B, C
         return BinaryOperator::createOr(CondVal, FalseVal);
       } else {
@@ -6586,7 +6595,7 @@ Instruction *InstCombiner::visitSelectInst(SelectInst &SI) {
       }
     } else if ((C = dyn_cast<ConstantInt>(FalseVal)) &&
                C->getType() == Type::Int1Ty) {
       }
     } else if ((C = dyn_cast<ConstantInt>(FalseVal)) &&
                C->getType() == Type::Int1Ty) {
-      if (C->getBoolValue() == false) {
+      if (C->getZExtValue() == false) {
         // Change: A = select B, C, false --> A = and B, C
         return BinaryOperator::createAnd(CondVal, TrueVal);
       } else {
         // Change: A = select B, C, false --> A = and B, C
         return BinaryOperator::createAnd(CondVal, TrueVal);
       } else {
@@ -9049,7 +9058,7 @@ static void AddReachableCodeToWorklist(BasicBlock *BB,
   if (BranchInst *BI = dyn_cast<BranchInst>(TI)) {
     if (BI->isConditional() && isa<ConstantInt>(BI->getCondition()) &&
         BI->getCondition()->getType() == Type::Int1Ty) {
   if (BranchInst *BI = dyn_cast<BranchInst>(TI)) {
     if (BI->isConditional() && isa<ConstantInt>(BI->getCondition()) &&
         BI->getCondition()->getType() == Type::Int1Ty) {
-      bool CondVal = cast<ConstantInt>(BI->getCondition())->getBoolValue();
+      bool CondVal = cast<ConstantInt>(BI->getCondition())->getZExtValue();
       AddReachableCodeToWorklist(BI->getSuccessor(!CondVal), Visited, WorkList,
                                  TD);
       return;
       AddReachableCodeToWorklist(BI->getSuccessor(!CondVal), Visited, WorkList,
                                  TD);
       return;
index c97c9b5518c7251f8863b4b21da1252c8a854c9d..80d4311ebcba2896454709e9bd7700ccdd86de33 100644 (file)
@@ -924,7 +924,8 @@ void LoopUnswitch::RewriteLoopBodyWithConditionConstant(Loop *L, Value *LIC,
     if (IsEqual)
       Replacement = Val;
     else
     if (IsEqual)
       Replacement = Val;
     else
-      Replacement = ConstantInt::get(!cast<ConstantInt>(Val)->getBoolValue());
+      Replacement = ConstantInt::get(Type::Int1Ty, 
+                                     !cast<ConstantInt>(Val)->getZExtValue());
     
     for (unsigned i = 0, e = Users.size(); i != e; ++i)
       if (Instruction *U = cast<Instruction>(Users[i])) {
     
     for (unsigned i = 0, e = Users.size(); i != e; ++i)
       if (Instruction *U = cast<Instruction>(Users[i])) {
@@ -1026,7 +1027,7 @@ void LoopUnswitch::SimplifyCode(std::vector<Instruction*> &Worklist) {
     switch (I->getOpcode()) {
     case Instruction::Select:
       if (ConstantInt *CB = dyn_cast<ConstantInt>(I->getOperand(0))) {
     switch (I->getOpcode()) {
     case Instruction::Select:
       if (ConstantInt *CB = dyn_cast<ConstantInt>(I->getOperand(0))) {
-        ReplaceUsesOfWith(I, I->getOperand(!CB->getBoolValue()+1), Worklist);
+        ReplaceUsesOfWith(I, I->getOperand(!CB->getZExtValue()+1), Worklist);
         continue;
       }
       break;
         continue;
       }
       break;
@@ -1036,7 +1037,7 @@ void LoopUnswitch::SimplifyCode(std::vector<Instruction*> &Worklist) {
         cast<BinaryOperator>(I)->swapOperands();
       if (ConstantInt *CB = dyn_cast<ConstantInt>(I->getOperand(1))) 
         if (CB->getType() == Type::Int1Ty) {
         cast<BinaryOperator>(I)->swapOperands();
       if (ConstantInt *CB = dyn_cast<ConstantInt>(I->getOperand(1))) 
         if (CB->getType() == Type::Int1Ty) {
-          if (CB->getBoolValue())   // X & 1 -> X
+          if (CB->getZExtValue())   // X & 1 -> X
             ReplaceUsesOfWith(I, I->getOperand(0), Worklist);
           else                  // X & 0 -> 0
             ReplaceUsesOfWith(I, I->getOperand(1), Worklist);
             ReplaceUsesOfWith(I, I->getOperand(0), Worklist);
           else                  // X & 0 -> 0
             ReplaceUsesOfWith(I, I->getOperand(1), Worklist);
@@ -1049,7 +1050,7 @@ void LoopUnswitch::SimplifyCode(std::vector<Instruction*> &Worklist) {
         cast<BinaryOperator>(I)->swapOperands();
       if (ConstantInt *CB = dyn_cast<ConstantInt>(I->getOperand(1)))
         if (CB->getType() == Type::Int1Ty) {
         cast<BinaryOperator>(I)->swapOperands();
       if (ConstantInt *CB = dyn_cast<ConstantInt>(I->getOperand(1)))
         if (CB->getType() == Type::Int1Ty) {
-          if (CB->getBoolValue())   // X | 1 -> 1
+          if (CB->getZExtValue())   // X | 1 -> 1
             ReplaceUsesOfWith(I, I->getOperand(1), Worklist);
           else                  // X | 0 -> X
             ReplaceUsesOfWith(I, I->getOperand(0), Worklist);
             ReplaceUsesOfWith(I, I->getOperand(1), Worklist);
           else                  // X | 0 -> X
             ReplaceUsesOfWith(I, I->getOperand(0), Worklist);
@@ -1094,8 +1095,8 @@ void LoopUnswitch::SimplifyCode(std::vector<Instruction*> &Worklist) {
         break;  // FIXME: Enable.
 
         DOUT << "Folded branch: " << *BI;
         break;  // FIXME: Enable.
 
         DOUT << "Folded branch: " << *BI;
-        BasicBlock *DeadSucc = BI->getSuccessor(CB->getBoolValue());
-        BasicBlock *LiveSucc = BI->getSuccessor(!CB->getBoolValue());
+        BasicBlock *DeadSucc = BI->getSuccessor(CB->getZExtValue());
+        BasicBlock *LiveSucc = BI->getSuccessor(!CB->getZExtValue());
         DeadSucc->removePredecessor(BI->getParent(), true);
         Worklist.push_back(new BranchInst(LiveSucc, BI));
         BI->eraseFromParent();
         DeadSucc->removePredecessor(BI->getParent(), true);
         Worklist.push_back(new BranchInst(LiveSucc, BI));
         BI->eraseFromParent();
index daf21d43f714df553ff8cdde3c2b2c6cf68bf9e6..2bc000440ae1380f548c51c0e5666521428c7d1f 100644 (file)
@@ -416,8 +416,7 @@ void SCCPSolver::getFeasibleSuccessors(TerminatorInst &TI,
     } else {
       LatticeVal &BCValue = getValueState(BI->getCondition());
       if (BCValue.isOverdefined() ||
     } else {
       LatticeVal &BCValue = getValueState(BI->getCondition());
       if (BCValue.isOverdefined() ||
-          (BCValue.isConstant() && 
-          BCValue.getConstant()->getType() != Type::Int1Ty)) {
+          (BCValue.isConstant() && !isa<ConstantInt>(BCValue.getConstant()))) {
         // Overdefined condition variables, and branches on unfoldable constant
         // conditions, mean the branch could go either way.
         Succs[0] = Succs[1] = true;
         // Overdefined condition variables, and branches on unfoldable constant
         // conditions, mean the branch could go either way.
         Succs[0] = Succs[1] = true;
@@ -647,10 +646,9 @@ void SCCPSolver::visitSelectInst(SelectInst &I) {
   LatticeVal &CondValue = getValueState(I.getCondition());
   if (CondValue.isUndefined())
     return;
   LatticeVal &CondValue = getValueState(I.getCondition());
   if (CondValue.isUndefined())
     return;
-  if (CondValue.isConstant() &&
-      CondValue.getConstant()->getType() == Type::Int1Ty) {
+  if (CondValue.isConstant()) {
     if (ConstantInt *CondCB = dyn_cast<ConstantInt>(CondValue.getConstant())){
     if (ConstantInt *CondCB = dyn_cast<ConstantInt>(CondValue.getConstant())){
-      mergeInValue(&I, getValueState(CondCB->getBoolValue() ? I.getTrueValue()
+      mergeInValue(&I, getValueState(CondCB->getZExtValue() ? I.getTrueValue()
                                                           : I.getFalseValue()));
       return;
     }
                                                           : I.getFalseValue()));
       return;
     }
index cb98dc58e268de64b467c822c3cbe92b253c57fb..753d657d583045a68f76da91b007c2b72f71f03c 100644 (file)
@@ -233,7 +233,7 @@ void PruningFunctionCloner::CloneBlock(const BasicBlock *BB) {
 
       // Constant fold to uncond branch!
       if (Cond) {
 
       // Constant fold to uncond branch!
       if (Cond) {
-        BasicBlock *Dest = BI->getSuccessor(!Cond->getBoolValue());
+        BasicBlock *Dest = BI->getSuccessor(!Cond->getZExtValue());
         ValueMap[OldTI] = new BranchInst(Dest, NewBB);
         CloneBlock(Dest);
         TerminatorDone = true;
         ValueMap[OldTI] = new BranchInst(Dest, NewBB);
         CloneBlock(Dest);
         TerminatorDone = true;
index 4e8f3c0ec4e6155c80f0efd53038b99403c9d0ee..e83f1b02fc6e51aa7186112c4cc8a70a37ea9543 100644 (file)
@@ -470,7 +470,7 @@ emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer,
           case 0:
           case 1: break;  // No value needed.
           case 2:         // Conditional branch, return a bool
           case 0:
           case 1: break;  // No value needed.
           case 2:         // Conditional branch, return a bool
-            brVal = ConstantInt::get(!SuccNum);
+            brVal = ConstantInt::get(Type::Int1Ty, !SuccNum);
             break;
           default:
             brVal = ConstantInt::get(Type::Int16Ty, SuccNum);
             break;
           default:
             brVal = ConstantInt::get(Type::Int16Ty, SuccNum);
index f3d6ca85ccf2684c07639eb63fb0da384210a72c..fd24f10de8b5a1a88d74422b26f8d59e232e9298 100644 (file)
@@ -176,8 +176,8 @@ bool llvm::ConstantFoldTerminator(BasicBlock *BB) {
     if (ConstantInt *Cond = dyn_cast<ConstantInt>(BI->getCondition())) {
       // Are we branching on constant?
       // YES.  Change to unconditional branch...
     if (ConstantInt *Cond = dyn_cast<ConstantInt>(BI->getCondition())) {
       // Are we branching on constant?
       // YES.  Change to unconditional branch...
-      BasicBlock *Destination = Cond->getBoolValue() ? Dest1 : Dest2;
-      BasicBlock *OldDest     = Cond->getBoolValue() ? Dest2 : Dest1;
+      BasicBlock *Destination = Cond->getZExtValue() ? Dest1 : Dest2;
+      BasicBlock *OldDest     = Cond->getZExtValue() ? Dest2 : Dest1;
 
       //cerr << "Function: " << T->getParent()->getParent()
       //     << "\nRemoving branch from " << T->getParent()
 
       //cerr << "Function: " << T->getParent()->getParent()
       //     << "\nRemoving branch from " << T->getParent()
index 964b47c4efb77953c4cf2916d8a758664c99b2fd..25bc16866f37269dbae2f480fe8ec4d3407e3a78 100644 (file)
@@ -975,7 +975,7 @@ static bool FoldCondBranchOnPHI(BranchInst *BI) {
       // Okay, we now know that all edges from PredBB should be revectored to
       // branch to RealDest.
       BasicBlock *PredBB = PN->getIncomingBlock(i);
       // Okay, we now know that all edges from PredBB should be revectored to
       // branch to RealDest.
       BasicBlock *PredBB = PN->getIncomingBlock(i);
-      BasicBlock *RealDest = BI->getSuccessor(!CB->getBoolValue());
+      BasicBlock *RealDest = BI->getSuccessor(!CB->getZExtValue());
       
       if (RealDest == BB) continue;  // Skip self loops.
       
       
       if (RealDest == BB) continue;  // Skip self loops.
       
@@ -1500,8 +1500,8 @@ bool llvm::SimplifyCFG(BasicBlock *BB) {
           if (PBI != BI && PBI->isConditional()) {
               
             // If this block ends with a branch instruction, and if there is a
           if (PBI != BI && PBI->isConditional()) {
               
             // If this block ends with a branch instruction, and if there is a
-            // predecessor that ends on a branch of the same condition, make this 
-            // conditional branch redundant.
+            // predecessor that ends on a branch of the same condition, make 
+            // this conditional branch redundant.
             if (PBI->getCondition() == BI->getCondition() &&
                 PBI->getSuccessor(0) != PBI->getSuccessor(1)) {
               // Okay, the outcome of this conditional branch is statically
             if (PBI->getCondition() == BI->getCondition() &&
                 PBI->getSuccessor(0) != PBI->getSuccessor(1)) {
               // Okay, the outcome of this conditional branch is statically
@@ -1509,23 +1509,24 @@ bool llvm::SimplifyCFG(BasicBlock *BB) {
               if (BB->getSinglePredecessor()) {
                 // Turn this into a branch on constant.
                 bool CondIsTrue = PBI->getSuccessor(0) == BB;
               if (BB->getSinglePredecessor()) {
                 // Turn this into a branch on constant.
                 bool CondIsTrue = PBI->getSuccessor(0) == BB;
-                BI->setCondition(ConstantInt::get(CondIsTrue));
+                BI->setCondition(ConstantInt::get(Type::Int1Ty, CondIsTrue));
                 return SimplifyCFG(BB);  // Nuke the branch on constant.
               }
               
                 return SimplifyCFG(BB);  // Nuke the branch on constant.
               }
               
-              // Otherwise, if there are multiple predecessors, insert a PHI that
-              // merges in the constant and simplify the block result.
+              // Otherwise, if there are multiple predecessors, insert a PHI 
+              // that merges in the constant and simplify the block result.
               if (BlockIsSimpleEnoughToThreadThrough(BB)) {
                 PHINode *NewPN = new PHINode(Type::Int1Ty,
               if (BlockIsSimpleEnoughToThreadThrough(BB)) {
                 PHINode *NewPN = new PHINode(Type::Int1Ty,
-                                             BI->getCondition()->getName()+".pr",
-                                             BB->begin());
+                                            BI->getCondition()->getName()+".pr",
+                                            BB->begin());
                 for (PI = pred_begin(BB), E = pred_end(BB); PI != E; ++PI)
                   if ((PBI = dyn_cast<BranchInst>((*PI)->getTerminator())) &&
                       PBI != BI && PBI->isConditional() &&
                       PBI->getCondition() == BI->getCondition() &&
                       PBI->getSuccessor(0) != PBI->getSuccessor(1)) {
                     bool CondIsTrue = PBI->getSuccessor(0) == BB;
                 for (PI = pred_begin(BB), E = pred_end(BB); PI != E; ++PI)
                   if ((PBI = dyn_cast<BranchInst>((*PI)->getTerminator())) &&
                       PBI != BI && PBI->isConditional() &&
                       PBI->getCondition() == BI->getCondition() &&
                       PBI->getSuccessor(0) != PBI->getSuccessor(1)) {
                     bool CondIsTrue = PBI->getSuccessor(0) == BB;
-                    NewPN->addIncoming(ConstantInt::get(CondIsTrue), *PI);
+                    NewPN->addIncoming(ConstantInt::get(Type::Int1Ty, 
+                                                        CondIsTrue), *PI);
                   } else {
                     NewPN->addIncoming(BI->getCondition(), *PI);
                   }
                   } else {
                     NewPN->addIncoming(BI->getCondition(), *PI);
                   }
index 09f6feed6d3b0aa7600097be60faab4100e8ff17..138ab3520fd37d0714176d1dc5ced65a9bb275aa 100644 (file)
@@ -440,8 +440,9 @@ static void WriteConstantInt(std::ostream &Out, const Constant *CV,
   static std::string Indent = "\n";
   if (const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) {
     if (CI->getType() == Type::Int1Ty) 
   static std::string Indent = "\n";
   if (const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) {
     if (CI->getType() == Type::Int1Ty) 
-      Out << (CI->getBoolValue() ? "true" : "false");
-    else Out << CI->getSExtValue();
+      Out << (CI->getZExtValue() ? "true" : "false");
+    else 
+      Out << CI->getSExtValue();
   } else if (const ConstantFP *CFP = dyn_cast<ConstantFP>(CV)) {
     // We would like to output the FP constant value in exponential notation,
     // but we cannot do this if doing so will lose precision.  Check here to
   } else if (const ConstantFP *CFP = dyn_cast<ConstantFP>(CV)) {
     // We would like to output the FP constant value in exponential notation,
     // but we cannot do this if doing so will lose precision.  Check here to
index 85e5992dcf1f3c2ac54710810c58fc615c4f083f..1f5aeb35caf8ccffb4d0ad3c8860e9e53a6eb923 100644 (file)
@@ -317,8 +317,7 @@ Constant *llvm::ConstantFoldSelectInstruction(const Constant *Cond,
                                               const Constant *V1,
                                               const Constant *V2) {
   if (const ConstantInt *CB = dyn_cast<ConstantInt>(Cond))
                                               const Constant *V1,
                                               const Constant *V2) {
   if (const ConstantInt *CB = dyn_cast<ConstantInt>(Cond))
-    if (CB->getType() == Type::Int1Ty)
-      return const_cast<Constant*>(CB->getBoolValue() ? V1 : V2);
+    return const_cast<Constant*>(CB->getZExtValue() ? V1 : V2);
 
   if (isa<UndefValue>(V1)) return const_cast<Constant*>(V2);
   if (isa<UndefValue>(V2)) return const_cast<Constant*>(V1);
 
   if (isa<UndefValue>(V1)) return const_cast<Constant*>(V2);
   if (isa<UndefValue>(V2)) return const_cast<Constant*>(V1);
@@ -560,11 +559,14 @@ Constant *llvm::ConstantFoldBinaryInstruction(unsigned Opcode,
           default:
             break;
           case Instruction::And:
           default:
             break;
           case Instruction::And:
-            return ConstantInt::get(CI1->getBoolValue() & CI2->getBoolValue());
+            return ConstantInt::get(Type::Int1Ty, 
+                                    CI1->getZExtValue() & CI2->getZExtValue());
           case Instruction::Or:
           case Instruction::Or:
-            return ConstantInt::get(CI1->getBoolValue() | CI2->getBoolValue());
+            return ConstantInt::get(Type::Int1Ty, 
+                                    CI1->getZExtValue() | CI2->getZExtValue());
           case Instruction::Xor:
           case Instruction::Xor:
-            return ConstantInt::get(CI1->getBoolValue() ^ CI2->getBoolValue());
+            return ConstantInt::get(Type::Int1Ty, 
+                                    CI1->getZExtValue() ^ CI2->getZExtValue());
         }
       } else {
         uint64_t C1Val = CI1->getZExtValue();
         }
       } else {
         uint64_t C1Val = CI1->getZExtValue();
@@ -765,15 +767,15 @@ static FCmpInst::Predicate evaluateFCmpRelation(const Constant *V1,
       Constant *C2 = const_cast<Constant*>(V2);
       R = dyn_cast<ConstantInt>(
                              ConstantExpr::getFCmp(FCmpInst::FCMP_OEQ, C1, C2));
       Constant *C2 = const_cast<Constant*>(V2);
       R = dyn_cast<ConstantInt>(
                              ConstantExpr::getFCmp(FCmpInst::FCMP_OEQ, C1, C2));
-      if (R && R->getBoolValue()) 
+      if (R && R->getZExtValue()) 
         return FCmpInst::FCMP_OEQ;
       R = dyn_cast<ConstantInt>(
                              ConstantExpr::getFCmp(FCmpInst::FCMP_OLT, C1, C2));
         return FCmpInst::FCMP_OEQ;
       R = dyn_cast<ConstantInt>(
                              ConstantExpr::getFCmp(FCmpInst::FCMP_OLT, C1, C2));
-      if (R && R->getBoolValue()) 
+      if (R && R->getZExtValue()) 
         return FCmpInst::FCMP_OLT;
       R = dyn_cast<ConstantInt>(
                              ConstantExpr::getFCmp(FCmpInst::FCMP_OGT, C1, C2));
         return FCmpInst::FCMP_OLT;
       R = dyn_cast<ConstantInt>(
                              ConstantExpr::getFCmp(FCmpInst::FCMP_OGT, C1, C2));
-      if (R && R->getBoolValue()) 
+      if (R && R->getZExtValue()) 
         return FCmpInst::FCMP_OGT;
 
       // Nothing more we can do
         return FCmpInst::FCMP_OGT;
 
       // Nothing more we can do
@@ -832,15 +834,15 @@ static ICmpInst::Predicate evaluateICmpRelation(const Constant *V1,
       Constant *C2 = const_cast<Constant*>(V2);
       ICmpInst::Predicate pred = ICmpInst::ICMP_EQ;
       R = dyn_cast<ConstantInt>(ConstantExpr::getICmp(pred, C1, C2));
       Constant *C2 = const_cast<Constant*>(V2);
       ICmpInst::Predicate pred = ICmpInst::ICMP_EQ;
       R = dyn_cast<ConstantInt>(ConstantExpr::getICmp(pred, C1, C2));
-      if (R && R->getBoolValue()) 
+      if (R && R->getZExtValue()) 
         return pred;
       pred = isSigned ? ICmpInst::ICMP_SLT : ICmpInst::ICMP_ULT;
       R = dyn_cast<ConstantInt>(ConstantExpr::getICmp(pred, C1, C2));
         return pred;
       pred = isSigned ? ICmpInst::ICMP_SLT : ICmpInst::ICMP_ULT;
       R = dyn_cast<ConstantInt>(ConstantExpr::getICmp(pred, C1, C2));
-      if (R && R->getBoolValue())
+      if (R && R->getZExtValue())
         return pred;
       pred = isSigned ?  ICmpInst::ICMP_SGT : ICmpInst::ICMP_UGT;
       R = dyn_cast<ConstantInt>(ConstantExpr::getICmp(pred, C1, C2));
         return pred;
       pred = isSigned ?  ICmpInst::ICMP_SGT : ICmpInst::ICMP_UGT;
       R = dyn_cast<ConstantInt>(ConstantExpr::getICmp(pred, C1, C2));
-      if (R && R->getBoolValue())
+      if (R && R->getZExtValue())
         return pred;
       
       // If we couldn't figure it out, bail.
         return pred;
       
       // If we couldn't figure it out, bail.
@@ -1059,20 +1061,30 @@ Constant *llvm::ConstantFoldCompareInstruction(unsigned short pred,
 
   if (isa<ConstantInt>(C1) && isa<ConstantInt>(C2) &&
       C1->getType() == Type::Int1Ty && C2->getType() == Type::Int1Ty) {
 
   if (isa<ConstantInt>(C1) && isa<ConstantInt>(C2) &&
       C1->getType() == Type::Int1Ty && C2->getType() == Type::Int1Ty) {
-    bool C1Val = cast<ConstantInt>(C1)->getBoolValue();
-    bool C2Val = cast<ConstantInt>(C2)->getBoolValue();
+    bool C1Val = cast<ConstantInt>(C1)->getZExtValue();
+    bool C2Val = cast<ConstantInt>(C2)->getZExtValue();
     switch (pred) {
     default: assert(0 && "Invalid ICmp Predicate"); return 0;
     switch (pred) {
     default: assert(0 && "Invalid ICmp Predicate"); return 0;
-    case ICmpInst::ICMP_EQ: return ConstantInt::get(C1Val == C2Val);
-    case ICmpInst::ICMP_NE: return ConstantInt::get(C1Val != C2Val);
-    case ICmpInst::ICMP_ULT:return ConstantInt::get(C1Val <  C2Val);
-    case ICmpInst::ICMP_UGT:return ConstantInt::get(C1Val >  C2Val);
-    case ICmpInst::ICMP_ULE:return ConstantInt::get(C1Val <= C2Val);
-    case ICmpInst::ICMP_UGE:return ConstantInt::get(C1Val >= C2Val);
-    case ICmpInst::ICMP_SLT:return ConstantInt::get(C1Val <  C2Val);
-    case ICmpInst::ICMP_SGT:return ConstantInt::get(C1Val >  C2Val);
-    case ICmpInst::ICMP_SLE:return ConstantInt::get(C1Val <= C2Val);
-    case ICmpInst::ICMP_SGE:return ConstantInt::get(C1Val >= C2Val);
+    case ICmpInst::ICMP_EQ: 
+      return ConstantInt::get(Type::Int1Ty, C1Val == C2Val);
+    case ICmpInst::ICMP_NE: 
+      return ConstantInt::get(Type::Int1Ty, C1Val != C2Val);
+    case ICmpInst::ICMP_ULT:
+      return ConstantInt::get(Type::Int1Ty, C1Val <  C2Val);
+    case ICmpInst::ICMP_UGT:
+      return ConstantInt::get(Type::Int1Ty, C1Val >  C2Val);
+    case ICmpInst::ICMP_ULE:
+      return ConstantInt::get(Type::Int1Ty, C1Val <= C2Val);
+    case ICmpInst::ICMP_UGE:
+      return ConstantInt::get(Type::Int1Ty, C1Val >= C2Val);
+    case ICmpInst::ICMP_SLT:
+      return ConstantInt::get(Type::Int1Ty, C1Val <  C2Val);
+    case ICmpInst::ICMP_SGT:
+      return ConstantInt::get(Type::Int1Ty, C1Val >  C2Val);
+    case ICmpInst::ICMP_SLE:
+      return ConstantInt::get(Type::Int1Ty, C1Val <= C2Val);
+    case ICmpInst::ICMP_SGE:
+      return ConstantInt::get(Type::Int1Ty, C1Val >= C2Val);
     }
   } else if (isa<ConstantInt>(C1) && isa<ConstantInt>(C2)) {
     if (ICmpInst::isSignedPredicate(ICmpInst::Predicate(pred))) {
     }
   } else if (isa<ConstantInt>(C1) && isa<ConstantInt>(C2)) {
     if (ICmpInst::isSignedPredicate(ICmpInst::Predicate(pred))) {
@@ -1080,22 +1092,22 @@ Constant *llvm::ConstantFoldCompareInstruction(unsigned short pred,
       int64_t V2 = cast<ConstantInt>(C2)->getSExtValue();
       switch (pred) {
       default: assert(0 && "Invalid ICmp Predicate"); return 0;
       int64_t V2 = cast<ConstantInt>(C2)->getSExtValue();
       switch (pred) {
       default: assert(0 && "Invalid ICmp Predicate"); return 0;
-      case ICmpInst::ICMP_SLT:return ConstantInt::get(V1 <  V2);
-      case ICmpInst::ICMP_SGT:return ConstantInt::get(V1 >  V2);
-      case ICmpInst::ICMP_SLE:return ConstantInt::get(V1 <= V2);
-      case ICmpInst::ICMP_SGE:return ConstantInt::get(V1 >= V2);
+      case ICmpInst::ICMP_SLT:return ConstantInt::get(Type::Int1Ty, V1 <  V2);
+      case ICmpInst::ICMP_SGT:return ConstantInt::get(Type::Int1Ty, V1 >  V2);
+      case ICmpInst::ICMP_SLE:return ConstantInt::get(Type::Int1Ty, V1 <= V2);
+      case ICmpInst::ICMP_SGE:return ConstantInt::get(Type::Int1Ty, V1 >= V2);
       }
     } else {
       uint64_t V1 = cast<ConstantInt>(C1)->getZExtValue();
       uint64_t V2 = cast<ConstantInt>(C2)->getZExtValue();
       switch (pred) {
       default: assert(0 && "Invalid ICmp Predicate"); return 0;
       }
     } else {
       uint64_t V1 = cast<ConstantInt>(C1)->getZExtValue();
       uint64_t V2 = cast<ConstantInt>(C2)->getZExtValue();
       switch (pred) {
       default: assert(0 && "Invalid ICmp Predicate"); return 0;
-      case ICmpInst::ICMP_EQ: return ConstantInt::get(V1 == V2);
-      case ICmpInst::ICMP_NE: return ConstantInt::get(V1 != V2);
-      case ICmpInst::ICMP_ULT:return ConstantInt::get(V1 <  V2);
-      case ICmpInst::ICMP_UGT:return ConstantInt::get(V1 >  V2);
-      case ICmpInst::ICMP_ULE:return ConstantInt::get(V1 <= V2);
-      case ICmpInst::ICMP_UGE:return ConstantInt::get(V1 >= V2);
+      case ICmpInst::ICMP_EQ: return ConstantInt::get(Type::Int1Ty, V1 == V2);
+      case ICmpInst::ICMP_NE: return ConstantInt::get(Type::Int1Ty, V1 != V2);
+      case ICmpInst::ICMP_ULT:return ConstantInt::get(Type::Int1Ty, V1 <  V2);
+      case ICmpInst::ICMP_UGT:return ConstantInt::get(Type::Int1Ty, V1 >  V2);
+      case ICmpInst::ICMP_ULE:return ConstantInt::get(Type::Int1Ty, V1 <= V2);
+      case ICmpInst::ICMP_UGE:return ConstantInt::get(Type::Int1Ty, V1 >= V2);
       }
     }
   } else if (isa<ConstantFP>(C1) && isa<ConstantFP>(C2)) {
       }
     }
   } else if (isa<ConstantFP>(C1) && isa<ConstantFP>(C2)) {
@@ -1106,39 +1118,45 @@ Constant *llvm::ConstantFoldCompareInstruction(unsigned short pred,
     case FCmpInst::FCMP_FALSE: return ConstantInt::getFalse();
     case FCmpInst::FCMP_TRUE:  return ConstantInt::getTrue();
     case FCmpInst::FCMP_UNO:
     case FCmpInst::FCMP_FALSE: return ConstantInt::getFalse();
     case FCmpInst::FCMP_TRUE:  return ConstantInt::getTrue();
     case FCmpInst::FCMP_UNO:
-      return ConstantInt::get(C1Val != C1Val || C2Val != C2Val);
+      return ConstantInt::get(Type::Int1Ty, C1Val != C1Val || C2Val != C2Val);
     case FCmpInst::FCMP_ORD:
     case FCmpInst::FCMP_ORD:
-      return ConstantInt::get(C1Val == C1Val && C2Val == C2Val);
+      return ConstantInt::get(Type::Int1Ty, C1Val == C1Val && C2Val == C2Val);
     case FCmpInst::FCMP_UEQ:
       if (C1Val != C1Val || C2Val != C2Val)
         return ConstantInt::getTrue();
       /* FALL THROUGH */
     case FCmpInst::FCMP_UEQ:
       if (C1Val != C1Val || C2Val != C2Val)
         return ConstantInt::getTrue();
       /* FALL THROUGH */
-    case FCmpInst::FCMP_OEQ:   return ConstantInt::get(C1Val == C2Val);
+    case FCmpInst::FCMP_OEQ:   
+      return ConstantInt::get(Type::Int1Ty, C1Val == C2Val);
     case FCmpInst::FCMP_UNE:
       if (C1Val != C1Val || C2Val != C2Val)
         return ConstantInt::getTrue();
       /* FALL THROUGH */
     case FCmpInst::FCMP_UNE:
       if (C1Val != C1Val || C2Val != C2Val)
         return ConstantInt::getTrue();
       /* FALL THROUGH */
-    case FCmpInst::FCMP_ONE:   return ConstantInt::get(C1Val != C2Val);
+    case FCmpInst::FCMP_ONE:   
+      return ConstantInt::get(Type::Int1Ty, C1Val != C2Val);
     case FCmpInst::FCMP_ULT: 
       if (C1Val != C1Val || C2Val != C2Val)
         return ConstantInt::getTrue();
       /* FALL THROUGH */
     case FCmpInst::FCMP_ULT: 
       if (C1Val != C1Val || C2Val != C2Val)
         return ConstantInt::getTrue();
       /* FALL THROUGH */
-    case FCmpInst::FCMP_OLT:   return ConstantInt::get(C1Val < C2Val);
+    case FCmpInst::FCMP_OLT:   
+      return ConstantInt::get(Type::Int1Ty, C1Val < C2Val);
     case FCmpInst::FCMP_UGT:
       if (C1Val != C1Val || C2Val != C2Val)
         return ConstantInt::getTrue();
       /* FALL THROUGH */
     case FCmpInst::FCMP_UGT:
       if (C1Val != C1Val || C2Val != C2Val)
         return ConstantInt::getTrue();
       /* FALL THROUGH */
-    case FCmpInst::FCMP_OGT:   return ConstantInt::get(C1Val > C2Val);
+    case FCmpInst::FCMP_OGT:
+      return ConstantInt::get(Type::Int1Ty, C1Val > C2Val);
     case FCmpInst::FCMP_ULE:
       if (C1Val != C1Val || C2Val != C2Val)
         return ConstantInt::getTrue();
       /* FALL THROUGH */
     case FCmpInst::FCMP_ULE:
       if (C1Val != C1Val || C2Val != C2Val)
         return ConstantInt::getTrue();
       /* FALL THROUGH */
-    case FCmpInst::FCMP_OLE:   return ConstantInt::get(C1Val <= C2Val);
+    case FCmpInst::FCMP_OLE: 
+      return ConstantInt::get(Type::Int1Ty, C1Val <= C2Val);
     case FCmpInst::FCMP_UGE:
       if (C1Val != C1Val || C2Val != C2Val)
         return ConstantInt::getTrue();
       /* FALL THROUGH */
     case FCmpInst::FCMP_UGE:
       if (C1Val != C1Val || C2Val != C2Val)
         return ConstantInt::getTrue();
       /* FALL THROUGH */
-    case FCmpInst::FCMP_OGE:   return ConstantInt::get(C1Val >= C2Val);
+    case FCmpInst::FCMP_OGE: 
+      return ConstantInt::get(Type::Int1Ty, C1Val >= C2Val);
     }
   } else if (const ConstantPacked *CP1 = dyn_cast<ConstantPacked>(C1)) {
     if (const ConstantPacked *CP2 = dyn_cast<ConstantPacked>(C2)) {
     }
   } else if (const ConstantPacked *CP1 = dyn_cast<ConstantPacked>(C1)) {
     if (const ConstantPacked *CP2 = dyn_cast<ConstantPacked>(C2)) {
@@ -1182,17 +1200,17 @@ Constant *llvm::ConstantFoldCompareInstruction(unsigned short pred,
     case FCmpInst::BAD_FCMP_PREDICATE:
       break; // Couldn't determine anything about these constants.
     case FCmpInst::FCMP_OEQ: // We know that C1 == C2
     case FCmpInst::BAD_FCMP_PREDICATE:
       break; // Couldn't determine anything about these constants.
     case FCmpInst::FCMP_OEQ: // We know that C1 == C2
-      return ConstantInt::get(
+      return ConstantInt::get(Type::Int1Ty,
           pred == FCmpInst::FCMP_UEQ || pred == FCmpInst::FCMP_OEQ ||
           pred == FCmpInst::FCMP_ULE || pred == FCmpInst::FCMP_OLE ||
           pred == FCmpInst::FCMP_UGE || pred == FCmpInst::FCMP_OGE);
     case FCmpInst::FCMP_OLT: // We know that C1 < C2
           pred == FCmpInst::FCMP_UEQ || pred == FCmpInst::FCMP_OEQ ||
           pred == FCmpInst::FCMP_ULE || pred == FCmpInst::FCMP_OLE ||
           pred == FCmpInst::FCMP_UGE || pred == FCmpInst::FCMP_OGE);
     case FCmpInst::FCMP_OLT: // We know that C1 < C2
-      return ConstantInt::get(
+      return ConstantInt::get(Type::Int1Ty,
           pred == FCmpInst::FCMP_UNE || pred == FCmpInst::FCMP_ONE ||
           pred == FCmpInst::FCMP_ULT || pred == FCmpInst::FCMP_OLT ||
           pred == FCmpInst::FCMP_ULE || pred == FCmpInst::FCMP_OLE);
     case FCmpInst::FCMP_OGT: // We know that C1 > C2
           pred == FCmpInst::FCMP_UNE || pred == FCmpInst::FCMP_ONE ||
           pred == FCmpInst::FCMP_ULT || pred == FCmpInst::FCMP_OLT ||
           pred == FCmpInst::FCMP_ULE || pred == FCmpInst::FCMP_OLE);
     case FCmpInst::FCMP_OGT: // We know that C1 > C2
-      return ConstantInt::get(
+      return ConstantInt::get(Type::Int1Ty,
           pred == FCmpInst::FCMP_UNE || pred == FCmpInst::FCMP_ONE ||
           pred == FCmpInst::FCMP_UGT || pred == FCmpInst::FCMP_OGT ||
           pred == FCmpInst::FCMP_UGE || pred == FCmpInst::FCMP_OGE);
           pred == FCmpInst::FCMP_UNE || pred == FCmpInst::FCMP_ONE ||
           pred == FCmpInst::FCMP_UGT || pred == FCmpInst::FCMP_OGT ||
           pred == FCmpInst::FCMP_UGE || pred == FCmpInst::FCMP_OGE);
@@ -1227,7 +1245,8 @@ Constant *llvm::ConstantFoldCompareInstruction(unsigned short pred,
     case ICmpInst::ICMP_EQ:   // We know the constants are equal!
       // If we know the constants are equal, we can decide the result of this
       // computation precisely.
     case ICmpInst::ICMP_EQ:   // We know the constants are equal!
       // If we know the constants are equal, we can decide the result of this
       // computation precisely.
-      return ConstantInt::get(pred == ICmpInst::ICMP_EQ  ||
+      return ConstantInt::get(Type::Int1Ty, 
+                              pred == ICmpInst::ICMP_EQ  ||
                               pred == ICmpInst::ICMP_ULE ||
                               pred == ICmpInst::ICMP_SLE ||
                               pred == ICmpInst::ICMP_UGE ||
                               pred == ICmpInst::ICMP_ULE ||
                               pred == ICmpInst::ICMP_SLE ||
                               pred == ICmpInst::ICMP_UGE ||
@@ -1235,25 +1254,29 @@ Constant *llvm::ConstantFoldCompareInstruction(unsigned short pred,
     case ICmpInst::ICMP_ULT:
       // If we know that C1 < C2, we can decide the result of this computation
       // precisely.
     case ICmpInst::ICMP_ULT:
       // If we know that C1 < C2, we can decide the result of this computation
       // precisely.
-      return ConstantInt::get(pred == ICmpInst::ICMP_ULT ||
+      return ConstantInt::get(Type::Int1Ty, 
+                              pred == ICmpInst::ICMP_ULT ||
                               pred == ICmpInst::ICMP_NE  ||
                               pred == ICmpInst::ICMP_ULE);
     case ICmpInst::ICMP_SLT:
       // If we know that C1 < C2, we can decide the result of this computation
       // precisely.
                               pred == ICmpInst::ICMP_NE  ||
                               pred == ICmpInst::ICMP_ULE);
     case ICmpInst::ICMP_SLT:
       // If we know that C1 < C2, we can decide the result of this computation
       // precisely.
-      return ConstantInt::get(pred == ICmpInst::ICMP_SLT ||
+      return ConstantInt::get(Type::Int1Ty,
+                              pred == ICmpInst::ICMP_SLT ||
                               pred == ICmpInst::ICMP_NE  ||
                               pred == ICmpInst::ICMP_SLE);
     case ICmpInst::ICMP_UGT:
       // If we know that C1 > C2, we can decide the result of this computation
       // precisely.
                               pred == ICmpInst::ICMP_NE  ||
                               pred == ICmpInst::ICMP_SLE);
     case ICmpInst::ICMP_UGT:
       // If we know that C1 > C2, we can decide the result of this computation
       // precisely.
-      return ConstantInt::get(pred == ICmpInst::ICMP_UGT ||
+      return ConstantInt::get(Type::Int1Ty, 
+                              pred == ICmpInst::ICMP_UGT ||
                               pred == ICmpInst::ICMP_NE  ||
                               pred == ICmpInst::ICMP_UGE);
     case ICmpInst::ICMP_SGT:
       // If we know that C1 > C2, we can decide the result of this computation
       // precisely.
                               pred == ICmpInst::ICMP_NE  ||
                               pred == ICmpInst::ICMP_UGE);
     case ICmpInst::ICMP_SGT:
       // If we know that C1 > C2, we can decide the result of this computation
       // precisely.
-      return ConstantInt::get(pred == ICmpInst::ICMP_SGT ||
+      return ConstantInt::get(Type::Int1Ty, 
+                              pred == ICmpInst::ICMP_SGT ||
                               pred == ICmpInst::ICMP_NE  ||
                               pred == ICmpInst::ICMP_SGE);
     case ICmpInst::ICMP_ULE:
                               pred == ICmpInst::ICMP_NE  ||
                               pred == ICmpInst::ICMP_SGE);
     case ICmpInst::ICMP_ULE:
index 48502903da96a1d6366441dbd6ee2b0b7d919950..73490912a5f47dbd60b165123edca8a09a90d236 100644 (file)
@@ -93,7 +93,7 @@ bool Constant::canTrap() const {
 Constant *Constant::getNullValue(const Type *Ty) {
   switch (Ty->getTypeID()) {
   case Type::Int1TyID: {
 Constant *Constant::getNullValue(const Type *Ty) {
   switch (Ty->getTypeID()) {
   case Type::Int1TyID: {
-    static Constant *NullBool = ConstantInt::get(false);
+    static Constant *NullBool = ConstantInt::get(Type::Int1Ty, false);
     return NullBool;
   }
   case Type::Int8TyID: {
     return NullBool;
   }
   case Type::Int8TyID: {
@@ -838,7 +838,11 @@ static ManagedStatic<ValueMap<uint64_t, Type, ConstantInt> > IntConstants;
 // just return the stored value while getSExtValue has to convert back to sign
 // extended. getZExtValue is more common in LLVM than getSExtValue().
 ConstantInt *ConstantInt::get(const Type *Ty, int64_t V) {
 // just return the stored value while getSExtValue has to convert back to sign
 // extended. getZExtValue is more common in LLVM than getSExtValue().
 ConstantInt *ConstantInt::get(const Type *Ty, int64_t V) {
-  if (Ty == Type::Int1Ty) return ConstantInt::get(V&1);
+  if (Ty == Type::Int1Ty) 
+    if (V & 1)
+      return getTrue();
+    else
+      return getFalse();
   return IntConstants->getOrCreate(Ty, V & Ty->getIntegralTypeMask());
 }
 
   return IntConstants->getOrCreate(Ty, V & Ty->getIntegralTypeMask());
 }
 
index 4e6fe6b3329eb04d6ff8df6724b9db99e57df62e..1f6cbaf2885e6e71d9546b7e28aff1b43f6a3b6d 100644 (file)
@@ -671,7 +671,7 @@ void CppWriter::printConstant(const Constant *CV) {
   if (const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) {
     if (CI->getType() == Type::Int1Ty)
       Out << "ConstantInt* " << constName << " = ConstantInt::get(" 
   if (const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) {
     if (CI->getType() == Type::Int1Ty)
       Out << "ConstantInt* " << constName << " = ConstantInt::get(" 
-          << (CI->getBoolValue() ? "true" : "false") << ");";
+          << (CI->getZExtValue() ? "true" : "false") << ");";
     else
       Out << "ConstantInt* " << constName << " = ConstantInt::get(" 
           << typeName << ", " << CI->getZExtValue() << ");";
     else
       Out << "ConstantInt* " << constName << " = ConstantInt::get(" 
           << typeName << ", " << CI->getZExtValue() << ");";