ART: Fix DeadPhiHandling creating >2 equivalents
Run test 531 failed a DCHECK because the DeadPhiHandling algorithm
would generate three phis of the same type:
(0) loop phi [#0, ref] with equivalents void & object
(1) type object equivalent by its first input => int & int
(2) request object equivalent by a user => int & int & object
(3) type second => int & object & object (dead)
(4) type first => object & object & object
This patch fixes the issue by skipping (1) when the phi already has
a type, thus not creating the third equivalent for the phi's user.
Change-Id: I00c990a5982ddc1f7de013f72bbcfb1c649a6e5f
diff --git a/compiler/optimizing/ssa_builder.cc b/compiler/optimizing/ssa_builder.cc
index ad8c682..fb11d76 100644
--- a/compiler/optimizing/ssa_builder.cc
+++ b/compiler/optimizing/ssa_builder.cc
@@ -145,8 +145,14 @@
if (phi->IsDead() && phi->HasEnvironmentUses()) {
phi->SetLive();
if (block->IsLoopHeader()) {
- // Give a type to the loop phi, to guarantee convergence of the algorithm.
- phi->SetType(phi->InputAt(0)->GetType());
+ // Give a type to the loop phi to guarantee convergence of the algorithm.
+ // Note that the dead phi may already have a type if it is an equivalent
+ // generated for a typed LoadLocal. In that case we do not change the
+ // type because it could lead to an unsupported PrimNot/Float/Double ->
+ // PrimInt/Long transition and create same type equivalents.
+ if (phi->GetType() == Primitive::kPrimVoid) {
+ phi->SetType(phi->InputAt(0)->GetType());
+ }
AddToWorklist(phi);
} else {
// Because we are doing a reverse post order visit, all inputs of