diff options
| author | Chris Lattner <sabre@nondot.org> | 2004-04-08 04:43:23 +0000 |
|---|---|---|
| committer | Chris Lattner <sabre@nondot.org> | 2004-04-08 04:43:23 +0000 |
| commit | 1c631e813da9d0dd6ba761dda220670f55790d45 (patch) | |
| tree | 7a7a66067954d26548429243e932aa0ac089b2a5 /llvm/lib/Transforms/Scalar/InstructionCombining.cpp | |
| parent | ac42fd5912ec4f1f23c8b5a035d79bfaa198ff74 (diff) | |
| download | bcm5719-llvm-1c631e813da9d0dd6ba761dda220670f55790d45.tar.gz bcm5719-llvm-1c631e813da9d0dd6ba761dda220670f55790d45.zip | |
Implement InstCombine/select.ll:test[7-10]
llvm-svn: 12769
Diffstat (limited to 'llvm/lib/Transforms/Scalar/InstructionCombining.cpp')
| -rw-r--r-- | llvm/lib/Transforms/Scalar/InstructionCombining.cpp | 41 |
1 files changed, 28 insertions, 13 deletions
diff --git a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp index 03477e0887f..0bb35348534 100644 --- a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp @@ -2027,25 +2027,41 @@ Instruction *InstCombiner::visitSelectInst(SelectInst &SI) { if (TrueVal == FalseVal) return ReplaceInstUsesWith(SI, TrueVal); + if (SI.getType() == Type::BoolTy) + if (ConstantBool *C = dyn_cast<ConstantBool>(TrueVal)) { + if (C == ConstantBool::True) { + // Change: A = select B, true, C --> A = or B, C + return BinaryOperator::create(Instruction::Or, CondVal, FalseVal); + } else { + // Change: A = select B, false, C --> A = and !B, C + Value *NotCond = + InsertNewInstBefore(BinaryOperator::createNot(CondVal, + "not."+CondVal->getName()), SI); + return BinaryOperator::create(Instruction::And, NotCond, FalseVal); + } + } else if (ConstantBool *C = dyn_cast<ConstantBool>(FalseVal)) { + if (C == ConstantBool::False) { + // Change: A = select B, C, false --> A = and B, C + return BinaryOperator::create(Instruction::And, CondVal, TrueVal); + } else { + // Change: A = select B, C, true --> A = or !B, C + Value *NotCond = + InsertNewInstBefore(BinaryOperator::createNot(CondVal, + "not."+CondVal->getName()), SI); + return BinaryOperator::create(Instruction::Or, NotCond, TrueVal); + } + } + // Selecting between two constants? if (Constant *TrueValC = dyn_cast<Constant>(TrueVal)) if (Constant *FalseValC = dyn_cast<Constant>(FalseVal)) { - if (SI.getType() == Type::BoolTy && - isa<ConstantBool>(TrueValC) && isa<ConstantBool>(FalseValC)) { - // select C, true, false -> C - if (TrueValC == ConstantBool::True) - return ReplaceInstUsesWith(SI, CondVal); - // select C, false, true -> !C - return BinaryOperator::createNot(CondVal); - } - // If the true constant is a 1 and the false is a zero, turn this into a // cast from bool. if (FalseValC->isNullValue() && isa<ConstantInt>(TrueValC) && cast<ConstantInt>(TrueValC)->getRawValue() == 1) return new CastInst(CondVal, SI.getType()); } - + return 0; } @@ -2177,9 +2193,8 @@ bool InstCombiner::transformConstExprCastCall(CallSite CS) { if ((*AI)->getType() == ParamTy) { Args.push_back(*AI); } else { - Instruction *Cast = new CastInst(*AI, ParamTy, "tmp"); - InsertNewInstBefore(Cast, *Caller); - Args.push_back(Cast); + Args.push_back(InsertNewInstBefore(new CastInst(*AI, ParamTy, "tmp"), + *Caller)); } } |

