Restructure `InstructionSimplifierVisitor::VisitAdd()`.
Address a comment from
https://android-review.googlesource.com/2565351 .
Test: m test-art-host-gtest
Test: testrunner.py --host --optimizing
Change-Id: Ie91fbfe54f9f067b79d3c8fb5587c44b4d531ef9
diff --git a/compiler/optimizing/instruction_simplifier.cc b/compiler/optimizing/instruction_simplifier.cc
index 0d2c252..e13c8ea 100644
--- a/compiler/optimizing/instruction_simplifier.cc
+++ b/compiler/optimizing/instruction_simplifier.cc
@@ -1456,24 +1456,26 @@
}
}
- HNeg* neg = left_is_neg ? left->AsNeg() : right->AsNegOrNull();
- if (left_is_neg != right_is_neg && neg->HasOnlyOneNonEnvironmentUse()) {
- // Replace code looking like
- // NEG tmp, b
- // ADD dst, a, tmp
- // with
- // SUB dst, a, b
- // We do not perform the optimization if the input negation has environment
- // uses or multiple non-environment uses as it could lead to worse code. In
- // particular, we do not want the live range of `b` to be extended if we are
- // not sure the initial 'NEG' instruction can be removed.
- HInstruction* other = left_is_neg ? right : left;
- HSub* sub =
- new(GetGraph()->GetAllocator()) HSub(instruction->GetType(), other, neg->GetInput());
- instruction->GetBlock()->ReplaceAndRemoveInstructionWith(instruction, sub);
- RecordSimplification();
- neg->GetBlock()->RemoveInstruction(neg);
- return;
+ if (left_is_neg != right_is_neg) {
+ HNeg* neg = left_is_neg ? left->AsNeg() : right->AsNeg();
+ if (neg->HasOnlyOneNonEnvironmentUse()) {
+ // Replace code looking like
+ // NEG tmp, b
+ // ADD dst, a, tmp
+ // with
+ // SUB dst, a, b
+ // We do not perform the optimization if the input negation has environment
+ // uses or multiple non-environment uses as it could lead to worse code. In
+ // particular, we do not want the live range of `b` to be extended if we are
+ // not sure the initial 'NEG' instruction can be removed.
+ HInstruction* other = left_is_neg ? right : left;
+ HSub* sub =
+ new(GetGraph()->GetAllocator()) HSub(instruction->GetType(), other, neg->GetInput());
+ instruction->GetBlock()->ReplaceAndRemoveInstructionWith(instruction, sub);
+ RecordSimplification();
+ neg->GetBlock()->RemoveInstruction(neg);
+ return;
+ }
}
if (TryReplaceWithRotate(instruction)) {