diff options
| author | 2015-01-16 12:35:40 +0000 | |
|---|---|---|
| committer | 2015-01-19 09:29:40 +0000 | |
| commit | 9ee66183d8e046ea661f642ba884626f16b46e06 (patch) | |
| tree | d400690c920b0857dafd06efd3db6336c9eeba5b /compiler/optimizing/graph_checker.cc | |
| parent | 36740379b9b1c81b7eb06ea9c9df411d0a9a765e (diff) | |
Constant fold after inlining.
- Inlining opens up new opportunities for constant folding.
- Fix a bug in constant folder where the result type was not
correctly set for the folding of a HCompare.
- Improve graph checker's coverage.
Change-Id: I0943bf8ff65505c4addc4a555a526b55e00b5268
Diffstat (limited to 'compiler/optimizing/graph_checker.cc')
| -rw-r--r-- | compiler/optimizing/graph_checker.cc | 50 |
1 files changed, 49 insertions, 1 deletions
diff --git a/compiler/optimizing/graph_checker.cc b/compiler/optimizing/graph_checker.cc index e55175faec..b20d5892eb 100644 --- a/compiler/optimizing/graph_checker.cc +++ b/compiler/optimizing/graph_checker.cc @@ -363,9 +363,29 @@ static Primitive::Type PrimitiveKind(Primitive::Type type) { } } +void SSAChecker::VisitIf(HIf* instruction) { + VisitInstruction(instruction); + HInstruction* input = instruction->InputAt(0); + if (input->IsIntConstant()) { + int value = input->AsIntConstant()->GetValue(); + if (value != 0 && value != 1) { + std::stringstream error; + error << "If instruction " << instruction->GetId() + << " has a non-boolean constant input whose value is: " + << value << "."; + errors_.push_back(error.str()); + } + } else if (instruction->InputAt(0)->GetType() != Primitive::kPrimBoolean) { + std::stringstream error; + error << "If instruction " << instruction->GetId() + << " has a non-boolean input type: " + << instruction->InputAt(0)->GetType() << "."; + errors_.push_back(error.str()); + } +} + void SSAChecker::VisitCondition(HCondition* op) { VisitInstruction(op); - // TODO: check inputs types, and special case the `null` check. if (op->GetType() != Primitive::kPrimBoolean) { std::stringstream error; error << "Condition " << op->DebugName() << " " << op->GetId() @@ -373,6 +393,34 @@ void SSAChecker::VisitCondition(HCondition* op) { << op->GetType() << "."; errors_.push_back(error.str()); } + HInstruction* lhs = op->InputAt(0); + HInstruction* rhs = op->InputAt(1); + if (lhs->GetType() == Primitive::kPrimNot && rhs->IsIntConstant()) { + if (rhs->AsIntConstant()->GetValue() != 0) { + std::stringstream error; + error << "Condition " << op->DebugName() << " " << op->GetId() + << " compares an object with a non-0 integer: " + << rhs->AsIntConstant()->GetValue() + << "."; + errors_.push_back(error.str()); + } + } else if (rhs->GetType() == Primitive::kPrimNot && lhs->IsIntConstant()) { + if (lhs->AsIntConstant()->GetValue() != 0) { + std::stringstream error; + error << "Condition " << op->DebugName() << " " << op->GetId() + << " compares a non-0 integer with an object: " + << lhs->AsIntConstant()->GetValue() + << "."; + errors_.push_back(error.str()); + } + } else if (PrimitiveKind(lhs->GetType()) != PrimitiveKind(rhs->GetType())) { + std::stringstream error; + error << "Condition " << op->DebugName() << " " << op->GetId() + << " has inputs of different type: " + << lhs->GetType() << ", and " << rhs->GetType() + << "."; + errors_.push_back(error.str()); + } } void SSAChecker::VisitBinaryOperation(HBinaryOperation* op) { |