diff options
author | 2015-03-31 09:59:27 +0100 | |
---|---|---|
committer | 2015-03-31 10:33:42 +0100 | |
commit | 2846b6810e196a1b25bf2d1b5cbe73dee4a2b286 (patch) | |
tree | 9be58420c3e9da52ab581357b4106f1d865e5217 /compiler/optimizing/boolean_simplifier.cc | |
parent | c4bd0e6a7f4839ea99222f06979cc2369cb9bf10 (diff) |
ART: General-case negation in boolean simplifier
Code transformations on the HGraph may optimize out the condition
instruction of an If and replace it with a boolean value. In such
case, the boolean simplifier would not know how to negate the
condition and would fail. This patch implements negation in this
general case with 'equals 0' as a substitute for the non-existing
boolean Not instruction.
Bug: 19992954
Change-Id: I152036fcc6bbecccc767d3024a5c060177597d88
Diffstat (limited to 'compiler/optimizing/boolean_simplifier.cc')
-rw-r--r-- | compiler/optimizing/boolean_simplifier.cc | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/compiler/optimizing/boolean_simplifier.cc b/compiler/optimizing/boolean_simplifier.cc index ab77505b6f..be432c5a20 100644 --- a/compiler/optimizing/boolean_simplifier.cc +++ b/compiler/optimizing/boolean_simplifier.cc @@ -59,7 +59,8 @@ static HInstruction* GetOppositeCondition(HInstruction* cond) { return new (allocator) HGreaterThan(lhs, rhs); } else if (cond->IsGreaterThan()) { return new (allocator) HLessThanOrEqual(lhs, rhs); - } else if (cond->IsGreaterThanOrEqual()) { + } else { + DCHECK(cond->IsGreaterThanOrEqual()); return new (allocator) HLessThan(lhs, rhs); } } else if (cond->IsIntConstant()) { @@ -70,10 +71,11 @@ static HInstruction* GetOppositeCondition(HInstruction* cond) { DCHECK(int_const->IsOne()); return graph->GetIntConstant(0); } + } else { + // General case when 'cond' is another instruction of type boolean. + // Negate with 'cond == 0'. + return new (allocator) HEqual(cond, graph->GetIntConstant(0)); } - - // TODO: b/19992954 - return nullptr; } void HBooleanSimplifier::Run() { @@ -105,10 +107,6 @@ void HBooleanSimplifier::Run() { HInstruction* replacement; if (NegatesCondition(true_value, false_value)) { replacement = GetOppositeCondition(if_condition); - if (replacement == nullptr) { - // Something we could not handle. - continue; - } if (replacement->GetBlock() == nullptr) { block->InsertInstructionBefore(replacement, if_instruction); } |