8329194: Cleanup Type::cmp definition and usage

Reviewed-by: dfenacci, chagedorn, qamai
This commit is contained in:
Jasmine Karthikeyan 2024-04-25 13:13:25 +00:00 committed by Tobias Hartmann
parent c9442014e5
commit b9927aa3a4
9 changed files with 35 additions and 29 deletions

@ -10249,7 +10249,7 @@ instruct mask_opers_evex(kReg dst, kReg src1, kReg src2, kReg kscratch) %{
ins_encode %{
const MachNode* mask1 = static_cast<const MachNode*>(this->in(this->operand_index($src1)));
const MachNode* mask2 = static_cast<const MachNode*>(this->in(this->operand_index($src2)));
assert(0 == Type::cmp(mask1->bottom_type(), mask2->bottom_type()), "");
assert(Type::equals(mask1->bottom_type(), mask2->bottom_type()), "Mask types must be equal");
uint masklen = Matcher::vector_length(this);
masklen = (masklen < 16 && !VM_Version::supports_avx512dq()) ? 16 : masklen;
__ masked_op(this->ideal_Opcode(), masklen, $dst$$KRegister, $src1$$KRegister, $src2$$KRegister);

@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -2724,10 +2724,10 @@ Node* PhiNode::merge_through_phi(Node* root_phi, PhaseIterGVN* igvn) {
cached_vbox = vbox;
} else if (vbox->vec_type() != cached_vbox->vec_type()) {
// TODO: vector type mismatch can be handled with additional reinterpret casts
assert(Type::cmp(vbox->vec_type(), cached_vbox->vec_type()) != 0, "inconsistent");
assert(!Type::equals(vbox->vec_type(), cached_vbox->vec_type()), "inconsistent");
return nullptr; // not optimizable: vector type mismatch
} else if (vbox->box_type() != cached_vbox->box_type()) {
assert(Type::cmp(vbox->box_type(), cached_vbox->box_type()) != 0, "inconsistent");
assert(!Type::equals(vbox->box_type(), cached_vbox->box_type()), "inconsistent");
return nullptr; // not optimizable: box type mismatch
}
} else {

@ -856,7 +856,7 @@ bool LoadNode::can_remove_control() const {
uint LoadNode::size_of() const { return sizeof(*this); }
bool LoadNode::cmp(const Node &n) const {
LoadNode& load = (LoadNode &)n;
return !Type::cmp(_type, load._type) &&
return Type::equals(_type, load._type) &&
_control_dependency == load._control_dependency &&
_mo == load._mo;
}

@ -3011,7 +3011,7 @@ uint TypeNode::hash() const {
return Node::hash() + _type->hash();
}
bool TypeNode::cmp(const Node& n) const {
return !Type::cmp(_type, ((TypeNode&)n)._type);
return Type::equals(_type, n.as_Type()->_type);
}
const Type* TypeNode::bottom_type() const { return _type; }
const Type* TypeNode::Value(PhaseGVN* phase) const { return _type; }

@ -399,11 +399,13 @@ const Type *Type::make( enum TYPES t ) {
}
//------------------------------cmp--------------------------------------------
int Type::cmp( const Type *const t1, const Type *const t2 ) {
if( t1->_base != t2->_base )
return 1; // Missed badly
bool Type::equals(const Type* t1, const Type* t2) {
if (t1->_base != t2->_base) {
return false; // Missed badly
}
assert(t1 != t2 || t1->eq(t2), "eq must be reflexive");
return !t1->eq(t2); // Return ZERO if equal
return t1->eq(t2);
}
const Type* Type::maybe_remove_speculative(bool include_speculative) const {
@ -433,9 +435,13 @@ void Type::Initialize_shared(Compile* current) {
Arena* shared_type_arena = new (mtCompiler)Arena(mtCompiler);
current->set_type_arena(shared_type_arena);
_shared_type_dict =
new (shared_type_arena) Dict( (CmpKey)Type::cmp, (Hash)Type::uhash,
shared_type_arena, 128 );
// Map the boolean result of Type::equals into a comparator result that CmpKey expects.
CmpKey type_cmp = [](const void* t1, const void* t2) -> int32_t {
return Type::equals((Type*) t1, (Type*) t2) ? 0 : 1;
};
_shared_type_dict = new (shared_type_arena) Dict(type_cmp, (Hash) Type::uhash, shared_type_arena, 128);
current->set_type_dict(_shared_type_dict);
// Make shared pre-built types.
@ -744,7 +750,7 @@ const Type *Type::hashcons(void) {
// Since we just discovered a new Type, compute its dual right now.
assert( !_dual, "" ); // No dual yet
_dual = xdual(); // Compute the dual
if (cmp(this, _dual) == 0) { // Handle self-symmetric
if (equals(this, _dual)) { // Handle self-symmetric
if (_dual != this) {
delete _dual;
_dual = this;

@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -157,7 +157,7 @@ private:
static const TypeInfo _type_info[];
static int uhash( const Type *const t );
// Structural equality check. Assumes that cmp() has already compared
// Structural equality check. Assumes that equals() has already compared
// the _base types and thus knows it can cast 't' appropriately.
virtual bool eq( const Type *t ) const;
@ -216,15 +216,15 @@ public:
// Create a new hash-consd type
static const Type *make(enum TYPES);
// Test for equivalence of types
static int cmp( const Type *const t1, const Type *const t2 );
static bool equals(const Type* t1, const Type* t2);
// Test for higher or equal in lattice
// Variant that drops the speculative part of the types
bool higher_equal(const Type *t) const {
return !cmp(meet(t),t->remove_speculative());
bool higher_equal(const Type* t) const {
return equals(meet(t), t->remove_speculative());
}
// Variant that keeps the speculative part of the types
bool higher_equal_speculative(const Type *t) const {
return !cmp(meet_speculative(t),t);
bool higher_equal_speculative(const Type* t) const {
return equals(meet_speculative(t), t);
}
// MEET operation; lower in lattice.

@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2020, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -2629,7 +2629,7 @@ bool LibraryCallKit::inline_vector_convert() {
op = gvn().transform(VectorCastNode::make(cast_vopc, op, elem_bt_to, num_elem_to));
}
}
} else if (Type::cmp(src_type, dst_type) != 0) {
} else if (!Type::equals(src_type, dst_type)) {
assert(!is_cast, "must be reinterpret");
op = gvn().transform(new VectorReinterpretNode(op, src_type, dst_type));
}

@ -1,5 +1,5 @@
/*
* Copyright (c) 2007, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2007, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -1668,7 +1668,7 @@ Node* VectorReinterpretNode::Identity(PhaseGVN *phase) {
// "VectorReinterpret (VectorReinterpret node) ==> node" if:
// 1) Types of 'node' and 'this' are identical
// 2) Truncations are not introduced by the first VectorReinterpret
if (Type::cmp(bottom_type(), n->in(1)->bottom_type()) == 0 &&
if (Type::equals(bottom_type(), n->in(1)->bottom_type()) &&
length_in_bytes() <= n->bottom_type()->is_vect()->length_in_bytes()) {
return n->in(1);
}
@ -1685,7 +1685,7 @@ Node* VectorInsertNode::make(Node* vec, Node* new_val, int position, PhaseGVN& g
Node* VectorUnboxNode::Ideal(PhaseGVN* phase, bool can_reshape) {
Node* n = obj()->uncast();
if (EnableVectorReboxing && n->Opcode() == Op_VectorBox) {
if (Type::cmp(bottom_type(), n->in(VectorBoxNode::Value)->bottom_type()) == 0) {
if (Type::equals(bottom_type(), n->in(VectorBoxNode::Value)->bottom_type())) {
// Handled by VectorUnboxNode::Identity()
} else {
VectorBoxNode* vbox = static_cast<VectorBoxNode*>(n);
@ -1722,7 +1722,7 @@ Node* VectorUnboxNode::Ideal(PhaseGVN* phase, bool can_reshape) {
Node* VectorUnboxNode::Identity(PhaseGVN* phase) {
Node* n = obj()->uncast();
if (EnableVectorReboxing && n->Opcode() == Op_VectorBox) {
if (Type::cmp(bottom_type(), n->in(VectorBoxNode::Value)->bottom_type()) == 0) {
if (Type::equals(bottom_type(), n->in(VectorBoxNode::Value)->bottom_type())) {
return n->in(VectorBoxNode::Value); // VectorUnbox (VectorBox v) ==> v
} else {
// Handled by VectorUnboxNode::Ideal().

@ -1560,7 +1560,7 @@ class VectorReinterpretNode : public VectorNode {
const TypeVect* src_type() { return _src_vt; }
virtual uint hash() const { return VectorNode::hash() + _src_vt->hash(); }
virtual bool cmp( const Node &n ) const {
return VectorNode::cmp(n) && !Type::cmp(_src_vt,((VectorReinterpretNode&)n)._src_vt);
return VectorNode::cmp(n) && Type::equals(_src_vt, ((VectorReinterpretNode&) n)._src_vt);
}
virtual Node* Identity(PhaseGVN* phase);
@ -1696,7 +1696,7 @@ class VectorInsertNode : public VectorNode {
VectorInsertNode(Node* vsrc, Node* new_val, ConINode* pos, const TypeVect* vt) : VectorNode(vsrc, new_val, (Node*)pos, vt) {
assert(pos->get_int() >= 0, "positive constants");
assert(pos->get_int() < (int)vt->length(), "index must be less than vector length");
assert(Type::cmp(vt, vsrc->bottom_type()) == 0, "input and output must be same type");
assert(Type::equals(vt, vsrc->bottom_type()), "input and output must be same type");
}
virtual int Opcode() const;
uint pos() const { return in(3)->get_int(); }