From a21f598fd4dfdb95dc8597d3156120cc20d94c02 Mon Sep 17 00:00:00 2001 From: Calin Juravle Date: Thu, 13 Nov 2014 15:53:04 +0000 Subject: [optimizing compiler] Fix Move for instruction with constant output Change-Id: I15d89292dc62f8dd8643530f95ace2e8be034411 --- compiler/optimizing/code_generator_arm.cc | 47 ++++++++++++------------ compiler/optimizing/code_generator_x86.cc | 54 ++++++++++++++++------------ compiler/optimizing/code_generator_x86_64.cc | 50 +++++++++++++++----------- 3 files changed, 85 insertions(+), 66 deletions(-) (limited to 'compiler') diff --git a/compiler/optimizing/code_generator_arm.cc b/compiler/optimizing/code_generator_arm.cc index 4d86732cc7..379979b8c8 100644 --- a/compiler/optimizing/code_generator_arm.cc +++ b/compiler/optimizing/code_generator_arm.cc @@ -672,13 +672,13 @@ void CodeGeneratorARM::Move32(Location destination, Location source) { __ LoadSFromOffset(destination.As(), SP, source.GetStackIndex()); } } else { - DCHECK(destination.IsStackSlot()); + DCHECK(destination.IsStackSlot()) << destination; if (source.IsRegister()) { __ StoreToOffset(kStoreWord, source.As(), SP, destination.GetStackIndex()); } else if (source.IsFpuRegister()) { __ StoreSToOffset(source.As(), SP, destination.GetStackIndex()); } else { - DCHECK(source.IsStackSlot()); + DCHECK(source.IsStackSlot()) << source; __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex()); __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); } @@ -780,26 +780,29 @@ void CodeGeneratorARM::Move(HInstruction* instruction, Location location, HInstr return; } - if (instruction->IsIntConstant()) { - int32_t value = instruction->AsIntConstant()->GetValue(); - if (location.IsRegister()) { - __ LoadImmediate(location.As(), value); - } else { - DCHECK(location.IsStackSlot()); - __ LoadImmediate(IP, value); - __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex()); - } - } else if (instruction->IsLongConstant()) { - int64_t value = instruction->AsLongConstant()->GetValue(); - if (location.IsRegisterPair()) { - __ LoadImmediate(location.AsRegisterPairLow(), Low32Bits(value)); - __ LoadImmediate(location.AsRegisterPairHigh(), High32Bits(value)); - } else { - DCHECK(location.IsDoubleStackSlot()); - __ LoadImmediate(IP, Low32Bits(value)); - __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex()); - __ LoadImmediate(IP, High32Bits(value)); - __ StoreToOffset(kStoreWord, IP, SP, location.GetHighStackIndex(kArmWordSize)); + if (locations != nullptr && locations->Out().IsConstant()) { + HConstant* const_to_move = locations->Out().GetConstant(); + if (const_to_move->IsIntConstant()) { + int32_t value = const_to_move->AsIntConstant()->GetValue(); + if (location.IsRegister()) { + __ LoadImmediate(location.As(), value); + } else { + DCHECK(location.IsStackSlot()); + __ LoadImmediate(IP, value); + __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex()); + } + } else if (const_to_move->IsLongConstant()) { + int64_t value = const_to_move->AsLongConstant()->GetValue(); + if (location.IsRegisterPair()) { + __ LoadImmediate(location.AsRegisterPairLow(), Low32Bits(value)); + __ LoadImmediate(location.AsRegisterPairHigh(), High32Bits(value)); + } else { + DCHECK(location.IsDoubleStackSlot()); + __ LoadImmediate(IP, Low32Bits(value)); + __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex()); + __ LoadImmediate(IP, High32Bits(value)); + __ StoreToOffset(kStoreWord, IP, SP, location.GetHighStackIndex(kArmWordSize)); + } } } else if (instruction->IsLoadLocal()) { uint32_t stack_slot = GetStackSlot(instruction->AsLoadLocal()->GetLocal()); diff --git a/compiler/optimizing/code_generator_x86.cc b/compiler/optimizing/code_generator_x86.cc index bd36399c6a..1daac06713 100644 --- a/compiler/optimizing/code_generator_x86.cc +++ b/compiler/optimizing/code_generator_x86.cc @@ -662,27 +662,35 @@ void CodeGeneratorX86::Move64(Location destination, Location source) { } void CodeGeneratorX86::Move(HInstruction* instruction, Location location, HInstruction* move_for) { - if (instruction->IsIntConstant()) { - Immediate imm(instruction->AsIntConstant()->GetValue()); - if (location.IsRegister()) { - __ movl(location.As(), imm); - } else if (location.IsStackSlot()) { - __ movl(Address(ESP, location.GetStackIndex()), imm); - } else { - DCHECK(location.IsConstant()); - DCHECK_EQ(location.GetConstant(), instruction); - } - } else if (instruction->IsLongConstant()) { - int64_t value = instruction->AsLongConstant()->GetValue(); - if (location.IsRegisterPair()) { - __ movl(location.AsRegisterPairLow(), Immediate(Low32Bits(value))); - __ movl(location.AsRegisterPairHigh(), Immediate(High32Bits(value))); - } else if (location.IsDoubleStackSlot()) { - __ movl(Address(ESP, location.GetStackIndex()), Immediate(Low32Bits(value))); - __ movl(Address(ESP, location.GetHighStackIndex(kX86WordSize)), Immediate(High32Bits(value))); - } else { - DCHECK(location.IsConstant()); - DCHECK_EQ(location.GetConstant(), instruction); + LocationSummary* locations = instruction->GetLocations(); + if (locations != nullptr && locations->Out().Equals(location)) { + return; + } + + if (locations != nullptr && locations->Out().IsConstant()) { + HConstant* const_to_move = locations->Out().GetConstant(); + if (const_to_move->IsIntConstant()) { + Immediate imm(const_to_move->AsIntConstant()->GetValue()); + if (location.IsRegister()) { + __ movl(location.As(), imm); + } else if (location.IsStackSlot()) { + __ movl(Address(ESP, location.GetStackIndex()), imm); + } else { + DCHECK(location.IsConstant()); + DCHECK_EQ(location.GetConstant(), const_to_move); + } + } else if (const_to_move->IsLongConstant()) { + int64_t value = const_to_move->AsLongConstant()->GetValue(); + if (location.IsRegisterPair()) { + __ movl(location.AsRegisterPairLow(), Immediate(Low32Bits(value))); + __ movl(location.AsRegisterPairHigh(), Immediate(High32Bits(value))); + } else if (location.IsDoubleStackSlot()) { + __ movl(Address(ESP, location.GetStackIndex()), Immediate(Low32Bits(value))); + __ movl(Address(ESP, location.GetHighStackIndex(kX86WordSize)), Immediate(High32Bits(value))); + } else { + DCHECK(location.IsConstant()); + DCHECK_EQ(location.GetConstant(), instruction); + } } } else if (instruction->IsTemporary()) { Location temp_location = GetTemporaryLocation(instruction->AsTemporary()); @@ -723,12 +731,12 @@ void CodeGeneratorX86::Move(HInstruction* instruction, Location location, HInstr case Primitive::kPrimInt: case Primitive::kPrimNot: case Primitive::kPrimFloat: - Move32(location, instruction->GetLocations()->Out()); + Move32(location, locations->Out()); break; case Primitive::kPrimLong: case Primitive::kPrimDouble: - Move64(location, instruction->GetLocations()->Out()); + Move64(location, locations->Out()); break; default: diff --git a/compiler/optimizing/code_generator_x86_64.cc b/compiler/optimizing/code_generator_x86_64.cc index 82bb7db7de..a8b6dd5498 100644 --- a/compiler/optimizing/code_generator_x86_64.cc +++ b/compiler/optimizing/code_generator_x86_64.cc @@ -587,26 +587,34 @@ void CodeGeneratorX86_64::Move(Location destination, Location source) { void CodeGeneratorX86_64::Move(HInstruction* instruction, Location location, HInstruction* move_for) { - if (instruction->IsIntConstant()) { - Immediate imm(instruction->AsIntConstant()->GetValue()); - if (location.IsRegister()) { - __ movl(location.As(), imm); - } else if (location.IsStackSlot()) { - __ movl(Address(CpuRegister(RSP), location.GetStackIndex()), imm); - } else { - DCHECK(location.IsConstant()); - DCHECK_EQ(location.GetConstant(), instruction); - } - } else if (instruction->IsLongConstant()) { - int64_t value = instruction->AsLongConstant()->GetValue(); - if (location.IsRegister()) { - __ movq(location.As(), Immediate(value)); - } else if (location.IsDoubleStackSlot()) { - __ movq(CpuRegister(TMP), Immediate(value)); - __ movq(Address(CpuRegister(RSP), location.GetStackIndex()), CpuRegister(TMP)); - } else { - DCHECK(location.IsConstant()); - DCHECK_EQ(location.GetConstant(), instruction); + LocationSummary* locations = instruction->GetLocations(); + if (locations != nullptr && locations->Out().Equals(location)) { + return; + } + + if (locations != nullptr && locations->Out().IsConstant()) { + HConstant* const_to_move = locations->Out().GetConstant(); + if (const_to_move->IsIntConstant()) { + Immediate imm(const_to_move->AsIntConstant()->GetValue()); + if (location.IsRegister()) { + __ movl(location.As(), imm); + } else if (location.IsStackSlot()) { + __ movl(Address(CpuRegister(RSP), location.GetStackIndex()), imm); + } else { + DCHECK(location.IsConstant()); + DCHECK_EQ(location.GetConstant(), const_to_move); + } + } else if (const_to_move->IsLongConstant()) { + int64_t value = const_to_move->AsLongConstant()->GetValue(); + if (location.IsRegister()) { + __ movq(location.As(), Immediate(value)); + } else if (location.IsDoubleStackSlot()) { + __ movq(CpuRegister(TMP), Immediate(value)); + __ movq(Address(CpuRegister(RSP), location.GetStackIndex()), CpuRegister(TMP)); + } else { + DCHECK(location.IsConstant()); + DCHECK_EQ(location.GetConstant(), const_to_move); + } } } else if (instruction->IsLoadLocal()) { switch (instruction->GetType()) { @@ -643,7 +651,7 @@ void CodeGeneratorX86_64::Move(HInstruction* instruction, case Primitive::kPrimLong: case Primitive::kPrimFloat: case Primitive::kPrimDouble: - Move(location, instruction->GetLocations()->Out()); + Move(location, locations->Out()); break; default: -- cgit v1.2.3-59-g8ed1b