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 | b909e8b0d4313f11cee79c3fb35110bc24f99fc2 (patch) | |
| tree | 282d69d78335ba1f57b891691a15c1ca87126bdf /llvm/lib/Transforms | |
| parent | 65a64e1e7a3cb59c7dfbbf643768d1055e6d1a3e (diff) | |
| download | bcm5719-llvm-b909e8b0d4313f11cee79c3fb35110bc24f99fc2.tar.gz bcm5719-llvm-b909e8b0d4313f11cee79c3fb35110bc24f99fc2.zip | |
Add trivial optimizations for select instructions
llvm-svn: 12317
Diffstat (limited to 'llvm/lib/Transforms')
| -rw-r--r-- | llvm/lib/Transforms/Scalar/InstructionCombining.cpp | 15 | 
1 files changed, 15 insertions, 0 deletions
| diff --git a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp index 724243369b5..7d308be1f21 100644 --- a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/llvm/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) { | 

