boolean resolveResultType(PhiInsn insn) {
    insn.updateSourcesToDefinitions(ssaMeth);

    RegisterSpecList sources = insn.getSources();

    // Start by finding the first non-void operand
    RegisterSpec first = null;
    int firstIndex = -1;

    int szSources = sources.size();
    for (int i = 0; i < szSources; i++) {
      RegisterSpec rs = sources.get(i);

      if (rs.getBasicType() != Type.BT_VOID) {
        first = rs;
        firstIndex = i;
      }
    }

    if (first == null) {
      // All operands are void -- we're not ready to resolve yet
      return false;
    }

    LocalItem firstLocal = first.getLocalItem();
    TypeBearer mergedType = first.getType();
    boolean sameLocals = true;
    for (int i = 0; i < szSources; i++) {
      if (i == firstIndex) {
        continue;
      }

      RegisterSpec rs = sources.get(i);

      // Just skip void (unresolved phi results) for now
      if (rs.getBasicType() == Type.BT_VOID) {
        continue;
      }

      sameLocals = sameLocals && equalsHandlesNulls(firstLocal, rs.getLocalItem());

      mergedType = Merger.mergeType(mergedType, rs.getType());
    }

    TypeBearer newResultType;

    if (mergedType != null) {
      newResultType = mergedType;
    } else {
      StringBuilder sb = new StringBuilder();

      for (int i = 0; i < szSources; i++) {
        sb.append(sources.get(i).toString());
        sb.append(' ');
      }

      throw new RuntimeException("Couldn't map types in phi insn:" + sb);
    }

    LocalItem newLocal = sameLocals ? firstLocal : null;

    RegisterSpec result = insn.getResult();

    if ((result.getTypeBearer() == newResultType)
        && equalsHandlesNulls(newLocal, result.getLocalItem())) {
      return false;
    }

    insn.changeResultType(newResultType, newLocal);

    return true;
  }
Resolves the result of a phi insn based on its operands. The "void" type, which is a
nonsensical type for a register, is used for registers defined by as-of-yet-unresolved phi
operations.

@return true if the result type changed, false if no change
android/android_framework/dex-maker/src/main/java/com/android/dx/ssa/PhiTypeResolver.java