aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/android/tools/r8/ir
diff options
context:
space:
mode:
authorMads Ager <ager@google.com>2017-05-23 14:31:04 +0200
committerMads Ager <ager@google.com>2017-05-23 14:31:04 +0200
commita66f4f1c961716543e6534a4d964ac654b759e41 (patch)
treec43419b361df4019264ef194b4217f4f2db3a086 /src/main/java/com/android/tools/r8/ir
parent1901889bf5876e7dead7baf26b709b18e819a3f1 (diff)
downloadr8-a66f4f1c961716543e6534a4d964ac654b759e41.tar.gz
Fix isRematerializable to always use the unadjusted real register number.
This ensures that isRematerializable returns the same value for the same interval both when generating moves and when performing peephole optimizations. Change-Id: I2953fac1db981e045c61b7c9717098c2479862a6
Diffstat (limited to 'src/main/java/com/android/tools/r8/ir')
-rw-r--r--src/main/java/com/android/tools/r8/ir/regalloc/LinearScanRegisterAllocator.java7
-rw-r--r--src/main/java/com/android/tools/r8/ir/regalloc/LiveIntervals.java8
2 files changed, 12 insertions, 3 deletions
diff --git a/src/main/java/com/android/tools/r8/ir/regalloc/LinearScanRegisterAllocator.java b/src/main/java/com/android/tools/r8/ir/regalloc/LinearScanRegisterAllocator.java
index e79abc1fb..f2d039d5b 100644
--- a/src/main/java/com/android/tools/r8/ir/regalloc/LinearScanRegisterAllocator.java
+++ b/src/main/java/com/android/tools/r8/ir/regalloc/LinearScanRegisterAllocator.java
@@ -470,7 +470,7 @@ public class LinearScanRegisterAllocator implements RegisterAllocator {
return realRegisterNumberFromAllocated(intervalsRegister);
}
- int realRegisterNumberFromAllocated(int allocated) {
+ int unadjustedRealRegisterFromAllocated(int allocated) {
assert allocated != NO_REGISTER;
assert allocated >= 0;
int register;
@@ -484,6 +484,11 @@ public class LinearScanRegisterAllocator implements RegisterAllocator {
// For everything else use the lower numbers.
register = allocated - numberOfArgumentRegisters - NUMBER_OF_SENTINEL_REGISTERS;
}
+ return register;
+ }
+
+ int realRegisterNumberFromAllocated(int allocated) {
+ int register = unadjustedRealRegisterFromAllocated(allocated);
// Adjust for spill registers that turn out to be unused because the value can be
// rematerialized instead of spilled.
if (unusedRegisters != null) {
diff --git a/src/main/java/com/android/tools/r8/ir/regalloc/LiveIntervals.java b/src/main/java/com/android/tools/r8/ir/regalloc/LiveIntervals.java
index f1d3b9e46..c966813dc 100644
--- a/src/main/java/com/android/tools/r8/ir/regalloc/LiveIntervals.java
+++ b/src/main/java/com/android/tools/r8/ir/regalloc/LiveIntervals.java
@@ -89,8 +89,12 @@ public class LiveIntervals {
}
// If one of the non-spilled splits uses a register that is higher than U8BIT_MAX we cannot
// rematerialize it using a ConstNumber instruction and we use spill moves instead of
- // rematerialization.
- int max = registerAllocator.realRegisterNumberFromAllocated(getMaxNonSpilledRegister());
+ // rematerialization. We use this check both before and after we have computed the set
+ // of unused registers. We therefore have to be careful to use the same max number for
+ // these computations. We use the unadjusted real register number to make sure that
+ // isRematerializable for the same intervals does not change from one phase of
+ // compilation to the next.
+ int max = registerAllocator.unadjustedRealRegisterFromAllocated(getMaxNonSpilledRegister());
return max < Constants.U8BIT_MAX;
}