Add sccp support for select instructions

llvm-svn: 12318
This commit is contained in:
Chris Lattner 2004-03-12 05:52:44 +00:00
parent b909e8b0d4
commit 59db22dcd4
1 changed files with 23 additions and 0 deletions

View 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];