Clean up previous code.

Add new combination to turn seteq X, 0 -> not(cast X to bool)


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@6604 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner
2003-06-04 05:10:11 +00:00
parent 9dad6d7411
commit 40f5d70db4

View File

@@ -683,8 +683,16 @@ Instruction *InstCombiner::visitSetCondInst(BinaryOperator &I) {
// integers at the end of their ranges... // integers at the end of their ranges...
// //
if (ConstantInt *CI = dyn_cast<ConstantInt>(Op1)) { if (ConstantInt *CI = dyn_cast<ConstantInt>(Op1)) {
if (CI->isNullValue() && I.getOpcode() == Instruction::SetNE) if (CI->isNullValue()) {
return new CastInst(Op0, Type::BoolTy, I.getName()); if (I.getOpcode() == Instruction::SetNE)
return new CastInst(Op0, Type::BoolTy, I.getName());
else if (I.getOpcode() == Instruction::SetEQ) {
// seteq X, 0 -> not (cast X to bool)
Instruction *Val = new CastInst(Op0, Type::BoolTy, I.getName()+".not");
InsertNewInstBefore(Val, I);
return BinaryOperator::createNot(Val, I.getName());
}
}
// Check to see if we are comparing against the minimum or maximum value... // Check to see if we are comparing against the minimum or maximum value...
if (CI->isMinValue()) { if (CI->isMinValue()) {
@@ -1064,15 +1072,16 @@ Instruction *InstCombiner::visitAllocationInst(AllocationInst &AI) {
Instruction *InstCombiner::visitBranchInst(BranchInst &BI) { Instruction *InstCombiner::visitBranchInst(BranchInst &BI) {
// Change br (not X), label True, label False to: br X, label False, True // Change br (not X), label True, label False to: br X, label False, True
if (BI.isConditional() && BinaryOperator::isNot(BI.getCondition())) { if (BI.isConditional())
BasicBlock *TrueDest = BI.getSuccessor(0); if (Value *V = dyn_castNotVal(BI.getCondition())) {
BasicBlock *FalseDest = BI.getSuccessor(1); BasicBlock *TrueDest = BI.getSuccessor(0);
// Swap Destinations and condition... BasicBlock *FalseDest = BI.getSuccessor(1);
BI.setCondition(BinaryOperator::getNotArgument(cast<BinaryOperator>(BI.getCondition()))); // Swap Destinations and condition...
BI.setSuccessor(0, FalseDest); BI.setCondition(V);
BI.setSuccessor(1, TrueDest); BI.setSuccessor(0, FalseDest);
return &BI; BI.setSuccessor(1, TrueDest);
} return &BI;
}
return 0; return 0;
} }