From 13b4718ecd52a674b25eac106e654d8e89872750 Mon Sep 17 00:00:00 2001 From: David Brazdil Date: Wed, 15 Apr 2015 16:29:32 +0100 Subject: ART: Remove DCHECKs for boolean type Since bool and int are interchangeable types, checking whether an input is kPrimBoolean can fail when replaced with 0/1 constant or a phi. This patch removes the problematic DCHECKs, adds a best-effort verification into SSAChecker but leaves the phi case empty until a suitable analysis is implemented. Change-Id: I31e8daf27dd33d2fd74049b82bed1cb7c240c8c6 --- compiler/optimizing/graph_checker.cc | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) (limited to 'compiler/optimizing/graph_checker.cc') diff --git a/compiler/optimizing/graph_checker.cc b/compiler/optimizing/graph_checker.cc index 7c3c2bf03d..906c8e8c76 100644 --- a/compiler/optimizing/graph_checker.cc +++ b/compiler/optimizing/graph_checker.cc @@ -369,26 +369,40 @@ void SSAChecker::VisitPhi(HPhi* phi) { } } -void SSAChecker::VisitIf(HIf* instruction) { - VisitInstruction(instruction); - HInstruction* input = instruction->InputAt(0); +void SSAChecker::HandleBooleanInput(HInstruction* instruction, size_t input_index) { + HInstruction* input = instruction->InputAt(input_index); if (input->IsIntConstant()) { - int value = input->AsIntConstant()->GetValue(); + int32_t value = input->AsIntConstant()->GetValue(); if (value != 0 && value != 1) { AddError(StringPrintf( - "If instruction %d has a non-Boolean constant input " - "whose value is: %d.", + "%s instruction %d has a non-Boolean constant input %d whose value is: %d.", + instruction->DebugName(), instruction->GetId(), + static_cast(input_index), value)); } - } else if (instruction->InputAt(0)->GetType() != Primitive::kPrimBoolean) { + } else if (input->GetType() == Primitive::kPrimInt && input->IsPhi()) { + // TODO: We need a data-flow analysis which determines if the Phi is boolean. + } else if (input->GetType() != Primitive::kPrimBoolean) { AddError(StringPrintf( - "If instruction %d has a non-Boolean input type: %s.", + "%s instruction %d has a non-Boolean input %d whose type is: %s.", + instruction->DebugName(), instruction->GetId(), - Primitive::PrettyDescriptor(instruction->InputAt(0)->GetType()))); + static_cast(input_index), + Primitive::PrettyDescriptor(input->GetType()))); } } +void SSAChecker::VisitIf(HIf* instruction) { + VisitInstruction(instruction); + HandleBooleanInput(instruction, 0); +} + +void SSAChecker::VisitBooleanNot(HBooleanNot* instruction) { + VisitInstruction(instruction); + HandleBooleanInput(instruction, 0); +} + void SSAChecker::VisitCondition(HCondition* op) { VisitInstruction(op); if (op->GetType() != Primitive::kPrimBoolean) { -- cgit v1.2.3-59-g8ed1b