Ensure environment is ready when populating loop.
Rationale:
OSR requires the suspend check to already have an environment,
albeit just for testing irreducible loops. This CL fixes the
omission. Note, the error is spurious on OSR and writing a
unit or regression test for this is hard.
Test: test-art-host
Bug: 36950873
Change-Id: Ica89e18e10deb438dead79e2cc40dd00a60b529f
diff --git a/compiler/optimizing/nodes.cc b/compiler/optimizing/nodes.cc
index 5617e4b..e71fea9 100644
--- a/compiler/optimizing/nodes.cc
+++ b/compiler/optimizing/nodes.cc
@@ -2380,11 +2380,13 @@
MakeRoomFor(&reverse_post_order_, 1, index_of_body - 1);
reverse_post_order_[index_of_body] = new_body;
- // Add gotos and suspend check (client must add conditional in header and copy environment).
+ // Add gotos and suspend check (client must add conditional in header).
new_pre_header->AddInstruction(new (arena_) HGoto());
HSuspendCheck* suspend_check = new (arena_) HSuspendCheck(header->GetDexPc());
new_header->AddInstruction(suspend_check);
new_body->AddInstruction(new (arena_) HGoto());
+ suspend_check->CopyEnvironmentFromWithLoopPhiAdjustment(
+ loop->GetSuspendCheck()->GetEnvironment(), header);
// Update loop information.
new_header->AddBackEdge(new_body);