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
diff --git a/compiler/optimizing/boolean_simplifier.cc b/compiler/optimizing/boolean_simplifier.cc
index ab77505..be432c5 100644
--- a/compiler/optimizing/boolean_simplifier.cc
+++ b/compiler/optimizing/boolean_simplifier.cc
@@ -59,7 +59,8 @@
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 @@
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 @@
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);
}