Quick compiler: improve ClobberSReg comments
Issue 6501474
Improve the comments describing the usage of ClobberSReg(). Also, desk-checked all current
uses of ClobberSReg() to make sure they are appropriate.
No code changes - only comments.
Change-Id: Ife8419a7e2c2e51b258df7709a7d903d1fd93a44
diff --git a/src/compiler/codegen/arm/fp_arm.cc b/src/compiler/codegen/arm/fp_arm.cc
index 5e0e73d..57c55cc 100644
--- a/src/compiler/codegen/arm/fp_arm.cc
+++ b/src/compiler/codegen/arm/fp_arm.cc
@@ -259,6 +259,7 @@
if (is_double) {
rl_src1 = LoadValueWide(cu, rl_src1, kFPReg);
rl_src2 = LoadValueWide(cu, rl_src2, kFPReg);
+ // In case result vreg is also a src vreg, break association to avoid useless copy by EvalLoc()
ClobberSReg(cu, rl_dest.s_reg_low);
rl_result = EvalLoc(cu, rl_dest, kCoreReg, true);
LoadConstant(cu, rl_result.low_reg, default_result);
@@ -267,6 +268,7 @@
} else {
rl_src1 = LoadValue(cu, rl_src1, kFPReg);
rl_src2 = LoadValue(cu, rl_src2, kFPReg);
+ // In case result vreg is also a srcvreg, break association to avoid useless copy by EvalLoc()
ClobberSReg(cu, rl_dest.s_reg_low);
rl_result = EvalLoc(cu, rl_dest, kCoreReg, true);
LoadConstant(cu, rl_result.low_reg, default_result);
diff --git a/src/compiler/codegen/ralloc_util.cc b/src/compiler/codegen/ralloc_util.cc
index 999c652..1a3a413 100644
--- a/src/compiler/codegen/ralloc_util.cc
+++ b/src/compiler/codegen/ralloc_util.cc
@@ -124,7 +124,17 @@
}
}
-/* Clobber any temp associated with an s_reg. Could be in either class */
+/*
+ * Break the association between a Dalvik vreg and a physical temp register of either register
+ * class.
+ * TODO: Ideally, the public version of this code should not exist. Besides its local usage
+ * in the register utilities, is is also used by code gen routines to work around a deficiency in
+ * local register allocation, which fails to distinguish between the "in" and "out" identities
+ * of Dalvik vregs. This can result in useless register copies when the same Dalvik vreg
+ * is used both as the source and destination register of an operation in which the type
+ * changes (for example: INT_TO_FLOAT v1, v1). Revisit when improved register allocation is
+ * addressed.
+ */
void ClobberSReg(CompilationUnit* cu, int s_reg)
{
#ifndef NDEBUG
diff --git a/src/compiler/codegen/x86/fp_x86.cc b/src/compiler/codegen/x86/fp_x86.cc
index 78c737d..6bfe9a2 100644
--- a/src/compiler/codegen/x86/fp_x86.cc
+++ b/src/compiler/codegen/x86/fp_x86.cc
@@ -158,6 +158,7 @@
case Instruction::FLOAT_TO_INT: {
rl_src = LoadValue(cu, rl_src, kFPReg);
src_reg = rl_src.low_reg;
+ // In case result vreg is also src vreg, break association to avoid useless copy by EvalLoc()
ClobberSReg(cu, rl_dest.s_reg_low);
rl_result = EvalLoc(cu, rl_dest, kCoreReg, true);
int temp_reg = AllocTempFloat(cu);
@@ -179,6 +180,7 @@
case Instruction::DOUBLE_TO_INT: {
rl_src = LoadValueWide(cu, rl_src, kFPReg);
src_reg = rl_src.low_reg;
+ // In case result vreg is also src vreg, break association to avoid useless copy by EvalLoc()
ClobberSReg(cu, rl_dest.s_reg_low);
rl_result = EvalLoc(cu, rl_dest, kCoreReg, true);
int temp_reg = AllocTempDouble(cu) | X86_FP_DOUBLE;
@@ -245,6 +247,7 @@
rl_src2 = LoadValueWide(cu, rl_src2, kFPReg);
src_reg2 = S2d(rl_src2.low_reg, rl_src2.high_reg);
}
+ // In case result vreg is also src vreg, break association to avoid useless copy by EvalLoc()
ClobberSReg(cu, rl_dest.s_reg_low);
RegLocation rl_result = EvalLoc(cu, rl_dest, kCoreReg, true);
LoadConstantNoClobber(cu, rl_result.low_reg, unordered_gt ? 1 : 0);