From 579dca12c2cfd60bc18aaadbd5331897d48fec29 Mon Sep 17 00:00:00 2001 From: Reid Spencer Date: Fri, 12 Jan 2007 04:24:46 +0000 Subject: Implement review feedback for the ConstantBool->ConstantInt merge. Chris 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 --- lib/Transforms/IPO/GlobalOpt.cpp | 4 +-- lib/Transforms/Instrumentation/RSProfiling.cpp | 4 +-- lib/Transforms/Scalar/CondPropagate.cpp | 2 +- lib/Transforms/Scalar/CorrelatedExprs.cpp | 26 +++++++------- lib/Transforms/Scalar/InstructionCombining.cpp | 47 +++++++++++++++----------- lib/Transforms/Scalar/LoopUnswitch.cpp | 13 +++---- lib/Transforms/Scalar/SCCP.cpp | 8 ++--- lib/Transforms/Utils/CloneFunction.cpp | 2 +- lib/Transforms/Utils/CodeExtractor.cpp | 2 +- lib/Transforms/Utils/Local.cpp | 4 +-- lib/Transforms/Utils/SimplifyCFG.cpp | 19 ++++++----- 11 files changed, 71 insertions(+), 60 deletions(-) (limited to 'lib/Transforms') diff --git a/lib/Transforms/IPO/GlobalOpt.cpp b/lib/Transforms/IPO/GlobalOpt.cpp index ce30477..86657c2 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(CurInst)) { ConstantInt *Val = diff --git a/lib/Transforms/Instrumentation/RSProfiling.cpp b/lib/Transforms/Instrumentation/RSProfiling.cpp index 5c0aa36..c0a7a05 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(Translate(dst)), bbC); new BranchInst(dst, cast(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(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 65e8c8d..253535e 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 09d5c07..00055b4 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(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(*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(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(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(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(Result)->getBoolValue() + return cast(Result)->getZExtValue() ? Relation::KnownTrue : Relation::KnownFalse; } } else { diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp index bf4f5f3..c039b39 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(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(Op0); - if (cast(Cmp)->getBoolValue()) { + if (cast(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(Op0); - if (cast(Cmp)->getBoolValue()) { + if (cast(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(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(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(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(Op0)) if (GlobalValue *GV1 = dyn_cast(Op1)) if (!GV0->hasExternalWeakLinkage() || !GV1->hasExternalWeakLinkage()) - return ReplaceInstUsesWith(I, ConstantInt::get(!isTrueWhenEqual(I))); + return ReplaceInstUsesWith(I, ConstantInt::get(Type::Int1Ty, + !isTrueWhenEqual(I))); // icmp , - Global/Stack value // addresses never equal each other! We already know that Op0 != Op1. @@ -4351,7 +4357,8 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) { isa(Op0)) && (isa(Op1) || isa(Op1) || isa(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(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(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(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 { @@ -6586,7 +6595,7 @@ Instruction *InstCombiner::visitSelectInst(SelectInst &SI) { } } else if ((C = dyn_cast(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 { @@ -9049,7 +9058,7 @@ static void AddReachableCodeToWorklist(BasicBlock *BB, if (BranchInst *BI = dyn_cast(TI)) { if (BI->isConditional() && isa(BI->getCondition()) && BI->getCondition()->getType() == Type::Int1Ty) { - bool CondVal = cast(BI->getCondition())->getBoolValue(); + bool CondVal = cast(BI->getCondition())->getZExtValue(); AddReachableCodeToWorklist(BI->getSuccessor(!CondVal), Visited, WorkList, TD); return; diff --git a/lib/Transforms/Scalar/LoopUnswitch.cpp b/lib/Transforms/Scalar/LoopUnswitch.cpp index c97c9b5..80d4311 100644 --- a/lib/Transforms/Scalar/LoopUnswitch.cpp +++ b/lib/Transforms/Scalar/LoopUnswitch.cpp @@ -924,7 +924,8 @@ void LoopUnswitch::RewriteLoopBodyWithConditionConstant(Loop *L, Value *LIC, if (IsEqual) Replacement = Val; else - Replacement = ConstantInt::get(!cast(Val)->getBoolValue()); + Replacement = ConstantInt::get(Type::Int1Ty, + !cast(Val)->getZExtValue()); for (unsigned i = 0, e = Users.size(); i != e; ++i) if (Instruction *U = cast(Users[i])) { @@ -1026,7 +1027,7 @@ void LoopUnswitch::SimplifyCode(std::vector &Worklist) { switch (I->getOpcode()) { case Instruction::Select: if (ConstantInt *CB = dyn_cast(I->getOperand(0))) { - ReplaceUsesOfWith(I, I->getOperand(!CB->getBoolValue()+1), Worklist); + ReplaceUsesOfWith(I, I->getOperand(!CB->getZExtValue()+1), Worklist); continue; } break; @@ -1036,7 +1037,7 @@ void LoopUnswitch::SimplifyCode(std::vector &Worklist) { cast(I)->swapOperands(); if (ConstantInt *CB = dyn_cast(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); @@ -1049,7 +1050,7 @@ void LoopUnswitch::SimplifyCode(std::vector &Worklist) { cast(I)->swapOperands(); if (ConstantInt *CB = dyn_cast(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); @@ -1094,8 +1095,8 @@ void LoopUnswitch::SimplifyCode(std::vector &Worklist) { 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(); diff --git a/lib/Transforms/Scalar/SCCP.cpp b/lib/Transforms/Scalar/SCCP.cpp index daf21d4..2bc0004 100644 --- a/lib/Transforms/Scalar/SCCP.cpp +++ b/lib/Transforms/Scalar/SCCP.cpp @@ -416,8 +416,7 @@ void SCCPSolver::getFeasibleSuccessors(TerminatorInst &TI, } else { LatticeVal &BCValue = getValueState(BI->getCondition()); if (BCValue.isOverdefined() || - (BCValue.isConstant() && - BCValue.getConstant()->getType() != Type::Int1Ty)) { + (BCValue.isConstant() && !isa(BCValue.getConstant()))) { // 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; - if (CondValue.isConstant() && - CondValue.getConstant()->getType() == Type::Int1Ty) { + if (CondValue.isConstant()) { if (ConstantInt *CondCB = dyn_cast(CondValue.getConstant())){ - mergeInValue(&I, getValueState(CondCB->getBoolValue() ? I.getTrueValue() + mergeInValue(&I, getValueState(CondCB->getZExtValue() ? I.getTrueValue() : I.getFalseValue())); return; } diff --git a/lib/Transforms/Utils/CloneFunction.cpp b/lib/Transforms/Utils/CloneFunction.cpp index cb98dc5..753d657 100644 --- a/lib/Transforms/Utils/CloneFunction.cpp +++ b/lib/Transforms/Utils/CloneFunction.cpp @@ -233,7 +233,7 @@ void PruningFunctionCloner::CloneBlock(const BasicBlock *BB) { // 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; diff --git a/lib/Transforms/Utils/CodeExtractor.cpp b/lib/Transforms/Utils/CodeExtractor.cpp index 4e8f3c0..e83f1b0 100644 --- a/lib/Transforms/Utils/CodeExtractor.cpp +++ b/lib/Transforms/Utils/CodeExtractor.cpp @@ -470,7 +470,7 @@ emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer, 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); diff --git a/lib/Transforms/Utils/Local.cpp b/lib/Transforms/Utils/Local.cpp index f3d6ca8..fd24f10 100644 --- a/lib/Transforms/Utils/Local.cpp +++ b/lib/Transforms/Utils/Local.cpp @@ -176,8 +176,8 @@ bool llvm::ConstantFoldTerminator(BasicBlock *BB) { if (ConstantInt *Cond = dyn_cast(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() diff --git a/lib/Transforms/Utils/SimplifyCFG.cpp b/lib/Transforms/Utils/SimplifyCFG.cpp index 964b47c..25bc168 100644 --- a/lib/Transforms/Utils/SimplifyCFG.cpp +++ b/lib/Transforms/Utils/SimplifyCFG.cpp @@ -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); - BasicBlock *RealDest = BI->getSuccessor(!CB->getBoolValue()); + BasicBlock *RealDest = BI->getSuccessor(!CB->getZExtValue()); 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 - // 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 @@ -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; - BI->setCondition(ConstantInt::get(CondIsTrue)); + BI->setCondition(ConstantInt::get(Type::Int1Ty, CondIsTrue)); 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, - 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((*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); } -- cgit v1.1