OSDN Git Service

Add sccp support for select instructions
authorChris Lattner <sabre@nondot.org>
Fri, 12 Mar 2004 05:52:44 +0000 (05:52 +0000)
committerChris Lattner <sabre@nondot.org>
Fri, 12 Mar 2004 05:52:44 +0000 (05:52 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12318 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/SCCP.cpp

index 56cb2cc..26c246d 100644 (file)
@@ -212,6 +212,7 @@ private:
   void visitTerminatorInst(TerminatorInst &TI);
 
   void visitCastInst(CastInst &I);
+  void visitSelectInst(SelectInst &I);
   void visitBinaryOperator(Instruction &I);
   void visitShiftInst(ShiftInst &I) { visitBinaryOperator(I); }
 
@@ -565,6 +566,28 @@ void SCCP::visitCastInst(CastInst &I) {
     markConstant(&I, ConstantExpr::getCast(VState.getConstant(), I.getType()));
 }
 
+void SCCP::visitSelectInst(SelectInst &I) {
+  InstVal &CondValue = getValueState(I.getCondition());
+  if (CondValue.isOverdefined())
+    markOverdefined(&I);
+  else if (CondValue.isConstant()) {
+    if (CondValue.getConstant() == ConstantBool::True) {
+      InstVal &Val = getValueState(I.getTrueValue());
+      if (Val.isOverdefined())
+        markOverdefined(&I);
+      else if (Val.isConstant())
+        markConstant(&I, Val.getConstant());
+    } else if (CondValue.getConstant() == ConstantBool::False) {
+      InstVal &Val = getValueState(I.getFalseValue());
+      if (Val.isOverdefined())
+        markOverdefined(&I);
+      else if (Val.isConstant())
+        markConstant(&I, Val.getConstant());
+    } else
+      markOverdefined(&I);
+  }
+}
+
 // Handle BinaryOperators and Shift Instructions...
 void SCCP::visitBinaryOperator(Instruction &I) {
   InstVal &IV = ValueState[&I];