Verify InitClass values never split
Bug: 192293683
Change-Id: I479b23c24775436a5aff3d8803705852d002edb6
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 9cb4c09..0c5705c 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
@@ -416,6 +416,9 @@
register = NO_REGISTER;
return this;
}
+
+ assert !getValue().isDefinedByInstructionSatisfying(Instruction::isInitClass);
+
start = toGapPosition(start);
LiveIntervals splitChild = new LiveIntervals(splitParent);
splitParent.splitChildren.add(splitChild);
diff --git a/src/test/java/com/android/tools/r8/ir/regalloc/Regress68656641.java b/src/test/java/com/android/tools/r8/ir/regalloc/Regress68656641.java
index ca5b2c0..07767cd 100644
--- a/src/test/java/com/android/tools/r8/ir/regalloc/Regress68656641.java
+++ b/src/test/java/com/android/tools/r8/ir/regalloc/Regress68656641.java
@@ -7,6 +7,7 @@
import com.android.tools.r8.graph.AppView;
import com.android.tools.r8.graph.DexApplication;
import com.android.tools.r8.ir.analysis.type.TypeElement;
+import com.android.tools.r8.ir.code.Argument;
import com.android.tools.r8.ir.code.IRCode;
import com.android.tools.r8.ir.code.Value;
import com.android.tools.r8.smali.SmaliBuilder;
@@ -62,18 +63,21 @@
MyRegisterAllocator allocator = new MyRegisterAllocator(appView, code);
// Setup live an inactive live interval with ranges [0, 10[ and [20, 30[ with only
// uses in the first interval and which is linked to another interval.
- LiveIntervals inactiveIntervals = new LiveIntervals(new Value(0, TypeElement.getInt(), null));
+ LiveIntervals inactiveIntervals =
+ new LiveIntervals(ensureDefinition(new Value(0, TypeElement.getInt(), null), 0));
inactiveIntervals.addRange(new LiveRange(0, 10));
inactiveIntervals.addUse(new LiveIntervalsUse(0, 10));
inactiveIntervals.addUse(new LiveIntervalsUse(4, 10));
inactiveIntervals.addRange(new LiveRange(20, 30));
inactiveIntervals.setRegister(0);
- LiveIntervals linked = new LiveIntervals(new Value(1, TypeElement.getInt(), null));
+ LiveIntervals linked =
+ new LiveIntervals(ensureDefinition(new Value(1, TypeElement.getInt(), null), 1));
linked.setRegister(1);
inactiveIntervals.link(linked);
allocator.addInactiveIntervals(inactiveIntervals);
// Setup an unhandled interval that overlaps the inactive interval.
- LiveIntervals unhandledIntervals = new LiveIntervals(new Value(2, TypeElement.getInt(), null));
+ LiveIntervals unhandledIntervals =
+ new LiveIntervals(ensureDefinition(new Value(2, TypeElement.getInt(), null), 2));
unhandledIntervals.addRange(new LiveRange(12, 24));
// Split the overlapping inactive intervals and check that after the split, the second
// part of the inactive interval is unhandled and will therefore get a new register
@@ -83,4 +87,10 @@
assert allocator.getUnhandled().peek().getStart() == 20;
assert allocator.getUnhandled().peek().getEnd() == 30;
}
+
+ private Value ensureDefinition(Value value, int index) {
+ Argument argument = new Argument(value, index, false);
+ value.definition = argument;
+ return value;
+ }
}