Do a null check on the sibling in the register allocator.
There may be a lifetime hole between the intervals, which means there is
no interval for the given position.
Litle sister of https://android-review.googlesource.com/#/c/209336/.
bug:27626705
Change-Id: I8082aa5ae2dc37d8fa5d4c430b69e6defa495439
diff --git a/compiler/optimizing/register_allocator.cc b/compiler/optimizing/register_allocator.cc
index 44bede8..b1f9cbc 100644
--- a/compiler/optimizing/register_allocator.cc
+++ b/compiler/optimizing/register_allocator.cc
@@ -1931,7 +1931,7 @@
// `GetSiblingAt` returns the sibling that contains a position, but there could be
// a lifetime hole in it. `CoversSlow` returns whether the interval is live at that
// position.
- if (sibling->CoversSlow(block->GetLifetimeStart())) {
+ if ((sibling != nullptr) && sibling->CoversSlow(block->GetLifetimeStart())) {
DCHECK(!sibling->HasRegister());
}
}
diff --git a/test/588-checker-irreducible-lifetime-hole/expected.txt b/test/588-checker-irreducible-lifetime-hole/expected.txt
index d81cc07..aab2009 100644
--- a/test/588-checker-irreducible-lifetime-hole/expected.txt
+++ b/test/588-checker-irreducible-lifetime-hole/expected.txt
@@ -1 +1,2 @@
42
+1
diff --git a/test/588-checker-irreducible-lifetime-hole/smali/IrreducibleLoop.smali b/test/588-checker-irreducible-lifetime-hole/smali/IrreducibleLoop.smali
index 207c77e..7dbd9da 100644
--- a/test/588-checker-irreducible-lifetime-hole/smali/IrreducibleLoop.smali
+++ b/test/588-checker-irreducible-lifetime-hole/smali/IrreducibleLoop.smali
@@ -16,13 +16,13 @@
.super Ljava/lang/Object;
-## CHECK-START-X86: int IrreducibleLoop.simpleLoop(int) dead_code_elimination (before)
+## CHECK-START-X86: int IrreducibleLoop.simpleLoop1(int) dead_code_elimination (before)
## CHECK-DAG: <<Method:(i|j)\d+>> CurrentMethod
## CHECK-DAG: <<Constant:i\d+>> IntConstant 42
## CHECK-DAG: Goto irreducible:true
## CHECK-DAG: InvokeStaticOrDirect [<<Constant>>,<<Method>>] loop:none
## CHECK-DAG: InvokeStaticOrDirect [{{i\d+}},<<Method>>] loop:none
-.method public static simpleLoop(I)I
+.method public static simpleLoop1(I)I
.registers 3
const/16 v0, 42
invoke-static {v0}, LIrreducibleLoop;->$noinline$m(I)V
@@ -57,6 +57,53 @@
return v0
.end method
+## CHECK-START-X86: int IrreducibleLoop.simpleLoop2(int) dead_code_elimination (before)
+## CHECK-DAG: <<Method:(i|j)\d+>> CurrentMethod
+## CHECK-DAG: <<Constant:i\d+>> IntConstant 42
+## CHECK-DAG: Goto irreducible:true
+## CHECK-DAG: InvokeStaticOrDirect [<<Constant>>,<<Method>>] loop:none
+## CHECK-DAG: InvokeStaticOrDirect [{{i\d+}},<<Method>>] loop:none
+.method public static simpleLoop2(I)I
+ .registers 3
+ const/16 v0, 42
+
+ :try_start1
+ invoke-static {v0}, LIrreducibleLoop;->$noinline$m(I)V
+ div-int v0, v0, v0
+ :try_end1
+ .catchall {:try_start1 .. :try_end1} :b14
+
+ :try_start2
+ invoke-static {v0}, LIrreducibleLoop;->$noinline$m(I)V
+ div-int v0, v0, v0
+ :try_end2
+ .catchall {:try_start2 .. :try_end2} :b45
+ goto :b49
+
+ :b14
+ goto :b15
+
+ :b45
+ goto :b15
+
+ :b15
+ goto :b16
+
+ :b16
+ goto :b49
+
+ :b49
+ invoke-static {v0}, LIrreducibleLoop;->$noinline$m(I)V
+ div-int v0, v0, v0
+ :try_end3
+ .catchall {:b49 .. :try_end3} :b49
+ if-eqz p0, :b16
+ goto :b26
+
+ :b26
+ return v0
+.end method
+
.method public static $noinline$m(I)V
.registers 3
const/16 v0, 0
diff --git a/test/588-checker-irreducible-lifetime-hole/src/Main.java b/test/588-checker-irreducible-lifetime-hole/src/Main.java
index 94e3357..98565b1 100644
--- a/test/588-checker-irreducible-lifetime-hole/src/Main.java
+++ b/test/588-checker-irreducible-lifetime-hole/src/Main.java
@@ -22,8 +22,15 @@
public static void main(String[] args) throws Exception {
Class<?> c = Class.forName("IrreducibleLoop");
- Method m = c.getMethod("simpleLoop", int.class);
- Object[] arguments = { 42 };
- System.out.println(m.invoke(null, arguments));
+ {
+ Method m = c.getMethod("simpleLoop1", int.class);
+ Object[] arguments = { 42 };
+ System.out.println(m.invoke(null, arguments));
+ }
+ {
+ Method m = c.getMethod("simpleLoop2", int.class);
+ Object[] arguments = { 42 };
+ System.out.println(m.invoke(null, arguments));
+ }
}
}