[llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp

Chris Lattner lattner at cs.uiuc.edu
Thu Mar 11 23:53:01 PST 2004


Changes in directory llvm/lib/Transforms/Scalar:

InstructionCombining.cpp updated: 1.168 -> 1.169

---
Log message:

Add trivial optimizations for select instructions


---
Diffs of the changes:  (+15 -0)

Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.168 llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.169
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.168	Fri Feb 27 23:22:00 2004
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp	Thu Mar 11 23:52:32 2004
@@ -108,6 +108,7 @@
     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);
@@ -1930,6 +1931,20 @@
   
   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
 //





More information about the llvm-commits mailing list