diff options
author | 2023-04-27 12:09:54 +0000 | |
---|---|---|
committer | 2023-04-27 14:57:39 +0000 | |
commit | d6ce8df21644ec03e01f819b793edee0a7522d2c (patch) | |
tree | a0f7354339187dedf35228e3d4a58316a0e368cf /compiler/optimizing/instruction_simplifier.cc | |
parent | 2df7a6550548a4a7e07ef1d575992951847eef78 (diff) |
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
Diffstat (limited to 'compiler/optimizing/instruction_simplifier.cc')
-rw-r--r-- | compiler/optimizing/instruction_simplifier.cc | 38 |
1 files changed, 20 insertions, 18 deletions
diff --git a/compiler/optimizing/instruction_simplifier.cc b/compiler/optimizing/instruction_simplifier.cc index 0d2c252184..e13c8eafaf 100644 --- a/compiler/optimizing/instruction_simplifier.cc +++ b/compiler/optimizing/instruction_simplifier.cc @@ -1456,24 +1456,26 @@ void InstructionSimplifierVisitor::VisitAdd(HAdd* instruction) { } } - 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)) { |