summaryrefslogtreecommitdiff
path: root/lib/Transforms
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2006-09-28 23:35:22 +0000
committerChris Lattner <sabre@nondot.org>2006-09-28 23:35:22 +0000
commit47811b76ca92ddfebdd73c633d04ba8a4f5b7b59 (patch)
tree3c7b9b20902cda17bf25711def4c18f5fea2fbd0 /lib/Transforms
parent850ba99cb6fe5b7c70eb81103441d1fe123d6291 (diff)
downloadllvm-47811b76ca92ddfebdd73c633d04ba8a4f5b7b59.tar.gz
llvm-47811b76ca92ddfebdd73c633d04ba8a4f5b7b59.tar.bz2
llvm-47811b76ca92ddfebdd73c633d04ba8a4f5b7b59.tar.xz
Eliminate ConstantBool::True and ConstantBool::False. Instead, provide
ConstantBool::getTrue() and ConstantBool::getFalse(). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@30665 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms')
-rw-r--r--lib/Transforms/IPO/GlobalOpt.cpp9
-rw-r--r--lib/Transforms/Scalar/CorrelatedExprs.cpp7
-rw-r--r--lib/Transforms/Scalar/InstructionCombining.cpp109
-rw-r--r--lib/Transforms/Scalar/LoopUnswitch.cpp19
-rw-r--r--lib/Transforms/Scalar/PredicateSimplifier.cpp73
-rw-r--r--lib/Transforms/Scalar/SCCP.cpp15
6 files changed, 113 insertions, 119 deletions
diff --git a/lib/Transforms/IPO/GlobalOpt.cpp b/lib/Transforms/IPO/GlobalOpt.cpp
index 609bd94aa1..37c1e40494 100644
--- a/lib/Transforms/IPO/GlobalOpt.cpp
+++ b/lib/Transforms/IPO/GlobalOpt.cpp
@@ -709,7 +709,7 @@ static GlobalVariable *OptimizeGlobalAddressOfMalloc(GlobalVariable *GV,
// keep track of whether the global was initialized yet or not.
GlobalVariable *InitBool =
new GlobalVariable(Type::BoolTy, false, GlobalValue::InternalLinkage,
- ConstantBool::False, GV->getName()+".init");
+ ConstantBool::getFalse(), GV->getName()+".init");
bool InitBoolUsed = false;
// Loop over all uses of GV, processing them in turn.
@@ -728,7 +728,7 @@ static GlobalVariable *OptimizeGlobalAddressOfMalloc(GlobalVariable *GV,
switch (SCI->getOpcode()) {
default: assert(0 && "Unknown opcode!");
case Instruction::SetLT:
- LV = ConstantBool::False; // X < null -> always false
+ LV = ConstantBool::getFalse(); // X < null -> always false
break;
case Instruction::SetEQ:
case Instruction::SetLE:
@@ -747,7 +747,7 @@ static GlobalVariable *OptimizeGlobalAddressOfMalloc(GlobalVariable *GV,
} else {
StoreInst *SI = cast<StoreInst>(GV->use_back());
// The global is initialized when the store to it occurs.
- new StoreInst(ConstantBool::True, InitBool, SI);
+ new StoreInst(ConstantBool::getTrue(), InitBool, SI);
SI->eraseFromParent();
}
@@ -859,7 +859,8 @@ static bool OptimizeOnceStoredGlobal(GlobalVariable *GV, Value *StoredOnceVal,
static void ShrinkGlobalToBoolean(GlobalVariable *GV, Constant *OtherVal) {
// Create the new global, initializing it to false.
GlobalVariable *NewGV = new GlobalVariable(Type::BoolTy, false,
- GlobalValue::InternalLinkage, ConstantBool::False, GV->getName()+".b");
+ GlobalValue::InternalLinkage, ConstantBool::getFalse(),
+ GV->getName()+".b");
GV->getParent()->getGlobalList().insert(GV, NewGV);
Constant *InitVal = GV->getInitializer();
diff --git a/lib/Transforms/Scalar/CorrelatedExprs.cpp b/lib/Transforms/Scalar/CorrelatedExprs.cpp
index 722a224639..4c5025659c 100644
--- a/lib/Transforms/Scalar/CorrelatedExprs.cpp
+++ b/lib/Transforms/Scalar/CorrelatedExprs.cpp
@@ -788,12 +788,12 @@ void CEE::PropagateBranchInfo(BranchInst *BI) {
// Propagate information into the true block...
//
- PropagateEquality(BI->getCondition(), ConstantBool::True,
+ PropagateEquality(BI->getCondition(), ConstantBool::getTrue(),
getRegionInfo(BI->getSuccessor(0)));
// Propagate information into the false block...
//
- PropagateEquality(BI->getCondition(), ConstantBool::False,
+ PropagateEquality(BI->getCondition(), ConstantBool::getFalse(),
getRegionInfo(BI->getSuccessor(1)));
}
@@ -971,8 +971,7 @@ void CEE::IncorporateInstruction(Instruction *Inst, RegionInfo &RI) {
// See if we can figure out a result for this instruction...
Relation::KnownResult Result = getSetCCResult(SCI, RI);
if (Result != Relation::Unknown) {
- PropagateEquality(SCI, Result ? ConstantBool::True : ConstantBool::False,
- RI);
+ PropagateEquality(SCI, ConstantBool::get(Result != 0), RI);
}
}
}
diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp
index 79c204f93e..19051fa2e1 100644
--- a/lib/Transforms/Scalar/InstructionCombining.cpp
+++ b/lib/Transforms/Scalar/InstructionCombining.cpp
@@ -1989,7 +1989,7 @@ Instruction *InstCombiner::visitDiv(BinaryOperator &I) {
if (ST->isNullValue()) {
Instruction *CondI = dyn_cast<Instruction>(SI->getOperand(0));
if (CondI && CondI->getParent() == I.getParent())
- UpdateValueUsesWith(CondI, ConstantBool::False);
+ UpdateValueUsesWith(CondI, ConstantBool::getFalse());
else if (I.getParent() != SI->getParent() || SI->hasOneUse())
I.setOperand(1, SI->getOperand(2));
else
@@ -2001,7 +2001,7 @@ Instruction *InstCombiner::visitDiv(BinaryOperator &I) {
if (ST->isNullValue()) {
Instruction *CondI = dyn_cast<Instruction>(SI->getOperand(0));
if (CondI && CondI->getParent() == I.getParent())
- UpdateValueUsesWith(CondI, ConstantBool::True);
+ UpdateValueUsesWith(CondI, ConstantBool::getTrue());
else if (I.getParent() != SI->getParent() || SI->hasOneUse())
I.setOperand(1, SI->getOperand(1));
else
@@ -2213,7 +2213,7 @@ Instruction *InstCombiner::visitRem(BinaryOperator &I) {
if (ST->isNullValue()) {
Instruction *CondI = dyn_cast<Instruction>(SI->getOperand(0));
if (CondI && CondI->getParent() == I.getParent())
- UpdateValueUsesWith(CondI, ConstantBool::False);
+ UpdateValueUsesWith(CondI, ConstantBool::getFalse());
else if (I.getParent() != SI->getParent() || SI->hasOneUse())
I.setOperand(1, SI->getOperand(2));
else
@@ -2225,7 +2225,7 @@ Instruction *InstCombiner::visitRem(BinaryOperator &I) {
if (ST->isNullValue()) {
Instruction *CondI = dyn_cast<Instruction>(SI->getOperand(0));
if (CondI && CondI->getParent() == I.getParent())
- UpdateValueUsesWith(CondI, ConstantBool::True);
+ UpdateValueUsesWith(CondI, ConstantBool::getTrue());
else if (I.getParent() != SI->getParent() || SI->hasOneUse())
I.setOperand(1, SI->getOperand(1));
else
@@ -2344,14 +2344,14 @@ static unsigned getSetCondCode(const SetCondInst *SCI) {
/// SetCC instruction.
static Value *getSetCCValue(unsigned Opcode, Value *LHS, Value *RHS) {
switch (Opcode) {
- case 0: return ConstantBool::False;
+ case 0: return ConstantBool::getFalse();
case 1: return new SetCondInst(Instruction::SetGT, LHS, RHS);
case 2: return new SetCondInst(Instruction::SetEQ, LHS, RHS);
case 3: return new SetCondInst(Instruction::SetGE, LHS, RHS);
case 4: return new SetCondInst(Instruction::SetLT, LHS, RHS);
case 5: return new SetCondInst(Instruction::SetNE, LHS, RHS);
case 6: return new SetCondInst(Instruction::SetLE, LHS, RHS);
- case 7: return ConstantBool::True;
+ case 7: return ConstantBool::getTrue();
default: assert(0 && "Illegal SetCCCode!"); return 0;
}
}
@@ -2851,7 +2851,7 @@ Instruction *InstCombiner::visitAnd(BinaryOperator &I) {
default: assert(0 && "Unknown integer condition code!");
case Instruction::SetEQ: // (X == 13 & X == 15) -> false
case Instruction::SetGT: // (X == 13 & X > 15) -> false
- return ReplaceInstUsesWith(I, ConstantBool::False);
+ return ReplaceInstUsesWith(I, ConstantBool::getFalse());
case Instruction::SetNE: // (X == 13 & X != 15) -> X == 13
case Instruction::SetLT: // (X == 13 & X < 15) -> X == 13
return ReplaceInstUsesWith(I, LHS);
@@ -2886,7 +2886,7 @@ Instruction *InstCombiner::visitAnd(BinaryOperator &I) {
default: assert(0 && "Unknown integer condition code!");
case Instruction::SetEQ: // (X < 13 & X == 15) -> false
case Instruction::SetGT: // (X < 13 & X > 15) -> false
- return ReplaceInstUsesWith(I, ConstantBool::False);
+ return ReplaceInstUsesWith(I, ConstantBool::getFalse());
case Instruction::SetNE: // (X < 13 & X != 15) -> X < 13
case Instruction::SetLT: // (X < 13 & X < 15) -> X < 13
return ReplaceInstUsesWith(I, LHS);
@@ -3254,7 +3254,7 @@ Instruction *InstCombiner::visitOr(BinaryOperator &I) {
return ReplaceInstUsesWith(I, LHS);
case Instruction::SetNE: // (X != 13 | X != 15) -> true
case Instruction::SetLT: // (X != 13 | X < 15) -> true
- return ReplaceInstUsesWith(I, ConstantBool::True);
+ return ReplaceInstUsesWith(I, ConstantBool::getTrue());
}
break;
case Instruction::SetLT:
@@ -3277,7 +3277,7 @@ Instruction *InstCombiner::visitOr(BinaryOperator &I) {
return ReplaceInstUsesWith(I, LHS);
case Instruction::SetNE: // (X > 13 | X != 15) -> true
case Instruction::SetLT: // (X > 13 | X < 15) -> true
- return ReplaceInstUsesWith(I, ConstantBool::True);
+ return ReplaceInstUsesWith(I, ConstantBool::getTrue());
}
}
}
@@ -3339,7 +3339,7 @@ Instruction *InstCombiner::visitXor(BinaryOperator &I) {
if (BinaryOperator *Op0I = dyn_cast<BinaryOperator>(Op0)) {
// xor (setcc A, B), true = not (setcc A, B) = setncc A, B
if (SetCondInst *SCI = dyn_cast<SetCondInst>(Op0I))
- if (RHS == ConstantBool::True && SCI->hasOneUse())
+ if (RHS == ConstantBool::getTrue() && SCI->hasOneUse())
return new SetCondInst(SCI->getInverseCondition(),
SCI->getOperand(0), SCI->getOperand(1));
@@ -3781,9 +3781,9 @@ Instruction *InstCombiner::visitSetCondInst(SetCondInst &I) {
// Check to see if we are comparing against the minimum or maximum value...
if (CI->isMinValue()) {
if (I.getOpcode() == Instruction::SetLT) // A < MIN -> FALSE
- return ReplaceInstUsesWith(I, ConstantBool::False);
+ return ReplaceInstUsesWith(I, ConstantBool::getFalse());
if (I.getOpcode() == Instruction::SetGE) // A >= MIN -> TRUE
- return ReplaceInstUsesWith(I, ConstantBool::True);
+ return ReplaceInstUsesWith(I, ConstantBool::getTrue());
if (I.getOpcode() == Instruction::SetLE) // A <= MIN -> A == MIN
return BinaryOperator::createSetEQ(Op0, Op1);
if (I.getOpcode() == Instruction::SetGT) // A > MIN -> A != MIN
@@ -3791,9 +3791,9 @@ Instruction *InstCombiner::visitSetCondInst(SetCondInst &I) {
} else if (CI->isMaxValue()) {
if (I.getOpcode() == Instruction::SetGT) // A > MAX -> FALSE
- return ReplaceInstUsesWith(I, ConstantBool::False);
+ return ReplaceInstUsesWith(I, ConstantBool::getFalse());
if (I.getOpcode() == Instruction::SetLE) // A <= MAX -> TRUE
- return ReplaceInstUsesWith(I, ConstantBool::True);
+ return ReplaceInstUsesWith(I, ConstantBool::getTrue());
if (I.getOpcode() == Instruction::SetGE) // A >= MAX -> A == MAX
return BinaryOperator::createSetEQ(Op0, Op1);
if (I.getOpcode() == Instruction::SetLT) // A < MAX -> A != MAX
@@ -3842,19 +3842,23 @@ Instruction *InstCombiner::visitSetCondInst(SetCondInst &I) {
default: assert(0 && "Unknown setcc opcode!");
case Instruction::SetEQ:
if (Max < RHSVal || Min > RHSVal)
- return ReplaceInstUsesWith(I, ConstantBool::False);
+ return ReplaceInstUsesWith(I, ConstantBool::getFalse());
break;
case Instruction::SetNE:
if (Max < RHSVal || Min > RHSVal)
- return ReplaceInstUsesWith(I, ConstantBool::True);
+ return ReplaceInstUsesWith(I, ConstantBool::getTrue());
break;
case Instruction::SetLT:
- if (Max < RHSVal) return ReplaceInstUsesWith(I, ConstantBool::True);
- if (Min > RHSVal) return ReplaceInstUsesWith(I, ConstantBool::False);
+ if (Max < RHSVal)
+ return ReplaceInstUsesWith(I, ConstantBool::getTrue());
+ if (Min > RHSVal)
+ return ReplaceInstUsesWith(I, ConstantBool::getFalse());
break;
case Instruction::SetGT:
- if (Min > RHSVal) return ReplaceInstUsesWith(I, ConstantBool::True);
- if (Max < RHSVal) return ReplaceInstUsesWith(I, ConstantBool::False);
+ if (Min > RHSVal)
+ return ReplaceInstUsesWith(I, ConstantBool::getTrue());
+ if (Max < RHSVal)
+ return ReplaceInstUsesWith(I, ConstantBool::getFalse());
break;
}
} else { // Signed comparison.
@@ -3866,19 +3870,23 @@ Instruction *InstCombiner::visitSetCondInst(SetCondInst &I) {
default: assert(0 && "Unknown setcc opcode!");
case Instruction::SetEQ:
if (Max < RHSVal || Min > RHSVal)
- return ReplaceInstUsesWith(I, ConstantBool::False);
+ return ReplaceInstUsesWith(I, ConstantBool::getFalse());
break;
case Instruction::SetNE:
if (Max < RHSVal || Min > RHSVal)
- return ReplaceInstUsesWith(I, ConstantBool::True);
+ return ReplaceInstUsesWith(I, ConstantBool::getTrue());
break;
case Instruction::SetLT:
- if (Max < RHSVal) return ReplaceInstUsesWith(I, ConstantBool::True);
- if (Min > RHSVal) return ReplaceInstUsesWith(I, ConstantBool::False);
+ if (Max < RHSVal)
+ return ReplaceInstUsesWith(I, ConstantBool::getTrue());
+ if (Min > RHSVal)
+ return ReplaceInstUsesWith(I, ConstantBool::getFalse());
break;
case Instruction::SetGT:
- if (Min > RHSVal) return ReplaceInstUsesWith(I, ConstantBool::True);
- if (Max < RHSVal) return ReplaceInstUsesWith(I, ConstantBool::False);
+ if (Min > RHSVal)
+ return ReplaceInstUsesWith(I, ConstantBool::getTrue());
+ if (Max < RHSVal)
+ return ReplaceInstUsesWith(I, ConstantBool::getFalse());
break;
}
}
@@ -3978,9 +3986,9 @@ Instruction *InstCombiner::visitSetCondInst(SetCondInst &I) {
// As a special case, check to see if this means that the
// result is always true or false now.
if (I.getOpcode() == Instruction::SetEQ)
- return ReplaceInstUsesWith(I, ConstantBool::False);
+ return ReplaceInstUsesWith(I, ConstantBool::getFalse());
if (I.getOpcode() == Instruction::SetNE)
- return ReplaceInstUsesWith(I, ConstantBool::True);
+ return ReplaceInstUsesWith(I, ConstantBool::getTrue());
} else {
I.setOperand(1, NewCst);
Constant *NewAndCST;
@@ -4200,7 +4208,7 @@ Instruction *InstCombiner::visitSetCondInst(SetCondInst &I) {
default: assert(0 && "Unhandled setcc opcode!");
case Instruction::SetEQ:
if (LoOverflow && HiOverflow)
- return ReplaceInstUsesWith(I, ConstantBool::False);
+ return ReplaceInstUsesWith(I, ConstantBool::getFalse());
else if (HiOverflow)
return new SetCondInst(Instruction::SetGE, X, LoBound);
else if (LoOverflow)
@@ -4209,7 +4217,7 @@ Instruction *InstCombiner::visitSetCondInst(SetCondInst &I) {
return InsertRangeTest(X, LoBound, HiBound, true, I);
case Instruction::SetNE:
if (LoOverflow && HiOverflow)
- return ReplaceInstUsesWith(I, ConstantBool::True);
+ return ReplaceInstUsesWith(I, ConstantBool::getTrue());
else if (HiOverflow)
return new SetCondInst(Instruction::SetLT, X, LoBound);
else if (LoOverflow)
@@ -4218,11 +4226,11 @@ Instruction *InstCombiner::visitSetCondInst(SetCondInst &I) {
return InsertRangeTest(X, LoBound, HiBound, false, I);
case Instruction::SetLT:
if (LoOverflow)
- return ReplaceInstUsesWith(I, ConstantBool::False);
+ return ReplaceInstUsesWith(I, ConstantBool::getFalse());
return new SetCondInst(Instruction::SetLT, X, LoBound);
case Instruction::SetGT:
if (HiOverflow)
- return ReplaceInstUsesWith(I, ConstantBool::False);
+ return ReplaceInstUsesWith(I, ConstantBool::getFalse());
return new SetCondInst(Instruction::SetGE, X, HiBound);
}
}
@@ -4558,9 +4566,9 @@ Instruction *InstCombiner::visitSetCondInstWithCastAndCast(SetCondInst &SCI) {
// If the value cannot be represented in the shorter type, we cannot emit
// a simple comparison.
if (SCI.getOpcode() == Instruction::SetEQ)
- return ReplaceInstUsesWith(SCI, ConstantBool::False);
+ return ReplaceInstUsesWith(SCI, ConstantBool::getFalse());
if (SCI.getOpcode() == Instruction::SetNE)
- return ReplaceInstUsesWith(SCI, ConstantBool::True);
+ return ReplaceInstUsesWith(SCI, ConstantBool::getTrue());
// Evaluate the comparison for LT.
Value *Result;
@@ -4569,21 +4577,21 @@ Instruction *InstCombiner::visitSetCondInstWithCastAndCast(SetCondInst &SCI) {
if (isSignSrc) {
// Signed extend and signed comparison.
if (cast<ConstantSInt>(CI)->getValue() < 0) // X < (small) --> false
- Result = ConstantBool::False;
+ Result = ConstantBool::getFalse();
else
- Result = ConstantBool::True; // X < (large) --> true
+ Result = ConstantBool::getTrue(); // X < (large) --> true
} else {
// Unsigned extend and signed comparison.
if (cast<ConstantSInt>(CI)->getValue() < 0)
- Result = ConstantBool::False;
+ Result = ConstantBool::getFalse();
else
- Result = ConstantBool::True;
+ Result = ConstantBool::getTrue();
}
} else {
// We're performing an unsigned comparison.
if (!isSignSrc) {
// Unsigned extend & compare -> always true.
- Result = ConstantBool::True;
+ Result = ConstantBool::getTrue();
} else {
// We're performing an unsigned comp with a sign extended value.
// This is true if the input is >= 0. [aka >s -1]
@@ -5389,7 +5397,7 @@ Instruction *InstCombiner::visitCastInst(CastInst &CI) {
// cast (xor bool X, true) to int --> xor (cast bool X to int), 1
if (SrcBitSize == 1 && SrcI->getOpcode() == Instruction::Xor &&
- Op1 == ConstantBool::True &&
+ Op1 == ConstantBool::getTrue() &&
(!Op0->hasOneUse() || !isa<SetCondInst>(Op0))) {
Value *New = InsertOperandCastBefore(Op0, DestTy, &CI);
return BinaryOperator::createXor(New,
@@ -5648,12 +5656,7 @@ Instruction *InstCombiner::visitSelectInst(SelectInst &SI) {
// select true, X, Y -> X
// select false, X, Y -> Y
if (ConstantBool *C = dyn_cast<ConstantBool>(CondVal))
- if (C == ConstantBool::True)
- return ReplaceInstUsesWith(SI, TrueVal);
- else {
- assert(C == ConstantBool::False);
- return ReplaceInstUsesWith(SI, FalseVal);
- }
+ return ReplaceInstUsesWith(SI, C->getValue() ? TrueVal : FalseVal);
// select C, X, X -> X
if (TrueVal == FalseVal)
@@ -5672,7 +5675,7 @@ Instruction *InstCombiner::visitSelectInst(SelectInst &SI) {
if (SI.getType() == Type::BoolTy)
if (ConstantBool *C = dyn_cast<ConstantBool>(TrueVal)) {
- if (C == ConstantBool::True) {
+ if (C->getValue()) {
// Change: A = select B, true, C --> A = or B, C
return BinaryOperator::createOr(CondVal, FalseVal);
} else {
@@ -5683,7 +5686,7 @@ Instruction *InstCombiner::visitSelectInst(SelectInst &SI) {
return BinaryOperator::createAnd(NotCond, FalseVal);
}
} else if (ConstantBool *C = dyn_cast<ConstantBool>(FalseVal)) {
- if (C == ConstantBool::False) {
+ if (C->getValue() == false) {
// Change: A = select B, C, false --> A = and B, C
return BinaryOperator::createAnd(CondVal, TrueVal);
} else {
@@ -6193,7 +6196,7 @@ Instruction *InstCombiner::visitCallSite(CallSite CS) {
Instruction *OldCall = CS.getInstruction();
// If the call and callee calling conventions don't match, this call must
// be unreachable, as the call is undefined.
- new StoreInst(ConstantBool::True,
+ new StoreInst(ConstantBool::getTrue(),
UndefValue::get(PointerType::get(Type::BoolTy)), OldCall);
if (!OldCall->use_empty())
OldCall->replaceAllUsesWith(UndefValue::get(OldCall->getType()));
@@ -6206,7 +6209,7 @@ Instruction *InstCombiner::visitCallSite(CallSite CS) {
// This instruction is not reachable, just remove it. We insert a store to
// undef so that we know that this code is not reachable, despite the fact
// that we can't modify the CFG here.
- new StoreInst(ConstantBool::True,
+ new StoreInst(ConstantBool::getTrue(),
UndefValue::get(PointerType::get(Type::BoolTy)),
CS.getInstruction());
@@ -6217,7 +6220,7 @@ Instruction *InstCombiner::visitCallSite(CallSite CS) {
if (InvokeInst *II = dyn_cast<InvokeInst>(CS.getInstruction())) {
// Don't break the CFG, insert a dummy cond branch.
new BranchInst(II->getNormalDest(), II->getUnwindDest(),
- ConstantBool::True, II);
+ ConstantBool::getTrue(), II);
}
return EraseInstFromFunction(*CS.getInstruction());
}
@@ -6901,7 +6904,7 @@ Instruction *InstCombiner::visitFreeInst(FreeInst &FI) {
// free undef -> unreachable.
if (isa<UndefValue>(Op)) {
// Insert a new store to null because we cannot modify the CFG here.
- new StoreInst(ConstantBool::True,
+ new StoreInst(ConstantBool::getTrue(),
UndefValue::get(PointerType::get(Type::BoolTy)), &FI);
return EraseInstFromFunction(FI);
}
diff --git a/lib/Transforms/Scalar/LoopUnswitch.cpp b/lib/Transforms/Scalar/LoopUnswitch.cpp
index ea643b698e..95217254bd 100644
--- a/lib/Transforms/Scalar/LoopUnswitch.cpp
+++ b/lib/Transforms/Scalar/LoopUnswitch.cpp
@@ -173,7 +173,8 @@ bool LoopUnswitch::visitLoop(Loop *L) {
// See if this, or some part of it, is loop invariant. If so, we can
// unswitch on it if we desire.
Value *LoopCond = FindLIVLoopCondition(BI->getCondition(), L, Changed);
- if (LoopCond && UnswitchIfProfitable(LoopCond, ConstantBool::True, L)) {
+ if (LoopCond && UnswitchIfProfitable(LoopCond, ConstantBool::getTrue(),
+ L)) {
++NumBranches;
return true;
}
@@ -196,7 +197,8 @@ bool LoopUnswitch::visitLoop(Loop *L) {
BBI != E; ++BBI)
if (SelectInst *SI = dyn_cast<SelectInst>(BBI)) {
Value *LoopCond = FindLIVLoopCondition(SI->getCondition(), L, Changed);
- if (LoopCond && UnswitchIfProfitable(LoopCond, ConstantBool::True, L)) {
+ if (LoopCond && UnswitchIfProfitable(LoopCond, ConstantBool::getTrue(),
+ L)) {
++NumSelects;
return true;
}
@@ -286,9 +288,9 @@ static bool IsTrivialUnswitchCondition(Loop *L, Value *Cond, Constant **Val = 0,
// side-effects. If so, determine the value of Cond that causes it to do
// this.
if ((LoopExitBB = isTrivialLoopExitBlock(L, BI->getSuccessor(0)))) {
- if (Val) *Val = ConstantBool::True;
+ if (Val) *Val = ConstantBool::getTrue();
} else if ((LoopExitBB = isTrivialLoopExitBlock(L, BI->getSuccessor(1)))) {
- if (Val) *Val = ConstantBool::False;
+ if (Val) *Val = ConstantBool::getFalse();
}
} else if (SwitchInst *SI = dyn_cast<SwitchInst>(HeaderTerm)) {
// If this isn't a switch on Cond, we can't handle it.
@@ -488,7 +490,7 @@ static void EmitPreheaderBranchOnCondition(Value *LIC, Constant *Val,
Value *BranchVal = LIC;
if (!isa<ConstantBool>(Val)) {
BranchVal = BinaryOperator::createSetEQ(LIC, Val, "tmp", InsertPt);
- } else if (Val != ConstantBool::True) {
+ } else if (Val != ConstantBool::getTrue()) {
// We want to enter the new loop when the condition is true.
std::swap(TrueDest, FalseDest);
}
@@ -964,10 +966,9 @@ void LoopUnswitch::RewriteLoopBodyWithConditionConstant(Loop *L, Value *LIC,
BasicBlock* Split = SplitBlock(Old, SI);
Instruction* OldTerm = Old->getTerminator();
- BranchInst* Branch = new BranchInst(Split,
- SI->getSuccessor(i),
- ConstantBool::True,
- OldTerm);
+ BranchInst* Branch = new BranchInst(Split, SI->getSuccessor(i),
+ ConstantBool::getTrue(),
+ OldTerm);
Old->getTerminator()->eraseFromParent();
diff --git a/lib/Transforms/Scalar/PredicateSimplifier.cpp b/lib/Transforms/Scalar/PredicateSimplifier.cpp
index 04755de79c..715818c686 100644
--- a/lib/Transforms/Scalar/PredicateSimplifier.cpp
+++ b/lib/Transforms/Scalar/PredicateSimplifier.cpp
@@ -315,51 +315,47 @@ namespace {
if (BinaryOperator *BO = dyn_cast<BinaryOperator>(V2)) {
switch (BO->getOpcode()) {
case Instruction::SetEQ:
- if (V1 == ConstantBool::True)
- add(Opcode, BO->getOperand(0), BO->getOperand(1), false);
- if (V1 == ConstantBool::False)
- add(Opcode, BO->getOperand(0), BO->getOperand(1), true);
+ if (ConstantBool *V1CB = dyn_cast<ConstantBool>(V1))
+ add(Opcode, BO->getOperand(0), BO->getOperand(1),!V1CB->getValue());
break;
case Instruction::SetNE:
- if (V1 == ConstantBool::True)
- add(Opcode, BO->getOperand(0), BO->getOperand(1), true);
- if (V1 == ConstantBool::False)
- add(Opcode, BO->getOperand(0), BO->getOperand(1), false);
+ if (ConstantBool *V1CB = dyn_cast<ConstantBool>(V1))
+ add(Opcode, BO->getOperand(0), BO->getOperand(1), V1CB->getValue());
break;
case Instruction::SetLT:
case Instruction::SetGT:
- if (V1 == ConstantBool::True)
+ if (V1 == ConstantBool::getTrue())
add(Opcode, BO->getOperand(0), BO->getOperand(1), true);
break;
case Instruction::SetLE:
case Instruction::SetGE:
- if (V1 == ConstantBool::False)
+ if (V1 == ConstantBool::getFalse())
add(Opcode, BO->getOperand(0), BO->getOperand(1), true);
break;
case Instruction::And:
- if (V1 == ConstantBool::True) {
- add(Opcode, ConstantBool::True, BO->getOperand(0), false);
- add(Opcode, ConstantBool::True, BO->getOperand(1), false);
+ if (V1 == ConstantBool::getTrue()) {
+ add(Opcode, V1, BO->getOperand(0), false);
+ add(Opcode, V1, BO->getOperand(1), false);
}
break;
case Instruction::Or:
- if (V1 == ConstantBool::False) {
- add(Opcode, ConstantBool::False, BO->getOperand(0), false);
- add(Opcode, ConstantBool::False, BO->getOperand(1), false);
+ if (V1 == ConstantBool::getFalse()) {
+ add(Opcode, V1, BO->getOperand(0), false);
+ add(Opcode, V1, BO->getOperand(1), false);
}
break;
case Instruction::Xor:
- if (V1 == ConstantBool::True) {
- if (BO->getOperand(0) == ConstantBool::True)
- add(Opcode, ConstantBool::False, BO->getOperand(1), false);
- if (BO->getOperand(1) == ConstantBool::True)
- add(Opcode, ConstantBool::False, BO->getOperand(0), false);
+ if (V1 == ConstantBool::getTrue()) {
+ if (BO->getOperand(0) == V1)
+ add(Opcode, ConstantBool::getFalse(), BO->getOperand(1), false);
+ if (BO->getOperand(1) == V1)
+ add(Opcode, ConstantBool::getFalse(), BO->getOperand(0), false);
}
- if (V1 == ConstantBool::False) {
- if (BO->getOperand(0) == ConstantBool::True)
- add(Opcode, ConstantBool::True, BO->getOperand(1), false);
- if (BO->getOperand(1) == ConstantBool::True)
- add(Opcode, ConstantBool::True, BO->getOperand(0), false);
+ if (V1 == ConstantBool::getFalse()) {
+ if (BO->getOperand(0) == ConstantBool::getTrue())
+ add(Opcode, ConstantBool::getTrue(), BO->getOperand(1), false);
+ if (BO->getOperand(1) == ConstantBool::getTrue())
+ add(Opcode, ConstantBool::getTrue(), BO->getOperand(0), false);
}
break;
default:
@@ -368,10 +364,8 @@ namespace {
} else if (SelectInst *SI = dyn_cast<SelectInst>(V2)) {
if (Opcode != EQ && Opcode != NE) return;
- ConstantBool *True = (Opcode==EQ) ? ConstantBool::True
- : ConstantBool::False,
- *False = (Opcode==EQ) ? ConstantBool::False
- : ConstantBool::True;
+ ConstantBool *True = ConstantBool::get(Opcode==EQ),
+ *False = ConstantBool::get(Opcode!=EQ);
if (V1 == SI->getTrueValue())
addEqual(SI->getCondition(), True);
@@ -525,8 +519,8 @@ Value *PredicateSimplifier::resolve(SetCondInst *SCI,
if (NE != KP.Properties.end()) {
switch (SCI->getOpcode()) {
- case Instruction::SetEQ: return ConstantBool::False;
- case Instruction::SetNE: return ConstantBool::True;
+ case Instruction::SetEQ: return ConstantBool::getFalse();
+ case Instruction::SetNE: return ConstantBool::getTrue();
case Instruction::SetLE:
case Instruction::SetGE:
case Instruction::SetLT:
@@ -558,10 +552,9 @@ Value *PredicateSimplifier::resolve(BinaryOperator *BO,
Value *PredicateSimplifier::resolve(SelectInst *SI, const PropertySet &KP) {
Value *Condition = resolve(SI->getCondition(), KP);
- if (Condition == ConstantBool::True)
- return resolve(SI->getTrueValue(), KP);
- else if (Condition == ConstantBool::False)
- return resolve(SI->getFalseValue(), KP);
+ if (ConstantBool *CB = dyn_cast<ConstantBool>(Condition))
+ return resolve(CB->getValue() ? SI->getTrueValue() : SI->getFalseValue(),
+ KP);
return SI;
}
@@ -674,10 +667,10 @@ void PredicateSimplifier::visit(BranchInst *BI, PropertySet &KP) {
BasicBlock *TrueDest = BI->getSuccessor(0),
*FalseDest = BI->getSuccessor(1);
- if (Condition == ConstantBool::True || TrueDest == FalseDest) {
+ if (Condition == ConstantBool::getTrue() || TrueDest == FalseDest) {
proceedToSuccessors(KP, BB);
return;
- } else if (Condition == ConstantBool::False) {
+ } else if (Condition == ConstantBool::getFalse()) {
proceedToSuccessors(KP, BB);
return;
}
@@ -686,14 +679,14 @@ void PredicateSimplifier::visit(BranchInst *BI, PropertySet &KP) {
for (DTNodeType::iterator I = Node->begin(), E = Node->end(); I != E; ++I) {
if ((*I)->getBlock() == TrueDest) {
PropertySet TrueProperties(KP);
- TrueProperties.addEqual(ConstantBool::True, Condition);
+ TrueProperties.addEqual(ConstantBool::getTrue(), Condition);
proceedToSuccessor(BI, 0, KP, TrueProperties);
continue;
}
if ((*I)->getBlock() == FalseDest) {
PropertySet FalseProperties(KP);
- FalseProperties.addEqual(ConstantBool::False, Condition);
+ FalseProperties.addEqual(ConstantBool::getFalse(), Condition);
proceedToSuccessor(BI, 1, KP, FalseProperties);
continue;
}
diff --git a/lib/Transforms/Scalar/SCCP.cpp b/lib/Transforms/Scalar/SCCP.cpp
index 31d084053c..d1eb8dddda 100644
--- a/lib/Transforms/Scalar/SCCP.cpp
+++ b/lib/Transforms/Scalar/SCCP.cpp
@@ -374,7 +374,7 @@ void SCCPSolver::getFeasibleSuccessors(TerminatorInst &TI,
Succs[0] = Succs[1] = true;
} else if (BCValue.isConstant()) {
// Constant condition variables mean the branch can only go a single way
- Succs[BCValue.getConstant() == ConstantBool::False] = true;
+ Succs[BCValue.getConstant() == ConstantBool::getFalse()] = true;
}
}
} else if (InvokeInst *II = dyn_cast<InvokeInst>(&TI)) {
@@ -432,7 +432,7 @@ bool SCCPSolver::isEdgeFeasible(BasicBlock *From, BasicBlock *To) {
// Constant condition variables mean the branch can only go a single way
return BI->getSuccessor(BCValue.getConstant() ==
- ConstantBool::False) == To;
+ ConstantBool::getFalse()) == To;
}
return false;
}
@@ -598,12 +598,9 @@ void SCCPSolver::visitSelectInst(SelectInst &I) {
if (CondValue.isUndefined())
return;
if (CondValue.isConstant()) {
- Value *InVal = 0;
- if (CondValue.getConstant() == ConstantBool::True) {
- mergeInValue(&I, getValueState(I.getTrueValue()));
- return;
- } else if (CondValue.getConstant() == ConstantBool::False) {
- mergeInValue(&I, getValueState(I.getFalseValue()));
+ if (ConstantBool *CondCB = dyn_cast<ConstantBool>(CondValue.getConstant())){
+ mergeInValue(&I, getValueState(CondCB->getValue() ? I.getTrueValue()
+ : I.getFalseValue()));
return;
}
}
@@ -1035,7 +1032,7 @@ bool SCCPSolver::ResolveBranchesIn(Function &F) {
if (BI->isConditional()) {
LatticeVal &BCValue = getValueState(BI->getCondition());
if (BCValue.isUndefined()) {
- BI->setCondition(ConstantBool::True);
+ BI->setCondition(ConstantBool::getTrue());
BranchesResolved = true;
visit(BI);
}