diff options
author | Chris Lattner <sabre@nondot.org> | 2004-03-12 05:52:44 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2004-03-12 05:52:44 +0000 |
commit | 6e32372fcdbac8eff07ab82c0b5b269d53bd9c51 (patch) | |
tree | 67e288cd1bcbf70f8e59569da6cf0e9ce946895a /lib/Transforms/Scalar/SCCP.cpp | |
parent | 3d69f46d64ca4cb8062b27c94b3077fa9048ebf8 (diff) |
Add sccp support for select instructions
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12318 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Scalar/SCCP.cpp')
-rw-r--r-- | lib/Transforms/Scalar/SCCP.cpp | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/lib/Transforms/Scalar/SCCP.cpp b/lib/Transforms/Scalar/SCCP.cpp index 56cb2cc770..26c246df00 100644 --- a/lib/Transforms/Scalar/SCCP.cpp +++ b/lib/Transforms/Scalar/SCCP.cpp @@ -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]; |