Skip to content

Commit e410af0

Browse files
author
Jatin Bhateja
committed
8342393: Promote commutative vector IR node sharing
Reviewed-by: vlivanov, epeter, sviswanathan
1 parent f755fad commit e410af0

File tree

4 files changed

+789
-1
lines changed

4 files changed

+789
-1
lines changed

src/hotspot/share/opto/vectornode.cpp

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1042,10 +1042,65 @@ Node* VectorNode::try_to_gen_masked_vector(PhaseGVN* gvn, Node* node, const Type
10421042
}
10431043
}
10441044

1045+
bool VectorNode::should_swap_inputs_to_help_global_value_numbering() {
1046+
// Predicated vector operations are sensitive to ordering of inputs.
1047+
// When the mask corresponding to a vector lane is false then
1048+
// the result of the operation is corresponding lane of its first operand.
1049+
// i.e. RES = VEC1.lanewise(OPER, VEC2, MASK) is semantically equivalent to
1050+
// RES = BLEND(VEC1, VEC1.lanewise(OPER, VEC2), MASK)
1051+
if (is_predicated_vector()) {
1052+
return false;
1053+
}
1054+
1055+
switch(Opcode()) {
1056+
case Op_AddVB:
1057+
case Op_AddVS:
1058+
case Op_AddVI:
1059+
case Op_AddVL:
1060+
case Op_AddVF:
1061+
case Op_AddVD:
1062+
1063+
case Op_MulVB:
1064+
case Op_MulVS:
1065+
case Op_MulVI:
1066+
case Op_MulVL:
1067+
case Op_MulVF:
1068+
case Op_MulVD:
1069+
1070+
case Op_MaxV:
1071+
case Op_MinV:
1072+
case Op_XorV:
1073+
case Op_OrV:
1074+
case Op_AndV:
1075+
case Op_UMinV:
1076+
case Op_UMaxV:
1077+
1078+
case Op_AndVMask:
1079+
case Op_OrVMask:
1080+
case Op_XorVMask:
1081+
1082+
case Op_SaturatingAddV:
1083+
assert(req() == 3, "Must be a binary operation");
1084+
// For non-predicated commutative operations, sort the inputs in
1085+
// increasing order of node indices.
1086+
if (in(1)->_idx > in(2)->_idx) {
1087+
return true;
1088+
}
1089+
// fallthrough
1090+
default:
1091+
return false;
1092+
}
1093+
}
1094+
10451095
Node* VectorNode::Ideal(PhaseGVN* phase, bool can_reshape) {
10461096
if (Matcher::vector_needs_partial_operations(this, vect_type())) {
10471097
return try_to_gen_masked_vector(phase, this, vect_type());
10481098
}
1099+
1100+
// Sort inputs of commutative non-predicated vector operations to help value numbering.
1101+
if (should_swap_inputs_to_help_global_value_numbering()) {
1102+
swap_edges(1, 2);
1103+
}
10491104
return nullptr;
10501105
}
10511106

@@ -2076,7 +2131,7 @@ Node* XorVNode::Ideal(PhaseGVN* phase, bool can_reshape) {
20762131
Node* zero = phase->transform(phase->zerocon(bt));
20772132
return VectorNode::scalar2vector(zero, length(), bt, bottom_type()->isa_vectmask() != nullptr);
20782133
}
2079-
return nullptr;
2134+
return VectorNode::Ideal(phase, can_reshape);
20802135
}
20812136

20822137
Node* VectorBlendNode::Identity(PhaseGVN* phase) {

src/hotspot/share/opto/vectornode.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ class VectorNode : public TypeNode {
8888
static bool is_convert_opcode(int opc);
8989
static bool is_minmax_opcode(int opc);
9090

91+
bool should_swap_inputs_to_help_global_value_numbering();
92+
9193
static bool is_vshift_cnt_opcode(int opc);
9294

9395
static bool is_rotate_opcode(int opc);

0 commit comments

Comments
 (0)