From d6ce8df21644ec03e01f819b793edee0a7522d2c Mon Sep 17 00:00:00 2001 From: Vladimir Marko Date: Thu, 27 Apr 2023 12:09:54 +0000 Subject: 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 --- compiler/optimizing/instruction_simplifier.cc | 38 ++++++++++++++------------- 1 file changed, 20 insertions(+), 18 deletions(-) (limited to 'compiler/optimizing') 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)) { -- cgit v1.2.3-59-g8ed1b