8153357: C2 creates incorrect cast after eliminating phi with unique input
authorzmajo
Mon, 18 Apr 2016 11:22:51 +0200
changeset 38045 808cbf1958ce
parent 38044 a2a381c8b429
child 38046 f8383064eaa2
child 38047 4787ae4b4d1c
8153357: C2 creates incorrect cast after eliminating phi with unique input Summary: Refine C2's logic to determine the type of cast node added. Reviewed-by: kvn
hotspot/src/share/vm/opto/cfgnode.cpp
--- a/hotspot/src/share/vm/opto/cfgnode.cpp	Mon Apr 18 09:39:55 2016 +0200
+++ b/hotspot/src/share/vm/opto/cfgnode.cpp	Mon Apr 18 11:22:51 2016 +0200
@@ -1703,16 +1703,19 @@
     }
 
     if (uncasted) {
-      // Wait until after parsing for the type information to propagate from the casts
+      // Add a cast node between the phi to be removed and its unique input.
+      // Wait until after parsing for the type information to propagate from the casts.
       assert(can_reshape, "Invalid during parsing");
       const Type* phi_type = bottom_type();
       assert(phi_type->isa_int() || phi_type->isa_ptr(), "bad phi type");
       int opcode;
+      // Determine the type of cast to be added.
       if (phi_type->isa_int()) {
         opcode = Op_CastII;
       } else {
         const Type* uin_type = phase->type(uin);
-        if (phi_type->join(TypePtr::NOTNULL) == uin_type->join(TypePtr::NOTNULL)) {
+        if ((phi_type->join(TypePtr::NOTNULL) == uin_type->join(TypePtr::NOTNULL)) ||
+            (!phi_type->isa_oopptr() && !uin_type->isa_oopptr())) {
           opcode = Op_CastPP;
         } else {
           opcode = Op_CheckCastPP;