Fix x86 and x64 codegens for 8/16 stores.
Test: 660-store-8-16
Change-Id: I6124818894205ebeed83929f3ff00bf2733292bf
diff --git a/compiler/optimizing/code_generator.h b/compiler/optimizing/code_generator.h
index 73202b4..51a0bae 100644
--- a/compiler/optimizing/code_generator.h
+++ b/compiler/optimizing/code_generator.h
@@ -446,6 +446,16 @@
return GetFrameSize() == (CallPushesPC() ? GetWordSize() : 0);
}
+ static int8_t GetInt8ValueOf(HConstant* constant) {
+ DCHECK(constant->IsIntConstant());
+ return constant->AsIntConstant()->GetValue();
+ }
+
+ static int16_t GetInt16ValueOf(HConstant* constant) {
+ DCHECK(constant->IsIntConstant());
+ return constant->AsIntConstant()->GetValue();
+ }
+
static int32_t GetInt32ValueOf(HConstant* constant) {
if (constant->IsIntConstant()) {
return constant->AsIntConstant()->GetValue();
diff --git a/compiler/optimizing/code_generator_x86.cc b/compiler/optimizing/code_generator_x86.cc
index af0e646..e5549fe 100644
--- a/compiler/optimizing/code_generator_x86.cc
+++ b/compiler/optimizing/code_generator_x86.cc
@@ -4956,8 +4956,8 @@
case Primitive::kPrimShort:
case Primitive::kPrimChar: {
if (value.IsConstant()) {
- int16_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant());
- __ movw(Address(base, offset), Immediate(v));
+ __ movw(Address(base, offset),
+ Immediate(CodeGenerator::GetInt16ValueOf(value.GetConstant())));
} else {
__ movw(Address(base, offset), value.AsRegister<Register>());
}
@@ -5404,7 +5404,7 @@
if (value.IsRegister()) {
__ movb(address, value.AsRegister<ByteRegister>());
} else {
- __ movb(address, Immediate(value.GetConstant()->AsIntConstant()->GetValue()));
+ __ movb(address, Immediate(CodeGenerator::GetInt8ValueOf(value.GetConstant())));
}
codegen_->MaybeRecordImplicitNullCheck(instruction);
break;
@@ -5417,7 +5417,7 @@
if (value.IsRegister()) {
__ movw(address, value.AsRegister<Register>());
} else {
- __ movw(address, Immediate(value.GetConstant()->AsIntConstant()->GetValue()));
+ __ movw(address, Immediate(CodeGenerator::GetInt16ValueOf(value.GetConstant())));
}
codegen_->MaybeRecordImplicitNullCheck(instruction);
break;
diff --git a/compiler/optimizing/code_generator_x86_64.cc b/compiler/optimizing/code_generator_x86_64.cc
index 86f6d51..8283887 100644
--- a/compiler/optimizing/code_generator_x86_64.cc
+++ b/compiler/optimizing/code_generator_x86_64.cc
@@ -4425,8 +4425,8 @@
case Primitive::kPrimBoolean:
case Primitive::kPrimByte: {
if (value.IsConstant()) {
- int8_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant());
- __ movb(Address(base, offset), Immediate(v));
+ __ movb(Address(base, offset),
+ Immediate(CodeGenerator::GetInt8ValueOf(value.GetConstant())));
} else {
__ movb(Address(base, offset), value.AsRegister<CpuRegister>());
}
@@ -4436,8 +4436,8 @@
case Primitive::kPrimShort:
case Primitive::kPrimChar: {
if (value.IsConstant()) {
- int16_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant());
- __ movw(Address(base, offset), Immediate(v));
+ __ movw(Address(base, offset),
+ Immediate(CodeGenerator::GetInt16ValueOf(value.GetConstant())));
} else {
__ movw(Address(base, offset), value.AsRegister<CpuRegister>());
}
@@ -4861,7 +4861,7 @@
if (value.IsRegister()) {
__ movb(address, value.AsRegister<CpuRegister>());
} else {
- __ movb(address, Immediate(value.GetConstant()->AsIntConstant()->GetValue()));
+ __ movb(address, Immediate(CodeGenerator::GetInt8ValueOf(value.GetConstant())));
}
codegen_->MaybeRecordImplicitNullCheck(instruction);
break;
@@ -4875,7 +4875,7 @@
__ movw(address, value.AsRegister<CpuRegister>());
} else {
DCHECK(value.IsConstant()) << value;
- __ movw(address, Immediate(value.GetConstant()->AsIntConstant()->GetValue()));
+ __ movw(address, Immediate(CodeGenerator::GetInt16ValueOf(value.GetConstant())));
}
codegen_->MaybeRecordImplicitNullCheck(instruction);
break;