Skip to content

Commit

Permalink
8342393: Promote commutative vector IR node sharing
Browse files Browse the repository at this point in the history
Reviewed-by: vlivanov, epeter, sviswanathan
  • Loading branch information
Jatin Bhateja committed Feb 24, 2025
1 parent f755fad commit e410af0
Show file tree
Hide file tree
Showing 4 changed files with 789 additions and 1 deletion.
57 changes: 56 additions & 1 deletion src/hotspot/share/opto/vectornode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1042,10 +1042,65 @@ Node* VectorNode::try_to_gen_masked_vector(PhaseGVN* gvn, Node* node, const Type
}
}

bool VectorNode::should_swap_inputs_to_help_global_value_numbering() {
// Predicated vector operations are sensitive to ordering of inputs.
// When the mask corresponding to a vector lane is false then
// the result of the operation is corresponding lane of its first operand.
// i.e. RES = VEC1.lanewise(OPER, VEC2, MASK) is semantically equivalent to
// RES = BLEND(VEC1, VEC1.lanewise(OPER, VEC2), MASK)
if (is_predicated_vector()) {
return false;
}

switch(Opcode()) {
case Op_AddVB:
case Op_AddVS:
case Op_AddVI:
case Op_AddVL:
case Op_AddVF:
case Op_AddVD:

case Op_MulVB:
case Op_MulVS:
case Op_MulVI:
case Op_MulVL:
case Op_MulVF:
case Op_MulVD:

case Op_MaxV:
case Op_MinV:
case Op_XorV:
case Op_OrV:
case Op_AndV:
case Op_UMinV:
case Op_UMaxV:

case Op_AndVMask:
case Op_OrVMask:
case Op_XorVMask:

case Op_SaturatingAddV:
assert(req() == 3, "Must be a binary operation");
// For non-predicated commutative operations, sort the inputs in
// increasing order of node indices.
if (in(1)->_idx > in(2)->_idx) {
return true;
}
// fallthrough
default:
return false;
}
}

Node* VectorNode::Ideal(PhaseGVN* phase, bool can_reshape) {
if (Matcher::vector_needs_partial_operations(this, vect_type())) {
return try_to_gen_masked_vector(phase, this, vect_type());
}

// Sort inputs of commutative non-predicated vector operations to help value numbering.
if (should_swap_inputs_to_help_global_value_numbering()) {
swap_edges(1, 2);
}
return nullptr;
}

Expand Down Expand Up @@ -2076,7 +2131,7 @@ Node* XorVNode::Ideal(PhaseGVN* phase, bool can_reshape) {
Node* zero = phase->transform(phase->zerocon(bt));
return VectorNode::scalar2vector(zero, length(), bt, bottom_type()->isa_vectmask() != nullptr);
}
return nullptr;
return VectorNode::Ideal(phase, can_reshape);
}

Node* VectorBlendNode::Identity(PhaseGVN* phase) {
Expand Down
2 changes: 2 additions & 0 deletions src/hotspot/share/opto/vectornode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ class VectorNode : public TypeNode {
static bool is_convert_opcode(int opc);
static bool is_minmax_opcode(int opc);

bool should_swap_inputs_to_help_global_value_numbering();

static bool is_vshift_cnt_opcode(int opc);

static bool is_rotate_opcode(int opc);
Expand Down
Loading

0 comments on commit e410af0

Please sign in to comment.