< prev index next >

src/hotspot/share/opto/subnode.cpp

Print this page
*** 28,10 ***
--- 28,11 ---
  #include "gc/shared/c2/barrierSetC2.hpp"
  #include "memory/allocation.inline.hpp"
  #include "opto/addnode.hpp"
  #include "opto/callnode.hpp"
  #include "opto/cfgnode.hpp"
+ #include "opto/inlinetypenode.hpp"
  #include "opto/loopnode.hpp"
  #include "opto/matcher.hpp"
  #include "opto/movenode.hpp"
  #include "opto/mulnode.hpp"
  #include "opto/opaquenode.hpp"

*** 890,21 ***
      }
    }
    return nullptr;                  // No change
  }
  
! Node *CmpLNode::Ideal( PhaseGVN *phase, bool can_reshape ) {
    const TypeLong *t2 = phase->type(in(2))->isa_long();
    if (Opcode() == Op_CmpL && in(1)->Opcode() == Op_ConvI2L && t2 && t2->is_con()) {
      const jlong con = t2->get_con();
      if (con >= min_jint && con <= max_jint) {
        return new CmpINode(in(1)->in(1), phase->intcon((jint)con));
      }
    }
    return nullptr;
  }
  
  //=============================================================================
  // Simplify a CmpL (compare 2 longs ) node, based on local information.
  // If both inputs are constants, compare them.
  const Type *CmpLNode::sub( const Type *t1, const Type *t2 ) const {
    const TypeLong *r0 = t1->is_long(); // Handy access
--- 891,53 ---
      }
    }
    return nullptr;                  // No change
  }
  
! //------------------------------Ideal------------------------------------------
+ Node* CmpLNode::Ideal(PhaseGVN* phase, bool can_reshape) {
+   Node* a = nullptr;
+   Node* b = nullptr;
+   if (is_double_null_check(phase, a, b) && (phase->type(a)->is_zero_type() || phase->type(b)->is_zero_type())) {
+     // Degraded to a simple null check, use old acmp
+     return new CmpPNode(a, b);
+   }
    const TypeLong *t2 = phase->type(in(2))->isa_long();
    if (Opcode() == Op_CmpL && in(1)->Opcode() == Op_ConvI2L && t2 && t2->is_con()) {
      const jlong con = t2->get_con();
      if (con >= min_jint && con <= max_jint) {
        return new CmpINode(in(1)->in(1), phase->intcon((jint)con));
      }
    }
    return nullptr;
  }
  
+ // Match double null check emitted by Compile::optimize_acmp()
+ bool CmpLNode::is_double_null_check(PhaseGVN* phase, Node*& a, Node*& b) const {
+   if (in(1)->Opcode() == Op_OrL &&
+       in(1)->in(1)->Opcode() == Op_CastP2X &&
+       in(1)->in(2)->Opcode() == Op_CastP2X &&
+       in(2)->bottom_type()->is_zero_type()) {
+     assert(EnableValhalla, "unexpected double null check");
+     a = in(1)->in(1)->in(1);
+     b = in(1)->in(2)->in(1);
+     return true;
+   }
+   return false;
+ }
+ 
+ //------------------------------Value------------------------------------------
+ const Type* CmpLNode::Value(PhaseGVN* phase) const {
+   Node* a = nullptr;
+   Node* b = nullptr;
+   if (is_double_null_check(phase, a, b) && (!phase->type(a)->maybe_null() || !phase->type(b)->maybe_null())) {
+     // One operand is never nullptr, emit constant false
+     return TypeInt::CC_GT;
+   }
+   return SubNode::Value(phase);
+ }
+ 
  //=============================================================================
  // Simplify a CmpL (compare 2 longs ) node, based on local information.
  // If both inputs are constants, compare them.
  const Type *CmpLNode::sub( const Type *t1, const Type *t2 ) const {
    const TypeLong *r0 = t1->is_long(); // Handy access

*** 1026,11 ***
        unrelated_classes = xklass1;
      } else if ((p0 && !p0->maybe_java_subtype_of(p1)) ||
                 (k0 && !k0->maybe_java_subtype_of(k1))) {
        unrelated_classes = xklass0;
      }
! 
      if (unrelated_classes) {
        // The oops classes are known to be unrelated. If the joined PTRs of
        // two oops is not Null and not Bottom, then we are sure that one
        // of the two oops is non-null, and the comparison will always fail.
        TypePtr::PTR jp = r0->join_ptr(r1->_ptr);
--- 1059,26 ---
        unrelated_classes = xklass1;
      } else if ((p0 && !p0->maybe_java_subtype_of(p1)) ||
                 (k0 && !k0->maybe_java_subtype_of(k1))) {
        unrelated_classes = xklass0;
      }
!     if (!unrelated_classes) {
+       // Handle inline type arrays
+       if ((r0->flat_in_array() && r1->not_flat_in_array()) ||
+           (r1->flat_in_array() && r0->not_flat_in_array())) {
+         // One type is in flat arrays but the other type is not. Must be unrelated.
+         unrelated_classes = true;
+       } else if ((r0->is_not_flat() && r1->is_flat()) ||
+                  (r1->is_not_flat() && r0->is_flat())) {
+         // One type is a non-flat array and the other type is a flat array. Must be unrelated.
+         unrelated_classes = true;
+       } else if ((r0->is_not_null_free() && r1->is_null_free()) ||
+                  (r1->is_not_null_free() && r0->is_null_free())) {
+         // One type is a nullable array and the other type is a null-free array. Must be unrelated.
+         unrelated_classes = true;
+       }
+     }
      if (unrelated_classes) {
        // The oops classes are known to be unrelated. If the joined PTRs of
        // two oops is not Null and not Bottom, then we are sure that one
        // of the two oops is non-null, and the comparison will always fail.
        TypePtr::PTR jp = r0->join_ptr(r1->_ptr);

*** 1111,11 ***
  //
  // Also check for the case of comparing an unknown klass loaded from the primary
  // super-type array vs a known klass with no subtypes.  This amounts to
  // checking to see an unknown klass subtypes a known klass with no subtypes;
  // this only happens on an exact match.  We can shorten this test by 1 load.
! Node *CmpPNode::Ideal( PhaseGVN *phase, bool can_reshape ) {
    // Normalize comparisons between Java mirrors into comparisons of the low-
    // level klass, where a dependent load could be shortened.
    //
    // The new pattern has a nice effect of matching the same pattern used in the
    // fast path of instanceof/checkcast/Class.isInstance(), which allows
--- 1159,18 ---
  //
  // Also check for the case of comparing an unknown klass loaded from the primary
  // super-type array vs a known klass with no subtypes.  This amounts to
  // checking to see an unknown klass subtypes a known klass with no subtypes;
  // this only happens on an exact match.  We can shorten this test by 1 load.
! Node* CmpPNode::Ideal(PhaseGVN *phase, bool can_reshape) {
+   // TODO 8284443 in(1) could be cast?
+   if (in(1)->is_InlineType() && phase->type(in(2))->is_zero_type()) {
+     // Null checking a scalarized but nullable inline type. Check the IsInit
+     // input instead of the oop input to avoid keeping buffer allocations alive.
+     return new CmpINode(in(1)->as_InlineType()->get_is_init(), phase->intcon(0));
+   }
+ 
    // Normalize comparisons between Java mirrors into comparisons of the low-
    // level klass, where a dependent load could be shortened.
    //
    // The new pattern has a nice effect of matching the same pattern used in the
    // fast path of instanceof/checkcast/Class.isInstance(), which allows

*** 1183,10 ***
--- 1238,17 ---
  
    // Verify that we understand the situation
    if (con2 != (intptr_t) superklass->super_check_offset())
      return nullptr;                // Might be element-klass loading from array klass
  
+   // Do not fold the subtype check to an array klass pointer comparison for null-able inline type arrays
+   // because null-free [LMyValue <: null-able [LMyValue but the klasses are different. Perform a full test.
+   if (superklass->is_obj_array_klass() && !superklass->as_array_klass()->is_elem_null_free() &&
+       superklass->as_array_klass()->element_klass()->is_inlinetype()) {
+     return nullptr;
+   }
+ 
    // If 'superklass' has no subklasses and is not an interface, then we are
    // assured that the only input which will pass the type check is
    // 'superklass' itself.
    //
    // We could be more liberal here, and allow the optimization on interfaces

*** 1326,10 ***
--- 1388,47 ---
      // Testing value required the precision of a double
    }
    return nullptr;                  // No change
  }
  
+ //=============================================================================
+ //------------------------------Value------------------------------------------
+ const Type* FlatArrayCheckNode::Value(PhaseGVN* phase) const {
+   bool all_not_flat = true;
+   for (uint i = ArrayOrKlass; i < req(); ++i) {
+     const Type* t = phase->type(in(i));
+     if (t == Type::TOP) {
+       return Type::TOP;
+     }
+     if (t->is_ptr()->is_flat()) {
+       // One of the input arrays is flat, check always passes
+       return TypeInt::CC_EQ;
+     } else if (!t->is_ptr()->is_not_flat()) {
+       // One of the input arrays might be flat
+       all_not_flat = false;
+     }
+   }
+   if (all_not_flat) {
+     // None of the input arrays can be flat, check always fails
+     return TypeInt::CC_GT;
+   }
+   return TypeInt::CC;
+ }
+ 
+ //------------------------------Ideal------------------------------------------
+ Node* FlatArrayCheckNode::Ideal(PhaseGVN* phase, bool can_reshape) {
+   bool changed = false;
+   // Remove inputs that are known to be non-flat
+   for (uint i = ArrayOrKlass; i < req(); ++i) {
+     const Type* t = phase->type(in(i));
+     if (t->isa_ptr() && t->is_ptr()->is_not_flat()) {
+       del_req(i--);
+       changed = true;
+     }
+   }
+   return changed ? this : nullptr;
+ }
  
  //=============================================================================
  //------------------------------cc2logical-------------------------------------
  // Convert a condition code type to a logical type
  const Type *BoolTest::cc2logical( const Type *CC ) const {
< prev index next >