diff options
27 files changed, 175 insertions, 159 deletions
diff --git a/include/llvm/Constants.h b/include/llvm/Constants.h index 337a62c511..dd85b43bc7 100644 --- a/include/llvm/Constants.h +++ b/include/llvm/Constants.h @@ -85,10 +85,6 @@ public: 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 @@ -96,22 +92,6 @@ public: /// @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 @@ -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. - virtual bool isAllOnesValue() const { - if (getType() == Type::Int1Ty) return getBoolValue() == true; + bool isAllOnesValue() const { 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. - 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 @@ -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. - 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 diff --git a/lib/Analysis/BasicAliasAnalysis.cpp b/lib/Analysis/BasicAliasAnalysis.cpp index ebe4cec60e..d49898a401 100644 --- a/lib/Analysis/BasicAliasAnalysis.cpp +++ b/lib/Analysis/BasicAliasAnalysis.cpp @@ -586,7 +586,7 @@ BasicAliasAnalysis::CheckGEPInstructions( 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; } diff --git a/lib/Analysis/ConstantRange.cpp b/lib/Analysis/ConstantRange.cpp index 6c2dce03aa..7a344201dd 100644 --- a/lib/Analysis/ConstantRange.cpp +++ b/lib/Analysis/ConstantRange.cpp @@ -64,7 +64,7 @@ static ConstantInt *getMinValue(const Type *Ty, bool isSigned = false) { } 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)); @@ -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??"); - 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??"); - return cast<ConstantInt>(C)->getBoolValue(); + return cast<ConstantInt>(C)->getZExtValue(); } static bool GT(ConstantInt *A, ConstantInt *B, bool isSigned) { diff --git a/lib/Analysis/ScalarEvolution.cpp b/lib/Analysis/ScalarEvolution.cpp index ad16acc9b4..27c9e622ca 100644 --- a/lib/Analysis/ScalarEvolution.cpp +++ b/lib/Analysis/ScalarEvolution.cpp @@ -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 - 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() @@ -1932,7 +1932,7 @@ ComputeIterationCountExhaustively(const Loop *L, Value *Cond, bool ExitWhen) { // 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)); @@ -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 (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 @@ -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 (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 diff --git a/lib/Bytecode/Reader/Reader.cpp b/lib/Bytecode/Reader/Reader.cpp index b3869fb773..787d000c23 100644 --- a/lib/Bytecode/Reader/Reader.cpp +++ b/lib/Bytecode/Reader/Reader.cpp @@ -1403,7 +1403,7 @@ Value *BytecodeReader::ParseConstantPoolValue(unsigned TypeID) { 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; } diff --git a/lib/Bytecode/Writer/Writer.cpp b/lib/Bytecode/Writer/Writer.cpp index 7acd2094c5..9a04428007 100644 --- a/lib/Bytecode/Writer/Writer.cpp +++ b/lib/Bytecode/Writer/Writer.cpp @@ -322,7 +322,7 @@ void BytecodeWriter::outputConstant(const Constant *CPV) { 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); diff --git a/lib/CodeGen/AsmPrinter.cpp b/lib/CodeGen/AsmPrinter.cpp index fed85b3e50..d7a134e46d 100644 --- a/lib/CodeGen/AsmPrinter.cpp +++ b/lib/CodeGen/AsmPrinter.cpp @@ -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) { - assert(CI->getBoolValue()); + assert(CI->getZExtValue()); O << "1"; } else O << CI->getSExtValue(); } else if (const GlobalValue *GV = dyn_cast<GlobalValue>(CV)) { diff --git a/lib/CodeGen/MachineDebugInfo.cpp b/lib/CodeGen/MachineDebugInfo.cpp index 2ebd64bf35..0a6d3acb9c 100644 --- a/lib/CodeGen/MachineDebugInfo.cpp +++ b/lib/CodeGen/MachineDebugInfo.cpp @@ -211,7 +211,7 @@ public: } 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++); @@ -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(Field)); + Elements.push_back(ConstantInt::get(Type::Int1Ty, Field)); } virtual void Apply(std::string &Field) { Elements.push_back(SR.getString(Field)); diff --git a/lib/ExecutionEngine/ExecutionEngine.cpp b/lib/ExecutionEngine/ExecutionEngine.cpp index 3c388d32f3..e5f9ea1f40 100644 --- a/lib/ExecutionEngine/ExecutionEngine.cpp +++ b/lib/ExecutionEngine/ExecutionEngine.cpp @@ -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 - 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); diff --git a/lib/ExecutionEngine/JIT/JIT.cpp b/lib/ExecutionEngine/JIT/JIT.cpp index f6ced0a251..13ee7199d9 100644 --- a/lib/ExecutionEngine/JIT/JIT.cpp +++ b/lib/ExecutionEngine/JIT/JIT.cpp @@ -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!"); - 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; diff --git a/lib/Support/ConstantRange.cpp b/lib/Support/ConstantRange.cpp index 6c2dce03aa..7a344201dd 100644 --- a/lib/Support/ConstantRange.cpp +++ b/lib/Support/ConstantRange.cpp @@ -64,7 +64,7 @@ static ConstantInt *getMinValue(const Type *Ty, bool isSigned = false) { } 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)); @@ -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??"); - 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??"); - return cast<ConstantInt>(C)->getBoolValue(); + return cast<ConstantInt>(C)->getZExtValue(); } static bool GT(ConstantInt *A, ConstantInt *B, bool isSigned) { diff --git a/lib/Target/CBackend/CBackend.cpp b/lib/Target/CBackend/CBackend.cpp index f945036a74..23465c5f6e 100644 --- a/lib/Target/CBackend/CBackend.cpp +++ b/lib/Target/CBackend/CBackend.cpp @@ -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) - Out << (CI->getBoolValue() ? '1' : '0') ; + Out << (CI->getZExtValue() ? '1' : '0') ; else { Out << "(("; printPrimitiveType(Out, Ty, false) << ')'; diff --git a/lib/Transforms/IPO/GlobalOpt.cpp b/lib/Transforms/IPO/GlobalOpt.cpp index ce30477c87..86657c2c0e 100644 --- a/lib/Transforms/IPO/GlobalOpt.cpp +++ b/lib/Transforms/IPO/GlobalOpt.cpp @@ -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) - 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 @@ -1803,7 +1803,7 @@ static bool EvaluateFunction(Function *F, Constant *&RetVal, // 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 = diff --git a/lib/Transforms/Instrumentation/RSProfiling.cpp b/lib/Transforms/Instrumentation/RSProfiling.cpp index 5c0aa36361..c0a7a0569b 100644 --- a/lib/Transforms/Instrumentation/RSProfiling.cpp +++ b/lib/Transforms/Instrumentation/RSProfiling.cpp @@ -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)), - ConstantInt::get(true), bbCp); + ConstantInt::get(Type::Int1Ty, true), bbCp); //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))), - ConstantInt::get(true))); + ConstantInt::get(Type::Int1Ty, true))); //do whatever is needed now that the function is duplicated c->PrepFunction(&F); diff --git a/lib/Transforms/Scalar/CondPropagate.cpp b/lib/Transforms/Scalar/CondPropagate.cpp index 65e8c8d1de..253535e3a5 100644 --- a/lib/Transforms/Scalar/CondPropagate.cpp +++ b/lib/Transforms/Scalar/CondPropagate.cpp @@ -139,7 +139,7 @@ void CondProp::SimplifyPredecessors(BranchInst *BI) { // 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 diff --git a/lib/Transforms/Scalar/CorrelatedExprs.cpp b/lib/Transforms/Scalar/CorrelatedExprs.cpp index 09d5c07060..00055b4586 100644 --- a/lib/Transforms/Scalar/CorrelatedExprs.cpp +++ b/lib/Transforms/Scalar/CorrelatedExprs.cpp @@ -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; - PropagateEquality(CI, ConstantInt::get(Res), NewRI); + PropagateEquality(CI, ConstantInt::get(Type::Int1Ty, Res), NewRI); } 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, - BI->getSuccessor(!CB->getBoolValue()), NewRI); + BI->getSuccessor(!CB->getZExtValue()), NewRI); 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. // - 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); } @@ -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. // - 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); } - // 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), - 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 (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); @@ -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)) { - 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); @@ -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) { - 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); - 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; @@ -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); - return cast<ConstantInt>(Result)->getBoolValue() + return cast<ConstantInt>(Result)->getZExtValue() ? Relation::KnownTrue : Relation::KnownFalse; } } else { diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp index bf4f5f3e23..c039b3999a 100644 --- a/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/lib/Transforms/Scalar/InstructionCombining.cpp @@ -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 ? - 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) { @@ -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); - if (cast<ConstantInt>(Cmp)->getBoolValue()) { + if (cast<ConstantInt>(Cmp)->getZExtValue()) { 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); - if (cast<ConstantInt>(Cmp)->getBoolValue()) { + if (cast<ConstantInt>(Cmp)->getZExtValue()) { 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. - ConstantInt::get(Cond == ICmpInst::ICMP_NE)); + ConstantInt::get(Type::Int1Ty, + Cond == ICmpInst::ICMP_NE)); } if (EmitIt) { @@ -4176,7 +4177,8 @@ Instruction *InstCombiner::FoldGEPICmp(User *GEPLHS, Value *RHS, 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 @@ -4253,7 +4255,8 @@ Instruction *InstCombiner::FoldGEPICmp(User *GEPLHS, Value *RHS, 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); @@ -4281,7 +4284,8 @@ Instruction *InstCombiner::visitFCmpInst(FCmpInst &I) { // 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)); @@ -4333,7 +4337,8 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) { // 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)); @@ -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()) - 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. @@ -4351,7 +4357,8 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) { 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) { @@ -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; - Constant *Cst = ConstantInt::get(IsICMP_NE); + Constant *Cst = ConstantInt::get(Type::Int1Ty, IsICMP_NE); 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; - Constant *Cst = ConstantInt::get(IsICMP_NE); + Constant *Cst = ConstantInt::get(Type::Int1Ty, IsICMP_NE); 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()) - return ReplaceInstUsesWith(I, ConstantInt::get(isICMP_NE)); + return ReplaceInstUsesWith(I, ConstantInt::get(Type::Int1Ty, + isICMP_NE)); } break; @@ -4967,7 +4975,8 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) { // 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)) @@ -6182,7 +6191,7 @@ Instruction *InstCombiner::commonIntCastTransforms(CastInst &CI) { 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); } @@ -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)) - return ReplaceInstUsesWith(SI, C->getBoolValue() ? TrueVal : FalseVal); + return ReplaceInstUsesWith(SI, C->getZExtValue() ? 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) { - if (C->getBoolValue()) { + if (C->getZExtValue()) { // Change: A = select B, true, C --> A = or B, C return BinaryOperator::createOr(CondVal, FalseVal); } else { |