summaryrefslogtreecommitdiff
path: root/compiler/optimizing/boolean_simplifier.cc
diff options
context:
space:
mode:
author Mark Mendell <mark.p.mendell@intel.com> 2015-11-17 11:16:56 -0500
committer David Brazdil <dbrazdil@google.com> 2015-11-20 16:48:04 +0000
commitf652917de5634b30c974c81d35a72871915b352a (patch)
treec50bcaf37c246df633d42a166334c9b6332e5394 /compiler/optimizing/boolean_simplifier.cc
parent60c4c6ad2b892bb00a6016a147b1cc089ba6bcb5 (diff)
Simplify boolean condition compared to 0
CaffeineMarkRR Logic has some boolean flipping which can be helped by some simplification. Simplify non-FP (A COND_OP B) != 0 to A OPPOSITE_COND_OP B. This is better than the original code, which would use a HBooleanNot after the condition. Also simplify non-FP (A COND_OP B) == 1 to A OPPOSITE_COND_OP B. Move GetOppositeCondition to nodes.h/nodes.cc to share with Boolean Simplification, renaming it to InsertOppositeCondition, as it inserts the new HInstruction (unless it is a constant). Change-Id: I34ded7758836e375de0d6fdba9239d2d451928d0 Signed-off-by: Mark Mendell <mark.p.mendell@intel.com>
Diffstat (limited to 'compiler/optimizing/boolean_simplifier.cc')
-rw-r--r--compiler/optimizing/boolean_simplifier.cc39
1 files changed, 1 insertions, 38 deletions
diff --git a/compiler/optimizing/boolean_simplifier.cc b/compiler/optimizing/boolean_simplifier.cc
index f985745e7a..f0cafc847f 100644
--- a/compiler/optimizing/boolean_simplifier.cc
+++ b/compiler/optimizing/boolean_simplifier.cc
@@ -61,40 +61,6 @@ static bool NegatesCondition(HInstruction* input_true, HInstruction* input_false
&& input_false->IsIntConstant() && input_false->AsIntConstant()->IsOne();
}
-// Returns an instruction with the opposite boolean value from 'cond'.
-static HInstruction* GetOppositeCondition(HInstruction* cond) {
- HGraph* graph = cond->GetBlock()->GetGraph();
- ArenaAllocator* allocator = graph->GetArena();
-
- if (cond->IsCondition()) {
- HInstruction* lhs = cond->InputAt(0);
- HInstruction* rhs = cond->InputAt(1);
- switch (cond->AsCondition()->GetOppositeCondition()) { // get *opposite*
- case kCondEQ: return new (allocator) HEqual(lhs, rhs);
- case kCondNE: return new (allocator) HNotEqual(lhs, rhs);
- case kCondLT: return new (allocator) HLessThan(lhs, rhs);
- case kCondLE: return new (allocator) HLessThanOrEqual(lhs, rhs);
- case kCondGT: return new (allocator) HGreaterThan(lhs, rhs);
- case kCondGE: return new (allocator) HGreaterThanOrEqual(lhs, rhs);
- case kCondB: return new (allocator) HBelow(lhs, rhs);
- case kCondBE: return new (allocator) HBelowOrEqual(lhs, rhs);
- case kCondA: return new (allocator) HAbove(lhs, rhs);
- case kCondAE: return new (allocator) HAboveOrEqual(lhs, rhs);
- }
- } else if (cond->IsIntConstant()) {
- HIntConstant* int_const = cond->AsIntConstant();
- if (int_const->IsZero()) {
- return graph->GetIntConstant(1);
- } else {
- DCHECK(int_const->IsOne());
- return graph->GetIntConstant(0);
- }
- }
- // General case when 'cond' is another instruction of type boolean,
- // as verified by SSAChecker.
- return new (allocator) HBooleanNot(cond);
-}
-
void HBooleanSimplifier::TryRemovingBooleanSelection(HBasicBlock* block) {
DCHECK(block->EndsWithIf());
@@ -126,10 +92,7 @@ void HBooleanSimplifier::TryRemovingBooleanSelection(HBasicBlock* block) {
HInstruction* replacement;
if (NegatesCondition(true_value, false_value)) {
- replacement = GetOppositeCondition(if_condition);
- if (replacement->GetBlock() == nullptr) {
- block->InsertInstructionBefore(replacement, if_instruction);
- }
+ replacement = graph_->InsertOppositeCondition(if_condition, if_instruction);
} else if (PreservesCondition(true_value, false_value)) {
replacement = if_condition;
} else {