diff options
author | Chris Lattner <sabre@nondot.org> | 2004-03-12 05:52:32 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2004-03-12 05:52:32 +0000 |
commit | 3d69f46d64ca4cb8062b27c94b3077fa9048ebf8 (patch) | |
tree | 2fc619722613dc5693793d38555ea5e3aed11d40 /lib/Transforms | |
parent | 9f24a077bda36334e6f7c8f27a97eccd820e9644 (diff) |
Add trivial optimizations for select instructions
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12317 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms')
-rw-r--r-- | lib/Transforms/Scalar/InstructionCombining.cpp | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp index 724243369b..7d308be1f2 100644 --- a/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/lib/Transforms/Scalar/InstructionCombining.cpp @@ -108,6 +108,7 @@ namespace { Instruction *visitSetCondInst(BinaryOperator &I); Instruction *visitShiftInst(ShiftInst &I); Instruction *visitCastInst(CastInst &CI); + Instruction *visitSelectInst(SelectInst &CI); Instruction *visitCallInst(CallInst &CI); Instruction *visitInvokeInst(InvokeInst &II); Instruction *visitPHINode(PHINode &PN); @@ -1931,6 +1932,20 @@ Instruction *InstCombiner::visitCastInst(CastInst &CI) { return 0; } +Instruction *InstCombiner::visitSelectInst(SelectInst &SI) { + if (ConstantBool *C = dyn_cast<ConstantBool>(SI.getCondition())) + if (C == ConstantBool::True) + return ReplaceInstUsesWith(SI, SI.getTrueValue()); + else { + assert(C == ConstantBool::False); + return ReplaceInstUsesWith(SI, SI.getFalseValue()); + } + // Other transformations are possible! + + return 0; +} + + // CallInst simplification // Instruction *InstCombiner::visitCallInst(CallInst &CI) { |