From ba56d060116d6e145be348fa575314654c6b0572 Mon Sep 17 00:00:00 2001 From: Mark Mendell Date: Tue, 5 May 2015 21:34:03 -0400 Subject: [optimizing] Improve 32 bit long shift by 1. Also change FOO << 1 to FOO+FOO in the instruction simplifier. This is an architecture independent simplification, which helps 'long << 1' for 32 bit architectures. Generate an add/adc for long << 1 in x86, in case something is generated after the simplifier. Add test cases for the simplification. Change-Id: I0d512331ef13cc4ccf10c80f11c370a10ed02294 Signed-off-by: Mark Mendell --- compiler/optimizing/instruction_simplifier.cc | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) (limited to 'compiler/optimizing/instruction_simplifier.cc') diff --git a/compiler/optimizing/instruction_simplifier.cc b/compiler/optimizing/instruction_simplifier.cc index e79d4f4bdc..46fad17b8f 100644 --- a/compiler/optimizing/instruction_simplifier.cc +++ b/compiler/optimizing/instruction_simplifier.cc @@ -137,13 +137,25 @@ void InstructionSimplifierVisitor::VisitShift(HBinaryOperation* instruction) { HConstant* input_cst = instruction->GetConstantRight(); HInstruction* input_other = instruction->GetLeastConstantLeft(); - if ((input_cst != nullptr) && input_cst->IsZero()) { - // Replace code looking like - // SHL dst, src, 0 - // with - // src - instruction->ReplaceWith(input_other); - instruction->GetBlock()->RemoveInstruction(instruction); + if (input_cst != nullptr) { + if (input_cst->IsZero()) { + // Replace code looking like + // SHL dst, src, 0 + // with + // src + instruction->ReplaceWith(input_other); + instruction->GetBlock()->RemoveInstruction(instruction); + } else if (instruction->IsShl() && input_cst->IsOne()) { + // Replace Shl looking like + // SHL dst, src, 1 + // with + // ADD dst, src, src + HAdd *add = new(GetGraph()->GetArena()) HAdd(instruction->GetType(), + input_other, + input_other); + instruction->GetBlock()->ReplaceAndRemoveInstructionWith(instruction, add); + RecordSimplification(); + } } } -- cgit v1.2.3-59-g8ed1b